forked from jbowensii/MoriaModCreator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_installer.ps1
More file actions
198 lines (169 loc) · 8.27 KB
/
build_installer.ps1
File metadata and controls
198 lines (169 loc) · 8.27 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
# Build Installer Script for Moria MOD Creator
# This script:
# 1. Cleans mymodfiles (removes subdirs without .ini files)
# 2. Creates zip files: Definitions.zip, mymodfiles.zip, NewObjects.zip, utilities.zip
# 3. Builds the installer with Inno Setup
# 4. Signs the installer
param(
[switch]$SkipSign,
[switch]$SkipBuild
)
$ErrorActionPreference = "Stop"
# Paths
$ProjectRoot = $PSScriptRoot
$AppDataDir = "$env:APPDATA\MoriaMODCreator"
$ReleaseDir = "$ProjectRoot\release"
$InstallerScript = "$ProjectRoot\installer\MoriaMODCreator.iss"
$SignTool = "$env:USERPROFILE\Tools\CodeSignTool\sign.bat"
$InnoSetup = "$env:LOCALAPPDATA\Programs\Inno Setup 6\ISCC.exe"
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " Moria MOD Creator - Build Installer " -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
# Step 1: Clean mymodfiles - remove subdirs without .ini files
Write-Host "[1/7] Cleaning mymodfiles directory..." -ForegroundColor Yellow
$mymodfilesDir = "$AppDataDir\mymodfiles"
if (Test-Path $mymodfilesDir) {
# Get all subdirectories recursively (deepest first for proper cleanup)
$subdirs = Get-ChildItem $mymodfilesDir -Directory -Recurse | Sort-Object { $_.FullName.Length } -Descending
$removed = 0
$kept = 0
foreach ($dir in $subdirs) {
# Check if this directory or any subdirectory contains .ini files
$hasIniFiles = Get-ChildItem $dir.FullName -Filter "*.ini" -Recurse -File -ErrorAction SilentlyContinue
if (-not $hasIniFiles) {
# No .ini files - remove the directory
Remove-Item $dir.FullName -Recurse -Force -ErrorAction SilentlyContinue
$removed++
} else {
# Has .ini files - remove non-.ini files but keep the directory structure
Get-ChildItem $dir.FullName -File -Recurse | Where-Object { $_.Extension -ne ".ini" } | Remove-Item -Force -ErrorAction SilentlyContinue
$kept++
}
}
Write-Host " Removed $removed empty subdirectories, kept $kept with .ini files" -ForegroundColor Green
} else {
Write-Host " mymodfiles directory not found, skipping cleanup" -ForegroundColor DarkYellow
}
# Step 2: Create Definitions.zip
Write-Host "[2/7] Creating Definitions.zip..." -ForegroundColor Yellow
$definitionsDir = "$AppDataDir\Definitions"
$definitionsZip = "$ReleaseDir\Definitions.zip"
if (Test-Path $definitionsDir) {
if (Test-Path $definitionsZip) { Remove-Item $definitionsZip -Force }
Compress-Archive -Path "$definitionsDir\*" -DestinationPath $definitionsZip -CompressionLevel Optimal
$zipSize = [math]::Round((Get-Item $definitionsZip).Length / 1KB)
Write-Host " Created Definitions.zip ($zipSize KB)" -ForegroundColor Green
} else {
Write-Host " Definitions directory not found!" -ForegroundColor Red
exit 1
}
# Step 3: Create mymodfiles.zip
Write-Host "[3/7] Creating mymodfiles.zip..." -ForegroundColor Yellow
$mymodfilesZip = "$ReleaseDir\mymodfiles.zip"
if (Test-Path $mymodfilesDir) {
if (Test-Path $mymodfilesZip) { Remove-Item $mymodfilesZip -Force }
Compress-Archive -Path "$mymodfilesDir\*" -DestinationPath $mymodfilesZip -CompressionLevel Optimal
$zipSize = [math]::Round((Get-Item $mymodfilesZip).Length / 1KB)
Write-Host " Created mymodfiles.zip ($zipSize KB)" -ForegroundColor Green
} else {
Write-Host " mymodfiles directory not found!" -ForegroundColor Red
exit 1
}
# Step 4: Create NewObjects.zip
Write-Host "[4/7] Creating NewObjects.zip..." -ForegroundColor Yellow
$newObjectsDir = "$AppDataDir\New Objects"
$newObjectsZip = "$ReleaseDir\NewObjects.zip"
if (Test-Path $newObjectsDir) {
if (Test-Path $newObjectsZip) { Remove-Item $newObjectsZip -Force }
Compress-Archive -Path "$newObjectsDir\*" -DestinationPath $newObjectsZip -CompressionLevel Optimal
$zipSize = [math]::Round((Get-Item $newObjectsZip).Length / 1KB)
Write-Host " Created NewObjects.zip ($zipSize KB)" -ForegroundColor Green
} else {
Write-Host " New Objects directory not found!" -ForegroundColor Red
exit 1
}
# Step 5: Create utilities.zip
Write-Host "[5/8] Creating utilities.zip..." -ForegroundColor Yellow
$utilitiesDir = "$AppDataDir\utilities"
$utilitiesZip = "$ReleaseDir\utilities.zip"
if (Test-Path $utilitiesDir) {
if (Test-Path $utilitiesZip) { Remove-Item $utilitiesZip -Force }
Compress-Archive -Path "$utilitiesDir\*" -DestinationPath $utilitiesZip -CompressionLevel Optimal
$zipSize = [math]::Round((Get-Item $utilitiesZip).Length / 1MB)
Write-Host " Created utilities.zip ($zipSize MB)" -ForegroundColor Green
} else {
Write-Host " utilities directory not found!" -ForegroundColor Red
exit 1
}
# Step 6: Create Constructions.zip (optional - only if directory exists and has content)
Write-Host "[6/8] Creating Constructions.zip..." -ForegroundColor Yellow
$constructionsDir = "$AppDataDir\Constructions"
$constructionsZip = "$ReleaseDir\Constructions.zip"
if (Test-Path $constructionsDir) {
$constructionsContent = Get-ChildItem $constructionsDir -Recurse -File
if ($constructionsContent) {
if (Test-Path $constructionsZip) { Remove-Item $constructionsZip -Force }
Compress-Archive -Path "$constructionsDir\*" -DestinationPath $constructionsZip -CompressionLevel Optimal
$zipSize = [math]::Round((Get-Item $constructionsZip).Length / 1KB)
Write-Host " Created Constructions.zip ($zipSize KB)" -ForegroundColor Green
} else {
Write-Host " Constructions directory is empty, skipping zip creation" -ForegroundColor DarkYellow
if (Test-Path $constructionsZip) { Remove-Item $constructionsZip -Force }
}
} else {
Write-Host " Constructions directory not found, skipping" -ForegroundColor DarkYellow
if (Test-Path $constructionsZip) { Remove-Item $constructionsZip -Force }
}
# Step 7: Build installer with Inno Setup
if (-not $SkipBuild) {
Write-Host "[7/8] Building installer with Inno Setup..." -ForegroundColor Yellow
if (-not (Test-Path $InnoSetup)) {
Write-Host " Inno Setup not found at: $InnoSetup" -ForegroundColor Red
exit 1
}
& $InnoSetup $InstallerScript
if ($LASTEXITCODE -ne 0) {
Write-Host " Installer build failed!" -ForegroundColor Red
exit 1
}
# Find the generated installer
$installer = Get-ChildItem $ReleaseDir -Filter "MoriaMODCreator_Setup_*.exe" | Sort-Object LastWriteTime -Descending | Select-Object -First 1
Write-Host " Built: $($installer.Name)" -ForegroundColor Green
} else {
Write-Host "[7/8] Skipping installer build (--SkipBuild)" -ForegroundColor DarkYellow
$installer = Get-ChildItem $ReleaseDir -Filter "MoriaMODCreator_Setup_*.exe" | Sort-Object LastWriteTime -Descending | Select-Object -First 1
}
# Step 8: Sign the installer
if (-not $SkipSign -and $installer) {
Write-Host "[8/8] Signing installer..." -ForegroundColor Yellow
if (-not (Test-Path $SignTool)) {
Write-Host " Sign tool not found at: $SignTool" -ForegroundColor Red
Write-Host " Skipping signing" -ForegroundColor DarkYellow
} else {
# Run sign tool from its directory
Push-Location (Split-Path $SignTool)
& $SignTool $installer.FullName
Pop-Location
# Verify signature
$sig = Get-AuthenticodeSignature $installer.FullName
if ($sig.Status -eq "Valid") {
Write-Host " Signed successfully by: $(($sig.SignerCertificate.Subject -split ',')[0] -replace 'CN=')" -ForegroundColor Green
} else {
Write-Host " Signing failed or not verified" -ForegroundColor Red
}
}
} else {
Write-Host "[8/8] Skipping signing (--SkipSign or no installer)" -ForegroundColor DarkYellow
}
# Summary
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " Build Complete! " -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Output files in: $ReleaseDir" -ForegroundColor White
Get-ChildItem $ReleaseDir -File | ForEach-Object {
$size = if ($_.Length -gt 1MB) { "{0:N2} MB" -f ($_.Length / 1MB) } else { "{0:N0} KB" -f ($_.Length / 1KB) }
Write-Host " - $($_.Name) ($size)"
}