Remove the last non-Unicode Windows functions

This commit is contained in:
Silent 2022-10-05 23:47:07 +02:00
parent e825ffade7
commit 0f978fe907
No known key found for this signature in database
GPG Key ID: AE53149BB0C45AF1
6 changed files with 28 additions and 27 deletions

View File

@ -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_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
# Enable Unicode
add_compile_options(-municode)

View File

@ -10,7 +10,7 @@
<PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset> <PlatformToolset>$(DefaultPlatformToolset)</PlatformToolset>
<TargetPlatformVersion>10.0.17763.0</TargetPlatformVersion> <TargetPlatformVersion>10.0.17763.0</TargetPlatformVersion>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>Unicode</CharacterSet>
<OutDir>$(SolutionDir)bin\</OutDir> <OutDir>$(SolutionDir)bin\</OutDir>
<IntDir>$(SolutionDir)obj\$(ProjectName)\$(Configuration)_$(Platform)\</IntDir> <IntDir>$(SolutionDir)obj\$(ProjectName)\$(Configuration)_$(Platform)\</IntDir>

View File

@ -62,20 +62,20 @@ namespace OpenRCT2::Ui
public: public:
Win32Context() Win32Context()
{ {
_win32module = GetModuleHandleA(nullptr); _win32module = GetModuleHandle(nullptr);
} }
void SetWindowIcon(SDL_Window* window) override void SetWindowIcon(SDL_Window* window) override
{ {
if (_win32module != nullptr) if (_win32module != nullptr)
{ {
HICON icon = LoadIconA(_win32module, MAKEINTRESOURCEA(IDI_ICON)); HICON icon = LoadIcon(_win32module, MAKEINTRESOURCE(IDI_ICON));
if (icon != nullptr) if (icon != nullptr)
{ {
HWND hwnd = GetHWND(window); HWND hwnd = GetHWND(window);
if (hwnd != nullptr) if (hwnd != nullptr)
{ {
SendMessageA(hwnd, WM_SETICON, ICON_SMALL, reinterpret_cast<LPARAM>(icon)); SendMessage(hwnd, WM_SETICON, ICON_SMALL, reinterpret_cast<LPARAM>(icon));
} }
} }
} }
@ -83,7 +83,7 @@ namespace OpenRCT2::Ui
bool IsSteamOverlayAttached() override bool IsSteamOverlayAttached() override
{ {
return (GetModuleHandleA("GameOverlayRenderer.dll") != nullptr); return (GetModuleHandleW(L"GameOverlayRenderer.dll") != nullptr);
} }
void ShowMessageBox(SDL_Window* window, const std::string& message) override void ShowMessageBox(SDL_Window* window, const std::string& message) override

View File

@ -48,7 +48,7 @@ namespace Guard
static std::optional<std::string> _lastAssertMessage = std::nullopt; static std::optional<std::string> _lastAssertMessage = std::nullopt;
#ifdef _WIN32 #ifdef _WIN32
[[nodiscard]] static std::string CreateDialogAssertMessage(std::string_view); [[nodiscard]] static std::wstring CreateDialogAssertMessage(std::string_view);
static void ForceCrash(); static void ForceCrash();
#endif #endif
@ -104,7 +104,8 @@ namespace Guard
{ {
// Show message box if we are not building for testing // Show message box if we are not building for testing
auto buffer = CreateDialogAssertMessage(formattedMessage); 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) if (result == IDABORT)
{ {
ForceCrash(); ForceCrash();
@ -134,19 +135,19 @@ namespace Guard
} }
#ifdef _WIN32 #ifdef _WIN32
[[nodiscard]] static std::string CreateDialogAssertMessage(std::string_view formattedMessage) [[nodiscard]] static std::wstring CreateDialogAssertMessage(std::string_view formattedMessage)
{ {
StringBuilder sb; StringBuilder sb;
sb.Append(ASSERTION_MESSAGE); sb.Append(ASSERTION_MESSAGE);
sb.Append("\r\n\r\n"); sb.Append("\n\n");
sb.Append("Version: "); sb.Append("Version: ");
sb.Append(gVersionInfoFull); sb.Append(gVersionInfoFull);
if (!formattedMessage.empty()) if (!formattedMessage.empty())
{ {
sb.Append("\r\n"); sb.Append("\n");
sb.Append(formattedMessage); sb.Append(formattedMessage);
} }
return sb.GetStdString(); return String::ToWideChar({ sb.GetBuffer(), sb.GetLength() });
} }
static void ForceCrash() static void ForceCrash()

View File

@ -104,13 +104,13 @@ static bool OnCrash(
{ {
if (!succeeded) if (!succeeded)
{ {
constexpr const char* DumpFailedMessage = "Failed to create the dump. Please file an issue with OpenRCT2 on GitHub and " constexpr const wchar_t* DumpFailedMessage = L"Failed to create the dump. Please file an issue with OpenRCT2 on GitHub "
"provide latest save, and provide " L"and provide latest save, and provide information about what you did "
"information about what you did before the crash occurred."; L"before the crash occurred.";
printf("%s\n", DumpFailedMessage); wprintf(L"%ls\n", DumpFailedMessage);
if (!gOpenRCT2SilentBreakpad) if (!gOpenRCT2SilentBreakpad)
{ {
MessageBoxA(nullptr, DumpFailedMessage, OPENRCT2_NAME, MB_OK | MB_ICONERROR); MessageBoxW(nullptr, DumpFailedMessage, L"" OPENRCT2_NAME, MB_OK | MB_ICONERROR);
} }
return succeeded; return succeeded;
} }

View File

@ -45,7 +45,7 @@ static uint32_t _frequency = 0;
static LARGE_INTEGER _entryTimestamp; static LARGE_INTEGER _entryTimestamp;
// The name of the mutex used to prevent multiple instances of the game from running // 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 SOFTWARE_CLASSES L"Software\\Classes"
# define MUI_CACHE L"Local Settings\\Software\\Microsoft\\Windows\\Shell\\MuiCache" # 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 IsOSVersionAtLeast(uint32_t major, uint32_t minor, uint32_t build)
{ {
bool result = false; bool result = false;
auto hModule = GetModuleHandleA("ntdll.dll"); auto hModule = GetModuleHandleW(L"ntdll.dll");
if (hModule != nullptr) if (hModule != nullptr)
{ {
using RtlGetVersionPtr = long(WINAPI*)(PRTL_OSVERSIONINFOW); using RtlGetVersionPtr = long(WINAPI*)(PRTL_OSVERSIONINFOW);
@ -470,7 +470,7 @@ namespace Platform
if (RegOpenKeyW(HKEY_CURRENT_USER, SOFTWARE_CLASSES, &hRootKey) == ERROR_SUCCESS) if (RegOpenKeyW(HKEY_CURRENT_USER, SOFTWARE_CLASSES, &hRootKey) == ERROR_SUCCESS)
{ {
// [hRootKey\.ext] // [hRootKey\.ext]
RegDeleteTreeA(hRootKey, extension); RegDeleteTreeW(hRootKey, String::ToWideChar(extension).c_str());
// [hRootKey\OpenRCT2.ext] // [hRootKey\OpenRCT2.ext]
auto progIdName = get_progIdName(extension); auto progIdName = get_progIdName(extension);
@ -786,18 +786,15 @@ namespace Platform
bool EnsureDirectoryExists(u8string_view path) bool EnsureDirectoryExists(u8string_view path)
{ {
if (Path::DirectoryExists(path))
return 1;
auto wPath = String::ToWideChar(path); auto wPath = String::ToWideChar(path);
auto success = CreateDirectoryW(wPath.c_str(), nullptr); auto success = CreateDirectoryW(wPath.c_str(), nullptr);
return success != FALSE; return success != FALSE || GetLastError() == ERROR_ALREADY_EXISTS;
} }
bool LockSingleInstance() bool LockSingleInstance()
{ {
// Check if operating system mutex exists // 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) if (mutex == nullptr)
{ {
log_error("unable to create mutex"); log_error("unable to create mutex");
@ -871,11 +868,11 @@ namespace Platform
{ {
// [hRootKey\openrct2] // [hRootKey\openrct2]
HKEY hClassKey; 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] // [hRootKey\openrct2\shell\open\command]
wchar_t exePath[MAX_PATH]; wchar_t exePath[MAX_PATH];