80 lines
2.4 KiB
PowerShell
80 lines
2.4 KiB
PowerShell
param(
|
|
[Parameter(Mandatory=$true)][string]$Version,
|
|
[Parameter(Mandatory=$true)][string]$BinPath,
|
|
[string]$WV2Fixed = "",
|
|
[string]$SevenZip = "C:\Program Files\7-Zip\7z.exe",
|
|
[string]$SfxModule = "C:\Program Files\7-Zip\7z.sfx",
|
|
[string]$OutputDir = "."
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
if ($Version -notin @("v3", "v4")) {
|
|
throw "Unsupported Version '$Version'. Use v3 or v4."
|
|
}
|
|
if (!(Test-Path $BinPath)) {
|
|
throw "Missing binary: $BinPath"
|
|
}
|
|
|
|
$Root = Resolve-Path (Join-Path $PSScriptRoot "..\..")
|
|
$OutRoot = Resolve-Path $OutputDir
|
|
$Work = Join-Path $PSScriptRoot "payload_$Version"
|
|
$Archive = Join-Path $PSScriptRoot "payload_$Version.7z"
|
|
$ZipOut = Join-Path $OutRoot "Avida-ED-$Version-Windows-x64.zip"
|
|
$ExeOut = Join-Path $OutRoot "Avida-ED-$Version-Windows-x64.exe"
|
|
|
|
Remove-Item $Work -Recurse -Force -ErrorAction SilentlyContinue
|
|
Remove-Item $Archive -Force -ErrorAction SilentlyContinue
|
|
New-Item -ItemType Directory -Force -Path $Work | Out-Null
|
|
|
|
Copy-Item $BinPath -Destination (Join-Path $Work "avidaed_onefile.exe")
|
|
|
|
$HasFixedRuntime = $false
|
|
if ($WV2Fixed -and (Test-Path $WV2Fixed)) {
|
|
Copy-Item $WV2Fixed -Destination (Join-Path $Work "WebView2Fixed") -Recurse
|
|
$HasFixedRuntime = $true
|
|
}
|
|
|
|
$runbat = @"
|
|
@echo off
|
|
setlocal
|
|
set HERE=%~dp0
|
|
if exist "%HERE%WebView2Fixed\msedgewebview2.exe" set WEBVIEW2_BROWSER_EXECUTABLE_FOLDER=%HERE%WebView2Fixed
|
|
start "" "%HERE%avidaed_onefile.exe"
|
|
"@
|
|
$runbat | Out-File -Encoding ASCII (Join-Path $Work "run.bat")
|
|
|
|
$readme = @"
|
|
Avida-ED $Version for Windows
|
|
|
|
Run run.bat to start Avida-ED.
|
|
|
|
This package includes a WebView2 Fixed Runtime: $HasFixedRuntime
|
|
If no fixed runtime is bundled, Microsoft Edge WebView2 Runtime must already be installed.
|
|
"@
|
|
$readme | Out-File -Encoding UTF8 (Join-Path $Work "README.txt")
|
|
|
|
if (!(Test-Path $SevenZip)) {
|
|
throw "Missing 7-Zip at $SevenZip"
|
|
}
|
|
|
|
& $SevenZip a -tzip $ZipOut "$Work\*" | Write-Host
|
|
Write-Host "Wrote $ZipOut"
|
|
|
|
if (Test-Path $SfxModule) {
|
|
& $SevenZip a -t7z $Archive "$Work\*" | Write-Host
|
|
$Cfg = Join-Path $PSScriptRoot "config.txt"
|
|
$OutStream = [System.IO.File]::Create($ExeOut)
|
|
try {
|
|
foreach ($Path in @($SfxModule, $Cfg, $Archive)) {
|
|
$Bytes = [System.IO.File]::ReadAllBytes($Path)
|
|
$OutStream.Write($Bytes, 0, $Bytes.Length)
|
|
}
|
|
} finally {
|
|
$OutStream.Close()
|
|
}
|
|
Write-Host "Wrote $ExeOut"
|
|
} else {
|
|
Write-Warning "SFX module not found at $SfxModule; skipped EXE creation."
|
|
}
|