mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DatFile] Wrap intial bucketby in an if-statement
This commit is contained in:
@@ -30,113 +30,111 @@ namespace SabreTools.Library.Dats
|
|||||||
/// <param name="norename">True if games should only be compared on game and file name, false if system and source are counted</param>
|
/// <param name="norename">True if games should only be compared on game and file name, false if system and source are counted</param>
|
||||||
public void BucketBy(SortedBy bucketBy, DedupeType deduperoms, bool lower = true, bool norename = true)
|
public void BucketBy(SortedBy bucketBy, DedupeType deduperoms, bool lower = true, bool norename = true)
|
||||||
{
|
{
|
||||||
// If we already have the right sorting, trust it
|
|
||||||
if (_sortedBy == bucketBy)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we have a situation where there's no dictionary or no keys at all, we skip
|
// If we have a situation where there's no dictionary or no keys at all, we skip
|
||||||
if (_items == null || _items.Count == 0)
|
if (_items == null || _items.Count == 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the sorted type
|
// If the sorted type isn't the same, we want to sort the dictionary accordingly
|
||||||
_sortedBy = bucketBy;
|
if (_sortedBy != bucketBy)
|
||||||
|
|
||||||
// Clone the current dictionary into a new one for sorting then reset the internal one
|
|
||||||
SortedDictionary<string, List<DatItem>> sortable = this.CloneDictionary();
|
|
||||||
this.ResetDictionary();
|
|
||||||
|
|
||||||
Globals.Logger.User("Organizing roms by {0}" + (deduperoms != DedupeType.None ? " and merging" : ""), bucketBy);
|
|
||||||
|
|
||||||
// First do the initial sort of all of the roms
|
|
||||||
List<string> keys = sortable.Keys.ToList();
|
|
||||||
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
|
|
||||||
{
|
{
|
||||||
List<DatItem> roms = sortable[key];
|
// Set the sorted type
|
||||||
|
_sortedBy = bucketBy;
|
||||||
|
|
||||||
// Now add each of the roms to their respective games
|
// Clone the current dictionary into a new one for sorting then reset the internal one
|
||||||
foreach (DatItem rom in roms)
|
SortedDictionary<string, List<DatItem>> sortable = this.CloneDictionary();
|
||||||
|
this.ResetDictionary();
|
||||||
|
|
||||||
|
Globals.Logger.User("Organizing roms by {0}" + (deduperoms != DedupeType.None ? " and merging" : ""), bucketBy);
|
||||||
|
|
||||||
|
// First do the initial sort of all of the roms
|
||||||
|
List<string> oldkeys = sortable.Keys.ToList();
|
||||||
|
Parallel.ForEach(oldkeys, Globals.ParallelOptions, key =>
|
||||||
{
|
{
|
||||||
string newkey = "";
|
List<DatItem> roms = sortable[key];
|
||||||
|
|
||||||
// We want to get the key most appropriate for the given sorting type
|
// Now add each of the roms to their respective games
|
||||||
switch (bucketBy)
|
foreach (DatItem rom in roms)
|
||||||
{
|
{
|
||||||
case SortedBy.CRC:
|
string newkey = "";
|
||||||
newkey = (rom.Type == ItemType.Rom ? ((Rom)rom).CRC : Constants.CRCZero);
|
|
||||||
break;
|
|
||||||
case SortedBy.Game:
|
|
||||||
newkey = (norename ? ""
|
|
||||||
: rom.SystemID.ToString().PadLeft(10, '0')
|
|
||||||
+ "-"
|
|
||||||
+ rom.SourceID.ToString().PadLeft(10, '0') + "-")
|
|
||||||
+ (String.IsNullOrEmpty(rom.Machine.Name)
|
|
||||||
? "Default"
|
|
||||||
: rom.Machine.Name);
|
|
||||||
if (lower)
|
|
||||||
{
|
|
||||||
newkey = newkey.ToLowerInvariant();
|
|
||||||
}
|
|
||||||
if (newkey == null)
|
|
||||||
{
|
|
||||||
newkey = "null";
|
|
||||||
}
|
|
||||||
|
|
||||||
newkey = HttpUtility.HtmlEncode(newkey);
|
// We want to get the key most appropriate for the given sorting type
|
||||||
break;
|
switch (bucketBy)
|
||||||
case SortedBy.MD5:
|
{
|
||||||
newkey = (rom.Type == ItemType.Rom
|
case SortedBy.CRC:
|
||||||
? ((Rom)rom).MD5
|
newkey = (rom.Type == ItemType.Rom ? ((Rom)rom).CRC : Constants.CRCZero);
|
||||||
: (rom.Type == ItemType.Disk
|
break;
|
||||||
? ((Disk)rom).MD5
|
case SortedBy.Game:
|
||||||
: Constants.MD5Zero));
|
newkey = (norename ? ""
|
||||||
break;
|
: rom.SystemID.ToString().PadLeft(10, '0')
|
||||||
case SortedBy.SHA1:
|
+ "-"
|
||||||
newkey = (rom.Type == ItemType.Rom
|
+ rom.SourceID.ToString().PadLeft(10, '0') + "-")
|
||||||
? ((Rom)rom).SHA1
|
+ (String.IsNullOrEmpty(rom.Machine.Name)
|
||||||
: (rom.Type == ItemType.Disk
|
? "Default"
|
||||||
? ((Disk)rom).SHA1
|
: rom.Machine.Name);
|
||||||
: Constants.SHA1Zero));
|
if (lower)
|
||||||
break;
|
{
|
||||||
case SortedBy.SHA256:
|
newkey = newkey.ToLowerInvariant();
|
||||||
newkey = (rom.Type == ItemType.Rom
|
}
|
||||||
? ((Rom)rom).SHA256
|
if (newkey == null)
|
||||||
: (rom.Type == ItemType.Disk
|
{
|
||||||
? ((Disk)rom).SHA256
|
newkey = "null";
|
||||||
: Constants.SHA256Zero));
|
}
|
||||||
break;
|
|
||||||
case SortedBy.SHA384:
|
newkey = HttpUtility.HtmlEncode(newkey);
|
||||||
newkey = (rom.Type == ItemType.Rom
|
break;
|
||||||
? ((Rom)rom).SHA384
|
case SortedBy.MD5:
|
||||||
: (rom.Type == ItemType.Disk
|
newkey = (rom.Type == ItemType.Rom
|
||||||
? ((Disk)rom).SHA384
|
? ((Rom)rom).MD5
|
||||||
: Constants.SHA384Zero));
|
: (rom.Type == ItemType.Disk
|
||||||
break;
|
? ((Disk)rom).MD5
|
||||||
case SortedBy.SHA512:
|
: Constants.MD5Zero));
|
||||||
newkey = (rom.Type == ItemType.Rom
|
break;
|
||||||
? ((Rom)rom).SHA512
|
case SortedBy.SHA1:
|
||||||
: (rom.Type == ItemType.Disk
|
newkey = (rom.Type == ItemType.Rom
|
||||||
? ((Disk)rom).SHA512
|
? ((Rom)rom).SHA1
|
||||||
: Constants.SHA512Zero));
|
: (rom.Type == ItemType.Disk
|
||||||
break;
|
? ((Disk)rom).SHA1
|
||||||
|
: Constants.SHA1Zero));
|
||||||
|
break;
|
||||||
|
case SortedBy.SHA256:
|
||||||
|
newkey = (rom.Type == ItemType.Rom
|
||||||
|
? ((Rom)rom).SHA256
|
||||||
|
: (rom.Type == ItemType.Disk
|
||||||
|
? ((Disk)rom).SHA256
|
||||||
|
: Constants.SHA256Zero));
|
||||||
|
break;
|
||||||
|
case SortedBy.SHA384:
|
||||||
|
newkey = (rom.Type == ItemType.Rom
|
||||||
|
? ((Rom)rom).SHA384
|
||||||
|
: (rom.Type == ItemType.Disk
|
||||||
|
? ((Disk)rom).SHA384
|
||||||
|
: Constants.SHA384Zero));
|
||||||
|
break;
|
||||||
|
case SortedBy.SHA512:
|
||||||
|
newkey = (rom.Type == ItemType.Rom
|
||||||
|
? ((Rom)rom).SHA512
|
||||||
|
: (rom.Type == ItemType.Disk
|
||||||
|
? ((Disk)rom).SHA512
|
||||||
|
: Constants.SHA512Zero));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Double and triple check the key
|
||||||
|
if (newkey == null)
|
||||||
|
{
|
||||||
|
newkey = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the DatItem to the dictionary
|
||||||
|
Add(newkey, rom);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
// Double and triple check the key
|
}
|
||||||
if (newkey == null)
|
|
||||||
{
|
|
||||||
newkey = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the DatItem to the dictionary
|
|
||||||
Add(newkey, rom);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Now go through and sort all of the individual lists
|
// Now go through and sort all of the individual lists
|
||||||
keys = Keys.ToList();
|
List<string> keys = Keys.ToList();
|
||||||
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
|
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
|
||||||
{
|
{
|
||||||
// Get the possibly unsorted list
|
// Get the possibly unsorted list
|
||||||
|
|||||||
Reference in New Issue
Block a user