private IEnumerable <Mod> GetTargetMods(ModCollection mods, Version factorioVersion) { if (HasVersionRestriction) { if (ExactRestriction) { if (mods.TryGetMod(ModName, ModVersion, out Mod mod)) { return(mod.EnumerateSingle()); } else { return(Enumerable.Empty <Mod>()); } } else { return(mods.Find(ModName, factorioVersion).Where(item => item.Version >= ModVersion)); } } else { return(mods.Find(ModName, factorioVersion)); } }
/// <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); }