mirror of
https://github.com/libretro/RetroArch
synced 2024-07-08 20:25:47 +00:00
Add more functions to paths.c
This commit is contained in:
parent
005b86eb5d
commit
069dbce5c5
167
paths.c
167
paths.c
|
@ -15,6 +15,8 @@
|
|||
|
||||
#include <compat/strl.h>
|
||||
#include <file/file_path.h>
|
||||
#include <string/stdstring.h>
|
||||
#include <retro_stat.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
|
@ -22,7 +24,160 @@
|
|||
|
||||
#include "paths.h"
|
||||
|
||||
#include "configuration.h"
|
||||
#include "content.h"
|
||||
#include "file_path_special.h"
|
||||
|
||||
#include "core.h"
|
||||
#include "msg_hash.h"
|
||||
#include "runloop.h"
|
||||
#include "verbosity.h"
|
||||
|
||||
#define MENU_VALUE_NO_CORE 0x7d5472cbU
|
||||
|
||||
static char current_savefile_dir[PATH_MAX_LENGTH] = {0};
|
||||
|
||||
void path_set_redirect(void)
|
||||
{
|
||||
char current_savestate_dir[PATH_MAX_LENGTH] = {0};
|
||||
uint32_t global_library_name_hash = 0;
|
||||
bool check_global_library_name_hash = false;
|
||||
global_t *global = global_get_ptr();
|
||||
settings_t *settings = config_get_ptr();
|
||||
rarch_system_info_t *info = NULL;
|
||||
|
||||
runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &info);
|
||||
|
||||
if (!global)
|
||||
return;
|
||||
|
||||
if (info->info.library_name &&
|
||||
!string_is_empty(info->info.library_name))
|
||||
global_library_name_hash =
|
||||
msg_hash_calculate(info->info.library_name);
|
||||
|
||||
/* Initialize current save directories
|
||||
* with the values from the config. */
|
||||
strlcpy(current_savefile_dir,
|
||||
global->dir.savefile,
|
||||
sizeof(current_savefile_dir));
|
||||
strlcpy(current_savestate_dir,
|
||||
global->dir.savestate,
|
||||
sizeof(current_savestate_dir));
|
||||
|
||||
check_global_library_name_hash = (global_library_name_hash != 0);
|
||||
#ifdef HAVE_MENU
|
||||
check_global_library_name_hash = check_global_library_name_hash &&
|
||||
(global_library_name_hash != MENU_VALUE_NO_CORE);
|
||||
#endif
|
||||
|
||||
if (check_global_library_name_hash)
|
||||
{
|
||||
/* per-core saves: append the library_name to the save location */
|
||||
if (settings->sort_savefiles_enable
|
||||
&& !string_is_empty(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(current_savefile_dir)
|
||||
&& !string_is_empty(current_savefile_dir))
|
||||
{
|
||||
path_mkdir(current_savefile_dir);
|
||||
if(!path_is_directory(current_savefile_dir))
|
||||
{
|
||||
RARCH_LOG("%s %s\n",
|
||||
msg_hash_to_str(MSG_REVERTING_SAVEFILE_DIRECTORY_TO),
|
||||
global->dir.savefile);
|
||||
|
||||
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
|
||||
&& !string_is_empty(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(current_savestate_dir) &&
|
||||
!string_is_empty(current_savestate_dir))
|
||||
{
|
||||
path_mkdir(current_savestate_dir);
|
||||
if(!path_is_directory(current_savestate_dir))
|
||||
{
|
||||
RARCH_LOG("%s %s\n",
|
||||
msg_hash_to_str(MSG_REVERTING_SAVESTATE_DIRECTORY_TO),
|
||||
global->dir.savestate);
|
||||
strlcpy(current_savestate_dir,
|
||||
global->dir.savestate,
|
||||
sizeof(current_savestate_dir));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Set savefile directory if empty based on content directory */
|
||||
if (string_is_empty(current_savefile_dir))
|
||||
{
|
||||
global_t *global = global_get_ptr();
|
||||
strlcpy(current_savefile_dir, global->name.base,
|
||||
sizeof(current_savefile_dir));
|
||||
path_basedir(current_savefile_dir);
|
||||
}
|
||||
|
||||
if(path_is_directory(current_savefile_dir))
|
||||
strlcpy(global->name.savefile, current_savefile_dir,
|
||||
sizeof(global->name.savefile));
|
||||
|
||||
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))
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
if (path_is_directory(global->name.savestate))
|
||||
{
|
||||
fill_pathname_dir(global->name.savestate, global->name.base,
|
||||
file_path_str(FILE_PATH_STATE_EXTENSION),
|
||||
sizeof(global->name.savestate));
|
||||
RARCH_LOG("%s \"%s\".\n",
|
||||
msg_hash_to_str(MSG_REDIRECTING_SAVESTATE_TO),
|
||||
global->name.savestate);
|
||||
}
|
||||
|
||||
if (path_is_directory(global->name.cheatfile))
|
||||
{
|
||||
fill_pathname_dir(global->name.cheatfile, global->name.base,
|
||||
file_path_str(FILE_PATH_STATE_EXTENSION),
|
||||
sizeof(global->name.cheatfile));
|
||||
RARCH_LOG("%s \"%s\".\n",
|
||||
msg_hash_to_str(MSG_REDIRECTING_CHEATFILE_TO),
|
||||
global->name.cheatfile);
|
||||
}
|
||||
}
|
||||
|
||||
void path_set_basename(const char *path)
|
||||
{
|
||||
|
@ -59,3 +214,15 @@ void path_set_basename(const char *path)
|
|||
if ((dst = strrchr(global->name.base, '.')))
|
||||
*dst = '\0';
|
||||
}
|
||||
|
||||
const char *path_get_current_savefile_dir(void)
|
||||
{
|
||||
char *ret = current_savefile_dir;
|
||||
|
||||
/* try to infer the path in case it's still empty by calling
|
||||
path_set_redirect */
|
||||
if (string_is_empty(ret) && !content_does_not_need_content())
|
||||
path_set_redirect();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
4
paths.h
4
paths.h
|
@ -21,8 +21,12 @@
|
|||
|
||||
RETRO_BEGIN_DECLS
|
||||
|
||||
void path_set_redirect(void);
|
||||
|
||||
void path_set_basename(const char *path);
|
||||
|
||||
const char *path_get_current_savefile_dir(void);
|
||||
|
||||
RETRO_END_DECLS
|
||||
|
||||
#endif
|
||||
|
|
161
retroarch.c
161
retroarch.c
|
@ -113,7 +113,6 @@ enum
|
|||
static bool current_core_explicitly_set = false;
|
||||
static enum rarch_core_type current_core_type = CORE_TYPE_PLAIN;
|
||||
static enum rarch_core_type explicit_current_core_type = CORE_TYPE_PLAIN;
|
||||
static char current_savefile_dir[PATH_MAX_LENGTH] = {0};
|
||||
static char error_string[PATH_MAX_LENGTH] = {0};
|
||||
static jmp_buf error_sjlj_context;
|
||||
|
||||
|
@ -375,162 +374,6 @@ static void retroarch_set_special_paths(char **argv, unsigned num_content)
|
|||
}
|
||||
}
|
||||
|
||||
#define MENU_VALUE_NO_CORE 0x7d5472cbU
|
||||
|
||||
static void retroarch_set_paths_redirect(void)
|
||||
{
|
||||
char current_savestate_dir[PATH_MAX_LENGTH] = {0};
|
||||
uint32_t global_library_name_hash = 0;
|
||||
bool check_global_library_name_hash = false;
|
||||
global_t *global = global_get_ptr();
|
||||
settings_t *settings = config_get_ptr();
|
||||
rarch_system_info_t *info = NULL;
|
||||
|
||||
runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &info);
|
||||
|
||||
if (!global)
|
||||
return;
|
||||
|
||||
if (info->info.library_name &&
|
||||
!string_is_empty(info->info.library_name))
|
||||
global_library_name_hash =
|
||||
msg_hash_calculate(info->info.library_name);
|
||||
|
||||
/* Initialize current save directories
|
||||
* with the values from the config. */
|
||||
strlcpy(current_savefile_dir,
|
||||
global->dir.savefile,
|
||||
sizeof(current_savefile_dir));
|
||||
strlcpy(current_savestate_dir,
|
||||
global->dir.savestate,
|
||||
sizeof(current_savestate_dir));
|
||||
|
||||
check_global_library_name_hash = (global_library_name_hash != 0);
|
||||
#ifdef HAVE_MENU
|
||||
check_global_library_name_hash = check_global_library_name_hash &&
|
||||
(global_library_name_hash != MENU_VALUE_NO_CORE);
|
||||
#endif
|
||||
|
||||
if (check_global_library_name_hash)
|
||||
{
|
||||
/* per-core saves: append the library_name to the save location */
|
||||
if (settings->sort_savefiles_enable
|
||||
&& !string_is_empty(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(current_savefile_dir)
|
||||
&& !string_is_empty(current_savefile_dir))
|
||||
{
|
||||
path_mkdir(current_savefile_dir);
|
||||
if(!path_is_directory(current_savefile_dir))
|
||||
{
|
||||
RARCH_LOG("%s %s\n",
|
||||
msg_hash_to_str(MSG_REVERTING_SAVEFILE_DIRECTORY_TO),
|
||||
global->dir.savefile);
|
||||
|
||||
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
|
||||
&& !string_is_empty(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(current_savestate_dir) &&
|
||||
!string_is_empty(current_savestate_dir))
|
||||
{
|
||||
path_mkdir(current_savestate_dir);
|
||||
if(!path_is_directory(current_savestate_dir))
|
||||
{
|
||||
RARCH_LOG("%s %s\n",
|
||||
msg_hash_to_str(MSG_REVERTING_SAVESTATE_DIRECTORY_TO),
|
||||
global->dir.savestate);
|
||||
strlcpy(current_savestate_dir,
|
||||
global->dir.savestate,
|
||||
sizeof(current_savestate_dir));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Set savefile directory if empty based on content directory */
|
||||
if (string_is_empty(current_savefile_dir))
|
||||
{
|
||||
global_t *global = global_get_ptr();
|
||||
strlcpy(current_savefile_dir, global->name.base,
|
||||
sizeof(current_savefile_dir));
|
||||
path_basedir(current_savefile_dir);
|
||||
}
|
||||
|
||||
if(path_is_directory(current_savefile_dir))
|
||||
strlcpy(global->name.savefile, current_savefile_dir,
|
||||
sizeof(global->name.savefile));
|
||||
|
||||
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))
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
if (path_is_directory(global->name.savestate))
|
||||
{
|
||||
fill_pathname_dir(global->name.savestate, global->name.base,
|
||||
file_path_str(FILE_PATH_STATE_EXTENSION),
|
||||
sizeof(global->name.savestate));
|
||||
RARCH_LOG("%s \"%s\".\n",
|
||||
msg_hash_to_str(MSG_REDIRECTING_SAVESTATE_TO),
|
||||
global->name.savestate);
|
||||
}
|
||||
|
||||
if (path_is_directory(global->name.cheatfile))
|
||||
{
|
||||
fill_pathname_dir(global->name.cheatfile, global->name.base,
|
||||
file_path_str(FILE_PATH_STATE_EXTENSION),
|
||||
sizeof(global->name.cheatfile));
|
||||
RARCH_LOG("%s \"%s\".\n",
|
||||
msg_hash_to_str(MSG_REDIRECTING_CHEATFILE_TO),
|
||||
global->name.cheatfile);
|
||||
}
|
||||
}
|
||||
|
||||
const char *retroarch_get_current_savefile_dir(void)
|
||||
{
|
||||
char *ret = current_savefile_dir;
|
||||
|
||||
/* try to infer the path in case it's still empty by calling
|
||||
set_paths_redirect */
|
||||
if (string_is_empty(ret) && !content_does_not_need_content())
|
||||
retroarch_set_paths_redirect();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
enum rarch_content_type retroarch_path_is_media_type(const char *path)
|
||||
{
|
||||
char ext_lower[PATH_MAX_LENGTH] = {0};
|
||||
|
@ -1502,7 +1345,7 @@ bool rarch_ctl(enum rarch_ctl_state state, void *data)
|
|||
case RARCH_CTL_SET_PATHS_REDIRECT:
|
||||
if (content_does_not_need_content())
|
||||
return false;
|
||||
retroarch_set_paths_redirect();
|
||||
path_set_redirect();
|
||||
break;
|
||||
case RARCH_CTL_SET_SRAM_ENABLE:
|
||||
{
|
||||
|
@ -1581,7 +1424,7 @@ void retroarch_set_pathnames(const char *path)
|
|||
fill_pathname_noext(global->name.cheatfile, global->name.base,
|
||||
file_path_str(FILE_PATH_CHT_EXTENSION), sizeof(global->name.cheatfile));
|
||||
|
||||
retroarch_set_paths_redirect();
|
||||
path_set_redirect();
|
||||
}
|
||||
|
||||
void retroarch_fill_pathnames(void)
|
||||
|
|
Loading…
Reference in New Issue
Block a user