|
87 | 87 | #include <dirent.h> |
88 | 88 | #endif |
89 | 89 |
|
| 90 | +#if defined(XR_USE_PLATFORM_WIN32) |
| 91 | +#include <PathCch.h> |
| 92 | +#endif |
| 93 | + |
90 | 94 | #if defined(XR_USE_PLATFORM_WIN32) |
91 | 95 | #define PATH_SEPARATOR ';' |
92 | 96 | #define DIRECTORY_SYMBOL '\\' |
@@ -128,7 +132,18 @@ bool FileSysUtilsGetAbsolutePath(const std::string& path, std::string& absolute) |
128 | 132 | } |
129 | 133 |
|
130 | 134 | bool FileSysUtilsGetCanonicalPath(const std::string& path, std::string& canonical) { |
| 135 | +#if defined(XR_USE_PLATFORM_WIN32) |
| 136 | + // std::filesystem::canonical fails on UWP and must be avoided. This alternative will not |
| 137 | + // follow symbolic links but symbolic links are not needed on Windows since the loader uses |
| 138 | + // the registry as a form of indirection instead. |
| 139 | + wchar_t canonical_wide_path[MAX_PATH]; |
| 140 | + if (FAILED(PathCchCanonicalize(canonical_wide_path, MAX_PATH, utf8_to_wide(path).c_str()))) { |
| 141 | + return false; |
| 142 | + } |
| 143 | + canonical = wide_to_utf8(canonical_wide_path); |
| 144 | +#else |
131 | 145 | canonical = FS_PREFIX::canonical(path).string(); |
| 146 | +#endif |
132 | 147 | return true; |
133 | 148 | } |
134 | 149 |
|
@@ -216,7 +231,7 @@ bool FileSysUtilsGetAbsolutePath(const std::string& path, std::string& absolute) |
216 | 231 |
|
217 | 232 | bool FileSysUtilsGetCanonicalPath(const std::string& path, std::string& absolute) { |
218 | 233 | wchar_t tmp_path[MAX_PATH]; |
219 | | - if (0 != PathCanonicalizeW(utf8_to_wide(path).c_str(), tmp_path)) { |
| 234 | + if (SUCCEEDED(PathCchCanonicalize(tmp_path, MAX_PATH, utf8_to_wide(path).c_str()))) { |
220 | 235 | absolute = wide_to_utf8(tmp_path); |
221 | 236 | return true; |
222 | 237 | } |
|
0 commit comments