From dbd43ddfbcbc7f1e41e7cb6a6f77f0f36e1a4851 Mon Sep 17 00:00:00 2001 From: spx Date: Wed, 15 Feb 2012 02:51:27 +0000 Subject: [PATCH] - Changed an interval of writing network statistics from a minute to two minutes. - Code cosmetic changes. --- Library/MeasureNet.cpp | 2 +- Library/Rainmeter.cpp | 33 +++++++++++++++++++++++++++++---- Library/Rainmeter.h | 2 ++ Library/System.cpp | 31 +++++++++---------------------- Library/System.h | 2 -- 5 files changed, 41 insertions(+), 29 deletions(-) diff --git a/Library/MeasureNet.cpp b/Library/MeasureNet.cpp index db622a05..be9c9778 100644 --- a/Library/MeasureNet.cpp +++ b/Library/MeasureNet.cpp @@ -495,7 +495,7 @@ void CMeasureNet::ReadConfig(CConfigParser& parser, const WCHAR* section, NET ne m_Cumulative = 0!=parser.ReadInt(section, L"Cumulative", 0); if (m_Cumulative) { - CSystem::SetNetworkStatisticsTimer(); + Rainmeter->SetNetworkStatisticsTimer(); } m_TrafficValue = parser.ReadFloat(section, L"TrafficValue", 0.0); diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index 3a37f00e..9c40e900 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -33,6 +33,15 @@ using namespace Gdiplus; +enum TIMER +{ + TIMER_NETSTATS = 1 +}; +enum INTERVAL +{ + INTERVAL_NETSTATS = 120000 +}; + CRainmeter* Rainmeter; // The module /* @@ -681,6 +690,8 @@ CRainmeter::CRainmeter() : */ CRainmeter::~CRainmeter() { + KillTimer(m_Window, TIMER_NETSTATS); + DeleteMeterWindow(NULL); delete m_TrayWindow; @@ -1075,9 +1086,18 @@ LRESULT CALLBACK CRainmeter::MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LP } break; + case WM_TIMER: + if (wParam == TIMER_NETSTATS) + { + CMeasureNet::UpdateIFTable(); + CMeasureNet::UpdateStats(); + Rainmeter->WriteStats(false); + } + break; + case WM_RAINMETER_DELAYED_REFRESH_ALL: Rainmeter->RefreshAll(); - return 0; + break; case WM_RAINMETER_DELAYED_EXECUTE: if (lParam) @@ -1087,7 +1107,7 @@ LRESULT CALLBACK CRainmeter::MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LP Rainmeter->ExecuteCommand(bang, NULL); free(bang); // _wcsdup() } - return 0; + break; default: return DefWindowProc(hWnd, uMsg, wParam, lParam); @@ -1096,6 +1116,11 @@ LRESULT CALLBACK CRainmeter::MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LP return 0; } +void CRainmeter::SetNetworkStatisticsTimer() +{ + static bool set = SetTimer(m_Window, TIMER_NETSTATS, INTERVAL_NETSTATS, NULL); +} + /* ** CreateDefaultConfigFile ** @@ -2489,7 +2514,7 @@ void CRainmeter::ReadStats() /* ** WriteStats ** -** Writes the statistics to the ini-file. If bForce is false the stats are written only once per minute. +** Writes the statistics to the ini-file. If bForce is false the stats are written only once per an appropriate interval. ** */ void CRainmeter::WriteStats(bool bForce) @@ -2498,7 +2523,7 @@ void CRainmeter::WriteStats(bool bForce) ULONGLONG ticks = CSystem::GetTickCount64(); - if (bForce || (lastWrite + 1000 * 60 < ticks)) + if (bForce || (lastWrite + INTERVAL_NETSTATS < ticks)) { lastWrite = ticks; diff --git a/Library/Rainmeter.h b/Library/Rainmeter.h index 0dec7ba6..f39a1503 100644 --- a/Library/Rainmeter.h +++ b/Library/Rainmeter.h @@ -123,6 +123,8 @@ public: int Initialize(HINSTANCE hInstance, LPCWSTR szPath); int MessagePump(); + void SetNetworkStatisticsTimer(); + CConfigParser* GetCurrentParser() { return m_CurrentParser; } void SetCurrentParser(CConfigParser* parser) { m_CurrentParser = parser; } diff --git a/Library/System.cpp b/Library/System.cpp index 70f60fc3..d47c47cb 100644 --- a/Library/System.cpp +++ b/Library/System.cpp @@ -32,14 +32,12 @@ using namespace Gdiplus; enum TIMER { - TIMER_SHOWDESKTOP = 1, - TIMER_NETSTATS = 2 + TIMER_SHOWDESKTOP = 1 }; enum INTERVAL { INTERVAL_SHOWDESKTOP = 250, - INTERVAL_RESTOREWINDOWS = 100, - INTERVAL_NETSTATS = 60000 + INTERVAL_RESTOREWINDOWS = 100 }; MULTIMONITOR_INFO CSystem::c_Monitors = { 0 }; @@ -135,7 +133,6 @@ void CSystem::Initialize(HINSTANCE instance) void CSystem::Finalize() { KillTimer(c_Window, TIMER_SHOWDESKTOP); - KillTimer(c_Window, TIMER_NETSTATS); if (c_WinEventHook) { @@ -156,11 +153,6 @@ void CSystem::Finalize() } } -void CSystem::SetNetworkStatisticsTimer() -{ - static bool set = SetTimer(c_Window, TIMER_NETSTATS, INTERVAL_NETSTATS, NULL); -} - /* ** MyInfoEnumProc ** @@ -1004,20 +996,12 @@ LRESULT CALLBACK CSystem::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lP { case WM_WINDOWPOSCHANGING: ((LPWINDOWPOS)lParam)->flags |= SWP_NOZORDER; - return 0; + break; case WM_TIMER: - switch (wParam) + if (wParam == TIMER_SHOWDESKTOP) { - case TIMER_SHOWDESKTOP: CheckDesktopState(GetWorkerW()); - return 0; - - case TIMER_NETSTATS: - CMeasureNet::UpdateIFTable(); - CMeasureNet::UpdateStats(); - Rainmeter->WriteStats(false); - return 0; } break; @@ -1042,10 +1026,13 @@ LRESULT CALLBACK CSystem::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lP PostMessage((*iter).second->GetWindow(), WM_DELAYED_MOVE, (WPARAM)uMsg, (LPARAM)0); } } - return 0; + break; + + default: + return DefWindowProc(hWnd, uMsg, wParam, lParam); } - return DefWindowProc(hWnd, uMsg, wParam, lParam); + return 0; } /* diff --git a/Library/System.h b/Library/System.h index 82b97382..405e7bc1 100644 --- a/Library/System.h +++ b/Library/System.h @@ -56,8 +56,6 @@ public: static void Initialize(HINSTANCE instance); static void Finalize(); - static void SetNetworkStatisticsTimer(); - static const MULTIMONITOR_INFO& GetMultiMonitorInfo() { return c_Monitors; } static size_t GetMonitorCount();