Update both naming and remarks for clarity

This commit is contained in:
Matt Nadareski
2025-01-13 09:24:16 -05:00
parent 31aa6a6478
commit 3dfd8a38b0

View File

@@ -97,15 +97,16 @@ namespace SabreTools.DatFiles
/// <summary> /// <summary>
/// Use romof tags to add roms to the children /// Use romof tags to add roms to the children
/// </summary> /// </summary>
/// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks>
private void AddRomsFromBiosImpl() private void AddRomsFromBiosImpl()
{ {
List<string> games = [.. Items.Keys]; List<string> buckets = [.. Items.Keys];
games.Sort(); buckets.Sort();
foreach (string game in games) foreach (string bucket in buckets)
{ {
// If the game has no items in it, we want to continue // If the bucket has no items in it
var items = Items[game]; var items = Items[bucket];
if (items == null || items.Count == 0) if (items == null || items.Count == 0)
continue; continue;
@@ -131,7 +132,7 @@ namespace SabreTools.DatFiles
DatItem datItem = (DatItem)item.Clone(); DatItem datItem = (DatItem)item.Clone();
datItem.CopyMachineInformation(copyFrom); datItem.CopyMachineInformation(copyFrom);
if (items.FindIndex(i => i.GetName() == datItem.GetName()) == -1 && !items.Contains(datItem)) if (items.FindIndex(i => i.GetName() == datItem.GetName()) == -1 && !items.Contains(datItem))
Add(game, datItem); Add(bucket, datItem);
} }
} }
} }
@@ -139,13 +140,14 @@ namespace SabreTools.DatFiles
/// <summary> /// <summary>
/// Use romof tags to add roms to the children /// Use romof tags to add roms to the children
/// </summary> /// </summary>
/// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks>
private void AddRomsFromBiosImplDB() private void AddRomsFromBiosImplDB()
{ {
List<string> games = [.. ItemsDB.SortedKeys]; List<string> buckets = [.. ItemsDB.SortedKeys];
foreach (string game in games) foreach (string bucket in buckets)
{ {
// Get the items for this game // If the bucket has no items in it
var items = GetItemsForBucketDB(game); var items = GetItemsForBucketDB(bucket);
if (items == null || items.Count == 0) if (items == null || items.Count == 0)
continue; continue;
@@ -185,15 +187,16 @@ namespace SabreTools.DatFiles
/// </summary> /// </summary>
/// <param name="subfolder">True to add DatItems to subfolder of parent (not including Disk), false otherwise</param> /// <param name="subfolder">True to add DatItems to subfolder of parent (not including Disk), false otherwise</param>
/// <param name="skipDedup">True to skip checking for duplicate ROMs in parent, false otherwise</param> /// <param name="skipDedup">True to skip checking for duplicate ROMs in parent, false otherwise</param>
/// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks>
private void AddRomsFromChildrenImpl(bool subfolder, bool skipDedup) private void AddRomsFromChildrenImpl(bool subfolder, bool skipDedup)
{ {
List<string> games = [.. Items.Keys]; List<string> buckets = [.. Items.Keys];
games.Sort(); buckets.Sort();
foreach (string game in games) foreach (string bucket in buckets)
{ {
// If the game has no items in it, we want to continue // If the bucket has no items in it
var items = Items[game]; var items = Items[bucket];
if (items == null || items.Count == 0) if (items == null || items.Count == 0)
continue; continue;
@@ -223,7 +226,7 @@ namespace SabreTools.DatFiles
copyFrom = parentItems[0]; copyFrom = parentItems[0];
} }
items = Items[game]; items = Items[bucket];
foreach (DatItem item in items!) foreach (DatItem item in items!)
{ {
// Special disk handling // Special disk handling
@@ -304,7 +307,7 @@ namespace SabreTools.DatFiles
} }
// Then, remove the old game so it's not picked up by the writer // Then, remove the old game so it's not picked up by the writer
Remove(game); Remove(bucket);
} }
} }
@@ -313,13 +316,14 @@ namespace SabreTools.DatFiles
/// </summary> /// </summary>
/// <param name="subfolder">True to add DatItems to subfolder of parent (not including Disk), false otherwise</param> /// <param name="subfolder">True to add DatItems to subfolder of parent (not including Disk), false otherwise</param>
/// <param name="skipDedup">True to skip checking for duplicate ROMs in parent, false otherwise</param> /// <param name="skipDedup">True to skip checking for duplicate ROMs in parent, false otherwise</param>
/// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks>
private void AddRomsFromChildrenImplDB(bool subfolder, bool skipDedup) private void AddRomsFromChildrenImplDB(bool subfolder, bool skipDedup)
{ {
List<string> games = [.. ItemsDB.SortedKeys]; List<string> buckets = [.. ItemsDB.SortedKeys];
foreach (string game in games) foreach (string bucket in buckets)
{ {
// If the game has no items in it, we want to continue // If the bucket has no items in it
var items = GetItemsForBucketDB(game); var items = GetItemsForBucketDB(bucket);
if (items == null || items.Count == 0) if (items == null || items.Count == 0)
continue; continue;
@@ -338,7 +342,7 @@ namespace SabreTools.DatFiles
if (cloneOfMachine.Value == null) if (cloneOfMachine.Value == null)
continue; continue;
items = GetItemsForBucketDB(game); items = GetItemsForBucketDB(bucket);
foreach (var item in items) foreach (var item in items)
{ {
// Get the parent items and current machine name // Get the parent items and current machine name
@@ -430,9 +434,9 @@ namespace SabreTools.DatFiles
// Then, remove the old game so it's not picked up by the writer // Then, remove the old game so it's not picked up by the writer
#if NET40_OR_GREATER || NETCOREAPP #if NET40_OR_GREATER || NETCOREAPP
ItemsDB._buckets.TryRemove(game, out _); ItemsDB._buckets.TryRemove(bucket, out _);
#else #else
ItemsDB._buckets.Remove(game); ItemsDB._buckets.Remove(bucket);
#endif #endif
} }
} }
@@ -442,16 +446,18 @@ namespace SabreTools.DatFiles
/// </summary> /// </summary>
/// <param name="dev">True if only child device sets are touched, false for non-device sets (default)</param> /// <param name="dev">True if only child device sets are touched, false for non-device sets (default)</param>
/// <param name="useSlotOptions">True if slotoptions tags are used as well, false otherwise</param> /// <param name="useSlotOptions">True if slotoptions tags are used as well, false otherwise</param>
/// <returns>True if any items were processed, false otherwise</returns>
/// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks>
private bool AddRomsFromDevicesImpl(bool dev, bool useSlotOptions) private bool AddRomsFromDevicesImpl(bool dev, bool useSlotOptions)
{ {
bool foundnew = false; bool foundnew = false;
List<string> machines = [.. Items.Keys]; List<string> buckets = [.. Items.Keys];
machines.Sort(); buckets.Sort();
foreach (string machine in machines) foreach (string bucket in buckets)
{ {
// If the machine doesn't have items, we continue // If the bucket doesn't have items
var datItems = Items[machine]; var datItems = Items[bucket];
if (datItems == null || datItems.Count == 0) if (datItems == null || datItems.Count == 0)
continue; continue;
@@ -510,7 +516,7 @@ namespace SabreTools.DatFiles
// Clone the item and then add it // Clone the item and then add it
DatItem datItem = (DatItem)item.Clone(); DatItem datItem = (DatItem)item.Clone();
datItem.CopyMachineInformation(copyFrom); datItem.CopyMachineInformation(copyFrom);
Add(machine, datItem); Add(bucket, datItem);
} }
} }
} }
@@ -563,7 +569,7 @@ namespace SabreTools.DatFiles
// Clone the item and then add it // Clone the item and then add it
DatItem datItem = (DatItem)item.Clone(); DatItem datItem = (DatItem)item.Clone();
datItem.CopyMachineInformation(copyFrom); datItem.CopyMachineInformation(copyFrom);
Add(machine, datItem); Add(bucket, datItem);
} }
} }
} }
@@ -593,14 +599,16 @@ namespace SabreTools.DatFiles
/// </summary> /// </summary>
/// <param name="dev">True if only child device sets are touched, false for non-device sets</param> /// <param name="dev">True if only child device sets are touched, false for non-device sets</param>
/// <param name="useSlotOptions">True if slotoptions tags are used as well, false otherwise</param> /// <param name="useSlotOptions">True if slotoptions tags are used as well, false otherwise</param>
/// <returns>True if any items were processed, false otherwise</returns>
/// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks>
private bool AddRomsFromDevicesImplDB(bool dev, bool useSlotOptions) private bool AddRomsFromDevicesImplDB(bool dev, bool useSlotOptions)
{ {
bool foundnew = false; bool foundnew = false;
List<string> games = [.. ItemsDB.SortedKeys]; List<string> buckets = [.. ItemsDB.SortedKeys];
foreach (string game in games) foreach (string bucket in buckets)
{ {
// If the game has no items in it, we want to continue // If the bucket has no items in it
var items = GetItemsForBucketDB(game); var items = GetItemsForBucketDB(bucket);
if (items == null || items.Count == 0) if (items == null || items.Count == 0)
continue; continue;
@@ -712,7 +720,7 @@ namespace SabreTools.DatFiles
.Select(o => o.GetStringFieldValue(Models.Metadata.SlotOption.DevNameKey)!)); .Select(o => o.GetStringFieldValue(Models.Metadata.SlotOption.DevNameKey)!));
// Set new machine information and add to the current machine // Set new machine information and add to the current machine
var copyFrom = ItemsDB.GetMachineForItem(GetItemsForBucketDB(game)!.First().Key); var copyFrom = ItemsDB.GetMachineForItem(GetItemsForBucketDB(bucket)!.First().Key);
if (copyFrom.Value == null) if (copyFrom.Value == null)
continue; continue;
@@ -755,15 +763,16 @@ namespace SabreTools.DatFiles
/// <summary> /// <summary>
/// Use cloneof tags to add roms to the children, setting the new romof tag in the process /// Use cloneof tags to add roms to the children, setting the new romof tag in the process
/// </summary> /// </summary>
/// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks>
private void AddRomsFromParentImpl() private void AddRomsFromParentImpl()
{ {
List<string> games = [.. Items.Keys]; List<string> buckets = [.. Items.Keys];
games.Sort(); buckets.Sort();
foreach (string game in games) foreach (string bucket in buckets)
{ {
// If the game has no items in it, we want to continue // If the bucket has no items in it
var items = Items[game]; var items = Items[bucket];
if (items == null || items.Count == 0) if (items == null || items.Count == 0)
continue; continue;
@@ -791,12 +800,12 @@ namespace SabreTools.DatFiles
if (items.FindIndex(i => string.Equals(i.GetName(), datItem.GetName(), StringComparison.OrdinalIgnoreCase)) == -1 if (items.FindIndex(i => string.Equals(i.GetName(), datItem.GetName(), StringComparison.OrdinalIgnoreCase)) == -1
&& !items.Contains(datItem)) && !items.Contains(datItem))
{ {
Add(game, datItem); Add(bucket, datItem);
} }
} }
// Now we want to get the parent romof tag and put it in each of the items // Now we want to get the parent romof tag and put it in each of the items
items = Items[game]; items = Items[bucket];
string? romof = Items[cloneOf!]![0].GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.RomOfKey); string? romof = Items[cloneOf!]![0].GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.RomOfKey);
foreach (DatItem item in items!) foreach (DatItem item in items!)
{ {
@@ -808,13 +817,14 @@ namespace SabreTools.DatFiles
/// <summary> /// <summary>
/// Use cloneof tags to add roms to the children, setting the new romof tag in the process /// Use cloneof tags to add roms to the children, setting the new romof tag in the process
/// </summary> /// </summary>
/// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks>
private void AddRomsFromParentImplDB() private void AddRomsFromParentImplDB()
{ {
List<string> games = [.. ItemsDB.SortedKeys]; List<string> buckets = [.. ItemsDB.SortedKeys];
foreach (string game in games) foreach (string bucket in buckets)
{ {
// If the game has no items in it, we want to continue // If the bucket has no items in it
var items = GetItemsForBucketDB(game); var items = GetItemsForBucketDB(bucket);
if (items == null || items.Count == 0) if (items == null || items.Count == 0)
continue; continue;
@@ -853,7 +863,7 @@ namespace SabreTools.DatFiles
continue; continue;
// Now we want to get the parent romof tag and put it in each of the items // Now we want to get the parent romof tag and put it in each of the items
items = GetItemsForBucketDB(game); items = GetItemsForBucketDB(bucket);
string? romof = parentMachine.Value.GetStringFieldValue(Models.Metadata.Machine.RomOfKey); string? romof = parentMachine.Value.GetStringFieldValue(Models.Metadata.Machine.RomOfKey);
foreach (var key in items.Keys) foreach (var key in items.Keys)
{ {
@@ -869,15 +879,16 @@ namespace SabreTools.DatFiles
/// <summary> /// <summary>
/// Remove all BIOS and device sets /// Remove all BIOS and device sets
/// </summary> /// </summary>
/// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks>
private void RemoveBiosAndDeviceSetsImpl() private void RemoveBiosAndDeviceSetsImpl()
{ {
List<string> games = [.. Items.Keys]; List<string> buckets = [.. Items.Keys];
games.Sort(); buckets.Sort();
foreach (string game in games) foreach (string bucket in buckets)
{ {
// If the game has no items in it, we want to continue // If the bucket has no items in it
var items = Items[game]; var items = Items[bucket];
if (items == null || items.Count == 0) if (items == null || items.Count == 0)
continue; continue;
@@ -890,7 +901,7 @@ namespace SabreTools.DatFiles
if ((machine.GetBoolFieldValue(Models.Metadata.Machine.IsBiosKey) == true) if ((machine.GetBoolFieldValue(Models.Metadata.Machine.IsBiosKey) == true)
|| (machine.GetBoolFieldValue(Models.Metadata.Machine.IsDeviceKey) == true)) || (machine.GetBoolFieldValue(Models.Metadata.Machine.IsDeviceKey) == true))
{ {
Remove(game); Remove(bucket);
} }
} }
} }
@@ -898,13 +909,14 @@ namespace SabreTools.DatFiles
/// <summary> /// <summary>
/// Remove all BIOS and device sets /// Remove all BIOS and device sets
/// </summary> /// </summary>
/// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks>
private void RemoveBiosAndDeviceSetsImplDB() private void RemoveBiosAndDeviceSetsImplDB()
{ {
List<string> games = [.. ItemsDB.SortedKeys]; List<string> buckets = [.. ItemsDB.SortedKeys];
foreach (string game in games) foreach (string bucket in buckets)
{ {
// If the game has no items in it, we want to continue // If the bucket has no items in it
var items = GetItemsForBucketDB(game); var items = GetItemsForBucketDB(bucket);
if (items == null || items.Count == 0) if (items == null || items.Count == 0)
continue; continue;
@@ -929,16 +941,17 @@ namespace SabreTools.DatFiles
/// Use romof tags to remove bios roms from children /// Use romof tags to remove bios roms from children
/// </summary> /// </summary>
/// <param name="bios">True if only child Bios sets are touched, false for non-bios sets</param> /// <param name="bios">True if only child Bios sets are touched, false for non-bios sets</param>
/// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks>
private void RemoveBiosRomsFromChildImpl(bool bios) private void RemoveBiosRomsFromChildImpl(bool bios)
{ {
// Loop through the romof tags // Loop through the romof tags
List<string> games = [.. Items.Keys]; List<string> buckets = [.. Items.Keys];
games.Sort(); buckets.Sort();
foreach (string game in games) foreach (string bucket in buckets)
{ {
// If the game has no items in it, we want to continue // If the bucket has no items in it
var items = Items[game]; var items = Items[bucket];
if (items == null || items.Count == 0) if (items == null || items.Count == 0)
continue; continue;
@@ -967,7 +980,7 @@ namespace SabreTools.DatFiles
DatItem datItem = (DatItem)item.Clone(); DatItem datItem = (DatItem)item.Clone();
while (items.Contains(datItem)) while (items.Contains(datItem))
{ {
Items.Remove(game, datItem); Items.Remove(bucket, datItem);
} }
} }
} }
@@ -977,14 +990,15 @@ namespace SabreTools.DatFiles
/// Use romof tags to remove bios roms from children /// Use romof tags to remove bios roms from children
/// </summary> /// </summary>
/// <param name="bios">True if only child Bios sets are touched, false for non-bios sets</param> /// <param name="bios">True if only child Bios sets are touched, false for non-bios sets</param>
/// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks>
internal void RemoveBiosRomsFromChildImplDB(bool bios) internal void RemoveBiosRomsFromChildImplDB(bool bios)
{ {
// Loop through the romof tags // Loop through the romof tags
List<string> games = [.. ItemsDB.SortedKeys]; List<string> buckets = [.. ItemsDB.SortedKeys];
foreach (string game in games) foreach (string bucket in buckets)
{ {
// If the game has no items in it, we want to continue // If the bucket has no items in it
var items = GetItemsForBucketDB(game); var items = GetItemsForBucketDB(bucket);
if (items == null || items.Count == 0) if (items == null || items.Count == 0)
continue; continue;
@@ -1022,15 +1036,16 @@ namespace SabreTools.DatFiles
/// <summary> /// <summary>
/// Use cloneof tags to remove roms from the children /// Use cloneof tags to remove roms from the children
/// </summary> /// </summary>
/// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks>
private void RemoveRomsFromChildImpl() private void RemoveRomsFromChildImpl()
{ {
List<string> games = [.. Items.Keys]; List<string> buckets = [.. Items.Keys];
games.Sort(); buckets.Sort();
foreach (string game in games) foreach (string bucket in buckets)
{ {
// If the game has no items in it, we want to continue // If the bucket has no items in it
var items = Items[game]; var items = Items[bucket];
if (items == null || items.Count == 0) if (items == null || items.Count == 0)
continue; continue;
@@ -1055,12 +1070,12 @@ namespace SabreTools.DatFiles
DatItem datItem = (DatItem)item.Clone(); DatItem datItem = (DatItem)item.Clone();
while (items.Contains(datItem)) while (items.Contains(datItem))
{ {
Items.Remove(game, datItem); Items.Remove(bucket, datItem);
} }
} }
// Now we want to get the parent romof tag and put it in each of the remaining items // Now we want to get the parent romof tag and put it in each of the remaining items
items = Items[game]; items = Items[bucket];
string? romof = Items[cloneOf!]![0].GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.RomOfKey); string? romof = Items[cloneOf!]![0].GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.RomOfKey);
foreach (DatItem item in items!) foreach (DatItem item in items!)
{ {
@@ -1072,13 +1087,14 @@ namespace SabreTools.DatFiles
/// <summary> /// <summary>
/// Use cloneof tags to remove roms from the children /// Use cloneof tags to remove roms from the children
/// </summary> /// </summary>
/// <remarks>Assumes items are bucketed by <see cref="ItemKey.Machine"/></remarks>
internal void RemoveRomsFromChildImplDB() internal void RemoveRomsFromChildImplDB()
{ {
List<string> games = [.. ItemsDB.SortedKeys]; List<string> buckets = [.. ItemsDB.SortedKeys];
foreach (string game in games) foreach (string bucket in buckets)
{ {
// If the game has no items in it, we want to continue // If the bucket has no items in it
var items = GetItemsForBucketDB(game); var items = GetItemsForBucketDB(bucket);
if (items == null || items.Count == 0) if (items == null || items.Count == 0)
continue; continue;
@@ -1108,7 +1124,7 @@ namespace SabreTools.DatFiles
} }
// Now we want to get the parent romof tag and put it in each of the remaining items // Now we want to get the parent romof tag and put it in each of the remaining items
items = GetItemsForBucketDB(game); items = GetItemsForBucketDB(bucket);
machine = ItemsDB.GetMachineForItem(GetItemsForBucketDB(cloneOf!)!.First().Key); machine = ItemsDB.GetMachineForItem(GetItemsForBucketDB(cloneOf!)!.First().Key);
if (machine.Value == null) if (machine.Value == null)
continue; continue;
@@ -1131,13 +1147,13 @@ namespace SabreTools.DatFiles
/// <remarks>Applies to <see cref="Items"/></remarks> /// <remarks>Applies to <see cref="Items"/></remarks>
private void RemoveMachineRelationshipTagsImpl() private void RemoveMachineRelationshipTagsImpl()
{ {
List<string> games = [.. Items.Keys]; List<string> buckets = [.. Items.Keys];
games.Sort(); buckets.Sort();
foreach (string game in games) foreach (string bucket in buckets)
{ {
// If the game has no items in it, we want to continue // If the bucket has no items in it
var items = Items[game]; var items = Items[bucket];
if (items == null || items.Count == 0) if (items == null || items.Count == 0)
continue; continue;