[DatFiles/] Make all DatFile types actually inherit from DatFile

This commit is contained in:
Matt Nadareski
2017-10-09 20:25:46 -07:00
parent 2209d0a13b
commit 09e16fcc4c
13 changed files with 423 additions and 496 deletions

View File

@@ -23,21 +23,18 @@ namespace SabreTools.Library.DatFiles
/// <summary>
/// Represents parsing and writing of an AttractMode DAT
/// </summary>
public class AttractMode
public class AttractMode : DatFile
{
/// <summary>
/// Parse an AttractMode DAT and return all found games within
/// </summary>
/// <param name="datFile">DatFile to populate with the read information</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="sysid">System ID for the DAT</param>
/// <param name="srcid">Source ID for the DAT</param>
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
/// <param name="clean">True if game names are sanitized, false otherwise (default)</param>
/// <param name="remUnicode">True if we should remove non-ASCII characters from output, false otherwise (default)</param>
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
/// <summary>
/// Create and open an output file for writing direct from a dictionary
/// </summary>
/// <param name="datFile">DatFile to write out from</param>
/// <param name="outfile">Name of the file to write to</param>
/// <returns>True if the DAT was written correctly, false otherwise</returns>
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<string> keys = datFile.Keys.ToList();
List<string> keys = Keys.ToList();
keys.Sort(new NaturalComparer());
foreach (string key in keys)
{
List<DatItem> roms = datFile[key];
List<DatItem> 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
/// </summary>
/// <param name="sw">StreamWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private static bool WriteHeader(StreamWriter sw)
private bool WriteHeader(StreamWriter sw)
{
try
{
@@ -222,11 +218,10 @@ namespace SabreTools.Library.DatFiles
/// <summary>
/// Write out Game start using the supplied StreamWriter
/// </summary>
/// <param name="datFile">DatFile to write out from</param>
/// <param name="sw">StreamWriter to output to</param>
/// <param name="rom">RomData object to be output</param>
/// <returns>True if the data was written, false on error</returns>
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 + ";"

View File

@@ -24,21 +24,18 @@ namespace SabreTools.Library.DatFiles
/// <summary>
/// Represents parsing and writing of a ClrMamePro DAT
/// </summary>
public class ClrMamePro
public class ClrMamePro : DatFile
{
/// <summary>
/// Parse a ClrMamePro DAT and return all found games and roms within
/// </summary>
/// <param name="datFile">DatFile to populate with the read information</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="sysid">System ID for the DAT</param>
/// <param name="srcid">Source ID for the DAT</param>
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
/// <param name="clean">True if game names are sanitized, false otherwise (default)</param>
/// <param name="remUnicode">True if we should remove non-ASCII characters from output, false otherwise (default)</param>
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
/// <summary>
/// Create and open an output file for writing direct from a dictionary
/// </summary>
/// <param name="datFile">DatFile to write out from</param>
/// <param name="outfile">Name of the file to write to</param>
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param>
/// <returns>True if the DAT was written correctly, false otherwise</returns>
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<string> keys = datFile.Keys.ToList();
List<string> keys = Keys.ToList();
keys.Sort(new NaturalComparer());
foreach (string key in keys)
{
List<DatItem> roms = datFile[key];
List<DatItem> 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
/// <summary>
/// Write out DAT header using the supplied StreamWriter
/// </summary>
/// <param name="datFile">DatFile to write out from</param>
/// <param name="sw">StreamWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
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
/// <summary>
/// Write out Game start using the supplied StreamWriter
/// </summary>
/// <param name="datFile">DatFile to write out from</param>
/// <param name="sw">StreamWriter to output to</param>
/// <param name="rom">RomData object to be output</param>
/// <returns>True if the data was written, false on error</returns>
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
/// <param name="sw">StreamWriter to output to</param>
/// <param name="rom">RomData object to be output</param>
/// <returns>True if the data was written, false on error</returns>
private static bool WriteEndGame(StreamWriter sw, DatItem rom)
private bool WriteEndGame(StreamWriter sw, DatItem rom)
{
try
{
@@ -834,7 +828,7 @@ namespace SabreTools.Library.DatFiles
/// <param name="rom">RomData object to be output</param>
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param>
/// <returns>True if the data was written, false on error</returns>
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
/// </summary>
/// <param name="sw">StreamWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private static bool WriteFooter(StreamWriter sw)
private bool WriteFooter(StreamWriter sw)
{
try
{

View File

@@ -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;
}
});

View File

@@ -22,21 +22,18 @@ namespace SabreTools.Library.DatFiles
/// <summary>
/// Represents parsing and writing of a DosCenter DAT
/// </summary>
public class DosCenter
public class DosCenter : DatFile
{
/// <summary>
/// Parse a DosCenter DAT and return all found games and roms within
/// </summary>
/// <param name="datFile">DatFile to populate with the read information</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="sysid">System ID for the DAT</param>
/// <param name="srcid">Source ID for the DAT</param>
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
/// <param name="clean">True if game names are sanitized, false otherwise (default)</param>
/// <param name="remUnicode">True if we should remove non-ASCII characters from output, false otherwise (default)</param>
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);
}
/// <summary>
/// Create and open an output file for writing direct from a dictionary
/// </summary>
/// <param name="datFile">DatFile to write out from</param>
/// <param name="outfile">Name of the file to write to</param>
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param>
/// <returns>True if the DAT was written correctly, false otherwise</returns>
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<string> keys = datFile.Keys.ToList();
List<string> keys = Keys.ToList();
keys.Sort(new NaturalComparer());
foreach (string key in keys)
{
List<DatItem> roms = datFile[key];
List<DatItem> roms = this[key];
// Resolve the names in the block
roms = DatItem.ResolveNames(roms);
@@ -161,21 +157,20 @@ namespace SabreTools.Library.DatFiles
/// <summary>
/// Write out DAT header using the supplied StreamWriter
/// </summary>
/// <param name="datFile">DatFile to write out from</param>
/// <param name="sw">StreamWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
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
/// <param name="sw">StreamWriter to output to</param>
/// <param name="rom">RomData object to be output</param>
/// <returns>True if the data was written, false on error</returns>
private static bool WriteStartGame(StreamWriter sw, DatItem rom)
private bool WriteStartGame(StreamWriter sw, DatItem rom)
{
try
{
@@ -227,7 +222,7 @@ namespace SabreTools.Library.DatFiles
/// <param name="sw">StreamWriter to output to</param>
/// <param name="rom">RomData object to be output</param>
/// <returns>True if the data was written, false on error</returns>
private static bool WriteEndGame(StreamWriter sw, DatItem rom)
private bool WriteEndGame(StreamWriter sw, DatItem rom)
{
try
{
@@ -252,7 +247,7 @@ namespace SabreTools.Library.DatFiles
/// <param name="rom">RomData object to be output</param>
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param>
/// <returns>True if the data was written, false on error</returns>
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
/// </summary>
/// <param name="sw">StreamWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private static bool WriteFooter(StreamWriter sw)
private bool WriteFooter(StreamWriter sw)
{
try
{

View File

@@ -23,21 +23,18 @@ namespace SabreTools.Library.DatFiles
/// <summary>
/// Represents parsing and writing of a hashfile such as an SFV, MD5, or SHA-1 file
/// </summary>
public class Hashfile
public class Hashfile : DatFile
{
/// <summary>
/// Parse a hashfile or SFV and return all found games and roms within
/// </summary>
/// <param name="datFile">DatFile to populate with the read information</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="sysid">System ID for the DAT</param>
/// <param name="srcid">Source ID for the DAT</param>
/// <param name="hashtype">Hash type that should be assumed</param>
/// <param name="clean">True if game names are sanitized, false otherwise (default)</param>
/// <param name="remUnicode">True if we should remove non-ASCII characters from output, false otherwise (default)</param>
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
/// <summary>
/// Create and open an output file for writing direct from a dictionary
/// </summary>
/// <param name="datFile">DatFile to write out from</param>
/// <param name="outfile">Name of the file to write to</param>
/// <param name="hash">Hash that should be written out</param>
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param>
/// <returns>True if the DAT was written correctly, false otherwise</returns>
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<string> keys = datFile.Keys.ToList();
List<string> keys = Keys.ToList();
keys.Sort(new NaturalComparer());
foreach (string key in keys)
{
List<DatItem> roms = datFile[key];
List<DatItem> 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
/// <summary>
/// Write out RomData using the supplied StreamWriter
/// </summary>
/// <param name="datFile">DatFile to write out from</param>
/// <param name="sw">StreamWriter to output to</param>
/// <param name="hash">Hash that should be written out</param>
/// <param name="rom">RomData object to be output</param>
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param>
/// <returns>True if the data was written, false on error</returns>
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;
}

View File

@@ -24,12 +24,11 @@ namespace SabreTools.Library.DatFiles
/// <summary>
/// Represents parsing and writing of a MAME Listroms DAT
/// </summary>
public class Listroms
public class Listroms : DatFile
{
/// <summary>
/// Parse a MAME Listroms DAT and return all found games and roms within
/// </summary>
/// <param name="datFile">DatFile to populate with the read information</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="sysid">System ID for the DAT</param>
/// <param name="srcid">Source ID for the DAT</param>
@@ -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
/// </remarks>
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
/// <summary>
/// Create and open an output file for writing direct from a dictionary
/// </summary>
/// <param name="datFile">DatFile to write out from</param>
/// <param name="outfile">Name of the file to write to</param>
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param>
/// <returns>True if the DAT was written correctly, false otherwise</returns>
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<string> keys = datFile.Keys.ToList();
List<string> keys = Keys.ToList();
keys.Sort(new NaturalComparer());
foreach (string key in keys)
{
List<DatItem> roms = datFile[key];
List<DatItem> roms = this[key];
// Resolve the names in the block
roms = DatItem.ResolveNames(roms);
@@ -336,7 +332,7 @@ namespace SabreTools.Library.DatFiles
/// <param name="sw">StreamWriter to output to</param>
/// <param name="rom">RomData object to be output</param>
/// <returns>True if the data was written, false on error</returns>
private static bool WriteStartGame(StreamWriter sw, DatItem rom)
private bool WriteStartGame(StreamWriter sw, DatItem rom)
{
try
{
@@ -366,7 +362,7 @@ namespace SabreTools.Library.DatFiles
/// </summary>
/// <param name="sw">StreamWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private static bool WriteEndGame(StreamWriter sw)
private bool WriteEndGame(StreamWriter sw)
{
try
{
@@ -391,7 +387,7 @@ namespace SabreTools.Library.DatFiles
/// <param name="rom">RomData object to be output</param>
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param>
/// <returns>True if the data was written, false on error</returns>
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

View File

@@ -25,12 +25,11 @@ namespace SabreTools.Library.DatFiles
/// <summary>
/// Represents parsing and writing of a Logiqx-derived DAT
/// </summary>
public class Logiqx
public class Logiqx : DatFile
{
/// <summary>
/// Parse a Logiqx XML DAT and return all found games and roms within
/// </summary>
/// <param name="datFile">DatFile to populate with the read information</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="sysid">System ID for the DAT</param>
/// <param name="srcid">Source ID for the DAT</param>
@@ -39,9 +38,7 @@ namespace SabreTools.Library.DatFiles
/// <param name="remUnicode">True if we should remove non-ASCII characters from output, false otherwise (default)</param>
/// <remarks>
/// </remarks>
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
/// <summary>
/// Create and open an output file for writing direct from a dictionary
/// </summary>
/// <param name="datFile">DatFile to write out from</param>
/// <param name="outfile">Name of the file to write to</param>
/// <param name="norename">True if games should only be compared on game and file name (default), false if system and source are counted</param>
/// <param name="stats">True if DAT statistics should be output on write, false otherwise (default)</param>
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param>
/// <param name="overwrite">True if files should be overwritten (default), false if they should be renamed instead</param>
/// <returns>True if the DAT was written correctly, false otherwise</returns>
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<string> keys = datFile.Keys.ToList();
List<string> keys = Keys.ToList();
keys.Sort(new NaturalComparer());
foreach (string key in keys)
{
List<DatItem> roms = datFile[key];
List<DatItem> 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
/// <summary>
/// Write out DAT header using the supplied StreamWriter
/// </summary>
/// <param name="datFile">DatFile to write out from</param>
/// <param name="sw">StreamWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private static bool WriteHeader(DatFile datFile, StreamWriter sw)
private bool WriteHeader(StreamWriter sw)
{
try
{
@@ -1282,29 +1274,29 @@ namespace SabreTools.Library.DatFiles
"<!DOCTYPE datafile PUBLIC \"-//Logiqx//DTD ROM Management Datafile//EN\" \"http://www.logiqx.com/Dats/datafile.dtd\">\n\n" +
"<datafile>\n" +
"\t<header>\n" +
"\t\t<name>" + HttpUtility.HtmlEncode(datFile.Name) + "</name>\n" +
"\t\t<description>" + HttpUtility.HtmlEncode(datFile.Description) + "</description>\n" +
(!String.IsNullOrEmpty(datFile.RootDir) ? "\t\t<rootdir>" + HttpUtility.HtmlEncode(datFile.RootDir) + "</rootdir>\n" : "") +
(!String.IsNullOrEmpty(datFile.Category) ? "\t\t<category>" + HttpUtility.HtmlEncode(datFile.Category) + "</category>\n" : "") +
"\t\t<version>" + HttpUtility.HtmlEncode(datFile.Version) + "</version>\n" +
(!String.IsNullOrEmpty(datFile.Date) ? "\t\t<date>" + HttpUtility.HtmlEncode(datFile.Date) + "</date>\n" : "") +
"\t\t<author>" + HttpUtility.HtmlEncode(datFile.Author) + "</author>\n" +
(!String.IsNullOrEmpty(datFile.Email) ? "\t\t<email>" + HttpUtility.HtmlEncode(datFile.Email) + "</email>\n" : "") +
(!String.IsNullOrEmpty(datFile.Homepage) ? "\t\t<homepage>" + HttpUtility.HtmlEncode(datFile.Homepage) + "</homepage>\n" : "") +
(!String.IsNullOrEmpty(datFile.Url) ? "\t\t<url>" + HttpUtility.HtmlEncode(datFile.Url) + "</url>\n" : "") +
(!String.IsNullOrEmpty(datFile.Comment) ? "\t\t<comment>" + HttpUtility.HtmlEncode(datFile.Comment) + "</comment>\n" : "") +
(!String.IsNullOrEmpty(datFile.Type) ? "\t\t<type>" + HttpUtility.HtmlEncode(datFile.Type) + "</type>\n" : "") +
(datFile.ForcePacking != ForcePacking.None || datFile.ForceMerging != ForceMerging.None || datFile.ForceNodump != ForceNodump.None ?
"\t\t<name>" + HttpUtility.HtmlEncode(Name) + "</name>\n" +
"\t\t<description>" + HttpUtility.HtmlEncode(Description) + "</description>\n" +
(!String.IsNullOrEmpty(RootDir) ? "\t\t<rootdir>" + HttpUtility.HtmlEncode(RootDir) + "</rootdir>\n" : "") +
(!String.IsNullOrEmpty(Category) ? "\t\t<category>" + HttpUtility.HtmlEncode(Category) + "</category>\n" : "") +
"\t\t<version>" + HttpUtility.HtmlEncode(Version) + "</version>\n" +
(!String.IsNullOrEmpty(Date) ? "\t\t<date>" + HttpUtility.HtmlEncode(Date) + "</date>\n" : "") +
"\t\t<author>" + HttpUtility.HtmlEncode(Author) + "</author>\n" +
(!String.IsNullOrEmpty(Email) ? "\t\t<email>" + HttpUtility.HtmlEncode(Email) + "</email>\n" : "") +
(!String.IsNullOrEmpty(Homepage) ? "\t\t<homepage>" + HttpUtility.HtmlEncode(Homepage) + "</homepage>\n" : "") +
(!String.IsNullOrEmpty(Url) ? "\t\t<url>" + HttpUtility.HtmlEncode(Url) + "</url>\n" : "") +
(!String.IsNullOrEmpty(Comment) ? "\t\t<comment>" + HttpUtility.HtmlEncode(Comment) + "</comment>\n" : "") +
(!String.IsNullOrEmpty(Type) ? "\t\t<type>" + HttpUtility.HtmlEncode(Type) + "</type>\n" : "") +
(ForcePacking != ForcePacking.None || ForceMerging != ForceMerging.None || ForceNodump != ForceNodump.None ?
"\t\t<clrmamepro" +
(datFile.ForcePacking == ForcePacking.Unzip ? " forcepacking=\"unzip\"" : "") +
(datFile.ForcePacking == ForcePacking.Zip ? " forcepacking=\"zip\"" : "") +
(datFile.ForceMerging == ForceMerging.Full ? " forcemerging=\"full\"" : "") +
(datFile.ForceMerging == ForceMerging.Split ? " forcemerging=\"split\"" : "") +
(datFile.ForceMerging == ForceMerging.Merged ? " forcemerging=\"merged\"" : "") +
(datFile.ForceMerging == ForceMerging.NonMerged ? " forcemerging=\"nonmerged\"" : "") +
(datFile.ForceNodump == ForceNodump.Ignore ? " forcenodump=\"ignore\"" : "") +
(datFile.ForceNodump == ForceNodump.Obsolete ? " forcenodump=\"obsolete\"" : "") +
(datFile.ForceNodump == ForceNodump.Required ? " forcenodump=\"required\"" : "") +
(ForcePacking == ForcePacking.Unzip ? " forcepacking=\"unzip\"" : "") +
(ForcePacking == ForcePacking.Zip ? " forcepacking=\"zip\"" : "") +
(ForceMerging == ForceMerging.Full ? " forcemerging=\"full\"" : "") +
(ForceMerging == ForceMerging.Split ? " forcemerging=\"split\"" : "") +
(ForceMerging == ForceMerging.Merged ? " forcemerging=\"merged\"" : "") +
(ForceMerging == ForceMerging.NonMerged ? " forcemerging=\"nonmerged\"" : "") +
(ForceNodump == ForceNodump.Ignore ? " forcenodump=\"ignore\"" : "") +
(ForceNodump == ForceNodump.Obsolete ? " forcenodump=\"obsolete\"" : "") +
(ForceNodump == ForceNodump.Required ? " forcenodump=\"required\"" : "") +
" />\n"
: "") +
"\t</header>\n";
@@ -1325,11 +1317,10 @@ namespace SabreTools.Library.DatFiles
/// <summary>
/// Write out Game start using the supplied StreamWriter
/// </summary>
/// <param name="datFile">DatFile to write out from</param>
/// <param name="sw">StreamWriter to output to</param>
/// <param name="rom">RomData object to be output</param>
/// <returns>True if the data was written, false on error</returns>
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<machine name=\"" + HttpUtility.HtmlEncode(rom.MachineName) + "\"" +
(datFile.ExcludeOf ? "" :
(ExcludeOf ? "" :
(rom.MachineType == MachineType.Bios ? " isbios=\"yes\"" : "") +
(rom.MachineType == MachineType.Device ? " isdevice=\"yes\"" : "") +
(rom.MachineType == MachineType.Mechanical ? " ismechanical=\"yes\"" : "") +
@@ -1378,7 +1369,7 @@ namespace SabreTools.Library.DatFiles
/// </summary>
/// <param name="sw">StreamWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private static bool WriteEndGame(StreamWriter sw)
private bool WriteEndGame(StreamWriter sw)
{
try
{
@@ -1403,7 +1394,7 @@ namespace SabreTools.Library.DatFiles
/// <param name="rom">RomData object to be output</param>
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param>
/// <returns>True if the data was written, false on error</returns>
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
/// </summary>
/// <param name="sw">StreamWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private static bool WriteFooter(StreamWriter sw)
private bool WriteFooter(StreamWriter sw)
{
try
{

View File

@@ -22,12 +22,11 @@ namespace SabreTools.Library.DatFiles
/// <summary>
/// Represents parsing and writing of a Missfile
/// </summary>
public class Missfile
public class Missfile : DatFile
{
/// <summary>
/// Parse a Missfileand return all found games and roms within
/// </summary>
/// <param name="datFile">DatFile to populate with the read information</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="sysid">System ID for the DAT</param>
/// <param name="srcid">Source ID for the DAT</param>
@@ -36,9 +35,7 @@ namespace SabreTools.Library.DatFiles
/// <param name="remUnicode">True if we should remove non-ASCII characters from output, false otherwise (default)</param>
/// <remarks>
/// </remarks>
public static void Parse(
DatFile datFile,
public void Parse(
// Standard Dat parsing
string filename,
int sysid,
@@ -56,11 +53,10 @@ namespace SabreTools.Library.DatFiles
/// <summary>
/// Create and open an output file for writing direct from a dictionary
/// </summary>
/// <param name="datFile">DatFile to write out from</param>
/// <param name="outfile">Name of the file to write to</param>
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param>
/// <returns>True if the DAT was written correctly, false otherwise</returns>
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<string> keys = datFile.Keys.ToList();
List<string> keys = Keys.ToList();
keys.Sort(new NaturalComparer());
foreach (string key in keys)
{
List<DatItem> roms = datFile[key];
List<DatItem> 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
/// <summary>
/// Write out RomData using the supplied StreamWriter
/// </summary>
/// <param name="datFile">DatFile to write out from</param>
/// <param name="sw">StreamWriter to output to</param>
/// <param name="rom">RomData object to be output</param>
/// <param name="lastgame">The name of the last game to be output</param>
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param>
/// <returns>True if the data was written, false on error</returns>
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";
}

View File

@@ -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
/// <summary>
/// Represents parsing and writing of an OfflineList XML DAT
/// </summary>
public class OfflineList
public class OfflineList : DatFile
{
/// <summary>
/// Parse an OfflineList XML DAT and return all found games and roms within
/// </summary>
/// <param name="datFile">DatFile to populate with the read information</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="sysid">System ID for the DAT</param>
/// <param name="srcid">Source ID for the DAT</param>
@@ -39,9 +36,7 @@ namespace SabreTools.Library.DatFiles
/// <param name="remUnicode">True if we should remove non-ASCII characters from output, false otherwise (default)</param>
/// <remarks>
/// </remarks>
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);
}
/// <summary>
/// Create and open an output file for writing direct from a dictionary
/// </summary>
/// <param name="datFile">DatFile to write out from</param>
/// <param name="outfile">Name of the file to write to</param>
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param>
/// <returns>True if the DAT was written correctly, false otherwise</returns>
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<string> keys = datFile.Keys.ToList();
List<string> keys = Keys.ToList();
keys.Sort(new NaturalComparer());
foreach (string key in keys)
{
List<DatItem> roms = datFile[key];
List<DatItem> roms = this[key];
// Resolve the names in the block
roms = DatItem.ResolveNames(roms);
@@ -157,18 +151,17 @@ namespace SabreTools.Library.DatFiles
/// <summary>
/// Write out DAT header using the supplied StreamWriter
/// </summary>
/// <param name="datFile">DatFile to write out from</param>
/// <param name="sw">StreamWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private static bool WriteHeader(DatFile datFile, StreamWriter sw)
private bool WriteHeader(StreamWriter sw)
{
try
{
string header = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
+ "<dat xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"datas.xsd\">\n"
+ "\t<configuration>\n"
+ "\t\t<datName>" + HttpUtility.HtmlEncode(datFile.Name) + "</datName>\n"
+ "\t\t<datVersion>" + datFile.Count + "</datVersion>\n"
+ "\t\t<datName>" + HttpUtility.HtmlEncode(Name) + "</datName>\n"
+ "\t\t<datVersion>" + Count + "</datVersion>\n"
+ "\t\t<system>none</system>\n"
+ "\t\t<screenshotsWidth>240</screenshotsWidth>\n"
+ "\t\t<screenshotsHeight>160</screenshotsHeight>\n"
@@ -191,9 +184,9 @@ namespace SabreTools.Library.DatFiles
+ "\t\t\t<extension>.bin</extension>\n"
+ "\t\t</canOpen>\n"
+ "\t\t<newDat>\n"
+ "\t\t\t<datVersionURL>" + HttpUtility.HtmlEncode(datFile.Url) + "</datVersionURL>\n"
+ "\t\t\t<datURL fileName=\"" + HttpUtility.HtmlEncode(datFile.FileName) + ".zip\">" + HttpUtility.HtmlEncode(datFile.Url) + "</datURL>\n"
+ "\t\t\t<imURL>" + HttpUtility.HtmlEncode(datFile.Url) + "</imURL>\n"
+ "\t\t\t<datVersionURL>" + HttpUtility.HtmlEncode(Url) + "</datVersionURL>\n"
+ "\t\t\t<datURL fileName=\"" + HttpUtility.HtmlEncode(FileName) + ".zip\">" + HttpUtility.HtmlEncode(Url) + "</datURL>\n"
+ "\t\t\t<imURL>" + HttpUtility.HtmlEncode(Url) + "</imURL>\n"
+ "\t\t</newDat>\n"
+ "\t\t<search>\n"
+ "\t\t\t<to value=\"location\" default=\"true\" auto=\"true\"/>\n"
@@ -225,7 +218,7 @@ namespace SabreTools.Library.DatFiles
/// </summary>
/// <param name="sw">StreamWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private static bool WriteEndGame(StreamWriter sw)
private bool WriteEndGame(StreamWriter sw)
{
try
{
@@ -250,7 +243,7 @@ namespace SabreTools.Library.DatFiles
/// <param name="rom">RomData object to be output</param>
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param>
/// <returns>True if the data was written, false on error</returns>
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
/// </summary>
/// <param name="sw">StreamWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private static bool WriteFooter(StreamWriter sw)
private bool WriteFooter(StreamWriter sw)
{
try
{

View File

@@ -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
/// <summary>
/// Represents parsing and writing of a RomCenter DAT
/// </summary>
public class RomCenter
public class RomCenter : DatFile
{
/// <summary>
/// Parse a RomCenter DAT and return all found games and roms within
/// </summary>
/// <param name="datFile">DatFile to populate with the read information</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="sysid">System ID for the DAT</param>
/// <param name="srcid">Source ID for the DAT</param>
/// <param name="clean">True if game names are sanitized, false otherwise (default)</param>
/// <param name="remUnicode">True if we should remove non-ASCII characters from output, false otherwise (default)</param>
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
/// <summary>
/// Create and open an output file for writing direct from a dictionary
/// </summary>
/// <param name="datFile">DatFile to write out from</param>
/// <param name="outfile">Name of the file to write to</param>
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param>
/// <returns>True if the DAT was written correctly, false otherwise</returns>
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<string> splitpath = new List<string>();
// Get a properly sorted set of keys
List<string> keys = datFile.Keys.ToList();
List<string> keys = Keys.ToList();
keys.Sort(new NaturalComparer());
foreach (string key in keys)
{
List<DatItem> roms = datFile[key];
List<DatItem> roms = this[key];
// Resolve the names in the block
roms = DatItem.ResolveNames(roms);
@@ -283,24 +277,23 @@ namespace SabreTools.Library.DatFiles
/// <summary>
/// Write out DAT header using the supplied StreamWriter
/// </summary>
/// <param name="datFile">DatFile to write out from</param>
/// <param name="sw">StreamWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
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
/// <param name="rom">RomData object to be output</param>
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param>
/// <returns>True if the data was written, false on error</returns>
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

View File

@@ -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
/// <summary>
/// Represents parsing and writing of an SabreDat XML DAT
/// </summary>
public class SabreDat
public class SabreDat : DatFile
{
/// <summary>
/// Parse an SabreDat XML DAT and return all found games and roms within
/// </summary>
/// <param name="datFile">DatFile to populate with the read information</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="sysid">System ID for the DAT</param>
/// <param name="srcid">Source ID for the DAT</param>
@@ -40,9 +36,7 @@ namespace SabreTools.Library.DatFiles
/// <param name="remUnicode">True if we should remove non-ASCII characters from output, false otherwise (default)</param>
/// <remarks>
/// </remarks>
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);
}
/// <summary>
/// Create and open an output file for writing direct from a dictionary
/// </summary>
/// <param name="datFile">DatFile to write out from</param>
/// <param name="outfile">Name of the file to write to</param>
/// <param name="norename">True if games should only be compared on game and file name (default), false if system and source are counted</param>
/// <param name="stats">True if DAT statistics should be output on write, false otherwise (default)</param>
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param>
/// <param name="overwrite">True if files should be overwritten (default), false if they should be renamed instead</param>
/// <returns>True if the DAT was written correctly, false otherwise</returns>
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<string> splitpath = new List<string>();
// Get a properly sorted set of keys
List<string> keys = datFile.Keys.ToList();
List<string> keys = Keys.ToList();
keys.Sort(new NaturalComparer());
foreach (string key in keys)
{
List<DatItem> roms = datFile[key];
List<DatItem> roms = this[key];
// Resolve the names in the block
roms = DatItem.ResolveNames(roms);
@@ -167,10 +157,9 @@ namespace SabreTools.Library.DatFiles
/// <summary>
/// Write out DAT header using the supplied StreamWriter
/// </summary>
/// <param name="datFile">DatFile to write out from</param>
/// <param name="sw">StreamWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private static bool WriteHeader(DatFile datFile, StreamWriter sw)
private bool WriteHeader(StreamWriter sw)
{
try
{
@@ -178,26 +167,26 @@ namespace SabreTools.Library.DatFiles
"<!DOCTYPE sabredat SYSTEM \"newdat.xsd\">\n\n" +
"<datafile>\n" +
"\t<header>\n" +
"\t\t<name>" + HttpUtility.HtmlEncode(datFile.Name) + "</name>\n" +
"\t\t<description>" + HttpUtility.HtmlEncode(datFile.Description) + "</description>\n" +
(!String.IsNullOrEmpty(datFile.RootDir) ? "\t\t<rootdir>" + HttpUtility.HtmlEncode(datFile.RootDir) + "</rootdir>\n" : "") +
(!String.IsNullOrEmpty(datFile.Category) ? "\t\t<category>" + HttpUtility.HtmlEncode(datFile.Category) + "</category>\n" : "") +
"\t\t<version>" + HttpUtility.HtmlEncode(datFile.Version) + "</version>\n" +
(!String.IsNullOrEmpty(datFile.Date) ? "\t\t<date>" + HttpUtility.HtmlEncode(datFile.Date) + "</date>\n" : "") +
"\t\t<author>" + HttpUtility.HtmlEncode(datFile.Author) + "</author>\n" +
(!String.IsNullOrEmpty(datFile.Comment) ? "\t\t<comment>" + HttpUtility.HtmlEncode(datFile.Comment) + "</comment>\n" : "") +
(!String.IsNullOrEmpty(datFile.Type) || datFile.ForcePacking != ForcePacking.None || datFile.ForceMerging != ForceMerging.None || datFile.ForceNodump != ForceNodump.None ?
"\t\t<name>" + HttpUtility.HtmlEncode(Name) + "</name>\n" +
"\t\t<description>" + HttpUtility.HtmlEncode(Description) + "</description>\n" +
(!String.IsNullOrEmpty(RootDir) ? "\t\t<rootdir>" + HttpUtility.HtmlEncode(RootDir) + "</rootdir>\n" : "") +
(!String.IsNullOrEmpty(Category) ? "\t\t<category>" + HttpUtility.HtmlEncode(Category) + "</category>\n" : "") +
"\t\t<version>" + HttpUtility.HtmlEncode(Version) + "</version>\n" +
(!String.IsNullOrEmpty(Date) ? "\t\t<date>" + HttpUtility.HtmlEncode(Date) + "</date>\n" : "") +
"\t\t<author>" + HttpUtility.HtmlEncode(Author) + "</author>\n" +
(!String.IsNullOrEmpty(Comment) ? "\t\t<comment>" + HttpUtility.HtmlEncode(Comment) + "</comment>\n" : "") +
(!String.IsNullOrEmpty(Type) || ForcePacking != ForcePacking.None || ForceMerging != ForceMerging.None || ForceNodump != ForceNodump.None ?
"\t\t<flags>\n" +
(!String.IsNullOrEmpty(datFile.Type) ? "\t\t\t<flag name=\"type\" value=\"" + HttpUtility.HtmlEncode(datFile.Type) + "\"/>\n" : "") +
(datFile.ForcePacking == ForcePacking.Unzip ? "\t\t\t<flag name=\"forcepacking\" value=\"unzip\"/>\n" : "") +
(datFile.ForcePacking == ForcePacking.Zip ? "\t\t\t<flag name=\"forcepacking\" value=\"zip\"/>\n" : "") +
(datFile.ForceMerging == ForceMerging.Full ? "\t\t\t<flag name=\"forcemerging\" value=\"full\"/>\n" : "") +
(datFile.ForceMerging == ForceMerging.Split ? "\t\t\t<flag name=\"forcemerging\" value=\"split\"/>\n" : "") +
(datFile.ForceMerging == ForceMerging.Merged ? "\t\t\t<flag name=\"forcemerging\" value=\"merged\"/>\n" : "") +
(datFile.ForceMerging == ForceMerging.NonMerged ? "\t\t\t<flag name=\"forcemerging\" value=\"nonmerged\"/>\n" : "") +
(datFile.ForceNodump == ForceNodump.Ignore ? "\t\t\t<flag name=\"forcenodump\" value=\"ignore\"/>\n" : "") +
(datFile.ForceNodump == ForceNodump.Obsolete ? "\t\t\t<flag name=\"forcenodump\" value=\"obsolete\"/>\n" : "") +
(datFile.ForceNodump == ForceNodump.Required ? "\t\t\t<flag name=\"forcenodump\" value=\"required\"/>\n" : "") +
(!String.IsNullOrEmpty(Type) ? "\t\t\t<flag name=\"type\" value=\"" + HttpUtility.HtmlEncode(Type) + "\"/>\n" : "") +
(ForcePacking == ForcePacking.Unzip ? "\t\t\t<flag name=\"forcepacking\" value=\"unzip\"/>\n" : "") +
(ForcePacking == ForcePacking.Zip ? "\t\t\t<flag name=\"forcepacking\" value=\"zip\"/>\n" : "") +
(ForceMerging == ForceMerging.Full ? "\t\t\t<flag name=\"forcemerging\" value=\"full\"/>\n" : "") +
(ForceMerging == ForceMerging.Split ? "\t\t\t<flag name=\"forcemerging\" value=\"split\"/>\n" : "") +
(ForceMerging == ForceMerging.Merged ? "\t\t\t<flag name=\"forcemerging\" value=\"merged\"/>\n" : "") +
(ForceMerging == ForceMerging.NonMerged ? "\t\t\t<flag name=\"forcemerging\" value=\"nonmerged\"/>\n" : "") +
(ForceNodump == ForceNodump.Ignore ? "\t\t\t<flag name=\"forcenodump\" value=\"ignore\"/>\n" : "") +
(ForceNodump == ForceNodump.Obsolete ? "\t\t\t<flag name=\"forcenodump\" value=\"obsolete\"/>\n" : "") +
(ForceNodump == ForceNodump.Required ? "\t\t\t<flag name=\"forcenodump\" value=\"required\"/>\n" : "") +
"\t\t</flags>\n"
: "") +
"\t</header>\n" +
@@ -226,7 +215,7 @@ namespace SabreTools.Library.DatFiles
/// <param name="depth">Current depth to output file at (SabreDAT only)</param>
/// <param name="last">Last known depth to cycle back from (SabreDAT only)</param>
/// <returns>The new depth of the tag</returns>
private static int WriteStartGame(StreamWriter sw, DatItem rom, List<string> newsplit, string lastgame, int depth, int last)
private int WriteStartGame(StreamWriter sw, DatItem rom, List<string> newsplit, string lastgame, int depth, int last)
{
try
{
@@ -269,7 +258,7 @@ namespace SabreTools.Library.DatFiles
/// <param name="depth">Current depth to output file at (SabreDAT only)</param>
/// <param name="last">Last known depth to cycle back from (SabreDAT only)</param>
/// <returns>The new depth of the tag</returns>
private static int WriteEndGame(StreamWriter sw, List<string> splitpath, List<string> newsplit, int depth, out int last)
private int WriteEndGame(StreamWriter sw, List<string> splitpath, List<string> newsplit, int depth, out int last)
{
last = 0;
@@ -325,7 +314,7 @@ namespace SabreTools.Library.DatFiles
/// <param name="depth">Current depth to output file at (SabreDAT only)</param>
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param>
/// <returns>True if the data was written, false on error</returns>
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
/// <param name="sw">StreamWriter to output to</param>
/// <param name="depth">Current depth to output file at (SabreDAT only)</param>
/// <returns>True if the data was written, false on error</returns>
private static bool WriteFooter(StreamWriter sw, int depth)
private bool WriteFooter(StreamWriter sw, int depth)
{
try
{

View File

@@ -21,12 +21,11 @@ namespace SabreTools.Library.DatFiles
/// <summary>
/// Represents parsing and writing of a value-separated DAT
/// </summary>
public class SeparatedValue
public class SeparatedValue : DatFile
{
/// <summary>
/// Parse a character-separated value DAT and return all found games and roms within
/// </summary>
/// <param name="datFile">DatFile to populate with the read information</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="sysid">System ID for the DAT</param>
/// <param name="srcid">Source ID for the DAT</param>
@@ -34,9 +33,7 @@ namespace SabreTools.Library.DatFiles
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
/// <param name="clean">True if game names are sanitized, false otherwise (default)</param>
/// <param name="remUnicode">True if we should remove non-ASCII characters from output, false otherwise (default)</param>
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
/// <summary>
/// Create and open an output file for writing direct from a dictionary
/// </summary>
/// <param name="datFile">DatFile to write out from</param>
/// <param name="outfile">Name of the file to write to</param>
/// <param name="delim">Delimiter for parsing individual lines</param>
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param>
/// <returns>True if the DAT was written correctly, false otherwise</returns>
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<string> keys = datFile.Keys.ToList();
List<string> keys = Keys.ToList();
keys.Sort(new NaturalComparer());
foreach (string key in keys)
{
List<DatItem> roms = datFile[key];
List<DatItem> 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
/// <param name="sw">StreamWriter to output to</param>
/// <param name="delim">Delimiter for parsing individual lines</param>
/// <returns>True if the data was written, false on error</returns>
private static bool WriteHeader(StreamWriter sw, char delim)
private bool WriteHeader(StreamWriter sw, char delim)
{
try
{
@@ -460,13 +456,12 @@ namespace SabreTools.Library.DatFiles
/// <summary>
/// Write out RomData using the supplied StreamWriter
/// </summary>
/// <param name="datFile">DatFile to write out from</param>
/// <param name="sw">StreamWriter to output to</param>
/// <param name="delim">Delimiter for parsing individual lines</param>
/// <param name="rom">RomData object to be output</param>
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param>
/// <returns>True if the data was written, false on error</returns>
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\""

View File

@@ -23,12 +23,11 @@ namespace SabreTools.Library.DatFiles
/// <summary>
/// Represents parsing and writing of an SabreDat XML DAT
/// </summary>
public class SoftwareList
public class SoftwareList : DatFile
{
/// <summary>
/// Parse an SabreDat XML DAT and return all found games and roms within
/// </summary>
/// <param name="datFile">DatFile to populate with the read information</param>
/// <param name="filename">Name of the file to be parsed</param>
/// <param name="sysid">System ID for the DAT</param>
/// <param name="srcid">Source ID for the DAT</param>
@@ -37,7 +36,7 @@ namespace SabreTools.Library.DatFiles
/// <param name="remUnicode">True if we should remove non-ASCII characters from output, false otherwise (default)</param>
/// <remarks>
/// </remarks>
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);
}
/// <summary>
/// Create and open an output file for writing direct from a dictionary
/// </summary>
/// <param name="datFile">DatFile to write out from</param>
/// <param name="outfile">Name of the file to write to</param>
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param>
/// <returns>True if the DAT was written correctly, false otherwise</returns>
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<string> keys = datFile.Keys.ToList();
List<string> keys = Keys.ToList();
keys.Sort(new NaturalComparer());
foreach (string key in keys)
{
List<DatItem> roms = datFile[key];
List<DatItem> 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
/// <summary>
/// Write out DAT header using the supplied StreamWriter
/// </summary>
/// <param name="datFile">DatFile to write out from</param>
/// <param name="sw">StreamWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private static bool WriteHeader(DatFile datFile, StreamWriter sw)
private bool WriteHeader(StreamWriter sw)
{
try
{
string header = "<?xml version=\"1.0\"?>\n" +
"<!DOCTYPE softwarelist SYSTEM \"softwarelist.dtd\">\n\n" +
"<softwarelist name=\"" + HttpUtility.HtmlEncode(datFile.Name) + "\"" +
" description=\"" + HttpUtility.HtmlEncode(datFile.Description) + "\"" +
(datFile.ForcePacking == ForcePacking.Unzip ? " forcepacking=\"unzip\"" : "") +
(datFile.ForcePacking == ForcePacking.Zip ? " forcepacking=\"zip\"" : "") +
(datFile.ForceMerging == ForceMerging.Full ? " forcemerging=\"full\"" : "") +
(datFile.ForceMerging == ForceMerging.Split ? " forcemerging=\"split\"" : "") +
(datFile.ForceMerging == ForceMerging.Merged ? " forcemerging=\"merged\"" : "") +
(datFile.ForceMerging == ForceMerging.NonMerged ? " forcemerging=\"nonmerged\"" : "") +
(datFile.ForceNodump == ForceNodump.Ignore ? " forcenodump=\"ignore\"" : "") +
(datFile.ForceNodump == ForceNodump.Obsolete ? " forcenodump=\"obsolete\"" : "") +
(datFile.ForceNodump == ForceNodump.Required ? " forcenodump=\"required\"" : "") +
"<softwarelist name=\"" + HttpUtility.HtmlEncode(Name) + "\"" +
" description=\"" + HttpUtility.HtmlEncode(Description) + "\"" +
(ForcePacking == ForcePacking.Unzip ? " forcepacking=\"unzip\"" : "") +
(ForcePacking == ForcePacking.Zip ? " forcepacking=\"zip\"" : "") +
(ForceMerging == ForceMerging.Full ? " forcemerging=\"full\"" : "") +
(ForceMerging == ForceMerging.Split ? " forcemerging=\"split\"" : "") +
(ForceMerging == ForceMerging.Merged ? " forcemerging=\"merged\"" : "") +
(ForceMerging == ForceMerging.NonMerged ? " forcemerging=\"nonmerged\"" : "") +
(ForceNodump == ForceNodump.Ignore ? " forcenodump=\"ignore\"" : "") +
(ForceNodump == ForceNodump.Obsolete ? " forcenodump=\"obsolete\"" : "") +
(ForceNodump == ForceNodump.Required ? " forcenodump=\"required\"" : "") +
">\n\n";
// Write the header out
@@ -193,11 +190,10 @@ namespace SabreTools.Library.DatFiles
/// <summary>
/// Write out Game start using the supplied StreamWriter
/// </summary>
/// <param name="datFile">DatFile to write out from</param>
/// <param name="sw">StreamWriter to output to</param>
/// <param name="rom">RomData object to be output</param>
/// <returns>True if the data was written, false on error</returns>
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<software name=\"" + HttpUtility.HtmlEncode(rom.MachineName) + "\""
+ (rom.Supported != null ? " supported=\"" + (rom.Supported == true ? "yes" : "no") + "\"" : "") +
(datFile.ExcludeOf ? "" :
(ExcludeOf ? "" :
(String.IsNullOrEmpty(rom.CloneOf) || (rom.MachineName.ToLowerInvariant() == rom.CloneOf.ToLowerInvariant())
? ""
: " cloneof=\"" + HttpUtility.HtmlEncode(rom.CloneOf) + "\"") +
@@ -246,7 +242,7 @@ namespace SabreTools.Library.DatFiles
/// </summary>
/// <param name="sw">StreamWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private static bool WriteEndGame(StreamWriter sw)
private bool WriteEndGame(StreamWriter sw)
{
try
{
@@ -271,7 +267,7 @@ namespace SabreTools.Library.DatFiles
/// <param name="rom">RomData object to be output</param>
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param>
/// <returns>True if the data was written, false on error</returns>
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
/// </summary>
/// <param name="sw">StreamWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private static bool WriteFooter(StreamWriter sw)
private bool WriteFooter(StreamWriter sw)
{
try
{