summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordarkvater <darkvater@openttd.org>2005-03-28 13:30:51 +0000
committerdarkvater <darkvater@openttd.org>2005-03-28 13:30:51 +0000
commit6bca4c041a243de1750f660aec7b386bdfce335e (patch)
tree6cffe0e6190cbdddbfde21540b0a10de2eadcef2
parent4573a9f872ca0f384d9db513687fcf35f664863f (diff)
downloadopenttd-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.c2
-rw-r--r--hal.h6
-rw-r--r--misc_gui.c22
-rw-r--r--os2.c21
-rw-r--r--unix.c24
-rw-r--r--win32.c40
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;
}
diff --git a/hal.h b/hal.h
index 4e4b29405..261ed0383 100644
--- a/hal.h
+++ b/hal.h
@@ -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)
diff --git a/os2.c b/os2.c
index 284757e40..edc0afb84 100644
--- a/os2.c
+++ b/os2.c
@@ -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)
diff --git a/unix.c b/unix.c
index 5ab036852..93fbcc79d 100644
--- a/unix.c
+++ b/unix.c
@@ -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)
diff --git a/win32.c b/win32.c
index 9d5a86632..c633e63e8 100644
--- a/win32.c
+++ b/win32.c
@@ -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)