(svn r7367) -Codechange: prevent adding files where the GRF ID is already in the list

This commit is contained in:
peter1138 2006-12-05 11:13:22 +00:00
parent 032ec36bcc
commit 4e26968521
2 changed files with 16 additions and 4 deletions

View File

@ -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

View File

@ -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;
}