From 490f17e9bf7940f0e09eac66ff3c5a8d536f3624 Mon Sep 17 00:00:00 2001 From: neonloop Date: Thu, 12 Aug 2021 15:34:52 +0000 Subject: Allows deleting game-specific config from menu --- main.c | 21 ++++++++++++++++++++- main.h | 2 ++ menu.c | 24 ++++++++++++++++++++++-- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 9cd0696..b3998db 100644 --- a/main.c +++ b/main.c @@ -22,6 +22,7 @@ bool should_quit = false; unsigned current_audio_buffer_size; char core_name[MAX_PATH]; char* content_path; +int config_override = 0; static uint32_t vsyncs; static uint32_t renders; @@ -126,6 +127,10 @@ int save_config(int is_game) config_write_keys(config_file); fclose(config_file); + + if (is_game) + config_override = 1; + return 0; } @@ -136,7 +141,9 @@ static void alloc_config_buffer(char **config_ptr) { config_file_name(config_filename, MAX_PATH, 1); config_file = fopen(config_filename, "rb"); - if (!config_file) { + if (config_file) { + config_override = 1; + } else { config_file_name(config_filename, MAX_PATH, 0); config_file = fopen(config_filename, "rb"); } @@ -191,6 +198,18 @@ static void load_config_keys(void) } } +int remove_config(int is_game) { + char config_filename[MAX_PATH]; + int ret; + + config_file_name(config_filename, MAX_PATH, is_game); + ret = remove(config_filename); + if (ret == 0) + config_override = 0; + + return ret; +} + void handle_emu_action(emu_action action) { static emu_action prev_action = EACTION_NONE; diff --git a/main.h b/main.h index 3d0a13c..146db02 100644 --- a/main.h +++ b/main.h @@ -22,6 +22,7 @@ extern bool should_quit; extern unsigned current_audio_buffer_size; extern char core_name[MAX_PATH]; extern char* content_path; +extern int config_override; #ifdef MMENU extern void* mmenu; @@ -55,6 +56,7 @@ static inline bool has_suffix_i(const char *str, const char *suffix) { void set_defaults(void); int save_config(int is_game); void load_config(void); +int remove_config(int is_game); void handle_emu_action(emu_action action); void pa_log(enum retro_log_level level, const char *fmt, ...); diff --git a/menu.c b/menu.c index e691f16..880dde5 100644 --- a/menu.c +++ b/menu.c @@ -23,6 +23,7 @@ typedef enum MA_MAIN_EXIT, MA_OPT_SAVECFG, MA_OPT_SAVECFG_GAME, + MA_OPT_RMCFG_GAME, MA_CTRL_PLAYER1, MA_CTRL_EMU, } menu_id; @@ -175,6 +176,16 @@ static int mh_savecfg(int id, int keys) return 1; } +static int mh_rmcfg(int id, int keys) +{ + if (remove_config(id == MA_OPT_RMCFG_GAME ? 1 : 0) == 0) + menu_update_msg("config removed"); + else + menu_update_msg("failed to remove config"); + + return 1; +} + static int menu_loop_core_options_page(int offset, int keys) { static int sel = 0; menu_entry *e_menu_core_options; @@ -235,8 +246,9 @@ static int menu_loop_core_options(int id, int keys) return menu_loop_core_options_page(0, keys); } -static const char h_restore_def[] = "Switches back to default / recommended\n" - "configuration"; +static const char h_rm_config_game[] = "Removes game-specific config file"; + +static const char h_restore_def[] = "Switches back to default settings"; static const char h_show_fps[] = "Shows frames and vsyncs per second"; @@ -325,17 +337,25 @@ static int menu_loop_keyconfig(int id, int keys) return 0; } +const char *config_label(int id, int *offs) { + return config_override ? "Loaded: game config" : "Loaded: global config"; +} + static menu_entry e_menu_config_options[] = { mee_cust_nosave ("Save global config", MA_OPT_SAVECFG, mh_savecfg, mgn_saveloadcfg), mee_cust_nosave ("Save game config", MA_OPT_SAVECFG_GAME, mh_savecfg, mgn_saveloadcfg), + mee_handler_id_h ("Delete game config", MA_OPT_RMCFG_GAME, mh_rmcfg, h_rm_config_game), mee_handler_h ("Restore defaults", mh_restore_defaults, h_restore_def), + mee_label (""), + mee_label_mk (0, config_label), mee_end, }; static int menu_loop_config_options(int id, int keys) { static int sel = 0; + me_enable(e_menu_config_options, MA_OPT_RMCFG_GAME, config_override == 1); me_loop(e_menu_config_options, &sel); -- cgit v1.2.3