--- a/hal.h Wed Mar 22 11:24:27 2006 +0000
+++ b/hal.h Wed Mar 22 11:26:08 2006 +0000
@@ -88,7 +88,7 @@
// Delete a name
bool FiosDelete(const char *name);
// Make a filename from a name
-void FiosMakeSavegameName(char *buf, const char *name);
+void FiosMakeSavegameName(char *buf, const char *name, size_t size);
int CDECL compare_FiosItems(const void *a, const void *b);
--- a/misc_gui.c Wed Mar 22 11:24:27 2006 +0000
+++ b/misc_gui.c Wed Mar 22 11:26:08 2006 +0000
@@ -1325,7 +1325,7 @@
DeleteWindow(w);
} else {
// SLD_SAVE_GAME, SLD_SAVE_SCENARIO copy clicked name to editbox
- ttd_strlcpy(WP(w, querystr_d).text.buf, file->name, WP(w, querystr_d).text.maxlength);
+ ttd_strlcpy(WP(w, querystr_d).text.buf, file->title, WP(w, querystr_d).text.maxlength);
UpdateTextBufferSize(&WP(w, querystr_d).text);
InvalidateWidget(w, 10);
}
@@ -1359,16 +1359,17 @@
if (HASBIT(w->click_state, 11)) { /* Delete button clicked */
if (!FiosDelete(WP(w,querystr_d).text.buf)) {
ShowErrorMessage(INVALID_STRING_ID, STR_4008_UNABLE_TO_DELETE_FILE, 0, 0);
+ } else {
+ BuildFileList();
+ /* Reset file name to current date on successfull delete */
+ if (_saveload_mode == SLD_SAVE_GAME) GenerateFileName();
}
+
+ UpdateTextBufferSize(&WP(w, querystr_d).text);
SetWindowDirty(w);
- BuildFileList();
- if (_saveload_mode == SLD_SAVE_GAME) {
- GenerateFileName(); /* Reset file name to current date */
- UpdateTextBufferSize(&WP(w, querystr_d).text);
- }
} else if (HASBIT(w->click_state, 12)) { /* Save button clicked */
_switch_mode = SM_SAVE;
- FiosMakeSavegameName(_file_to_saveload.name, WP(w,querystr_d).text.buf);
+ FiosMakeSavegameName(_file_to_saveload.name, WP(w,querystr_d).text.buf, sizeof(_file_to_saveload.name));
/* In the editor set up the vehicle engines correctly (date might have changed) */
if (_game_mode == GM_EDITOR) StartupEngines();
--- a/os2.c Wed Mar 22 11:24:27 2006 +0000
+++ b/os2.c Wed Mar 22 11:26:08 2006 +0000
@@ -401,7 +401,7 @@
return STR_4006_UNABLE_TO_READ_DRIVE;
}
-void FiosMakeSavegameName(char *buf, const char *name)
+void FiosMakeSavegameName(char *buf, const char *name, size_t size)
{
const char* extension;
const char* period;
@@ -415,14 +415,14 @@
period = strrchr(name, '.');
if (period != NULL && strcasecmp(period, extension) == 0) extension = "";
- sprintf(buf, "%s\\%s%s", _fios_path, name, extension);
+ snprintf(buf, size, "%s\\%s%s", _fios_path, name, extension);
}
bool FiosDelete(const char *name)
{
char path[512];
- snprintf(path, lengthof(path), "%s\\%s", _fios_path, name);
+ FiosMakeSavegameName(path, name, sizeof(path));
return unlink(path) == 0;
}
--- a/unix.c Wed Mar 22 11:24:27 2006 +0000
+++ b/unix.c Wed Mar 22 11:26:08 2006 +0000
@@ -361,7 +361,7 @@
return STR_4005_BYTES_FREE;
}
-void FiosMakeSavegameName(char *buf, const char *name)
+void FiosMakeSavegameName(char *buf, const char *name, size_t size)
{
const char* extension;
const char* period;
@@ -375,14 +375,14 @@
period = strrchr(name, '.');
if (period != NULL && strcasecmp(period, extension) == 0) extension = "";
- sprintf(buf, "%s/%s%s", _fios_path, name, extension);
+ snprintf(buf, size, "%s/%s%s", _fios_path, name, extension);
}
bool FiosDelete(const char *name)
{
char path[512];
- snprintf(path, lengthof(path), "%s/%s", _fios_path, name);
+ FiosMakeSavegameName(path, name, sizeof(path));
return unlink(path) == 0;
}
--- a/win32.c Wed Mar 22 11:24:27 2006 +0000
+++ b/win32.c Wed Mar 22 11:26:08 2006 +0000
@@ -963,7 +963,7 @@
return sid;
}
-void FiosMakeSavegameName(char *buf, const char *name)
+void FiosMakeSavegameName(char *buf, const char *name, size_t size)
{
const char* extension;
const char* period;
@@ -977,14 +977,14 @@
period = strrchr(name, '.');
if (period != NULL && strcasecmp(period, extension) == 0) extension = "";
- sprintf(buf, "%s\\%s%s", _fios_path, name, extension);
+ snprintf(buf, size, "%s\\%s%s", _fios_path, name, extension);
}
bool FiosDelete(const char *name)
{
char path[512];
- snprintf(path, lengthof(path), "%s\\%s", _fios_path, name);
+ FiosMakeSavegameName(path, name, sizeof(path));
return DeleteFile(path) != 0;
}