Disable per-game and per-content-directory remaps when running contentless cores (#13687)

This commit is contained in:
jdgleaver 2022-03-01 08:45:17 +00:00 committed by GitHub
parent e8e8404741
commit 4c87c307cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 68 additions and 56 deletions

View File

@ -4024,9 +4024,7 @@ bool config_unload_override(void)
bool config_load_remap(const char *directory_input_remapping,
void *data)
{
char content_dir_name[PATH_MAX_LENGTH] = { 0 };
/* path to the directory containing retroarch.cfg (prefix) */
char remap_directory[PATH_MAX_LENGTH];
char content_dir_name[PATH_MAX_LENGTH];
/* final path for core-specific configuration (prefix+suffix) */
char core_path[PATH_MAX_LENGTH];
/* final path for game-specific configuration (prefix+suffix) */
@ -4037,52 +4035,56 @@ bool config_load_remap(const char *directory_input_remapping,
rarch_system_info_t *system = (rarch_system_info_t*)data;
const char *core_name = system ? system->info.library_name : NULL;
const char *rarch_path_basename = path_get(RARCH_PATH_BASENAME);
const char *game_name = path_basename(rarch_path_basename);
const char *game_name = NULL;
bool has_content = !string_is_empty(rarch_path_basename);
enum msg_hash_enums msg_remap_loaded = MSG_GAME_REMAP_FILE_LOADED;
settings_t *settings = config_st;
bool notification_show_remap_load = settings->bools.notification_show_remap_load;
if (string_is_empty(core_name))
content_dir_name[0] = '\0';
core_path[0] = '\0';
game_path[0] = '\0';
content_path[0] = '\0';
/* > Cannot load remaps if we have no core
* > Cannot load remaps if remap directory is unset */
if (string_is_empty(core_name) ||
string_is_empty(directory_input_remapping))
return false;
/* Remap directory: remap_directory.
* Try remap directory setting, no fallbacks defined */
if (string_is_empty(directory_input_remapping))
return false;
RARCH_LOG("[Remaps]: Remap directory: \"%s\".\n", directory_input_remapping);
if (!string_is_empty(rarch_path_basename))
/* Concatenate strings into full paths for core_path,
* game_path, content_path */
if (has_content)
{
fill_pathname_parent_dir_name(content_dir_name,
rarch_path_basename, sizeof(content_dir_name));
game_name = path_basename(rarch_path_basename);
remap_directory[0] = core_path[0] = game_path[0] = '\0';
fill_pathname_join_special_ext(game_path,
directory_input_remapping, core_name,
game_name,
FILE_PATH_REMAP_EXTENSION,
sizeof(game_path));
strlcpy(remap_directory,
directory_input_remapping, sizeof(remap_directory));
RARCH_LOG("[Remaps]: Remap directory: \"%s\".\n", remap_directory);
fill_pathname_join_special_ext(content_path,
directory_input_remapping, core_name,
content_dir_name,
FILE_PATH_REMAP_EXTENSION,
sizeof(content_path));
}
/* Concatenate strings into full paths for core_path, game_path */
fill_pathname_join_special_ext(core_path,
remap_directory, core_name,
directory_input_remapping, core_name,
core_name,
FILE_PATH_REMAP_EXTENSION,
sizeof(core_path));
fill_pathname_join_special_ext(content_path,
remap_directory, core_name,
content_dir_name,
FILE_PATH_REMAP_EXTENSION,
sizeof(content_path));
fill_pathname_join_special_ext(game_path,
remap_directory, core_name,
game_name,
FILE_PATH_REMAP_EXTENSION,
sizeof(game_path));
input_remapping_set_defaults(false);
/* If a game remap file exists, load it. */
if ((new_conf = config_file_new_from_path_to_string(game_path)))
if (has_content && (new_conf = config_file_new_from_path_to_string(game_path)))
{
bool ret = input_remapping_load_file(new_conf, game_path);
config_file_free(new_conf);
@ -4098,7 +4100,7 @@ bool config_load_remap(const char *directory_input_remapping,
}
/* If a content-dir remap file exists, load it. */
if ((new_conf = config_file_new_from_path_to_string(content_path)))
if (has_content && (new_conf = config_file_new_from_path_to_string(content_path)))
{
bool ret = input_remapping_load_file(new_conf, content_path);
config_file_free(new_conf);

View File

@ -3407,50 +3407,59 @@ static int generic_action_ok_remap_file_operation(const char *path,
char content_dir[PATH_MAX_LENGTH];
struct retro_system_info *system = &runloop_state_get_ptr()->system.info;
const char *core_name = system ? system->library_name : NULL;
const char *rarch_path_basename = path_get(RARCH_PATH_BASENAME);
bool has_content = !string_is_empty(rarch_path_basename);
settings_t *settings = config_get_ptr();
const char *path_dir_input_remapping = settings->paths.directory_input_remapping;
directory[0] = file[0] = '\0';
directory[0] = '\0';
file[0] = '\0';
content_dir[0] = '\0';
if (!string_is_empty(core_name))
fill_pathname_join(
directory,
path_dir_input_remapping,
core_name,
sizeof(directory));
/* Cannot perform remap file operation if we
* have no core */
if (string_is_empty(core_name))
return menu_cbs_exit();
/* Get base remap file directory */
fill_pathname_join(
directory,
path_dir_input_remapping,
core_name,
sizeof(directory));
if (!path_is_directory(directory))
path_mkdir(directory);
switch (action_type)
{
case ACTION_OK_REMAP_FILE_SAVE_CORE:
case ACTION_OK_REMAP_FILE_REMOVE_CORE:
if (!string_is_empty(core_name))
fill_pathname_join(file, core_name, core_name, sizeof(file));
fill_pathname_join(file, core_name, core_name, sizeof(file));
break;
case ACTION_OK_REMAP_FILE_SAVE_GAME:
case ACTION_OK_REMAP_FILE_REMOVE_GAME:
if (!string_is_empty(core_name))
if (has_content)
fill_pathname_join(file, core_name,
path_basename(path_get(RARCH_PATH_BASENAME)), sizeof(file));
path_basename(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))
if (has_content)
{
fill_pathname_parent_dir_name(content_dir, path_get(RARCH_PATH_BASENAME), sizeof(content_dir));
fill_pathname_parent_dir_name(content_dir,
rarch_path_basename, sizeof(content_dir));
fill_pathname_join(file, core_name,
content_dir, sizeof(file));
}
break;
}
if (!path_is_directory(directory))
path_mkdir(directory);
if (action_type < ACTION_OK_REMAP_FILE_REMOVE_CORE)
{
if (input_remapping_save_file(file))
if (!string_is_empty(file) &&
input_remapping_save_file(file))
{
#ifdef HAVE_CONFIGFILE
switch (action_type)
{
case ACTION_OK_REMAP_FILE_SAVE_CORE:
@ -3463,7 +3472,6 @@ static int generic_action_ok_remap_file_operation(const char *path,
retroarch_ctl(RARCH_CTL_SET_REMAPS_CONTENT_DIR_ACTIVE, NULL);
break;
}
#endif
runloop_msg_queue_push(
msg_hash_to_str(MSG_REMAP_FILE_SAVED_SUCCESSFULLY),
@ -3478,7 +3486,8 @@ static int generic_action_ok_remap_file_operation(const char *path,
}
else
{
if (input_remapping_remove_file(file, path_dir_input_remapping))
if (!string_is_empty(file) &&
input_remapping_remove_file(file, path_dir_input_remapping))
{
switch (action_type)
{

View File

@ -6279,9 +6279,11 @@ unsigned menu_displaylist_build_list(
case DISPLAYLIST_OPTIONS_REMAPPINGS:
{
unsigned p;
unsigned max_users = settings->uints.input_max_users;
unsigned max_users = settings->uints.input_max_users;
#ifdef HAVE_CONFIGFILE
bool has_content = !string_is_empty(path_get(RARCH_PATH_CONTENT));
if (menu_entries_append_enum(list,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_REMAP_FILE_LOAD),
msg_hash_to_str(MENU_ENUM_LABEL_REMAP_FILE_LOAD),
@ -6294,13 +6296,13 @@ unsigned menu_displaylist_build_list(
MENU_ENUM_LABEL_REMAP_FILE_SAVE_CORE,
MENU_SETTING_ACTION, 0, 0))
count++;
if (menu_entries_append_enum(list,
if (has_content && menu_entries_append_enum(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))
count++;
if (menu_entries_append_enum(list,
if (has_content && menu_entries_append_enum(list,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_REMAP_FILE_SAVE_GAME),
msg_hash_to_str(MENU_ENUM_LABEL_REMAP_FILE_SAVE_GAME),
MENU_ENUM_LABEL_REMAP_FILE_SAVE_GAME,
@ -6315,7 +6317,7 @@ unsigned menu_displaylist_build_list(
MENU_SETTING_ACTION, 0, 0))
count++;
if (retroarch_ctl(RARCH_CTL_IS_REMAPS_GAME_ACTIVE, NULL))
if (has_content && retroarch_ctl(RARCH_CTL_IS_REMAPS_GAME_ACTIVE, NULL))
if (menu_entries_append_enum(list,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_REMAP_FILE_REMOVE_GAME),
msg_hash_to_str(MENU_ENUM_LABEL_REMAP_FILE_REMOVE_GAME),
@ -6323,7 +6325,7 @@ unsigned menu_displaylist_build_list(
MENU_SETTING_ACTION, 0, 0))
count++;
if (retroarch_ctl(RARCH_CTL_IS_REMAPS_CONTENT_DIR_ACTIVE, NULL))
if (has_content && retroarch_ctl(RARCH_CTL_IS_REMAPS_CONTENT_DIR_ACTIVE, NULL))
if (menu_entries_append_enum(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),
@ -6331,7 +6333,6 @@ unsigned menu_displaylist_build_list(
MENU_SETTING_ACTION, 0, 0))
count++;
#endif
if (menu_entries_append_enum(list,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_TURBO_FIRE_SETTINGS),
msg_hash_to_str(MENU_ENUM_LABEL_INPUT_TURBO_FIRE_SETTINGS),