From d889236a9974e270cf2c4c7ae2f35c177d5d21a2 Mon Sep 17 00:00:00 2001 From: CristianD Date: Wed, 29 Jul 2026 17:18:07 +0100 Subject: [PATCH] Update 8x8_Work_Updater.ps1 --- 8x8_Work_Updater.ps1 | 55 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/8x8_Work_Updater.ps1 b/8x8_Work_Updater.ps1 index 7e89cbf..e127a53 100644 --- a/8x8_Work_Updater.ps1 +++ b/8x8_Work_Updater.ps1 @@ -1,8 +1,8 @@ # ============================================================================== # Script Name: 8x8_Work_Updater.ps1 -# Description: Downloads 8x8, launches an interactive JCT600 GUI attached to -# the active user's session via BUILTIN\Users, waits for response, -# silently installs, relaunches 8x8 Work, and cleans up. +# Description: Downloads 8x8 with console progress bar, launches interactive +# JCT600 GUI attached to user session via BUILTIN\Users, waits +# for response, silently installs, relaunches 8x8, and cleans up. # ============================================================================== # Ensure script is running elevated @@ -24,17 +24,56 @@ if (Test-Path $flagFile) { Remove-Item $flagFile -Force } try { # -------------------------------------------------------------------------- - # Step 1: Download 8x8 Setup Installer + # Step 1: Download 8x8 Setup Installer with Console Progress Bar # -------------------------------------------------------------------------- $installerUrl = "https://work-desktop-assets.8x8.com/prod-publish/ga/work-64-msi-v8.35.2-6.msi" $installerPath = Join-Path $workDir "8x8_Work_Installer.msi" Write-Host "[1/5] Downloading 8x8 Work installer..." -ForegroundColor Cyan + try { - Invoke-WebRequest -Uri $installerUrl -OutFile $installerPath -UseBasicParsing - Write-Host "Download complete: $installerPath" -ForegroundColor Green + # Initialize .NET HttpClient + $httpClient = New-Object System.Net.Http.HttpClient + $response = $httpClient.GetAsync($installerUrl, [System.Net.Http.HttpCompletionOption]::ResponseHeadersRead).Result + + if (-not $response.IsSuccessStatusCode) { + throw "HTTP Error $($response.StatusCode)" + } + + $totalBytes = $response.Content.Headers.ContentLength + $inputStream = $response.Content.ReadAsStreamAsync().Result + $outputStream = [System.IO.File]::Create($installerPath) + $buffer = New-Object byte[] 8192 + $totalBytesRead = 0 + $bytesRead = 0 + + # Stream copy loop with progress indicator + while (($bytesRead = $inputStream.Read($buffer, 0, $buffer.Length)) -gt 0) { + $outputStream.Write($buffer, 0, $bytesRead) + $totalBytesRead += $bytesRead + + if ($totalBytes -gt 0) { + $percent = [math]::Round(($totalBytesRead / $totalBytes) * 100) + $downloadedMB = [math]::Round($totalBytesRead / 1MB, 2) + $totalMB = [math]::Round($totalBytes / 1MB, 2) + + # Render ASCII progress bar + $barLength = 30 + $filledLength = [math]::Round(($percent / 100) * $barLength) + $bar = ("█" * $filledLength) + ("░" * ($barLength - $filledLength)) + + Write-Host "`rDownloading: [$bar] $percent% ($downloadedMB MB / $totalMB MB)" -NoNewline -ForegroundColor Yellow + } + } + + # Close Streams + $outputStream.Close() + $inputStream.Close() + $httpClient.Dispose() + + Write-Host "`nDownload complete: $installerPath" -ForegroundColor Green } catch { - Write-Error "Failed to download installer from $installerUrl. Error: $_" + Write-Error "`nFailed to download installer from $installerUrl. Error: $_" exit 1 } @@ -153,8 +192,6 @@ $form.Dispose() $taskName = "JCT600_8x8_Update_UserDialog" $action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-ExecutionPolicy Bypass -WindowStyle Hidden -File `"$guiScript`"" - - # Use BUILTIN\Users group principal for Entra ID / Domain compatibility $principal = New-ScheduledTaskPrincipal -GroupId "BUILTIN\Users" -RunLevel Limited Register-ScheduledTask -TaskName $taskName -Action $action -Principal $principal -Force | Out-Null