mirror of
https://github.com/libretro/RetroArch
synced 2025-02-19 12:41:00 +00:00
allow saving of per-game core options
This commit is contained in:
parent
5ef592b59a
commit
9f99bef9f2
@ -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
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user