-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-msi-full.ps1
More file actions
219 lines (191 loc) · 7.17 KB
/
build-msi-full.ps1
File metadata and controls
219 lines (191 loc) · 7.17 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# Full PowerShell script to build MultiMC MSI installer
param (
[string]$DownloadUrl = "https://files.multimc.org/downloads/mmc-develop-win32.zip",
[string]$OutputDir = (Join-Path $PSScriptRoot "build"),
[string]$TempDir = (Join-Path $PSScriptRoot "temp"),
[string]$Version = "1.0.0",
[switch]$InstallWix = $false
)
function Install-WixToolset {
Write-Host "Installing WiX Toolset..."
$wixUrl = "https://github.com/wixtoolset/wix3/releases/download/wix3112rtm/wix311.exe"
$wixInstaller = Join-Path $TempDir "wix311.exe"
# Download WiX installer
Invoke-WebRequest -Uri $wixUrl -OutFile $wixInstaller
# Install WiX silently
Start-Process -FilePath $wixInstaller -ArgumentList "/install", "/quiet" -Wait
# Add WiX to PATH for this session
$env:PATH += ";C:\Program Files (x86)\WiX Toolset v3.11\bin"
}
function Test-WixToolset {
try {
$null = Get-Command candle.exe -ErrorAction Stop
$null = Get-Command light.exe -ErrorAction Stop
return $true
} catch {
return $false
}
}
# Create necessary directories
New-Item -ItemType Directory -Force -Path $OutputDir | Out-Null
New-Item -ItemType Directory -Force -Path $TempDir | Out-Null
# Check if WiX is installed
if (-not (Test-WixToolset)) {
if ($InstallWix) {
Install-WixToolset
} else {
Write-Error "WiX Toolset is not installed. Run this script with -InstallWix to install it automatically."
exit 1
}
}
# Download MultiMC
Write-Host "Downloading MultiMC from $DownloadUrl..."
$zipPath = Join-Path $TempDir "multimc.zip"
Invoke-WebRequest -Uri $DownloadUrl -OutFile $zipPath
# Extract the ZIP file
Write-Host "Extracting MultiMC..."
Expand-Archive -Path $zipPath -DestinationPath $TempDir -Force
# Find the MultiMC directory (it might be in a subdirectory)
$multiMCDir = Get-ChildItem -Path $TempDir -Directory | Where-Object { Test-Path (Join-Path $_.FullName "MultiMC.exe") } | Select-Object -First 1
if (-not $multiMCDir) {
# If we can't find a directory with MultiMC.exe, check if it's directly in the temp dir
if (Test-Path (Join-Path $TempDir "MultiMC.exe")) {
$multiMCDir = Get-Item $TempDir
} else {
Write-Error "Could not find MultiMC.exe in the extracted files."
exit 1
}
}
# Create license file from MultiMC's GitHub repository
$licensePath = Join-Path $TempDir "LICENSE.rtf"
$multiMCLicenseUrl = "https://raw.githubusercontent.com/MultiMC/Launcher/refs/heads/develop/COPYING.md"
$multiMCLicenseTempPath = Join-Path $TempDir "COPYING.md"
Write-Host "Downloading MultiMC license from GitHub..."
try {
Invoke-WebRequest -Uri $multiMCLicenseUrl -OutFile $multiMCLicenseTempPath -ErrorAction Stop
$licenseText = Get-Content -Path $multiMCLicenseTempPath -Raw
$licenseRtf = @"
{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1033{\fonttbl{\f0\fnil\fcharset0 Calibri;}}
{\*\generator Riched20 10.0.19041}\viewkind4\uc1
\pard\sa200\sl276\slmult1\f0\fs22\lang9 $($licenseText -replace "\r\n|\n", "\par ")\par
}
"@
Set-Content -Path $licensePath -Value $licenseRtf
} catch {
Write-Error "Failed to download MultiMC license from GitHub: $_"
exit 1
}
# Create placeholder images for the installer
Write-Host "Creating UI bitmaps for the installer..."
$bannerPath = Join-Path $TempDir "banner.bmp"
$dialogPath = Join-Path $TempDir "dialog.bmp"
# Create empty bitmap files with System.Drawing if they don't exist
Add-Type -AssemblyName System.Drawing
if (-not (Test-Path $bannerPath)) {
$banner = New-Object System.Drawing.Bitmap 493, 58
$graphics = [System.Drawing.Graphics]::FromImage($banner)
$graphics.FillRectangle([System.Drawing.Brushes]::White, 0, 0, 493, 58)
$banner.Save($bannerPath)
$banner.Dispose()
$graphics.Dispose()
}
if (-not (Test-Path $dialogPath)) {
$dialog = New-Object System.Drawing.Bitmap 493, 312
$graphics = [System.Drawing.Graphics]::FromImage($dialog)
$graphics.FillRectangle([System.Drawing.Brushes]::White, 0, 0, 493, 312)
$dialog.Save($dialogPath)
$dialog.Dispose()
$graphics.Dispose()
}
# Copy the main WiX file to the temp directory
Copy-Item -Path ".\MultiMC.wxs" -Destination $TempDir
# Update version in the WiX file
$wxsPath = Join-Path $TempDir "MultiMC.wxs"
(Get-Content $wxsPath) -replace 'Version="1.0.0"', "Version=`"$Version`"" | Set-Content $wxsPath
# First, create a working directory for processing files
$workingDir = Join-Path $TempDir "MultiMCFiles"
New-Item -ItemType Directory -Force -Path $workingDir | Out-Null
# Copy all files from the MultiMC directory to the working directory
Copy-Item -Path "$($multiMCDir.FullName)\*" -Destination $workingDir -Recurse -Force
# Change to the temp directory for WiX commands
Push-Location $TempDir
try {
# Debug - show what's in the directory
Write-Host "Contents of MultiMC directory:"
Get-ChildItem -Path $multiMCDir.FullName -Recurse | Select-Object -First 20 | ForEach-Object {
Write-Host $_.FullName
}
# Generate the file list using heat
Write-Host "Generating file list with heat..."
$heatArgs = @(
"dir"
"""$workingDir"""
"-cg"
"MultiMCFiles"
"-dr"
"INSTALLFOLDER"
"-gg"
"-srd"
"-ke"
"-sfrag"
"-var"
"var.SourceDir"
"-out"
"filelist.wxs"
)
$heatProc = Start-Process -FilePath "heat.exe" -ArgumentList $heatArgs -NoNewWindow -Wait -PassThru
if ($heatProc.ExitCode -ne 0) {
Write-Error "Heat exited with code $($heatProc.ExitCode)"
}
# Print the generated filelist.wxs for debugging
Write-Host "Generated filelist.wxs first 20 lines:"
Get-Content -Path "filelist.wxs" -TotalCount 20
# Compile the WiX source files
Write-Host "Compiling WiX source files with candle..."
$candleArgs = @(
"MultiMC.wxs"
"filelist.wxs"
"-dSourceDir=""$workingDir"""
"-ext"
"WixUtilExtension"
)
$candleProc = Start-Process -FilePath "candle.exe" -ArgumentList $candleArgs -NoNewWindow -Wait -PassThru
if ($candleProc.ExitCode -ne 0) {
Write-Error "Candle exited with code $($candleProc.ExitCode)"
}
# Link the compiled objects into an MSI
Write-Host "Linking with light to create MSI..."
$msiPath = Join-Path $OutputDir "MultiMC-$Version.msi"
$lightArgs = @(
"-ext"
"WixUIExtension"
"-ext"
"WixUtilExtension"
"MultiMC.wixobj"
"filelist.wixobj"
"-out"
"""$msiPath"""
"-sval"
"-b"
"""$TempDir"""
)
$lightProc = Start-Process -FilePath "light.exe" -ArgumentList $lightArgs -NoNewWindow -Wait -PassThru
if ($lightProc.ExitCode -ne 0) {
Write-Error "Light exited with code $($lightProc.ExitCode)"
}
if (Test-Path $msiPath) {
Write-Host "MSI created successfully: $msiPath"
} else {
Write-Error "Failed to create MSI."
exit 1
}
} finally {
# Return to the original directory
Pop-Location
}
# Clean up temp files if successful
if (Test-Path $msiPath) {
Write-Host "Cleaning up temporary files..."
Remove-Item -Path $TempDir -Recurse -Force
}
Write-Host "Build completed successfully."