public void CreateResFile(string output, out string resFile) { int code; string mcexe = "mc.exe"; if (!String.IsNullOrEmpty(_toolsBin)) mcexe = Path.Combine(_toolsBin, mcexe); using (ProcessRunner mc = new ProcessRunner(mcexe, "-U", "{0}", "-r", "{1}", "-h", "{1}")) using (StringWriter stdio = new StringWriter()) { mc.OutputReceived += delegate(object o, ProcessOutputEventArgs e) { stdio.WriteLine(e.Data); }; if (0 != (code = mc.RunFormatArgs(_mcFile, IntermediateFiles))) { Trace.WriteLine(stdio.ToString()); throw new ApplicationException(String.Format("mc.exe failed ({0:x}):\r\n{1}", code, stdio)); } } string rcFile = Path.Combine(IntermediateFiles, Path.ChangeExtension(Path.GetFileName(_mcFile), ".rc")); VersionInfo.AppendToRc(Path.GetFileName(output), rcFile); if (!String.IsNullOrEmpty(IconFile) && File.Exists(IconFile)) File.AppendAllText(rcFile, String.Format("\r\n1 ICON \"{0}\"\r\n", IconFile.Replace(@"\", @"\\"))); if (!String.IsNullOrEmpty(ManifestFile) && File.Exists(ManifestFile)) File.AppendAllText(rcFile, String.Format("\r\n1 24 \"{0}\"\r\n", ManifestFile.Replace(@"\", @"\\"))); if (!String.IsNullOrEmpty(ResourceScript)) File.AppendAllText(rcFile, "\r\n" + ResourceScript + "\r\n"); string rcexe = "rc.exe"; if (!String.IsNullOrEmpty(_toolsBin)) rcexe = Path.Combine(_toolsBin, rcexe); using (ProcessRunner rc = new ProcessRunner(rcexe, "{0}")) using (StringWriter stdio = new StringWriter()) { rc.OutputReceived += delegate(object o, ProcessOutputEventArgs e) { stdio.WriteLine(e.Data); Trace.WriteLine(e.Data, rcexe); }; if (0 != (code = rc.RunFormatArgs(rcFile))) throw new ApplicationException(String.Format("mc.exe failed ({0:x}):\r\n{1}", code, stdio)); } resFile = Path.ChangeExtension(rcFile, ".res"); }
public void TestBuildMcFromResX() { TestResourceBuilder builder1 = new TestResourceBuilder("TestNamespace", "TestResXClass1"); builder1.Add("Testing", "test value 1", "#MessageId=42"); using (TempDirectory intermediateFiles = new TempDirectory()) using (TempFile mctxt = TempFile.FromExtension(".mc")) { using (TempFile resx1 = TempFile.FromExtension(".resx")) { builder1.BuildResX(resx1.TempPath); Commands.ResXtoMc(mctxt.TempPath, new string[] { resx1.TempPath }); } string mcexe = TestResourceBuilder.FindExe("mc.exe"); using (ProcessRunner mc = new ProcessRunner(mcexe, "-U", "{0}", "-r", "{1}", "-h", "{1}")) { mc.OutputReceived += delegate(object o, ProcessOutputEventArgs e) { Trace.WriteLine(e.Data, mcexe); }; Assert.AreEqual(0, mc.RunFormatArgs(mctxt.TempPath, intermediateFiles.TempPath), "mc.exe failed."); } string rcfile = Path.Combine(intermediateFiles.TempPath, Path.GetFileNameWithoutExtension(mctxt.TempPath) + ".rc"); Assert.IsTrue(File.Exists(rcfile)); Assert.IsTrue(File.Exists(Path.ChangeExtension(rcfile, ".h"))); Assert.IsTrue(File.Exists(Path.Combine(intermediateFiles.TempPath, "MSG00409.bin"))); string rcexe = Path.Combine(Path.GetDirectoryName(mcexe), "rc.exe"); if (!File.Exists(rcexe)) rcexe = TestResourceBuilder.FindExe("rc.exe"); using (ProcessRunner rc = new ProcessRunner(rcexe, "{0}")) { rc.OutputReceived += delegate(object o, ProcessOutputEventArgs e) { Trace.WriteLine(e.Data, rcexe); }; Assert.AreEqual(0, rc.RunFormatArgs(rcfile), "rc.exe failed."); } string resfile = Path.ChangeExtension(rcfile, ".res"); Assert.IsTrue(File.Exists(resfile)); Assert.IsTrue(File.ReadAllText(resfile).Contains("\0t\0e\0s\0t\0 \0v\0a\0l\0u\0e\0 \01")); } }
public void TestFormatArgs() { string tempfile = Path.GetTempFileName(); try { ProcessRunner runner = new ProcessRunner("cmd.exe", "/C", "ECHO", "Hello", ">{0}"); runner.StartFormatArgs(tempfile); Assert.AreEqual(0, runner.ExitCode); string output = File.ReadAllText(tempfile).Trim(); Assert.AreEqual("Hello", output); File.Delete(tempfile); Assert.AreEqual(0, runner.RunFormatArgs(tempfile)); output = File.ReadAllText(tempfile).Trim(); Assert.AreEqual("Hello", output); } finally { File.Delete(tempfile); } }