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:
@@ -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,40 +433,26 @@ 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)
|
||||
private void WriteHeader(IniWriter iw)
|
||||
{
|
||||
try
|
||||
{
|
||||
iw.WriteSection("CREDITS");
|
||||
iw.WriteKeyValuePair("author", Header.Author);
|
||||
iw.WriteKeyValuePair("version", Header.Version);
|
||||
iw.WriteKeyValuePair("comment", Header.Comment);
|
||||
iw.WriteSection("CREDITS");
|
||||
iw.WriteKeyValuePair("author", Header.Author);
|
||||
iw.WriteKeyValuePair("version", Header.Version);
|
||||
iw.WriteKeyValuePair("comment", Header.Comment);
|
||||
|
||||
iw.WriteSection("DAT");
|
||||
iw.WriteKeyValuePair("version", Header.RomCenterVersion ?? "2.50");
|
||||
iw.WriteKeyValuePair("plugin", Header.System);
|
||||
iw.WriteKeyValuePair("split", Header.ForceMerging == MergingFlag.Split ? "1" : "0");
|
||||
iw.WriteKeyValuePair("merge", Header.ForceMerging == MergingFlag.Full || Header.ForceMerging == MergingFlag.Merged ? "1" : "0");
|
||||
iw.WriteSection("DAT");
|
||||
iw.WriteKeyValuePair("version", Header.RomCenterVersion ?? "2.50");
|
||||
iw.WriteKeyValuePair("plugin", Header.System);
|
||||
iw.WriteKeyValuePair("split", Header.ForceMerging == MergingFlag.Split ? "1" : "0");
|
||||
iw.WriteKeyValuePair("merge", Header.ForceMerging == MergingFlag.Full || Header.ForceMerging == MergingFlag.Merged ? "1" : "0");
|
||||
|
||||
iw.WriteSection("EMULATOR");
|
||||
iw.WriteKeyValuePair("refname", Header.Name);
|
||||
iw.WriteKeyValuePair("version", Header.Description);
|
||||
iw.WriteSection("EMULATOR");
|
||||
iw.WriteKeyValuePair("refname", Header.Name);
|
||||
iw.WriteKeyValuePair("version", Header.Description);
|
||||
|
||||
iw.WriteSection("GAMES");
|
||||
iw.WriteSection("GAMES");
|
||||
|
||||
iw.Flush();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Globals.Logger.Error(ex.ToString());
|
||||
if (Globals.ThrowOnError)
|
||||
throw ex;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
iw.Flush();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -476,8 +460,7 @@ namespace SabreTools.Library.DatFiles
|
||||
/// </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,47 +475,34 @@ namespace SabreTools.Library.DatFiles
|
||||
9 - merge name
|
||||
*/
|
||||
|
||||
try
|
||||
// Pre-process the item name
|
||||
ProcessItemName(datItem, true);
|
||||
|
||||
// Build the state
|
||||
switch (datItem.ItemType)
|
||||
{
|
||||
// Pre-process the item name
|
||||
ProcessItemName(datItem, true);
|
||||
case ItemType.Rom:
|
||||
var rom = datItem as Rom;
|
||||
|
||||
// Build the state
|
||||
switch (datItem.ItemType)
|
||||
{
|
||||
case ItemType.Rom:
|
||||
var rom = datItem as Rom;
|
||||
|
||||
iw.WriteString($"¬{rom.Machine.CloneOf ?? string.Empty}");
|
||||
iw.WriteString($"¬{rom.Machine.CloneOf ?? string.Empty}");
|
||||
iw.WriteString($"¬{rom.Machine.CloneOf ?? string.Empty}");
|
||||
iw.WriteString($"¬{rom.Machine.CloneOf ?? string.Empty}");
|
||||
iw.WriteString($"¬{rom.Machine.Name ?? string.Empty}");
|
||||
if (string.IsNullOrWhiteSpace(rom.Machine.Description ?? string.Empty))
|
||||
iw.WriteString($"¬{rom.Machine.Name ?? string.Empty}");
|
||||
if (string.IsNullOrWhiteSpace(rom.Machine.Description ?? string.Empty))
|
||||
iw.WriteString($"¬{rom.Machine.Name ?? string.Empty}");
|
||||
else
|
||||
iw.WriteString($"¬{rom.Machine.Description ?? string.Empty}");
|
||||
iw.WriteString($"¬{rom.Name ?? string.Empty}");
|
||||
iw.WriteString($"¬{rom.CRC ?? string.Empty}");
|
||||
iw.WriteString($"¬{rom.Size?.ToString() ?? string.Empty}");
|
||||
iw.WriteString($"¬{rom.Machine.RomOf ?? string.Empty}");
|
||||
iw.WriteString($"¬{rom.MergeTag ?? string.Empty}");
|
||||
iw.WriteString("¬");
|
||||
iw.WriteLine();
|
||||
else
|
||||
iw.WriteString($"¬{rom.Machine.Description ?? string.Empty}");
|
||||
iw.WriteString($"¬{rom.Name ?? string.Empty}");
|
||||
iw.WriteString($"¬{rom.CRC ?? string.Empty}");
|
||||
iw.WriteString($"¬{rom.Size?.ToString() ?? string.Empty}");
|
||||
iw.WriteString($"¬{rom.Machine.RomOf ?? string.Empty}");
|
||||
iw.WriteString($"¬{rom.MergeTag ?? string.Empty}");
|
||||
iw.WriteString("¬");
|
||||
iw.WriteLine();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
iw.Flush();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Globals.Logger.Error(ex.ToString());
|
||||
if (Globals.ThrowOnError)
|
||||
throw ex;
|
||||
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
iw.Flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user