diff options
| author | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 17:03:13 -0500 |
|---|---|---|
| committer | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 17:03:13 -0500 |
| commit | 85cc694efb619221878ca60f271d60fd62637632 (patch) | |
| tree | 332fd6dd96741e8570563273b30595733846ac37 /runtime/shims/file_system.cpp | |
| parent | fe5b522fa9e992b550f0ecc099f9b6edb058b610 (diff) | |
| parent | 49ea89f201e457ad010c84d1af6baa928a8a1a67 (diff) | |
Merge pull request #3655 from Claude
Diffstat (limited to 'runtime/shims/file_system.cpp')
| -rw-r--r-- | runtime/shims/file_system.cpp | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/runtime/shims/file_system.cpp b/runtime/shims/file_system.cpp index 3675cc73b..b81adb31f 100644 --- a/runtime/shims/file_system.cpp +++ b/runtime/shims/file_system.cpp | |||
| @@ -1002,12 +1002,50 @@ BOOL WINAPI copy_file_ex_a(LPCSTR from, LPCSTR to, LPPROGRESS_ROUTINE progress, | |||
| 1002 | return copy_file_ex_w(wide_from.c_str(), wide_to.c_str(), progress, data, cancel, flags); | 1002 | return copy_file_ex_w(wide_from.c_str(), wide_to.c_str(), progress, data, cancel, flags); |
| 1003 | } | 1003 | } |
| 1004 | 1004 | ||
| 1005 | namespace { | ||
| 1006 | |||
| 1007 | // The host's CopyFile2, or null where the host has none. Wine 9's kernel32 and kernelbase don't export it: Wine's | ||
| 1008 | // loader binds a static import of it to a stub that aborts the process when called ("unimplemented function | ||
| 1009 | // KERNEL32.dll.CopyFile2, aborting"), so a direct ::CopyFile2 call (or MSVC's std::filesystem::copy_file, which uses | ||
| 1010 | // it) kills a title under Wine 9 or a Proton built on it; pe_loader.cpp and loader_tls_test.cpp avoid it for the same | ||
| 1011 | // reason. GetProcAddress returns null there instead, and the fallback below runs. | ||
| 1012 | using CopyFile2Fn = HRESULT(WINAPI*)(PCWSTR, PCWSTR, COPYFILE2_EXTENDED_PARAMETERS*); | ||
| 1013 | CopyFile2Fn host_copy_file2() { | ||
| 1014 | static const CopyFile2Fn fn = [] { | ||
| 1015 | for (const wchar_t* dll : {L"kernelbase.dll", L"kernel32.dll"}) { | ||
| 1016 | if (const HMODULE module = GetModuleHandleW(dll)) | ||
| 1017 | if (const FARPROC p = GetProcAddress(module, "CopyFile2")) return reinterpret_cast<CopyFile2Fn>(p); | ||
| 1018 | } | ||
| 1019 | return CopyFile2Fn{}; | ||
| 1020 | }(); | ||
| 1021 | return fn; | ||
| 1022 | } | ||
| 1023 | |||
| 1024 | // CopyFile2 through CopyFileExW, for hosts without it. The flags both calls define are passed on; the rest are | ||
| 1025 | // CopyFile2-only hints and privilege requests (no offload, compressed traffic, low-free-space mode, ...) that don't | ||
| 1026 | // change what a plain file copy produces, and CopyFileExW refuses flags it doesn't know. The cancel flag has the same | ||
| 1027 | // type in both. A COPYFILE2 progress routine has another signature and message set, so it isn't called here. | ||
| 1028 | HRESULT copy_file2_fallback(const wchar_t* source, const wchar_t* destination, | ||
| 1029 | const COPYFILE2_EXTENDED_PARAMETERS* parameters) { | ||
| 1030 | constexpr DWORD kCopyFileExFlags = COPY_FILE_FAIL_IF_EXISTS | COPY_FILE_RESTARTABLE | | ||
| 1031 | COPY_FILE_OPEN_SOURCE_FOR_WRITE | COPY_FILE_ALLOW_DECRYPTED_DESTINATION | | ||
| 1032 | COPY_FILE_COPY_SYMLINK | COPY_FILE_NO_BUFFERING; | ||
| 1033 | const DWORD flags = parameters ? parameters->dwCopyFlags & kCopyFileExFlags : 0; | ||
| 1034 | BOOL* const cancel = parameters ? parameters->pfCancel : nullptr; | ||
| 1035 | if (::CopyFileExW(source, destination, nullptr, nullptr, cancel, flags)) return S_OK; | ||
| 1036 | const DWORD error = GetLastError(); | ||
| 1037 | return HRESULT_FROM_WIN32(error ? error : ERROR_GEN_FAILURE); | ||
| 1038 | } | ||
| 1039 | |||
| 1040 | } // namespace | ||
| 1041 | |||
| 1005 | HRESULT WINAPI copy_file2(PCWSTR from, PCWSTR to, COPYFILE2_EXTENDED_PARAMETERS* parameters) { | 1042 | HRESULT WINAPI copy_file2(PCWSTR from, PCWSTR to, COPYFILE2_EXTENDED_PARAMETERS* parameters) { |
| 1006 | const bool fail_if_exists = parameters && (parameters->dwCopyFlags & COPY_FILE_FAIL_IF_EXISTS) != 0; | 1043 | const bool fail_if_exists = parameters && (parameters->dwCopyFlags & COPY_FILE_FAIL_IF_EXISTS) != 0; |
| 1007 | std::filesystem::path source, destination; | 1044 | std::filesystem::path source, destination; |
| 1008 | DWORD error = 0; | 1045 | DWORD error = 0; |
| 1009 | if (!copy_paths(from, to, fail_if_exists, source, destination, error)) return HRESULT_FROM_WIN32(error); | 1046 | if (!copy_paths(from, to, fail_if_exists, source, destination, error)) return HRESULT_FROM_WIN32(error); |
| 1010 | return ::CopyFile2(source.c_str(), destination.c_str(), parameters); | 1047 | if (const CopyFile2Fn host = host_copy_file2()) return host(source.c_str(), destination.c_str(), parameters); |
| 1048 | return copy_file2_fallback(source.c_str(), destination.c_str(), parameters); | ||
| 1011 | } | 1049 | } |
| 1012 | 1050 | ||
| 1013 | BOOL WINAPI set_file_attributes_w(LPCWSTR name, DWORD attributes) { | 1051 | BOOL WINAPI set_file_attributes_w(LPCWSTR name, DWORD attributes) { |