Enhance Windows file handling with improved sync and error checking in read/write operations
This commit is contained in:
@@ -69,11 +69,16 @@ void SweepstoreFileHandle::readSeek(std::streampos pos, std::ios::seekdir dir) {
|
||||
}
|
||||
#else
|
||||
#ifdef _WIN32
|
||||
// On Windows, flush output and sync to invalidate input buffer
|
||||
// On Windows, flush and sync to disk, then invalidate buffers
|
||||
stream->flush();
|
||||
stream->seekp(pos, dir); // Sync put pointer
|
||||
stream->sync();
|
||||
stream->clear();
|
||||
// Sync both pointers to same position
|
||||
stream->seekp(pos, dir);
|
||||
stream->seekg(pos, dir);
|
||||
#else
|
||||
stream->seekg(pos, dir);
|
||||
#endif
|
||||
stream->seekg(pos, dir);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -84,7 +89,8 @@ void SweepstoreFileHandle::writeSeek(std::streampos pos, std::ios::seekdir dir)
|
||||
readSeek(pos, dir);
|
||||
#else
|
||||
#ifdef _WIN32
|
||||
stream->flush(); // Flush any pending writes
|
||||
stream->flush();
|
||||
stream->sync();
|
||||
#endif
|
||||
stream->seekp(pos, dir);
|
||||
#endif
|
||||
@@ -96,6 +102,12 @@ void SweepstoreFileHandle::readBytes(char* buffer, std::streamsize size) {
|
||||
unrealHandle->Read(reinterpret_cast<uint8*>(buffer), size);
|
||||
#else
|
||||
stream->read(buffer, size);
|
||||
#ifdef _WIN32
|
||||
// Check for read errors on Windows
|
||||
if (stream->fail() && !stream->eof()) {
|
||||
stream->clear();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -106,5 +118,11 @@ void SweepstoreFileHandle::writeBytes(const char* buffer, std::streamsize size)
|
||||
unrealHandle->Flush(); // Unreal requires explicit flush
|
||||
#else
|
||||
stream->write(buffer, size);
|
||||
#ifdef _WIN32
|
||||
// Check for write errors on Windows
|
||||
if (stream->fail()) {
|
||||
stream->clear();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user