AuroraRuntime/Source/SWInfo/AuVersionHelpers.cpp

204 lines
7.5 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuVersionHelpers.cpp
Date: 2022-1-25
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "AuSWInfo.hpp"
// NO HEADER (note -> .hpp wouldn't clash with windows' sdk)
namespace Aurora::SWInfo
{
static const AuUInt16 kWinVerNT4 = 0x0400;
static const AuUInt16 kWinVerWin2K = 0x0500;
static const AuUInt16 kWinVerWinXP = 0x0501;
static const AuUInt16 kWinVerWS03 = 0x0502;
static const AuUInt16 kWinVerWin6 = 0x0600;
static const AuUInt16 kWinVerVista = 0x0600;
static const AuUInt16 kWinVerWS08 = 0x0600;
static const AuUInt16 kWinVerWin7 = 0x0601;
static const AuUInt16 kWinVerWin8 = 0x0602;
static const AuUInt16 kWinVerWinBlue = 0x0603;
static const AuUInt16 kWinVerWin10 = 0x0A00;
static const AuUInt16 kKernPatchWin11 = 22000;
static const AuUInt16 kWin10KernPatchTH1 = 10240;
static const AuUInt16 kWin10KernPatchTH2 = 10586;
static const AuUInt16 kWin10KernPatchRS1 = 14393;
static const AuUInt16 kWin10KernPatchRS2 = 15063;
static const AuUInt16 kWin10KernPatchRS3 = 16299;
static const AuUInt16 kWin10KernPatchRS4 = 17134;
static const AuUInt16 kWin10KernPatchRS5 = 17763;
static const AuUInt16 kWin10KernPatch19H1 = 18362;
static const AuUInt16 kWin10KernPatch19H2 = 18363;
static const AuUInt16 kWin10KernPatch20H1 = 19041;
static const AuUInt16 kWin10KernPatch20H2 = 19042;
static const AuUInt16 kWin10KernPatch21H1 = 19043;
static const AuUInt16 kWin10KernPatch21H2 = 19044;
static const AuUInt16 kWin10KernPatch22H2 = 19045;
static const AuUInt16 kWin10KernPatchDummy = kKernPatchWin11;
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);
}
static bool DoWin10PatchGreaterCheck(AuUInt32 uPatch)
{
auto &info = GetPlatformInfo();
return info.ePlatform == Build::EPlatform::ePlatformWin32 &&
(info.uKernelMajor > AuBitsToHigher(kWinVerWin10) ||
(info.uKernelMajor == AuBitsToHigher(kWinVerWin10) &&
info.uKernelMinor || info.uKernelPatch >= uPatch));
}
static bool DoWin10PatchEqCheck(AuUInt32 uPatch, AuUInt32 uPatch2)
{
auto &info = GetPlatformInfo();
return info.ePlatform == Build::EPlatform::ePlatformWin32 &&
info.uKernelPatch >= uPatch &&
info.uKernelPatch < uPatch2 &&
info.uKernelMajor == AuBitsToHigher(kWinVerWin10) &&
info.uKernelMinor == AuBitsToLower(kWinVerWin10);
}
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()
{
return DoWin10PatchGreaterCheck(kKernPatchWin11);
}
#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();
}
#define ADD_WIN10_VER(name, next) \
\
AUKN_SYM bool IsWindows10Milestone ## name ## OrGreater() \
{ \
return DoWin10PatchGreaterCheck(kWin10KernPatch ## name); \
} \
\
AUKN_SYM bool IsWindows10Milestone ## name() \
{ \
return DoWin10PatchEqCheck(kWin10KernPatch ## name, kWin10KernPatch ## next); \
}
ADD_WIN10_VER(TH1, TH2);
ADD_WIN10_VER(TH2, RS1);
ADD_WIN10_VER(RS1, RS2);
ADD_WIN10_VER(RS2, RS3);
ADD_WIN10_VER(RS3, RS4);
ADD_WIN10_VER(RS4, RS5);
ADD_WIN10_VER(RS5, 19H1);
ADD_WIN10_VER(19H1, 19H2);
ADD_WIN10_VER(19H2, 20H1);
ADD_WIN10_VER(20H1, 20H2);
ADD_WIN10_VER(20H2, 21H1);
ADD_WIN10_VER(21H1, 21H2);
ADD_WIN10_VER(21H2, 22H2);
ADD_WIN10_VER(22H2, Dummy);
}