From e7d7d89066861ddc2774b1fd70fca8ae0511199b Mon Sep 17 00:00:00 2001 From: Bashar Astifan Date: Wed, 4 Sep 2024 22:56:37 +0400 Subject: [PATCH] Simplify & win11-build check fix Without build check on Windows 10 it will appear as Windows 11, I forgot to keep build check, also the process can be simplified more to avoid extra functions. --- Common/OSVersion.cpp | 25 +++++++++++++------------ Common/OSVersion.h | 3 ++- Core/Config.cpp | 6 +++--- Windows/MainWindow.cpp | 2 +- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/Common/OSVersion.cpp b/Common/OSVersion.cpp index 75ea112838..a69b8217c7 100644 --- a/Common/OSVersion.cpp +++ b/Common/OSVersion.cpp @@ -46,7 +46,7 @@ bool GetVersionFromKernel32(uint32_t &major, uint32_t &minor, uint32_t &build) { #endif } -bool DoesVersionMatchWindows(uint32_t major, uint32_t minor, uint32_t spMajor, uint32_t spMinor, bool greater) { +bool DoesVersionMatchWindows(uint32_t major, uint32_t minor, uint32_t spMajor, uint32_t spMinor, uint32_t build, bool greater) { #if !PPSSPP_PLATFORM(UWP) if (spMajor == 0 && spMinor == 0) { // "Applications not manifested for Windows 10 will return the Windows 8 OS version value (6.2)." @@ -55,7 +55,9 @@ bool DoesVersionMatchWindows(uint32_t major, uint32_t minor, uint32_t spMajor, u if (GetVersionFromKernel32(actualMajor, actualMinor, actualBuild)) { if (greater) return actualMajor > major || (major == actualMajor && actualMinor >= minor); - return major == actualMajor && minor == actualMinor; + + // To detect Windows 11 we must check build number + return major == actualMajor && minor == actualMinor && actualBuild >= build; } } @@ -86,25 +88,25 @@ bool DoesVersionMatchWindows(uint32_t major, uint32_t minor, uint32_t spMajor, u return VerifyVersionInfo(&osvi, typeMask, conditionMask) != FALSE; #else - if (greater) { + if (greater) return true; - } return false; #endif } -bool DoesVersionMatchWindows(WindowsReleaseInfo release) { - return DoesVersionMatchWindows(release.major, release.minor, release.spMajor, release.spMinor, release.greater); -} - bool IsVistaOrHigher() { // Vista is 6.0 - return DoesVersionMatchWindows(6, 0, 0, 0, true); + return DoesVersionMatchWindows(6, 0, 0, 0, 0, true); } bool IsWin7OrHigher() { // Win7 is 6.1 - return DoesVersionMatchWindows(6, 1, 0, 0, true); + return DoesVersionMatchWindows(6, 1, 0, 0, 0, true); +} + +bool IsWin8OrHigher() { + // Win8 is 6.2 + return DoesVersionMatchWindows(6, 2, 0, 0, 0, true); } std::string GetWindowsVersion() { @@ -126,8 +128,7 @@ std::string GetWindowsVersion() { // Start from higher to lower for (auto release = rbegin(windowsReleases); release != rend(windowsReleases); ++release) { WindowsReleaseInfo releaseInfo = release->second; - bool buildMatch = DoesVersionMatchWindows(releaseInfo); - if (buildMatch) { + if (DoesVersionMatchWindows(releaseInfo.major, releaseInfo.minor, releaseInfo.spMajor, releaseInfo.spMinor, releaseInfo.build, releaseInfo.greater)) { std::string previewText = release->first; return previewText; } diff --git a/Common/OSVersion.h b/Common/OSVersion.h index 0e44a4f205..c1704b85df 100644 --- a/Common/OSVersion.h +++ b/Common/OSVersion.h @@ -6,7 +6,8 @@ bool IsVistaOrHigher(); bool IsWin7OrHigher(); -bool DoesVersionMatchWindows(uint32_t major, uint32_t minor, uint32_t spMajor, uint32_t spMinor, bool acceptGreater); +bool IsWin8OrHigher(); +bool DoesVersionMatchWindows(uint32_t major, uint32_t minor, uint32_t spMajor, uint32_t spMinor, uint32_t build, bool acceptGreater); bool GetVersionFromKernel32(uint32_t& major, uint32_t& minor, uint32_t& build); std::string GetWindowsVersion(); diff --git a/Core/Config.cpp b/Core/Config.cpp index 5d2348d735..9e24732136 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -423,7 +423,7 @@ static int DefaultGPUBackend() { #if PPSSPP_PLATFORM(WINDOWS) // If no Vulkan, use Direct3D 11 on Windows 8+ (most importantly 10.) - if (DoesVersionMatchWindows(6, 2, 0, 0, true)) { + if (IsWin8OrHigher()) { return (int)GPUBackend::DIRECT3D11; } #elif PPSSPP_PLATFORM(ANDROID) @@ -489,7 +489,7 @@ int Config::NextValidBackend() { } #endif #if PPSSPP_PLATFORM(WINDOWS) - if (!failed.count(GPUBackend::DIRECT3D11) && DoesVersionMatchWindows(6, 1, 0, 0, true)) { + if (!failed.count(GPUBackend::DIRECT3D11) && IsWin7OrHigher()) { return (int)GPUBackend::DIRECT3D11; } #endif @@ -536,7 +536,7 @@ bool Config::IsBackendEnabled(GPUBackend backend) { if (backend != GPUBackend::OPENGL) return false; #elif PPSSPP_PLATFORM(WINDOWS) - if (backend == GPUBackend::DIRECT3D11 && !DoesVersionMatchWindows(6, 0, 0, 0, true)) + if (backend == GPUBackend::DIRECT3D11 && !IsVistaOrHigher()) return false; #else if (backend == GPUBackend::DIRECT3D11 || backend == GPUBackend::DIRECT3D9) diff --git a/Windows/MainWindow.cpp b/Windows/MainWindow.cpp index 8921e9c985..09857e31d2 100644 --- a/Windows/MainWindow.cpp +++ b/Windows/MainWindow.cpp @@ -765,7 +765,7 @@ namespace MainWindow switch (message) { case WM_CREATE: - if (!DoesVersionMatchWindows(6, 0, 0, 0, true)) { + if (!IsVistaOrHigher()) { // Remove the D3D11 choice on versions below XP RemoveMenu(GetMenu(hWnd), ID_OPTIONS_DIRECT3D11, MF_BYCOMMAND); }