beatrun.ru/static/install

158 lines
5.1 KiB
Text
Raw Normal View History

# Function to query the registry
function Get-RegistryValue {
param (
[string]$path,
[string]$value
)
try {
$result = Get-ItemProperty -Path $path -ErrorAction Stop
return $result.$value
} catch {
return $null
2024-03-17 16:35:33 +05:00
}
}
2024-12-02 19:20:23 +05:00
Write-Host "Searching for Steam installation..." -ForegroundColor White
# Get Steam installation path from registry
$steam_dir = Get-RegistryValue "HKLM:\SOFTWARE\Valve\Steam" "InstallPath"
2024-03-17 16:35:33 +05:00
if (-not $steam_dir) {
$steam_dir = Get-RegistryValue "HKLM:\SOFTWARE\WOW6432Node\Valve\Steam" "InstallPath"
}
2024-03-17 16:35:33 +05:00
2024-08-13 09:14:56 +05:00
# Fallback to searching for Steam.exe on all drives
if (-not $steam_dir) {
2024-12-02 19:20:23 +05:00
Write-Host "No registry key found. Searching for Steam executable on all drives..." -ForegroundColor Yellow
2024-09-14 22:58:28 +05:00
# Get all filesystem drives
$drives = Get-PSDrive -PSProvider FileSystem | Where-Object { $_.Name -match '^[A-Z]$' }
foreach ($drive in $drives) {
2024-09-14 22:58:28 +05:00
# Properly format drive path, avoid additional quotes
$drive_letter = $drive.Name
$steam_exe = Get-ChildItem -Path "$($drive_letter):\" -Recurse -Include "Steam.exe" -ErrorAction SilentlyContinue | Select-Object -First 1
if ($steam_exe) {
$steam_dir = Split-Path $steam_exe.FullName -Parent
break
}
}
}
if (-not $steam_dir) {
2024-12-02 19:20:23 +05:00
Write-Host "Steam installation path not found" -ForegroundColor Red
Read-Host "Press Enter to exit"
exit
}
2024-03-17 16:35:33 +05:00
2024-12-02 19:20:23 +05:00
Write-Host "Steam installation path: $steam_dir" -ForegroundColor Cyan
2024-08-13 09:14:56 +05:00
# Initialize Garry's Mod directory as null
$gmod_dir = $null
# Check for Garry's Mod installation in the primary Steam library
$gmod_check_path = Join-Path $steam_dir "steamapps\appmanifest_4000.acf"
if (Test-Path $gmod_check_path) {
$gmod_dir = Join-Path $steam_dir "steamapps\common\GarrysMod"
}
# Check for Garry's Mod in additional Steam library folders if not found in the primary
if (-not $gmod_dir) {
$library_folders_path = Join-Path $steam_dir "steamapps\libraryfolders.vdf"
if (Test-Path $library_folders_path) {
2024-08-13 09:14:56 +05:00
$library_folders = (Get-Content $library_folders_path) -join "`n"
$library_paths = $library_folders -split '(?=\s*"\d+"\s*{)' # Split by each library entry
2024-09-14 22:58:28 +05:00
2024-08-13 09:14:56 +05:00
foreach ($library in $library_paths) {
2024-09-14 22:58:28 +05:00
# Extract the library path from the line that contains "path"
2024-08-13 09:14:56 +05:00
if ($library -match '"path"\s*"\s*(.+)\s*"') {
2024-09-14 22:58:28 +05:00
# Clean the extracted path to remove extra backslashes or quotes
$library_path = $matches[1] -replace "\\{2,}", "\" # Replace any multiple backslashes with a single backslash
$library_path = $library_path.Trim('"') # Remove any surrounding quotes
2024-08-13 09:14:56 +05:00
}
2024-09-14 22:58:28 +05:00
# If "4000" (Garry's Mod ID) is found, set the GMod directory
2024-08-13 09:14:56 +05:00
if ($library -match '"4000"') {
$gmod_dir = Join-Path $library_path "steamapps\common\GarrysMod"
break
2024-03-17 16:35:33 +05:00
}
}
}
}
2024-08-13 09:14:56 +05:00
if (-not $gmod_dir) {
2024-12-02 19:20:23 +05:00
Write-Host "GMod installation path not found" -ForegroundColor Red
Read-Host "Press Enter to exit"
exit
2024-03-17 16:35:33 +05:00
}
2024-12-02 19:20:23 +05:00
Write-Host "GMod installation path: $gmod_dir" -ForegroundColor Cyan
# Confirm Garry's Mod installation path
$GMODPath = Join-Path $gmod_dir "garrysmod"
2024-12-02 19:20:23 +05:00
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 "(y/n)"
2024-12-02 19:20:23 +05:00
if ($GMODConfirmation -eq "y" -or $GMODConfirmation -eq "Y") {
2024-09-14 22:58:28 +05:00
# Define paths
$TempPath = Join-Path $GMODPath "temp"
$ZIPPath = Join-Path $TempPath "beatrun.zip"
$FolderMainPath = Join-Path $TempPath "beatrun-main"
2024-09-14 22:58:28 +05:00
$FolderPath = Join-Path $TempPath "beatrun"
$AddonPath = Join-Path $FolderPath "beatrun"
2024-09-14 22:58:28 +05:00
$NewAddonPath = Join-Path $GMODPath "addons\beatrun"
# Ensure the temporary directory exists
if (-not (Test-Path -Path $TempPath)) {
New-Item -ItemType Directory -Path $TempPath -Force | Out-Null
}
# Download Beatrun zip
2024-12-02 19:20:23 +05:00
Write-Host "Downloading the Beatrun archive..." -ForegroundColor White
2024-09-14 22:58:28 +05:00
try {
(New-Object Net.WebClient).DownloadFile("https://github.com/JonnyBro/beatrun/archive/refs/heads/main.zip", $ZIPPath)
2024-12-02 19:20:23 +05:00
Write-Host "Download successful!" -ForegroundColor Green
2024-09-14 22:58:28 +05:00
} catch {
2024-12-02 19:20:23 +05:00
Write-Host "Error: Unable to download Beatrun. Please check your internet connection or URL." -ForegroundColor Red
2024-09-14 22:58:28 +05:00
exit
}
# Unzip the archive
2024-12-02 19:20:23 +05:00
Write-Host "Unpacking the archive..." -ForegroundColor White
2024-09-14 22:58:28 +05:00
try {
Expand-Archive -Path $ZIPPath -DestinationPath $TempPath -Force
2024-12-02 19:20:23 +05:00
Write-Host "Unpacking successful!" -ForegroundColor Green
2024-09-14 22:58:28 +05:00
} catch {
2024-12-02 19:20:23 +05:00
Write-Host "Error: Failed to unpack the Beatrun archive." -ForegroundColor Red
2024-09-14 22:58:28 +05:00
exit
}
# Rename and prepare files
if (Test-Path $FolderMainPath) {
Rename-Item -Path $FolderMainPath -NewName $FolderPath
} else {
2024-12-02 19:20:23 +05:00
Write-Host "Error: Unpacked folder not found." -ForegroundColor Red
2024-09-14 22:58:28 +05:00
exit
}
# Remove the downloaded zip file
Remove-Item -Path $ZIPPath -Force
# Confirm the addon directory exists
if (Test-Path $NewAddonPath) {
2024-12-02 19:20:23 +05:00
Write-Host "Previous Beatrun installation found. Removing old installation..." -ForegroundColor White
2024-09-14 22:58:28 +05:00
Remove-Item -Path $NewAddonPath -Recurse -Force
2024-03-17 16:35:33 +05:00
}
2024-09-14 22:58:28 +05:00
# Move the new Beatrun addon
2024-12-02 19:20:23 +05:00
Write-Host "Installing Beatrun..." -ForegroundColor White
2024-09-14 22:58:28 +05:00
Move-Item -Path $AddonPath -Destination $NewAddonPath -Force
# Clean up temporary files
Remove-Item -Path $TempPath -Recurse -Force
2024-12-02 19:20:23 +05:00
Write-Host "Beatrun has been installed successfully!" -ForegroundColor Green
2024-03-17 16:35:33 +05:00
}