install.ps1: ask which drive to install to

Lists local fixed drives with free space and lets the player pick one by
number or letter. Enter keeps the previous location on the system drive
(%USERPROFILE%\mc-lan-party), so existing installs are still found;
other drives install to <drive>:\mc-lan-party. Warns under 3 GB free.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Mykhailo Ivanchenko
2026-10-24 13:11:51 +02:00
parent ffdcf78133
commit 238aa7809c
2 changed files with 35 additions and 2 deletions
+34 -1
View File
@@ -14,7 +14,40 @@ $ServerAddr = "minecraft.mivanchenko.de:25565" # always-on homelab box, same
$ErrorActionPreference = "Stop" # fail loudly instead of printing an error and silently continuing
$InstallDir = Join-Path $env:USERPROFILE "mc-lan-party"
# ---- pick the install drive (default: the system drive, under the user profile like before) ----
$SystemDrive = $env:SystemDrive # e.g. "C:"
$Drives = @(Get-CimInstance Win32_LogicalDisk -Filter "DriveType=3" | Sort-Object DeviceID) # local fixed disks only
Write-Host "Where should the LAN party Minecraft be installed? (needs ~3 GB)"
for ($i = 0; $i -lt $Drives.Count; $i++) {
$d = $Drives[$i]
$free = [math]::Round($d.FreeSpace / 1GB, 1)
$label = if ($d.VolumeName) { " ($($d.VolumeName))" } else { "" }
$default = if ($d.DeviceID -eq $SystemDrive) { " [default]" } else { "" }
Write-Host (" {0}) {1}{2} - {3} GB free{4}" -f ($i + 1), $d.DeviceID, $label, $free, $default)
}
$DriveChoice = $null
while (-not $DriveChoice) {
$answer = Read-Host "Drive number or letter [$SystemDrive]"
if ([string]::IsNullOrWhiteSpace($answer)) { $answer = $SystemDrive }
$answer = $answer.Trim()
if ($answer -match '^\d+$' -and [int]$answer -ge 1 -and [int]$answer -le $Drives.Count) {
$DriveChoice = $Drives[[int]$answer - 1]
} else {
$letter = $answer.TrimEnd(':', '\').ToUpper() + ":"
$DriveChoice = $Drives | Where-Object { $_.DeviceID -eq $letter } | Select-Object -First 1
}
if (-not $DriveChoice) { Write-Host " '$answer' is not one of the drives above, try again." -ForegroundColor Yellow }
}
if ($DriveChoice.FreeSpace -lt 3GB) {
Write-Host "==> Warning: only $([math]::Round($DriveChoice.FreeSpace / 1GB, 1)) GB free on $($DriveChoice.DeviceID), the install may run out of space." -ForegroundColor Yellow
}
# System drive keeps the old location so existing installs are found again; other drives get a top-level folder
if ($DriveChoice.DeviceID -eq $SystemDrive) {
$InstallDir = Join-Path $env:USERPROFILE "mc-lan-party"
} else {
$InstallDir = Join-Path "$($DriveChoice.DeviceID)\" "mc-lan-party"
}
New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null
Set-Location $InstallDir