diff --git a/src/librpsecure/win32/integrity_level.c b/src/librpsecure/win32/integrity_level.c index 482808e9d..8ff56d84a 100644 --- a/src/librpsecure/win32/integrity_level.c +++ b/src/librpsecure/win32/integrity_level.c @@ -2,7 +2,7 @@ * ROM Properties Page shell extension. (librpsecure/win32) * * integrity_level.c: Integrity level manipulation for process tokens. * * * - * Copyright (c) 2020-2022 by David Korth. * + * Copyright (c) 2020-2023 by David Korth. * * SPDX-License-Identifier: GPL-2.0-or-later * ***************************************************************************/ @@ -11,50 +11,20 @@ #include "integrity_level.h" -// C includes. +// C includes #include #include #include #include -// Windows includes. +// Windows includes #include #include +#include // stdboolx #include "stdboolx.h" -/** - * Check if we're running Windows Vista or later. - * @return True if running Vista; false if not. - */ -static bool isRunningVista(void) -{ - // Are we running Windows Vista or later? - // NOTE: Technically not thread-safe, but the worst that will - // happen is two threads set isVista to the same value. - static bool isVista = false; - static bool hasCheckedVista = false; - OSVERSIONINFO osvi; - - if (hasCheckedVista) { - return isVista; - } - -#ifdef _MSC_VER -# pragma warning(push) -# pragma warning(disable: 4996) -#endif /* _MSC_VER */ - // TODO: Use versionhelpers.h. - osvi.dwOSVersionInfoSize = sizeof(osvi); - isVista = (GetVersionEx(&osvi) && osvi.dwMajorVersion >= 6); -#ifdef _MSC_VER -# pragma warning(pop) -#endif /* _MSC_VER */ - - return isVista; -} - /** * Adjust a token's integrity level. * @param hToken Token. @@ -144,7 +114,7 @@ HANDLE CreateIntegrityLevelToken(int level) DWORD dwRet; // Are we running Windows Vista or later? - if (!isRunningVista()) { + if (!IsWindowsVistaOrGreater()) { // Not running Windows Vista or later. // Can't create a low-integrity token. return NULL; @@ -210,7 +180,7 @@ int GetProcessIntegrityLevel(void) DWORD dwLengthNeeded; // Are we running Windows Vista or later? - if (!isRunningVista()) { + if (!IsWindowsVistaOrGreater()) { // Not running Windows Vista or later. // Can't get the integrity level. return ret; @@ -289,7 +259,7 @@ DWORD SetProcessIntegrityLevel(int level) DWORD dwRet; // Are we running Windows Vista or later? - if (!isRunningVista()) { + if (!IsWindowsVistaOrGreater()) { // Not running Windows Vista or later. // Can't set the process integrity level. // We'll pretend everything "just works" anyway. diff --git a/src/librpsecure/win32/secoptions.c b/src/librpsecure/win32/secoptions.c index 3676bedac..dcffcb2c6 100644 --- a/src/librpsecure/win32/secoptions.c +++ b/src/librpsecure/win32/secoptions.c @@ -2,7 +2,7 @@ * ROM Properties Page shell extension. (librpsecure/win32) * * secoptions.c: Security options for executables. * * * - * Copyright (c) 2016-2022 by David Korth. * + * Copyright (c) 2016-2023 by David Korth. * * SPDX-License-Identifier: GPL-2.0-or-later * ***************************************************************************/ @@ -11,17 +11,18 @@ #include "secoptions.h" -// C includes. +// C includes #include #include #include #include -// Windows includes. +// Windows includes #include #include #include #include +#include #ifndef _WIN64 @@ -216,7 +217,6 @@ static DWORD HardenProcessIntegrityLevelPolicy(void) */ int rp_secure_win32_secoptions_init(int bHighSec) { - OSVERSIONINFO osvi; HMODULE hKernel32; PFNHEAPSETINFORMATION pfnHeapSetInformation; PFNSETDLLDIRECTORYW pfnSetDllDirectoryW; @@ -243,25 +243,6 @@ int rp_secure_win32_secoptions_init(int bHighSec) return GetLastError(); } -#ifdef _MSC_VER -# pragma warning(push) -# pragma warning(disable: 4996) -#endif /* _MSC_VER */ - // GetVersionEx() should never fail... - osvi.dwOSVersionInfoSize = sizeof(osvi); - bRet = GetVersionEx(&osvi); - assert(bRet != 0); - if (!bRet) { - // GetVersionEx() failed somehow. - // Assume we're running Windows XP. - osvi.dwMajorVersion = 5; - osvi.dwMinorVersion = 1; - osvi.dwBuildNumber = 2600; - } -#ifdef _MSC_VER -# pragma warning(pop) -#endif /* _MSC_VER */ - /** BEGIN: Windows XP/2003 **/ // Remove the current directory from the DLL search path. // TODO: Enable and test this. @@ -327,7 +308,7 @@ int rp_secure_win32_secoptions_init(int bHighSec) } #endif /* !_WIN64 */ - if (osvi.dwMajorVersion < 6) { + if (!IsWindowsVistaOrGreater()) { // We're done here. return 0; } @@ -338,9 +319,7 @@ int rp_secure_win32_secoptions_init(int bHighSec) // Harden the process's integrity level policy. HardenProcessIntegrityLevelPolicy(); - if ((osvi.dwMajorVersion == 6 && osvi.dwMinorVersion < 2) || - osvi.dwMajorVersion < 7) - { + if (!IsWindows8OrGreater()) { // We're done here. return 0; } diff --git a/src/rp-download/IDownloader.cpp b/src/rp-download/IDownloader.cpp index d4cf6db3a..e6f08593c 100644 --- a/src/rp-download/IDownloader.cpp +++ b/src/rp-download/IDownloader.cpp @@ -32,9 +32,6 @@ IDownloader::IDownloader() , m_if_modified_since(-1) , m_maxSize(0) , m_inProgress(false) -#ifdef _WIN32 - , m_isWinXP(false) -#endif /* _WIN32 */ { createUserAgent(); } @@ -45,9 +42,6 @@ IDownloader::IDownloader(const TCHAR *url) , m_if_modified_since(-1) , m_maxSize(0) , m_inProgress(false) -#ifdef _WIN32 - , m_isWinXP(false) -#endif /* _WIN32 */ { createUserAgent(); } @@ -58,9 +52,6 @@ IDownloader::IDownloader(const tstring &url) , m_if_modified_since(-1) , m_maxSize(0) , m_inProgress(false) -#ifdef _WIN32 - , m_isWinXP(false) -#endif /* _WIN32 */ { createUserAgent(); } @@ -263,9 +254,6 @@ tstring IDownloader::getOSRelease(void) _sntprintf(buf, _countof(buf), _T("%lu.%lu"), osvi.dwMajorVersion, osvi.dwMinorVersion); s_os_release += buf; - // Check if we're using an older (pre-Vista) version of Windows. - m_isWinXP = (osvi.dwMajorVersion < 6); - # ifdef _WIN64 s_os_release += _T("; Win64"); # else /* !_WIN64 */ diff --git a/src/rp-download/IDownloader.hpp b/src/rp-download/IDownloader.hpp index 540760665..8d1b06ca9 100644 --- a/src/rp-download/IDownloader.hpp +++ b/src/rp-download/IDownloader.hpp @@ -148,9 +148,6 @@ class IDownloader std::tstring m_userAgent; // User-Agent bool m_inProgress; // Set when downloading -#ifdef _WIN32 - bool m_isWinXP; // Set for Windows versions older than Vista -#endif /* _WIN32 */ }; } diff --git a/src/rp-download/WinInetDownloader.cpp b/src/rp-download/WinInetDownloader.cpp index b3d411fc6..ad47d9985 100644 --- a/src/rp-download/WinInetDownloader.cpp +++ b/src/rp-download/WinInetDownloader.cpp @@ -2,7 +2,7 @@ * ROM Properties Page shell extension. (rp-download) * * WinInetDownloader.cpp: WinInet-based file downloader. * * * - * Copyright (c) 2016-2022 by David Korth. * + * Copyright (c) 2016-2023 by David Korth. * * SPDX-License-Identifier: GPL-2.0-or-later * ***************************************************************************/ @@ -14,11 +14,12 @@ #include "libwin32common/w32err.hpp" #include "libwin32common/w32time.h" -// C++ STL classes. +// C++ STL classes using std::string; using std::wstring; -// Windows includes. +// Windows includes +#include #include namespace RpDownload { @@ -69,7 +70,7 @@ int WinInetDownloader::download(void) INTERNET_FLAG_NO_AUTH | INTERNET_FLAG_NO_COOKIES | INTERNET_FLAG_NO_UI; - if (m_isWinXP) { + if (!IsWindowsVistaOrGreater()) { // WinInet doesn't support SNI prior to Vista. static const TCHAR rpdb_domain[] = _T("https://rpdb.gerbilsoft.com/"); if (m_url.size() >= _countof(rpdb_domain) && diff --git a/src/svrplus/svrplus.c b/src/svrplus/svrplus.c index dbb88f7cb..90c705f8c 100644 --- a/src/svrplus/svrplus.c +++ b/src/svrplus/svrplus.c @@ -29,9 +29,10 @@ #include "librpsecure/restrict-dll.h" // Additional Windows headers -#include -#include #include +#include +#include +#include // Older versions of the Windows SDK might be missing some ARM systems. #ifndef IMAGE_FILE_MACHINE_ARM @@ -669,8 +670,8 @@ static void InitDialog(HWND hDlg) LPCTSTR s_strtbl; int ls_ret; - // OS version check. - OSVERSIONINFO osvi; + // OS version check + // MSVC 2022 runtime requires Windows Vista or later. unsigned int vcyear, vcver; static_assert(ARRAY_SIZE(g_archs) == ARRAY_SIZE(bHasMsvcForArch), "bHasMsvcForArch[] is out of sync with g_archs[]!"); @@ -735,14 +736,12 @@ static void InitDialog(HWND hDlg) SetWindowText(GetDlgItem(hDlg, IDC_STATIC_DESC), (ls_ret > 0) ? s_strtbl : _T("RES ERR")); // MSVC 2022 runtime requires Windows Vista or later. - osvi.dwOSVersionInfoSize = sizeof(osvi); - if (GetVersionEx(&osvi) != 0 && osvi.dwMajorVersion >= 6) { + if (IsWindowsVistaOrGreater()) { // Windows Vista or later. Use MSVC 2022. vcyear = 2022; vcver = 17; } else { - // Windows XP/2003 or earlier, or GetVersionEx() failed. - // Use MSVC 2017. + // Windows XP/2003 or earlier. Use MSVC 2017. vcyear = 2017; vcver = 15; } diff --git a/src/win32/AchWin32.cpp b/src/win32/AchWin32.cpp index 9b3dfc582..cfcc24642 100644 --- a/src/win32/AchWin32.cpp +++ b/src/win32/AchWin32.cpp @@ -23,10 +23,10 @@ using namespace LibRpBase; using LibRpFile::RpFile_windres; using LibRpTexture::rp_image; -// ROM icon. +// ROM icon #include "config/PropSheetIcon.hpp" -// C++ STL classes. +// C++ STL classes using std::string; using std::tstring; using std::unordered_map; @@ -362,9 +362,7 @@ int AchWin32Private::notifyFunc(Achievements::ID id) // TODO: DPI awareness. const UINT dpi = rp_GetDpiForWindow(hNotifyWnd); int iconSize; - OSVERSIONINFO osvi; - osvi.dwOSVersionInfoSize = sizeof(osvi); - if (GetVersionEx(&osvi) && osvi.dwMajorVersion >= 6) { + if (IsWindowsVistaOrGreater()) { // Windows Vista or later. Use the large icon. nid.dwInfoFlags |= NIIF_LARGE_ICON; iconSize = 32; diff --git a/src/win32/RP_ExtractIcon.cpp b/src/win32/RP_ExtractIcon.cpp index ce3a69dea..a02a09f85 100644 --- a/src/win32/RP_ExtractIcon.cpp +++ b/src/win32/RP_ExtractIcon.cpp @@ -34,10 +34,10 @@ RP_ExtractIcon_Private::RP_ExtractIcon_Private() // Enable icon squaring only on Windows XP. // On Windows 7 and 11, it causes the icon to look "squished" // if the original image is taller than it is wide. - OSVERSIONINFO osvi; - osvi.dwOSVersionInfoSize = sizeof(osvi); - if (GetVersionEx(&osvi) == 0 || osvi.dwMajorVersion < 6) { - // GetVersionEx() failed, or we're running Windows XP. + if (!IsWindowsVistaOrGreater()) { + // Not running Windows Vista or later. + // This must be Windows XP or earlier. + // Enable icon squaring. thumbnailer.setDoSquaring(true); } } diff --git a/src/win32/stdafx.h b/src/win32/stdafx.h index 2e8efc518..53c50da8b 100644 --- a/src/win32/stdafx.h +++ b/src/win32/stdafx.h @@ -25,12 +25,13 @@ #include "libwin32common/sdk/windowsx_ts.h" #include "libwin32common/sdk/commctrl_ts.h" -// Additional Windows headers. +// Additional Windows headers #include #include #include #include #include +#include // FIXME: shlobj.h on MinGW-w64 on AppVeyor doesn't properly inline a few // functions when building in C mode, resulting in multiple definition errors.