示例#1
0
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="release">The underlying GitHub release.</param>
 /// <param name="asset">The underlying download asset.</param>
 /// <param name="version">The SMAPI version.</param>
 /// <param name="isForDevs">Whether this is a 'for developers' download.</param>
 public ReleaseVersion(GitRelease release, GitAsset asset, ISemanticVersion version, bool isForDevs)
 {
     this.Release   = release;
     this.Asset     = asset;
     this.Version   = version;
     this.IsForDevs = isForDevs;
 }
示例#2
0
        /// <summary>
        /// Fetches the different versions/releases from the Githup repo
        /// </summary>
        async void GetVersions()
        {
            _window.WriteLog("Trying to fetch releases from GitHub...");
            _window.prog_loading.IsIndeterminate = true;

            using (var client = new WebClient())
            {
                client.Headers.Add("user-agent", "GitInstaller");

                //Save as _releasesjson so you don't have to fetch it again
                _releasesjson = await client.DownloadStringTaskAsync(_url.AbsoluteUri);

                _window.WriteLog("Fetched all releases from GitHub...");

                //Create GitRelease objects from the _releasesjson string
                _window.WriteLog("Creating Release objects...");
                JObject[] jobjs   = JsonConvert.DeserializeObject <JObject[]>(_releasesjson);
                int       idcount = 0;
                Releases.Clear();
                _window.cb_versions.Items.Clear();

                foreach (JObject job in jobjs)
                {
                    GitRelease robj = new GitRelease();
                    robj.Id           = idcount;
                    robj.Name         = job.Value <string>("name");
                    robj.Tag          = job.Value <string>("tag_name");
                    robj.Body         = job.Value <string>("body");
                    robj.GitUrl       = job.Value <string>("html_url");
                    robj.IsPrerelease = job.Value <bool>("prerelease");
                    robj.CreationDate = job.Value <string>("created_at");

                    //Author
                    JObject authorobj = job.Value <JObject>("author");
                    if (authorobj != null)
                    {
                        robj.AuthorName = authorobj.Value <string>("login");
                        robj.AuthorUrl  = authorobj.Value <string>("html_url");
                    }

                    //Assets
                    JToken assets = job.Value <JToken>("assets");

                    foreach (JToken asset in assets.Children())
                    {
                        GitAsset newasset = new GitAsset();
                        newasset.Filename    = asset.Value <string>("name");
                        newasset.DownloadUrl = asset.Value <string>("browser_download_url");
                        newasset.Size        = asset.Value <float>("size");
                        robj.Assets.Add(newasset);
                    }

                    if (Settings.Ignored_Tags.Length > 0)
                    {
                        foreach (string ignoredtags in Settings.Ignored_Tags)
                        {
                            if (!Utils.HasWildcard(robj.Tag, ignoredtags))
                            {
                                idcount++;
                                Releases.Add(robj);
                            }
                        }
                    }
                    else
                    {
                        idcount++;
                        Releases.Add(robj);
                    }
                }

                _window.cb_versions.SelectedIndex = 0;
            }
            _window.prog_loading.IsIndeterminate = false;
            if (Releases.Count < 1)
            {
                MessageBox.Show("No releases found for this repository! Can't progress with the installation...", "Warning!", MessageBoxButton.OK, MessageBoxImage.Warning);
                Environment.Exit(2);
                return;
            }
            _window.bt_install.IsEnabled = true;
            _window.WriteLog("Done creating release objects, " + Releases.Count + " releases added...");

            _window.UpdateVersions(Settings.Preview);
            _window.UpdateChanges(Releases[0]);
        }