Ejemplo n.º 1
0
        public override void CheckUpdate()
        {
            UpdateInfo = new UpdateInfo { CurrentVersion = this.CurrentVersion, ReleaseChannel = ReleaseType };

            try
            {
                using (WebClient wc = new WebClient())
                {
                    wc.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
                    wc.Headers.Add("user-agent", "ShareX");
                    wc.Proxy = Proxy;

                    using (MemoryStream ms = new MemoryStream(wc.DownloadData(URL)))
                    using (XmlTextReader xml = new XmlTextReader(ms))
                    {
                        XDocument xd = XDocument.Load(xml);

                        if (xd != null)
                        {
                            string node;

                            switch (ReleaseType)
                            {
                                default:
                                case ReleaseChannelType.Stable:
                                    node = "Stable";
                                    break;
                                case ReleaseChannelType.Beta:
                                    node = "Beta|Stable";
                                    break;
                                case ReleaseChannelType.Dev:
                                    node = "Dev|Beta|Stable";
                                    break;
                            }

                            string path = string.Format("Update/{0}/{1}", ApplicationName, node);
                            XElement xe = xd.GetNode(path);

                            if (xe != null)
                            {
                                UpdateInfo.LatestVersion = new Version(xe.Element("Version").Value);
                                UpdateInfo.DownloadURL = xe.Element("URL").Value;
                                UpdateInfo.RefreshStatus();
                                return;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                DebugHelper.WriteException(e, "Update check failed");
            }

            UpdateInfo.Status = UpdateStatus.UpdateCheckFailed;
        }
Ejemplo n.º 2
0
        public override void CheckUpdate()
        {
            UpdateInfo = new UpdateInfo { CurrentVersion = this.CurrentVersion };

            try
            {
                List<GitHubRelease> releases = GetReleases();

                if (releases != null && releases.Count > 0)
                {
                    GitHubRelease latestRelease = releases[0];

                    if (latestRelease != null && !string.IsNullOrEmpty(latestRelease.tag_name) && latestRelease.tag_name.Length > 1 &&
                        latestRelease.tag_name[0] == 'v')
                    {
                        UpdateInfo.LatestVersion = new Version(latestRelease.tag_name.Substring(1));

                        if (latestRelease.assets != null && latestRelease.assets.Count > 0)
                        {
                            foreach (GitHubAsset asset in latestRelease.assets)
                            {
                                if (asset != null && !string.IsNullOrEmpty(asset.name) && asset.name.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    UpdateInfo.Filename = asset.name;
                                    UpdateInfo.DownloadURL = asset.url;
                                    UpdateInfo.RefreshStatus();
                                    return;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                DebugHelper.WriteException(e, "GitHub update check failed");
            }

            UpdateInfo.Status = UpdateStatus.UpdateCheckFailed;
        }
Ejemplo n.º 3
0
 public DownloaderForm(UpdateInfo updateInfo)
     : this(updateInfo.DownloadURL, updateInfo.Filename)
 {
 }
Ejemplo n.º 4
0
 public DownloaderForm(UpdateInfo updateInfo)
     : this(updateInfo.DownloadURL, updateInfo.Filename)
 {
 }
Ejemplo n.º 5
0
        public bool CheckUpdate()
        {
            UpdateInfo = new UpdateInfo(ReleaseChannel);
            UpdateInfo.CurrentVersion = ApplicationVersion;

            try
            {
                RequestCachePolicy cachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);

                using (WebClient wc = new WebClient { Proxy = Proxy, CachePolicy = cachePolicy })
                using (MemoryStream ms = new MemoryStream(wc.DownloadData(URL)))
                using (XmlTextReader xml = new XmlTextReader(ms))
                {
                    XDocument xd = XDocument.Load(xml);

                    if (xd != null)
                    {
                        string node;

                        switch (ReleaseChannel)
                        {
                            default:
                            case ReleaseChannelType.Stable:
                                node = "Stable";
                                break;
                            case ReleaseChannelType.Beta:
                                node = "Beta|Stable";
                                break;
                            case ReleaseChannelType.Dev:
                                node = "Dev|Beta|Stable";
                                break;
                        }

                        string path = string.Format("Update/{0}/{1}", ApplicationName, node);
                        XElement xe = xd.GetNode(path);

                        if (xe != null)
                        {
                            UpdateInfo.LatestVersion = new Version(xe.GetValue("Version"));
                            UpdateInfo.URL = xe.GetValue("URL");

                            string date = xe.GetValue("Date");
                            if (!string.IsNullOrEmpty(date))
                            {
                                DateTime dateTime;
                                if (DateTime.TryParse(date, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
                                {
                                    UpdateInfo.Date = dateTime;
                                }
                            }

                            UpdateInfo.Summary = xe.GetValue("Summary");

                            if (UpdateInfo.IsUpdateRequired)
                            {
                                UpdateInfo.Status = UpdateStatus.UpdateRequired;

                                if (!string.IsNullOrEmpty(UpdateInfo.Summary) && UpdateInfo.Summary.IsValidUrl())
                                {
                                    try
                                    {
                                        wc.Encoding = Encoding.UTF8;
                                        UpdateInfo.Summary = wc.DownloadString(UpdateInfo.Summary.Trim());
                                    }
                                    catch (Exception ex)
                                    {
                                        DebugHelper.WriteException(ex);
                                    }
                                }
                            }
                            else
                            {
                                UpdateInfo.Status = UpdateStatus.UpToDate;
                            }

                            return true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                DebugHelper.WriteException(ex);
            }

            UpdateInfo.Status = UpdateStatus.UpdateCheckFailed;

            return false;
        }