private async void StartUpdateCheck() { cancellationTokenSource = new CancellationTokenSource(); updateTimeoutTimer.Start(); TimeoutUpDown.IsEnabled = false; checkInProgress = true; int updateTimeOut = (int)TimeoutUpDown.Value; timeoutCountdown = updateTimeOut; try { string currentVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); bool updateAvailable = await GithubReleaseParser.GetUpdateAvailableAsync(currentVersion, "AWilliams17", "Halo-CE-Mouse-Tool", updateTimeOut, cancellationTokenSource.Token); ShowUpdateAvailableDialog(updateAvailable); } catch (WebException ex) { System.Media.SystemSounds.Hand.Play(); MessageBox.Show($"Update Check Failed: '{ex.Message}'", "Update Check Failed"); } finally { StopUpdateCheck(); } }
private async void Update() { try { bool updateAvailable = false; DispatcherTimer.Tick += DispatcherTimer_Tick; DispatcherTimer.Interval = new TimeSpan(0, 0, 1); DispatcherTimer.Start(); updateAvailable = await GithubReleaseParser.GetUpdateAvailableAsync("AWilliams17", "Starbound-Asset-Ripper", 5, cancellationTokenSource.Token); DispatcherTimer.Stop(); if (updateAvailable) { string updateAvailableMessage = "An update is available. Would you like to go to the download page?"; var userAction = MessageBox.Show(updateAvailableMessage, "Update Available", MessageBoxButton.YesNo); if (userAction == MessageBoxResult.Yes) { Process.Start("https://github.com/AWilliams17/Starbound-Asset-Ripper/releases"); } } else { MessageBox.Show("No updates found.", "No updates available."); } } catch (WebException ex) { DispatcherTimer.Stop(); // So that when an error message comes up the timer still isn't ticking. if (ex.Status == WebExceptionStatus.Timeout) { MessageBox.Show("Check Timed Out after 5 seconds", "Check Timed Out"); } else { MessageBox.Show($"Error occurred while checking for updates: {ex.Message}", "Error checking for updates"); } } Close(); }