Refactor DAT name creation

This commit is contained in:
Matt Nadareski
2016-05-23 14:05:25 -07:00
parent 23c07252d9
commit 7afdf4adc5
2 changed files with 8 additions and 22 deletions

View File

@@ -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);

View File

@@ -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;
}
}
}