From 09e16fcc4c8a25b985beba702852ed9c4fa47488 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Mon, 9 Oct 2017 20:25:46 -0700 Subject: [PATCH] [DatFiles/] Make all DatFile types actually inherit from DatFile --- SabreTools.Library/DatFiles/AttractMode.cs | 25 +- SabreTools.Library/DatFiles/ClrMamePro.cs | 126 +++++---- SabreTools.Library/DatFiles/DatFile.cs | 70 ++--- SabreTools.Library/DatFiles/DosCenter.cs | 43 ++- SabreTools.Library/DatFiles/Hashfile.cs | 43 ++- SabreTools.Library/DatFiles/Listroms.cs | 32 +-- SabreTools.Library/DatFiles/Logiqx.cs | 253 +++++++++--------- SabreTools.Library/DatFiles/Missfile.cs | 45 ++-- SabreTools.Library/DatFiles/OfflineList.cs | 39 ++- SabreTools.Library/DatFiles/RomCenter.cs | 59 ++-- SabreTools.Library/DatFiles/SabreDat.cs | 73 +++-- SabreTools.Library/DatFiles/SeparatedValue.cs | 57 ++-- SabreTools.Library/DatFiles/SoftwareList.cs | 54 ++-- 13 files changed, 423 insertions(+), 496 deletions(-) diff --git a/SabreTools.Library/DatFiles/AttractMode.cs b/SabreTools.Library/DatFiles/AttractMode.cs index 4a609dec..ea3df03f 100644 --- a/SabreTools.Library/DatFiles/AttractMode.cs +++ b/SabreTools.Library/DatFiles/AttractMode.cs @@ -23,21 +23,18 @@ namespace SabreTools.Library.DatFiles /// /// Represents parsing and writing of an AttractMode DAT /// - public class AttractMode + public class AttractMode : DatFile { /// /// Parse an AttractMode DAT and return all found games within /// - /// DatFile to populate with the read information /// Name of the file to be parsed /// System ID for the DAT /// Source ID for the DAT /// True if full pathnames are to be kept, false otherwise (default) /// True if game names are sanitized, false otherwise (default) /// True if we should remove non-ASCII characters from output, false otherwise (default) - public static void Parse( - DatFile datFile, - + public void Parse( // Standard Dat parsing string filename, int sysid, @@ -98,7 +95,7 @@ namespace SabreTools.Library.DatFiles }; // Now process and add the rom - datFile.ParseAddHelper(rom, clean, remUnicode); + ParseAddHelper(rom, clean, remUnicode); } sr.Dispose(); @@ -107,10 +104,9 @@ namespace SabreTools.Library.DatFiles /// /// Create and open an output file for writing direct from a dictionary /// - /// DatFile to write out from /// Name of the file to write to /// True if the DAT was written correctly, false otherwise - public static bool WriteToFile(DatFile datFile, string outfile) + public bool WriteToFile(string outfile) { try { @@ -133,12 +129,12 @@ namespace SabreTools.Library.DatFiles string lastgame = null; // Get a properly sorted set of keys - List keys = datFile.Keys.ToList(); + List keys = Keys.ToList(); keys.Sort(new NaturalComparer()); foreach (string key in keys) { - List roms = datFile[key]; + List roms = this[key]; // Resolve the names in the block roms = DatItem.ResolveNames(roms); @@ -157,7 +153,7 @@ namespace SabreTools.Library.DatFiles // If we have a new game, output the beginning of the new item if (lastgame == null || lastgame.ToLowerInvariant() != item.MachineName.ToLowerInvariant()) { - WriteStartGame(datFile, sw, item); + WriteStartGame(sw, item); } // If we have a "null" game (created by DATFromDir or something similar), log it to file @@ -200,7 +196,7 @@ namespace SabreTools.Library.DatFiles /// /// StreamWriter to output to /// True if the data was written, false on error - private static bool WriteHeader(StreamWriter sw) + private bool WriteHeader(StreamWriter sw) { try { @@ -222,11 +218,10 @@ namespace SabreTools.Library.DatFiles /// /// Write out Game start using the supplied StreamWriter /// - /// DatFile to write out from /// StreamWriter to output to /// RomData object to be output /// True if the data was written, false on error - private static bool WriteStartGame(DatFile datFile, StreamWriter sw, DatItem rom) + private bool WriteStartGame(StreamWriter sw, DatItem rom) { try { @@ -238,7 +233,7 @@ namespace SabreTools.Library.DatFiles string state = rom.MachineName + ";" + rom.MachineDescription + ";" - + datFile.FileName + ";" + + FileName + ";" + rom.CloneOf + ";" + rom.Year + ";" + rom.Manufacturer + ";" diff --git a/SabreTools.Library/DatFiles/ClrMamePro.cs b/SabreTools.Library/DatFiles/ClrMamePro.cs index f26752d7..4bed3af9 100644 --- a/SabreTools.Library/DatFiles/ClrMamePro.cs +++ b/SabreTools.Library/DatFiles/ClrMamePro.cs @@ -24,21 +24,18 @@ namespace SabreTools.Library.DatFiles /// /// Represents parsing and writing of a ClrMamePro DAT /// - public class ClrMamePro + public class ClrMamePro : DatFile { /// /// Parse a ClrMamePro DAT and return all found games and roms within /// - /// DatFile to populate with the read information /// Name of the file to be parsed /// System ID for the DAT /// Source ID for the DAT /// True if full pathnames are to be kept, false otherwise (default) /// True if game names are sanitized, false otherwise (default) /// True if we should remove non-ASCII characters from output, false otherwise (default) - public static void Parse( - DatFile datFile, - + public void Parse( // Standard Dat parsing string filename, int sysid, @@ -148,7 +145,7 @@ namespace SabreTools.Library.DatFiles item.Name = line; // Now process and add the sample - datFile.ParseAddHelper(item, clean, remUnicode); + ParseAddHelper(item, clean, remUnicode); continue; } @@ -232,7 +229,7 @@ namespace SabreTools.Library.DatFiles } // Now process and add the rom - datFile.ParseAddHelper(item, clean, remUnicode); + ParseAddHelper(item, clean, remUnicode); continue; } @@ -444,7 +441,7 @@ namespace SabreTools.Library.DatFiles } // Now process and add the rom - datFile.ParseAddHelper(item, clean, remUnicode); + ParseAddHelper(item, clean, remUnicode); } // If the line is anything but a rom or disk and we're in a block @@ -486,11 +483,11 @@ namespace SabreTools.Library.DatFiles if (line.Trim().StartsWith("Name:")) { - datFile.Name = (String.IsNullOrEmpty(datFile.Name) ? line.Substring(6) : datFile.Name); + Name = (String.IsNullOrEmpty(Name) ? line.Substring(6) : Name); superdat = superdat || itemval.Contains(" - SuperDAT"); if (keep && superdat) { - datFile.Type = (String.IsNullOrEmpty(datFile.Type) ? "SuperDAT" : datFile.Type); + Type = (String.IsNullOrEmpty(Type) ? "SuperDAT" : Type); } continue; } @@ -499,103 +496,103 @@ namespace SabreTools.Library.DatFiles { case "name": case "Name:": - datFile.Name = (String.IsNullOrEmpty(datFile.Name) ? itemval : datFile.Name); + Name = (String.IsNullOrEmpty(Name) ? itemval : Name); superdat = superdat || itemval.Contains(" - SuperDAT"); if (keep && superdat) { - datFile.Type = (String.IsNullOrEmpty(datFile.Type) ? "SuperDAT" : datFile.Type); + Type = (String.IsNullOrEmpty(Type) ? "SuperDAT" : Type); } break; case "description": case "Description:": - datFile.Description = (String.IsNullOrEmpty(datFile.Description) ? itemval : datFile.Description); + Description = (String.IsNullOrEmpty(Description) ? itemval : Description); break; case "rootdir": - datFile.RootDir = (String.IsNullOrEmpty(datFile.RootDir) ? itemval : datFile.RootDir); + RootDir = (String.IsNullOrEmpty(RootDir) ? itemval : RootDir); break; case "category": - datFile.Category = (String.IsNullOrEmpty(datFile.Category) ? itemval : datFile.Category); + Category = (String.IsNullOrEmpty(Category) ? itemval : Category); break; case "version": case "Version:": - datFile.Version = (String.IsNullOrEmpty(datFile.Version) ? itemval : datFile.Version); + Version = (String.IsNullOrEmpty(Version) ? itemval : Version); break; case "date": case "Date:": - datFile.Date = (String.IsNullOrEmpty(datFile.Date) ? itemval : datFile.Date); + Date = (String.IsNullOrEmpty(Date) ? itemval : Date); break; case "author": case "Author:": - datFile.Author = (String.IsNullOrEmpty(datFile.Author) ? itemval : datFile.Author); + Author = (String.IsNullOrEmpty(Author) ? itemval : Author); break; case "email": - datFile.Email = (String.IsNullOrEmpty(datFile.Email) ? itemval : datFile.Email); + Email = (String.IsNullOrEmpty(Email) ? itemval : Email); break; case "homepage": case "Homepage:": - datFile.Homepage = (String.IsNullOrEmpty(datFile.Homepage) ? itemval : datFile.Homepage); + Homepage = (String.IsNullOrEmpty(Homepage) ? itemval : Homepage); break; case "url": - datFile.Url = (String.IsNullOrEmpty(datFile.Url) ? itemval : datFile.Url); + Url = (String.IsNullOrEmpty(Url) ? itemval : Url); break; case "comment": case "Comment:": - datFile.Comment = (String.IsNullOrEmpty(datFile.Comment) ? itemval : datFile.Comment); + Comment = (String.IsNullOrEmpty(Comment) ? itemval : Comment); break; case "header": - datFile.Header = (String.IsNullOrEmpty(datFile.Header) ? itemval : datFile.Header); + Header = (String.IsNullOrEmpty(Header) ? itemval : Header); break; case "type": - datFile.Type = (String.IsNullOrEmpty(datFile.Type) ? itemval : datFile.Type); + Type = (String.IsNullOrEmpty(Type) ? itemval : Type); superdat = superdat || itemval.Contains("SuperDAT"); break; case "forcemerging": - if (datFile.ForceMerging == ForceMerging.None) + if (ForceMerging == ForceMerging.None) { switch (itemval) { case "none": - datFile.ForceMerging = ForceMerging.None; + ForceMerging = ForceMerging.None; break; case "split": - datFile.ForceMerging = ForceMerging.Split; + ForceMerging = ForceMerging.Split; break; case "merged": - datFile.ForceMerging = ForceMerging.Merged; + ForceMerging = ForceMerging.Merged; break; case "nonmerged": - datFile.ForceMerging = ForceMerging.NonMerged; + ForceMerging = ForceMerging.NonMerged; break; case "full": - datFile.ForceMerging = ForceMerging.Full; + ForceMerging = ForceMerging.Full; break; } } break; case "forcezipping": - if (datFile.ForcePacking == ForcePacking.None) + if (ForcePacking == ForcePacking.None) { switch (itemval) { case "yes": - datFile.ForcePacking = ForcePacking.Zip; + ForcePacking = ForcePacking.Zip; break; case "no": - datFile.ForcePacking = ForcePacking.Unzip; + ForcePacking = ForcePacking.Unzip; break; } } break; case "forcepacking": - if (datFile.ForcePacking == ForcePacking.None) + if (ForcePacking == ForcePacking.None) { switch (itemval) { case "zip": - datFile.ForcePacking = ForcePacking.Zip; + ForcePacking = ForcePacking.Zip; break; case "unzip": - datFile.ForcePacking = ForcePacking.Unzip; + ForcePacking = ForcePacking.Unzip; break; } } @@ -619,11 +616,10 @@ namespace SabreTools.Library.DatFiles /// /// Create and open an output file for writing direct from a dictionary /// - /// DatFile to write out from /// Name of the file to write to /// True if blank roms should be skipped on output, false otherwise (default) /// True if the DAT was written correctly, false otherwise - public static bool WriteToFile(DatFile datFile, string outfile, bool ignoreblanks = false) + public bool WriteToFile(string outfile, bool ignoreblanks = false) { try { @@ -640,18 +636,18 @@ namespace SabreTools.Library.DatFiles StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(true)); // Write out the header - WriteHeader(datFile, sw); + WriteHeader(sw); // Write out each of the machines and roms string lastgame = null; // Get a properly sorted set of keys - List keys = datFile.Keys.ToList(); + List keys = Keys.ToList(); keys.Sort(new NaturalComparer()); foreach (string key in keys) { - List roms = datFile[key]; + List roms = this[key]; // Resolve the names in the block roms = DatItem.ResolveNames(roms); @@ -676,7 +672,7 @@ namespace SabreTools.Library.DatFiles // If we have a new game, output the beginning of the new item if (lastgame == null || lastgame.ToLowerInvariant() != rom.MachineName.ToLowerInvariant()) { - WriteStartGame(datFile, sw, rom); + WriteStartGame(sw, rom); } // If we have a "null" game (created by DATFromDir or something similar), log it to file @@ -724,30 +720,29 @@ namespace SabreTools.Library.DatFiles /// /// Write out DAT header using the supplied StreamWriter /// - /// DatFile to write out from /// StreamWriter to output to /// True if the data was written, false on error - private static bool WriteHeader(DatFile datFile, StreamWriter sw) + private bool WriteHeader(StreamWriter sw) { try { string header = "clrmamepro (\n" + - "\tname \"" + datFile.Name + "\"\n" + - "\tdescription \"" + datFile.Description + "\"\n" + - (!String.IsNullOrEmpty(datFile.Category) ? "\tcategory \"" + datFile.Category + "\"\n" : "") + - "\tversion \"" + datFile.Version + "\"\n" + - (!String.IsNullOrEmpty(datFile.Date) ? "\tdate \"" + datFile.Date + "\"\n" : "") + - "\tauthor \"" + datFile.Author + "\"\n" + - (!String.IsNullOrEmpty(datFile.Email) ? "\temail \"" + datFile.Email + "\"\n" : "") + - (!String.IsNullOrEmpty(datFile.Homepage) ? "\thomepage \"" + datFile.Homepage + "\"\n" : "") + - (!String.IsNullOrEmpty(datFile.Url) ? "\turl \"" + datFile.Url + "\"\n" : "") + - (!String.IsNullOrEmpty(datFile.Comment) ? "\tcomment \"" + datFile.Comment + "\"\n" : "") + - (datFile.ForcePacking == ForcePacking.Unzip ? "\tforcezipping no\n" : "") + - (datFile.ForcePacking == ForcePacking.Zip ? "\tforcezipping yes\n" : "") + - (datFile.ForceMerging == ForceMerging.Full ? "\tforcemerging full\n" : "") + - (datFile.ForceMerging == ForceMerging.Split ? "\tforcemerging split\n" : "") + - (datFile.ForceMerging == ForceMerging.Merged ? "\tforcemerging merged\n" : "") + - (datFile.ForceMerging == ForceMerging.NonMerged ? "\tforcemerging nonmerged\n" : "") + + "\tname \"" + Name + "\"\n" + + "\tdescription \"" + Description + "\"\n" + + (!String.IsNullOrEmpty(Category) ? "\tcategory \"" + Category + "\"\n" : "") + + "\tversion \"" + Version + "\"\n" + + (!String.IsNullOrEmpty(Date) ? "\tdate \"" + Date + "\"\n" : "") + + "\tauthor \"" + Author + "\"\n" + + (!String.IsNullOrEmpty(Email) ? "\temail \"" + Email + "\"\n" : "") + + (!String.IsNullOrEmpty(Homepage) ? "\thomepage \"" + Homepage + "\"\n" : "") + + (!String.IsNullOrEmpty(Url) ? "\turl \"" + Url + "\"\n" : "") + + (!String.IsNullOrEmpty(Comment) ? "\tcomment \"" + Comment + "\"\n" : "") + + (ForcePacking == ForcePacking.Unzip ? "\tforcezipping no\n" : "") + + (ForcePacking == ForcePacking.Zip ? "\tforcezipping yes\n" : "") + + (ForceMerging == ForceMerging.Full ? "\tforcemerging full\n" : "") + + (ForceMerging == ForceMerging.Split ? "\tforcemerging split\n" : "") + + (ForceMerging == ForceMerging.Merged ? "\tforcemerging merged\n" : "") + + (ForceMerging == ForceMerging.NonMerged ? "\tforcemerging nonmerged\n" : "") + ")\n"; // Write the header out @@ -766,11 +761,10 @@ namespace SabreTools.Library.DatFiles /// /// Write out Game start using the supplied StreamWriter /// - /// DatFile to write out from /// StreamWriter to output to /// RomData object to be output /// True if the data was written, false on error - private static bool WriteStartGame(DatFile datFile, StreamWriter sw, DatItem rom) + private bool WriteStartGame(StreamWriter sw, DatItem rom) { try { @@ -781,7 +775,7 @@ namespace SabreTools.Library.DatFiles } string state = "game (\n\tname \"" + rom.MachineName + "\"\n" + - (datFile.ExcludeOf ? "" : + (ExcludeOf ? "" : (String.IsNullOrEmpty(rom.RomOf) ? "" : "\tromof \"" + rom.RomOf + "\"\n") + (String.IsNullOrEmpty(rom.CloneOf) ? "" : "\tcloneof \"" + rom.CloneOf + "\"\n") + (String.IsNullOrEmpty(rom.SampleOf) ? "" : "\tsampleof \"" + rom.SampleOf + "\"\n") @@ -808,7 +802,7 @@ namespace SabreTools.Library.DatFiles /// StreamWriter to output to /// RomData object to be output /// True if the data was written, false on error - private static bool WriteEndGame(StreamWriter sw, DatItem rom) + private bool WriteEndGame(StreamWriter sw, DatItem rom) { try { @@ -834,7 +828,7 @@ namespace SabreTools.Library.DatFiles /// RomData object to be output /// True if blank roms should be skipped on output, false otherwise (default) /// True if the data was written, false on error - private static bool WriteRomData(StreamWriter sw, DatItem rom, bool ignoreblanks = false) + private bool WriteRomData(StreamWriter sw, DatItem rom, bool ignoreblanks = false) { // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip if (ignoreblanks @@ -917,7 +911,7 @@ namespace SabreTools.Library.DatFiles /// /// StreamWriter to output to /// True if the data was written, false on error - private static bool WriteFooter(StreamWriter sw) + private bool WriteFooter(StreamWriter sw) { try { diff --git a/SabreTools.Library/DatFiles/DatFile.cs b/SabreTools.Library/DatFiles/DatFile.cs index 0960070b..4d035d4f 100644 --- a/SabreTools.Library/DatFiles/DatFile.cs +++ b/SabreTools.Library/DatFiles/DatFile.cs @@ -1529,55 +1529,55 @@ namespace SabreTools.Library.DatFiles switch (FileTools.GetDatFormat(filename)) { case DatFormat.AttractMode: - AttractMode.Parse(this, filename, sysid, srcid, keep, clean, remUnicode); + (this as AttractMode).Parse(filename, sysid, srcid, keep, clean, remUnicode); break; case DatFormat.ClrMamePro: - ClrMamePro.Parse(this, filename, sysid, srcid, keep, clean, remUnicode); + (this as ClrMamePro).Parse(filename, sysid, srcid, keep, clean, remUnicode); break; case DatFormat.CSV: - SeparatedValue.Parse(this, filename, sysid, srcid, ',', keep, clean, remUnicode); + (this as SeparatedValue).Parse(filename, sysid, srcid, ',', keep, clean, remUnicode); break; case DatFormat.DOSCenter: - DosCenter.Parse(this, filename, sysid, srcid, keep, clean, remUnicode); + (this as DosCenter).Parse(filename, sysid, srcid, keep, clean, remUnicode); break; case DatFormat.Listroms: - Listroms.Parse(this, filename, sysid, srcid, keep, clean, remUnicode); + (this as Listroms).Parse(filename, sysid, srcid, keep, clean, remUnicode); break; case DatFormat.Logiqx: - Logiqx.Parse(this, filename, sysid, srcid, keep, clean, remUnicode); + (this as Logiqx).Parse(filename, sysid, srcid, keep, clean, remUnicode); break; case DatFormat.OfflineList: - OfflineList.Parse(this, filename, sysid, srcid, keep, clean, remUnicode); + (this as OfflineList).Parse(filename, sysid, srcid, keep, clean, remUnicode); break; case DatFormat.RedumpMD5: - Hashfile.Parse(this, filename, sysid, srcid, Hash.MD5, clean, remUnicode); + (this as Hashfile).Parse(filename, sysid, srcid, Hash.MD5, clean, remUnicode); break; case DatFormat.RedumpSFV: - Hashfile.Parse(this, filename, sysid, srcid, Hash.CRC, clean, remUnicode); + (this as Hashfile).Parse(filename, sysid, srcid, Hash.CRC, clean, remUnicode); break; case DatFormat.RedumpSHA1: - Hashfile.Parse(this, filename, sysid, srcid, Hash.SHA1, clean, remUnicode); + (this as Hashfile).Parse(filename, sysid, srcid, Hash.SHA1, clean, remUnicode); break; case DatFormat.RedumpSHA256: - Hashfile.Parse(this, filename, sysid, srcid, Hash.SHA256, clean, remUnicode); + (this as Hashfile).Parse(filename, sysid, srcid, Hash.SHA256, clean, remUnicode); break; case DatFormat.RedumpSHA384: - Hashfile.Parse(this, filename, sysid, srcid, Hash.SHA384, clean, remUnicode); + (this as Hashfile).Parse(filename, sysid, srcid, Hash.SHA384, clean, remUnicode); break; case DatFormat.RedumpSHA512: - Hashfile.Parse(this, filename, sysid, srcid, Hash.SHA512, clean, remUnicode); + (this as Hashfile).Parse(filename, sysid, srcid, Hash.SHA512, clean, remUnicode); break; case DatFormat.RomCenter: - RomCenter.Parse(this, filename, sysid, srcid, clean, remUnicode); + (this as RomCenter).Parse(filename, sysid, srcid, clean, remUnicode); break; case DatFormat.SabreDat: - SabreDat.Parse(this, filename, sysid, srcid, keep, clean, remUnicode); + (this as SabreDat).Parse(filename, sysid, srcid, keep, clean, remUnicode); break; case DatFormat.SoftwareList: - SoftwareList.Parse(this, filename, sysid, srcid, keep, clean, remUnicode); + (this as SoftwareList).Parse(filename, sysid, srcid, keep, clean, remUnicode); break; case DatFormat.TSV: - SeparatedValue.Parse(this, filename, sysid, srcid, '\t', keep, clean, remUnicode); + (this as SeparatedValue).Parse(filename, sysid, srcid, '\t', keep, clean, remUnicode); break; default: return; @@ -1918,58 +1918,58 @@ namespace SabreTools.Library.DatFiles switch (datFormat) { case DatFormat.AttractMode: - AttractMode.WriteToFile(this, outfile); + (this as AttractMode).WriteToFile(outfile); break; case DatFormat.ClrMamePro: - ClrMamePro.WriteToFile(this, outfile, ignoreblanks); + (this as ClrMamePro).WriteToFile(outfile, ignoreblanks); break; case DatFormat.CSV: - SeparatedValue.WriteToFile(this, outfile, ',', ignoreblanks); + (this as SeparatedValue).WriteToFile(outfile, ',', ignoreblanks); break; case DatFormat.DOSCenter: - DosCenter.WriteToFile(this, outfile, ignoreblanks); + (this as DosCenter).WriteToFile(outfile, ignoreblanks); break; case DatFormat.Listroms: - Listroms.WriteToFile(this, outfile, ignoreblanks); + (this as Listroms).WriteToFile(outfile, ignoreblanks); break; case DatFormat.Logiqx: - Logiqx.WriteToFile(this, outfile, ignoreblanks); + (this as Logiqx).WriteToFile(outfile, ignoreblanks); break; case DatFormat.MissFile: - Missfile.WriteToFile(this, outfile, ignoreblanks); + (this as Missfile).WriteToFile(outfile, ignoreblanks); break; case DatFormat.OfflineList: - OfflineList.WriteToFile(this, outfile, ignoreblanks); + (this as OfflineList).WriteToFile(outfile, ignoreblanks); break; case DatFormat.RedumpMD5: - Hashfile.WriteToFile(this, outfile, Hash.MD5, ignoreblanks); + (this as Hashfile).WriteToFile(outfile, Hash.MD5, ignoreblanks); break; case DatFormat.RedumpSFV: - Hashfile.WriteToFile(this, outfile, Hash.CRC, ignoreblanks); + (this as Hashfile).WriteToFile(outfile, Hash.CRC, ignoreblanks); break; case DatFormat.RedumpSHA1: - Hashfile.WriteToFile(this, outfile, Hash.SHA1, ignoreblanks); + (this as Hashfile).WriteToFile(outfile, Hash.SHA1, ignoreblanks); break; case DatFormat.RedumpSHA256: - Hashfile.WriteToFile(this, outfile, Hash.SHA256, ignoreblanks); + (this as Hashfile).WriteToFile(outfile, Hash.SHA256, ignoreblanks); break; case DatFormat.RedumpSHA384: - Hashfile.WriteToFile(this, outfile, Hash.SHA384, ignoreblanks); + (this as Hashfile).WriteToFile(outfile, Hash.SHA384, ignoreblanks); break; case DatFormat.RedumpSHA512: - Hashfile.WriteToFile(this, outfile, Hash.SHA512, ignoreblanks); + (this as Hashfile).WriteToFile(outfile, Hash.SHA512, ignoreblanks); break; case DatFormat.RomCenter: - RomCenter.WriteToFile(this, outfile, ignoreblanks); + (this as RomCenter).WriteToFile(outfile, ignoreblanks); break; case DatFormat.SabreDat: - SabreDat.WriteToFile(this, outfile, ignoreblanks); + (this as SabreDat).WriteToFile(outfile, ignoreblanks); break; case DatFormat.SoftwareList: - SoftwareList.WriteToFile(this, outfile, ignoreblanks); + (this as SoftwareList).WriteToFile(outfile, ignoreblanks); break; case DatFormat.TSV: - SeparatedValue.WriteToFile(this, outfile, '\t', ignoreblanks); + (this as SeparatedValue).WriteToFile(outfile, '\t', ignoreblanks); break; } }); diff --git a/SabreTools.Library/DatFiles/DosCenter.cs b/SabreTools.Library/DatFiles/DosCenter.cs index 5cd5018a..d1e8fe47 100644 --- a/SabreTools.Library/DatFiles/DosCenter.cs +++ b/SabreTools.Library/DatFiles/DosCenter.cs @@ -22,21 +22,18 @@ namespace SabreTools.Library.DatFiles /// /// Represents parsing and writing of a DosCenter DAT /// - public class DosCenter + public class DosCenter : DatFile { /// /// Parse a DosCenter DAT and return all found games and roms within /// - /// DatFile to populate with the read information /// Name of the file to be parsed /// System ID for the DAT /// Source ID for the DAT /// True if full pathnames are to be kept, false otherwise (default) /// True if game names are sanitized, false otherwise (default) /// True if we should remove non-ASCII characters from output, false otherwise (default) - public static void Parse( - DatFile datFile, - + public void Parse( // Standard Dat parsing string filename, int sysid, @@ -48,18 +45,17 @@ namespace SabreTools.Library.DatFiles bool remUnicode) { // ClrMamePro and DosCenter parsing are identical so it just calls one implementation - ClrMamePro.Parse(datFile, filename, sysid, srcid, keep, clean, remUnicode); + (this as DatFile as ClrMamePro).Parse(filename, sysid, srcid, keep, clean, remUnicode); } /// /// Create and open an output file for writing direct from a dictionary /// - /// DatFile to write out from /// Name of the file to write to /// True if blank roms should be skipped on output, false otherwise (default) /// True if the DAT was written correctly, false otherwise - public static bool WriteToFile(DatFile datFile, string outfile, bool ignoreblanks = false) + public bool WriteToFile(string outfile, bool ignoreblanks = false) { try { @@ -76,18 +72,18 @@ namespace SabreTools.Library.DatFiles StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(true)); // Write out the header - WriteHeader(datFile, sw); + WriteHeader(sw); // Write out each of the machines and roms string lastgame = null; // Get a properly sorted set of keys - List keys = datFile.Keys.ToList(); + List keys = Keys.ToList(); keys.Sort(new NaturalComparer()); foreach (string key in keys) { - List roms = datFile[key]; + List roms = this[key]; // Resolve the names in the block roms = DatItem.ResolveNames(roms); @@ -161,21 +157,20 @@ namespace SabreTools.Library.DatFiles /// /// Write out DAT header using the supplied StreamWriter /// - /// DatFile to write out from /// StreamWriter to output to /// True if the data was written, false on error - private static bool WriteHeader(DatFile datFile, StreamWriter sw) + private bool WriteHeader(StreamWriter sw) { try { string header = "DOSCenter (\n" + - "\tName: " + datFile.Name + "\n" + - "\tDescription: " + datFile.Description + "\n" + - "\tVersion: " + datFile.Version + "\n" + - "\tDate: " + datFile.Date + "\n" + - "\tAuthor: " + datFile.Author + "\n" + - "\tHomepage: " + datFile.Homepage + "\n" + - "\tComment: " + datFile.Comment + "\n" + + "\tName: " + Name + "\n" + + "\tDescription: " + Description + "\n" + + "\tVersion: " + Version + "\n" + + "\tDate: " + Date + "\n" + + "\tAuthor: " + Author + "\n" + + "\tHomepage: " + Homepage + "\n" + + "\tComment: " + Comment + "\n" + ")\n"; // Write the header out @@ -197,7 +192,7 @@ namespace SabreTools.Library.DatFiles /// StreamWriter to output to /// RomData object to be output /// True if the data was written, false on error - private static bool WriteStartGame(StreamWriter sw, DatItem rom) + private bool WriteStartGame(StreamWriter sw, DatItem rom) { try { @@ -227,7 +222,7 @@ namespace SabreTools.Library.DatFiles /// StreamWriter to output to /// RomData object to be output /// True if the data was written, false on error - private static bool WriteEndGame(StreamWriter sw, DatItem rom) + private bool WriteEndGame(StreamWriter sw, DatItem rom) { try { @@ -252,7 +247,7 @@ namespace SabreTools.Library.DatFiles /// RomData object to be output /// True if blank roms should be skipped on output, false otherwise (default) /// True if the data was written, false on error - private static bool WriteRomData(StreamWriter sw, DatItem rom, bool ignoreblanks = false) + private bool WriteRomData(StreamWriter sw, DatItem rom, bool ignoreblanks = false) { // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip if (ignoreblanks @@ -300,7 +295,7 @@ namespace SabreTools.Library.DatFiles /// /// StreamWriter to output to /// True if the data was written, false on error - private static bool WriteFooter(StreamWriter sw) + private bool WriteFooter(StreamWriter sw) { try { diff --git a/SabreTools.Library/DatFiles/Hashfile.cs b/SabreTools.Library/DatFiles/Hashfile.cs index 5f471f07..f2637f00 100644 --- a/SabreTools.Library/DatFiles/Hashfile.cs +++ b/SabreTools.Library/DatFiles/Hashfile.cs @@ -23,21 +23,18 @@ namespace SabreTools.Library.DatFiles /// /// Represents parsing and writing of a hashfile such as an SFV, MD5, or SHA-1 file /// - public class Hashfile + public class Hashfile : DatFile { /// /// Parse a hashfile or SFV and return all found games and roms within /// - /// DatFile to populate with the read information /// Name of the file to be parsed /// System ID for the DAT /// Source ID for the DAT /// Hash type that should be assumed /// True if game names are sanitized, false otherwise (default) /// True if we should remove non-ASCII characters from output, false otherwise (default) - public static void Parse( - DatFile datFile, - + public void Parse( // Standard Dat parsing string filename, int sysid, @@ -95,7 +92,7 @@ namespace SabreTools.Library.DatFiles }; // Now process and add the rom - datFile.ParseAddHelper(rom, clean, remUnicode); + ParseAddHelper(rom, clean, remUnicode); } sr.Dispose(); @@ -104,12 +101,11 @@ namespace SabreTools.Library.DatFiles /// /// Create and open an output file for writing direct from a dictionary /// - /// DatFile to write out from /// Name of the file to write to /// Hash that should be written out /// True if blank roms should be skipped on output, false otherwise (default) /// True if the DAT was written correctly, false otherwise - public static bool WriteToFile(DatFile datFile, string outfile, Hash hash, bool ignoreblanks = false) + public bool WriteToFile(string outfile, Hash hash, bool ignoreblanks = false) { try { @@ -126,12 +122,12 @@ namespace SabreTools.Library.DatFiles StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(true)); // Get a properly sorted set of keys - List keys = datFile.Keys.ToList(); + List keys = Keys.ToList(); keys.Sort(new NaturalComparer()); foreach (string key in keys) { - List roms = datFile[key]; + List roms = this[key]; // Resolve the names in the block roms = DatItem.ResolveNames(roms); @@ -156,7 +152,7 @@ namespace SabreTools.Library.DatFiles } // Now, output the rom data - WriteRomData(datFile, sw, hash, rom, ignoreblanks); + WriteRomData( sw, hash, rom, ignoreblanks); } } @@ -176,13 +172,12 @@ namespace SabreTools.Library.DatFiles /// /// Write out RomData using the supplied StreamWriter /// - /// DatFile to write out from /// StreamWriter to output to /// Hash that should be written out /// RomData object to be output /// True if blank roms should be skipped on output, false otherwise (default) /// True if the data was written, false on error - private static bool WriteRomData(DatFile datFile, StreamWriter sw, Hash hash, DatItem rom, bool ignoreblanks = false) + private bool WriteRomData(StreamWriter sw, Hash hash, DatItem rom, bool ignoreblanks = false) { // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip if (ignoreblanks @@ -200,57 +195,57 @@ namespace SabreTools.Library.DatFiles case Hash.MD5: if (rom.Type == ItemType.Rom) { - state += ((Rom)rom).MD5 + " *" + (datFile.GameName ? rom.MachineName + Path.DirectorySeparatorChar : "") + rom.Name + "\n"; + state += ((Rom)rom).MD5 + " *" + (GameName ? rom.MachineName + Path.DirectorySeparatorChar : "") + rom.Name + "\n"; } else if (rom.Type == ItemType.Disk) { - state += ((Disk)rom).MD5 + " *" + (datFile.GameName ? rom.MachineName + Path.DirectorySeparatorChar : "") + rom.Name + "\n"; + state += ((Disk)rom).MD5 + " *" + (GameName ? rom.MachineName + Path.DirectorySeparatorChar : "") + rom.Name + "\n"; } break; case Hash.CRC: if (rom.Type == ItemType.Rom) { - state += (datFile.GameName ? rom.MachineName + Path.DirectorySeparatorChar : "") + rom.Name + " " + ((Rom)rom).CRC + "\n"; + state += (GameName ? rom.MachineName + Path.DirectorySeparatorChar : "") + rom.Name + " " + ((Rom)rom).CRC + "\n"; } break; case Hash.SHA1: if (rom.Type == ItemType.Rom) { - state += ((Rom)rom).SHA1 + " *" + (datFile.GameName ? rom.MachineName + Path.DirectorySeparatorChar : "") + rom.Name + "\n"; + state += ((Rom)rom).SHA1 + " *" + (GameName ? rom.MachineName + Path.DirectorySeparatorChar : "") + rom.Name + "\n"; } else if (rom.Type == ItemType.Disk) { - state += ((Disk)rom).SHA1 + " *" + (datFile.GameName ? rom.MachineName + Path.DirectorySeparatorChar : "") + rom.Name + "\n"; + state += ((Disk)rom).SHA1 + " *" + (GameName ? rom.MachineName + Path.DirectorySeparatorChar : "") + rom.Name + "\n"; } break; case Hash.SHA256: if (rom.Type == ItemType.Rom) { - state += ((Rom)rom).SHA256 + " *" + (datFile.GameName ? rom.MachineName + Path.DirectorySeparatorChar : "") + rom.Name + "\n"; + state += ((Rom)rom).SHA256 + " *" + (GameName ? rom.MachineName + Path.DirectorySeparatorChar : "") + rom.Name + "\n"; } else if (rom.Type == ItemType.Disk) { - state += ((Disk)rom).SHA256 + " *" + (datFile.GameName ? rom.MachineName + Path.DirectorySeparatorChar : "") + rom.Name + "\n"; + state += ((Disk)rom).SHA256 + " *" + (GameName ? rom.MachineName + Path.DirectorySeparatorChar : "") + rom.Name + "\n"; } break; case Hash.SHA384: if (rom.Type == ItemType.Rom) { - state += ((Rom)rom).SHA384 + " *" + (datFile.GameName ? rom.MachineName + Path.DirectorySeparatorChar : "") + rom.Name + "\n"; + state += ((Rom)rom).SHA384 + " *" + (GameName ? rom.MachineName + Path.DirectorySeparatorChar : "") + rom.Name + "\n"; } else if (rom.Type == ItemType.Disk) { - state += ((Disk)rom).SHA384 + " *" + (datFile.GameName ? rom.MachineName + Path.DirectorySeparatorChar : "") + rom.Name + "\n"; + state += ((Disk)rom).SHA384 + " *" + (GameName ? rom.MachineName + Path.DirectorySeparatorChar : "") + rom.Name + "\n"; } break; case Hash.SHA512: if (rom.Type == ItemType.Rom) { - state += ((Rom)rom).SHA512 + " *" + (datFile.GameName ? rom.MachineName + Path.DirectorySeparatorChar : "") + rom.Name + "\n"; + state += ((Rom)rom).SHA512 + " *" + (GameName ? rom.MachineName + Path.DirectorySeparatorChar : "") + rom.Name + "\n"; } else if (rom.Type == ItemType.Disk) { - state += ((Disk)rom).SHA512 + " *" + (datFile.GameName ? rom.MachineName + Path.DirectorySeparatorChar : "") + rom.Name + "\n"; + state += ((Disk)rom).SHA512 + " *" + (GameName ? rom.MachineName + Path.DirectorySeparatorChar : "") + rom.Name + "\n"; } break; } diff --git a/SabreTools.Library/DatFiles/Listroms.cs b/SabreTools.Library/DatFiles/Listroms.cs index 692c94d3..0adcae9e 100644 --- a/SabreTools.Library/DatFiles/Listroms.cs +++ b/SabreTools.Library/DatFiles/Listroms.cs @@ -24,12 +24,11 @@ namespace SabreTools.Library.DatFiles /// /// Represents parsing and writing of a MAME Listroms DAT /// - public class Listroms + public class Listroms : DatFile { /// /// Parse a MAME Listroms DAT and return all found games and roms within /// - /// DatFile to populate with the read information /// Name of the file to be parsed /// System ID for the DAT /// Source ID for the DAT @@ -45,9 +44,7 @@ namespace SabreTools.Library.DatFiles /// 6331.sound-u8 32 BAD CRC(1d298cb0) SHA1(bb0bb62365402543e3154b9a77be9c75010e6abc) BAD_DUMP /// 16v8h-blue.u24 279 NO GOOD DUMP KNOWN /// - public static void Parse( - DatFile datFile, - + public void Parse( // Standard Dat parsing string filename, int sysid, @@ -127,7 +124,7 @@ namespace SabreTools.Library.DatFiles MachineName = gamename, }; - datFile.ParseAddHelper(disk, clean, remUnicode); + ParseAddHelper(disk, clean, remUnicode); } // Baddump Disks have 4 pieces (name, BAD, sha1, BAD_DUMP) @@ -142,7 +139,7 @@ namespace SabreTools.Library.DatFiles MachineName = gamename, }; - datFile.ParseAddHelper(disk, clean, remUnicode); + ParseAddHelper(disk, clean, remUnicode); } // Standard ROMs have 4 pieces (name, size, crc, sha1) @@ -163,7 +160,7 @@ namespace SabreTools.Library.DatFiles MachineName = gamename, }; - datFile.ParseAddHelper(rom, clean, remUnicode); + ParseAddHelper(rom, clean, remUnicode); } // Nodump Disks have 5 pieces (name, NO, GOOD, DUMP, KNOWN) @@ -177,7 +174,7 @@ namespace SabreTools.Library.DatFiles MachineName = gamename, }; - datFile.ParseAddHelper(disk, clean, remUnicode); + ParseAddHelper(disk, clean, remUnicode); } // Baddump ROMs have 6 pieces (name, size, BAD, crc, sha1, BAD_DUMP) @@ -199,7 +196,7 @@ namespace SabreTools.Library.DatFiles MachineName = gamename, }; - datFile.ParseAddHelper(rom, clean, remUnicode); + ParseAddHelper(rom, clean, remUnicode); } // Nodump ROMs have 6 pieces (name, size, NO, GOOD, DUMP, KNOWN) @@ -219,7 +216,7 @@ namespace SabreTools.Library.DatFiles MachineName = gamename, }; - datFile.ParseAddHelper(rom, clean, remUnicode); + ParseAddHelper(rom, clean, remUnicode); } // If we have something else, it's invalid @@ -235,11 +232,10 @@ namespace SabreTools.Library.DatFiles /// /// Create and open an output file for writing direct from a dictionary /// - /// DatFile to write out from /// Name of the file to write to /// True if blank roms should be skipped on output, false otherwise (default) /// True if the DAT was written correctly, false otherwise - public static bool WriteToFile(DatFile datFile, string outfile, bool ignoreblanks = false) + public bool WriteToFile(string outfile, bool ignoreblanks = false) { try { @@ -259,12 +255,12 @@ namespace SabreTools.Library.DatFiles string lastgame = null; // Get a properly sorted set of keys - List keys = datFile.Keys.ToList(); + List keys = Keys.ToList(); keys.Sort(new NaturalComparer()); foreach (string key in keys) { - List roms = datFile[key]; + List roms = this[key]; // Resolve the names in the block roms = DatItem.ResolveNames(roms); @@ -336,7 +332,7 @@ namespace SabreTools.Library.DatFiles /// StreamWriter to output to /// RomData object to be output /// True if the data was written, false on error - private static bool WriteStartGame(StreamWriter sw, DatItem rom) + private bool WriteStartGame(StreamWriter sw, DatItem rom) { try { @@ -366,7 +362,7 @@ namespace SabreTools.Library.DatFiles /// /// StreamWriter to output to /// True if the data was written, false on error - private static bool WriteEndGame(StreamWriter sw) + private bool WriteEndGame(StreamWriter sw) { try { @@ -391,7 +387,7 @@ namespace SabreTools.Library.DatFiles /// RomData object to be output /// True if blank roms should be skipped on output, false otherwise (default) /// True if the data was written, false on error - private static bool WriteRomData(StreamWriter sw, DatItem rom, bool ignoreblanks = false) + private bool WriteRomData(StreamWriter sw, DatItem rom, bool ignoreblanks = false) { // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip if (ignoreblanks diff --git a/SabreTools.Library/DatFiles/Logiqx.cs b/SabreTools.Library/DatFiles/Logiqx.cs index dd46e3e9..04505b2f 100644 --- a/SabreTools.Library/DatFiles/Logiqx.cs +++ b/SabreTools.Library/DatFiles/Logiqx.cs @@ -25,12 +25,11 @@ namespace SabreTools.Library.DatFiles /// /// Represents parsing and writing of a Logiqx-derived DAT /// - public class Logiqx + public class Logiqx : DatFile { /// /// Parse a Logiqx XML DAT and return all found games and roms within /// - /// DatFile to populate with the read information /// Name of the file to be parsed /// System ID for the DAT /// Source ID for the DAT @@ -39,9 +38,7 @@ namespace SabreTools.Library.DatFiles /// True if we should remove non-ASCII characters from output, false otherwise (default) /// /// - public static void Parse( - DatFile datFile, - + public void Parse( // Standard Dat parsing string filename, int sysid, @@ -85,7 +82,7 @@ namespace SabreTools.Library.DatFiles Rom rom = new Rom("null", tempgame, omitFromScan: Hash.DeepHashes); // TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually // Now process and add the rom - key = datFile.ParseAddHelper(rom, clean, remUnicode); + key = ParseAddHelper(rom, clean, remUnicode); } // Regardless, end the current folder @@ -102,7 +99,7 @@ namespace SabreTools.Library.DatFiles parent.RemoveAt(parent.Count - 1); if (keep && parentcount > 1) { - datFile.Type = (String.IsNullOrEmpty(datFile.Type) ? "SuperDAT" : datFile.Type); + Type = (String.IsNullOrEmpty(Type) ? "SuperDAT" : Type); superdat = true; } } @@ -121,8 +118,8 @@ namespace SabreTools.Library.DatFiles case "mame": if (xtr.GetAttribute("build") != null) { - datFile.Name = (String.IsNullOrEmpty(datFile.Name) ? xtr.GetAttribute("build") : datFile.Name); - datFile.Description = (String.IsNullOrEmpty(datFile.Description) ? datFile.Name : datFile.Name); + Name = (String.IsNullOrEmpty(Name) ? xtr.GetAttribute("build") : Name); + Description = (String.IsNullOrEmpty(Description) ? Name : Name); } xtr.Read(); break; @@ -130,57 +127,57 @@ namespace SabreTools.Library.DatFiles case "softwarelist": if (xtr.GetAttribute("name") != null) { - datFile.Name = (String.IsNullOrEmpty(datFile.Name) ? xtr.GetAttribute("name") : datFile.Name); + Name = (String.IsNullOrEmpty(Name) ? xtr.GetAttribute("name") : Name); } if (xtr.GetAttribute("description") != null) { - datFile.Description = (String.IsNullOrEmpty(datFile.Description) ? xtr.GetAttribute("description") : datFile.Description); + Description = (String.IsNullOrEmpty(Description) ? xtr.GetAttribute("description") : Description); } - if (xtr.GetAttribute("forcemerging") != null && datFile.ForceMerging == ForceMerging.None) + if (xtr.GetAttribute("forcemerging") != null && ForceMerging == ForceMerging.None) { switch (xtr.GetAttribute("forcemerging")) { case "none": - datFile.ForceMerging = ForceMerging.None; + ForceMerging = ForceMerging.None; break; case "split": - datFile.ForceMerging = ForceMerging.Split; + ForceMerging = ForceMerging.Split; break; case "merged": - datFile.ForceMerging = ForceMerging.Merged; + ForceMerging = ForceMerging.Merged; break; case "nonmerged": - datFile.ForceMerging = ForceMerging.NonMerged; + ForceMerging = ForceMerging.NonMerged; break; case "full": - datFile.ForceMerging = ForceMerging.Full; + ForceMerging = ForceMerging.Full; break; } } - if (xtr.GetAttribute("forcenodump") != null && datFile.ForceNodump == ForceNodump.None) + if (xtr.GetAttribute("forcenodump") != null && ForceNodump == ForceNodump.None) { switch (xtr.GetAttribute("forcenodump")) { case "obsolete": - datFile.ForceNodump = ForceNodump.Obsolete; + ForceNodump = ForceNodump.Obsolete; break; case "required": - datFile.ForceNodump = ForceNodump.Required; + ForceNodump = ForceNodump.Required; break; case "ignore": - datFile.ForceNodump = ForceNodump.Ignore; + ForceNodump = ForceNodump.Ignore; break; } } - if (xtr.GetAttribute("forcepacking") != null && datFile.ForcePacking == ForcePacking.None) + if (xtr.GetAttribute("forcepacking") != null && ForcePacking == ForcePacking.None) { switch (xtr.GetAttribute("forcepacking")) { case "zip": - datFile.ForcePacking = ForcePacking.Zip; + ForcePacking = ForcePacking.Zip; break; case "unzip": - datFile.ForcePacking = ForcePacking.Unzip; + ForcePacking = ForcePacking.Unzip; break; } } @@ -188,11 +185,11 @@ namespace SabreTools.Library.DatFiles break; // Handle M1 DATs since they're 99% the same as a SL DAT case "m1": - datFile.Name = (String.IsNullOrEmpty(datFile.Name) ? "M1" : datFile.Name); - datFile.Description = (String.IsNullOrEmpty(datFile.Description) ? "M1" : datFile.Description); + Name = (String.IsNullOrEmpty(Name) ? "M1" : Name); + Description = (String.IsNullOrEmpty(Description) ? "M1" : Description); if (xtr.GetAttribute("version") != null) { - datFile.Version = (String.IsNullOrEmpty(datFile.Version) ? xtr.GetAttribute("version") : datFile.Version); + Version = (String.IsNullOrEmpty(Version) ? xtr.GetAttribute("version") : Version); } xtr.Read(); break; @@ -223,16 +220,16 @@ namespace SabreTools.Library.DatFiles { case "datname": content = headreader.ReadElementContentAsString(); ; - datFile.Name = (String.IsNullOrEmpty(datFile.Name) ? content : datFile.Name); + Name = (String.IsNullOrEmpty(Name) ? content : Name); superdat = superdat || content.Contains(" - SuperDAT"); if (keep && superdat) { - datFile.Type = (String.IsNullOrEmpty(datFile.Type) ? "SuperDAT" : datFile.Type); + Type = (String.IsNullOrEmpty(Type) ? "SuperDAT" : Type); } break; case "datversionurl": content = headreader.ReadElementContentAsString(); ; - datFile.Url = (String.IsNullOrEmpty(datFile.Name) ? content : datFile.Url); + Url = (String.IsNullOrEmpty(Name) ? content : Url); break; default: headreader.Read(); @@ -268,121 +265,121 @@ namespace SabreTools.Library.DatFiles { case "name": content = headreader.ReadElementContentAsString(); ; - datFile.Name = (String.IsNullOrEmpty(datFile.Name) ? content : datFile.Name); + Name = (String.IsNullOrEmpty(Name) ? content : Name); superdat = superdat || content.Contains(" - SuperDAT"); if (keep && superdat) { - datFile.Type = (String.IsNullOrEmpty(datFile.Type) ? "SuperDAT" : datFile.Type); + Type = (String.IsNullOrEmpty(Type) ? "SuperDAT" : Type); } break; case "description": content = headreader.ReadElementContentAsString(); - datFile.Description = (String.IsNullOrEmpty(datFile.Description) ? content : datFile.Description); + Description = (String.IsNullOrEmpty(Description) ? content : Description); break; case "rootdir": content = headreader.ReadElementContentAsString(); - datFile.RootDir = (String.IsNullOrEmpty(datFile.RootDir) ? content : datFile.RootDir); + RootDir = (String.IsNullOrEmpty(RootDir) ? content : RootDir); break; case "category": content = headreader.ReadElementContentAsString(); - datFile.Category = (String.IsNullOrEmpty(datFile.Category) ? content : datFile.Category); + Category = (String.IsNullOrEmpty(Category) ? content : Category); break; case "version": content = headreader.ReadElementContentAsString(); - datFile.Version = (String.IsNullOrEmpty(datFile.Version) ? content : datFile.Version); + Version = (String.IsNullOrEmpty(Version) ? content : Version); break; case "date": content = headreader.ReadElementContentAsString(); - datFile.Date = (String.IsNullOrEmpty(datFile.Date) ? content.Replace(".", "/") : datFile.Date); + Date = (String.IsNullOrEmpty(Date) ? content.Replace(".", "/") : Date); break; case "author": content = headreader.ReadElementContentAsString(); - datFile.Author = (String.IsNullOrEmpty(datFile.Author) ? content : datFile.Author); + Author = (String.IsNullOrEmpty(Author) ? content : Author); // Special cases for SabreDAT - datFile.Email = (String.IsNullOrEmpty(datFile.Email) && !String.IsNullOrEmpty(headreader.GetAttribute("email")) ? - headreader.GetAttribute("email") : datFile.Email); - datFile.Homepage = (String.IsNullOrEmpty(datFile.Homepage) && !String.IsNullOrEmpty(headreader.GetAttribute("homepage")) ? - headreader.GetAttribute("homepage") : datFile.Homepage); - datFile.Url = (String.IsNullOrEmpty(datFile.Url) && !String.IsNullOrEmpty(headreader.GetAttribute("url")) ? - headreader.GetAttribute("url") : datFile.Url); + Email = (String.IsNullOrEmpty(Email) && !String.IsNullOrEmpty(headreader.GetAttribute("email")) ? + headreader.GetAttribute("email") : Email); + Homepage = (String.IsNullOrEmpty(Homepage) && !String.IsNullOrEmpty(headreader.GetAttribute("homepage")) ? + headreader.GetAttribute("homepage") : Homepage); + Url = (String.IsNullOrEmpty(Url) && !String.IsNullOrEmpty(headreader.GetAttribute("url")) ? + headreader.GetAttribute("url") : Url); break; case "email": content = headreader.ReadElementContentAsString(); - datFile.Email = (String.IsNullOrEmpty(datFile.Email) ? content : datFile.Email); + Email = (String.IsNullOrEmpty(Email) ? content : Email); break; case "homepage": content = headreader.ReadElementContentAsString(); - datFile.Homepage = (String.IsNullOrEmpty(datFile.Homepage) ? content : datFile.Homepage); + Homepage = (String.IsNullOrEmpty(Homepage) ? content : Homepage); break; case "url": content = headreader.ReadElementContentAsString(); - datFile.Url = (String.IsNullOrEmpty(datFile.Url) ? content : datFile.Url); + Url = (String.IsNullOrEmpty(Url) ? content : Url); break; case "comment": content = headreader.ReadElementContentAsString(); - datFile.Comment = (String.IsNullOrEmpty(datFile.Comment) ? content : datFile.Comment); + Comment = (String.IsNullOrEmpty(Comment) ? content : Comment); break; case "type": content = headreader.ReadElementContentAsString(); - datFile.Type = (String.IsNullOrEmpty(datFile.Type) ? content : datFile.Type); + Type = (String.IsNullOrEmpty(Type) ? content : Type); superdat = superdat || content.Contains("SuperDAT"); break; case "clrmamepro": case "romcenter": if (headreader.GetAttribute("header") != null) { - datFile.Header = (String.IsNullOrEmpty(datFile.Header) ? headreader.GetAttribute("header") : datFile.Header); + Header = (String.IsNullOrEmpty(Header) ? headreader.GetAttribute("header") : Header); } if (headreader.GetAttribute("plugin") != null) { - datFile.Header = (String.IsNullOrEmpty(datFile.Header) ? headreader.GetAttribute("plugin") : datFile.Header); + Header = (String.IsNullOrEmpty(Header) ? headreader.GetAttribute("plugin") : Header); } - if (headreader.GetAttribute("forcemerging") != null && datFile.ForceMerging == ForceMerging.None) + if (headreader.GetAttribute("forcemerging") != null && ForceMerging == ForceMerging.None) { switch (headreader.GetAttribute("forcemerging")) { case "none": - datFile.ForceMerging = ForceMerging.None; + ForceMerging = ForceMerging.None; break; case "split": - datFile.ForceMerging = ForceMerging.Split; + ForceMerging = ForceMerging.Split; break; case "merged": - datFile.ForceMerging = ForceMerging.Merged; + ForceMerging = ForceMerging.Merged; break; case "nonmerged": - datFile.ForceMerging = ForceMerging.NonMerged; + ForceMerging = ForceMerging.NonMerged; break; case "full": - datFile.ForceMerging = ForceMerging.Full; + ForceMerging = ForceMerging.Full; break; } } - if (headreader.GetAttribute("forcenodump") != null && datFile.ForceNodump == ForceNodump.None) + if (headreader.GetAttribute("forcenodump") != null && ForceNodump == ForceNodump.None) { switch (headreader.GetAttribute("forcenodump")) { case "obsolete": - datFile.ForceNodump = ForceNodump.Obsolete; + ForceNodump = ForceNodump.Obsolete; break; case "required": - datFile.ForceNodump = ForceNodump.Required; + ForceNodump = ForceNodump.Required; break; case "ignore": - datFile.ForceNodump = ForceNodump.Ignore; + ForceNodump = ForceNodump.Ignore; break; } } - if (headreader.GetAttribute("forcepacking") != null && datFile.ForcePacking == ForcePacking.None) + if (headreader.GetAttribute("forcepacking") != null && ForcePacking == ForcePacking.None) { switch (headreader.GetAttribute("forcepacking")) { case "zip": - datFile.ForcePacking = ForcePacking.Zip; + ForcePacking = ForcePacking.Zip; break; case "unzip": - datFile.ForcePacking = ForcePacking.Unzip; + ForcePacking = ForcePacking.Unzip; break; } } @@ -416,53 +413,53 @@ namespace SabreTools.Library.DatFiles switch (flagreader.GetAttribute("name")) { case "type": - datFile.Type = (String.IsNullOrEmpty(datFile.Type) ? content : datFile.Type); + Type = (String.IsNullOrEmpty(Type) ? content : Type); superdat = superdat || content.Contains("SuperDAT"); break; case "forcemerging": - if (datFile.ForceMerging == ForceMerging.None) + if (ForceMerging == ForceMerging.None) { switch (content) { case "split": - datFile.ForceMerging = ForceMerging.Split; + ForceMerging = ForceMerging.Split; break; case "none": - datFile.ForceMerging = ForceMerging.None; + ForceMerging = ForceMerging.None; break; case "full": - datFile.ForceMerging = ForceMerging.Full; + ForceMerging = ForceMerging.Full; break; } } break; case "forcenodump": - if (datFile.ForceNodump == ForceNodump.None) + if (ForceNodump == ForceNodump.None) { switch (content) { case "obsolete": - datFile.ForceNodump = ForceNodump.Obsolete; + ForceNodump = ForceNodump.Obsolete; break; case "required": - datFile.ForceNodump = ForceNodump.Required; + ForceNodump = ForceNodump.Required; break; case "ignore": - datFile.ForceNodump = ForceNodump.Ignore; + ForceNodump = ForceNodump.Ignore; break; } } break; case "forcepacking": - if (datFile.ForcePacking == ForcePacking.None) + if (ForcePacking == ForcePacking.None) { switch (content) { case "zip": - datFile.ForcePacking = ForcePacking.Zip; + ForcePacking = ForcePacking.Zip; break; case "unzip": - datFile.ForcePacking = ForcePacking.Unzip; + ForcePacking = ForcePacking.Unzip; break; } } @@ -631,7 +628,7 @@ namespace SabreTools.Library.DatFiles olrom.CopyMachineInformation(machine); // Now process and add the rom - key = datFile.ParseAddHelper(olrom, clean, remUnicode); + key = ParseAddHelper(olrom, clean, remUnicode); break; // For Software List and MAME listxml only @@ -727,7 +724,7 @@ namespace SabreTools.Library.DatFiles relrom.CopyMachineInformation(machine); // Now process and add the rom - key = datFile.ParseAddHelper(relrom, clean, remUnicode); + key = ParseAddHelper(relrom, clean, remUnicode); subreader.Read(); break; @@ -770,7 +767,7 @@ namespace SabreTools.Library.DatFiles biosrom.CopyMachineInformation(machine); // Now process and add the rom - key = datFile.ParseAddHelper(biosrom, clean, remUnicode); + key = ParseAddHelper(biosrom, clean, remUnicode); subreader.Read(); break; @@ -798,7 +795,7 @@ namespace SabreTools.Library.DatFiles archiverom.CopyMachineInformation(machine); // Now process and add the rom - key = datFile.ParseAddHelper(archiverom, clean, remUnicode); + key = ParseAddHelper(archiverom, clean, remUnicode); subreader.Read(); break; @@ -826,7 +823,7 @@ namespace SabreTools.Library.DatFiles samplerom.CopyMachineInformation(machine); // Now process and add the rom - key = datFile.ParseAddHelper(samplerom, clean, remUnicode); + key = ParseAddHelper(samplerom, clean, remUnicode); subreader.Read(); break; @@ -885,14 +882,14 @@ namespace SabreTools.Library.DatFiles // If the rom is continue or ignore, add the size to the previous rom if (subreader.GetAttribute("loadflag") == "continue" || subreader.GetAttribute("loadflag") == "ignore") { - int index = datFile[key].Count() - 1; - DatItem lastrom = datFile[key][index]; + int index = this[key].Count() - 1; + DatItem lastrom = this[key][index]; if (lastrom.Type == ItemType.Rom) { ((Rom)lastrom).Size += size; } - datFile[key].RemoveAt(index); - datFile[key].Add(lastrom); + this[key].RemoveAt(index); + this[key].Add(lastrom); subreader.Read(); continue; } @@ -967,7 +964,7 @@ namespace SabreTools.Library.DatFiles inrom.CopyMachineInformation(machine); // Now process and add the rom - key = datFile.ParseAddHelper(inrom, clean, remUnicode); + key = ParseAddHelper(inrom, clean, remUnicode); subreader.Read(); break; @@ -985,7 +982,7 @@ namespace SabreTools.Library.DatFiles superdat = true; if (keep) { - datFile.Type = (datFile.Type == "" ? "SuperDAT" : datFile.Type); + Type = (Type == "" ? "SuperDAT" : Type); } string foldername = (xtr.GetAttribute("name") ?? ""); @@ -1069,14 +1066,14 @@ namespace SabreTools.Library.DatFiles // If the rom is continue or ignore, add the size to the previous rom if (xtr.GetAttribute("loadflag") == "continue" || xtr.GetAttribute("loadflag") == "ignore") { - int index = datFile[key].Count() - 1; - DatItem lastrom = datFile[key][index]; + int index = this[key].Count() - 1; + DatItem lastrom = this[key][index]; if (lastrom.Type == ItemType.Rom) { ((Rom)lastrom).Size += size; } - datFile[key].RemoveAt(index); - datFile[key].Add(lastrom); + this[key].RemoveAt(index); + this[key].Add(lastrom); continue; } @@ -1140,7 +1137,7 @@ namespace SabreTools.Library.DatFiles rom.CopyMachineInformation(dir); // Now process and add the rom - key = datFile.ParseAddHelper(rom, clean, remUnicode); + key = ParseAddHelper(rom, clean, remUnicode); xtr.Read(); break; @@ -1164,14 +1161,10 @@ namespace SabreTools.Library.DatFiles /// /// Create and open an output file for writing direct from a dictionary /// - /// DatFile to write out from /// Name of the file to write to - /// True if games should only be compared on game and file name (default), false if system and source are counted - /// True if DAT statistics should be output on write, false otherwise (default) /// True if blank roms should be skipped on output, false otherwise (default) - /// True if files should be overwritten (default), false if they should be renamed instead /// True if the DAT was written correctly, false otherwise - public static bool WriteToFile(DatFile datFile, string outfile, bool norename = true, bool stats = false, bool ignoreblanks = false, bool overwrite = true) + public bool WriteToFile(string outfile, bool ignoreblanks = false) { try { @@ -1188,18 +1181,18 @@ namespace SabreTools.Library.DatFiles StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(true)); // Write out the header - WriteHeader(datFile, sw); + WriteHeader(sw); // Write out each of the machines and roms string lastgame = null; // Get a properly sorted set of keys - List keys = datFile.Keys.ToList(); + List keys = Keys.ToList(); keys.Sort(new NaturalComparer()); foreach (string key in keys) { - List roms = datFile[key]; + List roms = this[key]; // Resolve the names in the block roms = DatItem.ResolveNames(roms); @@ -1224,7 +1217,7 @@ namespace SabreTools.Library.DatFiles // If we have a new game, output the beginning of the new item if (lastgame == null || lastgame.ToLowerInvariant() != rom.MachineName.ToLowerInvariant()) { - WriteStartGame(datFile, sw, rom); + WriteStartGame(sw, rom); } // If we have a "null" game (created by DATFromDir or something similar), log it to file @@ -1271,10 +1264,9 @@ namespace SabreTools.Library.DatFiles /// /// Write out DAT header using the supplied StreamWriter /// - /// DatFile to write out from /// StreamWriter to output to /// True if the data was written, false on error - private static bool WriteHeader(DatFile datFile, StreamWriter sw) + private bool WriteHeader(StreamWriter sw) { try { @@ -1282,29 +1274,29 @@ namespace SabreTools.Library.DatFiles "\n\n" + "\n" + "\t
\n" + - "\t\t" + HttpUtility.HtmlEncode(datFile.Name) + "\n" + - "\t\t" + HttpUtility.HtmlEncode(datFile.Description) + "\n" + - (!String.IsNullOrEmpty(datFile.RootDir) ? "\t\t" + HttpUtility.HtmlEncode(datFile.RootDir) + "\n" : "") + - (!String.IsNullOrEmpty(datFile.Category) ? "\t\t" + HttpUtility.HtmlEncode(datFile.Category) + "\n" : "") + - "\t\t" + HttpUtility.HtmlEncode(datFile.Version) + "\n" + - (!String.IsNullOrEmpty(datFile.Date) ? "\t\t" + HttpUtility.HtmlEncode(datFile.Date) + "\n" : "") + - "\t\t" + HttpUtility.HtmlEncode(datFile.Author) + "\n" + - (!String.IsNullOrEmpty(datFile.Email) ? "\t\t" + HttpUtility.HtmlEncode(datFile.Email) + "\n" : "") + - (!String.IsNullOrEmpty(datFile.Homepage) ? "\t\t" + HttpUtility.HtmlEncode(datFile.Homepage) + "\n" : "") + - (!String.IsNullOrEmpty(datFile.Url) ? "\t\t" + HttpUtility.HtmlEncode(datFile.Url) + "\n" : "") + - (!String.IsNullOrEmpty(datFile.Comment) ? "\t\t" + HttpUtility.HtmlEncode(datFile.Comment) + "\n" : "") + - (!String.IsNullOrEmpty(datFile.Type) ? "\t\t" + HttpUtility.HtmlEncode(datFile.Type) + "\n" : "") + - (datFile.ForcePacking != ForcePacking.None || datFile.ForceMerging != ForceMerging.None || datFile.ForceNodump != ForceNodump.None ? + "\t\t" + HttpUtility.HtmlEncode(Name) + "\n" + + "\t\t" + HttpUtility.HtmlEncode(Description) + "\n" + + (!String.IsNullOrEmpty(RootDir) ? "\t\t" + HttpUtility.HtmlEncode(RootDir) + "\n" : "") + + (!String.IsNullOrEmpty(Category) ? "\t\t" + HttpUtility.HtmlEncode(Category) + "\n" : "") + + "\t\t" + HttpUtility.HtmlEncode(Version) + "\n" + + (!String.IsNullOrEmpty(Date) ? "\t\t" + HttpUtility.HtmlEncode(Date) + "\n" : "") + + "\t\t" + HttpUtility.HtmlEncode(Author) + "\n" + + (!String.IsNullOrEmpty(Email) ? "\t\t" + HttpUtility.HtmlEncode(Email) + "\n" : "") + + (!String.IsNullOrEmpty(Homepage) ? "\t\t" + HttpUtility.HtmlEncode(Homepage) + "\n" : "") + + (!String.IsNullOrEmpty(Url) ? "\t\t" + HttpUtility.HtmlEncode(Url) + "\n" : "") + + (!String.IsNullOrEmpty(Comment) ? "\t\t" + HttpUtility.HtmlEncode(Comment) + "\n" : "") + + (!String.IsNullOrEmpty(Type) ? "\t\t" + HttpUtility.HtmlEncode(Type) + "\n" : "") + + (ForcePacking != ForcePacking.None || ForceMerging != ForceMerging.None || ForceNodump != ForceNodump.None ? "\t\t\n" : "") + "\t
\n"; @@ -1325,11 +1317,10 @@ namespace SabreTools.Library.DatFiles /// /// Write out Game start using the supplied StreamWriter /// - /// DatFile to write out from /// StreamWriter to output to /// RomData object to be output /// True if the data was written, false on error - private static bool WriteStartGame(DatFile datFile, StreamWriter sw, DatItem rom) + private bool WriteStartGame(StreamWriter sw, DatItem rom) { try { @@ -1340,7 +1331,7 @@ namespace SabreTools.Library.DatFiles } string state = "\t /// StreamWriter to output to /// True if the data was written, false on error - private static bool WriteEndGame(StreamWriter sw) + private bool WriteEndGame(StreamWriter sw) { try { @@ -1403,7 +1394,7 @@ namespace SabreTools.Library.DatFiles /// RomData object to be output /// True if blank roms should be skipped on output, false otherwise (default) /// True if the data was written, false on error - private static bool WriteRomData(StreamWriter sw, DatItem rom, bool ignoreblanks = false) + private bool WriteRomData(StreamWriter sw, DatItem rom, bool ignoreblanks = false) { // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip if (ignoreblanks @@ -1486,7 +1477,7 @@ namespace SabreTools.Library.DatFiles /// /// StreamWriter to output to /// True if the data was written, false on error - private static bool WriteFooter(StreamWriter sw) + private bool WriteFooter(StreamWriter sw) { try { diff --git a/SabreTools.Library/DatFiles/Missfile.cs b/SabreTools.Library/DatFiles/Missfile.cs index 77f93856..f981fd4e 100644 --- a/SabreTools.Library/DatFiles/Missfile.cs +++ b/SabreTools.Library/DatFiles/Missfile.cs @@ -22,12 +22,11 @@ namespace SabreTools.Library.DatFiles /// /// Represents parsing and writing of a Missfile /// - public class Missfile + public class Missfile : DatFile { /// /// Parse a Missfileand return all found games and roms within /// - /// DatFile to populate with the read information /// Name of the file to be parsed /// System ID for the DAT /// Source ID for the DAT @@ -36,9 +35,7 @@ namespace SabreTools.Library.DatFiles /// True if we should remove non-ASCII characters from output, false otherwise (default) /// /// - public static void Parse( - DatFile datFile, - + public void Parse( // Standard Dat parsing string filename, int sysid, @@ -56,11 +53,10 @@ namespace SabreTools.Library.DatFiles /// /// Create and open an output file for writing direct from a dictionary /// - /// DatFile to write out from /// Name of the file to write to /// True if blank roms should be skipped on output, false otherwise (default) /// True if the DAT was written correctly, false otherwise - public static bool WriteToFile(DatFile datFile, string outfile, bool ignoreblanks = false) + public bool WriteToFile(string outfile, bool ignoreblanks = false) { try { @@ -80,12 +76,12 @@ namespace SabreTools.Library.DatFiles string lastgame = null; // Get a properly sorted set of keys - List keys = datFile.Keys.ToList(); + List keys = Keys.ToList(); keys.Sort(new NaturalComparer()); foreach (string key in keys) { - List roms = datFile[key]; + List roms = this[key]; // Resolve the names in the block roms = DatItem.ResolveNames(roms); @@ -112,7 +108,7 @@ namespace SabreTools.Library.DatFiles } // Now, output the rom data - WriteRomData(datFile, sw, rom, lastgame, ignoreblanks); + WriteRomData(sw, rom, lastgame, ignoreblanks); // Set the new data to compare against lastgame = rom.MachineName; @@ -135,13 +131,12 @@ namespace SabreTools.Library.DatFiles /// /// Write out RomData using the supplied StreamWriter /// - /// DatFile to write out from /// StreamWriter to output to /// RomData object to be output /// The name of the last game to be output /// True if blank roms should be skipped on output, false otherwise (default) /// True if the data was written, false on error - private static bool WriteRomData(DatFile datFile, StreamWriter sw, DatItem rom, string lastgame, bool ignoreblanks = false) + private bool WriteRomData(StreamWriter sw, DatItem rom, string lastgame, bool ignoreblanks = false) { // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip if (ignoreblanks @@ -154,8 +149,8 @@ namespace SabreTools.Library.DatFiles try { string state = "", name = "", pre = "", post = ""; - pre = datFile.Prefix + (datFile.Quotes ? "\"" : ""); - post = (datFile.Quotes ? "\"" : "") + datFile.Postfix; + pre = Prefix + (Quotes ? "\"" : ""); + post = (Quotes ? "\"" : "") + Postfix; if (rom.Type == ItemType.Rom) { @@ -231,7 +226,7 @@ namespace SabreTools.Library.DatFiles } // If we're in Romba mode, the state is consistent - if (datFile.Romba) + if (Romba) { if (rom.Type == ItemType.Rom) { @@ -264,33 +259,33 @@ namespace SabreTools.Library.DatFiles // Otherwise, use any flags else { - name = (datFile.UseGame ? rom.MachineName : rom.Name); - if (datFile.RepExt != "" || datFile.RemExt) + name = (UseGame ? rom.MachineName : rom.Name); + if (RepExt != "" || RemExt) { - if (datFile.RemExt) + if (RemExt) { - datFile.RepExt = ""; + RepExt = ""; } string dir = Path.GetDirectoryName(name); dir = (dir.StartsWith(Path.DirectorySeparatorChar.ToString()) ? dir.Remove(0, 1) : dir); - name = Path.Combine(dir, Path.GetFileNameWithoutExtension(name) + datFile.RepExt); + name = Path.Combine(dir, Path.GetFileNameWithoutExtension(name) + RepExt); } - if (datFile.AddExt != "") + if (AddExt != "") { - name += datFile.AddExt; + name += AddExt; } - if (!datFile.UseGame && datFile.GameName) + if (!UseGame && GameName) { name = Path.Combine(rom.MachineName, name); } - if (datFile.UseGame && rom.MachineName != lastgame) + if (UseGame && rom.MachineName != lastgame) { state += pre + name + post + "\n"; lastgame = rom.MachineName; } - else if (!datFile.UseGame) + else if (!UseGame) { state += pre + name + post + "\n"; } diff --git a/SabreTools.Library/DatFiles/OfflineList.cs b/SabreTools.Library/DatFiles/OfflineList.cs index 6e0a6030..77252e25 100644 --- a/SabreTools.Library/DatFiles/OfflineList.cs +++ b/SabreTools.Library/DatFiles/OfflineList.cs @@ -2,9 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using System.Text.RegularExpressions; using System.Web; -using System.Xml; using SabreTools.Library.Data; using SabreTools.Library.Items; @@ -25,12 +23,11 @@ namespace SabreTools.Library.DatFiles /// /// Represents parsing and writing of an OfflineList XML DAT /// - public class OfflineList + public class OfflineList : DatFile { /// /// Parse an OfflineList XML DAT and return all found games and roms within /// - /// DatFile to populate with the read information /// Name of the file to be parsed /// System ID for the DAT /// Source ID for the DAT @@ -39,9 +36,7 @@ namespace SabreTools.Library.DatFiles /// True if we should remove non-ASCII characters from output, false otherwise (default) /// /// - public static void Parse( - DatFile datFile, - + public void Parse( // Standard Dat parsing string filename, int sysid, @@ -53,17 +48,16 @@ namespace SabreTools.Library.DatFiles bool remUnicode) { // All XML-derived DATs share a lot in common so it just calls one implementation - Logiqx.Parse(datFile, filename, sysid, srcid, keep, clean, remUnicode); + (this as DatFile as Logiqx).Parse(filename, sysid, srcid, keep, clean, remUnicode); } /// /// Create and open an output file for writing direct from a dictionary /// - /// DatFile to write out from /// Name of the file to write to /// True if blank roms should be skipped on output, false otherwise (default) /// True if the DAT was written correctly, false otherwise - public static bool WriteToFile(DatFile datFile, string outfile, bool ignoreblanks = false) + public bool WriteToFile(string outfile, bool ignoreblanks = false) { try { @@ -80,18 +74,18 @@ namespace SabreTools.Library.DatFiles StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(true)); // Write out the header - WriteHeader(datFile, sw); + WriteHeader(sw); // Write out each of the machines and roms string lastgame = null; // Get a properly sorted set of keys - List keys = datFile.Keys.ToList(); + List keys = Keys.ToList(); keys.Sort(new NaturalComparer()); foreach (string key in keys) { - List roms = datFile[key]; + List roms = this[key]; // Resolve the names in the block roms = DatItem.ResolveNames(roms); @@ -157,18 +151,17 @@ namespace SabreTools.Library.DatFiles /// /// Write out DAT header using the supplied StreamWriter /// - /// DatFile to write out from /// StreamWriter to output to /// True if the data was written, false on error - private static bool WriteHeader(DatFile datFile, StreamWriter sw) + private bool WriteHeader(StreamWriter sw) { try { string header = "\n" + "\n" + "\t\n" - + "\t\t" + HttpUtility.HtmlEncode(datFile.Name) + "\n" - + "\t\t" + datFile.Count + "\n" + + "\t\t" + HttpUtility.HtmlEncode(Name) + "\n" + + "\t\t" + Count + "\n" + "\t\tnone\n" + "\t\t240\n" + "\t\t160\n" @@ -191,9 +184,9 @@ namespace SabreTools.Library.DatFiles + "\t\t\t.bin\n" + "\t\t\n" + "\t\t\n" - + "\t\t\t" + HttpUtility.HtmlEncode(datFile.Url) + "\n" - + "\t\t\t" + HttpUtility.HtmlEncode(datFile.Url) + "\n" - + "\t\t\t" + HttpUtility.HtmlEncode(datFile.Url) + "\n" + + "\t\t\t" + HttpUtility.HtmlEncode(Url) + "\n" + + "\t\t\t" + HttpUtility.HtmlEncode(Url) + "\n" + + "\t\t\t" + HttpUtility.HtmlEncode(Url) + "\n" + "\t\t\n" + "\t\t\n" + "\t\t\t\n" @@ -225,7 +218,7 @@ namespace SabreTools.Library.DatFiles /// /// StreamWriter to output to /// True if the data was written, false on error - private static bool WriteEndGame(StreamWriter sw) + private bool WriteEndGame(StreamWriter sw) { try { @@ -250,7 +243,7 @@ namespace SabreTools.Library.DatFiles /// RomData object to be output /// True if blank roms should be skipped on output, false otherwise (default) /// True if the data was written, false on error - private static bool WriteRomData(StreamWriter sw, DatItem rom, bool ignoreblanks = false) + private bool WriteRomData(StreamWriter sw, DatItem rom, bool ignoreblanks = false) { // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip if (ignoreblanks @@ -327,7 +320,7 @@ namespace SabreTools.Library.DatFiles /// /// StreamWriter to output to /// True if the data was written, false on error - private static bool WriteFooter(StreamWriter sw) + private bool WriteFooter(StreamWriter sw) { try { diff --git a/SabreTools.Library/DatFiles/RomCenter.cs b/SabreTools.Library/DatFiles/RomCenter.cs index 8358ec22..d26f6a98 100644 --- a/SabreTools.Library/DatFiles/RomCenter.cs +++ b/SabreTools.Library/DatFiles/RomCenter.cs @@ -2,9 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using System.Text.RegularExpressions; using System.Web; -using System.Xml; using SabreTools.Library.Data; using SabreTools.Library.Items; @@ -26,20 +24,17 @@ namespace SabreTools.Library.DatFiles /// /// Represents parsing and writing of a RomCenter DAT /// - public class RomCenter + public class RomCenter : DatFile { /// /// Parse a RomCenter DAT and return all found games and roms within /// - /// DatFile to populate with the read information /// Name of the file to be parsed /// System ID for the DAT /// Source ID for the DAT /// True if game names are sanitized, false otherwise (default) /// True if we should remove non-ASCII characters from output, false otherwise (default) - public static void Parse( - DatFile datFile, - + public void Parse( // Standard Dat parsing string filename, int sysid, @@ -84,7 +79,7 @@ namespace SabreTools.Library.DatFiles // If we have an author if (line.ToLowerInvariant().StartsWith("author=")) { - datFile.Author = (String.IsNullOrEmpty(datFile.Author) ? line.Split('=')[1] : datFile.Author); + Author = (String.IsNullOrEmpty(Author) ? line.Split('=')[1] : Author); } // If we have one of the three version tags else if (line.ToLowerInvariant().StartsWith("version=")) @@ -92,31 +87,31 @@ namespace SabreTools.Library.DatFiles switch (blocktype) { case "credits": - datFile.Version = (String.IsNullOrEmpty(datFile.Version) ? line.Split('=')[1] : datFile.Version); + Version = (String.IsNullOrEmpty(Version) ? line.Split('=')[1] : Version); break; case "emulator": - datFile.Description = (String.IsNullOrEmpty(datFile.Description) ? line.Split('=')[1] : datFile.Description); + Description = (String.IsNullOrEmpty(Description) ? line.Split('=')[1] : Description); break; } } // If we have a URL else if (line.ToLowerInvariant().StartsWith("url=")) { - datFile.Url = (String.IsNullOrEmpty(datFile.Url) ? line.Split('=')[1] : datFile.Url); + Url = (String.IsNullOrEmpty(Url) ? line.Split('=')[1] : Url); } // If we have a comment else if (line.ToLowerInvariant().StartsWith("comment=")) { - datFile.Comment = (String.IsNullOrEmpty(datFile.Comment) ? line.Split('=')[1] : datFile.Comment); + Comment = (String.IsNullOrEmpty(Comment) ? line.Split('=')[1] : Comment); } // If we have the split flag else if (line.ToLowerInvariant().StartsWith("split=")) { if (Int32.TryParse(line.Split('=')[1], out int split)) { - if (split == 1 && datFile.ForceMerging == ForceMerging.None) + if (split == 1 && ForceMerging == ForceMerging.None) { - datFile.ForceMerging = ForceMerging.Split; + ForceMerging = ForceMerging.Split; } } } @@ -125,16 +120,16 @@ namespace SabreTools.Library.DatFiles { if (Int32.TryParse(line.Split('=')[1], out int merge)) { - if (merge == 1 && datFile.ForceMerging == ForceMerging.None) + if (merge == 1 && ForceMerging == ForceMerging.None) { - datFile.ForceMerging = ForceMerging.Full; + ForceMerging = ForceMerging.Full; } } } // If we have the refname tag else if (line.ToLowerInvariant().StartsWith("refname=")) { - datFile.Name = (String.IsNullOrEmpty(datFile.Name) ? line.Split('=')[1] : datFile.Name); + Name = (String.IsNullOrEmpty(Name) ? line.Split('=')[1] : Name); } // If we have a rom else if (line.StartsWith("¬")) @@ -182,7 +177,7 @@ namespace SabreTools.Library.DatFiles }; // Now process and add the rom - datFile.ParseAddHelper(rom, clean, remUnicode); + ParseAddHelper(rom, clean, remUnicode); } } } @@ -193,11 +188,10 @@ namespace SabreTools.Library.DatFiles /// /// Create and open an output file for writing direct from a dictionary /// - /// DatFile to write out from /// Name of the file to write to /// True if blank roms should be skipped on output, false otherwise (default) /// True if the DAT was written correctly, false otherwise - public static bool WriteToFile(DatFile datFile, string outfile, bool ignoreblanks = false) + public bool WriteToFile(string outfile, bool ignoreblanks = false) { try { @@ -214,19 +208,19 @@ namespace SabreTools.Library.DatFiles StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(true)); // Write out the header - WriteHeader(datFile, sw); + WriteHeader(sw); // Write out each of the machines and roms string lastgame = null; List splitpath = new List(); // Get a properly sorted set of keys - List keys = datFile.Keys.ToList(); + List keys = Keys.ToList(); keys.Sort(new NaturalComparer()); foreach (string key in keys) { - List roms = datFile[key]; + List roms = this[key]; // Resolve the names in the block roms = DatItem.ResolveNames(roms); @@ -283,24 +277,23 @@ namespace SabreTools.Library.DatFiles /// /// Write out DAT header using the supplied StreamWriter /// - /// DatFile to write out from /// StreamWriter to output to /// True if the data was written, false on error - private static bool WriteHeader(DatFile datFile, StreamWriter sw) + private bool WriteHeader(StreamWriter sw) { try { string header = header = "[CREDITS]\n" + - "author=" + datFile.Author + "\n" + - "version=" + datFile.Version + "\n" + - "comment=" + datFile.Comment + "\n" + + "author=" + Author + "\n" + + "version=" + Version + "\n" + + "comment=" + Comment + "\n" + "[DAT]\n" + "version=2.50\n" + - "split=" + (datFile.ForceMerging == ForceMerging.Split ? "1" : "0") + "\n" + - "merge=" + (datFile.ForceMerging == ForceMerging.Full || datFile.ForceMerging == ForceMerging.Merged ? "1" : "0") + "\n" + + "split=" + (ForceMerging == ForceMerging.Split ? "1" : "0") + "\n" + + "merge=" + (ForceMerging == ForceMerging.Full || ForceMerging == ForceMerging.Merged ? "1" : "0") + "\n" + "[EMULATOR]\n" + - "refname=" + datFile.Name + "\n" + - "version=" + datFile.Description + "\n" + + "refname=" + Name + "\n" + + "version=" + Description + "\n" + "[GAMES]\n"; // Write the header out @@ -323,7 +316,7 @@ namespace SabreTools.Library.DatFiles /// RomData object to be output /// True if blank roms should be skipped on output, false otherwise (default) /// True if the data was written, false on error - private static bool WriteRomData(StreamWriter sw, DatItem rom, bool ignoreblanks = false) + private bool WriteRomData(StreamWriter sw, DatItem rom, bool ignoreblanks = false) { // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip if (ignoreblanks diff --git a/SabreTools.Library/DatFiles/SabreDat.cs b/SabreTools.Library/DatFiles/SabreDat.cs index 24b228a4..76348899 100644 --- a/SabreTools.Library/DatFiles/SabreDat.cs +++ b/SabreTools.Library/DatFiles/SabreDat.cs @@ -2,9 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using System.Text.RegularExpressions; using System.Web; -using System.Xml; using SabreTools.Library.Data; using SabreTools.Library.Items; @@ -16,7 +14,6 @@ using System.IO; using Alphaleonis.Win32.Filesystem; using FileStream = System.IO.FileStream; -using StreamReader = System.IO.StreamReader; using StreamWriter = System.IO.StreamWriter; #endif using NaturalSort; @@ -26,12 +23,11 @@ namespace SabreTools.Library.DatFiles /// /// Represents parsing and writing of an SabreDat XML DAT /// - public class SabreDat + public class SabreDat : DatFile { /// /// Parse an SabreDat XML DAT and return all found games and roms within /// - /// DatFile to populate with the read information /// Name of the file to be parsed /// System ID for the DAT /// Source ID for the DAT @@ -40,9 +36,7 @@ namespace SabreTools.Library.DatFiles /// True if we should remove non-ASCII characters from output, false otherwise (default) /// /// - public static void Parse( - DatFile datFile, - + public void Parse( // Standard Dat parsing string filename, int sysid, @@ -54,20 +48,16 @@ namespace SabreTools.Library.DatFiles bool remUnicode) { // All XML-derived DATs share a lot in common so it just calls one implementation - Logiqx.Parse(datFile, filename, sysid, srcid, keep, clean, remUnicode); + (this as DatFile as Logiqx).Parse(filename, sysid, srcid, keep, clean, remUnicode); } /// /// Create and open an output file for writing direct from a dictionary /// - /// DatFile to write out from /// Name of the file to write to - /// True if games should only be compared on game and file name (default), false if system and source are counted - /// True if DAT statistics should be output on write, false otherwise (default) /// True if blank roms should be skipped on output, false otherwise (default) - /// True if files should be overwritten (default), false if they should be renamed instead /// True if the DAT was written correctly, false otherwise - public static bool WriteToFile(DatFile datFile, string outfile, bool norename = true, bool stats = false, bool ignoreblanks = false, bool overwrite = true) + public bool WriteToFile(string outfile, bool ignoreblanks = false) { try { @@ -84,7 +74,7 @@ namespace SabreTools.Library.DatFiles StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(true)); // Write out the header - WriteHeader(datFile, sw); + WriteHeader(sw); // Write out each of the machines and roms int depth = 2, last = -1; @@ -92,12 +82,12 @@ namespace SabreTools.Library.DatFiles List splitpath = new List(); // Get a properly sorted set of keys - List keys = datFile.Keys.ToList(); + List keys = Keys.ToList(); keys.Sort(new NaturalComparer()); foreach (string key in keys) { - List roms = datFile[key]; + List roms = this[key]; // Resolve the names in the block roms = DatItem.ResolveNames(roms); @@ -167,10 +157,9 @@ namespace SabreTools.Library.DatFiles /// /// Write out DAT header using the supplied StreamWriter /// - /// DatFile to write out from /// StreamWriter to output to /// True if the data was written, false on error - private static bool WriteHeader(DatFile datFile, StreamWriter sw) + private bool WriteHeader(StreamWriter sw) { try { @@ -178,26 +167,26 @@ namespace SabreTools.Library.DatFiles "\n\n" + "\n" + "\t
\n" + - "\t\t" + HttpUtility.HtmlEncode(datFile.Name) + "\n" + - "\t\t" + HttpUtility.HtmlEncode(datFile.Description) + "\n" + - (!String.IsNullOrEmpty(datFile.RootDir) ? "\t\t" + HttpUtility.HtmlEncode(datFile.RootDir) + "\n" : "") + - (!String.IsNullOrEmpty(datFile.Category) ? "\t\t" + HttpUtility.HtmlEncode(datFile.Category) + "\n" : "") + - "\t\t" + HttpUtility.HtmlEncode(datFile.Version) + "\n" + - (!String.IsNullOrEmpty(datFile.Date) ? "\t\t" + HttpUtility.HtmlEncode(datFile.Date) + "\n" : "") + - "\t\t" + HttpUtility.HtmlEncode(datFile.Author) + "\n" + - (!String.IsNullOrEmpty(datFile.Comment) ? "\t\t" + HttpUtility.HtmlEncode(datFile.Comment) + "\n" : "") + - (!String.IsNullOrEmpty(datFile.Type) || datFile.ForcePacking != ForcePacking.None || datFile.ForceMerging != ForceMerging.None || datFile.ForceNodump != ForceNodump.None ? + "\t\t" + HttpUtility.HtmlEncode(Name) + "\n" + + "\t\t" + HttpUtility.HtmlEncode(Description) + "\n" + + (!String.IsNullOrEmpty(RootDir) ? "\t\t" + HttpUtility.HtmlEncode(RootDir) + "\n" : "") + + (!String.IsNullOrEmpty(Category) ? "\t\t" + HttpUtility.HtmlEncode(Category) + "\n" : "") + + "\t\t" + HttpUtility.HtmlEncode(Version) + "\n" + + (!String.IsNullOrEmpty(Date) ? "\t\t" + HttpUtility.HtmlEncode(Date) + "\n" : "") + + "\t\t" + HttpUtility.HtmlEncode(Author) + "\n" + + (!String.IsNullOrEmpty(Comment) ? "\t\t" + HttpUtility.HtmlEncode(Comment) + "\n" : "") + + (!String.IsNullOrEmpty(Type) || ForcePacking != ForcePacking.None || ForceMerging != ForceMerging.None || ForceNodump != ForceNodump.None ? "\t\t\n" + - (!String.IsNullOrEmpty(datFile.Type) ? "\t\t\t\n" : "") + - (datFile.ForcePacking == ForcePacking.Unzip ? "\t\t\t\n" : "") + - (datFile.ForcePacking == ForcePacking.Zip ? "\t\t\t\n" : "") + - (datFile.ForceMerging == ForceMerging.Full ? "\t\t\t\n" : "") + - (datFile.ForceMerging == ForceMerging.Split ? "\t\t\t\n" : "") + - (datFile.ForceMerging == ForceMerging.Merged ? "\t\t\t\n" : "") + - (datFile.ForceMerging == ForceMerging.NonMerged ? "\t\t\t\n" : "") + - (datFile.ForceNodump == ForceNodump.Ignore ? "\t\t\t\n" : "") + - (datFile.ForceNodump == ForceNodump.Obsolete ? "\t\t\t\n" : "") + - (datFile.ForceNodump == ForceNodump.Required ? "\t\t\t\n" : "") + + (!String.IsNullOrEmpty(Type) ? "\t\t\t\n" : "") + + (ForcePacking == ForcePacking.Unzip ? "\t\t\t\n" : "") + + (ForcePacking == ForcePacking.Zip ? "\t\t\t\n" : "") + + (ForceMerging == ForceMerging.Full ? "\t\t\t\n" : "") + + (ForceMerging == ForceMerging.Split ? "\t\t\t\n" : "") + + (ForceMerging == ForceMerging.Merged ? "\t\t\t\n" : "") + + (ForceMerging == ForceMerging.NonMerged ? "\t\t\t\n" : "") + + (ForceNodump == ForceNodump.Ignore ? "\t\t\t\n" : "") + + (ForceNodump == ForceNodump.Obsolete ? "\t\t\t\n" : "") + + (ForceNodump == ForceNodump.Required ? "\t\t\t\n" : "") + "\t\t\n" : "") + "\t
\n" + @@ -226,7 +215,7 @@ namespace SabreTools.Library.DatFiles /// Current depth to output file at (SabreDAT only) /// Last known depth to cycle back from (SabreDAT only) /// The new depth of the tag - private static int WriteStartGame(StreamWriter sw, DatItem rom, List newsplit, string lastgame, int depth, int last) + private int WriteStartGame(StreamWriter sw, DatItem rom, List newsplit, string lastgame, int depth, int last) { try { @@ -269,7 +258,7 @@ namespace SabreTools.Library.DatFiles /// Current depth to output file at (SabreDAT only) /// Last known depth to cycle back from (SabreDAT only) /// The new depth of the tag - private static int WriteEndGame(StreamWriter sw, List splitpath, List newsplit, int depth, out int last) + private int WriteEndGame(StreamWriter sw, List splitpath, List newsplit, int depth, out int last) { last = 0; @@ -325,7 +314,7 @@ namespace SabreTools.Library.DatFiles /// Current depth to output file at (SabreDAT only) /// True if blank roms should be skipped on output, false otherwise (default) /// True if the data was written, false on error - private static bool WriteRomData(StreamWriter sw, DatItem rom, int depth, bool ignoreblanks = false) + private bool WriteRomData(StreamWriter sw, DatItem rom, int depth, bool ignoreblanks = false) { // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip if (ignoreblanks @@ -419,7 +408,7 @@ namespace SabreTools.Library.DatFiles /// StreamWriter to output to /// Current depth to output file at (SabreDAT only) /// True if the data was written, false on error - private static bool WriteFooter(StreamWriter sw, int depth) + private bool WriteFooter(StreamWriter sw, int depth) { try { diff --git a/SabreTools.Library/DatFiles/SeparatedValue.cs b/SabreTools.Library/DatFiles/SeparatedValue.cs index 92cc109b..87ffe1ee 100644 --- a/SabreTools.Library/DatFiles/SeparatedValue.cs +++ b/SabreTools.Library/DatFiles/SeparatedValue.cs @@ -21,12 +21,11 @@ namespace SabreTools.Library.DatFiles /// /// Represents parsing and writing of a value-separated DAT /// - public class SeparatedValue + public class SeparatedValue : DatFile { /// /// Parse a character-separated value DAT and return all found games and roms within /// - /// DatFile to populate with the read information /// Name of the file to be parsed /// System ID for the DAT /// Source ID for the DAT @@ -34,9 +33,7 @@ namespace SabreTools.Library.DatFiles /// True if full pathnames are to be kept, false otherwise (default) /// True if game names are sanitized, false otherwise (default) /// True if we should remove non-ASCII characters from output, false otherwise (default) - public static void Parse( - DatFile datFile, - + public void Parse( // Standard Dat parsing string filename, int sysid, @@ -177,13 +174,13 @@ namespace SabreTools.Library.DatFiles switch (columns[i]) { case "DatFile.FileName": - datFile.FileName = (String.IsNullOrEmpty(datFile.FileName) ? value : datFile.FileName); + FileName = (String.IsNullOrEmpty(FileName) ? value : FileName); break; case "DatFile.Name": - datFile.Name = (String.IsNullOrEmpty(datFile.Name) ? value : datFile.Name); + Name = (String.IsNullOrEmpty(Name) ? value : Name); break; case "DatFile.Description": - datFile.Description = (String.IsNullOrEmpty(datFile.Description) ? value : datFile.Description); + Description = (String.IsNullOrEmpty(Description) ? value : Description); break; case "Machine.Name": machineName = value; @@ -279,7 +276,7 @@ namespace SabreTools.Library.DatFiles MachineDescription = machineDesc, }; - datFile.ParseAddHelper(archive, clean, remUnicode); + ParseAddHelper(archive, clean, remUnicode); break; case ItemType.BiosSet: BiosSet biosset = new BiosSet() @@ -290,7 +287,7 @@ namespace SabreTools.Library.DatFiles Description = machineDesc, }; - datFile.ParseAddHelper(biosset, clean, remUnicode); + ParseAddHelper(biosset, clean, remUnicode); break; case ItemType.Disk: Disk disk = new Disk() @@ -308,7 +305,7 @@ namespace SabreTools.Library.DatFiles ItemStatus = status, }; - datFile.ParseAddHelper(disk, clean, remUnicode); + ParseAddHelper(disk, clean, remUnicode); break; case ItemType.Release: Release release = new Release() @@ -319,7 +316,7 @@ namespace SabreTools.Library.DatFiles MachineDescription = machineDesc, }; - datFile.ParseAddHelper(release, clean, remUnicode); + ParseAddHelper(release, clean, remUnicode); break; case ItemType.Rom: Rom rom = new Rom() @@ -339,7 +336,7 @@ namespace SabreTools.Library.DatFiles ItemStatus = status, }; - datFile.ParseAddHelper(rom, clean, remUnicode); + ParseAddHelper(rom, clean, remUnicode); break; case ItemType.Sample: Sample sample = new Sample() @@ -350,7 +347,7 @@ namespace SabreTools.Library.DatFiles MachineDescription = machineDesc, }; - datFile.ParseAddHelper(sample, clean, remUnicode); + ParseAddHelper(sample, clean, remUnicode); break; } } @@ -359,12 +356,11 @@ namespace SabreTools.Library.DatFiles /// /// Create and open an output file for writing direct from a dictionary /// - /// DatFile to write out from /// Name of the file to write to /// Delimiter for parsing individual lines /// True if blank roms should be skipped on output, false otherwise (default) /// True if the DAT was written correctly, false otherwise - public static bool WriteToFile(DatFile datFile, string outfile, char delim, bool ignoreblanks = false) + public bool WriteToFile(string outfile, char delim, bool ignoreblanks = false) { try { @@ -384,12 +380,12 @@ namespace SabreTools.Library.DatFiles WriteHeader(sw, delim); // Get a properly sorted set of keys - List keys = datFile.Keys.ToList(); + List keys = Keys.ToList(); keys.Sort(new NaturalComparer()); foreach (string key in keys) { - List roms = datFile[key]; + List roms = this[key]; // Resolve the names in the block roms = DatItem.ResolveNames(roms); @@ -414,7 +410,7 @@ namespace SabreTools.Library.DatFiles } // Now, output the rom data - WriteRomData(datFile, sw, delim, rom, ignoreblanks); + WriteRomData(sw, delim, rom, ignoreblanks); } } @@ -437,7 +433,7 @@ namespace SabreTools.Library.DatFiles /// StreamWriter to output to /// Delimiter for parsing individual lines /// True if the data was written, false on error - private static bool WriteHeader(StreamWriter sw, char delim) + private bool WriteHeader(StreamWriter sw, char delim) { try { @@ -460,13 +456,12 @@ namespace SabreTools.Library.DatFiles /// /// Write out RomData using the supplied StreamWriter /// - /// DatFile to write out from /// StreamWriter to output to /// Delimiter for parsing individual lines /// RomData object to be output /// True if blank roms should be skipped on output, false otherwise (default) /// True if the data was written, false on error - private static bool WriteRomData(DatFile datFile, StreamWriter sw, char delim, DatItem rom, bool ignoreblanks = false) + private bool WriteRomData(StreamWriter sw, char delim, DatItem rom, bool ignoreblanks = false) { // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip if (ignoreblanks @@ -478,7 +473,7 @@ namespace SabreTools.Library.DatFiles try { - string state = "", name = "", pre = "", post = ""; + string state = "", pre = "", post = ""; // Separated values should only output Rom and Disk if (rom.Type != ItemType.Disk && rom.Type != ItemType.Rom) @@ -486,8 +481,8 @@ namespace SabreTools.Library.DatFiles return true; } - pre = datFile.Prefix + (datFile.Quotes ? "\"" : ""); - post = (datFile.Quotes ? "\"" : "") + datFile.Postfix; + pre = Prefix + (Quotes ? "\"" : ""); + post = (Quotes ? "\"" : "") + Postfix; if (rom.Type == ItemType.Rom) { @@ -558,9 +553,9 @@ namespace SabreTools.Library.DatFiles if (rom.Type == ItemType.Rom) { - string inline = string.Format("\"" + datFile.FileName + "\"" - + "{0}\"" + datFile.Name + "\"" - + "{0}\"" + datFile.Description + "\"" + string inline = string.Format("\"" + FileName + "\"" + + "{0}\"" + Name + "\"" + + "{0}\"" + Description + "\"" + "{0}\"" + rom.MachineName + "\"" + "{0}\"" + rom.MachineDescription + "\"" + "{0}" + "\"rom\"" @@ -578,9 +573,9 @@ namespace SabreTools.Library.DatFiles } else if (rom.Type == ItemType.Disk) { - string inline = string.Format("\"" + datFile.FileName + "\"" - + "{0}\"" + datFile.Name + "\"" - + "{0}\"" + datFile.Description + "\"" + string inline = string.Format("\"" + FileName + "\"" + + "{0}\"" + Name + "\"" + + "{0}\"" + Description + "\"" + "{0}\"" + rom.MachineName + "\"" + "{0}\"" + rom.MachineDescription + "\"" + "{0}" + "\"disk\"" diff --git a/SabreTools.Library/DatFiles/SoftwareList.cs b/SabreTools.Library/DatFiles/SoftwareList.cs index bad449c8..9c9ebbe3 100644 --- a/SabreTools.Library/DatFiles/SoftwareList.cs +++ b/SabreTools.Library/DatFiles/SoftwareList.cs @@ -23,12 +23,11 @@ namespace SabreTools.Library.DatFiles /// /// Represents parsing and writing of an SabreDat XML DAT /// - public class SoftwareList + public class SoftwareList : DatFile { /// /// Parse an SabreDat XML DAT and return all found games and roms within /// - /// DatFile to populate with the read information /// Name of the file to be parsed /// System ID for the DAT /// Source ID for the DAT @@ -37,7 +36,7 @@ namespace SabreTools.Library.DatFiles /// True if we should remove non-ASCII characters from output, false otherwise (default) /// /// - public static void Parse( + public void Parse( DatFile datFile, // Standard Dat parsing @@ -51,17 +50,16 @@ namespace SabreTools.Library.DatFiles bool remUnicode) { // All XML-derived DATs share a lot in common so it just calls one implementation - Logiqx.Parse(datFile, filename, sysid, srcid, keep, clean, remUnicode); + (this as DatFile as Logiqx).Parse(filename, sysid, srcid, keep, clean, remUnicode); } /// /// Create and open an output file for writing direct from a dictionary /// - /// DatFile to write out from /// Name of the file to write to /// True if blank roms should be skipped on output, false otherwise (default) /// True if the DAT was written correctly, false otherwise - public static bool WriteToFile(DatFile datFile, string outfile, bool ignoreblanks = false) + public bool WriteToFile(string outfile, bool ignoreblanks = false) { try { @@ -78,18 +76,18 @@ namespace SabreTools.Library.DatFiles StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(true)); // Write out the header - WriteHeader(datFile, sw); + WriteHeader(sw); // Write out each of the machines and roms string lastgame = null; // Get a properly sorted set of keys - List keys = datFile.Keys.ToList(); + List keys = Keys.ToList(); keys.Sort(new NaturalComparer()); foreach (string key in keys) { - List roms = datFile[key]; + List roms = this[key]; // Resolve the names in the block roms = DatItem.ResolveNames(roms); @@ -114,7 +112,7 @@ namespace SabreTools.Library.DatFiles // If we have a new game, output the beginning of the new item if (lastgame == null || lastgame.ToLowerInvariant() != rom.MachineName.ToLowerInvariant()) { - WriteStartGame(datFile, sw, rom); + WriteStartGame(sw, rom); } // If we have a "null" game (created by DATFromDir or something similar), log it to file @@ -155,26 +153,25 @@ namespace SabreTools.Library.DatFiles /// /// Write out DAT header using the supplied StreamWriter /// - /// DatFile to write out from /// StreamWriter to output to /// True if the data was written, false on error - private static bool WriteHeader(DatFile datFile, StreamWriter sw) + private bool WriteHeader(StreamWriter sw) { try { string header = "\n" + "\n\n" + - "\n\n"; // Write the header out @@ -193,11 +190,10 @@ namespace SabreTools.Library.DatFiles /// /// Write out Game start using the supplied StreamWriter /// - /// DatFile to write out from /// StreamWriter to output to /// RomData object to be output /// True if the data was written, false on error - private static bool WriteStartGame(DatFile datFile, StreamWriter sw, DatItem rom) + private bool WriteStartGame(StreamWriter sw, DatItem rom) { try { @@ -209,7 +205,7 @@ namespace SabreTools.Library.DatFiles string state = "\t /// StreamWriter to output to /// True if the data was written, false on error - private static bool WriteEndGame(StreamWriter sw) + private bool WriteEndGame(StreamWriter sw) { try { @@ -271,7 +267,7 @@ namespace SabreTools.Library.DatFiles /// RomData object to be output /// True if blank roms should be skipped on output, false otherwise (default) /// True if the data was written, false on error - private static bool WriteRomData(StreamWriter sw, DatItem rom, bool ignoreblanks = false) + private bool WriteRomData(StreamWriter sw, DatItem rom, bool ignoreblanks = false) { // If we are in ignore blanks mode AND we have a blank (0-size) rom, skip if (ignoreblanks @@ -381,7 +377,7 @@ namespace SabreTools.Library.DatFiles /// /// StreamWriter to output to /// True if the data was written, false on error - private static bool WriteFooter(StreamWriter sw) + private bool WriteFooter(StreamWriter sw) { try {