From eca9b3ddc9d2f85b53eb76bf1dafbf20918f56c0 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Mon, 28 May 2012 18:25:01 +0200 Subject: [PATCH] (360/PS3) 360 and PS3 both use rarch_manage_libretro_set_first_file now --- 360/main.c | 52 +++---------------------------- console/console_ext.c | 71 ++++++++++++++++++++++++++++++++++++++++++- console/console_ext.h | 7 ++++- ps3/main.c | 35 +++------------------ 4 files changed, 84 insertions(+), 81 deletions(-) diff --git a/360/main.c b/360/main.c index 55d6daf8bb..1582df7b69 100644 --- a/360/main.c +++ b/360/main.c @@ -187,60 +187,16 @@ static void set_default_settings (void) static void init_settings (bool load_libretro_path) { - char fname_tmp[PATH_MAX]; if(!path_file_exists(SYS_CONFIG_FILE)) rarch_config_create_default(SYS_CONFIG_FILE); config_file_t * conf = config_file_new(SYS_CONFIG_FILE); +#ifdef HAVE_LIBRETRO_MANAGEMENT if(load_libretro_path) - { - CONFIG_GET_STRING(libretro, "libretro_path"); - - if(!strcmp(g_settings.libretro, "")) - { - //We need to set libretro to the first entry in the cores - //directory so that it will be saved to the config file - char ** dir_list = dir_list_new("game:\\", ".xex"); - - if (!dir_list) - { - RARCH_ERR("Couldn't read directory.\n"); - return; - } - - const char * first_xex = dir_list[0]; - - if(first_xex) - { - fill_pathname_base(fname_tmp, first_xex, sizeof(fname_tmp)); - - if(strcmp(fname_tmp, "RetroArch-Salamander.xex") == 0) - { - RARCH_WARN("First entry is RetroArch Salamander itself, increment entry by one and check if it exists.\n"); - first_xex = dir_list[1]; - fill_pathname_base(fname_tmp, first_xex, sizeof(fname_tmp)); - - if(!first_xex) - { - //This is very unlikely to happen - RARCH_WARN("There is no second entry - no choice but to set it to RetroArch Salamander\n"); - first_xex = dir_list[0]; - fill_pathname_base(fname_tmp, first_xex, sizeof(fname_tmp)); - } - } - RARCH_LOG("Set first .xex entry in dir: [%s] to libretro path.\n", fname_tmp); - snprintf(g_settings.libretro, sizeof(g_settings.libretro), "game:\\%s", fname_tmp); - } - else - { - RARCH_ERR("Failed to set first .xex entry to libretro path.\n"); - } - - dir_list_free(dir_list); - } - } + rarch_manage_libretro_set_first_file(SYS_CONFIG_FILE, "game:\\", ".xex"); +#endif // g_settings CONFIG_GET_STRING(cheat_database, "cheat_database"); @@ -359,7 +315,7 @@ int main(int argc, char *argv[]) char full_path[1024]; snprintf(full_path, sizeof(full_path), "game:\\CORE.xex"); - bool load_libretro_path = rarch_manage_libretro_core(full_path, "game:\\", ".xex"); + bool load_libretro_path = rarch_manage_libretro_install(full_path, "game:\\", ".xex"); set_default_settings(); init_settings(load_libretro_path); diff --git a/console/console_ext.c b/console/console_ext.c index 816fc3a607..3d229c017b 100644 --- a/console/console_ext.c +++ b/console/console_ext.c @@ -27,6 +27,11 @@ #include "console_ext.h" #include "../file.h" +#ifdef HAVE_CONFIGFILE +#include "../conf/config_file.h" +#include "../conf/config_file_macros.h" +#endif + #ifdef HAVE_ZLIB #include "rzlib/zlib.h" #define WRITEBUFFERSIZE (1024 * 512) @@ -517,7 +522,7 @@ void rarch_set_auto_viewport(unsigned width, unsigned height) ============================================================ */ #ifdef HAVE_LIBRETRO_MANAGEMENT -bool rarch_manage_libretro_core(const char *full_path, const char *path, const char *exe_ext) +bool rarch_manage_libretro_install(const char *full_path, const char *path, const char *exe_ext) { g_extern.verbose = true; bool return_code; @@ -604,6 +609,68 @@ bool rarch_manage_libretro_core(const char *full_path, const char *path, const c return return_code; } + +#ifdef HAVE_CONFIGFILE +void rarch_manage_libretro_set_first_file(const char * conf_name, const char *libretro_path, const char * exe_ext) +{ +#ifdef _XBOX + char fname_tmp[PATH_MAX]; +#endif + + config_file_t * conf = config_file_new(conf_name); + + CONFIG_GET_STRING(libretro, "libretro_path"); + + if(!strcmp(g_settings.libretro, "")) + { + //We need to set libretro to the first entry in the cores + //directory so that it will be saved to the config file + + char ** dir_list = dir_list_new(libretro_path, exe_ext); + + if (!dir_list) + { + RARCH_ERR("Couldn't read directory.\n"); + return; + } + + const char * first_exe = dir_list[0]; + + if(first_exe) + { +#ifdef _XBOX + fill_pathname_base(fname_tmp, first_exe, sizeof(fname_tmp)); + + if(strcmp(fname_tmp, "RetroArch-Salamander.xex") == 0) + { + RARCH_WARN("First entry is RetroArch Salamander itself, increment entry by one and check if it exists.\n"); + first_exe = dir_list[1]; + fill_pathname_base(fname_tmp, first_exe, sizeof(fname_tmp)); + + if(!first_exe) + { + RARCH_ERR("Unlikely error happened - no second entry - no choice but to set it to RetroArch Salamander\n"); + first_exe = dir_list[0]; + fill_pathname_base(fname_tmp, first_exe, sizeof(fname_tmp)); + } + } + + RARCH_LOG("Set first entry in libretro core dir to libretro path: [%s].\n", fname_tmp); + snprintf(g_settings.libretro, sizeof(g_settings.libretro), "game:\\%s", fname_tmp); +#else + RARCH_LOG("Set first entry in libretro core dir to libretro path: [%s].\n", first_exe); + strlcpy(g_settings.libretro, first_exe, sizeof(g_settings.libretro)); +#endif + } + else + { + RARCH_ERR("Failed to set first .xex entry to libretro path.\n"); + } + + dir_list_free(dir_list); + } +} +#endif #endif /*============================================================ @@ -794,6 +861,7 @@ const char * rarch_convert_wchar_to_const_char(const wchar_t * wstr) CONFIG ============================================================ */ +#ifdef HAVE_CONFIGFILE void rarch_config_create_default(const char * conf_name) { FILE * f; @@ -873,3 +941,4 @@ void rarch_config_save(const char * conf_name) free(conf); } } +#endif diff --git a/console/console_ext.h b/console/console_ext.h index 5af5414395..068e22acdb 100644 --- a/console/console_ext.h +++ b/console/console_ext.h @@ -101,7 +101,12 @@ void rarch_input_set_default_keybind_names_for_emulator(void); void rarch_input_set_keybind(unsigned player, unsigned keybind_action, uint64_t default_retro_joypad_id); #ifdef HAVE_LIBRETRO_MANAGEMENT -bool rarch_manage_libretro_core(const char *full_path, const char *path, const char *exe_ext); +/*============================================================ + LIBRETRO MANAGEMENT +============================================================ */ + +bool rarch_manage_libretro_install(const char *full_path, const char *path, const char *exe_ext); +void rarch_manage_libretro_set_first_file(const char * conf_name, const char *libretro_path, const char * exe_ext); #endif /*============================================================ diff --git a/ps3/main.c b/ps3/main.c index d13651f89d..1f5b4e4c49 100644 --- a/ps3/main.c +++ b/ps3/main.c @@ -163,37 +163,10 @@ static void init_settings(bool load_libretro_path) // g_settings +#ifdef HAVE_LIBRETRO_MANAGEMENT if(load_libretro_path) - { - CONFIG_GET_STRING(libretro, "libretro_path"); - - if(!strcmp(g_settings.libretro, "")) - { - //We need to set libretro to the first entry in the cores - //directory so that it will be saved to the config file - char ** dir_list = dir_list_new(LIBRETRO_DIR_PATH, ".SELF"); - - if (!dir_list) - { - RARCH_ERR("Couldn't read %s directory.\n", EMULATOR_CORE_DIR); - return; - } - - const char * first_self = dir_list[0]; - - if(first_self) - { - RARCH_LOG("Set first entry in libretro %s dir: [%s] to libretro path.\n", EMULATOR_CORE_DIR, first_self); - strlcpy(g_settings.libretro, first_self, sizeof(g_settings.libretro)); - } - else - { - RARCH_ERR("Failed to set first entry in libretro %s dir to libretro path.\n", EMULATOR_CORE_DIR); - } - - dir_list_free(dir_list); - } - } + rarch_manage_libretro_set_first_file(SYS_CONFIG_FILE, LIBRETRO_DIR_PATH, ".SELF"); +#endif CONFIG_GET_STRING(cheat_database, "cheat_database"); CONFIG_GET_BOOL(rewind_enable, "rewind_enable"); @@ -407,7 +380,7 @@ int main(int argc, char *argv[]) char full_path[1024], tmp_path[1024]; snprintf(full_path, sizeof(full_path), "%s/%s/CORE.SELF", usrDirPath, EMULATOR_CORE_DIR); snprintf(tmp_path, sizeof(tmp_path), "%s/%s/", usrDirPath, EMULATOR_CORE_DIR); - bool load_libretro_path = rarch_manage_libretro_core(full_path, tmp_path, ".SELF"); + bool load_libretro_path = rarch_manage_libretro_install(full_path, tmp_path, ".SELF"); set_default_settings(); init_settings(load_libretro_path);