diff options
Diffstat (limited to 'runtime/shims/file_system.cpp')
| -rw-r--r-- | runtime/shims/file_system.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/runtime/shims/file_system.cpp b/runtime/shims/file_system.cpp index 4175156e8..b77697334 100644 --- a/runtime/shims/file_system.cpp +++ b/runtime/shims/file_system.cpp | |||
| @@ -142,6 +142,26 @@ std::filesystem::path win32_io_path(const std::filesystem::path& path) { | |||
| 142 | return std::filesystem::path(L"\\\\?\\" + full); | 142 | return std::filesystem::path(L"\\\\?\\" + full); |
| 143 | } | 143 | } |
| 144 | 144 | ||
| 145 | std::filesystem::path win32_find_path(const std::filesystem::path& path, const std::wstring& leaf) { | ||
| 146 | if (path.native().size() < MAX_PATH) return path; | ||
| 147 | const auto search = win32_io_path(path); | ||
| 148 | if (search == path || !leaf.ends_with(L'.') || leaf.find_first_of(L"*?") == std::wstring::npos) return search; | ||
| 149 | |||
| 150 | // GetFullPathNameW strips a terminal dot, but that dot changes a native Win32 search (e.g. "mesh*."). | ||
| 151 | // Preserve the DOS wildcard expression for the extended path and let the filesystem match it, including | ||
| 152 | // short names. The DOS_STAR, DOS_QM and DOS_DOT tokens are defined by MS-FSA 2.1.4.3-4. | ||
| 153 | std::wstring mask = search.filename().native(); | ||
| 154 | if (mask.ends_with(L'*')) mask.back() = L'<'; | ||
| 155 | else mask.push_back(L'"'); | ||
| 156 | for (size_t i = 0; i + 1 < mask.size(); ++i) { | ||
| 157 | const wchar_t next = mask[i + 1]; | ||
| 158 | if (mask[i] == L'?') mask[i] = L'>'; | ||
| 159 | else if (mask[i] == L'*' && next == L'.') mask[i] = L'<'; | ||
| 160 | else if (mask[i] == L'.' && (next == L'*' || next == L'?' || next == L'<')) mask[i] = L'"'; | ||
| 161 | } | ||
| 162 | return search.parent_path() / mask; | ||
| 163 | } | ||
| 164 | |||
| 145 | // "G:\x" is the installed package, like "GAME:\x", and "T:\x" a scratch folder the title may write to, the way the | 165 | // "G:\x" is the installed package, like "GAME:\x", and "T:\x" a scratch folder the title may write to, the way the |
| 146 | // other console layers map those two drives (RT-218). Only the executable can say which spelling the title uses, so | 166 | // other console layers map those two drives (RT-218). Only the executable can say which spelling the title uses, so |
| 147 | // a host drive of the same letter must keep working: a path under --game-dir or the overlay (a package on drive G:, | 167 | // a host drive of the same letter must keep working: a path under --game-dir or the overlay (a package on drive G:, |
| @@ -610,7 +630,7 @@ bool collect(const std::wstring& pattern, const std::vector<std::wstring>& parts | |||
| 610 | auto add_root = [&](const std::filesystem::path& root, bool overlay_root) { | 630 | auto add_root = [&](const std::filesystem::path& root, bool overlay_root) { |
| 611 | if (root.empty()) return; | 631 | if (root.empty()) return; |
| 612 | WIN32_FIND_DATAW found{}; | 632 | WIN32_FIND_DATAW found{}; |
| 613 | const HANDLE h = ::FindFirstFileW(win32_io_path(join(root, dirs) / leaf).c_str(), &found); | 633 | const HANDLE h = ::FindFirstFileW(win32_find_path(join(root, dirs) / leaf, leaf).c_str(), &found); |
| 614 | if (h == INVALID_HANDLE_VALUE) return; | 634 | if (h == INVALID_HANDLE_VALUE) return; |
| 615 | do { | 635 | do { |
| 616 | if (overlay_root && internal_dir(found.cFileName)) continue; | 636 | if (overlay_root && internal_dir(found.cFileName)) continue; |