From 81430de34557eb8679dd9408a77e82207d76c575 Mon Sep 17 00:00:00 2001 From: Guillaume Jacquemin Date: Mon, 28 Aug 2023 13:51:32 +0200 Subject: [PATCH] main: support running the app in Wine/Proton. Turns out the flag I used for SHGetKnownFolderPath() is not only deprecated starting with Win10 1703, but it also isn't implemented in Wine. It also was completely useless because the Save Tool isn't a "packaged process", as the docs call it. Ah, the joys of using WinAPI... --- src/SaveTool/SaveTool_Initialisation.cpp | 12 ++++++++++-- src/main.cpp | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/SaveTool/SaveTool_Initialisation.cpp b/src/SaveTool/SaveTool_Initialisation.cpp index e14bb2b..ba0441a 100644 --- a/src/SaveTool/SaveTool_Initialisation.cpp +++ b/src/SaveTool/SaveTool_Initialisation.cpp @@ -198,9 +198,17 @@ SaveTool::findGameDataDirectory() -> bool { wchar_t* localappdata_path = nullptr; Containers::ScopeGuard guard{localappdata_path, CoTaskMemFree}; - if(SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_NO_APPCONTAINER_REDIRECTION, nullptr, &localappdata_path) != S_OK) + auto result = SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_DEFAULT, nullptr, &localappdata_path); + if(result != S_OK) { - _lastError = Utility::format("SHGetKnownFolderPath() failed with error code {}.", GetLastError()); + char* message_buffer = nullptr; + auto size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, + nullptr, result, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), + reinterpret_cast(&message_buffer), 0, nullptr); + String message{message_buffer, size}; + LocalFree(message_buffer); + + _lastError = Utility::format("SHGetKnownFolderPath() failed with error code {}: {}", result, message); LOG_ERROR(_lastError); return false; } diff --git a/src/main.cpp b/src/main.cpp index 20e1be1..13e958c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -45,7 +45,7 @@ int main(int argc, char** argv) { Containers::StringView locale{str}; LOG_INFO_FORMAT("Current locale: {}", locale); - if(!locale.hasSuffix(".utf8")) { + if(!locale.hasSuffix(".utf8") && !locale.hasSuffix(".65001")) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "Your system doesn't support UTF-8.", nullptr); return EXIT_FAILURE;