embed ui executable directly into c# assembly
This commit is contained in:
@@ -5,10 +5,10 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
<PublishAot>false</PublishAot>
|
||||
<!-- todo: enable this once the app is aot compliant! -->
|
||||
<OutputType Condition="'$(Configuration)' == 'Release'">WinExe</OutputType>
|
||||
<PublishSingleFile>true</PublishSingleFile>
|
||||
<!-- todo: enable this once the app is aot compliant! -->
|
||||
<PublishAot>false</PublishAot>
|
||||
<OutputType Condition="'$(Configuration)' == 'Release'">WinExe</OutputType>
|
||||
<PublishSingleFile>true</PublishSingleFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -16,4 +16,12 @@
|
||||
<ProjectReference Include="..\Il2CppInspector.Common\Il2CppInspector.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- todo: this needs to be adjusted for multiplatform support -->
|
||||
<Target Name="BuildTauriFrontend" BeforeTargets="BeforeBuild">
|
||||
<Exec Command="pnpm tauri build --no-bundle" WorkingDirectory="..\Il2CppInspector.Redux.GUI.UI" />
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="..\Il2CppInspector.Redux.GUI.UI\src-tauri\target\release\il2cppinspectorredux.exe" />
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -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