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_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
# Enable Unicode
add_compile_options(-municode)

View File

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

View File

@ -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<LPARAM>(icon));
SendMessage(hwnd, WM_SETICON, ICON_SMALL, reinterpret_cast<LPARAM>(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

View File

@ -48,7 +48,7 @@ namespace Guard
static std::optional<std::string> _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()

View File

@ -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;
}

View File

@ -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];