summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2006-12-05 11:13:22 +0000
committerpeter1138 <peter1138@openttd.org>2006-12-05 11:13:22 +0000
commit941e6248cfe059ca3d17b8bd449100c2917839f9 (patch)
treedf8c160d605fb6e99c8db095afe47859bc7c367c
parent9e151cf54f7a522b0898802f656d85c58c8800c4 (diff)
downloadopenttd-941e6248cfe059ca3d17b8bd449100c2917839f9.tar.xz
(svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list
-rw-r--r--lang/english.txt1
-rw-r--r--newgrf_gui.c19
2 files changed, 16 insertions, 4 deletions
diff --git a/lang/english.txt b/lang/english.txt
index 24459f005..c848a5909 100644
--- a/lang/english.txt
+++ b/lang/english.txt
@@ -2898,6 +2898,7 @@ STR_NEWGRF_ADD_FILE :{BLACK}Add to s
STR_NEWGRF_ADD_FILE_TIP :{BLACK}Add the selected NewGRF file to your configuration
STR_NEWGRF_RESCAN_FILES :{BLACK}Rescan files
STR_NEWGRF_RESCAN_FILES_TIP :{BLACK}Update the list of available NewGRF files
+STR_NEWGRF_DUPLICATE_GRFID :{WHITE}Cannot add file: duplicate GRF ID
STR_NEWGRF_NOT_FOUND :{RED}Matching file not found
STR_NEWGRF_DISABLED :{RED}Disabled
diff --git a/newgrf_gui.c b/newgrf_gui.c
index 71a273b4f..7d7eb4f2c 100644
--- a/newgrf_gui.c
+++ b/newgrf_gui.c
@@ -167,13 +167,26 @@ static void NewGRFAddDlgWndProc(Window *w, WindowEvent *e)
case 6: /* Add selection to list */
if (WP(w, newgrf_add_d).sel != NULL) {
const GRFConfig *src = WP(w, newgrf_add_d).sel;
- GRFConfig *c = calloc(1, sizeof(*c));
+ GRFConfig **list, *c;
+
+ /* Find last entry in the list, checking for duplicate grfid on the way */
+ for (list = WP(w, newgrf_add_d).list; *list != NULL; list = &(*list)->next) {
+ if ((*list)->grfid == src->grfid) {
+ ShowErrorMessage(INVALID_STRING_ID, STR_NEWGRF_DUPLICATE_GRFID, 0, 0);
+ return;
+ }
+ }
+
+ /* Copy GRF details from scanned list */
+ c = calloc(1, sizeof(*c));
*c = *src;
c->filename = strdup(src->filename);
if (src->name != NULL) c->name = strdup(src->name);
if (src->info != NULL) c->info = strdup(src->info);
c->next = NULL;
- *WP(w, newgrf_add_d).list = c;
+
+ /* Append GRF config to configuration list */
+ *list = c;
DeleteWindowByClass(WC_SAVELOAD);
InvalidateWindowData(WC_GAME_OPTIONS, 0);
@@ -313,8 +326,6 @@ static void NewGRFWndProc(Window *w, WindowEvent *e)
w = AllocateWindowDesc(&_newgrf_add_dlg_desc);
w->resize.step_height = 10;
- /* Find the last entry in the list */
- for (; *list != NULL; list = &(*list)->next);
WP(w, newgrf_add_d).list = list;
break;
}