summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--console_cmds.c11
-rw-r--r--oldloader.c2
-rw-r--r--os2.c29
-rw-r--r--unix.c24
-rw-r--r--variables.h5
-rw-r--r--win32.c33
6 files changed, 48 insertions, 56 deletions
diff --git a/console_cmds.c b/console_cmds.c
index ff0ed891f..bc66d47f1 100644
--- a/console_cmds.c
+++ b/console_cmds.c
@@ -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();
diff --git a/oldloader.c b/oldloader.c
index 882292170..26f5813b0 100644
--- a/oldloader.c
+++ b/oldloader.c
@@ -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);
}
diff --git a/os2.c b/os2.c
index 6ceadf62f..f853f746f 100644
--- a/os2.c
+++ b/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 && (
diff --git a/unix.c b/unix.c
index f40783247..07585c926 100644
--- a/unix.c
+++ b/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 && (
diff --git a/variables.h b/variables.h
index acb69d162..cba31fca5 100644
--- a/variables.h
+++ b/variables.h
@@ -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.
diff --git a/win32.c b/win32.c
index c84a85066..9fb8ca0a5 100644
--- a/win32.c
+++ b/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);
-} \ No newline at end of file
+}