diff --git a/SabreTools.DatFiles.Test/DatFileTests.Removal.cs b/SabreTools.DatFiles.Test/DatFileTests.Removal.cs
index beb53a27..5d794d55 100644
--- a/SabreTools.DatFiles.Test/DatFileTests.Removal.cs
+++ b/SabreTools.DatFiles.Test/DatFileTests.Removal.cs
@@ -2,6 +2,35 @@ namespace SabreTools.DatFiles.Test
{
public partial class DatFileTests
{
-
+ #region RemoveHeaderFields
+
+ // TODO: Write RemoveHeaderFields tests
+ // - Null header
+ // - Empty list
+ // - Full list
+
+ #endregion
+
+ #region RemoveItemFields
+
+ // TODO: Write RemoveItemFields tests
+ // - Null item dict
+ // - Both lists empty
+ // - Machine only
+ // - Item only
+ // - Nested
+
+ #endregion
+
+ #region RemoveItemFieldsDB
+
+ // TODO: Write RemoveItemFieldsDB tests
+ // - Null item dict
+ // - Both lists empty
+ // - Machine only
+ // - Item only
+ // - Nested
+
+ #endregion
}
}
\ No newline at end of file
diff --git a/SabreTools.DatFiles/DatFile.Removal.cs b/SabreTools.DatFiles/DatFile.Removal.cs
index c34f2b90..26c1e348 100644
--- a/SabreTools.DatFiles/DatFile.Removal.cs
+++ b/SabreTools.DatFiles/DatFile.Removal.cs
@@ -13,27 +13,29 @@ namespace SabreTools.DatFiles
#region Removal
///
- /// Remove fields indicated by the three input lists
+ /// Remove header fields with given values
///
- public void ApplyRemovals(List headerFieldNames, List machineFieldNames, Dictionary> itemFieldNames)
+ public void RemoveHeaderFields(List headerFieldNames)
{
- // Remove DatHeader fields
- if (headerFieldNames.Count > 0)
- RemoveHeaderFields(headerFieldNames);
+ // If we have an invalid input, return
+ if (Header == null || headerFieldNames.Count == 0)
+ return;
- // Remove DatItem and Machine fields
- if (machineFieldNames.Count > 0 || itemFieldNames.Count > 0)
+ foreach (var fieldName in headerFieldNames)
{
- ApplyRemovalsItemDictionary(machineFieldNames, itemFieldNames);
- ApplyRemovalsItemDictionaryDB(machineFieldNames, itemFieldNames);
+ Header.RemoveField(fieldName);
}
}
///
/// Apply removals to the item dictionary
///
- private void ApplyRemovalsItemDictionary(List machineFieldNames, Dictionary> itemFieldNames)
+ public void RemoveItemFields(List machineFieldNames, Dictionary> itemFieldNames)
{
+ // If we have an invalid input, return
+ if (Items == null || (machineFieldNames.Count == 0 && itemFieldNames.Count == 0))
+ return;
+
#if NET452_OR_GREATER || NETCOREAPP
Parallel.ForEach(Items.Keys, Core.Globals.ParallelOptions, key =>
#elif NET40_OR_GREATER
@@ -64,8 +66,12 @@ namespace SabreTools.DatFiles
///
/// Apply removals to the item dictionary
///
- private void ApplyRemovalsItemDictionaryDB(List machineFieldNames, Dictionary> itemFieldNames)
+ public void RemoveItemFieldsDB(List machineFieldNames, Dictionary> itemFieldNames)
{
+ // If we have an invalid input, return
+ if (ItemsDB == null || (machineFieldNames.Count == 0 && itemFieldNames.Count == 0))
+ return;
+
#if NET452_OR_GREATER || NETCOREAPP
Parallel.ForEach(ItemsDB.SortedKeys, Core.Globals.ParallelOptions, key =>
#elif NET40_OR_GREATER
@@ -94,22 +100,7 @@ namespace SabreTools.DatFiles
}
///
- /// Remove fields with given values
- ///
- private void RemoveHeaderFields(List headerFieldNames)
- {
- // If we have an invalid input, return
- if (Header == null || headerFieldNames.Count == 0)
- return;
-
- foreach (var fieldName in headerFieldNames)
- {
- Header.RemoveField(fieldName);
- }
- }
-
- ///
- /// Remove fields with given values
+ /// Remove machine fields with given values
///
private static void RemoveFields(Machine? machine, List machineFieldNames)
{
diff --git a/SabreTools.DatTools/Remover.cs b/SabreTools.DatTools/Remover.cs
index 1bef7728..d0d85dfc 100644
--- a/SabreTools.DatTools/Remover.cs
+++ b/SabreTools.DatTools/Remover.cs
@@ -130,7 +130,9 @@ namespace SabreTools.DatTools
public void ApplyRemovals(DatFile datFile)
{
InternalStopwatch watch = new("Applying removals to DAT");
- datFile.ApplyRemovals(HeaderFieldNames, MachineFieldNames, ItemFieldNames);
+ datFile.RemoveHeaderFields(HeaderFieldNames);
+ datFile.RemoveItemFields(MachineFieldNames, ItemFieldNames);
+ datFile.RemoveItemFieldsDB(MachineFieldNames, ItemFieldNames);
watch.Stop();
}