2016-06-10 01:38:58 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2016-05-16 11:59:33 -07:00
|
|
|
|
|
|
|
|
|
|
namespace SabreTools.Helper
|
2016-04-12 15:03:47 -07:00
|
|
|
|
{
|
2016-08-29 13:05:32 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Intermediate struct for holding and processing hash data
|
|
|
|
|
|
/// </summary>
|
2016-08-29 13:13:00 -07:00
|
|
|
|
public struct HashData : IEquatable<HashData>
|
2016-08-29 13:05:32 -07:00
|
|
|
|
{
|
|
|
|
|
|
public long Size;
|
|
|
|
|
|
public string CRC;
|
|
|
|
|
|
public string MD5;
|
|
|
|
|
|
public string SHA1;
|
|
|
|
|
|
|
2016-08-29 13:13:00 -07:00
|
|
|
|
public bool Equals(HashData other)
|
2016-08-29 13:05:32 -07:00
|
|
|
|
{
|
2016-08-29 13:23:47 -07:00
|
|
|
|
return this.Equals(other, false);
|
2016-08-29 13:05:32 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-08-29 13:13:00 -07:00
|
|
|
|
public bool Equals(HashData other, bool IsDisk)
|
2016-08-29 13:05:32 -07:00
|
|
|
|
{
|
2016-08-29 13:23:47 -07:00
|
|
|
|
bool equals = false;
|
2016-08-29 13:13:00 -07:00
|
|
|
|
|
2016-08-29 13:23:47 -07:00
|
|
|
|
if (!IsDisk &&
|
|
|
|
|
|
((String.IsNullOrEmpty(this.MD5) || String.IsNullOrEmpty(other.MD5)) || this.MD5 == other.MD5) &&
|
|
|
|
|
|
((String.IsNullOrEmpty(this.SHA1) || String.IsNullOrEmpty(other.SHA1)) || this.SHA1 == other.SHA1))
|
|
|
|
|
|
{
|
|
|
|
|
|
equals = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (!IsDisk &&
|
|
|
|
|
|
(this.Size == other.Size) &&
|
|
|
|
|
|
((String.IsNullOrEmpty(this.CRC) || String.IsNullOrEmpty(other.CRC)) || this.CRC == other.CRC) &&
|
|
|
|
|
|
((String.IsNullOrEmpty(this.MD5) || String.IsNullOrEmpty(other.MD5)) || this.MD5 == other.MD5) &&
|
|
|
|
|
|
((String.IsNullOrEmpty(this.SHA1) || String.IsNullOrEmpty(other.SHA1)) || this.SHA1 == other.SHA1))
|
|
|
|
|
|
{
|
|
|
|
|
|
equals = true;
|
2016-08-29 13:13:00 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-08-29 13:23:47 -07:00
|
|
|
|
return equals;
|
2016-08-29 13:05:32 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-04-12 15:03:47 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Intermediate struct for holding and processing rom data
|
|
|
|
|
|
/// </summary>
|
2016-08-29 13:51:45 -07:00
|
|
|
|
public struct File : IComparable, IEquatable<File>
|
2016-04-12 15:03:47 -07:00
|
|
|
|
{
|
2016-08-29 13:42:27 -07:00
|
|
|
|
public Machine Machine;
|
2016-04-12 15:03:47 -07:00
|
|
|
|
public string Name;
|
2016-08-29 13:50:55 -07:00
|
|
|
|
public ItemType Type;
|
2016-08-29 13:05:32 -07:00
|
|
|
|
public HashData HashData;
|
2016-05-10 20:55:51 -07:00
|
|
|
|
public DupeType Dupe;
|
2016-05-18 16:59:34 -07:00
|
|
|
|
public bool Nodump;
|
2016-05-20 10:21:24 -07:00
|
|
|
|
public string Date;
|
2016-06-16 17:27:32 -07:00
|
|
|
|
public SourceMetadata Metadata;
|
2016-06-16 10:42:35 -07:00
|
|
|
|
|
|
|
|
|
|
public int CompareTo(object obj)
|
|
|
|
|
|
{
|
2016-07-12 10:42:29 -07:00
|
|
|
|
Logger temp = new Logger(false, "");
|
|
|
|
|
|
temp.Start();
|
|
|
|
|
|
|
|
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
2016-06-16 10:42:35 -07:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2016-08-29 13:51:45 -07:00
|
|
|
|
File comp = (File)obj;
|
2016-06-16 10:48:12 -07:00
|
|
|
|
|
2016-08-29 13:42:27 -07:00
|
|
|
|
if (this.Machine.Name == comp.Machine.Name)
|
2016-06-16 10:42:35 -07:00
|
|
|
|
{
|
2016-06-16 10:52:31 -07:00
|
|
|
|
if (this.Name == comp.Name)
|
2016-06-16 10:48:12 -07:00
|
|
|
|
{
|
2016-07-12 10:42:29 -07:00
|
|
|
|
ret = (RomTools.IsDuplicate(this, comp, temp) ? 0 : 1);
|
2016-06-16 10:48:12 -07:00
|
|
|
|
}
|
2016-07-12 10:42:29 -07:00
|
|
|
|
ret = String.Compare(this.Name, comp.Name);
|
2016-06-16 10:42:35 -07:00
|
|
|
|
}
|
2016-08-29 13:42:27 -07:00
|
|
|
|
ret = String.Compare(this.Machine.Name, comp.Machine.Name);
|
2016-06-16 10:42:35 -07:00
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
2016-07-12 10:42:29 -07:00
|
|
|
|
ret = 1;
|
2016-06-16 10:42:35 -07:00
|
|
|
|
}
|
2016-07-12 10:42:29 -07:00
|
|
|
|
|
|
|
|
|
|
temp.Close();
|
|
|
|
|
|
return ret;
|
2016-06-16 10:42:35 -07:00
|
|
|
|
}
|
2016-06-16 10:52:31 -07:00
|
|
|
|
|
2016-08-29 13:51:45 -07:00
|
|
|
|
public bool Equals(File other)
|
2016-06-16 10:52:31 -07:00
|
|
|
|
{
|
2016-07-12 10:42:29 -07:00
|
|
|
|
Logger temp = new Logger(false, "");
|
|
|
|
|
|
temp.Start();
|
|
|
|
|
|
bool isdupe = RomTools.IsDuplicate(this, other, temp);
|
|
|
|
|
|
temp.Close();
|
|
|
|
|
|
|
2016-08-29 13:42:27 -07:00
|
|
|
|
return (this.Machine.Name == other.Machine.Name &&
|
2016-06-16 10:52:31 -07:00
|
|
|
|
this.Name == other.Name &&
|
2016-07-12 10:42:29 -07:00
|
|
|
|
isdupe);
|
2016-06-16 10:52:31 -07:00
|
|
|
|
}
|
2016-04-12 15:03:47 -07:00
|
|
|
|
}
|
2016-05-15 14:34:06 -07:00
|
|
|
|
|
2016-06-16 17:17:29 -07:00
|
|
|
|
/// <summary>
|
2016-06-16 17:27:32 -07:00
|
|
|
|
/// Intermediate metadata kept with a RomData object representing source information
|
2016-06-16 17:17:29 -07:00
|
|
|
|
/// </summary>
|
2016-06-16 17:27:32 -07:00
|
|
|
|
public struct SourceMetadata
|
2016-06-16 17:17:29 -07:00
|
|
|
|
{
|
2016-06-16 17:27:32 -07:00
|
|
|
|
public int SystemID;
|
|
|
|
|
|
public string System;
|
|
|
|
|
|
public int SourceID;
|
|
|
|
|
|
public string Source;
|
2016-06-16 17:17:29 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-08-29 13:41:42 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Intermediate struct for holding and processing Rom/Machine data
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public struct Machine
|
|
|
|
|
|
{
|
|
|
|
|
|
public string Name;
|
|
|
|
|
|
public string Comment;
|
|
|
|
|
|
public string Description;
|
|
|
|
|
|
public string Year;
|
|
|
|
|
|
public string Manufacturer;
|
|
|
|
|
|
public string RomOf;
|
|
|
|
|
|
public string CloneOf;
|
|
|
|
|
|
public string SampleOf;
|
|
|
|
|
|
public string SourceFile;
|
|
|
|
|
|
public bool IsBios;
|
|
|
|
|
|
public string Board;
|
|
|
|
|
|
public string RebuildTo;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-05-15 14:34:06 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Intermediate struct for holding DAT information
|
|
|
|
|
|
/// </summary>
|
2016-06-16 18:57:34 -07:00
|
|
|
|
public struct Dat : ICloneable
|
2016-05-15 14:34:06 -07:00
|
|
|
|
{
|
2016-05-16 21:52:49 -07:00
|
|
|
|
// Data common to most DAT types
|
2016-05-25 11:11:54 -07:00
|
|
|
|
public string FileName;
|
2016-05-15 14:34:06 -07:00
|
|
|
|
public string Name;
|
|
|
|
|
|
public string Description;
|
2016-07-25 10:19:20 -07:00
|
|
|
|
public string RootDir;
|
2016-05-15 14:34:06 -07:00
|
|
|
|
public string Category;
|
|
|
|
|
|
public string Version;
|
|
|
|
|
|
public string Date;
|
|
|
|
|
|
public string Author;
|
|
|
|
|
|
public string Email;
|
|
|
|
|
|
public string Homepage;
|
|
|
|
|
|
public string Url;
|
|
|
|
|
|
public string Comment;
|
|
|
|
|
|
public string Header;
|
2016-05-17 11:23:06 -07:00
|
|
|
|
public string Type; // Generally only used for SuperDAT
|
2016-05-15 14:34:06 -07:00
|
|
|
|
public ForceMerging ForceMerging;
|
|
|
|
|
|
public ForceNodump ForceNodump;
|
|
|
|
|
|
public ForcePacking ForcePacking;
|
|
|
|
|
|
public OutputFormat OutputFormat;
|
2016-05-16 11:59:33 -07:00
|
|
|
|
public bool MergeRoms;
|
2016-08-29 13:52:13 -07:00
|
|
|
|
public Dictionary<string, List<File>> Files;
|
2016-05-16 21:52:49 -07:00
|
|
|
|
|
|
|
|
|
|
// Data specific to the Miss DAT type
|
|
|
|
|
|
public bool UseGame;
|
|
|
|
|
|
public string Prefix;
|
|
|
|
|
|
public string Postfix;
|
|
|
|
|
|
public bool Quotes;
|
|
|
|
|
|
public string RepExt;
|
|
|
|
|
|
public string AddExt;
|
|
|
|
|
|
public bool GameName;
|
|
|
|
|
|
public bool Romba;
|
2016-08-23 15:18:37 -07:00
|
|
|
|
public bool? TSV; // true for tab-deliminated output, false for comma-deliminated output
|
2016-05-31 23:34:19 -07:00
|
|
|
|
|
|
|
|
|
|
// Statistical data related to the DAT
|
|
|
|
|
|
public long RomCount;
|
|
|
|
|
|
public long DiskCount;
|
|
|
|
|
|
public long TotalSize;
|
|
|
|
|
|
public long CRCCount;
|
|
|
|
|
|
public long MD5Count;
|
|
|
|
|
|
public long SHA1Count;
|
|
|
|
|
|
public long NodumpCount;
|
2016-06-10 01:38:58 -07:00
|
|
|
|
|
|
|
|
|
|
public object Clone()
|
|
|
|
|
|
{
|
2016-06-16 18:57:34 -07:00
|
|
|
|
return new Dat
|
2016-06-10 01:38:58 -07:00
|
|
|
|
{
|
|
|
|
|
|
FileName = this.FileName,
|
|
|
|
|
|
Name = this.Name,
|
|
|
|
|
|
Description = this.Description,
|
2016-07-25 11:40:00 -07:00
|
|
|
|
RootDir = this.RootDir,
|
2016-06-10 01:38:58 -07:00
|
|
|
|
Category = this.Category,
|
|
|
|
|
|
Version = this.Version,
|
|
|
|
|
|
Date = this.Date,
|
|
|
|
|
|
Author = this.Author,
|
|
|
|
|
|
Email = this.Email,
|
|
|
|
|
|
Homepage = this.Homepage,
|
|
|
|
|
|
Url = this.Url,
|
|
|
|
|
|
Comment = this.Comment,
|
|
|
|
|
|
Header = this.Header,
|
|
|
|
|
|
Type = this.Type,
|
|
|
|
|
|
ForceMerging = this.ForceMerging,
|
|
|
|
|
|
ForceNodump = this.ForceNodump,
|
|
|
|
|
|
ForcePacking = this.ForcePacking,
|
|
|
|
|
|
OutputFormat = this.OutputFormat,
|
|
|
|
|
|
MergeRoms = this.MergeRoms,
|
2016-08-29 13:52:13 -07:00
|
|
|
|
Files = this.Files,
|
2016-06-10 01:38:58 -07:00
|
|
|
|
UseGame = this.UseGame,
|
|
|
|
|
|
Prefix = this.Prefix,
|
|
|
|
|
|
Postfix = this.Postfix,
|
|
|
|
|
|
Quotes = this.Quotes,
|
|
|
|
|
|
RepExt = this.RepExt,
|
|
|
|
|
|
AddExt = this.AddExt,
|
|
|
|
|
|
GameName = this.GameName,
|
|
|
|
|
|
Romba = this.Romba,
|
|
|
|
|
|
TSV = this.TSV,
|
|
|
|
|
|
RomCount = this.RomCount,
|
|
|
|
|
|
DiskCount = this.DiskCount,
|
|
|
|
|
|
TotalSize = this.TotalSize,
|
|
|
|
|
|
CRCCount = this.CRCCount,
|
|
|
|
|
|
MD5Count = this.MD5Count,
|
|
|
|
|
|
SHA1Count = this.SHA1Count,
|
|
|
|
|
|
NodumpCount = this.NodumpCount,
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2016-06-20 14:45:20 -07:00
|
|
|
|
|
|
|
|
|
|
public object CloneHeader()
|
|
|
|
|
|
{
|
|
|
|
|
|
return new Dat
|
|
|
|
|
|
{
|
|
|
|
|
|
FileName = this.FileName,
|
|
|
|
|
|
Name = this.Name,
|
|
|
|
|
|
Description = this.Description,
|
2016-07-25 11:40:00 -07:00
|
|
|
|
RootDir = this.RootDir,
|
2016-06-20 14:45:20 -07:00
|
|
|
|
Category = this.Category,
|
|
|
|
|
|
Version = this.Version,
|
|
|
|
|
|
Date = this.Date,
|
|
|
|
|
|
Author = this.Author,
|
|
|
|
|
|
Email = this.Email,
|
|
|
|
|
|
Homepage = this.Homepage,
|
|
|
|
|
|
Url = this.Url,
|
|
|
|
|
|
Comment = this.Comment,
|
|
|
|
|
|
Header = this.Header,
|
|
|
|
|
|
Type = this.Type,
|
|
|
|
|
|
ForceMerging = this.ForceMerging,
|
|
|
|
|
|
ForceNodump = this.ForceNodump,
|
|
|
|
|
|
ForcePacking = this.ForcePacking,
|
|
|
|
|
|
OutputFormat = this.OutputFormat,
|
|
|
|
|
|
MergeRoms = this.MergeRoms,
|
2016-08-29 13:52:13 -07:00
|
|
|
|
Files = new Dictionary<string, List<File>>(),
|
2016-06-20 14:45:20 -07:00
|
|
|
|
UseGame = this.UseGame,
|
|
|
|
|
|
Prefix = this.Prefix,
|
|
|
|
|
|
Postfix = this.Postfix,
|
|
|
|
|
|
Quotes = this.Quotes,
|
|
|
|
|
|
RepExt = this.RepExt,
|
|
|
|
|
|
AddExt = this.AddExt,
|
|
|
|
|
|
GameName = this.GameName,
|
|
|
|
|
|
Romba = this.Romba,
|
|
|
|
|
|
TSV = this.TSV,
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2016-05-15 14:34:06 -07:00
|
|
|
|
}
|
2016-06-16 19:36:05 -07:00
|
|
|
|
|
2016-06-16 22:17:58 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Intermediate struct for holding header skipper information
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public struct Skipper
|
|
|
|
|
|
{
|
|
|
|
|
|
public string Name;
|
|
|
|
|
|
public string Author;
|
|
|
|
|
|
public string Version;
|
|
|
|
|
|
public List<SkipperRule> Rules;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-06-16 19:36:05 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Intermediate struct for holding header skipper rule information
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public struct SkipperRule
|
|
|
|
|
|
{
|
2016-06-16 22:17:58 -07:00
|
|
|
|
public long? StartOffset; // null is EOF
|
|
|
|
|
|
public long? EndOffset; // null if EOF
|
|
|
|
|
|
public HeaderSkipOperation Operation;
|
|
|
|
|
|
public List<SkipperTest> Tests;
|
2016-06-16 19:36:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Intermediate struct for holding header test information
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public struct SkipperTest
|
|
|
|
|
|
{
|
2016-06-16 22:17:58 -07:00
|
|
|
|
public HeaderSkipTest Type;
|
|
|
|
|
|
public long? Offset; // null is EOF
|
|
|
|
|
|
public byte[] Value;
|
|
|
|
|
|
public bool Result;
|
|
|
|
|
|
public byte[] Mask;
|
|
|
|
|
|
public long? Size; // null is PO2, "power of 2" filesize
|
|
|
|
|
|
public HeaderSkipTestFileOperator Operator;
|
2016-06-16 19:36:05 -07:00
|
|
|
|
}
|
2016-04-12 15:03:47 -07:00
|
|
|
|
}
|