cleaner implementation of save file / save state sorting

This commit is contained in:
radius 2015-10-19 19:43:21 -05:00
parent 34cf3c6a13
commit a0fe04ead5
4 changed files with 56 additions and 75 deletions

View File

@ -549,14 +549,6 @@ static void event_deinit_core(bool reinit)
if (reinit)
event_command(EVENT_CMD_DRIVERS_DEINIT);
/* per-core saves: restore the original path so the config is not affected */
if(settings->sort_savefiles_enable)
strlcpy(global->dir.savefile, orig_savefile_dir,
sizeof(global->dir.savefile));
if(settings->sort_savestates_enable)
strlcpy(global->dir.savestate, orig_savestate_dir,
sizeof(global->dir.savestate));
/* auto overrides: reload the original config */
if(global->overrides_active)
{
@ -727,14 +719,6 @@ static bool event_init_core(void)
driver_t *driver = driver_get_ptr();
settings_t *settings = config_get_ptr();
/* per-core saves: save the original path */
if(orig_savefile_dir[0] == '\0')
strlcpy(orig_savefile_dir, global->dir.savefile,
sizeof(orig_savefile_dir));
if(orig_savestate_dir[0] == '\0')
strlcpy(orig_savestate_dir, global->dir.savestate,
sizeof(orig_savestate_dir));
/* auto overrides: apply overrides */
if(settings->auto_overrides_enable)
{

View File

@ -41,14 +41,6 @@ void main_exit_save_config(void)
if (settings->config_save_on_exit && *global->path.config)
{
/* restore original paths in case per-core organization is enabled */
if (settings->sort_savefiles_enable && orig_savefile_dir[0] != '\0')
strlcpy(global->dir.savefile, orig_savefile_dir,
sizeof(global->dir.savefile));
if (settings->sort_savestates_enable && orig_savestate_dir[0] != '\0')
strlcpy(global->dir.savestate, orig_savestate_dir,
sizeof(global->dir.savestate));
/* Save last core-specific config to the default config location,
* needed on consoles for core switching and reusing last good
* config for new cores.

View File

@ -54,8 +54,9 @@
#include "menu/menu_hash.h"
#endif
char orig_savestate_dir[PATH_MAX_LENGTH];
char orig_savefile_dir[PATH_MAX_LENGTH];
char current_savestate_dir[PATH_MAX_LENGTH];
char current_savefile_dir[PATH_MAX_LENGTH];
/* Descriptive names for options without short variant. Please keep the name in
sync with the option name. Order does not matter. */
@ -333,62 +334,66 @@ void set_paths_redirect(const char *path)
/* per-core saves: append the library_name to the save location */
if (settings->sort_savefiles_enable && global->dir.savefile[0] != '\0')
{
strlcpy(orig_savefile_dir,global->dir.savefile,
sizeof(orig_savefile_dir));
fill_pathname_dir(
global->dir.savefile,
fill_pathname_join(
current_savefile_dir,
global->dir.savefile,
info->info.library_name,
sizeof(global->dir.savefile));
/* If path doesn't exist, try to create it,
* if everything fails revert to the original path. */
if(!path_is_directory(global->dir.savefile) && global->dir.savefile[0] != '\0')
if(!path_is_directory(current_savefile_dir) && current_savefile_dir[0] != '\0')
{
path_mkdir(global->dir.savefile);
if(!path_is_directory(global->dir.savefile))
path_mkdir(current_savefile_dir);
if(!path_is_directory(current_savefile_dir))
{
RARCH_LOG("Reverting savefile directory to %s\n", orig_savefile_dir);
strlcpy(global->dir.savefile,
orig_savefile_dir,
sizeof(global->dir.savefile));
RARCH_LOG("Reverting savefile directory to %s\n", global->dir.savefile);
strlcpy(current_savefile_dir,
global->dir.savefile,
sizeof(current_savefile_dir));
}
}
}
else
strlcpy(current_savefile_dir,
global->dir.savefile,
sizeof(current_savefile_dir));
/* per-core states: append the library_name to the save location */
if (settings->sort_savestates_enable && global->dir.savestate[0] != '\0')
{
strlcpy(orig_savestate_dir,
global->dir.savestate,
sizeof(orig_savestate_dir));
fill_pathname_dir(global->dir.savestate,
fill_pathname_join(
current_savestate_dir,
global->dir.savestate,
info->info.library_name,
sizeof(global->dir.savestate));
/* If path doesn't exist, try to create it.
* If everything fails, revert to the original path. */
if(!path_is_directory(global->dir.savestate) && global->dir.savestate[0] != '\0')
if(!path_is_directory(current_savestate_dir) && current_savestate_dir[0] != '\0')
{
path_mkdir(global->dir.savestate);
if(!path_is_directory(global->dir.savestate))
path_mkdir(current_savestate_dir);
if(!path_is_directory(current_savestate_dir))
{
RARCH_LOG("Reverting savestate directory to %s\n", orig_savestate_dir);
strlcpy(global->dir.savestate,
orig_savestate_dir,
sizeof(global->dir.savestate));
RARCH_LOG("Reverting savestate directory to %s\n", global->dir.savestate);
strlcpy(current_savestate_dir,
global->dir.savestate,
sizeof(current_savestate_dir));
}
}
}
else
strlcpy(current_savestate_dir,
global->dir.savestate,
sizeof(current_savestate_dir));
}
if(path_is_directory(global->dir.savefile))
strlcpy(global->name.savefile, global->dir.savefile,
if(path_is_directory(current_savefile_dir))
strlcpy(global->name.savefile, current_savefile_dir,
sizeof(global->name.savefile));
if(path_is_directory(global->dir.savestate))
strlcpy(global->name.savestate, global->dir.savestate,
if(path_is_directory(current_savestate_dir))
strlcpy(global->name.savestate, current_savestate_dir,
sizeof(global->name.savestate));
if (path_is_directory(global->name.savefile))

View File

@ -207,8 +207,8 @@ int rarch_info_get_capabilities(enum rarch_capabilities type, char *s, size_t le
enum rarch_content_type rarch_path_is_media_type(const char *path);
extern char orig_savestate_dir[PATH_MAX_LENGTH];
extern char orig_savefile_dir[PATH_MAX_LENGTH];
extern char current_savestate_dir[PATH_MAX_LENGTH];
extern char current_savefile_dir[PATH_MAX_LENGTH];
extern bool orig_system_dir_empty;
#ifdef __cplusplus