From 74ed53b20197e3eba21f911c0a6d8166813c1bce Mon Sep 17 00:00:00 2001 From: LukeFZ <17146677+LukeFZ@users.noreply.github.com> Date: Sun, 20 Apr 2025 16:57:32 +0200 Subject: [PATCH] embed ui executable directly into c# assembly --- .github/workflows/build.yml | 10 ++---- .../Il2CppInspector.Redux.GUI.csproj | 16 ++++++--- Il2CppInspector.Redux.GUI/UiProcessService.cs | 34 +++++++++++++++++-- 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d14a822..5c6d8f9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/Il2CppInspector.Redux.GUI/Il2CppInspector.Redux.GUI.csproj b/Il2CppInspector.Redux.GUI/Il2CppInspector.Redux.GUI.csproj index f0c029b..103dc58 100644 --- a/Il2CppInspector.Redux.GUI/Il2CppInspector.Redux.GUI.csproj +++ b/Il2CppInspector.Redux.GUI/Il2CppInspector.Redux.GUI.csproj @@ -5,10 +5,10 @@ enable enable true - false - - WinExe - true + + false + WinExe + true @@ -16,4 +16,12 @@ + + + + + + + + diff --git a/Il2CppInspector.Redux.GUI/UiProcessService.cs b/Il2CppInspector.Redux.GUI/UiProcessService.cs index ce8169f..aa7210f 100644 --- a/Il2CppInspector.Redux.GUI/UiProcessService.cs +++ b/Il2CppInspector.Redux.GUI/UiProcessService.cs @@ -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); } } \ No newline at end of file