using System.Collections.Generic; using SabreTools.Core.Tools; using SabreTools.DatItems; using SabreTools.DatItems.Formats; using SabreTools.Hashing; namespace SabreTools.DatFiles { /// /// Statistics wrapper for outputting /// public class DatStatistics { #region Private instance variables /// /// Number of items for each hash type /// private readonly Dictionary _hashCounts = []; /// /// Number of items for each item type /// private readonly Dictionary _itemCounts = []; /// /// Number of items for each item status /// private readonly Dictionary _statusCounts = []; /// /// Lock for statistics calculation /// private readonly object statsLock = new(); #endregion #region Fields /// /// Overall item count /// public long TotalCount { get; private set; } = 0; /// /// Number of machines /// /// Special count only used by statistics output public long GameCount { get; set; } = 0; /// /// Total uncompressed size /// public long TotalSize { get; private set; } = 0; /// /// Number of items with the remove flag /// public long RemovedCount { get; private set; } = 0; /// /// Name to display on output /// public string? DisplayName { get; set; } /// /// Total machine count to use on output /// public long MachineCount { get; set; } /// /// Determines if statistics are for a directory or not /// public readonly bool IsDirectory; #endregion #region Constructors /// /// Default constructor /// public DatStatistics() { DisplayName = null; MachineCount = 0; IsDirectory = false; } /// /// Constructor for aggregate data /// public DatStatistics(string? displayName, bool isDirectory) { DisplayName = displayName; MachineCount = 0; IsDirectory = isDirectory; } #endregion #region Accessors /// /// Add to the statistics for a given DatItem /// /// Item to add info from public void AddItemStatistics(DatItem item) { lock (statsLock) { // No matter what the item is, we increment the count TotalCount++; // Increment removal count if (item.GetBoolFieldValue(DatItem.RemoveKey) == true) RemovedCount++; // Increment the item count for the type AddItemCount(item.GetStringFieldValue(Models.Metadata.DatItem.TypeKey).AsEnumValue()); // Some item types require special processing switch (item) { case Disk disk: AddItemStatistics(disk); break; case DatItems.Formats.File file: AddItemStatistics(file); break; case Media media: AddItemStatistics(media); break; case Rom rom: AddItemStatistics(rom); break; } } } /// /// Add to the statistics for a given DatItem /// /// Item to add info from public void AddItemStatistics(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.ReadString(Models.Metadata.DatItem.TypeKey).AsEnumValue()); // Some item types require special processing switch (item) { case Models.Metadata.Disk disk: AddItemStatistics(disk); break; case Models.Metadata.Media media: AddItemStatistics(media); break; case Models.Metadata.Rom rom: AddItemStatistics(rom); break; } } } /// /// Add statistics from another DatStatistics object /// /// DatStatistics object to add from public void AddStatistics(DatStatistics stats) { TotalCount += stats.TotalCount; // Loop through and add stats for all items foreach (var itemCountKvp in stats._itemCounts) { AddItemCount(itemCountKvp.Key, itemCountKvp.Value); } GameCount += stats.GameCount; TotalSize += stats.TotalSize; // Individual hash counts foreach (var hashCountKvp in stats._hashCounts) { AddHashCount(hashCountKvp.Key, hashCountKvp.Value); } // Individual status counts foreach (var statusCountKvp in stats._statusCounts) { AddStatusCount(statusCountKvp.Key, statusCountKvp.Value); } RemovedCount += stats.RemovedCount; } /// /// Get the item count for a given hash type, defaulting to 0 if it does not exist /// /// Hash type to retrieve /// The number of items with that hash, if it exists public long GetHashCount(HashType hashType) { lock (_hashCounts) { if (!_hashCounts.ContainsKey(hashType)) return 0; return _hashCounts[hashType]; } } /// /// Get the item count for a given item type, defaulting to 0 if it does not exist /// /// Item type to retrieve /// The number of items of that type, if it exists public long GetItemCount(ItemType itemType) { lock (_itemCounts) { if (!_itemCounts.ContainsKey(itemType)) return 0; return _itemCounts[itemType]; } } /// /// Get the item count for a given item status, defaulting to 0 if it does not exist /// /// Item status to retrieve /// The number of items of that type, if it exists public long GetStatusCount(ItemStatus itemStatus) { lock (_statusCounts) { if (!_statusCounts.ContainsKey(itemStatus)) return 0; return _statusCounts[itemStatus]; } } /// /// Remove from the statistics given a DatItem /// /// Item to remove info for public void RemoveItemStatistics(DatItem item) { // If we have a null item, we can't do anything if (item == null) return; lock (statsLock) { // No matter what the item is, we decrease the count TotalCount--; // Decrement removal count if (item.GetBoolFieldValue(DatItem.RemoveKey) == true) RemovedCount--; // Decrement the item count for the type RemoveItemCount(item.GetStringFieldValue(Models.Metadata.DatItem.TypeKey).AsEnumValue()); // Some item types require special processing switch (item) { case Disk disk: RemoveItemStatistics(disk); break; case DatItems.Formats.File file: RemoveItemStatistics(file); break; case Media media: RemoveItemStatistics(media); break; case Rom rom: RemoveItemStatistics(rom); break; } } } /// /// Remove from the statistics given a DatItem /// /// Item to remove info for public void RemoveItemStatistics(Models.Metadata.DatItem item) { // If we have a null item, we can't do anything if (item == 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.ReadString(Models.Metadata.DatItem.TypeKey).AsEnumValue()); // Some item types require special processing switch (item) { case Models.Metadata.Disk disk: RemoveItemStatistics(disk); break; case Models.Metadata.Media media: RemoveItemStatistics(media); break; case Models.Metadata.Rom rom: RemoveItemStatistics(rom); break; } } } /// /// Reset all statistics /// public void ResetStatistics() { _hashCounts.Clear(); _itemCounts.Clear(); _statusCounts.Clear(); TotalCount = 0; GameCount = 0; TotalSize = 0; RemovedCount = 0; } /// /// Increment the hash count for a given hash type /// /// Hash type to increment /// Amount to increment by, defaults to 1 private void AddHashCount(HashType hashType, long interval = 1) { lock (_hashCounts) { if (!_hashCounts.ContainsKey(hashType)) _hashCounts[hashType] = 0; _hashCounts[hashType] += interval; if (_hashCounts[hashType] < 0) _hashCounts[hashType] = 0; } } /// /// Increment the item count for a given item type /// /// Item type to increment /// Amount to increment by, defaults to 1 private void AddItemCount(ItemType itemType, long interval = 1) { lock (_itemCounts) { if (!_itemCounts.ContainsKey(itemType)) _itemCounts[itemType] = 0; _itemCounts[itemType] += interval; if (_itemCounts[itemType] < 0) _itemCounts[itemType] = 0; } } /// /// Add to the statistics for a given Disk /// /// Item to add info from private void AddItemStatistics(Disk disk) { if (disk.GetStringFieldValue(Models.Metadata.Disk.StatusKey).AsEnumValue() != ItemStatus.Nodump) { AddHashCount(HashType.MD5, string.IsNullOrEmpty(disk.GetStringFieldValue(Models.Metadata.Disk.MD5Key)) ? 0 : 1); AddHashCount(HashType.SHA1, string.IsNullOrEmpty(disk.GetStringFieldValue(Models.Metadata.Disk.SHA1Key)) ? 0 : 1); } AddStatusCount(ItemStatus.BadDump, disk.GetStringFieldValue(Models.Metadata.Disk.StatusKey).AsEnumValue() == ItemStatus.BadDump ? 1 : 0); AddStatusCount(ItemStatus.Good, disk.GetStringFieldValue(Models.Metadata.Disk.StatusKey).AsEnumValue() == ItemStatus.Good ? 1 : 0); AddStatusCount(ItemStatus.Nodump, disk.GetStringFieldValue(Models.Metadata.Disk.StatusKey).AsEnumValue() == ItemStatus.Nodump ? 1 : 0); AddStatusCount(ItemStatus.Verified, disk.GetStringFieldValue(Models.Metadata.Disk.StatusKey).AsEnumValue() == ItemStatus.Verified ? 1 : 0); } /// /// Add to the statistics for a given Disk /// /// Item to add info from private void AddItemStatistics(Models.Metadata.Disk disk) { if (disk.ReadString(Models.Metadata.Disk.StatusKey).AsEnumValue() != ItemStatus.Nodump) { AddHashCount(HashType.MD5, string.IsNullOrEmpty(disk.ReadString(Models.Metadata.Disk.MD5Key)) ? 0 : 1); AddHashCount(HashType.SHA1, string.IsNullOrEmpty(disk.ReadString(Models.Metadata.Disk.SHA1Key)) ? 0 : 1); } AddStatusCount(ItemStatus.BadDump, disk.ReadString(Models.Metadata.Disk.StatusKey).AsEnumValue() == ItemStatus.BadDump ? 1 : 0); AddStatusCount(ItemStatus.Good, disk.ReadString(Models.Metadata.Disk.StatusKey).AsEnumValue() == ItemStatus.Good ? 1 : 0); AddStatusCount(ItemStatus.Nodump, disk.ReadString(Models.Metadata.Disk.StatusKey).AsEnumValue() == ItemStatus.Nodump ? 1 : 0); AddStatusCount(ItemStatus.Verified, disk.ReadString(Models.Metadata.Disk.StatusKey).AsEnumValue() == ItemStatus.Verified ? 1 : 0); } /// /// Add to the statistics for a given File /// /// Item to add info from private void AddItemStatistics(DatItems.Formats.File file) { TotalSize += file.Size ?? 0; AddHashCount(HashType.CRC32, string.IsNullOrEmpty(file.CRC) ? 0 : 1); AddHashCount(HashType.MD5, string.IsNullOrEmpty(file.MD5) ? 0 : 1); AddHashCount(HashType.SHA1, string.IsNullOrEmpty(file.SHA1) ? 0 : 1); AddHashCount(HashType.SHA256, string.IsNullOrEmpty(file.SHA256) ? 0 : 1); } /// /// Add to the statistics for a given Media /// /// Item to add info from private void AddItemStatistics(Media media) { AddHashCount(HashType.MD5, string.IsNullOrEmpty(media.GetStringFieldValue(Models.Metadata.Media.MD5Key)) ? 0 : 1); AddHashCount(HashType.SHA1, string.IsNullOrEmpty(media.GetStringFieldValue(Models.Metadata.Media.SHA1Key)) ? 0 : 1); AddHashCount(HashType.SHA256, string.IsNullOrEmpty(media.GetStringFieldValue(Models.Metadata.Media.SHA256Key)) ? 0 : 1); AddHashCount(HashType.SpamSum, string.IsNullOrEmpty(media.GetStringFieldValue(Models.Metadata.Media.SpamSumKey)) ? 0 : 1); } /// /// Add to the statistics for a given Media /// /// Item to add info from private void AddItemStatistics(Models.Metadata.Media media) { AddHashCount(HashType.MD5, string.IsNullOrEmpty(media.ReadString(Models.Metadata.Media.MD5Key)) ? 0 : 1); AddHashCount(HashType.SHA1, string.IsNullOrEmpty(media.ReadString(Models.Metadata.Media.SHA1Key)) ? 0 : 1); AddHashCount(HashType.SHA256, string.IsNullOrEmpty(media.ReadString(Models.Metadata.Media.SHA256Key)) ? 0 : 1); AddHashCount(HashType.SpamSum, string.IsNullOrEmpty(media.ReadString(Models.Metadata.Media.SpamSumKey)) ? 0 : 1); } /// /// Add to the statistics for a given Rom /// /// Item to add info from private void AddItemStatistics(Rom rom) { if (rom.GetStringFieldValue(Models.Metadata.Rom.StatusKey).AsEnumValue() != ItemStatus.Nodump) { TotalSize += rom.GetInt64FieldValue(Models.Metadata.Rom.SizeKey) ?? 0; AddHashCount(HashType.CRC32, string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.CRCKey)) ? 0 : 1); AddHashCount(HashType.MD2, string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.MD2Key)) ? 0 : 1); AddHashCount(HashType.MD4, string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.MD4Key)) ? 0 : 1); AddHashCount(HashType.MD5, string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.MD5Key)) ? 0 : 1); AddHashCount(HashType.SHA1, string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.SHA1Key)) ? 0 : 1); AddHashCount(HashType.SHA256, string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.SHA256Key)) ? 0 : 1); AddHashCount(HashType.SHA384, string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.SHA384Key)) ? 0 : 1); AddHashCount(HashType.SHA512, string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.SHA512Key)) ? 0 : 1); AddHashCount(HashType.SpamSum, string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.SpamSumKey)) ? 0 : 1); } AddStatusCount(ItemStatus.BadDump, rom.GetStringFieldValue(Models.Metadata.Rom.StatusKey).AsEnumValue() == ItemStatus.BadDump ? 1 : 0); AddStatusCount(ItemStatus.Good, rom.GetStringFieldValue(Models.Metadata.Rom.StatusKey).AsEnumValue() == ItemStatus.Good ? 1 : 0); AddStatusCount(ItemStatus.Nodump, rom.GetStringFieldValue(Models.Metadata.Rom.StatusKey).AsEnumValue() == ItemStatus.Nodump ? 1 : 0); AddStatusCount(ItemStatus.Verified, rom.GetStringFieldValue(Models.Metadata.Rom.StatusKey).AsEnumValue() == ItemStatus.Verified ? 1 : 0); } /// /// Add to the statistics for a given Rom /// /// Item to add info from private void AddItemStatistics(Models.Metadata.Rom rom) { if (rom.ReadString(Models.Metadata.Rom.StatusKey).AsEnumValue() != ItemStatus.Nodump) { TotalSize += rom.ReadLong(Models.Metadata.Rom.SizeKey) ?? 0; AddHashCount(HashType.CRC32, string.IsNullOrEmpty(rom.ReadString(Models.Metadata.Rom.CRCKey)) ? 0 : 1); AddHashCount(HashType.MD2, string.IsNullOrEmpty(rom.ReadString(Models.Metadata.Rom.MD2Key)) ? 0 : 1); AddHashCount(HashType.MD4, string.IsNullOrEmpty(rom.ReadString(Models.Metadata.Rom.MD4Key)) ? 0 : 1); AddHashCount(HashType.MD5, string.IsNullOrEmpty(rom.ReadString(Models.Metadata.Rom.MD5Key)) ? 0 : 1); AddHashCount(HashType.SHA1, string.IsNullOrEmpty(rom.ReadString(Models.Metadata.Rom.SHA1Key)) ? 0 : 1); AddHashCount(HashType.SHA256, string.IsNullOrEmpty(rom.ReadString(Models.Metadata.Rom.SHA256Key)) ? 0 : 1); AddHashCount(HashType.SHA384, string.IsNullOrEmpty(rom.ReadString(Models.Metadata.Rom.SHA384Key)) ? 0 : 1); AddHashCount(HashType.SHA512, string.IsNullOrEmpty(rom.ReadString(Models.Metadata.Rom.SHA512Key)) ? 0 : 1); AddHashCount(HashType.SpamSum, string.IsNullOrEmpty(rom.ReadString(Models.Metadata.Rom.SpamSumKey)) ? 0 : 1); } AddStatusCount(ItemStatus.BadDump, rom.ReadString(Models.Metadata.Rom.StatusKey).AsEnumValue() == ItemStatus.BadDump ? 1 : 0); AddStatusCount(ItemStatus.Good, rom.ReadString(Models.Metadata.Rom.StatusKey).AsEnumValue() == ItemStatus.Good ? 1 : 0); AddStatusCount(ItemStatus.Nodump, rom.ReadString(Models.Metadata.Rom.StatusKey).AsEnumValue() == ItemStatus.Nodump ? 1 : 0); AddStatusCount(ItemStatus.Verified, rom.ReadString(Models.Metadata.Rom.StatusKey).AsEnumValue() == ItemStatus.Verified ? 1 : 0); } /// /// Increment the item count for a given item status /// /// Item type to increment /// Amount to increment by, defaults to 1 private void AddStatusCount(ItemStatus itemStatus, long interval = 1) { lock (_statusCounts) { if (!_statusCounts.ContainsKey(itemStatus)) _statusCounts[itemStatus] = 0; _statusCounts[itemStatus] += interval; if (_statusCounts[itemStatus] < 0) _statusCounts[itemStatus] = 0; } } /// /// Decrement the hash count for a given hash type /// /// Hash type to increment /// Amount to increment by, defaults to 1 private void RemoveHashCount(HashType hashType, long interval = 1) { lock (_hashCounts) { if (!_hashCounts.ContainsKey(hashType)) return; _hashCounts[hashType] -= interval; if (_hashCounts[hashType] < 0) _hashCounts[hashType] = 0; } } /// /// Decrement the item count for a given item type /// /// Item type to decrement /// Amount to increment by, defaults to 1 private void RemoveItemCount(ItemType itemType, long interval = 1) { lock (_itemCounts) { if (!_itemCounts.ContainsKey(itemType)) return; _itemCounts[itemType] -= interval; if (_itemCounts[itemType] < 0) _itemCounts[itemType] = 0; } } /// /// Remove from the statistics given a Disk /// /// Item to remove info for private void RemoveItemStatistics(Disk disk) { if (disk.GetStringFieldValue(Models.Metadata.Disk.StatusKey).AsEnumValue() != ItemStatus.Nodump) { RemoveHashCount(HashType.MD5, string.IsNullOrEmpty(disk.GetStringFieldValue(Models.Metadata.Disk.MD5Key)) ? 0 : 1); RemoveHashCount(HashType.SHA1, string.IsNullOrEmpty(disk.GetStringFieldValue(Models.Metadata.Disk.SHA1Key)) ? 0 : 1); } RemoveStatusCount(ItemStatus.BadDump, disk.GetStringFieldValue(Models.Metadata.Disk.StatusKey).AsEnumValue() == ItemStatus.BadDump ? 1 : 0); RemoveStatusCount(ItemStatus.Good, disk.GetStringFieldValue(Models.Metadata.Disk.StatusKey).AsEnumValue() == ItemStatus.Good ? 1 : 0); RemoveStatusCount(ItemStatus.Nodump, disk.GetStringFieldValue(Models.Metadata.Disk.StatusKey).AsEnumValue() == ItemStatus.Nodump ? 1 : 0); RemoveStatusCount(ItemStatus.Verified, disk.GetStringFieldValue(Models.Metadata.Disk.StatusKey).AsEnumValue() == ItemStatus.Verified ? 1 : 0); } /// /// Remove from the statistics given a Disk /// /// Item to remove info for private void RemoveItemStatistics(Models.Metadata.Disk disk) { if (disk.ReadString(Models.Metadata.Disk.StatusKey).AsEnumValue() != ItemStatus.Nodump) { RemoveHashCount(HashType.MD5, string.IsNullOrEmpty(disk.ReadString(Models.Metadata.Disk.MD5Key)) ? 0 : 1); RemoveHashCount(HashType.SHA1, string.IsNullOrEmpty(disk.ReadString(Models.Metadata.Disk.SHA1Key)) ? 0 : 1); } RemoveStatusCount(ItemStatus.BadDump, disk.ReadString(Models.Metadata.Disk.StatusKey).AsEnumValue() == ItemStatus.BadDump ? 1 : 0); RemoveStatusCount(ItemStatus.Good, disk.ReadString(Models.Metadata.Disk.StatusKey).AsEnumValue() == ItemStatus.Good ? 1 : 0); RemoveStatusCount(ItemStatus.Nodump, disk.ReadString(Models.Metadata.Disk.StatusKey).AsEnumValue() == ItemStatus.Nodump ? 1 : 0); RemoveStatusCount(ItemStatus.Verified, disk.ReadString(Models.Metadata.Disk.StatusKey).AsEnumValue() == ItemStatus.Verified ? 1 : 0); } /// /// Remove from the statistics given a File /// /// Item to remove info for private void RemoveItemStatistics(DatItems.Formats.File file) { TotalSize -= file.Size ?? 0; RemoveHashCount(HashType.CRC32, string.IsNullOrEmpty(file.CRC) ? 0 : 1); RemoveHashCount(HashType.MD5, string.IsNullOrEmpty(file.MD5) ? 0 : 1); RemoveHashCount(HashType.SHA1, string.IsNullOrEmpty(file.SHA1) ? 0 : 1); RemoveHashCount(HashType.SHA256, string.IsNullOrEmpty(file.SHA256) ? 0 : 1); } /// /// Remove from the statistics given a Media /// /// Item to remove info for private void RemoveItemStatistics(Media media) { RemoveHashCount(HashType.MD5, string.IsNullOrEmpty(media.GetStringFieldValue(Models.Metadata.Media.MD5Key)) ? 0 : 1); RemoveHashCount(HashType.SHA1, string.IsNullOrEmpty(media.GetStringFieldValue(Models.Metadata.Media.SHA1Key)) ? 0 : 1); RemoveHashCount(HashType.SHA256, string.IsNullOrEmpty(media.GetStringFieldValue(Models.Metadata.Media.SHA256Key)) ? 0 : 1); RemoveHashCount(HashType.SpamSum, string.IsNullOrEmpty(media.GetStringFieldValue(Models.Metadata.Media.SpamSumKey)) ? 0 : 1); } /// /// Remove from the statistics given a Media /// /// Item to remove info for private void RemoveItemStatistics(Models.Metadata.Media media) { RemoveHashCount(HashType.MD5, string.IsNullOrEmpty(media.ReadString(Models.Metadata.Media.MD5Key)) ? 0 : 1); RemoveHashCount(HashType.SHA1, string.IsNullOrEmpty(media.ReadString(Models.Metadata.Media.SHA1Key)) ? 0 : 1); RemoveHashCount(HashType.SHA256, string.IsNullOrEmpty(media.ReadString(Models.Metadata.Media.SHA256Key)) ? 0 : 1); RemoveHashCount(HashType.SpamSum, string.IsNullOrEmpty(media.ReadString(Models.Metadata.Media.SpamSumKey)) ? 0 : 1); } /// /// Remove from the statistics given a Rom /// /// Item to remove info for private void RemoveItemStatistics(Rom rom) { if (rom.GetStringFieldValue(Models.Metadata.Rom.StatusKey).AsEnumValue() != ItemStatus.Nodump) { TotalSize -= rom.GetInt64FieldValue(Models.Metadata.Rom.SizeKey) ?? 0; RemoveHashCount(HashType.CRC32, string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.CRCKey)) ? 0 : 1); RemoveHashCount(HashType.MD2, string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.MD2Key)) ? 0 : 1); RemoveHashCount(HashType.MD4, string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.MD4Key)) ? 0 : 1); RemoveHashCount(HashType.MD5, string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.MD5Key)) ? 0 : 1); RemoveHashCount(HashType.SHA1, string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.SHA1Key)) ? 0 : 1); RemoveHashCount(HashType.SHA256, string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.SHA256Key)) ? 0 : 1); RemoveHashCount(HashType.SHA384, string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.SHA384Key)) ? 0 : 1); RemoveHashCount(HashType.SHA512, string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.SHA512Key)) ? 0 : 1); RemoveHashCount(HashType.SpamSum, string.IsNullOrEmpty(rom.GetStringFieldValue(Models.Metadata.Rom.SpamSumKey)) ? 0 : 1); } RemoveStatusCount(ItemStatus.BadDump, rom.GetStringFieldValue(Models.Metadata.Rom.StatusKey).AsEnumValue() == ItemStatus.BadDump ? 1 : 0); RemoveStatusCount(ItemStatus.Good, rom.GetStringFieldValue(Models.Metadata.Rom.StatusKey).AsEnumValue() == ItemStatus.Good ? 1 : 0); RemoveStatusCount(ItemStatus.Nodump, rom.GetStringFieldValue(Models.Metadata.Rom.StatusKey).AsEnumValue() == ItemStatus.Nodump ? 1 : 0); RemoveStatusCount(ItemStatus.Verified, rom.GetStringFieldValue(Models.Metadata.Rom.StatusKey).AsEnumValue() == ItemStatus.Verified ? 1 : 0); } /// /// Remove from the statistics given a Rom /// /// Item to remove info for private void RemoveItemStatistics(Models.Metadata.Rom rom) { if (rom.ReadString(Models.Metadata.Rom.StatusKey).AsEnumValue() != ItemStatus.Nodump) { TotalSize -= rom.ReadLong(Models.Metadata.Rom.SizeKey) ?? 0; RemoveHashCount(HashType.CRC32, string.IsNullOrEmpty(rom.ReadString(Models.Metadata.Rom.CRCKey)) ? 0 : 1); RemoveHashCount(HashType.MD2, string.IsNullOrEmpty(rom.ReadString(Models.Metadata.Rom.MD2Key)) ? 0 : 1); RemoveHashCount(HashType.MD4, string.IsNullOrEmpty(rom.ReadString(Models.Metadata.Rom.MD4Key)) ? 0 : 1); RemoveHashCount(HashType.MD5, string.IsNullOrEmpty(rom.ReadString(Models.Metadata.Rom.MD5Key)) ? 0 : 1); RemoveHashCount(HashType.SHA1, string.IsNullOrEmpty(rom.ReadString(Models.Metadata.Rom.SHA1Key)) ? 0 : 1); RemoveHashCount(HashType.SHA256, string.IsNullOrEmpty(rom.ReadString(Models.Metadata.Rom.SHA256Key)) ? 0 : 1); RemoveHashCount(HashType.SHA384, string.IsNullOrEmpty(rom.ReadString(Models.Metadata.Rom.SHA384Key)) ? 0 : 1); RemoveHashCount(HashType.SHA512, string.IsNullOrEmpty(rom.ReadString(Models.Metadata.Rom.SHA512Key)) ? 0 : 1); RemoveHashCount(HashType.SpamSum, string.IsNullOrEmpty(rom.ReadString(Models.Metadata.Rom.SpamSumKey)) ? 0 : 1); } RemoveStatusCount(ItemStatus.BadDump, rom.ReadString(Models.Metadata.Rom.StatusKey).AsEnumValue() == ItemStatus.BadDump ? 1 : 0); RemoveStatusCount(ItemStatus.Good, rom.ReadString(Models.Metadata.Rom.StatusKey).AsEnumValue() == ItemStatus.Good ? 1 : 0); RemoveStatusCount(ItemStatus.Nodump, rom.ReadString(Models.Metadata.Rom.StatusKey).AsEnumValue() == ItemStatus.Nodump ? 1 : 0); RemoveStatusCount(ItemStatus.Verified, rom.ReadString(Models.Metadata.Rom.StatusKey).AsEnumValue() == ItemStatus.Verified ? 1 : 0); } /// /// Decrement the item count for a given item status /// /// Item type to decrement /// Amount to increment by, defaults to 1 private void RemoveStatusCount(ItemStatus itemStatus, long interval = 1) { lock (_statusCounts) { if (!_statusCounts.ContainsKey(itemStatus)) return; _statusCounts[itemStatus] -= interval; if (_statusCounts[itemStatus] < 0) _statusCounts[itemStatus] = 0; } } #endregion } }