From 9f99bef9f2ba57590f6d4f807a531972f6687993 Mon Sep 17 00:00:00 2001 From: radius Date: Sun, 15 Nov 2015 22:09:39 -0500 Subject: [PATCH] allow saving of per-game core options --- core_options.c | 24 +++++++++++++++++ core_options.h | 12 +++++++++ menu/cbs/menu_cbs_get_value.c | 9 +++++++ menu/cbs/menu_cbs_ok.c | 49 +++++++++++++++++++++++++++++++++++ menu/intl/menu_hash_us.c | 2 ++ menu/menu.h | 2 ++ menu/menu_displaylist.c | 4 +-- menu/menu_hash.h | 1 + 8 files changed, 101 insertions(+), 2 deletions(-) diff --git a/core_options.c b/core_options.c index 9df1aea179..15ba5e63d4 100644 --- a/core_options.c +++ b/core_options.c @@ -237,6 +237,30 @@ bool core_option_flush(core_option_manager_t *opt) return config_file_write(opt->conf, opt->conf_path); } +/** + * core_option_flush_game_specific: + * @opt : options manager handle + * @path : path for the core options file + * + * Writes core option key-pair values to a custom file. + * + * Returns: true (1) if core option values could be + * successfully saved to disk, otherwise false (0). + **/ +bool core_option_flush_game_specific(core_option_manager_t *opt, char* path) +{ + size_t i; + for (i = 0; i < opt->size; i++) + { + struct core_option *option = (struct core_option*)&opt->opts[i]; + + if (option) + config_set_string(opt->conf, option->key, core_option_get_val(opt, i)); +} + + return config_file_write(opt->conf, path); +} + /** * core_option_size: * @opt : options manager handle diff --git a/core_options.h b/core_options.h index 06f8ef28ff..7923bd3a4e 100644 --- a/core_options.h +++ b/core_options.h @@ -62,6 +62,18 @@ bool core_option_updated(core_option_manager_t *opt); **/ bool core_option_flush(core_option_manager_t *opt); +/** + * core_option_flush_game_specific: + * @opt : options manager handle + * @path : path for the core options file + * + * Writes core option key-pair values to a custom file. + * + * Returns: true (1) if core option values could be + * successfully saved to disk, otherwise false (0). + **/ +bool core_option_flush_game_specific(core_option_manager_t *opt, char* path); + /** * core_option_free: * @opt : options manager handle diff --git a/menu/cbs/menu_cbs_get_value.c b/menu/cbs/menu_cbs_get_value.c index 054b413554..e259e8a5ef 100644 --- a/menu/cbs/menu_cbs_get_value.c +++ b/menu/cbs/menu_cbs_get_value.c @@ -958,6 +958,7 @@ static void menu_action_setting_disp_set_label(file_list_t* list, { rarch_system_info_t *system = rarch_system_info_get_ptr(); uint32_t hash_label = menu_hash_calculate(label); + global_t *global = global_get_ptr(); *s = '\0'; *w = 19; @@ -1029,6 +1030,14 @@ static void menu_action_setting_disp_set_label(file_list_t* list, strlcpy(s, core_opt ? core_opt : "", len); } + else if (type >= MENU_SETTINGS_CORE_OPTION_CREATE) + { + const char *core_opt = NULL; + if (!system) + return; + + strlcpy(s, global->name.base ? path_basename(global->name.base) : "", len); + } else menu_setting_get_label(list, s, len, w, type, label, entry_label, i); diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index 3ce5cf008f..480e758d02 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -1246,6 +1246,52 @@ static int action_ok_disk_cycle_tray_status(const char *path, return generic_action_ok_command(EVENT_CMD_DISK_EJECT_TOGGLE); } +static int action_ok_option_create(const char *path, + const char *label, unsigned type, size_t idx, size_t entry_idx) +{ + /* create folder and core options stub file for subsequent runs */ + settings_t *settings = config_get_ptr(); + global_t *global = global_get_ptr(); + rarch_system_info_t *system = rarch_system_info_get_ptr(); + + const char *core_name = NULL; + const char *game_name = NULL; + config_file_t *option_file = NULL; + char game_path[PATH_MAX_LENGTH] = {0}; + char config_directory[PATH_MAX_LENGTH] = {0}; + char msg[PATH_MAX_LENGTH] = {0}; + + /* Config directory: config_directory. + * Try config directory setting first, + * fallback to the location of the current configuration file. */ + if (settings->menu_config_directory[0] != '\0') + strlcpy(config_directory, settings->menu_config_directory, PATH_MAX_LENGTH); + else if (global->path.config[0] != '\0') + fill_pathname_basedir(config_directory, global->path.config, PATH_MAX_LENGTH); + else + { + RARCH_WARN("Per-game Options: no config directory set\n"); + return false; + } + + core_name = system->info.library_name; + game_name = path_basename(global->name.base); + + /* Concatenate strings into full paths for game_path */ + fill_pathname_join(game_path, config_directory, core_name, PATH_MAX_LENGTH); + fill_pathname_join(game_path, game_path, game_name, PATH_MAX_LENGTH); + strlcat(game_path, ".opt", PATH_MAX_LENGTH); + + const struct retro_variable *vars; + + if(core_option_flush_game_specific(system->core_options,game_path)) + menu_display_msg_queue_push("Core options file saved successfully", 1, 100, true); + else + menu_display_msg_queue_push("Error saving core options file", 1, 100, true); + return 0; +} + + static int action_ok_close_content(const char *path, const char *label, unsigned type, size_t idx, size_t entry_idx) { @@ -2316,6 +2362,9 @@ static int menu_cbs_init_bind_ok_compare_type(menu_file_list_cbs_t *cbs, case MENU_SETTINGS_CORE_DISK_OPTIONS_DISK_CYCLE_TRAY_STATUS: BIND_ACTION_OK(cbs, action_ok_disk_cycle_tray_status); break; + case MENU_SETTINGS_CORE_OPTION_CREATE: + BIND_ACTION_OK(cbs, action_ok_option_create); + break; default: return -1; } diff --git a/menu/intl/menu_hash_us.c b/menu/intl/menu_hash_us.c index 0a9afa9850..ddeb048bbf 100644 --- a/menu/intl/menu_hash_us.c +++ b/menu/intl/menu_hash_us.c @@ -1028,6 +1028,8 @@ const char *menu_hash_to_str_us(uint32_t hash) return "Configuration Per-Core"; case MENU_LABEL_VALUE_GAME_SPECIFIC_OPTIONS: return "Use per-game core options if available"; + case MENU_LABEL_VALUE_GAME_SPECIFIC_OPTIONS_CREATE: + return "Create game-options file"; case MENU_LABEL_VALUE_AUTO_OVERRIDES_ENABLE: return "Load Override Files Automatically"; case MENU_LABEL_VALUE_CONFIG_SAVE_ON_EXIT: diff --git a/menu/menu.h b/menu/menu.h index 7bb42f835e..dd406e54bd 100644 --- a/menu/menu.h +++ b/menu/menu.h @@ -53,10 +53,12 @@ #define MENU_SETTINGS_CORE_INFO_NONE 0xffff #define MENU_SETTINGS_CORE_OPTION_NONE 0xffff #define MENU_SETTINGS_CHEEVOS_NONE 0xffff +#define MENU_SETTINGS_CORE_OPTION_CREATE 0x05000 #define MENU_SETTINGS_CORE_OPTION_START 0x10000 #define MENU_SETTINGS_PLAYLIST_ASSOCIATION_START 0x20000 #define MENU_SETTINGS_CHEEVOS_START 0x40000 + #define MENU_KEYBOARD_BIND_TIMEOUT_SECONDS 5 #ifdef __cplusplus diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 0c05250240..f969456b80 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -3003,8 +3003,8 @@ int menu_displaylist_push_list(menu_displaylist_info_t *info, unsigned type) if (settings->game_specific_options) { menu_entries_push(info->list, - menu_hash_to_str(MENU_LABEL_VALUE_NO_CORE_OPTIONS_AVAILABLE), "", - MENU_SETTINGS_CORE_OPTION_NONE, 0, 0); + menu_hash_to_str(MENU_LABEL_VALUE_GAME_SPECIFIC_OPTIONS_CREATE), "", + MENU_SETTINGS_CORE_OPTION_CREATE, 0, 0); } if (opts == 0) { diff --git a/menu/menu_hash.h b/menu/menu_hash.h index a17e8ec559..e87f42e12e 100644 --- a/menu/menu_hash.h +++ b/menu/menu_hash.h @@ -306,6 +306,7 @@ extern "C" { #define MENU_LABEL_VALUE_CORE_SPECIFIC_CONFIG 0x8b8bec5aU #define MENU_LABEL_GAME_SPECIFIC_OPTIONS 0x142ec90fU #define MENU_LABEL_VALUE_GAME_SPECIFIC_OPTIONS 0x6aed8a05U +#define MENU_LABEL_VALUE_GAME_SPECIFIC_OPTIONS_CREATE 0xf8d2456cU #define MENU_LABEL_AUTO_OVERRIDES_ENABLE 0x35ff91b6U #define MENU_LABEL_VALUE_AUTO_OVERRIDES_ENABLE 0xc21c3a11U #define MENU_LABEL_AUTO_REMAPS_ENABLE 0x98c8f98bU