/// <summary> /// Initializes this instance. /// </summary> private void Initialize() { if (AppUpdater.IsUpdatePackageAvailable()) { ActionButtonText = "Install update!"; } else if (AppUpdater.IsUpdateAvailable) { ActionButtonText = "Update!"; } else { ActionButtonText = "Check now!"; } }
/// <summary> /// Initializes all related to the Update service /// </summary> private void InitializeUpdateService() { AppUpdater.DownloadProgressChanged += AppUpdaterOnDownloadProgressChanged; AppUpdater.DownloadCompleted += AppUpdaterOnDownloadCompleted; // Handle New version found AppUpdater.CheckVersionsCompleted += async(sender, args) => { if (args.AskToDownloadHandled || (!args.AskToDownloadHandled && args.TargetSubscriberType != typeof(UpdateMenuViewModel))) { return; } // TODO: refactor this, it's f*****g messy if (args.HasNewVersionAvailable) { // 0 = Ask to download and install // 1 = Ask to install // 2 = Auto download and install if (UpdateModeIndex == 0) { // Independt ifs since the user might refuse to download if (!AppUpdater.IsUpdatePackageAvailable() && MessageBox.Show("There's a new version available. Would you like to download it?", "Update available", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { IsUpdating = true; await AppUpdater.DownloadLatestVersion(); } if ( MessageBox.Show("Would you like to install the update?", "Update available", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { AppUpdater.InstallLatestVersion(); } } else // No need to check since the possible values are 0 to 2 { IsUpdating = true; await AppUpdater.DownloadLatestVersion(); if (UpdateModeIndex == 1) { if ( MessageBox.Show("Would you like to install the update?", "Update available", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { AppUpdater.InstallLatestVersion(); } } else { await AppUpdater.DownloadLatestVersion(); AutoClosingMessageBox.Show("The update will be installed in 3 seconds...", "Closing in 3 seconds!", 3000); AppUpdater.InstallLatestVersion(); } } } else { MessageBox.Show("The latest version is already installed!", "No update available", MessageBoxButton.OK, MessageBoxImage.Information); } IsUpdating = false; args.AskToDownloadHandled = true; }; }