Skip to content

Commit

Permalink
Remove canonicalization in Windows loader (#239)
Browse files Browse the repository at this point in the history
* Remove canonicalization in Windows loader

* Add change fragment

* Remove submodule
  • Loading branch information
brycehutchings authored Feb 11, 2021
1 parent dc2de7f commit d5721f1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
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

0 comments on commit d5721f1

Please sign in to comment.