public ModJson LoadModJson(string filepath)
        {
            var mj = new ModJson
            {
                Versions = new ModJsonVersions
                {
                }
            };

            foreach (var c in ReadConfigFile(filepath))
            {
                switch (c.Key)
                {
                case "Name": mj.Name = c.Value; break;

                case "TagLine": mj.TagLine = c.Value; break;

                case "Author": mj.Author = c.Value; break;

                case "GameVersion": mj.Versions.Game = c.Value; break;

                case "ApiVersion": mj.Versions.Api = c.Value; break;

                case "Version": mj.Versions.Mod = c.Value; break;

                case "EntryFiles": mj.EntryFiles = c.Value.Split(',').Select(t => t.Trim()).ToArray(); break;

                case "Url": mj.Url = c.Value; break;
                }
            }

            return(mj);
        }
Exemple #2
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 });
        }
Exemple #3
0
 public IEnumerable <CfanJson> generateCfanJsons(IUser user, ModJson modJson)
 {
     foreach (IFmmConverter fmmConverter in fmmConverters)
     {
         IEnumerable <CfanJson> result = fmmConverter.generateCfanJsons(user, modJson);
         if (result != null)
         {
             return(result);
         }
     }
     throw new Exception($"None of the converters wanted to convert mod {modJson.name}.");
 }
Exemple #4
0
        public IEnumerable <CfanJson> generateCfanJsons(IUser user, ModJson modJson)
        {
            CfanJson[] cfanJsons = yieldCfanJsons(user, modJson).ToArray();
            var        groupedByNameAndVersions = cfanJsons.GroupBy(p => new { p.modInfo.version, p.modInfo.name }).ToArray();

            if (groupedByNameAndVersions.Any(p => p.Count() > 1))
            {
                user.RaiseError($"Some releases/files have duplicated name/version for {modJson.name}.");
                cfanJsons = groupedByNameAndVersions.Select(p => p.First()).ToArray();
            }
            return(cfanJsons);
        }
Exemple #5
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);
 }
Exemple #6
0
 protected IEnumerable <CfanJson> yieldCfanJsons(IUser user, ModJson modJson)
 {
     foreach (ModReleaseJson modReleaseJson in modJson.releases)
     {
         foreach (ModReleaseJson.ModReleaseJsonFile modReleaseJsonFile in modReleaseJson.files)
         {
             string url = checkUrl(user, modReleaseJsonFile.mirror, $"mod: {modJson.name}");
             if (string.IsNullOrEmpty(url))
             {
                 url = checkUrl(user, modReleaseJsonFile.url, $"mod: {modJson.name}");
             }
             if (string.IsNullOrEmpty(url))
             {
                 user.RaiseError($"Mod {modJson.name} does not have download url, omitting");
                 continue;
             }
             string expectedFilename = modJson.name + "_" + modReleaseJson.version + ".zip";
             string downloadedFilePath;
             try
             {
                 downloadedFilePath = fmmManager.getCachedOrDownloadFile(user, url, expectedFilename);
             }
             catch (NetfanDownloadKraken e)
             {
                 user.RaiseError($"Couldn't download {modJson.name}: {e.Message}");
                 continue;
             }
             catch (Exception e)
             {
                 user.RaiseError($"Couldn't handle {modJson.name}: {e.Message}");
                 continue;
             }
             yield return(fmmManager.generateCfanFromZipFile(user, downloadedFilePath, new Dictionary <string, string>
             {
                 ["x-source"] = typeof(FactorioModsComAggregator).Name,
                 ["fmm-id"] = modJson.id.ToString()
             }));
         }
     }
 }
Exemple #7
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);
        }
Exemple #8
0
        public ModImplementation LoadMod(ModJson json, string jsonFilePath)
        {
            if (json == null ||
                json.EntryFiles == null ||
                json.EntryFiles.Length == 0)
            {
                _logger.Warn("JSON file doesn't contain entry files: " + jsonFilePath);
                return(null);
            }

            var imp = new ModImplementation
            {
                Data         = json,
                JsonFilePath = jsonFilePath,
                ApiVer       = new Version(json.Versions.Api),
                GameVer      = new Version(json.Versions.Game),
                ModVer       = new Version(json.Versions.Mod),
                Mods         = new Dictionary <Assembly, Mod[]>()
            };

            if (!ValidateVersion(imp.ModVer, imp.GameVer, imp.ApiVer))
            {
                _logger.Warn($"Skipping {imp.Data.Name} (v{imp.ModVer}) - Invalid game version.");
                return(null);
            }

            var baseDir = Path.GetDirectoryName(jsonFilePath);

            foreach (var file in json.EntryFiles)
            {
                _logger.Debug($"Start loading entry file: {file}");
                var path = Path.Combine(baseDir, file);
                if (!File.Exists(path))
                {
                    _logger.Warn($"Couldn't find entry file for mod: {jsonFilePath}\r\nMissing file path: {path}");
                    continue;
                }

                try
                {
                    var assm = Assembly.LoadFrom(path);
                    var mods = LoadMod(assm, imp).ToArray();

                    imp.Mods.Add(assm, mods);
                    _logger.Debug($"Loaded entry file for: {jsonFilePath}\r\nEntry File: {path}");
                }
                catch (Exception ex)
                {
                    _logger.Error($"Failed to load assembly for mod: {jsonFilePath}\r\nAttempted to load: {path}\r\n{ex}");
                    continue;
                }
            }

            if (imp.Mods.Count <= 0)
            {
                _logger.Warn($"No mods found for file: {jsonFilePath}");
                return(null);
            }

            return(imp);
        }
Exemple #9
0
 public IEnumerable <CfanJson> generateCfanJsons(IUser user, ModJson modJson)
 {
     return(ignoreNames.Contains(modJson.name) ? new CfanJson[0] : null);
 }