mirror of https://github.com/OpenTTD/OpenTTD
(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)
parent
4573a9f872
commit
6bca4c041a
|
@ -293,7 +293,7 @@ DEF_CONSOLE_CMD(ConPrintWorkingDirectory)
|
||||||
FiosGetSavegameList(&_fios_num, SLD_LOAD_GAME);
|
FiosGetSavegameList(&_fios_num, SLD_LOAD_GAME);
|
||||||
FiosFreeSavegameList();
|
FiosFreeSavegameList();
|
||||||
|
|
||||||
FiosGetDescText(&path);
|
FiosGetDescText(&path, NULL);
|
||||||
IConsolePrint(_iconsole_color_default, path);
|
IConsolePrint(_iconsole_color_default, path);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
6
hal.h
6
hal.h
|
@ -132,10 +132,8 @@ FiosItem *FiosGetScenarioList(int *num, int mode);
|
||||||
void FiosFreeSavegameList(void);
|
void FiosFreeSavegameList(void);
|
||||||
// Browse to. Returns a filename w/path if we reached a file.
|
// Browse to. Returns a filename w/path if we reached a file.
|
||||||
char *FiosBrowseTo(const FiosItem *item);
|
char *FiosBrowseTo(const FiosItem *item);
|
||||||
// Get descriptive texts.
|
// Return path, free space and stringID
|
||||||
// Returns a path as well as a
|
StringID FiosGetDescText(const char **path, uint32 *tot);
|
||||||
// string describing the path.
|
|
||||||
StringID FiosGetDescText(const char **path);
|
|
||||||
// Delete a name
|
// Delete a name
|
||||||
void FiosDelete(const char *name);
|
void FiosDelete(const char *name);
|
||||||
// Make a filename from a name
|
// Make a filename from a name
|
||||||
|
|
22
misc_gui.c
22
misc_gui.c
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
#include "hal.h" // for file list
|
#include "hal.h" // for file list
|
||||||
|
|
||||||
|
static bool _fios_path_changed;
|
||||||
static bool _savegame_sort_dirty;
|
static bool _savegame_sort_dirty;
|
||||||
|
|
||||||
bool _query_string_active;
|
bool _query_string_active;
|
||||||
|
@ -1126,25 +1127,30 @@ static const Widget _save_dialog_scen_widgets[] = {
|
||||||
|
|
||||||
void BuildFileList(void)
|
void BuildFileList(void)
|
||||||
{
|
{
|
||||||
|
_fios_path_changed = true;
|
||||||
FiosFreeSavegameList();
|
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);
|
_fios_list = FiosGetScenarioList(&_fios_num, _saveload_mode);
|
||||||
else
|
} else
|
||||||
_fios_list = FiosGetSavegameList(&_fios_num, _saveload_mode);
|
_fios_list = FiosGetSavegameList(&_fios_num, _saveload_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DrawFiosTexts(void)
|
static void DrawFiosTexts(void)
|
||||||
{
|
{
|
||||||
const char *path;
|
static const char *path = NULL;
|
||||||
StringID str;
|
static StringID str = STR_4006_UNABLE_TO_READ_DRIVE;
|
||||||
|
static uint32 tot = 0;
|
||||||
|
|
||||||
str = FiosGetDescText(&path);
|
if (_fios_path_changed) {
|
||||||
if (str != 0)
|
str = FiosGetDescText(&path, &tot);
|
||||||
DrawString(2, 37, str, 0);
|
_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);
|
DoDrawString(path, 2, 27, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void MakeSortedSaveGameList(void)
|
static void MakeSortedSaveGameList(void)
|
||||||
{
|
{
|
||||||
/* Directories are always above the files (FIOS_TYPE_DIR)
|
/* Directories are always above the files (FIOS_TYPE_DIR)
|
||||||
|
|
21
os2.c
21
os2.c
|
@ -375,21 +375,28 @@ char *FiosBrowseTo(const FiosItem *item)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get descriptive texts.
|
/**
|
||||||
// Returns a path as well as a
|
* Get descriptive texts. Returns the path and free space
|
||||||
// string describing the path.
|
* left on the device
|
||||||
StringID FiosGetDescText(const char **path)
|
* @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;
|
struct diskfree_t free;
|
||||||
|
StringID sid;
|
||||||
char drive;
|
char drive;
|
||||||
|
|
||||||
*path = _fios_path;
|
*path = _fios_path;
|
||||||
drive = *path[0] - 'A' + 1;
|
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_4006_UNABLE_TO_READ_DRIVE;
|
||||||
return STR_4005_BYTES_FREE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FiosMakeSavegameName(char *buf, const char *name)
|
void FiosMakeSavegameName(char *buf, const char *name)
|
||||||
|
|
24
unix.c
24
unix.c
|
@ -300,28 +300,30 @@ char *FiosBrowseTo(const FiosItem *item)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get descriptive texts.
|
/**
|
||||||
// Returns a path as well as a
|
* Get descriptive texts. Returns the path and free space
|
||||||
// string describing the path.
|
* left on the device
|
||||||
StringID FiosGetDescText(const char **path)
|
* @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 : "/";
|
*path = _fios_path[0] != '\0' ? _fios_path : "/";
|
||||||
|
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
{
|
{
|
||||||
struct statvfs s;
|
struct statvfs s;
|
||||||
|
|
||||||
if (statvfs(*path, &s) == 0) {
|
if (statvfs(*path, &s) != 0) {
|
||||||
uint64 tot = (uint64)s.f_bsize * s.f_bavail;
|
free = ((uint64)s.f_bsize * s.f_bavail) >> 20;
|
||||||
SetDParam(0, (uint32)(tot >> 20));
|
|
||||||
return STR_4005_BYTES_FREE;
|
|
||||||
} else
|
} else
|
||||||
return STR_4006_UNABLE_TO_READ_DRIVE;
|
return STR_4006_UNABLE_TO_READ_DRIVE;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
SetDParam(0, 0);
|
|
||||||
return STR_4005_BYTES_FREE;
|
|
||||||
#endif
|
#endif
|
||||||
|
if (tot != NULL) *tot = free;
|
||||||
|
return STR_4005_BYTES_FREE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FiosMakeSavegameName(char *buf, const char *name)
|
void FiosMakeSavegameName(char *buf, const char *name)
|
||||||
|
|
40
win32.c
40
win32.c
|
@ -1546,13 +1546,17 @@ static FiosItem *FiosAlloc(void)
|
||||||
return &_fios_items[_fios_count++];
|
return &_fios_items[_fios_count++];
|
||||||
}
|
}
|
||||||
|
|
||||||
static HANDLE MyFindFirstFile(const char *path, const char *file,
|
static HANDLE MyFindFirstFile(const char *path, const char *file, WIN32_FIND_DATA *fd)
|
||||||
WIN32_FIND_DATA *fd)
|
|
||||||
{
|
{
|
||||||
|
UINT sem = SetErrorMode(SEM_FAILCRITICALERRORS); // disable 'no-disk' message box
|
||||||
|
HANDLE h;
|
||||||
char paths[MAX_PATH];
|
char paths[MAX_PATH];
|
||||||
|
|
||||||
sprintf(paths, "%s\\%s", path, file);
|
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)
|
int CDECL compare_FiosItems(const void *a, const void *b)
|
||||||
|
@ -1834,23 +1838,31 @@ char *FiosBrowseTo(const FiosItem *item)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get descriptive texts.
|
/**
|
||||||
// Returns a path as well as a
|
* Get descriptive texts. Returns the path and free space
|
||||||
// string describing the path.
|
* left on the device
|
||||||
StringID FiosGetDescText(const char **path)
|
* @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];
|
char root[4];
|
||||||
DWORD spc, bps, nfc, tnc;
|
DWORD spc, bps, nfc, tnc;
|
||||||
|
StringID sid;
|
||||||
|
|
||||||
*path = _fios_path;
|
*path = _fios_path;
|
||||||
|
|
||||||
sprintf(root, "%c:\\", _fios_path[0]);
|
sprintf(root, "%c:\\", _fios_path[0]);
|
||||||
if (GetDiskFreeSpace(root, &spc, &bps, &nfc, &tnc)) {
|
if (tot != NULL && GetDiskFreeSpace(root, &spc, &bps, &nfc, &tnc)) {
|
||||||
uint32 tot = ((spc * bps) * (uint64)nfc) >> 20;
|
*tot = ((spc * bps) * (uint64)nfc) >> 20;
|
||||||
SetDParam(0, tot);
|
sid = STR_4005_BYTES_FREE;
|
||||||
return STR_4005_BYTES_FREE;
|
} else
|
||||||
} else {
|
sid = STR_4006_UNABLE_TO_READ_DRIVE;
|
||||||
return STR_4006_UNABLE_TO_READ_DRIVE;
|
|
||||||
}
|
SetErrorMode(sem); // reset previous setting
|
||||||
|
return sid;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FiosMakeSavegameName(char *buf, const char *name)
|
void FiosMakeSavegameName(char *buf, const char *name)
|
||||||
|
|
Loading…
Reference in New Issue