From 51bc64559b7a7cc41cc877cb978ddb5da169435e Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 4 Feb 2020 01:02:40 +0100 Subject: [PATCH] Revert "(Config file) Don't save 'nul' entries in config file anymore -" This reverts commit 4c6d46137c05e583de5d8978e95991f36344d86b. --- configuration.c | 2 +- configuration.h | 4 ---- file_path_special.c | 2 +- input/input_driver.h | 3 ++- retroarch.c | 42 ++++++++++++++++++++++++------------------ 5 files changed, 28 insertions(+), 25 deletions(-) diff --git a/configuration.c b/configuration.c index 16c3b20f6a..02f78031bc 100644 --- a/configuration.c +++ b/configuration.c @@ -3725,7 +3725,7 @@ bool config_save_autoconf_profile(const char *path, unsigned user) if (bind->valid) input_config_save_keybind( conf, "input", input_config_bind_map_get_base(i), - bind); + bind, false); } ret = config_file_write(conf, autoconf_file, false); diff --git a/configuration.h b/configuration.h index 7cd26fc274..9c8d85f6fe 100644 --- a/configuration.h +++ b/configuration.h @@ -53,10 +53,6 @@ var = newvar; \ } -#ifndef EXPLICIT_NULL -#define EXPLICIT_NULL "nul" -#endif - enum crt_switch_type { CRT_SWITCH_NONE = 0, diff --git a/file_path_special.c b/file_path_special.c index a42920e319..b0978a9a27 100644 --- a/file_path_special.c +++ b/file_path_special.c @@ -453,7 +453,7 @@ void fill_short_pathname_representation_wrapper(char* out_rep, last_slash = find_last_slash(path_short); - if (last_slash) + if (last_slash != NULL) { /* We handle paths like: * /path/to/file.7z#mygame.img diff --git a/input/input_driver.h b/input/input_driver.h index 31de9de847..895f141386 100644 --- a/input/input_driver.h +++ b/input/input_driver.h @@ -545,7 +545,8 @@ uint16_t input_config_get_vid(unsigned port); void input_config_save_keybinds_user(void *data, unsigned user); void input_config_save_keybind(void *data, const char *prefix, - const char *base, const struct retro_keybind *bind); + const char *base, const struct retro_keybind *bind, + bool save_empty); void input_config_reset(void); diff --git a/retroarch.c b/retroarch.c index a2118a8b1f..4b807e3600 100644 --- a/retroarch.c +++ b/retroarch.c @@ -17731,12 +17731,9 @@ void input_config_save_keybinds_user(void *data, unsigned user) fill_pathname_join_delim(key, prefix, base, '_', sizeof(key)); input_keymaps_translate_rk_to_str(bind->key, btn, sizeof(btn)); + config_set_string(conf, key, btn); - if (!string_is_equal(btn, EXPLICIT_NULL)) - { - config_set_string(conf, key, btn); - input_config_save_keybind(conf, prefix, base, bind); - } + input_config_save_keybind(conf, prefix, base, bind, true); } } @@ -17778,7 +17775,7 @@ static void save_keybind_hat(config_file_t *conf, const char *key, static void save_keybind_joykey(config_file_t *conf, const char *prefix, const char *base, - const struct retro_keybind *bind) + const struct retro_keybind *bind, bool save_empty) { char key[64]; @@ -17787,7 +17784,12 @@ static void save_keybind_joykey(config_file_t *conf, fill_pathname_join_delim_concat(key, prefix, base, '_', "_btn", sizeof(key)); - if (GET_HAT_DIR(bind->joykey)) + if (bind->joykey == NO_BTN) + { + if (save_empty) + config_set_string(conf, key, "nul"); + } + else if (GET_HAT_DIR(bind->joykey)) save_keybind_hat(conf, key, bind); else config_set_uint64(conf, key, bind->joykey); @@ -17796,7 +17798,7 @@ static void save_keybind_joykey(config_file_t *conf, static void save_keybind_axis(config_file_t *conf, const char *prefix, const char *base, - const struct retro_keybind *bind) + const struct retro_keybind *bind, bool save_empty) { char key[64]; unsigned axis = 0; @@ -17809,7 +17811,12 @@ static void save_keybind_axis(config_file_t *conf, "_axis", sizeof(key)); - if (AXIS_NEG_GET(bind->joyaxis) != AXIS_DIR_NONE) + if (bind->joyaxis == AXIS_NONE) + { + if (save_empty) + config_set_string(conf, key, "nul"); + } + else if (AXIS_NEG_GET(bind->joyaxis) != AXIS_DIR_NONE) { dir = '-'; axis = AXIS_NEG_GET(bind->joyaxis); @@ -17834,7 +17841,7 @@ static void save_keybind_axis(config_file_t *conf, static void save_keybind_mbutton(config_file_t *conf, const char *prefix, const char *base, - const struct retro_keybind *bind) + const struct retro_keybind *bind, bool save_empty) { char key[64]; @@ -17873,6 +17880,8 @@ static void save_keybind_mbutton(config_file_t *conf, config_set_string(conf, key, "whd"); break; default: + if (save_empty) + config_set_string(conf, key, "nul"); break; } } @@ -17888,17 +17897,14 @@ static void save_keybind_mbutton(config_file_t *conf, * Save a key binding to the config file. */ void input_config_save_keybind(void *data, const char *prefix, - const char *base, const struct retro_keybind *bind) + const char *base, const struct retro_keybind *bind, + bool save_empty) { config_file_t *conf = (config_file_t*)data; - - if (bind->joykey != NO_BTN) - save_keybind_joykey(conf, prefix, base, bind); - if (bind->joyaxis != AXIS_NONE) - save_keybind_axis(conf, prefix, base, bind); - if (bind->mbutton != NO_BTN) - save_keybind_mbutton(conf, prefix, base, bind); + save_keybind_joykey (conf, prefix, base, bind, save_empty); + save_keybind_axis (conf, prefix, base, bind, save_empty); + save_keybind_mbutton(conf, prefix, base, bind, save_empty); } /* MIDI */