add colors to output

This commit is contained in:
Jonny_Bro (Nikita) 2024-12-02 19:20:23 +05:00
parent 177fa833a5
commit 37a97a7959

View file

@ -13,7 +13,7 @@ function Get-RegistryValue {
} }
} }
Write-Host "Searching for Steam installation..." Write-Host "Searching for Steam installation..." -ForegroundColor White
# Get Steam installation path from registry # Get Steam installation path from registry
$steam_dir = Get-RegistryValue "HKLM:\SOFTWARE\Valve\Steam" "InstallPath" $steam_dir = Get-RegistryValue "HKLM:\SOFTWARE\Valve\Steam" "InstallPath"
@ -24,7 +24,7 @@ if (-not $steam_dir) {
# Fallback to searching for Steam.exe on all drives # Fallback to searching for Steam.exe on all drives
if (-not $steam_dir) { if (-not $steam_dir) {
Write-Host "No registry key found. Searching for Steam executable on all drives..." Write-Host "No registry key found. Searching for Steam executable on all drives..." -ForegroundColor Yellow
# Get all filesystem drives # Get all filesystem drives
$drives = Get-PSDrive -PSProvider FileSystem | Where-Object { $_.Name -match '^[A-Z]$' } $drives = Get-PSDrive -PSProvider FileSystem | Where-Object { $_.Name -match '^[A-Z]$' }
@ -42,12 +42,12 @@ if (-not $steam_dir) {
} }
if (-not $steam_dir) { if (-not $steam_dir) {
Write-Host "Steam installation path not found" Write-Host "Steam installation path not found" -ForegroundColor Red
Read-Host "Press Enter to exit" Read-Host "Press Enter to exit"
exit exit
} }
Write-Host "Steam installation path: $steam_dir" Write-Host "Steam installation path: $steam_dir" -ForegroundColor Cyan
# Initialize Garry's Mod directory as null # Initialize Garry's Mod directory as null
$gmod_dir = $null $gmod_dir = $null
@ -84,19 +84,19 @@ if (-not $gmod_dir) {
} }
if (-not $gmod_dir) { if (-not $gmod_dir) {
Write-Host "GMod installation path not found" Write-Host "GMod installation path not found" -ForegroundColor Red
Read-Host "Press Enter to exit" Read-Host "Press Enter to exit"
exit exit
} }
Write-Host "GMod installation path: $gmod_dir" Write-Host "GMod installation path: $gmod_dir" -ForegroundColor Cyan
# Confirm Garry's Mod installation path # Confirm Garry's Mod installation path
$GMODPath = Join-Path $gmod_dir "garrysmod" $GMODPath = Join-Path $gmod_dir "garrysmod"
$_text = "Do you want to install in this path? It will completely wipe the previous Beatrun install if you had one!`n$GMODPath (y/n)" Write-Host "Do you want to install in this path? It will completely wipe the previous Beatrun install if you had one!" -ForegroundColor Yellow
$GMODConfirmation = Read-Host $_text $GMODConfirmation = Read-Host "(y/n)"
if ($GMODConfirmation -eq "y") { if ($GMODConfirmation -eq "y" -or $GMODConfirmation -eq "Y") {
# Define paths # Define paths
$TempPath = Join-Path $GMODPath "temp" $TempPath = Join-Path $GMODPath "temp"
$ZIPPath = Join-Path $TempPath "beatrun.zip" $ZIPPath = Join-Path $TempPath "beatrun.zip"
@ -111,22 +111,22 @@ if ($GMODConfirmation -eq "y") {
} }
# Download Beatrun zip # Download Beatrun zip
Write-Host "Downloading the Beatrun archive..." Write-Host "Downloading the Beatrun archive..." -ForegroundColor White
try { try {
(New-Object Net.WebClient).DownloadFile("https://github.com/JonnyBro/beatrun/archive/refs/heads/main.zip", $ZIPPath) (New-Object Net.WebClient).DownloadFile("https://github.com/JonnyBro/beatrun/archive/refs/heads/main.zip", $ZIPPath)
Write-Host "Download successful!" Write-Host "Download successful!" -ForegroundColor Green
} catch { } catch {
Write-Host "Error: Unable to download Beatrun. Please check your internet connection or URL." Write-Host "Error: Unable to download Beatrun. Please check your internet connection or URL." -ForegroundColor Red
exit exit
} }
# Unzip the archive # Unzip the archive
Write-Host "Unpacking the archive..." Write-Host "Unpacking the archive..." -ForegroundColor White
try { try {
Expand-Archive -Path $ZIPPath -DestinationPath $TempPath -Force Expand-Archive -Path $ZIPPath -DestinationPath $TempPath -Force
Write-Host "Unpacking successful!" Write-Host "Unpacking successful!" -ForegroundColor Green
} catch { } catch {
Write-Host "Error: Failed to unpack the Beatrun archive." Write-Host "Error: Failed to unpack the Beatrun archive." -ForegroundColor Red
exit exit
} }
@ -134,7 +134,7 @@ if ($GMODConfirmation -eq "y") {
if (Test-Path $FolderMainPath) { if (Test-Path $FolderMainPath) {
Rename-Item -Path $FolderMainPath -NewName $FolderPath Rename-Item -Path $FolderMainPath -NewName $FolderPath
} else { } else {
Write-Host "Error: Unpacked folder not found." Write-Host "Error: Unpacked folder not found." -ForegroundColor Red
exit exit
} }
@ -143,15 +143,15 @@ if ($GMODConfirmation -eq "y") {
# Confirm the addon directory exists # Confirm the addon directory exists
if (Test-Path $NewAddonPath) { if (Test-Path $NewAddonPath) {
Write-Host "Previous Beatrun installation found. Removing old installation..." Write-Host "Previous Beatrun installation found. Removing old installation..." -ForegroundColor White
Remove-Item -Path $NewAddonPath -Recurse -Force Remove-Item -Path $NewAddonPath -Recurse -Force
} }
# Move the new Beatrun addon # Move the new Beatrun addon
Write-Host "Installing Beatrun..." Write-Host "Installing Beatrun..." -ForegroundColor White
Move-Item -Path $AddonPath -Destination $NewAddonPath -Force Move-Item -Path $AddonPath -Destination $NewAddonPath -Force
# Clean up temporary files # Clean up temporary files
Remove-Item -Path $TempPath -Recurse -Force Remove-Item -Path $TempPath -Recurse -Force
Write-Host "Beatrun has been installed successfully!" Write-Host "Beatrun has been installed successfully!" -ForegroundColor Green
} }