2020-12-10 23:24:09 -08:00
|
|
|
|
using System.Collections;
|
2020-08-31 15:54:53 -07:00
|
|
|
|
using System.Collections.Concurrent;
|
2020-07-26 22:34:45 -07:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Threading.Tasks;
|
2020-09-08 10:12:41 -07:00
|
|
|
|
using System.Xml.Serialization;
|
2020-07-26 22:34:45 -07:00
|
|
|
|
|
2020-12-08 13:23:59 -08:00
|
|
|
|
using SabreTools.Core;
|
2020-12-08 15:15:41 -08:00
|
|
|
|
using SabreTools.DatItems;
|
2021-02-02 10:23:43 -08:00
|
|
|
|
using SabreTools.DatItems.Formats;
|
2020-12-07 14:29:45 -08:00
|
|
|
|
using SabreTools.Logging;
|
2020-07-26 22:34:45 -07:00
|
|
|
|
using NaturalSort;
|
2020-08-24 01:06:52 -07:00
|
|
|
|
using Newtonsoft.Json;
|
2020-07-26 22:34:45 -07:00
|
|
|
|
|
2020-12-08 16:37:08 -08:00
|
|
|
|
namespace SabreTools.DatFiles
|
2020-07-26 22:34:45 -07:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Item dictionary with statistics, bucketing, and sorting
|
|
|
|
|
|
/// </summary>
|
2022-11-03 12:23:10 -07:00
|
|
|
|
/// <remarks>
|
|
|
|
|
|
/// TODO: Make this into a database model instead of just an in-memory object
|
|
|
|
|
|
/// This will help handle extremely large sets
|
|
|
|
|
|
/// </remarks>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonObject("items"), XmlRoot("items")]
|
2023-08-10 23:22:14 -04:00
|
|
|
|
public class ItemDictionary : IDictionary<string, ConcurrentList<DatItem>?>
|
2020-07-26 22:34:45 -07:00
|
|
|
|
{
|
|
|
|
|
|
#region Private instance variables
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Determine the bucketing key for all items
|
|
|
|
|
|
/// </summary>
|
2020-12-14 15:31:28 -08:00
|
|
|
|
private ItemKey bucketedBy;
|
2020-07-26 22:34:45 -07:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Determine merging type for all items
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private DedupeType mergedBy;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Internal dictionary for the class
|
|
|
|
|
|
/// </summary>
|
2023-08-10 23:22:14 -04:00
|
|
|
|
private readonly ConcurrentDictionary<string, ConcurrentList<DatItem>?> items;
|
2020-07-26 22:34:45 -07:00
|
|
|
|
|
2020-09-18 15:01:03 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Lock for statistics calculation
|
|
|
|
|
|
/// </summary>
|
2023-04-19 16:39:58 -04:00
|
|
|
|
private readonly object statsLock = new();
|
2020-09-18 15:01:03 -07:00
|
|
|
|
|
2020-10-07 15:42:30 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Logging object
|
|
|
|
|
|
/// </summary>
|
2020-12-14 16:01:28 -08:00
|
|
|
|
private readonly Logger logger;
|
2020-10-07 15:42:30 -07:00
|
|
|
|
|
2020-07-26 22:34:45 -07:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Publically available fields
|
|
|
|
|
|
|
2020-07-27 01:39:32 -07:00
|
|
|
|
#region Keys
|
|
|
|
|
|
|
2020-07-26 22:34:45 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get the keys from the file dictionary
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>List of the keys</returns>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-07-26 22:34:45 -07:00
|
|
|
|
public ICollection<string> Keys
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return items.Keys; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get the keys in sorted order from the file dictionary
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>List of the keys in sorted order</returns>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-07-26 22:34:45 -07:00
|
|
|
|
public List<string> SortedKeys
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
var keys = items.Keys.ToList();
|
|
|
|
|
|
keys.Sort(new NaturalComparer());
|
|
|
|
|
|
return keys;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-27 01:39:32 -07:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Statistics
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Overall item count
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-07-27 01:39:32 -07:00
|
|
|
|
public long TotalCount { get; private set; } = 0;
|
|
|
|
|
|
|
2020-09-01 11:34:52 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of Adjuster items
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-09-01 11:34:52 -07:00
|
|
|
|
public long AdjusterCount { get; private set; } = 0;
|
|
|
|
|
|
|
2020-09-02 16:31:23 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of Analog items
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-09-02 16:31:23 -07:00
|
|
|
|
public long AnalogCount { get; private set; } = 0;
|
|
|
|
|
|
|
2020-07-27 01:39:32 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of Archive items
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-07-27 01:39:32 -07:00
|
|
|
|
public long ArchiveCount { get; private set; } = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of BiosSet items
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-07-27 01:39:32 -07:00
|
|
|
|
public long BiosSetCount { get; private set; } = 0;
|
|
|
|
|
|
|
2020-08-25 22:48:46 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of Chip items
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-08-25 22:48:46 -07:00
|
|
|
|
public long ChipCount { get; private set; } = 0;
|
|
|
|
|
|
|
2020-09-02 16:31:23 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of top-level Condition items
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-09-02 16:31:23 -07:00
|
|
|
|
public long ConditionCount { get; private set; } = 0;
|
|
|
|
|
|
|
2020-09-01 12:04:35 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of Configuration items
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-09-01 12:04:35 -07:00
|
|
|
|
public long ConfigurationCount { get; private set; } = 0;
|
|
|
|
|
|
|
2020-09-04 14:10:35 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of DataArea items
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-09-04 14:10:35 -07:00
|
|
|
|
public long DataAreaCount { get; private set; } = 0;
|
|
|
|
|
|
|
2020-09-02 17:09:19 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of Device items
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-09-02 17:09:19 -07:00
|
|
|
|
public long DeviceCount { get; private set; } = 0;
|
|
|
|
|
|
|
2020-08-31 23:01:51 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of Device Reference items
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-08-31 23:01:51 -07:00
|
|
|
|
public long DeviceReferenceCount { get; private set; } = 0;
|
|
|
|
|
|
|
2020-09-01 13:36:32 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of DIP Switch items
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-09-01 13:36:32 -07:00
|
|
|
|
public long DipSwitchCount { get; private set; } = 0;
|
|
|
|
|
|
|
2020-07-27 01:39:32 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of Disk items
|
|
|
|
|
|
/// </summary>
|
2020-09-18 15:01:03 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-07-27 01:39:32 -07:00
|
|
|
|
public long DiskCount { get; private set; } = 0;
|
|
|
|
|
|
|
2020-09-04 14:10:35 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of DiskArea items
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-09-04 14:10:35 -07:00
|
|
|
|
public long DiskAreaCount { get; private set; } = 0;
|
|
|
|
|
|
|
2020-09-02 21:36:14 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of Display items
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-09-02 21:36:14 -07:00
|
|
|
|
public long DisplayCount { get; private set; } = 0;
|
|
|
|
|
|
|
2020-09-02 15:38:10 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of Driver items
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-09-02 15:38:10 -07:00
|
|
|
|
public long DriverCount { get; private set; } = 0;
|
|
|
|
|
|
|
2020-09-02 13:31:50 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of Feature items
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-09-02 13:31:50 -07:00
|
|
|
|
public long FeatureCount { get; private set; } = 0;
|
|
|
|
|
|
|
2020-09-02 23:31:35 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of Info items
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-09-02 23:31:35 -07:00
|
|
|
|
public long InfoCount { get; private set; } = 0;
|
|
|
|
|
|
|
2020-09-02 21:59:26 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of Input items
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-09-02 21:59:26 -07:00
|
|
|
|
public long InputCount { get; private set; } = 0;
|
|
|
|
|
|
|
2020-08-27 16:57:22 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of Media items
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-08-27 16:57:22 -07:00
|
|
|
|
public long MediaCount { get; private set; } = 0;
|
|
|
|
|
|
|
2020-09-04 14:10:35 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of Part items
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-09-04 14:10:35 -07:00
|
|
|
|
public long PartCount { get; private set; } = 0;
|
|
|
|
|
|
|
2020-09-03 13:20:56 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of PartFeature items
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-09-03 13:20:56 -07:00
|
|
|
|
public long PartFeatureCount { get; private set; } = 0;
|
|
|
|
|
|
|
2020-09-02 17:22:31 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of Port items
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-09-02 17:22:31 -07:00
|
|
|
|
public long PortCount { get; private set; } = 0;
|
|
|
|
|
|
|
2020-09-01 11:34:52 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of RamOption items
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-09-01 11:34:52 -07:00
|
|
|
|
public long RamOptionCount { get; private set; } = 0;
|
|
|
|
|
|
|
2020-07-27 01:39:32 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of Release items
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-07-27 01:39:32 -07:00
|
|
|
|
public long ReleaseCount { get; private set; } = 0;
|
|
|
|
|
|
|
2023-04-19 12:26:54 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of ReleaseDetails items
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[JsonIgnore, XmlIgnore]
|
|
|
|
|
|
public long ReleaseDetailsCount { get; private set; } = 0;
|
|
|
|
|
|
|
2020-07-27 01:39:32 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of Rom items
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-07-27 01:39:32 -07:00
|
|
|
|
public long RomCount { get; private set; } = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of Sample items
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-07-27 01:39:32 -07:00
|
|
|
|
public long SampleCount { get; private set; } = 0;
|
|
|
|
|
|
|
2023-04-19 12:26:54 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of Serials items
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[JsonIgnore, XmlIgnore]
|
|
|
|
|
|
public long SerialsCount { get; private set; } = 0;
|
|
|
|
|
|
|
2020-09-03 00:48:07 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of SharedFeature items
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-09-03 00:48:07 -07:00
|
|
|
|
public long SharedFeatureCount { get; private set; } = 0;
|
|
|
|
|
|
|
2020-09-01 16:21:55 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of Slot items
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-09-01 16:21:55 -07:00
|
|
|
|
public long SlotCount { get; private set; } = 0;
|
|
|
|
|
|
|
2020-08-31 23:26:07 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of SoftwareList items
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-08-31 23:26:07 -07:00
|
|
|
|
public long SoftwareListCount { get; private set; } = 0;
|
|
|
|
|
|
|
2020-09-02 12:51:21 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of Sound items
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-09-02 12:51:21 -07:00
|
|
|
|
public long SoundCount { get; private set; } = 0;
|
|
|
|
|
|
|
2023-04-19 12:26:54 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of SourceDetails items
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[JsonIgnore, XmlIgnore]
|
|
|
|
|
|
public long SourceDetailsCount { get; private set; } = 0;
|
|
|
|
|
|
|
2020-07-27 01:39:32 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of machines
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <remarks>Special count only used by statistics output</remarks>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-12-10 23:24:09 -08:00
|
|
|
|
public long GameCount { get; set; } = 0;
|
2020-07-27 01:39:32 -07:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Total uncompressed size
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-07-27 01:39:32 -07:00
|
|
|
|
public long TotalSize { get; private set; } = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of items with a CRC hash
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-07-27 01:39:32 -07:00
|
|
|
|
public long CRCCount { get; private set; } = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of items with an MD5 hash
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-07-27 01:39:32 -07:00
|
|
|
|
public long MD5Count { get; private set; } = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of items with a SHA-1 hash
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-07-27 01:39:32 -07:00
|
|
|
|
public long SHA1Count { get; private set; } = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of items with a SHA-256 hash
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-07-27 01:39:32 -07:00
|
|
|
|
public long SHA256Count { get; private set; } = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of items with a SHA-384 hash
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-07-27 01:39:32 -07:00
|
|
|
|
public long SHA384Count { get; private set; } = 0;
|
|
|
|
|
|
|
2020-07-26 23:39:33 -07:00
|
|
|
|
/// <summary>
|
2020-07-27 01:39:32 -07:00
|
|
|
|
/// Number of items with a SHA-512 hash
|
2020-07-26 23:39:33 -07:00
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-07-27 01:39:32 -07:00
|
|
|
|
public long SHA512Count { get; private set; } = 0;
|
|
|
|
|
|
|
2020-09-04 15:02:15 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of items with a SpamSum fuzzy hash
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-09-04 15:02:15 -07:00
|
|
|
|
public long SpamSumCount { get; private set; } = 0;
|
|
|
|
|
|
|
2020-07-27 01:39:32 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of items with the baddump status
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-07-27 01:39:32 -07:00
|
|
|
|
public long BaddumpCount { get; private set; } = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of items with the good status
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-07-27 01:39:32 -07:00
|
|
|
|
public long GoodCount { get; private set; } = 0;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of items with the nodump status
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-07-27 01:39:32 -07:00
|
|
|
|
public long NodumpCount { get; private set; } = 0;
|
|
|
|
|
|
|
2020-08-30 17:02:07 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of items with the remove flag
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-08-30 17:02:07 -07:00
|
|
|
|
public long RemovedCount { get; private set; } = 0;
|
|
|
|
|
|
|
2020-07-27 01:39:32 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Number of items with the verified status
|
|
|
|
|
|
/// </summary>
|
2020-09-08 10:12:41 -07:00
|
|
|
|
[JsonIgnore, XmlIgnore]
|
2020-07-27 01:39:32 -07:00
|
|
|
|
public long VerifiedCount { get; private set; } = 0;
|
2020-07-26 23:39:33 -07:00
|
|
|
|
|
2020-07-26 22:34:45 -07:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2020-07-27 01:39:32 -07:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2020-07-26 22:34:45 -07:00
|
|
|
|
#region Accessors
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Passthrough to access the file dictionary
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="key">Key in the dictionary to reference</param>
|
2023-08-10 23:22:14 -04:00
|
|
|
|
public ConcurrentList<DatItem>? this[string key]
|
2020-07-26 22:34:45 -07:00
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
// Explicit lock for some weird corner cases
|
|
|
|
|
|
lock (key)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Ensure the key exists
|
|
|
|
|
|
EnsureKey(key);
|
|
|
|
|
|
|
|
|
|
|
|
// Now return the value
|
|
|
|
|
|
return items[key];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
2020-08-30 17:02:07 -07:00
|
|
|
|
Remove(key);
|
2020-12-19 22:42:16 -08:00
|
|
|
|
if (value == null)
|
|
|
|
|
|
items[key] = null;
|
|
|
|
|
|
else
|
|
|
|
|
|
AddRange(key, value);
|
2020-07-26 22:34:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Add a value to the file dictionary
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="key">Key in the dictionary to add to</param>
|
|
|
|
|
|
/// <param name="value">Value to add to the dictionary</param>
|
|
|
|
|
|
public void Add(string key, DatItem value)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Explicit lock for some weird corner cases
|
|
|
|
|
|
lock (key)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Ensure the key exists
|
|
|
|
|
|
EnsureKey(key);
|
|
|
|
|
|
|
|
|
|
|
|
// If item is null, don't add it
|
|
|
|
|
|
if (value == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
// Now add the value
|
2023-08-10 23:22:14 -04:00
|
|
|
|
items[key]!.Add(value);
|
2020-07-26 22:34:45 -07:00
|
|
|
|
|
|
|
|
|
|
// Now update the statistics
|
2020-07-27 01:39:32 -07:00
|
|
|
|
AddItemStatistics(value);
|
2020-07-26 22:34:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Add a range of values to the file dictionary
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="key">Key in the dictionary to add to</param>
|
|
|
|
|
|
/// <param name="value">Value to add to the dictionary</param>
|
2023-08-10 23:22:14 -04:00
|
|
|
|
public void Add(string key, ConcurrentList<DatItem>? value)
|
2020-07-26 22:34:45 -07:00
|
|
|
|
{
|
|
|
|
|
|
AddRange(key, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-23 13:22:06 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Add to the statistics given a DatItem
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="item">Item to add info from</param>
|
|
|
|
|
|
public void AddItemStatistics(DatItem item)
|
|
|
|
|
|
{
|
|
|
|
|
|
lock (statsLock)
|
|
|
|
|
|
{
|
|
|
|
|
|
// No matter what the item is, we increment the count
|
|
|
|
|
|
TotalCount++;
|
|
|
|
|
|
|
|
|
|
|
|
// Increment removal count
|
|
|
|
|
|
if (item.Remove)
|
|
|
|
|
|
RemovedCount++;
|
|
|
|
|
|
|
|
|
|
|
|
// Now we do different things for each item type
|
2023-08-10 23:22:14 -04:00
|
|
|
|
switch (item)
|
2020-12-23 13:22:06 -08:00
|
|
|
|
{
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Adjuster:
|
2020-12-23 13:22:06 -08:00
|
|
|
|
AdjusterCount++;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Analog:
|
2020-12-23 13:22:06 -08:00
|
|
|
|
AnalogCount++;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Archive:
|
2020-12-23 13:22:06 -08:00
|
|
|
|
ArchiveCount++;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case BiosSet:
|
2020-12-23 13:22:06 -08:00
|
|
|
|
BiosSetCount++;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Chip:
|
2020-12-23 13:22:06 -08:00
|
|
|
|
ChipCount++;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Condition:
|
2020-12-23 13:22:06 -08:00
|
|
|
|
ConditionCount++;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Configuration:
|
2020-12-23 13:22:06 -08:00
|
|
|
|
ConfigurationCount++;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case DataArea:
|
2020-12-23 13:22:06 -08:00
|
|
|
|
DataAreaCount++;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Device:
|
2020-12-23 13:22:06 -08:00
|
|
|
|
DeviceCount++;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case DeviceReference:
|
2020-12-23 13:22:06 -08:00
|
|
|
|
DeviceReferenceCount++;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case DipSwitch:
|
2020-12-23 13:22:06 -08:00
|
|
|
|
DipSwitchCount++;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Disk disk:
|
2020-12-23 13:22:06 -08:00
|
|
|
|
DiskCount++;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
if (disk.ItemStatus != ItemStatus.Nodump)
|
2020-12-23 13:22:06 -08:00
|
|
|
|
{
|
2023-08-10 23:22:14 -04:00
|
|
|
|
MD5Count += (string.IsNullOrWhiteSpace(disk.MD5) ? 0 : 1);
|
|
|
|
|
|
SHA1Count += (string.IsNullOrWhiteSpace(disk.SHA1) ? 0 : 1);
|
2020-12-23 13:22:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-10 23:22:14 -04:00
|
|
|
|
BaddumpCount += (disk.ItemStatus == ItemStatus.BadDump ? 1 : 0);
|
|
|
|
|
|
GoodCount += (disk.ItemStatus == ItemStatus.Good ? 1 : 0);
|
|
|
|
|
|
NodumpCount += (disk.ItemStatus == ItemStatus.Nodump ? 1 : 0);
|
|
|
|
|
|
VerifiedCount += (disk.ItemStatus == ItemStatus.Verified ? 1 : 0);
|
2020-12-23 13:22:06 -08:00
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case DiskArea:
|
2020-12-23 13:22:06 -08:00
|
|
|
|
DiskAreaCount++;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Display:
|
2020-12-23 13:22:06 -08:00
|
|
|
|
DisplayCount++;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Driver:
|
2020-12-23 13:22:06 -08:00
|
|
|
|
DriverCount++;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Feature:
|
2020-12-23 13:22:06 -08:00
|
|
|
|
FeatureCount++;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Info:
|
2020-12-23 13:22:06 -08:00
|
|
|
|
InfoCount++;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Input:
|
2020-12-23 13:22:06 -08:00
|
|
|
|
InputCount++;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Media media:
|
2020-12-23 13:22:06 -08:00
|
|
|
|
MediaCount++;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
MD5Count += (string.IsNullOrWhiteSpace(media.MD5) ? 0 : 1);
|
|
|
|
|
|
SHA1Count += (string.IsNullOrWhiteSpace(media.SHA1) ? 0 : 1);
|
|
|
|
|
|
SHA256Count += (string.IsNullOrWhiteSpace(media.SHA256) ? 0 : 1);
|
|
|
|
|
|
SpamSumCount += (string.IsNullOrWhiteSpace(media.SpamSum) ? 0 : 1);
|
2020-12-23 13:22:06 -08:00
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Part:
|
2020-12-23 13:22:06 -08:00
|
|
|
|
PartCount++;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case PartFeature:
|
2020-12-23 13:22:06 -08:00
|
|
|
|
PartFeatureCount++;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Port:
|
2020-12-23 13:22:06 -08:00
|
|
|
|
PortCount++;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case RamOption:
|
2020-12-23 13:22:06 -08:00
|
|
|
|
RamOptionCount++;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Release:
|
2020-12-23 13:22:06 -08:00
|
|
|
|
ReleaseCount++;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case ReleaseDetails:
|
2023-04-19 12:26:54 -04:00
|
|
|
|
ReleaseDetailsCount++;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Rom rom:
|
2020-12-23 13:22:06 -08:00
|
|
|
|
RomCount++;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
if (rom.ItemStatus != ItemStatus.Nodump)
|
2020-12-23 13:22:06 -08:00
|
|
|
|
{
|
2023-08-10 23:22:14 -04:00
|
|
|
|
TotalSize += rom.Size ?? 0;
|
|
|
|
|
|
CRCCount += (string.IsNullOrWhiteSpace(rom.CRC) ? 0 : 1);
|
|
|
|
|
|
MD5Count += (string.IsNullOrWhiteSpace(rom.MD5) ? 0 : 1);
|
|
|
|
|
|
SHA1Count += (string.IsNullOrWhiteSpace(rom.SHA1) ? 0 : 1);
|
|
|
|
|
|
SHA256Count += (string.IsNullOrWhiteSpace(rom.SHA256) ? 0 : 1);
|
|
|
|
|
|
SHA384Count += (string.IsNullOrWhiteSpace(rom.SHA384) ? 0 : 1);
|
|
|
|
|
|
SHA512Count += (string.IsNullOrWhiteSpace(rom.SHA512) ? 0 : 1);
|
|
|
|
|
|
SpamSumCount += (string.IsNullOrWhiteSpace(rom.SpamSum) ? 0 : 1);
|
2020-12-23 13:22:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-10 23:22:14 -04:00
|
|
|
|
BaddumpCount += (rom.ItemStatus == ItemStatus.BadDump ? 1 : 0);
|
|
|
|
|
|
GoodCount += (rom.ItemStatus == ItemStatus.Good ? 1 : 0);
|
|
|
|
|
|
NodumpCount += (rom.ItemStatus == ItemStatus.Nodump ? 1 : 0);
|
|
|
|
|
|
VerifiedCount += (rom.ItemStatus == ItemStatus.Verified ? 1 : 0);
|
2020-12-23 13:22:06 -08:00
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Sample:
|
2020-12-23 13:22:06 -08:00
|
|
|
|
SampleCount++;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Serials:
|
2023-04-19 12:26:54 -04:00
|
|
|
|
SerialsCount++;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case SharedFeature:
|
2020-12-23 13:22:06 -08:00
|
|
|
|
SharedFeatureCount++;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Slot:
|
2020-12-23 13:22:06 -08:00
|
|
|
|
SlotCount++;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case SoftwareList:
|
2020-12-23 13:22:06 -08:00
|
|
|
|
SoftwareListCount++;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Sound:
|
2020-12-23 13:22:06 -08:00
|
|
|
|
SoundCount++;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case SourceDetails:
|
2023-04-19 12:26:54 -04:00
|
|
|
|
SourceDetailsCount++;
|
|
|
|
|
|
break;
|
2020-12-23 13:22:06 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-26 22:34:45 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Add a range of values to the file dictionary
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="key">Key in the dictionary to add to</param>
|
|
|
|
|
|
/// <param name="value">Value to add to the dictionary</param>
|
2023-08-10 23:22:14 -04:00
|
|
|
|
public void AddRange(string key, ConcurrentList<DatItem>? value)
|
2020-07-26 22:34:45 -07:00
|
|
|
|
{
|
|
|
|
|
|
// Explicit lock for some weird corner cases
|
|
|
|
|
|
lock (key)
|
|
|
|
|
|
{
|
2020-12-19 22:42:16 -08:00
|
|
|
|
// If the value is null or empty, just return
|
|
|
|
|
|
if (value == null || !value.Any())
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2020-07-26 22:34:45 -07:00
|
|
|
|
// Ensure the key exists
|
|
|
|
|
|
EnsureKey(key);
|
|
|
|
|
|
|
|
|
|
|
|
// Now add the value
|
2023-08-10 23:22:14 -04:00
|
|
|
|
items[key]!.AddRange(value);
|
2020-07-26 22:34:45 -07:00
|
|
|
|
|
|
|
|
|
|
// Now update the statistics
|
|
|
|
|
|
foreach (DatItem item in value)
|
|
|
|
|
|
{
|
2020-07-27 01:39:32 -07:00
|
|
|
|
AddItemStatistics(item);
|
2020-07-26 22:34:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-10 23:24:09 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Add statistics from another DatStats object
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="stats">DatStats object to add from</param>
|
|
|
|
|
|
public void AddStatistics(ItemDictionary stats)
|
|
|
|
|
|
{
|
|
|
|
|
|
TotalCount += stats.Count;
|
|
|
|
|
|
|
|
|
|
|
|
ArchiveCount += stats.ArchiveCount;
|
|
|
|
|
|
BiosSetCount += stats.BiosSetCount;
|
|
|
|
|
|
ChipCount += stats.ChipCount;
|
|
|
|
|
|
DiskCount += stats.DiskCount;
|
|
|
|
|
|
MediaCount += stats.MediaCount;
|
|
|
|
|
|
ReleaseCount += stats.ReleaseCount;
|
|
|
|
|
|
RomCount += stats.RomCount;
|
|
|
|
|
|
SampleCount += stats.SampleCount;
|
|
|
|
|
|
|
|
|
|
|
|
GameCount += stats.GameCount;
|
|
|
|
|
|
|
|
|
|
|
|
TotalSize += stats.TotalSize;
|
|
|
|
|
|
|
|
|
|
|
|
// Individual hash counts
|
|
|
|
|
|
CRCCount += stats.CRCCount;
|
|
|
|
|
|
MD5Count += stats.MD5Count;
|
|
|
|
|
|
SHA1Count += stats.SHA1Count;
|
|
|
|
|
|
SHA256Count += stats.SHA256Count;
|
|
|
|
|
|
SHA384Count += stats.SHA384Count;
|
|
|
|
|
|
SHA512Count += stats.SHA512Count;
|
|
|
|
|
|
SpamSumCount += stats.SpamSumCount;
|
|
|
|
|
|
|
|
|
|
|
|
// Individual status counts
|
|
|
|
|
|
BaddumpCount += stats.BaddumpCount;
|
|
|
|
|
|
GoodCount += stats.GoodCount;
|
|
|
|
|
|
NodumpCount += stats.NodumpCount;
|
|
|
|
|
|
RemovedCount += stats.RemovedCount;
|
|
|
|
|
|
VerifiedCount += stats.VerifiedCount;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-26 22:34:45 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get if the file dictionary contains the key
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="key">Key in the dictionary to check</param>
|
|
|
|
|
|
/// <returns>True if the key exists, false otherwise</returns>
|
|
|
|
|
|
public bool ContainsKey(string key)
|
|
|
|
|
|
{
|
|
|
|
|
|
// If the key is null, we return false since keys can't be null
|
|
|
|
|
|
if (key == null)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
// Explicit lock for some weird corner cases
|
|
|
|
|
|
lock (key)
|
|
|
|
|
|
{
|
|
|
|
|
|
return items.ContainsKey(key);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get if the file dictionary contains the key and value
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="key">Key in the dictionary to check</param>
|
|
|
|
|
|
/// <param name="value">Value in the dictionary to check</param>
|
|
|
|
|
|
/// <returns>True if the key exists, false otherwise</returns>
|
|
|
|
|
|
public bool Contains(string key, DatItem value)
|
|
|
|
|
|
{
|
|
|
|
|
|
// If the key is null, we return false since keys can't be null
|
|
|
|
|
|
if (key == null)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
// Explicit lock for some weird corner cases
|
|
|
|
|
|
lock (key)
|
|
|
|
|
|
{
|
2023-08-10 23:22:14 -04:00
|
|
|
|
if (items.ContainsKey(key) && items[key] != null)
|
|
|
|
|
|
return items[key]!.Contains(value);
|
2020-07-26 22:34:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-23 14:06:48 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Ensure the key exists in the items dictionary
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="key">Key to ensure</param>
|
|
|
|
|
|
public void EnsureKey(string key)
|
|
|
|
|
|
{
|
|
|
|
|
|
// If the key is missing from the dictionary, add it
|
|
|
|
|
|
if (!items.ContainsKey(key))
|
2024-02-28 19:19:50 -05:00
|
|
|
|
items.TryAdd(key, []);
|
2020-12-23 14:06:48 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-28 15:06:07 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get a list of filtered items for a given key
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="key">Key in the dictionary to retrieve</param>
|
2021-07-18 21:00:01 -07:00
|
|
|
|
public ConcurrentList<DatItem> FilteredItems(string key)
|
2020-08-28 15:06:07 -07:00
|
|
|
|
{
|
|
|
|
|
|
lock (key)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Get the list, if possible
|
2023-08-10 23:22:14 -04:00
|
|
|
|
ConcurrentList<DatItem>? fi = items[key];
|
2020-08-28 15:06:07 -07:00
|
|
|
|
if (fi == null)
|
2024-02-28 19:19:50 -05:00
|
|
|
|
return [];
|
2020-08-28 15:06:07 -07:00
|
|
|
|
|
|
|
|
|
|
// Filter the list
|
2021-07-18 21:00:01 -07:00
|
|
|
|
return fi.Where(i => i != null)
|
2020-08-28 15:06:07 -07:00
|
|
|
|
.Where(i => !i.Remove)
|
2023-08-15 01:38:01 -04:00
|
|
|
|
.Where(i => i.Machine.Name != null)
|
2021-07-18 21:00:01 -07:00
|
|
|
|
.ToConcurrentList();
|
2020-08-28 15:06:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-26 22:34:45 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Remove a key from the file dictionary if it exists
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="key">Key in the dictionary to remove</param>
|
|
|
|
|
|
public bool Remove(string key)
|
|
|
|
|
|
{
|
2020-09-18 15:01:03 -07:00
|
|
|
|
// Explicit lock for some weird corner cases
|
|
|
|
|
|
lock (key)
|
2020-07-26 22:34:45 -07:00
|
|
|
|
{
|
2020-09-18 15:01:03 -07:00
|
|
|
|
// If the key doesn't exist, return
|
2023-08-10 23:22:14 -04:00
|
|
|
|
if (!ContainsKey(key) || items[key] == null)
|
2020-09-18 15:01:03 -07:00
|
|
|
|
return false;
|
2020-07-26 22:34:45 -07:00
|
|
|
|
|
2020-09-18 15:01:03 -07:00
|
|
|
|
// Remove the statistics first
|
2023-08-10 23:22:14 -04:00
|
|
|
|
foreach (DatItem item in items[key]!)
|
2020-09-18 15:01:03 -07:00
|
|
|
|
{
|
|
|
|
|
|
RemoveItemStatistics(item);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Remove the key from the dictionary
|
|
|
|
|
|
return items.TryRemove(key, out _);
|
|
|
|
|
|
}
|
2020-07-26 22:34:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Remove the first instance of a value from the file dictionary if it exists
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="key">Key in the dictionary to remove from</param>
|
|
|
|
|
|
/// <param name="value">Value to remove from the dictionary</param>
|
|
|
|
|
|
public bool Remove(string key, DatItem value)
|
|
|
|
|
|
{
|
2020-09-18 15:01:03 -07:00
|
|
|
|
// Explicit lock for some weird corner cases
|
|
|
|
|
|
lock (key)
|
|
|
|
|
|
{
|
|
|
|
|
|
// If the key and value doesn't exist, return
|
2023-08-10 23:22:14 -04:00
|
|
|
|
if (!Contains(key, value) || items[key] == null)
|
2020-09-18 15:01:03 -07:00
|
|
|
|
return false;
|
2020-07-26 22:34:45 -07:00
|
|
|
|
|
2020-09-18 15:01:03 -07:00
|
|
|
|
// Remove the statistics first
|
|
|
|
|
|
RemoveItemStatistics(value);
|
2020-07-26 22:34:45 -07:00
|
|
|
|
|
2023-08-10 23:22:14 -04:00
|
|
|
|
return items[key]!.Remove(value);
|
2020-09-18 15:01:03 -07:00
|
|
|
|
}
|
2020-07-26 22:34:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-28 01:13:55 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Reset a key from the file dictionary if it exists
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="key">Key in the dictionary to reset</param>
|
|
|
|
|
|
public bool Reset(string key)
|
|
|
|
|
|
{
|
|
|
|
|
|
// If the key doesn't exist, return
|
2023-08-10 23:22:14 -04:00
|
|
|
|
if (!ContainsKey(key) || items[key] == null)
|
2020-08-28 01:13:55 -07:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
// Remove the statistics first
|
2023-08-10 23:22:14 -04:00
|
|
|
|
foreach (DatItem item in items[key]!)
|
2020-08-28 01:13:55 -07:00
|
|
|
|
{
|
|
|
|
|
|
RemoveItemStatistics(item);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Remove the key from the dictionary
|
2024-02-28 19:19:50 -05:00
|
|
|
|
items[key] = [];
|
2020-08-28 01:13:55 -07:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-26 22:34:45 -07:00
|
|
|
|
/// <summary>
|
2020-12-14 15:31:28 -08:00
|
|
|
|
/// Override the internal ItemKey value
|
2020-07-26 22:34:45 -07:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="newBucket"></param>
|
2020-12-14 15:31:28 -08:00
|
|
|
|
public void SetBucketedBy(ItemKey newBucket)
|
2020-07-26 22:34:45 -07:00
|
|
|
|
{
|
|
|
|
|
|
bucketedBy = newBucket;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-27 01:39:32 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Remove from the statistics given a DatItem
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="item">Item to remove info for</param>
|
|
|
|
|
|
public void RemoveItemStatistics(DatItem item)
|
|
|
|
|
|
{
|
|
|
|
|
|
// If we have a null item, we can't do anything
|
|
|
|
|
|
if (item == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2020-09-18 15:01:03 -07:00
|
|
|
|
lock (statsLock)
|
|
|
|
|
|
{
|
|
|
|
|
|
// No matter what the item is, we decrease the count
|
|
|
|
|
|
TotalCount--;
|
2020-07-27 01:39:32 -07:00
|
|
|
|
|
2020-09-18 15:01:03 -07:00
|
|
|
|
// Decrement removal count
|
|
|
|
|
|
if (item.Remove)
|
|
|
|
|
|
RemovedCount--;
|
2020-07-27 01:39:32 -07:00
|
|
|
|
|
2020-09-18 15:01:03 -07:00
|
|
|
|
// Now we do different things for each item type
|
2023-08-10 23:22:14 -04:00
|
|
|
|
switch (item)
|
2020-09-18 15:01:03 -07:00
|
|
|
|
{
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Adjuster:
|
2020-09-18 15:01:03 -07:00
|
|
|
|
AdjusterCount--;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Analog:
|
2020-09-18 15:01:03 -07:00
|
|
|
|
AnalogCount--;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Archive:
|
2020-09-18 15:01:03 -07:00
|
|
|
|
ArchiveCount--;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case BiosSet:
|
2020-09-18 15:01:03 -07:00
|
|
|
|
BiosSetCount--;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Chip:
|
2020-09-18 15:01:03 -07:00
|
|
|
|
ChipCount--;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Condition:
|
2020-09-18 15:01:03 -07:00
|
|
|
|
ConditionCount--;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Configuration:
|
2020-09-18 15:01:03 -07:00
|
|
|
|
ConfigurationCount--;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case DataArea:
|
2020-09-18 15:01:03 -07:00
|
|
|
|
DataAreaCount--;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Device:
|
2020-09-18 15:01:03 -07:00
|
|
|
|
DeviceCount--;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case DeviceReference:
|
2020-09-18 15:01:03 -07:00
|
|
|
|
DeviceReferenceCount--;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case DipSwitch:
|
2020-09-18 15:01:03 -07:00
|
|
|
|
DipSwitchCount--;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Disk disk:
|
2020-09-18 15:01:03 -07:00
|
|
|
|
DiskCount--;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
if (disk.ItemStatus != ItemStatus.Nodump)
|
2020-09-18 15:01:03 -07:00
|
|
|
|
{
|
2023-08-10 23:22:14 -04:00
|
|
|
|
MD5Count -= (string.IsNullOrWhiteSpace(disk.MD5) ? 0 : 1);
|
|
|
|
|
|
SHA1Count -= (string.IsNullOrWhiteSpace(disk.SHA1) ? 0 : 1);
|
2020-09-18 15:01:03 -07:00
|
|
|
|
}
|
2020-07-27 01:39:32 -07:00
|
|
|
|
|
2023-08-10 23:22:14 -04:00
|
|
|
|
BaddumpCount -= (disk.ItemStatus == ItemStatus.BadDump ? 1 : 0);
|
|
|
|
|
|
GoodCount -= (disk.ItemStatus == ItemStatus.Good ? 1 : 0);
|
|
|
|
|
|
NodumpCount -= (disk.ItemStatus == ItemStatus.Nodump ? 1 : 0);
|
|
|
|
|
|
VerifiedCount -= (disk.ItemStatus == ItemStatus.Verified ? 1 : 0);
|
2020-09-18 15:01:03 -07:00
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case DiskArea:
|
2020-09-18 15:01:03 -07:00
|
|
|
|
DiskAreaCount--;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Display:
|
2020-09-18 15:01:03 -07:00
|
|
|
|
DisplayCount--;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Driver:
|
2020-09-18 15:01:03 -07:00
|
|
|
|
DriverCount--;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Feature:
|
2020-09-18 15:01:03 -07:00
|
|
|
|
FeatureCount--;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Info:
|
2020-09-18 15:01:03 -07:00
|
|
|
|
InfoCount--;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Input:
|
2020-09-18 15:01:03 -07:00
|
|
|
|
InputCount--;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Media media:
|
2020-09-18 15:01:03 -07:00
|
|
|
|
MediaCount--;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
MD5Count -= (string.IsNullOrWhiteSpace(media.MD5) ? 0 : 1);
|
|
|
|
|
|
SHA1Count -= (string.IsNullOrWhiteSpace(media.SHA1) ? 0 : 1);
|
|
|
|
|
|
SHA256Count -= (string.IsNullOrWhiteSpace(media.SHA256) ? 0 : 1);
|
2020-09-18 15:01:03 -07:00
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Part:
|
2020-09-18 15:01:03 -07:00
|
|
|
|
PartCount--;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case PartFeature:
|
2020-09-18 15:01:03 -07:00
|
|
|
|
PartFeatureCount--;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Port:
|
2020-09-18 15:01:03 -07:00
|
|
|
|
PortCount--;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case RamOption:
|
2020-09-18 15:01:03 -07:00
|
|
|
|
RamOptionCount--;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Release:
|
2020-09-18 15:01:03 -07:00
|
|
|
|
ReleaseCount--;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Rom rom:
|
2020-09-18 15:01:03 -07:00
|
|
|
|
RomCount--;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
if (rom.ItemStatus != ItemStatus.Nodump)
|
2020-09-18 15:01:03 -07:00
|
|
|
|
{
|
2023-08-10 23:22:14 -04:00
|
|
|
|
TotalSize -= rom.Size ?? 0;
|
|
|
|
|
|
CRCCount -= (string.IsNullOrWhiteSpace(rom.CRC) ? 0 : 1);
|
|
|
|
|
|
MD5Count -= (string.IsNullOrWhiteSpace(rom.MD5) ? 0 : 1);
|
|
|
|
|
|
SHA1Count -= (string.IsNullOrWhiteSpace(rom.SHA1) ? 0 : 1);
|
|
|
|
|
|
SHA256Count -= (string.IsNullOrWhiteSpace(rom.SHA256) ? 0 : 1);
|
|
|
|
|
|
SHA384Count -= (string.IsNullOrWhiteSpace(rom.SHA384) ? 0 : 1);
|
|
|
|
|
|
SHA512Count -= (string.IsNullOrWhiteSpace(rom.SHA512) ? 0 : 1);
|
2020-09-18 15:01:03 -07:00
|
|
|
|
}
|
2020-07-27 01:39:32 -07:00
|
|
|
|
|
2023-08-10 23:22:14 -04:00
|
|
|
|
BaddumpCount -= (rom.ItemStatus == ItemStatus.BadDump ? 1 : 0);
|
|
|
|
|
|
GoodCount -= (rom.ItemStatus == ItemStatus.Good ? 1 : 0);
|
|
|
|
|
|
NodumpCount -= (rom.ItemStatus == ItemStatus.Nodump ? 1 : 0);
|
|
|
|
|
|
VerifiedCount -= (rom.ItemStatus == ItemStatus.Verified ? 1 : 0);
|
2020-09-18 15:01:03 -07:00
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Sample:
|
2020-09-18 15:01:03 -07:00
|
|
|
|
SampleCount--;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case SharedFeature:
|
2020-09-18 15:01:03 -07:00
|
|
|
|
SharedFeatureCount--;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Slot:
|
2020-09-18 15:01:03 -07:00
|
|
|
|
SlotCount--;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case SoftwareList:
|
2020-09-18 15:01:03 -07:00
|
|
|
|
SoftwareListCount--;
|
|
|
|
|
|
break;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
case Sound:
|
2020-09-18 15:01:03 -07:00
|
|
|
|
SoundCount--;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2020-07-27 01:39:32 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-26 22:34:45 -07:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Constructors
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Generic constructor
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public ItemDictionary()
|
|
|
|
|
|
{
|
2020-12-14 15:31:28 -08:00
|
|
|
|
bucketedBy = ItemKey.NULL;
|
2020-07-26 22:34:45 -07:00
|
|
|
|
mergedBy = DedupeType.None;
|
2023-08-10 23:22:14 -04:00
|
|
|
|
items = new ConcurrentDictionary<string, ConcurrentList<DatItem>?>();
|
2020-10-07 16:37:10 -07:00
|
|
|
|
logger = new Logger(this);
|
2020-07-26 22:34:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Custom Functionality
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Take the arbitrarily bucketed Files Dictionary and convert to one bucketed by a user-defined method
|
|
|
|
|
|
/// </summary>
|
2020-12-14 15:31:28 -08:00
|
|
|
|
/// <param name="bucketBy">ItemKey enum representing how to bucket the individual items</param>
|
2020-07-26 22:34:45 -07:00
|
|
|
|
/// <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>
|
2020-12-14 15:31:28 -08:00
|
|
|
|
public void BucketBy(ItemKey bucketBy, DedupeType dedupeType, bool lower = true, bool norename = true)
|
2020-07-26 22:34:45 -07:00
|
|
|
|
{
|
|
|
|
|
|
// If we have a situation where there's no dictionary or no keys at all, we skip
|
2023-04-19 16:39:58 -04:00
|
|
|
|
if (items == null || items.IsEmpty)
|
2020-07-26 22:34:45 -07:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
// If the sorted type isn't the same, we want to sort the dictionary accordingly
|
2020-12-19 22:42:16 -08:00
|
|
|
|
if (bucketedBy != bucketBy && bucketBy != ItemKey.NULL)
|
2020-07-26 22:34:45 -07:00
|
|
|
|
{
|
2020-10-07 15:42:30 -07:00
|
|
|
|
logger.User($"Organizing roms by {bucketBy}");
|
2020-07-26 22:34:45 -07:00
|
|
|
|
|
|
|
|
|
|
// Set the sorted type
|
2020-07-27 01:39:32 -07:00
|
|
|
|
bucketedBy = bucketBy;
|
2020-07-26 22:34:45 -07:00
|
|
|
|
|
|
|
|
|
|
// Reset the merged type since this might change the merge
|
2020-07-27 01:39:32 -07:00
|
|
|
|
mergedBy = DedupeType.None;
|
2020-07-26 22:34:45 -07:00
|
|
|
|
|
|
|
|
|
|
// First do the initial sort of all of the roms inplace
|
2024-02-28 19:19:50 -05:00
|
|
|
|
List<string> oldkeys = [.. Keys];
|
2020-09-02 00:24:46 -07:00
|
|
|
|
Parallel.For(0, oldkeys.Count, Globals.ParallelOptions, k =>
|
2020-07-26 22:34:45 -07:00
|
|
|
|
{
|
|
|
|
|
|
string key = oldkeys[k];
|
2023-08-10 23:22:14 -04:00
|
|
|
|
if (this[key] == null)
|
|
|
|
|
|
Remove(key);
|
2020-07-26 22:34:45 -07:00
|
|
|
|
|
|
|
|
|
|
// Now add each of the roms to their respective keys
|
2023-08-10 23:22:14 -04:00
|
|
|
|
for (int i = 0; i < this[key]!.Count; i++)
|
2020-07-26 22:34:45 -07:00
|
|
|
|
{
|
2023-08-10 23:22:14 -04:00
|
|
|
|
DatItem item = this[key]![i];
|
2020-07-26 22:34:45 -07:00
|
|
|
|
if (item == null)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
// We want to get the key most appropriate for the given sorting type
|
|
|
|
|
|
string newkey = item.GetKey(bucketBy, lower, norename);
|
|
|
|
|
|
|
|
|
|
|
|
// If the key is different, move the item to the new key
|
|
|
|
|
|
if (newkey != key)
|
|
|
|
|
|
{
|
|
|
|
|
|
Add(newkey, item);
|
|
|
|
|
|
Remove(key, item);
|
|
|
|
|
|
i--; // This make sure that the pointer stays on the correct since one was removed
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If the key is now empty, remove it
|
2023-08-10 23:22:14 -04:00
|
|
|
|
if (this[key]!.Count == 0)
|
2020-07-26 22:34:45 -07:00
|
|
|
|
Remove(key);
|
2020-09-02 00:24:46 -07:00
|
|
|
|
});
|
2020-07-26 22:34:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If the merge type isn't the same, we want to merge the dictionary accordingly
|
2020-07-27 01:39:32 -07:00
|
|
|
|
if (mergedBy != dedupeType)
|
2020-07-26 22:34:45 -07:00
|
|
|
|
{
|
2020-10-07 15:42:30 -07:00
|
|
|
|
logger.User($"Deduping roms by {dedupeType}");
|
2020-07-26 22:34:45 -07:00
|
|
|
|
|
|
|
|
|
|
// Set the sorted type
|
2020-07-27 01:39:32 -07:00
|
|
|
|
mergedBy = dedupeType;
|
2020-07-26 22:34:45 -07:00
|
|
|
|
|
2024-02-28 19:19:50 -05:00
|
|
|
|
List<string> keys = [.. Keys];
|
2020-08-28 01:13:55 -07:00
|
|
|
|
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
|
2020-07-26 22:34:45 -07:00
|
|
|
|
{
|
|
|
|
|
|
// Get the possibly unsorted list
|
2023-08-12 00:55:41 -04:00
|
|
|
|
ConcurrentList<DatItem>? sortedlist = this[key]?.ToConcurrentList();
|
|
|
|
|
|
if (sortedlist == null)
|
|
|
|
|
|
return;
|
2020-07-26 22:34:45 -07:00
|
|
|
|
|
|
|
|
|
|
// Sort the list of items to be consistent
|
|
|
|
|
|
DatItem.Sort(ref sortedlist, false);
|
|
|
|
|
|
|
|
|
|
|
|
// If we're merging the roms, do so
|
2020-12-14 15:31:28 -08:00
|
|
|
|
if (dedupeType == DedupeType.Full || (dedupeType == DedupeType.Game && bucketBy == ItemKey.Machine))
|
2020-07-26 22:34:45 -07:00
|
|
|
|
sortedlist = DatItem.Merge(sortedlist);
|
|
|
|
|
|
|
|
|
|
|
|
// Add the list back to the dictionary
|
2020-08-28 01:13:55 -07:00
|
|
|
|
Reset(key);
|
2020-07-26 22:34:45 -07:00
|
|
|
|
AddRange(key, sortedlist);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
// If the merge type is the same, we want to sort the dictionary to be consistent
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2024-02-28 19:19:50 -05:00
|
|
|
|
List<string> keys = [.. Keys];
|
2020-08-28 01:13:55 -07:00
|
|
|
|
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
|
2020-07-26 22:34:45 -07:00
|
|
|
|
{
|
|
|
|
|
|
// Get the possibly unsorted list
|
2023-08-10 23:22:14 -04:00
|
|
|
|
ConcurrentList<DatItem>? sortedlist = this[key];
|
2020-07-26 22:34:45 -07:00
|
|
|
|
|
|
|
|
|
|
// Sort the list of items to be consistent
|
2023-08-10 23:22:14 -04:00
|
|
|
|
if (sortedlist != null)
|
|
|
|
|
|
DatItem.Sort(ref sortedlist, false);
|
2020-07-26 22:34:45 -07:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-28 13:33:05 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Remove any keys that have null or empty values
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void ClearEmpty()
|
|
|
|
|
|
{
|
|
|
|
|
|
var keys = items.Keys.Where(k => k != null).ToList();
|
|
|
|
|
|
foreach (string key in keys)
|
|
|
|
|
|
{
|
|
|
|
|
|
// If the key doesn't exist, skip
|
|
|
|
|
|
if (!items.ContainsKey(key))
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
// If the value is null, remove
|
|
|
|
|
|
else if (items[key] == null)
|
2020-08-31 15:54:53 -07:00
|
|
|
|
items.TryRemove(key, out _);
|
2020-08-28 13:33:05 -07:00
|
|
|
|
|
|
|
|
|
|
// If there are no non-blank items, remove
|
2023-08-10 23:22:14 -04:00
|
|
|
|
else if (!items[key]!.Any(i => i != null && i.ItemType != ItemType.Blank))
|
2020-08-31 15:54:53 -07:00
|
|
|
|
items.TryRemove(key, out _);
|
2020-08-28 13:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-26 22:34:45 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Remove all items marked for removal
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void ClearMarked()
|
|
|
|
|
|
{
|
2020-08-15 21:26:09 -07:00
|
|
|
|
var keys = items.Keys.ToList();
|
|
|
|
|
|
foreach (string key in keys)
|
2020-07-26 22:34:45 -07:00
|
|
|
|
{
|
2023-08-10 23:22:14 -04:00
|
|
|
|
ConcurrentList<DatItem>? oldItemList = items[key];
|
|
|
|
|
|
ConcurrentList<DatItem>? newItemList = oldItemList?.Where(i => !i.Remove)?.ToConcurrentList();
|
2020-07-26 22:34:45 -07:00
|
|
|
|
|
|
|
|
|
|
Remove(key);
|
|
|
|
|
|
AddRange(key, newItemList);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// List all duplicates found in a DAT based on a DatItem
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="datItem">Item to try to match</param>
|
|
|
|
|
|
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</param>
|
|
|
|
|
|
/// <returns>List of matched DatItem objects</returns>
|
2021-07-18 21:00:01 -07:00
|
|
|
|
public ConcurrentList<DatItem> GetDuplicates(DatItem datItem, bool sorted = false)
|
2020-07-26 22:34:45 -07:00
|
|
|
|
{
|
2024-02-28 19:19:50 -05:00
|
|
|
|
ConcurrentList<DatItem> output = [];
|
2020-07-26 22:34:45 -07:00
|
|
|
|
|
|
|
|
|
|
// Check for an empty rom list first
|
2020-07-27 01:39:32 -07:00
|
|
|
|
if (TotalCount == 0)
|
2020-07-26 22:34:45 -07:00
|
|
|
|
return output;
|
|
|
|
|
|
|
|
|
|
|
|
// We want to get the proper key for the DatItem
|
|
|
|
|
|
string key = SortAndGetKey(datItem, sorted);
|
|
|
|
|
|
|
|
|
|
|
|
// If the key doesn't exist, return the empty list
|
|
|
|
|
|
if (!ContainsKey(key))
|
|
|
|
|
|
return output;
|
|
|
|
|
|
|
|
|
|
|
|
// Try to find duplicates
|
2023-08-10 23:22:14 -04:00
|
|
|
|
ConcurrentList<DatItem>? roms = this[key];
|
|
|
|
|
|
if (roms == null)
|
|
|
|
|
|
return output;
|
|
|
|
|
|
|
2024-02-28 19:19:50 -05:00
|
|
|
|
ConcurrentList<DatItem> left = [];
|
2020-07-26 22:34:45 -07:00
|
|
|
|
for (int i = 0; i < roms.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
DatItem other = roms[i];
|
2020-08-28 22:38:10 -07:00
|
|
|
|
if (other.Remove)
|
|
|
|
|
|
continue;
|
2020-07-26 22:34:45 -07:00
|
|
|
|
|
|
|
|
|
|
if (datItem.Equals(other))
|
|
|
|
|
|
{
|
|
|
|
|
|
other.Remove = true;
|
|
|
|
|
|
output.Add(other);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
left.Add(other);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-28 22:38:10 -07:00
|
|
|
|
// Add back all roms with the proper flags
|
|
|
|
|
|
Remove(key);
|
|
|
|
|
|
AddRange(key, output);
|
|
|
|
|
|
AddRange(key, left);
|
2020-07-26 22:34:45 -07:00
|
|
|
|
|
|
|
|
|
|
return output;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Check if a DAT contains the given DatItem
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="datItem">Item to try to match</param>
|
|
|
|
|
|
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</param>
|
|
|
|
|
|
/// <returns>True if it contains the rom, false otherwise</returns>
|
|
|
|
|
|
public bool HasDuplicates(DatItem datItem, bool sorted = false)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Check for an empty rom list first
|
2020-07-27 01:39:32 -07:00
|
|
|
|
if (TotalCount == 0)
|
2020-07-26 22:34:45 -07:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
// We want to get the proper key for the DatItem
|
|
|
|
|
|
string key = SortAndGetKey(datItem, sorted);
|
|
|
|
|
|
|
|
|
|
|
|
// If the key doesn't exist, return the empty list
|
|
|
|
|
|
if (!ContainsKey(key))
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
// Try to find duplicates
|
2023-08-10 23:22:14 -04:00
|
|
|
|
ConcurrentList<DatItem>? roms = this[key];
|
|
|
|
|
|
return roms?.Any(r => datItem.Equals(r)) == true;
|
2020-07-26 22:34:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Recalculate the statistics for the Dat
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void RecalculateStats()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Wipe out any stats already there
|
2020-07-27 01:39:32 -07:00
|
|
|
|
ResetStatistics();
|
2020-07-26 22:34:45 -07:00
|
|
|
|
|
|
|
|
|
|
// If we have a blank Dat in any way, return
|
2020-08-29 23:14:43 -07:00
|
|
|
|
if (items == null)
|
2020-07-26 22:34:45 -07:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
// Loop through and add
|
2020-08-30 17:02:07 -07:00
|
|
|
|
foreach (string key in items.Keys)
|
2020-07-26 22:34:45 -07:00
|
|
|
|
{
|
2023-08-10 23:22:14 -04:00
|
|
|
|
ConcurrentList<DatItem>? datItems = items[key];
|
|
|
|
|
|
if (datItems == null)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
2020-07-26 22:34:45 -07:00
|
|
|
|
foreach (DatItem item in datItems)
|
|
|
|
|
|
{
|
2020-07-27 01:39:32 -07:00
|
|
|
|
AddItemStatistics(item);
|
2020-07-26 22:34:45 -07:00
|
|
|
|
}
|
2020-08-30 17:02:07 -07:00
|
|
|
|
}
|
2020-07-26 22:34:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-27 01:39:32 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Reset all statistics
|
|
|
|
|
|
/// </summary>
|
2020-12-10 23:24:09 -08:00
|
|
|
|
public void ResetStatistics()
|
2020-07-27 01:39:32 -07:00
|
|
|
|
{
|
|
|
|
|
|
TotalCount = 0;
|
|
|
|
|
|
|
|
|
|
|
|
ArchiveCount = 0;
|
|
|
|
|
|
BiosSetCount = 0;
|
2020-08-27 16:57:22 -07:00
|
|
|
|
ChipCount = 0;
|
2020-07-27 01:39:32 -07:00
|
|
|
|
DiskCount = 0;
|
2020-08-27 16:57:22 -07:00
|
|
|
|
MediaCount = 0;
|
2020-07-27 01:39:32 -07:00
|
|
|
|
ReleaseCount = 0;
|
|
|
|
|
|
RomCount = 0;
|
|
|
|
|
|
SampleCount = 0;
|
|
|
|
|
|
|
|
|
|
|
|
GameCount = 0;
|
|
|
|
|
|
|
|
|
|
|
|
TotalSize = 0;
|
|
|
|
|
|
|
|
|
|
|
|
CRCCount = 0;
|
|
|
|
|
|
MD5Count = 0;
|
|
|
|
|
|
SHA1Count = 0;
|
|
|
|
|
|
SHA256Count = 0;
|
|
|
|
|
|
SHA384Count = 0;
|
|
|
|
|
|
SHA512Count = 0;
|
2020-09-18 15:01:03 -07:00
|
|
|
|
SpamSumCount = 0;
|
2020-07-27 01:39:32 -07:00
|
|
|
|
|
|
|
|
|
|
BaddumpCount = 0;
|
|
|
|
|
|
GoodCount = 0;
|
|
|
|
|
|
NodumpCount = 0;
|
2020-08-30 17:02:07 -07:00
|
|
|
|
RemovedCount = 0;
|
2020-07-27 01:39:32 -07:00
|
|
|
|
VerifiedCount = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-10 23:24:09 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get the highest-order Field value that represents the statistics
|
|
|
|
|
|
/// </summary>
|
2020-12-14 15:31:28 -08:00
|
|
|
|
private ItemKey GetBestAvailable()
|
2020-12-10 23:24:09 -08:00
|
|
|
|
{
|
|
|
|
|
|
// If all items are supposed to have a SHA-512, we bucket by that
|
|
|
|
|
|
if (DiskCount + MediaCount + RomCount - NodumpCount == SHA512Count)
|
2020-12-14 15:31:28 -08:00
|
|
|
|
return ItemKey.SHA512;
|
2020-12-10 23:24:09 -08:00
|
|
|
|
|
|
|
|
|
|
// If all items are supposed to have a SHA-384, we bucket by that
|
|
|
|
|
|
else if (DiskCount + MediaCount + RomCount - NodumpCount == SHA384Count)
|
2020-12-14 15:31:28 -08:00
|
|
|
|
return ItemKey.SHA384;
|
2020-12-10 23:24:09 -08:00
|
|
|
|
|
|
|
|
|
|
// If all items are supposed to have a SHA-256, we bucket by that
|
|
|
|
|
|
else if (DiskCount + MediaCount + RomCount - NodumpCount == SHA256Count)
|
2020-12-14 15:31:28 -08:00
|
|
|
|
return ItemKey.SHA256;
|
2020-12-10 23:24:09 -08:00
|
|
|
|
|
|
|
|
|
|
// If all items are supposed to have a SHA-1, we bucket by that
|
|
|
|
|
|
else if (DiskCount + MediaCount + RomCount - NodumpCount == SHA1Count)
|
2020-12-14 15:31:28 -08:00
|
|
|
|
return ItemKey.SHA1;
|
2020-12-10 23:24:09 -08:00
|
|
|
|
|
|
|
|
|
|
// If all items are supposed to have a MD5, we bucket by that
|
|
|
|
|
|
else if (DiskCount + MediaCount + RomCount - NodumpCount == MD5Count)
|
2020-12-14 15:31:28 -08:00
|
|
|
|
return ItemKey.MD5;
|
2020-12-10 23:24:09 -08:00
|
|
|
|
|
|
|
|
|
|
// Otherwise, we bucket by CRC
|
|
|
|
|
|
else
|
2020-12-14 15:31:28 -08:00
|
|
|
|
return ItemKey.CRC;
|
2020-12-10 23:24:09 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-26 22:34:45 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Sort the input DAT and get the key to be used by the item
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="datItem">Item to try to match</param>
|
|
|
|
|
|
/// <param name="sorted">True if the DAT is already sorted accordingly, false otherwise (default)</param>
|
|
|
|
|
|
/// <returns>Key to try to use</returns>
|
|
|
|
|
|
private string SortAndGetKey(DatItem datItem, bool sorted = false)
|
|
|
|
|
|
{
|
|
|
|
|
|
// If we're not already sorted, take care of it
|
|
|
|
|
|
if (!sorted)
|
2020-07-27 01:39:32 -07:00
|
|
|
|
BucketBy(GetBestAvailable(), DedupeType.None);
|
2020-07-26 22:34:45 -07:00
|
|
|
|
|
|
|
|
|
|
// Now that we have the sorted type, we get the proper key
|
|
|
|
|
|
return datItem.GetKey(bucketedBy);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region IDictionary Implementations
|
|
|
|
|
|
|
2023-08-10 23:22:14 -04:00
|
|
|
|
public ICollection<ConcurrentList<DatItem>?> Values => ((IDictionary<string, ConcurrentList<DatItem>?>)items).Values;
|
2020-07-26 22:34:45 -07:00
|
|
|
|
|
2023-08-10 23:22:14 -04:00
|
|
|
|
public int Count => ((ICollection<KeyValuePair<string, ConcurrentList<DatItem>?>>)items).Count;
|
2020-07-26 22:34:45 -07:00
|
|
|
|
|
2023-08-10 23:22:14 -04:00
|
|
|
|
public bool IsReadOnly => ((ICollection<KeyValuePair<string, ConcurrentList<DatItem>?>>)items).IsReadOnly;
|
2020-07-26 22:34:45 -07:00
|
|
|
|
|
2023-08-10 23:22:14 -04:00
|
|
|
|
public bool TryGetValue(string key, out ConcurrentList<DatItem>? value)
|
2020-07-26 22:34:45 -07:00
|
|
|
|
{
|
2023-08-10 23:22:14 -04:00
|
|
|
|
return ((IDictionary<string, ConcurrentList<DatItem>?>)items).TryGetValue(key, out value);
|
2020-07-26 22:34:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-10 23:22:14 -04:00
|
|
|
|
public void Add(KeyValuePair<string, ConcurrentList<DatItem>?> item)
|
2020-07-26 22:34:45 -07:00
|
|
|
|
{
|
2023-08-10 23:22:14 -04:00
|
|
|
|
((ICollection<KeyValuePair<string, ConcurrentList<DatItem>?>>)items).Add(item);
|
2020-07-26 22:34:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Clear()
|
|
|
|
|
|
{
|
2023-08-10 23:22:14 -04:00
|
|
|
|
((ICollection<KeyValuePair<string, ConcurrentList<DatItem>?>>)items).Clear();
|
2020-07-26 22:34:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-10 23:22:14 -04:00
|
|
|
|
public bool Contains(KeyValuePair<string, ConcurrentList<DatItem>?> item)
|
2020-07-26 22:34:45 -07:00
|
|
|
|
{
|
2023-08-10 23:22:14 -04:00
|
|
|
|
return ((ICollection<KeyValuePair<string, ConcurrentList<DatItem>?>>)items).Contains(item);
|
2020-07-26 22:34:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-10 23:22:14 -04:00
|
|
|
|
public void CopyTo(KeyValuePair<string, ConcurrentList<DatItem>?>[] array, int arrayIndex)
|
2020-07-26 22:34:45 -07:00
|
|
|
|
{
|
2023-08-10 23:22:14 -04:00
|
|
|
|
((ICollection<KeyValuePair<string, ConcurrentList<DatItem>?>>)items).CopyTo(array, arrayIndex);
|
2020-07-26 22:34:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-10 23:22:14 -04:00
|
|
|
|
public bool Remove(KeyValuePair<string, ConcurrentList<DatItem>?> item)
|
2020-07-26 22:34:45 -07:00
|
|
|
|
{
|
2023-08-10 23:22:14 -04:00
|
|
|
|
return ((ICollection<KeyValuePair<string, ConcurrentList<DatItem>?>>)items).Remove(item);
|
2020-07-26 22:34:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-10 23:22:14 -04:00
|
|
|
|
public IEnumerator<KeyValuePair<string, ConcurrentList<DatItem>?>> GetEnumerator()
|
2020-07-26 22:34:45 -07:00
|
|
|
|
{
|
2023-08-10 23:22:14 -04:00
|
|
|
|
return ((IEnumerable<KeyValuePair<string, ConcurrentList<DatItem>?>>)items).GetEnumerator();
|
2020-07-26 22:34:45 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
|
|
|
|
{
|
|
|
|
|
|
return ((IEnumerable)items).GetEnumerator();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|