/// <summary> /// Checks the given mod's contents with all the other mod's contents found in the main mods list. /// </summary> /// <param name="newMod"></param> public void CheckModContents_WithExistingMods(Mod newMod, bool addMod = false) { List <Mod> conflictingMods = new List <Mod>(); //temp list for the conflicting mods List <string> conflictingModNames = new List <string>(); //temp list for the conflicting mods names (for the ui prompt) List <string> conflictingModFiles = new List <string>(); //temp list for the conflicting mods files (for the ui prompt) //loop through the mod list foreach (Mod mod in mods) { //create a boolean that states whether or not the given mod has conflicts bool hasConflictingFiles = false; //loop through the mod files for the current mod in the loop foreach (string file in mod.ModFiles) { //loop through each 'newModFile' and check each one with the given mod 'file' foreach (string newModFile in newMod.ModFiles) { if (file.Equals(newModFile)) { hasConflictingFiles = true; conflictingModFiles.Add(file); } } } //if there are conflicting files, add the current mod and its name to the list if (hasConflictingFiles) { conflictingMods.Add(mod); conflictingModNames.Add(mod.ModDisplayName); } } //if there are conflicting mods if (conflictingMods.Count != 0) { //for prompt ui string conflictingModsMessage = string.Join(", ", conflictingModNames); string conflictingModFilesMessage = string.Join(", ", conflictingModFiles); string finalMessage = string.Format("{0} has conflicts with the following mods! {1}. They share the following files! {2}. Do you want to remove the conflicting mods?", newMod.ModDisplayName, conflictingModsMessage, conflictingModFilesMessage); //notify the user about the conflicts, if they take action (press yes) it will remove the conflicting mods from the list, and removes the respective files and .json files if (MessageBoxes.Error_Confirm(finalMessage, "Mod Conflicts!")) { foreach (Mod mod in conflictingMods) { RemoveModFiles(mod); IOManagement.DeleteFile(mod.ModInfoJson_FilePath); mods.Remove(mod); } } return; } //if everything passes, add the mod (if the boolean on the function call has been set) if (addMod) { ExtractModZipFileContents_ToDirectory(newMod); mods.Add(newMod); } }