public static MatchResult FromFiles(string loadListFile, string scoreLogFile, string statsLogFile) { var result = new MatchResult { LoadListFile = loadListFile, ScoreLogFile = scoreLogFile, StatsLogFile = statsLogFile, }; result.ReadScoreLog(); result.ReadStatsLog(); return result; }
public MatchResult Run() { const string robotBattleExePath = @"C:\Program Files (x86)\Robot Battle\winrob32.exe"; var loadListFile = Path.GetTempPath() + "loadlist.ll"; var scoreLogFile = Path.GetTempPath() + "score.log"; var statsLogFile = Path.GetTempPath() + "stats.log"; using (var writer = XmlWriter.Create(loadListFile, new XmlWriterSettings { Indent = true })) { matchBuilder.ToXml().WriteTo(writer); } if (hideWindow) { var desktopName = "RobotBattle.Automation." + Guid.NewGuid(); var desktopPtr = NativeMethods.CreateDesktop(desktopName, null, null, 0, 0xff, IntPtr.Zero); try { if (desktopPtr == IntPtr.Zero) { throw new InvalidOperationException("Failed to create the secondary desktop"); } // set startup parameters. var si = new NativeMethods.StartupInfo(); si.cb = Marshal.SizeOf(si); si.lpDesktop = desktopName; var pi = new NativeMethods.ProcessInformation(); var path = string.Format( "\"{0}\" \"{1}\" /t /lf \"{2}\" /slf \"{3}\" /slg 1 /lo 1 /slo 1", robotBattleExePath, loadListFile, scoreLogFile, statsLogFile ); if ( !NativeMethods.CreateProcess(null, path, IntPtr.Zero, IntPtr.Zero, true, 0x00000020, /*NORMAL_PRIORITY_CLASS*/ IntPtr.Zero, null, ref si, ref pi)) { throw new InvalidOperationException("Failed to launch the Robot Battle process"); } Process.GetProcessById(pi.dwProcessId) .WaitForExit(); } finally { NativeMethods.CloseDesktop(desktopPtr); } } else { Process.Start(new ProcessStartInfo { FileName = robotBattleExePath, Arguments = string.Format( "\"{1}\" /t /lf \"{2}\" /slf \"{3}\" /slg 1 /lo 1 /slo 1", robotBattleExePath, loadListFile, scoreLogFile, statsLogFile ) }).WaitForExit(); } return(MatchResult.FromFiles(loadListFile, scoreLogFile, statsLogFile)); }