private static void AutoUpdater_UpdateReady(object sender, UpdateReadyEventArgs e) { logger.Info($"New update is ready to be installed ({e.Version})"); MessageBoxResult choice = MessageBoxResult.Yes; App.CallInSTAThread(() => { choice = CustomMessageBox.ShowYesNoCancel( "A new update is ready to be installed!", $"Toastify {e.Version}", "Install", // Yes "Open folder", // No "Go to GitHub", // Cancel MessageBoxImage.Information); }, true); logger.Info($"Use choice = {(choice == MessageBoxResult.Cancel ? "Go to GitHub" : choice == MessageBoxResult.No ? "Open folder" : "Install")}"); try { if (choice == MessageBoxResult.Cancel) { ProcessStartInfo psi = new ProcessStartInfo(e.GitHubReleaseUrl) { UseShellExecute = true }; Process.Start(psi); } else if (choice == MessageBoxResult.No) { FileInfo fileInfo = new FileInfo(e.InstallerPath); ProcessStartInfo psi = new ProcessStartInfo(fileInfo.Directory?.FullName) { UseShellExecute = true, Verb = "open" }; Process.Start(psi); } else { ProcessStartInfo psi = new ProcessStartInfo(e.InstallerPath) { UseShellExecute = true, Verb = "runas" }; Process.Start(psi); App.Terminate(); } } catch (Exception ex) { logger.Error($"Unknown error in {nameof(AutoUpdater_UpdateReady)}", ex); } }
void UpdateReady(object sender, UpdateReadyEventArgs e) { if (e.IsRequired) //important update, do the restart asap { _UpdateService.Restart(); } Execute.OnUIThread(() => _WindowManager.ShowDialog( TinyIoCContainer.Current.Resolve <UpdateReadyViewModel>( new NamedParameterOverloads(new Dictionary <string, object> { { "newVersion", e.NewVersion }, { "changelog", e.Changelog } })))); }
private async void VersionChecker_CheckVersionComplete(object sender, CheckVersionCompleteEventArgs e) { if (!ShouldDownload(Settings.Current.UpdateDeliveryMode) || !e.IsNew) { return; } if (string.IsNullOrWhiteSpace(e.GitHubReleaseDownloadUrl)) { this.AutoUpdateFailed?.Invoke(this, e); } else { using (WebClient webClient = new WebClient()) { webClient.Proxy = App.ProxyConfig.CreateWebProxy(); try { if (Directory.Exists(UpdateDownloadPath)) { Directory.Delete(UpdateDownloadPath, true); } Directory.CreateDirectory(UpdateDownloadPath); string filePath = Path.Combine(UpdateDownloadPath, "ToastifyInstaller.exe"); await webClient.DownloadFileTaskAsync(e.GitHubReleaseDownloadUrl, filePath).ConfigureAwait(false); if (File.Exists(filePath)) { UpdateReadyEventArgs updateReadyEventArgs = new UpdateReadyEventArgs { Version = e.Version, InstallerPath = filePath, GitHubReleaseUrl = e.GitHubReleaseUrl }; this.UpdateReady?.Invoke(this, updateReadyEventArgs); } else { this.AutoUpdateFailed?.Invoke(this, e); } } catch (Exception ex) { logger.Error("Unknown error while downloading new update.", ex); this.AutoUpdateFailed?.Invoke(this, e); } } } }