embed ui executable directly into c# assembly
This commit is contained in:
@@ -4,14 +4,39 @@ namespace Il2CppInspector.Redux.GUI;
|
||||
|
||||
public class UiProcessService(IHostApplicationLifetime lifetime) : BackgroundService
|
||||
{
|
||||
// NOTE: this is not really a good solution for getting people to launch the correct program.
|
||||
private const string UiExecutableName = "./resources/il2cppinspectorredux.exe";
|
||||
// TODO: This needs to be adjusted for multiplatform support
|
||||
private const string UiExecutableName = "il2cppinspectorredux.exe";
|
||||
|
||||
private Process? _uiProcess;
|
||||
private string? _uiExectuablePath;
|
||||
|
||||
public void LaunchUiProcess(int port)
|
||||
{
|
||||
_uiProcess = Process.Start(new ProcessStartInfo(UiExecutableName, [port.ToString()]));
|
||||
_uiExectuablePath ??= ExtractUiExecutable();
|
||||
_uiProcess = Process.Start(new ProcessStartInfo(_uiExectuablePath, [port.ToString()]));
|
||||
}
|
||||
|
||||
private static string ExtractUiExecutable()
|
||||
{
|
||||
try
|
||||
{
|
||||
using var executable =
|
||||
typeof(UiProcessService).Assembly.GetManifestResourceStream(
|
||||
$"{typeof(UiProcessService).Namespace!}.{UiExecutableName}");
|
||||
if (executable == null)
|
||||
throw new FileNotFoundException("Failed to open resource as stream.");
|
||||
|
||||
var tempDir = Directory.CreateTempSubdirectory("il2cppinspectorredux-ui");
|
||||
var uiExePath = Path.Join(tempDir.FullName, UiExecutableName);
|
||||
|
||||
using var fs = File.Create(uiExePath);
|
||||
executable.CopyTo(fs);
|
||||
return uiExePath;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new InvalidOperationException($"Failed to find embedded UI executable: {ex}");
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
@@ -28,6 +53,9 @@ public class UiProcessService(IHostApplicationLifetime lifetime) : BackgroundSer
|
||||
if (_uiProcess is { HasExited: false })
|
||||
_uiProcess.Kill();
|
||||
|
||||
if (_uiExectuablePath != null)
|
||||
File.Delete(_uiExectuablePath);
|
||||
|
||||
return base.StopAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user