From 9459224f23f4fe200b8a652c460120148c1fe052 Mon Sep 17 00:00:00 2001 From: kervala Date: Tue, 22 Sep 2015 09:43:24 +0200 Subject: [PATCH] Fixed: GetVersionEx deprecated under Windows 8.1+ and returns wrong version, replace it by RtlGetVersion from kernel --HG-- branch : develop --- code/nel/src/misc/system_info.cpp | 39 ++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/code/nel/src/misc/system_info.cpp b/code/nel/src/misc/system_info.cpp index 8524939c8..a5b78c08b 100644 --- a/code/nel/src/misc/system_info.cpp +++ b/code/nel/src/misc/system_info.cpp @@ -185,11 +185,12 @@ string CSystemInfo::getOS() typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO); typedef BOOL (WINAPI *PGPI)(DWORD, DWORD, DWORD, DWORD, PDWORD); + typedef LONG (WINAPI* pRtlGetVersion)(OSVERSIONINFOEXA*); SYSTEM_INFO si; PGNSI pGNSI; PGPI pGPI; - OSVERSIONINFOEX osvi; + OSVERSIONINFOEXA osvi; BOOL bOsVersionInfoEx; const int BUFSIZE = 80; @@ -197,15 +198,26 @@ string CSystemInfo::getOS() // If that fails, try using the OSVERSIONINFO structure. ZeroMemory(&si, sizeof(SYSTEM_INFO)); - ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); - osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); + ZeroMemory(&osvi, sizeof(osvi)); + osvi.dwOSVersionInfoSize = sizeof(osvi); - bOsVersionInfoEx = GetVersionExA ((OSVERSIONINFO *) &osvi); + HMODULE hNtDll = GetModuleHandleA("ntdll.dll"); + pRtlGetVersion RtlGetVersion = (pRtlGetVersion)GetProcAddress(hNtDll, "RtlGetVersion"); + + if (RtlGetVersion) + { + bOsVersionInfoEx = RtlGetVersion(&osvi) == 0; + } if(!bOsVersionInfoEx) { - osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); - if (! GetVersionExA ( (OSVERSIONINFO *) &osvi) ) + bOsVersionInfoEx = GetVersionExA ((OSVERSIONINFOA *) &osvi); + } + + if(!bOsVersionInfoEx) + { + osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFOA); + if (! GetVersionExA ( (OSVERSIONINFOA *) &osvi) ) return OSString+" Can't GetVersionEx()"; } @@ -223,13 +235,24 @@ string CSystemInfo::getOS() { OSString = "Microsoft"; - if ( osvi.dwMajorVersion > 6 ) + if ( osvi.dwMajorVersion > 10 ) { OSString += " Windows (not released)"; } + else if ( osvi.dwMajorVersion == 10 ) + { + OSString += " Windows 10"; + } else if ( osvi.dwMajorVersion == 6 ) { - if ( osvi.dwMinorVersion == 2 ) + if ( osvi.dwMinorVersion == 3 ) + { + if( osvi.wProductType == VER_NT_WORKSTATION ) + OSString += " Windows 8.1"; + else + OSString += " Windows Server 2012 R2"; + } + else if ( osvi.dwMinorVersion == 2 ) { if( osvi.wProductType == VER_NT_WORKSTATION ) OSString += " Windows 8";