From f81ea09f2035737624dfa86d5c750f2d3cffe7a7 Mon Sep 17 00:00:00 2001 From: radius Date: Sun, 13 May 2018 23:17:44 -0500 Subject: [PATCH] add saving, deletion options for per-dir remaps --- command.c | 5 ++++- configuration.c | 2 +- input/input_remapping.c | 1 + intl/msg_hash_lbl.h | 4 ++++ intl/msg_hash_us.h | 4 ++++ menu/cbs/menu_cbs_ok.c | 44 +++++++++++++++++++++++++++++++++++++++++ menu/menu_displaylist.c | 14 +++++++++++++ msg_hash.h | 3 +++ retroarch.c | 10 ++++++++++ retroarch.h | 4 ++++ 10 files changed, 89 insertions(+), 2 deletions(-) diff --git a/command.c b/command.c index 3bd70f9ad0..91755ce343 100644 --- a/command.c +++ b/command.c @@ -1297,7 +1297,9 @@ static void command_event_restore_default_shader_preset(void) static void command_event_restore_remaps(void) { - if (rarch_ctl(RARCH_CTL_IS_REMAPS_GAME_ACTIVE, NULL)) + if (rarch_ctl(RARCH_CTL_IS_REMAPS_CORE_ACTIVE, NULL) || + rarch_ctl(RARCH_CTL_IS_REMAPS_CONTENT_DIR_ACTIVE, NULL) || + rarch_ctl(RARCH_CTL_IS_REMAPS_GAME_ACTIVE, NULL)) input_remapping_set_defaults(true); } @@ -1520,6 +1522,7 @@ static void command_event_save_current_config(enum override_type type) break; case OVERRIDE_GAME: case OVERRIDE_CORE: + case OVERRIDE_CONTENT_DIR: if (config_save_overrides(type)) { strlcpy(msg, msg_hash_to_str(MSG_OVERRIDES_SAVED_SUCCESSFULLY), sizeof(msg)); diff --git a/configuration.c b/configuration.c index 0f18ef15b5..661c2eba17 100644 --- a/configuration.c +++ b/configuration.c @@ -3262,7 +3262,7 @@ bool config_load_remap(void) { runloop_msg_queue_push(msg_hash_to_str( MSG_GAME_REMAP_FILE_LOADED), 1, 100, true); - rarch_ctl(RARCH_CTL_SET_REMAPS_GAME_ACTIVE, NULL); + rarch_ctl(RARCH_CTL_SET_REMAPS_CONTENT_DIR_ACTIVE, NULL); goto success; } } diff --git a/input/input_remapping.c b/input/input_remapping.c index f92eb20d86..32e9875168 100644 --- a/input/input_remapping.c +++ b/input/input_remapping.c @@ -288,6 +288,7 @@ void input_remapping_set_defaults(bool deinit) free(global->name.remapfile); global->name.remapfile = NULL; rarch_ctl(RARCH_CTL_UNSET_REMAPS_CORE_ACTIVE, NULL); + rarch_ctl(RARCH_CTL_UNSET_REMAPS_CONTENT_DIR_ACTIVE, NULL); rarch_ctl(RARCH_CTL_UNSET_REMAPS_GAME_ACTIVE, NULL); } diff --git a/intl/msg_hash_lbl.h b/intl/msg_hash_lbl.h index 72175c21a3..34c9bbcd1d 100644 --- a/intl/msg_hash_lbl.h +++ b/intl/msg_hash_lbl.h @@ -897,8 +897,12 @@ MSG_HASH(MENU_ENUM_LABEL_REMAP_FILE_LOAD, "remap_file_load") MSG_HASH(MENU_ENUM_LABEL_REMAP_FILE_SAVE_CORE, "remap_file_save_core") +MSG_HASH(MENU_ENUM_LABEL_REMAP_FILE_SAVE_CONTENT_DIR, + "remap_file_save_content_dir") MSG_HASH(MENU_ENUM_LABEL_REMAP_FILE_SAVE_GAME, "remap_file_save_game") +MSG_HASH(MENU_ENUM_LABEL_REMAP_FILE_REMOVE_CONTENT_DIR, + "remap_file_remove_content_dir") MSG_HASH(MENU_ENUM_LABEL_REMAP_FILE_REMOVE_CORE, "remap_file_remove_core") MSG_HASH(MENU_ENUM_LABEL_REMAP_FILE_REMOVE_GAME, diff --git a/intl/msg_hash_us.h b/intl/msg_hash_us.h index 57f69f0759..3b843e4910 100644 --- a/intl/msg_hash_us.h +++ b/intl/msg_hash_us.h @@ -1343,12 +1343,16 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_REMAP_FILE_LOAD, "Load Remap File") MSG_HASH(MENU_ENUM_LABEL_VALUE_REMAP_FILE_SAVE_CORE, "Save Core Remap File") +MSG_HASH(MENU_ENUM_LABEL_VALUE_REMAP_FILE_SAVE_CONTENT_DIR, + "Save Content Directory Remap File") MSG_HASH(MENU_ENUM_LABEL_VALUE_REMAP_FILE_SAVE_GAME, "Save Game Remap File") MSG_HASH(MENU_ENUM_LABEL_VALUE_REMAP_FILE_REMOVE_CORE, "Delete Core Remap File") MSG_HASH(MENU_ENUM_LABEL_VALUE_REMAP_FILE_REMOVE_GAME, "Delete Game Remap File") +MSG_HASH(MENU_ENUM_LABEL_VALUE_REMAP_FILE_REMOVE_CONTENT_DIR, + "Delete Game Content Directory Remap File") MSG_HASH(MENU_ENUM_LABEL_VALUE_REQUIRED, "Required") MSG_HASH(MENU_ENUM_LABEL_VALUE_RESTART_CONTENT, diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index 7444c9a305..57b8da22c9 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -93,8 +93,10 @@ enum enum { ACTION_OK_REMAP_FILE_SAVE_CORE = 0, + ACTION_OK_REMAP_FILE_SAVE_CONTENT_DIR, ACTION_OK_REMAP_FILE_SAVE_GAME, ACTION_OK_REMAP_FILE_REMOVE_CORE, + ACTION_OK_REMAP_FILE_REMOVE_CONTENT_DIR, ACTION_OK_REMAP_FILE_REMOVE_GAME }; @@ -2309,6 +2311,7 @@ static int generic_action_ok_remap_file_operation(const char *path, { char directory[PATH_MAX_LENGTH]; char file[PATH_MAX_LENGTH]; + char content_dir[PATH_MAX_LENGTH]; settings_t *settings = config_get_ptr(); const char *core_name = NULL; rarch_system_info_t *info = runloop_get_system_info(); @@ -2338,6 +2341,15 @@ static int generic_action_ok_remap_file_operation(const char *path, fill_pathname_join(file, core_name, path_basename(path_get(RARCH_PATH_BASENAME)), sizeof(file)); break; + case ACTION_OK_REMAP_FILE_SAVE_CONTENT_DIR: + case ACTION_OK_REMAP_FILE_REMOVE_CONTENT_DIR: + if (!string_is_empty(core_name)) + { + fill_pathname_parent_dir_name(content_dir, path_get(RARCH_PATH_BASENAME), sizeof(content_dir)); + fill_pathname_join(file, core_name, + content_dir, sizeof(file)); + } + break; } if (!filestream_exists(directory)) @@ -2351,6 +2363,8 @@ static int generic_action_ok_remap_file_operation(const char *path, rarch_ctl(RARCH_CTL_SET_REMAPS_CORE_ACTIVE, NULL); else if (action_type == ACTION_OK_REMAP_FILE_SAVE_GAME) rarch_ctl(RARCH_CTL_SET_REMAPS_GAME_ACTIVE, NULL); + else if (action_type == ACTION_OK_REMAP_FILE_SAVE_CONTENT_DIR) + rarch_ctl(RARCH_CTL_SET_REMAPS_CONTENT_DIR_ACTIVE, NULL); runloop_msg_queue_push( msg_hash_to_str(MSG_REMAP_FILE_SAVED_SUCCESSFULLY), @@ -2379,6 +2393,13 @@ static int generic_action_ok_remap_file_operation(const char *path, input_remapping_set_defaults(true); } + else if (action_type == ACTION_OK_REMAP_FILE_REMOVE_CONTENT_DIR && + rarch_ctl(RARCH_CTL_IS_REMAPS_CONTENT_DIR_ACTIVE, NULL)) + { + rarch_ctl(RARCH_CTL_UNSET_REMAPS_CONTENT_DIR_ACTIVE, NULL); + input_remapping_set_defaults(true); + } + runloop_msg_queue_push( msg_hash_to_str(MSG_REMAP_FILE_REMOVED_SUCCESSFULLY), 1, 100, true); @@ -2398,6 +2419,13 @@ static int action_ok_remap_file_save_core(const char *path, idx, entry_idx, ACTION_OK_REMAP_FILE_SAVE_CORE); } +static int action_ok_remap_file_save_content_dir(const char *path, + const char *label, unsigned type, size_t idx, size_t entry_idx) +{ + return generic_action_ok_remap_file_operation(path, label, type, + idx, entry_idx, ACTION_OK_REMAP_FILE_SAVE_CONTENT_DIR); +} + static int action_ok_remap_file_save_game(const char *path, const char *label, unsigned type, size_t idx, size_t entry_idx) { @@ -2412,6 +2440,13 @@ static int action_ok_remap_file_remove_core(const char *path, idx, entry_idx, ACTION_OK_REMAP_FILE_REMOVE_CORE); } +static int action_ok_remap_file_remove_content_dir(const char *path, + const char *label, unsigned type, size_t idx, size_t entry_idx) +{ + return generic_action_ok_remap_file_operation(path, label, type, + idx, entry_idx, ACTION_OK_REMAP_FILE_REMOVE_CONTENT_DIR); +} + static int action_ok_remap_file_remove_game(const char *path, const char *label, unsigned type, size_t idx, size_t entry_idx) { @@ -4522,12 +4557,18 @@ static int menu_cbs_init_bind_ok_compare_label(menu_file_list_cbs_t *cbs, case MENU_ENUM_LABEL_REMAP_FILE_SAVE_CORE: BIND_ACTION_OK(cbs, action_ok_remap_file_save_core); break; + case MENU_ENUM_LABEL_REMAP_FILE_SAVE_CONTENT_DIR: + BIND_ACTION_OK(cbs, action_ok_remap_file_save_content_dir); + break; case MENU_ENUM_LABEL_REMAP_FILE_SAVE_GAME: BIND_ACTION_OK(cbs, action_ok_remap_file_save_game); break; case MENU_ENUM_LABEL_REMAP_FILE_REMOVE_CORE: BIND_ACTION_OK(cbs, action_ok_remap_file_remove_core); break; + case MENU_ENUM_LABEL_REMAP_FILE_REMOVE_CONTENT_DIR: + BIND_ACTION_OK(cbs, action_ok_remap_file_remove_content_dir); + break; case MENU_ENUM_LABEL_REMAP_FILE_REMOVE_GAME: BIND_ACTION_OK(cbs, action_ok_remap_file_remove_game); break; @@ -4744,6 +4785,9 @@ static int menu_cbs_init_bind_ok_compare_label(menu_file_list_cbs_t *cbs, case MENU_LABEL_REMAP_FILE_SAVE_CORE: BIND_ACTION_OK(cbs, action_ok_remap_file_save_core); break; + case MENU_LABEL_REMAP_FILE_SAVE_CONTENT_DIR: + BIND_ACTION_OK(cbs, action_ok_remap_file_save_content_dir); + break; case MENU_LABEL_REMAP_FILE_SAVE_GAME: BIND_ACTION_OK(cbs, action_ok_remap_file_save_game); break; diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 09e6949427..91c025cd2d 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -3206,6 +3206,11 @@ static int menu_displaylist_parse_options_remappings( msg_hash_to_str(MENU_ENUM_LABEL_REMAP_FILE_SAVE_CORE), MENU_ENUM_LABEL_REMAP_FILE_SAVE_CORE, MENU_SETTING_ACTION, 0, 0); + menu_entries_append_enum(info->list, + msg_hash_to_str(MENU_ENUM_LABEL_VALUE_REMAP_FILE_SAVE_CONTENT_DIR), + msg_hash_to_str(MENU_ENUM_LABEL_REMAP_FILE_SAVE_CONTENT_DIR), + MENU_ENUM_LABEL_REMAP_FILE_SAVE_CONTENT_DIR, + MENU_SETTING_ACTION, 0, 0); menu_entries_append_enum(info->list, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_REMAP_FILE_SAVE_GAME), msg_hash_to_str(MENU_ENUM_LABEL_REMAP_FILE_SAVE_GAME), @@ -3230,6 +3235,15 @@ static int menu_displaylist_parse_options_remappings( MENU_SETTING_ACTION, 0, 0); } + if (rarch_ctl(RARCH_CTL_IS_REMAPS_CONTENT_DIR_ACTIVE, NULL)) + { + menu_entries_append_enum(info->list, + msg_hash_to_str(MENU_ENUM_LABEL_VALUE_REMAP_FILE_REMOVE_CONTENT_DIR), + msg_hash_to_str(MENU_ENUM_LABEL_REMAP_FILE_REMOVE_CONTENT_DIR), + MENU_ENUM_LABEL_REMAP_FILE_REMOVE_CONTENT_DIR, + MENU_SETTING_ACTION, 0, 0); + } + system = runloop_get_system_info(); if (system) diff --git a/msg_hash.h b/msg_hash.h index 35418a1100..b1b18f80e4 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -1548,8 +1548,10 @@ enum msg_hash_enums MENU_ENUM_LABEL_OSK_ENABLE, MENU_LABEL(REMAP_FILE_SAVE_CORE), + MENU_LABEL(REMAP_FILE_SAVE_CONTENT_DIR), MENU_LABEL(REMAP_FILE_SAVE_GAME), MENU_LABEL(REMAP_FILE_REMOVE_CORE), + MENU_LABEL(REMAP_FILE_REMOVE_CONTENT_DIR), MENU_LABEL(REMAP_FILE_REMOVE_GAME), MENU_LABEL(RESTART_CONTENT), MENU_LABEL(RESUME), @@ -2052,6 +2054,7 @@ enum msg_hash_enums #define MENU_LABEL_CUSTOM_BIND_DEFAULTS 0xe88f7b13U #define MENU_LABEL_CONFIGURATIONS 0x3e930a50U #define MENU_LABEL_REMAP_FILE_SAVE_CORE 0x7c9d4c8fU +#define MENU_LABEL_REMAP_FILE_SAVE_CONTENT_DIR 0x7b99c1ffU #define MENU_LABEL_REMAP_FILE_SAVE_GAME 0x7c9f41e0U #define MENU_LABEL_CONTENT_COLLECTION_LIST 0x32d1df83U #define MENU_LABEL_COLLECTION 0x5fea5991U diff --git a/retroarch.c b/retroarch.c index cecf1ddbfd..e26f3128a9 100644 --- a/retroarch.c +++ b/retroarch.c @@ -236,6 +236,7 @@ static bool runloop_perfcnt_enable = false; static bool runloop_overrides_active = false; static bool runloop_remaps_core_active = false; static bool runloop_remaps_game_active = false; +static bool runloop_remaps_content_dir_active = false; static bool runloop_game_options_active = false; static bool runloop_missing_bios = false; static bool runloop_autosave = false; @@ -348,6 +349,7 @@ static void global_free(void) runloop_overrides_active = false; runloop_remaps_core_active = false; runloop_remaps_game_active = false; + runloop_remaps_content_dir_active = false; core_unset_input_descriptors(); @@ -1701,6 +1703,14 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data) break; case RARCH_CTL_IS_REMAPS_GAME_ACTIVE: return runloop_remaps_game_active; + case RARCH_CTL_SET_REMAPS_CONTENT_DIR_ACTIVE: + runloop_remaps_content_dir_active = true; + break; + case RARCH_CTL_UNSET_REMAPS_CONTENT_DIR_ACTIVE: + runloop_remaps_content_dir_active = false; + break; + case RARCH_CTL_IS_REMAPS_CONTENT_DIR_ACTIVE: + return runloop_remaps_content_dir_active; case RARCH_CTL_SET_MISSING_BIOS: runloop_missing_bios = true; break; diff --git a/retroarch.h b/retroarch.h index 02abfae515..1635c83de8 100644 --- a/retroarch.h +++ b/retroarch.h @@ -100,6 +100,10 @@ enum rarch_ctl_state RARCH_CTL_SET_REMAPS_CORE_ACTIVE, RARCH_CTL_UNSET_REMAPS_CORE_ACTIVE, + RARCH_CTL_IS_REMAPS_CONTENT_DIR_ACTIVE, + RARCH_CTL_SET_REMAPS_CONTENT_DIR_ACTIVE, + RARCH_CTL_UNSET_REMAPS_CONTENT_DIR_ACTIVE, + RARCH_CTL_IS_REMAPS_GAME_ACTIVE, RARCH_CTL_SET_REMAPS_GAME_ACTIVE, RARCH_CTL_UNSET_REMAPS_GAME_ACTIVE,