From 2a85374c6aba969795ccc647f681274d41ba4fc9 Mon Sep 17 00:00:00 2001 From: Tulio Leao Date: Tue, 14 Jul 2020 12:56:04 -0300 Subject: [PATCH] Cleanup c-style casts from Windows.cpp --- src/openrct2/platform/Windows.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/openrct2/platform/Windows.cpp b/src/openrct2/platform/Windows.cpp index 7413955038..58792ac69c 100644 --- a/src/openrct2/platform/Windows.cpp +++ b/src/openrct2/platform/Windows.cpp @@ -172,8 +172,8 @@ bool platform_get_steam_path(utf8* outPath, size_t outSize) return false; } - wSteamPath = (wchar_t*)malloc(size); - result = RegQueryValueExW(hKey, L"SteamPath", nullptr, &type, (LPBYTE)wSteamPath, &size); + wSteamPath = reinterpret_cast(malloc(size)); + result = RegQueryValueExW(hKey, L"SteamPath", nullptr, &type, reinterpret_cast(wSteamPath), &size); if (result == ERROR_SUCCESS) { auto utf8SteamPath = String::ToUtf8(wSteamPath); @@ -213,7 +213,7 @@ uint16_t platform_get_locale_language() { CHAR langCode[4]; - if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, (LPSTR)&langCode, sizeof(langCode)) == 0) + if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME, reinterpret_cast(&langCode), sizeof(langCode)) == 0) { return LANGUAGE_UNDEFINED; } @@ -300,7 +300,7 @@ time_t platform_file_get_modified_time(const utf8* path) uint8_t platform_get_locale_currency() { CHAR currCode[4]; - if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SINTLSYMBOL, (LPSTR)&currCode, sizeof(currCode)) == 0) + if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SINTLSYMBOL, reinterpret_cast(&currCode), sizeof(currCode)) == 0) { return platform_get_currency_value(nullptr); } @@ -312,7 +312,8 @@ MeasurementFormat platform_get_locale_measurement_format() { UINT measurement_system; if (GetLocaleInfo( - LOCALE_USER_DEFAULT, LOCALE_IMEASURE | LOCALE_RETURN_NUMBER, (LPSTR)&measurement_system, sizeof(measurement_system)) + LOCALE_USER_DEFAULT, LOCALE_IMEASURE | LOCALE_RETURN_NUMBER, reinterpret_cast(&measurement_system), + sizeof(measurement_system)) == 0) { return MeasurementFormat::Metric; @@ -334,7 +335,10 @@ TemperatureUnit platform_get_locale_temperature_format() // GetLocaleInfo will set fahrenheit to 1 if the locale on this computer // uses the United States measurement system or 0 otherwise. - if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IMEASURE | LOCALE_RETURN_NUMBER, (LPSTR)&fahrenheit, sizeof(fahrenheit)) == 0) + if (GetLocaleInfo( + LOCALE_USER_DEFAULT, LOCALE_IMEASURE | LOCALE_RETURN_NUMBER, reinterpret_cast(&fahrenheit), + sizeof(fahrenheit)) + == 0) { // Assume celsius by default if function call fails return TemperatureUnit::Celsius; @@ -351,7 +355,7 @@ uint8_t platform_get_locale_date_format() # if _WIN32_WINNT >= 0x0600 // Retrieve short date format, eg "MM/dd/yyyy" wchar_t dateFormat[20]; - if (GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, LOCALE_SSHORTDATE, dateFormat, (int)std::size(dateFormat)) == 0) + if (GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, LOCALE_SSHORTDATE, dateFormat, static_cast(std::size(dateFormat))) == 0) { return DATE_FORMAT_DAY_MONTH_YEAR; } @@ -446,7 +450,8 @@ std::string platform_get_absolute_path(const utf8* relativePath, const utf8* bas auto pathToResolveW = String::ToWideChar(pathToResolve); wchar_t fullPathW[MAX_PATH]{}; - auto fullPathLen = GetFullPathNameW(pathToResolveW.c_str(), (DWORD)std::size(fullPathW), fullPathW, nullptr); + auto fullPathLen = GetFullPathNameW( + pathToResolveW.c_str(), static_cast(std::size(fullPathW)), fullPathW, nullptr); if (fullPathLen != 0) { result = String::ToUtf8(fullPathW); @@ -460,7 +465,8 @@ datetime64 platform_get_datetime_now_utc() // Get file time FILETIME fileTime; GetSystemTimeAsFileTime(&fileTime); - uint64_t fileTime64 = ((uint64_t)fileTime.dwHighDateTime << 32ULL) | ((uint64_t)fileTime.dwLowDateTime); + uint64_t fileTime64 = (static_cast(fileTime.dwHighDateTime) << 32ULL) + | (static_cast(fileTime.dwLowDateTime)); // File time starts from: 1601-01-01T00:00:00Z // Convert to start from: 0001-01-01T00:00:00Z