async void NewVersionFound(string newVersion) { YesNo needsUpdate = YesNo.No; var newVersionFoundDialog = new NewVersionFoundDialog(newVersion); await parentView.dialogHostMain.ShowDialog(newVersionFoundDialog, null, (object s, DialogClosingEventArgs args) => { needsUpdate = (YesNo)args.Parameter; }); if (needsUpdate == YesNo.No) { return; } // Download and decompress bool result = false; var processingDialog = new ProcessingDialog(Properties.Resources.MsgBox_Downloading_Title, Properties.Resources.MsgBox_Downloading_Message); await parentView.dialogHostMain.ShowDialog(processingDialog, async (object s, DialogOpenedEventArgs args) => { result = await vm.PrepareForUpdate(); args.Session.Close(false); }); if (result) { parentView.Close(); } }
public bool ShowUiAndAskForUpdateDownload(Form owner, string applicationName, string appPath, UpdateType updateType) { using (NewVersionFoundDialog dlg = new NewVersionFoundDialog(owner, updateDefinition, this.CurrentVersion, tmpPath, applicationName, updateType)) { if (dlg.ShowDialog() != DialogResult.Yes) { return(false); } } using (DownloadFileProgressDialog dlg = new DownloadFileProgressDialog(owner)) { string urlWithUpdate; switch (updateType) { case UpdateType.MSI: urlWithUpdate = updateDefinition.LatestVersion.UrlWithMsiUpdate; break; case UpdateType.Portable: urlWithUpdate = updateDefinition.LatestVersion.UrlWithPortableUpdate; break; default: throw new InvalidOperationException(String.Format("Update type: {0} is not supported.", updateType)); } string localFileName = Path.Combine(tmpPath, Path.GetFileName(urlWithUpdate)); if (File.Exists(localFileName)) { File.Delete(localFileName); } if (dlg.DownloadFile(urlWithUpdate, localFileName)) { switch (updateType) { case UpdateType.MSI: RunMsiInstaller(localFileName); break; case UpdateType.Portable: UpdatePortable(localFileName, appPath); break; default: throw new NotImplementedException("Update type: " + updateType + " is not supported."); } return(true); } else { return(false); } } }