Пример #1
0
        public CfanModule GeneratorRandomModule(
            List <ModDependency> conflicts  = null,
            List <ModDependency> depends    = null,
            List <ModDependency> sugests    = null,
            List <String> provides          = null,
            List <ModDependency> recommends = null,
            string identifier = null,
            Version version   = null)
        {
            if (depends == null)
            {
                depends = new List <ModDependency>();
            }
            if (depends.All(p => p.modName != "base"))
            {
                depends.Add(new ModDependency("base"));
            }

            var cfanJson = new CfanJson()
            {
                modInfo = new ModInfoJson()
                {
                    dependencies = depends.ToArray(),
                    version      = new ModVersion(version?.ToString() ?? "0.0.1"),
                    name         = identifier ?? Generator.Next().ToString(CultureInfo.InvariantCulture),
                    description  = Generator.Next().ToString(CultureInfo.InvariantCulture),
                    title        = Generator.Next().ToString(CultureInfo.InvariantCulture)
                },
                conflicts = conflicts?.ToArray(),
                suggests  = sugests?.ToArray()
            };

            return(new CfanModule(cfanJson));
        }
Пример #2
0
        static void Main(string[] args)
        {
            IUser user = new ConsoleUser(false);

            repoPath          = args[0];
            repoUrlPrefix     = args[1];
            githubAccessToken = args[2];

            Directory.CreateDirectory(Path.Combine(repoPath, "cache"));
            NetFileCache netFileCache = new NetFileCache(Path.Combine(repoPath, "cache"));
            CombinedModFileNormalizer modFileNormalizer = new CombinedModFileNormalizer(new IModFileNormalizer[]
            {
                new RarToZipNormalizer(),
                new SevenZipToZipNormalizer(),
                new ModZipRootNormalizer()
            });
            ModDirectoryManager    manualModDirectoryManager  = new ModDirectoryManager(repoUrlPrefix, repoPath, "mods", modFileNormalizer, netFileCache);
            ModDirectoryManager    githubModsDirectoryManager = new ModDirectoryManager(repoUrlPrefix, repoPath, "mods-github", modFileNormalizer, netFileCache);
            CombinedCfanAggregator combinedAggregator         = new CombinedCfanAggregator(new ICfanAggregator[]
            {
                new LocalRepositoryAggregator(manualModDirectoryManager),
                new GithubAggregator(githubModsDirectoryManager, new GithubRepositoriesDataProvider(), githubAccessToken),
                new FactorioComAggregator(),
            });
            var cfanJsons = combinedAggregator.getAllCfanJsons(user).ToList();

            cfanJsons.Where(p => !CfanJson.requiresFactorioComAuthorization(p)).ToList().ForEach(p => saveCfanJson(user, p));
            cfanJsons.ForEach(p => saveCfanJson(user, p, v2: true));
            createFinalRepositoryTarGz(user);
            createFinalRepositoryTarGz(user, v2: true);
            user.RaiseMessage("Done.");
        }
Пример #3
0
        public IEnumerable <CfanJson> generateCfanJsons(IUser user, ModJson modJson)
        {
            if (modJson.latest_release == null)
            {
                return(new CfanJson[0]);
            }
            CfanJson cfanJson = getCfanJson(user, modJson, modJson.latest_release);

            return(cfanJson == null ? new CfanJson[0] : new[] { cfanJson });
        }
Пример #4
0
        public static CfanJson createCfanJsonFromModListJson(string file, string name, string title, ModVersion version, string author, string description = "")
        {
            ModListJson modList  = JsonConvert.DeserializeObject <ModListJson>(File.ReadAllText(file, Encoding.UTF8));
            CfanJson    cfanJson = createEmptyMetaCfanJson(name, title, version, author, description);

            cfanJson.modInfo.dependencies = modList.mods.Where(p => p.enabled == ModListJson.ModListJsonTruthy.YES)
                                            .Select(p => new ModDependency(p.name))
                                            .ToArray();
            cfanJson.suggests = modList.mods.Where(p => p.enabled == ModListJson.ModListJsonTruthy.NO).Select(p => new ModDependency(p.name)).ToArray();
            return(cfanJson);
        }
Пример #5
0
        public void NormalizeFactorioVersion()
        {
            var jsonString = @"{""tags"":[{""id"":21,""name"":""storage"",""title"":""Storage"",""description"":"""",""type"":""t""}],""ratings_count"":0,""game_versions"":[""0.13""],""license_url"":""https://opensource.org/licenses/MIT"",""latest_release"":{""id"":11169,""version"":""0.1.0"",""game_version"":""0.13"",""released_at"":""2017-12-18T08:51:02.518735Z"",""download_url"":""/api/downloads/data/mods/168/Warehousing_0.1.0.zip"",""info_json"":{""description"":""Store all the things! Warehousing provides high capacity storage buildings, including logistic network versions."",""author"":""Anoyomouse"",""name"":""Warehousing"",""dependencies"":[""base >= 0.15.0""],""contact"":""PM on the Factorio Forums"",""version"":""0.1.0"",""factorio_version"":""0.16"",""homepage"":""https://forums.factorio.com/17295"",""title"":""Warehousing Mod""},""file_name"":""Warehousing_0.1.0.zip"",""file_size"":609499,""downloads_count"":2381,""factorio_version"":""0.16""},""summary"":""Store all the things! Warehousing provides high capacity storage buildings, including logistic network versions."",""id"":168,""license_name"":""MIT"",""created_at"":""2016-06-30 14:31:27.945831+00:00"",""name"":""Warehousing"",""github_path"":""Anoyomouse/Warehousing"",""updated_at"":""2017-12-18 08:51:02.892619+00:00"",""first_media_file"":{""id"":302,""width"":686,""height"":489,""size"":816769,""urls"":{""original"":""https://mods-data.factorio.com/pub_data/media_files/jEL61ah7Nqxg.png"",""thumb"":""https://mods-data.factorio.com/pub_data/media_files/jEL61ah7Nqxg.thumb.png""}},""license_flags"":599,""title"":""Warehousing Mod"",""current_user_rating"":null,""downloads_count"":88876,""owner"":""anoyomouse"",""homepage"":""https://forums.factorio.com/17295""}";
            var modJson    = JsonConvert.DeserializeObject <ModJson>(jsonString);
            FactorioComDownloader  downloader = new FactorioComDownloader();
            IEnumerable <CfanJson> mods       = downloader.generateCfanJsons(new NullUser(), modJson);
            CfanJson      cfanJson            = mods.First();
            ModDependency factorioDependency  = cfanJson.modInfo.dependencies.First(p => p.modName == "base");

            Assert.IsTrue(factorioDependency.maxVersion > new ModVersion("0.16.0"));
        }
Пример #6
0
 public IEnumerable <CfanJson> generateCfanJsons(IUser user, ModJson modJson)
 {
     if (modJson.name == "5dim´s mod")
     {
         CfanJson cfan = localManager.generateCfanFromModPackJsonFile(user, Path.Combine(localManager.RepoPacksDirectoryPath, "5Dim-5dim-0.0.0.json"), new Dictionary <string, string>()
         {
             ["fmm-id"] = modJson.id.ToString()
         });
         return(new CfanJson[] { cfan });
     }
     return(null);
 }
Пример #7
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);
        }
Пример #8
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);
            }
        }
Пример #9
0
        public InstalledModule(KSP ksp, CfanModule module, IEnumerable <string> relative_files)
        {
            install_time       = DateTime.Now;
            source_module_json = module.cfanJson;
            source_module      = module;
            installed_files    = new Dictionary <string, InstalledModuleFile>();

            foreach (string file in relative_files)
            {
                if (Path.IsPathRooted(file))
                {
                    throw new PathErrorKraken(file, "InstalledModule *must* have relative paths");
                }

                // IMF needs a KSP object so it can compute the SHA1.
                installed_files[file] = new InstalledModuleFile(file, ksp);
            }
        }
Пример #10
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);
        }
Пример #11
0
        public IEnumerable <CfanJson> getAllCfanJsons(IUser user)
        {
            List <CfanJson> result = new List <CfanJson>();

            foreach (ICfanAggregator cfanAggregator in cfanAggregators)
            {
                foreach (CfanJson newCfan in cfanAggregator.getAllCfanJsons(user))
                {
                    CfanJson existingCfan = result.FirstOrDefault(p => p.modInfo.name == newCfan.modInfo.name && p.modInfo.version == newCfan.modInfo.version);
                    if (existingCfan != null)
                    {
                        cfanAggregator.mergeCfanJson(user, existingCfan, newCfan);
                    }
                    else
                    {
                        result.Add(newCfan);
                    }
                }
            }
            return(result);
        }
Пример #12
0
        protected static void saveCfanJson(IUser user, CfanJson cfanJson, bool v2 = false)
        {
            string subdirectory         = cfanJson.modInfo.name;
            string outputPath           = v2 ? Program.outputVersion2Path : Program.outputPath;
            string filename             = cfanJson.modInfo.name + "_" + cfanJson.modInfo.version + ".cfan";
            var    previousDependencies = cfanJson.modInfo.dependencies;

            if (!v2)
            {
                cfanJson.modInfo.dependencies = previousDependencies.ToList().Select(createLegacyDependency).ToArray();
            }
            Directory.CreateDirectory(Path.Combine(outputPath, subdirectory));
            File.WriteAllText(
                Path.Combine(outputPath, subdirectory, filename),
                JsonConvert.SerializeObject(cfanJson)
                );
            if (!v2)
            {
                cfanJson.modInfo.dependencies = previousDependencies;
            }
            user.RaiseMessage($"Generated {filename}");
        }
Пример #13
0
 public void mergeCfanJson(IUser user, CfanJson destination, CfanJson source)
 {
     // ignore, this requires auth that almost no one yet has in config (0.13 is in unstable atm)
     // so avoid it if possible
 }
Пример #14
0
 public void mergeCfanJson(IUser user, CfanJson destination, CfanJson source)
 {
     destination.aggregatorData["fmm-id"] = source.aggregatorData["fmm-id"];
 }
Пример #15
0
        /// <summary>
        /// Return the most recent release of a module with a optional ksp version to target and a RelationshipDescriptor to satisfy.
        /// </summary>
        /// <param name="ksp_version">If not null only consider mods which match this ksp version.</param>
        /// <param name="relationship">If not null only consider mods which satisfy the RelationshipDescriptor.</param>
        /// <returns></returns>
        public CfanModule Latest(FactorioVersion ksp_version = null, ModDependency relationship = null, bool hasFactorioAuth = false)
        {
            IDictionary <ModVersion, CfanJson> module_version = this.module_version;

            if (!hasFactorioAuth)
            {
                module_version = module_version.Where(p => !CfanJson.requiresFactorioComAuthorization(p.Value)).ToDictionary(p => p.Key, p => p.Value);
            }

            var      available_versions = new List <ModVersion>(module_version.Keys);
            CfanJson module;

            log.DebugFormat("Our dictionary has {0} keys", module_version.Keys.Count);
            log.DebugFormat("Choosing between {0} available versions", available_versions.Count);

            // Uh oh, nothing available. Maybe this existed once, but not any longer.
            if (available_versions.Count == 0)
            {
                return(null);
            }

            // No restrictions? Great, we can just pick the first one!
            if (ksp_version == null && relationship == null)
            {
                module = module_version[available_versions.First()];

                log.DebugFormat("No KSP version restriction, {0} is most recent", module.modInfo.version);
                return(new CfanModule(module));
            }

            // If there's no relationship to satisfy, we can just pick the first that is
            // compatible with our version of KSP.
            if (relationship == null)
            {
                // Time to check if there's anything that we can satisfy.
                var version =
                    available_versions.FirstOrDefault(v => new CfanModule(module_version[v]).IsCompatibleKSP(ksp_version));
                if (version != null)
                {
                    return(new CfanModule(module_version[version]));
                }

                log.DebugFormat("No version of {0} is compatible with KSP {1}",
                                module_version[available_versions[0]].modInfo.name, ksp_version);

                return(null);
            }

            // If we're here, then we have a relationship to satisfy, so things get more complex.
            if (ksp_version == null)
            {
                var version = available_versions.FirstOrDefault(p => relationship.isSatisfiedBy(identifier, p));
                return(version == null ? null : new CfanModule(module_version[version]));
            }
            else
            {
                var version = available_versions.FirstOrDefault(v =>
                                                                relationship.isSatisfiedBy(identifier, v) &&
                                                                new CfanModule(module_version[v]).IsCompatibleKSP(ksp_version));
                return(version == null ? null : new CfanModule(module_version[version]));
            }
        }
Пример #16
0
 public virtual void mergeCfanJson(IUser user, CfanJson destination, CfanJson source)
 {
     throw new NotImplementedException();
 }
Пример #17
0
 public void mergeCfanJson(IUser user, CfanJson destination, CfanJson source)
 {
     destination.aggregatorData["github-repo"] = source.aggregatorData["github-repo"];
 }
Пример #18
0
 public CfanModule(CfanJson cfanJson)
 {
     this.cfanJson = cfanJson;
 }