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/PluginUpdater_10.vcxproj | 1 - .../PluginUpdater/PluginUpdater_10.vcxproj.filters | 36 ++++---- plugins/PluginUpdater/PluginUpdater_12.vcxproj | 1 + .../PluginUpdater/PluginUpdater_12.vcxproj.filters | 3 + plugins/PluginUpdater/res/Menu.ico | Bin 1150 -> 5430 bytes plugins/PluginUpdater/res/Resource.rc | 19 ++-- plugins/PluginUpdater/res/info.ico | Bin 1150 -> 1150 bytes 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 +- 13 files changed, 148 insertions(+), 35 deletions(-) diff --git a/plugins/PluginUpdater/PluginUpdater_10.vcxproj b/plugins/PluginUpdater/PluginUpdater_10.vcxproj index 7a3265f76a..aacfd64146 100644 --- a/plugins/PluginUpdater/PluginUpdater_10.vcxproj +++ b/plugins/PluginUpdater/PluginUpdater_10.vcxproj @@ -205,7 +205,6 @@ - diff --git a/plugins/PluginUpdater/PluginUpdater_10.vcxproj.filters b/plugins/PluginUpdater/PluginUpdater_10.vcxproj.filters index bf536e18b4..a40a0d37b2 100644 --- a/plugins/PluginUpdater/PluginUpdater_10.vcxproj.filters +++ b/plugins/PluginUpdater/PluginUpdater_10.vcxproj.filters @@ -13,6 +13,9 @@ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav + + {794a226d-3db3-4b7e-aa4c-4d1b4d1aa76d} + @@ -72,23 +75,20 @@ - - Resource Files - - - Resource Files - - - Resource Files - - - Resource Files - - - Resource Files - - - Resource Files - + + Resource Files\Icons + + + Resource Files\Icons + + + Resource Files\Icons + + + Resource Files\Icons + + + Resource Files\Icons + \ No newline at end of file diff --git a/plugins/PluginUpdater/PluginUpdater_12.vcxproj b/plugins/PluginUpdater/PluginUpdater_12.vcxproj index e299a3626a..ba2c29aad2 100644 --- a/plugins/PluginUpdater/PluginUpdater_12.vcxproj +++ b/plugins/PluginUpdater/PluginUpdater_12.vcxproj @@ -205,6 +205,7 @@ + diff --git a/plugins/PluginUpdater/PluginUpdater_12.vcxproj.filters b/plugins/PluginUpdater/PluginUpdater_12.vcxproj.filters index 97de51ad38..a40a0d37b2 100644 --- a/plugins/PluginUpdater/PluginUpdater_12.vcxproj.filters +++ b/plugins/PluginUpdater/PluginUpdater_12.vcxproj.filters @@ -87,5 +87,8 @@ Resource Files\Icons + + Resource Files\Icons + \ No newline at end of file diff --git a/plugins/PluginUpdater/res/Menu.ico b/plugins/PluginUpdater/res/Menu.ico index 28eb3a7387..45594cc66e 100644 Binary files a/plugins/PluginUpdater/res/Menu.ico and b/plugins/PluginUpdater/res/Menu.ico differ diff --git a/plugins/PluginUpdater/res/Resource.rc b/plugins/PluginUpdater/res/Resource.rc index 626e0d32ad..d7fda4e6af 100644 --- a/plugins/PluginUpdater/res/Resource.rc +++ b/plugins/PluginUpdater/res/Resource.rc @@ -58,7 +58,7 @@ FONT 8, "MS Shell Dlg", 400, 0, 0x1 BEGIN END -IDD_OPT_UPDATENOTIFY DIALOGEX 0, 0, 261, 197 +IDD_OPT_UPDATENOTIFY DIALOGEX 0, 0, 261, 207 STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD EXSTYLE WS_EX_CONTROLPARENT FONT 8, "MS Shell Dlg", 0, 0, 0x1 @@ -66,20 +66,22 @@ BEGIN GROUPBOX "Hotkey",IDC_STATIC,2,0,253,26 CONTROL "Go to Customize -> Hotkeys to change the hotkey",IDC_LINK_HOTKEY, "Hyperlink",WS_TABSTOP,9,11,199,10 - GROUPBOX "Plugin updates options",IDC_STATIC,1,29,253,48 + GROUPBOX "Plugin updates options",IDC_STATIC,1,29,253,60 CONTROL "On startup",IDC_UPDATEONSTARTUP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,11,44,73,10 CONTROL "(but only once a day)",IDC_ONLYONCEADAY,"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,92,44,161,10 CONTROL "Every",IDC_UPDATEONPERIOD,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,11,58,52,10 EDITTEXT IDC_PERIOD,65,56,28,14,ES_AUTOHSCROLL | ES_NUMBER | WS_DISABLED CONTROL "",IDC_PERIODSPIN,"msctls_updown32",UDS_SETBUDDYINT | UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS | WS_DISABLED,92,56,10,15 COMBOBOX IDC_PERIODMEASURE,114,56,58,30,CBS_DROPDOWNLIST | CBS_SORT | WS_DISABLED | WS_VSCROLL | WS_TABSTOP - GROUPBOX "Files source",IDC_STATIC,1,80,253,96 - CONTROL "Stable version",IDC_STABLE,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,11,93,236,10 - CONTROL "Development version (less stable)",IDC_TRUNK,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,11,108,236,10 + CONTROL "Silent mode",IDC_SILENTMODE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,11,72,128,10 + GROUPBOX "Files source",IDC_STATIC,1,92,253,96 + CONTROL "Stable version",IDC_STABLE,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,11,105,236,10 + CONTROL "Development version (less stable)",IDC_TRUNK,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,11,120,236,10 CONTROL "Development version with debug symbols",IDC_TRUNK_SYMBOLS, - "Button",BS_AUTORADIOBUTTON | WS_TABSTOP,11,123,236,10 - CONTROL "Custom version",IDC_CUSTOM,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,11,138,236,10 - EDITTEXT IDC_CUSTOMURL,11,152,234,16,ES_AUTOHSCROLL + "Button",BS_AUTORADIOBUTTON | WS_TABSTOP,11,135,236,10 + CONTROL "Custom version",IDC_CUSTOM,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,11,150,236,10 + EDITTEXT IDC_CUSTOMURL,11,164,234,16,ES_AUTOHSCROLL + LTEXT "You need restart your Miranda to apply installed updates",IDC_NEEDRESTARTLABEL,10,192,222,8,NOT WS_VISIBLE END IDD_POPUP DIALOGEX 0, 0, 316, 182 @@ -183,7 +185,6 @@ BEGIN IDD_OPT_UPDATENOTIFY, DIALOG BEGIN - BOTTOMMARGIN, 196 END IDD_LIST, DIALOG diff --git a/plugins/PluginUpdater/res/info.ico b/plugins/PluginUpdater/res/info.ico index 296d8f8f3e..b4934e4e1f 100644 Binary files a/plugins/PluginUpdater/res/info.ico and b/plugins/PluginUpdater/res/info.ico differ 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