diff --git a/SabreTools.Library/DatFiles/DatFile.cs b/SabreTools.Library/DatFiles/DatFile.cs index 44d419cc..1c20289e 100644 --- a/SabreTools.Library/DatFiles/DatFile.cs +++ b/SabreTools.Library/DatFiles/DatFile.cs @@ -707,8 +707,9 @@ namespace SabreTools.Library.DatFiles /// Apply cleaning methods to the DatFile /// /// Cleaner to use + /// True if the error that is thrown should be thrown back to the caller, false otherwise /// True if cleaning was successful, false on error - public bool ApplyCleaning(Cleaner cleaner) + public bool ApplyCleaning(Cleaner cleaner, bool throwOnError = false) { try { @@ -751,9 +752,7 @@ namespace SabreTools.Library.DatFiles catch (Exception ex) { Globals.Logger.Error(ex); - if (Globals.ThrowOnError) - throw ex; - + if (throwOnError) throw ex; return false; } @@ -764,8 +763,9 @@ namespace SabreTools.Library.DatFiles /// Apply a set of Extra INIs on the DatFile /// /// ExtrasIni to use + /// True if the error that is thrown should be thrown back to the caller, false otherwise /// True if the extras were applied, false on error - public bool ApplyExtras(ExtraIni extras) + public bool ApplyExtras(ExtraIni extras, bool throwOnError = false) { try { @@ -817,9 +817,7 @@ namespace SabreTools.Library.DatFiles catch (Exception ex) { Globals.Logger.Error(ex); - if (Globals.ThrowOnError) - throw ex; - + if (throwOnError) throw ex; return false; } @@ -831,8 +829,9 @@ namespace SabreTools.Library.DatFiles /// /// Filter to use /// True if entire machines are considered, false otherwise (default) + /// True if the error that is thrown should be thrown back to the caller, false otherwise /// True if the DatFile was filtered, false on error - public bool ApplyFilter(Filter filter, bool perMachine = false) + public bool ApplyFilter(Filter filter, bool perMachine = false, bool throwOnError = false) { // If we have a null filter, return false if (filter == null) @@ -891,9 +890,7 @@ namespace SabreTools.Library.DatFiles catch (Exception ex) { Globals.Logger.Error(ex); - if (Globals.ThrowOnError) - throw ex; - + if (throwOnError) throw ex; return false; } @@ -905,8 +902,9 @@ namespace SabreTools.Library.DatFiles /// /// Split type to try /// True if DatFile tags override splitting, false otherwise + /// True if the error that is thrown should be thrown back to the caller, false otherwise /// True if the DatFile was split, false on error - public bool ApplySplitting(MergingFlag splitType, bool useTags) + public bool ApplySplitting(MergingFlag splitType, bool useTags, bool throwOnError = false) { try { @@ -940,9 +938,7 @@ namespace SabreTools.Library.DatFiles catch (Exception ex) { Globals.Logger.Error(ex); - if (Globals.ThrowOnError) - throw ex; - + if (throwOnError) throw ex; return false; } @@ -1011,7 +1007,8 @@ namespace SabreTools.Library.DatFiles /// /// Use game descriptions as names in the DAT, updating cloneof/romof/sampleof /// - public void MachineDescriptionToName() + /// True if the error that is thrown should be thrown back to the caller, false otherwise + public void MachineDescriptionToName(bool throwOnError = false) { try { @@ -1062,8 +1059,7 @@ namespace SabreTools.Library.DatFiles catch (Exception ex) { Globals.Logger.Warning(ex.ToString()); - if (Globals.ThrowOnError) - throw ex; + if (throwOnError) throw ex; } } @@ -3527,8 +3523,7 @@ namespace SabreTools.Library.DatFiles catch (Exception ex) { Globals.Logger.Error(ex, $"Datfile {outfile} could not be written out"); - if (Globals.ThrowOnError) - throw ex; + if (throwOnError) throw ex; } }); @@ -3536,9 +3531,7 @@ namespace SabreTools.Library.DatFiles catch (Exception ex) { Globals.Logger.Error(ex); - if (Globals.ThrowOnError) - throw ex; - + if (throwOnError) throw ex; return false; } diff --git a/SabreTools.Library/DatFiles/EverdriveSmdb.cs b/SabreTools.Library/DatFiles/EverdriveSmdb.cs index 7801dab3..88b010ee 100644 --- a/SabreTools.Library/DatFiles/EverdriveSmdb.cs +++ b/SabreTools.Library/DatFiles/EverdriveSmdb.cs @@ -139,9 +139,7 @@ namespace SabreTools.Library.DatFiles catch (Exception ex) { Globals.Logger.Error(ex); - if (Globals.ThrowOnError) - throw ex; - + if (throwOnError) throw ex; return false; } @@ -153,50 +151,36 @@ namespace SabreTools.Library.DatFiles /// /// SeparatedValueWriter to output to /// DatItem object to be output - /// True if the data was written, false on error - private bool WriteDatItem(SeparatedValueWriter svw, DatItem datItem) + 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); + case ItemType.Rom: + var rom = datItem as Rom; - // 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[] - { + string[] fields = new string[] + { rom.SHA256 ?? string.Empty, $"{rom.Machine.Name ?? string.Empty}/", rom.Name ?? string.Empty, rom.SHA1 ?? string.Empty, rom.MD5 ?? string.Empty, rom.CRC ?? string.Empty, - }; + }; - svw.WriteValues(fields); + svw.WriteValues(fields); - break; - } - - svw.Flush(); - } - catch (Exception ex) - { - Globals.Logger.Error(ex); - if (Globals.ThrowOnError) - throw ex; - - return false; + break; } - return true; + svw.Flush(); } } } diff --git a/SabreTools.Library/DatFiles/SeparatedValue.cs b/SabreTools.Library/DatFiles/SeparatedValue.cs index a105184e..d24cc679 100644 --- a/SabreTools.Library/DatFiles/SeparatedValue.cs +++ b/SabreTools.Library/DatFiles/SeparatedValue.cs @@ -66,9 +66,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; }