Add option to selectively 'lock' (prevent modification of) installed cores

This commit is contained in:
jdgleaver 2020-06-18 17:08:57 +01:00
parent 4ed7ad8465
commit 80f36e16d0
20 changed files with 674 additions and 56 deletions

View file

@ -36,6 +36,7 @@
#include "../../managers/core_option_manager.h"
#include "../../managers/cheat_manager.h"
#include "../../retroarch.h"
#include "../../verbosity.h"
#include "../../performance_counters.h"
#include "../../playlist.h"
#include "../../manual_content_scan.h"
@ -495,6 +496,70 @@ static int action_start_core_updater_entry(
}
#endif
static int action_start_core_lock(
const char *path, const char *label,
unsigned type, size_t idx, size_t entry_idx)
{
const char *core_path = path;
bool refresh = false;
int ret = 0;
if (string_is_empty(core_path))
return -1;
/* Core should be unlocked by default
* > If it is currently unlocked, do nothing */
if (!core_info_get_core_lock(core_path, true))
return ret;
/* ...Otherwise, attempt to unlock it */
if (!core_info_set_core_lock(core_path, false))
{
const char *core_name = NULL;
core_info_ctx_find_t core_info;
char msg[PATH_MAX_LENGTH];
msg[0] = '\0';
/* Need to fetch core name for error message */
core_info.inf = NULL;
core_info.path = core_path;
/* If core is found, use display name */
if (core_info_find(&core_info) &&
core_info.inf->display_name)
core_name = core_info.inf->display_name;
/* If not, use core file name */
else
core_name = path_basename(core_path);
/* Build error message */
strlcpy(msg, msg_hash_to_str(MSG_CORE_UNLOCK_FAILED), sizeof(msg));
if (!string_is_empty(core_name))
strlcat(msg, core_name, sizeof(msg));
/* Generate log + notification */
RARCH_ERR("%s\n", msg);
runloop_msg_queue_push(
msg,
1, 100, true,
NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
ret = -1;
}
/* Whenever lock status is changed, menu must be
* refreshed - do this even in the event of an error,
* since we don't want to leave the menu in an
* undefined state */
menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh);
menu_driver_ctl(RARCH_MENU_CTL_SET_PREVENT_POPULATE, NULL);
return ret;
}
static int action_start_lookup_setting(
const char *path, const char *label,
unsigned type, size_t idx, size_t entry_idx)
@ -636,6 +701,9 @@ static int menu_cbs_init_bind_start_compare_type(menu_file_list_cbs_t *cbs,
BIND_ACTION_START(cbs, action_start_core_updater_entry);
break;
#endif
case MENU_SETTING_ACTION_CORE_LOCK:
BIND_ACTION_START(cbs, action_start_core_lock);
break;
default:
return -1;
}