diff --git a/Common/Platform.cpp b/Common/Platform.cpp new file mode 100644 index 00000000..4c442546 --- /dev/null +++ b/Common/Platform.cpp @@ -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 + +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 \ No newline at end of file diff --git a/Common/Platform.h b/Common/Platform.h new file mode 100644 index 00000000..325f8e91 --- /dev/null +++ b/Common/Platform.h @@ -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 diff --git a/Library/DialogAbout.cpp b/Library/DialogAbout.cpp index 8eb3f5c1..770b7372 100644 --- a/Library/DialogAbout.cpp +++ b/Library/DialogAbout.cpp @@ -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); diff --git a/Library/DialogManage.cpp b/Library/DialogManage.cpp index 6792e9fe..69e576da 100644 --- a/Library/DialogManage.cpp +++ b/Library/DialogManage.cpp @@ -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); diff --git a/Library/Library.vcxproj b/Library/Library.vcxproj index 18fccff3..1189ad3e 100644 --- a/Library/Library.vcxproj +++ b/Library/Library.vcxproj @@ -66,6 +66,7 @@ + Use @@ -275,6 +276,7 @@ + diff --git a/Library/Library.vcxproj.filters b/Library/Library.vcxproj.filters index d839bd13..11b25381 100644 --- a/Library/Library.vcxproj.filters +++ b/Library/Library.vcxproj.filters @@ -333,6 +333,9 @@ Common + + Common + Common @@ -575,6 +578,9 @@ Common + + Common + Common diff --git a/Library/MeasureNet.cpp b/Library/MeasureNet.cpp index a0d34e21..039b5b83 100644 --- a/Library/MeasureNet.cpp +++ b/Library/MeasureNet.cpp @@ -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) diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index 04ab5ecd..b78ca7a8 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -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, diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index b88166bf..29c791d5 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -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, diff --git a/Library/System.cpp b/Library/System.cpp index 9556ce70..51024bc9 100644 --- a/Library/System.cpp +++ b/Library/System.cpp @@ -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) { diff --git a/Library/System.h b/Library/System.h index 1dd14768..5898cbc5 100644 --- a/Library/System.h +++ b/Library/System.h @@ -21,14 +21,7 @@ #include #include - -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(); diff --git a/Library/TrayWindow.cpp b/Library/TrayWindow.cpp index d53673e9..f4883e18 100644 --- a/Library/TrayWindow.cpp +++ b/Library/TrayWindow.cpp @@ -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);