Merge pull request #17776 from zoltanvb/delete_core_options

Enable core options reset without starting a core.
This commit is contained in:
LibretroAdmin 2025-04-07 16:02:50 -07:00 committed by GitHub
commit 7ff7e49f56
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 76 additions and 14 deletions

View File

@ -9464,11 +9464,11 @@ MSG_HASH(
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_CORE_OPTIONS_RESET,
"Reset Options"
"Reset Core Options"
)
MSG_HASH(
MENU_ENUM_SUBLABEL_CORE_OPTIONS_RESET,
"Set all core options to default values."
"Set all options of the current core to default values."
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_CORE_OPTIONS_FLUSH,

View File

@ -5655,7 +5655,7 @@ static int action_ok_folder_specific_core_options_remove(const char *path,
static int action_ok_core_options_reset(const char *path,
const char *label, unsigned type, size_t idx, size_t entry_idx)
{
core_options_reset();
core_options_reset(label);
return 0;
}

View File

@ -1021,6 +1021,14 @@ end:
MENU_SETTING_ACTION_CORE_DELETE, 0, 0, NULL))
count++;
#endif
/* Reset core options */
if (menu_entries_append(list,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_CORE_OPTIONS_RESET),
core_info->core_name,
MENU_ENUM_LABEL_CORE_OPTIONS_RESET,
MENU_SETTING_ACTION_CORE_OPTIONS_RESET, 0, 0, NULL))
count++;
}
#endif
}
@ -1471,7 +1479,7 @@ end:
/* Reset core options */
if (menu_entries_append(list,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_CORE_OPTIONS_RESET),
msg_hash_to_str(MENU_ENUM_LABEL_CORE_OPTIONS_RESET),
"",
MENU_ENUM_LABEL_CORE_OPTIONS_RESET,
MENU_SETTING_ACTION_CORE_OPTIONS_RESET, 0, 0, NULL))
count++;
@ -11317,6 +11325,13 @@ unsigned menu_displaylist_build_list(
false) == 0)
count++;
}
/* Reset core options */
if (!settings->bools.global_core_options && menu_entries_append(list,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_CORE_OPTIONS_RESET),
"",
MENU_ENUM_LABEL_CORE_OPTIONS_RESET,
MENU_SETTING_ACTION_CORE_OPTIONS_RESET, 0, 0, NULL))
count++;
}
break;
case DISPLAYLIST_DIRECTORY_SETTINGS_LIST:

View File

@ -195,7 +195,7 @@ void retroarch_init_task_queue(void);
/* Creates folder and core options stub file for subsequent runs */
bool core_options_create_override(bool game_specific);
bool core_options_remove_override(bool game_specific);
void core_options_reset(void);
void core_options_reset(const char *label);
void core_options_flush(void);
/**

View File

@ -5141,25 +5141,72 @@ error:
return false;
}
void core_options_reset(void)
void core_options_reset(const char* label)
{
size_t i;
runloop_state_t *runloop_st = &runloop_state;
core_option_manager_t *coreopts = runloop_st->core_options;
/* If there are no core options, there
* is nothing to do */
if (!coreopts || (coreopts->size < 1))
/* If there are no loaded core options, or the menu entry
* was indicating a reset for a specific core instead,
* do a "cold reset" (deletion of options file) */
if (!coreopts || !string_is_empty(label))
{
settings_t *settings = config_get_ptr();
const char *core_name = label;
char per_core_options_path[PATH_MAX_LENGTH];
RARCH_DBG("[Core]: Core options cold reset, label from menu entry \"%s\", loaded core \"%s\".\n",
label, runloop_st->system.info.library_name);
if (string_is_empty(label))
core_name = runloop_st->system.info.library_name;
if (settings->bools.global_core_options)
{
RARCH_WARN("[Core]: Core options cold reset is not supported when global core options are used, deletion skipped.\n");
return;
}
/* Get current options file path */
per_core_options_path[0] = '\0';
validate_per_core_options(
per_core_options_path, sizeof(per_core_options_path), true,
core_name, core_name);
if (string_is_empty(per_core_options_path))
{
RARCH_ERR("[Core]: Core options file could not be located, deletion skipped.\n");
return;
}
/* Remove current options file, if possible */
if (path_is_valid(per_core_options_path))
{
RARCH_WARN("[Core]: Deleting core options file: \"%s\".\n", per_core_options_path);
filestream_delete(per_core_options_path);
}
else
{
RARCH_ERR("[Core]: Core options file path is not valid, deletion skipped: \"%s\".\n", per_core_options_path);
return;
}
}
else if (coreopts->size < 1)
{
RARCH_WARN("[Core]: Core options reset invoked but there are no options.\n");
return;
}
else
{
for (i = 0; i < coreopts->size; i++)
coreopts->opts[i].index = coreopts->opts[i].default_index;
for (i = 0; i < coreopts->size; i++)
coreopts->opts[i].index = coreopts->opts[i].default_index;
coreopts->updated = true;
coreopts->updated = true;
#ifdef HAVE_CHEEVOS
rcheevos_validate_config_settings();
rcheevos_validate_config_settings();
#endif
}
{
const char *_msg = msg_hash_to_str(MSG_CORE_OPTIONS_RESET);