mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Make less things use global throw state
This commit is contained in:
@@ -29,7 +29,8 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="filename">Name of the file to be parsed</param>
|
/// <param name="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</param>
|
/// <param name="indexId">Index 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>
|
||||||
protected override void ParseFile(string filename, int indexId, bool keep)
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
|
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
|
||||||
{
|
{
|
||||||
// Open a file reader
|
// Open a file reader
|
||||||
Encoding enc = FileExtensions.GetEncoding(filename);
|
Encoding enc = FileExtensions.GetEncoding(filename);
|
||||||
@@ -62,9 +63,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
catch (InvalidDataException ex)
|
catch (InvalidDataException ex)
|
||||||
{
|
{
|
||||||
Globals.Logger.Warning($"Malformed line found in '{filename}' at line {svr.LineNumber}");
|
Globals.Logger.Warning($"Malformed line found in '{filename}' at line {svr.LineNumber}");
|
||||||
if (Globals.ThrowOnError)
|
if (throwOnError) throw ex;
|
||||||
throw ex;
|
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,8 +116,9 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <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>
|
||||||
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
||||||
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
|
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -170,9 +170,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Globals.Logger.Error(ex.ToString());
|
Globals.Logger.Error(ex.ToString());
|
||||||
if (Globals.ThrowOnError)
|
if (throwOnError) throw ex;
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,10 +181,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// Write out DAT header using the supplied StreamWriter
|
/// Write out DAT header using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="svw">SeparatedValueWriter to output to</param>
|
/// <param name="svw">SeparatedValueWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteHeader(SeparatedValueWriter svw)
|
||||||
private bool WriteHeader(SeparatedValueWriter svw)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
string[] headers = new string[]
|
string[] headers = new string[]
|
||||||
{
|
{
|
||||||
@@ -213,27 +208,14 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
svw.Flush();
|
svw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out Game start using the supplied StreamWriter
|
/// Write out Game start using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="svw">SeparatedValueWriter to output to</param>
|
/// <param name="svw">SeparatedValueWriter to output to</param>
|
||||||
/// <param name="datItem">DatItem object to be output</param>
|
/// <param name="datItem">DatItem object to be output</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
private bool WriteDatItem(SeparatedValueWriter svw, DatItem datItem)
|
private void WriteDatItem(SeparatedValueWriter svw, DatItem datItem)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// No game should start with a path separator
|
// No game should start with a path separator
|
||||||
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar);
|
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar);
|
||||||
@@ -273,16 +255,5 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
svw.Flush();
|
svw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="filename">Name of the file to be parsed</param>
|
/// <param name="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</param>
|
/// <param name="indexId">Index 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>
|
||||||
protected override void ParseFile(string filename, int indexId, bool keep)
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
|
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
|
||||||
{
|
{
|
||||||
// Open a file reader
|
// Open a file reader
|
||||||
Encoding enc = FileExtensions.GetEncoding(filename);
|
Encoding enc = FileExtensions.GetEncoding(filename);
|
||||||
@@ -412,8 +413,9 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <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>
|
||||||
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
||||||
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
|
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -480,9 +482,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Globals.Logger.Error(ex.ToString());
|
Globals.Logger.Error(ex.ToString());
|
||||||
if (Globals.ThrowOnError)
|
if (throwOnError) throw ex;
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -493,10 +493,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// Write out DAT header using the supplied StreamWriter
|
/// Write out DAT header using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cmpw">ClrMameProWriter to output to</param>
|
/// <param name="cmpw">ClrMameProWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteHeader(ClrMameProWriter cmpw)
|
||||||
private bool WriteHeader(ClrMameProWriter cmpw)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
cmpw.WriteStartElement("clrmamepro");
|
cmpw.WriteStartElement("clrmamepro");
|
||||||
|
|
||||||
@@ -518,27 +515,13 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
cmpw.Flush();
|
cmpw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out Game start using the supplied StreamWriter
|
/// Write out Game start using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cmpw">ClrMameProWriter to output to</param>
|
/// <param name="cmpw">ClrMameProWriter to output to</param>
|
||||||
/// <param name="datItem">DatItem object to be output</param>
|
/// <param name="datItem">DatItem object to be output</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteStartGame(ClrMameProWriter cmpw, DatItem datItem)
|
||||||
private bool WriteStartGame(ClrMameProWriter cmpw, DatItem datItem)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// No game should start with a path separator
|
// No game should start with a path separator
|
||||||
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar);
|
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar);
|
||||||
@@ -556,27 +539,13 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
cmpw.Flush();
|
cmpw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out Game end using the supplied StreamWriter
|
/// Write out Game end using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cmpw">ClrMameProWriter to output to</param>
|
/// <param name="cmpw">ClrMameProWriter to output to</param>
|
||||||
/// <param name="datItem">DatItem object to be output</param>
|
/// <param name="datItem">DatItem object to be output</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteEndGame(ClrMameProWriter cmpw, DatItem datItem)
|
||||||
private bool WriteEndGame(ClrMameProWriter cmpw, DatItem datItem)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// Build the state
|
// Build the state
|
||||||
cmpw.WriteOptionalStandalone("sampleof", datItem.Machine.SampleOf);
|
cmpw.WriteOptionalStandalone("sampleof", datItem.Machine.SampleOf);
|
||||||
@@ -586,17 +555,6 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
cmpw.Flush();
|
cmpw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out DatItem using the supplied StreamWriter
|
/// Write out DatItem using the supplied StreamWriter
|
||||||
@@ -604,10 +562,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="datFile">DatFile to write out from</param>
|
/// <param name="datFile">DatFile to write out from</param>
|
||||||
/// <param name="cmpw">ClrMameProWriter to output to</param>
|
/// <param name="cmpw">ClrMameProWriter to output to</param>
|
||||||
/// <param name="datItem">DatItem object to be output</param>
|
/// <param name="datItem">DatItem object to be output</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteDatItem(ClrMameProWriter cmpw, DatItem datItem)
|
||||||
private bool WriteDatItem(ClrMameProWriter cmpw, DatItem datItem)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// Pre-process the item name
|
// Pre-process the item name
|
||||||
ProcessItemName(datItem, true);
|
ProcessItemName(datItem, true);
|
||||||
@@ -693,42 +648,17 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
cmpw.Flush();
|
cmpw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out DAT footer using the supplied StreamWriter
|
/// Write out DAT footer using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cmpw">ClrMameProWriter to output to</param>
|
/// <param name="cmpw">ClrMameProWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteFooter(ClrMameProWriter cmpw)
|
||||||
private bool WriteFooter(ClrMameProWriter cmpw)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// End game
|
// End game
|
||||||
cmpw.WriteEndElement();
|
cmpw.WriteEndElement();
|
||||||
|
|
||||||
cmpw.Flush();
|
cmpw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1823,10 +1823,16 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="indexId">Index ID for the DAT</param>
|
/// <param name="indexId">Index 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="keepext">True if original extension should be kept, false otherwise (default)</param>
|
/// <param name="keepext">True if original extension should be kept, false otherwise (default)</param>
|
||||||
public void Parse(string filename, int indexId = 0, bool keep = false, bool keepext = false)
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
|
public void Parse(
|
||||||
|
string filename,
|
||||||
|
int indexId = 0,
|
||||||
|
bool keep = false,
|
||||||
|
bool keepext = false,
|
||||||
|
bool throwOnError = false)
|
||||||
{
|
{
|
||||||
ParentablePath path = new ParentablePath(filename.Trim('"'));
|
ParentablePath path = new ParentablePath(filename.Trim('"'));
|
||||||
Parse(path, indexId, keep, keepext);
|
Parse(path, indexId, keep, keepext, throwOnError);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -1836,7 +1842,13 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="indexId">Index ID for the DAT</param>
|
/// <param name="indexId">Index 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="keepext">True if original extension should be kept, false otherwise (default)</param>
|
/// <param name="keepext">True if original extension should be kept, false otherwise (default)</param>
|
||||||
public void Parse(ParentablePath filename, int indexId = 0, bool keep = false, bool keepext = false)
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
|
public void Parse(
|
||||||
|
ParentablePath filename,
|
||||||
|
int indexId = 0,
|
||||||
|
bool keep = false,
|
||||||
|
bool keepext = false,
|
||||||
|
bool throwOnError = false)
|
||||||
{
|
{
|
||||||
// Get the current path from the filename
|
// Get the current path from the filename
|
||||||
string currentPath = filename.CurrentPath;
|
string currentPath = filename.CurrentPath;
|
||||||
@@ -1855,13 +1867,12 @@ namespace SabreTools.Library.DatFiles
|
|||||||
// Now parse the correct type of DAT
|
// Now parse the correct type of DAT
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Create(currentPath.GetDatFormat(), this)?.ParseFile(currentPath, indexId, keep);
|
Create(currentPath.GetDatFormat(), this)?.ParseFile(currentPath, indexId, keep, throwOnError);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Globals.Logger.Error($"Error with file '{filename}': {ex}");
|
Globals.Logger.Error($"Error with file '{filename}': {ex}");
|
||||||
if (Globals.ThrowOnError)
|
if (throwOnError) throw ex;
|
||||||
throw ex;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1976,7 +1987,8 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="filename">Name of the file to be parsed</param>
|
/// <param name="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</param>
|
/// <param name="indexId">Index 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>
|
||||||
protected abstract void ParseFile(string filename, int indexId, bool keep);
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
|
protected abstract void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -3452,8 +3464,14 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="stats">True if DAT statistics should be output on write, false otherwise (default)</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>
|
/// <param name="overwrite">True if files should be overwritten (default), false if they should be renamed instead</param>
|
||||||
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
||||||
public bool Write(string outDir, bool norename = true, bool stats = false, bool ignoreblanks = false, bool overwrite = true)
|
public bool Write(string outDir,
|
||||||
|
bool norename = true,
|
||||||
|
bool stats = false,
|
||||||
|
bool ignoreblanks = false,
|
||||||
|
bool overwrite = true,
|
||||||
|
bool throwOnError = false)
|
||||||
{
|
{
|
||||||
// If we have nothing writable, abort
|
// If we have nothing writable, abort
|
||||||
if (!HasWritable())
|
if (!HasWritable())
|
||||||
@@ -3504,7 +3522,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
string outfile = outfiles[datFormat];
|
string outfile = outfiles[datFormat];
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Create(datFormat, this)?.WriteToFile(outfile, ignoreblanks);
|
Create(datFormat, this)?.WriteToFile(outfile, ignoreblanks, throwOnError);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -3532,8 +3550,9 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <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>
|
||||||
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
||||||
public abstract bool WriteToFile(string outfile, bool ignoreblanks = false);
|
public abstract bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a prefix or postfix from inputs
|
/// Create a prefix or postfix from inputs
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="filename">Name of the file to be parsed</param>
|
/// <param name="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</param>
|
/// <param name="indexId">Index 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>
|
||||||
protected override void ParseFile(string filename, int indexId, bool keep)
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
|
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
|
||||||
{
|
{
|
||||||
// Open a file reader
|
// Open a file reader
|
||||||
Encoding enc = FileExtensions.GetEncoding(filename);
|
Encoding enc = FileExtensions.GetEncoding(filename);
|
||||||
@@ -246,14 +247,14 @@ 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="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>
|
||||||
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
||||||
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
|
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -322,9 +323,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Globals.Logger.Error(ex.ToString());
|
Globals.Logger.Error(ex.ToString());
|
||||||
if (Globals.ThrowOnError)
|
if (throwOnError) throw ex;
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -335,10 +334,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// Write out DAT header using the supplied StreamWriter
|
/// Write out DAT header using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cmpw">ClrMameProWriter to output to</param>
|
/// <param name="cmpw">ClrMameProWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteHeader(ClrMameProWriter cmpw)
|
||||||
private bool WriteHeader(ClrMameProWriter cmpw)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// Build the state
|
// Build the state
|
||||||
cmpw.WriteStartElement("DOSCenter");
|
cmpw.WriteStartElement("DOSCenter");
|
||||||
@@ -355,27 +351,13 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
cmpw.Flush();
|
cmpw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out Game start using the supplied StreamWriter
|
/// Write out Game start using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cmpw">ClrMameProWriter to output to</param>
|
/// <param name="cmpw">ClrMameProWriter to output to</param>
|
||||||
/// <param name="datItem">DatItem object to be output</param>
|
/// <param name="datItem">DatItem object to be output</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteStartGame(ClrMameProWriter cmpw, DatItem datItem)
|
||||||
private bool WriteStartGame(ClrMameProWriter cmpw, DatItem datItem)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// No game should start with a path separator
|
// No game should start with a path separator
|
||||||
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar);
|
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar);
|
||||||
@@ -386,53 +368,25 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
cmpw.Flush();
|
cmpw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out Game end using the supplied StreamWriter
|
/// Write out Game end using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cmpw">ClrMameProWriter to output to</param>
|
/// <param name="cmpw">ClrMameProWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteEndGame(ClrMameProWriter cmpw)
|
||||||
private bool WriteEndGame(ClrMameProWriter cmpw)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// End game
|
// End game
|
||||||
cmpw.WriteEndElement();
|
cmpw.WriteEndElement();
|
||||||
|
|
||||||
cmpw.Flush();
|
cmpw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out DatItem using the supplied StreamWriter
|
/// Write out DatItem using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cmpw">ClrMameProWriter to output to</param>
|
/// <param name="cmpw">ClrMameProWriter to output to</param>
|
||||||
/// <param name="datItem">DatItem object to be output</param>
|
/// <param name="datItem">DatItem object to be output</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteDatItem(ClrMameProWriter cmpw, DatItem datItem)
|
||||||
private bool WriteDatItem(ClrMameProWriter cmpw, DatItem datItem)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// Pre-process the item name
|
// Pre-process the item name
|
||||||
ProcessItemName(datItem, true);
|
ProcessItemName(datItem, true);
|
||||||
@@ -453,42 +407,18 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
cmpw.Flush();
|
cmpw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out DAT footer using the supplied StreamWriter
|
/// Write out DAT footer using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cmpw">ClrMameProWriter to output to</param>
|
/// <param name="cmpw">ClrMameProWriter 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 bool WriteFooter(ClrMameProWriter cmpw)
|
private void WriteFooter(ClrMameProWriter cmpw)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// End game
|
// End game
|
||||||
cmpw.WriteEndElement();
|
cmpw.WriteEndElement();
|
||||||
|
|
||||||
cmpw.Flush();
|
cmpw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="filename">Name of the file to be parsed</param>
|
/// <param name="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</param>
|
/// <param name="indexId">Index 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>
|
||||||
protected override void ParseFile(string filename, int indexId, bool keep)
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
|
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
|
||||||
{
|
{
|
||||||
// Open a file reader
|
// Open a file reader
|
||||||
Encoding enc = FileExtensions.GetEncoding(filename);
|
Encoding enc = FileExtensions.GetEncoding(filename);
|
||||||
@@ -87,8 +88,9 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <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>
|
||||||
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
||||||
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
|
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="filename">Name of the file to be parsed</param>
|
/// <param name="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</param>
|
/// <param name="indexId">Index 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>
|
||||||
protected override void ParseFile(string filename, int indexId, bool keep)
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
|
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
|
||||||
{
|
{
|
||||||
// Open a file reader
|
// Open a file reader
|
||||||
Encoding enc = FileExtensions.GetEncoding(filename);
|
Encoding enc = FileExtensions.GetEncoding(filename);
|
||||||
@@ -102,8 +103,9 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <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>
|
||||||
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
||||||
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
|
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -152,9 +154,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Globals.Logger.Error(ex.ToString());
|
Globals.Logger.Error(ex.ToString());
|
||||||
if (Globals.ThrowOnError)
|
if (throwOnError) throw ex;
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,14 +162,11 @@ namespace SabreTools.Library.DatFiles
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out DatItem using the supplied StreamWriter
|
/// Write out DatItem using the supplied SeparatedValueWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="svw">SeparatedValueWriter to output to</param>
|
/// <param name="svw">SeparatedValueWriter to output to</param>
|
||||||
/// <param name="datItem">DatItem object to be output</param>
|
/// <param name="datItem">DatItem object to be output</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteDatItem(SeparatedValueWriter svw, DatItem datItem)
|
||||||
private bool WriteDatItem(SeparatedValueWriter svw, DatItem datItem)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// Build the state
|
// Build the state
|
||||||
string[] fields = new string[2];
|
string[] fields = new string[2];
|
||||||
@@ -347,16 +344,5 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
svw.Flush();
|
svw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
@@ -32,6 +31,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="filename">Name of the file to be parsed</param>
|
/// <param name="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</param>
|
/// <param name="indexId">Index 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="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// In a new style MAME listrom DAT, each game has the following format:
|
/// In a new style MAME listrom DAT, each game has the following format:
|
||||||
///
|
///
|
||||||
@@ -41,7 +41,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>
|
||||||
protected override void ParseFile(string filename, int indexId, bool keep)
|
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
|
||||||
{
|
{
|
||||||
// Open a file reader
|
// Open a file reader
|
||||||
Encoding enc = FileExtensions.GetEncoding(filename);
|
Encoding enc = FileExtensions.GetEncoding(filename);
|
||||||
@@ -255,8 +255,9 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <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>
|
||||||
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
||||||
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
|
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -314,9 +315,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Globals.Logger.Error(ex.ToString());
|
Globals.Logger.Error(ex.ToString());
|
||||||
if (Globals.ThrowOnError)
|
if (throwOnError) throw ex;
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -328,10 +327,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sw">StreamWriter to output to</param>
|
/// <param name="sw">StreamWriter to output to</param>
|
||||||
/// <param name="rom">DatItem object to be output</param>
|
/// <param name="rom">DatItem object to be output</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteStartGame(StreamWriter sw, DatItem rom)
|
||||||
private bool WriteStartGame(StreamWriter sw, DatItem rom)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// No game should start with a path separator
|
// No game should start with a path separator
|
||||||
rom.Machine.Name = rom.Machine.Name.TrimStart(Path.DirectorySeparatorChar);
|
rom.Machine.Name = rom.Machine.Name.TrimStart(Path.DirectorySeparatorChar);
|
||||||
@@ -342,53 +338,25 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
sw.Flush();
|
sw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out Game end using the supplied StreamWriter
|
/// Write out Game end using the supplied StreamWriter
|
||||||
/// </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>
|
private void WriteEndGame(StreamWriter sw)
|
||||||
private bool WriteEndGame(StreamWriter sw)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// End driver
|
// End driver
|
||||||
sw.Write("\n");
|
sw.Write("\n");
|
||||||
|
|
||||||
sw.Flush();
|
sw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out DatItem using the supplied StreamWriter
|
/// Write out DatItem using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sw">StreamWriter to output to</param>
|
/// <param name="sw">StreamWriter to output to</param>
|
||||||
/// <param name="datItem">DatItem object to be output</param>
|
/// <param name="datItem">DatItem object to be output</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteDatItem(StreamWriter sw, DatItem datItem)
|
||||||
private bool WriteDatItem(StreamWriter sw, DatItem datItem)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// Pre-process the item name
|
// Pre-process the item name
|
||||||
ProcessItemName(datItem, true);
|
ProcessItemName(datItem, true);
|
||||||
@@ -465,16 +433,5 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
sw.Flush();
|
sw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,9 +32,8 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="filename">Name of the file to be parsed</param>
|
/// <param name="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</param>
|
/// <param name="indexId">Index 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>
|
||||||
/// <remarks>
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
/// </remarks>
|
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
|
||||||
protected override void ParseFile(string filename, int indexId, bool keep)
|
|
||||||
{
|
{
|
||||||
// Prepare all internal variables
|
// Prepare all internal variables
|
||||||
XmlReader xtr = filename.GetXmlTextReader();
|
XmlReader xtr = filename.GetXmlTextReader();
|
||||||
@@ -92,8 +91,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Globals.Logger.Warning($"Exception found while parsing '{filename}': {ex}");
|
Globals.Logger.Warning($"Exception found while parsing '{filename}': {ex}");
|
||||||
if (Globals.ThrowOnError)
|
if (throwOnError) throw ex;
|
||||||
throw ex;
|
|
||||||
|
|
||||||
// For XML errors, just skip the affected node
|
// For XML errors, just skip the affected node
|
||||||
xtr?.Read();
|
xtr?.Read();
|
||||||
@@ -1133,8 +1131,9 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <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>
|
||||||
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
||||||
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
|
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -1203,9 +1202,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Globals.Logger.Error(ex.ToString());
|
Globals.Logger.Error(ex.ToString());
|
||||||
if (Globals.ThrowOnError)
|
if (throwOnError) throw ex;
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1216,10 +1213,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// Write out DAT header using the supplied StreamWriter
|
/// Write out DAT header using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteHeader(XmlTextWriter xtw)
|
||||||
private bool WriteHeader(XmlTextWriter xtw)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
xtw.WriteStartDocument();
|
xtw.WriteStartDocument();
|
||||||
|
|
||||||
@@ -1230,17 +1224,6 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
xtw.Flush();
|
xtw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out Game start using the supplied StreamWriter
|
/// Write out Game start using the supplied StreamWriter
|
||||||
@@ -1248,9 +1231,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||||
/// <param name="datItem">DatItem object to be output</param>
|
/// <param name="datItem">DatItem 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 bool WriteStartGame(XmlTextWriter xtw, DatItem datItem)
|
private void WriteStartGame(XmlTextWriter xtw, DatItem datItem)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// No game should start with a path separator
|
// No game should start with a path separator
|
||||||
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar);
|
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar);
|
||||||
@@ -1282,53 +1263,25 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
xtw.Flush();
|
xtw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out Game start using the supplied StreamWriter
|
/// Write out Game start using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteEndGame(XmlTextWriter xtw)
|
||||||
private bool WriteEndGame(XmlTextWriter xtw)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// End machine
|
// End machine
|
||||||
xtw.WriteEndElement();
|
xtw.WriteEndElement();
|
||||||
|
|
||||||
xtw.Flush();
|
xtw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out DatItem using the supplied StreamWriter
|
/// Write out DatItem using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||||
/// <param name="datItem">DatItem object to be output</param>
|
/// <param name="datItem">DatItem object to be output</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteDatItem(XmlTextWriter xtw, DatItem datItem)
|
||||||
private bool WriteDatItem(XmlTextWriter xtw, DatItem datItem)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// Pre-process the item name
|
// Pre-process the item name
|
||||||
ProcessItemName(datItem, true);
|
ProcessItemName(datItem, true);
|
||||||
@@ -1689,26 +1642,12 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
xtw.Flush();
|
xtw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out DAT footer using the supplied StreamWriter
|
/// Write out DAT footer using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteFooter(XmlTextWriter xtw)
|
||||||
private bool WriteFooter(XmlTextWriter xtw)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// End machine
|
// End machine
|
||||||
xtw.WriteEndElement();
|
xtw.WriteEndElement();
|
||||||
@@ -1718,16 +1657,5 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
xtw.Flush();
|
xtw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,8 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="filename">Name of the file to be parsed</param>
|
/// <param name="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</param>
|
/// <param name="indexId">Index 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>
|
||||||
protected override void ParseFile(string filename, int indexId, bool keep)
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
|
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
|
||||||
{
|
{
|
||||||
// Prepare all internal variables
|
// Prepare all internal variables
|
||||||
XmlReader xtr = filename.GetXmlTextReader();
|
XmlReader xtr = filename.GetXmlTextReader();
|
||||||
@@ -107,8 +108,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Globals.Logger.Warning($"Exception found while parsing '{filename}': {ex}");
|
Globals.Logger.Warning($"Exception found while parsing '{filename}': {ex}");
|
||||||
if (Globals.ThrowOnError)
|
if (throwOnError) throw ex;
|
||||||
throw ex;
|
|
||||||
|
|
||||||
// For XML errors, just skip the affected node
|
// For XML errors, just skip the affected node
|
||||||
xtr?.Read();
|
xtr?.Read();
|
||||||
@@ -663,8 +663,9 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <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>
|
||||||
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
||||||
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
|
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -733,9 +734,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Globals.Logger.Error(ex.ToString());
|
Globals.Logger.Error(ex.ToString());
|
||||||
if (Globals.ThrowOnError)
|
if (throwOnError) throw ex;
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -746,10 +745,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// Write out DAT header using the supplied StreamWriter
|
/// Write out DAT header using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteHeader(XmlTextWriter xtw)
|
||||||
private bool WriteHeader(XmlTextWriter xtw)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
xtw.WriteStartDocument();
|
xtw.WriteStartDocument();
|
||||||
xtw.WriteDocType("datafile", "-//Logiqx//DTD ROM Management Datafile//EN", "http://www.logiqx.com/Dats/datafile.dtd", null);
|
xtw.WriteDocType("datafile", "-//Logiqx//DTD ROM Management Datafile//EN", "http://www.logiqx.com/Dats/datafile.dtd", null);
|
||||||
@@ -813,27 +809,13 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
xtw.Flush();
|
xtw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out Game start using the supplied StreamWriter
|
/// Write out Game start using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||||
/// <param name="datItem">DatItem object to be output</param>
|
/// <param name="datItem">DatItem object to be output</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteStartGame(XmlTextWriter xtw, DatItem datItem)
|
||||||
private bool WriteStartGame(XmlTextWriter xtw, DatItem datItem)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// No game should start with a path separator
|
// No game should start with a path separator
|
||||||
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar);
|
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar);
|
||||||
@@ -899,53 +881,25 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
xtw.Flush();
|
xtw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out Game end using the supplied StreamWriter
|
/// Write out Game end using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteEndGame(XmlTextWriter xtw)
|
||||||
private bool WriteEndGame(XmlTextWriter xtw)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// End machine
|
// End machine
|
||||||
xtw.WriteEndElement();
|
xtw.WriteEndElement();
|
||||||
|
|
||||||
xtw.Flush();
|
xtw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out DatItem using the supplied StreamWriter
|
/// Write out DatItem using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||||
/// <param name="datItem">DatItem object to be output</param>
|
/// <param name="datItem">DatItem object to be output</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteDatItem(XmlTextWriter xtw, DatItem datItem)
|
||||||
private bool WriteDatItem(XmlTextWriter xtw, DatItem datItem)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// Pre-process the item name
|
// Pre-process the item name
|
||||||
ProcessItemName(datItem, true);
|
ProcessItemName(datItem, true);
|
||||||
@@ -1032,26 +986,12 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
xtw.Flush();
|
xtw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out DAT footer using the supplied StreamWriter
|
/// Write out DAT footer using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteFooter(XmlTextWriter xtw)
|
||||||
private bool WriteFooter(XmlTextWriter xtw)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// End machine
|
// End machine
|
||||||
xtw.WriteEndElement();
|
xtw.WriteEndElement();
|
||||||
@@ -1061,16 +1001,5 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
xtw.Flush();
|
xtw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
using SabreTools.Library.Data;
|
using SabreTools.Library.Data;
|
||||||
@@ -30,7 +29,8 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="filename">Name of the file to be parsed</param>
|
/// <param name="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</param>
|
/// <param name="indexId">Index 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>
|
||||||
protected override void ParseFile(string filename, int indexId, bool keep)
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
|
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
|
||||||
{
|
{
|
||||||
// There is no consistent way to parse a missfile...
|
// There is no consistent way to parse a missfile...
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
@@ -41,8 +41,9 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <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>
|
||||||
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
||||||
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
|
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -92,9 +93,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Globals.Logger.Error(ex.ToString());
|
Globals.Logger.Error(ex.ToString());
|
||||||
if (Globals.ThrowOnError)
|
if (throwOnError) throw ex;
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,10 +106,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="sw">StreamWriter to output to</param>
|
/// <param name="sw">StreamWriter to output to</param>
|
||||||
/// <param name="datItem">DatItem object to be output</param>
|
/// <param name="datItem">DatItem 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>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteDatItem(StreamWriter sw, DatItem datItem, string lastgame)
|
||||||
private bool WriteDatItem(StreamWriter sw, DatItem datItem, string lastgame)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// Process the item name
|
// Process the item name
|
||||||
ProcessItemName(datItem, false, forceRomName: false);
|
ProcessItemName(datItem, false, forceRomName: false);
|
||||||
@@ -128,16 +124,5 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
sw.Flush();
|
sw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,8 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="filename">Name of the file to be parsed</param>
|
/// <param name="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</param>
|
/// <param name="indexId">Index 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>
|
||||||
protected override void ParseFile(string filename, int indexId, bool keep)
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
|
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
|
||||||
{
|
{
|
||||||
XmlReader xtr = filename.GetXmlTextReader();
|
XmlReader xtr = filename.GetXmlTextReader();
|
||||||
|
|
||||||
@@ -78,8 +79,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Globals.Logger.Warning($"Exception found while parsing '{filename}': {ex}");
|
Globals.Logger.Warning($"Exception found while parsing '{filename}': {ex}");
|
||||||
if (Globals.ThrowOnError)
|
if (throwOnError) throw ex;
|
||||||
throw ex;
|
|
||||||
|
|
||||||
// For XML errors, just skip the affected node
|
// For XML errors, just skip the affected node
|
||||||
xtr?.Read();
|
xtr?.Read();
|
||||||
@@ -659,8 +659,9 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <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>
|
||||||
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
||||||
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
|
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -721,9 +722,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Globals.Logger.Error(ex.ToString());
|
Globals.Logger.Error(ex.ToString());
|
||||||
if (Globals.ThrowOnError)
|
if (throwOnError) throw ex;
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -734,10 +733,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// Write out DAT header using the supplied StreamWriter
|
/// Write out DAT header using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteHeader(XmlTextWriter xtw)
|
||||||
private bool WriteHeader(XmlTextWriter xtw)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
xtw.WriteStartDocument(false);
|
xtw.WriteStartDocument(false);
|
||||||
|
|
||||||
@@ -845,17 +841,6 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
xtw.Flush();
|
xtw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out DatItem using the supplied StreamWriter
|
/// Write out DatItem using the supplied StreamWriter
|
||||||
@@ -863,9 +848,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||||
/// <param name="datItem">DatItem object to be output</param>
|
/// <param name="datItem">DatItem 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 bool WriteDatItem(XmlTextWriter xtw, DatItem datItem)
|
private void WriteDatItem(XmlTextWriter xtw, DatItem datItem)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// Pre-process the item name
|
// Pre-process the item name
|
||||||
ProcessItemName(datItem, true);
|
ProcessItemName(datItem, true);
|
||||||
@@ -916,26 +899,13 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
xtw.Flush();
|
xtw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out DAT footer using the supplied StreamWriter
|
/// Write out DAT footer using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
/// <param name="xtw">XmlTextWriter 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 bool WriteFooter(XmlTextWriter xtw)
|
private void WriteFooter(XmlTextWriter xtw)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// End games
|
// End games
|
||||||
xtw.WriteEndElement();
|
xtw.WriteEndElement();
|
||||||
@@ -971,16 +941,5 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
xtw.Flush();
|
xtw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,8 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="filename">Name of the file to be parsed</param>
|
/// <param name="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</param>
|
/// <param name="indexId">Index 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>
|
||||||
protected override void ParseFile(string filename, int indexId, bool keep)
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
|
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
|
||||||
{
|
{
|
||||||
// Prepare all internal variables
|
// Prepare all internal variables
|
||||||
XmlReader xtr = filename.GetXmlTextReader();
|
XmlReader xtr = filename.GetXmlTextReader();
|
||||||
@@ -80,8 +81,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Globals.Logger.Warning($"Exception found while parsing '{filename}': {ex}");
|
Globals.Logger.Warning($"Exception found while parsing '{filename}': {ex}");
|
||||||
if (Globals.ThrowOnError)
|
if (throwOnError) throw ex;
|
||||||
throw ex;
|
|
||||||
|
|
||||||
// For XML errors, just skip the affected node
|
// For XML errors, just skip the affected node
|
||||||
xtr?.Read();
|
xtr?.Read();
|
||||||
@@ -513,8 +513,9 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <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>
|
||||||
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
||||||
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
|
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -583,9 +584,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Globals.Logger.Error(ex.ToString());
|
Globals.Logger.Error(ex.ToString());
|
||||||
if (Globals.ThrowOnError)
|
if (throwOnError) throw ex;
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -596,10 +595,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// Write out DAT header using the supplied StreamWriter
|
/// Write out DAT header using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteHeader(XmlTextWriter xtw)
|
||||||
private bool WriteHeader(XmlTextWriter xtw)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
xtw.WriteStartDocument();
|
xtw.WriteStartDocument();
|
||||||
xtw.WriteDocType("softwaredb", null, "softwaredb1.dtd", null);
|
xtw.WriteDocType("softwaredb", null, "softwaredb1.dtd", null);
|
||||||
@@ -623,27 +619,13 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
xtw.Flush();
|
xtw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out Game start using the supplied StreamWriter
|
/// Write out Game start using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||||
/// <param name="datItem">DatItem object to be output</param>
|
/// <param name="datItem">DatItem object to be output</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteStartGame(XmlTextWriter xtw, DatItem datItem)
|
||||||
private bool WriteStartGame(XmlTextWriter xtw, DatItem datItem)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// No game should start with a path separator
|
// No game should start with a path separator
|
||||||
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar);
|
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar);
|
||||||
@@ -659,53 +641,25 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
xtw.Flush();
|
xtw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out Game start using the supplied StreamWriter
|
/// Write out Game start using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteEndGame(XmlTextWriter xtw)
|
||||||
private bool WriteEndGame(XmlTextWriter xtw)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// End software
|
// End software
|
||||||
xtw.WriteEndElement();
|
xtw.WriteEndElement();
|
||||||
|
|
||||||
xtw.Flush();
|
xtw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out DatItem using the supplied StreamWriter
|
/// Write out DatItem using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||||
/// <param name="datItem">DatItem object to be output</param>
|
/// <param name="datItem">DatItem object to be output</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteDatItem(XmlTextWriter xtw, DatItem datItem)
|
||||||
private bool WriteDatItem(XmlTextWriter xtw, DatItem datItem)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// Pre-process the item name
|
// Pre-process the item name
|
||||||
ProcessItemName(datItem, true);
|
ProcessItemName(datItem, true);
|
||||||
@@ -763,26 +717,12 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
xtw.Flush();
|
xtw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out DAT footer using the supplied StreamWriter
|
/// Write out DAT footer using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteFooter(XmlTextWriter xtw)
|
||||||
private bool WriteFooter(XmlTextWriter xtw)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// End software
|
// End software
|
||||||
xtw.WriteEndElement();
|
xtw.WriteEndElement();
|
||||||
@@ -792,16 +732,5 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
xtw.Flush();
|
xtw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
using SabreTools.Library.Data;
|
using SabreTools.Library.Data;
|
||||||
@@ -31,7 +30,8 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="filename">Name of the file to be parsed</param>
|
/// <param name="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</param>
|
/// <param name="indexId">Index 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>
|
||||||
protected override void ParseFile(string filename, int indexId, bool keep)
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
|
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
|
||||||
{
|
{
|
||||||
// Prepare all intenral variables
|
// Prepare all intenral variables
|
||||||
IniReader ir = filename.GetIniReader(false);
|
IniReader ir = filename.GetIniReader(false);
|
||||||
@@ -85,8 +85,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Globals.Logger.Warning($"Exception found while parsing '{filename}': {ex}");
|
Globals.Logger.Warning($"Exception found while parsing '{filename}': {ex}");
|
||||||
if (Globals.ThrowOnError)
|
if (throwOnError) throw ex;
|
||||||
throw ex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ir.Dispose();
|
ir.Dispose();
|
||||||
@@ -367,8 +366,9 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <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>
|
||||||
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
||||||
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
|
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -422,9 +422,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Globals.Logger.Error(ex.ToString());
|
Globals.Logger.Error(ex.ToString());
|
||||||
if (Globals.ThrowOnError)
|
if (throwOnError) throw ex;
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -435,10 +433,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// Write out DAT header using the supplied StreamWriter
|
/// Write out DAT header using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="iw">IniWriter to output to</param>
|
/// <param name="iw">IniWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteHeader(IniWriter iw)
|
||||||
private bool WriteHeader(IniWriter iw)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
iw.WriteSection("CREDITS");
|
iw.WriteSection("CREDITS");
|
||||||
iw.WriteKeyValuePair("author", Header.Author);
|
iw.WriteKeyValuePair("author", Header.Author);
|
||||||
@@ -459,25 +454,13 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
iw.Flush();
|
iw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out DatItem using the supplied StreamWriter
|
/// Write out DatItem using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="iw">IniWriter to output to</param>
|
/// <param name="iw">IniWriter to output to</param>
|
||||||
/// <param name="datItem">DatItem object to be output</param>
|
/// <param name="datItem">DatItem object to be output</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteDatItem(IniWriter iw, DatItem datItem)
|
||||||
private bool WriteDatItem(IniWriter iw, DatItem datItem)
|
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
The rominfo order is as follows:
|
The rominfo order is as follows:
|
||||||
@@ -492,8 +475,6 @@ namespace SabreTools.Library.DatFiles
|
|||||||
9 - merge name
|
9 - merge name
|
||||||
*/
|
*/
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// Pre-process the item name
|
// Pre-process the item name
|
||||||
ProcessItemName(datItem, true);
|
ProcessItemName(datItem, true);
|
||||||
|
|
||||||
@@ -523,16 +504,5 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
iw.Flush();
|
iw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,8 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="filename">Name of the file to be parsed</param>
|
/// <param name="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</param>
|
/// <param name="indexId">Index 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>
|
||||||
protected override void ParseFile(string filename, int indexId, bool keep)
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
|
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
|
||||||
{
|
{
|
||||||
// Prepare all internal variables
|
// Prepare all internal variables
|
||||||
StreamReader sr = new StreamReader(FileExtensions.TryOpenRead(filename), new UTF8Encoding(false));
|
StreamReader sr = new StreamReader(FileExtensions.TryOpenRead(filename), new UTF8Encoding(false));
|
||||||
@@ -78,8 +79,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Globals.Logger.Warning($"Exception found while parsing '{filename}': {ex}");
|
Globals.Logger.Warning($"Exception found while parsing '{filename}': {ex}");
|
||||||
if (Globals.ThrowOnError)
|
if (throwOnError) throw ex;
|
||||||
throw ex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
jtr.Close();
|
jtr.Close();
|
||||||
@@ -336,8 +336,9 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <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>
|
||||||
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
||||||
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
|
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -407,9 +408,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Globals.Logger.Error(ex.ToString());
|
Globals.Logger.Error(ex.ToString());
|
||||||
if (Globals.ThrowOnError)
|
if (throwOnError) throw ex;
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -420,10 +419,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// Write out DAT header using the supplied JsonTextWriter
|
/// Write out DAT header using the supplied JsonTextWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="jtw">JsonTextWriter to output to</param>
|
/// <param name="jtw">JsonTextWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteHeader(JsonTextWriter jtw)
|
||||||
private bool WriteHeader(JsonTextWriter jtw)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
jtw.WriteStartObject();
|
jtw.WriteStartObject();
|
||||||
|
|
||||||
@@ -437,27 +433,13 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
jtw.Flush();
|
jtw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out Game start using the supplied JsonTextWriter
|
/// Write out Game start using the supplied JsonTextWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="jtw">JsonTextWriter to output to</param>
|
/// <param name="jtw">JsonTextWriter to output to</param>
|
||||||
/// <param name="datItem">DatItem object to be output</param>
|
/// <param name="datItem">DatItem object to be output</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteStartGame(JsonTextWriter jtw, DatItem datItem)
|
||||||
private bool WriteStartGame(JsonTextWriter jtw, DatItem datItem)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// No game should start with a path separator
|
// No game should start with a path separator
|
||||||
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar) ?? string.Empty;
|
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar) ?? string.Empty;
|
||||||
@@ -475,26 +457,12 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
jtw.Flush();
|
jtw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out Game end using the supplied JsonTextWriter
|
/// Write out Game end using the supplied JsonTextWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="jtw">JsonTextWriter to output to</param>
|
/// <param name="jtw">JsonTextWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteEndGame(JsonTextWriter jtw)
|
||||||
private bool WriteEndGame(JsonTextWriter jtw)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// End items
|
// End items
|
||||||
jtw.WriteEndArray();
|
jtw.WriteEndArray();
|
||||||
@@ -504,27 +472,13 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
jtw.Flush();
|
jtw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out DatItem using the supplied JsonTextWriter
|
/// Write out DatItem using the supplied JsonTextWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="jtw">JsonTextWriter to output to</param>
|
/// <param name="jtw">JsonTextWriter to output to</param>
|
||||||
/// <param name="datItem">DatItem object to be output</param>
|
/// <param name="datItem">DatItem object to be output</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteDatItem(JsonTextWriter jtw, DatItem datItem)
|
||||||
private bool WriteDatItem(JsonTextWriter jtw, DatItem datItem)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// Pre-process the item name
|
// Pre-process the item name
|
||||||
ProcessItemName(datItem, true);
|
ProcessItemName(datItem, true);
|
||||||
@@ -542,26 +496,12 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
jtw.Flush();
|
jtw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out DAT footer using the supplied JsonTextWriter
|
/// Write out DAT footer using the supplied JsonTextWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="jtw">JsonTextWriter to output to</param>
|
/// <param name="jtw">JsonTextWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteFooter(JsonTextWriter jtw)
|
||||||
private bool WriteFooter(JsonTextWriter jtw)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// End items
|
// End items
|
||||||
jtw.WriteEndArray();
|
jtw.WriteEndArray();
|
||||||
@@ -577,16 +517,5 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
jtw.Flush();
|
jtw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="filename">Name of the file to be parsed</param>
|
/// <param name="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</param>
|
/// <param name="indexId">Index 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>
|
||||||
protected override void ParseFile(string filename, int indexId, bool keep)
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
|
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
|
||||||
{
|
{
|
||||||
// Prepare all internal variables
|
// Prepare all internal variables
|
||||||
XmlReader xtr = filename.GetXmlTextReader();
|
XmlReader xtr = filename.GetXmlTextReader();
|
||||||
@@ -77,8 +78,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Globals.Logger.Warning($"Exception found while parsing '{filename}': {ex}");
|
Globals.Logger.Warning($"Exception found while parsing '{filename}': {ex}");
|
||||||
if (Globals.ThrowOnError)
|
if (throwOnError) throw ex;
|
||||||
throw ex;
|
|
||||||
|
|
||||||
// For XML errors, just skip the affected node
|
// For XML errors, just skip the affected node
|
||||||
xtr?.Read();
|
xtr?.Read();
|
||||||
@@ -103,8 +103,6 @@ namespace SabreTools.Library.DatFiles
|
|||||||
Machine machine = null;
|
Machine machine = null;
|
||||||
|
|
||||||
// Otherwise, read the directory
|
// Otherwise, read the directory
|
||||||
try
|
|
||||||
{
|
|
||||||
xtr.MoveToContent();
|
xtr.MoveToContent();
|
||||||
while (!xtr.EOF)
|
while (!xtr.EOF)
|
||||||
{
|
{
|
||||||
@@ -135,16 +133,6 @@ namespace SabreTools.Library.DatFiles
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Warning($"Exception found while parsing '{filename}': {ex}");
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
// For XML errors, just skip the affected node
|
|
||||||
xtr?.Read();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Read Files information
|
/// Read Files information
|
||||||
@@ -160,8 +148,6 @@ namespace SabreTools.Library.DatFiles
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Otherwise, read the items
|
// Otherwise, read the items
|
||||||
try
|
|
||||||
{
|
|
||||||
xtr.MoveToContent();
|
xtr.MoveToContent();
|
||||||
while (!xtr.EOF)
|
while (!xtr.EOF)
|
||||||
{
|
{
|
||||||
@@ -188,25 +174,15 @@ namespace SabreTools.Library.DatFiles
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Warning($"Exception found while parsing '{filename}': {ex}");
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
// For XML errors, just skip the affected node
|
|
||||||
xtr?.Read();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <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="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>
|
||||||
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
||||||
/// TODO: Fix writing out files that have a path in the name
|
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
|
||||||
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -275,9 +251,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Globals.Logger.Error(ex.ToString());
|
Globals.Logger.Error(ex.ToString());
|
||||||
if (Globals.ThrowOnError)
|
if (throwOnError) throw ex;
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,10 +262,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// Write out DAT header using the supplied StreamWriter
|
/// Write out DAT header using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteHeader(XmlTextWriter xtw)
|
||||||
private bool WriteHeader(XmlTextWriter xtw)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
xtw.WriteStartDocument();
|
xtw.WriteStartDocument();
|
||||||
|
|
||||||
@@ -306,27 +277,13 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
xtw.Flush();
|
xtw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out Game start using the supplied StreamWriter
|
/// Write out Game start using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||||
/// <param name="datItem">DatItem object to be output</param>
|
/// <param name="datItem">DatItem object to be output</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteStartGame(XmlTextWriter xtw, DatItem datItem)
|
||||||
private bool WriteStartGame(XmlTextWriter xtw, DatItem datItem)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// No game should start with a path separator
|
// No game should start with a path separator
|
||||||
datItem.Machine.Name = datItem.Machine.Name?.TrimStart(Path.DirectorySeparatorChar) ?? string.Empty;
|
datItem.Machine.Name = datItem.Machine.Name?.TrimStart(Path.DirectorySeparatorChar) ?? string.Empty;
|
||||||
@@ -342,25 +299,12 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
xtw.Flush();
|
xtw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out Game start using the supplied StreamWriter
|
/// Write out Game start using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||||
private bool WriteEndGame(XmlTextWriter xtw)
|
private void WriteEndGame(XmlTextWriter xtw)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// End files
|
// End files
|
||||||
xtw.WriteEndElement();
|
xtw.WriteEndElement();
|
||||||
@@ -370,27 +314,13 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
xtw.Flush();
|
xtw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out DatItem using the supplied StreamWriter
|
/// Write out DatItem using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||||
/// <param name="datItem">DatItem object to be output</param>
|
/// <param name="datItem">DatItem object to be output</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteDatItem(XmlTextWriter xtw, DatItem datItem)
|
||||||
private bool WriteDatItem(XmlTextWriter xtw, DatItem datItem)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// Pre-process the item name
|
// Pre-process the item name
|
||||||
ProcessItemName(datItem, true);
|
ProcessItemName(datItem, true);
|
||||||
@@ -403,26 +333,12 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
xtw.Flush();
|
xtw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out DAT footer using the supplied StreamWriter
|
/// Write out DAT footer using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteFooter(XmlTextWriter xtw)
|
||||||
private bool WriteFooter(XmlTextWriter xtw)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// End files
|
// End files
|
||||||
xtw.WriteEndElement();
|
xtw.WriteEndElement();
|
||||||
@@ -438,16 +354,5 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
xtw.Flush();
|
xtw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
using SabreTools.Library.Data;
|
using SabreTools.Library.Data;
|
||||||
@@ -36,7 +35,8 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="filename">Name of the file to be parsed</param>
|
/// <param name="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</param>
|
/// <param name="indexId">Index 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>
|
||||||
protected override void ParseFile(string filename, int indexId, bool keep)
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
|
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
|
||||||
{
|
{
|
||||||
// Open a file reader
|
// Open a file reader
|
||||||
Encoding enc = FileExtensions.GetEncoding(filename);
|
Encoding enc = FileExtensions.GetEncoding(filename);
|
||||||
@@ -106,8 +106,9 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <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>
|
||||||
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
||||||
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
|
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -159,9 +160,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Globals.Logger.Error(ex.ToString());
|
Globals.Logger.Error(ex.ToString());
|
||||||
if (Globals.ThrowOnError)
|
if (throwOnError) throw ex;
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,10 +171,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// Write out DAT header using the supplied StreamWriter
|
/// Write out DAT header using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="svw">SeparatedValueWriter to output to</param>
|
/// <param name="svw">SeparatedValueWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteHeader(SeparatedValueWriter svw)
|
||||||
private bool WriteHeader(SeparatedValueWriter svw)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
string[] headers = new string[]
|
string[] headers = new string[]
|
||||||
{
|
{
|
||||||
@@ -203,31 +199,17 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
svw.Flush();
|
svw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out DatItem using the supplied StreamWriter
|
/// Write out DatItem using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="svw">SeparatedValueWriter to output to</param>
|
/// <param name="svw">SeparatedValueWriter to output to</param>
|
||||||
/// <param name="datItem">DatItem object to be output</param>
|
/// <param name="datItem">DatItem object to be output</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteDatItem(SeparatedValueWriter svw, DatItem datItem)
|
||||||
private bool WriteDatItem(SeparatedValueWriter svw, DatItem datItem)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// Separated values should only output Rom and Disk
|
// Separated values should only output Rom and Disk
|
||||||
if (datItem.ItemType != ItemType.Disk && datItem.ItemType != ItemType.Rom)
|
if (datItem.ItemType != ItemType.Disk && datItem.ItemType != ItemType.Rom)
|
||||||
return true;
|
return;
|
||||||
|
|
||||||
// Build the state
|
// Build the state
|
||||||
// TODO: Can we have some way of saying what fields to write out? Support for read extends to all fields now
|
// TODO: Can we have some way of saying what fields to write out? Support for read extends to all fields now
|
||||||
@@ -299,16 +281,5 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
svw.Flush();
|
svw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,8 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// <param name="filename">Name of the file to be parsed</param>
|
/// <param name="filename">Name of the file to be parsed</param>
|
||||||
/// <param name="indexId">Index ID for the DAT</param>
|
/// <param name="indexId">Index 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>
|
||||||
protected override void ParseFile(string filename, int indexId, bool keep)
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
|
protected override void ParseFile(string filename, int indexId, bool keep, bool throwOnError = false)
|
||||||
{
|
{
|
||||||
// Prepare all internal variables
|
// Prepare all internal variables
|
||||||
XmlReader xtr = filename.GetXmlTextReader();
|
XmlReader xtr = filename.GetXmlTextReader();
|
||||||
@@ -81,8 +82,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Globals.Logger.Warning($"Exception found while parsing '{filename}': {ex}");
|
Globals.Logger.Warning($"Exception found while parsing '{filename}': {ex}");
|
||||||
if (Globals.ThrowOnError)
|
if (throwOnError) throw ex;
|
||||||
throw ex;
|
|
||||||
|
|
||||||
// For XML errors, just skip the affected node
|
// For XML errors, just skip the affected node
|
||||||
xtr?.Read();
|
xtr?.Read();
|
||||||
@@ -505,8 +505,9 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <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>
|
||||||
|
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
|
||||||
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
/// <returns>True if the DAT was written correctly, false otherwise</returns>
|
||||||
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
|
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -575,9 +576,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Globals.Logger.Error(ex.ToString());
|
Globals.Logger.Error(ex.ToString());
|
||||||
if (Globals.ThrowOnError)
|
if (throwOnError) throw ex;
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -588,10 +587,7 @@ namespace SabreTools.Library.DatFiles
|
|||||||
/// Write out DAT header using the supplied StreamWriter
|
/// Write out DAT header using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteHeader(XmlTextWriter xtw)
|
||||||
private bool WriteHeader(XmlTextWriter xtw)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
xtw.WriteStartDocument();
|
xtw.WriteStartDocument();
|
||||||
xtw.WriteDocType("softwarelist", null, "softwarelist.dtd", null);
|
xtw.WriteDocType("softwarelist", null, "softwarelist.dtd", null);
|
||||||
@@ -602,27 +598,13 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
xtw.Flush();
|
xtw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out Game start using the supplied StreamWriter
|
/// Write out Game start using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||||
/// <param name="datItem">DatItem object to be output</param>
|
/// <param name="datItem">DatItem object to be output</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteStartGame(XmlTextWriter xtw, DatItem datItem)
|
||||||
private bool WriteStartGame(XmlTextWriter xtw, DatItem datItem)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// No game should start with a path separator
|
// No game should start with a path separator
|
||||||
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar);
|
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar);
|
||||||
@@ -640,53 +622,25 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
xtw.Flush();
|
xtw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out Game start using the supplied StreamWriter
|
/// Write out Game start using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteEndGame(XmlTextWriter xtw)
|
||||||
private bool WriteEndGame(XmlTextWriter xtw)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// End software
|
// End software
|
||||||
xtw.WriteEndElement();
|
xtw.WriteEndElement();
|
||||||
|
|
||||||
xtw.Flush();
|
xtw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out DatItem using the supplied StreamWriter
|
/// Write out DatItem using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||||
/// <param name="datItem">DatItem object to be output</param>
|
/// <param name="datItem">DatItem object to be output</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteDatItem(XmlTextWriter xtw, DatItem datItem)
|
||||||
private bool WriteDatItem(XmlTextWriter xtw, DatItem datItem)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// Pre-process the item name
|
// Pre-process the item name
|
||||||
ProcessItemName(datItem, true);
|
ProcessItemName(datItem, true);
|
||||||
@@ -824,26 +778,12 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
xtw.Flush();
|
xtw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out DAT footer using the supplied StreamWriter
|
/// Write out DAT footer using the supplied StreamWriter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
/// <param name="xtw">XmlTextWriter to output to</param>
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
private void WriteFooter(XmlTextWriter xtw)
|
||||||
private bool WriteFooter(XmlTextWriter xtw)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
// End software
|
// End software
|
||||||
xtw.WriteEndElement();
|
xtw.WriteEndElement();
|
||||||
@@ -853,16 +793,5 @@ namespace SabreTools.Library.DatFiles
|
|||||||
|
|
||||||
xtw.Flush();
|
xtw.Flush();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Globals.Logger.Error(ex.ToString());
|
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -168,24 +168,8 @@ namespace SabreTools.Library.IO
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Special case for non-quoted names (old DATs only)
|
|
||||||
if (key == "name" && !linegc[i + 1].Contains("\""))
|
|
||||||
{
|
|
||||||
while (++i < linegc.Length
|
|
||||||
&& linegc[i] != "size"
|
|
||||||
&& linegc[i] != "crc"
|
|
||||||
&& linegc[i] != "md5"
|
|
||||||
&& linegc[i] != "sha1"
|
|
||||||
&& linegc[i] != "status")
|
|
||||||
{
|
|
||||||
value += $" {linegc[i]}";
|
|
||||||
}
|
|
||||||
|
|
||||||
value = value.Trim();
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
// Special cases for standalone statuses
|
// Special cases for standalone statuses
|
||||||
else if (key == "baddump" || key == "good" || key == "nodump" || key == "verified")
|
if (key == "baddump" || key == "good" || key == "nodump" || key == "verified")
|
||||||
{
|
{
|
||||||
value = key;
|
value = key;
|
||||||
key = "status";
|
key = "status";
|
||||||
|
|||||||
@@ -422,9 +422,6 @@ Reset the internal state: reset();";
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Globals.Logger.Error($"There was an exception processing {path}: {ex}");
|
Globals.Logger.Error($"There was an exception processing {path}: {ex}");
|
||||||
if (Globals.ThrowOnError)
|
|
||||||
throw ex;
|
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user