Пример #1
0
 private static void LoadModsFromFileDictionary(Dictionary <string, ModFileCollection> fileDictionary, ModCollection parentCollection, ModpackCollection modpackCollection)
 {
     foreach (var modFileList in fileDictionary.Select(kvp => kvp.Value))
     {
         var mod = new Mod(modFileList, parentCollection, modpackCollection);
         parentCollection.Add(mod);
     }
 }
Пример #2
0
        /// <summary>
        /// Adds a mod to the managed mod directory.
        /// </summary>
        /// <param name="file">The mod file to be added.</param>
        /// <param name="parentCollection">The mod collection.</param>
        /// <param name="modpackCollection">The modpack collection.</param>
        /// <param name="copy">Specifies if the mod file should be copied or moved.</param>
        /// <param name="silent">Specifies if messages should be displayed.</param>
        /// <returns>Returns the added mod, or an existing mod if the mod that was tried to be added already existed in the managed mod directory.</returns>
        public static async Task <Mod> Add(ModFile file, ModCollection parentCollection, ModpackCollection modpackCollection, bool copy, bool silent = false)
        {
            var infoFile = file.InfoFile;

            if (parentCollection.TryGetMod(infoFile.Name, infoFile.Version, out Mod existingMod))
            {
                if (!silent)
                {
                    ShowModExistsMessage(infoFile);
                }
                return(existingMod);
            }

            if (!file.ResidesInModDirectory)
            {
                var modDirectory = App.Instance.Settings.GetModDirectory(infoFile.FactorioVersion);
                if (!modDirectory.Exists)
                {
                    modDirectory.Create();
                }

                if (copy)
                {
                    file = await file.CopyToAsync(modDirectory.FullName);
                }
                else
                {
                    await file.MoveToAsync(modDirectory.FullName);
                }
            }

            var newMod = new Mod(file, parentCollection, modpackCollection);

            parentCollection.Add(newMod);
            return(newMod);
        }