コード例 #1
0
        /// <summary>
        /// Downloads the list of Ckan Repositories from the passed URL.
        /// </summary>
        /// <param name="repoListURL">The URL to get the Ckan Repositories from.</param>
        /// <returns>The list of Ckan Repositories from the passed URL.</returns>
        public static CkanRepositories GetRepositoryList(Uri repoListURL = null)
        {
            CkanRepositories repos;

            if (repoListURL != null)
            {
                // load repositories from repoListURL
                Messenger.AddInfo($"Downloading repository list from \"{repoListURL.AbsoluteUri}\"...");

                var content = Www.Load(repoListURL.AbsoluteUri);
                repos = JsonConvert.DeserializeObject <CkanRepositories>(content);

                Messenger.AddInfo($"Downloading repository list done. {repos.repositories.Length} repositories found.");
            }
            else
            {
                // create default repository
                repos = new CkanRepositories {
                    repositories = new [] { CkanRepository.GitHubRepository }
                };
            }

            return(repos);
        }
コード例 #2
0
        /// <summary>
        /// Gets the content of the site of the passed URL and parses it for ModInfos.
        /// </summary>
        /// <param name="url">The URL of the site to parse the ModInfos from.</param>
        /// <returns>The ModInfos parsed from the site of the passed URL.</returns>
        public ModInfo GetModInfo(string url)
        {
            string modInfoUrl = MODINFO_URL + (url.Split(new string[] { "/" }, StringSplitOptions.None).ToList())[4];

            if (string.IsNullOrEmpty(modInfoUrl))
            {
                return(null);
            }

            string content = Www.Load(modInfoUrl);

            if (string.IsNullOrEmpty(content))
            {
                return(null);
            }

            JObject jObject = JObject.Parse(content);

            var modInfo = new ModInfo
            {
                SiteHandlerName = Name,
                ModURL          = url,
                AdditionalURL   = GetString(jObject["website"]),
                ProductID       = GetString(jObject["id"]),
                Name            = GetString(jObject["name"]),
                Downloads       = GetString(jObject["downloads"]),
                Author          = GetString(jObject["author"]),
                Version         = GetVersion(jObject["versions"] as JToken),
                KSPVersion      = GetKSPVersion(jObject["versions"] as JToken),
                Note            = GetString(jObject["description"])
            };

            ////modInfo.CreationDate = kerbalMod.Versions.Last().Date; // TODO when KS API supports dates from versions

            return(modInfo);
        }