2017-06-13 13:18:41 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2017-09-25 12:21:52 -07:00
|
|
|
|
using System.Linq;
|
2016-10-24 13:51:39 -07:00
|
|
|
|
|
2017-05-04 02:41:11 -07:00
|
|
|
|
using SabreTools.Library.Data;
|
2016-10-26 22:10:47 -07:00
|
|
|
|
|
2017-05-04 02:41:11 -07:00
|
|
|
|
namespace SabreTools.Library.Dats
|
2016-04-19 01:11:23 -07:00
|
|
|
|
{
|
2016-11-08 16:04:26 -08:00
|
|
|
|
public partial class DatFile
|
2016-04-19 01:11:23 -07:00
|
|
|
|
{
|
2016-09-19 20:08:25 -07:00
|
|
|
|
#region Private instance variables
|
|
|
|
|
|
|
2017-10-06 15:49:32 -07:00
|
|
|
|
// Internal DatHeader values
|
|
|
|
|
|
private DatHeader _datHeader = new DatHeader();
|
|
|
|
|
|
|
|
|
|
|
|
// DatItems dictionary
|
2017-09-25 12:38:13 -07:00
|
|
|
|
private SortedDictionary<string, List<DatItem>> _items = new SortedDictionary<string, List<DatItem>>();
|
2016-10-06 11:42:55 -07:00
|
|
|
|
private SortedBy _sortedBy;
|
2016-09-19 20:08:25 -07:00
|
|
|
|
|
2017-10-06 15:49:32 -07:00
|
|
|
|
// Internal statistical data
|
|
|
|
|
|
DatStats _datStats = new DatStats();
|
2016-09-19 20:08:25 -07:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Publicly facing variables
|
|
|
|
|
|
|
|
|
|
|
|
// Data common to most DAT types
|
|
|
|
|
|
public string FileName
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datHeader.FileName; }
|
|
|
|
|
|
set { _datHeader.FileName = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
public string Name
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datHeader.Name; }
|
|
|
|
|
|
set { _datHeader.Name = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
public string Description
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datHeader.Description; }
|
|
|
|
|
|
set { _datHeader.Description = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
public string RootDir
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datHeader.RootDir; }
|
|
|
|
|
|
set { _datHeader.RootDir = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
public string Category
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datHeader.Category; }
|
|
|
|
|
|
set { _datHeader.Category = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
public string Version
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datHeader.Version; }
|
|
|
|
|
|
set { _datHeader.Version = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
public string Date
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datHeader.Date; }
|
|
|
|
|
|
set { _datHeader.Date = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
public string Author
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datHeader.Author; }
|
|
|
|
|
|
set { _datHeader.Author = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
public string Email
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datHeader.Email; }
|
|
|
|
|
|
set { _datHeader.Email = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
public string Homepage
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datHeader.Homepage; }
|
|
|
|
|
|
set { _datHeader.Homepage = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
public string Url
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datHeader.Url; }
|
|
|
|
|
|
set { _datHeader.Url = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
public string Comment
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datHeader.Comment; }
|
|
|
|
|
|
set { _datHeader.Comment = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
public string Header
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datHeader.Header; }
|
|
|
|
|
|
set { _datHeader.Header = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
public string Type // Generally only used for SuperDAT
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datHeader.Type; }
|
|
|
|
|
|
set { _datHeader.Type = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
public ForceMerging ForceMerging
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datHeader.ForceMerging; }
|
|
|
|
|
|
set { _datHeader.ForceMerging = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
public ForceNodump ForceNodump
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datHeader.ForceNodump; }
|
|
|
|
|
|
set { _datHeader.ForceNodump = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
public ForcePacking ForcePacking
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datHeader.ForcePacking; }
|
|
|
|
|
|
set { _datHeader.ForcePacking = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
2016-10-25 15:02:02 -07:00
|
|
|
|
public DatFormat DatFormat
|
2016-09-19 20:08:25 -07:00
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datHeader.DatFormat; }
|
|
|
|
|
|
set { _datHeader.DatFormat = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
2016-10-04 10:26:19 -07:00
|
|
|
|
public bool ExcludeOf
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datHeader.ExcludeOf; }
|
|
|
|
|
|
set { _datHeader.ExcludeOf = value; }
|
2016-10-04 10:26:19 -07:00
|
|
|
|
}
|
2017-08-29 11:46:01 -07:00
|
|
|
|
public DedupeType DedupeRoms
|
2016-09-19 20:08:25 -07:00
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datHeader.DedupeRoms; }
|
|
|
|
|
|
set { _datHeader.DedupeRoms = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
2017-02-26 22:41:17 -08:00
|
|
|
|
public Hash StripHash
|
2017-02-25 20:35:06 -08:00
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datHeader.StripHash; }
|
|
|
|
|
|
set { _datHeader.StripHash = value; }
|
2017-02-25 20:35:06 -08:00
|
|
|
|
}
|
2017-02-27 21:53:20 -08:00
|
|
|
|
public bool OneGameOneRegion
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datHeader.OneGameOneRegion; }
|
|
|
|
|
|
set { _datHeader.OneGameOneRegion = value; }
|
2017-02-27 21:53:20 -08:00
|
|
|
|
}
|
|
|
|
|
|
public List<string> Regions
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datHeader.Regions; }
|
|
|
|
|
|
set { _datHeader.Regions = value; }
|
2017-02-27 21:53:20 -08:00
|
|
|
|
}
|
2016-10-06 11:42:55 -07:00
|
|
|
|
public SortedBy SortedBy
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return _sortedBy; }
|
|
|
|
|
|
}
|
2016-09-19 20:08:25 -07:00
|
|
|
|
|
|
|
|
|
|
// Data specific to the Miss DAT type
|
|
|
|
|
|
public bool UseGame
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datHeader.UseGame; }
|
|
|
|
|
|
set { _datHeader.UseGame = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
public string Prefix
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datHeader.Prefix; }
|
|
|
|
|
|
set { _datHeader.Prefix = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
public string Postfix
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datHeader.Postfix; }
|
|
|
|
|
|
set { _datHeader.Postfix = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
public bool Quotes
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datHeader.Quotes; }
|
|
|
|
|
|
set { _datHeader.Quotes = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
public string RepExt
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datHeader.RepExt; }
|
|
|
|
|
|
set { _datHeader.RepExt = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
public string AddExt
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datHeader.AddExt; }
|
|
|
|
|
|
set { _datHeader.AddExt = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
public bool RemExt
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datHeader.RemExt; }
|
|
|
|
|
|
set { _datHeader.RemExt = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
public bool GameName
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datHeader.GameName; }
|
|
|
|
|
|
set { _datHeader.GameName = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
public bool Romba
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datHeader.Romba; }
|
|
|
|
|
|
set { _datHeader.Romba = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Statistical data related to the DAT
|
2017-06-13 13:18:41 -07:00
|
|
|
|
public long Count
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datStats.Count; }
|
|
|
|
|
|
private set { _datStats.Count = value; }
|
2017-06-13 13:18:41 -07:00
|
|
|
|
}
|
2017-10-06 15:49:32 -07:00
|
|
|
|
public long ArchiveCount
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return _datStats.ArchiveCount; }
|
|
|
|
|
|
private set { _datStats.ArchiveCount = value; }
|
|
|
|
|
|
}
|
|
|
|
|
|
public long BiosSetCount
|
2016-09-19 20:08:25 -07:00
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datStats.BiosSetCount; }
|
|
|
|
|
|
private set { _datStats.BiosSetCount = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
public long DiskCount
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datStats.DiskCount; }
|
|
|
|
|
|
private set { _datStats.DiskCount = value; }
|
|
|
|
|
|
}
|
|
|
|
|
|
public long ReleaseCount
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return _datStats.ReleaseCount; }
|
|
|
|
|
|
private set { _datStats.ReleaseCount = value; }
|
|
|
|
|
|
}
|
|
|
|
|
|
public long RomCount
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return _datStats.RomCount; }
|
|
|
|
|
|
private set { _datStats.RomCount = value; }
|
|
|
|
|
|
}
|
|
|
|
|
|
public long SampleCount
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return _datStats.SampleCount; }
|
|
|
|
|
|
private set { _datStats.SampleCount = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
public long TotalSize
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datStats.TotalSize; }
|
|
|
|
|
|
private set { _datStats.TotalSize = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
public long CRCCount
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datStats.CRCCount; }
|
|
|
|
|
|
private set { _datStats.CRCCount = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
public long MD5Count
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datStats.MD5Count; }
|
|
|
|
|
|
private set { _datStats.MD5Count = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
public long SHA1Count
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datStats.SHA1Count; }
|
|
|
|
|
|
private set { _datStats.SHA1Count = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
2017-02-23 14:34:01 -08:00
|
|
|
|
public long SHA256Count
|
2017-02-23 14:23:41 -08:00
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datStats.SHA256Count; }
|
|
|
|
|
|
private set { _datStats.SHA256Count = value; }
|
2017-02-23 14:23:41 -08:00
|
|
|
|
}
|
2017-02-27 00:01:24 -08:00
|
|
|
|
public long SHA384Count
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datStats.SHA384Count; }
|
|
|
|
|
|
private set { _datStats.SHA384Count = value; }
|
2017-02-27 00:01:24 -08:00
|
|
|
|
}
|
|
|
|
|
|
public long SHA512Count
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datStats.SHA512Count; }
|
|
|
|
|
|
private set { _datStats.SHA512Count = value; }
|
2017-02-27 00:01:24 -08:00
|
|
|
|
}
|
2016-09-26 16:42:06 -07:00
|
|
|
|
public long BaddumpCount
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datStats.BaddumpCount; }
|
|
|
|
|
|
private set { _datStats.BaddumpCount = value; }
|
|
|
|
|
|
}
|
|
|
|
|
|
public long GoodCount
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return _datStats.GoodCount; }
|
|
|
|
|
|
private set { _datStats.GoodCount = value; }
|
2016-09-26 16:42:06 -07:00
|
|
|
|
}
|
2016-09-19 20:08:25 -07:00
|
|
|
|
public long NodumpCount
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
get { return _datStats.NodumpCount; }
|
|
|
|
|
|
private set { _datStats.NodumpCount = value; }
|
|
|
|
|
|
}
|
|
|
|
|
|
public long VerifiedCount
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return _datStats.VerifiedCount; }
|
|
|
|
|
|
private set { _datStats.VerifiedCount = value; }
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2016-10-06 11:42:55 -07:00
|
|
|
|
#region Instance Methods
|
|
|
|
|
|
|
2016-11-08 15:29:52 -08:00
|
|
|
|
#region Accessors
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Passthrough to access the file dictionary
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="key">Key in the dictionary to reference</param>
|
2017-09-25 12:21:52 -07:00
|
|
|
|
/// <remarks>We don't want to allow direct setting of values because it bypasses the statistics</remarks>
|
2016-11-08 15:29:52 -08:00
|
|
|
|
public List<DatItem> this[string key]
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
// If the dictionary is null, create it
|
2017-09-25 12:38:13 -07:00
|
|
|
|
if (_items == null)
|
2016-11-08 15:29:52 -08:00
|
|
|
|
{
|
2017-09-25 12:38:13 -07:00
|
|
|
|
_items = new SortedDictionary<string, List<DatItem>>();
|
2016-11-08 15:29:52 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-25 12:38:13 -07:00
|
|
|
|
lock (_items)
|
2016-11-08 15:29:52 -08:00
|
|
|
|
{
|
2016-12-01 11:43:09 -08:00
|
|
|
|
// If the key is missing from the dictionary, add it
|
2017-09-25 12:38:13 -07:00
|
|
|
|
if (!_items.ContainsKey(key))
|
2016-12-01 11:43:09 -08:00
|
|
|
|
{
|
2017-09-25 12:38:13 -07:00
|
|
|
|
_items.Add(key, new List<DatItem>());
|
2016-12-01 11:43:09 -08:00
|
|
|
|
}
|
2016-11-08 15:29:52 -08:00
|
|
|
|
|
2016-12-01 11:43:09 -08:00
|
|
|
|
// Now return the value
|
2017-09-25 12:38:13 -07:00
|
|
|
|
return _items[key];
|
2016-12-01 11:43:09 -08:00
|
|
|
|
}
|
2016-11-08 15:29:52 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Add a new key to the file dictionary
|
|
|
|
|
|
/// </summary>
|
2017-06-13 13:18:41 -07:00
|
|
|
|
/// <param name="key">Key in the dictionary to add</param>
|
2016-11-08 15:29:52 -08:00
|
|
|
|
public void Add(string key)
|
|
|
|
|
|
{
|
2016-12-01 11:43:09 -08:00
|
|
|
|
// If the dictionary is null, create it
|
2017-09-25 12:38:13 -07:00
|
|
|
|
if (_items == null)
|
2016-11-08 15:29:52 -08:00
|
|
|
|
{
|
2017-09-25 12:38:13 -07:00
|
|
|
|
_items = new SortedDictionary<string, List<DatItem>>();
|
2016-12-01 11:43:09 -08:00
|
|
|
|
}
|
2016-11-08 15:29:52 -08:00
|
|
|
|
|
2017-09-25 12:38:13 -07:00
|
|
|
|
lock (_items)
|
2016-12-01 11:43:09 -08:00
|
|
|
|
{
|
2016-11-08 15:29:52 -08:00
|
|
|
|
// If the key is missing from the dictionary, add it
|
2017-09-25 12:38:13 -07:00
|
|
|
|
if (!_items.ContainsKey(key))
|
2016-11-08 15:29:52 -08:00
|
|
|
|
{
|
2017-09-25 12:38:13 -07:00
|
|
|
|
_items.Add(key, new List<DatItem>());
|
2016-11-08 15:29:52 -08: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)
|
|
|
|
|
|
{
|
2016-12-01 11:43:09 -08:00
|
|
|
|
// If the dictionary is null, create it
|
2017-09-25 12:38:13 -07:00
|
|
|
|
if (_items == null)
|
2016-11-08 15:29:52 -08:00
|
|
|
|
{
|
2017-09-25 12:38:13 -07:00
|
|
|
|
_items = new SortedDictionary<string, List<DatItem>>();
|
2016-12-01 11:43:09 -08:00
|
|
|
|
}
|
2016-11-08 15:29:52 -08:00
|
|
|
|
|
2017-06-13 13:18:41 -07:00
|
|
|
|
// Add the key, if necessary
|
|
|
|
|
|
Add(key);
|
|
|
|
|
|
|
2017-09-25 12:38:13 -07:00
|
|
|
|
lock (_items)
|
2016-12-01 11:43:09 -08:00
|
|
|
|
{
|
2016-11-08 15:29:52 -08:00
|
|
|
|
// Now add the value
|
2017-09-25 12:38:13 -07:00
|
|
|
|
_items[key].Add(value);
|
2017-06-13 13:18:41 -07:00
|
|
|
|
|
|
|
|
|
|
// Now update the statistics
|
2017-10-06 15:49:32 -07:00
|
|
|
|
_datStats.AddItem(value);
|
2016-11-08 15:29:52 -08: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>
|
|
|
|
|
|
public void AddRange(string key, List<DatItem> value)
|
|
|
|
|
|
{
|
2016-12-01 11:43:09 -08:00
|
|
|
|
// If the dictionary is null, create it
|
2017-09-25 12:38:13 -07:00
|
|
|
|
if (_items == null)
|
2016-11-08 15:29:52 -08:00
|
|
|
|
{
|
2017-09-25 12:38:13 -07:00
|
|
|
|
_items = new SortedDictionary<string, List<DatItem>>();
|
2016-12-01 11:43:09 -08:00
|
|
|
|
}
|
2016-11-08 15:29:52 -08:00
|
|
|
|
|
2017-06-13 13:18:41 -07:00
|
|
|
|
// Add the key, if necessary
|
|
|
|
|
|
Add(key);
|
|
|
|
|
|
|
2017-09-25 12:38:13 -07:00
|
|
|
|
lock (_items)
|
2016-12-01 11:43:09 -08:00
|
|
|
|
{
|
2016-11-08 15:29:52 -08:00
|
|
|
|
// Now add the value
|
2017-09-25 12:38:13 -07:00
|
|
|
|
_items[key].AddRange(value);
|
2017-06-13 13:18:41 -07:00
|
|
|
|
|
|
|
|
|
|
// Now update the statistics
|
|
|
|
|
|
foreach (DatItem item in value)
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
_datStats.AddItem(item);
|
2017-06-13 13:18:41 -07:00
|
|
|
|
}
|
2016-11-08 15:29:52 -08: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>
|
2017-09-25 12:56:45 -07:00
|
|
|
|
public bool Contains(string key)
|
2016-11-08 15:29:52 -08:00
|
|
|
|
{
|
2017-09-25 12:56:45 -07:00
|
|
|
|
bool contains = false;
|
|
|
|
|
|
|
2016-12-01 11:43:09 -08:00
|
|
|
|
// If the dictionary is null, create it
|
2017-09-25 12:38:13 -07:00
|
|
|
|
if (_items == null)
|
2016-11-08 15:29:52 -08:00
|
|
|
|
{
|
2017-09-25 12:38:13 -07:00
|
|
|
|
_items = new SortedDictionary<string, List<DatItem>>();
|
2016-12-01 11:43:09 -08:00
|
|
|
|
}
|
2016-11-08 15:29:52 -08:00
|
|
|
|
|
2017-03-05 10:22:58 -08:00
|
|
|
|
// If the key is null, we return false since keys can't be null
|
|
|
|
|
|
if (key == null)
|
|
|
|
|
|
{
|
2017-09-25 12:56:45 -07:00
|
|
|
|
return contains;
|
2017-03-05 10:22:58 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-25 12:38:13 -07:00
|
|
|
|
lock (_items)
|
2016-12-01 11:43:09 -08:00
|
|
|
|
{
|
2017-09-25 12:56:45 -07:00
|
|
|
|
contains = _items.ContainsKey(key);
|
2016-11-08 15:29:52 -08:00
|
|
|
|
}
|
2017-09-25 12:56:45 -07:00
|
|
|
|
|
|
|
|
|
|
return contains;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <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)
|
|
|
|
|
|
{
|
|
|
|
|
|
bool contains = false;
|
|
|
|
|
|
|
|
|
|
|
|
// If the dictionary is null, create it
|
|
|
|
|
|
if (_items == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_items = new SortedDictionary<string, List<DatItem>>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If the key is null, we return false since keys can't be null
|
|
|
|
|
|
if (key == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return contains;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lock (_items)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_items.ContainsKey(key))
|
|
|
|
|
|
{
|
|
|
|
|
|
contains = _items.ContainsKey(key);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return contains;
|
2016-11-08 15:29:52 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Get the keys from the file dictionary
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>IEnumerable of the keys</returns>
|
|
|
|
|
|
public IEnumerable<string> Keys
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2016-12-01 11:43:09 -08:00
|
|
|
|
// If the dictionary is null, create it
|
2017-09-25 12:38:13 -07:00
|
|
|
|
if (_items == null)
|
2016-11-08 15:29:52 -08:00
|
|
|
|
{
|
2017-09-25 12:38:13 -07:00
|
|
|
|
_items = new SortedDictionary<string, List<DatItem>>();
|
2016-12-01 11:43:09 -08:00
|
|
|
|
}
|
2016-11-08 15:29:52 -08:00
|
|
|
|
|
2017-09-25 12:38:13 -07:00
|
|
|
|
lock (_items)
|
2016-12-01 11:43:09 -08:00
|
|
|
|
{
|
2017-09-25 12:38:13 -07:00
|
|
|
|
return _items.Keys;
|
2016-11-08 15:29:52 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Remove a key from the file dictionary
|
|
|
|
|
|
/// </summary>
|
2017-09-25 12:21:52 -07:00
|
|
|
|
/// <param name="key">Key in the dictionary to remove</param>
|
2016-11-08 15:29:52 -08:00
|
|
|
|
public void Remove(string key)
|
|
|
|
|
|
{
|
2016-12-01 11:43:09 -08:00
|
|
|
|
// If the dictionary is null, create it
|
2017-09-25 12:38:13 -07:00
|
|
|
|
if (_items == null)
|
2016-11-08 15:29:52 -08:00
|
|
|
|
{
|
2017-09-25 12:38:13 -07:00
|
|
|
|
_items = new SortedDictionary<string, List<DatItem>>();
|
2016-12-01 11:43:09 -08:00
|
|
|
|
}
|
2016-11-08 15:29:52 -08:00
|
|
|
|
|
2017-09-25 12:56:45 -07:00
|
|
|
|
// If the key doesn't exist, return
|
|
|
|
|
|
if (!Contains(key))
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-25 12:38:13 -07:00
|
|
|
|
lock (_items)
|
2016-12-01 11:43:09 -08:00
|
|
|
|
{
|
2017-09-25 12:56:45 -07:00
|
|
|
|
// Remove the statistics first
|
|
|
|
|
|
foreach (DatItem item in _items[key])
|
2016-11-08 15:29:52 -08:00
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
_datStats.RemoveItem(item);
|
2016-11-08 15:29:52 -08:00
|
|
|
|
}
|
2017-09-25 12:56:45 -07:00
|
|
|
|
|
|
|
|
|
|
// Remove the key from the dictionary
|
|
|
|
|
|
_items.Remove(key);
|
2016-11-08 15:29:52 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-25 12:21:52 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Remove a value from the file dictionary
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="key">Key in the dictionary to remove from</param>
|
|
|
|
|
|
/// <param name="value">Value to remove from the dictionary</param>
|
|
|
|
|
|
public void Remove(string key, DatItem value)
|
|
|
|
|
|
{
|
|
|
|
|
|
// If the dictionary is null, create it
|
2017-09-25 12:38:13 -07:00
|
|
|
|
if (_items == null)
|
2017-09-25 12:21:52 -07:00
|
|
|
|
{
|
2017-09-25 12:38:13 -07:00
|
|
|
|
_items = new SortedDictionary<string, List<DatItem>>();
|
2017-09-25 12:21:52 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-25 12:56:45 -07:00
|
|
|
|
// If the key and value doesn't exist, return
|
|
|
|
|
|
if (!Contains(key, value))
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-25 12:38:13 -07:00
|
|
|
|
lock (_items)
|
2017-09-25 12:21:52 -07:00
|
|
|
|
{
|
|
|
|
|
|
// While the key is in the dictionary and the item is there, remove it
|
2017-09-25 12:38:13 -07:00
|
|
|
|
while (_items.ContainsKey(key) && _items[key].Contains(value))
|
2017-09-25 12:21:52 -07:00
|
|
|
|
{
|
|
|
|
|
|
// Remove the statistics first
|
2017-10-06 15:49:32 -07:00
|
|
|
|
_datStats.RemoveItem(value);
|
2017-09-25 12:21:52 -07:00
|
|
|
|
|
2017-09-25 12:38:13 -07:00
|
|
|
|
_items[key].Remove(value);
|
2017-09-25 12:21:52 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Remove a range of values from the file dictionary
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="key">Key in the dictionary to remove from</param>
|
|
|
|
|
|
/// <param name="value">Value to remove from the dictionary</param>
|
|
|
|
|
|
public void RemoveRange(string key, List<DatItem> value)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach(DatItem item in value)
|
|
|
|
|
|
{
|
|
|
|
|
|
Remove(key, item);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-11-08 15:29:52 -08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2016-11-08 16:04:26 -08:00
|
|
|
|
#region Constructors
|
2016-09-19 20:08:25 -07:00
|
|
|
|
|
2016-11-08 16:04:26 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Create a new, empty DatFile object
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public DatFile()
|
2016-09-19 20:08:25 -07:00
|
|
|
|
{
|
2017-09-25 12:38:13 -07:00
|
|
|
|
_items = new SortedDictionary<string, List<DatItem>>();
|
2016-11-08 16:04:26 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2017-10-06 15:49:32 -07:00
|
|
|
|
/// Create a new DatFile from an existing one using the header values only
|
2016-11-08 16:04:26 -08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="df"></param>
|
|
|
|
|
|
public DatFile(DatFile datFile)
|
|
|
|
|
|
{
|
2017-10-06 15:49:32 -07:00
|
|
|
|
_datHeader = (DatHeader)datFile._datHeader.Clone();
|
2016-09-19 20:08:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2017-09-25 12:21:52 -07:00
|
|
|
|
#region Dictionary Manipulation
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Clones the files dictionary
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>A new files dictionary instance</returns>
|
2017-09-25 14:28:55 -07:00
|
|
|
|
public SortedDictionary<string, List<DatItem>> CloneDictionary()
|
2017-09-25 12:21:52 -07:00
|
|
|
|
{
|
|
|
|
|
|
// Create the placeholder dictionary to be used
|
|
|
|
|
|
SortedDictionary<string, List<DatItem>> sorted = new SortedDictionary<string, List<DatItem>>();
|
|
|
|
|
|
|
|
|
|
|
|
// Now perform a deep clone on the entire dictionary
|
|
|
|
|
|
List<string> keys = Keys.ToList();
|
|
|
|
|
|
foreach (string key in keys)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Clone each list of DATs in the dictionary
|
|
|
|
|
|
List<DatItem> olditems = this[key];
|
|
|
|
|
|
List<DatItem> newitems = new List<DatItem>();
|
|
|
|
|
|
foreach (DatItem item in olditems)
|
|
|
|
|
|
{
|
|
|
|
|
|
newitems.Add((DatItem)item.Clone());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If the key is missing from the new dictionary, add it
|
|
|
|
|
|
if (!sorted.ContainsKey(key))
|
|
|
|
|
|
{
|
|
|
|
|
|
sorted.Add(key, new List<DatItem>());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Now add the list of items
|
|
|
|
|
|
sorted[key].AddRange(newitems);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return sorted;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-25 14:28:55 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Delete the file dictionary
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void DeleteDictionary()
|
|
|
|
|
|
{
|
|
|
|
|
|
_items = null;
|
|
|
|
|
|
|
|
|
|
|
|
// Reset statistics
|
2017-10-06 15:49:32 -07:00
|
|
|
|
_datStats.Reset();
|
2017-09-25 14:28:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Reset the file dictionary
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void ResetDictionary()
|
|
|
|
|
|
{
|
|
|
|
|
|
_items = new SortedDictionary<string, List<DatItem>>();
|
|
|
|
|
|
|
|
|
|
|
|
// Reset statistics
|
2017-10-06 15:49:32 -07:00
|
|
|
|
_datStats.Reset();
|
2017-09-25 14:28:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-25 12:21:52 -07:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2016-10-24 16:14:22 -07:00
|
|
|
|
#endregion // Instance Methods
|
2016-04-19 01:11:23 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|