embed ui executable directly into c# assembly

This commit is contained in:
LukeFZ
2025-04-20 16:57:32 +02:00
parent 1163ed597c
commit 74ed53b201
3 changed files with 46 additions and 14 deletions

View File

@@ -52,19 +52,15 @@ jobs:
- name: Restore NuGet packages
run: dotnet restore -r win-x64 ./Il2CppInspector.Redux.GUI
- name: Build GUI C# component
# note: we embed the exe directly into the c# component, and it it is built alongside it
# in another msbuild target.
- name: Build GUI
run: dotnet publish ./Il2CppInspector.Redux.GUI/Il2CppInspector.Redux.GUI.csproj -r win-x64 --no-self-contained
- name: Build GUI TS component
run: pnpm tauri build --no-bundle
working-directory: ./Il2CppInspector.Redux.GUI.UI
- name: Copy components to output directory
run: |
mkdir ./build_output
mkdir ./build_output/resources
cp ./Il2CppInspector.Redux.GUI/bin/Release/net9.0/win-x64/publish/Il2CppInspector.Redux.GUI.exe ./build_output/
cp ./Il2CppInspector.Redux.GUI.UI/src-tauri/target/release/il2cppinspectorredux.exe ./build_output/resources/
- name: Upload GUI Artifact
uses: actions/upload-artifact@v4

View File

@@ -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>

View File

@@ -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);
}
}