From 5a07d757e92f5dfe3a4664ee6086a9a784b5f605 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Wed, 22 Aug 2012 22:04:28 +0200 Subject: [PATCH] (Libretro management) some cleanups --- console/rarch_console_config.c | 2 +- console/rarch_console_libretro_mgmt.c | 35 +++++++++++++-------------- console/rarch_console_libretro_mgmt.h | 2 ++ ps3/frontend/main.c | 6 ++--- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/console/rarch_console_config.c b/console/rarch_console_config.c index d0865331ee..eab4fb4d08 100644 --- a/console/rarch_console_config.c +++ b/console/rarch_console_config.c @@ -42,7 +42,7 @@ void rarch_config_load(const char * conf_name, const char * libretro_dir_path, c { CONFIG_GET_STRING(libretro, "libretro_path"); - if(strcmp(g_settings.libretro, "") == 0) + if(!rarch_manage_libretro_exists(g_settings.libretro)) { char first_file[PATH_MAX]; rarch_manage_libretro_set_first_file(first_file, sizeof(first_file), libretro_dir_path, exe_ext); diff --git a/console/rarch_console_libretro_mgmt.c b/console/rarch_console_libretro_mgmt.c index 3bd261b9e7..c715ac85c7 100644 --- a/console/rarch_console_libretro_mgmt.c +++ b/console/rarch_console_libretro_mgmt.c @@ -54,19 +54,17 @@ void rarch_console_name_from_id(char *name, size_t size) } } -bool rarch_configure_libretro_core(const char *full_path, const char *tmp_path, +bool rarch_configure_libretro_core(const char *core_exe_path, const char *tmp_path, const char *libretro_path, const char *config_path, const char *extension) { - bool ret = false; bool find_libretro_file = false; - char libretro_core_installed[1024]; g_extern.verbose = true; //install and rename libretro core first if 'CORE' executable exists - if (path_file_exists(full_path)) + if (path_file_exists(core_exe_path)) { - size_t sizeof_libretro_core = sizeof(libretro_core_installed); + bool ret = false; char tmp_path2[PATH_MAX], tmp_pathnewfile[PATH_MAX]; rarch_console_name_from_id(tmp_path2, sizeof(tmp_path2)); @@ -89,31 +87,24 @@ bool rarch_configure_libretro_core(const char *full_path, const char *tmp_path, } //now attempt the renaming. - ret = rename(full_path, tmp_pathnewfile); + ret = rename(core_exe_path, tmp_pathnewfile); if (ret == 0) { - RARCH_LOG("libretro core [%s] renamed to: [%s].\n", full_path, tmp_pathnewfile); - strlcpy(libretro_core_installed, tmp_pathnewfile, sizeof_libretro_core); - ret = 1; + RARCH_LOG("libretro core [%s] renamed to: [%s].\n", core_exe_path, tmp_pathnewfile); + snprintf(g_settings.libretro, sizeof(g_settings.libretro), tmp_pathnewfile); } else { + RARCH_ERR("Failed to rename CORE executable.\n"); - RARCH_WARN("CORE executable was not found, or some other errors occurred. Will attempt to load libretro core path from config file.\n"); - ret = 0; + RARCH_WARN("CORE executable was not found, or some other error occurred. Will attempt to load libretro core path from config file.\n"); + find_libretro_file = true; } } g_extern.verbose = false; - //if we have just installed a libretro core, set libretro path in settings to newly installed libretro core - - if(ret) - strlcpy(g_settings.libretro, libretro_core_installed, sizeof(g_settings.libretro)); - else - find_libretro_file = true; - return find_libretro_file; } @@ -135,6 +126,14 @@ bool rarch_manage_libretro_extension_supported(const char *filename) #endif +bool rarch_manage_libretro_exists(const char *path) +{ + if(path_file_exists(path)) + return true; + else + return false; +} + void rarch_manage_libretro_set_first_file(char *first_file, size_t size_of_first_file, const char *libretro_path, const char * exe_ext) { struct string_list *dir_list = dir_list_new(libretro_path, exe_ext, false); diff --git a/console/rarch_console_libretro_mgmt.h b/console/rarch_console_libretro_mgmt.h index 108a9b751c..896a19f6c7 100644 --- a/console/rarch_console_libretro_mgmt.h +++ b/console/rarch_console_libretro_mgmt.h @@ -43,6 +43,8 @@ bool rarch_configure_libretro_core(const char *full_path, const char *tmp_path, // Transforms a library id to a name suitable as a pathname. bool rarch_manage_libretro_extension_supported(const char *filename); +bool rarch_manage_libretro_exists(const char *path); #endif + #endif diff --git a/ps3/frontend/main.c b/ps3/frontend/main.c index 7fb81d0035..a9f087629a 100644 --- a/ps3/frontend/main.c +++ b/ps3/frontend/main.c @@ -253,10 +253,10 @@ int main(int argc, char *argv[]) const char *extension = default_paths.executable_extension; const input_driver_t *input = &input_ps3; - char full_path[1024]; - snprintf(full_path, sizeof(full_path), "%sCORE%s", path_prefix, extension); + char core_exe_path[1024]; + snprintf(core_exe_path, sizeof(core_exe_path), "%sCORE%s", path_prefix, extension); - bool find_libretro_file = rarch_configure_libretro_core(full_path, path_prefix, path_prefix, + bool find_libretro_file = rarch_configure_libretro_core(core_exe_path, path_prefix, path_prefix, default_paths.config_file, extension); rarch_settings_set_default(input);