Move subsystem path to paths.c

This commit is contained in:
twinaphex 2016-09-25 15:49:09 +02:00
parent b3ec735e75
commit a1488ae34f
8 changed files with 88 additions and 53 deletions

View File

@ -953,7 +953,6 @@ static bool command_event_disk_control_append_image(const char *path)
unsigned new_idx; unsigned new_idx;
char msg[128] = {0}; char msg[128] = {0};
struct retro_game_info info = {0}; struct retro_game_info info = {0};
global_t *global = global_get_ptr();
const struct retro_disk_control_callback *control = NULL; const struct retro_disk_control_callback *control = NULL;
rarch_system_info_t *sysinfo = NULL; rarch_system_info_t *sysinfo = NULL;
@ -985,7 +984,7 @@ static bool command_event_disk_control_append_image(const char *path)
command_event(CMD_EVENT_AUTOSAVE_DEINIT, NULL); command_event(CMD_EVENT_AUTOSAVE_DEINIT, NULL);
/* TODO: Need to figure out what to do with subsystems case. */ /* TODO: Need to figure out what to do with subsystems case. */
if (string_is_empty(global->subsystem)) if (path_is_subsystem_empty())
{ {
/* Update paths for our new image. /* Update paths for our new image.
* If we actually use append_image, we assume that we * If we actually use append_image, we assume that we
@ -2453,17 +2452,6 @@ bool command_event(enum event_command cmd, void *data)
case CMD_EVENT_TEMPORARY_CONTENT_DEINIT: case CMD_EVENT_TEMPORARY_CONTENT_DEINIT:
content_deinit(); content_deinit();
break; break;
case CMD_EVENT_SUBSYSTEM_FULLPATHS_DEINIT:
{
global_t *global = global_get_ptr();
if (!global)
break;
if (global->subsystem_fullpaths)
string_list_free(global->subsystem_fullpaths);
global->subsystem_fullpaths = NULL;
}
break;
case CMD_EVENT_LOG_FILE_DEINIT: case CMD_EVENT_LOG_FILE_DEINIT:
retro_main_log_file_deinit(); retro_main_log_file_deinit();
break; break;

View File

@ -191,7 +191,6 @@ enum event_command
CMD_EVENT_RESIZE_WINDOWED_SCALE, CMD_EVENT_RESIZE_WINDOWED_SCALE,
/* Deinitializes temporary content. */ /* Deinitializes temporary content. */
CMD_EVENT_TEMPORARY_CONTENT_DEINIT, CMD_EVENT_TEMPORARY_CONTENT_DEINIT,
CMD_EVENT_SUBSYSTEM_FULLPATHS_DEINIT,
CMD_EVENT_LOG_FILE_DEINIT, CMD_EVENT_LOG_FILE_DEINIT,
/* Toggles disk eject. */ /* Toggles disk eject. */
CMD_EVENT_DISK_EJECT_TOGGLE, CMD_EVENT_DISK_EJECT_TOGGLE,

60
paths.c
View File

@ -48,8 +48,13 @@
#define MENU_VALUE_NO_CORE 0x7d5472cbU #define MENU_VALUE_NO_CORE 0x7d5472cbU
/* For --subsystem content. */
static struct string_list *subsystem_fullpaths = NULL;
char subsystem_path[PATH_MAX_LENGTH] = {0};
static char path_default_shader_preset[PATH_MAX_LENGTH] = {0}; static char path_default_shader_preset[PATH_MAX_LENGTH] = {0};
static char path_main_basename[PATH_MAX_LENGTH] = {0} static char path_main_basename[PATH_MAX_LENGTH] = {0}
; ;
static char path_content[PATH_MAX_LENGTH] = {0}; static char path_content[PATH_MAX_LENGTH] = {0};
static char current_savefile_dir[PATH_MAX_LENGTH] = {0}; static char current_savefile_dir[PATH_MAX_LENGTH] = {0};
@ -242,6 +247,11 @@ void path_set_basename(const char *path)
*dst = '\0'; *dst = '\0';
} }
struct string_list *path_get_subsystem_list(void)
{
return subsystem_fullpaths;
}
const char *path_get_current_savefile_dir(void) const char *path_get_current_savefile_dir(void)
{ {
char *ret = current_savefile_dir; char *ret = current_savefile_dir;
@ -263,13 +273,13 @@ void path_set_special(char **argv, unsigned num_content)
/* First content file is the significant one. */ /* First content file is the significant one. */
path_set_basename(argv[0]); path_set_basename(argv[0]);
global->subsystem_fullpaths = string_list_new(); subsystem_fullpaths = string_list_new();
retro_assert(global->subsystem_fullpaths); retro_assert(subsystem_fullpaths);
attr.i = 0; attr.i = 0;
for (i = 0; i < num_content; i++) for (i = 0; i < num_content; i++)
string_list_append(global->subsystem_fullpaths, argv[i], attr); string_list_append(subsystem_fullpaths, argv[i], attr);
/* We defer SRAM path updates until we can resolve it. /* We defer SRAM path updates until we can resolve it.
* It is more complicated for special content types. */ * It is more complicated for special content types. */
@ -302,7 +312,7 @@ static bool path_init_subsystem(void)
if (!system) if (!system)
return false; return false;
if (string_is_empty(global->subsystem)) if (path_is_subsystem_empty())
return false; return false;
/* For subsystems, we know exactly which RAM types are supported. */ /* For subsystems, we know exactly which RAM types are supported. */
@ -310,12 +320,12 @@ static bool path_init_subsystem(void)
info = libretro_find_subsystem_info( info = libretro_find_subsystem_info(
system->subsystem.data, system->subsystem.data,
system->subsystem.size, system->subsystem.size,
global->subsystem); path_get_subsystem());
/* We'll handle this error gracefully later. */ /* We'll handle this error gracefully later. */
num_content = MIN(info ? info->num_roms : 0, num_content = MIN(info ? info->num_roms : 0,
global->subsystem_fullpaths ? path_is_subsystem_empty() ?
global->subsystem_fullpaths->size : 0); 0 : subsystem_fullpaths->size);
for (i = 0; i < num_content; i++) for (i = 0; i < num_content; i++)
@ -337,12 +347,12 @@ static bool path_init_subsystem(void)
/* Redirect content fullpath to save directory. */ /* Redirect content fullpath to save directory. */
strlcpy(path, dir_get_savefile(), sizeof(path)); strlcpy(path, dir_get_savefile(), sizeof(path));
fill_pathname_dir(path, fill_pathname_dir(path,
global->subsystem_fullpaths->elems[i].data, ext, subsystem_fullpaths->elems[i].data, ext,
sizeof(path)); sizeof(path));
} }
else else
{ {
fill_pathname(path, global->subsystem_fullpaths->elems[i].data, fill_pathname(path, subsystem_fullpaths->elems[i].data,
ext, sizeof(path)); ext, sizeof(path));
} }
@ -452,6 +462,11 @@ void path_fill_names(void)
/* Core file path */ /* Core file path */
const char *path_get_subsystem(void)
{
return subsystem_path;
}
const char *path_get_basename(void) const char *path_get_basename(void)
{ {
return path_main_basename; return path_main_basename;
@ -482,6 +497,16 @@ void path_set_core(const char *path)
strlcpy(path_libretro, path, sizeof(path_libretro)); strlcpy(path_libretro, path, sizeof(path_libretro));
} }
void path_set_subsystem(const char *path)
{
strlcpy(subsystem_path, path, sizeof(subsystem_path));
}
void path_clear_subsystem(void)
{
*subsystem_path = '\0';
}
void path_clear_core(void) void path_clear_core(void)
{ {
*path_libretro = '\0'; *path_libretro = '\0';
@ -494,6 +519,14 @@ void path_clear_default_shader_preset(void)
/* Config file path */ /* Config file path */
bool path_is_subsystem_empty(void)
{
if (string_is_empty(subsystem_path))
return true;
return false;
}
bool path_is_config_empty(void) bool path_is_config_empty(void)
{ {
if (string_is_empty(path_config_file)) if (string_is_empty(path_config_file))
@ -685,3 +718,10 @@ enum rarch_content_type path_is_media_type(const char *path)
return RARCH_CONTENT_NONE; return RARCH_CONTENT_NONE;
} }
void path_deinit_subsystem(void)
{
if (subsystem_fullpaths)
string_list_free(subsystem_fullpaths);
subsystem_fullpaths = NULL;
}

16
paths.h
View File

@ -19,6 +19,8 @@
#include <boolean.h> #include <boolean.h>
#include <retro_common_api.h> #include <retro_common_api.h>
#include <lists/string_list.h>
RETRO_BEGIN_DECLS RETRO_BEGIN_DECLS
enum rarch_content_type enum rarch_content_type
@ -29,6 +31,8 @@ enum rarch_content_type
RARCH_CONTENT_IMAGE RARCH_CONTENT_IMAGE
}; };
void path_deinit_subsystem(void);
void path_deinit_savefile(void); void path_deinit_savefile(void);
void path_init_savefile(void); void path_init_savefile(void);
@ -39,6 +43,8 @@ void path_fill_names(void);
/* set functions */ /* set functions */
void path_set_subsystem(const char *path);
void path_set_redirect(void); void path_set_redirect(void);
bool path_set_content(const char *path); bool path_set_content(const char *path);
@ -67,8 +73,14 @@ size_t path_get_core_size(void);
char *path_get_core_ptr(void); char *path_get_core_ptr(void);
/* get list functions */
struct string_list *path_get_subsystem_list(void);
/* get functions */ /* get functions */
const char *path_get_subsystem(void);
bool path_get_content(char **fullpath); bool path_get_content(char **fullpath);
const char *path_get_current_savefile_dir(void); const char *path_get_current_savefile_dir(void);
@ -87,6 +99,8 @@ bool path_get_default_shader_preset(char **preset);
/* clear functions */ /* clear functions */
void path_clear_subsystem(void);
void path_clear_default_shader_preset(void); void path_clear_default_shader_preset(void);
void path_clear_basename(void); void path_clear_basename(void);
@ -105,6 +119,8 @@ void path_clear_all(void);
/* is functions */ /* is functions */
bool path_is_subsystem_empty(void);
bool path_is_core_empty(void); bool path_is_core_empty(void);
bool path_is_config_empty(void); bool path_is_config_empty(void);

View File

@ -468,7 +468,7 @@ static void retroarch_parse_input(int argc, char *argv[])
if (!current_core_explicitly_set) if (!current_core_explicitly_set)
retroarch_set_current_core_type(CORE_TYPE_DUMMY, false); retroarch_set_current_core_type(CORE_TYPE_DUMMY, false);
*global->subsystem = '\0'; path_clear_subsystem();
retroarch_override_setting_free_state(); retroarch_override_setting_free_state();
@ -789,7 +789,7 @@ static void retroarch_parse_input(int argc, char *argv[])
break; break;
case RA_OPT_SUBSYSTEM: case RA_OPT_SUBSYSTEM:
strlcpy(global->subsystem, optarg, sizeof(global->subsystem)); path_set_subsystem(optarg);
break; break;
case RA_OPT_FEATURES: case RA_OPT_FEATURES:
@ -840,13 +840,13 @@ static void retroarch_parse_input(int argc, char *argv[])
#endif #endif
} }
if (string_is_empty(global->subsystem) && optind < argc) if (path_is_subsystem_empty() && optind < argc)
{ {
/* We requested explicit ROM, so use PLAIN core type. */ /* We requested explicit ROM, so use PLAIN core type. */
retroarch_set_current_core_type(CORE_TYPE_PLAIN, false); retroarch_set_current_core_type(CORE_TYPE_PLAIN, false);
path_set_names((const char*)argv[optind]); path_set_names((const char*)argv[optind]);
} }
else if (!string_is_empty(global->subsystem) && optind < argc) else if (!path_is_subsystem_empty() && optind < argc)
{ {
/* We requested explicit ROM, so use PLAIN core type. */ /* We requested explicit ROM, so use PLAIN core type. */
retroarch_set_current_core_type(CORE_TYPE_PLAIN, false); retroarch_set_current_core_type(CORE_TYPE_PLAIN, false);
@ -1159,8 +1159,8 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data)
command_event(CMD_EVENT_CORE_DEINIT, NULL); command_event(CMD_EVENT_CORE_DEINIT, NULL);
command_event(CMD_EVENT_TEMPORARY_CONTENT_DEINIT, NULL); command_event(CMD_EVENT_TEMPORARY_CONTENT_DEINIT, NULL);
command_event(CMD_EVENT_SUBSYSTEM_FULLPATHS_DEINIT, NULL);
path_deinit_subsystem();
path_deinit_savefile(); path_deinit_savefile();
rarch_ctl(RARCH_CTL_UNSET_INITED, NULL); rarch_ctl(RARCH_CTL_UNSET_INITED, NULL);

View File

@ -735,7 +735,8 @@ bool runloop_ctl(enum runloop_ctl_state state, void *data)
{ {
global_t *global = NULL; global_t *global = NULL;
command_event(CMD_EVENT_TEMPORARY_CONTENT_DEINIT, NULL); command_event(CMD_EVENT_TEMPORARY_CONTENT_DEINIT, NULL);
command_event(CMD_EVENT_SUBSYSTEM_FULLPATHS_DEINIT, NULL);
path_deinit_subsystem();
command_event(CMD_EVENT_RECORD_DEINIT, NULL); command_event(CMD_EVENT_RECORD_DEINIT, NULL);
command_event(CMD_EVENT_LOG_FILE_DEINIT, NULL); command_event(CMD_EVENT_LOG_FILE_DEINIT, NULL);

View File

@ -154,10 +154,6 @@ typedef struct global
char remapfile[PATH_MAX_LENGTH]; char remapfile[PATH_MAX_LENGTH];
} name; } name;
/* For --subsystem content. */
char subsystem[PATH_MAX_LENGTH];
struct string_list *subsystem_fullpaths;
struct struct
{ {
bool block_patch; bool block_patch;

View File

@ -589,9 +589,9 @@ static const struct retro_subsystem_info *init_content_file_subsystem(bool *ret)
{ {
const struct retro_subsystem_info *special = NULL; const struct retro_subsystem_info *special = NULL;
rarch_system_info_t *system = NULL; rarch_system_info_t *system = NULL;
global_t *global = global_get_ptr(); struct string_list *subsystem = path_get_subsystem_list();
if (global && string_is_empty(global->subsystem)) if (path_is_subsystem_empty())
{ {
*ret = true; *ret = true;
return NULL; return NULL;
@ -602,40 +602,36 @@ static const struct retro_subsystem_info *init_content_file_subsystem(bool *ret)
if (system) if (system)
special = special =
libretro_find_subsystem_info(system->subsystem.data, libretro_find_subsystem_info(system->subsystem.data,
system->subsystem.size, global->subsystem); system->subsystem.size, path_get_subsystem());
if (!special) if (!special)
{ {
RARCH_ERR( RARCH_ERR(
"Failed to find subsystem \"%s\" in libretro implementation.\n", "Failed to find subsystem \"%s\" in libretro implementation.\n",
global->subsystem); path_get_subsystem());
goto error; goto error;
} }
if (special->num_roms && !global->subsystem_fullpaths) if (special->num_roms && !subsystem)
{ {
RARCH_ERR("%s\n", RARCH_ERR("%s\n",
msg_hash_to_str(MSG_ERROR_LIBRETRO_CORE_REQUIRES_SPECIAL_CONTENT)); msg_hash_to_str(MSG_ERROR_LIBRETRO_CORE_REQUIRES_SPECIAL_CONTENT));
goto error; goto error;
} }
else if ((global else if (special->num_roms && (special->num_roms != subsystem->size))
&& special->num_roms)
&& (special->num_roms
!= global->subsystem_fullpaths->size))
{ {
RARCH_ERR("Libretro core requires %u content files for " RARCH_ERR("Libretro core requires %u content files for "
"subsystem \"%s\", but %u content files were provided.\n", "subsystem \"%s\", but %u content files were provided.\n",
special->num_roms, special->desc, special->num_roms, special->desc,
(unsigned)global->subsystem_fullpaths->size); (unsigned)subsystem->size);
goto error; goto error;
} }
else if (!special->num_roms && global->subsystem_fullpaths else if (!special->num_roms && subsystem && subsystem->size)
&& global->subsystem_fullpaths->size)
{ {
RARCH_ERR("Libretro core takes no content for subsystem \"%s\", " RARCH_ERR("Libretro core takes no content for subsystem \"%s\", "
"but %u content files were provided.\n", "but %u content files were provided.\n",
special->desc, special->desc,
(unsigned)global->subsystem_fullpaths->size); (unsigned)subsystem->size);
goto error; goto error;
} }
@ -654,22 +650,21 @@ static bool init_content_file_set_attribs(
const struct retro_subsystem_info *special) const struct retro_subsystem_info *special)
{ {
union string_list_elem_attr attr; union string_list_elem_attr attr;
global_t *global = global_get_ptr(); struct string_list *subsystem = path_get_subsystem_list();
attr.i = 0; attr.i = 0;
if (!string_is_empty(global->subsystem) && special) if (!path_is_subsystem_empty() && special)
{ {
unsigned i; unsigned i;
for (i = 0; i < global->subsystem_fullpaths->size; i++) for (i = 0; i < subsystem->size; i++)
{ {
attr.i = special->roms[i].block_extract; attr.i = special->roms[i].block_extract;
attr.i |= special->roms[i].need_fullpath << 1; attr.i |= special->roms[i].need_fullpath << 1;
attr.i |= special->roms[i].required << 2; attr.i |= special->roms[i].required << 2;
string_list_append(content, string_list_append(content, subsystem->elems[i].data, attr);
global->subsystem_fullpaths->elems[i].data, attr);
} }
} }
else else