diff --git a/audio/xaudio-c/xaudio.h b/audio/xaudio-c/xaudio.h index 3992d559a1..64a5dd9360 100644 --- a/audio/xaudio-c/xaudio.h +++ b/audio/xaudio-c/xaudio.h @@ -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 diff --git a/file.h b/file.h index 308f74a127..305b9fafae 100644 --- a/file.h +++ b/file.h @@ -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); diff --git a/file_path.c b/file_path.c index c7dbdd08e9..558f1d2e47 100644 --- a/file_path.c +++ b/file_path.c @@ -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); } + diff --git a/settings.c b/settings.c index 02386242f3..ff1810aa17 100644 --- a/settings.c +++ b/settings.c @@ -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);