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:
@@ -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,127 +733,113 @@ 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)
|
||||
private void WriteHeader(XmlTextWriter xtw)
|
||||
{
|
||||
try
|
||||
xtw.WriteStartDocument(false);
|
||||
|
||||
xtw.WriteStartElement("dat");
|
||||
xtw.WriteAttributeString("xsi", "xmlns", "http://www.w3.org/2001/XMLSchema-instance");
|
||||
xtw.WriteAttributeString("noNamespaceSchemaLocation", "xsi", "datas.xsd");
|
||||
|
||||
xtw.WriteStartElement("configuration");
|
||||
xtw.WriteRequiredElementString("datName", Header.Name);
|
||||
xtw.WriteElementString("datVersion", Items.TotalCount.ToString());
|
||||
xtw.WriteRequiredElementString("system", Header.System);
|
||||
xtw.WriteRequiredElementString("screenshotsWidth", Header.ScreenshotsWidth);
|
||||
xtw.WriteRequiredElementString("screenshotsHeight", Header.ScreenshotsHeight);
|
||||
|
||||
if (Header.Infos != null)
|
||||
{
|
||||
xtw.WriteStartDocument(false);
|
||||
xtw.WriteStartElement("infos");
|
||||
|
||||
xtw.WriteStartElement("dat");
|
||||
xtw.WriteAttributeString("xsi", "xmlns", "http://www.w3.org/2001/XMLSchema-instance");
|
||||
xtw.WriteAttributeString("noNamespaceSchemaLocation", "xsi", "datas.xsd");
|
||||
|
||||
xtw.WriteStartElement("configuration");
|
||||
xtw.WriteRequiredElementString("datName", Header.Name);
|
||||
xtw.WriteElementString("datVersion", Items.TotalCount.ToString());
|
||||
xtw.WriteRequiredElementString("system", Header.System);
|
||||
xtw.WriteRequiredElementString("screenshotsWidth", Header.ScreenshotsWidth);
|
||||
xtw.WriteRequiredElementString("screenshotsHeight", Header.ScreenshotsHeight);
|
||||
|
||||
if (Header.Infos != null)
|
||||
foreach (var info in Header.Infos)
|
||||
{
|
||||
xtw.WriteStartElement("infos");
|
||||
|
||||
foreach (var info in Header.Infos)
|
||||
{
|
||||
xtw.WriteStartElement(info.Name);
|
||||
xtw.WriteAttributeString("visible", info.Visible?.ToString());
|
||||
xtw.WriteAttributeString("inNamingOption", info.InNamingOption?.ToString());
|
||||
xtw.WriteAttributeString("default", info.Default?.ToString());
|
||||
xtw.WriteEndElement();
|
||||
}
|
||||
|
||||
// End infos
|
||||
xtw.WriteEndElement();
|
||||
}
|
||||
|
||||
if (Header.CanOpen != null)
|
||||
{
|
||||
xtw.WriteStartElement("canOpen");
|
||||
|
||||
foreach (string extension in Header.CanOpen)
|
||||
{
|
||||
xtw.WriteElementString("extension", extension);
|
||||
}
|
||||
|
||||
// End canOpen
|
||||
xtw.WriteStartElement(info.Name);
|
||||
xtw.WriteAttributeString("visible", info.Visible?.ToString());
|
||||
xtw.WriteAttributeString("inNamingOption", info.InNamingOption?.ToString());
|
||||
xtw.WriteAttributeString("default", info.Default?.ToString());
|
||||
xtw.WriteEndElement();
|
||||
}
|
||||
|
||||
xtw.WriteStartElement("newDat");
|
||||
xtw.WriteRequiredElementString("datVersionURL", Header.Url);
|
||||
|
||||
xtw.WriteStartElement("datUrl");
|
||||
xtw.WriteAttributeString("fileName", $"{Header.FileName ?? string.Empty}.zip");
|
||||
xtw.WriteString(Header.Url);
|
||||
// End infos
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.WriteRequiredElementString("imURL", Header.Url);
|
||||
|
||||
// End newDat
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.WriteStartElement("search");
|
||||
|
||||
xtw.WriteStartElement("to");
|
||||
xtw.WriteAttributeString("value", "location");
|
||||
xtw.WriteAttributeString("default", "true");
|
||||
xtw.WriteAttributeString("auto", "true");
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.WriteStartElement("to");
|
||||
xtw.WriteAttributeString("value", "romSize");
|
||||
xtw.WriteAttributeString("default", "true");
|
||||
xtw.WriteAttributeString("auto", "false");
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.WriteStartElement("to");
|
||||
xtw.WriteAttributeString("value", "languages");
|
||||
xtw.WriteAttributeString("default", "true");
|
||||
xtw.WriteAttributeString("auto", "true");
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.WriteStartElement("to");
|
||||
xtw.WriteAttributeString("value", "saveType");
|
||||
xtw.WriteAttributeString("default", "false");
|
||||
xtw.WriteAttributeString("auto", "false");
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.WriteStartElement("to");
|
||||
xtw.WriteAttributeString("value", "publisher");
|
||||
xtw.WriteAttributeString("default", "false");
|
||||
xtw.WriteAttributeString("auto", "true");
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.WriteStartElement("to");
|
||||
xtw.WriteAttributeString("value", "sourceRom");
|
||||
xtw.WriteAttributeString("default", "false");
|
||||
xtw.WriteAttributeString("auto", "true");
|
||||
xtw.WriteEndElement();
|
||||
|
||||
// End search
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.WriteRequiredElementString("romTitle", Header.RomTitle ?? "%u - %n");
|
||||
|
||||
// End configuration
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.WriteStartElement("games");
|
||||
|
||||
xtw.Flush();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
if (Header.CanOpen != null)
|
||||
{
|
||||
Globals.Logger.Error(ex.ToString());
|
||||
if (Globals.ThrowOnError)
|
||||
throw ex;
|
||||
xtw.WriteStartElement("canOpen");
|
||||
|
||||
return false;
|
||||
foreach (string extension in Header.CanOpen)
|
||||
{
|
||||
xtw.WriteElementString("extension", extension);
|
||||
}
|
||||
|
||||
// End canOpen
|
||||
xtw.WriteEndElement();
|
||||
}
|
||||
|
||||
return true;
|
||||
xtw.WriteStartElement("newDat");
|
||||
xtw.WriteRequiredElementString("datVersionURL", Header.Url);
|
||||
|
||||
xtw.WriteStartElement("datUrl");
|
||||
xtw.WriteAttributeString("fileName", $"{Header.FileName ?? string.Empty}.zip");
|
||||
xtw.WriteString(Header.Url);
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.WriteRequiredElementString("imURL", Header.Url);
|
||||
|
||||
// End newDat
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.WriteStartElement("search");
|
||||
|
||||
xtw.WriteStartElement("to");
|
||||
xtw.WriteAttributeString("value", "location");
|
||||
xtw.WriteAttributeString("default", "true");
|
||||
xtw.WriteAttributeString("auto", "true");
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.WriteStartElement("to");
|
||||
xtw.WriteAttributeString("value", "romSize");
|
||||
xtw.WriteAttributeString("default", "true");
|
||||
xtw.WriteAttributeString("auto", "false");
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.WriteStartElement("to");
|
||||
xtw.WriteAttributeString("value", "languages");
|
||||
xtw.WriteAttributeString("default", "true");
|
||||
xtw.WriteAttributeString("auto", "true");
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.WriteStartElement("to");
|
||||
xtw.WriteAttributeString("value", "saveType");
|
||||
xtw.WriteAttributeString("default", "false");
|
||||
xtw.WriteAttributeString("auto", "false");
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.WriteStartElement("to");
|
||||
xtw.WriteAttributeString("value", "publisher");
|
||||
xtw.WriteAttributeString("default", "false");
|
||||
xtw.WriteAttributeString("auto", "true");
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.WriteStartElement("to");
|
||||
xtw.WriteAttributeString("value", "sourceRom");
|
||||
xtw.WriteAttributeString("default", "false");
|
||||
xtw.WriteAttributeString("auto", "true");
|
||||
xtw.WriteEndElement();
|
||||
|
||||
// End search
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.WriteRequiredElementString("romTitle", Header.RomTitle ?? "%u - %n");
|
||||
|
||||
// End configuration
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.WriteStartElement("games");
|
||||
|
||||
xtw.Flush();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -863,69 +848,56 @@ 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)
|
||||
private void WriteDatItem(XmlTextWriter xtw, DatItem datItem)
|
||||
{
|
||||
try
|
||||
// Pre-process the item name
|
||||
ProcessItemName(datItem, true);
|
||||
|
||||
// Build the state
|
||||
xtw.WriteStartElement("game");
|
||||
xtw.WriteElementString("imageNumber", "1");
|
||||
xtw.WriteElementString("releaseNumber", "1");
|
||||
xtw.WriteRequiredElementString("title", datItem.GetName() ?? string.Empty);
|
||||
xtw.WriteElementString("saveType", "None");
|
||||
|
||||
if (datItem.ItemType == ItemType.Rom)
|
||||
{
|
||||
// Pre-process the item name
|
||||
ProcessItemName(datItem, true);
|
||||
var rom = datItem as Rom;
|
||||
xtw.WriteRequiredElementString("romSize", rom.Size?.ToString());
|
||||
}
|
||||
|
||||
// Build the state
|
||||
xtw.WriteStartElement("game");
|
||||
xtw.WriteElementString("imageNumber", "1");
|
||||
xtw.WriteElementString("releaseNumber", "1");
|
||||
xtw.WriteRequiredElementString("title", datItem.GetName() ?? string.Empty);
|
||||
xtw.WriteElementString("saveType", "None");
|
||||
xtw.WriteRequiredElementString("publisher", datItem.Machine.Publisher);
|
||||
xtw.WriteElementString("location", "0");
|
||||
xtw.WriteElementString("sourceRom", "None");
|
||||
xtw.WriteElementString("language", "0");
|
||||
|
||||
if (datItem.ItemType == ItemType.Rom)
|
||||
if (datItem.ItemType == ItemType.Rom)
|
||||
{
|
||||
var rom = datItem as Rom;
|
||||
string tempext = "." + PathExtensions.GetNormalizedExtension(rom.Name);
|
||||
|
||||
xtw.WriteStartElement("files");
|
||||
if (!string.IsNullOrWhiteSpace(rom.CRC))
|
||||
{
|
||||
var rom = datItem as Rom;
|
||||
xtw.WriteRequiredElementString("romSize", rom.Size?.ToString());
|
||||
}
|
||||
|
||||
xtw.WriteRequiredElementString("publisher", datItem.Machine.Publisher);
|
||||
xtw.WriteElementString("location", "0");
|
||||
xtw.WriteElementString("sourceRom", "None");
|
||||
xtw.WriteElementString("language", "0");
|
||||
|
||||
if (datItem.ItemType == ItemType.Rom)
|
||||
{
|
||||
var rom = datItem as Rom;
|
||||
string tempext = "." + PathExtensions.GetNormalizedExtension(rom.Name);
|
||||
|
||||
xtw.WriteStartElement("files");
|
||||
if (!string.IsNullOrWhiteSpace(rom.CRC))
|
||||
{
|
||||
xtw.WriteStartElement("romCRC");
|
||||
xtw.WriteRequiredAttributeString("extension", tempext);
|
||||
xtw.WriteString(rom.CRC?.ToUpperInvariant());
|
||||
xtw.WriteEndElement();
|
||||
}
|
||||
|
||||
// End files
|
||||
xtw.WriteStartElement("romCRC");
|
||||
xtw.WriteRequiredAttributeString("extension", tempext);
|
||||
xtw.WriteString(rom.CRC?.ToUpperInvariant());
|
||||
xtw.WriteEndElement();
|
||||
}
|
||||
|
||||
xtw.WriteElementString("im1CRC", "00000000");
|
||||
xtw.WriteElementString("im2CRC", "00000000");
|
||||
xtw.WriteRequiredElementString("comment", datItem.Machine.Comment);
|
||||
xtw.WriteRequiredElementString("duplicateID", datItem.Machine.CloneOf);
|
||||
|
||||
// End game
|
||||
// End files
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.Flush();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Globals.Logger.Error(ex.ToString());
|
||||
if (Globals.ThrowOnError)
|
||||
throw ex;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
xtw.WriteElementString("im1CRC", "00000000");
|
||||
xtw.WriteElementString("im2CRC", "00000000");
|
||||
xtw.WriteRequiredElementString("comment", datItem.Machine.Comment);
|
||||
xtw.WriteRequiredElementString("duplicateID", datItem.Machine.CloneOf);
|
||||
|
||||
// End game
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.Flush();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -933,54 +905,41 @@ namespace SabreTools.Library.DatFiles
|
||||
/// </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)
|
||||
private void WriteFooter(XmlTextWriter xtw)
|
||||
{
|
||||
try
|
||||
{
|
||||
// End games
|
||||
xtw.WriteEndElement();
|
||||
// End games
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.WriteStartElement("gui");
|
||||
xtw.WriteStartElement("gui");
|
||||
|
||||
xtw.WriteStartElement("images");
|
||||
xtw.WriteAttributeString("width", "487");
|
||||
xtw.WriteAttributeString("height", "162");
|
||||
xtw.WriteStartElement("images");
|
||||
xtw.WriteAttributeString("width", "487");
|
||||
xtw.WriteAttributeString("height", "162");
|
||||
|
||||
xtw.WriteStartElement("image");
|
||||
xtw.WriteAttributeString("x", "0");
|
||||
xtw.WriteAttributeString("y", "0");
|
||||
xtw.WriteAttributeString("width", "240");
|
||||
xtw.WriteAttributeString("height", "160");
|
||||
xtw.WriteEndElement();
|
||||
xtw.WriteStartElement("image");
|
||||
xtw.WriteAttributeString("x", "0");
|
||||
xtw.WriteAttributeString("y", "0");
|
||||
xtw.WriteAttributeString("width", "240");
|
||||
xtw.WriteAttributeString("height", "160");
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.WriteStartElement("image");
|
||||
xtw.WriteAttributeString("x", "245");
|
||||
xtw.WriteAttributeString("y", "0");
|
||||
xtw.WriteAttributeString("width", "240");
|
||||
xtw.WriteAttributeString("height", "160");
|
||||
xtw.WriteEndElement();
|
||||
xtw.WriteStartElement("image");
|
||||
xtw.WriteAttributeString("x", "245");
|
||||
xtw.WriteAttributeString("y", "0");
|
||||
xtw.WriteAttributeString("width", "240");
|
||||
xtw.WriteAttributeString("height", "160");
|
||||
xtw.WriteEndElement();
|
||||
|
||||
// End images
|
||||
xtw.WriteEndElement();
|
||||
// End images
|
||||
xtw.WriteEndElement();
|
||||
|
||||
// End gui
|
||||
xtw.WriteEndElement();
|
||||
// End gui
|
||||
xtw.WriteEndElement();
|
||||
|
||||
// End dat
|
||||
xtw.WriteEndElement();
|
||||
// End dat
|
||||
xtw.WriteEndElement();
|
||||
|
||||
xtw.Flush();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Globals.Logger.Error(ex.ToString());
|
||||
if (Globals.ThrowOnError)
|
||||
throw ex;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
xtw.Flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user