Fix OS detection on Windows 10.
Compatibility mode will be handled in a later diff. Comments by: @Itms, @vladislavbelov Differential Revision: https://code.wildfiregames.com/D2420 This was SVN commit r24238.
This commit is contained in:
parent
15001ec798
commit
1fbf51ccf1
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2010 Wildfire Games.
|
||||
/* Copyright (C) 2020 Wildfire Games.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@ -21,30 +21,49 @@
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
#include "lib/sysdep/os/win/wposix/wutsname.h"
|
||||
|
||||
#include "lib/sysdep/os/win/wposix/wutsname.h"
|
||||
#include "lib/sysdep/os/win/wutil.h" // WinScopedPreserveLastError
|
||||
#include "lib/sysdep/os/win/wversion.h" // wversion_Family
|
||||
|
||||
#include <sstream>
|
||||
#include <winternl.h>
|
||||
|
||||
/**
|
||||
* Taken and modified from: https://stackoverflow.com/questions/32115255/c-how-to-detect-windows-10
|
||||
*/
|
||||
int uname(struct utsname* un)
|
||||
{
|
||||
OSVERSIONINFOW vi = { sizeof(OSVERSIONINFOW) };
|
||||
GetVersionExW(&vi);
|
||||
WUTIL_FUNC(pRtlGetVersion, NTSTATUS, (LPOSVERSIONINFOEXW));
|
||||
WUTIL_IMPORT_NTDLL(RtlGetVersion , pRtlGetVersion);
|
||||
|
||||
// OS implementation name
|
||||
sprintf_s(un->sysname, ARRAY_SIZE(un->sysname), "%ls", wversion_Family());
|
||||
if (!pRtlGetVersion)
|
||||
return -1;
|
||||
|
||||
// release info
|
||||
const wchar_t* vs = vi.szCSDVersion;
|
||||
OSVERSIONINFOEXW osInfo = { sizeof(OSVERSIONINFOEXW) };
|
||||
pRtlGetVersion(&osInfo);
|
||||
std::ostringstream stream;
|
||||
|
||||
// OS Implementation name
|
||||
if (osInfo.dwMajorVersion >= 10)
|
||||
{
|
||||
stream << "Win" << osInfo.dwMajorVersion;
|
||||
}
|
||||
else
|
||||
stream << wversion_Family() << "\0";
|
||||
|
||||
sprintf_s(un->sysname, ARRAY_SIZE(un->sysname), "%s", stream.str().c_str());
|
||||
|
||||
|
||||
// OS Service Pack
|
||||
int sp;
|
||||
if(swscanf_s(vs, L"Service Pack %d", &sp) == 1)
|
||||
if (swscanf_s(osInfo.szCSDVersion, L"Service Pack %d", &sp) == 1)
|
||||
sprintf_s(un->release, ARRAY_SIZE(un->release), "SP %d", sp);
|
||||
else
|
||||
un->release[0] = '\0';
|
||||
|
||||
// version
|
||||
sprintf_s(un->version, ARRAY_SIZE(un->version), "%ls.%lu", wversion_String(), vi.dwBuildNumber & 0xFFFF);
|
||||
// OS Version.
|
||||
sprintf_s(un->version, ARRAY_SIZE(un->version), "%lu.%lu.%lu", osInfo.dwMajorVersion, osInfo.dwMinorVersion, osInfo.dwBuildNumber);
|
||||
|
||||
// node name
|
||||
{
|
||||
@ -55,8 +74,8 @@ int uname(struct utsname* un)
|
||||
|
||||
// hardware type
|
||||
SYSTEM_INFO si;
|
||||
GetSystemInfo(&si);
|
||||
if(si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
|
||||
GetNativeSystemInfo(&si);
|
||||
if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
|
||||
strcpy_s(un->machine, ARRAY_SIZE(un->machine), "x64");
|
||||
else
|
||||
strcpy_s(un->machine, ARRAY_SIZE(un->machine), "x86");
|
||||
|
@ -67,6 +67,10 @@ bool wutil_IsValidHandle(H h)
|
||||
#define WUTIL_IMPORT_KERNEL32(procName, varName)\
|
||||
WUTIL_IMPORT(GetModuleHandleW(L"kernel32.dll"), procName, varName)
|
||||
|
||||
// note: ntdll is guaranteed to be loaded, so we don't
|
||||
// need to LoadLibrary and FreeLibrary.
|
||||
#define WUTIL_IMPORT_NTDLL(procName, varName)\
|
||||
WUTIL_IMPORT(GetModuleHandleW(L"ntdll.dll"), procName, varName)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// safe allocator
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2018 Wildfire Games.
|
||||
/* Copyright (C) 2020 Wildfire Games.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@ -35,29 +35,29 @@ static wchar_t windowsVersionString[20];
|
||||
static size_t windowsVersion; // see WVERSION_*
|
||||
|
||||
|
||||
const wchar_t* wversion_Family()
|
||||
const char* wversion_Family()
|
||||
{
|
||||
ENSURE(windowsVersion != 0);
|
||||
switch(windowsVersion)
|
||||
{
|
||||
case WVERSION_2K:
|
||||
return L"Win2k";
|
||||
return "Win2k";
|
||||
case WVERSION_XP:
|
||||
return L"WinXP";
|
||||
return "WinXP";
|
||||
case WVERSION_XP64:
|
||||
return L"WinXP64";
|
||||
return "WinXP64";
|
||||
case WVERSION_VISTA:
|
||||
return L"Vista";
|
||||
return "Vista";
|
||||
case WVERSION_7:
|
||||
return L"Win7";
|
||||
return "Win7";
|
||||
case WVERSION_8:
|
||||
return L"Win8";
|
||||
return "Win8";
|
||||
case WVERSION_8_1:
|
||||
return L"Win8.1";
|
||||
return "Win8.1";
|
||||
case WVERSION_10:
|
||||
return L"Win10";
|
||||
return "Win10";
|
||||
default:
|
||||
return L"Windows";
|
||||
return "Windows";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2014 Wildfire Games.
|
||||
/* Copyright (C) 2020 Wildfire Games.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
@ -46,6 +46,6 @@ LIB_API size_t wversion_Number();
|
||||
/**
|
||||
* @return short textual representation of the version
|
||||
**/
|
||||
extern const wchar_t* wversion_Family();
|
||||
extern const char* wversion_Family();
|
||||
|
||||
#endif // #ifndef INCLUDED_WVERSION
|
||||
|
Loading…
Reference in New Issue
Block a user