Create generic functions for dirs.c

This commit is contained in:
twinaphex 2016-10-03 08:15:41 +02:00
parent 849ce80c50
commit a4d48688c6
7 changed files with 58 additions and 102 deletions

View File

@ -658,9 +658,9 @@ static int populate_settings_path(settings_t *settings, struct config_path_setti
SETTING_PATH("audio_filter_dir",
settings->directory.audio_filter, true, NULL, true);
SETTING_PATH("savefile_directory",
dir_get_savefile_ptr(), true, NULL, false);
dir_get_ptr(RARCH_DIR_SAVEFILE), true, NULL, false);
SETTING_PATH("savestate_directory",
dir_get_savestate_ptr(), true, NULL, false);
dir_get_ptr(RARCH_DIR_SAVESTATE), true, NULL, false);
#ifdef HAVE_MENU
SETTING_PATH("rgui_browser_directory",
settings->directory.menu_content, true, NULL, true);
@ -673,7 +673,7 @@ static int populate_settings_path(settings_t *settings, struct config_path_setti
#endif
#ifdef HAVE_OVERLAY
SETTING_PATH("osk_overlay_directory",
dir_get_osk_overlay_ptr(), true, NULL, true);
dir_get_ptr(RARCH_DIR_OSK_OVERLAY), true, NULL, true);
#endif
#ifndef HAVE_DYNAMIC
SETTING_PATH("libretro_path",
@ -2099,7 +2099,7 @@ static bool config_load_file(const char *path, bool set_defaults,
#ifdef HAVE_OVERLAY
if (string_is_equal(settings->directory.overlay, "default"))
*settings->directory.overlay = '\0';
if (string_is_equal(dir_get_osk_overlay(), "default"))
if (string_is_equal(dir_get(RARCH_DIR_OSK_OVERLAY), "default"))
dir_clear(RARCH_DIR_OSK_OVERLAY);
#endif
if (string_is_equal(settings->directory.system, "default"))

90
dirs.c
View File

@ -259,62 +259,50 @@ void dir_clear_all(void)
/* get ptr functions */
char *dir_get_osk_overlay_ptr(void)
char *dir_get_ptr(enum rarch_dir_type type)
{
return dir_osk_overlay;
switch (type)
{
case RARCH_DIR_OSK_OVERLAY:
return dir_osk_overlay;
case RARCH_DIR_SAVEFILE:
return dir_savefile;
case RARCH_DIR_CURRENT_SAVEFILE:
return current_savefile_dir;
case RARCH_DIR_SAVESTATE:
return dir_savestate;
case RARCH_DIR_CURRENT_SAVESTATE:
return current_savestate_dir;
case RARCH_DIR_SYSTEM:
return dir_system;
case RARCH_DIR_NONE:
break;
}
return NULL;
}
char *dir_get_savefile_ptr(void)
const char *dir_get(enum rarch_dir_type type)
{
return dir_savefile;
}
switch (type)
{
case RARCH_DIR_OSK_OVERLAY:
return dir_osk_overlay;
case RARCH_DIR_SAVEFILE:
return dir_savefile;
case RARCH_DIR_CURRENT_SAVEFILE:
return current_savefile_dir;
case RARCH_DIR_SAVESTATE:
return dir_savestate;
case RARCH_DIR_CURRENT_SAVESTATE:
return current_savestate_dir;
case RARCH_DIR_SYSTEM:
return dir_system;
case RARCH_DIR_NONE:
break;
}
char *dir_get_system_ptr(void)
{
return dir_system;
}
char *dir_get_savestate_ptr(void)
{
return dir_savestate;
}
/* get functions */
const char *dir_get_current_savefile(void)
{
/* try to infer the path in case it's still empty by calling
path_set_redirect */
if (string_is_empty(current_savefile_dir)
&& !content_does_not_need_content())
path_set_redirect();
return current_savefile_dir;
}
const char *dir_get_current_savestate(void)
{
return current_savestate_dir;
}
const char *dir_get_osk_overlay(void)
{
return dir_osk_overlay;
}
const char *dir_get_system(void)
{
return dir_system;
}
const char *dir_get_savefile(void)
{
return dir_savefile;
}
const char *dir_get_savestate(void)
{
return dir_savestate;
return NULL;
}
/* set functions */

36
dirs.h
View File

@ -32,55 +32,23 @@ enum rarch_dir_type
RARCH_DIR_OSK_OVERLAY
};
/* init functions */
bool dir_init_shader(void);
/* free functions */
bool dir_free_shader(void);
/* check functions */
void dir_check_shader(bool pressed_next, bool pressed_prev);
/* empty functions */
bool dir_is_empty(enum rarch_dir_type type);
/* clear functions */
void dir_clear(enum rarch_dir_type type);
void dir_clear_all(void);
size_t dir_get_size(enum rarch_dir_type type);
/* get ptr functions */
char *dir_get_ptr(enum rarch_dir_type type);
char *dir_get_osk_overlay_ptr(void);
char *dir_get_savefile_ptr(void);
char *dir_get_savestate_ptr(void);
char *dir_get_system_ptr(void);
char *dir_get_osk_overlay_ptr(void);
/* get functions */
const char *dir_get_osk_overlay(void);
const char *dir_get_savefile(void);
const char *dir_get_savestate(void);
const char *dir_get_system(void);
const char *dir_get_current_savefile(void);
const char *dir_get_current_savestate(void);
const char *dir_get(enum rarch_dir_type type);
/* set functions */

View File

@ -1037,9 +1037,9 @@ bool rarch_environment_cb(unsigned cmd, void *data)
dir_set_system(temp_path);
}
*(const char**)data = dir_get_system_ptr();
*(const char**)data = dir_get_ptr(RARCH_DIR_SYSTEM);
RARCH_LOG("Environ SYSTEM_DIRECTORY: \"%s\".\n",
dir_get_system());
dir_get(RARCH_DIR_SYSTEM));
}
else
{
@ -1051,7 +1051,7 @@ bool rarch_environment_cb(unsigned cmd, void *data)
break;
case RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY:
*(const char**)data = dir_get_current_savefile();
*(const char**)data = dir_get(RARCH_DIR_CURRENT_SAVEFILE);
break;
case RETRO_ENVIRONMENT_GET_USERNAME:

View File

@ -4810,7 +4810,7 @@ static bool setting_append_list(
sizeof(settings->path.osk_overlay),
msg_hash_to_str(MENU_ENUM_LABEL_KEYBOARD_OVERLAY_PRESET),
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_KEYBOARD_OVERLAY_PRESET),
dir_get_osk_overlay_ptr(),
dir_get_ptr(RARCH_DIR_OSK_OVERLAY),
&group_info,
&subgroup_info,
parent_group,
@ -6502,7 +6502,7 @@ static bool setting_append_list(
CONFIG_DIR(
list, list_info,
dir_get_osk_overlay_ptr(),
dir_get_ptr(RARCH_DIR_OSK_OVERLAY),
dir_get_size(RARCH_DIR_OSK_OVERLAY),
msg_hash_to_str(MENU_ENUM_LABEL_OSK_OVERLAY_DIRECTORY),
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_OSK_OVERLAY_DIRECTORY),
@ -6578,7 +6578,7 @@ static bool setting_append_list(
CONFIG_DIR(
list, list_info,
dir_get_savefile_ptr(),
dir_get_ptr(RARCH_DIR_SAVEFILE),
dir_get_size(RARCH_DIR_SAVEFILE),
msg_hash_to_str(MENU_ENUM_LABEL_SAVEFILE_DIRECTORY),
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SAVEFILE_DIRECTORY),
@ -6593,7 +6593,7 @@ static bool setting_append_list(
CONFIG_DIR(
list, list_info,
dir_get_savestate_ptr(),
dir_get_ptr(RARCH_DIR_SAVESTATE),
dir_get_size(RARCH_DIR_SAVESTATE),
msg_hash_to_str(MENU_ENUM_LABEL_SAVESTATE_DIRECTORY),
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_SAVESTATE_DIRECTORY),

View File

@ -67,8 +67,8 @@ void path_set_redirect(void)
bool check_library_name_hash = false;
rarch_system_info_t *info = NULL;
global_t *global = global_get_ptr();
const char *old_savefile_dir = dir_get_savefile();
const char *old_savestate_dir = dir_get_savestate();
const char *old_savefile_dir = dir_get(RARCH_DIR_SAVEFILE);
const char *old_savestate_dir = dir_get(RARCH_DIR_SAVESTATE);
runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &info);
@ -330,11 +330,11 @@ static bool path_init_subsystem(void)
snprintf(ext, sizeof(ext), ".%s", mem->extension);
if (path_is_directory(dir_get_savefile()))
if (path_is_directory(dir_get(RARCH_DIR_SAVEFILE)))
{
/* Use SRAM dir */
/* Redirect content fullpath to save directory. */
strlcpy(path, dir_get_savefile(), sizeof(path));
strlcpy(path, dir_get(RARCH_DIR_SAVEFILE), sizeof(path));
fill_pathname_dir(path,
subsystem_fullpaths->elems[i].data, ext,
sizeof(path));

View File

@ -848,9 +848,9 @@ static void menu_content_environment_get(int *argc, char *argv[],
if (!path_is_empty(RARCH_PATH_CONFIG))
wrap_args->config_path = path_get(RARCH_PATH_CONFIG);
if (!dir_is_empty(RARCH_DIR_SAVEFILE))
wrap_args->sram_path = dir_get_savefile();
wrap_args->sram_path = dir_get(RARCH_DIR_SAVEFILE);
if (!dir_is_empty(RARCH_DIR_SAVESTATE))
wrap_args->state_path = dir_get_savestate();
wrap_args->state_path = dir_get(RARCH_DIR_SAVESTATE);
if (fullpath && *fullpath)
wrap_args->content_path = fullpath;
if (!retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_LIBRETRO, NULL))