Add progress bars to install-prerequisites.ps1

- Added overall progress tracking for required installations (1/3, 2/3, 3/3)
- Added progress indicators for optional installations
- Added individual package installation progress with status updates
- Progress bars show clear visual feedback during installation process
- Helps users understand how far along the installation is
This commit is contained in:
Bjarke Sporring
2026-01-14 16:37:39 +01:00
parent f696044461
commit 6d2e099eb4

View File

@@ -146,7 +146,12 @@ function Install-Package {
Write-Host " Running: $installCmd" -ForegroundColor Gray Write-Host " Running: $installCmd" -ForegroundColor Gray
try { try {
# Show progress during installation
Write-Progress -Activity "Installing $Name" -Status "Downloading and installing..." -PercentComplete 25
$result = Invoke-Expression $installCmd 2>&1 $result = Invoke-Expression $installCmd 2>&1
Write-Progress -Activity "Installing $Name" -Status "Verifying installation..." -PercentComplete 75
# Check if installation succeeded # Check if installation succeeded
Start-Sleep -Seconds 2 # Give the system time to register the new command Start-Sleep -Seconds 2 # Give the system time to register the new command
@@ -157,16 +162,19 @@ function Install-Package {
if (Test-CommandExists $CheckCommand) { if (Test-CommandExists $CheckCommand) {
$version = Get-InstalledVersion $CheckCommand $version = Get-InstalledVersion $CheckCommand
Write-Success "$Name installed successfully: $version" Write-Success "$Name installed successfully: $version"
Write-Progress -Activity "Installing $Name" -Completed
return $true return $true
} }
else { else {
Write-Warning "$Name installation completed, but command '$CheckCommand' not found." Write-Warning "$Name installation completed, but command '$CheckCommand' not found."
Write-Host " You may need to restart your terminal or computer." -ForegroundColor Yellow Write-Host " You may need to restart your terminal or computer." -ForegroundColor Yellow
Write-Progress -Activity "Installing $Name" -Completed
return $false return $false
} }
} }
catch { catch {
Write-Error "Failed to install $Name`: $_" Write-Error "Failed to install $Name`: $_"
Write-Progress -Activity "Installing $Name" -Completed
return $false return $false
} }
} }
@@ -253,19 +261,38 @@ $results = @{
WindowsTerminal = $null WindowsTerminal = $null
} }
# Progress tracking
$totalSteps = 3 # Required installations
$currentStep = 0
Write-Host "`nStarting installation..." -ForegroundColor Cyan Write-Host "`nStarting installation..." -ForegroundColor Cyan
Write-Host "Note: Some installations may take a few minutes." -ForegroundColor Gray Write-Host "Note: Some installations may take a few minutes." -ForegroundColor Gray
Write-Host "" Write-Host ""
# Progress bar helper
function Write-ProgressIndicator {
param(
[string]$Activity,
[string]$Status,
[int]$PercentComplete
)
Write-Progress -Activity $Activity -Status $Status -PercentComplete $PercentComplete
}
#region Required Installations #region Required Installations
# Install PowerShell 7 # Install PowerShell 7
$currentStep++
Write-ProgressIndicator -Activity "Installing Required Tools" -Status "Installing PowerShell 7 (1/3)" -PercentComplete (($currentStep / $totalSteps) * 100)
$results.PowerShell = Install-Package ` $results.PowerShell = Install-Package `
-Name "PowerShell 7" ` -Name "PowerShell 7" `
-WingetId "Microsoft.PowerShell" ` -WingetId "Microsoft.PowerShell" `
-CheckCommand "pwsh" -CheckCommand "pwsh"
# Install Git # Install Git
$currentStep++
Write-ProgressIndicator -Activity "Installing Required Tools" -Status "Installing Git (2/3)" -PercentComplete (($currentStep / $totalSteps) * 100)
$results.Git = Install-Package ` $results.Git = Install-Package `
-Name "Git" ` -Name "Git" `
-WingetId "Git.Git" ` -WingetId "Git.Git" `
@@ -282,11 +309,16 @@ if ($results.Git) {
} }
# Install Visual Studio Code # Install Visual Studio Code
$currentStep++
Write-ProgressIndicator -Activity "Installing Required Tools" -Status "Installing Visual Studio Code (3/3)" -PercentComplete (($currentStep / $totalSteps) * 100)
$results.VSCode = Install-Package ` $results.VSCode = Install-Package `
-Name "Visual Studio Code" ` -Name "Visual Studio Code" `
-WingetId "Microsoft.VisualStudioCode" ` -WingetId "Microsoft.VisualStudioCode" `
-CheckCommand "code" -CheckCommand "code"
# Clear progress bar
Write-Progress -Activity "Installing Required Tools" -Completed
#endregion #endregion
#region Optional Installations #region Optional Installations
@@ -294,10 +326,12 @@ $results.VSCode = Install-Package `
# Python 3.12 (optional) # Python 3.12 (optional)
Write-Host "" Write-Host ""
if (Get-UserConfirmation "Do you want to install Python 3.12? (Required for Module 08: Multiplayer Git)") { if (Get-UserConfirmation "Do you want to install Python 3.12? (Required for Module 08: Multiplayer Git)") {
Write-ProgressIndicator -Activity "Installing Optional Tools" -Status "Installing Python 3.12" -PercentComplete 50
$results.Python = Install-Package ` $results.Python = Install-Package `
-Name "Python 3.12" ` -Name "Python 3.12" `
-WingetId "Python.Python.3.12" ` -WingetId "Python.Python.3.12" `
-CheckCommand "python" -CheckCommand "python"
Write-Progress -Activity "Installing Optional Tools" -Completed
} }
else { else {
Write-Host " Skipping Python installation." -ForegroundColor Gray Write-Host " Skipping Python installation." -ForegroundColor Gray
@@ -307,10 +341,12 @@ else {
# Windows Terminal (optional) # Windows Terminal (optional)
Write-Host "" Write-Host ""
if (Get-UserConfirmation "Do you want to install Windows Terminal? (Highly recommended for better terminal experience)") { if (Get-UserConfirmation "Do you want to install Windows Terminal? (Highly recommended for better terminal experience)") {
Write-ProgressIndicator -Activity "Installing Optional Tools" -Status "Installing Windows Terminal" -PercentComplete 50
$results.WindowsTerminal = Install-Package ` $results.WindowsTerminal = Install-Package `
-Name "Windows Terminal" ` -Name "Windows Terminal" `
-WingetId "Microsoft.WindowsTerminal" ` -WingetId "Microsoft.WindowsTerminal" `
-CheckCommand "wt" -CheckCommand "wt"
Write-Progress -Activity "Installing Optional Tools" -Completed
} }
else { else {
Write-Host " Skipping Windows Terminal installation." -ForegroundColor Gray Write-Host " Skipping Windows Terminal installation." -ForegroundColor Gray