From 0f978fe9073734201daba86c45dcfe2642c44b02 Mon Sep 17 00:00:00 2001 From: Silent Date: Wed, 5 Oct 2022 23:47:07 +0200 Subject: [PATCH] Remove the last non-Unicode Windows functions --- CMakeLists_mingw.txt | 3 +++ openrct2.common.props | 2 +- src/openrct2-ui/UiContext.Win32.cpp | 8 ++++---- src/openrct2/core/Guard.cpp | 13 +++++++------ src/openrct2/platform/Crash.cpp | 10 +++++----- src/openrct2/platform/Platform.Win32.cpp | 19 ++++++++----------- 6 files changed, 28 insertions(+), 27 deletions(-) diff --git a/CMakeLists_mingw.txt b/CMakeLists_mingw.txt index ffb338d416..830c5031e4 100644 --- a/CMakeLists_mingw.txt +++ b/CMakeLists_mingw.txt @@ -23,3 +23,6 @@ SET(CMAKE_FIND_ROOT_PATH ${TARGET_ENVIRONMENT}) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + +# Enable Unicode +add_compile_options(-municode) diff --git a/openrct2.common.props b/openrct2.common.props index fd137d0d7f..6afb7deebf 100644 --- a/openrct2.common.props +++ b/openrct2.common.props @@ -10,7 +10,7 @@ $(DefaultPlatformToolset) 10.0.17763.0 - MultiByte + Unicode $(SolutionDir)bin\ $(SolutionDir)obj\$(ProjectName)\$(Configuration)_$(Platform)\ diff --git a/src/openrct2-ui/UiContext.Win32.cpp b/src/openrct2-ui/UiContext.Win32.cpp index 14e7d70cda..740820d57c 100644 --- a/src/openrct2-ui/UiContext.Win32.cpp +++ b/src/openrct2-ui/UiContext.Win32.cpp @@ -62,20 +62,20 @@ namespace OpenRCT2::Ui public: Win32Context() { - _win32module = GetModuleHandleA(nullptr); + _win32module = GetModuleHandle(nullptr); } void SetWindowIcon(SDL_Window* window) override { if (_win32module != nullptr) { - HICON icon = LoadIconA(_win32module, MAKEINTRESOURCEA(IDI_ICON)); + HICON icon = LoadIcon(_win32module, MAKEINTRESOURCE(IDI_ICON)); if (icon != nullptr) { HWND hwnd = GetHWND(window); if (hwnd != nullptr) { - SendMessageA(hwnd, WM_SETICON, ICON_SMALL, reinterpret_cast(icon)); + SendMessage(hwnd, WM_SETICON, ICON_SMALL, reinterpret_cast(icon)); } } } @@ -83,7 +83,7 @@ namespace OpenRCT2::Ui bool IsSteamOverlayAttached() override { - return (GetModuleHandleA("GameOverlayRenderer.dll") != nullptr); + return (GetModuleHandleW(L"GameOverlayRenderer.dll") != nullptr); } void ShowMessageBox(SDL_Window* window, const std::string& message) override diff --git a/src/openrct2/core/Guard.cpp b/src/openrct2/core/Guard.cpp index 8a48f0f1ea..fdeefaf688 100644 --- a/src/openrct2/core/Guard.cpp +++ b/src/openrct2/core/Guard.cpp @@ -48,7 +48,7 @@ namespace Guard static std::optional _lastAssertMessage = std::nullopt; #ifdef _WIN32 - [[nodiscard]] static std::string CreateDialogAssertMessage(std::string_view); + [[nodiscard]] static std::wstring CreateDialogAssertMessage(std::string_view); static void ForceCrash(); #endif @@ -104,7 +104,8 @@ namespace Guard { // Show message box if we are not building for testing auto buffer = CreateDialogAssertMessage(formattedMessage); - int32_t result = MessageBoxA(nullptr, buffer.c_str(), OPENRCT2_NAME, MB_ABORTRETRYIGNORE | MB_ICONEXCLAMATION); + int32_t result = MessageBoxW( + nullptr, buffer.c_str(), L"" OPENRCT2_NAME, MB_ABORTRETRYIGNORE | MB_ICONEXCLAMATION); if (result == IDABORT) { ForceCrash(); @@ -134,19 +135,19 @@ namespace Guard } #ifdef _WIN32 - [[nodiscard]] static std::string CreateDialogAssertMessage(std::string_view formattedMessage) + [[nodiscard]] static std::wstring CreateDialogAssertMessage(std::string_view formattedMessage) { StringBuilder sb; sb.Append(ASSERTION_MESSAGE); - sb.Append("\r\n\r\n"); + sb.Append("\n\n"); sb.Append("Version: "); sb.Append(gVersionInfoFull); if (!formattedMessage.empty()) { - sb.Append("\r\n"); + sb.Append("\n"); sb.Append(formattedMessage); } - return sb.GetStdString(); + return String::ToWideChar({ sb.GetBuffer(), sb.GetLength() }); } static void ForceCrash() diff --git a/src/openrct2/platform/Crash.cpp b/src/openrct2/platform/Crash.cpp index 4d9e356edb..a47c4cc5a4 100644 --- a/src/openrct2/platform/Crash.cpp +++ b/src/openrct2/platform/Crash.cpp @@ -104,13 +104,13 @@ static bool OnCrash( { if (!succeeded) { - constexpr const char* DumpFailedMessage = "Failed to create the dump. Please file an issue with OpenRCT2 on GitHub and " - "provide latest save, and provide " - "information about what you did before the crash occurred."; - printf("%s\n", DumpFailedMessage); + constexpr const wchar_t* DumpFailedMessage = L"Failed to create the dump. Please file an issue with OpenRCT2 on GitHub " + L"and provide latest save, and provide information about what you did " + L"before the crash occurred."; + wprintf(L"%ls\n", DumpFailedMessage); if (!gOpenRCT2SilentBreakpad) { - MessageBoxA(nullptr, DumpFailedMessage, OPENRCT2_NAME, MB_OK | MB_ICONERROR); + MessageBoxW(nullptr, DumpFailedMessage, L"" OPENRCT2_NAME, MB_OK | MB_ICONERROR); } return succeeded; } diff --git a/src/openrct2/platform/Platform.Win32.cpp b/src/openrct2/platform/Platform.Win32.cpp index 8d01dcbc88..5056906d1f 100644 --- a/src/openrct2/platform/Platform.Win32.cpp +++ b/src/openrct2/platform/Platform.Win32.cpp @@ -45,7 +45,7 @@ static uint32_t _frequency = 0; static LARGE_INTEGER _entryTimestamp; // The name of the mutex used to prevent multiple instances of the game from running -static constexpr char SINGLE_INSTANCE_MUTEX_NAME[] = "RollerCoaster Tycoon 2_GSKMUTEX"; +static constexpr wchar_t SINGLE_INSTANCE_MUTEX_NAME[] = L"RollerCoaster Tycoon 2_GSKMUTEX"; # define SOFTWARE_CLASSES L"Software\\Classes" # define MUI_CACHE L"Local Settings\\Software\\Microsoft\\Windows\\Shell\\MuiCache" @@ -224,7 +224,7 @@ namespace Platform bool IsOSVersionAtLeast(uint32_t major, uint32_t minor, uint32_t build) { bool result = false; - auto hModule = GetModuleHandleA("ntdll.dll"); + auto hModule = GetModuleHandleW(L"ntdll.dll"); if (hModule != nullptr) { using RtlGetVersionPtr = long(WINAPI*)(PRTL_OSVERSIONINFOW); @@ -470,7 +470,7 @@ namespace Platform if (RegOpenKeyW(HKEY_CURRENT_USER, SOFTWARE_CLASSES, &hRootKey) == ERROR_SUCCESS) { // [hRootKey\.ext] - RegDeleteTreeA(hRootKey, extension); + RegDeleteTreeW(hRootKey, String::ToWideChar(extension).c_str()); // [hRootKey\OpenRCT2.ext] auto progIdName = get_progIdName(extension); @@ -786,18 +786,15 @@ namespace Platform bool EnsureDirectoryExists(u8string_view path) { - if (Path::DirectoryExists(path)) - return 1; - auto wPath = String::ToWideChar(path); auto success = CreateDirectoryW(wPath.c_str(), nullptr); - return success != FALSE; + return success != FALSE || GetLastError() == ERROR_ALREADY_EXISTS; } bool LockSingleInstance() { // Check if operating system mutex exists - HANDLE mutex = CreateMutex(nullptr, FALSE, SINGLE_INSTANCE_MUTEX_NAME); + HANDLE mutex = CreateMutexW(nullptr, FALSE, SINGLE_INSTANCE_MUTEX_NAME); if (mutex == nullptr) { log_error("unable to create mutex"); @@ -871,11 +868,11 @@ namespace Platform { // [hRootKey\openrct2] HKEY hClassKey; - if (RegCreateKeyA(hRootKey, "openrct2", &hClassKey) == ERROR_SUCCESS) + if (RegCreateKeyW(hRootKey, L"openrct2", &hClassKey) == ERROR_SUCCESS) { - if (RegSetValueA(hClassKey, nullptr, REG_SZ, "URL:openrct2", 0) == ERROR_SUCCESS) + if (RegSetValueW(hClassKey, nullptr, REG_SZ, L"URL:openrct2", 0) == ERROR_SUCCESS) { - if (RegSetKeyValueA(hClassKey, nullptr, "URL Protocol", REG_SZ, "", 0) == ERROR_SUCCESS) + if (RegSetKeyValueW(hClassKey, nullptr, L"URL Protocol", REG_SZ, "", 0) == ERROR_SUCCESS) { // [hRootKey\openrct2\shell\open\command] wchar_t exePath[MAX_PATH];