diff --git a/docs/.vuepress/public/install.ps1 b/docs/.vuepress/public/install.ps1 index 7255738d..8a14a86c 100644 --- a/docs/.vuepress/public/install.ps1 +++ b/docs/.vuepress/public/install.ps1 @@ -39,9 +39,41 @@ $tag = $release.tag_name Write-Host "Downloading MinecraftClient $tag ($suffix)..." -# Suppress the progress bar to avoid cluttering the terminal and speed up the download -$ProgressPreference = 'SilentlyContinue' -Invoke-WebRequest -Uri $downloadUrl -OutFile $OUTPUT -UseBasicParsing +# Download with a built-in ASCII progress bar (no external tools required). +# HttpWebRequest streams the body on the main thread so we can update the +# progress bar inline without any Runspace or thread-safety concerns. +$outPath = Join-Path (Get-Location).Path $OUTPUT +$request = [System.Net.HttpWebRequest]::Create($downloadUrl) +$response = $request.GetResponse() +$totalBytes = $response.ContentLength + +$responseStream = $response.GetResponseStream() +$fileStream = [System.IO.File]::Create($outPath) +$buffer = New-Object byte[] 32768 +$totalRead = 0 + +try { + while ($true) { + $read = $responseStream.Read($buffer, 0, $buffer.Length) + if ($read -le 0) { break } + $fileStream.Write($buffer, 0, $read) + $totalRead += $read + if ($totalBytes -gt 0) { + $pct = [int]($totalRead * 100 / $totalBytes) + $filled = '=' * [int]($pct / 2) + $bar = $filled.PadRight(50) + $recv = [math]::Round($totalRead / 1MB, 1) + $total = [math]::Round($totalBytes / 1MB, 1) + Write-Host -NoNewline ("`r[{0}] {1,3}% {2,6:N1} / {3,6:N1} MB" -f $bar, $pct, $recv, $total) + } + } +} finally { + $fileStream.Close() + $responseStream.Close() + $response.Close() +} + +Write-Host "" # end the progress line Write-Host "" Write-Host "Downloaded: .\$OUTPUT" diff --git a/docs/.vuepress/public/install.sh b/docs/.vuepress/public/install.sh index f1cf57d0..d3e74d3d 100644 --- a/docs/.vuepress/public/install.sh +++ b/docs/.vuepress/public/install.sh @@ -57,6 +57,12 @@ _download_file() { if command -v curl >/dev/null 2>&1; then curl -fL --progress-bar -o "$2" "$1" elif command -v wget >/dev/null 2>&1; then + # --show-progress forces the progress bar even when stdout is not a TTY. + # Fall back silently to default output if the flag is not supported + # (older wget versions, e.g. BusyBox wget). + if wget --show-progress -O "$2" "$1" 2>/dev/null; then + return 0 + fi wget -O "$2" "$1" else echo "Error: Neither 'curl' nor 'wget' is available. Please install one and retry." >&2