예제 #1
0
        private static async Task InitProgramAsync()
        {
            var factory = new GlobalSingletonFactory(ApplicationDirectory, ApplicationDataDirectory);

            Settings = await factory.LoadSettingsAsync();

            (Manager, Locations) = await factory.CreateManagerAsync(Settings);

            Locations.ModsReloaded += async(s, e) =>
            {
                _modpacks = await LoadModpacksAsync();
            };
            _modpacks = await LoadModpacksAsync();
        }
예제 #2
0
        private static async Task <ObservableDictionary <int, Modpack> > LoadModpacksAsync()
        {
            var result = new ObservableDictionary <int, Modpack>();

            string path = Path.Combine(ApplicationDataDirectory.FullName, "modpacks.json");
            var    file = new FileInfo(path);

            if (!file.Exists)
            {
                Log.Verbose("No mopack file found, skipping import");
                return(result);
            }

            var imported = await Importer.ImportAsync(file, TemporaryDirectory.FullName, false);

            var package = imported.Package; // Disregard extracted files since there aren't any

            if ((package is null) || (package.Mods is null))
            {
                Log.Verbose("No mopacks to import");
                return(result);
            }

            // We have to build a lookup table of mods before we can load any modpacks
            var modMappings = new Dictionary <int, Mod>();

            foreach (var modDef in package.Mods)
            {
                // Usually we'd have to take a whole lot of options into account.
                // However since the package we are loading is created very specifically
                // we can skip most of it and read name and version straight away.
                if (Manager.ContainsMod(modDef.Name, modDef.Version, out Mod? mod))
                {
                    modMappings.Add(modDef.Uid, mod);
                }
            }

            foreach (var modpackDef in package.Modpacks)
            {
                var modpack = new Modpack {
                    DisplayName = modpackDef.Name
                };

                // Instead of throwing an error when a mod or modpack is not found we just ignore it.
                // This way people are free to delete mods from within Factorio or even manually without causing a crash.
                foreach (int modId in modpackDef.ModIds)
                {
                    if (modMappings.TryGetValue(modId, out Mod? mod))
                    {
                        modpack.Add(mod);
                    }
                }
                foreach (int modpackId in modpackDef.ModpackIds)
                {
                    if (result.TryGetValue(modpackId, out var subPack))
                    {
                        modpack.Add(subPack);
                    }
                }

                result.Add(modpackDef.Uid, modpack);
                Log.Verbose($"Successfully loaded modpack '{modpack.DisplayName}' with ID {modpackDef.Uid}");
            }

            return(result);
        }
 public ObservableKeyCollection(ObservableDictionary <TKey, TValue> parent, ICollection <TKey> baseCollection)
     : base(parent, baseCollection)
 {
 }
 protected ObservableDictionaryCollection(ObservableDictionary <TKey, TValue> parent, ICollection <T> baseCollection)
 {
     (_parent, _baseCollection) = (parent, baseCollection);
     _parent.CollectionChanged += OnParentCollectionChanged;
 }