About Dialog: Retrieve a more detailed OS name

This commit is contained in:
Brian Ferguson 2014-02-13 01:16:42 -07:00
parent 67aeaf5392
commit 66d12ec92a
3 changed files with 192 additions and 56 deletions

View File

@ -18,63 +18,213 @@
#include "StdAfx.h"
#include "Platform.h"
#include <wchar.h>
namespace Platform {
LPCWSTR GetPlatformName()
LPCWSTR GetPlatformName(bool getExtendedInfo)
{
static WCHAR buffer[256];
wcscpy_s(buffer, L"");
bool isServer = IsWindowsServer();
OSVERSIONINFOEX osvi = { sizeof(OSVERSIONINFOEX) };
if (GetVersionEx((OSVERSIONINFO*)&osvi))
{
if (osvi.dwMajorVersion == 5)
// Note: Place newer versions at the top. Service pack helper functions are commented out for
// backward compatibility with the SysInfo plugin.
if (IsWindows8Point1OrGreater())
{
if (osvi.dwMinorVersion == 2)
wcscat_s(buffer, isServer ? L"Windows Server 2012 R2" : L"Windows 8.1");
}
else if (IsWindows8OrGreater())
{
wcscat_s(buffer, isServer ? L"Windows Server 2012" : L"Windows 8");
}
else if (IsWindows7OrGreater())
{
wcscat_s(buffer, isServer ? L"Windows Server 2008 R2" : L"Windows 7");
}
else if (IsWindowsVistaOrGreater())
{
wcscat_s(buffer, isServer ? L"Windows Server 2008" : L"Windows Vista");
}
else if (IsWindowsXPOrGreater())
{
if (GetSystemMetrics(SM_SERVERR2) != 0)
{
return L"Windows 2003";
wcscat_s(buffer, L"Windows Server 2003 R2");
}
else if (osvi.dwMinorVersion == 1)
else if (osvi.wSuiteMask & VER_SUITE_WH_SERVER)
{
return L"Windows XP";
wcscat_s(buffer, L"Windows Home Server");
}
else
{
wcscat_s(buffer, isServer ? L"Windows Server 2003" : L"Windows XP");
}
}
else
{
if (osvi.dwMinorVersion == 3 && osvi.wProductType == VER_NT_WORKSTATION)
wcscat_s(buffer, L"Unknown");
}
if (getExtendedInfo && _wcsicmp(buffer, L"Unknown") != 0)
{
if (IsWindowsVistaOrGreater())
{
return L"Windows 8.1";
PGETPRODUCTINFO pGetProductInfo = (PGETPRODUCTINFO)
GetProcAddress(GetModuleHandle(L"kernel32"), "GetProductInfo");
if (pGetProductInfo)
{
DWORD dwType;
if (pGetProductInfo(osvi.dwMajorVersion, osvi.dwMinorVersion,
osvi.wServicePackMajor, osvi.wServicePackMinor, &dwType))
{
// Only use most common versions.
// Full list at: http://msdn.microsoft.com/en-us/library/windows/desktop/ms724358%28v=vs.85%29.aspx
switch (dwType)
{
case PRODUCT_ULTIMATE:
case PRODUCT_ULTIMATE_N:
wcscat_s(buffer, L" Ultimate"); break;
case PRODUCT_PROFESSIONAL:
case PRODUCT_PROFESSIONAL_N:
wcscat_s(buffer, L" Professional"); break;
case PRODUCT_PROFESSIONAL_WMC:
wcscat_s(buffer, L" Professional Media Center"); break;
case PRODUCT_HOME_PREMIUM:
case PRODUCT_HOME_PREMIUM_N:
wcscat_s(buffer, L" Home Premium"); break;
case PRODUCT_HOME_BASIC:
case PRODUCT_HOME_BASIC_N:
wcscat_s(buffer, L" Home Basic"); break;
case PRODUCT_STARTER:
case PRODUCT_STARTER_N:
wcscat_s(buffer, L" Starter"); break;
case PRODUCT_ENTERPRISE:
case PRODUCT_ENTERPRISE_EVALUATION:
case PRODUCT_ENTERPRISE_N:
case PRODUCT_ENTERPRISE_N_EVALUATION:
wcscat_s(buffer, L" Enterprise"); break;
case PRODUCT_BUSINESS:
case PRODUCT_BUSINESS_N:
wcscat_s(buffer, L" Business"); break;
// Server Editions
case PRODUCT_CLUSTER_SERVER:
case PRODUCT_CLUSTER_SERVER_V:
wcscat_s(buffer, L" Cluster Edition"); break;
case PRODUCT_DATACENTER_SERVER:
case PRODUCT_DATACENTER_SERVER_V:
case PRODUCT_DATACENTER_SERVER_CORE:
case PRODUCT_DATACENTER_SERVER_CORE_V:
case PRODUCT_DATACENTER_EVALUATION_SERVER:
wcscat_s(buffer, L" Datacenter Edition"); break;
case PRODUCT_ENTERPRISE_SERVER:
case PRODUCT_ENTERPRISE_SERVER_V:
case PRODUCT_ENTERPRISE_SERVER_CORE:
case PRODUCT_ENTERPRISE_SERVER_CORE_V:
case PRODUCT_ENTERPRISE_SERVER_IA64:
wcscat_s(buffer, L" Enterprise Edition"); break;
case PRODUCT_SMALLBUSINESS_SERVER:
case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM:
case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM_CORE:
wcscat_s(buffer, L" Small Business Server"); break;
case PRODUCT_STANDARD_SERVER:
case PRODUCT_STANDARD_SERVER_V:
case PRODUCT_STANDARD_SERVER_CORE:
case PRODUCT_STANDARD_SERVER_CORE_V:
wcscat_s(buffer, L" Standard Edition"); break;
case PRODUCT_WEB_SERVER:
case PRODUCT_WEB_SERVER_CORE:
wcscat_s(buffer, L" Web Server"); break;
}
}
}
}
else if (osvi.dwMinorVersion == 3 && osvi.wProductType != VER_NT_WORKSTATION)
else if (IsWindowsXPOrGreater())
{
return L"Windows Server 2012 R2";
if (isServer)
{
if (osvi.wSuiteMask & VER_SUITE_COMPUTE_SERVER)
{
wcscat_s(buffer, L" Compute Cluster Edition");
}
else if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
{
wcscat_s(buffer, L" Datacenter Edition");
}
else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
{
wcscat_s(buffer, L" Enterprise Edition");
}
else if (osvi.wSuiteMask & VER_SUITE_BLADE)
{
wcscat_s(buffer, L" Web Edition");
}
else
{
wcscat_s(buffer, L" Standard Edition");
}
}
else
{
if (osvi.wSuiteMask & VER_SUITE_PERSONAL)
{
wcscat_s(buffer, L" Home Edition");
}
else if (GetSystemMetrics(SM_MEDIACENTER))
{
wcscat_s(buffer, L" Media Center Edition");
}
else if (GetSystemMetrics(SM_STARTER))
{
wcscat_s(buffer, L" Starter Edition");
}
else if (GetSystemMetrics(SM_TABLETPC))
{
wcscat_s(buffer, L" Tablet PC Edition");
}
else
{
return L" Professional";
}
}
}
else if (osvi.dwMinorVersion == 2 && osvi.wProductType == VER_NT_WORKSTATION)
// Build number and 32/64 bit
bool is64Bit = false;
bool has64Bit = Platform::GetPlatformBit(is64Bit);
_snwprintf_s(buffer, _TRUNCATE, L"%s %s-bit (build %d)",
buffer,
(has64Bit) ? (is64Bit) ? L"64" : L"32" : L"???",
osvi.dwBuildNumber);
// Service Pack
if (osvi.szCSDVersion)
{
return L"Windows 8";
}
else if (osvi.dwMinorVersion == 2 && osvi.wProductType != VER_NT_WORKSTATION)
{
return L"Windows Server 2012";
}
else if (osvi.dwMinorVersion == 1 && osvi.wProductType == VER_NT_WORKSTATION)
{
return L"Windows 7";
}
else if (osvi.dwMinorVersion == 1 && osvi.wProductType != VER_NT_WORKSTATION)
{
return L"Windows Server 2008 R2";
}
else if (osvi.dwMinorVersion == 0 && osvi.wProductType == VER_NT_WORKSTATION)
{
return L"Windows Vista";
}
else if (osvi.dwMinorVersion == 0 && osvi.wProductType != VER_NT_WORKSTATION)
{
return L"Windows Server 2008";
wcscat_s(buffer, L", ");
wcscat_s(buffer, osvi.szCSDVersion);
}
}
}
return L"Unknown";
return buffer;
}
/*

View File

@ -22,8 +22,13 @@
namespace Platform {
typedef BOOL(WINAPI * LPFN_ISWOW64PROCESS)(HANDLE hProcess, PBOOL Wow64Process);
typedef BOOL(WINAPI * PGETPRODUCTINFO)(DWORD dwOSMajorVersion,
DWORD dwOSMinorVersion,
DWORD dwSpMajorVersion,
DWORD dwSpMinorVersion,
PDWORD pdwReturnedProductType);
LPCWSTR GetPlatformName();
LPCWSTR GetPlatformName(bool getExtendedInfo = false);
bool GetPlatformBit(bool& is64Bit);
} // namespace Platform

View File

@ -1239,20 +1239,10 @@ void DialogAbout::TabVersion::Initialize()
SetWindowText(item, tmpSz);
item = GetControl(Id_WinVerLabel);
std::wstring text = Platform::GetPlatformName();
bool is64Bit = false;
if (Platform::GetPlatformBit(is64Bit))
{
text += (is64Bit) ? L" (64-bit)" : L" (32-bit)";
}
else
{
text += L" (???-bit)";
}
SetWindowText(item, text.c_str());
SetWindowText(item, Platform::GetPlatformName(true));
item = GetControl(Id_PathLabel);
text = L"Path: " + GetRainmeter().GetPath();
std::wstring text = L"Path: " + GetRainmeter().GetPath();
SetWindowText(item, text.c_str());
item = GetControl(Id_IniFileLabel);
@ -1299,16 +1289,7 @@ INT_PTR DialogAbout::TabVersion::OnCommand(WPARAM wParam, LPARAM lParam)
int len = _snwprintf_s(tmpSz, _TRUNCATE, L"%s%s r%i %s (%s)", APPVERSION, revision_beta ? L" beta" : L"", revision_number, APPBITS, APPDATE);
std::wstring text(tmpSz, len);
text += L'\n';
text += Platform::GetPlatformName();
bool is64Bit = false;
if (Platform::GetPlatformBit(is64Bit))
{
text += (is64Bit) ? L" (64-bit)" : L" (32-bit)";
}
else
{
text += L" (???-bit)";
}
text += Platform::GetPlatformName(true);
text += L"\nPath: ";
text += GetRainmeter().GetPath();
text += L"\nIniFile: ";