Repository navigation
Expand file tree
/
Copy pathinstaller-package.ps1
More file actions
76 lines (69 loc) · 4.07 KB
/
Copy pathinstaller-package.ps1
File metadata and controls
76 lines (69 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# 格式转换工具 安装程序构建脚本
# 流程:先复用 portable-package.ps1 生成免安装版,再用 Inno Setup 压成单文件安装包
# 输出:release\FormatConverter-setup-<版本>.exe(中文向导、可选安装目录、开始菜单/桌面快捷方式、可卸载)
# 依赖:Inno Setup 6 缺失时自动下载并静默安装到 %LOCALAPPDATA%\Programs\Inno Setup 6
# 注意: 本文件必须保持 UTF-8 带 BOM 编码(PS 5.1 会把无 BOM 的 UTF-8 当 ANSI 解析,中文注释变乱码)
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$OutputEncoding = [System.Text.Encoding]::UTF8
$ErrorActionPreference = "Stop"
$root = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $root
Write-Host "Installer build working directory: $root" -ForegroundColor Cyan
$AppVersion = "2.0.0"
# ---- [1/3] 生成免安装版(jpackage app-image + skiko 原生库)----
Write-Host ""
Write-Host "[1/3] Building portable distribution first..." -ForegroundColor Cyan
& powershell -NoProfile -ExecutionPolicy Bypass -File (Join-Path $root "portable-package.ps1")
if ($LASTEXITCODE -ne 0) { throw "portable package failed with exit $LASTEXITCODE" }
# ---- [2/3] 定位 Inno Setup 6(缺失时自动下载静默安装)----
Write-Host ""
Write-Host "[2/3] Locating Inno Setup 6 compiler..." -ForegroundColor Cyan
$isccCandidates = @(
(Join-Path $env:LOCALAPPDATA "Programs\Inno Setup 6\ISCC.exe"),
(Join-Path ${env:ProgramFiles(x86)} "Inno Setup 6\ISCC.exe"),
(Join-Path $env:ProgramFiles "Inno Setup 6\ISCC.exe")
)
$iscc = $isccCandidates | Where-Object { Test-Path $_ } | Select-Object -First 1
if (-not $iscc) {
Write-Host "[!] Inno Setup 6 not found. Downloading and installing silently..." -ForegroundColor Yellow
$innoSetupExe = Join-Path $env:TEMP "innosetup-installer.exe"
$urls = @(
"https://github.com/jrsoftware/issrc/releases/download/is-6_7_3/innosetup-6.7.3.exe",
"https://github.com/jrsoftware/issrc/releases/download/is-7_1_0/innosetup-7.1.0-x64.exe"
)
$downloaded = $false
foreach ($u in $urls) {
try {
Write-Host " Downloading: $u" -ForegroundColor Gray
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri $u -OutFile $innoSetupExe -UseBasicParsing -ErrorAction Stop
$fs = [IO.File]::OpenRead($innoSetupExe)
$mz = @($fs.ReadByte(), $fs.ReadByte()); $fs.Close()
if ($mz[0] -eq 0x4D -and $mz[1] -eq 0x5A -and (Get-Item $innoSetupExe).Length -gt 5MB) {
$downloaded = $true
break
}
Write-Host " Not a valid PE file, trying next mirror..." -ForegroundColor Yellow
} catch {
Write-Host " Download failed: $_" -ForegroundColor Yellow
}
}
if (-not $downloaded) { throw "Cannot download Inno Setup - install it manually from https://jrsoftware.org/isdl.php then retry." }
$innoDir = Join-Path $env:LOCALAPPDATA "Programs\Inno Setup 6"
$p = Start-Process -FilePath $innoSetupExe -ArgumentList "/VERYSILENT","/SUPPRESSMSGBOXES","/NORESTART","/CURRENTUSER","/DIR=`"$innoDir`"" -Wait -PassThru
if ($p.ExitCode -ne 0) { throw "Inno Setup silent install failed with exit $($p.ExitCode)" }
Remove-Item $innoSetupExe -Force -ErrorAction SilentlyContinue
$iscc = Join-Path $innoDir "ISCC.exe"
if (-not (Test-Path $iscc)) { throw "ISCC.exe not found after install: $iscc" }
}
Write-Host "[OK] ISCC: $iscc" -ForegroundColor Green
# ---- [3/3] 编译单文件安装包 ----
Write-Host ""
Write-Host "[3/3] Compiling installer (this compresses ~200MB, may take a while)..." -ForegroundColor Cyan
& $iscc "/DAppVersion=$AppVersion" (Join-Path $root "installer\FormatConverter.iss")
if ($LASTEXITCODE -ne 0) { throw "ISCC failed with exit $LASTEXITCODE" }
$outFile = Join-Path $root "release\FormatConverter-setup-$AppVersion.exe"
if (-not (Test-Path $outFile)) { throw "Installer output not found: $outFile" }
$sizeMb = [math]::Round((Get-Item $outFile).Length / 1MB, 1)
Write-Host ""
Write-Host "Installer ready: $outFile ($sizeMb MB)" -ForegroundColor Green