diff --git a/SabreTools.DatFiles/DatFile.Splitting.cs b/SabreTools.DatFiles/DatFile.Splitting.cs index 8b4e8ce7..ac0ae633 100644 --- a/SabreTools.DatFiles/DatFile.Splitting.cs +++ b/SabreTools.DatFiles/DatFile.Splitting.cs @@ -109,7 +109,7 @@ namespace SabreTools.DatFiles foreach (string bucket in buckets) { // If the bucket has no items in it - var items = Items[bucket]; + var items = GetItemsForBucket(bucket); if (items == null || items.Count == 0) continue; @@ -124,7 +124,7 @@ namespace SabreTools.DatFiles continue; // If the parent doesn't have any items, we want to continue - var parentItems = Items[romOf!]; + var parentItems = GetItemsForBucket(romOf!); if (parentItems == null || parentItems.Count == 0) continue; @@ -205,7 +205,7 @@ namespace SabreTools.DatFiles foreach (string bucket in buckets) { // If the bucket has no items in it - var items = Items[bucket]; + var items = GetItemsForBucket(bucket); if (items == null || items.Count == 0) continue; @@ -220,7 +220,7 @@ namespace SabreTools.DatFiles continue; // Get the parent items - var parentItems = Items[cloneOf!]; + var parentItems = GetItemsForBucket(cloneOf!); // Otherwise, move the items from the current game to a subfolder of the parent game DatItem copyFrom; @@ -235,7 +235,7 @@ namespace SabreTools.DatFiles copyFrom = parentItems[0]; } - items = Items[bucket]; + items = GetItemsForBucket(bucket); foreach (DatItem item in items!) { // Special disk handling @@ -244,7 +244,7 @@ namespace SabreTools.DatFiles string? mergeTag = disk.GetStringFieldValue(Models.Metadata.Disk.MergeKey); // If the merge tag exists and the parent already contains it, skip - if (mergeTag != null && Items[cloneOf!]! + if (mergeTag != null && GetItemsForBucket(cloneOf!)! .FindAll(i => i is Disk) .ConvertAll(i => (i as Disk)!.GetName()).Contains(mergeTag)) { @@ -252,7 +252,7 @@ namespace SabreTools.DatFiles } // If the merge tag exists but the parent doesn't contain it, add to parent - else if (mergeTag != null && !Items[cloneOf!]! + else if (mergeTag != null && !GetItemsForBucket(cloneOf!)! .FindAll(i => i is Disk) .ConvertAll(i => (i as Disk)!.GetName()).Contains(mergeTag)) { @@ -272,7 +272,7 @@ namespace SabreTools.DatFiles else if (item is Rom rom) { // If the merge tag exists and the parent already contains it, skip - if (rom.GetStringFieldValue(Models.Metadata.Rom.MergeKey) != null && Items[cloneOf!]! + if (rom.GetStringFieldValue(Models.Metadata.Rom.MergeKey) != null && GetItemsForBucket(cloneOf!)! .FindAll(i => i is Rom) .ConvertAll(i => (i as Rom)!.GetName()) .Contains(rom.GetStringFieldValue(Models.Metadata.Rom.MergeKey))) @@ -281,7 +281,7 @@ namespace SabreTools.DatFiles } // If the merge tag exists but the parent doesn't contain it, add to subfolder of parent - else if (rom.GetStringFieldValue(Models.Metadata.Rom.MergeKey) != null && !Items[cloneOf!]! + else if (rom.GetStringFieldValue(Models.Metadata.Rom.MergeKey) != null && !GetItemsForBucket(cloneOf!)! .FindAll(i => i is Rom) .ConvertAll(i => (i as Rom)!.GetName()) .Contains(rom.GetStringFieldValue(Models.Metadata.Rom.MergeKey))) @@ -294,7 +294,7 @@ namespace SabreTools.DatFiles } // If the parent doesn't already contain this item, add to subfolder of parent - else if (!Items[cloneOf!]!.Contains(item) || skipDedup) + else if (!GetItemsForBucket(cloneOf!)!.Contains(item) || skipDedup) { if (subfolder) rom.SetName($"{item.GetFieldValue(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey)}\\{rom.GetName()}"); @@ -305,7 +305,7 @@ namespace SabreTools.DatFiles } // All other that would be missing to subfolder of parent - else if (!Items[cloneOf!]!.Contains(item)) + else if (!GetItemsForBucket(cloneOf!)!.Contains(item)) { if (subfolder) item.SetName($"{item.GetFieldValue(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey)}\\{item.GetName()}"); @@ -472,7 +472,7 @@ namespace SabreTools.DatFiles foreach (string bucket in buckets) { // If the bucket doesn't have items - var datItems = Items[bucket]; + var datItems = GetItemsForBucket(bucket); if (datItems == null || datItems.Count == 0) continue; @@ -510,7 +510,7 @@ namespace SabreTools.DatFiles continue; // Add to the list of new device reference names - var devItems = Items[deviceReference!]; + var devItems = GetItemsForBucket(deviceReference!); if (devItems == null || devItems.Count == 0) continue; @@ -561,7 +561,7 @@ namespace SabreTools.DatFiles continue; // Add to the list of new slot option names - var slotItems = Items[slotOption!]; + var slotItems = GetItemsForBucket(slotOption!); if (slotItems == null || slotItems.Count == 0) continue; @@ -793,7 +793,7 @@ namespace SabreTools.DatFiles foreach (string bucket in buckets) { // If the bucket has no items in it - var items = Items[bucket]; + var items = GetItemsForBucket(bucket); if (items == null || items.Count == 0) continue; @@ -808,7 +808,7 @@ namespace SabreTools.DatFiles continue; // If the parent doesn't have any items, we want to continue - var parentItems = Items[cloneOf!]; + var parentItems = GetItemsForBucket(cloneOf!); if (parentItems == null || parentItems.Count == 0) continue; @@ -826,8 +826,8 @@ namespace SabreTools.DatFiles } // Now we want to get the parent romof tag and put it in each of the items - items = Items[bucket]; - string? romof = Items[cloneOf!]![0].GetFieldValue(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.RomOfKey); + items = GetItemsForBucket(bucket); + string? romof = GetItemsForBucket(cloneOf!)![0].GetFieldValue(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.RomOfKey); foreach (DatItem item in items!) { item.GetFieldValue(DatItem.MachineKey)!.SetFieldValue(Models.Metadata.Machine.RomOfKey, romof); @@ -915,7 +915,7 @@ namespace SabreTools.DatFiles foreach (string bucket in buckets) { // If the bucket has no items in it - var items = Items[bucket]; + var items = GetItemsForBucket(bucket); if (items == null || items.Count == 0) continue; @@ -984,7 +984,7 @@ namespace SabreTools.DatFiles foreach (string bucket in buckets) { // If the bucket has no items in it - var items = Items[bucket]; + var items = GetItemsForBucket(bucket); if (items == null || items.Count == 0) continue; @@ -1003,7 +1003,7 @@ namespace SabreTools.DatFiles continue; // If the parent doesn't have any items, we want to continue - var parentItems = Items[romOf!]; + var parentItems = GetItemsForBucket(romOf!); if (parentItems == null || parentItems.Count == 0) continue; @@ -1084,7 +1084,7 @@ namespace SabreTools.DatFiles foreach (string bucket in buckets) { // If the bucket has no items in it - var items = Items[bucket]; + var items = GetItemsForBucket(bucket); if (items == null || items.Count == 0) continue; @@ -1099,7 +1099,7 @@ namespace SabreTools.DatFiles continue; // If the parent doesn't have any items, we want to continue - var parentItems = Items[cloneOf!]; + var parentItems = GetItemsForBucket(cloneOf!); if (parentItems == null || parentItems.Count == 0) continue; @@ -1114,8 +1114,8 @@ namespace SabreTools.DatFiles } // Now we want to get the parent romof tag and put it in each of the remaining items - items = Items[bucket]; - string? romof = Items[cloneOf!]![0].GetFieldValue(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.RomOfKey); + items = GetItemsForBucket(bucket); + string? romof = GetItemsForBucket(cloneOf!)![0].GetFieldValue(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.RomOfKey); foreach (DatItem item in items!) { item.GetFieldValue(DatItem.MachineKey)!.SetFieldValue(Models.Metadata.Machine.RomOfKey, romof); @@ -1195,7 +1195,7 @@ namespace SabreTools.DatFiles foreach (string bucket in buckets) { // If the bucket has no items in it - var items = Items[bucket]; + var items = GetItemsForBucket(bucket); if (items == null || items.Count == 0) continue; diff --git a/SabreTools.DatFiles/ItemDictionary.cs b/SabreTools.DatFiles/ItemDictionary.cs index ab279e48..b714866b 100644 --- a/SabreTools.DatFiles/ItemDictionary.cs +++ b/SabreTools.DatFiles/ItemDictionary.cs @@ -20,6 +20,7 @@ using SabreTools.Hashing; using SabreTools.IO.Logging; using SabreTools.Matching.Compare; +// TODO: Remove IDictionary implementation namespace SabreTools.DatFiles { /// diff --git a/SabreTools.DatTools/DatFromDir.cs b/SabreTools.DatTools/DatFromDir.cs index c559995e..c0cc85db 100644 --- a/SabreTools.DatTools/DatFromDir.cs +++ b/SabreTools.DatTools/DatFromDir.cs @@ -387,7 +387,7 @@ namespace SabreTools.DatTools blankRom.SetName(romname); blankRom.SetFieldValue(DatItem.MachineKey, blankMachine); - datFile.Items["null"]?.Add(blankRom); + datFile.Add("null", blankRom); #if NET40_OR_GREATER || NETCOREAPP }); #else diff --git a/SabreTools.DatTools/Remover.cs b/SabreTools.DatTools/Remover.cs index b9b3aeac..280086ff 100644 --- a/SabreTools.DatTools/Remover.cs +++ b/SabreTools.DatTools/Remover.cs @@ -168,7 +168,7 @@ namespace SabreTools.DatTools foreach (var key in itemDictionary.Keys) { - List? items = itemDictionary[key]; + List? items = itemDictionary.GetItemsForBucket(key); if (items == null) continue; diff --git a/SabreTools.DatTools/Splitter.cs b/SabreTools.DatTools/Splitter.cs index 0ca95100..0af8f0c8 100644 --- a/SabreTools.DatTools/Splitter.cs +++ b/SabreTools.DatTools/Splitter.cs @@ -797,7 +797,7 @@ namespace SabreTools.DatTools foreach (string machine in keys) { // Get the current machine - var items = datFile.Items[machine]; + var items = datFile.GetItemsForBucket(machine); if (items == null || items.Count == 0) { _staticLogger.Error($"{machine} contains no items and will be skipped");