-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
153 lines (135 loc) · 5.66 KB
/
Copy pathbuild.ps1
File metadata and controls
153 lines (135 loc) · 5.66 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
param(
[string]$Root = "",
[string]$Version = ""
)
$ErrorActionPreference = "Stop"
if (-not $Root) {
$Root = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
}
$config = & (Join-Path $Root "config.ps1")
if (-not $Version) { $Version = [string]$config.Version }
$payloadDir = Join-Path $Root "examples\win-unpacked"
$payloadExe = Join-Path $payloadDir ([string]$config.AppExeName)
if (-not (Test-Path $payloadExe)) {
throw @"
Missing payload exe: $payloadExe
Drop your Electron/portable win-unpacked build into examples\win-unpacked\
so that '$($config.AppExeName)' exists, then re-run build.
"@
}
$icon = Join-Path $Root "assets\app.ico"
if (-not (Test-Path $icon)) {
throw "Missing $icon — place a neutral .ico there (or generate one with scripts\make-icon.ps1)."
}
# Write Inno include with product identity
$inc = Join-Path $Root "installer\product.inc"
$protocol = [string]$config.ProtocolScheme
$incLines = @(
"; Auto-generated by scripts/build.ps1 — do not edit by hand.",
"#define MyAppName `"$($config.AppName)`"",
"#define MyAppPublisher `"$($config.AppPublisher)`"",
"#define MyAppURL `"$($config.AppUrl)`"",
"#define MyAppExeName `"$($config.AppExeName)`"",
"#define MyAppId `"$($config.AppId)`"",
"#define MyAppGuid `"$($config.AppGuid)`"",
"#define MyRequiredMB `"$($config.RequiredMB)`"",
"#define MyProtocol `"$protocol`""
)
$utf8Bom = New-Object System.Text.UTF8Encoding $true
[IO.File]::WriteAllText($inc, ($incLines -join "`r`n") + "`r`n", $utf8Bom)
Write-Host "Generating installer UI..."
& "$PSScriptRoot\generate-ui.ps1" -Root $Root
$toolsDir = Join-Path $env:LOCALAPPDATA "windows-setup-shell-tools\InnoSetup"
$candidates = @(
(Join-Path $toolsDir "ISCC.exe"),
"${env:ProgramFiles(x86)}\Inno Setup 7\ISCC.exe",
"$env:ProgramFiles\Inno Setup 7\ISCC.exe",
"${env:ProgramFiles(x86)}\Inno Setup 6\ISCC.exe",
"$env:ProgramFiles\Inno Setup 6\ISCC.exe"
)
$cmd = Get-Command iscc -ErrorAction SilentlyContinue
if ($cmd) { $candidates = @($cmd.Source) + $candidates }
function Get-IsccVersion([string]$Path) {
try {
$info = [Diagnostics.FileVersionInfo]::GetVersionInfo($Path)
$raw = $info.ProductVersion
if (-not $raw) { $raw = $info.FileVersion }
if ($raw -match '^(\d+)\.(\d+)') { return [version]"$($Matches[1]).$($Matches[2])" }
} catch {}
return $null
}
$iscc = $null
foreach ($path in $candidates) {
if ($path -and (Test-Path $path)) {
$ver = Get-IsccVersion $path
if (-not $ver -or $ver -eq [version]"0.0" -or $ver -ge [version]"6.6") {
$iscc = $path
break
}
}
}
if (-not $iscc) {
Write-Host "Inno Setup 6.6+ not found. Downloading compiler..."
New-Item -ItemType Directory -Path $toolsDir -Force | Out-Null
$installer = Join-Path $env:TEMP "innosetup-setup.exe"
$urls = @(
"https://github.com/jrsoftware/issrc/releases/download/is-7_1_0/innosetup-7.1.0-x64.exe",
"https://github.com/jrsoftware/issrc/releases/download/is-6_7_3/innosetup-6.7.3.exe"
)
$downloaded = $false
foreach ($url in $urls) {
try {
if (Test-Path $installer) { Remove-Item $installer -Force }
& curl.exe -L --fail --silent --show-error -o $installer $url
if ($LASTEXITCODE -eq 0 -and (Test-Path $installer) -and ((Get-Item $installer).Length -gt 1MB)) {
$downloaded = $true
break
}
} catch {}
}
if (-not $downloaded) {
throw "Could not download Inno Setup. Install from https://jrsoftware.org/isinfo.php"
}
$setupArgs = @("/VERYSILENT","/SUPPRESSMSGBOXES","/NORESTART","/SP-","/CURRENTUSER","/NOICONS","/DIR=`"$toolsDir`"")
$proc = Start-Process -FilePath $installer -ArgumentList $setupArgs -Wait -PassThru
if ($proc.ExitCode -ne 0 -and -not (Test-Path (Join-Path $toolsDir "ISCC.exe"))) {
throw "Inno Setup installer exited $($proc.ExitCode)"
}
$iscc = Join-Path $toolsDir "ISCC.exe"
}
$iss = Join-Path $Root "installer\setup.iss"
[IO.File]::WriteAllText($iss, [IO.File]::ReadAllText($iss), $utf8Bom)
$releaseDir = Join-Path $Root "release"
New-Item -ItemType Directory -Path $releaseDir -Force | Out-Null
$outName = [string]$config.OutputName
Write-Host "ISCC: $iscc"
Write-Host "Version: $Version"
Push-Location (Join-Path $Root "installer")
try {
& $iscc "/DMyAppVersion=$Version" "/DMyOutputName=$outName" $iss
if ($LASTEXITCODE -ne 0) { throw "ISCC failed with exit $LASTEXITCODE" }
} finally {
Pop-Location
}
$setup = Join-Path $releaseDir "$outName.exe"
if (-not (Test-Path $setup)) { throw "ISCC did not write $setup" }
if ($env:CSC_LINK -and (Test-Path $env:CSC_LINK)) {
$kits = Get-ChildItem "${env:ProgramFiles(x86)}\Windows Kits\10\bin" -Recurse -Filter signtool.exe -ErrorAction SilentlyContinue |
Where-Object { $_.FullName -match '\\x64\\signtool.exe$' } |
Sort-Object FullName -Descending |
Select-Object -First 1
$signtool = if ($kits) { $kits.FullName } else { $null }
if ($signtool) {
Write-Host "Signing $setup"
$signArgs = @("sign","/f",$env:CSC_LINK,"/fd","SHA256","/td","SHA256","/tr","http://timestamp.digicert.com",$setup)
if ($env:CSC_KEY_PASSWORD) {
$signArgs = @("sign","/f",$env:CSC_LINK,"/p",$env:CSC_KEY_PASSWORD,"/fd","SHA256","/td","SHA256","/tr","http://timestamp.digicert.com",$setup)
}
& $signtool @signArgs
if ($LASTEXITCODE -ne 0) { throw "signtool failed" }
} else {
Write-Warning "CSC_LINK set but signtool.exe not found; left unsigned."
}
}
Write-Host "Installer: $setup"
Get-Item $setup | Select-Object Name, Length, LastWriteTime | Format-List