mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Refactor DAT name creation
This commit is contained in:
@@ -71,11 +71,8 @@ namespace SabreTools.Helper
|
|||||||
// Create the output directory if it doesn't already exist
|
// Create the output directory if it doesn't already exist
|
||||||
Directory.CreateDirectory(outDir);
|
Directory.CreateDirectory(outDir);
|
||||||
|
|
||||||
// Get the outfile and clean the path
|
// Get the outfile name
|
||||||
string outfile = outDir + datdata.Description + (datdata.OutputFormat == OutputFormat.Xml || datdata.OutputFormat == OutputFormat.SabreDat ? ".xml" : ".dat");
|
string outfile = Style.CreateOutfileName(outDir, datdata);
|
||||||
outfile = (outfile.Contains(Path.DirectorySeparatorChar.ToString() + Path.DirectorySeparatorChar.ToString()) ?
|
|
||||||
outfile.Replace(Path.DirectorySeparatorChar.ToString() + Path.DirectorySeparatorChar.ToString(), Path.DirectorySeparatorChar.ToString()) :
|
|
||||||
outfile);
|
|
||||||
|
|
||||||
logger.User("Opening file for writing: " + outfile);
|
logger.User("Opening file for writing: " + outfile);
|
||||||
|
|
||||||
|
|||||||
@@ -139,25 +139,14 @@ namespace SabreTools.Helper
|
|||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://stackoverflow.com/questions/203528/what-is-the-simplest-way-to-get-indented-xml-with-line-breaks-from-xmldocument
|
public static string CreateOutfileName(string outDir, DatData datdata)
|
||||||
// http://www.timvw.be/2007/01/08/generating-utf-8-with-systemxmlxmlwriter/
|
|
||||||
public static string Beautify(XmlDocument doc)
|
|
||||||
{
|
{
|
||||||
MemoryStream ms = new MemoryStream();
|
string outfile = outDir + datdata.Description + (datdata.OutputFormat == OutputFormat.Xml || datdata.OutputFormat == OutputFormat.SabreDat ? ".xml" : ".dat");
|
||||||
XmlWriterSettings settings = new XmlWriterSettings
|
outfile = (outfile.Contains(Path.DirectorySeparatorChar.ToString() + Path.DirectorySeparatorChar.ToString()) ?
|
||||||
{
|
outfile.Replace(Path.DirectorySeparatorChar.ToString() + Path.DirectorySeparatorChar.ToString(), Path.DirectorySeparatorChar.ToString()) :
|
||||||
Encoding = new UTF8Encoding(false),
|
outfile);
|
||||||
Indent = true,
|
|
||||||
IndentChars = "\t",
|
|
||||||
NewLineChars = "\r\n",
|
|
||||||
NewLineHandling = NewLineHandling.Replace
|
|
||||||
};
|
|
||||||
|
|
||||||
using (XmlWriter writer = XmlWriter.Create(ms, settings))
|
return outfile;
|
||||||
{
|
|
||||||
doc.Save(writer);
|
|
||||||
}
|
|
||||||
return Encoding.UTF8.GetString(ms.ToArray());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user