@@ -46,226 +46,18 @@ jobs:
4646 Copy-Item assets\icon\icon.png -Destination installer-staging\launcher.ico
4747 }
4848
49- - name : Create installer script
49+ - name : Create installer script from template
5050 run : |
51- # Create the installer script by writing it directly to avoid nested here-string issues
52- $scriptContent = @"
53- # Woodlanders Launcher - Windows Installer with JRE Auto-Download
54- # Auto-generated installer script
51+ # Use the template file from the repo
52+ $scriptContent = Get-Content -Path .github\scripts\windows-installer-template.ps1 -Raw
5553
56- param(
57- [switch]$Silent = $false
58- )
59-
60- $ErrorActionPreference = "Stop"
61-
62- # Configuration
63- $APP_NAME = "Woodlanders Launcher"
64- $APP_VERSION = "${{ github.ref_name }}"
65- $JRE_VERSION = "21"
66- $INSTALL_DIR = "$env:LOCALAPPDATA\Woodlanders\Launcher"
67- $JRE_DIR = "$INSTALL_DIR\jre"
68- $DESKTOP_SHORTCUT = "$env:USERPROFILE\Desktop\Woodlanders Launcher.lnk"
69- $START_MENU_DIR = "$env:APPDATA\Microsoft\Windows\Start Menu\Programs\Woodlanders"
70-
71- # Liberica JDK Full (includes JavaFX) download URL
72- $JRE_DOWNLOAD_URL = "https://download.bell-sw.com/java/21.0.5+11/bellsoft-jdk21.0.5+11-windows-amd64-full.zip"
73-
74- function Write-Status {
75- param([string]$Message)
76- if (-not $Silent) {
77- Write-Host $Message -ForegroundColor Cyan
78- }
79- }
80-
81- function Write-Success {
82- param([string]$Message)
83- if (-not $Silent) {
84- Write-Host "✓ $Message" -ForegroundColor Green
85- }
86- }
87-
88- function Write-Error-Message {
89- param([string]$Message)
90- Write-Host "✗ $Message" -ForegroundColor Red
91- }
92-
93- function Test-JavaInstalled {
94- try {
95- $javaVersion = java -version 2>&1 | Select-String "version" | ForEach-Object { $_.ToString() }
96- if ($javaVersion -match "(\d+)\.(\d+)") {
97- $majorVersion = [int]$matches[1]
98- if ($majorVersion -ge 17) {
99- return $true
100- }
101- }
102- } catch {
103- return $false
104- }
105- return $false
106- }
107-
108- function Download-JRE {
109- Write-Status "Java 21+ not found. Downloading bundled JDK with JavaFX..."
110-
111- if (Test-Path "$JRE_DIR\bin\java.exe") {
112- Write-Success "JDK already installed"
113- return $true
114- }
115-
116- if (Test-Path $JRE_DIR) {
117- Remove-Item $JRE_DIR -Recurse -Force -ErrorAction SilentlyContinue
118- }
119-
120- New-Item -ItemType Directory -Force -Path $JRE_DIR | Out-Null
121-
122- $jreZip = "$env:TEMP\woodlanders-jre.zip"
123-
124- try {
125- Write-Status "Downloading JDK $JRE_VERSION with JavaFX (this may take a few minutes)..."
126-
127- $ProgressPreference = 'SilentlyContinue'
128- Invoke-WebRequest -Uri $JRE_DOWNLOAD_URL -OutFile $jreZip -UseBasicParsing
129- $ProgressPreference = 'Continue'
130-
131- Write-Status "Extracting JDK..."
132- $tempExtract = "$env:TEMP\woodlanders-jre-extract"
133- if (Test-Path $tempExtract) {
134- Remove-Item $tempExtract -Recurse -Force
135- }
136- Expand-Archive -Path $jreZip -DestinationPath $tempExtract -Force
137-
138- $extractedDir = Get-ChildItem -Path $tempExtract -Directory | Select-Object -First 1
139- Get-ChildItem -Path $extractedDir.FullName | Move-Item -Destination $JRE_DIR -Force
140-
141- Remove-Item $tempExtract -Recurse -Force
142- Remove-Item $jreZip -Force
143-
144- Write-Success "JDK with JavaFX downloaded and installed"
145- return $true
146- } catch {
147- Write-Error-Message "Failed to download JDK: $_"
148- return $false
149- }
150- }
151-
152- function Install-Application {
153- Write-Status "Installing $APP_NAME..."
154-
155- New-Item -ItemType Directory -Force -Path $INSTALL_DIR | Out-Null
156-
157- $scriptDir = if ($PSScriptRoot) { $PSScriptRoot } elseif ($MyInvocation.MyCommand.Path) { Split-Path -Parent $MyInvocation.MyCommand.Path } else { Get-Location | Select-Object -ExpandProperty Path }
158-
159- if (Test-Path "$scriptDir\woodlanders-launcher.jar") {
160- Copy-Item "$scriptDir\woodlanders-launcher.jar" -Destination $INSTALL_DIR -Force
161- Write-Success "Application files copied"
162- } else {
163- Write-Error-Message "Application JAR not found in: $scriptDir"
164- return $false
165- }
166-
167- if (Test-Path "$scriptDir\launcher-icon.png") {
168- Copy-Item "$scriptDir\launcher-icon.png" -Destination $INSTALL_DIR -Force
169- }
170-
171- return $true
172- }
173-
174- function Create-LauncherScript {
175- `$batContent = "@echo off``r``nsetlocal``r``nset APP_DIR=%~dp0``r``nset JAVAFX_CACHE=%USERPROFILE%\.cache\woodlanders-javafx``r``nif exist %APP_DIR%jre\bin\java.exe (set JAVA_CMD=%APP_DIR%jre\bin\java.exe) else (set JAVA_CMD=java)``r``n%JAVA_CMD% -Djavafx.cachedir=%JAVAFX_CACHE% -jar %APP_DIR%woodlanders-launcher.jar``r``nif %ERRORLEVEL% neq 0 (echo. & echo Application failed to start. & pause)``r``nendlocal"
176- `$batContent | Out-File -FilePath "`$INSTALL_DIR\launcher.bat" -Encoding ASCII -Force
177- Write-Success "Launcher script created"
178- }
179-
180- function Create-Shortcuts {
181- $WshShell = New-Object -ComObject WScript.Shell
182-
183- $Shortcut = $WshShell.CreateShortcut($DESKTOP_SHORTCUT)
184- $Shortcut.TargetPath = "$INSTALL_DIR\launcher.bat"
185- $Shortcut.WorkingDirectory = $INSTALL_DIR
186- $Shortcut.Description = "Woodlanders Game Launcher"
187- if (Test-Path "$INSTALL_DIR\launcher-icon.png") {
188- $Shortcut.IconLocation = "$INSTALL_DIR\launcher-icon.png"
189- }
190- $Shortcut.Save()
191- Write-Success "Desktop shortcut created"
192-
193- New-Item -ItemType Directory -Force -Path $START_MENU_DIR | Out-Null
194- $StartMenuShortcut = $WshShell.CreateShortcut("$START_MENU_DIR\Woodlanders Launcher.lnk")
195- $StartMenuShortcut.TargetPath = "$INSTALL_DIR\launcher.bat"
196- $StartMenuShortcut.WorkingDirectory = $INSTALL_DIR
197- $StartMenuShortcut.Description = "Woodlanders Game Launcher"
198- if (Test-Path "$INSTALL_DIR\launcher-icon.png") {
199- $StartMenuShortcut.IconLocation = "$INSTALL_DIR\launcher-icon.png"
200- }
201- $StartMenuShortcut.Save()
202- Write-Success "Start Menu shortcut created"
203- }
204-
205- function Show-CompletionMessage {
206- Write-Host ""
207- Write-Host "=========================================" -ForegroundColor Green
208- Write-Host " Installation Complete!" -ForegroundColor Green
209- Write-Host "=========================================" -ForegroundColor Green
210- Write-Host ""
211- Write-Host "Installed to: $INSTALL_DIR"
212- Write-Host ""
213- Write-Host "You can now launch $APP_NAME from:"
214- Write-Host " • Desktop shortcut"
215- Write-Host " • Start Menu > Woodlanders"
216- Write-Host ""
217-
218- if (-not $Silent) {
219- $launch = Read-Host "Launch now? (Y/n)"
220- if ($launch -ne 'n' -and $launch -ne 'N') {
221- Write-Host ""
222- Write-Host "Launching $APP_NAME..." -ForegroundColor Cyan
223- Start-Process -FilePath "$INSTALL_DIR\launcher.bat"
224- Start-Sleep -Seconds 2
225- Write-Host "Launcher started. You can close this window." -ForegroundColor Green
226- }
227- }
228- }
229-
230- # Main installation process
231- try {
232- Write-Host ""
233- Write-Host "=========================================" -ForegroundColor Cyan
234- Write-Host " $APP_NAME Installer" -ForegroundColor Cyan
235- Write-Host " Version: $APP_VERSION" -ForegroundColor Cyan
236- Write-Host "=========================================" -ForegroundColor Cyan
237- Write-Host ""
238-
239- if (Test-JavaInstalled) {
240- Write-Success "Java 17+ found on system"
241- } else {
242- if (-not (Download-JRE)) {
243- throw "Failed to download and install JRE"
244- }
245- }
246-
247- if (-not (Install-Application)) {
248- throw "Failed to install application"
249- }
250-
251- Create-LauncherScript
252- Create-Shortcuts
253- Show-CompletionMessage
254-
255- } catch {
256- Write-Host ""
257- Write-Error-Message "Installation failed: $_"
258- Write-Host ""
259- if (-not $Silent) {
260- Read-Host "Press Enter to exit"
261- }
262- exit 1
263- }
264- "@
54+ # Replace version placeholder
55+ $scriptContent = $scriptContent -replace '\$\{VERSION\}', '${{ github.ref_name }}'
26556
266- # Fix the scriptDir line for ps2exe compatibility
267- $scriptContent = $scriptContent -replace '\` $scriptDir = if \(\` $PSScriptRoot\) \{ \` $PSScriptRoot \} else \{ Split-Path -Parent \` $MyInvocation\.MyCommand\.Path \}', '` $scriptDir = if ($PSScriptRoot) { $PSScriptRoot } elseif ($MyInvocation.MyCommand.Path) { Split-Path -Parent $MyInvocation.MyCommand.Path } else { Get-Location | Select-Object -ExpandProperty Path }'
57+ # Fix scriptDir for ps2exe compatibility
58+ $scriptContent = $scriptContent -replace '\$scriptDir = if \(\$PSScriptRoot\) \{ \$PSScriptRoot \} else \{ Split-Path -Parent \$MyInvocation\.MyCommand\.Path \}', '$scriptDir = if ($PSScriptRoot) { $PSScriptRoot } elseif ($MyInvocation.MyCommand.Path) { Split-Path -Parent $MyInvocation.MyCommand.Path } else { Get-Location | Select-Object -ExpandProperty Path }'
26859
60+ # Save the processed script
26961 $scriptContent | Out-File -FilePath installer-staging\install.ps1 -Encoding UTF8
27062
27163 - name : Create README for installer
0 commit comments