mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Make SortedKeys an array for both
This commit is contained in:
@@ -191,13 +191,12 @@ namespace SabreTools.DatFiles
|
|||||||
/// <remarks>Applies to <see cref="Items"/></remarks>
|
/// <remarks>Applies to <see cref="Items"/></remarks>
|
||||||
private void ExecuteFiltersImpl(FilterRunner filterRunner)
|
private void ExecuteFiltersImpl(FilterRunner filterRunner)
|
||||||
{
|
{
|
||||||
List<string> keys = [.. Items.SortedKeys];
|
|
||||||
#if NET452_OR_GREATER || NETCOREAPP
|
#if NET452_OR_GREATER || NETCOREAPP
|
||||||
Parallel.ForEach(keys, Core.Globals.ParallelOptions, key =>
|
Parallel.ForEach(Items.SortedKeys, Core.Globals.ParallelOptions, key =>
|
||||||
#elif NET40_OR_GREATER
|
#elif NET40_OR_GREATER
|
||||||
Parallel.ForEach(keys, key =>
|
Parallel.ForEach(Items.SortedKeys, key =>
|
||||||
#else
|
#else
|
||||||
foreach (var key in keys)
|
foreach (var key in Items.SortedKeys)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
ExecuteFilterOnBucket(filterRunner, key);
|
ExecuteFilterOnBucket(filterRunner, key);
|
||||||
|
|||||||
@@ -240,10 +240,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
private void AddItemsFromChildrenImpl(bool subfolder, bool skipDedup)
|
private void AddItemsFromChildrenImpl(bool subfolder, bool skipDedup)
|
||||||
{
|
{
|
||||||
List<string> buckets = [.. Items.SortedKeys];
|
foreach (string bucket in Items.SortedKeys)
|
||||||
buckets.Sort();
|
|
||||||
|
|
||||||
foreach (string bucket in buckets)
|
|
||||||
{
|
{
|
||||||
// If the bucket has no items in it
|
// If the bucket has no items in it
|
||||||
List<DatItem> items = GetItemsForBucket(bucket);
|
List<DatItem> items = GetItemsForBucket(bucket);
|
||||||
@@ -503,10 +500,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
private void AddItemsFromCloneOfParentImpl()
|
private void AddItemsFromCloneOfParentImpl()
|
||||||
{
|
{
|
||||||
List<string> buckets = [.. Items.SortedKeys];
|
foreach (string bucket in Items.SortedKeys)
|
||||||
buckets.Sort();
|
|
||||||
|
|
||||||
foreach (string bucket in buckets)
|
|
||||||
{
|
{
|
||||||
// If the bucket has no items in it
|
// If the bucket has no items in it
|
||||||
List<DatItem> items = GetItemsForBucket(bucket);
|
List<DatItem> items = GetItemsForBucket(bucket);
|
||||||
@@ -625,10 +619,7 @@ namespace SabreTools.DatFiles
|
|||||||
private bool AddItemsFromDevicesImpl(bool deviceOnly, bool useSlotOptions)
|
private bool AddItemsFromDevicesImpl(bool deviceOnly, bool useSlotOptions)
|
||||||
{
|
{
|
||||||
bool foundnew = false;
|
bool foundnew = false;
|
||||||
List<string> buckets = [.. Items.SortedKeys];
|
foreach (string bucket in Items.SortedKeys)
|
||||||
buckets.Sort();
|
|
||||||
|
|
||||||
foreach (string bucket in buckets)
|
|
||||||
{
|
{
|
||||||
// If the bucket doesn't have items
|
// If the bucket doesn't have items
|
||||||
List<DatItem> datItems = GetItemsForBucket(bucket);
|
List<DatItem> datItems = GetItemsForBucket(bucket);
|
||||||
@@ -937,10 +928,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
private void AddItemsFromRomOfParentImpl()
|
private void AddItemsFromRomOfParentImpl()
|
||||||
{
|
{
|
||||||
List<string> buckets = [.. Items.SortedKeys];
|
foreach (string bucket in Items.SortedKeys)
|
||||||
buckets.Sort();
|
|
||||||
|
|
||||||
foreach (string bucket in buckets)
|
|
||||||
{
|
{
|
||||||
// If the bucket has no items in it
|
// If the bucket has no items in it
|
||||||
List<DatItem> items = GetItemsForBucket(bucket);
|
List<DatItem> items = GetItemsForBucket(bucket);
|
||||||
@@ -1023,10 +1011,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
private void RemoveBiosAndDeviceSetsImpl()
|
private void RemoveBiosAndDeviceSetsImpl()
|
||||||
{
|
{
|
||||||
List<string> buckets = [.. Items.SortedKeys];
|
foreach (string bucket in Items.SortedKeys)
|
||||||
buckets.Sort();
|
|
||||||
|
|
||||||
foreach (string bucket in buckets)
|
|
||||||
{
|
{
|
||||||
// If the bucket has no items in it
|
// If the bucket has no items in it
|
||||||
List<DatItem> items = GetItemsForBucket(bucket);
|
List<DatItem> items = GetItemsForBucket(bucket);
|
||||||
@@ -1093,10 +1078,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
private void RemoveItemsFromCloneOfChildImpl()
|
private void RemoveItemsFromCloneOfChildImpl()
|
||||||
{
|
{
|
||||||
List<string> buckets = [.. Items.SortedKeys];
|
foreach (string bucket in Items.SortedKeys)
|
||||||
buckets.Sort();
|
|
||||||
|
|
||||||
foreach (string bucket in buckets)
|
|
||||||
{
|
{
|
||||||
// If the bucket has no items in it
|
// If the bucket has no items in it
|
||||||
List<DatItem> items = GetItemsForBucket(bucket);
|
List<DatItem> items = GetItemsForBucket(bucket);
|
||||||
@@ -1200,10 +1182,7 @@ namespace SabreTools.DatFiles
|
|||||||
private void RemoveItemsFromRomOfChildImpl()
|
private void RemoveItemsFromRomOfChildImpl()
|
||||||
{
|
{
|
||||||
// Loop through the romof tags
|
// Loop through the romof tags
|
||||||
List<string> buckets = [.. Items.SortedKeys];
|
foreach (string bucket in Items.SortedKeys)
|
||||||
buckets.Sort();
|
|
||||||
|
|
||||||
foreach (string bucket in buckets)
|
|
||||||
{
|
{
|
||||||
// If the bucket has no items in it
|
// If the bucket has no items in it
|
||||||
List<DatItem> items = GetItemsForBucket(bucket);
|
List<DatItem> items = GetItemsForBucket(bucket);
|
||||||
@@ -1281,10 +1260,7 @@ 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> buckets = [.. Items.SortedKeys];
|
foreach (string bucket in Items.SortedKeys)
|
||||||
buckets.Sort();
|
|
||||||
|
|
||||||
foreach (string bucket in buckets)
|
|
||||||
{
|
{
|
||||||
// If the bucket has no items in it
|
// If the bucket has no items in it
|
||||||
var items = GetItemsForBucket(bucket);
|
var items = GetItemsForBucket(bucket);
|
||||||
|
|||||||
@@ -311,13 +311,12 @@ namespace SabreTools.DatFiles
|
|||||||
/// <param name="inputs">List of inputs to use for renaming</param>
|
/// <param name="inputs">List of inputs to use for renaming</param>
|
||||||
public static void ApplySuperDAT(DatFile datFile, List<ParentablePath> inputs)
|
public static void ApplySuperDAT(DatFile datFile, List<ParentablePath> inputs)
|
||||||
{
|
{
|
||||||
List<string> keys = [.. datFile.Items.SortedKeys];
|
|
||||||
#if NET452_OR_GREATER || NETCOREAPP
|
#if NET452_OR_GREATER || NETCOREAPP
|
||||||
Parallel.ForEach(keys, Core.Globals.ParallelOptions, key =>
|
Parallel.ForEach(datFile.Items.SortedKeys, Core.Globals.ParallelOptions, key =>
|
||||||
#elif NET40_OR_GREATER
|
#elif NET40_OR_GREATER
|
||||||
Parallel.ForEach(keys, key =>
|
Parallel.ForEach(datFile.Items.SortedKeys, key =>
|
||||||
#else
|
#else
|
||||||
foreach (var key in keys)
|
foreach (var key in datFile.Items.SortedKeys)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
List<DatItem>? items = datFile.GetItemsForBucket(key);
|
List<DatItem>? items = datFile.GetItemsForBucket(key);
|
||||||
@@ -685,13 +684,12 @@ namespace SabreTools.DatFiles
|
|||||||
intDat.BucketBy(ItemKey.CRC, DedupeType.Full);
|
intDat.BucketBy(ItemKey.CRC, DedupeType.Full);
|
||||||
|
|
||||||
// Then we compare against the base DAT
|
// Then we compare against the base DAT
|
||||||
List<string> keys = [.. intDat.Items.SortedKeys];
|
|
||||||
#if NET452_OR_GREATER || NETCOREAPP
|
#if NET452_OR_GREATER || NETCOREAPP
|
||||||
Parallel.ForEach(keys, Core.Globals.ParallelOptions, key =>
|
Parallel.ForEach(intDat.Items.SortedKeys, Core.Globals.ParallelOptions, key =>
|
||||||
#elif NET40_OR_GREATER
|
#elif NET40_OR_GREATER
|
||||||
Parallel.ForEach(keys, key =>
|
Parallel.ForEach(intDat.Items.SortedKeys, key =>
|
||||||
#else
|
#else
|
||||||
foreach (var key in keys)
|
foreach (var key in intDat.Items.SortedKeys)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
// Game Against uses game names
|
// Game Against uses game names
|
||||||
@@ -1522,8 +1520,7 @@ namespace SabreTools.DatFiles
|
|||||||
private static void AddFromExisting(DatFile addTo, DatFile addFrom, bool delete = false)
|
private static void AddFromExisting(DatFile addTo, DatFile addFrom, bool delete = false)
|
||||||
{
|
{
|
||||||
// Get the list of keys from the DAT
|
// Get the list of keys from the DAT
|
||||||
List<string> keys = [.. addFrom.Items.SortedKeys];
|
foreach (string key in addFrom.Items.SortedKeys)
|
||||||
foreach (string key in keys)
|
|
||||||
{
|
{
|
||||||
// Add everything from the key to the internal DAT
|
// Add everything from the key to the internal DAT
|
||||||
addFrom.GetItemsForBucket(key).ForEach(item => addTo.AddItem(item, statsOnly: false));
|
addFrom.GetItemsForBucket(key).ForEach(item => addTo.AddItem(item, statsOnly: false));
|
||||||
|
|||||||
@@ -50,29 +50,23 @@ namespace SabreTools.DatFiles
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Publically available fields
|
#region Fields
|
||||||
|
|
||||||
#region Keys
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the keys in sorted order from the file dictionary
|
/// Get the keys in sorted order from the file dictionary
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>List of the keys in sorted order</returns>
|
/// <returns>List of the keys in sorted order</returns>
|
||||||
[JsonIgnore, XmlIgnore]
|
[JsonIgnore, XmlIgnore]
|
||||||
public List<string> SortedKeys
|
public string[] SortedKeys
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
List<string> keys = [.. _items.Keys];
|
List<string> keys = [.. _items.Keys];
|
||||||
keys.Sort(new NaturalComparer());
|
keys.Sort(new NaturalComparer());
|
||||||
return keys;
|
return [.. keys];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Statistics
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// DAT statistics
|
/// DAT statistics
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -81,8 +75,6 @@ namespace SabreTools.DatFiles
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -204,8 +196,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal void ClearEmpty()
|
internal void ClearEmpty()
|
||||||
{
|
{
|
||||||
string[] keys = [.. SortedKeys];
|
foreach (string key in SortedKeys)
|
||||||
foreach (string key in keys)
|
|
||||||
{
|
{
|
||||||
#if NET40_OR_GREATER || NETCOREAPP
|
#if NET40_OR_GREATER || NETCOREAPP
|
||||||
// If the key doesn't exist, skip
|
// If the key doesn't exist, skip
|
||||||
@@ -240,8 +231,7 @@ namespace SabreTools.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal void ClearMarked()
|
internal void ClearMarked()
|
||||||
{
|
{
|
||||||
string[] keys = [.. SortedKeys];
|
foreach (string key in SortedKeys)
|
||||||
foreach (string key in keys)
|
|
||||||
{
|
{
|
||||||
// Perform filtering on items
|
// Perform filtering on items
|
||||||
List<DatItem> list = GetItemsForBucket(key, filter: true);
|
List<DatItem> list = GetItemsForBucket(key, filter: true);
|
||||||
@@ -664,13 +654,12 @@ namespace SabreTools.DatFiles
|
|||||||
// Set the sorted type
|
// Set the sorted type
|
||||||
_mergedBy = dedupeType;
|
_mergedBy = dedupeType;
|
||||||
|
|
||||||
List<string> keys = [.. SortedKeys];
|
|
||||||
#if NET452_OR_GREATER || NETCOREAPP
|
#if NET452_OR_GREATER || NETCOREAPP
|
||||||
Parallel.ForEach(keys, Core.Globals.ParallelOptions, key =>
|
Parallel.ForEach(SortedKeys, Core.Globals.ParallelOptions, key =>
|
||||||
#elif NET40_OR_GREATER
|
#elif NET40_OR_GREATER
|
||||||
Parallel.ForEach(keys, key =>
|
Parallel.ForEach(SortedKeys, key =>
|
||||||
#else
|
#else
|
||||||
foreach (var key in keys)
|
foreach (var key in SortedKeys)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
// Get the possibly unsorted list
|
// Get the possibly unsorted list
|
||||||
@@ -698,13 +687,12 @@ namespace SabreTools.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void PerformSorting()
|
private void PerformSorting()
|
||||||
{
|
{
|
||||||
List<string> keys = [.. SortedKeys];
|
|
||||||
#if NET452_OR_GREATER || NETCOREAPP
|
#if NET452_OR_GREATER || NETCOREAPP
|
||||||
Parallel.ForEach(keys, Core.Globals.ParallelOptions, key =>
|
Parallel.ForEach(SortedKeys, Core.Globals.ParallelOptions, key =>
|
||||||
#elif NET40_OR_GREATER
|
#elif NET40_OR_GREATER
|
||||||
Parallel.ForEach(keys, key =>
|
Parallel.ForEach(SortedKeys, key =>
|
||||||
#else
|
#else
|
||||||
foreach (var key in keys)
|
foreach (var key in SortedKeys)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
// Get the possibly unsorted list
|
// Get the possibly unsorted list
|
||||||
|
|||||||
@@ -152,8 +152,7 @@ namespace SabreTools.DatTools
|
|||||||
/// <param name="datFile">Current DatFile object to run operations on</param>
|
/// <param name="datFile">Current DatFile object to run operations on</param>
|
||||||
internal void CleanDatItems(DatFile datFile)
|
internal void CleanDatItems(DatFile datFile)
|
||||||
{
|
{
|
||||||
List<string> keys = [.. datFile.Items.SortedKeys];
|
foreach (string key in datFile.Items.SortedKeys)
|
||||||
foreach (string key in keys)
|
|
||||||
{
|
{
|
||||||
// For every item in the current key
|
// For every item in the current key
|
||||||
var items = datFile.GetItemsForBucket(key);
|
var items = datFile.GetItemsForBucket(key);
|
||||||
|
|||||||
@@ -109,8 +109,7 @@ namespace SabreTools.DatTools
|
|||||||
datFile.BucketBy(ItemKey.SHA1, DedupeType.None);
|
datFile.BucketBy(ItemKey.SHA1, DedupeType.None);
|
||||||
|
|
||||||
// Then we want to loop through each of the hashes and see if we can rebuild
|
// Then we want to loop through each of the hashes and see if we can rebuild
|
||||||
List<string> keys = [.. datFile.Items.SortedKeys];
|
foreach (string hash in datFile.Items.SortedKeys)
|
||||||
foreach (string hash in keys)
|
|
||||||
{
|
{
|
||||||
// Pre-empt any issues that could arise from string length
|
// Pre-empt any issues that could arise from string length
|
||||||
if (hash.Length != Constants.SHA1Length)
|
if (hash.Length != Constants.SHA1Length)
|
||||||
|
|||||||
@@ -83,17 +83,17 @@ namespace SabreTools.DatTools
|
|||||||
{
|
{
|
||||||
DatStatistics individualStats = datdata.DatStatistics;
|
DatStatistics individualStats = datdata.DatStatistics;
|
||||||
individualStats.DisplayName = datdata.Header.GetStringFieldValue(DatHeader.FileNameKey);
|
individualStats.DisplayName = datdata.Header.GetStringFieldValue(DatHeader.FileNameKey);
|
||||||
individualStats.MachineCount = datdata.Items.SortedKeys.Count;
|
individualStats.MachineCount = datdata.Items.SortedKeys.Length;
|
||||||
stats.Add(individualStats);
|
stats.Add(individualStats);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add single DAT stats to dir
|
// Add single DAT stats to dir
|
||||||
dirStats.AddStatistics(datdata.DatStatistics);
|
dirStats.AddStatistics(datdata.DatStatistics);
|
||||||
dirStats.GameCount += datdata.Items.SortedKeys.Count;
|
dirStats.GameCount += datdata.Items.SortedKeys.Length;
|
||||||
|
|
||||||
// Add single DAT stats to totals
|
// Add single DAT stats to totals
|
||||||
totalStats.AddStatistics(datdata.DatStatistics);
|
totalStats.AddStatistics(datdata.DatStatistics);
|
||||||
totalStats.GameCount += datdata.Items.SortedKeys.Count;
|
totalStats.GameCount += datdata.Items.SortedKeys.Length;
|
||||||
|
|
||||||
// Make sure to assign the new directory
|
// Make sure to assign the new directory
|
||||||
lastdir = thisdir;
|
lastdir = thisdir;
|
||||||
|
|||||||
@@ -58,8 +58,7 @@ namespace SabreTools.DatTools
|
|||||||
datFile.BucketBy(ItemKey.SHA1, DedupeType.None);
|
datFile.BucketBy(ItemKey.SHA1, DedupeType.None);
|
||||||
|
|
||||||
// Then we want to loop through each of the hashes and see if we can rebuild
|
// Then we want to loop through each of the hashes and see if we can rebuild
|
||||||
List<string> keys = [.. datFile.Items.SortedKeys];
|
foreach (string hash in datFile.Items.SortedKeys)
|
||||||
foreach (string hash in keys)
|
|
||||||
{
|
{
|
||||||
// Pre-empt any issues that could arise from string length
|
// Pre-empt any issues that could arise from string length
|
||||||
if (hash.Length != Constants.SHA1Length)
|
if (hash.Length != Constants.SHA1Length)
|
||||||
@@ -216,8 +215,7 @@ namespace SabreTools.DatTools
|
|||||||
datFile.BucketBy(ItemKey.Machine, DedupeType.Full);
|
datFile.BucketBy(ItemKey.Machine, DedupeType.Full);
|
||||||
|
|
||||||
// Then mark items for removal
|
// Then mark items for removal
|
||||||
List<string> keys = [.. datFile.Items.SortedKeys];
|
foreach (string key in datFile.Items.SortedKeys)
|
||||||
foreach (string key in keys)
|
|
||||||
{
|
{
|
||||||
List<DatItem>? items = datFile.GetItemsForBucket(key);
|
List<DatItem>? items = datFile.GetItemsForBucket(key);
|
||||||
if (items == null)
|
if (items == null)
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ namespace SabreTools.DatTools
|
|||||||
datFile.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
datFile.BucketBy(ItemKey.Machine, DedupeType.None, norename: true);
|
||||||
|
|
||||||
datFile.DatStatistics.DisplayName = datFile.Header.GetStringFieldValue(DatHeader.FileNameKey);
|
datFile.DatStatistics.DisplayName = datFile.Header.GetStringFieldValue(DatHeader.FileNameKey);
|
||||||
datFile.DatStatistics.MachineCount = datFile.Items.SortedKeys.Count;
|
datFile.DatStatistics.MachineCount = datFile.Items.SortedKeys.Length;
|
||||||
|
|
||||||
List<DatStatistics> statsList =
|
List<DatStatistics> statsList =
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ namespace SabreTools.Test.DatFiles
|
|||||||
dict.AddItem(rom4, statsOnly: false);
|
dict.AddItem(rom4, statsOnly: false);
|
||||||
|
|
||||||
dict.BucketBy(itemKey, DedupeType.None);
|
dict.BucketBy(itemKey, DedupeType.None);
|
||||||
Assert.Equal(expected, dict.SortedKeys.Count);
|
Assert.Equal(expected, dict.SortedKeys.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
Reference in New Issue
Block a user