[DatFile, DatHeader, DatStats] Descriptors

This commit is contained in:
Matt Nadareski
2019-01-08 11:49:31 -08:00
parent b0d91d11c3
commit 9e3df30b90
3 changed files with 6292 additions and 5861 deletions

View File

@@ -5,7 +5,6 @@ using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;
using SabreTools.Library.Data;
using SabreTools.Library.FileTypes;
using SabreTools.Library.DatItems;
@@ -41,8 +40,6 @@ namespace SabreTools.Library.DatFiles
// DatItems dictionary
internal SortedDictionary<string, List<DatItem>> _items = new SortedDictionary<string, List<DatItem>>();
internal SortedBy _sortedBy;
internal DedupeType _mergedBy;
// Internal statistical data
internal DatStats _datStats = new DatStats();
@@ -51,7 +48,11 @@ namespace SabreTools.Library.DatFiles
#region Publicly facing variables
// Data common to most DAT types
#region Data common to most DAT types
/// <summary>
/// External name of the DAT
/// </summary>
public string FileName
{
get
@@ -65,6 +66,10 @@ namespace SabreTools.Library.DatFiles
_datHeader.FileName = value;
}
}
/// <summary>
/// Internal name of the DAT
/// </summary>
public string Name
{
get
@@ -78,6 +83,10 @@ namespace SabreTools.Library.DatFiles
_datHeader.Name = value;
}
}
/// <summary>
/// DAT description
/// </summary>
public string Description
{
get
@@ -91,6 +100,10 @@ namespace SabreTools.Library.DatFiles
_datHeader.Description = value;
}
}
/// <summary>
/// Root directory for the files; currently TruRip/EmuARC-exclusive
/// </summary>
public string RootDir
{
get
@@ -104,6 +117,10 @@ namespace SabreTools.Library.DatFiles
_datHeader.RootDir = value;
}
}
/// <summary>
/// General category of items found in the DAT
/// </summary>
public string Category
{
get
@@ -117,6 +134,10 @@ namespace SabreTools.Library.DatFiles
_datHeader.Category = value;
}
}
/// <summary>
/// Version of the DAT
/// </summary>
public string Version
{
get
@@ -130,6 +151,10 @@ namespace SabreTools.Library.DatFiles
_datHeader.Version = value;
}
}
/// <summary>
/// Creation or modification date
/// </summary>
public string Date
{
get
@@ -143,6 +168,10 @@ namespace SabreTools.Library.DatFiles
_datHeader.Date = value;
}
}
/// <summary>
/// List of authors who contributed to the DAT
/// </summary>
public string Author
{
get
@@ -156,6 +185,10 @@ namespace SabreTools.Library.DatFiles
_datHeader.Author = value;
}
}
/// <summary>
/// Email address for DAT author(s)
/// </summary>
public string Email
{
get
@@ -169,6 +202,10 @@ namespace SabreTools.Library.DatFiles
_datHeader.Email = value;
}
}
/// <summary>
/// Author or distribution homepage name
/// </summary>
public string Homepage
{
get
@@ -182,6 +219,10 @@ namespace SabreTools.Library.DatFiles
_datHeader.Homepage = value;
}
}
/// <summary>
/// Author or distribution URL
/// </summary>
public string Url
{
get
@@ -195,6 +236,10 @@ namespace SabreTools.Library.DatFiles
_datHeader.Url = value;
}
}
/// <summary>
/// Any comment that does not already fit an existing field
/// </summary>
public string Comment
{
get
@@ -208,6 +253,10 @@ namespace SabreTools.Library.DatFiles
_datHeader.Comment = value;
}
}
/// <summary>
/// Header skipper to be used when loading the DAT
/// </summary>
public string Header
{
get
@@ -221,7 +270,11 @@ namespace SabreTools.Library.DatFiles
_datHeader.Header = value;
}
}
public string Type // Generally only used for SuperDAT
/// <summary>
/// Classification of the DAT. Generally only used for SuperDAT
/// </summary>
public string Type
{
get
{
@@ -234,6 +287,10 @@ namespace SabreTools.Library.DatFiles
_datHeader.Type = value;
}
}
/// <summary>
/// Force a merging style when loaded
/// </summary>
public ForceMerging ForceMerging
{
get
@@ -247,6 +304,10 @@ namespace SabreTools.Library.DatFiles
_datHeader.ForceMerging = value;
}
}
/// <summary>
/// Force nodump handling when loaded
/// </summary>
public ForceNodump ForceNodump
{
get
@@ -260,6 +321,10 @@ namespace SabreTools.Library.DatFiles
_datHeader.ForceNodump = value;
}
}
/// <summary>
/// Force output packing when loaded
/// </summary>
public ForcePacking ForcePacking
{
get
@@ -273,6 +338,10 @@ namespace SabreTools.Library.DatFiles
_datHeader.ForcePacking = value;
}
}
/// <summary>
/// Read or write format
/// </summary>
public DatFormat DatFormat
{
get
@@ -286,6 +355,10 @@ namespace SabreTools.Library.DatFiles
_datHeader.DatFormat = value;
}
}
/// <summary>
/// List of fields in machine and items to exclude from writing
/// </summary>
public bool[] ExcludeFields
{
get
@@ -299,6 +372,10 @@ namespace SabreTools.Library.DatFiles
_datHeader.ExcludeFields = value;
}
}
/// <summary>
/// Enable "One Rom, One Region (1G1R)" mode
/// </summary>
public bool OneRom
{
get
@@ -312,6 +389,10 @@ namespace SabreTools.Library.DatFiles
_datHeader.OneRom = value;
}
}
/// <summary>
/// Keep machines that don't contain any items
/// </summary>
public bool KeepEmptyGames
{
get
@@ -325,6 +406,10 @@ namespace SabreTools.Library.DatFiles
_datHeader.KeepEmptyGames = value;
}
}
/// <summary>
/// Remove scene dates from the beginning of machine names
/// </summary>
public bool SceneDateStrip
{
get
@@ -338,6 +423,10 @@ namespace SabreTools.Library.DatFiles
_datHeader.SceneDateStrip = value;
}
}
/// <summary>
/// Deduplicate items using the given method
/// </summary>
public DedupeType DedupeRoms
{
get
@@ -351,16 +440,36 @@ namespace SabreTools.Library.DatFiles
_datHeader.DedupeRoms = value;
}
}
public SortedBy SortedBy
/// <summary>
/// Strip hash types from items
/// </summary>
public Hash StripHash
{
get { return _sortedBy; }
get
{
EnsureDatHeader();
return _datHeader.StripHash;
}
public DedupeType MergedBy
{
get { return _mergedBy; }
}
// Write pre-processing
/// <summary>
/// Determine the sorting key for all items
/// </summary>
public SortedBy SortedBy { get; private set; }
/// <summary>
/// Determine merging type for all items
/// </summary>
public DedupeType MergedBy { get; private set; }
#endregion
#region Write pre-processing
/// <summary>
/// Text to prepend to all outputted lines
/// </summary>
public string Prefix
{
get
@@ -374,6 +483,10 @@ namespace SabreTools.Library.DatFiles
_datHeader.Prefix = value;
}
}
/// <summary>
/// Text to append to all outputted lines
/// </summary>
public string Postfix
{
get
@@ -387,6 +500,10 @@ namespace SabreTools.Library.DatFiles
_datHeader.Postfix = value;
}
}
/// <summary>
/// Add a new extension to all items
/// </summary>
public string AddExtension
{
get
@@ -400,6 +517,10 @@ namespace SabreTools.Library.DatFiles
_datHeader.AddExtension = value;
}
}
/// <summary>
/// Replace all item extensions
/// </summary>
public string ReplaceExtension
{
get
@@ -413,6 +534,10 @@ namespace SabreTools.Library.DatFiles
_datHeader.ReplaceExtension = value;
}
}
/// <summary>
/// Remove all item extensions
/// </summary>
public bool RemoveExtension
{
get
@@ -426,6 +551,10 @@ namespace SabreTools.Library.DatFiles
_datHeader.RemoveExtension = value;
}
}
/// <summary>
/// Romba output mode
/// </summary>
public bool Romba
{
get
@@ -439,6 +568,10 @@ namespace SabreTools.Library.DatFiles
_datHeader.Romba = value;
}
}
/// <summary>
/// Output the machine name
/// </summary>
public bool GameName
{
get
@@ -452,6 +585,10 @@ namespace SabreTools.Library.DatFiles
_datHeader.GameName = value;
}
}
/// <summary>
/// Wrap quotes around the entire line, sans prefix and postfix
/// </summary>
public bool Quotes
{
get
@@ -466,7 +603,13 @@ namespace SabreTools.Library.DatFiles
}
}
// Data specific to the Miss DAT type
#endregion
#region Data specific to the Miss DAT type
/// <summary>
/// Output the item name
/// </summary>
public bool UseRomName
{
get
@@ -481,7 +624,13 @@ namespace SabreTools.Library.DatFiles
}
}
// Statistical data related to the DAT
#endregion
#region Statistical data related to the DAT
/// <summary>
/// Statistics writing format
/// </summary>
public StatReportFormat ReportFormat
{
get
@@ -495,6 +644,10 @@ namespace SabreTools.Library.DatFiles
_datStats.ReportFormat = value;
}
}
/// <summary>
/// Overall item count
/// </summary>
public long Count
{
get
@@ -508,6 +661,10 @@ namespace SabreTools.Library.DatFiles
_datStats.Count = value;
}
}
/// <summary>
/// Number of Archive items
/// </summary>
public long ArchiveCount
{
get
@@ -521,6 +678,10 @@ namespace SabreTools.Library.DatFiles
_datStats.ArchiveCount = value;
}
}
/// <summary>
/// Number of BiosSet items
/// </summary>
public long BiosSetCount
{
get
@@ -534,6 +695,10 @@ namespace SabreTools.Library.DatFiles
_datStats.BiosSetCount = value;
}
}
/// <summary>
/// Number of Disk items
/// </summary>
public long DiskCount
{
get
@@ -547,6 +712,10 @@ namespace SabreTools.Library.DatFiles
_datStats.DiskCount = value;
}
}
/// <summary>
/// Number of Release items
/// </summary>
public long ReleaseCount
{
get
@@ -560,6 +729,10 @@ namespace SabreTools.Library.DatFiles
_datStats.ReleaseCount = value;
}
}
/// <summary>
/// Number of Rom items
/// </summary>
public long RomCount
{
get
@@ -573,6 +746,10 @@ namespace SabreTools.Library.DatFiles
_datStats.RomCount = value;
}
}
/// <summary>
/// Number of Sample items
/// </summary>
public long SampleCount
{
get
@@ -586,6 +763,10 @@ namespace SabreTools.Library.DatFiles
_datStats.SampleCount = value;
}
}
/// <summary>
/// Total uncompressed size
/// </summary>
public long TotalSize
{
get
@@ -599,6 +780,10 @@ namespace SabreTools.Library.DatFiles
_datStats.TotalSize = value;
}
}
/// <summary>
/// Number of items with a CRC hash
/// </summary>
public long CRCCount
{
get
@@ -612,6 +797,10 @@ namespace SabreTools.Library.DatFiles
_datStats.CRCCount = value;
}
}
/// <summary>
/// Number of items with an MD5 hash
/// </summary>
public long MD5Count
{
get
@@ -625,6 +814,10 @@ namespace SabreTools.Library.DatFiles
_datStats.MD5Count = value;
}
}
/// <summary>
/// Number of items with a SHA-1 hash
/// </summary>
public long SHA1Count
{
get
@@ -638,6 +831,10 @@ namespace SabreTools.Library.DatFiles
_datStats.SHA1Count = value;
}
}
/// <summary>
/// Number of items with a SHA-256 hash
/// </summary>
public long SHA256Count
{
get
@@ -651,6 +848,10 @@ namespace SabreTools.Library.DatFiles
_datStats.SHA256Count = value;
}
}
/// <summary>
/// Number of items with a SHA-384 hash
/// </summary>
public long SHA384Count
{
get
@@ -664,6 +865,10 @@ namespace SabreTools.Library.DatFiles
_datStats.SHA384Count = value;
}
}
/// <summary>
/// Number of items with a SHA-512 hash
/// </summary>
public long SHA512Count
{
get
@@ -677,6 +882,10 @@ namespace SabreTools.Library.DatFiles
_datStats.SHA512Count = value;
}
}
/// <summary>
/// Number of items with the baddump status
/// </summary>
public long BaddumpCount
{
get
@@ -690,6 +899,10 @@ namespace SabreTools.Library.DatFiles
_datStats.BaddumpCount = value;
}
}
/// <summary>
/// Number of items with the good status
/// </summary>
public long GoodCount
{
get
@@ -703,6 +916,10 @@ namespace SabreTools.Library.DatFiles
_datStats.GoodCount = value;
}
}
/// <summary>
/// Number of items with the nodump status
/// </summary>
public long NodumpCount
{
get
@@ -716,6 +933,10 @@ namespace SabreTools.Library.DatFiles
_datStats.NodumpCount = value;
}
}
/// <summary>
/// Number of items with the verified status
/// </summary>
public long VerifiedCount
{
get
@@ -732,6 +953,8 @@ namespace SabreTools.Library.DatFiles
#endregion
#endregion
#region Instance Methods
#region Accessors
@@ -1031,15 +1254,15 @@ namespace SabreTools.Library.DatFiles
}
// If the sorted type isn't the same, we want to sort the dictionary accordingly
if (_sortedBy != bucketBy)
if (this.SortedBy != bucketBy)
{
Globals.Logger.User("Organizing roms by {0}", bucketBy);
// Set the sorted type
_sortedBy = bucketBy;
this.SortedBy = bucketBy;
// Reset the merged type since this might change the merge
_mergedBy = DedupeType.None;
this.MergedBy = DedupeType.None;
// First do the initial sort of all of the roms inplace
List<string> oldkeys = Keys;
@@ -1076,12 +1299,12 @@ namespace SabreTools.Library.DatFiles
}
// If the merge type isn't the same, we want to merge the dictionary accordingly
if (_mergedBy != deduperoms)
if (this.MergedBy != deduperoms)
{
Globals.Logger.User("Deduping roms by {0}", deduperoms);
// Set the sorted type
_mergedBy = deduperoms;
this.MergedBy = deduperoms;
List<string> keys = Keys;
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
@@ -1208,8 +1431,8 @@ namespace SabreTools.Library.DatFiles
{
this._datHeader = datFile._datHeader;
this._items = datFile._items;
this._sortedBy = datFile._sortedBy;
this._mergedBy = datFile._mergedBy;
this.SortedBy = datFile.SortedBy;
this.MergedBy = datFile.MergedBy;
this._datStats = datFile._datStats;
}
}
@@ -2031,8 +2254,8 @@ namespace SabreTools.Library.DatFiles
public void DeleteDictionary()
{
_items = null;
_sortedBy = SortedBy.Default;
_mergedBy = DedupeType.None;
this.SortedBy = SortedBy.Default;
this.MergedBy = DedupeType.None;
// Reset statistics
_datStats.Reset();
@@ -2044,8 +2267,8 @@ namespace SabreTools.Library.DatFiles
public void ResetDictionary()
{
_items = new SortedDictionary<string, List<DatItem>>();
_sortedBy = SortedBy.Default;
_mergedBy = DedupeType.None;
this.SortedBy = SortedBy.Default;
this.MergedBy = DedupeType.None;
// Reset statistics
_datStats.Reset();
@@ -2801,7 +3024,7 @@ namespace SabreTools.Library.DatFiles
// If the output type isn't set already, get the internal output type
DatFormat = (DatFormat == 0 ? Utilities.GetDatFormatFromFile(filename) : DatFormat);
_sortedBy = SortedBy.CRC; // Setting this because it can reduce issues later
this.SortedBy = SortedBy.CRC; // Setting this because it can reduce issues later
// Now parse the correct type of DAT
try

View File

@@ -10,43 +10,183 @@ namespace SabreTools.Library.DatFiles
{
#region Publicly facing variables
// Data common to most DAT types
#region Data common to most DAT types
/// <summary>
/// External name of the DAT
/// </summary>
public string FileName { get; set; }
/// <summary>
/// Internal name of the DAT
/// </summary>
public string Name { get; set; }
/// <summary>
/// DAT description
/// </summary>
public string Description { get; set; }
/// <summary>
/// Root directory for the files; currently TruRip/EmuARC-exclusive
/// </summary>
public string RootDir { get; set; }
/// <summary>
/// General category of items found in the DAT
/// </summary>
public string Category { get; set; }
/// <summary>
/// Version of the DAT
/// </summary>
public string Version { get; set; }
/// <summary>
/// Creation or modification date
/// </summary>
public string Date { get; set; }
/// <summary>
/// List of authors who contributed to the DAT
/// </summary>
public string Author { get; set; }
/// <summary>
/// Email address for DAT author(s)
/// </summary>
public string Email { get; set; }
/// <summary>
/// Author or distribution homepage name
/// </summary>
public string Homepage { get; set; }
/// <summary>
/// Author or distribution URL
/// </summary>
public string Url { get; set; }
/// <summary>
/// Any comment that does not already fit an existing field
/// </summary>
public string Comment { get; set; }
/// <summary>
/// Header skipper to be used when loading the DAT
/// </summary>
public string Header { get; set; }
public string Type { get; set; } // Generally only used for SuperDAT
/// <summary>
/// Classification of the DAT. Generally only used for SuperDAT
/// </summary>
public string Type { get; set; }
/// <summary>
/// Force a merging style when loaded
/// </summary>
public ForceMerging ForceMerging { get; set; }
/// <summary>
/// Force nodump handling when loaded
/// </summary>
public ForceNodump ForceNodump { get; set; }
/// <summary>
/// Force output packing when loaded
/// </summary>
public ForcePacking ForcePacking { get; set; }
/// <summary>
/// Read or write format
/// </summary>
public DatFormat DatFormat { get; set; }
/// <summary>
/// List of fields in machine and items to exclude from writing
/// </summary>
public bool[] ExcludeFields { get; set; } = new bool[Enum.GetNames(typeof(Field)).Length];
/// <summary>
/// Enable "One Rom, One Region (1G1R)" mode
/// </summary>
public bool OneRom { get; set; }
/// <summary>
/// Keep machines that don't contain any items
/// </summary>
public bool KeepEmptyGames { get; set; }
/// <summary>
/// Remove scene dates from the beginning of machine names
/// </summary>
public bool SceneDateStrip { get; set; }
/// <summary>
/// Deduplicate items using the given method
/// </summary>
public DedupeType DedupeRoms { get; set; }
/// <summary>
/// Strip hash types from items
/// </summary>
public Hash StripHash { get; private set; }
// Data specific to the Miss DAT type
public bool UseRomName { get; set; }
#endregion
#region Write pre-processing
/// <summary>
/// Text to prepend to all outputted lines
/// </summary>
public string Prefix { get; set; }
/// <summary>
/// Text to append to all outputted lines
/// </summary>
public string Postfix { get; set; }
public bool Quotes { get; set; }
public string ReplaceExtension { get; set; }
/// <summary>
/// Add a new extension to all items
/// </summary>
public string AddExtension { get; set; }
/// <summary>
/// Replace all item extensions
/// </summary>
public string ReplaceExtension { get; set; }
/// <summary>
/// Remove all item extensions
/// </summary>
public bool RemoveExtension { get; set; }
public bool GameName { get; set; }
/// <summary>
/// Romba output mode
/// </summary>
public bool Romba { get; set; }
/// <summary>
/// Output the machine name
/// </summary>
public bool GameName { get; set; }
/// <summary>
/// Wrap quotes around the entire line, sans prefix and postfix
/// </summary>
public bool Quotes { get; set; }
#endregion
#region Data specific to the Miss DAT type
/// <summary>
/// Output the item name
/// </summary>
public bool UseRomName { get; set; }
#endregion
#endregion
#region Instance Methods

View File

@@ -1,5 +1,4 @@
using System;
using SabreTools.Library.Data;
using SabreTools.Library.DatItems;
@@ -12,45 +11,114 @@ namespace SabreTools.Library.DatFiles
{
#region Private instance variables
// Object used to lock stats updates
/// <summary>
/// Object used to lock stats updates
/// </summary>
private object _lockObject = new object();
#endregion
#region Publicly facing variables
// Statistics report format
/// <summary>
/// Statistics writing format
/// </summary>
public StatReportFormat ReportFormat { get; set; } = StatReportFormat.None;
// Overall item count
/// <summary>
/// Overall item count
/// </summary>
public long Count { get; set; } = 0;
// Individual DatItem type counts
/// <summary>
/// Number of Archive items
/// </summary>
public long ArchiveCount { get; set; } = 0;
/// <summary>
/// Number of BiosSet items
/// </summary>
public long BiosSetCount { get; set; } = 0;
/// <summary>
/// Number of Disk items
/// </summary>
public long DiskCount { get; set; } = 0;
/// <summary>
/// Number of Release items
/// </summary>
public long ReleaseCount { get; set; } = 0;
/// <summary>
/// Number of Rom items
/// </summary>
public long RomCount { get; set; } = 0;
/// <summary>
/// Number of Sample items
/// </summary>
public long SampleCount { get; set; } = 0;
// Special count only used by statistics output
/// <summary>
/// Number of machines
/// </summary>
/// <remarks>Special count only used by statistics output</remarks>
public long GameCount { get; set; } = 0;
// Total reported size
/// <summary>
/// Total uncompressed size
/// </summary>
public long TotalSize { get; set; } = 0;
// Individual hash counts
/// <summary>
/// Number of items with a CRC hash
/// </summary>
public long CRCCount { get; set; } = 0;
/// <summary>
/// Number of items with an MD5 hash
/// </summary>
public long MD5Count { get; set; } = 0;
/// <summary>
/// Number of items with a SHA-1 hash
/// </summary>
public long SHA1Count { get; set; } = 0;
/// <summary>
/// Number of items with a SHA-256 hash
/// </summary>
public long SHA256Count { get; set; } = 0;
/// <summary>
/// Number of items with a SHA-384 hash
/// </summary>
public long SHA384Count { get; set; } = 0;
/// <summary>
/// Number of items with a SHA-512 hash
/// </summary>
public long SHA512Count { get; set; } = 0;
// Individual status counts
/// <summary>
/// Number of items with the baddump status
/// </summary>
public long BaddumpCount { get; set; } = 0;
/// <summary>
/// Number of items with the good status
/// </summary>
public long GoodCount { get; set; } = 0;
/// <summary>
/// Number of items with the nodump status
/// </summary>
public long NodumpCount { get; set; } = 0;
/// <summary>
/// Number of items with the verified status
/// </summary>
public long VerifiedCount { get; set; } = 0;
#endregion