mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
feat: add ASCII progress bars to both install scripts
Agent-Logs-Url: https://github.com/MCCTeam/Minecraft-Console-Client/sessions/00d3b725-2246-40c5-93e4-d9813d95c333 Co-authored-by: milutinke <441903+milutinke@users.noreply.github.com>
This commit is contained in:
parent
53afc252ea
commit
46fdd687c7
2 changed files with 41 additions and 3 deletions
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue