Skip to content

Commit

Permalink
Remove any traces of WinNT5.1 as per #16911
Browse files Browse the repository at this point in the history
  • Loading branch information
CookiePLMonster committed Jun 20, 2022
1 parent 29beb29 commit dc7e31f
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 109 deletions.
5 changes: 0 additions & 5 deletions src/openrct2-ui/UiContext.Win32.cpp
Expand Up @@ -35,14 +35,9 @@

static std::wstring SHGetPathFromIDListLongPath(LPCITEMIDLIST pidl)
{
# if _WIN32_WINNT < 0x0600
std::wstring pszPath(MAX_PATH, 0);
auto result = SHGetPathFromIDListW(pidl, pszPath.data());
# else
// Limit path length to 32K
std::wstring pszPath(std::numeric_limits<int16_t>().max(), 0);
auto result = SHGetPathFromIDListEx(pidl, pszPath.data(), static_cast<DWORD>(pszPath.size()), GPFIDL_DEFAULT);
# endif
if (result)
{
// Truncate at first null terminator
Expand Down
8 changes: 4 additions & 4 deletions src/openrct2/cmdline/RootCommands.cpp
Expand Up @@ -96,7 +96,7 @@ static exitcode_t HandleCommandJoin(CommandLineArgEnumerator * enumerator);
static exitcode_t HandleCommandSetRCT2(CommandLineArgEnumerator * enumerator);
static exitcode_t HandleCommandScanObjects(CommandLineArgEnumerator * enumerator);

#if defined(_WIN32) && _WIN32_WINNT >= 0x0600
#if defined(_WIN32)

static bool _removeShell = false;

Expand Down Expand Up @@ -133,7 +133,7 @@ const CommandLineCommand CommandLine::RootCommands[]
DefineCommand("scan-objects", "<path>", StandardOptions, HandleCommandScanObjects),
DefineCommand("handle-uri", "openrct2://.../", StandardOptions, CommandLine::HandleCommandUri),

#if defined(_WIN32) && _WIN32_WINNT >= 0x0600
#if defined(_WIN32)
DefineCommand("register-shell", "", RegisterShellOptions, HandleCommandRegisterShell),
#endif

Expand Down Expand Up @@ -400,7 +400,7 @@ static exitcode_t HandleCommandScanObjects([[maybe_unused]] CommandLineArgEnumer
return EXITCODE_OK;
}

#if defined(_WIN32) && _WIN32_WINNT >= 0x0600
#if defined(_WIN32)
static exitcode_t HandleCommandRegisterShell([[maybe_unused]] CommandLineArgEnumerator* enumerator)
{
exitcode_t result = CommandLine::HandleCommandDefault();
Expand All @@ -419,7 +419,7 @@ static exitcode_t HandleCommandRegisterShell([[maybe_unused]] CommandLineArgEnum
}
return EXITCODE_OK;
}
#endif // defined(_WIN32) && _WIN32_WINNT >= 0x0600
#endif // defined(_WIN32)

static void PrintAbout()
{
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/core/Crypt.CNG.cpp
Expand Up @@ -7,7 +7,7 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/

#if !defined(DISABLE_NETWORK) && defined(_WIN32) && (!defined(_WIN32_WINNT) || _WIN32_WINNT >= 0x0600)
#if !defined(DISABLE_NETWORK) && defined(_WIN32)

# include "Crypt.h"

Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/core/Crypt.OpenSSL.cpp
Expand Up @@ -7,7 +7,7 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/

#if !defined(DISABLE_NETWORK) && (!defined(_WIN32) || (defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0600))
#if !defined(DISABLE_NETWORK) && !defined(_WIN32)

# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
Expand Down
6 changes: 0 additions & 6 deletions src/openrct2/core/FileWatcher.cpp
Expand Up @@ -111,13 +111,7 @@ FileWatcher::FileWatcher(const std::string& directoryPath)
FileWatcher::~FileWatcher()
{
#ifdef _WIN32
# if _WIN32_WINNT < 0x0600
// TODO CancelIo is documented as not working across a different thread but
// CancelIoEx is not available.
CancelIo(_directoryHandle);
# else
CancelIoEx(_directoryHandle, nullptr);
# endif
CloseHandle(_directoryHandle);
#elif defined(__linux__)
_finished = true;
Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/core/Http.WinHttp.cpp
Expand Up @@ -7,7 +7,7 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/

#if !defined(DISABLE_HTTP) && defined(_WIN32) && (!defined(_WIN32_WINNT) || _WIN32_WINNT >= 0x0600)
#if !defined(DISABLE_HTTP) && defined(_WIN32)

# include "Http.h"

Expand Down
2 changes: 1 addition & 1 deletion src/openrct2/core/Http.cURL.cpp
Expand Up @@ -7,7 +7,7 @@
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/

#if !defined(DISABLE_HTTP) && (!defined(_WIN32) || (defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0600))
#if !defined(DISABLE_HTTP) && !defined(_WIN32)

# include "Http.h"

Expand Down
6 changes: 0 additions & 6 deletions src/openrct2/core/String.cpp
Expand Up @@ -704,7 +704,6 @@ namespace String
std::string ToUpper(std::string_view src)
{
#ifdef _WIN32
# if _WIN32_WINNT >= 0x0600
auto srcW = ToWideChar(src);

// Measure how long the destination needs to be
Expand All @@ -728,11 +727,6 @@ namespace String
}

return String::ToUtf8(dstW);
# else
std::string dst = std::string(src);
std::transform(dst.begin(), dst.end(), dst.begin(), [](unsigned char c) { return std::toupper(c); });
return dst;
# endif
#else
icu::UnicodeString str = icu::UnicodeString::fromUTF8(std::string(src));
str.toUpper();
Expand Down
7 changes: 0 additions & 7 deletions src/openrct2/network/Socket.cpp
Expand Up @@ -643,12 +643,6 @@ class TcpSocket final : public ITcpSocket, protected Socket
std::string GetIpAddressFromSocket(const sockaddr_in* addr) const
{
std::string result;
# if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0600
if (addr->sin_family == AF_INET)
{
result = inet_ntoa(addr->sin_addr);
}
# else
if (addr->sin_family == AF_INET)
{
char str[INET_ADDRSTRLEN]{};
Expand All @@ -662,7 +656,6 @@ class TcpSocket final : public ITcpSocket, protected Socket
inet_ntop(AF_INET6, &addrv6->sin6_addr, str, sizeof(str));
result = str;
}
# endif
return result;
}
};
Expand Down
86 changes: 9 additions & 77 deletions src/openrct2/platform/Platform.Win32.cpp
Expand Up @@ -21,15 +21,6 @@
# include <shlobj.h>
# undef GetEnvironmentVariable

# if _WIN32_WINNT >= 0x0600
# define __USE_SHGETKNOWNFOLDERPATH__
# define __USE_GETDATEFORMATEX__
# else
# ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
# define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
# endif
# endif

# include "../OpenRCT2.h"
# include "../common.h"
# include "../core/Path.hpp"
Expand All @@ -42,10 +33,6 @@
# include <iterator>
# include <locale>

# if _WIN32_WINNT < 0x600
# define swprintf_s(a, b, c, d, ...) swprintf(a, b, c, ##__VA_ARGS__)
# endif

// Native resource IDs
# include "../../../resources/resource.h"

Expand Down Expand Up @@ -80,11 +67,7 @@ char* strndup(const char* src, size_t size)

namespace Platform
{
# ifdef __USE_SHGETKNOWNFOLDERPATH__
static std::string WIN32_GetKnownFolderPath(REFKNOWNFOLDERID rfid);
# else
static std::string WIN32_GetFolderPath(int nFolder);
# endif
static std::string WIN32_GetModuleFileNameW(HMODULE hModule);

std::string GetEnvironmentVariable(std::string_view name)
Expand Down Expand Up @@ -128,11 +111,7 @@ namespace Platform
case SPECIAL_FOLDER::USER_CONFIG:
case SPECIAL_FOLDER::USER_DATA:
{
# ifdef __USE_SHGETKNOWNFOLDERPATH__
auto path = WIN32_GetKnownFolderPath(FOLDERID_Documents);
# else
auto path = WIN32_GetFolderPath(CSIDL_PERSONAL);
# endif
if (path.empty())
{
path = GetFolderPath(SPECIAL_FOLDER::USER_HOME);
Expand All @@ -141,11 +120,7 @@ namespace Platform
}
case SPECIAL_FOLDER::USER_HOME:
{
# ifdef __USE_SHGETKNOWNFOLDERPATH__
auto path = WIN32_GetKnownFolderPath(FOLDERID_Profile);
# else
auto path = WIN32_GetFolderPath(CSIDL_PROFILE);
# endif
if (path.empty())
{
path = GetHomePathViaEnvironment();
Expand All @@ -158,11 +133,7 @@ namespace Platform
}
case SPECIAL_FOLDER::RCT2_DISCORD:
{
# ifdef __USE_SHGETKNOWNFOLDERPATH__
auto path = WIN32_GetKnownFolderPath(FOLDERID_LocalAppData);
# else
auto path = WIN32_GetFolderPath(CSIDL_LOCAL_APPDATA);
# endif
if (!path.empty())
{
path = Path::Combine(path, u8"DiscordGames\\RollerCoaster Tycoon 2 Triple Thrill Pack\\content\\Game");
Expand Down Expand Up @@ -226,13 +197,8 @@ namespace Platform
std::string result;

wchar_t date[20];
# ifdef __USE_GETDATEFORMATEX__
ptrdiff_t charsWritten = GetDateFormatEx(
LOCALE_NAME_USER_DEFAULT, DATE_SHORTDATE, &st, nullptr, date, static_cast<int>(std::size(date)), nullptr);
# else
ptrdiff_t charsWritten = GetDateFormatW(
LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st, nullptr, date, static_cast<int>(std::size(date)));
# endif
if (charsWritten != 0)
{
result = String::ToUtf8(std::wstring_view(date, charsWritten - 1));
Expand All @@ -246,12 +212,8 @@ namespace Platform
std::string result;

wchar_t time[20];
# ifdef __USE_GETDATEFORMATEX__
ptrdiff_t charsWritten = GetTimeFormatEx(
LOCALE_NAME_USER_DEFAULT, 0, &st, nullptr, time, static_cast<int>(std::size(time)));
# else
ptrdiff_t charsWritten = GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, nullptr, time, static_cast<int>(std::size(time)));
# endif
if (charsWritten != 0)
{
result = String::ToUtf8(std::wstring_view(time, charsWritten - 1));
Expand Down Expand Up @@ -347,7 +309,6 @@ namespace Platform
return isSupported;
}

# ifdef __USE_SHGETKNOWNFOLDERPATH__
static std::string WIN32_GetKnownFolderPath(REFKNOWNFOLDERID rfid)
{
std::string path;
Expand All @@ -359,18 +320,6 @@ namespace Platform
CoTaskMemFree(wpath);
return path;
}
# else
static std::string WIN32_GetFolderPath(int nFolder)
{
std::string path;
wchar_t wpath[MAX_PATH];
if (SUCCEEDED(SHGetFolderPathW(nullptr, nFolder | CSIDL_FLAG_CREATE, nullptr, 0, wpath)))
{
path = String::ToUtf8(wpath);
}
return path;
}
# endif

static std::string WIN32_GetModuleFileNameW(HMODULE hModule)
{
Expand Down Expand Up @@ -408,7 +357,6 @@ namespace Platform
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nullptr, nullptr);
}

# if _WIN32_WINNT >= 0x0600
static HMODULE _dllModule = nullptr;
static HMODULE GetDLLModule()
{
Expand All @@ -425,13 +373,11 @@ namespace Platform
auto progIdNameW = String::ToWideChar(progIdName);
return progIdNameW;
}
# endif

bool SetUpFileAssociation(
std::string_view extension, std::string_view fileTypeText, std::string_view commandText, std::string_view commandArgs,
const uint32_t iconIndex)
{
# if _WIN32_WINNT >= 0x0600
wchar_t exePathW[MAX_PATH];
wchar_t dllPathW[MAX_PATH];

Expand Down Expand Up @@ -514,13 +460,11 @@ namespace Platform
RegCloseKey(hRootKey);
return false;
}
# endif
return true;
}

static void RemoveFileAssociation(const utf8* extension)
{
# if _WIN32_WINNT >= 0x0600
// [HKEY_CURRENT_USER\Software\Classes]
HKEY hRootKey;
if (RegOpenKeyW(HKEY_CURRENT_USER, SOFTWARE_CLASSES, &hRootKey) == ERROR_SUCCESS)
Expand All @@ -534,7 +478,6 @@ namespace Platform

RegCloseKey(hRootKey);
}
# endif
}

void RemoveFileAssociations()
Expand Down Expand Up @@ -748,7 +691,6 @@ namespace Platform

uint8_t GetLocaleDateFormat()
{
# 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, static_cast<int>(std::size(dateFormat)))
Expand Down Expand Up @@ -791,7 +733,6 @@ namespace Platform
// Closest possible option
return DATE_FORMAT_YEAR_MONTH_DAY;
}
# endif

// Default fallback
return DATE_FORMAT_DAY_MONTH_YEAR;
Expand Down Expand Up @@ -870,11 +811,7 @@ namespace Platform

std::string GetFontPath(const TTFFontDescriptor& font)
{
# if defined(__USE_SHGETKNOWNFOLDERPATH__)
auto path = WIN32_GetKnownFolderPath(FOLDERID_Fonts);
# else
auto path = WIN32_GetFolderPath(CSIDL_FONTS);
# endif
return !path.empty() ? Path::Combine(path, font.filename) : std::string();
}

Expand All @@ -890,23 +827,20 @@ namespace Platform

bool LockSingleInstance()
{
HANDLE mutex, status;

// Check if operating system mutex exists
mutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, SINGLE_INSTANCE_MUTEX_NAME);
HANDLE mutex = CreateMutex(nullptr, FALSE, SINGLE_INSTANCE_MUTEX_NAME);
if (mutex == nullptr)
{
// Create new mutex
status = CreateMutex(nullptr, FALSE, SINGLE_INSTANCE_MUTEX_NAME);
if (status == nullptr)
log_error("unable to create mutex");

log_error("unable to create mutex");
return true;
}

// Already running
CloseHandle(mutex);
return false;
else if (GetLastError() == ERROR_ALREADY_EXISTS)
{
// Already running
CloseHandle(mutex);
return false;
}
return true;
}

int32_t GetDrives()
Expand Down Expand Up @@ -960,7 +894,6 @@ namespace Platform

bool SetupUriProtocol()
{
# if _WIN32_WINNT >= 0x0600
log_verbose("Setting up URI protocol...");

// [HKEY_CURRENT_USER\Software\Classes]
Expand Down Expand Up @@ -1002,7 +935,6 @@ namespace Platform
}
}
}
# endif

log_verbose("URI protocol setup failed");
return false;
Expand Down

0 comments on commit dc7e31f

Please sign in to comment.