mirror of
https://github.com/LegacyUpdate/LegacyUpdate.git
synced 2025-01-22 14:12:07 -05:00
107 lines
2.9 KiB
C
107 lines
2.9 KiB
C
#pragma once
|
|
|
|
#include <windows.h>
|
|
|
|
// Windows 11 Copper (22H2). "WIN10" typo is from the original sdkddkvers.h
|
|
#ifndef NTDDI_WIN10_CU
|
|
#define NTDDI_WIN10_CU 0x0A00000D
|
|
#endif
|
|
|
|
#define BUILD_WIN10_1507 10240
|
|
#define BUILD_WIN10_1511 10586
|
|
#define BUILD_WIN10_1607 14393
|
|
#define BUILD_WIN10_1703 15063
|
|
#define BUILD_WIN10_1709 16299
|
|
#define BUILD_WIN10_1803 17134
|
|
#define BUILD_WIN10_1809 17763
|
|
#define BUILD_WIN10_1903 18362
|
|
#define BUILD_WIN10_1909 18363
|
|
#define BUILD_WIN10_2004 19041
|
|
#define BUILD_WIN10_20H2 19042
|
|
#define BUILD_WIN10_21H1 19043
|
|
#define BUILD_WIN10_21H2 19044
|
|
#define BUILD_WIN10_22H2 19045
|
|
#define BUILD_WIN11_21H1 22000
|
|
#define BUILD_WIN11_22H2 22621
|
|
#define BUILD_WIN11_23H2 22631
|
|
#define BUILD_WIN11_24H2 26100
|
|
|
|
EXTERN_C IMAGE_DOS_HEADER __ImageBase;
|
|
|
|
static BOOL _loadedVersionInfo = FALSE;
|
|
static OSVERSIONINFOEX _versionInfo;
|
|
static DWORD _winVer;
|
|
|
|
static inline OSVERSIONINFOEX *GetVersionInfo() {
|
|
if (!_loadedVersionInfo) {
|
|
_loadedVersionInfo = TRUE;
|
|
ZeroMemory(&_versionInfo, sizeof(OSVERSIONINFOEX));
|
|
_versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
|
|
GetVersionEx((LPOSVERSIONINFO)&_versionInfo);
|
|
_winVer = (_versionInfo.dwMajorVersion << 8) | _versionInfo.dwMinorVersion;
|
|
}
|
|
return &_versionInfo;
|
|
}
|
|
|
|
#define _IS_OS_MACRO(name, ver) \
|
|
static inline BOOL IsWin ## name() { \
|
|
GetVersionInfo(); \
|
|
return _winVer == ver; \
|
|
} \
|
|
static inline BOOL AtLeastWin ## name() { \
|
|
GetVersionInfo(); \
|
|
return _winVer >= ver; \
|
|
} \
|
|
static inline BOOL AtMostWin ## name() { \
|
|
GetVersionInfo(); \
|
|
return _winVer <= ver; \
|
|
}
|
|
|
|
_IS_OS_MACRO(NT4, 0x0400)
|
|
_IS_OS_MACRO(2000, 0x0500)
|
|
_IS_OS_MACRO(XP2002, 0x0501)
|
|
_IS_OS_MACRO(XP2003, 0x0502)
|
|
_IS_OS_MACRO(Vista, 0x0600)
|
|
_IS_OS_MACRO(7, 0x0601)
|
|
_IS_OS_MACRO(8, 0x0602)
|
|
_IS_OS_MACRO(8_1, 0x0603)
|
|
_IS_OS_MACRO(10, 0x0A00)
|
|
#undef _IS_OS_MACRO
|
|
|
|
#define _IS_BUILD_MACRO(ver) \
|
|
static inline BOOL IsWin ## ver() { \
|
|
return GetVersionInfo()->dwBuildNumber == BUILD_WIN ## ver; \
|
|
} \
|
|
static inline BOOL AtLeastWin ## ver() { \
|
|
return GetVersionInfo()->dwBuildNumber >= BUILD_WIN ## ver; \
|
|
} \
|
|
static inline BOOL AtMostWin ## ver() { \
|
|
return GetVersionInfo()->dwBuildNumber <= BUILD_WIN ## ver; \
|
|
}
|
|
|
|
_IS_BUILD_MACRO(10_1507)
|
|
_IS_BUILD_MACRO(10_1511)
|
|
_IS_BUILD_MACRO(10_1607)
|
|
_IS_BUILD_MACRO(10_1703)
|
|
_IS_BUILD_MACRO(10_1709)
|
|
_IS_BUILD_MACRO(10_1803)
|
|
_IS_BUILD_MACRO(10_1809)
|
|
_IS_BUILD_MACRO(10_1903)
|
|
_IS_BUILD_MACRO(10_1909)
|
|
_IS_BUILD_MACRO(10_2004)
|
|
_IS_BUILD_MACRO(10_20H2)
|
|
_IS_BUILD_MACRO(10_21H1)
|
|
_IS_BUILD_MACRO(10_21H2)
|
|
_IS_BUILD_MACRO(10_22H2)
|
|
_IS_BUILD_MACRO(11_21H1)
|
|
_IS_BUILD_MACRO(11_22H2)
|
|
_IS_BUILD_MACRO(11_23H2)
|
|
_IS_BUILD_MACRO(11_24H2)
|
|
#undef _IS_BUILD_MACRO
|
|
|
|
EXTERN_C HRESULT GetOwnVersion(LPWSTR *version);
|
|
|
|
static inline void GetOwnFileName(LPWSTR *filename) {
|
|
*filename = (LPWSTR)LocalAlloc(LPTR, MAX_PATH * sizeof(WCHAR));
|
|
GetModuleFileName((HMODULE)&__ImageBase, *filename, MAX_PATH);
|
|
}
|