From 9b65924898541aa981fdee23b835a58ad0090fff Mon Sep 17 00:00:00 2001 From: ergo720 <45463469+ergo720@users.noreply.github.com> Date: Thu, 7 Oct 2021 22:26:37 +0200 Subject: [PATCH] Added workaround for dokany bug when reading files inside xisos mounted by xbox-iso-vfs --- src/common/FilePaths.hpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/common/FilePaths.hpp b/src/common/FilePaths.hpp index 36486aada..8de99a862 100644 --- a/src/common/FilePaths.hpp +++ b/src/common/FilePaths.hpp @@ -30,8 +30,17 @@ static inline void CxbxResolveHostToFullPath(std::filesystem::path& file_path, std::string_view finish_error_sentence) { std::error_code error; std::filesystem::path sanityPath = std::filesystem::canonical(file_path, error); - if (error.value() != 0) { - CxbxrKrnlAbortEx(LOG_PREFIX_INIT, "Could not resolve to %s: %s", finish_error_sentence.data(), file_path.string().c_str()); + if (error) { + + // The MS implementation of std::filesystem::canonical internally calls GetFinalPathNameByHandleW, which fails with ERROR_FILE_NOT_FOUND when called + // on a file inside a mounted xiso under Windows with the xbox-iso-vfs tool because of this known dokany bug https://github.com/dokan-dev/dokany/issues/343 + EmuLogInit(LOG_LEVEL::WARNING, "Could not resolve to %s: %s, dokany in use? The error was: %s", + finish_error_sentence.data(), file_path.string().c_str(), error.message().c_str()); + + sanityPath = std::filesystem::absolute(std::filesystem::weakly_canonical(file_path, error), error); + if (error) { + CxbxrKrnlAbortEx(LOG_PREFIX_INIT, "Could not resolve to %s: %s. The error was: %s", finish_error_sentence.data(), file_path.string().c_str(), error.message().c_str()); + } } file_path = sanityPath; }