diff --git a/SabreHelper/RomManipulation.cs b/SabreHelper/RomManipulation.cs index 40375105..ef4cc45b 100644 --- a/SabreHelper/RomManipulation.cs +++ b/SabreHelper/RomManipulation.cs @@ -29,15 +29,13 @@ namespace SabreTools.Helper } /// - /// Get the name of the DAT for external use + /// Get the XmlDocument associated with a file, if possible /// /// Name of the file to be parsed /// Logger object for console and file output - /// The internal name of the DAT on success, empty string otherwise - public static string GetDatName(string filename, Logger logger) + /// The XmlDocument representing the (possibly converted) file, null otherwise + public static XmlDocument GetXmlDocument(string filename, Logger logger) { - string name = ""; - XmlDocument doc = new XmlDocument(); try { @@ -52,12 +50,32 @@ namespace SabreTools.Helper catch (Exception ex) { logger.Error(ex.ToString()); - return name; + return null; } } catch (Exception ex) { logger.Error(ex.ToString()); + return null; + } + + return doc; + } + + /// + /// Get the name of the DAT for external use + /// + /// Name of the file to be parsed + /// Logger object for console and file output + /// The internal name of the DAT on success, empty string otherwise + public static string GetDatName(string filename, Logger logger) + { + string name = ""; + XmlDocument doc = GetXmlDocument(filename, logger); + + // If the returned document is null, return the blank string + if (doc == null) + { return name; } @@ -100,26 +118,11 @@ namespace SabreTools.Helper List roms = new List(); bool superdat = false; - XmlDocument doc = new XmlDocument(); - try + XmlDocument doc = GetXmlDocument(filename, logger); + + // If the returned document is null, return the empty list + if (doc == null) { - doc.LoadXml(File.ReadAllText(filename)); - } - catch (XmlException) - { - try - { - doc.LoadXml(Converters.RomVaultToXML(File.ReadAllLines(filename)).ToString()); - } - catch (Exception ex) - { - logger.Error(ex.ToString()); - return roms; - } - } - catch (Exception ex) - { - logger.Error(ex.ToString()); return roms; }