mirror of
https://github.com/libretro/RetroArch.git
synced 2025-02-23 03:02:04 +00:00
Merge pull request #1595 from fr500/master
Override and remap improvements
This commit is contained in:
commit
136720a4c0
167
configuration.c
167
configuration.c
@ -1642,7 +1642,7 @@ static void config_load_core_specific(void)
|
||||
* core-specific: $CONFIG_DIR/$CORE_NAME/$CORE_NAME.cfg fallback: $CURRENT_CFG_LOCATION/$CORE_NAME/$CORE_NAME.cfg
|
||||
* game-specific: $CONFIG_DIR/$CORE_NAME/$ROM_NAME.cfg fallback: $CURRENT_CFG_LOCATION/$CORE_NAME/$GAME_NAME.cfg
|
||||
*
|
||||
* Returns: false if there was an error.
|
||||
* Returns: false if there was an error or no action was performed.
|
||||
*
|
||||
*/
|
||||
bool config_load_override(void)
|
||||
@ -1651,8 +1651,16 @@ bool config_load_override(void)
|
||||
core_path[PATH_MAX_LENGTH], /* final path for core-specific configuration (prefix+suffix) */
|
||||
game_path[PATH_MAX_LENGTH]; /* final path for game-specific configuration (prefix+suffix) */
|
||||
const char *core_name, *game_name; /* suffix */
|
||||
global_t *global = global_get_ptr(); /* global pointer */
|
||||
settings_t *settings = config_get_ptr(); /* config pointer */
|
||||
|
||||
global_t *global = global_get_ptr();
|
||||
settings_t *settings = config_get_ptr();
|
||||
|
||||
//early return in case a library isn't loaded
|
||||
if(!global->system.info.library_name || !strcmp(global->system.info.library_name,"No Core"))
|
||||
return false;
|
||||
|
||||
RARCH_LOG("Game name: %s\n",global->basename);
|
||||
RARCH_LOG("Core name: %s\n",global->system.info.library_name);
|
||||
|
||||
if (!global || !settings )
|
||||
{
|
||||
@ -1660,38 +1668,23 @@ bool config_load_override(void)
|
||||
return false;
|
||||
}
|
||||
|
||||
//early return in case a library isn't loaded
|
||||
if (!global->system.info.library_name || !strcmp(global->system.info.library_name,"No Core"))
|
||||
{
|
||||
RARCH_LOG("No library loaded, not using overrides.\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
RARCH_LOG("Game name: %s\n",global->basename);
|
||||
RARCH_LOG("Core name: %s\n",global->system.info.library_name);
|
||||
|
||||
/* Config directory: config_directory. */
|
||||
if (settings->menu_config_directory) /* Try RGUI path setting first */
|
||||
// Config directory: config_directory.
|
||||
// Try config directory setting first, fallback to the location of the current configuration file
|
||||
if (settings->menu_config_directory)
|
||||
strlcpy(config_directory, settings->menu_config_directory, PATH_MAX_LENGTH);
|
||||
else if (global->config_path) /* If that setting is default, use the directory that retroarch.cfg is in */
|
||||
else if (global->config_path)
|
||||
fill_pathname_basedir(config_directory, global->config_path, PATH_MAX_LENGTH);
|
||||
else
|
||||
{
|
||||
RARCH_WARN("No config directory set under Settings > Path and retroarch.cfg not found.\n");
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
RARCH_LOG("Config directory: %s\n", config_directory);
|
||||
|
||||
/* Core name: core_name
|
||||
* i.e. Mupen64plus */
|
||||
core_name = global->system.info.library_name;
|
||||
game_name = path_basename(global->basename);
|
||||
|
||||
/* ROM basename: game_name
|
||||
* no extension or leading directory i.e. "Super Mario 64 (USA)" */
|
||||
game_name = path_basename(global->basename);
|
||||
|
||||
/* Concat strings into full paths: core_path, game_path */
|
||||
// Concatenate strings into full paths for core_path, game_path
|
||||
fill_pathname_join(core_path, config_directory, core_name, PATH_MAX_LENGTH);
|
||||
fill_pathname_join(core_path, core_path, core_name, PATH_MAX_LENGTH);
|
||||
strlcat(core_path, ".cfg", PATH_MAX_LENGTH);
|
||||
@ -1700,30 +1693,31 @@ bool config_load_override(void)
|
||||
fill_pathname_join(game_path, game_path, game_name, PATH_MAX_LENGTH);
|
||||
strlcat(game_path, ".cfg", PATH_MAX_LENGTH);
|
||||
|
||||
/* Create a new config file from core_path */
|
||||
// Create a new config file from core_path
|
||||
config_file_t *new_conf = config_file_new(core_path);
|
||||
|
||||
bool should_append = false;
|
||||
|
||||
/* Append core-specific */
|
||||
// If a core override exists, add it's location to append_config_path
|
||||
if (new_conf)
|
||||
{
|
||||
RARCH_LOG("Core-specific configuration found at %s. Appending.\n", core_path);
|
||||
RARCH_LOG("Core-specific overrides found at %s. Appending.\n", core_path);
|
||||
strlcpy(global->append_config_path, core_path, sizeof(global->append_config_path));
|
||||
should_append = true;
|
||||
}
|
||||
else
|
||||
RARCH_LOG("No core-specific configuration found at %s.\n", core_path);
|
||||
RARCH_LOG("No core-specific overrides found at %s.\n", core_path);
|
||||
|
||||
new_conf = NULL;
|
||||
|
||||
/* Create a new config file from game_path */
|
||||
// Create a new config file from game_path
|
||||
new_conf = config_file_new(game_path);
|
||||
|
||||
/* Append game-specific */
|
||||
// If a game override exists, add it's location to append_config_path
|
||||
if (new_conf)
|
||||
{
|
||||
if (should_append)
|
||||
RARCH_LOG("Game-specific overrides found at %s. Appending.\n", game_path);
|
||||
if(should_append)
|
||||
{
|
||||
strlcat(global->append_config_path, "|", sizeof(global->append_config_path));
|
||||
strlcat(global->append_config_path, game_path, sizeof(global->append_config_path));
|
||||
@ -1731,16 +1725,42 @@ bool config_load_override(void)
|
||||
else
|
||||
strlcpy(global->append_config_path, game_path, sizeof(global->append_config_path));
|
||||
|
||||
RARCH_LOG("Game-specific configuration found at %s. Appending.\n", game_path);
|
||||
should_append = true;
|
||||
}
|
||||
else
|
||||
RARCH_LOG("No game-specific configuration found at %s.\n", game_path);
|
||||
RARCH_LOG("No game-specific overrides found at %s.\n", game_path);
|
||||
|
||||
if (should_append && !config_load_file(global->config_path, false))
|
||||
// Re-load the configuration with any overrides that might have been found
|
||||
if(should_append)
|
||||
{
|
||||
if(config_load_file(global->config_path, false))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* config_unload_override:
|
||||
*
|
||||
* Unloads configuration overrides if overrides are active.
|
||||
*
|
||||
*
|
||||
* Returns: false if there was an error.
|
||||
*/
|
||||
bool config_unload_override(void)
|
||||
{
|
||||
global_t *global = global_get_ptr();
|
||||
settings_t *settings = config_get_ptr();
|
||||
|
||||
*global->append_config_path = NULL;
|
||||
if (config_load_file(global->config_path, false))
|
||||
{
|
||||
RARCH_LOG("Configuration overrides unloaded, original configuration reset\n");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
return true; /* only means no errors were caught */
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1754,7 +1774,7 @@ bool config_load_override(void)
|
||||
* core-specific: $REMAP_DIR/$CORE_NAME/$CORE_NAME.cfg
|
||||
* game-specific: $REMAP_DIR/$CORE_NAME/$GAME_NAME.cfg
|
||||
*
|
||||
* Returns: false if there was an error.
|
||||
* Returns: false if there was an error or no action was performed.
|
||||
*/
|
||||
bool config_load_remap(void)
|
||||
{
|
||||
@ -1767,31 +1787,26 @@ bool config_load_remap(void)
|
||||
|
||||
//early return in case a library isn't loaded or remapping is disabled
|
||||
if(!global->system.info.library_name || !strcmp(global->system.info.library_name,"No Core"))
|
||||
return true;
|
||||
return false;
|
||||
|
||||
RARCH_LOG("Game name: %s\n",global->basename);
|
||||
RARCH_LOG("Core name: %s\n",global->system.info.library_name);
|
||||
|
||||
/* Config directory: remap_directory. */
|
||||
if (settings->input_remapping_directory) /* Try config file path setting first */
|
||||
// Remap directory: remap_directory.
|
||||
// Try remap directory setting, no fallbacks defined
|
||||
if (settings->input_remapping_directory)
|
||||
strlcpy(remap_directory, settings->input_remapping_directory, PATH_MAX_LENGTH);
|
||||
else
|
||||
{
|
||||
RARCH_WARN("No remap directory set.\n");
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
RARCH_LOG("Remap directory: %s\n", remap_directory);
|
||||
|
||||
/* Core name: core_name
|
||||
* i.e. Mupen64plus */
|
||||
core_name = global->system.info.library_name;
|
||||
game_name = path_basename(global->basename);
|
||||
|
||||
/* ROM basename: game_name
|
||||
* no extension or leading directory i.e. "Super Mario 64 (USA)" */
|
||||
game_name = path_basename(global->basename);
|
||||
|
||||
/* Concat strings into full paths: core_path, game_path */
|
||||
// Concatenate strings into full paths for core_path, game_path
|
||||
fill_pathname_join(core_path, remap_directory, core_name, PATH_MAX_LENGTH);
|
||||
fill_pathname_join(core_path, core_path, core_name, PATH_MAX_LENGTH);
|
||||
strlcat(core_path, ".rmp", PATH_MAX_LENGTH);
|
||||
@ -1800,35 +1815,46 @@ bool config_load_remap(void)
|
||||
fill_pathname_join(game_path, game_path, game_name, PATH_MAX_LENGTH);
|
||||
strlcat(game_path, ".rmp", PATH_MAX_LENGTH);
|
||||
|
||||
/* Create a new config file from core_path */
|
||||
config_file_t *new_conf = config_file_new(core_path);
|
||||
// Create a new config file from game_path
|
||||
config_file_t * new_conf = config_file_new(game_path);
|
||||
|
||||
/* Append core-specific */
|
||||
if (new_conf)
|
||||
{
|
||||
RARCH_LOG("Core-specific remap found at %s. Loading.\n", core_path);
|
||||
if(!input_remapping_load_file(core_path))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
RARCH_LOG("No core-specific remap found at %s.\n", core_path);
|
||||
|
||||
new_conf = NULL;
|
||||
|
||||
/* Create a new config file from game_path */
|
||||
new_conf = config_file_new(game_path);
|
||||
|
||||
/* Append game-specific */
|
||||
// If a game remap file exists, load it
|
||||
if (new_conf)
|
||||
{
|
||||
RARCH_LOG("Game-specific remap found at %s. Appending.\n", game_path);
|
||||
if(!input_remapping_load_file(game_path))
|
||||
return false;
|
||||
if(input_remapping_load_file(game_path))
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
RARCH_LOG("No core-specific remap found at %s.\n", core_path);
|
||||
*settings->input.remapping_path= '\0';
|
||||
input_remapping_set_defaults();
|
||||
}
|
||||
|
||||
new_conf = NULL;
|
||||
|
||||
// Create a new config file from core_path
|
||||
new_conf = config_file_new(core_path);
|
||||
|
||||
// If a core remap file exists, load it
|
||||
if (new_conf)
|
||||
{
|
||||
RARCH_LOG("Core-specific remap found at %s. Loading.\n", core_path);
|
||||
if(input_remapping_load_file(core_path))
|
||||
return true;
|
||||
}
|
||||
else
|
||||
RARCH_LOG("No game-specific remap found at %s.\n", game_path);
|
||||
{
|
||||
RARCH_LOG("No core-specific remap found at %s.\n", core_path);
|
||||
*settings->input.remapping_path= '\0';
|
||||
input_remapping_set_defaults();
|
||||
}
|
||||
|
||||
|
||||
return true; /* only means no errors were caught */
|
||||
new_conf = NULL;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void parse_config_file(void)
|
||||
@ -2104,7 +2130,6 @@ bool config_save_file(const char *path)
|
||||
config_set_bool(conf, "fps_show", settings->fps_show);
|
||||
config_set_bool(conf, "ui_menubar_enable", settings->ui.menubar_enable);
|
||||
config_set_bool(conf, "suspend_screensaver_enable", settings->ui.suspend_screensaver_enable);
|
||||
config_set_path(conf, "libretro_path", settings->libretro);
|
||||
config_set_path(conf, "libretro_directory", settings->libretro_directory);
|
||||
config_set_path(conf, "libretro_info_path", settings->libretro_info_path);
|
||||
config_set_path(conf, "content_database_path", settings->content_database);
|
||||
|
@ -407,17 +407,27 @@ void config_load(void);
|
||||
* These settings will always have precedence, thus this feature
|
||||
* can be used to enforce overrides.
|
||||
*
|
||||
* Returns: false if there was an error.
|
||||
* Returns: false if there was an error or no action was performed.
|
||||
*
|
||||
*/
|
||||
bool config_load_override(void);
|
||||
|
||||
/**
|
||||
* config_unload_override:
|
||||
*
|
||||
* Unloads configuration overrides if overrides are active.
|
||||
*
|
||||
*
|
||||
* Returns: false if there was an error.
|
||||
*/
|
||||
bool config_unload_override(void);
|
||||
|
||||
/**
|
||||
* config_load_remap:
|
||||
*
|
||||
* Tries to append game-specific and core-specific remap files.
|
||||
*
|
||||
* Returns: false if there was an error.
|
||||
* Returns: false if there was an error or no action was performed.
|
||||
*
|
||||
*/
|
||||
bool config_load_remap(void);
|
||||
|
@ -1417,10 +1417,14 @@ static int deferred_push_core_input_remapping_options(void *data, void *userdata
|
||||
return -1;
|
||||
|
||||
menu_list_clear(list);
|
||||
menu_list_push(list, "Remap File Load", "remap_file_load",
|
||||
menu_list_push(list, "Load Remap File", "remap_file_load",
|
||||
MENU_SETTING_ACTION, 0);
|
||||
menu_list_push(list, "Remap File Save As",
|
||||
menu_list_push(list, "Save Remap File As",
|
||||
"remap_file_save_as", MENU_SETTING_ACTION, 0);
|
||||
menu_list_push(list, "Save Core Remap File",
|
||||
"remap_file_save_core", MENU_SETTING_ACTION, 0);
|
||||
menu_list_push(list, "Save Game Remap File",
|
||||
"remap_file_save_game", MENU_SETTING_ACTION, 0);
|
||||
|
||||
for (p = 0; p < settings->input.max_users; p++)
|
||||
{
|
||||
|
@ -508,6 +508,53 @@ static int action_ok_remap_file_save_as(const char *path,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int action_ok_remap_file_save_core(const char *path,
|
||||
const char *label, unsigned type, size_t idx)
|
||||
{
|
||||
global_t *global = global_get_ptr();
|
||||
settings_t *settings = config_get_ptr();
|
||||
|
||||
const char *core_name;
|
||||
core_name = global->system.info.library_name;
|
||||
|
||||
char directory[PATH_MAX_LENGTH];
|
||||
char file[PATH_MAX_LENGTH];
|
||||
|
||||
fill_pathname_join(directory,settings->input_remapping_directory,core_name,PATH_MAX_LENGTH);
|
||||
fill_pathname_join(file,core_name,core_name,PATH_MAX_LENGTH);
|
||||
|
||||
if(!path_file_exists(directory))
|
||||
path_mkdir(directory);
|
||||
|
||||
input_remapping_save_file(file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int action_ok_remap_file_save_game(const char *path,
|
||||
const char *label, unsigned type, size_t idx)
|
||||
{
|
||||
global_t *global = global_get_ptr();
|
||||
settings_t *settings = config_get_ptr();
|
||||
|
||||
const char *core_name;
|
||||
core_name = global->system.info.library_name;
|
||||
|
||||
const char *game_name;
|
||||
game_name = path_basename(global->basename);
|
||||
|
||||
char directory[PATH_MAX_LENGTH];
|
||||
char file[PATH_MAX_LENGTH];
|
||||
|
||||
fill_pathname_join(directory,settings->input_remapping_directory,core_name,PATH_MAX_LENGTH);
|
||||
fill_pathname_join(file,core_name,game_name,PATH_MAX_LENGTH);
|
||||
|
||||
if(!path_file_exists(directory))
|
||||
path_mkdir(directory);
|
||||
|
||||
input_remapping_save_file(file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int action_ok_path_use_directory(const char *path,
|
||||
const char *label, unsigned type, size_t idx)
|
||||
{
|
||||
@ -1265,6 +1312,10 @@ void menu_entries_cbs_init_bind_ok(menu_file_list_cbs_t *cbs,
|
||||
cbs->action_ok = action_ok_cheat_file_save_as;
|
||||
else if (!strcmp(label, "remap_file_save_as"))
|
||||
cbs->action_ok = action_ok_remap_file_save_as;
|
||||
else if (!strcmp(label, "remap_file_save_core"))
|
||||
cbs->action_ok = action_ok_remap_file_save_core;
|
||||
else if (!strcmp(label, "remap_file_save_game"))
|
||||
cbs->action_ok = action_ok_remap_file_save_game;
|
||||
else if (!strcmp(label, "core_list"))
|
||||
cbs->action_ok = action_ok_core_list;
|
||||
else if (!strcmp(label, "disk_image_append"))
|
||||
|
31
retroarch.c
31
retroarch.c
@ -24,6 +24,7 @@
|
||||
#include "libretro_version_1.h"
|
||||
#include "dynamic.h"
|
||||
#include "content.h"
|
||||
#include "configuration.h"
|
||||
#include <file/file_path.h>
|
||||
#include <file/dir_list.h>
|
||||
#include "general.h"
|
||||
@ -415,6 +416,8 @@ static void parse_input(int argc, char *argv[])
|
||||
*global->bps_name = '\0';
|
||||
*global->ips_name = '\0';
|
||||
*global->subsystem = '\0';
|
||||
|
||||
global->overrides_active = false;
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
@ -1842,12 +1845,21 @@ static void init_system_av_info(void)
|
||||
|
||||
static void deinit_core(bool reinit)
|
||||
{
|
||||
|
||||
global_t *global = global_get_ptr();
|
||||
|
||||
pretro_unload_game();
|
||||
pretro_deinit();
|
||||
|
||||
if (reinit)
|
||||
rarch_main_command(RARCH_CMD_DRIVERS_DEINIT);
|
||||
|
||||
|
||||
if(global->overrides_active)
|
||||
{
|
||||
config_unload_override();
|
||||
global->overrides_active = false;
|
||||
}
|
||||
pretro_set_environment(rarch_environment_cb);
|
||||
uninit_libretro_sym();
|
||||
}
|
||||
|
||||
@ -1884,15 +1896,16 @@ static bool init_content(void)
|
||||
static bool init_core(void)
|
||||
{
|
||||
driver_t *driver = driver_get_ptr();
|
||||
global_t *global = global_get_ptr();
|
||||
|
||||
//needs testing for regressions
|
||||
pretro_set_environment(rarch_environment_cb);
|
||||
global_t *global = global_get_ptr();
|
||||
|
||||
if (!config_load_override())
|
||||
RARCH_ERR("Error loading override files\n");
|
||||
if (!config_load_remap())
|
||||
RARCH_ERR("Error loading remap files\n");
|
||||
if (config_load_override())
|
||||
global->overrides_active = true;
|
||||
else
|
||||
global->overrides_active = false;
|
||||
|
||||
pretro_set_environment(rarch_environment_cb);
|
||||
|
||||
config_load_remap();
|
||||
|
||||
verify_api_version();
|
||||
pretro_init();
|
||||
|
Loading…
x
Reference in New Issue
Block a user