(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)
authordarkvater
Mon, 28 Mar 2005 13:30:51 +0000
changeset 1596 c1c439a2d5b2
parent 1595 b1a8323c1024
child 1597 cc09dbccddac
(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)
console_cmds.c
hal.h
misc_gui.c
os2.c
unix.c
win32.c
--- a/console_cmds.c	Mon Mar 28 12:38:02 2005 +0000
+++ b/console_cmds.c	Mon Mar 28 13:30:51 2005 +0000
@@ -293,7 +293,7 @@
 	FiosGetSavegameList(&_fios_num, SLD_LOAD_GAME);
 	FiosFreeSavegameList();
 
-	FiosGetDescText(&path);
+	FiosGetDescText(&path, NULL);
 	IConsolePrint(_iconsole_color_default, path);
 	return NULL;
 }
--- a/hal.h	Mon Mar 28 12:38:02 2005 +0000
+++ b/hal.h	Mon Mar 28 13:30:51 2005 +0000
@@ -132,10 +132,8 @@
 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
--- a/misc_gui.c	Mon Mar 28 12:38:02 2005 +0000
+++ b/misc_gui.c	Mon Mar 28 13:30:51 2005 +0000
@@ -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 @@
 
 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)
--- a/os2.c	Mon Mar 28 12:38:02 2005 +0000
+++ b/os2.c	Mon Mar 28 13:30:51 2005 +0000
@@ -375,21 +375,28 @@
 	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)
--- a/unix.c	Mon Mar 28 12:38:02 2005 +0000
+++ b/unix.c	Mon Mar 28 13:30:51 2005 +0000
@@ -300,28 +300,30 @@
 	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);
+#endif
+	if (tot != NULL) *tot = free;
 	return STR_4005_BYTES_FREE;
-#endif
 }
 
 void FiosMakeSavegameName(char *buf, const char *name)
--- a/win32.c	Mon Mar 28 12:38:02 2005 +0000
+++ b/win32.c	Mon Mar 28 13:30:51 2005 +0000
@@ -1546,13 +1546,17 @@
 	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 @@
 	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)