Make less things use global throw state

This commit is contained in:
Matt Nadareski
2020-09-15 14:23:40 -07:00
parent 91f659dca2
commit f506915a04
19 changed files with 1713 additions and 2503 deletions

View File

@@ -29,7 +29,8 @@ namespace SabreTools.Library.DatFiles
/// <param name="filename">Name of the file to be parsed</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>
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
Encoding enc = FileExtensions.GetEncoding(filename);
@@ -62,9 +63,7 @@ namespace SabreTools.Library.DatFiles
catch (InvalidDataException ex)
{
Globals.Logger.Warning($"Malformed line found in '{filename}' at line {svr.LineNumber}");
if (Globals.ThrowOnError)
throw ex;
if (throwOnError) throw ex;
continue;
}
@@ -117,8 +116,9 @@ namespace SabreTools.Library.DatFiles
/// </summary>
/// <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="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>
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
{
try
{
@@ -170,9 +170,7 @@ namespace SabreTools.Library.DatFiles
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
if (throwOnError) throw ex;
return false;
}
@@ -183,10 +181,7 @@ namespace SabreTools.Library.DatFiles
/// Write out DAT header using the supplied StreamWriter
/// </summary>
/// <param name="svw">SeparatedValueWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteHeader(SeparatedValueWriter svw)
{
try
private void WriteHeader(SeparatedValueWriter svw)
{
string[] headers = new string[]
{
@@ -213,27 +208,14 @@ namespace SabreTools.Library.DatFiles
svw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out Game start using the supplied StreamWriter
/// </summary>
/// <param name="svw">SeparatedValueWriter to output to</param>
/// <param name="datItem">DatItem object to be output</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteDatItem(SeparatedValueWriter svw, DatItem datItem)
{
try
/// <param name="throwOnError">True if the error that is thrown should be thrown back to the caller, false otherwise</param>
private void WriteDatItem(SeparatedValueWriter svw, DatItem datItem)
{
// No game should start with a path separator
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar);
@@ -273,16 +255,5 @@ namespace SabreTools.Library.DatFiles
svw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
}
}

View File

@@ -31,7 +31,8 @@ namespace SabreTools.Library.DatFiles
/// <param name="filename">Name of the file to be parsed</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>
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
Encoding enc = FileExtensions.GetEncoding(filename);
@@ -412,8 +413,9 @@ namespace SabreTools.Library.DatFiles
/// </summary>
/// <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="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>
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
{
try
{
@@ -480,9 +482,7 @@ namespace SabreTools.Library.DatFiles
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
if (throwOnError) throw ex;
return false;
}
@@ -493,10 +493,7 @@ namespace SabreTools.Library.DatFiles
/// Write out DAT header using the supplied StreamWriter
/// </summary>
/// <param name="cmpw">ClrMameProWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteHeader(ClrMameProWriter cmpw)
{
try
private void WriteHeader(ClrMameProWriter cmpw)
{
cmpw.WriteStartElement("clrmamepro");
@@ -518,27 +515,13 @@ namespace SabreTools.Library.DatFiles
cmpw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out Game start using the supplied StreamWriter
/// </summary>
/// <param name="cmpw">ClrMameProWriter to output to</param>
/// <param name="datItem">DatItem object to be output</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteStartGame(ClrMameProWriter cmpw, DatItem datItem)
{
try
private void WriteStartGame(ClrMameProWriter cmpw, DatItem datItem)
{
// No game should start with a path separator
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar);
@@ -556,27 +539,13 @@ namespace SabreTools.Library.DatFiles
cmpw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out Game end using the supplied StreamWriter
/// </summary>
/// <param name="cmpw">ClrMameProWriter to output to</param>
/// <param name="datItem">DatItem object to be output</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteEndGame(ClrMameProWriter cmpw, DatItem datItem)
{
try
private void WriteEndGame(ClrMameProWriter cmpw, DatItem datItem)
{
// Build the state
cmpw.WriteOptionalStandalone("sampleof", datItem.Machine.SampleOf);
@@ -586,17 +555,6 @@ namespace SabreTools.Library.DatFiles
cmpw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// 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="cmpw">ClrMameProWriter to output to</param>
/// <param name="datItem">DatItem object to be output</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteDatItem(ClrMameProWriter cmpw, DatItem datItem)
{
try
private void WriteDatItem(ClrMameProWriter cmpw, DatItem datItem)
{
// Pre-process the item name
ProcessItemName(datItem, true);
@@ -693,42 +648,17 @@ namespace SabreTools.Library.DatFiles
cmpw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out DAT footer using the supplied StreamWriter
/// </summary>
/// <param name="cmpw">ClrMameProWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteFooter(ClrMameProWriter cmpw)
{
try
private void WriteFooter(ClrMameProWriter cmpw)
{
// End game
cmpw.WriteEndElement();
cmpw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
}
}

View File

@@ -1823,10 +1823,16 @@ namespace SabreTools.Library.DatFiles
/// <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="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('"'));
Parse(path, indexId, keep, keepext);
Parse(path, indexId, keep, keepext, throwOnError);
}
/// <summary>
@@ -1836,7 +1842,13 @@ namespace SabreTools.Library.DatFiles
/// <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="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
string currentPath = filename.CurrentPath;
@@ -1855,13 +1867,12 @@ namespace SabreTools.Library.DatFiles
// Now parse the correct type of DAT
try
{
Create(currentPath.GetDatFormat(), this)?.ParseFile(currentPath, indexId, keep);
Create(currentPath.GetDatFormat(), this)?.ParseFile(currentPath, indexId, keep, throwOnError);
}
catch (Exception ex)
{
Globals.Logger.Error($"Error with file '{filename}': {ex}");
if (Globals.ThrowOnError)
throw ex;
if (throwOnError) throw ex;
}
}
@@ -1976,7 +1987,8 @@ namespace SabreTools.Library.DatFiles
/// <param name="filename">Name of the file to be parsed</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>
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
@@ -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="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="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>
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 (!HasWritable())
@@ -3504,7 +3522,7 @@ namespace SabreTools.Library.DatFiles
string outfile = outfiles[datFormat];
try
{
Create(datFormat, this)?.WriteToFile(outfile, ignoreblanks);
Create(datFormat, this)?.WriteToFile(outfile, ignoreblanks, throwOnError);
}
catch (Exception ex)
{
@@ -3532,8 +3550,9 @@ namespace SabreTools.Library.DatFiles
/// </summary>
/// <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="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>
public abstract bool WriteToFile(string outfile, bool ignoreblanks = false);
public abstract bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false);
/// <summary>
/// Create a prefix or postfix from inputs

View File

@@ -31,7 +31,8 @@ namespace SabreTools.Library.DatFiles
/// <param name="filename">Name of the file to be parsed</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>
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
Encoding enc = FileExtensions.GetEncoding(filename);
@@ -246,14 +247,14 @@ namespace SabreTools.Library.DatFiles
}
}
/// <summary>
/// Create and open an output file for writing direct from a dictionary
/// </summary>
/// <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="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>
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
{
try
{
@@ -322,9 +323,7 @@ namespace SabreTools.Library.DatFiles
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
if (throwOnError) throw ex;
return false;
}
@@ -335,10 +334,7 @@ namespace SabreTools.Library.DatFiles
/// Write out DAT header using the supplied StreamWriter
/// </summary>
/// <param name="cmpw">ClrMameProWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteHeader(ClrMameProWriter cmpw)
{
try
private void WriteHeader(ClrMameProWriter cmpw)
{
// Build the state
cmpw.WriteStartElement("DOSCenter");
@@ -355,27 +351,13 @@ namespace SabreTools.Library.DatFiles
cmpw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out Game start using the supplied StreamWriter
/// </summary>
/// <param name="cmpw">ClrMameProWriter to output to</param>
/// <param name="datItem">DatItem object to be output</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteStartGame(ClrMameProWriter cmpw, DatItem datItem)
{
try
private void WriteStartGame(ClrMameProWriter cmpw, DatItem datItem)
{
// No game should start with a path separator
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar);
@@ -386,53 +368,25 @@ namespace SabreTools.Library.DatFiles
cmpw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out Game end using the supplied StreamWriter
/// </summary>
/// <param name="cmpw">ClrMameProWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteEndGame(ClrMameProWriter cmpw)
{
try
private void WriteEndGame(ClrMameProWriter cmpw)
{
// End game
cmpw.WriteEndElement();
cmpw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out DatItem using the supplied StreamWriter
/// </summary>
/// <param name="cmpw">ClrMameProWriter to output to</param>
/// <param name="datItem">DatItem object to be output</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteDatItem(ClrMameProWriter cmpw, DatItem datItem)
{
try
private void WriteDatItem(ClrMameProWriter cmpw, DatItem datItem)
{
// Pre-process the item name
ProcessItemName(datItem, true);
@@ -453,42 +407,18 @@ namespace SabreTools.Library.DatFiles
cmpw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out DAT footer using the supplied StreamWriter
/// </summary>
/// <param name="cmpw">ClrMameProWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteFooter(ClrMameProWriter cmpw)
{
try
private void WriteFooter(ClrMameProWriter cmpw)
{
// End game
cmpw.WriteEndElement();
cmpw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
}
}

View File

@@ -30,7 +30,8 @@ namespace SabreTools.Library.DatFiles
/// <param name="filename">Name of the file to be parsed</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>
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
Encoding enc = FileExtensions.GetEncoding(filename);
@@ -87,8 +88,9 @@ namespace SabreTools.Library.DatFiles
/// </summary>
/// <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="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>
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
{
try
{

View File

@@ -34,7 +34,8 @@ namespace SabreTools.Library.DatFiles
/// <param name="filename">Name of the file to be parsed</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>
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
Encoding enc = FileExtensions.GetEncoding(filename);
@@ -102,8 +103,9 @@ namespace SabreTools.Library.DatFiles
/// </summary>
/// <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="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>
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
{
try
{
@@ -152,9 +154,7 @@ namespace SabreTools.Library.DatFiles
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
if (throwOnError) throw ex;
return false;
}
@@ -162,14 +162,11 @@ namespace SabreTools.Library.DatFiles
}
/// <summary>
/// Write out DatItem using the supplied StreamWriter
/// Write out DatItem using the supplied SeparatedValueWriter
/// </summary>
/// <param name="svw">SeparatedValueWriter to output to</param>
/// <param name="datItem">DatItem object to be output</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteDatItem(SeparatedValueWriter svw, DatItem datItem)
{
try
private void WriteDatItem(SeparatedValueWriter svw, DatItem datItem)
{
// Build the state
string[] fields = new string[2];
@@ -347,16 +344,5 @@ namespace SabreTools.Library.DatFiles
svw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
}
}

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
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="indexId">Index ID for the DAT</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>
/// 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
/// 16v8h-blue.u24 279 NO GOOD DUMP KNOWN
/// </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
Encoding enc = FileExtensions.GetEncoding(filename);
@@ -255,8 +255,9 @@ namespace SabreTools.Library.DatFiles
/// </summary>
/// <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="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>
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
{
try
{
@@ -314,9 +315,7 @@ namespace SabreTools.Library.DatFiles
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
if (throwOnError) throw ex;
return false;
}
@@ -328,10 +327,7 @@ namespace SabreTools.Library.DatFiles
/// </summary>
/// <param name="sw">StreamWriter to output to</param>
/// <param name="rom">DatItem object to be output</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteStartGame(StreamWriter sw, DatItem rom)
{
try
private void WriteStartGame(StreamWriter sw, DatItem rom)
{
// No game should start with a path separator
rom.Machine.Name = rom.Machine.Name.TrimStart(Path.DirectorySeparatorChar);
@@ -342,53 +338,25 @@ namespace SabreTools.Library.DatFiles
sw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out Game end using the supplied StreamWriter
/// </summary>
/// <param name="sw">StreamWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteEndGame(StreamWriter sw)
{
try
private void WriteEndGame(StreamWriter sw)
{
// End driver
sw.Write("\n");
sw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out DatItem using the supplied StreamWriter
/// </summary>
/// <param name="sw">StreamWriter to output to</param>
/// <param name="datItem">DatItem object to be output</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteDatItem(StreamWriter sw, DatItem datItem)
{
try
private void WriteDatItem(StreamWriter sw, DatItem datItem)
{
// Pre-process the item name
ProcessItemName(datItem, true);
@@ -465,16 +433,5 @@ namespace SabreTools.Library.DatFiles
sw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
}
}

View File

@@ -32,9 +32,8 @@ namespace SabreTools.Library.DatFiles
/// <param name="filename">Name of the file to be parsed</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>
/// <remarks>
/// </remarks>
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
XmlReader xtr = filename.GetXmlTextReader();
@@ -92,8 +91,7 @@ namespace SabreTools.Library.DatFiles
catch (Exception ex)
{
Globals.Logger.Warning($"Exception found while parsing '{filename}': {ex}");
if (Globals.ThrowOnError)
throw ex;
if (throwOnError) throw ex;
// For XML errors, just skip the affected node
xtr?.Read();
@@ -1133,8 +1131,9 @@ namespace SabreTools.Library.DatFiles
/// </summary>
/// <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="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>
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
{
try
{
@@ -1203,9 +1202,7 @@ namespace SabreTools.Library.DatFiles
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
if (throwOnError) throw ex;
return false;
}
@@ -1216,10 +1213,7 @@ namespace SabreTools.Library.DatFiles
/// Write out DAT header using the supplied StreamWriter
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteHeader(XmlTextWriter xtw)
{
try
private void WriteHeader(XmlTextWriter xtw)
{
xtw.WriteStartDocument();
@@ -1230,17 +1224,6 @@ namespace SabreTools.Library.DatFiles
xtw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// 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="datItem">DatItem object to be output</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteStartGame(XmlTextWriter xtw, DatItem datItem)
{
try
private void WriteStartGame(XmlTextWriter xtw, DatItem datItem)
{
// No game should start with a path separator
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar);
@@ -1282,53 +1263,25 @@ namespace SabreTools.Library.DatFiles
xtw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out Game start using the supplied StreamWriter
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteEndGame(XmlTextWriter xtw)
{
try
private void WriteEndGame(XmlTextWriter xtw)
{
// End machine
xtw.WriteEndElement();
xtw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out DatItem using the supplied StreamWriter
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
/// <param name="datItem">DatItem object to be output</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteDatItem(XmlTextWriter xtw, DatItem datItem)
{
try
private void WriteDatItem(XmlTextWriter xtw, DatItem datItem)
{
// Pre-process the item name
ProcessItemName(datItem, true);
@@ -1689,26 +1642,12 @@ namespace SabreTools.Library.DatFiles
xtw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out DAT footer using the supplied StreamWriter
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteFooter(XmlTextWriter xtw)
{
try
private void WriteFooter(XmlTextWriter xtw)
{
// End machine
xtw.WriteEndElement();
@@ -1718,16 +1657,5 @@ namespace SabreTools.Library.DatFiles
xtw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
}
}

View File

@@ -38,7 +38,8 @@ namespace SabreTools.Library.DatFiles
/// <param name="filename">Name of the file to be parsed</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>
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
XmlReader xtr = filename.GetXmlTextReader();
@@ -107,8 +108,7 @@ namespace SabreTools.Library.DatFiles
catch (Exception ex)
{
Globals.Logger.Warning($"Exception found while parsing '{filename}': {ex}");
if (Globals.ThrowOnError)
throw ex;
if (throwOnError) throw ex;
// For XML errors, just skip the affected node
xtr?.Read();
@@ -663,8 +663,9 @@ namespace SabreTools.Library.DatFiles
/// </summary>
/// <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="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>
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
{
try
{
@@ -733,9 +734,7 @@ namespace SabreTools.Library.DatFiles
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
if (throwOnError) throw ex;
return false;
}
@@ -746,10 +745,7 @@ namespace SabreTools.Library.DatFiles
/// Write out DAT header using the supplied StreamWriter
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteHeader(XmlTextWriter xtw)
{
try
private void WriteHeader(XmlTextWriter xtw)
{
xtw.WriteStartDocument();
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();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out Game start using the supplied StreamWriter
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
/// <param name="datItem">DatItem object to be output</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteStartGame(XmlTextWriter xtw, DatItem datItem)
{
try
private void WriteStartGame(XmlTextWriter xtw, DatItem datItem)
{
// No game should start with a path separator
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar);
@@ -899,53 +881,25 @@ namespace SabreTools.Library.DatFiles
xtw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out Game end using the supplied StreamWriter
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteEndGame(XmlTextWriter xtw)
{
try
private void WriteEndGame(XmlTextWriter xtw)
{
// End machine
xtw.WriteEndElement();
xtw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out DatItem using the supplied StreamWriter
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
/// <param name="datItem">DatItem object to be output</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteDatItem(XmlTextWriter xtw, DatItem datItem)
{
try
private void WriteDatItem(XmlTextWriter xtw, DatItem datItem)
{
// Pre-process the item name
ProcessItemName(datItem, true);
@@ -1032,26 +986,12 @@ namespace SabreTools.Library.DatFiles
xtw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out DAT footer using the supplied StreamWriter
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteFooter(XmlTextWriter xtw)
{
try
private void WriteFooter(XmlTextWriter xtw)
{
// End machine
xtw.WriteEndElement();
@@ -1061,16 +1001,5 @@ namespace SabreTools.Library.DatFiles
xtw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
}
}

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
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="indexId">Index ID for the DAT</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...
throw new NotImplementedException();
@@ -41,8 +41,9 @@ namespace SabreTools.Library.DatFiles
/// </summary>
/// <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="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>
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
{
try
{
@@ -92,9 +93,7 @@ namespace SabreTools.Library.DatFiles
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
if (throwOnError) throw ex;
return false;
}
@@ -107,10 +106,7 @@ namespace SabreTools.Library.DatFiles
/// <param name="sw">StreamWriter to output to</param>
/// <param name="datItem">DatItem object 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 bool WriteDatItem(StreamWriter sw, DatItem datItem, string lastgame)
{
try
private void WriteDatItem(StreamWriter sw, DatItem datItem, string lastgame)
{
// Process the item name
ProcessItemName(datItem, false, forceRomName: false);
@@ -128,16 +124,5 @@ namespace SabreTools.Library.DatFiles
sw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
}
}

View File

@@ -32,7 +32,8 @@ namespace SabreTools.Library.DatFiles
/// <param name="filename">Name of the file to be parsed</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>
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();
@@ -78,8 +79,7 @@ namespace SabreTools.Library.DatFiles
catch (Exception ex)
{
Globals.Logger.Warning($"Exception found while parsing '{filename}': {ex}");
if (Globals.ThrowOnError)
throw ex;
if (throwOnError) throw ex;
// For XML errors, just skip the affected node
xtr?.Read();
@@ -659,8 +659,9 @@ namespace SabreTools.Library.DatFiles
/// </summary>
/// <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="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>
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
{
try
{
@@ -721,9 +722,7 @@ namespace SabreTools.Library.DatFiles
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
if (throwOnError) throw ex;
return false;
}
@@ -734,10 +733,7 @@ namespace SabreTools.Library.DatFiles
/// Write out DAT header using the supplied StreamWriter
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteHeader(XmlTextWriter xtw)
{
try
private void WriteHeader(XmlTextWriter xtw)
{
xtw.WriteStartDocument(false);
@@ -845,17 +841,6 @@ namespace SabreTools.Library.DatFiles
xtw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// 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="datItem">DatItem object to be output</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteDatItem(XmlTextWriter xtw, DatItem datItem)
{
try
private void WriteDatItem(XmlTextWriter xtw, DatItem datItem)
{
// Pre-process the item name
ProcessItemName(datItem, true);
@@ -916,26 +899,13 @@ namespace SabreTools.Library.DatFiles
xtw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out DAT footer using the supplied StreamWriter
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteFooter(XmlTextWriter xtw)
{
try
private void WriteFooter(XmlTextWriter xtw)
{
// End games
xtw.WriteEndElement();
@@ -971,16 +941,5 @@ namespace SabreTools.Library.DatFiles
xtw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
}
}

View File

@@ -32,7 +32,8 @@ namespace SabreTools.Library.DatFiles
/// <param name="filename">Name of the file to be parsed</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>
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
XmlReader xtr = filename.GetXmlTextReader();
@@ -80,8 +81,7 @@ namespace SabreTools.Library.DatFiles
catch (Exception ex)
{
Globals.Logger.Warning($"Exception found while parsing '{filename}': {ex}");
if (Globals.ThrowOnError)
throw ex;
if (throwOnError) throw ex;
// For XML errors, just skip the affected node
xtr?.Read();
@@ -513,8 +513,9 @@ namespace SabreTools.Library.DatFiles
/// </summary>
/// <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="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>
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
{
try
{
@@ -583,9 +584,7 @@ namespace SabreTools.Library.DatFiles
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
if (throwOnError) throw ex;
return false;
}
@@ -596,10 +595,7 @@ namespace SabreTools.Library.DatFiles
/// Write out DAT header using the supplied StreamWriter
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteHeader(XmlTextWriter xtw)
{
try
private void WriteHeader(XmlTextWriter xtw)
{
xtw.WriteStartDocument();
xtw.WriteDocType("softwaredb", null, "softwaredb1.dtd", null);
@@ -623,27 +619,13 @@ namespace SabreTools.Library.DatFiles
xtw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out Game start using the supplied StreamWriter
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
/// <param name="datItem">DatItem object to be output</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteStartGame(XmlTextWriter xtw, DatItem datItem)
{
try
private void WriteStartGame(XmlTextWriter xtw, DatItem datItem)
{
// No game should start with a path separator
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar);
@@ -659,53 +641,25 @@ namespace SabreTools.Library.DatFiles
xtw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out Game start using the supplied StreamWriter
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteEndGame(XmlTextWriter xtw)
{
try
private void WriteEndGame(XmlTextWriter xtw)
{
// End software
xtw.WriteEndElement();
xtw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out DatItem using the supplied StreamWriter
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
/// <param name="datItem">DatItem object to be output</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteDatItem(XmlTextWriter xtw, DatItem datItem)
{
try
private void WriteDatItem(XmlTextWriter xtw, DatItem datItem)
{
// Pre-process the item name
ProcessItemName(datItem, true);
@@ -763,26 +717,12 @@ namespace SabreTools.Library.DatFiles
xtw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out DAT footer using the supplied StreamWriter
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteFooter(XmlTextWriter xtw)
{
try
private void WriteFooter(XmlTextWriter xtw)
{
// End software
xtw.WriteEndElement();
@@ -792,16 +732,5 @@ namespace SabreTools.Library.DatFiles
xtw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
}
}

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
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="indexId">Index ID for the DAT</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
IniReader ir = filename.GetIniReader(false);
@@ -85,8 +85,7 @@ namespace SabreTools.Library.DatFiles
catch (Exception ex)
{
Globals.Logger.Warning($"Exception found while parsing '{filename}': {ex}");
if (Globals.ThrowOnError)
throw ex;
if (throwOnError) throw ex;
}
ir.Dispose();
@@ -367,8 +366,9 @@ namespace SabreTools.Library.DatFiles
/// </summary>
/// <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="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>
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
{
try
{
@@ -422,9 +422,7 @@ namespace SabreTools.Library.DatFiles
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
if (throwOnError) throw ex;
return false;
}
@@ -435,10 +433,7 @@ namespace SabreTools.Library.DatFiles
/// Write out DAT header using the supplied StreamWriter
/// </summary>
/// <param name="iw">IniWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteHeader(IniWriter iw)
{
try
private void WriteHeader(IniWriter iw)
{
iw.WriteSection("CREDITS");
iw.WriteKeyValuePair("author", Header.Author);
@@ -459,25 +454,13 @@ namespace SabreTools.Library.DatFiles
iw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out DatItem using the supplied StreamWriter
/// </summary>
/// <param name="iw">IniWriter to output to</param>
/// <param name="datItem">DatItem object to be output</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteDatItem(IniWriter iw, DatItem datItem)
private void WriteDatItem(IniWriter iw, DatItem datItem)
{
/*
The rominfo order is as follows:
@@ -492,8 +475,6 @@ namespace SabreTools.Library.DatFiles
9 - merge name
*/
try
{
// Pre-process the item name
ProcessItemName(datItem, true);
@@ -523,16 +504,5 @@ namespace SabreTools.Library.DatFiles
iw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
}
}

View File

@@ -32,7 +32,8 @@ namespace SabreTools.Library.DatFiles
/// <param name="filename">Name of the file to be parsed</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>
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
StreamReader sr = new StreamReader(FileExtensions.TryOpenRead(filename), new UTF8Encoding(false));
@@ -78,8 +79,7 @@ namespace SabreTools.Library.DatFiles
catch (Exception ex)
{
Globals.Logger.Warning($"Exception found while parsing '{filename}': {ex}");
if (Globals.ThrowOnError)
throw ex;
if (throwOnError) throw ex;
}
jtr.Close();
@@ -336,8 +336,9 @@ namespace SabreTools.Library.DatFiles
/// </summary>
/// <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="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>
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
{
try
{
@@ -407,9 +408,7 @@ namespace SabreTools.Library.DatFiles
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
if (throwOnError) throw ex;
return false;
}
@@ -420,10 +419,7 @@ namespace SabreTools.Library.DatFiles
/// Write out DAT header using the supplied JsonTextWriter
/// </summary>
/// <param name="jtw">JsonTextWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteHeader(JsonTextWriter jtw)
{
try
private void WriteHeader(JsonTextWriter jtw)
{
jtw.WriteStartObject();
@@ -437,27 +433,13 @@ namespace SabreTools.Library.DatFiles
jtw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out Game start using the supplied JsonTextWriter
/// </summary>
/// <param name="jtw">JsonTextWriter to output to</param>
/// <param name="datItem">DatItem object to be output</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteStartGame(JsonTextWriter jtw, DatItem datItem)
{
try
private void WriteStartGame(JsonTextWriter jtw, DatItem datItem)
{
// No game should start with a path separator
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar) ?? string.Empty;
@@ -475,26 +457,12 @@ namespace SabreTools.Library.DatFiles
jtw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out Game end using the supplied JsonTextWriter
/// </summary>
/// <param name="jtw">JsonTextWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteEndGame(JsonTextWriter jtw)
{
try
private void WriteEndGame(JsonTextWriter jtw)
{
// End items
jtw.WriteEndArray();
@@ -504,27 +472,13 @@ namespace SabreTools.Library.DatFiles
jtw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out DatItem using the supplied JsonTextWriter
/// </summary>
/// <param name="jtw">JsonTextWriter to output to</param>
/// <param name="datItem">DatItem object to be output</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteDatItem(JsonTextWriter jtw, DatItem datItem)
{
try
private void WriteDatItem(JsonTextWriter jtw, DatItem datItem)
{
// Pre-process the item name
ProcessItemName(datItem, true);
@@ -542,26 +496,12 @@ namespace SabreTools.Library.DatFiles
jtw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out DAT footer using the supplied JsonTextWriter
/// </summary>
/// <param name="jtw">JsonTextWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteFooter(JsonTextWriter jtw)
{
try
private void WriteFooter(JsonTextWriter jtw)
{
// End items
jtw.WriteEndArray();
@@ -577,16 +517,5 @@ namespace SabreTools.Library.DatFiles
jtw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
}
}

View File

@@ -31,7 +31,8 @@ namespace SabreTools.Library.DatFiles
/// <param name="filename">Name of the file to be parsed</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>
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
XmlReader xtr = filename.GetXmlTextReader();
@@ -77,8 +78,7 @@ namespace SabreTools.Library.DatFiles
catch (Exception ex)
{
Globals.Logger.Warning($"Exception found while parsing '{filename}': {ex}");
if (Globals.ThrowOnError)
throw ex;
if (throwOnError) throw ex;
// For XML errors, just skip the affected node
xtr?.Read();
@@ -103,8 +103,6 @@ namespace SabreTools.Library.DatFiles
Machine machine = null;
// Otherwise, read the directory
try
{
xtr.MoveToContent();
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>
/// Read Files information
@@ -160,8 +148,6 @@ namespace SabreTools.Library.DatFiles
return;
// Otherwise, read the items
try
{
xtr.MoveToContent();
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>
/// Create and open an output file for writing direct from a dictionary
/// </summary>
/// <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="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>
/// TODO: Fix writing out files that have a path in the name
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
{
try
{
@@ -275,9 +251,7 @@ namespace SabreTools.Library.DatFiles
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
if (throwOnError) throw ex;
return false;
}
@@ -288,10 +262,7 @@ namespace SabreTools.Library.DatFiles
/// Write out DAT header using the supplied StreamWriter
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteHeader(XmlTextWriter xtw)
{
try
private void WriteHeader(XmlTextWriter xtw)
{
xtw.WriteStartDocument();
@@ -306,27 +277,13 @@ namespace SabreTools.Library.DatFiles
xtw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out Game start using the supplied StreamWriter
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
/// <param name="datItem">DatItem object to be output</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteStartGame(XmlTextWriter xtw, DatItem datItem)
{
try
private void WriteStartGame(XmlTextWriter xtw, DatItem datItem)
{
// No game should start with a path separator
datItem.Machine.Name = datItem.Machine.Name?.TrimStart(Path.DirectorySeparatorChar) ?? string.Empty;
@@ -342,25 +299,12 @@ namespace SabreTools.Library.DatFiles
xtw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out Game start using the supplied StreamWriter
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
private bool WriteEndGame(XmlTextWriter xtw)
{
try
private void WriteEndGame(XmlTextWriter xtw)
{
// End files
xtw.WriteEndElement();
@@ -370,27 +314,13 @@ namespace SabreTools.Library.DatFiles
xtw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out DatItem using the supplied StreamWriter
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
/// <param name="datItem">DatItem object to be output</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteDatItem(XmlTextWriter xtw, DatItem datItem)
{
try
private void WriteDatItem(XmlTextWriter xtw, DatItem datItem)
{
// Pre-process the item name
ProcessItemName(datItem, true);
@@ -403,26 +333,12 @@ namespace SabreTools.Library.DatFiles
xtw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out DAT footer using the supplied StreamWriter
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteFooter(XmlTextWriter xtw)
{
try
private void WriteFooter(XmlTextWriter xtw)
{
// End files
xtw.WriteEndElement();
@@ -438,16 +354,5 @@ namespace SabreTools.Library.DatFiles
xtw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
}
}

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
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="indexId">Index ID for the DAT</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
Encoding enc = FileExtensions.GetEncoding(filename);
@@ -106,8 +106,9 @@ namespace SabreTools.Library.DatFiles
/// </summary>
/// <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="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>
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
{
try
{
@@ -159,9 +160,7 @@ namespace SabreTools.Library.DatFiles
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
if (throwOnError) throw ex;
return false;
}
@@ -172,10 +171,7 @@ namespace SabreTools.Library.DatFiles
/// Write out DAT header using the supplied StreamWriter
/// </summary>
/// <param name="svw">SeparatedValueWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteHeader(SeparatedValueWriter svw)
{
try
private void WriteHeader(SeparatedValueWriter svw)
{
string[] headers = new string[]
{
@@ -203,31 +199,17 @@ namespace SabreTools.Library.DatFiles
svw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out DatItem using the supplied StreamWriter
/// </summary>
/// <param name="svw">SeparatedValueWriter to output to</param>
/// <param name="datItem">DatItem object to be output</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteDatItem(SeparatedValueWriter svw, DatItem datItem)
{
try
private void WriteDatItem(SeparatedValueWriter svw, DatItem datItem)
{
// Separated values should only output Rom and Disk
if (datItem.ItemType != ItemType.Disk && datItem.ItemType != ItemType.Rom)
return true;
return;
// Build the state
// 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();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
}
}

View File

@@ -33,7 +33,8 @@ namespace SabreTools.Library.DatFiles
/// <param name="filename">Name of the file to be parsed</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>
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
XmlReader xtr = filename.GetXmlTextReader();
@@ -81,8 +82,7 @@ namespace SabreTools.Library.DatFiles
catch (Exception ex)
{
Globals.Logger.Warning($"Exception found while parsing '{filename}': {ex}");
if (Globals.ThrowOnError)
throw ex;
if (throwOnError) throw ex;
// For XML errors, just skip the affected node
xtr?.Read();
@@ -505,8 +505,9 @@ namespace SabreTools.Library.DatFiles
/// </summary>
/// <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="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>
public override bool WriteToFile(string outfile, bool ignoreblanks = false)
public override bool WriteToFile(string outfile, bool ignoreblanks = false, bool throwOnError = false)
{
try
{
@@ -575,9 +576,7 @@ namespace SabreTools.Library.DatFiles
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
if (throwOnError) throw ex;
return false;
}
@@ -588,10 +587,7 @@ namespace SabreTools.Library.DatFiles
/// Write out DAT header using the supplied StreamWriter
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteHeader(XmlTextWriter xtw)
{
try
private void WriteHeader(XmlTextWriter xtw)
{
xtw.WriteStartDocument();
xtw.WriteDocType("softwarelist", null, "softwarelist.dtd", null);
@@ -602,27 +598,13 @@ namespace SabreTools.Library.DatFiles
xtw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out Game start using the supplied StreamWriter
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
/// <param name="datItem">DatItem object to be output</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteStartGame(XmlTextWriter xtw, DatItem datItem)
{
try
private void WriteStartGame(XmlTextWriter xtw, DatItem datItem)
{
// No game should start with a path separator
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar);
@@ -640,53 +622,25 @@ namespace SabreTools.Library.DatFiles
xtw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out Game start using the supplied StreamWriter
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteEndGame(XmlTextWriter xtw)
{
try
private void WriteEndGame(XmlTextWriter xtw)
{
// End software
xtw.WriteEndElement();
xtw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out DatItem using the supplied StreamWriter
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
/// <param name="datItem">DatItem object to be output</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteDatItem(XmlTextWriter xtw, DatItem datItem)
{
try
private void WriteDatItem(XmlTextWriter xtw, DatItem datItem)
{
// Pre-process the item name
ProcessItemName(datItem, true);
@@ -824,26 +778,12 @@ namespace SabreTools.Library.DatFiles
xtw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
/// <summary>
/// Write out DAT footer using the supplied StreamWriter
/// </summary>
/// <param name="xtw">XmlTextWriter to output to</param>
/// <returns>True if the data was written, false on error</returns>
private bool WriteFooter(XmlTextWriter xtw)
{
try
private void WriteFooter(XmlTextWriter xtw)
{
// End software
xtw.WriteEndElement();
@@ -853,16 +793,5 @@ namespace SabreTools.Library.DatFiles
xtw.Flush();
}
catch (Exception ex)
{
Globals.Logger.Error(ex.ToString());
if (Globals.ThrowOnError)
throw ex;
return false;
}
return true;
}
}
}

View File

@@ -168,24 +168,8 @@ namespace SabreTools.Library.IO
}
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
else if (key == "baddump" || key == "good" || key == "nodump" || key == "verified")
if (key == "baddump" || key == "good" || key == "nodump" || key == "verified")
{
value = key;
key = "status";

View File

@@ -422,9 +422,6 @@ Reset the internal state: reset();";
catch (Exception ex)
{
Globals.Logger.Error($"There was an exception processing {path}: {ex}");
if (Globals.ThrowOnError)
throw ex;
continue;
}
}