diff --git a/paths.c b/paths.c index 8d6f0893df..37a13a403f 100644 --- a/paths.c +++ b/paths.c @@ -27,7 +27,9 @@ #include "paths.h" #include "configuration.h" +#include "command.h" #include "content.h" +#include "dynamic.h" #include "file_path_special.h" #include "core.h" @@ -265,3 +267,101 @@ void path_set_special(char **argv, unsigned num_content) global->name.savestate); } } + +void path_init_savefile(void) +{ + global_t *global = global_get_ptr(); + rarch_system_info_t *system = NULL; + + runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system); + + command_event(CMD_EVENT_SAVEFILES_DEINIT, NULL); + + global->savefiles = string_list_new(); + retro_assert(global->savefiles); + + if (system && !string_is_empty(global->subsystem)) + { + /* For subsystems, we know exactly which RAM types are supported. */ + + unsigned i, j; + const struct retro_subsystem_info *info = + libretro_find_subsystem_info( + system->subsystem.data, + system->subsystem.size, + global->subsystem); + + /* We'll handle this error gracefully later. */ + unsigned num_content = MIN(info ? info->num_roms : 0, + global->subsystem_fullpaths ? + global->subsystem_fullpaths->size : 0); + + bool use_sram_dir = path_is_directory(global->dir.savefile); + + for (i = 0; i < num_content; i++) + { + for (j = 0; j < info->roms[i].num_memory; j++) + { + union string_list_elem_attr attr; + char path[PATH_MAX_LENGTH] = {0}; + char ext[32] = {0}; + const struct retro_subsystem_memory_info *mem = + (const struct retro_subsystem_memory_info*) + &info->roms[i].memory[j]; + + snprintf(ext, sizeof(ext), ".%s", mem->extension); + + if (use_sram_dir) + { + /* Redirect content fullpath to save directory. */ + strlcpy(path, global->dir.savefile, sizeof(path)); + fill_pathname_dir(path, + global->subsystem_fullpaths->elems[i].data, ext, + sizeof(path)); + } + else + { + fill_pathname(path, global->subsystem_fullpaths->elems[i].data, + ext, sizeof(path)); + } + + attr.i = mem->type; + string_list_append(global->savefiles, path, attr); + } + } + + /* Let other relevant paths be inferred from the main SRAM location. */ + if (!retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_SAVE_PATH)) + fill_pathname_noext(global->name.savefile, + global->name.base, + file_path_str(FILE_PATH_SRM_EXTENSION), + sizeof(global->name.savefile)); + + if (path_is_directory(global->name.savefile)) + { + fill_pathname_dir(global->name.savefile, + global->name.base, + file_path_str(FILE_PATH_SRM_EXTENSION), + sizeof(global->name.savefile)); + RARCH_LOG("%s \"%s\".\n", + msg_hash_to_str(MSG_REDIRECTING_SAVEFILE_TO), + global->name.savefile); + } + } + else + { + union string_list_elem_attr attr; + char savefile_name_rtc[PATH_MAX_LENGTH] = {0}; + + attr.i = RETRO_MEMORY_SAVE_RAM; + string_list_append(global->savefiles, global->name.savefile, attr); + + /* Infer .rtc save path from save ram path. */ + attr.i = RETRO_MEMORY_RTC; + fill_pathname(savefile_name_rtc, + global->name.savefile, + file_path_str(FILE_PATH_RTC_EXTENSION), + sizeof(savefile_name_rtc)); + string_list_append(global->savefiles, savefile_name_rtc, attr); + } +} diff --git a/paths.h b/paths.h index cb3449701e..39318cec4a 100644 --- a/paths.h +++ b/paths.h @@ -21,6 +21,8 @@ RETRO_BEGIN_DECLS +void path_init_savefile(void); + void path_set_redirect(void); void path_set_special(char **argv, unsigned num_content); diff --git a/retroarch.c b/retroarch.c index 1be266cf07..d4609ff3af 100644 --- a/retroarch.c +++ b/retroarch.c @@ -890,104 +890,6 @@ static void retroarch_parse_input(int argc, char *argv[]) sizeof(global->dir.savestate)); } -static void retroarch_init_savefile_paths(void) -{ - global_t *global = global_get_ptr(); - rarch_system_info_t *system = NULL; - - runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system); - - command_event(CMD_EVENT_SAVEFILES_DEINIT, NULL); - - global->savefiles = string_list_new(); - retro_assert(global->savefiles); - - if (system && !string_is_empty(global->subsystem)) - { - /* For subsystems, we know exactly which RAM types are supported. */ - - unsigned i, j; - const struct retro_subsystem_info *info = - libretro_find_subsystem_info( - system->subsystem.data, - system->subsystem.size, - global->subsystem); - - /* We'll handle this error gracefully later. */ - unsigned num_content = MIN(info ? info->num_roms : 0, - global->subsystem_fullpaths ? - global->subsystem_fullpaths->size : 0); - - bool use_sram_dir = path_is_directory(global->dir.savefile); - - for (i = 0; i < num_content; i++) - { - for (j = 0; j < info->roms[i].num_memory; j++) - { - union string_list_elem_attr attr; - char path[PATH_MAX_LENGTH] = {0}; - char ext[32] = {0}; - const struct retro_subsystem_memory_info *mem = - (const struct retro_subsystem_memory_info*) - &info->roms[i].memory[j]; - - snprintf(ext, sizeof(ext), ".%s", mem->extension); - - if (use_sram_dir) - { - /* Redirect content fullpath to save directory. */ - strlcpy(path, global->dir.savefile, sizeof(path)); - fill_pathname_dir(path, - global->subsystem_fullpaths->elems[i].data, ext, - sizeof(path)); - } - else - { - fill_pathname(path, global->subsystem_fullpaths->elems[i].data, - ext, sizeof(path)); - } - - attr.i = mem->type; - string_list_append(global->savefiles, path, attr); - } - } - - /* Let other relevant paths be inferred from the main SRAM location. */ - if (!retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_SAVE_PATH)) - fill_pathname_noext(global->name.savefile, - global->name.base, - file_path_str(FILE_PATH_SRM_EXTENSION), - sizeof(global->name.savefile)); - - if (path_is_directory(global->name.savefile)) - { - fill_pathname_dir(global->name.savefile, - global->name.base, - file_path_str(FILE_PATH_SRM_EXTENSION), - sizeof(global->name.savefile)); - RARCH_LOG("%s \"%s\".\n", - msg_hash_to_str(MSG_REDIRECTING_SAVEFILE_TO), - global->name.savefile); - } - } - else - { - union string_list_elem_attr attr; - char savefile_name_rtc[PATH_MAX_LENGTH] = {0}; - - attr.i = RETRO_MEMORY_SAVE_RAM; - string_list_append(global->savefiles, global->name.savefile, attr); - - /* Infer .rtc save path from save ram path. */ - attr.i = RETRO_MEMORY_RTC; - fill_pathname(savefile_name_rtc, - global->name.savefile, - file_path_str(FILE_PATH_RTC_EXTENSION), - sizeof(savefile_name_rtc)); - string_list_append(global->savefiles, savefile_name_rtc, attr); - } -} - static bool retroarch_init_state(void) { video_driver_set_active(); @@ -1395,7 +1297,7 @@ void retroarch_fill_pathnames(void) { global_t *global = global_get_ptr(); - retroarch_init_savefile_paths(); + path_init_savefile(); bsv_movie_set_path(global->name.savefile); if (string_is_empty(global->name.base))