diff --git a/src/util/SFile.cpp b/src/util/SFile.cpp index 60c63a2..84a29f6 100644 --- a/src/util/SFile.cpp +++ b/src/util/SFile.cpp @@ -59,6 +59,22 @@ uint32_t SFile::GetFileSize(SFile* file, uint32_t* filesizeHigh) { return low; } +// TODO: Proper implementation +int32_t SFile::FileExists(const char* filename) { + return SFile::FileExistsEx(filename, 0); +} + +// TODO: Proper implementation +int32_t SFile::FileExistsEx(const char* filename, uint32_t a2) { + SFile* test_file; + if (!SFile::Open(filename, &test_file)) { + return 0; + } + + SFile::Close(test_file); + return 1; +} + int32_t SFile::IsStreamingMode() { // TODO return 0; @@ -157,6 +173,39 @@ int32_t SFile::OpenEx(SArchive* archive, const char* filename, uint32_t flags, S return 1; } +uint32_t SFile::SetFilePointer(SFile* file, int32_t distancetomove, int32_t* distancetomovehigh, uint32_t movemethod) { + switch (file->m_type) { + case SFILE_PLAIN: { + auto stream = reinterpret_cast(file->m_handle); + int32_t whence = movemethod; + if (whence != 0 && whence != 1) { + if (whence >= 2) { + whence = movemethod != 2 ? -1 : 2; + } + } + int64_t offset = distancetomove; + if (distancetomovehigh) { + offset |= *distancetomovehigh << 32; + } + int64_t pos; + Blizzard::File::SetPos(stream, offset, whence); + if (Blizzard::File::GetPos(stream, pos)) { + if (distancetomovehigh) { + *distancetomovehigh = (pos >> 32) & 0xFFFFFFFF; + } + return pos & 0xFFFFFFFF; + } + + return 0xFFFFFFFF; + } + case SFILE_PAQ: { + return static_cast(SFileSetFilePointer(file->m_handle, static_cast(distancetomove), reinterpret_cast(distancetomovehigh), static_cast(movemethod))); + } + default: + STORM_ASSERT(0); + } +} + // TODO Proper implementation int32_t SFile::Read(SFile* file, void* buffer, size_t bytestoread, size_t* bytesread, SOVERLAPPED* overlapped, TASYNCPARAMBLOCK* asyncparam) { switch (file->m_type) { diff --git a/src/util/SFile.hpp b/src/util/SFile.hpp index e5ec20e..1e3db95 100644 --- a/src/util/SFile.hpp +++ b/src/util/SFile.hpp @@ -26,10 +26,13 @@ class SFile { // Static functions static int32_t Close(SFile*); static uint32_t GetFileSize(SFile*, uint32_t*); + static int32_t FileExists(const char* filename); + static int32_t FileExistsEx(const char* filename, uint32_t a2); static int32_t IsStreamingMode(void); static int32_t Load(SArchive*, const char*, void**, size_t*, size_t, uint32_t, SOVERLAPPED*); static int32_t Open(const char*, SFile**); static int32_t OpenEx(SArchive*, const char*, uint32_t, SFile**); + static uint32_t SetFilePointer(SFile* file, int32_t distancetomove, int32_t* distancetomovehigh, uint32_t movemethod); static int32_t Read(SFile*, void*, size_t, size_t*, SOVERLAPPED*, TASYNCPARAMBLOCK*); static int32_t Unload(void*); static int32_t SetBasePath(const char* path);