mirror of
https://github.com/libretro/RetroArch
synced 2025-01-30 12:32:52 +00:00
Move libretro_management functions to frontend_console and rename
them
This commit is contained in:
parent
fd62c53c80
commit
413c757144
@ -21,80 +21,6 @@
|
|||||||
|
|
||||||
#include "rarch_console_libretro_mgmt.h"
|
#include "rarch_console_libretro_mgmt.h"
|
||||||
|
|
||||||
void rarch_console_name_from_id(char *name, size_t size)
|
|
||||||
{
|
|
||||||
if (size == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
struct retro_system_info info;
|
|
||||||
retro_get_system_info(&info);
|
|
||||||
const char *id = info.library_name ? info.library_name : "Unknown";
|
|
||||||
|
|
||||||
if (!id || strlen(id) >= size)
|
|
||||||
{
|
|
||||||
name[0] = '\0';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
name[strlen(id)] = '\0';
|
|
||||||
|
|
||||||
for (size_t i = 0; id[i] != '\0'; i++)
|
|
||||||
{
|
|
||||||
char c = id[i];
|
|
||||||
if (isspace(c) || isblank(c))
|
|
||||||
name[i] = '_';
|
|
||||||
else
|
|
||||||
name[i] = tolower(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if a CORE executable exists (full_path), this means we have just installed
|
|
||||||
// a new libretro port and therefore we need to change it to a more
|
|
||||||
// sane name.
|
|
||||||
|
|
||||||
bool rarch_libretro_core_install(const char *core_exe_path, const char *tmp_path,
|
|
||||||
const char *libretro_path, const char *config_path, const char *extension)
|
|
||||||
{
|
|
||||||
int ret = 0;
|
|
||||||
char tmp_path2[PATH_MAX], tmp_pathnewfile[PATH_MAX];
|
|
||||||
|
|
||||||
rarch_console_name_from_id(tmp_path2, sizeof(tmp_path2));
|
|
||||||
strlcat(tmp_path2, extension, sizeof(tmp_path2));
|
|
||||||
snprintf(tmp_pathnewfile, sizeof(tmp_pathnewfile), "%s%s", tmp_path, tmp_path2);
|
|
||||||
|
|
||||||
if (path_file_exists(tmp_pathnewfile))
|
|
||||||
{
|
|
||||||
// if libretro core already exists, this means we are
|
|
||||||
// upgrading the libretro core - so delete pre-existing
|
|
||||||
// file first.
|
|
||||||
|
|
||||||
RARCH_LOG("Upgrading emulator core...\n");
|
|
||||||
ret = remove(tmp_pathnewfile);
|
|
||||||
|
|
||||||
if (ret == 0)
|
|
||||||
RARCH_LOG("Succeeded in removing pre-existing libretro core: [%s].\n", tmp_pathnewfile);
|
|
||||||
else
|
|
||||||
RARCH_ERR("Failed to remove pre-existing libretro core: [%s].\n", tmp_pathnewfile);
|
|
||||||
}
|
|
||||||
|
|
||||||
//now attempt the renaming.
|
|
||||||
ret = rename(core_exe_path, tmp_pathnewfile);
|
|
||||||
|
|
||||||
if (ret == 0)
|
|
||||||
{
|
|
||||||
RARCH_LOG("Libretro core [%s] successfully 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 error occurred. Will attempt to load libretro core path from config file.\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool rarch_manage_libretro_extension_supported(const char *filename)
|
bool rarch_manage_libretro_extension_supported(const char *filename)
|
||||||
{
|
{
|
||||||
bool ext_supported = false;
|
bool ext_supported = false;
|
||||||
|
@ -30,13 +30,6 @@ enum
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
void rarch_console_name_from_id(char *name, size_t size);
|
|
||||||
|
|
||||||
//install/upgrade (and rename) libretro core if 'CORE' executable exists
|
|
||||||
bool rarch_libretro_core_install(const char *full_path, const char *tmp_path,
|
|
||||||
const char *libretro_path, const char *config_path, const char *extension);
|
|
||||||
|
|
||||||
// Transforms a library id to a name suitable as a pathname.
|
|
||||||
bool rarch_manage_libretro_extension_supported(const char *filename);
|
bool rarch_manage_libretro_extension_supported(const char *filename);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -19,15 +19,7 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
//optional RetroArch forward declarations
|
#include "frontend_console.h"
|
||||||
static void rarch_console_exec(const char *path);
|
|
||||||
|
|
||||||
#ifdef IS_SALAMANDER
|
|
||||||
//optional Salamander forward declarations
|
|
||||||
static void rarch_manage_libretro_set_first_file(char *first_file,
|
|
||||||
size_t size_of_first_file, const char *libretro_path,
|
|
||||||
const char * exe_ext);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__CELLOS_LV2__)
|
#if defined(__CELLOS_LV2__)
|
||||||
#include "platform/platform_ps3.c"
|
#include "platform/platform_ps3.c"
|
||||||
@ -105,6 +97,84 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBRETRO_MANAGEMENT
|
||||||
|
|
||||||
|
// Transforms a library id to a name suitable as a pathname.
|
||||||
|
static void get_libretro_core_name(char *name, size_t size)
|
||||||
|
{
|
||||||
|
if (size == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
struct retro_system_info info;
|
||||||
|
retro_get_system_info(&info);
|
||||||
|
const char *id = info.library_name ? info.library_name : "Unknown";
|
||||||
|
|
||||||
|
if (!id || strlen(id) >= size)
|
||||||
|
{
|
||||||
|
name[0] = '\0';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
name[strlen(id)] = '\0';
|
||||||
|
|
||||||
|
for (size_t i = 0; id[i] != '\0'; i++)
|
||||||
|
{
|
||||||
|
char c = id[i];
|
||||||
|
if (isspace(c) || isblank(c))
|
||||||
|
name[i] = '_';
|
||||||
|
else
|
||||||
|
name[i] = tolower(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If a CORE executable of name CORE.extension exists, rename filename
|
||||||
|
// to a more sane name.
|
||||||
|
static bool install_libretro_core(const char *core_exe_path, const char *tmp_path,
|
||||||
|
const char *libretro_path, const char *config_path, const char *extension)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
char tmp_path2[PATH_MAX], tmp_pathnewfile[PATH_MAX];
|
||||||
|
|
||||||
|
get_libretro_core_name(tmp_path2, sizeof(tmp_path2));
|
||||||
|
|
||||||
|
strlcat(tmp_path2, extension, sizeof(tmp_path2));
|
||||||
|
snprintf(tmp_pathnewfile, sizeof(tmp_pathnewfile), "%s%s", tmp_path, tmp_path2);
|
||||||
|
|
||||||
|
if (path_file_exists(tmp_pathnewfile))
|
||||||
|
{
|
||||||
|
// If core already exists, we are upgrading the core -
|
||||||
|
// delete existing file first.
|
||||||
|
|
||||||
|
RARCH_LOG("Upgrading emulator core...\n");
|
||||||
|
ret = remove(tmp_pathnewfile);
|
||||||
|
|
||||||
|
if (ret == 0)
|
||||||
|
RARCH_LOG("Succeeded in removing pre-existing libretro core: [%s].\n", tmp_pathnewfile);
|
||||||
|
else
|
||||||
|
RARCH_ERR("Failed to remove pre-existing libretro core: [%s].\n", tmp_pathnewfile);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now attempt the renaming of the core.
|
||||||
|
ret = rename(core_exe_path, tmp_pathnewfile);
|
||||||
|
|
||||||
|
if (ret == 0)
|
||||||
|
{
|
||||||
|
RARCH_LOG("Libretro core [%s] successfully 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 error occurred. Will attempt to load libretro core path from config file.\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
// Only called once on init and deinit.
|
// Only called once on init and deinit.
|
||||||
// Video and input drivers need to be active (owned)
|
// Video and input drivers need to be active (owned)
|
||||||
// before retroarch core starts.
|
// before retroarch core starts.
|
||||||
@ -167,7 +237,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (path_file_exists(core_exe_path))
|
if (path_file_exists(core_exe_path))
|
||||||
{
|
{
|
||||||
if (rarch_libretro_core_install(core_exe_path, path_prefix, path_prefix,
|
if (install_libretro_core(core_exe_path, path_prefix, path_prefix,
|
||||||
g_extern.config_path, extension))
|
g_extern.config_path, extension))
|
||||||
{
|
{
|
||||||
RARCH_LOG("New default libretro core saved to config file: %s.\n", g_settings.libretro);
|
RARCH_LOG("New default libretro core saved to config file: %s.\n", g_settings.libretro);
|
||||||
|
@ -609,7 +609,7 @@ static void system_post_init(void)
|
|||||||
gx_video_t *gx = (gx_video_t*)driver.video_data;
|
gx_video_t *gx = (gx_video_t*)driver.video_data;
|
||||||
char core_name[64];
|
char core_name[64];
|
||||||
|
|
||||||
rarch_console_name_from_id(core_name, sizeof(core_name));
|
get_libretro_core_name(core_name, sizeof(core_name));
|
||||||
snprintf(input_path, sizeof(input_path), "%s/%s.cfg", default_paths.input_presets_dir, core_name);
|
snprintf(input_path, sizeof(input_path), "%s/%s.cfg", default_paths.input_presets_dir, core_name);
|
||||||
config_read_keybinds(input_path);
|
config_read_keybinds(input_path);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user