mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[DatFiles/] Make all DatFile types actually inherit from DatFile
This commit is contained in:
@@ -23,21 +23,18 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents parsing and writing of an AttractMode DAT
|
/// Represents parsing and writing of an AttractMode DAT
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class AttractMode
|
public class AttractMode : DatFile
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parse an AttractMode DAT and return all found games within
|
/// Parse an AttractMode DAT and return all found games within
|
||||||
/// </summary>
|
/// </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="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="sysid">System ID for the DAT</param>
|
/// <param name="sysid">System ID for the DAT</param>
|
||||||
/// <param name="srcid">Source 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="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="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>
|
/// <param name="remUnicode">True if we should remove non-ASCII characters from output, false otherwise (default)</param>
|
||||||
public static void Parse(
|
public void Parse(
|
||||||
DatFile datFile,
|
|
||||||
|
|
||||||
// Standard Dat parsing
|
// Standard Dat parsing
|
||||||
string filename,
|
string filename,
|
||||||
int sysid,
|
int sysid,
|
||||||
@@ -98,7 +95,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Now process and add the rom
|
// Now process and add the rom
|
||||||
datFile.ParseAddHelper(rom, clean, remUnicode);
|
ParseAddHelper(rom, clean, remUnicode);
|
||||||
}
|
}
|
||||||
|
|
||||||
sr.Dispose();
|
sr.Dispose();
|
||||||
@@ -107,10 +104,9 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create and open an output file for writing direct from a dictionary
|
/// Create and open an output file for writing direct from a dictionary
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="datFile">DatFile to write out from</param>
|
|
||||||
/// <param name="outfile">Name of the file to write to</param>
|
/// <param name="outfile">Name of the file to write to</param>
|
||||||
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
/// <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
|
try
|
||||||
{
|
{
|
||||||
@@ -133,12 +129,12 @@ namespace SabreTools.Library.DatFiles
|
|||||||
string lastgame = null;
|
string lastgame = null;
|
||||||
|
|
||||||
// Get a properly sorted set of keys
|
// Get a properly sorted set of keys
|
||||||
List<string> keys = datFile.Keys.ToList();
|
List<string> keys = Keys.ToList();
|
||||||
keys.Sort(new NaturalComparer());
|
keys.Sort(new NaturalComparer());
|
||||||
|
|
||||||
foreach (string key in keys)
|
foreach (string key in keys)
|
||||||
{
|
{
|
||||||
List<DatItem> roms = datFile[key];
|
List<DatItem> roms = this[key];
|
||||||
|
|
||||||
// Resolve the names in the block
|
// Resolve the names in the block
|
||||||
roms = DatItem.ResolveNames(roms);
|
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 we have a new game, output the beginning of the new item
|
||||||
if (lastgame == null || lastgame.ToLowerInvariant() != item.MachineName.ToLowerInvariant())
|
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
|
// 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>
|
/// </summary>
|
||||||
/// <param name="sw">StreamWriter to output to</param>
|
/// <param name="sw">StreamWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
/// <returns>True if the data was written, false on error</returns>
|
||||||
private static bool WriteHeader(StreamWriter sw)
|
private bool WriteHeader(StreamWriter sw)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -222,11 +218,10 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out Game start using the supplied StreamWriter
|
/// Write out Game start using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="datFile">DatFile to write out from</param>
|
|
||||||
/// <param name="sw">StreamWriter to output to</param>
|
/// <param name="sw">StreamWriter to output to</param>
|
||||||
/// <param name="rom">RomData object to be output</param>
|
/// <param name="rom">RomData object to be output</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
/// <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
|
try
|
||||||
{
|
{
|
||||||
@@ -238,7 +233,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
string state = rom.MachineName + ";"
|
string state = rom.MachineName + ";"
|
||||||
+ rom.MachineDescription + ";"
|
+ rom.MachineDescription + ";"
|
||||||
+ datFile.FileName + ";"
|
+ FileName + ";"
|
||||||
+ rom.CloneOf + ";"
|
+ rom.CloneOf + ";"
|
||||||
+ rom.Year + ";"
|
+ rom.Year + ";"
|
||||||
+ rom.Manufacturer + ";"
|
+ rom.Manufacturer + ";"
|
||||||
|
|||||||
@@ -24,21 +24,18 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents parsing and writing of a ClrMamePro DAT
|
/// Represents parsing and writing of a ClrMamePro DAT
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ClrMamePro
|
public class ClrMamePro : DatFile
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parse a ClrMamePro DAT and return all found games and roms within
|
/// Parse a ClrMamePro DAT and return all found games and roms within
|
||||||
/// </summary>
|
/// </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="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="sysid">System ID for the DAT</param>
|
/// <param name="sysid">System ID for the DAT</param>
|
||||||
/// <param name="srcid">Source 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="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="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>
|
/// <param name="remUnicode">True if we should remove non-ASCII characters from output, false otherwise (default)</param>
|
||||||
public static void Parse(
|
public void Parse(
|
||||||
DatFile datFile,
|
|
||||||
|
|
||||||
// Standard Dat parsing
|
// Standard Dat parsing
|
||||||
string filename,
|
string filename,
|
||||||
int sysid,
|
int sysid,
|
||||||
@@ -148,7 +145,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
item.Name = line;
|
item.Name = line;
|
||||||
|
|
||||||
// Now process and add the sample
|
// Now process and add the sample
|
||||||
datFile.ParseAddHelper(item, clean, remUnicode);
|
ParseAddHelper(item, clean, remUnicode);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -232,7 +229,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now process and add the rom
|
// Now process and add the rom
|
||||||
datFile.ParseAddHelper(item, clean, remUnicode);
|
ParseAddHelper(item, clean, remUnicode);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -444,7 +441,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now process and add the rom
|
// 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
|
// 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:"))
|
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");
|
superdat = superdat || itemval.Contains(" - SuperDAT");
|
||||||
if (keep && superdat)
|
if (keep && superdat)
|
||||||
{
|
{
|
||||||
datFile.Type = (String.IsNullOrEmpty(datFile.Type) ? "SuperDAT" : datFile.Type);
|
Type = (String.IsNullOrEmpty(Type) ? "SuperDAT" : Type);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -499,103 +496,103 @@ namespace SabreTools.Library.DatFiles
|
|||||||
{
|
{
|
||||||
case "name":
|
case "name":
|
||||||
case "Name:":
|
case "Name:":
|
||||||
datFile.Name = (String.IsNullOrEmpty(datFile.Name) ? itemval : datFile.Name);
|
Name = (String.IsNullOrEmpty(Name) ? itemval : Name);
|
||||||
superdat = superdat || itemval.Contains(" - SuperDAT");
|
superdat = superdat || itemval.Contains(" - SuperDAT");
|
||||||
if (keep && superdat)
|
if (keep && superdat)
|
||||||
{
|
{
|
||||||
datFile.Type = (String.IsNullOrEmpty(datFile.Type) ? "SuperDAT" : datFile.Type);
|
Type = (String.IsNullOrEmpty(Type) ? "SuperDAT" : Type);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "description":
|
case "description":
|
||||||
case "Description:":
|
case "Description:":
|
||||||
datFile.Description = (String.IsNullOrEmpty(datFile.Description) ? itemval : datFile.Description);
|
Description = (String.IsNullOrEmpty(Description) ? itemval : Description);
|
||||||
break;
|
break;
|
||||||
case "rootdir":
|
case "rootdir":
|
||||||
datFile.RootDir = (String.IsNullOrEmpty(datFile.RootDir) ? itemval : datFile.RootDir);
|
RootDir = (String.IsNullOrEmpty(RootDir) ? itemval : RootDir);
|
||||||
break;
|
break;
|
||||||
case "category":
|
case "category":
|
||||||
datFile.Category = (String.IsNullOrEmpty(datFile.Category) ? itemval : datFile.Category);
|
Category = (String.IsNullOrEmpty(Category) ? itemval : Category);
|
||||||
break;
|
break;
|
||||||
case "version":
|
case "version":
|
||||||
case "Version:":
|
case "Version:":
|
||||||
datFile.Version = (String.IsNullOrEmpty(datFile.Version) ? itemval : datFile.Version);
|
Version = (String.IsNullOrEmpty(Version) ? itemval : Version);
|
||||||
break;
|
break;
|
||||||
case "date":
|
case "date":
|
||||||
case "Date:":
|
case "Date:":
|
||||||
datFile.Date = (String.IsNullOrEmpty(datFile.Date) ? itemval : datFile.Date);
|
Date = (String.IsNullOrEmpty(Date) ? itemval : Date);
|
||||||
break;
|
break;
|
||||||
case "author":
|
case "author":
|
||||||
case "Author:":
|
case "Author:":
|
||||||
datFile.Author = (String.IsNullOrEmpty(datFile.Author) ? itemval : datFile.Author);
|
Author = (String.IsNullOrEmpty(Author) ? itemval : Author);
|
||||||
break;
|
break;
|
||||||
case "email":
|
case "email":
|
||||||
datFile.Email = (String.IsNullOrEmpty(datFile.Email) ? itemval : datFile.Email);
|
Email = (String.IsNullOrEmpty(Email) ? itemval : Email);
|
||||||
break;
|
break;
|
||||||
case "homepage":
|
case "homepage":
|
||||||
case "Homepage:":
|
case "Homepage:":
|
||||||
datFile.Homepage = (String.IsNullOrEmpty(datFile.Homepage) ? itemval : datFile.Homepage);
|
Homepage = (String.IsNullOrEmpty(Homepage) ? itemval : Homepage);
|
||||||
break;
|
break;
|
||||||
case "url":
|
case "url":
|
||||||
datFile.Url = (String.IsNullOrEmpty(datFile.Url) ? itemval : datFile.Url);
|
Url = (String.IsNullOrEmpty(Url) ? itemval : Url);
|
||||||
break;
|
break;
|
||||||
case "comment":
|
case "comment":
|
||||||
case "Comment:":
|
case "Comment:":
|
||||||
datFile.Comment = (String.IsNullOrEmpty(datFile.Comment) ? itemval : datFile.Comment);
|
Comment = (String.IsNullOrEmpty(Comment) ? itemval : Comment);
|
||||||
break;
|
break;
|
||||||
case "header":
|
case "header":
|
||||||
datFile.Header = (String.IsNullOrEmpty(datFile.Header) ? itemval : datFile.Header);
|
Header = (String.IsNullOrEmpty(Header) ? itemval : Header);
|
||||||
break;
|
break;
|
||||||
case "type":
|
case "type":
|
||||||
datFile.Type = (String.IsNullOrEmpty(datFile.Type) ? itemval : datFile.Type);
|
Type = (String.IsNullOrEmpty(Type) ? itemval : Type);
|
||||||
superdat = superdat || itemval.Contains("SuperDAT");
|
superdat = superdat || itemval.Contains("SuperDAT");
|
||||||
break;
|
break;
|
||||||
case "forcemerging":
|
case "forcemerging":
|
||||||
if (datFile.ForceMerging == ForceMerging.None)
|
if (ForceMerging == ForceMerging.None)
|
||||||
{
|
{
|
||||||
switch (itemval)
|
switch (itemval)
|
||||||
{
|
{
|
||||||
case "none":
|
case "none":
|
||||||
datFile.ForceMerging = ForceMerging.None;
|
ForceMerging = ForceMerging.None;
|
||||||
break;
|
break;
|
||||||
case "split":
|
case "split":
|
||||||
datFile.ForceMerging = ForceMerging.Split;
|
ForceMerging = ForceMerging.Split;
|
||||||
break;
|
break;
|
||||||
case "merged":
|
case "merged":
|
||||||
datFile.ForceMerging = ForceMerging.Merged;
|
ForceMerging = ForceMerging.Merged;
|
||||||
break;
|
break;
|
||||||
case "nonmerged":
|
case "nonmerged":
|
||||||
datFile.ForceMerging = ForceMerging.NonMerged;
|
ForceMerging = ForceMerging.NonMerged;
|
||||||
break;
|
break;
|
||||||
case "full":
|
case "full":
|
||||||
datFile.ForceMerging = ForceMerging.Full;
|
ForceMerging = ForceMerging.Full;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "forcezipping":
|
case "forcezipping":
|
||||||
if (datFile.ForcePacking == ForcePacking.None)
|
if (ForcePacking == ForcePacking.None)
|
||||||
{
|
{
|
||||||
switch (itemval)
|
switch (itemval)
|
||||||
{
|
{
|
||||||
case "yes":
|
case "yes":
|
||||||
datFile.ForcePacking = ForcePacking.Zip;
|
ForcePacking = ForcePacking.Zip;
|
||||||
break;
|
break;
|
||||||
case "no":
|
case "no":
|
||||||
datFile.ForcePacking = ForcePacking.Unzip;
|
ForcePacking = ForcePacking.Unzip;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "forcepacking":
|
case "forcepacking":
|
||||||
if (datFile.ForcePacking == ForcePacking.None)
|
if (ForcePacking == ForcePacking.None)
|
||||||
{
|
{
|
||||||
switch (itemval)
|
switch (itemval)
|
||||||
{
|
{
|
||||||
case "zip":
|
case "zip":
|
||||||
datFile.ForcePacking = ForcePacking.Zip;
|
ForcePacking = ForcePacking.Zip;
|
||||||
break;
|
break;
|
||||||
case "unzip":
|
case "unzip":
|
||||||
datFile.ForcePacking = ForcePacking.Unzip;
|
ForcePacking = ForcePacking.Unzip;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -619,11 +616,10 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create and open an output file for writing direct from a dictionary
|
/// Create and open an output file for writing direct from a dictionary
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="datFile">DatFile to write out from</param>
|
|
||||||
/// <param name="outfile">Name of the file to write to</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>
|
/// <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>
|
/// <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
|
try
|
||||||
{
|
{
|
||||||
@@ -640,18 +636,18 @@ namespace SabreTools.Library.DatFiles
|
|||||||
StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(true));
|
StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(true));
|
||||||
|
|
||||||
// Write out the header
|
// Write out the header
|
||||||
WriteHeader(datFile, sw);
|
WriteHeader(sw);
|
||||||
|
|
||||||
// Write out each of the machines and roms
|
// Write out each of the machines and roms
|
||||||
string lastgame = null;
|
string lastgame = null;
|
||||||
|
|
||||||
// Get a properly sorted set of keys
|
// Get a properly sorted set of keys
|
||||||
List<string> keys = datFile.Keys.ToList();
|
List<string> keys = Keys.ToList();
|
||||||
keys.Sort(new NaturalComparer());
|
keys.Sort(new NaturalComparer());
|
||||||
|
|
||||||
foreach (string key in keys)
|
foreach (string key in keys)
|
||||||
{
|
{
|
||||||
List<DatItem> roms = datFile[key];
|
List<DatItem> roms = this[key];
|
||||||
|
|
||||||
// Resolve the names in the block
|
// Resolve the names in the block
|
||||||
roms = DatItem.ResolveNames(roms);
|
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 we have a new game, output the beginning of the new item
|
||||||
if (lastgame == null || lastgame.ToLowerInvariant() != rom.MachineName.ToLowerInvariant())
|
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
|
// 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>
|
/// <summary>
|
||||||
/// Write out DAT header using the supplied StreamWriter
|
/// Write out DAT header using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="datFile">DatFile to write out from</param>
|
|
||||||
/// <param name="sw">StreamWriter to output to</param>
|
/// <param name="sw">StreamWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
/// <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
|
try
|
||||||
{
|
{
|
||||||
string header = "clrmamepro (\n" +
|
string header = "clrmamepro (\n" +
|
||||||
"\tname \"" + datFile.Name + "\"\n" +
|
"\tname \"" + Name + "\"\n" +
|
||||||
"\tdescription \"" + datFile.Description + "\"\n" +
|
"\tdescription \"" + Description + "\"\n" +
|
||||||
(!String.IsNullOrEmpty(datFile.Category) ? "\tcategory \"" + datFile.Category + "\"\n" : "") +
|
(!String.IsNullOrEmpty(Category) ? "\tcategory \"" + Category + "\"\n" : "") +
|
||||||
"\tversion \"" + datFile.Version + "\"\n" +
|
"\tversion \"" + Version + "\"\n" +
|
||||||
(!String.IsNullOrEmpty(datFile.Date) ? "\tdate \"" + datFile.Date + "\"\n" : "") +
|
(!String.IsNullOrEmpty(Date) ? "\tdate \"" + Date + "\"\n" : "") +
|
||||||
"\tauthor \"" + datFile.Author + "\"\n" +
|
"\tauthor \"" + Author + "\"\n" +
|
||||||
(!String.IsNullOrEmpty(datFile.Email) ? "\temail \"" + datFile.Email + "\"\n" : "") +
|
(!String.IsNullOrEmpty(Email) ? "\temail \"" + Email + "\"\n" : "") +
|
||||||
(!String.IsNullOrEmpty(datFile.Homepage) ? "\thomepage \"" + datFile.Homepage + "\"\n" : "") +
|
(!String.IsNullOrEmpty(Homepage) ? "\thomepage \"" + Homepage + "\"\n" : "") +
|
||||||
(!String.IsNullOrEmpty(datFile.Url) ? "\turl \"" + datFile.Url + "\"\n" : "") +
|
(!String.IsNullOrEmpty(Url) ? "\turl \"" + Url + "\"\n" : "") +
|
||||||
(!String.IsNullOrEmpty(datFile.Comment) ? "\tcomment \"" + datFile.Comment + "\"\n" : "") +
|
(!String.IsNullOrEmpty(Comment) ? "\tcomment \"" + Comment + "\"\n" : "") +
|
||||||
(datFile.ForcePacking == ForcePacking.Unzip ? "\tforcezipping no\n" : "") +
|
(ForcePacking == ForcePacking.Unzip ? "\tforcezipping no\n" : "") +
|
||||||
(datFile.ForcePacking == ForcePacking.Zip ? "\tforcezipping yes\n" : "") +
|
(ForcePacking == ForcePacking.Zip ? "\tforcezipping yes\n" : "") +
|
||||||
(datFile.ForceMerging == ForceMerging.Full ? "\tforcemerging full\n" : "") +
|
(ForceMerging == ForceMerging.Full ? "\tforcemerging full\n" : "") +
|
||||||
(datFile.ForceMerging == ForceMerging.Split ? "\tforcemerging split\n" : "") +
|
(ForceMerging == ForceMerging.Split ? "\tforcemerging split\n" : "") +
|
||||||
(datFile.ForceMerging == ForceMerging.Merged ? "\tforcemerging merged\n" : "") +
|
(ForceMerging == ForceMerging.Merged ? "\tforcemerging merged\n" : "") +
|
||||||
(datFile.ForceMerging == ForceMerging.NonMerged ? "\tforcemerging nonmerged\n" : "") +
|
(ForceMerging == ForceMerging.NonMerged ? "\tforcemerging nonmerged\n" : "") +
|
||||||
")\n";
|
")\n";
|
||||||
|
|
||||||
// Write the header out
|
// Write the header out
|
||||||
@@ -766,11 +761,10 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out Game start using the supplied StreamWriter
|
/// Write out Game start using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="datFile">DatFile to write out from</param>
|
|
||||||
/// <param name="sw">StreamWriter to output to</param>
|
/// <param name="sw">StreamWriter to output to</param>
|
||||||
/// <param name="rom">RomData object to be output</param>
|
/// <param name="rom">RomData object to be output</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
/// <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
|
try
|
||||||
{
|
{
|
||||||
@@ -781,7 +775,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
}
|
}
|
||||||
|
|
||||||
string state = "game (\n\tname \"" + rom.MachineName + "\"\n" +
|
string state = "game (\n\tname \"" + rom.MachineName + "\"\n" +
|
||||||
(datFile.ExcludeOf ? "" :
|
(ExcludeOf ? "" :
|
||||||
(String.IsNullOrEmpty(rom.RomOf) ? "" : "\tromof \"" + rom.RomOf + "\"\n") +
|
(String.IsNullOrEmpty(rom.RomOf) ? "" : "\tromof \"" + rom.RomOf + "\"\n") +
|
||||||
(String.IsNullOrEmpty(rom.CloneOf) ? "" : "\tcloneof \"" + rom.CloneOf + "\"\n") +
|
(String.IsNullOrEmpty(rom.CloneOf) ? "" : "\tcloneof \"" + rom.CloneOf + "\"\n") +
|
||||||
(String.IsNullOrEmpty(rom.SampleOf) ? "" : "\tsampleof \"" + rom.SampleOf + "\"\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="sw">StreamWriter to output to</param>
|
||||||
/// <param name="rom">RomData object to be output</param>
|
/// <param name="rom">RomData object to be output</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
/// <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
|
try
|
||||||
{
|
{
|
||||||
@@ -834,7 +828,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="rom">RomData object to be output</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>
|
/// <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>
|
/// <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 we are in ignore blanks mode AND we have a blank (0-size) rom, skip
|
||||||
if (ignoreblanks
|
if (ignoreblanks
|
||||||
@@ -917,7 +911,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sw">StreamWriter to output to</param>
|
/// <param name="sw">StreamWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
/// <returns>True if the data was written, false on error</returns>
|
||||||
private static bool WriteFooter(StreamWriter sw)
|
private bool WriteFooter(StreamWriter sw)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1529,55 +1529,55 @@ namespace SabreTools.Library.DatFiles
|
|||||||
switch (FileTools.GetDatFormat(filename))
|
switch (FileTools.GetDatFormat(filename))
|
||||||
{
|
{
|
||||||
case DatFormat.AttractMode:
|
case DatFormat.AttractMode:
|
||||||
AttractMode.Parse(this, filename, sysid, srcid, keep, clean, remUnicode);
|
(this as AttractMode).Parse(filename, sysid, srcid, keep, clean, remUnicode);
|
||||||
break;
|
break;
|
||||||
case DatFormat.ClrMamePro:
|
case DatFormat.ClrMamePro:
|
||||||
ClrMamePro.Parse(this, filename, sysid, srcid, keep, clean, remUnicode);
|
(this as ClrMamePro).Parse(filename, sysid, srcid, keep, clean, remUnicode);
|
||||||
break;
|
break;
|
||||||
case DatFormat.CSV:
|
case DatFormat.CSV:
|
||||||
SeparatedValue.Parse(this, filename, sysid, srcid, ',', keep, clean, remUnicode);
|
(this as SeparatedValue).Parse(filename, sysid, srcid, ',', keep, clean, remUnicode);
|
||||||
break;
|
break;
|
||||||
case DatFormat.DOSCenter:
|
case DatFormat.DOSCenter:
|
||||||
DosCenter.Parse(this, filename, sysid, srcid, keep, clean, remUnicode);
|
(this as DosCenter).Parse(filename, sysid, srcid, keep, clean, remUnicode);
|
||||||
break;
|
break;
|
||||||
case DatFormat.Listroms:
|
case DatFormat.Listroms:
|
||||||
Listroms.Parse(this, filename, sysid, srcid, keep, clean, remUnicode);
|
(this as Listroms).Parse(filename, sysid, srcid, keep, clean, remUnicode);
|
||||||
break;
|
break;
|
||||||
case DatFormat.Logiqx:
|
case DatFormat.Logiqx:
|
||||||
Logiqx.Parse(this, filename, sysid, srcid, keep, clean, remUnicode);
|
(this as Logiqx).Parse(filename, sysid, srcid, keep, clean, remUnicode);
|
||||||
break;
|
break;
|
||||||
case DatFormat.OfflineList:
|
case DatFormat.OfflineList:
|
||||||
OfflineList.Parse(this, filename, sysid, srcid, keep, clean, remUnicode);
|
(this as OfflineList).Parse(filename, sysid, srcid, keep, clean, remUnicode);
|
||||||
break;
|
break;
|
||||||
case DatFormat.RedumpMD5:
|
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;
|
break;
|
||||||
case DatFormat.RedumpSFV:
|
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;
|
break;
|
||||||
case DatFormat.RedumpSHA1:
|
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;
|
break;
|
||||||
case DatFormat.RedumpSHA256:
|
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;
|
break;
|
||||||
case DatFormat.RedumpSHA384:
|
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;
|
break;
|
||||||
case DatFormat.RedumpSHA512:
|
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;
|
break;
|
||||||
case DatFormat.RomCenter:
|
case DatFormat.RomCenter:
|
||||||
RomCenter.Parse(this, filename, sysid, srcid, clean, remUnicode);
|
(this as RomCenter).Parse(filename, sysid, srcid, clean, remUnicode);
|
||||||
break;
|
break;
|
||||||
case DatFormat.SabreDat:
|
case DatFormat.SabreDat:
|
||||||
SabreDat.Parse(this, filename, sysid, srcid, keep, clean, remUnicode);
|
(this as SabreDat).Parse(filename, sysid, srcid, keep, clean, remUnicode);
|
||||||
break;
|
break;
|
||||||
case DatFormat.SoftwareList:
|
case DatFormat.SoftwareList:
|
||||||
SoftwareList.Parse(this, filename, sysid, srcid, keep, clean, remUnicode);
|
(this as SoftwareList).Parse(filename, sysid, srcid, keep, clean, remUnicode);
|
||||||
break;
|
break;
|
||||||
case DatFormat.TSV:
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
@@ -1918,58 +1918,58 @@ namespace SabreTools.Library.DatFiles
|
|||||||
switch (datFormat)
|
switch (datFormat)
|
||||||
{
|
{
|
||||||
case DatFormat.AttractMode:
|
case DatFormat.AttractMode:
|
||||||
AttractMode.WriteToFile(this, outfile);
|
(this as AttractMode).WriteToFile(outfile);
|
||||||
break;
|
break;
|
||||||
case DatFormat.ClrMamePro:
|
case DatFormat.ClrMamePro:
|
||||||
ClrMamePro.WriteToFile(this, outfile, ignoreblanks);
|
(this as ClrMamePro).WriteToFile(outfile, ignoreblanks);
|
||||||
break;
|
break;
|
||||||
case DatFormat.CSV:
|
case DatFormat.CSV:
|
||||||
SeparatedValue.WriteToFile(this, outfile, ',', ignoreblanks);
|
(this as SeparatedValue).WriteToFile(outfile, ',', ignoreblanks);
|
||||||
break;
|
break;
|
||||||
case DatFormat.DOSCenter:
|
case DatFormat.DOSCenter:
|
||||||
DosCenter.WriteToFile(this, outfile, ignoreblanks);
|
(this as DosCenter).WriteToFile(outfile, ignoreblanks);
|
||||||
break;
|
break;
|
||||||
case DatFormat.Listroms:
|
case DatFormat.Listroms:
|
||||||
Listroms.WriteToFile(this, outfile, ignoreblanks);
|
(this as Listroms).WriteToFile(outfile, ignoreblanks);
|
||||||
break;
|
break;
|
||||||
case DatFormat.Logiqx:
|
case DatFormat.Logiqx:
|
||||||
Logiqx.WriteToFile(this, outfile, ignoreblanks);
|
(this as Logiqx).WriteToFile(outfile, ignoreblanks);
|
||||||
break;
|
break;
|
||||||
case DatFormat.MissFile:
|
case DatFormat.MissFile:
|
||||||
Missfile.WriteToFile(this, outfile, ignoreblanks);
|
(this as Missfile).WriteToFile(outfile, ignoreblanks);
|
||||||
break;
|
break;
|
||||||
case DatFormat.OfflineList:
|
case DatFormat.OfflineList:
|
||||||
OfflineList.WriteToFile(this, outfile, ignoreblanks);
|
(this as OfflineList).WriteToFile(outfile, ignoreblanks);
|
||||||
break;
|
break;
|
||||||
case DatFormat.RedumpMD5:
|
case DatFormat.RedumpMD5:
|
||||||
Hashfile.WriteToFile(this, outfile, Hash.MD5, ignoreblanks);
|
(this as Hashfile).WriteToFile(outfile, Hash.MD5, ignoreblanks);
|
||||||
break;
|
break;
|
||||||
case DatFormat.RedumpSFV:
|
case DatFormat.RedumpSFV:
|
||||||
Hashfile.WriteToFile(this, outfile, Hash.CRC, ignoreblanks);
|
(this as Hashfile).WriteToFile(outfile, Hash.CRC, ignoreblanks);
|
||||||
break;
|
break;
|
||||||
case DatFormat.RedumpSHA1:
|
case DatFormat.RedumpSHA1:
|
||||||
Hashfile.WriteToFile(this, outfile, Hash.SHA1, ignoreblanks);
|
(this as Hashfile).WriteToFile(outfile, Hash.SHA1, ignoreblanks);
|
||||||
break;
|
break;
|
||||||
case DatFormat.RedumpSHA256:
|
case DatFormat.RedumpSHA256:
|
||||||
Hashfile.WriteToFile(this, outfile, Hash.SHA256, ignoreblanks);
|
(this as Hashfile).WriteToFile(outfile, Hash.SHA256, ignoreblanks);
|
||||||
break;
|
break;
|
||||||
case DatFormat.RedumpSHA384:
|
case DatFormat.RedumpSHA384:
|
||||||
Hashfile.WriteToFile(this, outfile, Hash.SHA384, ignoreblanks);
|
(this as Hashfile).WriteToFile(outfile, Hash.SHA384, ignoreblanks);
|
||||||
break;
|
break;
|
||||||
case DatFormat.RedumpSHA512:
|
case DatFormat.RedumpSHA512:
|
||||||
Hashfile.WriteToFile(this, outfile, Hash.SHA512, ignoreblanks);
|
(this as Hashfile).WriteToFile(outfile, Hash.SHA512, ignoreblanks);
|
||||||
break;
|
break;
|
||||||
case DatFormat.RomCenter:
|
case DatFormat.RomCenter:
|
||||||
RomCenter.WriteToFile(this, outfile, ignoreblanks);
|
(this as RomCenter).WriteToFile(outfile, ignoreblanks);
|
||||||
break;
|
break;
|
||||||
case DatFormat.SabreDat:
|
case DatFormat.SabreDat:
|
||||||
SabreDat.WriteToFile(this, outfile, ignoreblanks);
|
(this as SabreDat).WriteToFile(outfile, ignoreblanks);
|
||||||
break;
|
break;
|
||||||
case DatFormat.SoftwareList:
|
case DatFormat.SoftwareList:
|
||||||
SoftwareList.WriteToFile(this, outfile, ignoreblanks);
|
(this as SoftwareList).WriteToFile(outfile, ignoreblanks);
|
||||||
break;
|
break;
|
||||||
case DatFormat.TSV:
|
case DatFormat.TSV:
|
||||||
SeparatedValue.WriteToFile(this, outfile, '\t', ignoreblanks);
|
(this as SeparatedValue).WriteToFile(outfile, '\t', ignoreblanks);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -22,21 +22,18 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents parsing and writing of a DosCenter DAT
|
/// Represents parsing and writing of a DosCenter DAT
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DosCenter
|
public class DosCenter : DatFile
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parse a DosCenter DAT and return all found games and roms within
|
/// Parse a DosCenter DAT and return all found games and roms within
|
||||||
/// </summary>
|
/// </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="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="sysid">System ID for the DAT</param>
|
/// <param name="sysid">System ID for the DAT</param>
|
||||||
/// <param name="srcid">Source 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="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="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>
|
/// <param name="remUnicode">True if we should remove non-ASCII characters from output, false otherwise (default)</param>
|
||||||
public static void Parse(
|
public void Parse(
|
||||||
DatFile datFile,
|
|
||||||
|
|
||||||
// Standard Dat parsing
|
// Standard Dat parsing
|
||||||
string filename,
|
string filename,
|
||||||
int sysid,
|
int sysid,
|
||||||
@@ -48,18 +45,17 @@ namespace SabreTools.Library.DatFiles
|
|||||||
bool remUnicode)
|
bool remUnicode)
|
||||||
{
|
{
|
||||||
// ClrMamePro and DosCenter parsing are identical so it just calls one implementation
|
// 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>
|
/// <summary>
|
||||||
/// Create and open an output file for writing direct from a dictionary
|
/// Create and open an output file for writing direct from a dictionary
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="datFile">DatFile to write out from</param>
|
|
||||||
/// <param name="outfile">Name of the file to write to</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>
|
/// <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>
|
/// <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
|
try
|
||||||
{
|
{
|
||||||
@@ -76,18 +72,18 @@ namespace SabreTools.Library.DatFiles
|
|||||||
StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(true));
|
StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(true));
|
||||||
|
|
||||||
// Write out the header
|
// Write out the header
|
||||||
WriteHeader(datFile, sw);
|
WriteHeader(sw);
|
||||||
|
|
||||||
// Write out each of the machines and roms
|
// Write out each of the machines and roms
|
||||||
string lastgame = null;
|
string lastgame = null;
|
||||||
|
|
||||||
// Get a properly sorted set of keys
|
// Get a properly sorted set of keys
|
||||||
List<string> keys = datFile.Keys.ToList();
|
List<string> keys = Keys.ToList();
|
||||||
keys.Sort(new NaturalComparer());
|
keys.Sort(new NaturalComparer());
|
||||||
|
|
||||||
foreach (string key in keys)
|
foreach (string key in keys)
|
||||||
{
|
{
|
||||||
List<DatItem> roms = datFile[key];
|
List<DatItem> roms = this[key];
|
||||||
|
|
||||||
// Resolve the names in the block
|
// Resolve the names in the block
|
||||||
roms = DatItem.ResolveNames(roms);
|
roms = DatItem.ResolveNames(roms);
|
||||||
@@ -161,21 +157,20 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out DAT header using the supplied StreamWriter
|
/// Write out DAT header using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="datFile">DatFile to write out from</param>
|
|
||||||
/// <param name="sw">StreamWriter to output to</param>
|
/// <param name="sw">StreamWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
/// <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
|
try
|
||||||
{
|
{
|
||||||
string header = "DOSCenter (\n" +
|
string header = "DOSCenter (\n" +
|
||||||
"\tName: " + datFile.Name + "\n" +
|
"\tName: " + Name + "\n" +
|
||||||
"\tDescription: " + datFile.Description + "\n" +
|
"\tDescription: " + Description + "\n" +
|
||||||
"\tVersion: " + datFile.Version + "\n" +
|
"\tVersion: " + Version + "\n" +
|
||||||
"\tDate: " + datFile.Date + "\n" +
|
"\tDate: " + Date + "\n" +
|
||||||
"\tAuthor: " + datFile.Author + "\n" +
|
"\tAuthor: " + Author + "\n" +
|
||||||
"\tHomepage: " + datFile.Homepage + "\n" +
|
"\tHomepage: " + Homepage + "\n" +
|
||||||
"\tComment: " + datFile.Comment + "\n" +
|
"\tComment: " + Comment + "\n" +
|
||||||
")\n";
|
")\n";
|
||||||
|
|
||||||
// Write the header out
|
// Write the header out
|
||||||
@@ -197,7 +192,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="sw">StreamWriter to output to</param>
|
/// <param name="sw">StreamWriter to output to</param>
|
||||||
/// <param name="rom">RomData object to be output</param>
|
/// <param name="rom">RomData object to be output</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
/// <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
|
try
|
||||||
{
|
{
|
||||||
@@ -227,7 +222,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="sw">StreamWriter to output to</param>
|
/// <param name="sw">StreamWriter to output to</param>
|
||||||
/// <param name="rom">RomData object to be output</param>
|
/// <param name="rom">RomData object to be output</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
/// <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
|
try
|
||||||
{
|
{
|
||||||
@@ -252,7 +247,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="rom">RomData object to be output</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>
|
/// <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>
|
/// <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 we are in ignore blanks mode AND we have a blank (0-size) rom, skip
|
||||||
if (ignoreblanks
|
if (ignoreblanks
|
||||||
@@ -300,7 +295,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sw">StreamWriter to output to</param>
|
/// <param name="sw">StreamWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
/// <returns>True if the data was written, false on error</returns>
|
||||||
private static bool WriteFooter(StreamWriter sw)
|
private bool WriteFooter(StreamWriter sw)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -23,21 +23,18 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents parsing and writing of a hashfile such as an SFV, MD5, or SHA-1 file
|
/// Represents parsing and writing of a hashfile such as an SFV, MD5, or SHA-1 file
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Hashfile
|
public class Hashfile : DatFile
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parse a hashfile or SFV and return all found games and roms within
|
/// Parse a hashfile or SFV and return all found games and roms within
|
||||||
/// </summary>
|
/// </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="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="sysid">System ID for the DAT</param>
|
/// <param name="sysid">System ID for the DAT</param>
|
||||||
/// <param name="srcid">Source 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="hashtype">Hash type that should be assumed</param>
|
||||||
/// <param name="clean">True if game names are sanitized, 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>
|
/// <param name="remUnicode">True if we should remove non-ASCII characters from output, false otherwise (default)</param>
|
||||||
public static void Parse(
|
public void Parse(
|
||||||
DatFile datFile,
|
|
||||||
|
|
||||||
// Standard Dat parsing
|
// Standard Dat parsing
|
||||||
string filename,
|
string filename,
|
||||||
int sysid,
|
int sysid,
|
||||||
@@ -95,7 +92,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Now process and add the rom
|
// Now process and add the rom
|
||||||
datFile.ParseAddHelper(rom, clean, remUnicode);
|
ParseAddHelper(rom, clean, remUnicode);
|
||||||
}
|
}
|
||||||
|
|
||||||
sr.Dispose();
|
sr.Dispose();
|
||||||
@@ -104,12 +101,11 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create and open an output file for writing direct from a dictionary
|
/// Create and open an output file for writing direct from a dictionary
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="datFile">DatFile to write out from</param>
|
|
||||||
/// <param name="outfile">Name of the file to write to</param>
|
/// <param name="outfile">Name of the file to write to</param>
|
||||||
/// <param name="hash">Hash that should be written out</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>
|
/// <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>
|
/// <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
|
try
|
||||||
{
|
{
|
||||||
@@ -126,12 +122,12 @@ namespace SabreTools.Library.DatFiles
|
|||||||
StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(true));
|
StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(true));
|
||||||
|
|
||||||
// Get a properly sorted set of keys
|
// Get a properly sorted set of keys
|
||||||
List<string> keys = datFile.Keys.ToList();
|
List<string> keys = Keys.ToList();
|
||||||
keys.Sort(new NaturalComparer());
|
keys.Sort(new NaturalComparer());
|
||||||
|
|
||||||
foreach (string key in keys)
|
foreach (string key in keys)
|
||||||
{
|
{
|
||||||
List<DatItem> roms = datFile[key];
|
List<DatItem> roms = this[key];
|
||||||
|
|
||||||
// Resolve the names in the block
|
// Resolve the names in the block
|
||||||
roms = DatItem.ResolveNames(roms);
|
roms = DatItem.ResolveNames(roms);
|
||||||
@@ -156,7 +152,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now, output the rom data
|
// 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>
|
/// <summary>
|
||||||
/// Write out RomData using the supplied StreamWriter
|
/// Write out RomData using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="datFile">DatFile to write out from</param>
|
|
||||||
/// <param name="sw">StreamWriter to output to</param>
|
/// <param name="sw">StreamWriter to output to</param>
|
||||||
/// <param name="hash">Hash that should be written out</param>
|
/// <param name="hash">Hash that should be written out</param>
|
||||||
/// <param name="rom">RomData object to be output</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>
|
/// <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>
|
/// <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 we are in ignore blanks mode AND we have a blank (0-size) rom, skip
|
||||||
if (ignoreblanks
|
if (ignoreblanks
|
||||||
@@ -200,57 +195,57 @@ namespace SabreTools.Library.DatFiles
|
|||||||
case Hash.MD5:
|
case Hash.MD5:
|
||||||
if (rom.Type == ItemType.Rom)
|
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)
|
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;
|
break;
|
||||||
case Hash.CRC:
|
case Hash.CRC:
|
||||||
if (rom.Type == ItemType.Rom)
|
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;
|
break;
|
||||||
case Hash.SHA1:
|
case Hash.SHA1:
|
||||||
if (rom.Type == ItemType.Rom)
|
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)
|
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;
|
break;
|
||||||
case Hash.SHA256:
|
case Hash.SHA256:
|
||||||
if (rom.Type == ItemType.Rom)
|
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)
|
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;
|
break;
|
||||||
case Hash.SHA384:
|
case Hash.SHA384:
|
||||||
if (rom.Type == ItemType.Rom)
|
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)
|
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;
|
break;
|
||||||
case Hash.SHA512:
|
case Hash.SHA512:
|
||||||
if (rom.Type == ItemType.Rom)
|
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)
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,12 +24,11 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents parsing and writing of a MAME Listroms DAT
|
/// Represents parsing and writing of a MAME Listroms DAT
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Listroms
|
public class Listroms : DatFile
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parse a MAME Listroms DAT and return all found games and roms within
|
/// Parse a MAME Listroms DAT and return all found games and roms within
|
||||||
/// </summary>
|
/// </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="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="sysid">System ID for the DAT</param>
|
/// <param name="sysid">System ID for the DAT</param>
|
||||||
/// <param name="srcid">Source 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
|
/// 6331.sound-u8 32 BAD CRC(1d298cb0) SHA1(bb0bb62365402543e3154b9a77be9c75010e6abc) BAD_DUMP
|
||||||
/// 16v8h-blue.u24 279 NO GOOD DUMP KNOWN
|
/// 16v8h-blue.u24 279 NO GOOD DUMP KNOWN
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public static void Parse(
|
public void Parse(
|
||||||
DatFile datFile,
|
|
||||||
|
|
||||||
// Standard Dat parsing
|
// Standard Dat parsing
|
||||||
string filename,
|
string filename,
|
||||||
int sysid,
|
int sysid,
|
||||||
@@ -127,7 +124,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
MachineName = gamename,
|
MachineName = gamename,
|
||||||
};
|
};
|
||||||
|
|
||||||
datFile.ParseAddHelper(disk, clean, remUnicode);
|
ParseAddHelper(disk, clean, remUnicode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Baddump Disks have 4 pieces (name, BAD, sha1, BAD_DUMP)
|
// Baddump Disks have 4 pieces (name, BAD, sha1, BAD_DUMP)
|
||||||
@@ -142,7 +139,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
MachineName = gamename,
|
MachineName = gamename,
|
||||||
};
|
};
|
||||||
|
|
||||||
datFile.ParseAddHelper(disk, clean, remUnicode);
|
ParseAddHelper(disk, clean, remUnicode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Standard ROMs have 4 pieces (name, size, crc, sha1)
|
// Standard ROMs have 4 pieces (name, size, crc, sha1)
|
||||||
@@ -163,7 +160,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
MachineName = gamename,
|
MachineName = gamename,
|
||||||
};
|
};
|
||||||
|
|
||||||
datFile.ParseAddHelper(rom, clean, remUnicode);
|
ParseAddHelper(rom, clean, remUnicode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nodump Disks have 5 pieces (name, NO, GOOD, DUMP, KNOWN)
|
// Nodump Disks have 5 pieces (name, NO, GOOD, DUMP, KNOWN)
|
||||||
@@ -177,7 +174,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
MachineName = gamename,
|
MachineName = gamename,
|
||||||
};
|
};
|
||||||
|
|
||||||
datFile.ParseAddHelper(disk, clean, remUnicode);
|
ParseAddHelper(disk, clean, remUnicode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Baddump ROMs have 6 pieces (name, size, BAD, crc, sha1, BAD_DUMP)
|
// Baddump ROMs have 6 pieces (name, size, BAD, crc, sha1, BAD_DUMP)
|
||||||
@@ -199,7 +196,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
MachineName = gamename,
|
MachineName = gamename,
|
||||||
};
|
};
|
||||||
|
|
||||||
datFile.ParseAddHelper(rom, clean, remUnicode);
|
ParseAddHelper(rom, clean, remUnicode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nodump ROMs have 6 pieces (name, size, NO, GOOD, DUMP, KNOWN)
|
// Nodump ROMs have 6 pieces (name, size, NO, GOOD, DUMP, KNOWN)
|
||||||
@@ -219,7 +216,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
MachineName = gamename,
|
MachineName = gamename,
|
||||||
};
|
};
|
||||||
|
|
||||||
datFile.ParseAddHelper(rom, clean, remUnicode);
|
ParseAddHelper(rom, clean, remUnicode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we have something else, it's invalid
|
// If we have something else, it's invalid
|
||||||
@@ -235,11 +232,10 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create and open an output file for writing direct from a dictionary
|
/// Create and open an output file for writing direct from a dictionary
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="datFile">DatFile to write out from</param>
|
|
||||||
/// <param name="outfile">Name of the file to write to</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>
|
/// <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>
|
/// <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
|
try
|
||||||
{
|
{
|
||||||
@@ -259,12 +255,12 @@ namespace SabreTools.Library.DatFiles
|
|||||||
string lastgame = null;
|
string lastgame = null;
|
||||||
|
|
||||||
// Get a properly sorted set of keys
|
// Get a properly sorted set of keys
|
||||||
List<string> keys = datFile.Keys.ToList();
|
List<string> keys = Keys.ToList();
|
||||||
keys.Sort(new NaturalComparer());
|
keys.Sort(new NaturalComparer());
|
||||||
|
|
||||||
foreach (string key in keys)
|
foreach (string key in keys)
|
||||||
{
|
{
|
||||||
List<DatItem> roms = datFile[key];
|
List<DatItem> roms = this[key];
|
||||||
|
|
||||||
// Resolve the names in the block
|
// Resolve the names in the block
|
||||||
roms = DatItem.ResolveNames(roms);
|
roms = DatItem.ResolveNames(roms);
|
||||||
@@ -336,7 +332,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="sw">StreamWriter to output to</param>
|
/// <param name="sw">StreamWriter to output to</param>
|
||||||
/// <param name="rom">RomData object to be output</param>
|
/// <param name="rom">RomData object to be output</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
/// <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
|
try
|
||||||
{
|
{
|
||||||
@@ -366,7 +362,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sw">StreamWriter to output to</param>
|
/// <param name="sw">StreamWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
/// <returns>True if the data was written, false on error</returns>
|
||||||
private static bool WriteEndGame(StreamWriter sw)
|
private bool WriteEndGame(StreamWriter sw)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -391,7 +387,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="rom">RomData object to be output</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>
|
/// <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>
|
/// <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 we are in ignore blanks mode AND we have a blank (0-size) rom, skip
|
||||||
if (ignoreblanks
|
if (ignoreblanks
|
||||||
|
|||||||
@@ -25,12 +25,11 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents parsing and writing of a Logiqx-derived DAT
|
/// Represents parsing and writing of a Logiqx-derived DAT
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Logiqx
|
public class Logiqx : DatFile
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parse a Logiqx XML DAT and return all found games and roms within
|
/// Parse a Logiqx XML DAT and return all found games and roms within
|
||||||
/// </summary>
|
/// </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="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="sysid">System ID for the DAT</param>
|
/// <param name="sysid">System ID for the DAT</param>
|
||||||
/// <param name="srcid">Source 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>
|
/// <param name="remUnicode">True if we should remove non-ASCII characters from output, false otherwise (default)</param>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public static void Parse(
|
public void Parse(
|
||||||
DatFile datFile,
|
|
||||||
|
|
||||||
// Standard Dat parsing
|
// Standard Dat parsing
|
||||||
string filename,
|
string filename,
|
||||||
int sysid,
|
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
|
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
|
// Now process and add the rom
|
||||||
key = datFile.ParseAddHelper(rom, clean, remUnicode);
|
key = ParseAddHelper(rom, clean, remUnicode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Regardless, end the current folder
|
// Regardless, end the current folder
|
||||||
@@ -102,7 +99,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
parent.RemoveAt(parent.Count - 1);
|
parent.RemoveAt(parent.Count - 1);
|
||||||
if (keep && parentcount > 1)
|
if (keep && parentcount > 1)
|
||||||
{
|
{
|
||||||
datFile.Type = (String.IsNullOrEmpty(datFile.Type) ? "SuperDAT" : datFile.Type);
|
Type = (String.IsNullOrEmpty(Type) ? "SuperDAT" : Type);
|
||||||
superdat = true;
|
superdat = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -121,8 +118,8 @@ namespace SabreTools.Library.DatFiles
|
|||||||
case "mame":
|
case "mame":
|
||||||
if (xtr.GetAttribute("build") != null)
|
if (xtr.GetAttribute("build") != null)
|
||||||
{
|
{
|
||||||
datFile.Name = (String.IsNullOrEmpty(datFile.Name) ? xtr.GetAttribute("build") : datFile.Name);
|
Name = (String.IsNullOrEmpty(Name) ? xtr.GetAttribute("build") : Name);
|
||||||
datFile.Description = (String.IsNullOrEmpty(datFile.Description) ? datFile.Name : datFile.Name);
|
Description = (String.IsNullOrEmpty(Description) ? Name : Name);
|
||||||
}
|
}
|
||||||
xtr.Read();
|
xtr.Read();
|
||||||
break;
|
break;
|
||||||
@@ -130,57 +127,57 @@ namespace SabreTools.Library.DatFiles
|
|||||||
case "softwarelist":
|
case "softwarelist":
|
||||||
if (xtr.GetAttribute("name") != null)
|
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)
|
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"))
|
switch (xtr.GetAttribute("forcemerging"))
|
||||||
{
|
{
|
||||||
case "none":
|
case "none":
|
||||||
datFile.ForceMerging = ForceMerging.None;
|
ForceMerging = ForceMerging.None;
|
||||||
break;
|
break;
|
||||||
case "split":
|
case "split":
|
||||||
datFile.ForceMerging = ForceMerging.Split;
|
ForceMerging = ForceMerging.Split;
|
||||||
break;
|
break;
|
||||||
case "merged":
|
case "merged":
|
||||||
datFile.ForceMerging = ForceMerging.Merged;
|
ForceMerging = ForceMerging.Merged;
|
||||||
break;
|
break;
|
||||||
case "nonmerged":
|
case "nonmerged":
|
||||||
datFile.ForceMerging = ForceMerging.NonMerged;
|
ForceMerging = ForceMerging.NonMerged;
|
||||||
break;
|
break;
|
||||||
case "full":
|
case "full":
|
||||||
datFile.ForceMerging = ForceMerging.Full;
|
ForceMerging = ForceMerging.Full;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (xtr.GetAttribute("forcenodump") != null && datFile.ForceNodump == ForceNodump.None)
|
if (xtr.GetAttribute("forcenodump") != null && ForceNodump == ForceNodump.None)
|
||||||
{
|
{
|
||||||
switch (xtr.GetAttribute("forcenodump"))
|
switch (xtr.GetAttribute("forcenodump"))
|
||||||
{
|
{
|
||||||
case "obsolete":
|
case "obsolete":
|
||||||
datFile.ForceNodump = ForceNodump.Obsolete;
|
ForceNodump = ForceNodump.Obsolete;
|
||||||
break;
|
break;
|
||||||
case "required":
|
case "required":
|
||||||
datFile.ForceNodump = ForceNodump.Required;
|
ForceNodump = ForceNodump.Required;
|
||||||
break;
|
break;
|
||||||
case "ignore":
|
case "ignore":
|
||||||
datFile.ForceNodump = ForceNodump.Ignore;
|
ForceNodump = ForceNodump.Ignore;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (xtr.GetAttribute("forcepacking") != null && datFile.ForcePacking == ForcePacking.None)
|
if (xtr.GetAttribute("forcepacking") != null && ForcePacking == ForcePacking.None)
|
||||||
{
|
{
|
||||||
switch (xtr.GetAttribute("forcepacking"))
|
switch (xtr.GetAttribute("forcepacking"))
|
||||||
{
|
{
|
||||||
case "zip":
|
case "zip":
|
||||||
datFile.ForcePacking = ForcePacking.Zip;
|
ForcePacking = ForcePacking.Zip;
|
||||||
break;
|
break;
|
||||||
case "unzip":
|
case "unzip":
|
||||||
datFile.ForcePacking = ForcePacking.Unzip;
|
ForcePacking = ForcePacking.Unzip;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -188,11 +185,11 @@ namespace SabreTools.Library.DatFiles
|
|||||||
break;
|
break;
|
||||||
// Handle M1 DATs since they're 99% the same as a SL DAT
|
// Handle M1 DATs since they're 99% the same as a SL DAT
|
||||||
case "m1":
|
case "m1":
|
||||||
datFile.Name = (String.IsNullOrEmpty(datFile.Name) ? "M1" : datFile.Name);
|
Name = (String.IsNullOrEmpty(Name) ? "M1" : Name);
|
||||||
datFile.Description = (String.IsNullOrEmpty(datFile.Description) ? "M1" : datFile.Description);
|
Description = (String.IsNullOrEmpty(Description) ? "M1" : Description);
|
||||||
if (xtr.GetAttribute("version") != null)
|
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();
|
xtr.Read();
|
||||||
break;
|
break;
|
||||||
@@ -223,16 +220,16 @@ namespace SabreTools.Library.DatFiles
|
|||||||
{
|
{
|
||||||
case "datname":
|
case "datname":
|
||||||
content = headreader.ReadElementContentAsString(); ;
|
content = headreader.ReadElementContentAsString(); ;
|
||||||
datFile.Name = (String.IsNullOrEmpty(datFile.Name) ? content : datFile.Name);
|
Name = (String.IsNullOrEmpty(Name) ? content : Name);
|
||||||
superdat = superdat || content.Contains(" - SuperDAT");
|
superdat = superdat || content.Contains(" - SuperDAT");
|
||||||
if (keep && superdat)
|
if (keep && superdat)
|
||||||
{
|
{
|
||||||
datFile.Type = (String.IsNullOrEmpty(datFile.Type) ? "SuperDAT" : datFile.Type);
|
Type = (String.IsNullOrEmpty(Type) ? "SuperDAT" : Type);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "datversionurl":
|
case "datversionurl":
|
||||||
content = headreader.ReadElementContentAsString(); ;
|
content = headreader.ReadElementContentAsString(); ;
|
||||||
datFile.Url = (String.IsNullOrEmpty(datFile.Name) ? content : datFile.Url);
|
Url = (String.IsNullOrEmpty(Name) ? content : Url);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
headreader.Read();
|
headreader.Read();
|
||||||
@@ -268,121 +265,121 @@ namespace SabreTools.Library.DatFiles
|
|||||||
{
|
{
|
||||||
case "name":
|
case "name":
|
||||||
content = headreader.ReadElementContentAsString(); ;
|
content = headreader.ReadElementContentAsString(); ;
|
||||||
datFile.Name = (String.IsNullOrEmpty(datFile.Name) ? content : datFile.Name);
|
Name = (String.IsNullOrEmpty(Name) ? content : Name);
|
||||||
superdat = superdat || content.Contains(" - SuperDAT");
|
superdat = superdat || content.Contains(" - SuperDAT");
|
||||||
if (keep && superdat)
|
if (keep && superdat)
|
||||||
{
|
{
|
||||||
datFile.Type = (String.IsNullOrEmpty(datFile.Type) ? "SuperDAT" : datFile.Type);
|
Type = (String.IsNullOrEmpty(Type) ? "SuperDAT" : Type);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "description":
|
case "description":
|
||||||
content = headreader.ReadElementContentAsString();
|
content = headreader.ReadElementContentAsString();
|
||||||
datFile.Description = (String.IsNullOrEmpty(datFile.Description) ? content : datFile.Description);
|
Description = (String.IsNullOrEmpty(Description) ? content : Description);
|
||||||
break;
|
break;
|
||||||
case "rootdir":
|
case "rootdir":
|
||||||
content = headreader.ReadElementContentAsString();
|
content = headreader.ReadElementContentAsString();
|
||||||
datFile.RootDir = (String.IsNullOrEmpty(datFile.RootDir) ? content : datFile.RootDir);
|
RootDir = (String.IsNullOrEmpty(RootDir) ? content : RootDir);
|
||||||
break;
|
break;
|
||||||
case "category":
|
case "category":
|
||||||
content = headreader.ReadElementContentAsString();
|
content = headreader.ReadElementContentAsString();
|
||||||
datFile.Category = (String.IsNullOrEmpty(datFile.Category) ? content : datFile.Category);
|
Category = (String.IsNullOrEmpty(Category) ? content : Category);
|
||||||
break;
|
break;
|
||||||
case "version":
|
case "version":
|
||||||
content = headreader.ReadElementContentAsString();
|
content = headreader.ReadElementContentAsString();
|
||||||
datFile.Version = (String.IsNullOrEmpty(datFile.Version) ? content : datFile.Version);
|
Version = (String.IsNullOrEmpty(Version) ? content : Version);
|
||||||
break;
|
break;
|
||||||
case "date":
|
case "date":
|
||||||
content = headreader.ReadElementContentAsString();
|
content = headreader.ReadElementContentAsString();
|
||||||
datFile.Date = (String.IsNullOrEmpty(datFile.Date) ? content.Replace(".", "/") : datFile.Date);
|
Date = (String.IsNullOrEmpty(Date) ? content.Replace(".", "/") : Date);
|
||||||
break;
|
break;
|
||||||
case "author":
|
case "author":
|
||||||
content = headreader.ReadElementContentAsString();
|
content = headreader.ReadElementContentAsString();
|
||||||
datFile.Author = (String.IsNullOrEmpty(datFile.Author) ? content : datFile.Author);
|
Author = (String.IsNullOrEmpty(Author) ? content : Author);
|
||||||
|
|
||||||
// Special cases for SabreDAT
|
// Special cases for SabreDAT
|
||||||
datFile.Email = (String.IsNullOrEmpty(datFile.Email) && !String.IsNullOrEmpty(headreader.GetAttribute("email")) ?
|
Email = (String.IsNullOrEmpty(Email) && !String.IsNullOrEmpty(headreader.GetAttribute("email")) ?
|
||||||
headreader.GetAttribute("email") : datFile.Email);
|
headreader.GetAttribute("email") : Email);
|
||||||
datFile.Homepage = (String.IsNullOrEmpty(datFile.Homepage) && !String.IsNullOrEmpty(headreader.GetAttribute("homepage")) ?
|
Homepage = (String.IsNullOrEmpty(Homepage) && !String.IsNullOrEmpty(headreader.GetAttribute("homepage")) ?
|
||||||
headreader.GetAttribute("homepage") : datFile.Homepage);
|
headreader.GetAttribute("homepage") : Homepage);
|
||||||
datFile.Url = (String.IsNullOrEmpty(datFile.Url) && !String.IsNullOrEmpty(headreader.GetAttribute("url")) ?
|
Url = (String.IsNullOrEmpty(Url) && !String.IsNullOrEmpty(headreader.GetAttribute("url")) ?
|
||||||
headreader.GetAttribute("url") : datFile.Url);
|
headreader.GetAttribute("url") : Url);
|
||||||
break;
|
break;
|
||||||
case "email":
|
case "email":
|
||||||
content = headreader.ReadElementContentAsString();
|
content = headreader.ReadElementContentAsString();
|
||||||
datFile.Email = (String.IsNullOrEmpty(datFile.Email) ? content : datFile.Email);
|
Email = (String.IsNullOrEmpty(Email) ? content : Email);
|
||||||
break;
|
break;
|
||||||
case "homepage":
|
case "homepage":
|
||||||
content = headreader.ReadElementContentAsString();
|
content = headreader.ReadElementContentAsString();
|
||||||
datFile.Homepage = (String.IsNullOrEmpty(datFile.Homepage) ? content : datFile.Homepage);
|
Homepage = (String.IsNullOrEmpty(Homepage) ? content : Homepage);
|
||||||
break;
|
break;
|
||||||
case "url":
|
case "url":
|
||||||
content = headreader.ReadElementContentAsString();
|
content = headreader.ReadElementContentAsString();
|
||||||
datFile.Url = (String.IsNullOrEmpty(datFile.Url) ? content : datFile.Url);
|
Url = (String.IsNullOrEmpty(Url) ? content : Url);
|
||||||
break;
|
break;
|
||||||
case "comment":
|
case "comment":
|
||||||
content = headreader.ReadElementContentAsString();
|
content = headreader.ReadElementContentAsString();
|
||||||
datFile.Comment = (String.IsNullOrEmpty(datFile.Comment) ? content : datFile.Comment);
|
Comment = (String.IsNullOrEmpty(Comment) ? content : Comment);
|
||||||
break;
|
break;
|
||||||
case "type":
|
case "type":
|
||||||
content = headreader.ReadElementContentAsString();
|
content = headreader.ReadElementContentAsString();
|
||||||
datFile.Type = (String.IsNullOrEmpty(datFile.Type) ? content : datFile.Type);
|
Type = (String.IsNullOrEmpty(Type) ? content : Type);
|
||||||
superdat = superdat || content.Contains("SuperDAT");
|
superdat = superdat || content.Contains("SuperDAT");
|
||||||
break;
|
break;
|
||||||
case "clrmamepro":
|
case "clrmamepro":
|
||||||
case "romcenter":
|
case "romcenter":
|
||||||
if (headreader.GetAttribute("header") != null)
|
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)
|
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"))
|
switch (headreader.GetAttribute("forcemerging"))
|
||||||
{
|
{
|
||||||
case "none":
|
case "none":
|
||||||
datFile.ForceMerging = ForceMerging.None;
|
ForceMerging = ForceMerging.None;
|
||||||
break;
|
break;
|
||||||
case "split":
|
case "split":
|
||||||
datFile.ForceMerging = ForceMerging.Split;
|
ForceMerging = ForceMerging.Split;
|
||||||
break;
|
break;
|
||||||
case "merged":
|
case "merged":
|
||||||
datFile.ForceMerging = ForceMerging.Merged;
|
ForceMerging = ForceMerging.Merged;
|
||||||
break;
|
break;
|
||||||
case "nonmerged":
|
case "nonmerged":
|
||||||
datFile.ForceMerging = ForceMerging.NonMerged;
|
ForceMerging = ForceMerging.NonMerged;
|
||||||
break;
|
break;
|
||||||
case "full":
|
case "full":
|
||||||
datFile.ForceMerging = ForceMerging.Full;
|
ForceMerging = ForceMerging.Full;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (headreader.GetAttribute("forcenodump") != null && datFile.ForceNodump == ForceNodump.None)
|
if (headreader.GetAttribute("forcenodump") != null && ForceNodump == ForceNodump.None)
|
||||||
{
|
{
|
||||||
switch (headreader.GetAttribute("forcenodump"))
|
switch (headreader.GetAttribute("forcenodump"))
|
||||||
{
|
{
|
||||||
case "obsolete":
|
case "obsolete":
|
||||||
datFile.ForceNodump = ForceNodump.Obsolete;
|
ForceNodump = ForceNodump.Obsolete;
|
||||||
break;
|
break;
|
||||||
case "required":
|
case "required":
|
||||||
datFile.ForceNodump = ForceNodump.Required;
|
ForceNodump = ForceNodump.Required;
|
||||||
break;
|
break;
|
||||||
case "ignore":
|
case "ignore":
|
||||||
datFile.ForceNodump = ForceNodump.Ignore;
|
ForceNodump = ForceNodump.Ignore;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (headreader.GetAttribute("forcepacking") != null && datFile.ForcePacking == ForcePacking.None)
|
if (headreader.GetAttribute("forcepacking") != null && ForcePacking == ForcePacking.None)
|
||||||
{
|
{
|
||||||
switch (headreader.GetAttribute("forcepacking"))
|
switch (headreader.GetAttribute("forcepacking"))
|
||||||
{
|
{
|
||||||
case "zip":
|
case "zip":
|
||||||
datFile.ForcePacking = ForcePacking.Zip;
|
ForcePacking = ForcePacking.Zip;
|
||||||
break;
|
break;
|
||||||
case "unzip":
|
case "unzip":
|
||||||
datFile.ForcePacking = ForcePacking.Unzip;
|
ForcePacking = ForcePacking.Unzip;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -416,53 +413,53 @@ namespace SabreTools.Library.DatFiles
|
|||||||
switch (flagreader.GetAttribute("name"))
|
switch (flagreader.GetAttribute("name"))
|
||||||
{
|
{
|
||||||
case "type":
|
case "type":
|
||||||
datFile.Type = (String.IsNullOrEmpty(datFile.Type) ? content : datFile.Type);
|
Type = (String.IsNullOrEmpty(Type) ? content : Type);
|
||||||
superdat = superdat || content.Contains("SuperDAT");
|
superdat = superdat || content.Contains("SuperDAT");
|
||||||
break;
|
break;
|
||||||
case "forcemerging":
|
case "forcemerging":
|
||||||
if (datFile.ForceMerging == ForceMerging.None)
|
if (ForceMerging == ForceMerging.None)
|
||||||
{
|
{
|
||||||
switch (content)
|
switch (content)
|
||||||
{
|
{
|
||||||
case "split":
|
case "split":
|
||||||
datFile.ForceMerging = ForceMerging.Split;
|
ForceMerging = ForceMerging.Split;
|
||||||
break;
|
break;
|
||||||
case "none":
|
case "none":
|
||||||
datFile.ForceMerging = ForceMerging.None;
|
ForceMerging = ForceMerging.None;
|
||||||
break;
|
break;
|
||||||
case "full":
|
case "full":
|
||||||
datFile.ForceMerging = ForceMerging.Full;
|
ForceMerging = ForceMerging.Full;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "forcenodump":
|
case "forcenodump":
|
||||||
if (datFile.ForceNodump == ForceNodump.None)
|
if (ForceNodump == ForceNodump.None)
|
||||||
{
|
{
|
||||||
switch (content)
|
switch (content)
|
||||||
{
|
{
|
||||||
case "obsolete":
|
case "obsolete":
|
||||||
datFile.ForceNodump = ForceNodump.Obsolete;
|
ForceNodump = ForceNodump.Obsolete;
|
||||||
break;
|
break;
|
||||||
case "required":
|
case "required":
|
||||||
datFile.ForceNodump = ForceNodump.Required;
|
ForceNodump = ForceNodump.Required;
|
||||||
break;
|
break;
|
||||||
case "ignore":
|
case "ignore":
|
||||||
datFile.ForceNodump = ForceNodump.Ignore;
|
ForceNodump = ForceNodump.Ignore;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "forcepacking":
|
case "forcepacking":
|
||||||
if (datFile.ForcePacking == ForcePacking.None)
|
if (ForcePacking == ForcePacking.None)
|
||||||
{
|
{
|
||||||
switch (content)
|
switch (content)
|
||||||
{
|
{
|
||||||
case "zip":
|
case "zip":
|
||||||
datFile.ForcePacking = ForcePacking.Zip;
|
ForcePacking = ForcePacking.Zip;
|
||||||
break;
|
break;
|
||||||
case "unzip":
|
case "unzip":
|
||||||
datFile.ForcePacking = ForcePacking.Unzip;
|
ForcePacking = ForcePacking.Unzip;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -631,7 +628,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
olrom.CopyMachineInformation(machine);
|
olrom.CopyMachineInformation(machine);
|
||||||
|
|
||||||
// Now process and add the rom
|
// Now process and add the rom
|
||||||
key = datFile.ParseAddHelper(olrom, clean, remUnicode);
|
key = ParseAddHelper(olrom, clean, remUnicode);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// For Software List and MAME listxml only
|
// For Software List and MAME listxml only
|
||||||
@@ -727,7 +724,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
relrom.CopyMachineInformation(machine);
|
relrom.CopyMachineInformation(machine);
|
||||||
|
|
||||||
// Now process and add the rom
|
// Now process and add the rom
|
||||||
key = datFile.ParseAddHelper(relrom, clean, remUnicode);
|
key = ParseAddHelper(relrom, clean, remUnicode);
|
||||||
|
|
||||||
subreader.Read();
|
subreader.Read();
|
||||||
break;
|
break;
|
||||||
@@ -770,7 +767,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
biosrom.CopyMachineInformation(machine);
|
biosrom.CopyMachineInformation(machine);
|
||||||
|
|
||||||
// Now process and add the rom
|
// Now process and add the rom
|
||||||
key = datFile.ParseAddHelper(biosrom, clean, remUnicode);
|
key = ParseAddHelper(biosrom, clean, remUnicode);
|
||||||
|
|
||||||
subreader.Read();
|
subreader.Read();
|
||||||
break;
|
break;
|
||||||
@@ -798,7 +795,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
archiverom.CopyMachineInformation(machine);
|
archiverom.CopyMachineInformation(machine);
|
||||||
|
|
||||||
// Now process and add the rom
|
// Now process and add the rom
|
||||||
key = datFile.ParseAddHelper(archiverom, clean, remUnicode);
|
key = ParseAddHelper(archiverom, clean, remUnicode);
|
||||||
|
|
||||||
subreader.Read();
|
subreader.Read();
|
||||||
break;
|
break;
|
||||||
@@ -826,7 +823,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
samplerom.CopyMachineInformation(machine);
|
samplerom.CopyMachineInformation(machine);
|
||||||
|
|
||||||
// Now process and add the rom
|
// Now process and add the rom
|
||||||
key = datFile.ParseAddHelper(samplerom, clean, remUnicode);
|
key = ParseAddHelper(samplerom, clean, remUnicode);
|
||||||
|
|
||||||
subreader.Read();
|
subreader.Read();
|
||||||
break;
|
break;
|
||||||
@@ -885,14 +882,14 @@ namespace SabreTools.Library.DatFiles
|
|||||||
// If the rom is continue or ignore, add the size to the previous rom
|
// If the rom is continue or ignore, add the size to the previous rom
|
||||||
if (subreader.GetAttribute("loadflag") == "continue" || subreader.GetAttribute("loadflag") == "ignore")
|
if (subreader.GetAttribute("loadflag") == "continue" || subreader.GetAttribute("loadflag") == "ignore")
|
||||||
{
|
{
|
||||||
int index = datFile[key].Count() - 1;
|
int index = this[key].Count() - 1;
|
||||||
DatItem lastrom = datFile[key][index];
|
DatItem lastrom = this[key][index];
|
||||||
if (lastrom.Type == ItemType.Rom)
|
if (lastrom.Type == ItemType.Rom)
|
||||||
{
|
{
|
||||||
((Rom)lastrom).Size += size;
|
((Rom)lastrom).Size += size;
|
||||||
}
|
}
|
||||||
datFile[key].RemoveAt(index);
|
this[key].RemoveAt(index);
|
||||||
datFile[key].Add(lastrom);
|
this[key].Add(lastrom);
|
||||||
subreader.Read();
|
subreader.Read();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -967,7 +964,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
inrom.CopyMachineInformation(machine);
|
inrom.CopyMachineInformation(machine);
|
||||||
|
|
||||||
// Now process and add the rom
|
// Now process and add the rom
|
||||||
key = datFile.ParseAddHelper(inrom, clean, remUnicode);
|
key = ParseAddHelper(inrom, clean, remUnicode);
|
||||||
|
|
||||||
subreader.Read();
|
subreader.Read();
|
||||||
break;
|
break;
|
||||||
@@ -985,7 +982,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
superdat = true;
|
superdat = true;
|
||||||
if (keep)
|
if (keep)
|
||||||
{
|
{
|
||||||
datFile.Type = (datFile.Type == "" ? "SuperDAT" : datFile.Type);
|
Type = (Type == "" ? "SuperDAT" : Type);
|
||||||
}
|
}
|
||||||
|
|
||||||
string foldername = (xtr.GetAttribute("name") ?? "");
|
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 the rom is continue or ignore, add the size to the previous rom
|
||||||
if (xtr.GetAttribute("loadflag") == "continue" || xtr.GetAttribute("loadflag") == "ignore")
|
if (xtr.GetAttribute("loadflag") == "continue" || xtr.GetAttribute("loadflag") == "ignore")
|
||||||
{
|
{
|
||||||
int index = datFile[key].Count() - 1;
|
int index = this[key].Count() - 1;
|
||||||
DatItem lastrom = datFile[key][index];
|
DatItem lastrom = this[key][index];
|
||||||
if (lastrom.Type == ItemType.Rom)
|
if (lastrom.Type == ItemType.Rom)
|
||||||
{
|
{
|
||||||
((Rom)lastrom).Size += size;
|
((Rom)lastrom).Size += size;
|
||||||
}
|
}
|
||||||
datFile[key].RemoveAt(index);
|
this[key].RemoveAt(index);
|
||||||
datFile[key].Add(lastrom);
|
this[key].Add(lastrom);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1140,7 +1137,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
rom.CopyMachineInformation(dir);
|
rom.CopyMachineInformation(dir);
|
||||||
|
|
||||||
// Now process and add the rom
|
// Now process and add the rom
|
||||||
key = datFile.ParseAddHelper(rom, clean, remUnicode);
|
key = ParseAddHelper(rom, clean, remUnicode);
|
||||||
|
|
||||||
xtr.Read();
|
xtr.Read();
|
||||||
break;
|
break;
|
||||||
@@ -1164,14 +1161,10 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create and open an output file for writing direct from a dictionary
|
/// Create and open an output file for writing direct from a dictionary
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="datFile">DatFile to write out from</param>
|
|
||||||
/// <param name="outfile">Name of the file to write to</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="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>
|
/// <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
|
try
|
||||||
{
|
{
|
||||||
@@ -1188,18 +1181,18 @@ namespace SabreTools.Library.DatFiles
|
|||||||
StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(true));
|
StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(true));
|
||||||
|
|
||||||
// Write out the header
|
// Write out the header
|
||||||
WriteHeader(datFile, sw);
|
WriteHeader(sw);
|
||||||
|
|
||||||
// Write out each of the machines and roms
|
// Write out each of the machines and roms
|
||||||
string lastgame = null;
|
string lastgame = null;
|
||||||
|
|
||||||
// Get a properly sorted set of keys
|
// Get a properly sorted set of keys
|
||||||
List<string> keys = datFile.Keys.ToList();
|
List<string> keys = Keys.ToList();
|
||||||
keys.Sort(new NaturalComparer());
|
keys.Sort(new NaturalComparer());
|
||||||
|
|
||||||
foreach (string key in keys)
|
foreach (string key in keys)
|
||||||
{
|
{
|
||||||
List<DatItem> roms = datFile[key];
|
List<DatItem> roms = this[key];
|
||||||
|
|
||||||
// Resolve the names in the block
|
// Resolve the names in the block
|
||||||
roms = DatItem.ResolveNames(roms);
|
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 we have a new game, output the beginning of the new item
|
||||||
if (lastgame == null || lastgame.ToLowerInvariant() != rom.MachineName.ToLowerInvariant())
|
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
|
// 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>
|
/// <summary>
|
||||||
/// Write out DAT header using the supplied StreamWriter
|
/// Write out DAT header using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="datFile">DatFile to write out from</param>
|
|
||||||
/// <param name="sw">StreamWriter to output to</param>
|
/// <param name="sw">StreamWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
/// <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
|
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" +
|
"<!DOCTYPE datafile PUBLIC \"-//Logiqx//DTD ROM Management Datafile//EN\" \"http://www.logiqx.com/Dats/datafile.dtd\">\n\n" +
|
||||||
"<datafile>\n" +
|
"<datafile>\n" +
|
||||||
"\t<header>\n" +
|
"\t<header>\n" +
|
||||||
"\t\t<name>" + HttpUtility.HtmlEncode(datFile.Name) + "</name>\n" +
|
"\t\t<name>" + HttpUtility.HtmlEncode(Name) + "</name>\n" +
|
||||||
"\t\t<description>" + HttpUtility.HtmlEncode(datFile.Description) + "</description>\n" +
|
"\t\t<description>" + HttpUtility.HtmlEncode(Description) + "</description>\n" +
|
||||||
(!String.IsNullOrEmpty(datFile.RootDir) ? "\t\t<rootdir>" + HttpUtility.HtmlEncode(datFile.RootDir) + "</rootdir>\n" : "") +
|
(!String.IsNullOrEmpty(RootDir) ? "\t\t<rootdir>" + HttpUtility.HtmlEncode(RootDir) + "</rootdir>\n" : "") +
|
||||||
(!String.IsNullOrEmpty(datFile.Category) ? "\t\t<category>" + HttpUtility.HtmlEncode(datFile.Category) + "</category>\n" : "") +
|
(!String.IsNullOrEmpty(Category) ? "\t\t<category>" + HttpUtility.HtmlEncode(Category) + "</category>\n" : "") +
|
||||||
"\t\t<version>" + HttpUtility.HtmlEncode(datFile.Version) + "</version>\n" +
|
"\t\t<version>" + HttpUtility.HtmlEncode(Version) + "</version>\n" +
|
||||||
(!String.IsNullOrEmpty(datFile.Date) ? "\t\t<date>" + HttpUtility.HtmlEncode(datFile.Date) + "</date>\n" : "") +
|
(!String.IsNullOrEmpty(Date) ? "\t\t<date>" + HttpUtility.HtmlEncode(Date) + "</date>\n" : "") +
|
||||||
"\t\t<author>" + HttpUtility.HtmlEncode(datFile.Author) + "</author>\n" +
|
"\t\t<author>" + HttpUtility.HtmlEncode(Author) + "</author>\n" +
|
||||||
(!String.IsNullOrEmpty(datFile.Email) ? "\t\t<email>" + HttpUtility.HtmlEncode(datFile.Email) + "</email>\n" : "") +
|
(!String.IsNullOrEmpty(Email) ? "\t\t<email>" + HttpUtility.HtmlEncode(Email) + "</email>\n" : "") +
|
||||||
(!String.IsNullOrEmpty(datFile.Homepage) ? "\t\t<homepage>" + HttpUtility.HtmlEncode(datFile.Homepage) + "</homepage>\n" : "") +
|
(!String.IsNullOrEmpty(Homepage) ? "\t\t<homepage>" + HttpUtility.HtmlEncode(Homepage) + "</homepage>\n" : "") +
|
||||||
(!String.IsNullOrEmpty(datFile.Url) ? "\t\t<url>" + HttpUtility.HtmlEncode(datFile.Url) + "</url>\n" : "") +
|
(!String.IsNullOrEmpty(Url) ? "\t\t<url>" + HttpUtility.HtmlEncode(Url) + "</url>\n" : "") +
|
||||||
(!String.IsNullOrEmpty(datFile.Comment) ? "\t\t<comment>" + HttpUtility.HtmlEncode(datFile.Comment) + "</comment>\n" : "") +
|
(!String.IsNullOrEmpty(Comment) ? "\t\t<comment>" + HttpUtility.HtmlEncode(Comment) + "</comment>\n" : "") +
|
||||||
(!String.IsNullOrEmpty(datFile.Type) ? "\t\t<type>" + HttpUtility.HtmlEncode(datFile.Type) + "</type>\n" : "") +
|
(!String.IsNullOrEmpty(Type) ? "\t\t<type>" + HttpUtility.HtmlEncode(Type) + "</type>\n" : "") +
|
||||||
(datFile.ForcePacking != ForcePacking.None || datFile.ForceMerging != ForceMerging.None || datFile.ForceNodump != ForceNodump.None ?
|
(ForcePacking != ForcePacking.None || ForceMerging != ForceMerging.None || ForceNodump != ForceNodump.None ?
|
||||||
"\t\t<clrmamepro" +
|
"\t\t<clrmamepro" +
|
||||||
(datFile.ForcePacking == ForcePacking.Unzip ? " forcepacking=\"unzip\"" : "") +
|
(ForcePacking == ForcePacking.Unzip ? " forcepacking=\"unzip\"" : "") +
|
||||||
(datFile.ForcePacking == ForcePacking.Zip ? " forcepacking=\"zip\"" : "") +
|
(ForcePacking == ForcePacking.Zip ? " forcepacking=\"zip\"" : "") +
|
||||||
(datFile.ForceMerging == ForceMerging.Full ? " forcemerging=\"full\"" : "") +
|
(ForceMerging == ForceMerging.Full ? " forcemerging=\"full\"" : "") +
|
||||||
(datFile.ForceMerging == ForceMerging.Split ? " forcemerging=\"split\"" : "") +
|
(ForceMerging == ForceMerging.Split ? " forcemerging=\"split\"" : "") +
|
||||||
(datFile.ForceMerging == ForceMerging.Merged ? " forcemerging=\"merged\"" : "") +
|
(ForceMerging == ForceMerging.Merged ? " forcemerging=\"merged\"" : "") +
|
||||||
(datFile.ForceMerging == ForceMerging.NonMerged ? " forcemerging=\"nonmerged\"" : "") +
|
(ForceMerging == ForceMerging.NonMerged ? " forcemerging=\"nonmerged\"" : "") +
|
||||||
(datFile.ForceNodump == ForceNodump.Ignore ? " forcenodump=\"ignore\"" : "") +
|
(ForceNodump == ForceNodump.Ignore ? " forcenodump=\"ignore\"" : "") +
|
||||||
(datFile.ForceNodump == ForceNodump.Obsolete ? " forcenodump=\"obsolete\"" : "") +
|
(ForceNodump == ForceNodump.Obsolete ? " forcenodump=\"obsolete\"" : "") +
|
||||||
(datFile.ForceNodump == ForceNodump.Required ? " forcenodump=\"required\"" : "") +
|
(ForceNodump == ForceNodump.Required ? " forcenodump=\"required\"" : "") +
|
||||||
" />\n"
|
" />\n"
|
||||||
: "") +
|
: "") +
|
||||||
"\t</header>\n";
|
"\t</header>\n";
|
||||||
@@ -1325,11 +1317,10 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out Game start using the supplied StreamWriter
|
/// Write out Game start using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="datFile">DatFile to write out from</param>
|
|
||||||
/// <param name="sw">StreamWriter to output to</param>
|
/// <param name="sw">StreamWriter to output to</param>
|
||||||
/// <param name="rom">RomData object to be output</param>
|
/// <param name="rom">RomData object to be output</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
/// <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
|
try
|
||||||
{
|
{
|
||||||
@@ -1340,7 +1331,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
}
|
}
|
||||||
|
|
||||||
string state = "\t<machine name=\"" + HttpUtility.HtmlEncode(rom.MachineName) + "\"" +
|
string state = "\t<machine name=\"" + HttpUtility.HtmlEncode(rom.MachineName) + "\"" +
|
||||||
(datFile.ExcludeOf ? "" :
|
(ExcludeOf ? "" :
|
||||||
(rom.MachineType == MachineType.Bios ? " isbios=\"yes\"" : "") +
|
(rom.MachineType == MachineType.Bios ? " isbios=\"yes\"" : "") +
|
||||||
(rom.MachineType == MachineType.Device ? " isdevice=\"yes\"" : "") +
|
(rom.MachineType == MachineType.Device ? " isdevice=\"yes\"" : "") +
|
||||||
(rom.MachineType == MachineType.Mechanical ? " ismechanical=\"yes\"" : "") +
|
(rom.MachineType == MachineType.Mechanical ? " ismechanical=\"yes\"" : "") +
|
||||||
@@ -1378,7 +1369,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sw">StreamWriter to output to</param>
|
/// <param name="sw">StreamWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
/// <returns>True if the data was written, false on error</returns>
|
||||||
private static bool WriteEndGame(StreamWriter sw)
|
private bool WriteEndGame(StreamWriter sw)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -1403,7 +1394,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="rom">RomData object to be output</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>
|
/// <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>
|
/// <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 we are in ignore blanks mode AND we have a blank (0-size) rom, skip
|
||||||
if (ignoreblanks
|
if (ignoreblanks
|
||||||
@@ -1486,7 +1477,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sw">StreamWriter to output to</param>
|
/// <param name="sw">StreamWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
/// <returns>True if the data was written, false on error</returns>
|
||||||
private static bool WriteFooter(StreamWriter sw)
|
private bool WriteFooter(StreamWriter sw)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,12 +22,11 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents parsing and writing of a Missfile
|
/// Represents parsing and writing of a Missfile
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Missfile
|
public class Missfile : DatFile
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parse a Missfileand return all found games and roms within
|
/// Parse a Missfileand return all found games and roms within
|
||||||
/// </summary>
|
/// </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="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="sysid">System ID for the DAT</param>
|
/// <param name="sysid">System ID for the DAT</param>
|
||||||
/// <param name="srcid">Source 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>
|
/// <param name="remUnicode">True if we should remove non-ASCII characters from output, false otherwise (default)</param>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public static void Parse(
|
public void Parse(
|
||||||
DatFile datFile,
|
|
||||||
|
|
||||||
// Standard Dat parsing
|
// Standard Dat parsing
|
||||||
string filename,
|
string filename,
|
||||||
int sysid,
|
int sysid,
|
||||||
@@ -56,11 +53,10 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create and open an output file for writing direct from a dictionary
|
/// Create and open an output file for writing direct from a dictionary
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="datFile">DatFile to write out from</param>
|
|
||||||
/// <param name="outfile">Name of the file to write to</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>
|
/// <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>
|
/// <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
|
try
|
||||||
{
|
{
|
||||||
@@ -80,12 +76,12 @@ namespace SabreTools.Library.DatFiles
|
|||||||
string lastgame = null;
|
string lastgame = null;
|
||||||
|
|
||||||
// Get a properly sorted set of keys
|
// Get a properly sorted set of keys
|
||||||
List<string> keys = datFile.Keys.ToList();
|
List<string> keys = Keys.ToList();
|
||||||
keys.Sort(new NaturalComparer());
|
keys.Sort(new NaturalComparer());
|
||||||
|
|
||||||
foreach (string key in keys)
|
foreach (string key in keys)
|
||||||
{
|
{
|
||||||
List<DatItem> roms = datFile[key];
|
List<DatItem> roms = this[key];
|
||||||
|
|
||||||
// Resolve the names in the block
|
// Resolve the names in the block
|
||||||
roms = DatItem.ResolveNames(roms);
|
roms = DatItem.ResolveNames(roms);
|
||||||
@@ -112,7 +108,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now, output the rom data
|
// Now, output the rom data
|
||||||
WriteRomData(datFile, sw, rom, lastgame, ignoreblanks);
|
WriteRomData(sw, rom, lastgame, ignoreblanks);
|
||||||
|
|
||||||
// Set the new data to compare against
|
// Set the new data to compare against
|
||||||
lastgame = rom.MachineName;
|
lastgame = rom.MachineName;
|
||||||
@@ -135,13 +131,12 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out RomData using the supplied StreamWriter
|
/// Write out RomData using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="datFile">DatFile to write out from</param>
|
|
||||||
/// <param name="sw">StreamWriter to output to</param>
|
/// <param name="sw">StreamWriter to output to</param>
|
||||||
/// <param name="rom">RomData object to be output</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="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>
|
/// <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>
|
/// <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 we are in ignore blanks mode AND we have a blank (0-size) rom, skip
|
||||||
if (ignoreblanks
|
if (ignoreblanks
|
||||||
@@ -154,8 +149,8 @@ namespace SabreTools.Library.DatFiles
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
string state = "", name = "", pre = "", post = "";
|
string state = "", name = "", pre = "", post = "";
|
||||||
pre = datFile.Prefix + (datFile.Quotes ? "\"" : "");
|
pre = Prefix + (Quotes ? "\"" : "");
|
||||||
post = (datFile.Quotes ? "\"" : "") + datFile.Postfix;
|
post = (Quotes ? "\"" : "") + Postfix;
|
||||||
|
|
||||||
if (rom.Type == ItemType.Rom)
|
if (rom.Type == ItemType.Rom)
|
||||||
{
|
{
|
||||||
@@ -231,7 +226,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If we're in Romba mode, the state is consistent
|
// If we're in Romba mode, the state is consistent
|
||||||
if (datFile.Romba)
|
if (Romba)
|
||||||
{
|
{
|
||||||
if (rom.Type == ItemType.Rom)
|
if (rom.Type == ItemType.Rom)
|
||||||
{
|
{
|
||||||
@@ -264,33 +259,33 @@ namespace SabreTools.Library.DatFiles
|
|||||||
// Otherwise, use any flags
|
// Otherwise, use any flags
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
name = (datFile.UseGame ? rom.MachineName : rom.Name);
|
name = (UseGame ? rom.MachineName : rom.Name);
|
||||||
if (datFile.RepExt != "" || datFile.RemExt)
|
if (RepExt != "" || RemExt)
|
||||||
{
|
{
|
||||||
if (datFile.RemExt)
|
if (RemExt)
|
||||||
{
|
{
|
||||||
datFile.RepExt = "";
|
RepExt = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
string dir = Path.GetDirectoryName(name);
|
string dir = Path.GetDirectoryName(name);
|
||||||
dir = (dir.StartsWith(Path.DirectorySeparatorChar.ToString()) ? dir.Remove(0, 1) : dir);
|
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);
|
name = Path.Combine(rom.MachineName, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (datFile.UseGame && rom.MachineName != lastgame)
|
if (UseGame && rom.MachineName != lastgame)
|
||||||
{
|
{
|
||||||
state += pre + name + post + "\n";
|
state += pre + name + post + "\n";
|
||||||
lastgame = rom.MachineName;
|
lastgame = rom.MachineName;
|
||||||
}
|
}
|
||||||
else if (!datFile.UseGame)
|
else if (!UseGame)
|
||||||
{
|
{
|
||||||
state += pre + name + post + "\n";
|
state += pre + name + post + "\n";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using System.Xml;
|
|
||||||
|
|
||||||
using SabreTools.Library.Data;
|
using SabreTools.Library.Data;
|
||||||
using SabreTools.Library.Items;
|
using SabreTools.Library.Items;
|
||||||
@@ -25,12 +23,11 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents parsing and writing of an OfflineList XML DAT
|
/// Represents parsing and writing of an OfflineList XML DAT
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class OfflineList
|
public class OfflineList : DatFile
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parse an OfflineList XML DAT and return all found games and roms within
|
/// Parse an OfflineList XML DAT and return all found games and roms within
|
||||||
/// </summary>
|
/// </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="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="sysid">System ID for the DAT</param>
|
/// <param name="sysid">System ID for the DAT</param>
|
||||||
/// <param name="srcid">Source 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>
|
/// <param name="remUnicode">True if we should remove non-ASCII characters from output, false otherwise (default)</param>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public static void Parse(
|
public void Parse(
|
||||||
DatFile datFile,
|
|
||||||
|
|
||||||
// Standard Dat parsing
|
// Standard Dat parsing
|
||||||
string filename,
|
string filename,
|
||||||
int sysid,
|
int sysid,
|
||||||
@@ -53,17 +48,16 @@ namespace SabreTools.Library.DatFiles
|
|||||||
bool remUnicode)
|
bool remUnicode)
|
||||||
{
|
{
|
||||||
// All XML-derived DATs share a lot in common so it just calls one implementation
|
// 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>
|
/// <summary>
|
||||||
/// Create and open an output file for writing direct from a dictionary
|
/// Create and open an output file for writing direct from a dictionary
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="datFile">DatFile to write out from</param>
|
|
||||||
/// <param name="outfile">Name of the file to write to</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>
|
/// <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>
|
/// <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
|
try
|
||||||
{
|
{
|
||||||
@@ -80,18 +74,18 @@ namespace SabreTools.Library.DatFiles
|
|||||||
StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(true));
|
StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(true));
|
||||||
|
|
||||||
// Write out the header
|
// Write out the header
|
||||||
WriteHeader(datFile, sw);
|
WriteHeader(sw);
|
||||||
|
|
||||||
// Write out each of the machines and roms
|
// Write out each of the machines and roms
|
||||||
string lastgame = null;
|
string lastgame = null;
|
||||||
|
|
||||||
// Get a properly sorted set of keys
|
// Get a properly sorted set of keys
|
||||||
List<string> keys = datFile.Keys.ToList();
|
List<string> keys = Keys.ToList();
|
||||||
keys.Sort(new NaturalComparer());
|
keys.Sort(new NaturalComparer());
|
||||||
|
|
||||||
foreach (string key in keys)
|
foreach (string key in keys)
|
||||||
{
|
{
|
||||||
List<DatItem> roms = datFile[key];
|
List<DatItem> roms = this[key];
|
||||||
|
|
||||||
// Resolve the names in the block
|
// Resolve the names in the block
|
||||||
roms = DatItem.ResolveNames(roms);
|
roms = DatItem.ResolveNames(roms);
|
||||||
@@ -157,18 +151,17 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out DAT header using the supplied StreamWriter
|
/// Write out DAT header using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="datFile">DatFile to write out from</param>
|
|
||||||
/// <param name="sw">StreamWriter to output to</param>
|
/// <param name="sw">StreamWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
/// <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
|
try
|
||||||
{
|
{
|
||||||
string header = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
|
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"
|
+ "<dat xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"datas.xsd\">\n"
|
||||||
+ "\t<configuration>\n"
|
+ "\t<configuration>\n"
|
||||||
+ "\t\t<datName>" + HttpUtility.HtmlEncode(datFile.Name) + "</datName>\n"
|
+ "\t\t<datName>" + HttpUtility.HtmlEncode(Name) + "</datName>\n"
|
||||||
+ "\t\t<datVersion>" + datFile.Count + "</datVersion>\n"
|
+ "\t\t<datVersion>" + Count + "</datVersion>\n"
|
||||||
+ "\t\t<system>none</system>\n"
|
+ "\t\t<system>none</system>\n"
|
||||||
+ "\t\t<screenshotsWidth>240</screenshotsWidth>\n"
|
+ "\t\t<screenshotsWidth>240</screenshotsWidth>\n"
|
||||||
+ "\t\t<screenshotsHeight>160</screenshotsHeight>\n"
|
+ "\t\t<screenshotsHeight>160</screenshotsHeight>\n"
|
||||||
@@ -191,9 +184,9 @@ namespace SabreTools.Library.DatFiles
|
|||||||
+ "\t\t\t<extension>.bin</extension>\n"
|
+ "\t\t\t<extension>.bin</extension>\n"
|
||||||
+ "\t\t</canOpen>\n"
|
+ "\t\t</canOpen>\n"
|
||||||
+ "\t\t<newDat>\n"
|
+ "\t\t<newDat>\n"
|
||||||
+ "\t\t\t<datVersionURL>" + HttpUtility.HtmlEncode(datFile.Url) + "</datVersionURL>\n"
|
+ "\t\t\t<datVersionURL>" + HttpUtility.HtmlEncode(Url) + "</datVersionURL>\n"
|
||||||
+ "\t\t\t<datURL fileName=\"" + HttpUtility.HtmlEncode(datFile.FileName) + ".zip\">" + HttpUtility.HtmlEncode(datFile.Url) + "</datURL>\n"
|
+ "\t\t\t<datURL fileName=\"" + HttpUtility.HtmlEncode(FileName) + ".zip\">" + HttpUtility.HtmlEncode(Url) + "</datURL>\n"
|
||||||
+ "\t\t\t<imURL>" + HttpUtility.HtmlEncode(datFile.Url) + "</imURL>\n"
|
+ "\t\t\t<imURL>" + HttpUtility.HtmlEncode(Url) + "</imURL>\n"
|
||||||
+ "\t\t</newDat>\n"
|
+ "\t\t</newDat>\n"
|
||||||
+ "\t\t<search>\n"
|
+ "\t\t<search>\n"
|
||||||
+ "\t\t\t<to value=\"location\" default=\"true\" auto=\"true\"/>\n"
|
+ "\t\t\t<to value=\"location\" default=\"true\" auto=\"true\"/>\n"
|
||||||
@@ -225,7 +218,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sw">StreamWriter to output to</param>
|
/// <param name="sw">StreamWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
/// <returns>True if the data was written, false on error</returns>
|
||||||
private static bool WriteEndGame(StreamWriter sw)
|
private bool WriteEndGame(StreamWriter sw)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -250,7 +243,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="rom">RomData object to be output</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>
|
/// <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>
|
/// <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 we are in ignore blanks mode AND we have a blank (0-size) rom, skip
|
||||||
if (ignoreblanks
|
if (ignoreblanks
|
||||||
@@ -327,7 +320,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sw">StreamWriter to output to</param>
|
/// <param name="sw">StreamWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
/// <returns>True if the data was written, false on error</returns>
|
||||||
private static bool WriteFooter(StreamWriter sw)
|
private bool WriteFooter(StreamWriter sw)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,9 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using System.Xml;
|
|
||||||
|
|
||||||
using SabreTools.Library.Data;
|
using SabreTools.Library.Data;
|
||||||
using SabreTools.Library.Items;
|
using SabreTools.Library.Items;
|
||||||
@@ -26,20 +24,17 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents parsing and writing of a RomCenter DAT
|
/// Represents parsing and writing of a RomCenter DAT
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class RomCenter
|
public class RomCenter : DatFile
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parse a RomCenter DAT and return all found games and roms within
|
/// Parse a RomCenter DAT and return all found games and roms within
|
||||||
/// </summary>
|
/// </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="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="sysid">System ID for the DAT</param>
|
/// <param name="sysid">System ID for the DAT</param>
|
||||||
/// <param name="srcid">Source 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="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>
|
/// <param name="remUnicode">True if we should remove non-ASCII characters from output, false otherwise (default)</param>
|
||||||
public static void Parse(
|
public void Parse(
|
||||||
DatFile datFile,
|
|
||||||
|
|
||||||
// Standard Dat parsing
|
// Standard Dat parsing
|
||||||
string filename,
|
string filename,
|
||||||
int sysid,
|
int sysid,
|
||||||
@@ -84,7 +79,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
// If we have an author
|
// If we have an author
|
||||||
if (line.ToLowerInvariant().StartsWith("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
|
// If we have one of the three version tags
|
||||||
else if (line.ToLowerInvariant().StartsWith("version="))
|
else if (line.ToLowerInvariant().StartsWith("version="))
|
||||||
@@ -92,31 +87,31 @@ namespace SabreTools.Library.DatFiles
|
|||||||
switch (blocktype)
|
switch (blocktype)
|
||||||
{
|
{
|
||||||
case "credits":
|
case "credits":
|
||||||
datFile.Version = (String.IsNullOrEmpty(datFile.Version) ? line.Split('=')[1] : datFile.Version);
|
Version = (String.IsNullOrEmpty(Version) ? line.Split('=')[1] : Version);
|
||||||
break;
|
break;
|
||||||
case "emulator":
|
case "emulator":
|
||||||
datFile.Description = (String.IsNullOrEmpty(datFile.Description) ? line.Split('=')[1] : datFile.Description);
|
Description = (String.IsNullOrEmpty(Description) ? line.Split('=')[1] : Description);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If we have a URL
|
// If we have a URL
|
||||||
else if (line.ToLowerInvariant().StartsWith("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
|
// If we have a comment
|
||||||
else if (line.ToLowerInvariant().StartsWith("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
|
// If we have the split flag
|
||||||
else if (line.ToLowerInvariant().StartsWith("split="))
|
else if (line.ToLowerInvariant().StartsWith("split="))
|
||||||
{
|
{
|
||||||
if (Int32.TryParse(line.Split('=')[1], out int 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 (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
|
// If we have the refname tag
|
||||||
else if (line.ToLowerInvariant().StartsWith("refname="))
|
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
|
// If we have a rom
|
||||||
else if (line.StartsWith("¬"))
|
else if (line.StartsWith("¬"))
|
||||||
@@ -182,7 +177,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Now process and add the rom
|
// Now process and add the rom
|
||||||
datFile.ParseAddHelper(rom, clean, remUnicode);
|
ParseAddHelper(rom, clean, remUnicode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -193,11 +188,10 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create and open an output file for writing direct from a dictionary
|
/// Create and open an output file for writing direct from a dictionary
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="datFile">DatFile to write out from</param>
|
|
||||||
/// <param name="outfile">Name of the file to write to</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>
|
/// <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>
|
/// <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
|
try
|
||||||
{
|
{
|
||||||
@@ -214,19 +208,19 @@ namespace SabreTools.Library.DatFiles
|
|||||||
StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(true));
|
StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(true));
|
||||||
|
|
||||||
// Write out the header
|
// Write out the header
|
||||||
WriteHeader(datFile, sw);
|
WriteHeader(sw);
|
||||||
|
|
||||||
// Write out each of the machines and roms
|
// Write out each of the machines and roms
|
||||||
string lastgame = null;
|
string lastgame = null;
|
||||||
List<string> splitpath = new List<string>();
|
List<string> splitpath = new List<string>();
|
||||||
|
|
||||||
// Get a properly sorted set of keys
|
// Get a properly sorted set of keys
|
||||||
List<string> keys = datFile.Keys.ToList();
|
List<string> keys = Keys.ToList();
|
||||||
keys.Sort(new NaturalComparer());
|
keys.Sort(new NaturalComparer());
|
||||||
|
|
||||||
foreach (string key in keys)
|
foreach (string key in keys)
|
||||||
{
|
{
|
||||||
List<DatItem> roms = datFile[key];
|
List<DatItem> roms = this[key];
|
||||||
|
|
||||||
// Resolve the names in the block
|
// Resolve the names in the block
|
||||||
roms = DatItem.ResolveNames(roms);
|
roms = DatItem.ResolveNames(roms);
|
||||||
@@ -283,24 +277,23 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out DAT header using the supplied StreamWriter
|
/// Write out DAT header using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="datFile">DatFile to write out from</param>
|
|
||||||
/// <param name="sw">StreamWriter to output to</param>
|
/// <param name="sw">StreamWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
/// <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
|
try
|
||||||
{
|
{
|
||||||
string header = header = "[CREDITS]\n" +
|
string header = header = "[CREDITS]\n" +
|
||||||
"author=" + datFile.Author + "\n" +
|
"author=" + Author + "\n" +
|
||||||
"version=" + datFile.Version + "\n" +
|
"version=" + Version + "\n" +
|
||||||
"comment=" + datFile.Comment + "\n" +
|
"comment=" + Comment + "\n" +
|
||||||
"[DAT]\n" +
|
"[DAT]\n" +
|
||||||
"version=2.50\n" +
|
"version=2.50\n" +
|
||||||
"split=" + (datFile.ForceMerging == ForceMerging.Split ? "1" : "0") + "\n" +
|
"split=" + (ForceMerging == ForceMerging.Split ? "1" : "0") + "\n" +
|
||||||
"merge=" + (datFile.ForceMerging == ForceMerging.Full || datFile.ForceMerging == ForceMerging.Merged ? "1" : "0") + "\n" +
|
"merge=" + (ForceMerging == ForceMerging.Full || ForceMerging == ForceMerging.Merged ? "1" : "0") + "\n" +
|
||||||
"[EMULATOR]\n" +
|
"[EMULATOR]\n" +
|
||||||
"refname=" + datFile.Name + "\n" +
|
"refname=" + Name + "\n" +
|
||||||
"version=" + datFile.Description + "\n" +
|
"version=" + Description + "\n" +
|
||||||
"[GAMES]\n";
|
"[GAMES]\n";
|
||||||
|
|
||||||
// Write the header out
|
// Write the header out
|
||||||
@@ -323,7 +316,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="rom">RomData object to be output</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>
|
/// <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>
|
/// <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 we are in ignore blanks mode AND we have a blank (0-size) rom, skip
|
||||||
if (ignoreblanks
|
if (ignoreblanks
|
||||||
|
|||||||
@@ -2,9 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using System.Xml;
|
|
||||||
|
|
||||||
using SabreTools.Library.Data;
|
using SabreTools.Library.Data;
|
||||||
using SabreTools.Library.Items;
|
using SabreTools.Library.Items;
|
||||||
@@ -16,7 +14,6 @@ using System.IO;
|
|||||||
using Alphaleonis.Win32.Filesystem;
|
using Alphaleonis.Win32.Filesystem;
|
||||||
|
|
||||||
using FileStream = System.IO.FileStream;
|
using FileStream = System.IO.FileStream;
|
||||||
using StreamReader = System.IO.StreamReader;
|
|
||||||
using StreamWriter = System.IO.StreamWriter;
|
using StreamWriter = System.IO.StreamWriter;
|
||||||
#endif
|
#endif
|
||||||
using NaturalSort;
|
using NaturalSort;
|
||||||
@@ -26,12 +23,11 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents parsing and writing of an SabreDat XML DAT
|
/// Represents parsing and writing of an SabreDat XML DAT
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SabreDat
|
public class SabreDat : DatFile
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parse an SabreDat XML DAT and return all found games and roms within
|
/// Parse an SabreDat XML DAT and return all found games and roms within
|
||||||
/// </summary>
|
/// </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="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="sysid">System ID for the DAT</param>
|
/// <param name="sysid">System ID for the DAT</param>
|
||||||
/// <param name="srcid">Source 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>
|
/// <param name="remUnicode">True if we should remove non-ASCII characters from output, false otherwise (default)</param>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public static void Parse(
|
public void Parse(
|
||||||
DatFile datFile,
|
|
||||||
|
|
||||||
// Standard Dat parsing
|
// Standard Dat parsing
|
||||||
string filename,
|
string filename,
|
||||||
int sysid,
|
int sysid,
|
||||||
@@ -54,20 +48,16 @@ namespace SabreTools.Library.DatFiles
|
|||||||
bool remUnicode)
|
bool remUnicode)
|
||||||
{
|
{
|
||||||
// All XML-derived DATs share a lot in common so it just calls one implementation
|
// 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>
|
/// <summary>
|
||||||
/// Create and open an output file for writing direct from a dictionary
|
/// Create and open an output file for writing direct from a dictionary
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="datFile">DatFile to write out from</param>
|
|
||||||
/// <param name="outfile">Name of the file to write to</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="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>
|
/// <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
|
try
|
||||||
{
|
{
|
||||||
@@ -84,7 +74,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(true));
|
StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(true));
|
||||||
|
|
||||||
// Write out the header
|
// Write out the header
|
||||||
WriteHeader(datFile, sw);
|
WriteHeader(sw);
|
||||||
|
|
||||||
// Write out each of the machines and roms
|
// Write out each of the machines and roms
|
||||||
int depth = 2, last = -1;
|
int depth = 2, last = -1;
|
||||||
@@ -92,12 +82,12 @@ namespace SabreTools.Library.DatFiles
|
|||||||
List<string> splitpath = new List<string>();
|
List<string> splitpath = new List<string>();
|
||||||
|
|
||||||
// Get a properly sorted set of keys
|
// Get a properly sorted set of keys
|
||||||
List<string> keys = datFile.Keys.ToList();
|
List<string> keys = Keys.ToList();
|
||||||
keys.Sort(new NaturalComparer());
|
keys.Sort(new NaturalComparer());
|
||||||
|
|
||||||
foreach (string key in keys)
|
foreach (string key in keys)
|
||||||
{
|
{
|
||||||
List<DatItem> roms = datFile[key];
|
List<DatItem> roms = this[key];
|
||||||
|
|
||||||
// Resolve the names in the block
|
// Resolve the names in the block
|
||||||
roms = DatItem.ResolveNames(roms);
|
roms = DatItem.ResolveNames(roms);
|
||||||
@@ -167,10 +157,9 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out DAT header using the supplied StreamWriter
|
/// Write out DAT header using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="datFile">DatFile to write out from</param>
|
|
||||||
/// <param name="sw">StreamWriter to output to</param>
|
/// <param name="sw">StreamWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
/// <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
|
try
|
||||||
{
|
{
|
||||||
@@ -178,26 +167,26 @@ namespace SabreTools.Library.DatFiles
|
|||||||
"<!DOCTYPE sabredat SYSTEM \"newdat.xsd\">\n\n" +
|
"<!DOCTYPE sabredat SYSTEM \"newdat.xsd\">\n\n" +
|
||||||
"<datafile>\n" +
|
"<datafile>\n" +
|
||||||
"\t<header>\n" +
|
"\t<header>\n" +
|
||||||
"\t\t<name>" + HttpUtility.HtmlEncode(datFile.Name) + "</name>\n" +
|
"\t\t<name>" + HttpUtility.HtmlEncode(Name) + "</name>\n" +
|
||||||
"\t\t<description>" + HttpUtility.HtmlEncode(datFile.Description) + "</description>\n" +
|
"\t\t<description>" + HttpUtility.HtmlEncode(Description) + "</description>\n" +
|
||||||
(!String.IsNullOrEmpty(datFile.RootDir) ? "\t\t<rootdir>" + HttpUtility.HtmlEncode(datFile.RootDir) + "</rootdir>\n" : "") +
|
(!String.IsNullOrEmpty(RootDir) ? "\t\t<rootdir>" + HttpUtility.HtmlEncode(RootDir) + "</rootdir>\n" : "") +
|
||||||
(!String.IsNullOrEmpty(datFile.Category) ? "\t\t<category>" + HttpUtility.HtmlEncode(datFile.Category) + "</category>\n" : "") +
|
(!String.IsNullOrEmpty(Category) ? "\t\t<category>" + HttpUtility.HtmlEncode(Category) + "</category>\n" : "") +
|
||||||
"\t\t<version>" + HttpUtility.HtmlEncode(datFile.Version) + "</version>\n" +
|
"\t\t<version>" + HttpUtility.HtmlEncode(Version) + "</version>\n" +
|
||||||
(!String.IsNullOrEmpty(datFile.Date) ? "\t\t<date>" + HttpUtility.HtmlEncode(datFile.Date) + "</date>\n" : "") +
|
(!String.IsNullOrEmpty(Date) ? "\t\t<date>" + HttpUtility.HtmlEncode(Date) + "</date>\n" : "") +
|
||||||
"\t\t<author>" + HttpUtility.HtmlEncode(datFile.Author) + "</author>\n" +
|
"\t\t<author>" + HttpUtility.HtmlEncode(Author) + "</author>\n" +
|
||||||
(!String.IsNullOrEmpty(datFile.Comment) ? "\t\t<comment>" + HttpUtility.HtmlEncode(datFile.Comment) + "</comment>\n" : "") +
|
(!String.IsNullOrEmpty(Comment) ? "\t\t<comment>" + HttpUtility.HtmlEncode(Comment) + "</comment>\n" : "") +
|
||||||
(!String.IsNullOrEmpty(datFile.Type) || datFile.ForcePacking != ForcePacking.None || datFile.ForceMerging != ForceMerging.None || datFile.ForceNodump != ForceNodump.None ?
|
(!String.IsNullOrEmpty(Type) || ForcePacking != ForcePacking.None || ForceMerging != ForceMerging.None || ForceNodump != ForceNodump.None ?
|
||||||
"\t\t<flags>\n" +
|
"\t\t<flags>\n" +
|
||||||
(!String.IsNullOrEmpty(datFile.Type) ? "\t\t\t<flag name=\"type\" value=\"" + HttpUtility.HtmlEncode(datFile.Type) + "\"/>\n" : "") +
|
(!String.IsNullOrEmpty(Type) ? "\t\t\t<flag name=\"type\" value=\"" + HttpUtility.HtmlEncode(Type) + "\"/>\n" : "") +
|
||||||
(datFile.ForcePacking == ForcePacking.Unzip ? "\t\t\t<flag name=\"forcepacking\" value=\"unzip\"/>\n" : "") +
|
(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" : "") +
|
(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" : "") +
|
(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" : "") +
|
(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" : "") +
|
(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" : "") +
|
(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" : "") +
|
(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" : "") +
|
(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" : "") +
|
(ForceNodump == ForceNodump.Required ? "\t\t\t<flag name=\"forcenodump\" value=\"required\"/>\n" : "") +
|
||||||
"\t\t</flags>\n"
|
"\t\t</flags>\n"
|
||||||
: "") +
|
: "") +
|
||||||
"\t</header>\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="depth">Current depth to output file at (SabreDAT only)</param>
|
||||||
/// <param name="last">Last known depth to cycle back from (SabreDAT only)</param>
|
/// <param name="last">Last known depth to cycle back from (SabreDAT only)</param>
|
||||||
/// <returns>The new depth of the tag</returns>
|
/// <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
|
try
|
||||||
{
|
{
|
||||||
@@ -269,7 +258,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="depth">Current depth to output file at (SabreDAT only)</param>
|
/// <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>
|
/// <param name="last">Last known depth to cycle back from (SabreDAT only)</param>
|
||||||
/// <returns>The new depth of the tag</returns>
|
/// <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;
|
last = 0;
|
||||||
|
|
||||||
@@ -325,7 +314,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="depth">Current depth to output file at (SabreDAT only)</param>
|
/// <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>
|
/// <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>
|
/// <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 we are in ignore blanks mode AND we have a blank (0-size) rom, skip
|
||||||
if (ignoreblanks
|
if (ignoreblanks
|
||||||
@@ -419,7 +408,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="sw">StreamWriter to output to</param>
|
/// <param name="sw">StreamWriter to output to</param>
|
||||||
/// <param name="depth">Current depth to output file at (SabreDAT only)</param>
|
/// <param name="depth">Current depth to output file at (SabreDAT only)</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
/// <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
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,12 +21,11 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents parsing and writing of a value-separated DAT
|
/// Represents parsing and writing of a value-separated DAT
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SeparatedValue
|
public class SeparatedValue : DatFile
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parse a character-separated value DAT and return all found games and roms within
|
/// Parse a character-separated value DAT and return all found games and roms within
|
||||||
/// </summary>
|
/// </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="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="sysid">System ID for the DAT</param>
|
/// <param name="sysid">System ID for the DAT</param>
|
||||||
/// <param name="srcid">Source 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="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="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>
|
/// <param name="remUnicode">True if we should remove non-ASCII characters from output, false otherwise (default)</param>
|
||||||
public static void Parse(
|
public void Parse(
|
||||||
DatFile datFile,
|
|
||||||
|
|
||||||
// Standard Dat parsing
|
// Standard Dat parsing
|
||||||
string filename,
|
string filename,
|
||||||
int sysid,
|
int sysid,
|
||||||
@@ -177,13 +174,13 @@ namespace SabreTools.Library.DatFiles
|
|||||||
switch (columns[i])
|
switch (columns[i])
|
||||||
{
|
{
|
||||||
case "DatFile.FileName":
|
case "DatFile.FileName":
|
||||||
datFile.FileName = (String.IsNullOrEmpty(datFile.FileName) ? value : datFile.FileName);
|
FileName = (String.IsNullOrEmpty(FileName) ? value : FileName);
|
||||||
break;
|
break;
|
||||||
case "DatFile.Name":
|
case "DatFile.Name":
|
||||||
datFile.Name = (String.IsNullOrEmpty(datFile.Name) ? value : datFile.Name);
|
Name = (String.IsNullOrEmpty(Name) ? value : Name);
|
||||||
break;
|
break;
|
||||||
case "DatFile.Description":
|
case "DatFile.Description":
|
||||||
datFile.Description = (String.IsNullOrEmpty(datFile.Description) ? value : datFile.Description);
|
Description = (String.IsNullOrEmpty(Description) ? value : Description);
|
||||||
break;
|
break;
|
||||||
case "Machine.Name":
|
case "Machine.Name":
|
||||||
machineName = value;
|
machineName = value;
|
||||||
@@ -279,7 +276,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
MachineDescription = machineDesc,
|
MachineDescription = machineDesc,
|
||||||
};
|
};
|
||||||
|
|
||||||
datFile.ParseAddHelper(archive, clean, remUnicode);
|
ParseAddHelper(archive, clean, remUnicode);
|
||||||
break;
|
break;
|
||||||
case ItemType.BiosSet:
|
case ItemType.BiosSet:
|
||||||
BiosSet biosset = new BiosSet()
|
BiosSet biosset = new BiosSet()
|
||||||
@@ -290,7 +287,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
Description = machineDesc,
|
Description = machineDesc,
|
||||||
};
|
};
|
||||||
|
|
||||||
datFile.ParseAddHelper(biosset, clean, remUnicode);
|
ParseAddHelper(biosset, clean, remUnicode);
|
||||||
break;
|
break;
|
||||||
case ItemType.Disk:
|
case ItemType.Disk:
|
||||||
Disk disk = new Disk()
|
Disk disk = new Disk()
|
||||||
@@ -308,7 +305,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
ItemStatus = status,
|
ItemStatus = status,
|
||||||
};
|
};
|
||||||
|
|
||||||
datFile.ParseAddHelper(disk, clean, remUnicode);
|
ParseAddHelper(disk, clean, remUnicode);
|
||||||
break;
|
break;
|
||||||
case ItemType.Release:
|
case ItemType.Release:
|
||||||
Release release = new Release()
|
Release release = new Release()
|
||||||
@@ -319,7 +316,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
MachineDescription = machineDesc,
|
MachineDescription = machineDesc,
|
||||||
};
|
};
|
||||||
|
|
||||||
datFile.ParseAddHelper(release, clean, remUnicode);
|
ParseAddHelper(release, clean, remUnicode);
|
||||||
break;
|
break;
|
||||||
case ItemType.Rom:
|
case ItemType.Rom:
|
||||||
Rom rom = new Rom()
|
Rom rom = new Rom()
|
||||||
@@ -339,7 +336,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
ItemStatus = status,
|
ItemStatus = status,
|
||||||
};
|
};
|
||||||
|
|
||||||
datFile.ParseAddHelper(rom, clean, remUnicode);
|
ParseAddHelper(rom, clean, remUnicode);
|
||||||
break;
|
break;
|
||||||
case ItemType.Sample:
|
case ItemType.Sample:
|
||||||
Sample sample = new Sample()
|
Sample sample = new Sample()
|
||||||
@@ -350,7 +347,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
MachineDescription = machineDesc,
|
MachineDescription = machineDesc,
|
||||||
};
|
};
|
||||||
|
|
||||||
datFile.ParseAddHelper(sample, clean, remUnicode);
|
ParseAddHelper(sample, clean, remUnicode);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -359,12 +356,11 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create and open an output file for writing direct from a dictionary
|
/// Create and open an output file for writing direct from a dictionary
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="datFile">DatFile to write out from</param>
|
|
||||||
/// <param name="outfile">Name of the file to write to</param>
|
/// <param name="outfile">Name of the file to write to</param>
|
||||||
/// <param name="delim">Delimiter for parsing individual lines</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>
|
/// <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>
|
/// <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
|
try
|
||||||
{
|
{
|
||||||
@@ -384,12 +380,12 @@ namespace SabreTools.Library.DatFiles
|
|||||||
WriteHeader(sw, delim);
|
WriteHeader(sw, delim);
|
||||||
|
|
||||||
// Get a properly sorted set of keys
|
// Get a properly sorted set of keys
|
||||||
List<string> keys = datFile.Keys.ToList();
|
List<string> keys = Keys.ToList();
|
||||||
keys.Sort(new NaturalComparer());
|
keys.Sort(new NaturalComparer());
|
||||||
|
|
||||||
foreach (string key in keys)
|
foreach (string key in keys)
|
||||||
{
|
{
|
||||||
List<DatItem> roms = datFile[key];
|
List<DatItem> roms = this[key];
|
||||||
|
|
||||||
// Resolve the names in the block
|
// Resolve the names in the block
|
||||||
roms = DatItem.ResolveNames(roms);
|
roms = DatItem.ResolveNames(roms);
|
||||||
@@ -414,7 +410,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now, output the rom data
|
// 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="sw">StreamWriter to output to</param>
|
||||||
/// <param name="delim">Delimiter for parsing individual lines</param>
|
/// <param name="delim">Delimiter for parsing individual lines</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
/// <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
|
try
|
||||||
{
|
{
|
||||||
@@ -460,13 +456,12 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out RomData using the supplied StreamWriter
|
/// Write out RomData using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="datFile">DatFile to write out from</param>
|
|
||||||
/// <param name="sw">StreamWriter to output to</param>
|
/// <param name="sw">StreamWriter to output to</param>
|
||||||
/// <param name="delim">Delimiter for parsing individual lines</param>
|
/// <param name="delim">Delimiter for parsing individual lines</param>
|
||||||
/// <param name="rom">RomData object to be output</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>
|
/// <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>
|
/// <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 we are in ignore blanks mode AND we have a blank (0-size) rom, skip
|
||||||
if (ignoreblanks
|
if (ignoreblanks
|
||||||
@@ -478,7 +473,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string state = "", name = "", pre = "", post = "";
|
string state = "", pre = "", post = "";
|
||||||
|
|
||||||
// Separated values should only output Rom and Disk
|
// Separated values should only output Rom and Disk
|
||||||
if (rom.Type != ItemType.Disk && rom.Type != ItemType.Rom)
|
if (rom.Type != ItemType.Disk && rom.Type != ItemType.Rom)
|
||||||
@@ -486,8 +481,8 @@ namespace SabreTools.Library.DatFiles
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
pre = datFile.Prefix + (datFile.Quotes ? "\"" : "");
|
pre = Prefix + (Quotes ? "\"" : "");
|
||||||
post = (datFile.Quotes ? "\"" : "") + datFile.Postfix;
|
post = (Quotes ? "\"" : "") + Postfix;
|
||||||
|
|
||||||
if (rom.Type == ItemType.Rom)
|
if (rom.Type == ItemType.Rom)
|
||||||
{
|
{
|
||||||
@@ -558,9 +553,9 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
if (rom.Type == ItemType.Rom)
|
if (rom.Type == ItemType.Rom)
|
||||||
{
|
{
|
||||||
string inline = string.Format("\"" + datFile.FileName + "\""
|
string inline = string.Format("\"" + FileName + "\""
|
||||||
+ "{0}\"" + datFile.Name + "\""
|
+ "{0}\"" + Name + "\""
|
||||||
+ "{0}\"" + datFile.Description + "\""
|
+ "{0}\"" + Description + "\""
|
||||||
+ "{0}\"" + rom.MachineName + "\""
|
+ "{0}\"" + rom.MachineName + "\""
|
||||||
+ "{0}\"" + rom.MachineDescription + "\""
|
+ "{0}\"" + rom.MachineDescription + "\""
|
||||||
+ "{0}" + "\"rom\""
|
+ "{0}" + "\"rom\""
|
||||||
@@ -578,9 +573,9 @@ namespace SabreTools.Library.DatFiles
|
|||||||
}
|
}
|
||||||
else if (rom.Type == ItemType.Disk)
|
else if (rom.Type == ItemType.Disk)
|
||||||
{
|
{
|
||||||
string inline = string.Format("\"" + datFile.FileName + "\""
|
string inline = string.Format("\"" + FileName + "\""
|
||||||
+ "{0}\"" + datFile.Name + "\""
|
+ "{0}\"" + Name + "\""
|
||||||
+ "{0}\"" + datFile.Description + "\""
|
+ "{0}\"" + Description + "\""
|
||||||
+ "{0}\"" + rom.MachineName + "\""
|
+ "{0}\"" + rom.MachineName + "\""
|
||||||
+ "{0}\"" + rom.MachineDescription + "\""
|
+ "{0}\"" + rom.MachineDescription + "\""
|
||||||
+ "{0}" + "\"disk\""
|
+ "{0}" + "\"disk\""
|
||||||
|
|||||||
@@ -23,12 +23,11 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents parsing and writing of an SabreDat XML DAT
|
/// Represents parsing and writing of an SabreDat XML DAT
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class SoftwareList
|
public class SoftwareList : DatFile
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parse an SabreDat XML DAT and return all found games and roms within
|
/// Parse an SabreDat XML DAT and return all found games and roms within
|
||||||
/// </summary>
|
/// </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="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="sysid">System ID for the DAT</param>
|
/// <param name="sysid">System ID for the DAT</param>
|
||||||
/// <param name="srcid">Source 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>
|
/// <param name="remUnicode">True if we should remove non-ASCII characters from output, false otherwise (default)</param>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public static void Parse(
|
public void Parse(
|
||||||
DatFile datFile,
|
DatFile datFile,
|
||||||
|
|
||||||
// Standard Dat parsing
|
// Standard Dat parsing
|
||||||
@@ -51,17 +50,16 @@ namespace SabreTools.Library.DatFiles
|
|||||||
bool remUnicode)
|
bool remUnicode)
|
||||||
{
|
{
|
||||||
// All XML-derived DATs share a lot in common so it just calls one implementation
|
// 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>
|
/// <summary>
|
||||||
/// Create and open an output file for writing direct from a dictionary
|
/// Create and open an output file for writing direct from a dictionary
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="datFile">DatFile to write out from</param>
|
|
||||||
/// <param name="outfile">Name of the file to write to</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>
|
/// <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>
|
/// <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
|
try
|
||||||
{
|
{
|
||||||
@@ -78,18 +76,18 @@ namespace SabreTools.Library.DatFiles
|
|||||||
StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(true));
|
StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(true));
|
||||||
|
|
||||||
// Write out the header
|
// Write out the header
|
||||||
WriteHeader(datFile, sw);
|
WriteHeader(sw);
|
||||||
|
|
||||||
// Write out each of the machines and roms
|
// Write out each of the machines and roms
|
||||||
string lastgame = null;
|
string lastgame = null;
|
||||||
|
|
||||||
// Get a properly sorted set of keys
|
// Get a properly sorted set of keys
|
||||||
List<string> keys = datFile.Keys.ToList();
|
List<string> keys = Keys.ToList();
|
||||||
keys.Sort(new NaturalComparer());
|
keys.Sort(new NaturalComparer());
|
||||||
|
|
||||||
foreach (string key in keys)
|
foreach (string key in keys)
|
||||||
{
|
{
|
||||||
List<DatItem> roms = datFile[key];
|
List<DatItem> roms = this[key];
|
||||||
|
|
||||||
// Resolve the names in the block
|
// Resolve the names in the block
|
||||||
roms = DatItem.ResolveNames(roms);
|
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 we have a new game, output the beginning of the new item
|
||||||
if (lastgame == null || lastgame.ToLowerInvariant() != rom.MachineName.ToLowerInvariant())
|
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
|
// 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>
|
/// <summary>
|
||||||
/// Write out DAT header using the supplied StreamWriter
|
/// Write out DAT header using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="datFile">DatFile to write out from</param>
|
|
||||||
/// <param name="sw">StreamWriter to output to</param>
|
/// <param name="sw">StreamWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
/// <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
|
try
|
||||||
{
|
{
|
||||||
string header = "<?xml version=\"1.0\"?>\n" +
|
string header = "<?xml version=\"1.0\"?>\n" +
|
||||||
"<!DOCTYPE softwarelist SYSTEM \"softwarelist.dtd\">\n\n" +
|
"<!DOCTYPE softwarelist SYSTEM \"softwarelist.dtd\">\n\n" +
|
||||||
"<softwarelist name=\"" + HttpUtility.HtmlEncode(datFile.Name) + "\"" +
|
"<softwarelist name=\"" + HttpUtility.HtmlEncode(Name) + "\"" +
|
||||||
" description=\"" + HttpUtility.HtmlEncode(datFile.Description) + "\"" +
|
" description=\"" + HttpUtility.HtmlEncode(Description) + "\"" +
|
||||||
(datFile.ForcePacking == ForcePacking.Unzip ? " forcepacking=\"unzip\"" : "") +
|
(ForcePacking == ForcePacking.Unzip ? " forcepacking=\"unzip\"" : "") +
|
||||||
(datFile.ForcePacking == ForcePacking.Zip ? " forcepacking=\"zip\"" : "") +
|
(ForcePacking == ForcePacking.Zip ? " forcepacking=\"zip\"" : "") +
|
||||||
(datFile.ForceMerging == ForceMerging.Full ? " forcemerging=\"full\"" : "") +
|
(ForceMerging == ForceMerging.Full ? " forcemerging=\"full\"" : "") +
|
||||||
(datFile.ForceMerging == ForceMerging.Split ? " forcemerging=\"split\"" : "") +
|
(ForceMerging == ForceMerging.Split ? " forcemerging=\"split\"" : "") +
|
||||||
(datFile.ForceMerging == ForceMerging.Merged ? " forcemerging=\"merged\"" : "") +
|
(ForceMerging == ForceMerging.Merged ? " forcemerging=\"merged\"" : "") +
|
||||||
(datFile.ForceMerging == ForceMerging.NonMerged ? " forcemerging=\"nonmerged\"" : "") +
|
(ForceMerging == ForceMerging.NonMerged ? " forcemerging=\"nonmerged\"" : "") +
|
||||||
(datFile.ForceNodump == ForceNodump.Ignore ? " forcenodump=\"ignore\"" : "") +
|
(ForceNodump == ForceNodump.Ignore ? " forcenodump=\"ignore\"" : "") +
|
||||||
(datFile.ForceNodump == ForceNodump.Obsolete ? " forcenodump=\"obsolete\"" : "") +
|
(ForceNodump == ForceNodump.Obsolete ? " forcenodump=\"obsolete\"" : "") +
|
||||||
(datFile.ForceNodump == ForceNodump.Required ? " forcenodump=\"required\"" : "") +
|
(ForceNodump == ForceNodump.Required ? " forcenodump=\"required\"" : "") +
|
||||||
">\n\n";
|
">\n\n";
|
||||||
|
|
||||||
// Write the header out
|
// Write the header out
|
||||||
@@ -193,11 +190,10 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out Game start using the supplied StreamWriter
|
/// Write out Game start using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="datFile">DatFile to write out from</param>
|
|
||||||
/// <param name="sw">StreamWriter to output to</param>
|
/// <param name="sw">StreamWriter to output to</param>
|
||||||
/// <param name="rom">RomData object to be output</param>
|
/// <param name="rom">RomData object to be output</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
/// <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
|
try
|
||||||
{
|
{
|
||||||
@@ -209,7 +205,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
string state = "\t<software name=\"" + HttpUtility.HtmlEncode(rom.MachineName) + "\""
|
string state = "\t<software name=\"" + HttpUtility.HtmlEncode(rom.MachineName) + "\""
|
||||||
+ (rom.Supported != null ? " supported=\"" + (rom.Supported == true ? "yes" : "no") + "\"" : "") +
|
+ (rom.Supported != null ? " supported=\"" + (rom.Supported == true ? "yes" : "no") + "\"" : "") +
|
||||||
(datFile.ExcludeOf ? "" :
|
(ExcludeOf ? "" :
|
||||||
(String.IsNullOrEmpty(rom.CloneOf) || (rom.MachineName.ToLowerInvariant() == rom.CloneOf.ToLowerInvariant())
|
(String.IsNullOrEmpty(rom.CloneOf) || (rom.MachineName.ToLowerInvariant() == rom.CloneOf.ToLowerInvariant())
|
||||||
? ""
|
? ""
|
||||||
: " cloneof=\"" + HttpUtility.HtmlEncode(rom.CloneOf) + "\"") +
|
: " cloneof=\"" + HttpUtility.HtmlEncode(rom.CloneOf) + "\"") +
|
||||||
@@ -246,7 +242,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sw">StreamWriter to output to</param>
|
/// <param name="sw">StreamWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
/// <returns>True if the data was written, false on error</returns>
|
||||||
private static bool WriteEndGame(StreamWriter sw)
|
private bool WriteEndGame(StreamWriter sw)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -271,7 +267,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="rom">RomData object to be output</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>
|
/// <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>
|
/// <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 we are in ignore blanks mode AND we have a blank (0-size) rom, skip
|
||||||
if (ignoreblanks
|
if (ignoreblanks
|
||||||
@@ -381,7 +377,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sw">StreamWriter to output to</param>
|
/// <param name="sw">StreamWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
/// <returns>True if the data was written, false on error</returns>
|
||||||
private static bool WriteFooter(StreamWriter sw)
|
private bool WriteFooter(StreamWriter sw)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user