Implement file handling improvements with Unreal compatibility and enhanced read/write methods

This commit is contained in:
ImBenji
2025-12-02 15:08:10 +00:00
parent 55d5ab7a7b
commit ad6a740a73
4 changed files with 170 additions and 52 deletions

View File

@@ -4,21 +4,26 @@
#include <string>
#include <memory>
#ifdef WITH_UNREAL
#include "HAL/PlatformFileManager.h"
#include "GenericPlatform/GenericPlatformFile.h"
#endif
class SweepstoreFileHandle {
private:
std::string path;
#ifdef WITH_UNREAL
IFileHandle* unrealHandle;
#else
std::unique_ptr<std::fstream> stream;
#endif
public:
SweepstoreFileHandle(const std::string& p, std::ios::openmode mode = std::ios::in | std::ios::out | std::ios::binary)
: path(p), stream(std::make_unique<std::fstream>(p, mode)) {
if (!stream->is_open()) {
throw std::runtime_error("Failed to open file: " + path);
}
}
SweepstoreFileHandle(const std::string& p, std::ios::openmode mode = std::ios::in | std::ios::out | std::ios::binary);
const std::string& getPath() const { return path; }
#ifndef WITH_UNREAL
std::fstream& getStream() { return *stream; }
const std::fstream& getStream() const { return *stream; }
@@ -28,14 +33,16 @@ public:
std::fstream& operator*() { return *stream; }
const std::fstream& operator*() const { return *stream; }
#endif
bool isOpen() const { return stream && stream->is_open(); }
bool isOpen() const;
void close();
void close() {
if (stream) {
stream->close();
}
}
// Windows-compatible I/O wrappers
void readSeek(std::streampos pos, std::ios::seekdir dir = std::ios::beg);
void writeSeek(std::streampos pos, std::ios::seekdir dir = std::ios::beg);
void readBytes(char* buffer, std::streamsize size);
void writeBytes(const char* buffer, std::streamsize size);
SweepstoreFileHandle(SweepstoreFileHandle&&) noexcept = default;
SweepstoreFileHandle& operator=(SweepstoreFileHandle&&) noexcept = default;