diff --git a/SabreTools.Helper/Tools/RomTools.cs b/SabreTools.Helper/Tools/RomTools.cs index 26a10459..e1c71a4e 100644 --- a/SabreTools.Helper/Tools/RomTools.cs +++ b/SabreTools.Helper/Tools/RomTools.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Security.Cryptography; using System.Text.RegularExpressions; @@ -187,8 +188,9 @@ namespace SabreTools.Helper /// /// Rom to use as a base /// DAT to match against + /// True to remove matched roms from the input, false otherwise (default) /// List of matched RomData objects - public static List GetDuplicates(Rom lastrom, Dat datdata) + public static List GetDuplicates(Rom lastrom, Dat datdata, bool remove = false) { List output = new List(); @@ -199,14 +201,27 @@ namespace SabreTools.Helper } // Try to find duplicates - foreach (List roms in datdata.Roms.Values) + List keys = datdata.Roms.Keys.ToList(); + foreach (string key in keys) { + List roms = datdata.Roms[key]; + List left = new List(); foreach (Rom rom in roms) { if (IsDuplicate(rom, lastrom)) { output.Add(rom); } + else + { + left.Add(rom); + } + } + + // If we're in removal mode, replace the list with the new one + if (remove) + { + datdata.Roms[key] = left; } }