コード例 #1
0
        public string GetLatestDownloadURL(bool includePreRelease, bool isPortable, bool isBrowserDownloadURL)
        {
            try
            {
                GitHubRelease latestRelease = GetLatestRelease(includePreRelease);

                if (UpdateReleaseInfo(latestRelease, isPortable, isBrowserDownloadURL))
                {
                    return(DownloadURL);
                }
            }
            catch (Exception)
            {
                //DebugHelper.WriteException(e);
            }

            return(null);
        }
コード例 #2
0
        public bool UpdateReleaseInfo(GitHubRelease release, bool isPortable, bool isBrowserDownloadURL)
        {
            if (release != null && !string.IsNullOrEmpty(release.tag_name) && release.tag_name.Length > 1 && release.tag_name[0] == 'v')
            {
                LatestVersion = new Version(release.tag_name.Substring(1));

                if (release.assets != null && release.assets.Count > 0)
                {
                    string endsWith;

                    if (isPortable)
                    {
                        endsWith = "portable.zip";
                    }
                    else
                    {
                        endsWith = ".exe";
                    }

                    foreach (GitHubAsset asset in release.assets)
                    {
                        if (asset != null && !string.IsNullOrEmpty(asset.name) && asset.name.EndsWith(endsWith, StringComparison.InvariantCultureIgnoreCase))
                        {
                            Filename = asset.name;

                            if (isBrowserDownloadURL)
                            {
                                DownloadURL = asset.browser_download_url;
                            }
                            else
                            {
                                DownloadURL = asset.url;
                            }

                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
コード例 #3
0
        private GitHubRelease GetLatestRelease(bool includePreRelease)
        {
            GitHubRelease latestRelease = null;

            List <GitHubRelease> releases = GetReleases();

            if (releases != null && releases.Count > 0)
            {
                if (includePreRelease)
                {
                    latestRelease = releases[0];
                }
                else
                {
                    latestRelease = releases.FirstOrDefault(x => !x.prerelease);
                }
            }

            return(latestRelease);
        }