mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
This commit is contained in:
parent
fff763b5ce
commit
24cccc8333
52
src/fios.cpp
52
src/fios.cpp
|
@ -152,6 +152,10 @@ char *FiosBrowseTo(const FiosItem *item)
|
||||||
snprintf(str_buffr, lengthof(str_buffr), "%s%s", path, item->name);
|
snprintf(str_buffr, lengthof(str_buffr), "%s%s", path, item->name);
|
||||||
return str_buffr;
|
return str_buffr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case FIOS_TYPE_DRIVE:
|
||||||
|
case FIOS_TYPE_INVALID:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -208,13 +212,13 @@ bool FileExists(const char *filename)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef byte fios_getlist_callback_proc(int mode, const char *filename, const char *ext, char *title);
|
typedef FiosType fios_getlist_callback_proc(SaveLoadDialogMode mode, const char *filename, const char *ext, char *title);
|
||||||
|
|
||||||
/** Create a list of the files in a directory, according to some arbitrary rule.
|
/** Create a list of the files in a directory, according to some arbitrary rule.
|
||||||
* @param mode The mode we are in. Some modes don't allow 'parent'.
|
* @param mode The mode we are in. Some modes don't allow 'parent'.
|
||||||
* @param callback_proc The function that is called where you need to do the filtering.
|
* @param callback_proc The function that is called where you need to do the filtering.
|
||||||
* @return Return the list of files. */
|
* @return Return the list of files. */
|
||||||
static FiosItem *FiosGetFileList(int mode, fios_getlist_callback_proc *callback_proc)
|
static FiosItem *FiosGetFileList(SaveLoadDialogMode mode, fios_getlist_callback_proc *callback_proc)
|
||||||
{
|
{
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
struct dirent *dirent;
|
struct dirent *dirent;
|
||||||
|
@ -277,7 +281,7 @@ static FiosItem *FiosGetFileList(int mode, fios_getlist_callback_proc *callback_
|
||||||
if ((t = strrchr(d_name, '.')) == NULL) continue;
|
if ((t = strrchr(d_name, '.')) == NULL) continue;
|
||||||
fios_title[0] = '\0'; // reset the title;
|
fios_title[0] = '\0'; // reset the title;
|
||||||
|
|
||||||
byte type = callback_proc(mode, d_name, t, fios_title);
|
FiosType type = callback_proc(mode, d_name, t, fios_title);
|
||||||
if (type != FIOS_TYPE_INVALID) {
|
if (type != FIOS_TYPE_INVALID) {
|
||||||
fios = FiosAlloc();
|
fios = FiosAlloc();
|
||||||
fios->mtime = sb.st_mtime;
|
fios->mtime = sb.st_mtime;
|
||||||
|
@ -313,7 +317,7 @@ static FiosItem *FiosGetFileList(int mode, fios_getlist_callback_proc *callback_
|
||||||
* @see FiosGetFileList
|
* @see FiosGetFileList
|
||||||
* @see FiosGetSavegameList
|
* @see FiosGetSavegameList
|
||||||
*/
|
*/
|
||||||
static byte FiosGetSavegameListCallback(int mode, const char *file, const char *ext, char *title)
|
static FiosType FiosGetSavegameListCallback(SaveLoadDialogMode mode, const char *file, const char *ext, char *title)
|
||||||
{
|
{
|
||||||
/* Show savegame files
|
/* Show savegame files
|
||||||
* .SAV OpenTTD saved game
|
* .SAV OpenTTD saved game
|
||||||
|
@ -339,16 +343,16 @@ static byte FiosGetSavegameListCallback(int mode, const char *file, const char *
|
||||||
* @return A pointer to an array of FiosItem representing all the files to be shown in the save/load dialog.
|
* @return A pointer to an array of FiosItem representing all the files to be shown in the save/load dialog.
|
||||||
* @see FiosGetFileList
|
* @see FiosGetFileList
|
||||||
*/
|
*/
|
||||||
FiosItem *FiosGetSavegameList(int mode)
|
FiosItem *FiosGetSavegameList(SaveLoadDialogMode mode)
|
||||||
{
|
{
|
||||||
static char *_fios_save_path = NULL;
|
static char *fios_save_path = NULL;
|
||||||
|
|
||||||
if (_fios_save_path == NULL) {
|
if (fios_save_path == NULL) {
|
||||||
_fios_save_path = MallocT<char>(MAX_PATH);
|
fios_save_path = MallocT<char>(MAX_PATH);
|
||||||
FioGetDirectory(_fios_save_path, MAX_PATH, SAVE_DIR);
|
FioGetDirectory(fios_save_path, MAX_PATH, SAVE_DIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
_fios_path = _fios_save_path;
|
_fios_path = fios_save_path;
|
||||||
|
|
||||||
return FiosGetFileList(mode, &FiosGetSavegameListCallback);
|
return FiosGetFileList(mode, &FiosGetSavegameListCallback);
|
||||||
}
|
}
|
||||||
|
@ -363,7 +367,7 @@ FiosItem *FiosGetSavegameList(int mode)
|
||||||
* @see FiosGetFileList
|
* @see FiosGetFileList
|
||||||
* @see FiosGetScenarioList
|
* @see FiosGetScenarioList
|
||||||
*/
|
*/
|
||||||
static byte FiosGetScenarioListCallback(int mode, const char *file, const char *ext, char *title)
|
static FiosType FiosGetScenarioListCallback(SaveLoadDialogMode mode, const char *file, const char *ext, char *title)
|
||||||
{
|
{
|
||||||
/* Show scenario files
|
/* Show scenario files
|
||||||
* .SCN OpenTTD style scenario file
|
* .SCN OpenTTD style scenario file
|
||||||
|
@ -387,22 +391,22 @@ static byte FiosGetScenarioListCallback(int mode, const char *file, const char *
|
||||||
* @return A pointer to an array of FiosItem representing all the files to be shown in the save/load dialog.
|
* @return A pointer to an array of FiosItem representing all the files to be shown in the save/load dialog.
|
||||||
* @see FiosGetFileList
|
* @see FiosGetFileList
|
||||||
*/
|
*/
|
||||||
FiosItem *FiosGetScenarioList(int mode)
|
FiosItem *FiosGetScenarioList(SaveLoadDialogMode mode)
|
||||||
{
|
{
|
||||||
static char *_fios_scn_path = NULL;
|
static char *fios_scn_path = NULL;
|
||||||
|
|
||||||
/* Copy the default path on first run or on 'New Game' */
|
/* Copy the default path on first run or on 'New Game' */
|
||||||
if (_fios_scn_path == NULL) {
|
if (fios_scn_path == NULL) {
|
||||||
_fios_scn_path = MallocT<char>(MAX_PATH);
|
fios_scn_path = MallocT<char>(MAX_PATH);
|
||||||
FioGetDirectory(_fios_scn_path, MAX_PATH, SCENARIO_DIR);
|
FioGetDirectory(fios_scn_path, MAX_PATH, SCENARIO_DIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
_fios_path = _fios_scn_path;
|
_fios_path = fios_scn_path;
|
||||||
|
|
||||||
return FiosGetFileList(mode, &FiosGetScenarioListCallback);
|
return FiosGetFileList(mode, &FiosGetScenarioListCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
static byte FiosGetHeightmapListCallback(int mode, const char *file, const char *ext, char *title)
|
static FiosType FiosGetHeightmapListCallback(SaveLoadDialogMode mode, const char *file, const char *ext, char *title)
|
||||||
{
|
{
|
||||||
/* Show heightmap files
|
/* Show heightmap files
|
||||||
* .PNG PNG Based heightmap files
|
* .PNG PNG Based heightmap files
|
||||||
|
@ -419,16 +423,16 @@ static byte FiosGetHeightmapListCallback(int mode, const char *file, const char
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get a list of Heightmaps */
|
/* Get a list of Heightmaps */
|
||||||
FiosItem *FiosGetHeightmapList(int mode)
|
FiosItem *FiosGetHeightmapList(SaveLoadDialogMode mode)
|
||||||
{
|
{
|
||||||
static char *_fios_hmap_path = NULL;
|
static char *fios_hmap_path = NULL;
|
||||||
|
|
||||||
if (_fios_hmap_path == NULL) {
|
if (fios_hmap_path == NULL) {
|
||||||
_fios_hmap_path = MallocT<char>(MAX_PATH);
|
fios_hmap_path = MallocT<char>(MAX_PATH);
|
||||||
FioGetDirectory(_fios_hmap_path, MAX_PATH, HEIGHTMAP_DIR);
|
FioGetDirectory(fios_hmap_path, MAX_PATH, HEIGHTMAP_DIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
_fios_path = _fios_hmap_path;
|
_fios_path = fios_hmap_path;
|
||||||
|
|
||||||
return FiosGetFileList(mode, &FiosGetHeightmapListCallback);
|
return FiosGetFileList(mode, &FiosGetHeightmapListCallback);
|
||||||
}
|
}
|
||||||
|
|
32
src/fios.h
32
src/fios.h
|
@ -42,23 +42,23 @@ enum FileType {
|
||||||
FT_HEIGHTMAP, ///< heightmap file
|
FT_HEIGHTMAP, ///< heightmap file
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum FiosType {
|
||||||
FIOS_TYPE_DRIVE = 0,
|
FIOS_TYPE_DRIVE,
|
||||||
FIOS_TYPE_PARENT = 1,
|
FIOS_TYPE_PARENT,
|
||||||
FIOS_TYPE_DIR = 2,
|
FIOS_TYPE_DIR,
|
||||||
FIOS_TYPE_FILE = 3,
|
FIOS_TYPE_FILE,
|
||||||
FIOS_TYPE_OLDFILE = 4,
|
FIOS_TYPE_OLDFILE,
|
||||||
FIOS_TYPE_SCENARIO = 5,
|
FIOS_TYPE_SCENARIO,
|
||||||
FIOS_TYPE_OLD_SCENARIO = 6,
|
FIOS_TYPE_OLD_SCENARIO,
|
||||||
FIOS_TYPE_DIRECT = 7,
|
FIOS_TYPE_DIRECT,
|
||||||
FIOS_TYPE_PNG = 8,
|
FIOS_TYPE_PNG,
|
||||||
FIOS_TYPE_BMP = 9,
|
FIOS_TYPE_BMP,
|
||||||
FIOS_TYPE_INVALID = 255,
|
FIOS_TYPE_INVALID = 255,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Deals with finding savegames */
|
/* Deals with finding savegames */
|
||||||
struct FiosItem {
|
struct FiosItem {
|
||||||
byte type;
|
FiosType type;
|
||||||
uint64 mtime;
|
uint64 mtime;
|
||||||
char title[64];
|
char title[64];
|
||||||
char name[256 - 12 - 64];
|
char name[256 - 12 - 64];
|
||||||
|
@ -82,11 +82,11 @@ extern SaveLoadDialogMode _saveload_mode; ///< defined in misc_gui.cpp
|
||||||
void ShowSaveLoadDialog(SaveLoadDialogMode mode);
|
void ShowSaveLoadDialog(SaveLoadDialogMode mode);
|
||||||
|
|
||||||
/* Get a list of savegames */
|
/* Get a list of savegames */
|
||||||
FiosItem *FiosGetSavegameList(int mode);
|
FiosItem *FiosGetSavegameList(SaveLoadDialogMode mode);
|
||||||
/* Get a list of scenarios */
|
/* Get a list of scenarios */
|
||||||
FiosItem *FiosGetScenarioList(int mode);
|
FiosItem *FiosGetScenarioList(SaveLoadDialogMode mode);
|
||||||
/* Get a list of Heightmaps */
|
/* Get a list of Heightmaps */
|
||||||
FiosItem *FiosGetHeightmapList(int mode);
|
FiosItem *FiosGetHeightmapList(SaveLoadDialogMode mode);
|
||||||
/* Free the list of savegames */
|
/* Free the list of savegames */
|
||||||
void FiosFreeSavegameList();
|
void FiosFreeSavegameList();
|
||||||
/* Browse to. Returns a filename w/path if we reached a file. */
|
/* Browse to. Returns a filename w/path if we reached a file. */
|
||||||
|
|
|
@ -1455,6 +1455,7 @@ static void MakeSortedSaveGameList()
|
||||||
case FIOS_TYPE_DIR: sort_start++; break;
|
case FIOS_TYPE_DIR: sort_start++; break;
|
||||||
case FIOS_TYPE_PARENT: sort_start++; break;
|
case FIOS_TYPE_PARENT: sort_start++; break;
|
||||||
case FIOS_TYPE_DRIVE: sort_end++; break;
|
case FIOS_TYPE_DRIVE: sort_end++; break;
|
||||||
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue