using System; using System.Collections.Generic; namespace SabreTools.Helper { /// /// Intermediate struct for holding and processing hash data /// public struct HashData : IEquatable { public long Size; public string CRC; public string MD5; public string SHA1; public bool Equals(HashData other) { return this.Equals(other, false); } public bool Equals(HashData other, bool IsDisk) { bool equals = false; 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; } return equals; } } /// /// Intermediate struct for holding and processing rom data /// public struct Rom : IComparable, IEquatable { public Machine Machine; public string Name; public string Type; public HashData HashData; public DupeType Dupe; public bool Nodump; public string Date; public SourceMetadata Metadata; public int CompareTo(object obj) { Logger temp = new Logger(false, ""); temp.Start(); int ret = 0; try { Rom comp = (Rom)obj; if (this.Machine.Name == comp.Machine.Name) { if (this.Name == comp.Name) { ret = (RomTools.IsDuplicate(this, comp, temp) ? 0 : 1); } ret = String.Compare(this.Name, comp.Name); } ret = String.Compare(this.Machine.Name, comp.Machine.Name); } catch { ret = 1; } temp.Close(); return ret; } public bool Equals(Rom other) { Logger temp = new Logger(false, ""); temp.Start(); bool isdupe = RomTools.IsDuplicate(this, other, temp); temp.Close(); return (this.Machine.Name == other.Machine.Name && this.Name == other.Name && isdupe); } } /// /// Intermediate metadata kept with a RomData object representing source information /// public struct SourceMetadata { public int SystemID; public string System; public int SourceID; public string Source; } /// /// Intermediate struct for holding and processing Rom/Machine data /// 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; } /// /// Intermediate struct for holding DAT information /// public struct Dat : ICloneable { // Data common to most DAT types public string FileName; public string Name; public string Description; public string RootDir; 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; public string Type; // Generally only used for SuperDAT public ForceMerging ForceMerging; public ForceNodump ForceNodump; public ForcePacking ForcePacking; public OutputFormat OutputFormat; public bool MergeRoms; public Dictionary> Roms; // 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; public bool? TSV; // true for tab-deliminated output, false for comma-deliminated output // 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; public object Clone() { return new Dat { FileName = this.FileName, Name = this.Name, Description = this.Description, RootDir = this.RootDir, 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, Roms = this.Roms, 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, }; } public object CloneHeader() { return new Dat { FileName = this.FileName, Name = this.Name, Description = this.Description, RootDir = this.RootDir, 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, Roms = new Dictionary>(), 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, }; } } /// /// Intermediate struct for holding header skipper information /// public struct Skipper { public string Name; public string Author; public string Version; public List Rules; } /// /// Intermediate struct for holding header skipper rule information /// public struct SkipperRule { public long? StartOffset; // null is EOF public long? EndOffset; // null if EOF public HeaderSkipOperation Operation; public List Tests; } /// /// Intermediate struct for holding header test information /// public struct SkipperTest { 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; } }