示例#1
0
        private AddonSearchResult GetAddonSearchResult(CurseSearchResult result, CurseFile latestFile)
        {
            try
            {
                var thumbnailUrl = GetThumbnailUrl(result);
                var id           = result.Id;
                var name         = result.Name;
                var fileName     = latestFile.FileName;
                var folders      = GetFolderNames(latestFile);
                var gameVersion  = GetGameVersion(latestFile);
                var author       = GetAuthor(result);
                var downloadUrl  = latestFile.DownloadUrl;

                return(new AddonSearchResult
                {
                    Author = author,
                    ExternalId = id.ToString(),
                    Folders = folders,
                    GameVersion = gameVersion,
                    Name = name,
                    ThumbnailUrl = thumbnailUrl,
                    Version = fileName,
                    DownloadUrl = downloadUrl,
                    ExternalUrl = result.WebsiteUrl
                });
            }
            catch (Exception ex)
            {
                Log.Error(ex, "GetAddonSearchResult");
                Console.WriteLine(ex);
                return(null);
            }
        }
示例#2
0
        private Metadata TransformOne(JObject json, CurseMod curseMod, CurseFile latestVersion)
        {
            Log.InfoFormat("Found Curse mod: {0} {1}", curseMod.GetName(), latestVersion.GetFileVersion());

            // Only pre-fill version info if there's none already. GH #199
            if (json["ksp_version_min"] == null && json["ksp_version_max"] == null && json["ksp_version"] == null)
            {
                KspVersion minVer = latestVersion.versions.Min();
                KspVersion maxVer = latestVersion.versions.Max();
                if (minVer == maxVer)
                {
                    Log.DebugFormat("Writing ksp_version from Curse: {0}", latestVersion.version);
                    json["ksp_version"] = latestVersion.version.ToString();
                }
                else
                {
                    Log.DebugFormat("Writing ksp_version_min,_max from Curse: {0}, {1}", minVer, maxVer);
                    json["ksp_version_min"] = minVer.ToString();
                    json["ksp_version_max"] = maxVer.ToString();
                }
            }

            var useDownloadNameVersion = false;
            var useFilenameVersion     = false;
            var useCurseIdVersion      = false;

            var curseMetadata = (JObject)json["x_netkan_curse"];

            if (curseMetadata != null)
            {
                var useDownloadNameVersionMetadata = (bool?)curseMetadata["use_download_name_version"];
                if (useDownloadNameVersionMetadata != null)
                {
                    useDownloadNameVersion = useDownloadNameVersionMetadata.Value;
                }

                var useFilenameVersionMetadata = (bool?)curseMetadata["use_filename_version"];
                if (useFilenameVersionMetadata != null)
                {
                    useFilenameVersion = useFilenameVersionMetadata.Value;
                }

                var useCurseIdVersionMetadata = (bool?)curseMetadata["use_curse_id_version"];
                if (useCurseIdVersionMetadata != null)
                {
                    useCurseIdVersion = useCurseIdVersionMetadata.Value;
                }

                if ((useDownloadNameVersion ? 1 : 0) + (useFilenameVersion ? 1 : 0) + (useCurseIdVersion ? 1 : 0) > 1)
                {
                    throw new Kraken("Conflicting version options set in x_netkan_curse");
                }
            }

            json.SafeAdd("name", curseMod.GetName());
            json.SafeAdd("abstract", curseMod.description);

            if (useDownloadNameVersion)
            {
                json.SafeAdd("version", latestVersion.name);
            }
            else if (useFilenameVersion)
            {
                json.SafeAdd("version", latestVersion.GetFilename());
            }
            else if (useCurseIdVersion)
            {
                json.SafeAdd("version", latestVersion.GetCurseIdVersion());
            }
            else
            {
                json.SafeAdd("version", latestVersion.GetFileVersion());
            }

            json.SafeAdd("author", JToken.FromObject(curseMod.authors));
            json.SafeAdd("download", Regex.Replace(latestVersion.GetDownloadUrl(), " ", "%20"));

            // Curse provides users with the following default selection of licenses. Let's convert them to CKAN
            // compatible license strings if possible.
            //
            // "Academic Free License v3.0"                               - Becomes "AFL-3.0"
            // "Ace3 Style BSD"                                           - Becomes "restricted"
            // "All Rights Reserved"                                      - Becomes "restricted"
            // "Apache License version 2.0"                               - Becomes "Apache-2.0"
            // "Apple Public Source License version 2.0 (APSL)"           - Becomes "APSL-2.0"
            // "BSD License"                                              - Becomes "BSD-3-clause"
            // "Common Development and Distribution License (CDDL) "      - Becomes "CDDL"
            // "GNU Affero General Public License version 3 (AGPLv3)"     - Becomes "AGPL-3.0"
            // "GNU General Public License version 2 (GPLv2)"             - Becomes "GPL-2.0"
            // "GNU General Public License version 3 (GPLv3)"             - Becomes "GPL-3.0"
            // "GNU Lesser General Public License version 2.1 (LGPLv2.1)" - Becomes "LGPL-2.1"
            // "GNU Lesser General Public License version 3 (LGPLv3)"     - Becomes "LGPL-3.0"
            // "ISC License (ISCL)"                                       - Becomes "ISC"
            // "Microsoft Public License (Ms-PL)"                         - Becomes "Ms-PL"
            // "Microsoft Reciprocal License (Ms-RL)"                     - Becomes "Ms-RL"
            // "MIT License"                                              - Becomes "MIT"
            // "Mozilla Public License 1.0 (MPL)"                         - Becomes "MPL-1.0"
            // "Mozilla Public License 1.1 (MPL 1.1)"                     - Becomes "MPL-1.1"
            // "Public Domain"                                            - Becomes "public-domain"
            // "WTFPL"                                                    - Becomes "WTFPL"
            // "zlib/libpng License"                                      - Becomes "Zlib"
            // "Custom License"                                           - Becomes "unknown"

            var curseLicense = curseMod.license.Trim();

            switch (curseLicense)
            {
            case "Academic Free License v3.0":
                json.SafeAdd("license", "AFL-3.0");
                break;

            case "Ace3 Style BSD":
                json.SafeAdd("license", "restricted");
                break;

            case "All Rights Reserved":
                json.SafeAdd("license", "restricted");
                break;

            case "Apache License version 2.0":
                json.SafeAdd("license", "Apache-2.0");
                break;

            case "Apple Public Source License version 2.0 (APSL)":
                json.SafeAdd("license", "APSL-2.0");
                break;

            case "BSD License":
                json.SafeAdd("license", "BSD-3-clause");
                break;

            case "Common Development and Distribution License (CDDL) ":
                json.SafeAdd("license", "CDDL");
                break;

            case "GNU Affero General Public License version 3 (AGPLv3)":
                json.SafeAdd("license", "AGPL-3.0");
                break;

            case "GNU General Public License version 2 (GPLv2)":
                json.SafeAdd("license", "GPL-2.0");
                break;

            case "GNU General Public License version 3 (GPLv3)":
                json.SafeAdd("license", "GPL-3.0");
                break;

            case "GNU Lesser General Public License version 2.1 (LGPLv2.1)":
                json.SafeAdd("license", "LGPL-2.1");
                break;

            case "GNU Lesser General Public License version 3 (LGPLv3)":
                json.SafeAdd("license", "LGPL-3.0");
                break;

            case "ISC License (ISCL)":
                json.SafeAdd("license", "ISC");
                break;

            case "Microsoft Public License (Ms-PL)":
                json.SafeAdd("license", "Ms-PL");
                break;

            case "Microsoft Reciprocal License (Ms-RL)":
                json.SafeAdd("license", "Ms-RL");
                break;

            case "MIT License":
                json.SafeAdd("license", "MIT");
                break;

            case "Mozilla Public License 1.0 (MPL)":
                json.SafeAdd("license", "MPL-1.0");
                break;

            case "Mozilla Public License 1.1 (MPL 1.1)":
                json.SafeAdd("license", "MPL-1.1");
                break;

            case "Public Domain":
                json.SafeAdd("license", "public-domain");
                break;

            case "WTFPL":
                json.SafeAdd("license", "WTFPL");
                break;

            case "zlib/libpng License":
                json.SafeAdd("license", "Zlib");
                break;

            default:
                json.SafeAdd("license", "unknown");
                break;
            }

            // Make sure resources exist.
            if (json["resources"] == null)
            {
                json["resources"] = new JObject();
            }

            var resourcesJson = (JObject)json["resources"];

            //resourcesJson.SafeAdd("homepage", Normalize(curseMod.website));
            //resourcesJson.SafeAdd("repository", Normalize(curseMod.source_code));
            resourcesJson.SafeAdd("curse", curseMod.GetProjectUrl());

            if (curseMod.thumbnail != null)
            {
                resourcesJson.SafeAdd("x_screenshot", Normalize(new Uri(curseMod.thumbnail)));
            }

            Log.DebugFormat("Transformed metadata:{0}{1}", Environment.NewLine, json);

            return(new Metadata(json));
        }
示例#3
0
 private bool DoesFileMatchClientType(CurseFile file, string clientTypeStr)
 {
     return(file.ReleaseType == CurseReleaseType.Release &&
            file.GameVersionFlavor == clientTypeStr &&
            file.IsAlternate == false);
 }
示例#4
0
 private IEnumerable <CurseDependency> GetRequiredDependencies(CurseFile file)
 {
     return(file.Dependencies
            .Where(dep => dep.Type.AsAddonDependencyType() == AddonDependencyType.Required));
 }
示例#5
0
 private string GetGameVersion(CurseFile file)
 {
     return(file.GameVersion.FirstOrDefault());
 }
示例#6
0
 private IList <string> GetFolderNames(CurseFile file)
 {
     return(file.Modules.Select(m => m.Foldername).ToList());
 }