From 317ad3181dc3decf0cc52824e59cbac5a53adcce Mon Sep 17 00:00:00 2001 From: jdgleaver Date: Mon, 9 Nov 2020 11:18:49 +0000 Subject: [PATCH] (config_file) Enable saving of changed parameters when '#include' directives are used --- libretro-common/file/config_file.c | 56 ++++++++++++++++++------------ 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/libretro-common/file/config_file.c b/libretro-common/file/config_file.c index 38dedaa06d..2d8026b1f1 100644 --- a/libretro-common/file/config_file.c +++ b/libretro-common/file/config_file.c @@ -1053,11 +1053,7 @@ void config_set_string(config_file_t *conf, const char *key, const char *val) if (entry) { /* An entry corresponding to 'key' already exists - * > Check if it's read only */ - if (entry->readonly) - return; - - /* Check whether value is currently set */ + * > Check whether value is currently set */ if (entry->value) { /* Do nothing if value is unchanged */ @@ -1069,9 +1065,12 @@ void config_set_string(config_file_t *conf, const char *key, const char *val) free(entry->value); } - /* Update value */ - entry->value = strdup(val); - conf->modified = true; + /* Update value + * > Note that once a value is set, it + * is no longer considered 'read only' */ + entry->value = strdup(val); + entry->readonly = false; + conf->modified = true; return; } } @@ -1245,14 +1244,6 @@ void config_file_dump_orbis(config_file_t *conf, int fd) { struct config_entry_list *list = NULL; struct config_include_list *includes = conf->includes; - while (includes) - { - char cad[256]; - snprintf(cad, sizeof(cad), - "#include %s\n", includes->path); - orbisWrite(fd, cad, strlen(cad)); - includes = includes->next; - } list = config_file_merge_sort_linked_list( (struct config_entry_list*)conf->entries, @@ -1270,6 +1261,21 @@ void config_file_dump_orbis(config_file_t *conf, int fd) } list = list->next; } + + /* Config files are read from the top down - if + * duplicate entries are found then the topmost + * one in the list takes precedence. This means + * '#include' directives must go *after* individual + * config entries, otherwise they will override + * any custom-set values */ + while (includes) + { + char cad[256]; + snprintf(cad, sizeof(cad), + "#include %s\n", includes->path); + orbisWrite(fd, cad, strlen(cad)); + includes = includes->next; + } } #endif @@ -1278,12 +1284,6 @@ void config_file_dump(config_file_t *conf, FILE *file, bool sort) struct config_entry_list *list = NULL; struct config_include_list *includes = conf->includes; - while (includes) - { - fprintf(file, "#include \"%s\"\n", includes->path); - includes = includes->next; - } - if (sort) list = config_file_merge_sort_linked_list( (struct config_entry_list*)conf->entries, @@ -1299,6 +1299,18 @@ void config_file_dump(config_file_t *conf, FILE *file, bool sort) fprintf(file, "%s = \"%s\"\n", list->key, list->value); list = list->next; } + + /* Config files are read from the top down - if + * duplicate entries are found then the topmost + * one in the list takes precedence. This means + * '#include' directives must go *after* individual + * config entries, otherwise they will override + * any custom-set values */ + while (includes) + { + fprintf(file, "#include \"%s\"\n", includes->path); + includes = includes->next; + } } bool config_entry_exists(config_file_t *conf, const char *entry)