mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Remove public add-to-key functionality
This commit is contained in:
@@ -102,11 +102,11 @@ namespace SabreTools.DatFiles
|
||||
Dictionary<string, string> mapping = [];
|
||||
#endif
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
Parallel.ForEach(Items.Keys, Globals.ParallelOptions, key =>
|
||||
Parallel.ForEach(Items.SortedKeys, Globals.ParallelOptions, key =>
|
||||
#elif NET40_OR_GREATER
|
||||
Parallel.ForEach(Items.Keys, key =>
|
||||
Parallel.ForEach(Items.SortedKeys, key =>
|
||||
#else
|
||||
foreach (var key in Items.Keys)
|
||||
foreach (var key in Items.SortedKeys)
|
||||
#endif
|
||||
{
|
||||
var items = GetItemsForBucket(key);
|
||||
@@ -191,7 +191,7 @@ namespace SabreTools.DatFiles
|
||||
/// <remarks>Applies to <see cref="Items"/></remarks>
|
||||
private void ExecuteFiltersImpl(FilterRunner filterRunner)
|
||||
{
|
||||
List<string> keys = [.. Items.Keys];
|
||||
List<string> keys = [.. Items.SortedKeys];
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
Parallel.ForEach(keys, Core.Globals.ParallelOptions, key =>
|
||||
#elif NET40_OR_GREATER
|
||||
@@ -327,7 +327,7 @@ namespace SabreTools.DatFiles
|
||||
|
||||
// Then we want to get a mapping of all machines to parents
|
||||
Dictionary<string, List<string>> parents = [];
|
||||
foreach (string key in Items.Keys)
|
||||
foreach (string key in Items.SortedKeys)
|
||||
{
|
||||
DatItem item = GetItemsForBucket(key)[0];
|
||||
|
||||
@@ -389,7 +389,7 @@ namespace SabreTools.DatFiles
|
||||
parents[key].Remove(machine);
|
||||
|
||||
// Remove the rest of the items from this key
|
||||
parents[key].ForEach(k => Remove(k));
|
||||
parents[key].ForEach(k => RemoveBucket(k));
|
||||
}
|
||||
|
||||
// Finally, strip out the parent tags
|
||||
@@ -483,11 +483,11 @@ namespace SabreTools.DatFiles
|
||||
{
|
||||
// For each rom, we want to update the game to be "<game name>/<rom name>"
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
Parallel.ForEach(Items.Keys, Globals.ParallelOptions, key =>
|
||||
Parallel.ForEach(Items.SortedKeys, Globals.ParallelOptions, key =>
|
||||
#elif NET40_OR_GREATER
|
||||
Parallel.ForEach(Items.Keys, key =>
|
||||
Parallel.ForEach(Items.SortedKeys, key =>
|
||||
#else
|
||||
foreach (var key in Items.Keys)
|
||||
foreach (var key in Items.SortedKeys)
|
||||
#endif
|
||||
{
|
||||
var items = GetItemsForBucket(key);
|
||||
@@ -640,11 +640,11 @@ namespace SabreTools.DatFiles
|
||||
{
|
||||
// Now process all of the roms
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
Parallel.ForEach(Items.Keys, Globals.ParallelOptions, key =>
|
||||
Parallel.ForEach(Items.SortedKeys, Globals.ParallelOptions, key =>
|
||||
#elif NET40_OR_GREATER
|
||||
Parallel.ForEach(Items.Keys, key =>
|
||||
Parallel.ForEach(Items.SortedKeys, key =>
|
||||
#else
|
||||
foreach (var key in Items.Keys)
|
||||
foreach (var key in Items.SortedKeys)
|
||||
#endif
|
||||
{
|
||||
var items = GetItemsForBucket(key);
|
||||
@@ -725,11 +725,11 @@ namespace SabreTools.DatFiles
|
||||
private void UpdateMachineNamesFromDescriptions(IDictionary<string, string> mapping)
|
||||
{
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
Parallel.ForEach(Items.Keys, Globals.ParallelOptions, key =>
|
||||
Parallel.ForEach(Items.SortedKeys, Globals.ParallelOptions, key =>
|
||||
#elif NET40_OR_GREATER
|
||||
Parallel.ForEach(Items.Keys, key =>
|
||||
Parallel.ForEach(Items.SortedKeys, key =>
|
||||
#else
|
||||
foreach (var key in Items.Keys)
|
||||
foreach (var key in Items.SortedKeys)
|
||||
#endif
|
||||
{
|
||||
var items = GetItemsForBucket(key);
|
||||
|
||||
@@ -240,7 +240,7 @@ namespace SabreTools.DatFiles
|
||||
/// </remarks>
|
||||
private void AddItemsFromChildrenImpl(bool subfolder, bool skipDedup)
|
||||
{
|
||||
List<string> buckets = [.. Items.Keys];
|
||||
List<string> buckets = [.. Items.SortedKeys];
|
||||
buckets.Sort();
|
||||
|
||||
foreach (string bucket in buckets)
|
||||
@@ -298,14 +298,14 @@ namespace SabreTools.DatFiles
|
||||
.Contains(mergeTag))
|
||||
{
|
||||
disk.CopyMachineInformation(copyFrom);
|
||||
Add(cloneOf, disk);
|
||||
AddItem(disk, statsOnly: false);
|
||||
}
|
||||
|
||||
// If there is no merge tag, add to parent
|
||||
else if (mergeTag == null)
|
||||
{
|
||||
disk.CopyMachineInformation(copyFrom);
|
||||
Add(cloneOf, disk);
|
||||
AddItem(disk, statsOnly: false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,7 +331,7 @@ namespace SabreTools.DatFiles
|
||||
rom.SetName($"{rom.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey)}\\{rom.GetName()}");
|
||||
|
||||
rom.CopyMachineInformation(copyFrom);
|
||||
Add(cloneOf, rom);
|
||||
AddItem(rom, statsOnly: false);
|
||||
}
|
||||
|
||||
// If the parent doesn't already contain this item, add to subfolder of parent
|
||||
@@ -341,7 +341,7 @@ namespace SabreTools.DatFiles
|
||||
rom.SetName($"{item.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey)}\\{rom.GetName()}");
|
||||
|
||||
rom.CopyMachineInformation(copyFrom);
|
||||
Add(cloneOf, rom);
|
||||
AddItem(rom, statsOnly: false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -352,12 +352,12 @@ namespace SabreTools.DatFiles
|
||||
item.SetName($"{item.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey)}\\{item.GetName()}");
|
||||
|
||||
item.CopyMachineInformation(copyFrom);
|
||||
Add(cloneOf, item);
|
||||
AddItem(item, statsOnly: false);
|
||||
}
|
||||
}
|
||||
|
||||
// Then, remove the old game so it's not picked up by the writer
|
||||
Remove(bucket);
|
||||
RemoveBucket(bucket);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -503,7 +503,7 @@ namespace SabreTools.DatFiles
|
||||
/// </remarks>
|
||||
private void AddItemsFromCloneOfParentImpl()
|
||||
{
|
||||
List<string> buckets = [.. Items.Keys];
|
||||
List<string> buckets = [.. Items.SortedKeys];
|
||||
buckets.Sort();
|
||||
|
||||
foreach (string bucket in buckets)
|
||||
@@ -533,7 +533,7 @@ namespace SabreTools.DatFiles
|
||||
if (!items.Exists(i => string.Equals(i.GetName(), datItem.GetName(), StringComparison.OrdinalIgnoreCase))
|
||||
&& !items.Contains(datItem))
|
||||
{
|
||||
Add(bucket, datItem);
|
||||
AddItem(datItem, statsOnly: false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -625,7 +625,7 @@ namespace SabreTools.DatFiles
|
||||
private bool AddItemsFromDevicesImpl(bool deviceOnly, bool useSlotOptions)
|
||||
{
|
||||
bool foundnew = false;
|
||||
List<string> buckets = [.. Items.Keys];
|
||||
List<string> buckets = [.. Items.SortedKeys];
|
||||
buckets.Sort();
|
||||
|
||||
foreach (string bucket in buckets)
|
||||
@@ -686,7 +686,7 @@ namespace SabreTools.DatFiles
|
||||
// Clone the item and then add it
|
||||
DatItem datItem = (DatItem)item.Clone();
|
||||
datItem.CopyMachineInformation(copyFrom);
|
||||
Add(bucket, datItem);
|
||||
AddItem(datItem, statsOnly: false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -734,7 +734,7 @@ namespace SabreTools.DatFiles
|
||||
// Clone the item and then add it
|
||||
DatItem datItem = (DatItem)item.Clone();
|
||||
datItem.CopyMachineInformation(copyFrom);
|
||||
Add(bucket, datItem);
|
||||
AddItem(datItem, statsOnly: false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -937,7 +937,7 @@ namespace SabreTools.DatFiles
|
||||
/// </remarks>
|
||||
private void AddItemsFromRomOfParentImpl()
|
||||
{
|
||||
List<string> buckets = [.. Items.Keys];
|
||||
List<string> buckets = [.. Items.SortedKeys];
|
||||
buckets.Sort();
|
||||
|
||||
foreach (string bucket in buckets)
|
||||
@@ -965,7 +965,7 @@ namespace SabreTools.DatFiles
|
||||
DatItem datItem = (DatItem)item.Clone();
|
||||
datItem.CopyMachineInformation(copyFrom);
|
||||
if (!items.Exists(i => i.GetName() == datItem.GetName()) && !items.Contains(datItem))
|
||||
Add(bucket, datItem);
|
||||
AddItem(datItem, statsOnly: false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1023,7 +1023,7 @@ namespace SabreTools.DatFiles
|
||||
/// </remarks>
|
||||
private void RemoveBiosAndDeviceSetsImpl()
|
||||
{
|
||||
List<string> buckets = [.. Items.Keys];
|
||||
List<string> buckets = [.. Items.SortedKeys];
|
||||
buckets.Sort();
|
||||
|
||||
foreach (string bucket in buckets)
|
||||
@@ -1042,7 +1042,7 @@ namespace SabreTools.DatFiles
|
||||
if ((machine.GetBoolFieldValue(Models.Metadata.Machine.IsBiosKey) == true)
|
||||
|| (machine.GetBoolFieldValue(Models.Metadata.Machine.IsDeviceKey) == true))
|
||||
{
|
||||
Remove(bucket);
|
||||
RemoveBucket(bucket);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1093,7 +1093,7 @@ namespace SabreTools.DatFiles
|
||||
/// </remarks>
|
||||
private void RemoveItemsFromCloneOfChildImpl()
|
||||
{
|
||||
List<string> buckets = [.. Items.Keys];
|
||||
List<string> buckets = [.. Items.SortedKeys];
|
||||
buckets.Sort();
|
||||
|
||||
foreach (string bucket in buckets)
|
||||
@@ -1120,7 +1120,7 @@ namespace SabreTools.DatFiles
|
||||
var matchedItems = items.FindAll(i => i.Equals(item));
|
||||
foreach (var match in matchedItems)
|
||||
{
|
||||
Items.Remove(bucket, match);
|
||||
RemoveItem(bucket, match);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1200,7 +1200,7 @@ namespace SabreTools.DatFiles
|
||||
private void RemoveItemsFromRomOfChildImpl()
|
||||
{
|
||||
// Loop through the romof tags
|
||||
List<string> buckets = [.. Items.Keys];
|
||||
List<string> buckets = [.. Items.SortedKeys];
|
||||
buckets.Sort();
|
||||
|
||||
foreach (string bucket in buckets)
|
||||
@@ -1227,7 +1227,7 @@ namespace SabreTools.DatFiles
|
||||
var matchedItems = items.FindAll(i => i.Equals(item));
|
||||
foreach (var match in matchedItems)
|
||||
{
|
||||
Items.Remove(bucket, match);
|
||||
RemoveItem(bucket, match);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1281,7 +1281,7 @@ namespace SabreTools.DatFiles
|
||||
/// <remarks>Applies to <see cref="Items"/></remarks>
|
||||
private void RemoveMachineRelationshipTagsImpl()
|
||||
{
|
||||
List<string> buckets = [.. Items.Keys];
|
||||
List<string> buckets = [.. Items.SortedKeys];
|
||||
buckets.Sort();
|
||||
|
||||
foreach (string bucket in buckets)
|
||||
|
||||
@@ -142,26 +142,6 @@ namespace SabreTools.DatFiles
|
||||
|
||||
#region Item Dictionary Passthrough - Accessors
|
||||
|
||||
/// <summary>
|
||||
/// Add a value to the file dictionary
|
||||
/// </summary>
|
||||
/// <param name="key">Key in the dictionary to add to</param>
|
||||
/// <param name="value">Value to add to the dictionary</param>
|
||||
public void Add(string key, DatItem value)
|
||||
{
|
||||
Items.Add(key, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a range of values to the file dictionary
|
||||
/// </summary>
|
||||
/// <param name="key">Key in the dictionary to add to</param>
|
||||
/// <param name="value">Value to add to the dictionary</param>
|
||||
public void Add(string key, List<DatItem>? value)
|
||||
{
|
||||
Items.Add(key, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a DatItem to the dictionary after checking
|
||||
/// </summary>
|
||||
@@ -242,9 +222,19 @@ namespace SabreTools.DatFiles
|
||||
/// Remove a key from the file dictionary if it exists
|
||||
/// </summary>
|
||||
/// <param name="key">Key in the dictionary to remove</param>
|
||||
public bool Remove(string key)
|
||||
public bool RemoveBucket(string key)
|
||||
{
|
||||
return Items.Remove(key);
|
||||
return Items.RemoveBucket(key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove the first instance of a value from the file dictionary if it exists
|
||||
/// </summary>
|
||||
/// <param name="key">Key in the dictionary to remove from</param>
|
||||
/// <param name="value">Value to remove from the dictionary</param>
|
||||
public bool RemoveItem(string key, DatItem value)
|
||||
{
|
||||
return Items.RemoveItem(key, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -311,7 +311,7 @@ namespace SabreTools.DatFiles
|
||||
/// <param name="inputs">List of inputs to use for renaming</param>
|
||||
public static void ApplySuperDAT(DatFile datFile, List<ParentablePath> inputs)
|
||||
{
|
||||
List<string> keys = [.. datFile.Items.Keys];
|
||||
List<string> keys = [.. datFile.Items.SortedKeys];
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
Parallel.ForEach(keys, Core.Globals.ParallelOptions, key =>
|
||||
#elif NET40_OR_GREATER
|
||||
@@ -366,8 +366,8 @@ namespace SabreTools.DatFiles
|
||||
newItems.Add(newItem);
|
||||
}
|
||||
|
||||
datFile.Remove(key);
|
||||
datFile.Add(key, newItems);
|
||||
datFile.RemoveBucket(key);
|
||||
newItems.ForEach(item => datFile.AddItem(item, statsOnly: false));
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
@@ -467,11 +467,11 @@ namespace SabreTools.DatFiles
|
||||
|
||||
// Then we do a hashwise comparison against the base DAT
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
Parallel.ForEach(intDat.Items.Keys, Core.Globals.ParallelOptions, key =>
|
||||
Parallel.ForEach(intDat.Items.SortedKeys, Core.Globals.ParallelOptions, key =>
|
||||
#elif NET40_OR_GREATER
|
||||
Parallel.ForEach(intDat.Items.Keys, key =>
|
||||
Parallel.ForEach(intDat.Items.SortedKeys, key =>
|
||||
#else
|
||||
foreach (var key in intDat.Items.Keys)
|
||||
foreach (var key in intDat.Items.SortedKeys)
|
||||
#endif
|
||||
{
|
||||
List<DatItem>? datItems = intDat.GetItemsForBucket(key);
|
||||
@@ -497,8 +497,8 @@ namespace SabreTools.DatFiles
|
||||
}
|
||||
|
||||
// Now add the new list to the key
|
||||
intDat.Remove(key);
|
||||
intDat.Add(key, newDatItems);
|
||||
intDat.RemoveBucket(key);
|
||||
newDatItems.ForEach(item => intDat.AddItem(item, statsOnly: false));
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
@@ -515,11 +515,11 @@ namespace SabreTools.DatFiles
|
||||
|
||||
// Then we do a namewise comparison against the base DAT
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
Parallel.ForEach(intDat.Items.Keys, Core.Globals.ParallelOptions, key =>
|
||||
Parallel.ForEach(intDat.Items.SortedKeys, Core.Globals.ParallelOptions, key =>
|
||||
#elif NET40_OR_GREATER
|
||||
Parallel.ForEach(intDat.Items.Keys, key =>
|
||||
Parallel.ForEach(intDat.Items.SortedKeys, key =>
|
||||
#else
|
||||
foreach (var key in intDat.Items.Keys)
|
||||
foreach (var key in intDat.Items.SortedKeys)
|
||||
#endif
|
||||
{
|
||||
List<DatItem>? datItems = intDat.GetItemsForBucket(key);
|
||||
@@ -547,8 +547,8 @@ namespace SabreTools.DatFiles
|
||||
}
|
||||
|
||||
// Now add the new list to the key
|
||||
intDat.Remove(key);
|
||||
intDat.Add(key, newDatItems);
|
||||
intDat.RemoveBucket(key);
|
||||
newDatItems.ForEach(item => intDat.AddItem(item, statsOnly: false));
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
@@ -685,7 +685,7 @@ namespace SabreTools.DatFiles
|
||||
intDat.BucketBy(ItemKey.CRC, DedupeType.Full);
|
||||
|
||||
// Then we compare against the base DAT
|
||||
List<string> keys = [.. intDat.Items.Keys];
|
||||
List<string> keys = [.. intDat.Items.SortedKeys];
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
Parallel.ForEach(keys, Core.Globals.ParallelOptions, key =>
|
||||
#elif NET40_OR_GREATER
|
||||
@@ -737,7 +737,7 @@ namespace SabreTools.DatFiles
|
||||
|
||||
// If we have an exact match, remove the game
|
||||
if (exactMatch)
|
||||
intDat.Remove(key);
|
||||
intDat.RemoveBucket(key);
|
||||
}
|
||||
|
||||
// Standard Against uses hashes
|
||||
@@ -759,8 +759,8 @@ namespace SabreTools.DatFiles
|
||||
}
|
||||
|
||||
// Now add the new list to the key
|
||||
intDat.Remove(key);
|
||||
intDat.Add(key, keepDatItems);
|
||||
intDat.RemoveBucket(key);
|
||||
keepDatItems.ForEach(item => intDat.AddItem(item, statsOnly: false));
|
||||
}
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
@@ -859,11 +859,11 @@ namespace SabreTools.DatFiles
|
||||
watch.Start("Populating duplicate DAT");
|
||||
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
Parallel.ForEach(datFile.Items.Keys, Core.Globals.ParallelOptions, key =>
|
||||
Parallel.ForEach(datFile.Items.SortedKeys, Core.Globals.ParallelOptions, key =>
|
||||
#elif NET40_OR_GREATER
|
||||
Parallel.ForEach(datFile.Items.Keys, key =>
|
||||
Parallel.ForEach(datFile.Items.SortedKeys, key =>
|
||||
#else
|
||||
foreach (var key in datFile.Items.Keys)
|
||||
foreach (var key in datFile.Items.SortedKeys)
|
||||
#endif
|
||||
{
|
||||
List<DatItem> items = Merge(datFile.GetItemsForBucket(key));
|
||||
@@ -891,7 +891,7 @@ namespace SabreTools.DatFiles
|
||||
if (item.GetFieldValue<Source?>(DatItem.SourceKey) != null)
|
||||
newrom.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, newrom.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey) + $" ({Path.GetFileNameWithoutExtension(inputs[item.GetFieldValue<Source?>(DatItem.SourceKey)!.Index].CurrentPath)})");
|
||||
|
||||
dupeData.Add(key, newrom);
|
||||
dupeData.AddItem(newrom, statsOnly: false);
|
||||
}
|
||||
}
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
@@ -1084,11 +1084,11 @@ namespace SabreTools.DatFiles
|
||||
watch.Start("Populating all individual DATs");
|
||||
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
Parallel.ForEach(datFile.Items.Keys, Core.Globals.ParallelOptions, key =>
|
||||
Parallel.ForEach(datFile.Items.SortedKeys, Core.Globals.ParallelOptions, key =>
|
||||
#elif NET40_OR_GREATER
|
||||
Parallel.ForEach(datFile.Items.Keys, key =>
|
||||
Parallel.ForEach(datFile.Items.SortedKeys, key =>
|
||||
#else
|
||||
foreach (var key in datFile.Items.Keys)
|
||||
foreach (var key in datFile.Items.SortedKeys)
|
||||
#endif
|
||||
{
|
||||
List<DatItem> items = Merge(datFile.GetItemsForBucket(key));
|
||||
@@ -1112,7 +1112,7 @@ namespace SabreTools.DatFiles
|
||||
#else
|
||||
if (item.GetFieldValue<DupeType>(DatItem.DupeTypeKey).HasFlag(DupeType.Internal) || item.GetFieldValue<DupeType>(DatItem.DupeTypeKey) == 0x00)
|
||||
#endif
|
||||
outDats[item.GetFieldValue<Source?>(DatItem.SourceKey)!.Index].Add(key, item);
|
||||
outDats[item.GetFieldValue<Source?>(DatItem.SourceKey)!.Index].AddItem(item, statsOnly: false);
|
||||
}
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
@@ -1294,11 +1294,11 @@ namespace SabreTools.DatFiles
|
||||
watch.Start("Populating no duplicate DAT");
|
||||
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
Parallel.ForEach(datFile.Items.Keys, Core.Globals.ParallelOptions, key =>
|
||||
Parallel.ForEach(datFile.Items.SortedKeys, Core.Globals.ParallelOptions, key =>
|
||||
#elif NET40_OR_GREATER
|
||||
Parallel.ForEach(datFile.Items.Keys, key =>
|
||||
Parallel.ForEach(datFile.Items.SortedKeys, key =>
|
||||
#else
|
||||
foreach (var key in datFile.Items.Keys)
|
||||
foreach (var key in datFile.Items.SortedKeys)
|
||||
#endif
|
||||
{
|
||||
List<DatItem> items = Merge(datFile.GetItemsForBucket(key));
|
||||
@@ -1324,7 +1324,7 @@ namespace SabreTools.DatFiles
|
||||
continue;
|
||||
|
||||
newrom.GetFieldValue<Machine>(DatItem.MachineKey)!.SetFieldValue<string?>(Models.Metadata.Machine.NameKey, newrom.GetFieldValue<Machine>(DatItem.MachineKey)!.GetStringFieldValue(Models.Metadata.Machine.NameKey) + $" ({Path.GetFileNameWithoutExtension(inputs[newrom.GetFieldValue<Source?>(DatItem.SourceKey)!.Index].CurrentPath)})");
|
||||
outerDiffData.Add(key, newrom);
|
||||
outerDiffData.AddItem(newrom, statsOnly: false);
|
||||
}
|
||||
}
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
@@ -1522,15 +1522,15 @@ namespace SabreTools.DatFiles
|
||||
private static void AddFromExisting(DatFile addTo, DatFile addFrom, bool delete = false)
|
||||
{
|
||||
// Get the list of keys from the DAT
|
||||
List<string> keys = [.. addFrom.Items.Keys];
|
||||
List<string> keys = [.. addFrom.Items.SortedKeys];
|
||||
foreach (string key in keys)
|
||||
{
|
||||
// Add everything from the key to the internal DAT
|
||||
addTo.Add(key, addFrom.GetItemsForBucket(key));
|
||||
addFrom.GetItemsForBucket(key).ForEach(item => addTo.AddItem(item, statsOnly: false));
|
||||
|
||||
// Now remove the key from the source DAT
|
||||
if (delete)
|
||||
addFrom.Remove(key);
|
||||
addFrom.RemoveBucket(key);
|
||||
}
|
||||
|
||||
// Now remove the file dictionary from the source DAT
|
||||
@@ -1612,11 +1612,11 @@ namespace SabreTools.DatFiles
|
||||
{
|
||||
// Loop through and add the items for this index to the output
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
Parallel.ForEach(datFile.Items.Keys, Core.Globals.ParallelOptions, key =>
|
||||
Parallel.ForEach(datFile.Items.SortedKeys, Core.Globals.ParallelOptions, key =>
|
||||
#elif NET40_OR_GREATER
|
||||
Parallel.ForEach(datFile.Items.Keys, key =>
|
||||
Parallel.ForEach(datFile.Items.SortedKeys, key =>
|
||||
#else
|
||||
foreach (var key in datFile.Items.Keys)
|
||||
foreach (var key in datFile.Items.SortedKeys)
|
||||
#endif
|
||||
{
|
||||
List<DatItem> items = Merge(datFile.GetItemsForBucket(key));
|
||||
@@ -1633,7 +1633,7 @@ namespace SabreTools.DatFiles
|
||||
{
|
||||
var source = item.GetFieldValue<Source?>(DatItem.SourceKey);
|
||||
if (source != null && source.Index == index)
|
||||
indexDat.Add(key, item);
|
||||
indexDat.AddItem(item, statsOnly: false);
|
||||
}
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
|
||||
@@ -54,16 +54,6 @@ namespace SabreTools.DatFiles
|
||||
|
||||
#region Keys
|
||||
|
||||
/// <summary>
|
||||
/// Get the keys from the file dictionary
|
||||
/// </summary>
|
||||
/// <returns>List of the keys</returns>
|
||||
[JsonIgnore, XmlIgnore]
|
||||
public ICollection<string> Keys
|
||||
{
|
||||
get { return _items.Keys; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the keys in sorted order from the file dictionary
|
||||
/// </summary>
|
||||
@@ -109,59 +99,6 @@ namespace SabreTools.DatFiles
|
||||
|
||||
#region Accessors
|
||||
|
||||
/// <summary>
|
||||
/// Add a value to the file dictionary
|
||||
/// </summary>
|
||||
/// <param name="key">Key in the dictionary to add to</param>
|
||||
/// <param name="value">Value to add to the dictionary</param>
|
||||
public void Add(string key, DatItem value)
|
||||
{
|
||||
// Explicit lock for some weird corner cases
|
||||
lock (key)
|
||||
{
|
||||
// Ensure the key exists
|
||||
EnsureBucketingKey(key);
|
||||
|
||||
// If item is null, don't add it
|
||||
if (value == null)
|
||||
return;
|
||||
|
||||
// Now add the value
|
||||
_items[key]!.Add(value);
|
||||
|
||||
// Now update the statistics
|
||||
DatStatistics.AddItemStatistics(value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a range of values to the file dictionary
|
||||
/// </summary>
|
||||
/// <param name="key">Key in the dictionary to add to</param>
|
||||
/// <param name="value">Value to add to the dictionary</param>
|
||||
public void Add(string key, List<DatItem>? value)
|
||||
{
|
||||
// Explicit lock for some weird corner cases
|
||||
lock (key)
|
||||
{
|
||||
// If the value is null or empty, just return
|
||||
if (value == null || value.Count == 0)
|
||||
return;
|
||||
|
||||
// Ensure the key exists
|
||||
EnsureBucketingKey(key);
|
||||
|
||||
// Now add the value
|
||||
_items[key]!.AddRange(value);
|
||||
|
||||
// Now update the statistics
|
||||
foreach (DatItem item in value)
|
||||
{
|
||||
DatStatistics.AddItemStatistics(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a DatItem to the dictionary after checking
|
||||
/// </summary>
|
||||
@@ -256,7 +193,7 @@ namespace SabreTools.DatFiles
|
||||
}
|
||||
else
|
||||
{
|
||||
Add(key, item);
|
||||
AddItem(key, item);
|
||||
}
|
||||
|
||||
return key;
|
||||
@@ -267,7 +204,7 @@ namespace SabreTools.DatFiles
|
||||
/// </summary>
|
||||
internal void ClearEmpty()
|
||||
{
|
||||
string[] keys = [.. Keys];
|
||||
string[] keys = [.. SortedKeys];
|
||||
foreach (string key in keys)
|
||||
{
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
@@ -303,15 +240,21 @@ namespace SabreTools.DatFiles
|
||||
/// </summary>
|
||||
internal void ClearMarked()
|
||||
{
|
||||
string[] keys = [.. Keys];
|
||||
string[] keys = [.. SortedKeys];
|
||||
foreach (string key in keys)
|
||||
{
|
||||
// Skip invalid item lists
|
||||
List<DatItem> oldItemList = GetItemsForBucket(key);
|
||||
List<DatItem> newItemList = oldItemList.FindAll(i => i.GetBoolFieldValue(DatItem.RemoveKey) != true);
|
||||
// Perform filtering on items
|
||||
List<DatItem> list = GetItemsForBucket(key, filter: true);
|
||||
|
||||
Remove(key);
|
||||
Add(key, newItemList);
|
||||
// Remove the current list
|
||||
RemoveBucket(key);
|
||||
|
||||
// Add the filtered list back
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
_ = _items.TryAdd(key, list);
|
||||
#else
|
||||
_items[key] = list;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -333,33 +276,6 @@ namespace SabreTools.DatFiles
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get if the file dictionary contains the key and value
|
||||
/// </summary>
|
||||
/// <param name="key">Key in the dictionary to check</param>
|
||||
/// <param name="value">Value in the dictionary to check</param>
|
||||
/// <returns>True if the key exists, false otherwise</returns>
|
||||
public bool Contains(string key, DatItem value)
|
||||
{
|
||||
// If the key is null, we return false since keys can't be null
|
||||
if (key == null)
|
||||
return false;
|
||||
|
||||
// Explicit lock for some weird corner cases
|
||||
lock (key)
|
||||
{
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
if (_items.TryGetValue(key, out var list) && list != null)
|
||||
return list.Exists(i => i.Equals(value));
|
||||
#else
|
||||
if (_items.ContainsKey(key) && _items[key] != null)
|
||||
return _items[key]!.Exists(i => i.Equals(value));
|
||||
#endif
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensure the key exists in the items dictionary
|
||||
/// </summary>
|
||||
@@ -378,6 +294,9 @@ namespace SabreTools.DatFiles
|
||||
/// <summary>
|
||||
/// Get the items associated with a bucket name
|
||||
/// </summary>
|
||||
/// <param name="bucketName">Name of the bucket to retrive items for</param>
|
||||
/// <param name="filter">Indicates if RemoveKey filtering is performed</param>
|
||||
/// <returns>List representing the bucket items, empty on missing</returns>
|
||||
public List<DatItem> GetItemsForBucket(string? bucketName, bool filter = false)
|
||||
{
|
||||
if (bucketName == null)
|
||||
@@ -410,28 +329,27 @@ namespace SabreTools.DatFiles
|
||||
/// Remove a key from the file dictionary if it exists
|
||||
/// </summary>
|
||||
/// <param name="key">Key in the dictionary to remove</param>
|
||||
public bool Remove(string key)
|
||||
public bool RemoveBucket(string key)
|
||||
{
|
||||
// Explicit lock for some weird corner cases
|
||||
lock (key)
|
||||
{
|
||||
// If the key doesn't exist, return
|
||||
if (!ContainsKey(key) || _items[key] == null)
|
||||
return false;
|
||||
|
||||
// Remove the statistics first
|
||||
foreach (DatItem item in _items[key]!)
|
||||
{
|
||||
DatStatistics.RemoveItemStatistics(item);
|
||||
}
|
||||
|
||||
// Remove the key from the dictionary
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
return _items.TryRemove(key, out _);
|
||||
bool removed = _items.TryRemove(key, out var list);
|
||||
#else
|
||||
return _items.Remove(key);
|
||||
if (!_items.ContainsKey(key))
|
||||
return false;
|
||||
|
||||
bool removed = true;
|
||||
var list = _items[key];
|
||||
_items.Remove(key);
|
||||
#endif
|
||||
if (list == null)
|
||||
return removed;
|
||||
|
||||
foreach (var item in list)
|
||||
{
|
||||
DatStatistics.RemoveItemStatistics(item);
|
||||
}
|
||||
|
||||
return removed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -439,43 +357,35 @@ namespace SabreTools.DatFiles
|
||||
/// </summary>
|
||||
/// <param name="key">Key in the dictionary to remove from</param>
|
||||
/// <param name="value">Value to remove from the dictionary</param>
|
||||
public bool Remove(string key, DatItem value)
|
||||
public bool RemoveItem(string key, DatItem value)
|
||||
{
|
||||
// Explicit lock for some weird corner cases
|
||||
lock (key)
|
||||
{
|
||||
// If the key and value doesn't exist, return
|
||||
if (!Contains(key, value) || _items[key] == null)
|
||||
// If the key doesn't exist, return
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
if (!_items.TryGetValue(key, out var list) || list == null)
|
||||
return false;
|
||||
#else
|
||||
if (!_items.ContainsKey(key))
|
||||
return false;
|
||||
|
||||
var list = _items[key];
|
||||
if (list == null)
|
||||
return false;
|
||||
#endif
|
||||
|
||||
// If the value doesn't exist in the key, return
|
||||
if (!list.Exists(i => i.Equals(value)))
|
||||
return false;
|
||||
|
||||
// Remove the statistics first
|
||||
DatStatistics.RemoveItemStatistics(value);
|
||||
|
||||
return _items[key]!.Remove(value);
|
||||
return list.Remove(value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset a key from the file dictionary if it exists
|
||||
/// </summary>
|
||||
/// <param name="key">Key in the dictionary to reset</param>
|
||||
public bool Reset(string key)
|
||||
{
|
||||
// If the key doesn't exist, return
|
||||
if (!ContainsKey(key) || _items[key] == null)
|
||||
return false;
|
||||
|
||||
// Remove the statistics first
|
||||
foreach (DatItem item in _items[key]!)
|
||||
{
|
||||
DatStatistics.RemoveItemStatistics(item);
|
||||
}
|
||||
|
||||
// Remove the key from the dictionary
|
||||
_items[key] = [];
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Override the internal ItemKey value
|
||||
/// </summary>
|
||||
@@ -485,6 +395,31 @@ namespace SabreTools.DatFiles
|
||||
_bucketedBy = newBucket;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a value to the file dictionary
|
||||
/// </summary>
|
||||
/// <param name="key">Key in the dictionary to add to</param>
|
||||
/// <param name="value">Value to add to the dictionary</param>
|
||||
internal void AddItem(string key, DatItem value)
|
||||
{
|
||||
// Explicit lock for some weird corner cases
|
||||
lock (key)
|
||||
{
|
||||
// Ensure the key exists
|
||||
EnsureBucketingKey(key);
|
||||
|
||||
// If item is null, don't add it
|
||||
if (value == null)
|
||||
return;
|
||||
|
||||
// Now add the value
|
||||
_items[key]!.Add(value);
|
||||
|
||||
// Now update the statistics
|
||||
DatStatistics.AddItemStatistics(value);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Bucketing
|
||||
@@ -532,28 +467,29 @@ namespace SabreTools.DatFiles
|
||||
/// <remarks>This also sets the remove flag on any duplicates found</remarks>
|
||||
internal List<DatItem> GetDuplicates(DatItem datItem, bool sorted = false)
|
||||
{
|
||||
List<DatItem> output = [];
|
||||
|
||||
// Check for an empty rom list first
|
||||
if (DatStatistics.TotalCount == 0)
|
||||
return output;
|
||||
return [];
|
||||
|
||||
// We want to get the proper key for the DatItem
|
||||
string key = SortAndGetKey(datItem, sorted);
|
||||
|
||||
// If the key doesn't exist, return the empty list
|
||||
if (!ContainsKey(key))
|
||||
return output;
|
||||
// Get the items for the current key, if possible
|
||||
List<DatItem> roms = GetItemsForBucket(key, filter: false);
|
||||
if (roms.Count == 0)
|
||||
return [];
|
||||
|
||||
// Remove the current key
|
||||
RemoveBucket(key);
|
||||
|
||||
// Try to find duplicates
|
||||
List<DatItem> roms = GetItemsForBucket(key);
|
||||
List<DatItem> left = [];
|
||||
List<DatItem> output = [];
|
||||
for (int i = 0; i < roms.Count; i++)
|
||||
{
|
||||
DatItem other = roms[i];
|
||||
if (other.GetBoolFieldValue(DatItem.RemoveKey) == true)
|
||||
{
|
||||
left.Add(other);
|
||||
AddItem(key, other);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -562,16 +498,9 @@ namespace SabreTools.DatFiles
|
||||
other.SetFieldValue<bool?>(DatItem.RemoveKey, true);
|
||||
output.Add(other);
|
||||
}
|
||||
else
|
||||
{
|
||||
left.Add(other);
|
||||
}
|
||||
}
|
||||
|
||||
// Add back all roms with the proper flags
|
||||
Remove(key);
|
||||
Add(key, output);
|
||||
Add(key, left);
|
||||
AddItem(key, other);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
@@ -651,7 +580,7 @@ namespace SabreTools.DatFiles
|
||||
/// <param name="lower">True if the key should be lowercased, false otherwise</param>
|
||||
/// <param name="norename">True if games should only be compared on game and file name, false if system and source are counted</param>
|
||||
/// </summary>
|
||||
private string GetBucketKey(DatItem datItem, ItemKey bucketBy, bool lower, bool norename)
|
||||
private static string GetBucketKey(DatItem datItem, ItemKey bucketBy, bool lower, bool norename)
|
||||
{
|
||||
if (datItem == null)
|
||||
return string.Empty;
|
||||
@@ -679,7 +608,7 @@ namespace SabreTools.DatFiles
|
||||
_mergedBy = DedupeType.None;
|
||||
|
||||
// First do the initial sort of all of the roms inplace
|
||||
List<string> oldkeys = [.. Keys];
|
||||
List<string> oldkeys = [.. SortedKeys];
|
||||
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
Parallel.For(0, oldkeys.Count, Core.Globals.ParallelOptions, k =>
|
||||
@@ -691,7 +620,7 @@ namespace SabreTools.DatFiles
|
||||
{
|
||||
string key = oldkeys[k];
|
||||
if (GetItemsForBucket(key).Count == 0)
|
||||
Remove(key);
|
||||
RemoveBucket(key);
|
||||
|
||||
// Now add each of the roms to their respective keys
|
||||
for (int i = 0; i < GetItemsForBucket(key).Count; i++)
|
||||
@@ -706,8 +635,8 @@ namespace SabreTools.DatFiles
|
||||
// If the key is different, move the item to the new key
|
||||
if (newkey != key)
|
||||
{
|
||||
Add(newkey, item);
|
||||
bool removed = Remove(key, item);
|
||||
AddItem(newkey, item);
|
||||
bool removed = RemoveItem(key, item);
|
||||
if (!removed)
|
||||
break;
|
||||
|
||||
@@ -717,7 +646,7 @@ namespace SabreTools.DatFiles
|
||||
|
||||
// If the key is now empty, remove it
|
||||
if (GetItemsForBucket(key).Count == 0)
|
||||
Remove(key);
|
||||
RemoveBucket(key);
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
@@ -735,7 +664,7 @@ namespace SabreTools.DatFiles
|
||||
// Set the sorted type
|
||||
_mergedBy = dedupeType;
|
||||
|
||||
List<string> keys = [.. Keys];
|
||||
List<string> keys = [.. SortedKeys];
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
Parallel.ForEach(keys, Core.Globals.ParallelOptions, key =>
|
||||
#elif NET40_OR_GREATER
|
||||
@@ -755,8 +684,8 @@ namespace SabreTools.DatFiles
|
||||
sortedList = DatFileTool.Merge(sortedList);
|
||||
|
||||
// Add the list back to the dictionary
|
||||
Reset(key);
|
||||
Add(key, sortedList);
|
||||
RemoveBucket(key);
|
||||
sortedList.ForEach(item => AddItem(key, item));
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
@@ -769,7 +698,7 @@ namespace SabreTools.DatFiles
|
||||
/// </summary>
|
||||
private void PerformSorting()
|
||||
{
|
||||
List<string> keys = [.. Keys];
|
||||
List<string> keys = [.. SortedKeys];
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
Parallel.ForEach(keys, Core.Globals.ParallelOptions, key =>
|
||||
#elif NET40_OR_GREATER
|
||||
@@ -785,8 +714,8 @@ namespace SabreTools.DatFiles
|
||||
DatFileTool.Sort(ref sortedList, false);
|
||||
|
||||
// Add the list back to the dictionary
|
||||
Reset(key);
|
||||
Add(key, sortedList);
|
||||
RemoveBucket(key);
|
||||
sortedList.ForEach(item => AddItem(key, item));
|
||||
#if NET40_OR_GREATER || NETCOREAPP
|
||||
});
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user