From 919a2f00eec56a3098ec06ea6ba66eccb524e014 Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 8 Sep 2021 21:58:38 -0600 Subject: [PATCH] Replace GetTickCount with GetTickCount64 and remove System::GetTickCount --- Library/MeasureUptime.cpp | 2 +- Library/MeterBitmap.cpp | 10 +++++----- Library/NowPlaying/PlayerAIMP.cpp | 6 +++--- Library/NowPlaying/PlayerAIMP.h | 2 +- Library/NowPlaying/PlayerITunes.cpp | 4 ++-- Library/NowPlaying/PlayerITunes.h | 2 +- Library/NowPlaying/PlayerSpotify.cpp | 6 +++--- Library/NowPlaying/PlayerSpotify.h | 2 +- Library/NowPlaying/PlayerWMP.cpp | 6 +++--- Library/NowPlaying/PlayerWMP.h | 2 +- Library/NowPlaying/PlayerWinamp.cpp | 6 +++--- Library/NowPlaying/PlayerWinamp.h | 2 +- Library/Rainmeter.cpp | 2 +- Library/Skin.cpp | 2 +- Library/System.cpp | 24 ----------------------- Library/System.h | 1 - Plugins/PluginAdvancedCPU/AdvancedCPU.cpp | 21 +------------------- Plugins/PluginFolderInfo/FolderInfo.cpp | 6 +++--- Plugins/PluginFolderInfo/FolderInfo.h | 4 ++-- 19 files changed, 33 insertions(+), 77 deletions(-) diff --git a/Library/MeasureUptime.cpp b/Library/MeasureUptime.cpp index a1fcd9672..ebfb67d4c 100644 --- a/Library/MeasureUptime.cpp +++ b/Library/MeasureUptime.cpp @@ -58,7 +58,7 @@ void MeasureUptime::UpdateValue() { if (!m_SecondsDefined) { - ULONGLONG ticks = System::GetTickCount64(); + ULONGLONG ticks = GetTickCount64(); m_Value = (double)(__int64)(ticks / 1000); } else diff --git a/Library/MeterBitmap.cpp b/Library/MeterBitmap.cpp index f62fb440d..81787b3eb 100644 --- a/Library/MeterBitmap.cpp +++ b/Library/MeterBitmap.cpp @@ -230,7 +230,7 @@ bool MeterBitmap::Update() if ((int)(value * realFrames) != (int)(m_Value * realFrames)) { m_TransitionStartValue = m_Value; - m_TransitionStartTicks = System::GetTickCount64(); + m_TransitionStartTicks = GetTickCount64(); } else { @@ -364,7 +364,7 @@ bool MeterBitmap::Draw(Gfx::Canvas& canvas) // If transition is ongoing the pick the correct frame if (m_TransitionStartTicks > 0) { - int diffTicks = (int)(System::GetTickCount64() - m_TransitionStartTicks); + int diffTicks = (int)(GetTickCount64() - m_TransitionStartTicks); int range = ((value % realFrames) - (transitionValue % realFrames)) * (m_TransitionFrameCount + 1); if (range < 0) @@ -384,7 +384,7 @@ bool MeterBitmap::Draw(Gfx::Canvas& canvas) } } - //LogDebugF(L"[%u] Value: %f Frame: %i (Transition = %s)", GetTickCount(), m_Value, frame, m_TransitionStartTicks > 0 ? L"true" : L"false"); + //LogDebugF(L"[%llu] Value: %f Frame: %i (Transition = %s)", GetTickCount64(), m_Value, frame, m_TransitionStartTicks > 0ULL ? L"true" : L"false"); if (bitmap->GetHeight() > bitmap->GetWidth()) { @@ -442,7 +442,7 @@ bool MeterBitmap::Draw(Gfx::Canvas& canvas) // If transition is ongoing the pick the correct frame if (m_TransitionStartTicks > 0) { - int diffTicks = (int)(System::GetTickCount64() - m_TransitionStartTicks); + int diffTicks = (int)(GetTickCount64() - m_TransitionStartTicks); if (diffTicks > ((m_TransitionFrameCount + 1) * m_Skin->GetTransitionUpdate())) { @@ -461,7 +461,7 @@ bool MeterBitmap::Draw(Gfx::Canvas& canvas) } } - //LogDebugF(L"[%u] Value: %f Frame: %i (Transition = %s)", GetTickCount(), m_Value, frame, m_TransitionStartTicks > 0 ? L"true" : L"false"); + //LogDebugF(L"[%llu] Value: %f Frame: %i (Transition = %s)", GetTickCount64(), m_Value, frame, m_TransitionStartTicks > 0ULL ? L"true" : L"false"); if (bitmap->GetHeight() > bitmap->GetWidth()) { diff --git a/Library/NowPlaying/PlayerAIMP.cpp b/Library/NowPlaying/PlayerAIMP.cpp index 0f5bf0227..4c667ffe3 100644 --- a/Library/NowPlaying/PlayerAIMP.cpp +++ b/Library/NowPlaying/PlayerAIMP.cpp @@ -19,7 +19,7 @@ Player* PlayerAIMP::c_Player = nullptr; PlayerAIMP::PlayerAIMP() : Player(), m_Window(), m_WinampWindow(), - m_LastCheckTime(0), + m_LastCheckTime(0ULL), m_LastFileSize(0), m_LastTitleSize(0), m_FileMap(), @@ -58,10 +58,10 @@ Player* PlayerAIMP::Create() */ bool PlayerAIMP::CheckWindow() { - DWORD time = GetTickCount(); + ULONGLONG time = GetTickCount64(); // Try to find AIMP every 5 seconds - if (time - m_LastCheckTime > 5000) + if (time - m_LastCheckTime > 5000ULL) { m_LastCheckTime = time; m_Window = FindWindow(L"AIMP2_RemoteInfo", L"AIMP2_RemoteInfo"); diff --git a/Library/NowPlaying/PlayerAIMP.h b/Library/NowPlaying/PlayerAIMP.h index 6e595d466..07832ce55 100644 --- a/Library/NowPlaying/PlayerAIMP.h +++ b/Library/NowPlaying/PlayerAIMP.h @@ -43,7 +43,7 @@ class PlayerAIMP : public Player HWND m_Window; // AIMP window HWND m_WinampWindow; // AIMP Winamp API window - DWORD m_LastCheckTime; + ULONGLONG m_LastCheckTime; INT64 m_LastFileSize; DWORD m_LastTitleSize; LPVOID m_FileMap; diff --git a/Library/NowPlaying/PlayerITunes.cpp b/Library/NowPlaying/PlayerITunes.cpp index 365287c1f..2a549fbb8 100644 --- a/Library/NowPlaying/PlayerITunes.cpp +++ b/Library/NowPlaying/PlayerITunes.cpp @@ -222,8 +222,8 @@ LRESULT CALLBACK PlayerITunes::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARA */ bool PlayerITunes::CheckWindow() { - DWORD time = GetTickCount(); - if (time - m_LastCheckTime > 500UL) + ULONGLONG time = GetTickCount64(); + if (time - m_LastCheckTime > 500ULL) { m_LastCheckTime = time; diff --git a/Library/NowPlaying/PlayerITunes.h b/Library/NowPlaying/PlayerITunes.h index e016ece16..15541eaf0 100644 --- a/Library/NowPlaying/PlayerITunes.h +++ b/Library/NowPlaying/PlayerITunes.h @@ -75,7 +75,7 @@ class PlayerITunes : public Player static Player* c_Player; HWND m_CallbackWindow; - DWORD m_LastCheckTime; + ULONGLONG m_LastCheckTime; bool m_iTunesActive; IiTunes* m_iTunes; CEventHandler* m_iTunesEvent; diff --git a/Library/NowPlaying/PlayerSpotify.cpp b/Library/NowPlaying/PlayerSpotify.cpp index 6a244813b..e005103d9 100644 --- a/Library/NowPlaying/PlayerSpotify.cpp +++ b/Library/NowPlaying/PlayerSpotify.cpp @@ -17,7 +17,7 @@ Player* PlayerSpotify::c_Player = nullptr; */ PlayerSpotify::PlayerSpotify() : Player(), m_Window(), - m_LastCheckTime(0) + m_LastCheckTime(0ULL) { } @@ -72,10 +72,10 @@ std::wstring GetExe(HWND hwnd) */ bool PlayerSpotify::CheckWindow() { - DWORD time = GetTickCount(); + ULONGLONG time = GetTickCount64(); // Try to find Spotify window every 5 seconds - if (time - m_LastCheckTime > 5000) + if (time - m_LastCheckTime > 5000ULL) { m_LastCheckTime = time; diff --git a/Library/NowPlaying/PlayerSpotify.h b/Library/NowPlaying/PlayerSpotify.h index 71f3517e8..9f9a979ed 100644 --- a/Library/NowPlaying/PlayerSpotify.h +++ b/Library/NowPlaying/PlayerSpotify.h @@ -46,7 +46,7 @@ class PlayerSpotify : public Player static Player* c_Player; HWND m_Window; - DWORD m_LastCheckTime; + ULONGLONG m_LastCheckTime; }; #endif diff --git a/Library/NowPlaying/PlayerWMP.cpp b/Library/NowPlaying/PlayerWMP.cpp index b413216b5..8ee00df25 100644 --- a/Library/NowPlaying/PlayerWMP.cpp +++ b/Library/NowPlaying/PlayerWMP.cpp @@ -203,7 +203,7 @@ void PlayerWMP::CRemoteHost::SwitchedToControl() PlayerWMP::PlayerWMP() : Player(), m_TrackChanged(false), m_Window(), - m_LastCheckTime(0), + m_LastCheckTime(0ULL), m_ConnectionCookie() { } @@ -499,10 +499,10 @@ void PlayerWMP::UpdateData() } else { - DWORD time = GetTickCount(); + ULONGLONG time = GetTickCount64(); // Try to find WMP window every 5 seconds - if (m_LastCheckTime = 0 || time - m_LastCheckTime > 5000) + if (m_LastCheckTime = 0 || time - m_LastCheckTime > 5000ULL) { m_LastCheckTime = time; diff --git a/Library/NowPlaying/PlayerWMP.h b/Library/NowPlaying/PlayerWMP.h index 779680d05..96367b25e 100644 --- a/Library/NowPlaying/PlayerWMP.h +++ b/Library/NowPlaying/PlayerWMP.h @@ -121,7 +121,7 @@ class PlayerWMP : public Player bool m_TrackChanged; HWND m_Window; - DWORD m_LastCheckTime; + ULONGLONG m_LastCheckTime; Microsoft::WRL::ComPtr m_IPlayer; Microsoft::WRL::ComPtr m_IControls; diff --git a/Library/NowPlaying/PlayerWinamp.cpp b/Library/NowPlaying/PlayerWinamp.cpp index 24f71b234..e49516385 100644 --- a/Library/NowPlaying/PlayerWinamp.cpp +++ b/Library/NowPlaying/PlayerWinamp.cpp @@ -21,7 +21,7 @@ Player* PlayerWinamp::c_Player = nullptr; */ PlayerWinamp::PlayerWinamp(WINAMPTYPE type) : Player(), m_Window(), - m_LastCheckTime(0), + m_LastCheckTime(0ULL), m_UseUnicodeAPI(false), m_PlayingStream(false), m_WinampType(type), @@ -60,10 +60,10 @@ Player* PlayerWinamp::Create(WINAMPTYPE type) */ bool PlayerWinamp::CheckWindow() { - DWORD time = GetTickCount(); + ULONGLONG time = GetTickCount64(); // Try to find Winamp window every 5 seconds - if (time - m_LastCheckTime > 5000) + if (time - m_LastCheckTime > 5000ULL) { m_LastCheckTime = time; diff --git a/Library/NowPlaying/PlayerWinamp.h b/Library/NowPlaying/PlayerWinamp.h index a5929b5fc..158bdcc41 100644 --- a/Library/NowPlaying/PlayerWinamp.h +++ b/Library/NowPlaying/PlayerWinamp.h @@ -47,7 +47,7 @@ class PlayerWinamp : public Player static Player* c_Player; HWND m_Window; // Winamp window - DWORD m_LastCheckTime; + ULONGLONG m_LastCheckTime; bool m_UseUnicodeAPI; bool m_PlayingStream; WINAMPTYPE m_WinampType; diff --git a/Library/Rainmeter.cpp b/Library/Rainmeter.cpp index c0a82e082..4c068b45b 100644 --- a/Library/Rainmeter.cpp +++ b/Library/Rainmeter.cpp @@ -1999,7 +1999,7 @@ void Rainmeter::WriteStats(bool bForce) { static ULONGLONG lastWrite = 0; - ULONGLONG ticks = System::GetTickCount64(); + ULONGLONG ticks = GetTickCount64(); if (bForce || (lastWrite + INTERVAL_NETSTATS < ticks)) { diff --git a/Library/Skin.cpp b/Library/Skin.cpp index addb505df..c77819772 100644 --- a/Library/Skin.cpp +++ b/Library/Skin.cpp @@ -3324,7 +3324,7 @@ LRESULT Skin::OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam) break; } - ULONGLONG ticks = System::GetTickCount64(); + ULONGLONG ticks = GetTickCount64(); if (m_FadeStartTime == 0) { m_FadeStartTime = ticks; diff --git a/Library/System.cpp b/Library/System.cpp index 51ba3868d..6da7331e7 100644 --- a/Library/System.cpp +++ b/Library/System.cpp @@ -990,30 +990,6 @@ LRESULT CALLBACK System::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPa return 0; } -/* -** Retrieves the number of milliseconds that have elapsed since the system was started. -** In XP, returns the predictive value due to the 32bit limitation. -** -*/ -ULONGLONG System::GetTickCount64() -{ - static auto s_GetTickCount64 = - (decltype(GetTickCount64)*)GetProcAddress(GetModuleHandle(L"kernel32"), "GetTickCount64"); - - if (s_GetTickCount64) - { - return s_GetTickCount64(); - } - else - { - static ULONGLONG lastTicks = 0; - ULONGLONG ticks = GetTickCount(); - while (ticks < lastTicks) ticks += 0x100000000; - lastTicks = ticks; - return ticks; - } -} - /* ** Gets the cursor position in last message retrieved by GetMessage(). ** diff --git a/Library/System.h b/Library/System.h index 03a72a09c..da135e672 100644 --- a/Library/System.h +++ b/Library/System.h @@ -52,7 +52,6 @@ class System static HWND GetHelperWindow() { return c_HelperWindow; } static void PrepareHelperWindow(HWND WorkerW = GetWorkerW()); - static ULONGLONG GetTickCount64(); static POINT GetCursorPosition(); static bool IsFileWritable(LPCWSTR file); diff --git a/Plugins/PluginAdvancedCPU/AdvancedCPU.cpp b/Plugins/PluginAdvancedCPU/AdvancedCPU.cpp index ceba05cc2..9d170a0b1 100644 --- a/Plugins/PluginAdvancedCPU/AdvancedCPU.cpp +++ b/Plugins/PluginAdvancedCPU/AdvancedCPU.cpp @@ -131,32 +131,13 @@ bool CheckProcess(MeasureData* measure, const WCHAR* name) return false; } -ULONGLONG _GetTickCount64() -{ - typedef ULONGLONG (WINAPI * FPGETTICKCOUNT64)(); - static FPGETTICKCOUNT64 c_GetTickCount64 = (FPGETTICKCOUNT64)GetProcAddress(GetModuleHandle(L"kernel32"), "GetTickCount64"); - - if (c_GetTickCount64) - { - return c_GetTickCount64(); - } - else - { - static ULONGLONG lastTicks = 0; - ULONGLONG ticks = GetTickCount(); - while (ticks < lastTicks) ticks += 0x100000000; - lastTicks = ticks; - return ticks; - } -} - PLUGIN_EXPORT double Update(void* data) { MeasureData* measure = (MeasureData*)data; static ULONGLONG oldTime = 0; // Only update twice per second - ULONGLONG time = _GetTickCount64(); + ULONGLONG time = GetTickCount64(); if (oldTime == 0 || time - oldTime > 500) { UpdateProcesses(); diff --git a/Plugins/PluginFolderInfo/FolderInfo.cpp b/Plugins/PluginFolderInfo/FolderInfo.cpp index d48a56f89..f1d9e7078 100644 --- a/Plugins/PluginFolderInfo/FolderInfo.cpp +++ b/Plugins/PluginFolderInfo/FolderInfo.cpp @@ -10,7 +10,7 @@ #include #include "../API/RainmeterAPI.h" -#define UPDATE_TIME_MIN_MS 10000 +#define UPDATE_TIME_MIN_MS (10000ULL) CFolderInfo::CFolderInfo(void* ownerSkin) : m_InstanceCount(1), @@ -63,7 +63,7 @@ void CFolderInfo::FreePcre() void CFolderInfo::Update() { - DWORD now = GetTickCount(); + ULONGLONG now = GetTickCount64(); if (now - m_LastUpdateTime > UPDATE_TIME_MIN_MS) { Clear(); @@ -157,7 +157,7 @@ void CFolderInfo::SetPath(LPCWSTR path) m_Path = path; // Force update next time - m_LastUpdateTime = 0; + m_LastUpdateTime = 0ULL; } } diff --git a/Plugins/PluginFolderInfo/FolderInfo.h b/Plugins/PluginFolderInfo/FolderInfo.h index 7be9c1b51..c93e90e63 100644 --- a/Plugins/PluginFolderInfo/FolderInfo.h +++ b/Plugins/PluginFolderInfo/FolderInfo.h @@ -23,7 +23,7 @@ class CFolderInfo void RemoveInstance(); void* GetSkin() { return m_Skin; } - DWORD GetLastUpdateTime() { return m_LastUpdateTime; } + ULONGLONG GetLastUpdateTime() { return m_LastUpdateTime; } void SetPath(LPCWSTR path); void SetRegExpFilter(LPCWSTR filter); @@ -53,5 +53,5 @@ class CFolderInfo UINT m_FileCount; UINT m_FolderCount; pcre16* m_RegExpFilter; - DWORD m_LastUpdateTime; + ULONGLONG m_LastUpdateTime; };