private static void ShowUpdate(CommandEventArgs e) { string[] args; try { args = (string[])e.Argument; } catch { return; } if (args == null || args.Length < 8) { return; } string title = args[0], header = args[1], description = args[2], url = args[3], urltext = args[4], version = args[5], newVersion = args[6], tag = args[7]; using (UpdateAvailableDialog uad = new UpdateAvailableDialog()) { try { uad.Text = string.Format(uad.Text, title); uad.headLabel.Text = header; uad.bodyLabel.Text = description; uad.linkLabel.Text = urltext; uad.linkLabel.Links.Add(0, urltext.Length).LinkData = url; if (!string.IsNullOrEmpty(version)) { uad.newVerLabel.Text = newVersion; uad.curVerLabel.Text = GetUIVersion(e.Context).ToString(3); uad.versionPanel.Enabled = uad.versionPanel.Visible = true; } if (string.IsNullOrEmpty(tag)) { uad.sameCheck.Enabled = uad.sameCheck.Visible = false; } } catch { return; // Don't throw a visible exception from a background check! } uad.ShowDialog(e.Context); if (uad.sameCheck.Checked) { IAnkhConfigurationService config = e.GetService <IAnkhConfigurationService>(); using (RegistryKey rk = config.OpenUserInstanceKey("UpdateCheck")) { rk.SetValue("SkipTag", tag); } } } }
public static void DoAutoUpdateCheck() { NewVersionCheck check = new NewVersionCheck(new CurrentVersionInfo()); check.OnErrorF = (msg) => { // ?? }; check.DoNewVersionCheck((url, force) => { UpdateAvailableDialog.Show_NoForce(CotangentUI.MainUICanvas, url, check); }); }
/// <summary> /// Checks if the current version is the newest version /// </summary> private static void CheckVersion(bool force = false) { // Don't check the version if the setting is disabled and we aren't being forced if (!force || !Settings.CheckForUpdates) { return; } try { // Query the remote Github API for newer releases var request = (HttpWebRequest)WebRequest.Create("https://api.github.com/repos/brkastner/SDownload/releases"); request.Method = WebRequestMethods.Http.Get; request.Accept = "application/vnd.github.v3+json"; request.UserAgent = "SDownload"; // Process response var response = request.GetResponse().GetResponseStream(); if (response == null) { throw new HandledException("There was an issue checking for updates!"); } var contract = new DataContractJsonSerializer(typeof(GithubReleaseItemContract[])).ReadObject(response) as GithubReleaseItemContract[]; if (contract == null) { throw new HandledException("Could not deserialize the version update information!", true); } var currentVersion = new int[3]; var i = 0; foreach (var num in (Application.ProductVersion).Split('.')) { currentVersion[i++] = Int32.Parse(num); } // Combine any new releases to get the changelog from each var newerReleases = (from release in contract let versionNumbers = (release.TagName.Remove(0, 1)).Split('.') where ((Int32.Parse(versionNumbers[0]) > currentVersion[0]) || // Major (Int32.Parse(versionNumbers[0]) == currentVersion[0] && // Minor Int32.Parse(versionNumbers[1]) > currentVersion[1]) || (Int32.Parse(versionNumbers[0]) == currentVersion[0] && // Incremental Int32.Parse(versionNumbers[1]) == currentVersion[1] && Int32.Parse(versionNumbers[2]) > currentVersion[2])) && !release.Draft // Ignore drafts select release).ToList(); // Remove beta updates if the option is disabled if (!Settings.EnableBetaUpdates) { newerReleases = (from release in newerReleases where !release.PreRelease select release).ToList(); } if (newerReleases.Count < 1) { return; } // Current version is not up to date, prompt the user to download the new version UpdateAvailableDialog.Prompt(newerReleases[0].Assets[0].Url, newerReleases); } catch (WebException e) { CrashHandler.Throw("Unable to make a connection to the SDownload API to check for updates!", e); } }