(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)

This commit is contained in:
darkvater 2005-03-28 13:30:51 +00:00
parent 555a78aaac
commit d643ca6271
6 changed files with 70 additions and 45 deletions

View File

@ -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;
}

6
hal.h
View File

@ -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

View File

@ -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)
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)

21
os2.c
View File

@ -375,23 +375,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)
{
struct diskfree_t free;
StringID sid;
char drive;
*path = _fios_path;
drive = *path[0] - 'A' + 1;
_getdiskfree(drive, &free);
SetDParam(0, free.avail_clusters * free.sectors_per_cluster * free.bytes_per_sector);
if (tot != NULL && _getdiskfree(drive, &free) == 0) {
*tot = 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)
{
const char* extension;

24
unix.c
View File

@ -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)

40
win32.c
View File

@ -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)