diff --git a/Castor/Castor.csproj b/Castor/Castor.csproj index e867cfb..467f90d 100644 --- a/Castor/Castor.csproj +++ b/Castor/Castor.csproj @@ -51,9 +51,6 @@ - - PreserveNewest - PreserveNewest diff --git a/Castor/Interfaces/ICommandService.cs b/Castor/Interfaces/ICommandService.cs index ed53385..1b6fe15 100644 --- a/Castor/Interfaces/ICommandService.cs +++ b/Castor/Interfaces/ICommandService.cs @@ -1,6 +1,4 @@ -using System.Diagnostics; - -namespace Castor.Interfaces +namespace Castor.Interfaces { interface ICommandService { @@ -10,6 +8,6 @@ interface ICommandService void Install(string[] args); void Version(); void Serve(string[] args); - Process ConsoleCommand(string arg); + void ConsoleCommand(string program, string arg); } } diff --git a/Castor/Interfaces/IFileService.cs b/Castor/Interfaces/IFileService.cs index db4efb7..ee1a65c 100644 --- a/Castor/Interfaces/IFileService.cs +++ b/Castor/Interfaces/IFileService.cs @@ -1,9 +1,4 @@ using Castor.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Castor.Interfaces { diff --git a/Castor/Services/CommandService.cs b/Castor/Services/CommandService.cs index 63967b4..65e9d07 100644 --- a/Castor/Services/CommandService.cs +++ b/Castor/Services/CommandService.cs @@ -1,12 +1,9 @@ using Castor.Interfaces; using Castor.Models; -using Newtonsoft.Json.Linq; using System; -using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.IO.Compression; -using System.Reflection; using System.Text.Json; namespace Castor.Services @@ -173,17 +170,13 @@ public void Serve(string[] args) string baseDirectory = AppDomain.CurrentDomain.BaseDirectory; - File.Copy($"{baseDirectory}\\castor-serve-mod.z2f", "castor-serve-mod.z2f"); - - string command = $"\"{castorConfig.ZT2loc}\\zt.exe\" {baseDirectory}castor-serve-save.z2s"; Console.WriteLine("preparing serve"); - Console.WriteLine("loading Tiny Test Map..."); - using (ConsoleCommand(command)) - { - - } + Console.WriteLine("loading Tiny Test Map"); + string ZTprogram = $"\"{castorConfig.ZT2loc}\\zt.exe\""; + string ZTarg = $"{baseDirectory}castor-serve-save.z2s"; - File.Delete("castor-serve-mod.z2f"); + Console.WriteLine("watching Zoo Tycoon 2..."); + ConsoleCommand(ZTprogram, ZTarg); } public void Version() @@ -191,16 +184,29 @@ public void Version() Console.WriteLine("Castor v3.0.0-beta"); } - public Process ConsoleCommand(string arg) + public void ConsoleCommand(string program, string arg) + { + using (var process = new Process()) + { + process.StartInfo.FileName = program; + process.StartInfo.Arguments = arg; + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.UseShellExecute = false; + process.Start(); + + while (!process.StandardOutput.EndOfStream) + { + string line = process.StandardOutput.ReadLine(); + Console.WriteLine(line); + // do something with line + } + process.WaitForExit(); + } + } + + void p_OutputDataReceived(object sender, DataReceivedEventArgs e) { - Process process = new(); - ProcessStartInfo startInfo = new(); - startInfo.WindowStyle = ProcessWindowStyle.Hidden; - startInfo.FileName = "cmd.exe"; - startInfo.Arguments = $"/C {arg}"; - process.StartInfo = startInfo; - process.Start(); - return process; + Console.WriteLine($"[{DateTime.Now}] {e.Data}"); } } } diff --git a/Castor/castor-serve-mod.z2f b/Castor/castor-serve-mod.z2f deleted file mode 100644 index d35db1a..0000000 Binary files a/Castor/castor-serve-mod.z2f and /dev/null differ