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 | |
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)
-rw-r--r-- | console_cmds.c | 2 | ||||
-rw-r--r-- | hal.h | 6 | ||||
-rw-r--r-- | misc_gui.c | 22 | ||||
-rw-r--r-- | os2.c | 21 | ||||
-rw-r--r-- | unix.c | 24 | ||||
-rw-r--r-- | win32.c | 40 |
6 files changed, 70 insertions, 45 deletions
diff --git a/console_cmds.c b/console_cmds.c index e8ddcb051..809808c3a 100644 --- a/console_cmds.c +++ b/console_cmds.c @@ -293,7 +293,7 @@ DEF_CONSOLE_CMD(ConPrintWorkingDirectory) FiosGetSavegameList(&_fios_num, SLD_LOAD_GAME); FiosFreeSavegameList(); - FiosGetDescText(&path); + FiosGetDescText(&path, NULL); IConsolePrint(_iconsole_color_default, path); return NULL; } @@ -132,10 +132,8 @@ FiosItem *FiosGetScenarioList(int *num, int mode); void FiosFreeSavegameList(void); // Browse to. Returns a filename w/path if we reached a file. char *FiosBrowseTo(const FiosItem *item); -// Get descriptive texts. -// Returns a path as well as a -// string describing the path. -StringID FiosGetDescText(const char **path); +// Return path, free space and stringID +StringID FiosGetDescText(const char **path, uint32 *tot); // Delete a name void FiosDelete(const char *name); // Make a filename from a name diff --git a/misc_gui.c b/misc_gui.c index acfc5e83c..0860246f8 100644 --- a/misc_gui.c +++ b/misc_gui.c @@ -20,6 +20,7 @@ #include "hal.h" // for file list +static bool _fios_path_changed; static bool _savegame_sort_dirty; bool _query_string_active; @@ -1126,25 +1127,30 @@ static const Widget _save_dialog_scen_widgets[] = { void BuildFileList(void) { + _fios_path_changed = true; FiosFreeSavegameList(); - if(_saveload_mode==SLD_NEW_GAME || _saveload_mode==SLD_LOAD_SCENARIO || _saveload_mode==SLD_SAVE_SCENARIO) + if (_saveload_mode == SLD_NEW_GAME || _saveload_mode == SLD_LOAD_SCENARIO || _saveload_mode == SLD_SAVE_SCENARIO) { _fios_list = FiosGetScenarioList(&_fios_num, _saveload_mode); - else + } else _fios_list = FiosGetSavegameList(&_fios_num, _saveload_mode); } static void DrawFiosTexts(void) { - const char *path; - StringID str; + static const char *path = NULL; + static StringID str = STR_4006_UNABLE_TO_READ_DRIVE; + static uint32 tot = 0; - str = FiosGetDescText(&path); - if (str != 0) - DrawString(2, 37, str, 0); + if (_fios_path_changed) { + str = FiosGetDescText(&path, &tot); + _fios_path_changed = false; + } + + if (str != STR_4006_UNABLE_TO_READ_DRIVE) SetDParam(0, tot); + DrawString(2, 37, str, 0); DoDrawString(path, 2, 27, 16); } - static void MakeSortedSaveGameList(void) { /* Directories are always above the files (FIOS_TYPE_DIR) @@ -375,21 +375,28 @@ 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) { struct diskfree_t free; + StringID sid; char drive; *path = _fios_path; drive = *path[0] - 'A' + 1; - _getdiskfree(drive, &free); + if (tot != NULL && _getdiskfree(drive, &free) == 0) { + *tot = free.avail_clusters * free.sectors_per_cluster * free.bytes_per_sector; + return STR_4005_BYTES_FREE; + } - SetDParam(0, free.avail_clusters * free.sectors_per_cluster * free.bytes_per_sector); - return STR_4005_BYTES_FREE; + return STR_4006_UNABLE_TO_READ_DRIVE; } void FiosMakeSavegameName(char *buf, const char *name) @@ -300,28 +300,30 @@ 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) { + uint32 free = 0; *path = _fios_path[0] != '\0' ? _fios_path : "/"; #if defined(__linux__) { struct statvfs s; - if (statvfs(*path, &s) == 0) { - uint64 tot = (uint64)s.f_bsize * s.f_bavail; - SetDParam(0, (uint32)(tot >> 20)); - return STR_4005_BYTES_FREE; + if (statvfs(*path, &s) != 0) { + free = ((uint64)s.f_bsize * s.f_bavail) >> 20; } else return STR_4006_UNABLE_TO_READ_DRIVE; } -#else - SetDParam(0, 0); - return STR_4005_BYTES_FREE; #endif + if (tot != NULL) *tot = free; + return STR_4005_BYTES_FREE; } void FiosMakeSavegameName(char *buf, const char *name) @@ -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) |