-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
385 lines (315 loc) · 11.8 KB
/
install.ps1
File metadata and controls
385 lines (315 loc) · 11.8 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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
# HEAL - Hello ElementAstro Launcher
# Windows PowerShell installation script
# Copyright (C) 2024 ElementAstro
param(
[switch]$Force,
[string]$InstallPath = "$env:LOCALAPPDATA\HEAL",
[switch]$NoDesktopShortcut,
[switch]$NoStartMenu,
[switch]$Verbose
)
# Set error action preference
$ErrorActionPreference = "Stop"
# Configuration
$HealVersion = "1.0.0"
$StartMenuPath = "$env:APPDATA\Microsoft\Windows\Start Menu\Programs"
$DesktopPath = [Environment]::GetFolderPath("Desktop")
# Colors for output (if supported)
$Colors = @{
Red = "Red"
Green = "Green"
Yellow = "Yellow"
Blue = "Blue"
White = "White"
}
# Logging functions
function Write-Status {
param([string]$Message)
Write-Host "[INFO] $Message" -ForegroundColor $Colors.Blue
}
function Write-Success {
param([string]$Message)
Write-Host "[SUCCESS] $Message" -ForegroundColor $Colors.Green
}
function Write-Warning {
param([string]$Message)
Write-Host "[WARNING] $Message" -ForegroundColor $Colors.Yellow
}
function Write-Error {
param([string]$Message)
Write-Host "[ERROR] $Message" -ForegroundColor $Colors.Red
}
# Check if running as administrator
function Test-Administrator {
$currentUser = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($currentUser)
return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
# Check system requirements
function Test-Requirements {
Write-Status "Checking system requirements..."
# Check Windows version
$osVersion = [System.Environment]::OSVersion.Version
if ($osVersion.Major -lt 10) {
Write-Warning "Windows 10 or later is recommended. Current version: $($osVersion.ToString())"
} else {
Write-Success "Windows version: $($osVersion.ToString()) (compatible)"
}
# Check PowerShell version
$psVersion = $PSVersionTable.PSVersion
if ($psVersion.Major -lt 5) {
Write-Error "PowerShell 5.0 or later is required. Current version: $($psVersion.ToString())"
exit 1
} else {
Write-Success "PowerShell version: $($psVersion.ToString()) (compatible)"
}
# Check for Python (optional)
try {
$pythonVersion = python --version 2>$null
if ($pythonVersion) {
Write-Success "Python detected: $pythonVersion"
}
} catch {
Write-Warning "Python not found. Some features may require Python 3.11+"
}
# Check available disk space
$drive = (Get-Item $InstallPath).PSDrive.Name
$freeSpace = (Get-WmiObject -Class Win32_LogicalDisk -Filter "DeviceID='${drive}:'").FreeSpace
$requiredSpace = 500MB # Estimated requirement
if ($freeSpace -lt $requiredSpace) {
Write-Error "Insufficient disk space. Required: $($requiredSpace/1MB)MB, Available: $($freeSpace/1MB)MB"
exit 1
}
}
# Create installation directories
function New-InstallDirectories {
Write-Status "Creating installation directories..."
try {
if (Test-Path $InstallPath) {
if ($Force) {
Write-Warning "Removing existing installation at $InstallPath"
Remove-Item $InstallPath -Recurse -Force
} else {
Write-Error "Installation directory already exists: $InstallPath"
Write-Status "Use -Force to overwrite existing installation"
exit 1
}
}
New-Item -ItemType Directory -Path $InstallPath -Force | Out-Null
Write-Success "Installation directory created: $InstallPath"
} catch {
Write-Error "Failed to create installation directory: $($_.Exception.Message)"
exit 1
}
}
# Install HEAL application
function Install-Heal {
Write-Status "Installing HEAL application..."
try {
# Check if we're in the source directory
if (Test-Path "main.py" -and Test-Path "src\heal") {
Write-Status "Installing from source directory..."
# Copy application files
Copy-Item -Path "." -Destination $InstallPath -Recurse -Force
# Install Python dependencies if requirements.txt exists
if (Test-Path "requirements.txt") {
Write-Status "Installing Python dependencies..."
try {
python -m pip install --user -r requirements.txt
Write-Success "Python dependencies installed"
} catch {
Write-Warning "Failed to install Python dependencies: $($_.Exception.Message)"
}
}
# Build the application if build script exists
if (Test-Path "scripts\build.py") {
Write-Status "Building HEAL application..."
Set-Location $InstallPath
try {
python scripts\build.py --no-clean
Write-Success "HEAL application built successfully"
} catch {
Write-Warning "Build failed: $($_.Exception.Message)"
}
}
} elseif (Test-Path "HEAL.exe" -or Test-Path "HEAL") {
Write-Status "Installing from pre-built package..."
# Copy pre-built files
Copy-Item -Path "." -Destination $InstallPath -Recurse -Force
} else {
Write-Error "HEAL application files not found in current directory"
Write-Status "Please run this script from the HEAL source or distribution directory"
exit 1
}
Write-Success "HEAL application installed successfully"
} catch {
Write-Error "Installation failed: $($_.Exception.Message)"
exit 1
}
}
# Create launcher script
function New-Launcher {
Write-Status "Creating launcher script..."
try {
$launcherScript = @"
@echo off
cd /d "$InstallPath"
REM Try to run the built executable first
if exist "dist\HEAL\HEAL.exe" (
start "" "dist\HEAL\HEAL.exe" %*
) else if exist "HEAL.exe" (
start "" "HEAL.exe" %*
) else if exist "main.py" (
python main.py %*
) else (
echo Error: HEAL executable not found
pause
exit /b 1
)
"@
$launcherPath = "$InstallPath\heal.bat"
$launcherScript | Out-File -FilePath $launcherPath -Encoding ASCII
Write-Success "Launcher script created: $launcherPath"
} catch {
Write-Error "Failed to create launcher script: $($_.Exception.Message)"
}
}
# Create desktop shortcut
function New-DesktopShortcut {
if ($NoDesktopShortcut) {
return
}
Write-Status "Creating desktop shortcut..."
try {
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$DesktopPath\HEAL.lnk")
$Shortcut.TargetPath = "$InstallPath\heal.bat"
$Shortcut.WorkingDirectory = $InstallPath
$Shortcut.Description = "Hello ElementAstro Launcher"
# Set icon if available
$iconPath = "$InstallPath\src\heal\resources\images\icon.ico"
if (Test-Path $iconPath) {
$Shortcut.IconLocation = $iconPath
}
$Shortcut.Save()
Write-Success "Desktop shortcut created"
} catch {
Write-Warning "Failed to create desktop shortcut: $($_.Exception.Message)"
}
}
# Create Start Menu shortcut
function New-StartMenuShortcut {
if ($NoStartMenu) {
return
}
Write-Status "Creating Start Menu shortcut..."
try {
$startMenuDir = "$StartMenuPath\HEAL"
New-Item -ItemType Directory -Path $startMenuDir -Force | Out-Null
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$startMenuDir\HEAL.lnk")
$Shortcut.TargetPath = "$InstallPath\heal.bat"
$Shortcut.WorkingDirectory = $InstallPath
$Shortcut.Description = "Hello ElementAstro Launcher"
# Set icon if available
$iconPath = "$InstallPath\src\heal\resources\images\icon.ico"
if (Test-Path $iconPath) {
$Shortcut.IconLocation = $iconPath
}
$Shortcut.Save()
# Create uninstaller shortcut
$UninstallShortcut = $WshShell.CreateShortcut("$startMenuDir\Uninstall HEAL.lnk")
$UninstallShortcut.TargetPath = "powershell.exe"
$UninstallShortcut.Arguments = "-ExecutionPolicy Bypass -File `"$InstallPath\uninstall.ps1`""
$UninstallShortcut.WorkingDirectory = $InstallPath
$UninstallShortcut.Description = "Uninstall HEAL"
$UninstallShortcut.Save()
Write-Success "Start Menu shortcuts created"
} catch {
Write-Warning "Failed to create Start Menu shortcuts: $($_.Exception.Message)"
}
}
# Create uninstaller
function New-Uninstaller {
Write-Status "Creating uninstaller..."
try {
$uninstallScript = @"
# HEAL Uninstaller
param([switch]`$Silent)
if (-not `$Silent) {
`$result = [System.Windows.Forms.MessageBox]::Show(
"Are you sure you want to uninstall HEAL?",
"Uninstall HEAL",
[System.Windows.Forms.MessageBoxButtons]::YesNo,
[System.Windows.Forms.MessageBoxIcon]::Question
)
if (`$result -eq [System.Windows.Forms.DialogResult]::No) {
exit 0
}
}
Write-Host "Uninstalling HEAL..." -ForegroundColor Yellow
# Remove installation directory
Remove-Item "$InstallPath" -Recurse -Force -ErrorAction SilentlyContinue
# Remove shortcuts
Remove-Item "$DesktopPath\HEAL.lnk" -Force -ErrorAction SilentlyContinue
Remove-Item "$StartMenuPath\HEAL" -Recurse -Force -ErrorAction SilentlyContinue
Write-Host "HEAL has been uninstalled successfully." -ForegroundColor Green
if (-not `$Silent) {
Read-Host "Press Enter to exit"
}
"@
$uninstallPath = "$InstallPath\uninstall.ps1"
$uninstallScript | Out-File -FilePath $uninstallPath -Encoding UTF8
Write-Success "Uninstaller created: $uninstallPath"
} catch {
Write-Warning "Failed to create uninstaller: $($_.Exception.Message)"
}
}
# Cleanup function
function Invoke-Cleanup {
if ($LASTEXITCODE -ne 0) {
Write-Error "Installation failed. Cleaning up..."
try {
Remove-Item $InstallPath -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item "$DesktopPath\HEAL.lnk" -Force -ErrorAction SilentlyContinue
Remove-Item "$StartMenuPath\HEAL" -Recurse -Force -ErrorAction SilentlyContinue
} catch {
# Ignore cleanup errors
}
}
}
# Main installation function
function Install-Main {
Write-Host "HEAL - Hello ElementAstro Launcher Installer" -ForegroundColor Cyan
Write-Host "=============================================" -ForegroundColor Cyan
Write-Host ""
Write-Status "Installation path: $InstallPath"
if (Test-Administrator) {
Write-Warning "Running as Administrator. This is not required for user installation."
}
try {
Test-Requirements
New-InstallDirectories
Install-Heal
New-Launcher
New-DesktopShortcut
New-StartMenuShortcut
New-Uninstaller
Write-Host ""
Write-Success "HEAL installation completed successfully!"
Write-Host ""
Write-Status "You can now run HEAL using:"
Write-Host " - Desktop shortcut (if created)"
Write-Host " - Start Menu > HEAL > HEAL"
Write-Host " - Command: $InstallPath\heal.bat"
Write-Host ""
Write-Status "Installation directory: $InstallPath"
Write-Status "To uninstall, run: $InstallPath\uninstall.ps1"
} catch {
Write-Error "Installation failed: $($_.Exception.Message)"
Invoke-Cleanup
exit 1
}
}
# Run main installation
Install-Main