예제 #1
0
        private static bool ModTemplatesEqual(ModTemplate template, ModExportTemplate exportTemplate, bool downloadNewer)
        {
            if (template.Mod == exportTemplate.Mod)
            {
                //Same mod, if options match templates are equal
                bool includeEquals    = (template.Include == exportTemplate.Included);
                bool exportModeEquals = (template.ExportMode == exportTemplate.MaskedExportMode);

                return((includeEquals || downloadNewer) && exportModeEquals);
            }
            else if (template.Mod.Name == exportTemplate.Name)
            {
                if (template.Mod.Version == exportTemplate.Version)
                {
                    //Different objects but same mod, if options match templates are equal (this should actually never happen)
                    bool includeEquals    = (template.Include == exportTemplate.Included);
                    bool exportModeEquals = (template.ExportMode == exportTemplate.MaskedExportMode);

                    return((includeEquals || downloadNewer) && exportModeEquals);
                }
                else
                {
                    //Different versions of same mod
                    if (downloadNewer || (!template.Include && !exportTemplate.Included))
                    {
                        if (template.UseNewestVersion && ((exportTemplate.ExportMode & ExportMode.Mask) == ExportMode.NewestVersion))
                        {
                            //Both use newest version, currently installed version doesn't matter, templates are equal
                            return(true);
                        }
                        else if (template.UseFactorioVersion && ((exportTemplate.ExportMode & ExportMode.Mask) == ExportMode.FactorioVersion))
                        {
                            //Both use Factorio version, templates are equal if Factorio versions are equal
                            return(template.Mod.FactorioVersion == exportTemplate.FactorioVersion);
                        }
                    }
                }
            }

            return(false);
        }
        public static ModpackExportTemplate FromModpack(Modpack modpack, bool includeVersionInfo)
        {
            var mods     = new List <ModExportTemplate>();
            var modpacks = new List <string>();

            foreach (var reference in modpack.Mods)
            {
                ModReference     modReference     = reference as ModReference;
                ModpackReference modpackReference = reference as ModpackReference;

                if (modReference != null)
                {
                    mods.Add(ModExportTemplate.FromMod(modReference.Mod, includeVersionInfo));
                }
                else if (modpackReference != null)
                {
                    modpacks.Add(modpackReference.Modpack.Name);
                }
            }

            return(new ModpackExportTemplate(modpack.Name, mods.ToArray(), modpacks.ToArray()));
        }
예제 #3
0
        private static async Task <ModExportTemplate> AddUniqueModTemplate(ModTemplate template, List <ModExportTemplate> uniqueTemplates)
        {
            bool downloadNewer = template.Include && (template.UseNewestVersion || template.UseFactorioVersion);

            foreach (var exportTemplate in uniqueTemplates)
            {
                if (ModTemplatesEqual(template, exportTemplate, downloadNewer))
                {
                    return(exportTemplate);
                }
            }

            var exportMode = template.ExportMode;

            if (template.Include)
            {
                exportMode = exportMode | ExportMode.Included;
            }
            if (downloadNewer)
            {
                exportMode = exportMode | ExportMode.DownloadNewer;
            }
            var newExportTemplate = new ModExportTemplate(template.Mod, exportMode);

            if (template.Include)
            {
                var tempDir = new DirectoryInfo(App.Instance.TempPath);
                if (!tempDir.Exists)
                {
                    tempDir.Create();
                }

                await newExportTemplate.Mod.ExportFile(tempDir.FullName, newExportTemplate.Uid);
            }

            uniqueTemplates.Add(newExportTemplate);
            return(newExportTemplate);
        }
예제 #4
0
        public static async Task <ExportTemplate> CreateTemplateV2(IEnumerable <ModpackTemplate> modpacks)
        {
            ModExportTemplate.ResetUid();
            ModpackExportTemplate.ResetUid();

            var modExportTemplates     = new List <ModExportTemplate>();
            var modpackExportTemplates = new List <ModpackExportTemplate>();

            var sortedModpacks = ModpackTopologicalSort(modpacks);

            foreach (var modpack in sortedModpacks)
            {
                var modIds     = new List <int>();
                var modpackIds = new List <int>();

                foreach (var mod in modpack.ModTemplates)
                {
                    var template = await AddUniqueModTemplate(mod, modExportTemplates);

                    modIds.Add(template.Uid);
                }

                foreach (var subModpack in modpack.ModpackTemplates)
                {
                    var exportTemplate = modpackExportTemplates.FirstOrDefault(et => et.Modpack == subModpack.Modpack);
                    if (exportTemplate != null)
                    {
                        modpackIds.Add(exportTemplate.Uid);
                    }
                }

                var modpackExportTemplate = new ModpackExportTemplate(modpack.Modpack, modIds.ToArray(), modpackIds.ToArray());
                modpackExportTemplates.Add(modpackExportTemplate);
            }

            return(new ExportTemplate(modExportTemplates.ToArray(), modpackExportTemplates.ToArray()));
        }