private static void AddFileToDictionary(Dictionary <string, ModFileCollection> dictionary, FileSystemInfo file) { if (ModFile.TryLoad(file, out var modFile)) { string key = $"{modFile.Name}_{modFile.Version}"; ModFileCollection collection; if (!dictionary.TryGetValue(key, out collection)) { collection = new ModFileCollection(); dictionary.Add(key, collection); } collection.Add(modFile); } }
private static bool TryLoadVersion(DirectoryInfo directory, out Version Version) { Version = null; var baseModDir = new DirectoryInfo(Path.Combine(directory.FullName, @"data\base")); if (!baseModDir.Exists) { return(false); } ModFile modFile; if (!ModFile.TryLoadFromDirectory(baseModDir, out modFile)) { return(false); } Version = modFile.Version; return(modFile.Name == "base"); }
/// <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); }
/// <summary> /// Adds a mod to the managed mod directory. /// </summary> /// <param name="archiveFile">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="hasUid">Specifies if the mod file to be added contains a UID in its name.</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(FileInfo archiveFile, ModCollection parentCollection, ModpackCollection modpackCollection, bool copy, bool hasUid = false, bool silent = false) { if (ModFile.TryLoadFromFile(archiveFile, out var modFile, hasUid)) { return(await Add(modFile, parentCollection, modpackCollection, copy, silent)); }