Пример #1
0
        public CfanJson generateCfanFromZipFile(IUser user, string file, Dictionary <string, string> aggregatorData)
        {
            if (Path.GetDirectoryName(file) != RepoModsDirectoryPath)
            {
                throw new Exception($"Unexpected file '{file}' not in mods directory!");
            }
            CfanJson cfanJson = CfanGenerator.createCfanJsonFromFile(file);

            cfanJson.aggregatorData = aggregatorData;
            cfanJson.downloadUrls   = new string[] { RepoExternalUrl + Path.GetFileName(file) };
            return(cfanJson);
        }
Пример #2
0
        public void Export(IRegistryQuerier registry, Stream stream)
        {
            string   description = "Saved CFAN mods from " + DateTime.Now.ToLongDateString();
            CfanJson metaCfan    = CfanGenerator.createEmptyMetaCfanJson("saved-cfan-mods", "Saved CFAN mods", new ModVersion("0.0.0"), "CFAN user", description);

            metaCfan.modInfo.dependencies = registry.Installed(false).Select(p => new ModDependency(withVersions ? p.Key + " == " + p.Value : p.Key)).ToArray();
            string cfanJsonString = JsonConvert.SerializeObject(metaCfan);

            using (var writer = new StreamWriter(stream))
            {
                writer.Write(cfanJsonString);
            }
        }
Пример #3
0
        public CfanJson generateCfanFromModPackJsonFile(IUser user, string file, Dictionary <string, string> aggregatorData)
        {
            if (Path.GetDirectoryName(file) != RepoPacksDirectoryPath)
            {
                throw new Exception($"Unexpected file '{file}' not in mods directory!");
            }
            if (Path.GetExtension(file) != ".json")
            {
                throw new Exception($"Unexpected file '{file}' in packs!");
            }
            string[]   splitStrings = Path.GetFileNameWithoutExtension(file).Split(new[] { '-' }, 3);
            string     author       = splitStrings[0];
            string     nameAndTitle = splitStrings[1];
            ModVersion version      = new ModVersion(splitStrings[2]);
            string     description  = $"This is a meta-package that will install all mods from the modpack {nameAndTitle} by {author}.";
            CfanJson   cfanJson     = CfanGenerator.createCfanJsonFromModListJson(file, nameAndTitle, nameAndTitle, version, author, description);

            cfanJson.aggregatorData = aggregatorData;
            return(cfanJson);
        }
Пример #4
0
        protected CfanJson getCfanJson(IUser user, ModJson modJson, LatestModReleaseJson latestModReleaseJson)
        {
            if (string.IsNullOrEmpty(latestModReleaseJson.download_url))
            {
                user.RaiseError($"Mod {modJson.name} does not have download url, omitting");
                return(null);
            }
            ModInfoJson infoJson = new ModInfoJson
            {
                factorio_version = latestModReleaseJson.info_json.factorio_version,
                author           = new List <string> {
                    modJson.owner
                },
                name         = modJson.name,
                title        = modJson.title,
                homepage     = modJson.homepage,
                contact      = modJson.github_path,
                version      = new ModVersion(latestModReleaseJson.version),
                description  = modJson.summary,
                dependencies = new ModDependency[] { }
            };

            fixBaseGameVersionRequirement(infoJson);
            var cfanJson = CfanGenerator.createCfanJsonFromModInfoJson(infoJson, 0);

            cfanJson.downloadUrls   = new[] { FactorioComAggregator.BASE_URI + latestModReleaseJson.download_url };
            cfanJson.aggregatorData = new Dictionary <string, string>
            {
                ["x-source"]                = typeof(FactorioComAggregator).Name,
                ["factorio-com-id"]         = modJson.id.ToString(),
                ["factorio-com-source"]     = FactorioComAggregator.BASE_URI + "/mods/" + modJson.owner + "/" + modJson.name,
                ["requires-factorio-token"] = "1"
            };
            cfanJson.tags       = new string[] { };
            cfanJson.categories = new string[] { };
            return(cfanJson);
        }