Update compile.yml #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build SimpleImager EXE | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| runs-on: windows-latest | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v4 | |
| - name: Compile Native C# Wrapper to EXE | |
| shell: bash | |
| run: | | |
| # 1. Convert batch file to base64 | |
| BAT_B64=$(base64 D-Acquisition.bat | tr -d '\n') | |
| # 2. Write C# safely with no variable evaluation conflicts | |
| cat << 'EOF' > Wrapper.cs | |
| using System; | |
| using System.Diagnostics; | |
| using System.IO; | |
| using System.Text; | |
| class Program { | |
| static void Main(string[] args) { | |
| string currentDir = AppDomain.CurrentDomain.BaseDirectory; | |
| string tempPath = Path.Combine(Path.GetTempPath(), "SimpleImager_" + Guid.NewGuid().ToString().Substring(0,8) + ".bat"); | |
| try { | |
| File.WriteAllText(tempPath, Encoding.UTF8.GetString(Convert.FromBase64String("INSERT_BASE64_HERE"))); | |
| ProcessStartInfo psi = new ProcessStartInfo("cmd.exe"); | |
| string argsString = ""; | |
| if (args.Length > 0) { | |
| argsString = string.Join(" ", args); | |
| } | |
| // This forces the script to run in the folder containing ftkimager.exe | |
| psi.Arguments = "/c \"cd /d \"" + currentDir + "\" & \"" + tempPath + "\" " + argsString + "\""; | |
| psi.WorkingDirectory = currentDir; | |
| psi.UseShellExecute = true; | |
| psi.Verb = "runas"; | |
| Process p = Process.Start(psi); | |
| p.WaitForExit(); | |
| } | |
| catch (Exception ex) { | |
| Console.WriteLine("Execution Error: " + ex.Message); | |
| } | |
| finally { | |
| if (File.Exists(tempPath)) { | |
| File.Delete(tempPath); | |
| } | |
| } | |
| } | |
| } | |
| EOF | |
| # 3. Insert the batch code into the C# wrapper | |
| sed -i "s|INSERT_BASE64_HERE|$BAT_B64|g" Wrapper.cs | |
| # 4. Find the built-in C# compiler and build the EXE | |
| CSC_PATH=$(find /c/Windows/Microsoft.NET/Framework64 -name "csc.exe" | sort -r | head -n 1) | |
| "$CSC_PATH" -nologo -out:SimpleImager.exe -target:exe Wrapper.cs | |
| - name: Upload Ready-to-Sell Package | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: SimpleImager-Commercial | |
| path: SimpleImager.exe |