summaryrefslogtreecommitdiff
path: root/plugins/PluginUpdater/src/Utils.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2014-10-02 19:57:39 +0000
committerGeorge Hazan <george.hazan@gmail.com>2014-10-02 19:57:39 +0000
commitc9c613bc0131355019d900ea73c646deb6f127ac (patch)
treee8b796967fe101b48003465e739377189821a19a /plugins/PluginUpdater/src/Utils.cpp
parent03fec7536e1a86a3f05246e177d09e10f2e982c3 (diff)
PluginUpdater:
- fix against overflow in the interval's calculation; - code cleaning; git-svn-id: http://svn.miranda-ng.org/main/trunk@10670 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/PluginUpdater/src/Utils.cpp')
-rw-r--r--plugins/PluginUpdater/src/Utils.cpp49
1 files changed, 26 insertions, 23 deletions
diff --git a/plugins/PluginUpdater/src/Utils.cpp b/plugins/PluginUpdater/src/Utils.cpp
index 4154420bc5..1cda5a2f13 100644
--- a/plugins/PluginUpdater/src/Utils.cpp
+++ b/plugins/PluginUpdater/src/Utils.cpp
@@ -355,9 +355,9 @@ bool DownloadFile(FILEURL *pFileURL, HANDLE &nlc)
/////////////////////////////////////////////////////////////////////////////////////////
-LONG PeriodToMilliseconds(const int period, BYTE &periodMeasure)
+LONGLONG PeriodToMilliseconds(const int period, BYTE &periodMeasure)
{
- LONG result = period * 1000;
+ LONGLONG result = period * 1000;
switch(periodMeasure) {
case 1:
// day
@@ -381,11 +381,13 @@ void CALLBACK TimerAPCProc(void *, DWORD, DWORD)
void InitTimer(void *type)
{
- if (opts.bUpdateOnPeriod) {
- LONG interval = PeriodToMilliseconds(opts.Period, opts.bPeriodMeasure);
+ if (!opts.bUpdateOnPeriod)
+ return;
- switch ((int)type) {
- case 0: // default, plan next check relative to last check
+ LONGLONG interval = PeriodToMilliseconds(opts.Period, opts.bPeriodMeasure);
+
+ switch ((int)type) {
+ case 0: // default, plan next check relative to last check
{
time_t now = time(NULL);
time_t was = db_get_dw(NULL, MODNAME, "LastUpdate", 0);
@@ -393,27 +395,28 @@ void InitTimer(void *type)
interval -= (now - was) * 1000;
if (interval <= 0)
interval = 1000; // no last update or too far in the past -> do it now
- break;
- }
- case 1: // options changed, use set interval from now
- break;
- case 2: // failed last check, check again in two hours
- interval = 1000 * 60 * 60 * 2;
- break;
}
+ break;
- FILETIME ft;
- GetSystemTimeAsFileTime(&ft);
-
- LARGE_INTEGER li;
- li.LowPart = ft.dwLowDateTime;
- li.HighPart = ft.dwHighDateTime;
- li.QuadPart += (ULONGLONG)(interval * 10000LL);
- SetWaitableTimer(Timer, &li, 0, TimerAPCProc, NULL, 0);
+ case 1: // options changed, use set interval from now
+ break;
- // Wait in an alertable state for the timer to go off.
- SleepEx(INFINITE, TRUE);
+ case 2: // failed last check, check again in two hours
+ interval = 1000 * 60 * 60 * 2;
+ break;
}
+
+ FILETIME ft;
+ GetSystemTimeAsFileTime(&ft);
+
+ LARGE_INTEGER li;
+ li.LowPart = ft.dwLowDateTime;
+ li.HighPart = ft.dwHighDateTime;
+ li.QuadPart += interval * 10000LL;
+ SetWaitableTimer(Timer, &li, 0, TimerAPCProc, NULL, 0);
+
+ // Wait in an alertable state for the timer to go off.
+ SleepEx(INFINITE, TRUE);
}
void strdel(TCHAR *parBuffer, int len)