From 80845f1cd6b11d57f6cfc2bab83be9c4e299c3bd Mon Sep 17 00:00:00 2001 From: radius Date: Tue, 9 Feb 2016 23:39:16 -0500 Subject: [PATCH] save only modified values when saving remaps --- input/input_remapping.c | 17 ++++++++++++++++- libretro-common/file/config_file.c | 16 +++++++++++++++- libretro-common/include/file/config_file.h | 1 + 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/input/input_remapping.c b/input/input_remapping.c index c3265815b0..a87917fbe1 100644 --- a/input/input_remapping.c +++ b/input/input_remapping.c @@ -161,7 +161,22 @@ bool input_remapping_save_file(const char *path) { fill_pathname_join_delim(key_ident[j], buf, key_strings[j], '_', sizeof(key_ident[j])); - config_set_int(conf, key_ident[j], settings->input.remap_ids[i][j]); + + /* only save values that have been modified */ + if(j < RARCH_FIRST_CUSTOM_BIND) + { + if(settings->input.remap_ids[i][j] != j) + config_set_int(conf, key_ident[j], settings->input.remap_ids[i][j]); + else + config_unset(conf,key_ident[j]); + } + else + { + if(settings->input.remap_ids[i][j] != j - RARCH_FIRST_CUSTOM_BIND) + config_set_int(conf, key_ident[j], settings->input.remap_ids[i][j]); + else + config_unset(conf,key_ident[j]); + } } for (i = 0; i < MAX_USERS; i++) diff --git a/libretro-common/file/config_file.c b/libretro-common/file/config_file.c index 1b0e730cef..dabbbe952d 100644 --- a/libretro-common/file/config_file.c +++ b/libretro-common/file/config_file.c @@ -773,6 +773,20 @@ void config_set_string(config_file_t *conf, const char *key, const char *val) conf->entries = entry; } +void config_unset(config_file_t *conf, const char *key) +{ + struct config_entry_list *last = conf->entries; + struct config_entry_list *entry = config_get_entry(conf, key, &last); + + if (!entry) + return; + + entry->key = NULL; + entry->value = NULL; + free(entry->key); + free(entry->value); +} + void config_set_path(config_file_t *conf, const char *entry, const char *val) { #if defined(RARCH_CONSOLE) @@ -873,7 +887,7 @@ void config_file_dump(config_file_t *conf, FILE *file) list = (struct config_entry_list*)conf->entries; while (list) { - if (!list->readonly) + if (!list->readonly && list->key) fprintf(file, "%s = \"%s\"\n", list->key, list->value); list = list->next; } diff --git a/libretro-common/include/file/config_file.h b/libretro-common/include/file/config_file.h index 161ec41022..81baca941c 100644 --- a/libretro-common/include/file/config_file.h +++ b/libretro-common/include/file/config_file.h @@ -147,6 +147,7 @@ void config_set_hex(config_file_t *conf, const char *entry, unsigned val); void config_set_uint64(config_file_t *conf, const char *entry, uint64_t val); void config_set_char(config_file_t *conf, const char *entry, char val); void config_set_string(config_file_t *conf, const char *entry, const char *val); +void config_unset(config_file_t *conf, const char *key); void config_set_path(config_file_t *conf, const char *entry, const char *val); void config_set_bool(config_file_t *conf, const char *entry, bool val);