mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Minor tweaks to sync Item collections
This commit is contained in:
@@ -27,12 +27,12 @@ namespace SabreTools.DatFiles
|
||||
/// <summary>
|
||||
/// Determine the bucketing key for all items
|
||||
/// </summary>
|
||||
private ItemKey bucketedBy;
|
||||
private ItemKey _bucketedBy;
|
||||
|
||||
/// <summary>
|
||||
/// Determine merging type for all items
|
||||
/// </summary>
|
||||
private DedupeType mergedBy;
|
||||
private DedupeType _mergedBy;
|
||||
|
||||
/// <summary>
|
||||
/// Internal dictionary for the class
|
||||
@@ -100,8 +100,8 @@ namespace SabreTools.DatFiles
|
||||
/// </summary>
|
||||
public ItemDictionary()
|
||||
{
|
||||
bucketedBy = ItemKey.NULL;
|
||||
mergedBy = DedupeType.None;
|
||||
_bucketedBy = ItemKey.NULL;
|
||||
_mergedBy = DedupeType.None;
|
||||
_logger = new Logger(this);
|
||||
}
|
||||
|
||||
@@ -482,7 +482,7 @@ namespace SabreTools.DatFiles
|
||||
/// <param name="newBucket"></param>
|
||||
public void SetBucketedBy(ItemKey newBucket)
|
||||
{
|
||||
bucketedBy = newBucket;
|
||||
_bucketedBy = newBucket;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -503,14 +503,14 @@ namespace SabreTools.DatFiles
|
||||
return;
|
||||
|
||||
// If the sorted type isn't the same, we want to sort the dictionary accordingly
|
||||
if (bucketedBy != bucketBy && bucketBy != ItemKey.NULL)
|
||||
if (_bucketedBy != bucketBy && bucketBy != ItemKey.NULL)
|
||||
{
|
||||
_logger.User($"Organizing roms by {bucketBy}");
|
||||
PerformBucketing(bucketBy, lower, norename);
|
||||
}
|
||||
|
||||
// If the merge type isn't the same, we want to merge the dictionary accordingly
|
||||
if (mergedBy != dedupeType)
|
||||
if (_mergedBy != dedupeType)
|
||||
{
|
||||
_logger.User($"Deduping roms by {dedupeType}");
|
||||
PerformDeduplication(bucketBy, dedupeType);
|
||||
@@ -653,10 +653,10 @@ namespace SabreTools.DatFiles
|
||||
private void PerformBucketing(ItemKey bucketBy, bool lower, bool norename)
|
||||
{
|
||||
// Set the sorted type
|
||||
bucketedBy = bucketBy;
|
||||
_bucketedBy = bucketBy;
|
||||
|
||||
// Reset the merged type since this might change the merge
|
||||
mergedBy = DedupeType.None;
|
||||
_mergedBy = DedupeType.None;
|
||||
|
||||
// First do the initial sort of all of the roms inplace
|
||||
List<string> oldkeys = [.. Keys];
|
||||
@@ -713,7 +713,7 @@ namespace SabreTools.DatFiles
|
||||
private void PerformDeduplication(ItemKey bucketBy, DedupeType dedupeType)
|
||||
{
|
||||
// Set the sorted type
|
||||
mergedBy = dedupeType;
|
||||
_mergedBy = dedupeType;
|
||||
|
||||
List<string> keys = [.. Keys];
|
||||
#if NET452_OR_GREATER || NETCOREAPP
|
||||
@@ -787,7 +787,7 @@ namespace SabreTools.DatFiles
|
||||
BucketBy(GetBestAvailable(), DedupeType.None);
|
||||
|
||||
// Now that we have the sorted type, we get the proper key
|
||||
return datItem.GetKey(bucketedBy);
|
||||
return datItem.GetKey(_bucketedBy);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -1005,7 +1005,7 @@ namespace SabreTools.DatFiles
|
||||
// Treat NULL like machine
|
||||
ItemKey.NULL => (norename ? string.Empty : sourceKeyPadded) + machineName,
|
||||
ItemKey.Machine => (norename ? string.Empty : sourceKeyPadded) + machineName,
|
||||
_ => GetBucketHashValue(datItem, bucketBy),
|
||||
_ => datItem.GetKeyDB(bucketBy, source.Value, lower, norename),
|
||||
};
|
||||
|
||||
if (lower)
|
||||
@@ -1014,68 +1014,6 @@ namespace SabreTools.DatFiles
|
||||
return bucketKey;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the hash value for a given item, if possible
|
||||
/// </summary>
|
||||
private static string GetBucketHashValue(DatItem datItem, ItemKey bucketBy)
|
||||
{
|
||||
return datItem switch
|
||||
{
|
||||
Disk disk => bucketBy switch
|
||||
{
|
||||
ItemKey.CRC => ZeroHash.CRC32Str,
|
||||
ItemKey.MD2 => ZeroHash.GetString(HashType.MD2),
|
||||
ItemKey.MD4 => ZeroHash.GetString(HashType.MD4),
|
||||
ItemKey.MD5 => disk.GetStringFieldValue(Models.Metadata.Disk.MD5Key) ?? string.Empty,
|
||||
ItemKey.SHA1 => disk.GetStringFieldValue(Models.Metadata.Disk.SHA1Key) ?? string.Empty,
|
||||
ItemKey.SHA256 => ZeroHash.SHA256Str,
|
||||
ItemKey.SHA384 => ZeroHash.SHA384Str,
|
||||
ItemKey.SHA512 => ZeroHash.SHA512Str,
|
||||
ItemKey.SpamSum => ZeroHash.SpamSumStr,
|
||||
_ => string.Empty,
|
||||
},
|
||||
Media media => bucketBy switch
|
||||
{
|
||||
ItemKey.CRC => ZeroHash.CRC32Str,
|
||||
ItemKey.MD2 => ZeroHash.GetString(HashType.MD2),
|
||||
ItemKey.MD4 => ZeroHash.GetString(HashType.MD4),
|
||||
ItemKey.MD5 => media.GetStringFieldValue(Models.Metadata.Media.MD5Key) ?? string.Empty,
|
||||
ItemKey.SHA1 => media.GetStringFieldValue(Models.Metadata.Media.SHA1Key) ?? string.Empty,
|
||||
ItemKey.SHA256 => media.GetStringFieldValue(Models.Metadata.Media.SHA256Key) ?? string.Empty,
|
||||
ItemKey.SHA384 => ZeroHash.SHA384Str,
|
||||
ItemKey.SHA512 => ZeroHash.SHA512Str,
|
||||
ItemKey.SpamSum => media.GetStringFieldValue(Models.Metadata.Media.SpamSumKey) ?? string.Empty,
|
||||
_ => string.Empty,
|
||||
},
|
||||
Rom rom => bucketBy switch
|
||||
{
|
||||
ItemKey.CRC => rom.GetStringFieldValue(Models.Metadata.Rom.CRCKey) ?? string.Empty,
|
||||
ItemKey.MD2 => rom.GetStringFieldValue(Models.Metadata.Rom.MD2Key) ?? string.Empty,
|
||||
ItemKey.MD4 => rom.GetStringFieldValue(Models.Metadata.Rom.MD4Key) ?? string.Empty,
|
||||
ItemKey.MD5 => rom.GetStringFieldValue(Models.Metadata.Rom.MD5Key) ?? string.Empty,
|
||||
ItemKey.SHA1 => rom.GetStringFieldValue(Models.Metadata.Rom.SHA1Key) ?? string.Empty,
|
||||
ItemKey.SHA256 => rom.GetStringFieldValue(Models.Metadata.Rom.SHA256Key) ?? string.Empty,
|
||||
ItemKey.SHA384 => rom.GetStringFieldValue(Models.Metadata.Rom.SHA384Key) ?? string.Empty,
|
||||
ItemKey.SHA512 => rom.GetStringFieldValue(Models.Metadata.Rom.SHA512Key) ?? string.Empty,
|
||||
ItemKey.SpamSum => rom.GetStringFieldValue(Models.Metadata.Rom.SpamSumKey) ?? string.Empty,
|
||||
_ => string.Empty,
|
||||
},
|
||||
_ => bucketBy switch
|
||||
{
|
||||
ItemKey.CRC => ZeroHash.CRC32Str,
|
||||
ItemKey.MD2 => ZeroHash.GetString(HashType.MD2),
|
||||
ItemKey.MD4 => ZeroHash.GetString(HashType.MD4),
|
||||
ItemKey.MD5 => ZeroHash.MD5Str,
|
||||
ItemKey.SHA1 => ZeroHash.SHA1Str,
|
||||
ItemKey.SHA256 => ZeroHash.SHA256Str,
|
||||
ItemKey.SHA384 => ZeroHash.SHA384Str,
|
||||
ItemKey.SHA512 => ZeroHash.SHA512Str,
|
||||
ItemKey.SpamSum => ZeroHash.SpamSumStr,
|
||||
_ => string.Empty,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ensure the key exists in the items dictionary
|
||||
/// </summary>
|
||||
|
||||
@@ -468,6 +468,7 @@ namespace SabreTools.DatItems
|
||||
if (!norename && source != null)
|
||||
sourceString = source.Index.ToString().PadLeft(10, '0') + "-";
|
||||
|
||||
// TODO: This will never have a value for DB
|
||||
string machineString = "Default";
|
||||
var machine = GetFieldValue<Machine>(DatItem.MachineKey);
|
||||
if (machine != null)
|
||||
|
||||
Reference in New Issue
Block a user