- Uptime now shows over 49.7 days correctly in Vista or later.

- Some related tweaks.
This commit is contained in:
spx 2011-06-05 12:32:18 +00:00
parent 62c0268fef
commit 3a7d937021
10 changed files with 53 additions and 25 deletions

View File

@ -505,15 +505,11 @@ BOOL LSLog(int nLevel, LPCTSTR pszModule, LPCTSTR pszMessage)
logInfo.message = pszMessage; logInfo.message = pszMessage;
// Add timestamp // Add timestamp
static DWORD startTime = 0; static ULONGLONG startTime = CSystem::GetTickCount64();
ULONGLONG time = CSystem::GetTickCount64();
DWORD time = GetTickCount();
if (startTime == 0)
{
startTime = time;
}
WCHAR buffer[128]; WCHAR buffer[128];
_snwprintf_s(buffer, _TRUNCATE, L"(%02i:%02i:%02i.%03i) ", (time - startTime) / (1000 * 60* 60), ((time - startTime) / (1000 * 60)) % 60, ((time - startTime) / 1000) % 60, (time - startTime) % 1000); _snwprintf_s(buffer, _TRUNCATE, L"(%02llu:%02llu:%02llu.%03llu) ", (time - startTime) / (1000 * 60* 60), ((time - startTime) / (1000 * 60)) % 60, ((time - startTime) / 1000) % 60, (time - startTime) % 1000);
std::wstring message(buffer); std::wstring message(buffer);
logInfo.timestamp = message; logInfo.timestamp = message;

View File

@ -19,6 +19,7 @@
#include "StdAfx.h" #include "StdAfx.h"
#include "MeasureUptime.h" #include "MeasureUptime.h"
#include "Rainmeter.h" #include "Rainmeter.h"
#include "System.h"
/* /*
** CMeasureUptime ** CMeasureUptime
@ -73,8 +74,8 @@ bool CMeasureUptime::Update()
{ {
if (!CMeasure::PreUpdate()) return false; if (!CMeasure::PreUpdate()) return false;
DWORD ticks = GetTickCount(); ULONGLONG ticks = CSystem::GetTickCount64();
m_Value = ticks / 1000; m_Value = (double)(__int64)(ticks / 1000);
return PostUpdate(); return PostUpdate();
} }

View File

@ -803,7 +803,6 @@ bool CMeter::Draw(Graphics& graphics)
if (m_AntiAlias) if (m_AntiAlias)
{ {
//graphics.SetInterpolationMode(InterpolationModeBicubic); // Bicubic is not suitable for shrinking an image.
graphics.SetSmoothingMode(SmoothingModeHighQuality); graphics.SetSmoothingMode(SmoothingModeHighQuality);
graphics.SetPixelOffsetMode(PixelOffsetModeHighQuality); graphics.SetPixelOffsetMode(PixelOffsetModeHighQuality);
} }

View File

@ -21,6 +21,7 @@
#include "Measure.h" #include "Measure.h"
#include "Error.h" #include "Error.h"
#include "Rainmeter.h" #include "Rainmeter.h"
#include "System.h"
using namespace Gdiplus; using namespace Gdiplus;
@ -252,7 +253,7 @@ bool CMeterBitmap::Update()
if ((int)(value * realFrames) != (int)(m_Value * realFrames)) if ((int)(value * realFrames) != (int)(m_Value * realFrames))
{ {
m_TransitionStartValue = m_Value; m_TransitionStartValue = m_Value;
m_TransitionStartTicks = GetTickCount(); m_TransitionStartTicks = CSystem::GetTickCount64();
} }
else else
{ {
@ -301,7 +302,6 @@ bool CMeterBitmap::Draw(Graphics& graphics)
int x = GetX(); int x = GetX();
int y = GetY(); int y = GetY();
DWORD diffTicks = GetTickCount() - m_TransitionStartTicks;
if (m_Extend) if (m_Extend)
{ {
int value = (int)m_Value; int value = (int)m_Value;
@ -362,20 +362,21 @@ bool CMeterBitmap::Draw(Graphics& graphics)
// If transition is ongoing the pick the correct frame // If transition is ongoing the pick the correct frame
if (m_TransitionStartTicks > 0) if (m_TransitionStartTicks > 0)
{ {
int range = ((value % realFrames) - ((int)transitionValue % realFrames)) * (m_TransitionFrameCount + 1); int diffTicks = (int)(CSystem::GetTickCount64() - m_TransitionStartTicks);
int range = ((value % realFrames) - (transitionValue % realFrames)) * (m_TransitionFrameCount + 1);
if (range < 0) if (range < 0)
{ {
range += m_FrameCount; range += m_FrameCount;
} }
int frameAdjustment = 0; int frameAdjustment = range * diffTicks / ((m_TransitionFrameCount + 1) * m_MeterWindow->GetTransitionUpdate());
frameAdjustment = range * diffTicks / ((m_TransitionFrameCount + 1) * m_MeterWindow->GetTransitionUpdate());
if (frameAdjustment > range) if (frameAdjustment > range)
{ {
m_TransitionStartTicks = 0; // The transition is over. Draw with the real value. m_TransitionStartTicks = 0; // The transition is over. Draw with the real value.
} }
else else
{ {
frame = ((int)transitionValue % realFrames) * (m_TransitionFrameCount + 1); frame = (transitionValue % realFrames) * (m_TransitionFrameCount + 1);
frame += frameAdjustment; frame += frameAdjustment;
frame %= m_FrameCount; frame %= m_FrameCount;
} }
@ -430,7 +431,9 @@ bool CMeterBitmap::Draw(Graphics& graphics)
// If transition is ongoing the pick the correct frame // If transition is ongoing the pick the correct frame
if (m_TransitionStartTicks > 0) if (m_TransitionStartTicks > 0)
{ {
if ((int)diffTicks > ((m_TransitionFrameCount + 1) * m_MeterWindow->GetTransitionUpdate())) int diffTicks = (int)(CSystem::GetTickCount64() - m_TransitionStartTicks);
if (diffTicks > ((m_TransitionFrameCount + 1) * m_MeterWindow->GetTransitionUpdate()))
{ {
m_TransitionStartTicks = 0; // The transition is over. Draw with the real value. m_TransitionStartTicks = 0; // The transition is over. Draw with the real value.
} }

View File

@ -50,7 +50,7 @@ private:
int m_Digits; int m_Digits;
double m_Value; double m_Value;
DWORD m_TransitionStartTicks; ULONGLONG m_TransitionStartTicks;
double m_TransitionStartValue; double m_TransitionStartValue;
}; };

View File

@ -3050,13 +3050,13 @@ LRESULT CMeterWindow::OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam)
} }
else if (wParam == FADETIMER) else if (wParam == FADETIMER)
{ {
DWORD ticks = GetTickCount(); ULONGLONG ticks = CSystem::GetTickCount64();
if (m_FadeStartTime == 0) if (m_FadeStartTime == 0)
{ {
m_FadeStartTime = ticks; m_FadeStartTime = ticks;
} }
if (ticks - m_FadeStartTime > (DWORD)m_FadeDuration) if (ticks - m_FadeStartTime > (ULONGLONG)m_FadeDuration)
{ {
KillTimer(m_Window, FADETIMER); KillTimer(m_Window, FADETIMER);
m_FadeStartTime = 0; m_FadeStartTime = 0;
@ -3071,7 +3071,7 @@ LRESULT CMeterWindow::OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam)
} }
else else
{ {
double value = (ticks - m_FadeStartTime); double value = (double)(__int64)(ticks - m_FadeStartTime);
value /= m_FadeDuration; value /= m_FadeDuration;
value *= m_FadeEndValue - m_FadeStartValue; value *= m_FadeEndValue - m_FadeStartValue;
value += m_FadeStartValue; value += m_FadeStartValue;

View File

@ -409,7 +409,7 @@ private:
BLURMODE m_BlurMode; // The blur mode BLURMODE m_BlurMode; // The blur mode
HRGN m_BlurRegion; // Handle to the blur region HRGN m_BlurRegion; // Handle to the blur region
DWORD m_FadeStartTime; ULONGLONG m_FadeStartTime;
int m_FadeStartValue; int m_FadeStartValue;
int m_FadeEndValue; int m_FadeEndValue;
int m_TransparencyValue; int m_TransparencyValue;

View File

@ -3728,11 +3728,13 @@ void CRainmeter::ReadStats()
*/ */
void CRainmeter::WriteStats(bool bForce) void CRainmeter::WriteStats(bool bForce)
{ {
static DWORD lastWrite = 0; static ULONGLONG lastWrite = 0;
if (bForce || (lastWrite + 1000 * 60 < GetTickCount())) ULONGLONG ticks = CSystem::GetTickCount64();
if (bForce || (lastWrite + 1000 * 60 < ticks))
{ {
lastWrite = GetTickCount(); lastWrite = ticks;
// Write the date for statistics // Write the date for statistics
WritePrivateProfileString(L"Statistics", L"Since", m_StatsDate.c_str(), m_StatsFile.c_str()); WritePrivateProfileString(L"Statistics", L"Since", m_StatsDate.c_str(), m_StatsFile.c_str());

View File

@ -951,6 +951,32 @@ OSPLATFORM CSystem::GetOSPlatform()
return c_Platform; return c_Platform;
} }
/*
** GetTickCount64
**
** 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 CSystem::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;
}
}
/* /*
** RmLoadLibrary ** RmLoadLibrary
** **

View File

@ -72,6 +72,7 @@ public:
static void PrepareHelperWindow(HWND WorkerW); static void PrepareHelperWindow(HWND WorkerW);
static OSPLATFORM GetOSPlatform(); static OSPLATFORM GetOSPlatform();
static ULONGLONG GetTickCount64();
static HMODULE RmLoadLibrary(LPCWSTR lpLibFileName, DWORD* dwError = NULL, bool ignoreErrors = false); static HMODULE RmLoadLibrary(LPCWSTR lpLibFileName, DWORD* dwError = NULL, bool ignoreErrors = false);
static void ResetWorkingDirectory(); static void ResetWorkingDirectory();