From f43cfc59f5a300a040b19d36f090e4f4816fcbb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20P=C3=B6sel?= Date: Fri, 2 Aug 2013 15:07:20 +0000 Subject: PluginUpdater: one fix git-svn-id: http://svn.miranda-ng.org/main/trunk@5551 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/PluginUpdater/src/Common.h | 2 +- plugins/PluginUpdater/src/DlgUpdate.cpp | 4 ++-- plugins/PluginUpdater/src/Options.cpp | 4 ++-- plugins/PluginUpdater/src/Utils.cpp | 25 +++++++++++++++++-------- 4 files changed, 22 insertions(+), 13 deletions(-) (limited to 'plugins/PluginUpdater/src') diff --git a/plugins/PluginUpdater/src/Common.h b/plugins/PluginUpdater/src/Common.h index 4caf660fcc..846d8b01ba 100644 --- a/plugins/PluginUpdater/src/Common.h +++ b/plugins/PluginUpdater/src/Common.h @@ -180,7 +180,7 @@ void ShowPopup(HWND hDlg, LPCTSTR Title, LPCTSTR Text, int Number, int ActType) void __stdcall RestartMe(void*); void __stdcall OpenPluginOptions(void*); BOOL AllowUpdateOnStartup(); -void InitTimer(bool lastSuccess = true); +void InitTimer(int type = 0); INT_PTR MenuCommand(WPARAM wParam,LPARAM lParam); INT_PTR ShowListCommand(WPARAM wParam,LPARAM lParam); diff --git a/plugins/PluginUpdater/src/DlgUpdate.cpp b/plugins/PluginUpdater/src/DlgUpdate.cpp index 8c2ff2bd45..197987898b 100644 --- a/plugins/PluginUpdater/src/DlgUpdate.cpp +++ b/plugins/PluginUpdater/src/DlgUpdate.cpp @@ -142,7 +142,7 @@ LBL_Exit: opts.bForceRedownload = false; db_unset(NULL, MODNAME, "ForceRedownload"); - db_set_b(NULL, MODNAME, "RestartCount", 2); + db_set_b(NULL, MODNAME, "RestartCount", 5); CallFunctionAsync(RestartMe, 0); goto LBL_Exit; } @@ -560,7 +560,7 @@ static void CheckUpdates(void *) } else CallFunctionAsync(LaunchDialog, UpdateFiles); } - InitTimer(success); + InitTimer(success ? 0 : 2); hashes.destroy(); hCheckThread = NULL; diff --git a/plugins/PluginUpdater/src/Options.cpp b/plugins/PluginUpdater/src/Options.cpp index 1368f4cbbb..bc5be97382 100644 --- a/plugins/PluginUpdater/src/Options.cpp +++ b/plugins/PluginUpdater/src/Options.cpp @@ -142,14 +142,14 @@ INT_PTR CALLBACK UpdateNotifyOptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPA opts.bPeriodMeasure = ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_PERIODMEASURE)); - InitTimer(); - db_set_b(NULL, MODNAME, "UpdateOnStartup", opts.bUpdateOnStartup); db_set_b(NULL, MODNAME, "OnlyOnceADay", opts.bOnlyOnceADay); db_set_b(NULL, MODNAME, "UpdateOnPeriod", opts.bUpdateOnPeriod); db_set_b(NULL, MODNAME, "PeriodMeasure", opts.bPeriodMeasure); db_set_dw(NULL, MODNAME, "Period", opts.Period); + InitTimer(1); + if ( IsDlgButtonChecked(hwndDlg, IDC_STABLE)) db_set_s(NULL, MODNAME, "UpdateURL", DEFAULT_UPDATE_URL); else if ( IsDlgButtonChecked(hwndDlg, IDC_TRUNK)) diff --git a/plugins/PluginUpdater/src/Utils.cpp b/plugins/PluginUpdater/src/Utils.cpp index 2b57022b51..7d6d8c754d 100644 --- a/plugins/PluginUpdater/src/Utils.cpp +++ b/plugins/PluginUpdater/src/Utils.cpp @@ -376,20 +376,29 @@ void CALLBACK TimerAPCProc(LPVOID lpArg, DWORD dwTimerLowValue, DWORD dwTimerHig DoCheck(true); } -void InitTimer(bool lastSuccess) +void InitTimer(int type) { CancelWaitableTimer(Timer); if (opts.bUpdateOnPeriod) { LONG interval = PeriodToMilliseconds(opts.Period, opts.bPeriodMeasure); - time_t now = time(NULL); - time_t was = db_get_dw(NULL, MODNAME, "LastUpdate", 0); + switch (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); - interval -= (now - was) * 1000; - if (interval <= 0) - interval = 1000; // no last update or too far in the past -> do it now - else if (!lastSuccess) - interval = 1000 * 60 * 60; // failed last check, check again in one hour + 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; + } _int64 qwDueTime = -10000i64 * interval; -- cgit v1.2.3