mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-09-22 14:55:11 +00:00
Turn removal key into a metadata property
This commit is contained in:
@@ -242,7 +242,7 @@ namespace SabreTools.Metadata.DatFiles
|
||||
foreach (var item in items)
|
||||
{
|
||||
if (!item.PassesFilter(filterRunner))
|
||||
item.Write<bool?>(DatItem.RemoveKey, true);
|
||||
item.RemoveFlag = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,7 +263,7 @@ namespace SabreTools.Metadata.DatFiles
|
||||
foreach (var item in items)
|
||||
{
|
||||
if (!item.Value.PassesFilterDB(filterRunner))
|
||||
item.Value.Write<bool?>(DatItem.RemoveKey, true);
|
||||
item.Value.RemoveFlag = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -980,7 +980,7 @@ namespace SabreTools.Metadata.DatFiles
|
||||
}
|
||||
|
||||
// If the item is supposed to be removed, we ignore
|
||||
if (datItem.ReadBool(DatItem.RemoveKey) == true)
|
||||
if (datItem.RemoveFlag)
|
||||
{
|
||||
string itemString = JsonConvert.SerializeObject(datItem, Formatting.None);
|
||||
_logger.Verbose($"Item '{itemString}' was skipped because it was marked for removal");
|
||||
|
||||
@@ -117,7 +117,7 @@ namespace SabreTools.Metadata.DatFiles
|
||||
TotalCount++;
|
||||
|
||||
// Increment removal count
|
||||
if (item.ReadBool(DatItem.RemoveKey) == true)
|
||||
if (item.RemoveFlag)
|
||||
RemovedCount++;
|
||||
|
||||
// Increment the item count for the type
|
||||
@@ -144,44 +144,6 @@ namespace SabreTools.Metadata.DatFiles
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add to the statistics for a given DatItem
|
||||
/// </summary>
|
||||
/// <param name="item">Item to add info from</param>
|
||||
public void AddItemStatistics(Data.Models.Metadata.DatItem item)
|
||||
{
|
||||
lock (statsLock)
|
||||
{
|
||||
// No matter what the item is, we increment the count
|
||||
TotalCount++;
|
||||
|
||||
// Increment removal count
|
||||
if (item.ReadBool(DatItem.RemoveKey) == true)
|
||||
RemovedCount++;
|
||||
|
||||
// Increment the item count for the type
|
||||
AddItemCount(item.ItemType);
|
||||
|
||||
// Some item types require special processing
|
||||
switch (item)
|
||||
{
|
||||
case Data.Models.Metadata.Disk disk:
|
||||
AddItemStatistics(disk);
|
||||
break;
|
||||
case Data.Models.Metadata.Media media:
|
||||
AddItemStatistics(media);
|
||||
break;
|
||||
case Data.Models.Metadata.Rom rom:
|
||||
AddItemStatistics(rom);
|
||||
break;
|
||||
|
||||
default:
|
||||
// Item type requires no special processing
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add statistics from another DatStatistics object
|
||||
/// </summary>
|
||||
@@ -279,7 +241,7 @@ namespace SabreTools.Metadata.DatFiles
|
||||
TotalCount--;
|
||||
|
||||
// Decrement removal count
|
||||
if (item.ReadBool(DatItem.RemoveKey) == true)
|
||||
if (item.RemoveFlag)
|
||||
RemovedCount--;
|
||||
|
||||
// Decrement the item count for the type
|
||||
@@ -308,48 +270,6 @@ namespace SabreTools.Metadata.DatFiles
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove from the statistics given a DatItem
|
||||
/// </summary>
|
||||
/// <param name="item">Item to remove info for</param>
|
||||
public void RemoveItemStatistics(Data.Models.Metadata.DatItem item)
|
||||
{
|
||||
// If we have a null item, we can't do anything
|
||||
if (item is null)
|
||||
return;
|
||||
|
||||
lock (statsLock)
|
||||
{
|
||||
// No matter what the item is, we decrease the count
|
||||
TotalCount--;
|
||||
|
||||
// Decrement removal count
|
||||
if (item.ReadBool(DatItem.RemoveKey) == true)
|
||||
RemovedCount--;
|
||||
|
||||
// Decrement the item count for the type
|
||||
RemoveItemCount(item.ItemType);
|
||||
|
||||
// Some item types require special processing
|
||||
switch (item)
|
||||
{
|
||||
case Data.Models.Metadata.Disk disk:
|
||||
RemoveItemStatistics(disk);
|
||||
break;
|
||||
case Data.Models.Metadata.Media media:
|
||||
RemoveItemStatistics(media);
|
||||
break;
|
||||
case Data.Models.Metadata.Rom rom:
|
||||
RemoveItemStatistics(rom);
|
||||
break;
|
||||
|
||||
default:
|
||||
// Item type requires no special processing
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reset all statistics
|
||||
/// </summary>
|
||||
@@ -420,25 +340,6 @@ namespace SabreTools.Metadata.DatFiles
|
||||
AddStatusCount(ItemStatus.Verified, status == ItemStatus.Verified ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add to the statistics for a given Disk
|
||||
/// </summary>
|
||||
/// <param name="disk">Item to add info from</param>
|
||||
private void AddItemStatistics(Data.Models.Metadata.Disk disk)
|
||||
{
|
||||
ItemStatus? status = disk.Status;
|
||||
if (status != ItemStatus.Nodump)
|
||||
{
|
||||
AddHashCount(HashType.MD5, string.IsNullOrEmpty(disk.ReadString(Data.Models.Metadata.Disk.MD5Key)) ? 0 : 1);
|
||||
AddHashCount(HashType.SHA1, string.IsNullOrEmpty(disk.ReadString(Data.Models.Metadata.Disk.SHA1Key)) ? 0 : 1);
|
||||
}
|
||||
|
||||
AddStatusCount(ItemStatus.BadDump, status == ItemStatus.BadDump ? 1 : 0);
|
||||
AddStatusCount(ItemStatus.Good, status == ItemStatus.Good ? 1 : 0);
|
||||
AddStatusCount(ItemStatus.Nodump, status == ItemStatus.Nodump ? 1 : 0);
|
||||
AddStatusCount(ItemStatus.Verified, status == ItemStatus.Verified ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add to the statistics for a given File
|
||||
/// </summary>
|
||||
@@ -464,18 +365,6 @@ namespace SabreTools.Metadata.DatFiles
|
||||
AddHashCount(HashType.SpamSum, string.IsNullOrEmpty(media.ReadString(Data.Models.Metadata.Media.SpamSumKey)) ? 0 : 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add to the statistics for a given Media
|
||||
/// </summary>
|
||||
/// <param name="media">Item to add info from</param>
|
||||
private void AddItemStatistics(Data.Models.Metadata.Media media)
|
||||
{
|
||||
AddHashCount(HashType.MD5, string.IsNullOrEmpty(media.ReadString(Data.Models.Metadata.Media.MD5Key)) ? 0 : 1);
|
||||
AddHashCount(HashType.SHA1, string.IsNullOrEmpty(media.ReadString(Data.Models.Metadata.Media.SHA1Key)) ? 0 : 1);
|
||||
AddHashCount(HashType.SHA256, string.IsNullOrEmpty(media.ReadString(Data.Models.Metadata.Media.SHA256Key)) ? 0 : 1);
|
||||
AddHashCount(HashType.SpamSum, string.IsNullOrEmpty(media.ReadString(Data.Models.Metadata.Media.SpamSumKey)) ? 0 : 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add to the statistics for a given Rom
|
||||
/// </summary>
|
||||
@@ -507,37 +396,6 @@ namespace SabreTools.Metadata.DatFiles
|
||||
AddStatusCount(ItemStatus.Verified, status == ItemStatus.Verified ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add to the statistics for a given Rom
|
||||
/// </summary>
|
||||
/// <param name="rom">Item to add info from</param>
|
||||
private void AddItemStatistics(Data.Models.Metadata.Rom rom)
|
||||
{
|
||||
ItemStatus? status = rom.Status;
|
||||
if (status != ItemStatus.Nodump)
|
||||
{
|
||||
TotalSize += rom.ReadLong(Data.Models.Metadata.Rom.SizeKey) ?? 0;
|
||||
AddHashCount(HashType.CRC16, string.IsNullOrEmpty(rom.ReadString(Data.Models.Metadata.Rom.CRC16Key)) ? 0 : 1);
|
||||
AddHashCount(HashType.CRC32, string.IsNullOrEmpty(rom.ReadString(Data.Models.Metadata.Rom.CRCKey)) ? 0 : 1);
|
||||
AddHashCount(HashType.CRC64, string.IsNullOrEmpty(rom.ReadString(Data.Models.Metadata.Rom.CRC64Key)) ? 0 : 1);
|
||||
AddHashCount(HashType.MD2, string.IsNullOrEmpty(rom.ReadString(Data.Models.Metadata.Rom.MD2Key)) ? 0 : 1);
|
||||
AddHashCount(HashType.MD4, string.IsNullOrEmpty(rom.ReadString(Data.Models.Metadata.Rom.MD4Key)) ? 0 : 1);
|
||||
AddHashCount(HashType.MD5, string.IsNullOrEmpty(rom.ReadString(Data.Models.Metadata.Rom.MD5Key)) ? 0 : 1);
|
||||
AddHashCount(HashType.RIPEMD128, string.IsNullOrEmpty(rom.ReadString(Data.Models.Metadata.Rom.RIPEMD128Key)) ? 0 : 1);
|
||||
AddHashCount(HashType.RIPEMD160, string.IsNullOrEmpty(rom.ReadString(Data.Models.Metadata.Rom.RIPEMD160Key)) ? 0 : 1);
|
||||
AddHashCount(HashType.SHA1, string.IsNullOrEmpty(rom.ReadString(Data.Models.Metadata.Rom.SHA1Key)) ? 0 : 1);
|
||||
AddHashCount(HashType.SHA256, string.IsNullOrEmpty(rom.ReadString(Data.Models.Metadata.Rom.SHA256Key)) ? 0 : 1);
|
||||
AddHashCount(HashType.SHA384, string.IsNullOrEmpty(rom.ReadString(Data.Models.Metadata.Rom.SHA384Key)) ? 0 : 1);
|
||||
AddHashCount(HashType.SHA512, string.IsNullOrEmpty(rom.ReadString(Data.Models.Metadata.Rom.SHA512Key)) ? 0 : 1);
|
||||
AddHashCount(HashType.SpamSum, string.IsNullOrEmpty(rom.ReadString(Data.Models.Metadata.Rom.SpamSumKey)) ? 0 : 1);
|
||||
}
|
||||
|
||||
AddStatusCount(ItemStatus.BadDump, status == ItemStatus.BadDump ? 1 : 0);
|
||||
AddStatusCount(ItemStatus.Good, status == ItemStatus.Good ? 1 : 0);
|
||||
AddStatusCount(ItemStatus.Nodump, status == ItemStatus.Nodump ? 1 : 0);
|
||||
AddStatusCount(ItemStatus.Verified, status == ItemStatus.Verified ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Increment the item count for a given item status
|
||||
/// </summary>
|
||||
@@ -611,25 +469,6 @@ namespace SabreTools.Metadata.DatFiles
|
||||
RemoveStatusCount(ItemStatus.Verified, status == ItemStatus.Verified ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove from the statistics given a Disk
|
||||
/// </summary>
|
||||
/// <param name="disk">Item to remove info for</param>
|
||||
private void RemoveItemStatistics(Data.Models.Metadata.Disk disk)
|
||||
{
|
||||
ItemStatus? status = disk.Status;
|
||||
if (status != ItemStatus.Nodump)
|
||||
{
|
||||
RemoveHashCount(HashType.MD5, string.IsNullOrEmpty(disk.ReadString(Data.Models.Metadata.Disk.MD5Key)) ? 0 : 1);
|
||||
RemoveHashCount(HashType.SHA1, string.IsNullOrEmpty(disk.ReadString(Data.Models.Metadata.Disk.SHA1Key)) ? 0 : 1);
|
||||
}
|
||||
|
||||
RemoveStatusCount(ItemStatus.BadDump, status == ItemStatus.BadDump ? 1 : 0);
|
||||
RemoveStatusCount(ItemStatus.Good, status == ItemStatus.Good ? 1 : 0);
|
||||
RemoveStatusCount(ItemStatus.Nodump, status == ItemStatus.Nodump ? 1 : 0);
|
||||
RemoveStatusCount(ItemStatus.Verified, status == ItemStatus.Verified ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove from the statistics given a File
|
||||
/// </summary>
|
||||
@@ -655,18 +494,6 @@ namespace SabreTools.Metadata.DatFiles
|
||||
RemoveHashCount(HashType.SpamSum, string.IsNullOrEmpty(media.ReadString(Data.Models.Metadata.Media.SpamSumKey)) ? 0 : 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove from the statistics given a Media
|
||||
/// </summary>
|
||||
/// <param name="media">Item to remove info for</param>
|
||||
private void RemoveItemStatistics(Data.Models.Metadata.Media media)
|
||||
{
|
||||
RemoveHashCount(HashType.MD5, string.IsNullOrEmpty(media.ReadString(Data.Models.Metadata.Media.MD5Key)) ? 0 : 1);
|
||||
RemoveHashCount(HashType.SHA1, string.IsNullOrEmpty(media.ReadString(Data.Models.Metadata.Media.SHA1Key)) ? 0 : 1);
|
||||
RemoveHashCount(HashType.SHA256, string.IsNullOrEmpty(media.ReadString(Data.Models.Metadata.Media.SHA256Key)) ? 0 : 1);
|
||||
RemoveHashCount(HashType.SpamSum, string.IsNullOrEmpty(media.ReadString(Data.Models.Metadata.Media.SpamSumKey)) ? 0 : 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove from the statistics given a Rom
|
||||
/// </summary>
|
||||
@@ -698,37 +525,6 @@ namespace SabreTools.Metadata.DatFiles
|
||||
RemoveStatusCount(ItemStatus.Verified, status == ItemStatus.Verified ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove from the statistics given a Rom
|
||||
/// </summary>
|
||||
/// <param name="rom">Item to remove info for</param>
|
||||
private void RemoveItemStatistics(Data.Models.Metadata.Rom rom)
|
||||
{
|
||||
ItemStatus? status = rom.Status;
|
||||
if (status != ItemStatus.Nodump)
|
||||
{
|
||||
TotalSize -= rom.ReadLong(Data.Models.Metadata.Rom.SizeKey) ?? 0;
|
||||
RemoveHashCount(HashType.CRC16, string.IsNullOrEmpty(rom.ReadString(Data.Models.Metadata.Rom.CRC16Key)) ? 0 : 1);
|
||||
RemoveHashCount(HashType.CRC32, string.IsNullOrEmpty(rom.ReadString(Data.Models.Metadata.Rom.CRCKey)) ? 0 : 1);
|
||||
RemoveHashCount(HashType.CRC64, string.IsNullOrEmpty(rom.ReadString(Data.Models.Metadata.Rom.CRC64Key)) ? 0 : 1);
|
||||
RemoveHashCount(HashType.MD2, string.IsNullOrEmpty(rom.ReadString(Data.Models.Metadata.Rom.MD2Key)) ? 0 : 1);
|
||||
RemoveHashCount(HashType.MD4, string.IsNullOrEmpty(rom.ReadString(Data.Models.Metadata.Rom.MD4Key)) ? 0 : 1);
|
||||
RemoveHashCount(HashType.MD5, string.IsNullOrEmpty(rom.ReadString(Data.Models.Metadata.Rom.MD5Key)) ? 0 : 1);
|
||||
RemoveHashCount(HashType.RIPEMD128, string.IsNullOrEmpty(rom.ReadString(Data.Models.Metadata.Rom.RIPEMD128Key)) ? 0 : 1);
|
||||
RemoveHashCount(HashType.RIPEMD160, string.IsNullOrEmpty(rom.ReadString(Data.Models.Metadata.Rom.RIPEMD160Key)) ? 0 : 1);
|
||||
RemoveHashCount(HashType.SHA1, string.IsNullOrEmpty(rom.ReadString(Data.Models.Metadata.Rom.SHA1Key)) ? 0 : 1);
|
||||
RemoveHashCount(HashType.SHA256, string.IsNullOrEmpty(rom.ReadString(Data.Models.Metadata.Rom.SHA256Key)) ? 0 : 1);
|
||||
RemoveHashCount(HashType.SHA384, string.IsNullOrEmpty(rom.ReadString(Data.Models.Metadata.Rom.SHA384Key)) ? 0 : 1);
|
||||
RemoveHashCount(HashType.SHA512, string.IsNullOrEmpty(rom.ReadString(Data.Models.Metadata.Rom.SHA512Key)) ? 0 : 1);
|
||||
RemoveHashCount(HashType.SpamSum, string.IsNullOrEmpty(rom.ReadString(Data.Models.Metadata.Rom.SpamSumKey)) ? 0 : 1);
|
||||
}
|
||||
|
||||
RemoveStatusCount(ItemStatus.BadDump, status == ItemStatus.BadDump ? 1 : 0);
|
||||
RemoveStatusCount(ItemStatus.Good, status == ItemStatus.Good ? 1 : 0);
|
||||
RemoveStatusCount(ItemStatus.Nodump, status == ItemStatus.Nodump ? 1 : 0);
|
||||
RemoveStatusCount(ItemStatus.Verified, status == ItemStatus.Verified ? 1 : 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decrement the item count for a given item status
|
||||
/// </summary>
|
||||
|
||||
@@ -227,7 +227,7 @@ namespace SabreTools.Metadata.DatFiles
|
||||
/// 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>
|
||||
/// <param name="filter">Indicates if RemoveFlag filtering is performed</param>
|
||||
/// <returns>List representing the bucket items, empty on missing</returns>
|
||||
public List<DatItem> GetItemsForBucket(string? bucketName, bool filter = false)
|
||||
{
|
||||
@@ -250,7 +250,7 @@ namespace SabreTools.Metadata.DatFiles
|
||||
var datItems = new List<DatItem>();
|
||||
foreach (DatItem item in items)
|
||||
{
|
||||
if (item.ReadBool(DatItem.RemoveKey) != true)
|
||||
if (!item.RemoveFlag)
|
||||
datItems.Add(item);
|
||||
}
|
||||
|
||||
@@ -601,13 +601,13 @@ namespace SabreTools.Metadata.DatFiles
|
||||
foreach (DatItem other in items)
|
||||
{
|
||||
// Skip items marked for removal
|
||||
if (other.ReadBool(DatItem.RemoveKey) == true)
|
||||
if (other.RemoveFlag)
|
||||
continue;
|
||||
|
||||
// Mark duplicates for future removal
|
||||
if (datItem.Equals(other))
|
||||
{
|
||||
other.Write<bool?>(DatItem.RemoveKey, true);
|
||||
other.RemoveFlag = true;
|
||||
output.Add(other);
|
||||
}
|
||||
}
|
||||
@@ -767,7 +767,7 @@ namespace SabreTools.Metadata.DatFiles
|
||||
for (int i = 0; i < GetItemsForBucket(key).Count; i++)
|
||||
{
|
||||
DatItem item = GetItemsForBucket(key)[i];
|
||||
if (item is null || item.ReadBool(DatItem.RemoveKey) == true)
|
||||
if (item is null || item.RemoveFlag)
|
||||
continue;
|
||||
|
||||
// Get the machine and source
|
||||
|
||||
@@ -332,7 +332,7 @@ namespace SabreTools.Metadata.DatFiles
|
||||
var datItem = _items[itemIndex];
|
||||
#endif
|
||||
|
||||
if (datItem.ReadBool(DatItem.RemoveKey) != true)
|
||||
if (!datItem.RemoveFlag)
|
||||
continue;
|
||||
|
||||
RemoveItem(itemIndex);
|
||||
@@ -378,7 +378,7 @@ namespace SabreTools.Metadata.DatFiles
|
||||
continue;
|
||||
#endif
|
||||
|
||||
if (!filter || datItem.ReadBool(DatItem.RemoveKey) != true)
|
||||
if (!filter || !datItem.RemoveFlag)
|
||||
datItems[itemId] = datItem;
|
||||
}
|
||||
|
||||
@@ -805,13 +805,13 @@ namespace SabreTools.Metadata.DatFiles
|
||||
foreach (var rom in items)
|
||||
{
|
||||
// Skip items marked for removal
|
||||
if (rom.Value.ReadBool(DatItem.RemoveKey) == true)
|
||||
if (rom.Value.RemoveFlag)
|
||||
continue;
|
||||
|
||||
// Mark duplicates for future removal
|
||||
if (datItem.Value.Equals(rom.Value))
|
||||
{
|
||||
rom.Value.Write<bool?>(DatItem.RemoveKey, true);
|
||||
rom.Value.RemoveFlag = true;
|
||||
output[rom.Key] = rom.Value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user