protected virtual void update_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { result = (UpdateAvailability)e.Result; if (result == UpdateAvailability.None) { UpdateButton.IsEnabled = true; UpdateButton.Visibility = System.Windows.Visibility.Visible; UpdateAvailableButton.IsEnabled = false; UpdateAvailableButton.Visibility = System.Windows.Visibility.Collapsed; } else { UpdateButton.IsEnabled = false; UpdateButton.Visibility = System.Windows.Visibility.Collapsed; UpdateAvailableButton.IsEnabled = true; UpdateAvailableButton.Visibility = System.Windows.Visibility.Visible; } switch (result) { case UpdateAvailability.Data: TranslationHelpers.translate(UpdateAvailableButton, "DataUpdateAvailable"); if (this.Visibility != System.Windows.Visibility.Visible) notifier.sendBalloon(Strings.GetMessageString("DataUpdateAvailable")); break; case UpdateAvailability.DataAndProgram: case UpdateAvailability.Program: TranslationHelpers.translate(UpdateAvailableButton, "ProgramUpdateAvailable"); if (this.Visibility != System.Windows.Visibility.Visible) notifier.sendBalloon(Strings.GetMessageString("ProgramUpdateAvailable")); break; } TranslationHelpers.translate(UpdateButton, "CheckForUpdates"); }
private void UpdateShimIfNecessary(UpdateAvailability shimUpdateAvailability) { if (string.IsNullOrEmpty(shimUpdateAvailability.Version)) { return; } var updateShimPath = Path.Combine(executingAssemblyPath, "MusketeerUpdateShim.exe"); var shimVersion = File.Exists(updateShimPath) ? AssemblyName.GetAssemblyName(updateShimPath).Version : new Version("0.0.0.0"); var updateVersion = new Version(shimUpdateAvailability.Version); if (updateVersion.CompareTo(shimVersion) <= 0) { return; } logger.Info("New version of the MusketeerUpdateShim found: '{0}'. Starting update.", updateVersion); var downloadFilePath = Path.Combine(executingAssemblyPath, "updateshim.zip"); castleConnector.DownloadFile(shimUpdateAvailability.FullUrlToUpdate, downloadFilePath); if (IsFileUnaltered(downloadFilePath, shimUpdateAvailability.FileHash)) { FileUtils.ExtractZipToDirectoryAndOverrideExistingFiles(downloadFilePath, executingAssemblyPath); logger.Info("Shim update to version '{0}' finished.", updateVersion); } else { logger.Warn("Shim update failed. The checksum of the file did not match the original."); } File.Delete(downloadFilePath); }
private void UpdateMusketeerIfNecessary(UpdateAvailability updateAvailability) { if (string.IsNullOrEmpty(updateAvailability.Version)) { return; } var currentVersion = Assembly.GetExecutingAssembly().GetName().Version; var updateVersion = new Version(updateAvailability.Version); if (updateVersion.CompareTo(currentVersion) <= 0) { return; } var downloadFilePath = Path.Combine(executingAssemblyPath, "update.zip"); if (File.Exists(downloadFilePath)) { logger.Error("The update file exists - this indicates that the previous update was unsuccessful and " + "we won't try again. Please check the update.log and remove the update.zip file when the problem " + "is fixed."); return; } logger.Info("New version of the Musketeer service found: '{0}'. Starting update procedure.", updateVersion); castleConnector.DownloadFile(updateAvailability.FullUrlToUpdate, downloadFilePath); if (!IsFileUnaltered(downloadFilePath, updateAvailability.FileHash)) { logger.Warn("The downloaded file checksum did not match the original - update aborted. We will try again later."); File.Delete(downloadFilePath); return; } var currentProcess = Process.GetCurrentProcess(); var shimPath = Path.Combine(executingAssemblyPath, "MusketeerUpdateShim.exe"); Process shimProcess; if (currentProcess.SessionId == 0) { shimProcess = Process.Start(shimPath, string.Format("--pid {0} --update \"{1}\" --startsvc \"{2}\"", currentProcess.Id, downloadFilePath, MusketeerService.ServiceName)); logger.Info("Update process was started with PID: {0}. The Musketeer service is stopping now.", shimProcess.Id); new ServiceController(MusketeerService.ServiceName).Stop(); } else { shimProcess = Process.Start(shimPath, string.Format("--pid {0} --update \"{1}\" --startapp \"{2}\"", currentProcess.Id, downloadFilePath, Assembly.GetEntryAssembly().Location)); logger.Info("Update process was started with PID: {0}. The update will start after Musketeer is closed.", shimProcess.Id); } }
private UpdateAvailability FindUpdate(string updatePrefix) { var update = new UpdateAvailability(); var updatesBaseUrl = string.Format("{0}{1}/content/updates/", Request.Url.SiteBase, Request.Url.BasePath); var updatesFolder = Path.Combine(pathProvider.GetRootPath(), "Content", "updates"); if (Directory.Exists(updatesFolder)) { var updateFilePath = Directory.GetFiles(updatesFolder, updatePrefix + "*.zip").OrderByDescending( f => f).FirstOrDefault(); if (updateFilePath != null) { update.Version = Path.GetFileNameWithoutExtension(updateFilePath).Remove(0, updatePrefix.Length); update.FileHash = CalculateFileHash(updateFilePath); update.FullUrlToUpdate = updatesBaseUrl + Path.GetFileName(updateFilePath); } } return(update); }
protected virtual void update_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { result = (UpdateAvailability)e.Result; if (result == UpdateAvailability.None) { UpdateButton.IsEnabled = true; UpdateButton.Visibility = System.Windows.Visibility.Visible; UpdateAvailableButton.IsEnabled = false; UpdateAvailableButton.Visibility = System.Windows.Visibility.Collapsed; } else { UpdateButton.IsEnabled = false; UpdateButton.Visibility = System.Windows.Visibility.Collapsed; UpdateAvailableButton.IsEnabled = true; UpdateAvailableButton.Visibility = System.Windows.Visibility.Visible; } switch (result) { case UpdateAvailability.Data: TranslationHelpers.translate(UpdateAvailableButton, "DataUpdateAvailable"); if (this.Visibility != System.Windows.Visibility.Visible) { notifier.sendBalloon(Strings.GetMessageString("DataUpdateAvailable")); } break; case UpdateAvailability.DataAndProgram: case UpdateAvailability.Program: TranslationHelpers.translate(UpdateAvailableButton, "ProgramUpdateAvailable"); if (this.Visibility != System.Windows.Visibility.Visible) { notifier.sendBalloon(Strings.GetMessageString("ProgramUpdateAvailable")); } break; } TranslationHelpers.translate(UpdateButton, "CheckForUpdates"); }
public async Task HandleUpdateCheckAsync(bool isStartupCheck = true) { UpdateAvailability updateAvailability = await CheckUpdateAvailabilityAsync(); switch (updateAvailability) { case UpdateAvailability.IsInsiderVersion: if (isStartupCheck) { NotificationManager.ShowNotification("Snap Desktop", $"{Environment.UserName}:\n你正在使用开发版 Snap Desktop"); } else { NotificationManager.ShowNotification("Snap Desktop", "开发版 Snap Desktop ,不需要更新"); } break; case UpdateAvailability.IsNewestRelease: if (isStartupCheck) { NotificationManager.ShowNotification("Snap Desktop", $"欢迎{Environment.UserName}"); } else { NotificationManager.ShowNotification("Snap Desktop", "不需要更新,这是 Snap Desktop 的最新发行版"); } break; case UpdateAvailability.NeedUpdate: NotificationManager.ShowNotification("Snap Desktop", $"发现可用的更新,版本号:{NewVersion},单击此通知以下载...", () => { DownloadAndInstallPackage(); }); break; case UpdateAvailability.NotAvailable: NotificationManager.ShowNotification("Snap Desktop", "检查更新失败...\n ·你的设备可能需要联网"); break; } }