#4978 Removed getOSName impl relying on deprecated GetVersionEx

This commit is contained in:
Andrew Nelless 2016-06-24 13:10:17 +01:00 committed by Jerry (Xinyu Hou)
parent cf1e5239cb
commit 74c48c6516
1 changed files with 18 additions and 48 deletions

View File

@ -49,56 +49,26 @@ ArchSystemWindows::~ArchSystemWindows()
std::string std::string
ArchSystemWindows::getOSName() const ArchSystemWindows::getOSName() const
{ {
#if WINVER >= _WIN32_WINNT_WIN2K std::string osName ("Microsoft Windows <unknown>");
OSVERSIONINFOEX info; static const TCHAR* const windowsVersionKeyNames[] = {
#else _T("SOFTWARE"),
OSVERSIONINFO info; _T("Microsoft"),
#endif _T("Windows NT"),
_T("CurrentVersion"),
NULL
};
info.dwOSVersionInfoSize = sizeof(info); HKEY key = ArchMiscWindows::openKey(HKEY_LOCAL_MACHINE, windowsVersionKeyNames);
if (GetVersionEx((OSVERSIONINFO*) &info)) { if (key == NULL) {
switch (info.dwPlatformId) { return osName;
case VER_PLATFORM_WIN32_NT:
#if WINVER >= _WIN32_WINNT_WIN2K
if (info.dwMajorVersion == 6) {
if (info.dwMinorVersion == 0) {
if (info.wProductType == VER_NT_WORKSTATION) {
return "Microsoft Windows Vista";
}
else {
return "Microsoft Windows Server 2008";
}
}
else if (info.dwMinorVersion == 1) {
if (info.wProductType == VER_NT_WORKSTATION) {
return "Microsoft Windows 7";
}
else {
return "Microsoft Windows Server 2008 R2";
}
}
}
#endif
if (info.dwMajorVersion == 5 && info.dwMinorVersion == 2) {
return "Microsoft Windows Server 2003";
}
if (info.dwMajorVersion == 5 && info.dwMinorVersion == 1) {
return "Microsoft Windows XP";
}
if (info.dwMajorVersion == 5 && info.dwMinorVersion == 0) {
return "Microsoft Windows Server 2000";
}
char buffer[100];
sprintf(buffer, "Microsoft Windows %d.%d",
info.dwMajorVersion, info.dwMinorVersion);
return buffer;
default:
break;
}
} }
return "Microsoft Windows <unknown>";
std::string productName = ArchMiscWindows::readValueString(key, "ProductName");
if (osName.empty()) {
return osName;
}
return "Microsoft " + productName;
} }
std::string std::string