diff --git a/src/XIVLauncher.Common.Unix/UnixGameRunner.cs b/src/XIVLauncher.Common.Unix/UnixGameRunner.cs index e612377de..34241f5b4 100644 --- a/src/XIVLauncher.Common.Unix/UnixGameRunner.cs +++ b/src/XIVLauncher.Common.Unix/UnixGameRunner.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; +using Serilog; using XIVLauncher.Common.Dalamud; using XIVLauncher.Common.PlatformAbstractions; using XIVLauncher.Common.Unix.Compatibility; @@ -31,4 +32,50 @@ public UnixGameRunner(CompatibilityTools compatibility, DalamudLauncher dalamudL return compatibility.RunInPrefix($"\"{path}\" {arguments}", workingDirectory, environment, writeLog: true); } } + + private void ProcessOutputHandler(object sender, DataReceivedEventArgs args) + { + Log.Information("Process output: {0}", args.Data); + } + + public Process? Run(string path, string workingDirectory, string arguments, IDictionary environment, bool withCompatibility) + { + if (withCompatibility) + { + return compatibility.RunInPrefix($"\"{path}\" {arguments}", workingDirectory, environment, writeLog: true); + } + + var psi = new ProcessStartInfo(path, arguments) + { + WorkingDirectory = workingDirectory, + RedirectStandardError = true, + RedirectStandardOutput = true, + UseShellExecute = false + }; + + foreach (var envVar in environment) + { + if (psi.Environment.ContainsKey(envVar.Key)) + { + psi.Environment[envVar.Key] = envVar.Value; + } + else + { + psi.Environment.Add(envVar.Key, envVar.Value); + } + } + + var p = new Process() + { + StartInfo = psi, + }; + + p.OutputDataReceived += ProcessOutputHandler; + + p.Start(); + p.BeginOutputReadLine(); + p.BeginErrorReadLine(); + + return p; + } } \ No newline at end of file diff --git a/src/XIVLauncher.Common.Windows/WindowsGameRunner.cs b/src/XIVLauncher.Common.Windows/WindowsGameRunner.cs index 229fcc943..1535820e9 100644 --- a/src/XIVLauncher.Common.Windows/WindowsGameRunner.cs +++ b/src/XIVLauncher.Common.Windows/WindowsGameRunner.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; +using Serilog; using XIVLauncher.Common.Dalamud; using XIVLauncher.Common.Game; using XIVLauncher.Common.PlatformAbstractions; @@ -44,4 +45,45 @@ public Process Start(string path, string workingDirectory, string arguments, IDi return NativeAclFix.LaunchGame(workingDirectory, path, arguments, environment, dpiAwareness, process => { }); } } + + private void ProcessOutputHandler(object sender, DataReceivedEventArgs args) + { + Log.Information("Process output: {0}", args.Data); + } + + public Process? Run(string path, string workingDirectory, string arguments, IDictionary environment, bool withCompatibility) + { + var psi = new ProcessStartInfo(path, arguments) + { + WorkingDirectory = workingDirectory, + RedirectStandardError = true, + RedirectStandardOutput = true, + UseShellExecute = false + }; + + foreach (var envVar in environment) + { + if (psi.Environment.ContainsKey(envVar.Key)) + { + psi.Environment[envVar.Key] = envVar.Value; + } + else + { + psi.Environment.Add(envVar.Key, envVar.Value); + } + } + + var p = new Process() + { + StartInfo = psi + }; + + p.OutputDataReceived += ProcessOutputHandler; + + p.Start(); + p.BeginOutputReadLine(); + p.BeginErrorReadLine(); + + return p; + } } \ No newline at end of file diff --git a/src/XIVLauncher.Common/PlatformAbstractions/IGameRunner.cs b/src/XIVLauncher.Common/PlatformAbstractions/IGameRunner.cs index d0a19656b..18449f2cb 100644 --- a/src/XIVLauncher.Common/PlatformAbstractions/IGameRunner.cs +++ b/src/XIVLauncher.Common/PlatformAbstractions/IGameRunner.cs @@ -6,4 +6,6 @@ namespace XIVLauncher.Common.PlatformAbstractions; public interface IGameRunner { Process? Start(string path, string workingDirectory, string arguments, IDictionary environment, DpiAwareness dpiAwareness); + + Process? Run(string path, string workingDirectory, string arguments, IDictionary environment, bool withCompatibility); } \ No newline at end of file