From ea8b7ca0b8975158f89938b4a1af7e51bb542dff Mon Sep 17 00:00:00 2001 From: fallenoak Date: Thu, 30 Oct 2025 23:04:29 -0500 Subject: [PATCH] feat(util): add SFile::FileExists --- src/util/SFile.cpp | 16 ++++++++++++++++ src/util/SFile.hpp | 1 + 2 files changed, 17 insertions(+) diff --git a/src/util/SFile.cpp b/src/util/SFile.cpp index e741b3e..44b0d02 100644 --- a/src/util/SFile.cpp +++ b/src/util/SFile.cpp @@ -16,6 +16,22 @@ int32_t SFile::Close(SFile* file) { return 1; } +// TODO Proper implementation +int32_t SFile::FileExists(const char* filename) { + auto pathLen = SStrLen(filename); + char path[STORM_MAX_PATH]; + SStrCopy(path, filename, sizeof(path)); + + for (int32_t i = 0; i < pathLen; ++i) { + if (path[i] == '\\') { + path[i] = '/'; + } + } + + std::ifstream f(path); + return f.good(); +} + // TODO Proper implementation size_t SFile::GetFileSize(SFile* file, size_t* filesizeHigh) { return file->m_size; diff --git a/src/util/SFile.hpp b/src/util/SFile.hpp index 244bb14..f46dc81 100644 --- a/src/util/SFile.hpp +++ b/src/util/SFile.hpp @@ -14,6 +14,7 @@ class SFile { public: // Static functions static int32_t Close(SFile*); + static int32_t FileExists(const char* filename); static size_t GetFileSize(SFile*, size_t*); static int32_t IsStreamingMode(); static int32_t IsStreamingTrial();