Added filename sanitizing, and blz.exe is ran from the same directory as the executable now. Fixes #1 and fixes #5.

This commit is contained in:
Prof. 9
2014-05-24 06:13:18 +02:00
parent 8e4ec9917a
commit 21d1ca0a61

View File

@@ -6,12 +6,13 @@ using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace WfcReplay
{
class Program
{
static string version = "v0.3";
static string version = "v0.4";
static void Main(string[] args)
{
@@ -37,6 +38,7 @@ namespace WfcReplay
MemoryStream outStream = new MemoryStream(Encoding.UTF8.GetBytes(code));
outStream.Position = 0;
string fileName = makeGameString(romReader) + ".txt";
fileName = makeFileNameSafe(fileName);
writeFile(fileName, outStream);
Console.WriteLine("Success!");
Console.WriteLine("Code written to " + Directory.GetCurrentDirectory() + "\\" + fileName + ".");
@@ -109,6 +111,11 @@ namespace WfcReplay
{
writeFile(tempFolderPath + fileName, file);
}
static string makeFileNameSafe(string fileName)
{
string[] validParts = fileName.Split(System.IO.Path.GetInvalidFileNameChars(), StringSplitOptions.RemoveEmptyEntries);
return string.Join("-", validParts);
}
string tempFolderPath;
@@ -308,6 +315,7 @@ namespace WfcReplay
writeTempFile(fileName, file);
ProcessStartInfo psi = new ProcessStartInfo("blz.exe", "-d " + tempFolderPath + fileName);
psi.WorkingDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
psi.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(psi).WaitForExit();