diff options
author | darkvater <darkvater@openttd.org> | 2005-03-28 13:30:51 +0000 |
---|---|---|
committer | darkvater <darkvater@openttd.org> | 2005-03-28 13:30:51 +0000 |
commit | 6bca4c041a243de1750f660aec7b386bdfce335e (patch) | |
tree | 6cffe0e6190cbdddbfde21540b0a10de2eadcef2 /win32.c | |
parent | 4573a9f872ca0f384d9db513687fcf35f664863f (diff) | |
download | openttd-6bca4c041a243de1750f660aec7b386bdfce335e.tar.xz |
(svn r2100) - Fix: [1024703]: Infinite access for A:\ (win32). Patch [1171208]. Only requery drive(s) if the user changes a directory, also surpress the OS error box that pops up on some windows machines. Tron + glx (and me)
Diffstat (limited to 'win32.c')
-rw-r--r-- | win32.c | 40 |
1 files changed, 26 insertions, 14 deletions
@@ -1546,13 +1546,17 @@ static FiosItem *FiosAlloc(void) return &_fios_items[_fios_count++]; } -static HANDLE MyFindFirstFile(const char *path, const char *file, - WIN32_FIND_DATA *fd) +static HANDLE MyFindFirstFile(const char *path, const char *file, WIN32_FIND_DATA *fd) { + UINT sem = SetErrorMode(SEM_FAILCRITICALERRORS); // disable 'no-disk' message box + HANDLE h; char paths[MAX_PATH]; sprintf(paths, "%s\\%s", path, file); - return FindFirstFile(paths, fd); + h = FindFirstFile(paths, fd); + + SetErrorMode(sem); // restore previous setting + return h; } int CDECL compare_FiosItems(const void *a, const void *b) @@ -1834,23 +1838,31 @@ char *FiosBrowseTo(const FiosItem *item) return NULL; } -// Get descriptive texts. -// Returns a path as well as a -// string describing the path. -StringID FiosGetDescText(const char **path) +/** + * Get descriptive texts. Returns the path and free space + * left on the device + * @param path string describing the path + * @param tfs total free space in megabytes, optional (can be NULL) + * @return StringID describing the path (free space or failure) + */ +StringID FiosGetDescText(const char **path, uint32 *tot) { + UINT sem = SetErrorMode(SEM_FAILCRITICALERRORS); // disable 'no-disk' message box char root[4]; DWORD spc, bps, nfc, tnc; + StringID sid; + *path = _fios_path; sprintf(root, "%c:\\", _fios_path[0]); - if (GetDiskFreeSpace(root, &spc, &bps, &nfc, &tnc)) { - uint32 tot = ((spc * bps) * (uint64)nfc) >> 20; - SetDParam(0, tot); - return STR_4005_BYTES_FREE; - } else { - return STR_4006_UNABLE_TO_READ_DRIVE; - } + if (tot != NULL && GetDiskFreeSpace(root, &spc, &bps, &nfc, &tnc)) { + *tot = ((spc * bps) * (uint64)nfc) >> 20; + sid = STR_4005_BYTES_FREE; + } else + sid = STR_4006_UNABLE_TO_READ_DRIVE; + + SetErrorMode(sem); // reset previous setting + return sid; } void FiosMakeSavegameName(char *buf, const char *name) |