From f8847c2493e899ad2e7527803354bc47ba6ac736 Mon Sep 17 00:00:00 2001 From: Tobias Weimer Date: Fri, 21 Aug 2015 20:06:53 +0000 Subject: PluginUpdater: - Implemented "Backup profile after update" option - minor fixes git-svn-id: http://svn.miranda-ng.org/main/trunk@15007 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/PluginUpdater/src/DlgListNew.cpp | 50 ++++++++++++----------------- plugins/PluginUpdater/src/DlgUpdate.cpp | 11 +++++-- plugins/PluginUpdater/src/Events.cpp | 3 -- plugins/PluginUpdater/src/Options.cpp | 27 ++++++++++------ plugins/PluginUpdater/src/PluginUpdater.cpp | 6 ++-- plugins/PluginUpdater/src/Utils.cpp | 1 + plugins/PluginUpdater/src/resource.h | 2 +- plugins/PluginUpdater/src/stdafx.h | 20 ++++++++---- 8 files changed, 66 insertions(+), 54 deletions(-) (limited to 'plugins/PluginUpdater/src') diff --git a/plugins/PluginUpdater/src/DlgListNew.cpp b/plugins/PluginUpdater/src/DlgListNew.cpp index 6dc0558cc8..d144b5cd35 100644 --- a/plugins/PluginUpdater/src/DlgListNew.cpp +++ b/plugins/PluginUpdater/src/DlgListNew.cpp @@ -423,24 +423,19 @@ void UninitListNew() DestroyWindow(hwndDialog); } -INT_PTR ShowListCommand(WPARAM,LPARAM) +static INT_PTR ShowListCommand(WPARAM,LPARAM) { DoGetList(); return 0; } -void InitListNew() -{ - CreateServiceFunction(MS_PU_SHOWLIST, ShowListCommand); -} - void UnloadListNew() { if (hListThread) hListThread = NULL; } -INT_PTR ParseUriService(WPARAM wParam, LPARAM lParam) +static INT_PTR ParseUriService(WPARAM, LPARAM lParam) { TCHAR *arg = (TCHAR *)lParam; if (arg == NULL) @@ -458,6 +453,9 @@ INT_PTR ParseUriService(WPARAM wParam, LPARAM lParam) p = _tcschr(pluginPath, _T('/')); if (p) *p = _T('\\'); + if (GetFileAttributes(pluginPath) != INVALID_FILE_ATTRIBUTES) + return 0; + ptrT updateUrl(GetDefaultUrl()), baseUrl; SERVLIST hashes(50, CompareHashes); if (!ParseHashes(updateUrl, baseUrl, hashes)) { @@ -465,30 +463,24 @@ INT_PTR ParseUriService(WPARAM wParam, LPARAM lParam) return 1; } - FILELIST *fileList = new FILELIST(1); + ServListEntry *hash = hashes.find((ServListEntry*)&pluginPath); + if (hash == NULL) + return 0; VARST dirName(_T("%miranda_path%")); - for (int i = 0; i < hashes.getCount(); i++) - { - ServListEntry &hash = hashes[i]; - - if (mir_tstrcmpi(hash.m_name, pluginPath) == 0) - { - TCHAR tszPath[MAX_PATH]; - mir_sntprintf(tszPath, _countof(tszPath), _T("%s\\%s"), dirName, hash.m_name); - - FILEINFO *fileInfo = ServerEntryToFileInfo(hash, baseUrl, tszPath); - fileList->insert(fileInfo); + TCHAR tszPath[MAX_PATH]; + mir_sntprintf(tszPath, _countof(tszPath), _T("%s\\%s"), dirName, hash->m_name); + FILEINFO *fileInfo = ServerEntryToFileInfo(*hash, baseUrl, tszPath); - break; - } - } - - if (fileList->getCount() == 0) { - ShowPopup(TranslateT("Plugin Updater"), TranslateT("List is empty."), POPUP_TYPE_INFO); - delete fileList; - } - else CallFunctionAsync(LaunchListDialog, fileList); + FILELIST *fileList = new FILELIST(1); + fileList->insert(fileInfo); + CallFunctionAsync(LaunchListDialog, fileList); return 0; -} \ No newline at end of file +} + +void InitListNew() +{ + CreateServiceFunction(MODNAME "/ParseUri", ParseUriService); + CreateServiceFunction(MS_PU_SHOWLIST, ShowListCommand); +} diff --git a/plugins/PluginUpdater/src/DlgUpdate.cpp b/plugins/PluginUpdater/src/DlgUpdate.cpp index b5238f131c..6030a73d4c 100644 --- a/plugins/PluginUpdater/src/DlgUpdate.cpp +++ b/plugins/PluginUpdater/src/DlgUpdate.cpp @@ -133,6 +133,9 @@ static void ApplyUpdates(void *param) db_set_b(NULL, MODNAME, DB_SETTING_RESTART_COUNT, 5); + if (opts.bBackup) + CallService(MS_AB_BACKUP); + // 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); @@ -356,9 +359,9 @@ static INT_PTR CALLBACK DlgUpdate(HWND hDlg, UINT message, WPARAM wParam, LPARAM return FALSE; } -static void DlgUpdateSilent(void *lParam) +static void DlgUpdateSilent(void *param) { - OBJLIST &UpdateFiles = *(OBJLIST *)lParam; + OBJLIST &UpdateFiles = *(OBJLIST *)param; if (UpdateFiles.getCount() == 0) { delete &UpdateFiles; return; @@ -652,6 +655,7 @@ static int ScanFolder(const TCHAR *tszFolder, size_t cbBaseLen, int level, const strdel(tszNewName + iPos, 1); } +#if MIRANDA_VER >= 0x0A00 // No need to hash a file if we are forcing a redownload anyway if (!opts.bForceRedownload) { // try to hash the file @@ -673,6 +677,7 @@ static int ScanFolder(const TCHAR *tszFolder, size_t cbBaseLen, int level, const } else Netlib_LogfT(hNetlibUser, _T("File %s: Forcing redownload"), ffd.cFileName); +#endif ptszUrl = item->m_name; MyCRC = item->m_crc; @@ -851,7 +856,7 @@ void InitTimer(void *type) LONGLONG interval; - switch ((int)type) { + switch ((INT_PTR)type) { case 0: // default, plan next check relative to last check { time_t now = time(NULL); diff --git a/plugins/PluginUpdater/src/Events.cpp b/plugins/PluginUpdater/src/Events.cpp index 6781bc4a88..ee9d124113 100644 --- a/plugins/PluginUpdater/src/Events.cpp +++ b/plugins/PluginUpdater/src/Events.cpp @@ -55,10 +55,7 @@ int ModulesLoaded(WPARAM, LPARAM) #if MIRANDA_VER >= 0x0A00 if (ServiceExists(MS_ASSOCMGR_ADDNEWURLTYPE)) - { - CreateServiceFunction(MODNAME "/ParseUri", ParseUriService); AssocMgr_AddNewUrlTypeT("mirpu:", TranslateT("Plugin updater URI scheme"), hInst, IDI_PLGLIST, MODNAME "/ParseUri", 0); - } #endif int iRestartCount = db_get_b(NULL, MODNAME, DB_SETTING_RESTART_COUNT, 2); diff --git a/plugins/PluginUpdater/src/Options.cpp b/plugins/PluginUpdater/src/Options.cpp index 235b214244..04f563cae2 100644 --- a/plugins/PluginUpdater/src/Options.cpp +++ b/plugins/PluginUpdater/src/Options.cpp @@ -60,11 +60,10 @@ TCHAR* GetDefaultUrl() } } -INT_PTR CALLBACK UpdateNotifyOptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +static INT_PTR CALLBACK UpdateNotifyOptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); if (opts.bUpdateOnStartup) { CheckDlgButton(hwndDlg, IDC_UPDATEONSTARTUP, BST_CHECKED); EnableWindow(GetDlgItem(hwndDlg, IDC_ONLYONCEADAY), TRUE); @@ -83,11 +82,14 @@ INT_PTR CALLBACK UpdateNotifyOptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPA SendDlgItemMessage(hwndDlg, IDC_PERIODSPIN, UDM_SETRANGE, 0, MAKELONG(99, 1)); SendDlgItemMessage(hwndDlg, IDC_PERIODSPIN, UDM_SETPOS, 0, (LPARAM)opts.Period); - Edit_LimitText(GetDlgItem(hwndDlg, IDC_PERIOD), 2); + if (ServiceExists(MS_AB_BACKUP)) { + EnableWindow(GetDlgItem(hwndDlg, IDC_BACKUP), TRUE); + SetDlgItemText(hwndDlg, IDC_BACKUP, LPGENT("Backup profile after update")); + if(opts.bBackup) + CheckDlgButton(hwndDlg, IDC_BACKUP, BST_CHECKED); + } - ComboBox_InsertString(GetDlgItem(hwndDlg, IDC_PERIODMEASURE), 0, TranslateT("hours")); - ComboBox_InsertString(GetDlgItem(hwndDlg, IDC_PERIODMEASURE), 1, TranslateT("days")); - ComboBox_SetCurSel(GetDlgItem(hwndDlg, IDC_PERIODMEASURE), opts.bPeriodMeasure); + Edit_LimitText(GetDlgItem(hwndDlg, IDC_PERIOD), 2); if (db_get_b(NULL, MODNAME, DB_SETTING_DONT_SWITCH_TO_STABLE, 0)) { EnableWindow(GetDlgItem(hwndDlg, IDC_STABLE), FALSE); @@ -95,8 +97,13 @@ INT_PTR CALLBACK UpdateNotifyOptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPA int UpdateMode = db_get_b(NULL, MODNAME, DB_SETTING_UPDATE_MODE, UPDATE_MODE_STABLE); if (UpdateMode == UPDATE_MODE_STABLE) db_set_b(NULL, MODNAME, DB_SETTING_UPDATE_MODE, UPDATE_MODE_TRUNK); - SetDlgItemText(hwndDlg,IDC_STABLE,TranslateT("Stable version (incompatible with current development version)")); + SetDlgItemText(hwndDlg,IDC_STABLE,LPGENT("Stable version (incompatible with current development version)")); } + TranslateDialogDefault(hwndDlg); + + ComboBox_InsertString(GetDlgItem(hwndDlg, IDC_PERIODMEASURE), 0, TranslateT("hours")); + ComboBox_InsertString(GetDlgItem(hwndDlg, IDC_PERIODMEASURE), 1, TranslateT("days")); + ComboBox_SetCurSel(GetDlgItem(hwndDlg, IDC_PERIODMEASURE), opts.bPeriodMeasure); switch (GetUpdateMode()) { case UPDATE_MODE_STABLE: @@ -129,6 +136,7 @@ INT_PTR CALLBACK UpdateNotifyOptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPA // fall through case IDC_SILENTMODE: case IDC_ONLYONCEADAY: + case IDC_BACKUP: SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; @@ -203,6 +211,7 @@ INT_PTR CALLBACK UpdateNotifyOptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPA db_set_b(NULL, MODNAME, "UpdateOnPeriod", opts.bUpdateOnPeriod = IsDlgButtonChecked(hwndDlg, IDC_UPDATEONPERIOD)); db_set_b(NULL, MODNAME, "PeriodMeasure", opts.bPeriodMeasure = ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_PERIODMEASURE))); db_set_b(NULL, MODNAME, "SilentMode", opts.bSilentMode = IsDlgButtonChecked(hwndDlg, IDC_SILENTMODE)); + db_set_b(NULL, MODNAME, "Backup", opts.bBackup = IsDlgButtonChecked(hwndDlg, IDC_BACKUP)); TCHAR buffer[3] = {0}; Edit_GetText(GetDlgItem(hwndDlg, IDC_PERIOD), buffer, _countof(buffer)); db_set_dw(NULL, MODNAME, "Period", opts.Period = _ttoi(buffer)); @@ -241,7 +250,7 @@ INT_PTR CALLBACK UpdateNotifyOptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPA return FALSE; } -INT_PTR CALLBACK DlgPopupOpts(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam) +static INT_PTR CALLBACK DlgPopupOpts(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_INITDIALOG: @@ -434,7 +443,7 @@ INT_PTR CALLBACK DlgPopupOpts(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam) return FALSE; } -int OptInit(WPARAM wParam, LPARAM) +static int OptInit(WPARAM wParam, LPARAM) { OPTIONSDIALOGPAGE odp = { 0 }; odp.position = 100000000; diff --git a/plugins/PluginUpdater/src/PluginUpdater.cpp b/plugins/PluginUpdater/src/PluginUpdater.cpp index c030a6376d..a360721322 100644 --- a/plugins/PluginUpdater/src/PluginUpdater.cpp +++ b/plugins/PluginUpdater/src/PluginUpdater.cpp @@ -132,15 +132,15 @@ extern "C" __declspec(dllexport) int Load(void) 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 (!_tcscmp(dbvUpdateURL, _T(DEFAULT_UPDATE_URL))) { + if (!_tcscmp(dbvUpdateURL, _T(DEFAULT_UPDATE_URL_OLD))) { db_set_b(0, MODNAME, DB_SETTING_UPDATE_MODE, UPDATE_MODE_STABLE); db_unset(0, MODNAME, DB_SETTING_UPDATE_URL); } - else if (!_tcscmp(dbvUpdateURL, _T(DEFAULT_UPDATE_URL_TRUNK))) { + else if (!_tcscmp(dbvUpdateURL, _T(DEFAULT_UPDATE_URL_TRUNK_OLD))) { db_set_b(0, MODNAME, DB_SETTING_UPDATE_MODE, UPDATE_MODE_TRUNK); db_unset(0, MODNAME, DB_SETTING_UPDATE_URL); } - else if (!_tcscmp(dbvUpdateURL, _T(DEFAULT_UPDATE_URL_TRUNK_SYMBOLS)_T("/"))) { + else if (!_tcscmp(dbvUpdateURL, _T(DEFAULT_UPDATE_URL_TRUNK_SYMBOLS_OLD)_T("/"))) { db_set_b(0, MODNAME, DB_SETTING_UPDATE_MODE, UPDATE_MODE_TRUNK_SYMBOLS); db_unset(0, MODNAME, DB_SETTING_UPDATE_URL); } diff --git a/plugins/PluginUpdater/src/Utils.cpp b/plugins/PluginUpdater/src/Utils.cpp index b8bf392a5f..33db2655d8 100644 --- a/plugins/PluginUpdater/src/Utils.cpp +++ b/plugins/PluginUpdater/src/Utils.cpp @@ -36,6 +36,7 @@ void LoadOptions() opts.bPeriodMeasure = db_get_b(NULL, MODNAME, "PeriodMeasure", DEFAULT_PERIODMEASURE); opts.bForceRedownload = db_get_b(NULL, MODNAME, DB_SETTING_REDOWNLOAD, 0); opts.bSilentMode = db_get_b(NULL, MODNAME, "SilentMode", 0); + opts.bBackup = db_get_b(NULL, MODNAME, "Backup", 0); } #if MIRANDA_VER >= 0x0A00 diff --git a/plugins/PluginUpdater/src/resource.h b/plugins/PluginUpdater/src/resource.h index d4461bd62a..d735fc5065 100644 --- a/plugins/PluginUpdater/src/resource.h +++ b/plugins/PluginUpdater/src/resource.h @@ -49,7 +49,7 @@ #define IDC_CUSTOM 1046 #define IDC_SILENTMODE 1047 #define IDC_NEEDRESTARTLABEL 1048 -#define IDC_DONTSWITCHTOSTABLE 1049 +#define IDC_BACKUP 1049 #define IDC_MSG_BOXES 40071 #define IDC_ERRORS 40072 #define IDC_INFO_MESSAGES 40073 diff --git a/plugins/PluginUpdater/src/stdafx.h b/plugins/PluginUpdater/src/stdafx.h index eda11fe2b8..a4376d5101 100644 --- a/plugins/PluginUpdater/src/stdafx.h +++ b/plugins/PluginUpdater/src/stdafx.h @@ -39,6 +39,7 @@ Boston, MA 02111-1307, USA. #include #include #include +#include #include @@ -85,7 +86,7 @@ typedef OBJLIST FILELIST; extern struct PlugOptions { - BYTE bUpdateOnStartup, bUpdateOnPeriod, bOnlyOnceADay, bForceRedownload, bSilentMode; + BYTE bUpdateOnStartup, bUpdateOnPeriod, bOnlyOnceADay, bForceRedownload, bSilentMode, bBackup; BOOL bSilent; BYTE bPeriodMeasure; @@ -102,12 +103,21 @@ extern struct PlugOptions #else #define DEFAULT_ONLYONCEADAY 1 #endif +#ifdef _WIN64 +#define PLATFORM "64" +#else +#define PLATFORM "32" +#endif -#define DEFAULT_UPDATE_URL "http://miranda-ng.org/distr/stable/x%platform%" -#define DEFAULT_UPDATE_URL_TRUNK "http://miranda-ng.org/distr/x%platform%" -#define DEFAULT_UPDATE_URL_TRUNK_SYMBOLS "http://miranda-ng.org/distr/pdb_x%platform%" +#define DEFAULT_UPDATE_URL "http://miranda-ng.org/distr/stable/x" PLATFORM +#define DEFAULT_UPDATE_URL_TRUNK "http://miranda-ng.org/distr/x" PLATFORM +#define DEFAULT_UPDATE_URL_TRUNK_SYMBOLS "http://miranda-ng.org/distr/pdb_x" PLATFORM #define PLUGIN_INFO_URL _T("http://miranda-ng.org/p/%s") +#define DEFAULT_UPDATE_URL_OLD "http://miranda-ng.org/distr/stable/x%platform%" +#define DEFAULT_UPDATE_URL_TRUNK_OLD "http://miranda-ng.org/distr/x%platform%" +#define DEFAULT_UPDATE_URL_TRUNK_SYMBOLS_OLD "http://miranda-ng.org/distr/pdb_x%platform%" + #define UPDATE_MODE_CUSTOM 0 #define UPDATE_MODE_STABLE 1 #define UPDATE_MODE_TRUNK 2 @@ -216,8 +226,6 @@ void InitTimer(void *type); bool unzip(const TCHAR *ptszZipFile, TCHAR *ptszDestPath, TCHAR *ptszBackPath,bool ch); void strdel(TCHAR *parBuffer, int len); -INT_PTR ParseUriService(WPARAM wParam, LPARAM lParam); - /////////////////////////////////////////////////////////////////////////////// int CalculateModuleHash(const TCHAR *tszFileName, char *dest); -- cgit v1.2.3