static void ApplyDownloads(void *param) { HWND hDlg = (HWND)param; ////////////////////////////////////////////////////////////////////////////////////// // if we need to escalate priviledges, launch a atub if (!PrepareEscalation()) { PostMessage(hDlg, WM_CLOSE, 0, 0); return; } ////////////////////////////////////////////////////////////////////////////////////// // ok, let's unpack all zips AutoHandle pipe(hPipe); HWND hwndList = GetDlgItem(hDlg, IDC_LIST_UPDATES); OBJLIST<FILEINFO> &todo = *(OBJLIST<FILEINFO> *)GetWindowLongPtr(hDlg, GWLP_USERDATA); //create needed folders after escalating priviledges. Folders creates when we actually install updates TCHAR tszFileTemp[MAX_PATH], tszFileBack[MAX_PATH]; mir_sntprintf(tszFileBack, _countof(tszFileBack), _T("%s\\Backups"), tszRoot); SafeCreateDirectory(tszFileBack); mir_sntprintf(tszFileTemp, _countof(tszFileTemp), _T("%s\\Temp"), tszRoot); SafeCreateDirectory(tszFileTemp); VARST tszMirandaPath(_T("%miranda_path%")); HANDLE nlc = NULL; for (int i=0; i < todo.getCount(); ++i) { ListView_EnsureVisible(hwndList, i, FALSE); if (todo[i].bEnabled) { // download update ListView_SetItemText(hwndList, i, 1, TranslateT("Downloading...")); if (DownloadFile(&todo[i].File, nlc)) { ListView_SetItemText(hwndList, i, 1, TranslateT("Succeeded.")); if (unzip(todo[i].File.tszDiskPath, tszMirandaPath, tszFileBack,false)) SafeDeleteFile(todo[i].File.tszDiskPath); // remove .zip after successful update } else ListView_SetItemText(hwndList, i, 1, TranslateT("Failed!")); } else ListView_SetItemText(hwndList, i, 1, TranslateT("Skipped.")); } Netlib_CloseHandle(nlc); ShowPopup(TranslateT("Plugin Updater"), TranslateT("Download complete"), POPUP_TYPE_INFO); int rc = MessageBox(hDlg, TranslateT("Download complete. Do you want to go to plugins option page?"), TranslateT("Plugin Updater"), MB_YESNO | MB_ICONQUESTION); if (rc == IDYES) CallFunctionAsync(OpenPluginOptions, 0); PostMessage(hDlg, WM_CLOSE, 0, 0); }
static void ApplyUpdates(void *param) { HWND hDlg = (HWND)param; OBJLIST<FILEINFO> &todo = *(OBJLIST<FILEINFO> *)GetWindowLongPtr(hDlg, GWLP_USERDATA); if (todo.getCount() == 0) { return; } // 1) If we need to escalate priviledges, launch a stub if (!PrepareEscalation()) { PostMessage(hDlg, WM_CLOSE, 0, 0); return; } AutoHandle pipe(hPipe); HWND hwndList = GetDlgItem(hDlg, IDC_LIST_UPDATES); //create needed folders after escalating priviledges. Folders creates when we actually install updates 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); // 2) Download all plugins HANDLE nlc = NULL; for (int i=0; i < todo.getCount(); i++) { ListView_EnsureVisible(hwndList, i, FALSE); if (!todo[i].bEnabled) { SetStringText(hwndList, i, TranslateT("Skipped.")); } else if (todo[i].bDeleteOnly) { SetStringText(hwndList, i, TranslateT("Will be deleted!")); } else { // download update SetStringText(hwndList, i, TranslateT("Downloading...")); FILEURL *pFileUrl = &todo[i].File; if (!DownloadFile(pFileUrl, nlc)) { SetStringText(hwndList, i, TranslateT("Failed!")); // interrupt update as we require all components to be updated Netlib_CloseHandle(nlc); PostMessage(hDlg, UM_ERROR, 0, 0); SkinPlaySound("updatefailed"); return; } SetStringText(hwndList, i, TranslateT("Succeeded.")); } } Netlib_CloseHandle(nlc); // 3) Unpack all zips VARST tszMirandaPath(_T("%miranda_path%")); for (int i = 0; i < todo.getCount(); i++) { FILEINFO& p = todo[i]; if (p.bEnabled) { if (p.bDeleteOnly) { // we need only to backup the old file TCHAR *ptszRelPath = p.tszNewName + _tcslen(tszMirandaPath) + 1, tszBackFile[MAX_PATH]; mir_sntprintf(tszBackFile, SIZEOF(tszBackFile), _T("%s\\%s"), tszFileBack, ptszRelPath); BackupFile(p.tszNewName, tszBackFile); } else { // 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], tszBackFile[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 } } } SkinPlaySound("updatecompleted"); #if MIRANDA_VER < 0x0A00 // 4) Change title of clist 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, DB_SETTING_REDOWNLOAD); 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); #else CallFunctionAsync(RestartMe, 0); #endif }
static void DlgUpdateSilent(void *lParam) { OBJLIST<FILEINFO> &UpdateFiles = *(OBJLIST<FILEINFO> *)lParam; if (UpdateFiles.getCount() == 0) { delete &UpdateFiles; return; } // 1) If we need to escalate priviledges, launch a stub if (!PrepareEscalation()) { delete &UpdateFiles; return; } AutoHandle pipe(hPipe); //create needed folders after escalating priviledges. Folders creates when we actually install updates 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); // 2) Download all plugins HANDLE nlc = NULL; // Count all updates that have been enabled int count = 0; for (int i = 0; i < UpdateFiles.getCount(); i++) { if (UpdateFiles[i].bEnabled && !UpdateFiles[i].bDeleteOnly) { // download update FILEURL *pFileUrl = &UpdateFiles[i].File; if (!DownloadFile(pFileUrl, nlc)) { // interrupt update as we require all components to be updated Netlib_CloseHandle(nlc); SkinPlaySound("updatefailed"); delete &UpdateFiles; return; } count++; } } Netlib_CloseHandle(nlc); // All available updates have been disabled if (count == 0) { delete &UpdateFiles; return; } // 3) Unpack all zips VARST tszMirandaPath(_T("%miranda_path%")); for (int i = 0; i < UpdateFiles.getCount(); i++) { FILEINFO& p = UpdateFiles[i]; if (p.bEnabled) { if (p.bDeleteOnly) { // we need only to backup the old file TCHAR *ptszRelPath = p.tszNewName + _tcslen(tszMirandaPath) + 1, tszBackFile[MAX_PATH]; mir_sntprintf(tszBackFile, SIZEOF(tszBackFile), _T("%s\\%s"), tszFileBack, ptszRelPath); BackupFile(p.tszNewName, tszBackFile); } else { // 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], tszBackFile[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); } // remove .zip after successful update if (unzip(p.File.tszDiskPath, tszMirandaPath, tszFileBack, true)) SafeDeleteFile(p.File.tszDiskPath); } } } delete &UpdateFiles; SkinPlaySound("updatecompleted"); #if MIRANDA_VER < 0x0A00 // 4) Change title of clist 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, DB_SETTING_REDOWNLOAD); 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]; mir_sntprintf(tszTitle, SIZEOF(tszTitle), TranslateT("%d component(s) was updated"), count); if (ServiceExists(MS_POPUP_ADDPOPUPT) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1)) { ShowPopup(tszTitle,TranslateT("You need to restart your Miranda to apply installed updates."),POPUP_TYPE_MSG); } else { bool notified = false; if (ServiceExists(MS_CLIST_SYSTRAY_NOTIFY)) { MIRANDASYSTRAYNOTIFY err; err.szProto = MODULEA; err.cbSize = sizeof(err); err.dwInfoFlags = NIIF_INTERN_UNICODE | NIIF_INFO; err.tszInfoTitle = tszTitle; err.tszInfo = TranslateT("You need to restart your Miranda to apply installed updates."); err.uTimeout = 30000; notified = !CallService(MS_CLIST_SYSTRAY_NOTIFY, 0, (LPARAM)&err); } if (!notified) { // Error, let's try to show MessageBox as last way to inform user about successful update TCHAR tszText[200]; mir_sntprintf(tszText, SIZEOF(tszText), _T("%s\n\n%s"), TranslateT("You need to restart your Miranda to apply installed updates."), TranslateT("Would you like to restart it now?")); 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); #else CallFunctionAsync(RestartMe, 0); #endif } } }
static void ApplyDownloads(void *param) { HWND hDlg = (HWND)param; ////////////////////////////////////////////////////////////////////////////////////// // if we need to escalate priviledges, launch a atub if (!PrepareEscalation()) { DestroyWindow(hDlg); return; } ////////////////////////////////////////////////////////////////////////////////////// // ok, let's unpack all zips AutoHandle pipe(hPipe); HWND hwndList = GetDlgItem(hDlg, IDC_LIST_UPDATES); OBJLIST<FILEINFO> &todo = *(OBJLIST<FILEINFO> *)GetWindowLongPtr(hDlg, GWLP_USERDATA); TCHAR tszBuff[2048], 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); HANDLE nlc = NULL; for (int i=0; i < todo.getCount(); ++i) { ListView_EnsureVisible(hwndList, i, FALSE); if (!todo[i].bEnabled) { ListView_SetItemText(hwndList, i, 2, TranslateT("Skipped.")); continue; } // download update ListView_SetItemText(hwndList, i, 2, TranslateT("Downloading...")); FILEURL *pFileUrl = &todo[i].File; if (!DownloadFile(pFileUrl->tszDownloadURL, pFileUrl->tszDiskPath, pFileUrl->CRCsum, nlc)) { ListView_SetItemText(hwndList, i, 2, TranslateT("Failed!")); } else ListView_SetItemText(hwndList, i, 2, TranslateT("Succeeded.")); } Netlib_CloseHandle(nlc); if (todo.getCount() > 0) { ShowPopup(0, LPGENT("Plugin Updater"), TranslateT("Download complete"), 2, 0); TCHAR *tszMirandaPath = Utils_ReplaceVarsT(_T("%miranda_path%")); for (int i = 0; i < todo.getCount(); i++) { if (!todo[i].bEnabled) continue; TCHAR tszBackFile[MAX_PATH]; FILEINFO& p = todo[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,false)) SafeDeleteFile(p.File.tszDiskPath); // remove .zip after successful update } } PopupDataText temp; temp.Title = TranslateT("Plugin Updater"); temp.Text = tszBuff; lstrcpyn(tszBuff, TranslateT("Download complete. Do you want to go to plugins option page?"), SIZEOF(tszBuff)); int rc = MessageBox(hDlg, temp.Text, temp.Title, MB_YESNO | MB_ICONQUESTION); if (rc == IDYES) CallFunctionAsync(OpenPluginOptions, 0); CloseWindow(hDlg); DestroyWindow(hDlg); hwndDialog = NULL; return; }