Skip to content

Commit 7ed3357

Browse files
author
Ben Reader
committed
fixed up formatting, added async to bits, added progress bar to download
1 parent e54f8a6 commit 7ed3357

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

scripts/Install-VSCode.ps1

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ param(
127127
[string]$BuildEdition = "stable",
128128

129129
[Parameter()]
130-
[switch]
131-
$User,
130+
[switch]$User,
132131

133132
[Parameter()]
134133
[ValidateNotNull()]
@@ -175,7 +174,7 @@ if (!($IsLinux -or $IsOSX)) {
175174
break;
176175
}
177176
}
178-
if (($User -eq $true) -and ($BuildEdition -eq "Insider")) {
177+
if ($User -and $BuildEdition -eq "Insider") {
179178
$codeCmdPath = "$env:LocalAppData\Programs\Microsoft VS Code Insiders\bin\code-insiders.cmd"
180179
$appName = "Visual Studio Code - Insiders Edition ($($Architecture) - User)"
181180
$fileUri = "https://vscode-update.azurewebsites.net/latest/$($bitVersion)-user/$($BuildEdition)"
@@ -188,8 +187,12 @@ if (!($IsLinux -or $IsOSX)) {
188187

189188
if (!(Test-Path $codeCmdPath)) {
190189
Write-Host "`nDownloading latest $appName..." -ForegroundColor Yellow
191-
Remove-Item -Force "$env:TEMP\vscode-$($BuildEdition).exe" -ErrorAction SilentlyContinue
192-
Start-BitsTransfer $fileUri -Destination "$env:TEMP\vscode-$($BuildEdition).exe"
190+
Remove-Item -Force "$env:TEMP\vscode-$($BuildEdition).exe" -ErrorAction SilentlyContinuev
191+
$bitsDl = Start-BitsTransfer $fileUri -Destination "$env:TEMP\vscode-$($BuildEdition).exe" -Asynchronous
192+
do {
193+
Write-Progress -Activity "Downloading: $AppName" -Status "$([math]::round($bitsDl.BytesTransferred / 1mb))mb / $([math]::round($bitsDl.BytesTotal / 1mb))mb" -PercentComplete ($($bitsDl.BytesTransferred) / $($bitsDl.BytesTotal) * 100 )
194+
}
195+
until ($bitsDl.JobState -eq "Transferred")
193196

194197
Write-Host "`nInstalling $appName..." -ForegroundColor Yellow
195198
Start-Process -Wait "$env:TEMP\vscode-$($BuildEdition).exe" -ArgumentList /silent, /mergetasks=!runcode

0 commit comments

Comments
 (0)