diff --git a/DATabase/DATabase.cs b/DATabase/DATabase.cs index 22cb0b4e..d9751571 100644 --- a/DATabase/DATabase.cs +++ b/DATabase/DATabase.cs @@ -621,9 +621,7 @@ Make a selection: /// /// /// At an unspecified future date, this will also include the following currently-separate programs: - /// - MergeDAT /// - DATFromDir - /// - DatToMiss /// private static void DatToolsMenu() { diff --git a/DATabase/TrimMerge.cs b/DATabase/TrimMerge.cs index 605b1d95..58ed0569 100644 --- a/DATabase/TrimMerge.cs +++ b/DATabase/TrimMerge.cs @@ -112,8 +112,8 @@ namespace SabreTools } // Now write the file out accordingly - Output.WriteToDat(Path.GetFileNameWithoutExtension(filename), - Path.GetFileNameWithoutExtension(filename), "", "", "", "", _forceunpack, !RomManipulation.IsXmlDat(filename), Path.GetDirectoryName(filename), outroms, _logger); + Output.WriteToDat(RomManipulation.GetDatName(filename, _logger), RomManipulation.GetDatDescription(filename, _logger), + "", "", "", "", _forceunpack, !RomManipulation.IsXmlDat(filename), Path.GetDirectoryName(filename), outroms, _logger); // Remove the original file if different and inform the user if (Path.GetExtension(filename) != (RomManipulation.IsXmlDat(filename) ? ".xml" : ".dat")) diff --git a/SabreHelper/Build.cs b/SabreHelper/Build.cs index c0aeb9cb..d919065e 100644 --- a/SabreHelper/Build.cs +++ b/SabreHelper/Build.cs @@ -128,7 +128,7 @@ Options: -c=, --cat= Set the category of the DAT -v=, --version= Set the version of the DAT -au=, --author= Set the author of the DAT - -rm, --remove Remove a system or source from the database + -rm, --remove Remove a system or source from the database system= System ID source= Source ID -tm, --trim-merge Consolidate DAT into a single game and trim entries diff --git a/SabreHelper/RomManipulation.cs b/SabreHelper/RomManipulation.cs index 477e1227..8b712132 100644 --- a/SabreHelper/RomManipulation.cs +++ b/SabreHelper/RomManipulation.cs @@ -99,12 +99,63 @@ namespace SabreTools.Helper // Get the name from the header if (node != null && node.Name == "header") { - name = node.SelectSingleNode("name").InnerText; + XmlNode temp = node.SelectSingleNode("name"); + if (temp != null) + { + name = temp.InnerText; + } } return name; } + /// + /// Get the description 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 GetDatDescription(string filename, Logger logger) + { + string desc = ""; + XmlDocument doc = GetXmlDocument(filename, logger); + + // If the returned document is null, return the blank string + if (doc == null) + { + return desc; + } + + // Experimental looping using only XML parsing + XmlNode node = doc.FirstChild; + if (node != null && node.Name == "xml") + { + // Skip over everything that's not an element + while (node.NodeType != XmlNodeType.Element) + { + node = node.NextSibling; + } + } + + // Once we find the main body, enter it + if (node != null && (node.Name == "datafile" || node.Name == "softwarelist")) + { + node = node.FirstChild; + } + + // Get the name from the header + if (node != null && node.Name == "header") + { + XmlNode temp = node.SelectSingleNode("description"); + if (temp != null) + { + desc = temp.InnerText; + } + } + + return desc; + } + /// /// Parse a DAT and return all found games and roms within ///