Enhance Windows file handling with improved sync and error checking in read/write operations
This commit is contained in:
parent
7adca647a6
commit
5d9b34e030
1 changed files with 24 additions and 28 deletions
|
|
@ -55,6 +55,7 @@ void SweepstoreFileHandle::close() {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(_WIN32) || defined(WITH_UNREAL)
|
||||||
// readSeek
|
// readSeek
|
||||||
void SweepstoreFileHandle::readSeek(std::streampos pos, std::ios::seekdir dir) {
|
void SweepstoreFileHandle::readSeek(std::streampos pos, std::ios::seekdir dir) {
|
||||||
#ifdef WITH_UNREAL
|
#ifdef WITH_UNREAL
|
||||||
|
|
@ -68,17 +69,14 @@ void SweepstoreFileHandle::readSeek(std::streampos pos, std::ios::seekdir dir) {
|
||||||
unrealHandle->SeekFromEnd(unrealPos);
|
unrealHandle->SeekFromEnd(unrealPos);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#ifdef _WIN32
|
// Windows
|
||||||
// On Windows, flush and sync to disk, then invalidate buffers
|
// On Windows, flush and sync to disk, then invalidate buffers
|
||||||
stream->flush();
|
stream->flush();
|
||||||
stream->sync();
|
stream->sync();
|
||||||
stream->clear();
|
stream->clear();
|
||||||
// Sync both pointers to same position
|
// Sync both pointers to same position
|
||||||
stream->seekp(pos, dir);
|
stream->seekp(pos, dir);
|
||||||
stream->seekg(pos, dir);
|
stream->seekg(pos, dir);
|
||||||
#else
|
|
||||||
stream->seekg(pos, dir);
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,10 +86,9 @@ void SweepstoreFileHandle::writeSeek(std::streampos pos, std::ios::seekdir dir)
|
||||||
// Same as readSeek for Unreal
|
// Same as readSeek for Unreal
|
||||||
readSeek(pos, dir);
|
readSeek(pos, dir);
|
||||||
#else
|
#else
|
||||||
#ifdef _WIN32
|
// Windows
|
||||||
stream->flush();
|
stream->flush();
|
||||||
stream->sync();
|
stream->sync();
|
||||||
#endif
|
|
||||||
stream->seekp(pos, dir);
|
stream->seekp(pos, dir);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
@ -101,13 +98,12 @@ void SweepstoreFileHandle::readBytes(char* buffer, std::streamsize size) {
|
||||||
#ifdef WITH_UNREAL
|
#ifdef WITH_UNREAL
|
||||||
unrealHandle->Read(reinterpret_cast<uint8*>(buffer), size);
|
unrealHandle->Read(reinterpret_cast<uint8*>(buffer), size);
|
||||||
#else
|
#else
|
||||||
|
// Windows
|
||||||
stream->read(buffer, size);
|
stream->read(buffer, size);
|
||||||
#ifdef _WIN32
|
// Check for read errors on Windows
|
||||||
// Check for read errors on Windows
|
if (stream->fail() && !stream->eof()) {
|
||||||
if (stream->fail() && !stream->eof()) {
|
stream->clear();
|
||||||
stream->clear();
|
}
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -117,12 +113,12 @@ void SweepstoreFileHandle::writeBytes(const char* buffer, std::streamsize size)
|
||||||
unrealHandle->Write(reinterpret_cast<const uint8*>(buffer), size);
|
unrealHandle->Write(reinterpret_cast<const uint8*>(buffer), size);
|
||||||
unrealHandle->Flush(); // Unreal requires explicit flush
|
unrealHandle->Flush(); // Unreal requires explicit flush
|
||||||
#else
|
#else
|
||||||
|
// Windows
|
||||||
stream->write(buffer, size);
|
stream->write(buffer, size);
|
||||||
#ifdef _WIN32
|
// Check for write errors on Windows
|
||||||
// Check for write errors on Windows
|
if (stream->fail()) {
|
||||||
if (stream->fail()) {
|
stream->clear();
|
||||||
stream->clear();
|
}
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#endif // _WIN32 || WITH_UNREAL
|
||||||
Loading…
Add table
Reference in a new issue