From 7386d8f92c231b228592b0357f9fe4a5ea1f0694 Mon Sep 17 00:00:00 2001 From: Kirill Volinsky Date: Mon, 26 May 2014 10:54:10 +0000 Subject: added silent mode for update git-svn-id: http://svn.miranda-ng.org/main/trunk@9313 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/PluginUpdater/src/Common.h | 2 +- plugins/PluginUpdater/src/DlgUpdate.cpp | 99 ++++++++++++++++++++++++++++- plugins/PluginUpdater/src/Options.cpp | 6 ++ plugins/PluginUpdater/src/PluginUpdater.cpp | 3 + plugins/PluginUpdater/src/Utils.cpp | 9 +-- plugins/PluginUpdater/src/resource.h | 4 +- 6 files changed, 116 insertions(+), 7 deletions(-) (limited to 'plugins/PluginUpdater/src') diff --git a/plugins/PluginUpdater/src/Common.h b/plugins/PluginUpdater/src/Common.h index 2f916f3673..add054051c 100644 --- a/plugins/PluginUpdater/src/Common.h +++ b/plugins/PluginUpdater/src/Common.h @@ -93,7 +93,7 @@ struct PopupDataText struct PlugOptions { - BYTE bUpdateOnStartup, bUpdateOnPeriod, bOnlyOnceADay, bForceRedownload; + BYTE bUpdateOnStartup, bUpdateOnPeriod, bOnlyOnceADay, bForceRedownload, bSilentMode; BOOL bSilent, bDlgDld; BYTE bPeriodMeasure; diff --git a/plugins/PluginUpdater/src/DlgUpdate.cpp b/plugins/PluginUpdater/src/DlgUpdate.cpp index 7979403af1..d585abfdef 100644 --- a/plugins/PluginUpdater/src/DlgUpdate.cpp +++ b/plugins/PluginUpdater/src/DlgUpdate.cpp @@ -169,6 +169,7 @@ static INT_PTR CALLBACK DlgUpdate(HWND hDlg, UINT message, WPARAM wParam, LPARAM TranslateDialogDefault(hDlg); SendMessage(hwndList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES); SendMessage(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)Skin_GetIcon("check_update")); + SendMessage(hDlg, WM_SETICON, ICON_BIG, (LPARAM)Skin_GetIcon("check_update", 1)); { OSVERSIONINFO osver = { sizeof(osver) }; if (GetVersionEx(&osver) && osver.dwMajorVersion >= 6) @@ -333,9 +334,105 @@ static INT_PTR CALLBACK DlgUpdate(HWND hDlg, UINT message, WPARAM wParam, LPARAM return FALSE; } +static void DlgUpdateSilent(void *lParam) +{ + OBJLIST &UpdateFiles = *(OBJLIST *)lParam; + + ////////////////////////////////////////////////////////////////////////////////////// + // if we need to escalate priviledges, launch a atub + + if (!PrepareEscalation()) { + return; + } + + ////////////////////////////////////////////////////////////////////////////////////// + // ok, let's unpack all zips + + AutoHandle pipe(hPipe); + TCHAR tszFileTemp[MAX_PATH], tszFileBack[MAX_PATH]; + + mir_sntprintf(tszFileBack, SIZEOF(tszFileBack), _T("%s\\Backups"), tszRoot); + SafeCreateDirectory(tszFileBack); + + mir_sntprintf(tszFileTemp, SIZEOF(tszFileTemp), _T("%s\\Temp"), tszRoot); + SafeCreateDirectory(tszFileTemp); + + bool error = false; + HANDLE nlc = NULL; + for (int i = 0; i < UpdateFiles.getCount(); i++) { + if (!db_get_b(NULL, MODNAME "Files", StrToLower(_T2A(UpdateFiles[i].tszOldName)), true)) { + continue; + } + if (UpdateFiles[i].bDeleteOnly) { + continue; + } + + // download update + FILEURL *pFileUrl = &UpdateFiles[i].File; + if (!DownloadFile(pFileUrl->tszDownloadURL, pFileUrl->tszDiskPath, pFileUrl->CRCsum, nlc)) { + // interrupt update as we require all components to be updated + error = true; + break; + } + } + Netlib_CloseHandle(nlc); + + if (error) { + return; + } + if (UpdateFiles.getCount() > 0) { + TCHAR *tszMirandaPath = Utils_ReplaceVarsT(_T("%miranda_path%")); + + for (int i = 0; i < UpdateFiles.getCount(); i++) { + if (!db_get_b(NULL, MODNAME "Files", StrToLower(_T2A(UpdateFiles[i].tszOldName)), true)) + continue; + + TCHAR tszBackFile[MAX_PATH]; + FILEINFO& p = UpdateFiles[i]; + if (p.bDeleteOnly) { // we need only to backup the old file + TCHAR *ptszRelPath = p.tszNewName + _tcslen(tszMirandaPath) + 1; + mir_sntprintf(tszBackFile, SIZEOF(tszBackFile), _T("%s\\%s"), tszFileBack, ptszRelPath); + BackupFile(p.tszNewName, tszBackFile); + continue; + } + + // if file name differs, we also need to backup the old file here + // otherwise it would be replaced by unzip + if (_tcsicmp(p.tszOldName, p.tszNewName)) { + TCHAR tszSrcPath[MAX_PATH]; + mir_sntprintf(tszSrcPath, SIZEOF(tszSrcPath), _T("%s\\%s"), tszMirandaPath, p.tszOldName); + mir_sntprintf(tszBackFile, SIZEOF(tszBackFile), _T("%s\\%s"), tszFileBack, p.tszOldName); + BackupFile(tszSrcPath, tszBackFile); + } + + if (unzip(p.File.tszDiskPath, tszMirandaPath, tszFileBack, true)) + SafeDeleteFile(p.File.tszDiskPath); // remove .zip after successful update + } + + // Change title of clist +#if MIRANDA_VER < 0x0A00 + ptrT title = db_get_tsa(NULL, "CList", "TitleText"); + if (!_tcsicmp(title, _T("Miranda IM"))) + db_set_ts(NULL, "CList", "TitleText", _T("Miranda NG")); +#endif + + opts.bForceRedownload = false; + db_unset(NULL, MODNAME, "ForceRedownload"); + + db_set_b(NULL, MODNAME, "RestartCount", 5); + db_set_b(NULL, MODNAME, "NeedRestart", 1); + + if (!opts.bSilent) + ShowPopup(0, LPGENT("Plugin Updater"), LPGENT("You need restart your Miranda to apply installed updates"), 2, 0, 1); + } +} + static void __stdcall LaunchDialog(void *param) { - CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_UPDATE), GetDesktopWindow(), DlgUpdate, (LPARAM)param); + if (opts.bSilentMode) + DlgUpdateSilent(param); + else + CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_UPDATE), GetDesktopWindow(), DlgUpdate, (LPARAM)param); } ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/plugins/PluginUpdater/src/Options.cpp b/plugins/PluginUpdater/src/Options.cpp index d94f247be9..10624c4ba3 100644 --- a/plugins/PluginUpdater/src/Options.cpp +++ b/plugins/PluginUpdater/src/Options.cpp @@ -46,6 +46,9 @@ INT_PTR CALLBACK UpdateNotifyOptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPA EnableWindow(GetDlgItem(hwndDlg, IDC_PERIOD), opts.bUpdateOnPeriod); 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)) + ShowWindow(GetDlgItem(hwndDlg, IDC_NEEDRESTARTLABEL), SW_SHOW); SendDlgItemMessage(hwndDlg, IDC_PERIODSPIN, UDM_SETRANGE, 0, MAKELONG(99, 1)); SendDlgItemMessage(hwndDlg, IDC_PERIODSPIN, UDM_SETPOS, 0, (LPARAM)opts.Period); @@ -85,6 +88,7 @@ INT_PTR CALLBACK UpdateNotifyOptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPA EnableWindow(GetDlgItem(hwndDlg, IDC_ONLYONCEADAY), IsDlgButtonChecked(hwndDlg, IDC_UPDATEONSTARTUP)); break; + case IDC_SILENTMODE: case IDC_ONLYONCEADAY: SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); break; @@ -135,6 +139,7 @@ INT_PTR CALLBACK UpdateNotifyOptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPA opts.bOnlyOnceADay = IsDlgButtonChecked(hwndDlg, IDC_ONLYONCEADAY); opts.bUpdateOnPeriod = IsDlgButtonChecked(hwndDlg, IDC_UPDATEONPERIOD); + opts.bSilentMode = IsDlgButtonChecked(hwndDlg, IDC_SILENTMODE); TCHAR buffer[3] = {0}; Edit_GetText(GetDlgItem(hwndDlg, IDC_PERIOD), buffer, SIZEOF(buffer)); @@ -146,6 +151,7 @@ INT_PTR CALLBACK UpdateNotifyOptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPA 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_b(NULL, MODNAME, "SilentMode", opts.bSilentMode); db_set_dw(NULL, MODNAME, "Period", opts.Period); InitTimer(1); diff --git a/plugins/PluginUpdater/src/PluginUpdater.cpp b/plugins/PluginUpdater/src/PluginUpdater.cpp index 3e90fb75eb..1cfa3f2ab9 100644 --- a/plugins/PluginUpdater/src/PluginUpdater.cpp +++ b/plugins/PluginUpdater/src/PluginUpdater.cpp @@ -89,6 +89,9 @@ extern "C" __declspec(dllexport) int Load(void) ServiceInit(); #endif + + db_set_b(NULL, MODNAME, "NeedRestart", 0); + hPluginUpdaterFolder = FoldersRegisterCustomPathT(MODULEA, LPGEN("Plugin Updater"), MIRANDA_PATHT _T("\\")DEFAULT_UPDATES_FOLDER); if (hPluginUpdaterFolder) OnFoldersChanged(0, 0); diff --git a/plugins/PluginUpdater/src/Utils.cpp b/plugins/PluginUpdater/src/Utils.cpp index 267e8ea2a6..d64f5c51b3 100644 --- a/plugins/PluginUpdater/src/Utils.cpp +++ b/plugins/PluginUpdater/src/Utils.cpp @@ -123,6 +123,7 @@ void LoadOptions() 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.bSilentMode = db_get_b(NULL, MODNAME, "SilentMode", 0); } ULONG crc32_table[256]; @@ -411,13 +412,13 @@ void InitTimer(int type) } } -void strdel(TCHAR *parBuffer, int len ) +void strdel(TCHAR *parBuffer, int len) { TCHAR* p; - for (p = parBuffer+len; *p != 0; p++) - p[ -len ] = *p; + for (p = parBuffer + len; *p != 0; p++) + p[-len] = *p; - p[ -len ] = '\0'; + p[-len] = '\0'; } #if MIRANDA_VER < 0x0A00 diff --git a/plugins/PluginUpdater/src/resource.h b/plugins/PluginUpdater/src/resource.h index 78ae34a6b9..92771780d2 100644 --- a/plugins/PluginUpdater/src/resource.h +++ b/plugins/PluginUpdater/src/resource.h @@ -48,6 +48,8 @@ #define IDC_TRUNK 1044 #define IDC_TRUNK_SYMBOLS 1045 #define IDC_CUSTOM 1046 +#define IDC_SILENTMODE 1047 +#define IDC_NEEDRESTARTLABEL 1048 #define IDC_MSG_BOXES 40071 #define IDC_ERRORS 40072 #define IDC_INFO_MESSAGES 40073 @@ -67,7 +69,7 @@ #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 117 #define _APS_NEXT_COMMAND_VALUE 40075 -#define _APS_NEXT_CONTROL_VALUE 1044 +#define _APS_NEXT_CONTROL_VALUE 1049 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif -- cgit v1.2.3