mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
This commit is contained in:
parent
d355aa11a5
commit
80aa8c868b
|
@ -198,6 +198,7 @@ static const FiosItem* GetFiosItem(const char* file)
|
|||
|
||||
for (i = 0; i < _fios_num; i++) {
|
||||
if (strcmp(file, _fios_list[i].name) == 0) break;
|
||||
if (strcmp(file, _fios_list[i].title) == 0) break;
|
||||
}
|
||||
|
||||
if (i == _fios_num) { /* If no name matches, try to parse it as number */
|
||||
|
@ -227,11 +228,13 @@ DEF_CONSOLE_CMD(ConLoad)
|
|||
item = GetFiosItem(file);
|
||||
if (item != NULL) {
|
||||
switch (item->type) {
|
||||
case FIOS_TYPE_FILE: case FIOS_TYPE_OLDFILE:
|
||||
case FIOS_TYPE_FILE: case FIOS_TYPE_OLDFILE: {
|
||||
_switch_mode = SM_LOAD;
|
||||
SetFiosType(item->type);
|
||||
strcpy(_file_to_saveload.name, FiosBrowseTo(item));
|
||||
break;
|
||||
|
||||
ttd_strlcpy(_file_to_saveload.name, FiosBrowseTo(item), sizeof(_file_to_saveload.name));
|
||||
ttd_strlcpy(_file_to_saveload.title, item->title, sizeof(_file_to_saveload.title));
|
||||
} break;
|
||||
default: IConsolePrintF(_icolour_err, "%s: Not a savegame.", file);
|
||||
}
|
||||
} else
|
||||
|
@ -255,7 +258,7 @@ DEF_CONSOLE_CMD(ConListFiles)
|
|||
|
||||
for (i = 0; i < _fios_num; i++) {
|
||||
const FiosItem *item = &_fios_list[i];
|
||||
IConsolePrintF(_icolour_def, "%d) %s", i, (item->title[0] != '\0') ? item->title : item->name);
|
||||
IConsolePrintF(_icolour_def, "%d) %s", i, item->title);
|
||||
}
|
||||
|
||||
FiosFreeSavegameList();
|
||||
|
|
|
@ -1641,7 +1641,7 @@ void GetOldSaveGameName(char *title, const char *file)
|
|||
return;
|
||||
|
||||
if (fread(title, 1, 48, f) != 48)
|
||||
title[0] = '\0';
|
||||
snprintf(title, 48, "Corrupt file");
|
||||
|
||||
fclose(f);
|
||||
}
|
||||
|
|
29
os2.c
29
os2.c
|
@ -58,10 +58,7 @@ int compare_FiosItems(const void *a, const void *b)
|
|||
if (_savegame_sort_order < 2) // sort by date
|
||||
r = da->mtime < db->mtime ? -1 : 1;
|
||||
else
|
||||
r = strcasecmp(
|
||||
da->title[0] != '\0' ? da->title : da->name,
|
||||
db->title[0] != '\0' ? db->title : db->name
|
||||
);
|
||||
r = strcasecmp(da->title, db->title);
|
||||
|
||||
if (_savegame_sort_order & 1) r = -r;
|
||||
return r;
|
||||
|
@ -99,10 +96,7 @@ FiosItem *FiosGetSavegameList(int *num, int mode)
|
|||
strcpy(_fios_save_path, _path.save_dir);
|
||||
}
|
||||
|
||||
if (_game_mode == GM_EDITOR)
|
||||
_fios_path = _fios_scn_path;
|
||||
else
|
||||
_fios_path = _fios_save_path;
|
||||
_fios_path = _fios_scn_path;
|
||||
|
||||
// Parent directory, only if not of the type C:\.
|
||||
if (_fios_path[3] != '\0') {
|
||||
|
@ -125,8 +119,7 @@ FiosItem *FiosGetSavegameList(int *num, int mode)
|
|||
fios->type = FIOS_TYPE_DIR;
|
||||
fios->mtime = 0;
|
||||
ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
|
||||
snprintf(fios->title, lengthof(fios->title),
|
||||
"%s\\ (Directory)", dirent->d_name);
|
||||
snprintf(fios->title, lengthof(fios->title), "%s\\ (Directory)", dirent->d_name);
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
|
@ -162,8 +155,10 @@ FiosItem *FiosGetSavegameList(int *num, int mode)
|
|||
fios = FiosAlloc();
|
||||
fios->type = FIOS_TYPE_FILE;
|
||||
fios->mtime = sb.st_mtime;
|
||||
fios->title[0] = '\0';
|
||||
ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
|
||||
|
||||
*t = '\0'; // strip extension
|
||||
ttd_strlcpy(fios->title, dirent->d_name, lengthof(fios->title));
|
||||
} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) {
|
||||
if (t != NULL && (
|
||||
strcasecmp(t, ".ss1") == 0 ||
|
||||
|
@ -226,9 +221,8 @@ FiosItem *FiosGetScenarioList(int *num, int mode)
|
|||
int sort_start;
|
||||
char filename[MAX_PATH];
|
||||
|
||||
if (mode == SLD_NEW_GAME || _fios_scn_path == NULL) {
|
||||
if (_fios_scn_path == NULL)
|
||||
_fios_scn_path = malloc(MAX_PATH);
|
||||
if (_fios_scn_path == NULL) {
|
||||
_fios_scn_path = malloc(MAX_PATH);
|
||||
strcpy(_fios_scn_path, _path.scenario_dir);
|
||||
}
|
||||
|
||||
|
@ -254,8 +248,7 @@ FiosItem *FiosGetScenarioList(int *num, int mode)
|
|||
fios->type = FIOS_TYPE_DIR;
|
||||
fios->mtime = 0;
|
||||
ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
|
||||
snprintf(fios->title, lengthof(fios->title),
|
||||
"%s\\ (Directory)", dirent->d_name);
|
||||
snprintf(fios->title, lengthof(fios->title), "%s\\ (Directory)", dirent->d_name);
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
|
@ -282,8 +275,10 @@ FiosItem *FiosGetScenarioList(int *num, int mode)
|
|||
fios = FiosAlloc();
|
||||
fios->type = FIOS_TYPE_SCENARIO;
|
||||
fios->mtime = sb.st_mtime;
|
||||
fios->title[0] = '\0';
|
||||
ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
|
||||
|
||||
*t = '\0'; // strip extension
|
||||
ttd_strlcpy(fios->title, dirent->d_name, lengthof(fios->title));
|
||||
} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO ||
|
||||
mode == SLD_NEW_GAME) {
|
||||
if (t != NULL && (
|
||||
|
|
24
unix.c
24
unix.c
|
@ -62,10 +62,7 @@ int compare_FiosItems(const void *a, const void *b)
|
|||
if (_savegame_sort_order < 2) // sort by date
|
||||
r = da->mtime < db->mtime ? -1 : 1;
|
||||
else
|
||||
r = strcasecmp(
|
||||
da->title[0] != '\0' ? da->title : da->name,
|
||||
db->title[0] != '\0' ? db->title : db->name
|
||||
);
|
||||
r = strcasecmp(da->title, db->title);
|
||||
|
||||
if (_savegame_sort_order & 1) r = -r;
|
||||
return r;
|
||||
|
@ -87,10 +84,7 @@ FiosItem *FiosGetSavegameList(int *num, int mode)
|
|||
strcpy(_fios_save_path, _path.save_dir);
|
||||
}
|
||||
|
||||
if (_game_mode == GM_EDITOR)
|
||||
_fios_path = _fios_scn_path;
|
||||
else
|
||||
_fios_path = _fios_save_path;
|
||||
_fios_path = _fios_save_path;
|
||||
|
||||
// Parent directory, only if not in root already.
|
||||
if (_fios_path[1] != '\0') {
|
||||
|
@ -151,8 +145,10 @@ FiosItem *FiosGetSavegameList(int *num, int mode)
|
|||
fios = FiosAlloc();
|
||||
fios->type = FIOS_TYPE_FILE;
|
||||
fios->mtime = sb.st_mtime;
|
||||
fios->title[0] = '\0';
|
||||
ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
|
||||
|
||||
*t = '\0'; // strip extension
|
||||
ttd_strlcpy(fios->title, dirent->d_name, lengthof(fios->title));
|
||||
} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) {
|
||||
if (t != NULL && (
|
||||
strcasecmp(t, ".ss1") == 0 ||
|
||||
|
@ -212,8 +208,7 @@ FiosItem *FiosGetScenarioList(int *num, int mode)
|
|||
fios->type = FIOS_TYPE_DIR;
|
||||
fios->mtime = 0;
|
||||
ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
|
||||
snprintf(fios->title, lengthof(fios->title),
|
||||
"%s/ (Directory)", dirent->d_name);
|
||||
snprintf(fios->title, lengthof(fios->title), "%s/ (Directory)", dirent->d_name);
|
||||
}
|
||||
}
|
||||
closedir(dir);
|
||||
|
@ -232,8 +227,7 @@ FiosItem *FiosGetScenarioList(int *num, int mode)
|
|||
while ((dirent = readdir(dir)) != NULL) {
|
||||
char *t;
|
||||
|
||||
snprintf(filename, lengthof(filename), "%s/%s",
|
||||
_fios_path, dirent->d_name);
|
||||
snprintf(filename, lengthof(filename), "%s/%s", _fios_path, dirent->d_name);
|
||||
if (stat(filename, &sb) || S_ISDIR(sb.st_mode)) continue;
|
||||
|
||||
t = strrchr(dirent->d_name, '.');
|
||||
|
@ -241,8 +235,10 @@ FiosItem *FiosGetScenarioList(int *num, int mode)
|
|||
fios = FiosAlloc();
|
||||
fios->type = FIOS_TYPE_SCENARIO;
|
||||
fios->mtime = sb.st_mtime;
|
||||
fios->title[0] = '\0';
|
||||
ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
|
||||
|
||||
*t = '\0'; // strip extension
|
||||
ttd_strlcpy(fios->title, dirent->d_name, lengthof(fios->title));
|
||||
} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO ||
|
||||
mode == SLD_NEW_GAME) {
|
||||
if (t != NULL && (
|
||||
|
|
|
@ -320,8 +320,9 @@ VARDEF uint _returned_refit_amount;
|
|||
|
||||
// Deals with the type of the savegame, independent of extension
|
||||
typedef struct {
|
||||
int mode; // savegame/scenario type (old, new)
|
||||
char name[MAX_PATH]; // name
|
||||
int mode; // savegame/scenario type (old, new)
|
||||
char name[MAX_PATH]; // name
|
||||
char title[255]; // internal name of the game
|
||||
} SmallFiosItem;
|
||||
|
||||
// Used when switching from the intro menu.
|
||||
|
|
33
win32.c
33
win32.c
|
@ -1579,10 +1579,7 @@ int CDECL compare_FiosItems(const void *a, const void *b)
|
|||
if (_savegame_sort_order < 2) // sort by date
|
||||
r = da->mtime < db->mtime ? -1 : 1;
|
||||
else
|
||||
r = strcasecmp(
|
||||
da->title[0] != '\0' ? da->title : da->name,
|
||||
db->title[0] != '\0' ? db->title : db->name
|
||||
);
|
||||
r = strcasecmp(da->title, db->title);
|
||||
|
||||
if (_savegame_sort_order & 1) r = -r;
|
||||
return r;
|
||||
|
@ -1602,10 +1599,7 @@ FiosItem *FiosGetSavegameList(int *num, int mode)
|
|||
strcpy(_fios_save_path, _path.save_dir);
|
||||
}
|
||||
|
||||
if (_game_mode == GM_EDITOR)
|
||||
_fios_path = _fios_scn_path;
|
||||
else
|
||||
_fios_path = _fios_save_path;
|
||||
_fios_path = _fios_save_path;
|
||||
|
||||
// Parent directory, only if not of the type C:\.
|
||||
if (_fios_path[3] != '\0') {
|
||||
|
@ -1627,8 +1621,7 @@ FiosItem *FiosGetSavegameList(int *num, int mode)
|
|||
fios->type = FIOS_TYPE_DIR;
|
||||
fios->mtime = 0;
|
||||
ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name));
|
||||
snprintf(fios->title, lengthof(fios->title),
|
||||
"%s\\ (Directory)", fd.cFileName);
|
||||
snprintf(fios->title, lengthof(fios->title), "%s\\ (Directory)", fd.cFileName);
|
||||
}
|
||||
} while (FindNextFile(h, &fd));
|
||||
FindClose(h);
|
||||
|
@ -1655,8 +1648,11 @@ FiosItem *FiosGetSavegameList(int *num, int mode)
|
|||
fios = FiosAlloc();
|
||||
fios->type = FIOS_TYPE_FILE;
|
||||
fios->mtime = *(uint64*)&fd.ftLastWriteTime;
|
||||
fios->title[0] = '\0';
|
||||
ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name));
|
||||
|
||||
*t = '\0'; // strip extension
|
||||
ttd_strlcpy(fios->title, fd.cFileName, lengthof(fios->title));
|
||||
|
||||
} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) {
|
||||
if (t != NULL && (
|
||||
strcasecmp(t, ".ss1") == 0 ||
|
||||
|
@ -1706,9 +1702,8 @@ FiosItem *FiosGetScenarioList(int *num, int mode)
|
|||
HANDLE h;
|
||||
int sort_start;
|
||||
|
||||
if (mode == SLD_NEW_GAME || _fios_scn_path == NULL) {
|
||||
if (_fios_scn_path == NULL)
|
||||
_fios_scn_path = malloc(MAX_PATH);
|
||||
if (_fios_scn_path == NULL) {
|
||||
_fios_scn_path = malloc(MAX_PATH);
|
||||
strcpy(_fios_scn_path, _path.scenario_dir);
|
||||
}
|
||||
|
||||
|
@ -1733,8 +1728,7 @@ FiosItem *FiosGetScenarioList(int *num, int mode)
|
|||
fios->type = FIOS_TYPE_DIR;
|
||||
fios->mtime = 0;
|
||||
ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name));
|
||||
snprintf(fios->title, lengthof(fios->title),
|
||||
"%s\\ (Directory)", fd.cFileName);
|
||||
snprintf(fios->title, lengthof(fios->title), "%s\\ (Directory)", fd.cFileName);
|
||||
}
|
||||
} while (FindNextFile(h, &fd));
|
||||
FindClose(h);
|
||||
|
@ -1760,8 +1754,11 @@ FiosItem *FiosGetScenarioList(int *num, int mode)
|
|||
fios = FiosAlloc();
|
||||
fios->type = FIOS_TYPE_SCENARIO;
|
||||
fios->mtime = *(uint64*)&fd.ftLastWriteTime;
|
||||
fios->title[0] = '\0';
|
||||
ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name));
|
||||
|
||||
*t = '\0'; // strip extension
|
||||
ttd_strlcpy(fios->title, fd.cFileName, lengthof(fios->title));
|
||||
|
||||
} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO ||
|
||||
mode == SLD_NEW_GAME) {
|
||||
if (t != NULL && (
|
||||
|
@ -2269,4 +2266,4 @@ void JoinOTTDThread(void)
|
|||
void CSleep(int milliseconds)
|
||||
{
|
||||
Sleep(milliseconds);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue