Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[xlcore][feature] Implement Run functions on the runners #1257

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/XIVLauncher.Common.Unix/UnixGameRunner.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<string, string> 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;
}
}
42 changes: 42 additions & 0 deletions src/XIVLauncher.Common.Windows/WindowsGameRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<string, string> 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;
}
}
2 changes: 2 additions & 0 deletions src/XIVLauncher.Common/PlatformAbstractions/IGameRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ namespace XIVLauncher.Common.PlatformAbstractions;
public interface IGameRunner
{
Process? Start(string path, string workingDirectory, string arguments, IDictionary<string, string> environment, DpiAwareness dpiAwareness);

Process? Run(string path, string workingDirectory, string arguments, IDictionary<string, string> environment, bool withCompatibility);
}