diff --git a/DatSplit/DatSplit.cs b/DatSplit/DatSplit.cs index 7147bba8..2d515ebe 100644 --- a/DatSplit/DatSplit.cs +++ b/DatSplit/DatSplit.cs @@ -154,37 +154,16 @@ namespace DatSplit // Append the built nodes to the documents outDocA.AppendChild(outDocA.ImportNode(outA, true)); string outPathA = Path.GetFileNameWithoutExtension(filename) + extA + Path.GetExtension(filename); - File.WriteAllText(outPathA, Beautify(outDocA), Encoding.UTF8); + File.WriteAllText(outPathA, Style.Beautify(outDocA), Encoding.UTF8); outDocB.AppendChild(outDocB.ImportNode(outB, true)); string outPathB = Path.GetFileNameWithoutExtension(filename) + extB + Path.GetExtension(filename); - File.WriteAllText(outPathB, Beautify(outDocB), Encoding.UTF8); + File.WriteAllText(outPathB, Style.Beautify(outDocB), Encoding.UTF8); } public static void Help() { Console.WriteLine("DatSplit.exe "); } - - // http://stackoverflow.com/questions/203528/what-is-the-simplest-way-to-get-indented-xml-with-line-breaks-from-xmldocument - // http://www.timvw.be/2007/01/08/generating-utf-8-with-systemxmlxmlwriter/ - static public string Beautify(XmlDocument doc) - { - MemoryStream ms = new MemoryStream(); - XmlWriterSettings settings = new XmlWriterSettings - { - Encoding = new UTF8Encoding(false), - Indent = true, - IndentChars = "\t", - NewLineChars = "\r\n", - NewLineHandling = NewLineHandling.Replace - }; - - using (XmlWriter writer = XmlWriter.Create(ms, settings)) - { - doc.Save(writer); - } - return Encoding.UTF8.GetString(ms.ToArray()); - } } } diff --git a/SabreHelper/Style.cs b/SabreHelper/Style.cs index c6665450..b4bdf7a0 100644 --- a/SabreHelper/Style.cs +++ b/SabreHelper/Style.cs @@ -1,4 +1,7 @@ -using System.Text.RegularExpressions; +using System.IO; +using System.Text; +using System.Text.RegularExpressions; +using System.Xml; namespace SabreTools.Helper { @@ -135,5 +138,26 @@ namespace SabreTools.Helper return input; } + + // http://stackoverflow.com/questions/203528/what-is-the-simplest-way-to-get-indented-xml-with-line-breaks-from-xmldocument + // http://www.timvw.be/2007/01/08/generating-utf-8-with-systemxmlxmlwriter/ + public static string Beautify(XmlDocument doc) + { + MemoryStream ms = new MemoryStream(); + XmlWriterSettings settings = new XmlWriterSettings + { + Encoding = new UTF8Encoding(false), + Indent = true, + IndentChars = "\t", + NewLineChars = "\r\n", + NewLineHandling = NewLineHandling.Replace + }; + + using (XmlWriter writer = XmlWriter.Create(ms, settings)) + { + doc.Save(writer); + } + return Encoding.UTF8.GetString(ms.ToArray()); + } } } diff --git a/SingleGame/SingleGame.cs b/SingleGame/SingleGame.cs index 55f42de4..99c1cd44 100644 --- a/SingleGame/SingleGame.cs +++ b/SingleGame/SingleGame.cs @@ -115,33 +115,12 @@ namespace SabreTools tempDoc.AppendChild(tempDoc.CreateDocumentType("datafile", "-//Logiqx//DTD ROM Management Datafile//EN", "http://www.logiqx.com/Dats/datafile.dtd", null)); tempDoc.AppendChild(outNode); string outPath = Path.GetFileNameWithoutExtension(filename) + ".new" + Path.GetExtension(filename); - File.WriteAllText(outPath, Beautify(tempDoc)); + File.WriteAllText(outPath, Style.Beautify(tempDoc)); } private static void Help() { } - - // http://stackoverflow.com/questions/203528/what-is-the-simplest-way-to-get-indented-xml-with-line-breaks-from-xmldocument - // http://www.timvw.be/2007/01/08/generating-utf-8-with-systemxmlxmlwriter/ - static public string Beautify(XmlDocument doc) - { - MemoryStream ms = new MemoryStream(); - XmlWriterSettings settings = new XmlWriterSettings - { - Encoding = new UTF8Encoding(false), - Indent = true, - IndentChars = "\t", - NewLineChars = "\r\n", - NewLineHandling = NewLineHandling.Replace - }; - - using (XmlWriter writer = XmlWriter.Create(ms, settings)) - { - doc.Save(writer); - } - return Encoding.UTF8.GetString(ms.ToArray()); - } } }