Skip to content

Commit

Permalink
Allow ~/ to be used in config for regular paths on *nix.
Browse files Browse the repository at this point in the history
  • Loading branch information
Themaister committed Sep 7, 2012
1 parent 369431d commit 6a16951
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
2 changes: 1 addition & 1 deletion audio/xaudio-c/xaudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions file.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
22 changes: 22 additions & 0 deletions file_path.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);
}

24 changes: 17 additions & 7 deletions settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand All @@ -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);

Expand Down

0 comments on commit 6a16951

Please sign in to comment.