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."); }
/// <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])); } }