diff --git a/Source/utils/file_util.cpp b/Source/utils/file_util.cpp index 797b62cd0..75b1b73fb 100644 --- a/Source/utils/file_util.cpp +++ b/Source/utils/file_util.cpp @@ -3,7 +3,6 @@ #include #include -#include #include @@ -26,6 +25,7 @@ #endif #if _POSIX_C_SOURCE >= 200112L || defined(_BSD_SOURCE) || defined(__APPLE__) +#include #include #else #include @@ -82,11 +82,25 @@ bool FileExists(const char *path) bool GetFileSize(const char *path, std::uintmax_t *size) { +#if defined(_WIN64) || defined(_WIN32) + const auto pathUtf16 = ToWideChar(path); + if (pathUtf16 == nullptr) { + LogError("UTF-8 -> UTF-16 conversion error code {}", ::GetLastError()); + return false; + } + WIN32_FILE_ATTRIBUTE_DATA attr; + if (!GetFileAttributesExW(&pathUtf16[0], GetFileExInfoStandard, &attr)) { + return false; + } + *size = (attr.nFileSizeHigh) << (sizeof(attr.nFileSizeHigh) * 8) | attr.nFileSizeLow; + return true; +#else struct ::stat statResult; if (::stat(path, &statResult) == -1) return false; *size = static_cast(statResult.st_size); return true; +#endif } bool ResizeFile(const char *path, std::uintmax_t size)