Create path_is_empty

This commit is contained in:
twinaphex 2016-09-30 04:43:16 +02:00
parent 228886062b
commit 1266c0609a
10 changed files with 47 additions and 62 deletions

View File

@ -981,7 +981,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 (path_is_subsystem_empty()) if (path_is_empty(RARCH_PATH_SUBSYSTEM))
{ {
/* 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
@ -1485,7 +1485,7 @@ static bool command_event_save_core_config(void)
if (!string_is_empty(settings->directory.menu_config)) if (!string_is_empty(settings->directory.menu_config))
strlcpy(config_dir, settings->directory.menu_config, strlcpy(config_dir, settings->directory.menu_config,
sizeof(config_dir)); sizeof(config_dir));
else if (!path_is_config_empty()) /* Fallback */ else if (!path_is_empty(RARCH_PATH_CONFIG)) /* Fallback */
fill_pathname_basedir(config_dir, path_get(RARCH_PATH_CONFIG), fill_pathname_basedir(config_dir, path_get(RARCH_PATH_CONFIG),
sizeof(config_dir)); sizeof(config_dir));
else else
@ -1591,7 +1591,7 @@ static void command_event_save_current_config(int override_type)
RARCH_ERR("[overrides] %s\n", msg); RARCH_ERR("[overrides] %s\n", msg);
} }
} }
else if (!path_is_config_empty()) else if (!path_is_empty(RARCH_PATH_CONFIG))
command_event_save_config(path_get(RARCH_PATH_CONFIG), msg, sizeof(msg)); command_event_save_config(path_get(RARCH_PATH_CONFIG), msg, sizeof(msg));
if (!string_is_empty(msg)) if (!string_is_empty(msg))

View File

@ -1716,7 +1716,7 @@ static bool config_load_file(const char *path, bool set_defaults,
if (set_defaults) if (set_defaults)
config_set_defaults(); config_set_defaults();
if (!path_is_config_append_empty()) if (!path_is_empty(RARCH_PATH_CONFIG_APPEND))
{ {
/* Don't destroy append_config_path, store in temporary /* Don't destroy append_config_path, store in temporary
* variable. */ * variable. */
@ -2573,14 +2573,14 @@ bool config_load_shader_preset(void)
static void parse_config_file(void) static void parse_config_file(void)
{ {
if (!path_is_config_empty()) if (!path_is_empty(RARCH_PATH_CONFIG))
{ {
RARCH_LOG("Config: loading config from: %s.\n", path_get(RARCH_PATH_CONFIG)); RARCH_LOG("Config: loading config from: %s.\n", path_get(RARCH_PATH_CONFIG));
} }
else else
{ {
RARCH_LOG("Loading default config.\n"); RARCH_LOG("Loading default config.\n");
if (!path_is_config_empty()) if (!path_is_empty(RARCH_PATH_CONFIG))
RARCH_LOG("Config: found default config: %s.\n", path_get(RARCH_PATH_CONFIG)); RARCH_LOG("Config: found default config: %s.\n", path_get(RARCH_PATH_CONFIG));
} }
@ -3260,7 +3260,7 @@ bool config_replace(char *path)
if (string_is_equal(path, path_get(RARCH_PATH_CONFIG))) if (string_is_equal(path, path_get(RARCH_PATH_CONFIG)))
return false; return false;
if (settings->config_save_on_exit && !path_is_config_empty()) if (settings->config_save_on_exit && !path_is_empty(RARCH_PATH_CONFIG))
config_save_file(path_get(RARCH_PATH_CONFIG)); config_save_file(path_get(RARCH_PATH_CONFIG));
path_set(RARCH_PATH_CONFIG, path); path_set(RARCH_PATH_CONFIG, path);

View File

@ -290,7 +290,7 @@ void fill_pathname_application_special(char *s, size_t len, enum application_spe
* fallback to the location of the current configuration file. */ * fallback to the location of the current configuration file. */
if (!string_is_empty(settings->directory.menu_config)) if (!string_is_empty(settings->directory.menu_config))
strlcpy(s, settings->directory.menu_config, len); strlcpy(s, settings->directory.menu_config, len);
else if (!path_is_config_empty()) else if (!path_is_empty(RARCH_PATH_CONFIG))
fill_pathname_basedir(s, path_get(RARCH_PATH_CONFIG), len); fill_pathname_basedir(s, path_get(RARCH_PATH_CONFIG), len);
} }
break; break;

View File

@ -130,7 +130,7 @@ static void menu_action_setting_disp_set_label_configurations(
*w = 19; *w = 19;
strlcpy(s2, path, len2); strlcpy(s2, path, len2);
if (!path_is_config_empty()) if (!path_is_empty(RARCH_PATH_CONFIG))
fill_pathname_base(s, path_get(RARCH_PATH_CONFIG), fill_pathname_base(s, path_get(RARCH_PATH_CONFIG),
len); len);
else else

View File

@ -295,7 +295,7 @@ bool menu_shader_manager_save_preset(
strlcpy(buffer, conf_path, sizeof(buffer)); strlcpy(buffer, conf_path, sizeof(buffer));
} }
if (!path_is_config_empty()) if (!path_is_empty(RARCH_PATH_CONFIG))
fill_pathname_basedir( fill_pathname_basedir(
config_directory, config_directory,
path_get(RARCH_PATH_CONFIG), path_get(RARCH_PATH_CONFIG),

65
paths.c
View File

@ -310,7 +310,7 @@ static bool path_init_subsystem(void)
if (!system) if (!system)
return false; return false;
if (path_is_subsystem_empty()) if (path_is_empty(RARCH_PATH_SUBSYSTEM))
return false; return false;
/* For subsystems, we know exactly which RAM types are supported. */ /* For subsystems, we know exactly which RAM types are supported. */
@ -325,7 +325,7 @@ static bool path_init_subsystem(void)
if (info) if (info)
{ {
unsigned num_content = MIN(info->num_roms, unsigned num_content = MIN(info->num_roms,
path_is_subsystem_empty() ? path_is_empty(RARCH_PATH_SUBSYSTEM) ?
0 : subsystem_fullpaths->size); 0 : subsystem_fullpaths->size);
for (i = 0; i < num_content; i++) for (i = 0; i < num_content; i++)
@ -469,17 +469,17 @@ const char *path_get(enum rarch_path_type type)
case RARCH_PATH_BASENAME: case RARCH_PATH_BASENAME:
return path_main_basename; return path_main_basename;
case RARCH_PATH_CORE_OPTIONS: case RARCH_PATH_CORE_OPTIONS:
if (!path_is_core_options_empty()) if (!path_is_empty(RARCH_PATH_CORE_OPTIONS))
return path_core_options_file; return path_core_options_file;
break; break;
case RARCH_PATH_SUBSYSTEM: case RARCH_PATH_SUBSYSTEM:
return subsystem_path; return subsystem_path;
case RARCH_PATH_CONFIG: case RARCH_PATH_CONFIG:
if (!path_is_config_empty()) if (!path_is_empty(RARCH_PATH_CONFIG))
return path_config_file; return path_config_file;
break; break;
case RARCH_PATH_CONFIG_APPEND: case RARCH_PATH_CONFIG_APPEND:
if (!path_is_config_append_empty()) if (!path_is_empty(RARCH_PATH_CONFIG_APPEND))
return path_config_append_file; return path_config_append_file;
break; break;
case RARCH_PATH_CORE: case RARCH_PATH_CORE:
@ -492,10 +492,6 @@ const char *path_get(enum rarch_path_type type)
return NULL; return NULL;
} }
bool path_is_core_empty(void)
{
return !path_libretro[0];
}
size_t path_get_core_size(void) size_t path_get_core_size(void)
{ {
@ -571,20 +567,31 @@ bool path_set(enum rarch_path_type type, const char *path)
return true; return true;
} }
/* Config file path */ bool path_is_empty(enum rarch_path_type type)
bool path_is_subsystem_empty(void)
{ {
if (string_is_empty(subsystem_path)) switch (type)
return true; {
case RARCH_PATH_SUBSYSTEM:
return false; if (string_is_empty(subsystem_path))
} return true;
break;
bool path_is_config_empty(void) case RARCH_PATH_CONFIG:
{ if (string_is_empty(path_config_file))
if (string_is_empty(path_config_file)) return true;
return true; break;
case RARCH_PATH_CORE_OPTIONS:
if (string_is_empty(path_core_options_file))
return true;
break;
case RARCH_PATH_CONFIG_APPEND:
if (string_is_empty(path_config_append_file))
return true;
break;
case RARCH_PATH_CORE:
return !path_libretro[0];
default:
break;
}
return false; return false;
} }
@ -640,23 +647,9 @@ void path_clear_all(void)
/* Core options file path */ /* Core options file path */
bool path_is_core_options_empty(void)
{
if (string_is_empty(path_core_options_file))
return true;
return false;
}
/* Append config file path */ /* Append config file path */
bool path_is_config_append_empty(void)
{
if (string_is_empty(path_config_append_file))
return true;
return false;
}
bool path_get_content(char **fullpath) bool path_get_content(char **fullpath)
{ {

10
paths.h
View File

@ -96,15 +96,7 @@ void path_clear_all(void);
/* is functions */ /* is functions */
bool path_is_subsystem_empty(void); bool path_is_empty(enum rarch_path_type type);
bool path_is_core_empty(void);
bool path_is_config_empty(void);
bool path_is_core_options_empty(void);
bool path_is_config_append_empty(void);
enum rarch_content_type path_is_media_type(const char *path); enum rarch_content_type path_is_media_type(const char *path);

View File

@ -839,13 +839,13 @@ static void retroarch_parse_input(int argc, char *argv[])
#endif #endif
} }
if (path_is_subsystem_empty() && optind < argc) if (path_is_empty(RARCH_PATH_SUBSYSTEM) && 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(RARCH_PATH_NAMES, (const char*)argv[optind]); path_set(RARCH_PATH_NAMES, (const char*)argv[optind]);
} }
else if (!path_is_subsystem_empty() && optind < argc) else if (!path_is_empty(RARCH_PATH_SUBSYSTEM) && 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);

View File

@ -940,7 +940,7 @@ bool runloop_ctl(enum runloop_ctl_state state, void *data)
if (settings) if (settings)
options_path = settings->path.core_options; options_path = settings->path.core_options;
if (options_path && string_is_empty(options_path) && !path_is_config_empty()) if (options_path && string_is_empty(options_path) && !path_is_empty(RARCH_PATH_CONFIG))
{ {
fill_pathname_resolve_relative(buf, path_get(RARCH_PATH_CONFIG), fill_pathname_resolve_relative(buf, path_get(RARCH_PATH_CONFIG),
file_path_str(FILE_PATH_CORE_OPTIONS_CONFIG), sizeof(buf)); file_path_str(FILE_PATH_CORE_OPTIONS_CONFIG), sizeof(buf));
@ -966,7 +966,7 @@ bool runloop_ctl(enum runloop_ctl_state state, void *data)
/* check if game options file was just created and flush /* check if game options file was just created and flush
to that file instead */ to that file instead */
if(!path_is_core_options_empty()) if(!path_is_empty(RARCH_PATH_CORE_OPTIONS))
{ {
core_option_manager_flush_game_specific(runloop_core_options, core_option_manager_flush_game_specific(runloop_core_options,
path_get(RARCH_PATH_CORE_OPTIONS)); path_get(RARCH_PATH_CORE_OPTIONS));

View File

@ -590,7 +590,7 @@ static const struct retro_subsystem_info *init_content_file_subsystem(bool *ret)
rarch_system_info_t *system = NULL; rarch_system_info_t *system = NULL;
struct string_list *subsystem = path_get_subsystem_list(); struct string_list *subsystem = path_get_subsystem_list();
if (path_is_subsystem_empty()) if (path_is_empty(RARCH_PATH_SUBSYSTEM))
{ {
*ret = true; *ret = true;
return NULL; return NULL;
@ -653,7 +653,7 @@ static bool init_content_file_set_attribs(
attr.i = 0; attr.i = 0;
if (!path_is_subsystem_empty() && special) if (!path_is_empty(RARCH_PATH_SUBSYSTEM) && special)
{ {
unsigned i; unsigned i;
@ -845,7 +845,7 @@ static void menu_content_environment_get(int *argc, char *argv[],
wrap_args->state_path = NULL; wrap_args->state_path = NULL;
wrap_args->content_path = NULL; wrap_args->content_path = NULL;
if (!path_is_config_empty()) if (!path_is_empty(RARCH_PATH_CONFIG))
wrap_args->config_path = path_get(RARCH_PATH_CONFIG); wrap_args->config_path = path_get(RARCH_PATH_CONFIG);
if (!dir_is_savefile_empty()) if (!dir_is_savefile_empty())
wrap_args->sram_path = dir_get_savefile(); wrap_args->sram_path = dir_get_savefile();