Added OS name and architecture to the about dialog. Also moved GetPlatformName() from the SysInfo plugin to Platform namespace.

This commit is contained in:
Brian Ferguson 2014-02-11 12:17:05 -07:00
parent d00d4bb313
commit b2c4bb826a
6 changed files with 140 additions and 63 deletions

View File

@ -56,4 +56,110 @@ Version GetVersion()
return s_Version;
}
LPCWSTR GetPlatformName()
{
OSVERSIONINFOEX osvi = { sizeof(OSVERSIONINFOEX) };
if (GetVersionEx((OSVERSIONINFO*)&osvi))
{
if (osvi.dwMajorVersion == 5)
{
if (osvi.dwMinorVersion == 2)
{
return L"Windows 2003";
}
else if (osvi.dwMinorVersion == 1)
{
return L"Windows XP";
}
}
else
{
if (osvi.dwMinorVersion == 3 && osvi.wProductType == VER_NT_WORKSTATION)
{
return L"Windows 8.1";
}
else if (osvi.dwMinorVersion == 3 && osvi.wProductType != VER_NT_WORKSTATION)
{
return L"Windows Server 2012 R2";
}
else if (osvi.dwMinorVersion == 2 && osvi.wProductType == VER_NT_WORKSTATION)
{
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";
}
}
}
return L"Unknown";
}
/*
** Returns |true| if the OS architecture can be found (either 32-bit or 64-bit),
** or |false| if it cannot be determined.
**
** Note: IsWow64Process was introduced with Windows XP SP2.
*/
bool GetPlatformBit(bool& is64Bit)
{
#if _WIN64
is64Bit = true;
return true;
#elif _WIN32
BOOL isWow64 = FALSE;
LPFN_ISWOW64PROCESS fnIsWow64Process =
(LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle(L"kernel32"), "IsWow64Process");
if (fnIsWow64Process)
{
if (!fnIsWow64Process(GetCurrentProcess(), &isWow64))
{
return false;
}
if (isWow64)
{
is64Bit = true;
}
else
{
is64Bit = false;
}
return true;
}
else
{
return false;
}
#else
return false;
#endif
}
} // namespace Platform

View File

@ -21,6 +21,8 @@
namespace Platform {
typedef BOOL(WINAPI * LPFN_ISWOW64PROCESS)(HANDLE hProcess, PBOOL Wow64Process);
enum Version
{
WinXP,
@ -30,6 +32,8 @@ enum Version
};
Version GetVersion();
LPCWSTR GetPlatformName();
bool GetPlatformBit(bool& is64Bit);
#define RM_PLATFORM_DECLARE_HELPERS(ver) \
inline bool IsAtMost ## ver() { return GetVersion() <= ver; } \

View File

@ -25,6 +25,7 @@
#include "resource.h"
#include "DialogAbout.h"
#include "../Version.h"
#include "../Common/Platform.h"
WINDOWPLACEMENT DialogAbout::c_WindowPlacement = {0};
DialogAbout* DialogAbout::c_Dialog = nullptr;
@ -1206,17 +1207,20 @@ void DialogAbout::TabVersion::Create(HWND owner)
CT_LINKLABEL(Id_LicenseLink, ID_STR_COPYRIGHTNOTICE,
28, 26, 300, 9,
WS_VISIBLE, 0),
CT_LABEL(Id_PathLabel, 0,
CT_LABEL(Id_WinVerLabel, 0,
0, 43, 360, 9,
WS_VISIBLE | SS_ENDELLIPSIS | SS_NOPREFIX, 0),
CT_LABEL(Id_IniFileLabel, 0,
CT_LABEL(Id_PathLabel, 0,
0, 56, 360, 9,
WS_VISIBLE | SS_ENDELLIPSIS | SS_NOPREFIX, 0),
CT_LABEL(Id_SkinPathLabel, 0,
CT_LABEL(Id_IniFileLabel, 0,
0, 69, 360, 9,
WS_VISIBLE | SS_ENDELLIPSIS | SS_NOPREFIX, 0),
CT_LABEL(Id_SkinPathLabel, 0,
0, 82, 360, 9,
WS_VISIBLE | SS_ENDELLIPSIS | SS_NOPREFIX, 0),
CT_BUTTON(Id_CopyButton, ID_STR_COPYTOCLIPBOARD,
0, 85, buttonWidth + 25, 14,
0, 98, buttonWidth + 25, 14,
WS_VISIBLE | WS_TABSTOP, 0)
};
@ -1234,8 +1238,21 @@ void DialogAbout::TabVersion::Initialize()
_snwprintf_s(tmpSz, _TRUNCATE, L"%s%s r%i %s (%s)", APPVERSION, revision_beta ? L" beta" : L"", revision_number, APPBITS, APPDATE);
SetWindowText(item, tmpSz);
item = GetControl(Id_WinVerLabel);
std::wstring text = Platform::GetPlatformName();
bool is64Bit = false;
if (Platform::GetPlatformBit(is64Bit))
{
text.append(is64Bit ? L" (64-bit)" : L" (32-bit)");
}
else
{
text.append(L" (???-bit)");
}
SetWindowText(item, text.c_str());
item = GetControl(Id_PathLabel);
std::wstring text = L"Path: " + GetRainmeter().GetPath();
text = L"Path: " + GetRainmeter().GetPath();
SetWindowText(item, text.c_str());
item = GetControl(Id_IniFileLabel);

View File

@ -143,6 +143,7 @@ private:
Id_VersionLabel,
Id_HomeLink,
Id_LicenseLink,
Id_WinVerLabel,
Id_PathLabel,
Id_IniFileLabel,
Id_SkinPathLabel,

View File

@ -30,6 +30,11 @@
<ItemGroup>
<ClCompile Include="SysInfo.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Common\Common.vcxproj">
<Project>{19312085-aa51-4bd6-be92-4b6098cca539}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>

View File

@ -23,6 +23,7 @@
#include <stdlib.h>
#include "../API/RainmeterAPI.h"
#include "../../Library/Export.h"
#include"../../Common/Platform.h"
typedef struct
{
@ -73,7 +74,6 @@ struct MeasureData
MeasureData() : type(), data() {}
};
LPCWSTR GetPlatformName();
NLM_CONNECTIVITY GetNetworkConnectivity();
BOOL CALLBACK MyInfoEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData);
@ -261,7 +261,7 @@ PLUGIN_EXPORT LPCWSTR GetString(void* data)
return sBuffer;
case MEASURE_OS_VERSION:
return GetPlatformName();
return Platform::GetPlatformName();
case MEASURE_ADAPTER_DESCRIPTION:
if (ERROR_SUCCESS == GetAdaptersInfo((IP_ADAPTER_INFO*)tmpBuffer, &tmpBufferLen))
@ -468,62 +468,6 @@ PLUGIN_EXPORT void Finalize(void* data)
delete measure;
}
LPCWSTR GetPlatformName()
{
OSVERSIONINFOEX osvi = {sizeof(OSVERSIONINFOEX)};
if (GetVersionEx((OSVERSIONINFO*)&osvi))
{
if (osvi.dwMajorVersion == 5)
{
if (osvi.dwMinorVersion == 2)
{
return L"Windows 2003";
}
else if (osvi.dwMinorVersion == 1)
{
return L"Windows XP";
}
}
else
{
if (osvi.dwMinorVersion == 3 && osvi.wProductType == VER_NT_WORKSTATION)
{
return L"Windows 8.1";
}
else if (osvi.dwMinorVersion == 3 && osvi.wProductType != VER_NT_WORKSTATION)
{
return L"Windows Server 2012 R2";
}
else if (osvi.dwMinorVersion == 2 && osvi.wProductType == VER_NT_WORKSTATION)
{
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";
}
}
}
return L"Unknown";
}
NLM_CONNECTIVITY GetNetworkConnectivity()
{
// This is initialized like this in case INetworkListManager is not available (i.e. on WinXP).