From 5d9b34e03028c8df15d446240e13f1c71966e3f5 Mon Sep 17 00:00:00 2001 From: ImBenji Date: Tue, 2 Dec 2025 15:15:47 +0000 Subject: [PATCH] Enhance Windows file handling with improved sync and error checking in read/write operations --- .../Private/sweepstore/utils/file_handle.cpp | 52 +++++++++---------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/cpp/src/Private/sweepstore/utils/file_handle.cpp b/cpp/src/Private/sweepstore/utils/file_handle.cpp index 05b6d4a..06f4e1c 100644 --- a/cpp/src/Private/sweepstore/utils/file_handle.cpp +++ b/cpp/src/Private/sweepstore/utils/file_handle.cpp @@ -55,6 +55,7 @@ void SweepstoreFileHandle::close() { #endif } +#if defined(_WIN32) || defined(WITH_UNREAL) // readSeek void SweepstoreFileHandle::readSeek(std::streampos pos, std::ios::seekdir dir) { #ifdef WITH_UNREAL @@ -68,17 +69,14 @@ void SweepstoreFileHandle::readSeek(std::streampos pos, std::ios::seekdir dir) { unrealHandle->SeekFromEnd(unrealPos); } #else - #ifdef _WIN32 - // On Windows, flush and sync to disk, then invalidate buffers - stream->flush(); - stream->sync(); - stream->clear(); - // Sync both pointers to same position - stream->seekp(pos, dir); - stream->seekg(pos, dir); - #else - stream->seekg(pos, dir); - #endif + // Windows + // On Windows, flush and sync to disk, then invalidate buffers + stream->flush(); + stream->sync(); + stream->clear(); + // Sync both pointers to same position + stream->seekp(pos, dir); + stream->seekg(pos, dir); #endif } @@ -88,10 +86,9 @@ void SweepstoreFileHandle::writeSeek(std::streampos pos, std::ios::seekdir dir) // Same as readSeek for Unreal readSeek(pos, dir); #else - #ifdef _WIN32 - stream->flush(); - stream->sync(); - #endif + // Windows + stream->flush(); + stream->sync(); stream->seekp(pos, dir); #endif } @@ -101,13 +98,12 @@ void SweepstoreFileHandle::readBytes(char* buffer, std::streamsize size) { #ifdef WITH_UNREAL unrealHandle->Read(reinterpret_cast(buffer), size); #else + // Windows stream->read(buffer, size); - #ifdef _WIN32 - // Check for read errors on Windows - if (stream->fail() && !stream->eof()) { - stream->clear(); - } - #endif + // Check for read errors on Windows + if (stream->fail() && !stream->eof()) { + stream->clear(); + } #endif } @@ -117,12 +113,12 @@ void SweepstoreFileHandle::writeBytes(const char* buffer, std::streamsize size) unrealHandle->Write(reinterpret_cast(buffer), size); unrealHandle->Flush(); // Unreal requires explicit flush #else + // Windows stream->write(buffer, size); - #ifdef _WIN32 - // Check for write errors on Windows - if (stream->fail()) { - stream->clear(); - } - #endif + // Check for write errors on Windows + if (stream->fail()) { + stream->clear(); + } #endif -} \ No newline at end of file +} +#endif // _WIN32 || WITH_UNREAL \ No newline at end of file