Revert "remove windows specific code because stat works for this on windows"
This reverts commit 0987f8b479.
This commit is contained in:
parent
6f71fd5b21
commit
cfd72b68a0
1 changed files with 15 additions and 1 deletions
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
|
|
@ -26,6 +25,7 @@
|
|||
#endif
|
||||
|
||||
#if _POSIX_C_SOURCE >= 200112L || defined(_BSD_SOURCE) || defined(__APPLE__)
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include <cstdio>
|
||||
|
|
@ -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<uintmax_t>(statResult.st_size);
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool ResizeFile(const char *path, std::uintmax_t size)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue