mirror of
https://github.com/EricPlayZ/EGameTools.git
synced 2025-07-18 17:37:53 +08:00
47 lines
1.7 KiB
C++
47 lines
1.7 KiB
C++
#include "utils.h"
|
|
#include <Windows.h>
|
|
|
|
namespace Utils {
|
|
WindowsVersion GetWindowsVersion() {
|
|
OSVERSIONINFOEX info{};
|
|
DWORDLONG dwlConditionMask = 0;
|
|
|
|
// Initialize the OSVERSIONINFOEX structure.
|
|
ZeroMemory(&info, sizeof(OSVERSIONINFOEX));
|
|
info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
|
|
info.dwMajorVersion = 6;
|
|
|
|
// Initialize the condition mask.
|
|
VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, VER_EQUAL);
|
|
|
|
if (VerifyVersionInfo(&info, VER_MAJORVERSION, dwlConditionMask)) {
|
|
// The major version is 6.
|
|
info.dwMinorVersion = 1;
|
|
VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION, VER_EQUAL);
|
|
|
|
if (VerifyVersionInfo(&info, VER_MINORVERSION, dwlConditionMask))
|
|
return WindowsVersion::Windows7;
|
|
|
|
info.dwMinorVersion = 2;
|
|
VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION, VER_EQUAL);
|
|
|
|
if (VerifyVersionInfo(&info, VER_MINORVERSION, dwlConditionMask))
|
|
return WindowsVersion::Windows10; // Windows 8 and 8.1 also use 6.2
|
|
|
|
info.dwMinorVersion = 3;
|
|
VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION, VER_EQUAL);
|
|
|
|
if (VerifyVersionInfo(&info, VER_MINORVERSION, dwlConditionMask))
|
|
return WindowsVersion::Windows10;
|
|
} else {
|
|
// The major version is not 6. Check if it's greater than 6.
|
|
info.dwMajorVersion = 7;
|
|
VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL);
|
|
|
|
if (VerifyVersionInfo(&info, VER_MAJORVERSION, dwlConditionMask))
|
|
return WindowsVersion::Windows10;
|
|
}
|
|
|
|
return WindowsVersion::Unknown;
|
|
}
|
|
} |