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
|
||||
Directory.CreateDirectory(outDir);
|
||||
|
||||
// Get the outfile and clean the path
|
||||
string outfile = outDir + datdata.Description + (datdata.OutputFormat == OutputFormat.Xml || datdata.OutputFormat == OutputFormat.SabreDat ? ".xml" : ".dat");
|
||||
outfile = (outfile.Contains(Path.DirectorySeparatorChar.ToString() + Path.DirectorySeparatorChar.ToString()) ?
|
||||
outfile.Replace(Path.DirectorySeparatorChar.ToString() + Path.DirectorySeparatorChar.ToString(), Path.DirectorySeparatorChar.ToString()) :
|
||||
outfile);
|
||||
// Get the outfile name
|
||||
string outfile = Style.CreateOutfileName(outDir, datdata);
|
||||
|
||||
logger.User("Opening file for writing: " + outfile);
|
||||
|
||||
|
||||
@@ -139,25 +139,14 @@ 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)
|
||||
public static string CreateOutfileName(string outDir, DatData datdata)
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
XmlWriterSettings settings = new XmlWriterSettings
|
||||
{
|
||||
Encoding = new UTF8Encoding(false),
|
||||
Indent = true,
|
||||
IndentChars = "\t",
|
||||
NewLineChars = "\r\n",
|
||||
NewLineHandling = NewLineHandling.Replace
|
||||
};
|
||||
string outfile = outDir + datdata.Description + (datdata.OutputFormat == OutputFormat.Xml || datdata.OutputFormat == OutputFormat.SabreDat ? ".xml" : ".dat");
|
||||
outfile = (outfile.Contains(Path.DirectorySeparatorChar.ToString() + Path.DirectorySeparatorChar.ToString()) ?
|
||||
outfile.Replace(Path.DirectorySeparatorChar.ToString() + Path.DirectorySeparatorChar.ToString(), Path.DirectorySeparatorChar.ToString()) :
|
||||
outfile);
|
||||
|
||||
using (XmlWriter writer = XmlWriter.Create(ms, settings))
|
||||
{
|
||||
doc.Save(writer);
|
||||
}
|
||||
return Encoding.UTF8.GetString(ms.ToArray());
|
||||
return outfile;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user