summaryrefslogtreecommitdiff
path: root/plugins/PluginUpdater
diff options
context:
space:
mode:
authorRobert Pösel <robyer@seznam.cz>2014-10-07 18:41:08 +0000
committerRobert Pösel <robyer@seznam.cz>2014-10-07 18:41:08 +0000
commite7a40f49fabfb003a2603b08a59f205ba1a1a478 (patch)
treee1e04e7d3ef0b5c8e04f62e4659e508cdec58cab /plugins/PluginUpdater
parentb4b974a256953c3e97a7e7b8426740e98fd4541f (diff)
PluginUpdater:
- Fix setting custom URL ("UpdateURL" is not same as "UpdateUrl") - Use constants for often used db setting names - Version bump git-svn-id: http://svn.miranda-ng.org/main/trunk@10733 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/PluginUpdater')
-rw-r--r--plugins/PluginUpdater/src/Common.h7
-rw-r--r--plugins/PluginUpdater/src/DlgUpdate.cpp26
-rw-r--r--plugins/PluginUpdater/src/Events.cpp4
-rw-r--r--plugins/PluginUpdater/src/Options.cpp30
-rw-r--r--plugins/PluginUpdater/src/PluginUpdater.cpp26
-rw-r--r--plugins/PluginUpdater/src/Utils.cpp12
-rw-r--r--plugins/PluginUpdater/src/unzipfile.cpp2
7 files changed, 57 insertions, 50 deletions
diff --git a/plugins/PluginUpdater/src/Common.h b/plugins/PluginUpdater/src/Common.h
index e45e885fdd..7b700ae3f0 100644
--- a/plugins/PluginUpdater/src/Common.h
+++ b/plugins/PluginUpdater/src/Common.h
@@ -121,6 +121,13 @@ struct PlugOptions
#define UPDATE_MODE_TRUNK_SYMBOLS 3
#define UPDATE_MODE_MAX_VALUE 3 // when adding new mode, increment this number
+#define DB_SETTING_UPDATE_MODE "UpdateMode"
+#define DB_SETTING_UPDATE_URL "UpdateURL"
+#define DB_SETTING_REDOWNLOAD "ForceRedownload"
+#define DB_SETTING_NEED_RESTART "NeedRestart"
+#define DB_SETTING_RESTART_COUNT "RestartCount"
+#define DB_SETTING_LAST_UPDATE "LastUpdate"
+#define DB_MODULE_FILES MODNAME "Files"
#define MAX_RETRIES 3
diff --git a/plugins/PluginUpdater/src/DlgUpdate.cpp b/plugins/PluginUpdater/src/DlgUpdate.cpp
index 18f75b3e50..3aee7f8c76 100644
--- a/plugins/PluginUpdater/src/DlgUpdate.cpp
+++ b/plugins/PluginUpdater/src/DlgUpdate.cpp
@@ -32,7 +32,7 @@ static void SelectAll(HWND hDlg, bool bEnable)
for (int i=0; i < todo.getCount(); i++) {
ListView_SetCheckState(hwndList, i, bEnable);
- db_set_b(NULL, MODNAME "Files", StrToLower(_T2A(todo[i].tszOldName)), todo[i].bEnabled = bEnable);
+ db_set_b(NULL, DB_MODULE_FILES, StrToLower(_T2A(todo[i].tszOldName)), todo[i].bEnabled = bEnable);
}
}
@@ -130,16 +130,16 @@ static void ApplyUpdates(void *param)
#endif
opts.bForceRedownload = false;
- db_unset(NULL, MODNAME, "ForceRedownload");
+ db_unset(NULL, MODNAME, DB_SETTING_REDOWNLOAD);
- db_set_b(NULL, MODNAME, "RestartCount", 5);
+ db_set_b(NULL, MODNAME, DB_SETTING_RESTART_COUNT, 5);
// 5) Prepare Restart
int rc = MessageBox(hDlg, TranslateT("Update complete. Press Yes to restart Miranda now or No to postpone a restart until the exit."), TranslateT("Plugin Updater"), MB_YESNO | MB_ICONQUESTION);
PostMessage(hDlg, WM_CLOSE, 0, 0);
if (rc == IDYES)
#if MIRANDA_VER >= 0x0A00
- CallServiceSync(MS_SYSTEM_RESTART, db_get_b(NULL,MODNAME,"RestartCurrentProfile",1) ? 1 : 0, 0);
+ CallServiceSync(MS_SYSTEM_RESTART, db_get_b(NULL, MODNAME, "RestartCurrentProfile", 1) ? 1 : 0, 0);
#else
CallFunctionAsync(RestartMe, 0);
#endif
@@ -276,7 +276,7 @@ static INT_PTR CALLBACK DlgUpdate(HWND hDlg, UINT message, WPARAM wParam, LPARAM
ListView_GetItem(hwndList, &lvI);
FILEINFO *p = (FILEINFO*)lvI.lParam;
- db_set_b(NULL, MODNAME "Files", StrToLower(_T2A(p->tszOldName)), p->bEnabled = ListView_GetCheckState(hwndList, nmlv->iItem));
+ db_set_b(NULL, DB_MODULE_FILES, StrToLower(_T2A(p->tszOldName)), p->bEnabled = ListView_GetCheckState(hwndList, nmlv->iItem));
// Toggle the Download button
bool enableOk = false;
@@ -343,7 +343,7 @@ static INT_PTR CALLBACK DlgUpdate(HWND hDlg, UINT message, WPARAM wParam, LPARAM
delete (OBJLIST<FILEINFO> *)GetWindowLongPtr(hDlg, GWLP_USERDATA);
SetWindowLongPtr(hDlg, GWLP_USERDATA, 0);
#if MIRANDA_VER >= 0x0A00
- db_set_dw(NULL, MODNAME, "LastUpdate", time(NULL));
+ db_set_dw(NULL, MODNAME, DB_SETTING_LAST_UPDATE, time(NULL));
#endif
mir_forkthread(InitTimer, 0);
break;
@@ -440,10 +440,10 @@ static void DlgUpdateSilent(void *lParam)
#endif
opts.bForceRedownload = false;
- db_unset(NULL, MODNAME, "ForceRedownload");
+ db_unset(NULL, MODNAME, DB_SETTING_REDOWNLOAD);
- db_set_b(NULL, MODNAME, "RestartCount", 5);
- db_set_b(NULL, MODNAME, "NeedRestart", 1);
+ db_set_b(NULL, MODNAME, DB_SETTING_RESTART_COUNT, 5);
+ db_set_b(NULL, MODNAME, DB_SETTING_NEED_RESTART, 1);
// 5) Prepare Restart
TCHAR tszTitle[100];
@@ -473,7 +473,7 @@ static void DlgUpdateSilent(void *lParam)
if (MessageBox(NULL, tszText, tszTitle, MB_ICONINFORMATION | MB_YESNO) == IDYES)
#if MIRANDA_VER >= 0x0A00
- CallServiceSync(MS_SYSTEM_RESTART, db_get_b(NULL,MODNAME,"RestartCurrentProfile",1) ? 1 : 0, 0);
+ CallServiceSync(MS_SYSTEM_RESTART, db_get_b(NULL, MODNAME, "RestartCurrentProfile", 1) ? 1 : 0, 0);
#else
CallFunctionAsync(RestartMe, 0);
#endif
@@ -690,7 +690,7 @@ static int ScanFolder(const TCHAR *tszFolder, size_t cbBaseLen, int level, const
*p++ = '/';
// remember whether the user has decided not to update this component with this particular new version
- FileInfo->bEnabled = db_get_b(NULL, MODNAME "Files", StrToLower(_T2A(FileInfo->tszOldName)), 1);
+ FileInfo->bEnabled = db_get_b(NULL, DB_MODULE_FILES, StrToLower(_T2A(FileInfo->tszOldName)), 1);
FileInfo->File.CRCsum = MyCRC;
UpdateFiles->insert(FileInfo);
@@ -750,7 +750,7 @@ void DoCheck(bool bSilent)
else {
opts.bSilent = bSilent;
#if MIRANDA_VER >= 0x0A00
- db_set_dw(NULL, MODNAME, "LastUpdate", time(NULL));
+ db_set_dw(NULL, MODNAME, DB_SETTING_LAST_UPDATE, time(NULL));
#endif
hCheckThread = mir_forkthread(CheckUpdates, 0);
}
@@ -785,7 +785,7 @@ void CheckUpdateOnStartup()
if (opts.bUpdateOnStartup) {
if (opts.bOnlyOnceADay) {
time_t now = time(NULL),
- was = db_get_dw(NULL, MODNAME, "LastUpdate", 0);
+ was = db_get_dw(NULL, MODNAME, DB_SETTING_LAST_UPDATE, 0);
if ((now - was) < 86400)
return;
diff --git a/plugins/PluginUpdater/src/Events.cpp b/plugins/PluginUpdater/src/Events.cpp
index 6afabbe2a7..ed2d5e7811 100644
--- a/plugins/PluginUpdater/src/Events.cpp
+++ b/plugins/PluginUpdater/src/Events.cpp
@@ -53,9 +53,9 @@ int ModulesLoaded(WPARAM, LPARAM)
else
lstrcpyn(tszRoot, VARST( _T("%miranda_path%\\"DEFAULT_UPDATES_FOLDER)), SIZEOF(tszRoot));
- int iRestartCount = db_get_b(NULL, MODNAME, "RestartCount", 2);
+ int iRestartCount = db_get_b(NULL, MODNAME, DB_SETTING_RESTART_COUNT, 2);
if (iRestartCount > 0)
- db_set_b(NULL, MODNAME, "RestartCount", iRestartCount-1);
+ db_set_b(NULL, MODNAME, DB_SETTING_RESTART_COUNT, iRestartCount - 1);
else
EmptyFolder(); // silently
diff --git a/plugins/PluginUpdater/src/Options.cpp b/plugins/PluginUpdater/src/Options.cpp
index 3a51c9ac90..f646cbdba9 100644
--- a/plugins/PluginUpdater/src/Options.cpp
+++ b/plugins/PluginUpdater/src/Options.cpp
@@ -33,7 +33,7 @@ INT_PTR CALLBACK UpdateNotifyOptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPA
EnableWindow(GetDlgItem(hwndDlg, IDC_PERIODSPIN), opts.bUpdateOnPeriod);
EnableWindow(GetDlgItem(hwndDlg, IDC_PERIODMEASURE), opts.bUpdateOnPeriod);
CheckDlgButton(hwndDlg, IDC_SILENTMODE, opts.bSilentMode);
- if (db_get_b(NULL, MODNAME, "NeedRestart", 0))
+ if (db_get_b(NULL, MODNAME, DB_SETTING_NEED_RESTART, 0))
ShowWindow(GetDlgItem(hwndDlg, IDC_NEEDRESTARTLABEL), SW_SHOW);
SendDlgItemMessage(hwndDlg, IDC_PERIODSPIN, UDM_SETRANGE, 0, MAKELONG(99, 1));
@@ -62,7 +62,7 @@ INT_PTR CALLBACK UpdateNotifyOptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPA
CheckDlgButton(hwndDlg, IDC_CUSTOM, TRUE);
EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOMURL), TRUE);
- ptrT url(db_get_tsa(NULL, MODNAME, "UpdateURL"));
+ ptrT url(db_get_tsa(NULL, MODNAME, DB_SETTING_UPDATE_URL));
SetDlgItemText(hwndDlg, IDC_CUSTOMURL, (url == NULL) ? ptrT(GetDefaultUrl()) : url);
}
}
@@ -106,7 +106,7 @@ INT_PTR CALLBACK UpdateNotifyOptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPA
case IDC_CUSTOM:
EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOMURL), TRUE);
{
- ptrT url(db_get_tsa(NULL, MODNAME, "UpdateURL"));
+ ptrT url(db_get_tsa(NULL, MODNAME, DB_SETTING_UPDATE_URL));
SetDlgItemText(hwndDlg, IDC_CUSTOMURL, (url == NULL) ? ptrT(GetDefaultUrl()) : url);
}
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
@@ -154,30 +154,30 @@ INT_PTR CALLBACK UpdateNotifyOptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPA
mir_forkthread(InitTimer, (void*)1);
if ( IsDlgButtonChecked(hwndDlg, IDC_STABLE)) {
- db_set_b(NULL, MODNAME, "UpdateMode", UPDATE_MODE_STABLE);
+ db_set_b(NULL, MODNAME, DB_SETTING_UPDATE_MODE, UPDATE_MODE_STABLE);
opts.bForceRedownload = 0;
- db_unset(NULL, MODNAME, "ForceRedownload");
+ db_unset(NULL, MODNAME, DB_SETTING_REDOWNLOAD);
}
else if ( IsDlgButtonChecked(hwndDlg, IDC_TRUNK)) {
- db_set_b(NULL, MODNAME, "UpdateMode", UPDATE_MODE_TRUNK);
+ db_set_b(NULL, MODNAME, DB_SETTING_UPDATE_MODE, UPDATE_MODE_TRUNK);
opts.bForceRedownload = 0;
- db_unset(NULL, MODNAME, "ForceRedownload");
+ db_unset(NULL, MODNAME, DB_SETTING_REDOWNLOAD);
}
else if ( IsDlgButtonChecked(hwndDlg, IDC_TRUNK_SYMBOLS)) {
// Only set ForceRedownload if the previous UpdateMode was different
// to redownload all plugin with pdb files
- if(db_get_b(NULL, MODNAME, "UpdateMode", UPDATE_MODE_STABLE) != UPDATE_MODE_TRUNK_SYMBOLS) {
- db_set_b(NULL, MODNAME, "ForceRedownload", opts.bForceRedownload = 1);
- db_set_b(NULL, MODNAME, "UpdateMode", UPDATE_MODE_TRUNK_SYMBOLS);
+ if (db_get_b(NULL, MODNAME, DB_SETTING_UPDATE_MODE, UPDATE_MODE_STABLE) != UPDATE_MODE_TRUNK_SYMBOLS) {
+ db_set_b(NULL, MODNAME, DB_SETTING_REDOWNLOAD, opts.bForceRedownload = 1);
+ db_set_b(NULL, MODNAME, DB_SETTING_UPDATE_MODE, UPDATE_MODE_TRUNK_SYMBOLS);
}
}
else {
- char szUrl[100];
- GetDlgItemTextA(hwndDlg, IDC_CUSTOMURL, szUrl, SIZEOF(szUrl));
- db_set_s(NULL, MODNAME, "UpdateURL", szUrl);
- db_set_b(NULL, MODNAME, "UpdateMode", UPDATE_MODE_CUSTOM);
+ TCHAR tszUrl[100];
+ GetDlgItemText(hwndDlg, IDC_CUSTOMURL, tszUrl, SIZEOF(tszUrl));
+ db_set_ts(NULL, MODNAME, DB_SETTING_UPDATE_URL, tszUrl);
+ db_set_b(NULL, MODNAME, DB_SETTING_UPDATE_MODE, UPDATE_MODE_CUSTOM);
opts.bForceRedownload = 0;
- db_unset(NULL, MODNAME, "ForceRedownload");
+ db_unset(NULL, MODNAME, DB_SETTING_REDOWNLOAD);
}
}
break;
diff --git a/plugins/PluginUpdater/src/PluginUpdater.cpp b/plugins/PluginUpdater/src/PluginUpdater.cpp
index 7ae7d8a48f..281c04e623 100644
--- a/plugins/PluginUpdater/src/PluginUpdater.cpp
+++ b/plugins/PluginUpdater/src/PluginUpdater.cpp
@@ -72,7 +72,7 @@ extern "C" __declspec(dllexport) int Load(void)
InitServices();
#endif
- db_set_b(NULL, MODNAME, "NeedRestart", 0);
+ db_set_b(NULL, MODNAME, DB_SETTING_NEED_RESTART, 0);
DWORD dwLen = GetTempPath( SIZEOF(tszTempPath), tszTempPath);
if (tszTempPath[dwLen-1] == '\\')
@@ -121,22 +121,22 @@ extern "C" __declspec(dllexport) int Load(void)
SkinAddNewSoundEx("updatefailed", LPGEN("Plugin Updater"), LPGEN("Update failed"));
// Upgrade old settings
- if (-1 == db_get_b(0, MODNAME, "UpdateMode", -1)) {
- ptrA dbvUpdateURL(db_get_sa(0, MODNAME, "UpdateURL"));
+ if (-1 == db_get_b(0, MODNAME, DB_SETTING_UPDATE_MODE, -1)) {
+ ptrT dbvUpdateURL(db_get_tsa(0, MODNAME, DB_SETTING_UPDATE_URL));
if (dbvUpdateURL) {
- if (!strcmp(dbvUpdateURL, DEFAULT_UPDATE_URL)) {
- db_set_b(0, MODNAME, "UpdateMode", UPDATE_MODE_STABLE);
- db_unset(0, MODNAME, "UpdateURL");
+ if (!_tcscmp(dbvUpdateURL, _T(DEFAULT_UPDATE_URL))) {
+ db_set_b(0, MODNAME, DB_SETTING_UPDATE_MODE, UPDATE_MODE_STABLE);
+ db_unset(0, MODNAME, DB_SETTING_UPDATE_URL);
}
- else if (!strcmp(dbvUpdateURL, DEFAULT_UPDATE_URL_TRUNK)) {
- db_set_b(0, MODNAME, "UpdateMode", UPDATE_MODE_TRUNK);
- db_unset(0, MODNAME, "UpdateURL");
+ else if (!_tcscmp(dbvUpdateURL, _T(DEFAULT_UPDATE_URL_TRUNK))) {
+ db_set_b(0, MODNAME, DB_SETTING_UPDATE_MODE, UPDATE_MODE_TRUNK);
+ db_unset(0, MODNAME, DB_SETTING_UPDATE_URL);
}
- else if (!strcmp(dbvUpdateURL, DEFAULT_UPDATE_URL_TRUNK_SYMBOLS"/")) {
- db_set_b(0, MODNAME, "UpdateMode", UPDATE_MODE_TRUNK_SYMBOLS);
- db_unset(0, MODNAME, "UpdateURL");
+ else if (!_tcscmp(dbvUpdateURL, _T(DEFAULT_UPDATE_URL_TRUNK_SYMBOLS)_T("/"))) {
+ db_set_b(0, MODNAME, DB_SETTING_UPDATE_MODE, UPDATE_MODE_TRUNK_SYMBOLS);
+ db_unset(0, MODNAME, DB_SETTING_UPDATE_URL);
}
- else db_set_b(0, MODNAME, "UpdateMode", UPDATE_MODE_CUSTOM);
+ else db_set_b(0, MODNAME, DB_SETTING_UPDATE_MODE, UPDATE_MODE_CUSTOM);
}
}
return 0;
diff --git a/plugins/PluginUpdater/src/Utils.cpp b/plugins/PluginUpdater/src/Utils.cpp
index 1cda5a2f13..15b50d05ae 100644
--- a/plugins/PluginUpdater/src/Utils.cpp
+++ b/plugins/PluginUpdater/src/Utils.cpp
@@ -85,7 +85,7 @@ void LoadOptions()
opts.bUpdateOnPeriod = db_get_b(NULL, MODNAME, "UpdateOnPeriod", DEFAULT_UPDATEONPERIOD);
opts.Period = db_get_dw(NULL, MODNAME, "Period", DEFAULT_PERIOD);
opts.bPeriodMeasure = db_get_b(NULL, MODNAME, "PeriodMeasure", DEFAULT_PERIODMEASURE);
- opts.bForceRedownload = db_get_b(NULL, MODNAME, "ForceRedownload", 0);
+ opts.bForceRedownload = db_get_b(NULL, MODNAME, DB_SETTING_REDOWNLOAD, 0);
opts.bSilentMode = db_get_b(NULL, MODNAME, "SilentMode", 0);
}
@@ -144,14 +144,14 @@ int Get_CRC(unsigned char* buffer, ULONG bufsize)
int GetUpdateMode()
{
- int UpdateMode = db_get_b(NULL, MODNAME, "UpdateMode", -1);
+ int UpdateMode = db_get_b(NULL, MODNAME, DB_SETTING_UPDATE_MODE, -1);
// Check if there is url for custom mode
if (UpdateMode == UPDATE_MODE_CUSTOM) {
- ptrT url( db_get_tsa(NULL, MODNAME, "UpdateUrl"));
+ ptrT url(db_get_tsa(NULL, MODNAME, DB_SETTING_UPDATE_URL));
if (url == NULL || !_tcslen(url)) {
// No url for custom mode, reset that setting so it will be determined automatically
- db_unset(NULL, MODNAME, "UpdateMode");
+ db_unset(NULL, MODNAME, DB_SETTING_UPDATE_MODE);
UpdateMode = -1;
}
}
@@ -179,7 +179,7 @@ TCHAR* GetDefaultUrl()
case UPDATE_MODE_TRUNK_SYMBOLS:
return mir_tstrdup(_T(DEFAULT_UPDATE_URL_TRUNK_SYMBOLS));
default:
- return db_get_tsa(NULL, MODNAME, "UpdateUrl");
+ return db_get_tsa(NULL, MODNAME, DB_SETTING_UPDATE_URL);
}
#endif
}
@@ -390,7 +390,7 @@ void InitTimer(void *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);
+ time_t was = db_get_dw(NULL, MODNAME, DB_SETTING_LAST_UPDATE, 0);
interval -= (now - was) * 1000;
if (interval <= 0)
diff --git a/plugins/PluginUpdater/src/unzipfile.cpp b/plugins/PluginUpdater/src/unzipfile.cpp
index 2b4ed8bf2f..17282cba41 100644
--- a/plugins/PluginUpdater/src/unzipfile.cpp
+++ b/plugins/PluginUpdater/src/unzipfile.cpp
@@ -53,7 +53,7 @@ bool extractCurrentFile(unzFile uf, TCHAR *ptszDestPath, TCHAR *ptszBackPath, bo
// This is because there may be more then one file in a single zip
// So we need to check each file
- if (ch && !db_get_b(NULL, MODNAME "Files", StrToLower(ptrA(mir_strdup(filename))), 1))
+ if (ch && !db_get_b(NULL, DB_MODULE_FILES, StrToLower(ptrA(mir_strdup(filename))), 1))
return true;
TCHAR tszDestFile[MAX_PATH], tszBackFile[MAX_PATH];