[DatFile, DatItem] Add better removal logic

This commit is contained in:
Matt Nadareski
2017-10-31 14:53:02 -07:00
parent 178ddcd7d9
commit 67b7c277b5
2 changed files with 42 additions and 8 deletions

View File

@@ -2534,6 +2534,29 @@ namespace SabreTools.Library.DatFiles
}
}
/// <summary>
/// Remove all items marked for removal from the DAT
/// </summary>
private void RemoveMarkedItems()
{
List<string> keys = Keys;
foreach (string key in keys)
{
List<DatItem> items = this[key];
List<DatItem> newItems = new List<DatItem>();
foreach (DatItem item in items)
{
if (!item.Remove)
{
newItems.Add(item);
}
}
Remove(key);
AddRange(key, newItems);
}
}
/// <summary>
/// Strip the given hash types from the DAT
/// </summary>
@@ -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);
}