@@ -21,6 +21,8 @@ std::filesystem::path g_reshade_dll_path;
2121std::filesystem::path g_reshade_base_path;
2222std::filesystem::path g_target_executable_path;
2323
24+ extern bool resolve_path (std::filesystem::path &path, std::error_code &ec, const std::filesystem::path &base);
25+
2426// / <summary>
2527// / Checks whether the current application is an UWP app.
2628// / </summary>
@@ -47,42 +49,22 @@ bool is_windows7()
4749 return VerifyVersionInfo (&verinfo_windows7, VER_MAJORVERSION | VER_MINORVERSION, condition) != FALSE ;
4850}
4951
50- // / <summary>
51- // / Expands any environment variables in the path (like "%USERPROFILE%") and checks whether it points towards an existing directory.
52- // / </summary>
53- static bool resolve_env_path (std::filesystem::path &path, const std::filesystem::path &base = g_reshade_dll_path.parent_path())
54- {
55- if (path.empty ())
56- return false ;
57-
58- WCHAR buf[4096 ];
59- if (ExpandEnvironmentStringsW (path.c_str (), buf, ARRAYSIZE (buf)))
60- path = buf;
61- else
62- return false ;
63-
64- path = base / path;
65-
66- std::error_code ec;
67- path = std::filesystem::canonical (path, ec);
68- return !ec && std::filesystem::is_directory (path, ec);
69- }
70-
7152// / <summary>
7253// / Returns the path that should be used as base for relative paths.
7354// / </summary>
7455std::filesystem::path get_base_path (bool default_to_target_executable_path = false )
7556{
57+ std::error_code ec;
7658 std::filesystem::path path_override;
7759
7860 // Cannot use global config here yet, since it uses base path for look up, so look at config file next to target executable instead
7961 if (reshade::ini_file::load_cache (g_target_executable_path.parent_path () / L" ReShade.ini" ).get (" INSTALL" , " BasePath" , path_override) &&
80- resolve_env_path (path_override))
62+ resolve_path (path_override, ec, g_reshade_dll_path. parent_path ()) && std::filesystem::is_directory (path_override, ec ))
8163 return path_override;
8264
8365 WCHAR buf[4096 ];
8466 path_override.assign (buf, buf + GetEnvironmentVariableW (L" RESHADE_BASE_PATH_OVERRIDE" , buf, ARRAYSIZE (buf)));
85- if (resolve_env_path (path_override))
67+ if (resolve_path (path_override, ec, g_reshade_dll_path. parent_path ()) && std::filesystem::is_directory (path_override, ec ))
8668 return path_override;
8769
8870 return default_to_target_executable_path ? g_target_executable_path.parent_path () : g_reshade_dll_path.parent_path ();
0 commit comments