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="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,46 +181,32 @@ 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)
|
||||
private void WriteHeader(SeparatedValueWriter svw)
|
||||
{
|
||||
try
|
||||
string[] headers = new string[]
|
||||
{
|
||||
string[] headers = new string[]
|
||||
{
|
||||
"#Name",
|
||||
"Title",
|
||||
"Emulator",
|
||||
"CloneOf",
|
||||
"Year",
|
||||
"Manufacturer",
|
||||
"Category",
|
||||
"Players",
|
||||
"Rotation",
|
||||
"Control",
|
||||
"Status",
|
||||
"DisplayCount",
|
||||
"DisplayType",
|
||||
"AltRomname",
|
||||
"AltTitle",
|
||||
"Extra",
|
||||
"Buttons",
|
||||
};
|
||||
"#Name",
|
||||
"Title",
|
||||
"Emulator",
|
||||
"CloneOf",
|
||||
"Year",
|
||||
"Manufacturer",
|
||||
"Category",
|
||||
"Players",
|
||||
"Rotation",
|
||||
"Control",
|
||||
"Status",
|
||||
"DisplayCount",
|
||||
"DisplayType",
|
||||
"AltRomname",
|
||||
"AltTitle",
|
||||
"Extra",
|
||||
"Buttons",
|
||||
};
|
||||
|
||||
svw.WriteHeader(headers);
|
||||
svw.WriteHeader(headers);
|
||||
|
||||
svw.Flush();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Globals.Logger.Error(ex.ToString());
|
||||
if (Globals.ThrowOnError)
|
||||
throw ex;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
svw.Flush();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -230,24 +214,22 @@ namespace SabreTools.Library.DatFiles
|
||||
/// </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)
|
||||
/// <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)
|
||||
{
|
||||
try
|
||||
// No game should start with a path separator
|
||||
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar);
|
||||
|
||||
// Pre-process the item name
|
||||
ProcessItemName(datItem, true);
|
||||
|
||||
// Build the state
|
||||
switch (datItem.ItemType)
|
||||
{
|
||||
// No game should start with a path separator
|
||||
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar);
|
||||
|
||||
// Pre-process the item name
|
||||
ProcessItemName(datItem, true);
|
||||
|
||||
// Build the state
|
||||
switch (datItem.ItemType)
|
||||
{
|
||||
case ItemType.Rom:
|
||||
var rom = datItem as Rom;
|
||||
string[] fields = new string[]
|
||||
{
|
||||
case ItemType.Rom:
|
||||
var rom = datItem as Rom;
|
||||
string[] fields = new string[]
|
||||
{
|
||||
rom.Machine.Name,
|
||||
rom.Machine.Description,
|
||||
Header.FileName,
|
||||
@@ -265,24 +247,13 @@ namespace SabreTools.Library.DatFiles
|
||||
rom.AltTitle,
|
||||
rom.Machine.Comment,
|
||||
rom.Machine.Buttons,
|
||||
};
|
||||
};
|
||||
|
||||
svw.WriteValues(fields);
|
||||
break;
|
||||
}
|
||||
|
||||
svw.Flush();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Globals.Logger.Error(ex.ToString());
|
||||
if (Globals.ThrowOnError)
|
||||
throw ex;
|
||||
|
||||
return false;
|
||||
svw.WriteValues(fields);
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
svw.Flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user