public static async Task CheckForNewVersion(bool isStartup, bool forceUpdate = false) { Settings settings = SettingsPersister.Retrieve(); if (forceUpdate) { settings.UpdateInfo = null; } if (CheckForUpdates(settings)) { settings.UpdateInfo.LastCheckedForUpdates = DateTime.Now; HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Add("User-Agent", "KML2SQL.Updater"); HttpResponseMessage response = await client.GetAsync(apiUrl); if (response.IsSuccessStatusCode) { SemVersion latestVersion = await GetLatestVersion(response); SemVersion thisVersion = SemVersion.Parse(GetCurrentVersion()); if (latestVersion > thisVersion && ShouldNag(settings, latestVersion)) { settings.UpdateInfo.LastTimeNagged = DateTime.Now; MessageBoxResult mbResult = MessageBox.Show( "A new version is availbe. Press 'Yes' to go to the download page, Cancel to skip, or 'No' to not be reminded unless an even newer version comes out.", "New Version Available!", MessageBoxButton.YesNoCancel); if (mbResult == MessageBoxResult.Yes) { Process.Start(downloadUrl); } if (mbResult == MessageBoxResult.No) { settings.UpdateInfo.DontNag = true; } } else if (!isStartup) { MessageBox.Show("Your app is fully updated", "No updates found", MessageBoxButton.OK, MessageBoxImage.Information); } } SettingsPersister.Persist(settings); } else if (!isStartup) { MessageBox.Show("Your app is fully updated", "No updates found", MessageBoxButton.OK, MessageBoxImage.Information); } }
public static async Task CheckForNewVersion() { var settings = SettingsPersister.Retrieve(); if (CheckForUpdates(settings)) { settings.UpdateInfo.LastCheckedForUpdates = DateTime.Now; var client = new HttpClient(); //client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/vnd.github.v3+json")); client.DefaultRequestHeaders.Add("User-Agent", "Pharylon"); var response = await client.GetAsync(apiUrl); if (response.IsSuccessStatusCode) { var latestVersion = await GetLatestVersion(response); var thisVersion = SemVersion.Parse(GetCurrentVersion()); if (latestVersion > thisVersion && ShouldNag(settings, latestVersion)) { settings.UpdateInfo.LastTimeNagged = DateTime.Now; var mbResult = MessageBox.Show( "A new version is availbe. Press 'Yes' to go to the download page, Cancel to skip, or 'No' to not be reminded unless an even newer version comes out.", "New Version Available!", MessageBoxButton.YesNoCancel); if (mbResult == MessageBoxResult.Yes) { Process.Start(downloadUrl); } if (mbResult == MessageBoxResult.No) { settings.UpdateInfo.DontNag = true; } } } SettingsPersister.Persist(settings); } }