Change: [Win32] Use more modern way of getting free disk space

This commit is contained in:
Niels Martin Hansen 2021-02-21 21:05:43 +01:00
parent b427ddce88
commit cc465efa67
1 changed files with 3 additions and 8 deletions

View File

@ -244,15 +244,10 @@ bool FiosIsHiddenFile(const struct dirent *ent)
bool FiosGetDiskFreeSpace(const char *path, uint64 *tot)
{
UINT sem = SetErrorMode(SEM_FAILCRITICALERRORS); // disable 'no-disk' message box
bool retval = false;
wchar_t root[4];
DWORD spc, bps, nfc, tnc;
_snwprintf(root, lengthof(root), L"%c:" PATHSEP, path[0]);
if (tot != nullptr && GetDiskFreeSpace(root, &spc, &bps, &nfc, &tnc)) {
*tot = ((spc * bps) * (uint64)nfc);
retval = true;
}
ULARGE_INTEGER bytes_free;
bool retval = GetDiskFreeSpaceEx(OTTD2FS(path), &bytes_free, nullptr, nullptr);
if (retval) *tot = bytes_free.QuadPart;
SetErrorMode(sem); // reset previous setting
return retval;