Move CSystem::GetOSPlatform() to Platform.h

This commit is contained in:
Birunthan Mohanathas 2013-03-12 17:48:47 +02:00
parent 87014a8a87
commit f9e4230ddd
12 changed files with 127 additions and 58 deletions

59
Common/Platform.cpp Normal file
View File

@ -0,0 +1,59 @@
/*
Copyright (C) 2013 Birunthan Mohanathas
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "Platform.h"
#include <Windows.h>
namespace Platform {
Version GetVersion()
{
static Version s_Version = ([]()
{
OSVERSIONINFOEX osvi = {sizeof(OSVERSIONINFOEX)};
if (GetVersionEx((OSVERSIONINFO*)&osvi))
{
switch (osvi.dwMajorVersion)
{
case 5:
// Not checking for osvi.dwMinorVersion >= 1 because Rainmeter won't run on pre-XP.
return Version::WinXP;
case 6:
switch (osvi.dwMinorVersion)
{
case 0:
return Version::WinVista; // Vista, Server 2008
case 1:
return Version::Win7; // 7, Server 2008R2
default:
return Version::Win8; // 8, Server 2012
}
break;
}
}
return Version::Win8; // newer OS
})();
return s_Version;
}
} // namespace Platform

46
Common/Platform.h Normal file
View File

@ -0,0 +1,46 @@
/*
Copyright (C) 2013 Birunthan Mohanathas
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef RM_COMMON_PLATFORM_H_
#define RM_COMMON_PLATFORM_H_
namespace Platform {
enum Version
{
WinXP,
WinVista,
Win7,
Win8
};
Version GetVersion();
#define RM_PLATFORM_DECLARE_HELPERS(ver) \
inline bool IsAtMost ## ver() { return GetVersion() <= ver; } \
inline bool Is ## ver() { return GetVersion() == ver; } \
inline bool IsAtLeast ## ver() { return GetVersion() >= ver; } \
RM_PLATFORM_DECLARE_HELPERS(WinXP)
RM_PLATFORM_DECLARE_HELPERS(WinVista)
RM_PLATFORM_DECLARE_HELPERS(Win7)
RM_PLATFORM_DECLARE_HELPERS(Win8)
} // namespace Platform
#endif

View File

@ -262,7 +262,7 @@ INT_PTR CDialogAbout::OnInitDialog(WPARAM wParam, LPARAM lParam)
item = GetControl(Id_CloseButton);
SendMessage(m_Window, WM_NEXTDLGCTL, (WPARAM)item, TRUE);
if (CSystem::GetOSPlatform() >= OSPLATFORM_VISTA)
if (Platform::IsAtLeastWinVista())
{
item = m_TabLog.GetControl(CTabLog::Id_ItemsListView);
SetWindowTheme(item, L"explorer", NULL);
@ -638,7 +638,7 @@ void CDialogAbout::CTabSkins::Initialize()
LVGROUP lvg;
lvg.cbSize = sizeof(LVGROUP);
lvg.mask = LVGF_HEADER | LVGF_GROUPID | LVGF_STATE;
lvg.state = (CSystem::GetOSPlatform() >= OSPLATFORM_VISTA) ? LVGS_COLLAPSIBLE : LVGS_NORMAL;
lvg.state = (Platform::IsAtLeastWinVista()) ? LVGS_COLLAPSIBLE : LVGS_NORMAL;
lvg.iGroupId = 0;
lvg.pszHeader = GetString(ID_STR_MEASURES);
ListView_InsertGroup(item, 0, &lvg);

View File

@ -233,7 +233,7 @@ INT_PTR CDialogManage::OnInitDialog(WPARAM wParam, LPARAM lParam)
item = m_TabSkins.GetControl(CTabSkins::Id_FileLabel);
SendMessage(item, WM_SETFONT, (WPARAM)m_FontBold, 0);
if (CSystem::GetOSPlatform() >= OSPLATFORM_VISTA)
if (Platform::IsAtLeastWinVista())
{
// Use arrows instead of plus/minus in the tree for Vista+
item = m_TabSkins.GetControl(CTabSkins::Id_SkinsTreeView);

View File

@ -66,6 +66,7 @@
<ClCompile Include="..\Common\ControlTemplate.cpp" />
<ClCompile Include="..\Common\Dialog.cpp" />
<ClCompile Include="..\Common\MenuTemplate.cpp" />
<ClCompile Include="..\Common\Platform.cpp" />
<ClCompile Include="..\Common\StringUtil.cpp" />
<ClCompile Include="ConfigParser.cpp">
<PrecompiledHeader>Use</PrecompiledHeader>
@ -275,6 +276,7 @@
<ClInclude Include="..\Common\ControlTemplate.h" />
<ClInclude Include="..\Common\Dialog.h" />
<ClInclude Include="..\Common\MenuTemplate.h" />
<ClInclude Include="..\Common\Platform.h" />
<ClInclude Include="..\Common\StringUtil.h" />
<ClInclude Include="ConfigParser.h" />
<ClInclude Include="DialogAbout.h" />

View File

@ -333,6 +333,9 @@
<ClCompile Include="..\Common\MenuTemplate.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\Platform.cpp">
<Filter>Common</Filter>
</ClCompile>
<ClCompile Include="..\Common\StringUtil.cpp">
<Filter>Common</Filter>
</ClCompile>
@ -575,6 +578,9 @@
<ClInclude Include="..\Common\MenuTemplate.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="..\Common\Platform.h">
<Filter>Common</Filter>
</ClInclude>
<ClInclude Include="..\Common\StringUtil.h">
<Filter>Common</Filter>
</ClInclude>

View File

@ -691,7 +691,7 @@ void CMeasureNet::WriteStats(const WCHAR* iniFile, const std::wstring& statsDate
*/
void CMeasureNet::InitializeStatic()
{
if (CSystem::GetOSPlatform() >= OSPLATFORM_VISTA)
if (Platform::IsAtLeastWinVista())
{
HMODULE IpHlpApiLibrary = GetModuleHandle(L"IpHlpApi.dll");
if (IpHlpApiLibrary)

View File

@ -145,7 +145,7 @@ CMeterWindow::CMeterWindow(const std::wstring& folderPath, const std::wstring& f
m_FontCollection(),
m_ToolTipHidden(false)
{
if (!c_DwmInstance && CSystem::GetOSPlatform() >= OSPLATFORM_VISTA)
if (!c_DwmInstance && Platform::IsAtLeastWinVista())
{
c_DwmInstance = CSystem::RmLoadLibrary(L"dwmapi.dll");
if (c_DwmInstance)
@ -1030,7 +1030,7 @@ void CMeterWindow::HideBlur()
*/
void CMeterWindow::ResizeBlur(const std::wstring& arg, int mode)
{
if (CSystem::GetOSPlatform() >= OSPLATFORM_VISTA)
if (Platform::IsAtLeastWinVista())
{
WCHAR* parseSz = _wcsdup(arg.c_str());
int type, x, y, w = 0, h = 0;
@ -2054,7 +2054,7 @@ bool CMeterWindow::ReadSkin()
m_TransitionUpdate = m_Parser.ReadInt(L"Rainmeter", L"TransitionUpdate", INTERVAL_TRANSITION);
m_ToolTipHidden = 0 != m_Parser.ReadInt(L"Rainmeter", L"ToolTipHidden", 0);
if (CSystem::GetOSPlatform() >= OSPLATFORM_VISTA)
if (Platform::IsAtLeastWinVista())
{
if (0 != m_Parser.ReadInt(L"Rainmeter", L"Blur", 0))
{
@ -2095,7 +2095,7 @@ bool CMeterWindow::ReadSkin()
HANDLE find = FindFirstFileEx(
resourcePath.c_str(),
(CSystem::GetOSPlatform() >= OSPLATFORM_7) ? FindExInfoBasic : FindExInfoStandard,
(Platform::IsAtLeastWin7()) ? FindExInfoBasic : FindExInfoStandard,
&fd,
FindExSearchNameMatch,
NULL,

View File

@ -1828,7 +1828,7 @@ int CRainmeter::ScanForSkinsRecursive(const std::wstring& path, std::wstring bas
hSearch = FindFirstFileEx(
filter.c_str(),
(CSystem::GetOSPlatform() >= OSPLATFORM_7) ? FindExInfoBasic : FindExInfoStandard,
(Platform::IsAtLeastWin7()) ? FindExInfoBasic : FindExInfoStandard,
&fileData,
FindExSearchNameMatch,
NULL,
@ -1935,7 +1935,7 @@ void CRainmeter::ScanForLayouts()
hSearch = FindFirstFileEx(
folders.c_str(),
(CSystem::GetOSPlatform() >= OSPLATFORM_7) ? FindExInfoBasic : FindExInfoStandard,
(Platform::IsAtLeastWin7()) ? FindExInfoBasic : FindExInfoStandard,
&fileData,
FindExSearchNameMatch,
NULL,

View File

@ -540,40 +540,6 @@ void CSystem::UpdateWorkareaInfo()
}
}
/*
** Sets the OS platform.
**
*/
OSPLATFORM CSystem::InitOSPlatform()
{
OSVERSIONINFOEX osvi = {sizeof(OSVERSIONINFOEX)};
if (GetVersionEx((OSVERSIONINFO*)&osvi))
{
switch (osvi.dwMajorVersion)
{
case 5:
// Not checking for osvi.dwMinorVersion >= 1 because Rainmeter won't run on pre-XP
return OSPLATFORM_XP;
case 6:
switch (osvi.dwMinorVersion)
{
case 0:
return OSPLATFORM_VISTA; // Vista, Server 2008
case 1:
return OSPLATFORM_7; // 7, Server 2008R2
default:
return OSPLATFORM_8; // 8, Server 2012
}
break;
}
}
return OSPLATFORM_8; // newer OS
}
/*
** Finds the Default Shell's window.
**
@ -1125,7 +1091,7 @@ void CSystem::ResetWorkingDirectory()
void CSystem::InitializeCriticalSection(LPCRITICAL_SECTION lpCriticalSection)
{
typedef BOOL (WINAPI * FPINITCRITEX)(LPCRITICAL_SECTION lpCriticalSection, DWORD dwSpinCount, DWORD Flags);
static FPINITCRITEX InitializeCriticalSectionEx = (GetOSPlatform() >= OSPLATFORM_VISTA) ?
static FPINITCRITEX InitializeCriticalSectionEx = Platform::IsAtLeastWinVista() ?
(FPINITCRITEX)GetProcAddress(GetModuleHandle(L"Kernel32"), "InitializeCriticalSectionEx") : nullptr;
if (InitializeCriticalSectionEx)
@ -1212,7 +1178,7 @@ void CSystem::SetWallpaper(const std::wstring& wallpaper, const std::wstring& st
{
wallStyle = L"2";
}
else if (GetOSPlatform() >= OSPLATFORM_7)
else if (Platform::IsAtLeastWin7())
{
if (_wcsicmp(option, L"FIT") == 0)
{

View File

@ -21,14 +21,7 @@
#include <windows.h>
#include <vector>
enum OSPLATFORM
{
OSPLATFORM_XP,
OSPLATFORM_VISTA,
OSPLATFORM_7,
OSPLATFORM_8
};
#include "../Common/Platform.h"
struct MonitorInfo
{
@ -67,7 +60,6 @@ public:
static HWND GetHelperWindow() { return c_HelperWindow; }
static void PrepareHelperWindow(HWND WorkerW = GetWorkerW());
static OSPLATFORM GetOSPlatform() { static OSPLATFORM c_Platform = InitOSPlatform(); return c_Platform; }
static ULONGLONG GetTickCount64();
static POINT GetCursorPosition();
@ -99,8 +91,6 @@ private:
static void ClearMultiMonitorInfo() { c_Monitors.monitors.clear(); }
static void UpdateWorkareaInfo();
static OSPLATFORM InitOSPlatform();
static HWND GetDefaultShellWindow();
static HWND GetWorkerW();
static void ChangeZPosInOrder();

View File

@ -309,7 +309,7 @@ void CTrayWindow::ShowNotification(TRAY_NOTIFICATION id, const WCHAR* title, con
wcsncpy_s(nid.szInfoTitle, title, _TRUNCATE);
wcsncpy_s(nid.szInfo, text, _TRUNCATE);
if (CSystem::GetOSPlatform() > OSPLATFORM_VISTA)
if (Platform::IsAtLeastWinVista())
{
nid.dwInfoFlags |= NIIF_LARGE_ICON;
nid.hBalloonIcon = GetIcon(IDI_RAINMETER, true);