diff --git a/configuration.c b/configuration.c index 021dc80aa4..c4836ed3d0 100644 --- a/configuration.c +++ b/configuration.c @@ -1352,10 +1352,6 @@ static struct config_path_setting *populate_settings_path( #ifdef HAVE_VIDEO_LAYOUT SETTING_PATH("video_layout_directory", settings->paths.directory_video_layout, true, NULL, true); -#endif -#ifndef HAVE_DYNAMIC - SETTING_PATH("libretro_path", - path_get_ptr(RARCH_PATH_CORE), false, NULL, false); #endif SETTING_PATH( "screenshot_directory", @@ -2454,8 +2450,6 @@ void config_set_defaults(void *data) configuration_set_string(settings, settings->paths.network_buildbot_url, g_defaults.path_buildbot_server_url); - if (!string_is_empty(g_defaults.path_core)) - path_set(RARCH_PATH_CORE, g_defaults.path_core); if (!string_is_empty(g_defaults.dirs[DEFAULT_DIR_DATABASE])) configuration_set_string(settings, settings->paths.path_content_database, @@ -2889,7 +2883,6 @@ static bool config_load_file(global_t *global, unsigned msg_color = 0; char *save = NULL; char *override_username = NULL; - const char *path_core = NULL; const char *path_config = NULL; int bool_settings_size = sizeof(settings->bools) / sizeof(settings->bools.placeholder); int float_settings_size = sizeof(settings->floats) / sizeof(settings->floats.placeholder); @@ -3097,11 +3090,6 @@ static bool config_load_file(global_t *global, configuration_set_string(settings, settings->paths.directory_libretro, tmp_str); -#ifndef HAVE_DYNAMIC - if (config_get_path(conf, "libretro_path", tmp_str, sizeof(tmp_str))) - path_set(RARCH_PATH_CORE, tmp_str); -#endif - #ifdef RARCH_CONSOLE video_driver_load_settings(conf); #endif @@ -3131,7 +3119,6 @@ static bool config_load_file(global_t *global, #endif path_config = path_get(RARCH_PATH_CONFIG); - path_core = path_get(RARCH_PATH_CORE); if (string_is_empty(settings->paths.path_content_history)) { @@ -3219,22 +3206,6 @@ static bool config_load_file(global_t *global, } } -#ifdef RARCH_CONSOLE - if (!string_is_empty(path_core)) - { -#endif - /* Safe-guard against older behavior. */ - if (path_is_directory(path_core)) - { - RARCH_WARN("\"libretro_path\" is a directory, using this for \"libretro_directory\" instead.\n"); - configuration_set_string(settings, - settings->paths.directory_libretro, path_core); - path_clear(RARCH_PATH_CORE); - } -#ifdef RARCH_CONSOLE - } -#endif - if (string_is_equal(settings->paths.path_menu_wallpaper, "default")) *settings->paths.path_menu_wallpaper = '\0'; if (string_is_equal(settings->paths.path_rgui_theme_preset, "default")) @@ -3431,7 +3402,6 @@ end: */ bool config_load_override(void *data) { - char buf[PATH_MAX_LENGTH]; char core_path[PATH_MAX_LENGTH]; char game_path[PATH_MAX_LENGTH]; char content_path[PATH_MAX_LENGTH]; @@ -3452,7 +3422,7 @@ bool config_load_override(void *data) if (string_is_empty(core_name) || string_is_empty(game_name)) return false; - config_directory[0] = core_path[0] = game_path[0] = buf[0] = '\0'; + config_directory[0] = core_path[0] = game_path[0] = '\0'; fill_pathname_application_special(config_directory, sizeof(config_directory), APPLICATION_SPECIAL_DIRECTORY_CONFIG); @@ -3555,9 +3525,6 @@ bool config_load_override(void *data) /* Re-load the configuration with any overrides * that might have been found */ - /* Store the libretro_path we're using since it will be - * overwritten by the override when reloading. */ - strlcpy(buf, path_get(RARCH_PATH_CORE), sizeof(buf)); /* Toggle has_save_path to false so it resets */ retroarch_override_setting_unset(RARCH_OVERRIDE_SETTING_STATE_PATH, NULL); @@ -3567,9 +3534,6 @@ bool config_load_override(void *data) path_get(RARCH_PATH_CONFIG), settings)) return false; - /* Restore the libretro_path we're using - * since it will be overwritten by the override when reloading. */ - path_set(RARCH_PATH_CORE, buf); if (settings->bools.notification_show_config_override_load) runloop_msg_queue_push(msg_hash_to_str(MSG_CONFIG_OVERRIDE_LOADED), 1, 100, false, @@ -4408,7 +4372,7 @@ bool config_replace(bool config_replace_save_on_exit, char *path) rarch_ctl(RARCH_CTL_UNSET_BLOCK_CONFIG_READ, NULL); - /* Load core in new config. */ + /* Load core in new (salamander) config. */ path_clear(RARCH_PATH_CORE); return task_push_start_dummy_core(&content_info); @@ -4689,3 +4653,106 @@ void input_remapping_set_defaults(bool deinit) } } #endif + +#if !defined(HAVE_DYNAMIC) +/* Salamander config file contains a single + * entry (libretro_path), which is linked to + * RARCH_PATH_CORE + * > Used to select which core to load + * when launching a salamander build */ + +static bool config_file_salamander_get_path(char *s, size_t len) +{ + const char *rarch_config_path = g_defaults.path_config; + + if (!string_is_empty(rarch_config_path)) + fill_pathname_resolve_relative(s, + rarch_config_path, + FILE_PATH_SALAMANDER_CONFIG, + len); + else + strlcpy(s, FILE_PATH_SALAMANDER_CONFIG, len); + + return !string_is_empty(s); +} + +void config_load_file_salamander(void) +{ + config_file_t *config = NULL; + char config_path[PATH_MAX_LENGTH]; + char libretro_path[PATH_MAX_LENGTH]; + + config_path[0] = '\0'; + libretro_path[0] = '\0'; + + /* Get config file path */ + if (!config_file_salamander_get_path( + config_path, sizeof(config_path))) + return; + + /* Open config file */ + config = config_file_new_from_path_to_string(config_path); + + if (!config) + return; + + /* Read 'libretro_path' value and update + * RARCH_PATH_CORE */ + RARCH_LOG("[config] Loading salamander config from: \"%s\".\n", + config_path); + + if (config_get_path(config, "libretro_path", + libretro_path, sizeof(libretro_path)) && + !string_is_empty(libretro_path) && + !string_is_equal(libretro_path, "builtin")) + path_set(RARCH_PATH_CORE, libretro_path); + + config_file_free(config); +} + +void config_save_file_salamander(void) +{ + config_file_t *config = NULL; + const char *libretro_path = path_get(RARCH_PATH_CORE); + bool success = false; + char config_path[PATH_MAX_LENGTH]; + + config_path[0] = '\0'; + + if (string_is_empty(libretro_path) || + string_is_equal(libretro_path, "builtin")) + return; + + /* Get config file path */ + if (!config_file_salamander_get_path( + config_path, sizeof(config_path))) + return; + + /* Open config file */ + config = config_file_new_from_path_to_string(config_path); + + if (!config) + config = config_file_new_alloc(); + + if (!config) + goto end; + + /* Update config file */ + config_set_path(config, "libretro_path", libretro_path); + + /* Save config file + * > Only one entry - no need to sort */ + success = config_file_write(config, config_path, false); + +end: + if (success) + RARCH_LOG("[config] Saving salamander config to: \"%s\".\n", + config_path); + else + RARCH_ERR("[config] Failed to create new salamander config file in: \"%s\".\n", + config_path); + + if (config) + config_file_free(config); +} +#endif diff --git a/configuration.h b/configuration.h index d226005550..d5d19166fa 100644 --- a/configuration.h +++ b/configuration.h @@ -951,6 +951,16 @@ void config_set_defaults(void *data); void config_load(void *data); +#if !defined(HAVE_DYNAMIC) +/* Salamander config file contains a single + * entry (libretro_path), which is linked to + * RARCH_PATH_CORE + * > Used to select which core to load + * when launching a salamander build */ +void config_load_file_salamander(void); +void config_save_file_salamander(void); +#endif + settings_t *config_get_ptr(void); RETRO_END_DECLS diff --git a/defaults.h b/defaults.h index 0bd1d94c2f..e01d7ffc02 100644 --- a/defaults.h +++ b/defaults.h @@ -85,7 +85,6 @@ struct defaults char dirs [DEFAULT_DIR_LAST + 1][PATH_MAX_LENGTH]; char path_config[PATH_MAX_LENGTH]; - char path_core [PATH_MAX_LENGTH]; char path_buildbot_server_url[255]; char settings_menu[32]; diff --git a/file_path_special.h b/file_path_special.h index f0c777e403..635a76cdef 100644 --- a/file_path_special.h +++ b/file_path_special.h @@ -96,6 +96,7 @@ RETRO_BEGIN_DECLS #define FILE_PATH_CONTENT_IMAGE_HISTORY "content_image_history.lpl" #define FILE_PATH_CORE_OPTIONS_CONFIG "retroarch-core-options.cfg" #define FILE_PATH_MAIN_CONFIG "retroarch.cfg" +#define FILE_PATH_SALAMANDER_CONFIG "retroarch-salamander.cfg" #define FILE_PATH_BACKGROUND_IMAGE "bg.png" #define FILE_PATH_TTF_FONT "font.ttf" #define FILE_PATH_RUNTIME_EXTENSION ".lrtl" diff --git a/frontend/frontend_driver.c b/frontend/frontend_driver.c index 619316ffe5..1082686205 100644 --- a/frontend/frontend_driver.c +++ b/frontend/frontend_driver.c @@ -22,14 +22,14 @@ #include #include -#if defined(_3DS) -#include <3ds.h> -#endif - #ifdef HAVE_CONFIG_H #include "../config.h" #endif +#if defined(_3DS) +#include <3ds.h> +#endif + #include "frontend_driver.h" #ifndef __WINRT__ diff --git a/frontend/frontend_salamander.c b/frontend/frontend_salamander.c index e70c368fbd..96f6adf493 100644 --- a/frontend/frontend_salamander.c +++ b/frontend/frontend_salamander.c @@ -33,6 +33,7 @@ #include "frontend_driver.h" #include "../defaults.h" #include "../verbosity.h" +#include "../file_path_special.h" struct defaults g_defaults; @@ -117,55 +118,76 @@ static void find_and_set_first_file(char *s, size_t len, static void salamander_init(char *s, size_t len) { - /* normal executable loading path */ - bool config_exists = config_file_exists(g_defaults.path_config); + /* Normal executable loading path */ + config_file_t *config = NULL; + const char *rarch_config_path = g_defaults.path_config; + bool config_valid = false; + char config_path[PATH_MAX_LENGTH]; - if (config_exists) + config_path[0] = '\0'; + + /* Get salamander config file path */ + if (!string_is_empty(rarch_config_path)) + fill_pathname_resolve_relative(config_path, + rarch_config_path, + FILE_PATH_SALAMANDER_CONFIG, + sizeof(config_path)); + else + strlcpy(config_path, FILE_PATH_SALAMANDER_CONFIG, + sizeof(config_path)); + + /* Attempt to open config file */ + config = config_file_new_from_path_to_string(config_path); + + if (config) { - char tmp_str[PATH_MAX_LENGTH] = {0}; - config_file_t * conf = config_file_new(g_defaults.path_config); + char libretro_path[PATH_MAX_LENGTH]; - if (conf) - { - config_get_array(conf, "libretro_path", tmp_str, sizeof(tmp_str)); - config_file_free(conf); + libretro_path[0] = '\0'; - if (memcmp(tmp_str, "builtin", 7) != 0) - strlcpy(s, tmp_str, len); - } -#ifdef GEKKO - /* stupid libfat bug or something; sometimes it says - * the file is there when it doesn't. */ - else + if (config_get_path(config, "libretro_path", + libretro_path, sizeof(libretro_path)) && + !string_is_empty(libretro_path) && + !string_is_equal(libretro_path, "builtin")) { - config_exists = false; + strlcpy(s, libretro_path, len); + config_valid = true; } -#endif + + config_file_free(config); + config = NULL; } - if (!config_exists || string_is_equal(s, "")) + if (!config_valid) { - char executable_name[PATH_MAX_LENGTH] = {0}; + char executable_name[PATH_MAX_LENGTH]; + executable_name[0] = '\0'; + + /* No config file - search filesystem for + * first available core */ frontend_driver_get_core_extension( executable_name, sizeof(executable_name)); find_and_set_first_file(s, len, executable_name); - } - else - RARCH_LOG("Start [%s] found in retroarch.cfg.\n", s); - if (!config_exists) - { - config_file_t *conf = config_file_new_alloc(); - - if (conf) + /* Save result to new config file */ + if (!string_is_empty(s)) { - config_set_string(conf, "libretro_path", s); - config_file_write(conf, g_defaults.path_config, true); - config_file_free(conf); + config = config_file_new_alloc(); + + if (config) + { + config_set_path(config, "libretro_path", s); + config_file_write(config, config_path, false); + config_file_free(config); + } } } + else + RARCH_LOG("Start [%s] found in %s.\n", s, + FILE_PATH_SALAMANDER_CONFIG); } + #ifdef HAVE_MAIN int salamander_main(int argc, char *argv[]) #else diff --git a/retroarch.c b/retroarch.c index db5a623001..ef374be29d 100644 --- a/retroarch.c +++ b/retroarch.c @@ -16528,6 +16528,9 @@ bool command_event(enum event_command cmd, void *data) config_set_defaults(&p_rarch->g_extern); break; case CMD_EVENT_MENU_SAVE_CURRENT_CONFIG: +#if !defined(HAVE_DYNAMIC) + config_save_file_salamander(); +#endif #ifdef HAVE_CONFIGFILE command_event_save_current_config(p_rarch, OVERRIDE_NONE); #endif @@ -36259,8 +36262,15 @@ static void retroarch_parse_input_and_config( /* Load the config file now that we know what it is */ #ifdef HAVE_CONFIGFILE if (!p_rarch->rarch_block_config_read) +#endif + { + /* If this is a static build, load salamander + * config file first (sets RARCH_PATH_CORE) */ +#if !defined(HAVE_DYNAMIC) + config_load_file_salamander(); #endif config_load(&p_rarch->g_extern); + } /* Second pass: All other arguments override the config file */ optind = 1;