Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove canonicalization in Windows loader #239

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/sdk/pr.239.gh.OpenXR-SDK-Source.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Loader: Fix loader failing to load on Windows 7 due to pathcch dependency.
27 changes: 9 additions & 18 deletions src/common/filesystem_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@
#include <dirent.h>
#endif

#if defined(XR_USE_PLATFORM_WIN32)
#include <pathcch.h>
#endif

#if defined(XR_USE_PLATFORM_WIN32)
#define PATH_SEPARATOR ';'
#define DIRECTORY_SYMBOL '\\'
Expand Down Expand Up @@ -121,14 +117,10 @@ bool FileSysUtilsGetAbsolutePath(const std::string& path, std::string& absolute)

bool FileSysUtilsGetCanonicalPath(const std::string& path, std::string& canonical) {
#if defined(XR_USE_PLATFORM_WIN32)
// std::filesystem::canonical fails on UWP and must be avoided. This alternative will not
// follow symbolic links but symbolic links are not needed on Windows since the loader uses
// the registry as a form of indirection instead.
wchar_t canonical_wide_path[MAX_PATH];
if (FAILED(PathCchCanonicalize(canonical_wide_path, MAX_PATH, utf8_to_wide(path).c_str()))) {
return false;
}
canonical = wide_to_utf8(canonical_wide_path);
// std::filesystem::canonical fails on UWP and must be avoided. Further, PathCchCanonicalize is not available on Windows 7 and
// PathCanonicalizeW is not available on UWP. However, symbolic links are not important on Windows since the loader uses the
// registry for indirection instead, and so this function can be a no-op on Windows.
canonical = path;
#else
canonical = FS_PREFIX::canonical(path).string();
#endif
Expand Down Expand Up @@ -218,12 +210,11 @@ bool FileSysUtilsGetAbsolutePath(const std::string& path, std::string& absolute)
}

bool FileSysUtilsGetCanonicalPath(const std::string& path, std::string& absolute) {
wchar_t tmp_path[MAX_PATH];
if (SUCCEEDED(PathCchCanonicalize(tmp_path, MAX_PATH, utf8_to_wide(path).c_str()))) {
absolute = wide_to_utf8(tmp_path);
return true;
}
return false;
// PathCchCanonicalize is not available on Windows 7 and PathCanonicalizeW is not available on UWP. However, symbolic links are
// not important on Windows since the loader uses the registry for indirection instead, and so this function can be a no-op on
// Windows.
absolute = path;
return true;
}

bool FileSysUtilsCombinePaths(const std::string& parent, const std::string& child, std::string& combined) {
Expand Down
2 changes: 1 addition & 1 deletion src/loader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ elseif(WIN32)
target_compile_options(openxr_loader PRIVATE /wd6386)
endif()

target_link_libraries(openxr_loader PUBLIC advapi32 pathcch)
target_link_libraries(openxr_loader PUBLIC advapi32)

# Need to copy DLL to client directories so clients can easily load it.
if(DYNAMIC_LOADER AND (CMAKE_GENERATOR MATCHES "^Visual Studio.*"))
Expand Down