diff --git a/SabreTools.Library/DatFiles/DatFile.cs b/SabreTools.Library/DatFiles/DatFile.cs
index cbf8010c..df96ed88 100644
--- a/SabreTools.Library/DatFiles/DatFile.cs
+++ b/SabreTools.Library/DatFiles/DatFile.cs
@@ -2534,6 +2534,29 @@ namespace SabreTools.Library.DatFiles
}
}
+ ///
+ /// Remove all items marked for removal from the DAT
+ ///
+ private void RemoveMarkedItems()
+ {
+ List keys = Keys;
+ foreach (string key in keys)
+ {
+ List items = this[key];
+ List newItems = new List();
+ foreach (DatItem item in items)
+ {
+ if (!item.Remove)
+ {
+ newItems.Add(item);
+ }
+ }
+
+ Remove(key);
+ AddRange(key, newItems);
+ }
+ }
+
///
/// Strip the given hash types from the DAT
///
@@ -4031,6 +4054,7 @@ namespace SabreTools.Library.DatFiles
FileName = "fixDAT_" + FileName;
Name = "fixDAT_" + Name;
Description = "fixDAT_" + Description;
+ RemoveMarkedItems();
WriteToFile(outDir);
}
@@ -4178,6 +4202,7 @@ namespace SabreTools.Library.DatFiles
FileName = "fixDAT_" + FileName;
Name = "fixDAT_" + Name;
Description = "fixDAT_" + Description;
+ RemoveMarkedItems();
WriteToFile(outDir);
}
diff --git a/SabreTools.Library/Items/DatItem.cs b/SabreTools.Library/Items/DatItem.cs
index 36a63427..0b1fce40 100644
--- a/SabreTools.Library/Items/DatItem.cs
+++ b/SabreTools.Library/Items/DatItem.cs
@@ -23,7 +23,7 @@ namespace SabreTools.Library.Items
// Standard item information
protected string _name;
- private string _merge;
+ protected string _merge;
protected ItemType _itemType;
protected DupeType _dupeType;
@@ -45,6 +45,7 @@ namespace SabreTools.Library.Items
protected string _systemName;
protected int _sourceId;
protected string _sourceName;
+ protected bool _remove;
#endregion
@@ -431,6 +432,11 @@ namespace SabreTools.Library.Items
get { return _sourceName; }
set { _sourceName = value; }
}
+ public bool Remove
+ {
+ get { return _remove; }
+ set { _remove = value; }
+ }
#endregion
@@ -582,7 +588,7 @@ namespace SabreTools.Library.Items
/// List all duplicates found in a DAT based on a rom
///
/// Dat to match against
- /// True to remove matched roms from the input, false otherwise (default)
+ /// True to mark matched roms for removal from the input, false otherwise (default)
/// True if the DAT is already sorted accordingly, false otherwise (default)
/// List of matched DatItem objects
public List GetDuplicates(DatFile datdata, bool remove = false, bool sorted = false)
@@ -607,23 +613,26 @@ namespace SabreTools.Library.Items
// Try to find duplicates
List roms = datdata[key];
List left = new List();
-
- foreach (DatItem rom in roms)
+ for (int i = 0; i < roms.Count; i++)
{
- if (this.Equals(rom))
+ DatItem datItem = roms[i];
+
+ if (this.Equals(datItem))
{
- output.Add(rom);
+ datItem.Remove = true;
+ output.Add(datItem);
}
else
{
- left.Add(rom);
+ left.Add(datItem);
}
}
- // If we're in removal mode, replace the list with the new one
+ // If we're in removal mode, add back all roms with the proper flags
if (remove)
{
datdata.Remove(key);
+ datdata.AddRange(key, output);
datdata.AddRange(key, left);
}