/*** Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved. File: AuVersionHelpers.cpp Date: 2022-1-25 Author: Reece ***/ #include #include "AuSWInfo.hpp" // NO HEADER (note -> .hpp wouldn't clash with windows' sdk) namespace Aurora::SWInfo { static AuUInt16 kWinVerNT4 = 0x0400; static AuUInt16 kWinVerWin2K = 0x0500; static AuUInt16 kWinVerWinXP = 0x0501; static AuUInt16 kWinVerWS03 = 0x0502; static AuUInt16 kWinVerWin6 = 0x0600; static AuUInt16 kWinVerVista = 0x0600; static AuUInt16 kWinVerWS08 = 0x0600; static AuUInt16 kWinVerWin7 = 0x0601; static AuUInt16 kWinVerWin8 = 0x0602; static AuUInt16 kWinVerWinBlue = 0x0603; static AuUInt16 kWinVerWin10 = 0x0A00; static AuUInt16 kKernPatchWin11 = 22000; static bool IsWindowsVersionOrGreater(AuUInt8 major, AuUInt8 minor, AuUInt16 sp) { auto &info = GetPlatformInfo(); return info.ePlatform == Build::EPlatform::ePlatformWin32 && (info.uKernelMajor > major || (info.uKernelMajor == major && info.uKernelMinor >= minor)) && ((info.uKernelMajor == major && info.uKernelMinor == minor) ? info.uUserlandMinor >= sp : true); } AUKN_SYM bool IsWindowsXPOrGreater() { return IsWindowsVersionOrGreater(AuBitsToHigher(kWinVerWinXP), AuBitsToLower(kWinVerWinXP), 0); } AUKN_SYM bool IsWindowsXPSP1OrGreater() { return IsWindowsVersionOrGreater(AuBitsToHigher(kWinVerWinXP), AuBitsToLower(kWinVerWinXP), 1); } AUKN_SYM bool IsWindowsXPSP2OrGreater() { return IsWindowsVersionOrGreater(AuBitsToHigher(kWinVerWinXP), AuBitsToLower(kWinVerWinXP), 2); } AUKN_SYM bool IsWindowsXPSP3OrGreater() { return IsWindowsVersionOrGreater(AuBitsToHigher(kWinVerWinXP), AuBitsToLower(kWinVerWinXP), 3); } AUKN_SYM bool IsWindowsVistaOrGreater() { return IsWindowsVersionOrGreater(AuBitsToHigher(kWinVerVista), AuBitsToLower(kWinVerVista), 0); } AUKN_SYM bool IsWindowsVistaSP1OrGreater() { return IsWindowsVersionOrGreater(AuBitsToHigher(kWinVerVista), AuBitsToLower(kWinVerVista), 1); } AUKN_SYM bool IsWindowsVistaSP2OrGreater() { return IsWindowsVersionOrGreater(AuBitsToHigher(kWinVerVista), AuBitsToLower(kWinVerVista), 2); } AUKN_SYM bool IsWindows7OrGreater() { return IsWindowsVersionOrGreater(AuBitsToHigher(kWinVerWin7), AuBitsToLower(kWinVerWin7), 0); } AUKN_SYM bool IsWindows7SP1OrGreater() { return IsWindowsVersionOrGreater(AuBitsToHigher(kWinVerWin7), AuBitsToLower(kWinVerWin7), 1); } AUKN_SYM bool IsWindows8OrGreater() { return IsWindowsVersionOrGreater(AuBitsToHigher(kWinVerWin8), AuBitsToLower(kWinVerWin8), 0); } AUKN_SYM bool IsWindows8Point1OrGreater() { return IsWindowsVersionOrGreater(AuBitsToHigher(kWinVerWinBlue), AuBitsToLower(kWinVerWinBlue), 0); } AUKN_SYM bool IsWindows10OrGreater() { return IsWindowsVersionOrGreater(AuBitsToHigher(kWinVerWin10), AuBitsToLower(kWinVerWin10), 0); } AUKN_SYM bool IsWindows11OrGreater() { auto &info = GetPlatformInfo(); return IsWindowsVersionOrGreater(AuBitsToHigher(kWinVerWin10), AuBitsToLower(kWinVerWin10), 0) && (info.uKernelPatch >= kKernPatchWin11 || info.uKernelMajor > AuBitsToHigher(kWinVerWin10)); } #define ADD_ABS_CHECK(A, B) \ AUKN_SYM bool IsWindows ## A() \ { \ return IsWindows ## A ## OrGreater() && !IsWindows ## B ## OrGreater(); \ } ADD_ABS_CHECK(XP, XPSP1) ADD_ABS_CHECK(XPSP1, XPSP2) ADD_ABS_CHECK(XPSP2, XPSP3) ADD_ABS_CHECK(XPSP3, Vista) ADD_ABS_CHECK(Vista, VistaSP1) ADD_ABS_CHECK(VistaSP1, VistaSP2) ADD_ABS_CHECK(VistaSP2, 7) ADD_ABS_CHECK(7, 7SP1) ADD_ABS_CHECK(7SP1, 8) ADD_ABS_CHECK(8, 8Point1) ADD_ABS_CHECK(8Point1, 10) ADD_ABS_CHECK(10, 11) AUKN_SYM bool IsWindows11() { return IsWindows11OrGreater(); } AUKN_SYM bool IsWindowsXPAny() { return IsWindowsXPOrGreater() && !IsWindowsVistaOrGreater(); } AUKN_SYM bool IsWindowsVistaAny() { return IsWindowsVistaOrGreater() && !IsWindows7OrGreater(); } AUKN_SYM bool IsWindows7Any() { return IsWindows7OrGreater() && !IsWindows8OrGreater(); } AUKN_SYM bool IsWindows8Any() { return IsWindows8OrGreater() && !IsWindows10OrGreater(); } }