From fa315a9f645bb1373a5067e680eecbe06ed77ef0 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Sun, 21 Dec 2025 12:13:05 +0100 Subject: [PATCH] Adopt long path changes from !5054 --- components/files/windowspath.cpp | 34 ++++++++++++++++++++++---------- components/files/wineutils.hpp | 2 +- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/components/files/windowspath.cpp b/components/files/windowspath.cpp index 827ef7cc95..b6b5001774 100644 --- a/components/files/windowspath.cpp +++ b/components/files/windowspath.cpp @@ -44,15 +44,23 @@ namespace Files if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, subKey, 0, flags, &key.mKey) == ERROR_SUCCESS) { // Key existed, let's try to read the install dir - std::array buf{}; - DWORD len = static_cast(buf.size() * sizeof(wchar_t)); + std::wstring buffer; + buffer.reserve(MAX_PATH); + DWORD len = static_cast(MAX_PATH * sizeof(wchar_t)); - if (RegQueryValueExW(key.mKey, valueName, nullptr, nullptr, reinterpret_cast(buf.data()), &len) - == ERROR_SUCCESS) + auto result = RegQueryValueExW( + key.mKey, valueName, nullptr, nullptr, reinterpret_cast(buffer.data()), &len); + if (result == ERROR_MORE_DATA) { - // This should always be true + buffer.reserve(len / sizeof(wchar_t)); + result = RegQueryValueExW( + key.mKey, valueName, nullptr, nullptr, reinterpret_cast(buffer.data()), &len); + } + if (result == ERROR_SUCCESS) + { + // This should always be true. Note that we don't need to care above because of the trailing \0 if (len % sizeof(wchar_t) == 0) - return std::filesystem::path(buf.data(), buf.data() + len / sizeof(wchar_t)); + return std::filesystem::path(buffer.data(), buffer.data() + len / sizeof(wchar_t)); } } return {}; @@ -97,11 +105,17 @@ namespace Files { std::filesystem::path localPath = std::filesystem::current_path() / ""; - WCHAR path[MAX_PATH + 1] = {}; - - if (GetModuleFileNameW(nullptr, path, MAX_PATH + 1) > 0) + std::wstring executablePath; + DWORD copied = 0; + do { - localPath = std::filesystem::path(path).parent_path() / ""; + executablePath.resize(executablePath.size() + MAX_PATH); + copied = GetModuleFileNameW(nullptr, executablePath.data(), static_cast(executablePath.size())); + } while (GetLastError() == ERROR_INSUFFICIENT_BUFFER); + + if (copied > 0) + { + localPath = std::filesystem::path(executablePath).parent_path() / ""; } // lookup exe path diff --git a/components/files/wineutils.hpp b/components/files/wineutils.hpp index b6aed24bd0..bc5a0bc112 100644 --- a/components/files/wineutils.hpp +++ b/components/files/wineutils.hpp @@ -11,7 +11,7 @@ namespace Files::Wine { - static std::filesystem::path getInstallPath(const std::filesystem::path& homePath) + inline std::filesystem::path getInstallPath(const std::filesystem::path& homePath) { std::filesystem::path wineDefaultRegistry = homePath / ".wine/system.reg"; if (!std::filesystem::is_regular_file(wineDefaultRegistry))