mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Move bucketing away from Field
This commit is contained in:
@@ -277,7 +277,7 @@ namespace SabreTools.DatFiles
|
||||
}
|
||||
|
||||
// Get the key and add the file
|
||||
key = item.GetKey(Field.Machine_Name);
|
||||
key = item.GetKey(ItemKey.Machine);
|
||||
Items.Add(key, item);
|
||||
|
||||
return key;
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace SabreTools.DatFiles
|
||||
/// <summary>
|
||||
/// Determine the bucketing key for all items
|
||||
/// </summary>
|
||||
private Field bucketedBy;
|
||||
private ItemKey bucketedBy;
|
||||
|
||||
/// <summary>
|
||||
/// Determine merging type for all items
|
||||
@@ -616,10 +616,10 @@ namespace SabreTools.DatFiles
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Override the internal Field value
|
||||
/// Override the internal ItemKey value
|
||||
/// </summary>
|
||||
/// <param name="newBucket"></param>
|
||||
public void SetBucketedBy(Field newBucket)
|
||||
public void SetBucketedBy(ItemKey newBucket)
|
||||
{
|
||||
bucketedBy = newBucket;
|
||||
}
|
||||
@@ -930,7 +930,7 @@ namespace SabreTools.DatFiles
|
||||
/// </summary>
|
||||
public ItemDictionary()
|
||||
{
|
||||
bucketedBy = Field.NULL;
|
||||
bucketedBy = ItemKey.NULL;
|
||||
mergedBy = DedupeType.None;
|
||||
items = new ConcurrentDictionary<string, List<DatItem>>();
|
||||
logger = new Logger(this);
|
||||
@@ -943,11 +943,11 @@ namespace SabreTools.DatFiles
|
||||
/// <summary>
|
||||
/// Take the arbitrarily bucketed Files Dictionary and convert to one bucketed by a user-defined method
|
||||
/// </summary>
|
||||
/// <param name="bucketBy">Field enum representing how to bucket the individual items</param>
|
||||
/// <param name="bucketBy">ItemKey enum representing how to bucket the individual items</param>
|
||||
/// <param name="dedupeType">Dedupe type that should be used</param>
|
||||
/// <param name="lower">True if the key should be lowercased (default), 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>
|
||||
public void BucketBy(Field bucketBy, DedupeType dedupeType, bool lower = true, bool norename = true)
|
||||
public void BucketBy(ItemKey bucketBy, DedupeType dedupeType, bool lower = true, bool norename = true)
|
||||
{
|
||||
// If we have a situation where there's no dictionary or no keys at all, we skip
|
||||
if (items == null || items.Count == 0)
|
||||
@@ -1013,7 +1013,7 @@ namespace SabreTools.DatFiles
|
||||
DatItem.Sort(ref sortedlist, false);
|
||||
|
||||
// If we're merging the roms, do so
|
||||
if (dedupeType == DedupeType.Full || (dedupeType == DedupeType.Game && bucketBy == Field.Machine_Name))
|
||||
if (dedupeType == DedupeType.Full || (dedupeType == DedupeType.Game && bucketBy == ItemKey.Machine))
|
||||
sortedlist = DatItem.Merge(sortedlist);
|
||||
|
||||
// Add the list back to the dictionary
|
||||
@@ -1208,31 +1208,31 @@ namespace SabreTools.DatFiles
|
||||
/// <summary>
|
||||
/// Get the highest-order Field value that represents the statistics
|
||||
/// </summary>
|
||||
private Field GetBestAvailable()
|
||||
private ItemKey GetBestAvailable()
|
||||
{
|
||||
// If all items are supposed to have a SHA-512, we bucket by that
|
||||
if (DiskCount + MediaCount + RomCount - NodumpCount == SHA512Count)
|
||||
return Field.DatItem_SHA512;
|
||||
return ItemKey.SHA512;
|
||||
|
||||
// If all items are supposed to have a SHA-384, we bucket by that
|
||||
else if (DiskCount + MediaCount + RomCount - NodumpCount == SHA384Count)
|
||||
return Field.DatItem_SHA384;
|
||||
return ItemKey.SHA384;
|
||||
|
||||
// If all items are supposed to have a SHA-256, we bucket by that
|
||||
else if (DiskCount + MediaCount + RomCount - NodumpCount == SHA256Count)
|
||||
return Field.DatItem_SHA256;
|
||||
return ItemKey.SHA256;
|
||||
|
||||
// If all items are supposed to have a SHA-1, we bucket by that
|
||||
else if (DiskCount + MediaCount + RomCount - NodumpCount == SHA1Count)
|
||||
return Field.DatItem_SHA1;
|
||||
return ItemKey.SHA1;
|
||||
|
||||
// If all items are supposed to have a MD5, we bucket by that
|
||||
else if (DiskCount + MediaCount + RomCount - NodumpCount == MD5Count)
|
||||
return Field.DatItem_MD5;
|
||||
return ItemKey.MD5;
|
||||
|
||||
// Otherwise, we bucket by CRC
|
||||
else
|
||||
return Field.DatItem_CRC;
|
||||
return ItemKey.CRC;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -429,12 +429,12 @@ namespace SabreTools.DatItems
|
||||
/// <summary>
|
||||
/// Get the dictionary key that should be used for a given item and bucketing type
|
||||
/// </summary>
|
||||
/// <param name="bucketedBy">Field value representing what key to get</param>
|
||||
/// <param name="bucketedBy">ItemKey value representing what key to get</param>
|
||||
/// <param name="lower">True if the key should be lowercased (default), 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>
|
||||
/// <returns>String representing the key to be used for the DatItem</returns>
|
||||
/// TODO: What other fields can we reasonably allow bucketing on?
|
||||
public virtual string GetKey(Field bucketedBy, bool lower = true, bool norename = true)
|
||||
public virtual string GetKey(ItemKey bucketedBy, bool lower = true, bool norename = true)
|
||||
{
|
||||
// Set the output key as the default blank string
|
||||
string key = string.Empty;
|
||||
@@ -442,11 +442,11 @@ namespace SabreTools.DatItems
|
||||
// Now determine what the key should be based on the bucketedBy value
|
||||
switch (bucketedBy)
|
||||
{
|
||||
case Field.DatItem_CRC:
|
||||
case ItemKey.CRC:
|
||||
key = Constants.CRCZero;
|
||||
break;
|
||||
|
||||
case Field.Machine_Name:
|
||||
case ItemKey.Machine:
|
||||
key = (norename ? string.Empty
|
||||
: Source.Index.ToString().PadLeft(10, '0')
|
||||
+ "-")
|
||||
@@ -461,27 +461,27 @@ namespace SabreTools.DatItems
|
||||
|
||||
break;
|
||||
|
||||
case Field.DatItem_MD5:
|
||||
case ItemKey.MD5:
|
||||
key = Constants.MD5Zero;
|
||||
break;
|
||||
|
||||
case Field.DatItem_SHA1:
|
||||
case ItemKey.SHA1:
|
||||
key = Constants.SHA1Zero;
|
||||
break;
|
||||
|
||||
case Field.DatItem_SHA256:
|
||||
case ItemKey.SHA256:
|
||||
key = Constants.SHA256Zero;
|
||||
break;
|
||||
|
||||
case Field.DatItem_SHA384:
|
||||
case ItemKey.SHA384:
|
||||
key = Constants.SHA384Zero;
|
||||
break;
|
||||
|
||||
case Field.DatItem_SHA512:
|
||||
case ItemKey.SHA512:
|
||||
key = Constants.SHA512Zero;
|
||||
break;
|
||||
|
||||
case Field.DatItem_SpamSum:
|
||||
case ItemKey.SpamSum:
|
||||
key = Constants.SpamSumZero;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -366,14 +366,8 @@ namespace SabreTools.DatItems
|
||||
|
||||
#region Sorting and Merging
|
||||
|
||||
/// <summary>
|
||||
/// Get the dictionary key that should be used for a given item and bucketing type
|
||||
/// </summary>
|
||||
/// <param name="bucketedBy">Field enum representing what key to get</param>
|
||||
/// <param name="lower">True if the key should be lowercased (default), 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>
|
||||
/// <returns>String representing the key to be used for the DatItem</returns>
|
||||
public override string GetKey(Field bucketedBy, bool lower = true, bool norename = true)
|
||||
/// <inheritdoc/>
|
||||
public override string GetKey(ItemKey bucketedBy, bool lower = true, bool norename = true)
|
||||
{
|
||||
// Set the output key as the default blank string
|
||||
string key = string.Empty;
|
||||
@@ -381,11 +375,11 @@ namespace SabreTools.DatItems
|
||||
// Now determine what the key should be based on the bucketedBy value
|
||||
switch (bucketedBy)
|
||||
{
|
||||
case Field.DatItem_MD5:
|
||||
case ItemKey.MD5:
|
||||
key = MD5;
|
||||
break;
|
||||
|
||||
case Field.DatItem_SHA1:
|
||||
case ItemKey.SHA1:
|
||||
key = SHA1;
|
||||
break;
|
||||
|
||||
|
||||
@@ -16,4 +16,22 @@ namespace SabreTools.DatItems
|
||||
Internal = 1 << 2,
|
||||
External = 1 << 3,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A subset of fields that can be used as keys
|
||||
/// </summary>
|
||||
public enum ItemKey
|
||||
{
|
||||
NULL = 0,
|
||||
|
||||
Machine,
|
||||
|
||||
CRC,
|
||||
MD5,
|
||||
SHA1,
|
||||
SHA256,
|
||||
SHA384,
|
||||
SHA512,
|
||||
SpamSum,
|
||||
}
|
||||
}
|
||||
@@ -289,14 +289,8 @@ namespace SabreTools.DatItems
|
||||
|
||||
#region Sorting and Merging
|
||||
|
||||
/// <summary>
|
||||
/// Get the dictionary key that should be used for a given item and bucketing type
|
||||
/// </summary>
|
||||
/// <param name="bucketedBy">Field enum representing what key to get</param>
|
||||
/// <param name="lower">True if the key should be lowercased (default), 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>
|
||||
/// <returns>String representing the key to be used for the DatItem</returns>
|
||||
public override string GetKey(Field bucketedBy, bool lower = true, bool norename = true)
|
||||
/// <inheritdoc/>
|
||||
public override string GetKey(ItemKey bucketedBy, bool lower = true, bool norename = true)
|
||||
{
|
||||
// Set the output key as the default blank string
|
||||
string key = string.Empty;
|
||||
@@ -304,19 +298,19 @@ namespace SabreTools.DatItems
|
||||
// Now determine what the key should be based on the bucketedBy value
|
||||
switch (bucketedBy)
|
||||
{
|
||||
case Field.DatItem_MD5:
|
||||
case ItemKey.MD5:
|
||||
key = MD5;
|
||||
break;
|
||||
|
||||
case Field.DatItem_SHA1:
|
||||
case ItemKey.SHA1:
|
||||
key = SHA1;
|
||||
break;
|
||||
|
||||
case Field.DatItem_SHA256:
|
||||
case ItemKey.SHA256:
|
||||
key = SHA256;
|
||||
break;
|
||||
|
||||
case Field.DatItem_SpamSum:
|
||||
case ItemKey.SpamSum:
|
||||
key = SpamSum;
|
||||
break;
|
||||
|
||||
|
||||
@@ -625,14 +625,8 @@ namespace SabreTools.DatItems
|
||||
|
||||
#region Sorting and Merging
|
||||
|
||||
/// <summary>
|
||||
/// Get the dictionary key that should be used for a given item and bucketing type
|
||||
/// </summary>
|
||||
/// <param name="bucketedBy">Field enum representing what key to get</param>
|
||||
/// <param name="lower">True if the key should be lowercased (default), 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>
|
||||
/// <returns>String representing the key to be used for the DatItem</returns>
|
||||
public override string GetKey(Field bucketedBy, bool lower = true, bool norename = true)
|
||||
/// <inheritdoc/>
|
||||
public override string GetKey(ItemKey bucketedBy, bool lower = true, bool norename = true)
|
||||
{
|
||||
// Set the output key as the default blank string
|
||||
string key = string.Empty;
|
||||
@@ -640,31 +634,31 @@ namespace SabreTools.DatItems
|
||||
// Now determine what the key should be based on the bucketedBy value
|
||||
switch (bucketedBy)
|
||||
{
|
||||
case Field.DatItem_CRC:
|
||||
case ItemKey.CRC:
|
||||
key = CRC;
|
||||
break;
|
||||
|
||||
case Field.DatItem_MD5:
|
||||
case ItemKey.MD5:
|
||||
key = MD5;
|
||||
break;
|
||||
|
||||
case Field.DatItem_SHA1:
|
||||
case ItemKey.SHA1:
|
||||
key = SHA1;
|
||||
break;
|
||||
|
||||
case Field.DatItem_SHA256:
|
||||
case ItemKey.SHA256:
|
||||
key = SHA256;
|
||||
break;
|
||||
|
||||
case Field.DatItem_SHA384:
|
||||
case ItemKey.SHA384:
|
||||
key = SHA384;
|
||||
break;
|
||||
|
||||
case Field.DatItem_SHA512:
|
||||
case ItemKey.SHA512:
|
||||
key = SHA512;
|
||||
break;
|
||||
|
||||
case Field.DatItem_SpamSum:
|
||||
case ItemKey.SpamSum:
|
||||
key = SpamSum;
|
||||
break;
|
||||
|
||||
|
||||
@@ -337,7 +337,7 @@ namespace SabreTools.DatTools
|
||||
SetDatItemInfo(datFile, datItem, item, parent, basepath);
|
||||
|
||||
// Add the file information to the DAT
|
||||
string key = datItem.GetKey(Field.DatItem_CRC);
|
||||
string key = datItem.GetKey(ItemKey.CRC);
|
||||
datFile.Items.Add(key, datItem);
|
||||
|
||||
logger.Verbose($"File added: {datItem.GetName() ?? string.Empty}");
|
||||
|
||||
Reference in New Issue
Block a user