Allow ~/ to be used in config for regular paths on *nix.

This commit is contained in:
Themaister 2012-09-07 22:20:49 +02:00
parent 369431d97d
commit 6a169513c9
4 changed files with 43 additions and 8 deletions

View File

@ -3,7 +3,7 @@
authors: OV2, Themaister
*/
// Kinda stripped down. Only contains the bare essentials used in SSNES.
// Kinda stripped down. Only contains the bare essentials used in RetroArch.
#ifndef XAUDIO2_MINGW_H
#define XAUDIO2_MINGW_H

3
file.h
View File

@ -99,6 +99,9 @@ void fill_pathname_base(char *out_path, const char *in_path, size_t size);
// If in_path is a path without any slashes (relative current directory), out_path will get path ".".
void fill_pathname_basedir(char *out_path, const char *in_path, size_t size);
// Copies string, and attempts to replace magic like ~/, etc with proper paths, like a shell would.
void fill_pathname_shell(char *out_path, const char *in_path, size_t size);
size_t convert_char_to_wchar(wchar_t *out_wchar, const char *in_char, size_t size);
size_t convert_wchar_to_char(char *out_char, const wchar_t *in_wchar, size_t size);

View File

@ -424,6 +424,27 @@ void fill_pathname_basedir(char *out_dir, const char *in_path, size_t size)
}
}
void fill_pathname_shell(char *out_path, const char *in_path, size_t size)
{
#if !defined(_WIN32) && !defined(RARCH_CONSOLE)
if (*in_path == '~')
{
const char *home = getenv("HOME");
if (home)
{
size_t src_size = strlcpy(out_path, home, size);
rarch_assert(src_size < size);
out_path += src_size;
size -= src_size;
in_path++;
}
}
#endif
rarch_assert(strlcpy(out_path, in_path, size) < size);
}
size_t convert_char_to_wchar(wchar_t *out_wchar, const char *in_char, size_t size)
{
return mbstowcs(out_wchar, in_char, size / sizeof(wchar_t));
@ -433,3 +454,4 @@ size_t convert_wchar_to_char(char *out_char, const wchar_t *in_wchar, size_t siz
{
return wcstombs(out_char, in_wchar, size);
}

View File

@ -416,7 +416,8 @@ bool config_load_file(const char *path)
#endif
#if defined(HAVE_XML)
CONFIG_GET_STRING(video.shader_dir, "video_shader_dir");
if (config_get_array(conf, "video_shader_dir", tmp_str, sizeof(tmp_str)))
fill_pathname_shell(g_settings.video.shader_dir, tmp_str, sizeof(g_settings.video.shader_dir));
#endif
CONFIG_GET_FLOAT(input.axis_threshold, "input_axis_threshold");
@ -447,7 +448,9 @@ bool config_load_file(const char *path)
if (!*g_settings.libretro)
CONFIG_GET_STRING(libretro, "libretro_path");
CONFIG_GET_STRING(screenshot_directory, "screenshot_directory");
if (config_get_array(conf, "screenshot_directory", tmp_str, sizeof(tmp_str)))
fill_pathname_shell(g_settings.screenshot_directory, tmp_str, sizeof(g_settings.screenshot_directory));
if (*g_settings.screenshot_directory && !path_is_directory(g_settings.screenshot_directory))
{
RARCH_WARN("screenshot_directory is not an existing directory, ignoring ...\n");
@ -493,9 +496,12 @@ bool config_load_file(const char *path)
if (!g_extern.has_set_save_path && config_get_array(conf, "savefile_directory", tmp_str, sizeof(tmp_str)))
{
if (path_is_directory(tmp_str))
char tmp[PATH_MAX];
fill_pathname_shell(tmp, tmp_str, sizeof(tmp));
if (path_is_directory(tmp))
{
strlcpy(g_extern.savefile_name_srm, tmp_str, sizeof(g_extern.savefile_name_srm));
strlcpy(g_extern.savefile_name_srm, tmp, sizeof(g_extern.savefile_name_srm));
fill_pathname_dir(g_extern.savefile_name_srm, g_extern.basename, ".srm", sizeof(g_extern.savefile_name_srm));
}
else
@ -504,16 +510,20 @@ bool config_load_file(const char *path)
if (!g_extern.has_set_state_path && config_get_array(conf, "savestate_directory", tmp_str, sizeof(tmp_str)))
{
if (path_is_directory(tmp_str))
char tmp[PATH_MAX];
fill_pathname_shell(tmp, tmp_str, sizeof(tmp));
if (path_is_directory(tmp))
{
strlcpy(g_extern.savestate_name, tmp_str, sizeof(g_extern.savestate_name));
strlcpy(g_extern.savestate_name, tmp, sizeof(g_extern.savestate_name));
fill_pathname_dir(g_extern.savestate_name, g_extern.basename, ".state", sizeof(g_extern.savestate_name));
}
else
RARCH_WARN("savestate_directory is not a directory, ignoring ...\n");
}
CONFIG_GET_STRING(system_directory, "system_directory");
if (config_get_array(conf, "system_directory", tmp_str, sizeof(tmp_str)))
fill_pathname_shell(g_settings.system_directory, tmp_str, sizeof(g_settings.system_directory));
config_read_keybinds_conf(conf);