diff --git a/src/openrct2-dll/openrct2-dll.cpp b/src/openrct2-dll/openrct2-dll.cpp index e203706282..24f2340fc8 100644 --- a/src/openrct2-dll/openrct2-dll.cpp +++ b/src/openrct2-dll/openrct2-dll.cpp @@ -32,7 +32,7 @@ using namespace OpenRCT2::Ui; static char** GetCommandLineArgs(int argc, wchar_t** argvW); static void FreeCommandLineArgs(int argc, char** argv); -static char* ConvertUTF16toUTF8(const wchar_t* src); +static char* ConvertWideChartoUTF8(const wchar_t* src); DLLEXPORT int LaunchOpenRCT2(int argc, wchar_t** argvW) { @@ -63,7 +63,7 @@ static char** GetCommandLineArgs(int argc, wchar_t** argvW) // Convert to UTF-8 for (int i = 0; i < argc; i++) { - argv[i] = ConvertUTF16toUTF8(argvW[i]); + argv[i] = ConvertWideChartoUTF8(argvW[i]); } return argv; @@ -79,7 +79,7 @@ static void FreeCommandLineArgs(int argc, char** argv) free(argv); } -static char* ConvertUTF16toUTF8(const wchar_t* src) +static char* ConvertWideChartoUTF8(const wchar_t* src) { int srcLen = lstrlenW(src); int sizeReq = WideCharToMultiByte(CP_UTF8, 0, src, srcLen, nullptr, 0, nullptr, nullptr); diff --git a/src/openrct2-ui/UiContext.Win32.cpp b/src/openrct2-ui/UiContext.Win32.cpp index c9b0e99538..c19b3fcd98 100644 --- a/src/openrct2-ui/UiContext.Win32.cpp +++ b/src/openrct2-ui/UiContext.Win32.cpp @@ -87,23 +87,23 @@ namespace OpenRCT2::Ui void ShowMessageBox(SDL_Window* window, const std::string& message) override { HWND hwnd = GetHWND(window); - std::wstring messageW = String::ToUtf16(message); + std::wstring messageW = String::ToWideChar(message); MessageBoxW(hwnd, messageW.c_str(), L"OpenRCT2", MB_OK); } void OpenFolder(const std::string& path) override { - std::wstring pathW = String::ToUtf16(path); + std::wstring pathW = String::ToWideChar(path); ShellExecuteW(NULL, L"open", pathW.c_str(), NULL, NULL, SW_SHOWNORMAL); } std::string ShowFileDialog(SDL_Window* window, const FileDialogDesc& desc) override { - std::wstring wcFilename = String::ToUtf16(desc.DefaultFilename); + std::wstring wcFilename = String::ToWideChar(desc.DefaultFilename); wcFilename.resize(std::max(wcFilename.size(), MAX_PATH)); - std::wstring wcTitle = String::ToUtf16(desc.Title); - std::wstring wcInitialDirectory = String::ToUtf16(desc.InitialDirectory); + std::wstring wcTitle = String::ToWideChar(desc.Title); + std::wstring wcInitialDirectory = String::ToWideChar(desc.InitialDirectory); std::wstring wcFilters = GetFilterString(desc.Filters); // Set open file name options @@ -162,7 +162,7 @@ namespace OpenRCT2::Ui LPMALLOC lpMalloc; if (SUCCEEDED(CoInitializeEx(0, COINIT_APARTMENTTHREADED)) && SUCCEEDED(SHGetMalloc(&lpMalloc))) { - std::wstring titleW = String::ToUtf16(title); + std::wstring titleW = String::ToWideChar(title); BROWSEINFOW bi = {}; bi.lpszTitle = titleW.c_str(); bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE | BIF_NONEWFOLDERBUTTON; @@ -211,7 +211,7 @@ namespace OpenRCT2::Ui std::wstringstream filtersb; for (auto filter : filters) { - filtersb << String::ToUtf16(filter.Name) << '\0' << String::ToUtf16(filter.Pattern) << '\0'; + filtersb << String::ToWideChar(filter.Name) << '\0' << String::ToWideChar(filter.Pattern) << '\0'; } return filtersb.str(); } diff --git a/src/openrct2-ui/windows/Changelog.cpp b/src/openrct2-ui/windows/Changelog.cpp index 97c3308f59..a5ba4b3fbe 100644 --- a/src/openrct2-ui/windows/Changelog.cpp +++ b/src/openrct2-ui/windows/Changelog.cpp @@ -213,7 +213,7 @@ static std::string GetChangelogText() { auto path = GetChangelogPath(); #if defined(_WIN32) && !defined(__MINGW32__) - auto pathW = String::ToUtf16(path); + auto pathW = String::ToWideChar(path); auto fs = std::ifstream(pathW, std::ios::in); #else auto fs = std::ifstream(path, std::ios::in); diff --git a/src/openrct2/CmdlineSprite.cpp b/src/openrct2/CmdlineSprite.cpp index ea4e9945e8..3a3f52f204 100644 --- a/src/openrct2/CmdlineSprite.cpp +++ b/src/openrct2/CmdlineSprite.cpp @@ -69,8 +69,8 @@ static uint8_t* spriteFileData; static FILE* fopen_utf8(const char* path, const char* mode) { - auto pathW = String::ToUtf16(path); - auto modeW = String::ToUtf16(mode); + auto pathW = String::ToWideChar(path); + auto modeW = String::ToWideChar(mode); auto file = _wfopen(pathW.c_str(), modeW.c_str()); return file; } diff --git a/src/openrct2/common.h b/src/openrct2/common.h index 2110a4415c..1af006ac29 100644 --- a/src/openrct2/common.h +++ b/src/openrct2/common.h @@ -31,10 +31,6 @@ using namespace Numerics; using utf8 = char; using utf8string = utf8*; using const_utf8string = const utf8*; -#ifdef _WIN32 -using utf16 = wchar_t; -using utf16string = utf16*; -#endif // Define MAX_PATH for various headers that don't want to include system headers // just for MAX_PATH diff --git a/src/openrct2/core/File.cpp b/src/openrct2/core/File.cpp index df3220daf7..5df4e4514d 100644 --- a/src/openrct2/core/File.cpp +++ b/src/openrct2/core/File.cpp @@ -49,7 +49,7 @@ namespace File std::vector result; #if defined(_WIN32) && !defined(__MINGW32__) - auto pathW = String::ToUtf16(std::string(path)); + auto pathW = String::ToWideChar(std::string(path)); std::ifstream fs(pathW, std::ios::in | std::ios::binary); #else std::ifstream fs(std::string(path), std::ios::in | std::ios::binary); @@ -125,7 +125,7 @@ namespace File { uint64_t lastModified = 0; #ifdef _WIN32 - auto pathW = String::ToUtf16(path.c_str()); + auto pathW = String::ToWideChar(path.c_str()); auto hFile = CreateFileW(pathW.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, 0, nullptr); if (hFile != INVALID_HANDLE_VALUE) { diff --git a/src/openrct2/core/FileScanner.cpp b/src/openrct2/core/FileScanner.cpp index c3084124f1..169d62df4f 100644 --- a/src/openrct2/core/FileScanner.cpp +++ b/src/openrct2/core/FileScanner.cpp @@ -228,7 +228,7 @@ public: void GetDirectoryChildren(std::vector& children, const std::string& path) override { auto pattern = path + "\\*"; - auto wPattern = String::ToUtf16(pattern.c_str()); + auto wPattern = String::ToWideChar(pattern.c_str()); WIN32_FIND_DATAW findData; HANDLE hFile = FindFirstFileW(wPattern.c_str(), &findData); diff --git a/src/openrct2/core/FileStream.hpp b/src/openrct2/core/FileStream.hpp index dc4b5e1b83..716be814b1 100644 --- a/src/openrct2/core/FileStream.hpp +++ b/src/openrct2/core/FileStream.hpp @@ -70,8 +70,8 @@ public: } #ifdef _WIN32 - auto pathW = String::ToUtf16(path); - auto modeW = String::ToUtf16(mode); + auto pathW = String::ToWideChar(path); + auto modeW = String::ToWideChar(mode); _file = _wfopen(pathW.c_str(), modeW.c_str()); #else if (fileMode == FILE_MODE_OPEN) diff --git a/src/openrct2/core/Imaging.cpp b/src/openrct2/core/Imaging.cpp index 3772b7d02e..18b676fdd0 100644 --- a/src/openrct2/core/Imaging.cpp +++ b/src/openrct2/core/Imaging.cpp @@ -305,7 +305,7 @@ namespace Imaging default: { #if defined(_WIN32) && !defined(__MINGW32__) - auto pathW = String::ToUtf16(path); + auto pathW = String::ToWideChar(path); std::ifstream fs(pathW, std::ios::binary); #else std::ifstream fs(path.data(), std::ios::binary); @@ -331,7 +331,7 @@ namespace Imaging case IMAGE_FORMAT::PNG: { #if defined(_WIN32) && !defined(__MINGW32__) - auto pathW = String::ToUtf16(path); + auto pathW = String::ToWideChar(path); std::ofstream fs(pathW, std::ios::binary); #else std::ofstream fs(path.data(), std::ios::binary); diff --git a/src/openrct2/core/Path.cpp b/src/openrct2/core/Path.cpp index 8dfaf7f3e2..8c1bfeb045 100644 --- a/src/openrct2/core/Path.cpp +++ b/src/openrct2/core/Path.cpp @@ -171,7 +171,7 @@ namespace Path utf8* GetAbsolute(utf8* buffer, size_t bufferSize, const utf8* relativePath) { #ifdef _WIN32 - auto relativePathW = String::ToUtf16(relativePath); + auto relativePathW = String::ToWideChar(relativePath); wchar_t absolutePathW[MAX_PATH]; DWORD length = GetFullPathNameW(relativePathW.c_str(), (DWORD)std::size(absolutePathW), absolutePathW, nullptr); if (length == 0) diff --git a/src/openrct2/core/String.cpp b/src/openrct2/core/String.cpp index 68da671696..bf5ec321f9 100644 --- a/src/openrct2/core/String.cpp +++ b/src/openrct2/core/String.cpp @@ -97,7 +97,7 @@ namespace String #endif } - std::wstring ToUtf16(const std::string_view& src) + std::wstring ToWideChar(const std::string_view& src) { #ifdef _WIN32 int srcLen = (int)src.size(); @@ -706,7 +706,7 @@ namespace String std::string ToUpper(const std::string_view& src) { #ifdef _WIN32 - auto srcW = ToUtf16(src); + auto srcW = ToWideChar(src); // Measure how long the destination needs to be auto requiredSize = LCMapStringEx( diff --git a/src/openrct2/core/String.hpp b/src/openrct2/core/String.hpp index 8314655ffc..3f337aa629 100644 --- a/src/openrct2/core/String.hpp +++ b/src/openrct2/core/String.hpp @@ -37,7 +37,7 @@ namespace String std::string StdFormat_VA(const utf8* format, va_list args); std::string StdFormat(const utf8* format, ...); std::string ToUtf8(const std::wstring_view& src); - std::wstring ToUtf16(const std::string_view& src); + std::wstring ToWideChar(const std::string_view& src); bool IsNullOrEmpty(const utf8* str); int32_t Compare(const std::string& a, const std::string& b, bool ignoreCase = false); diff --git a/src/openrct2/network/Network.cpp b/src/openrct2/network/Network.cpp index a4ecd1d205..9f77360605 100644 --- a/src/openrct2/network/Network.cpp +++ b/src/openrct2/network/Network.cpp @@ -1356,7 +1356,7 @@ void Network::BeginChatLog() _chatLogPath = BeginLog(directory, "", _chatLogFilenameFormat); # if defined(_WIN32) && !defined(__MINGW32__) - auto pathW = String::ToUtf16(_chatLogPath.c_str()); + auto pathW = String::ToWideChar(_chatLogPath.c_str()); _chat_log_fs.open(pathW.c_str(), std::ios::out | std::ios::app); # else _chat_log_fs.open(_chatLogPath, std::ios::out | std::ios::app); @@ -1382,7 +1382,7 @@ void Network::BeginServerLog() _serverLogPath = BeginLog(directory, ServerName, _serverLogFilenameFormat); # if defined(_WIN32) && !defined(__MINGW32__) - auto pathW = String::ToUtf16(_serverLogPath.c_str()); + auto pathW = String::ToWideChar(_serverLogPath.c_str()); _server_log_fs.open(pathW.c_str(), std::ios::out | std::ios::app | std::ios::binary); # else _server_log_fs.open(_serverLogPath, std::ios::out | std::ios::app | std::ios::binary); diff --git a/src/openrct2/platform/Crash.cpp b/src/openrct2/platform/Crash.cpp index 6d6fc6bf7c..5dd09091c2 100644 --- a/src/openrct2/platform/Crash.cpp +++ b/src/openrct2/platform/Crash.cpp @@ -68,7 +68,7 @@ static bool UploadMinidump(const std::map& files, in } else { - parameters[L"commit"] = String::ToUtf16(gVersionInfoFull); + parameters[L"commit"] = String::ToWideChar(gVersionInfoFull); } int timeout = 10000; bool success = google_breakpad::HTTPUpload::SendRequest(url, parameters, files, &timeout, &response, &error); @@ -189,7 +189,7 @@ static bool OnCrash( std::string screenshotPath = screenshot_dump(); if (!screenshotPath.empty()) { - auto screenshotPathW = String::ToUtf16(screenshotPath.c_str()); + auto screenshotPathW = String::ToWideChar(screenshotPath.c_str()); uploadFiles[L"attachment_screenshot.png"] = screenshotPathW; } @@ -266,7 +266,7 @@ static std::wstring GetDumpDirectory() { char userDirectory[MAX_PATH]; platform_get_user_directory(userDirectory, nullptr, sizeof(userDirectory)); - auto result = String::ToUtf16(userDirectory); + auto result = String::ToWideChar(userDirectory); return result; } diff --git a/src/openrct2/platform/Platform.Win32.cpp b/src/openrct2/platform/Platform.Win32.cpp index 62ecff739c..b23ab59d5d 100644 --- a/src/openrct2/platform/Platform.Win32.cpp +++ b/src/openrct2/platform/Platform.Win32.cpp @@ -50,7 +50,7 @@ namespace Platform std::string GetEnvironmentVariable(const std::string& name) { std::wstring result; - auto wname = String::ToUtf16(name); + auto wname = String::ToWideChar(name); wchar_t wvalue[256]; auto valueSize = GetEnvironmentVariableW(wname.c_str(), wvalue, (DWORD)std::size(wvalue)); if (valueSize < std::size(wvalue)) diff --git a/src/openrct2/platform/Posix.cpp b/src/openrct2/platform/Posix.cpp index e31aa4fc0a..092e635d1b 100644 --- a/src/openrct2/platform/Posix.cpp +++ b/src/openrct2/platform/Posix.cpp @@ -98,7 +98,7 @@ void platform_get_time_local(rct2_time* out_time) static size_t platform_utf8_to_multibyte(const utf8* path, char* buffer, size_t buffer_size) { - auto wpath = String::ToUtf16(path); + auto wpath = String::ToWideChar(path); setlocale(LC_CTYPE, "UTF-8"); size_t len = wcstombs(NULL, wpath.c_str(), 0); bool truncated = false; diff --git a/src/openrct2/platform/Windows.cpp b/src/openrct2/platform/Windows.cpp index 3e11ec3ce1..e602d1eb70 100644 --- a/src/openrct2/platform/Windows.cpp +++ b/src/openrct2/platform/Windows.cpp @@ -85,7 +85,7 @@ void platform_get_time_local(rct2_time* out_time) bool platform_file_exists(const utf8* path) { - auto wPath = String::ToUtf16(path); + auto wPath = String::ToWideChar(path); DWORD result = GetFileAttributesW(wPath.c_str()); DWORD error = GetLastError(); return !(result == INVALID_FILE_ATTRIBUTES && (error == ERROR_FILE_NOT_FOUND || error == ERROR_PATH_NOT_FOUND)); @@ -93,7 +93,7 @@ bool platform_file_exists(const utf8* path) bool platform_directory_exists(const utf8* path) { - auto wPath = String::ToUtf16(path); + auto wPath = String::ToWideChar(path); DWORD dwAttrib = GetFileAttributesW(wPath.c_str()); return dwAttrib != INVALID_FILE_ATTRIBUTES && (dwAttrib & FILE_ATTRIBUTE_DIRECTORY); } @@ -125,7 +125,7 @@ bool platform_ensure_directory_exists(const utf8* path) if (platform_directory_exists(path)) return 1; - auto wPath = String::ToUtf16(path); + auto wPath = String::ToWideChar(path); auto success = CreateDirectoryW(wPath.c_str(), nullptr); return success != FALSE; } @@ -133,7 +133,7 @@ bool platform_ensure_directory_exists(const utf8* path) bool platform_directory_delete(const utf8* path) { // Needs to be double-null terminated as pFrom is a null terminated array of strings - auto wPath = String::ToUtf16(path) + L"\0"; + auto wPath = String::ToWideChar(path) + L"\0"; SHFILEOPSTRUCTW fileop; fileop.hwnd = nullptr; // no status display @@ -180,23 +180,23 @@ int32_t platform_get_drives() bool platform_file_copy(const utf8* srcPath, const utf8* dstPath, bool overwrite) { - auto wSrcPath = String::ToUtf16(srcPath); - auto wDstPath = String::ToUtf16(dstPath); + auto wSrcPath = String::ToWideChar(srcPath); + auto wDstPath = String::ToWideChar(dstPath); auto success = CopyFileW(wSrcPath.c_str(), wDstPath.c_str(), overwrite ? FALSE : TRUE); return success != FALSE; } bool platform_file_move(const utf8* srcPath, const utf8* dstPath) { - auto wSrcPath = String::ToUtf16(srcPath); - auto wDstPath = String::ToUtf16(dstPath); + auto wSrcPath = String::ToWideChar(srcPath); + auto wDstPath = String::ToWideChar(dstPath); auto success = MoveFileW(wSrcPath.c_str(), wDstPath.c_str()); return success != FALSE; } bool platform_file_delete(const utf8* path) { - auto wPath = String::ToUtf16(path); + auto wPath = String::ToWideChar(path); auto success = DeleteFileW(wPath.c_str()); return success != FALSE; } @@ -326,7 +326,7 @@ uint16_t platform_get_locale_language() time_t platform_file_get_modified_time(const utf8* path) { WIN32_FILE_ATTRIBUTE_DATA data{}; - auto wPath = String::ToUtf16(path); + auto wPath = String::ToWideChar(path); auto result = GetFileAttributesExW(wPath.c_str(), GetFileExInfoStandard, &data); if (result != FALSE) { @@ -488,7 +488,7 @@ std::string platform_get_absolute_path(const utf8* relativePath, const utf8* bas pathToResolve = std::string(basePath) + std::string("\\") + relativePath; } - auto pathToResolveW = String::ToUtf16(pathToResolve); + auto pathToResolveW = String::ToWideChar(pathToResolve); wchar_t fullPathW[MAX_PATH]{}; auto fullPathLen = GetFullPathNameW(pathToResolveW.c_str(), (DWORD)std::size(fullPathW), fullPathW, nullptr); if (fullPathLen != 0) @@ -554,7 +554,7 @@ bool platform_process_is_elevated() static std::wstring get_progIdName(const std::string_view& extension) { auto progIdName = std::string(OPENRCT2_NAME) + std::string(extension); - auto progIdNameW = String::ToUtf16(progIdName); + auto progIdNameW = String::ToWideChar(progIdName); return progIdNameW; } @@ -569,10 +569,10 @@ static bool windows_setup_file_association( GetModuleFileNameW(nullptr, exePathW, (DWORD)std::size(exePathW)); GetModuleFileNameW(plaform_get_dll_module(), dllPathW, (DWORD)std::size(dllPathW)); - auto extensionW = String::ToUtf16(extension); - auto fileTypeTextW = String::ToUtf16(fileTypeText); - auto commandTextW = String::ToUtf16(commandText); - auto commandArgsW = String::ToUtf16(commandArgs); + auto extensionW = String::ToWideChar(extension); + auto fileTypeTextW = String::ToWideChar(fileTypeText); + auto commandTextW = String::ToWideChar(commandText); + auto commandArgsW = String::ToWideChar(commandArgs); auto progIdNameW = get_progIdName(extension); bool result = false;