- 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;
// 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];
_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);
logInfo.timestamp = message;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -3728,11 +3728,13 @@ void CRainmeter::ReadStats()
*/
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
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;
}
/*
** 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
**

View File

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