Skip to content

Commit

Permalink
Replace GetTickCount with GetTickCount64 and remove System::GetTickCount
Browse files Browse the repository at this point in the history
  • Loading branch information
brianferguson committed Sep 9, 2021
1 parent b7c8f03 commit 919a2f0
Show file tree
Hide file tree
Showing 19 changed files with 33 additions and 77 deletions.
2 changes: 1 addition & 1 deletion Library/MeasureUptime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void MeasureUptime::UpdateValue()
{
if (!m_SecondsDefined)
{
ULONGLONG ticks = System::GetTickCount64();
ULONGLONG ticks = GetTickCount64();
m_Value = (double)(__int64)(ticks / 1000);
}
else
Expand Down
10 changes: 5 additions & 5 deletions Library/MeterBitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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)
Expand All @@ -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())
{
Expand Down Expand Up @@ -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()))
{
Expand All @@ -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())
{
Expand Down
6 changes: 3 additions & 3 deletions Library/NowPlaying/PlayerAIMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion Library/NowPlaying/PlayerAIMP.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions Library/NowPlaying/PlayerITunes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion Library/NowPlaying/PlayerITunes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions Library/NowPlaying/PlayerSpotify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Player* PlayerSpotify::c_Player = nullptr;
*/
PlayerSpotify::PlayerSpotify() : Player(),
m_Window(),
m_LastCheckTime(0)
m_LastCheckTime(0ULL)
{
}

Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion Library/NowPlaying/PlayerSpotify.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class PlayerSpotify : public Player
static Player* c_Player;

HWND m_Window;
DWORD m_LastCheckTime;
ULONGLONG m_LastCheckTime;
};

#endif
6 changes: 3 additions & 3 deletions Library/NowPlaying/PlayerWMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void PlayerWMP::CRemoteHost::SwitchedToControl()
PlayerWMP::PlayerWMP() : Player(),
m_TrackChanged(false),
m_Window(),
m_LastCheckTime(0),
m_LastCheckTime(0ULL),
m_ConnectionCookie()
{
}
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion Library/NowPlaying/PlayerWMP.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class PlayerWMP : public Player

bool m_TrackChanged;
HWND m_Window;
DWORD m_LastCheckTime;
ULONGLONG m_LastCheckTime;

Microsoft::WRL::ComPtr<IWMPPlayer4> m_IPlayer;
Microsoft::WRL::ComPtr<IWMPControls> m_IControls;
Expand Down
6 changes: 3 additions & 3 deletions Library/NowPlaying/PlayerWinamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion Library/NowPlaying/PlayerWinamp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Library/Rainmeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
2 changes: 1 addition & 1 deletion Library/Skin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 0 additions & 24 deletions Library/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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().
**
Expand Down
1 change: 0 additions & 1 deletion Library/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
21 changes: 1 addition & 20 deletions Plugins/PluginAdvancedCPU/AdvancedCPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions Plugins/PluginFolderInfo/FolderInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <list>
#include "../API/RainmeterAPI.h"

#define UPDATE_TIME_MIN_MS 10000
#define UPDATE_TIME_MIN_MS (10000ULL)

CFolderInfo::CFolderInfo(void* ownerSkin) :
m_InstanceCount(1),
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -157,7 +157,7 @@ void CFolderInfo::SetPath(LPCWSTR path)
m_Path = path;

// Force update next time
m_LastUpdateTime = 0;
m_LastUpdateTime = 0ULL;
}
}

Expand Down
4 changes: 2 additions & 2 deletions Plugins/PluginFolderInfo/FolderInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -53,5 +53,5 @@ class CFolderInfo
UINT m_FileCount;
UINT m_FolderCount;
pcre16* m_RegExpFilter;
DWORD m_LastUpdateTime;
ULONGLONG m_LastUpdateTime;
};

0 comments on commit 919a2f0

Please sign in to comment.