Ejemplo n.º 1
0
        // Dispose of current update process.
        public static void Dispose()
        {
            if (Latest != null)
            {
                if (Latest.IsDownloading)
                {
                    throw new UpdaterException(L10n.Message("Download still in progress"));
                }
                Latest.Dispose();
                Latest = null;
            }

            IsChecked = false;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Disposing CI and API resources
 /// </summary>
 public void Dispose()
 {
     Release.Dispose(_knc);
     Release.Dispose(_technoTrend);
     Release.Dispose(_digitalEveryWhere);
     Release.Dispose(_hauppauge);
     Release.Dispose(_conexant);
     Release.Dispose(_genericbdas);
     Release.Dispose(_isgenericatsc);
     Release.Dispose(_isvixsatsc);
     Release.Dispose(_genpix);
     Release.Dispose(_winTvCiModule);
     Release.Dispose(_twinhan);
     Release.Dispose(_profred);
     Release.Dispose(_TeVii);
 }
Ejemplo n.º 3
0
        /* Checks for updates and returns release informations when there is newer one.
         * Returns null if there is no newer release.
         * If Prerelease argument is true, it will return also Pre-release, otherwise Pre-releases are ignored.
         * An existing last checked release will be discarded.
         * Throws UpdaterException if error occurs.
         */
        public static Release CheckForUpdates(bool Prerelease = true)
        {
            if (Latest != null)
            {
                if (Latest.IsDownloading)
                {
                    throw new UpdaterException("Download already in progress");
                }
                Latest.Dispose();
            }
            Latest    = null;
            IsChecked = IsInstalled = false;

            var webClient = new UpdaterWebClient();

            webClient.Encoding = Encoding.UTF8;

            try
            {
                string json = webClient.DownloadString(GitAPILatestReleaseURL);

                RavenJArray releases = RavenJArray.Parse(json);
                if (releases.Length < 1)
                {
                    throw new UpdaterException("No release found");
                }

                string current = GetCurrentVersion(); // Current version (tag).

                // Iterate thru avialable releases.
                foreach (RavenJObject release in (RavenJArray)releases)
                {
                    // Drafts are not returned by API, but just in case...
                    bool draft = release["draft"].Value <bool>();
                    if (draft)
                    {
                        continue;        // Ignore drafts.
                    }
                    // Check if there are assets attached.
                    RavenJArray assets = (RavenJArray)release["assets"];
                    if (assets.Length < 1)
                    {
                        continue;                    // No assets, ignore it.
                    }
                    // Compare release tag with our version (tag).
                    // Assumption is that no one will make realease with older version tag.
                    // So, any different version should be newer.
                    string tag = release["tag_name"].Value <string>();
                    if (tag == current) // If we didn't find different tag till now, then there is no newer version.
                    {
                        IsChecked = true;

                        return(null);
                    }

                    // Check if it is pre-release and we want to update to it.
                    bool prerelease = release["prerelease"].Value <bool>();
                    if (prerelease && !Prerelease)
                    {
                        continue;                            // Found unwanted pre-release, ignore it.
                    }
                    // Find PoESkillTree ZIP package.
                    RavenJObject zipAsset = null;
                    foreach (RavenJObject asset in assets)
                    {
                        string content_type = asset["content_type"].Value <string>();
                        if (content_type != "application/zip")
                        {
                            continue;                                    // Not a ZIP, ignore it.
                        }
                        string name = asset["name"].Value <string>();
                        Match  m    = ReZipPackage.Match(name);
                        if (m.Success)
                        {
                            // Found ZIP package.
                            zipAsset = asset;
                            break;
                        }
                    }
                    if (zipAsset == null)
                    {
                        continue;                   // No ZIP package found.
                    }
                    // This is newer release (probably).
                    IsChecked = true;
                    Latest    = new Release
                    {
                        Name        = release["name"].Value <string>(),
                        Description = release["body"].Value <string>(),
                        Prerelease  = prerelease,
                        Version     = tag,
                        URI         = new Uri(zipAsset["browser_download_url"].Value <string>())
                    };

                    // We are done, exit loop.
                    break;
                }
            }
            catch (WebException e)
            {
                if (e.Status == WebExceptionStatus.ProtocolError)
                {
                    throw new UpdaterException("HTTP " + ((int)((HttpWebResponse)e.Response).StatusCode) + " " + ((HttpWebResponse)e.Response).StatusDescription);
                }
                else
                {
                    throw new UpdaterException(e.Message, e);
                }
            }
            catch (Exception e)
            {
                throw new UpdaterException(e.Message, e);
            }

            return(Latest);
        }
Ejemplo n.º 4
0
        /* Checks for updates and returns release informations when there is newer one.
         * Returns null if there is no newer release.
         * An existing last checked release will be discarded.
         * Throws UpdaterException if error occurs.
         */
        public static Release CheckForUpdates()
        {
            if (Latest != null)
            {
                if (Latest.IsDownloading)
                {
                    throw new UpdaterException("Download already in progress");
                }
                Latest.Dispose();
            }
            Latest    = null;
            IsChecked = IsInstalled = false;

            var webClient = new UpdaterWebClient();

            webClient.Encoding = Encoding.UTF8;

            try
            {
                string json = webClient.DownloadString(GitAPILatestReleaseURL);

                RavenJArray releases = RavenJArray.Parse(json);
                if (releases.Length < 1)
                {
                    throw new UpdaterException("No release found");
                }

                RavenJObject latest = (RavenJObject)releases[0];
                RavenJArray  assets = (RavenJArray)latest["assets"];
                if (assets.Length < 1)
                {
                    throw new UpdaterException("Package for release is missing");
                }

                string current = GetCurrentVersion();
                string tag     = latest["tag_name"].Value <string>();
                if (tag == current)
                {
                    IsChecked = true;

                    return(null);
                }

                string url = ((RavenJObject)assets[0])["browser_download_url"].Value <string>();

                IsChecked = true;
                Latest    = new Release
                {
                    Name        = latest["name"].Value <string>(),
                    Description = latest["body"].Value <string>(),
                    Version     = tag,
                    URI         = new Uri(url)
                };
            }
            catch (WebException e)
            {
                if (e.Status == WebExceptionStatus.ProtocolError)
                {
                    throw new UpdaterException("HTTP " + ((int)((HttpWebResponse)e.Response).StatusCode) + " " + ((HttpWebResponse)e.Response).StatusDescription);
                }
                else
                {
                    throw new UpdaterException(e.Message, e);
                }
            }
            catch (Exception e)
            {
                throw new UpdaterException(e.Message, e);
            }

            return(Latest);
        }