Skip to content

Commit 969e460

Browse files
tabs-not-spacesrjmholt
authored andcommitted
Add BitsTransfer & user switch to install latest user profile insiders edition with Install-VSCode.ps1 script (#1477)
* Use BitsTransfer instead of Invoke-WebRequest to download VSCode * Make transfer asynchronous * Add a parameter to configure whether insiders, user-install or normal VSCode is installed
1 parent 3eec223 commit 969e460

File tree

1 file changed

+41
-10
lines changed

1 file changed

+41
-10
lines changed

scripts/Install-VSCode.ps1

+41-10
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
.EXTERNALSCRIPTDEPENDENCIES
2626
2727
.RELEASENOTES
28+
15/08/2018 - added functionality to install the new "User Install" variant of Insiders Edition.
29+
--
2830
21/03/2018 - added functionality to install the VSCode context menus. Also, VSCode is now always added to the search path
2931
--
3032
20/03/2018 - fix OS detection to prevent error
@@ -57,8 +59,10 @@
5759
downloaded instead. If parameter is not used, then 64-bit is used as default.
5860
5961
.PARAMETER BuildEdition
60-
A validated string defining which build edition or "stream" to download - stable or
61-
insiders edition. If the parameter is not used, then stable is downloaded as default.
62+
A validated string defining which build edition or "stream" to download:
63+
Stable or Insiders Edition (system install or user profile install).
64+
If the parameter is not used, then stable is downloaded as default.
65+
6266
6367
.PARAMETER AdditionalExtensions
6468
An array of strings that are the fully-qualified names of extensions to be
@@ -91,9 +95,9 @@
9195
extensions.
9296
9397
.EXAMPLE
94-
Install-VSCode.ps1 -BuildEdition Insider -LaunchWhenDone
98+
Install-VSCode.ps1 -BuildEdition Insider-User -LaunchWhenDone
9599
96-
Installs Visual Studio Code Insiders Edition (64-bit) and then launches the editor
100+
Installs Visual Studio Code Insiders Edition (64-bit) to the user profile and then launches the editor
97101
after installation completes.
98102
99103
.NOTES
@@ -122,12 +126,15 @@
122126
[CmdletBinding()]
123127
param(
124128
[parameter()]
125-
[ValidateSet(,"64-bit","32-bit")]
129+
[ValidateSet(, "64-bit", "32-bit")]
126130
[string]$Architecture = "64-bit",
127131

128132
[parameter()]
129-
[ValidateSet("stable","insider")]
130-
[string]$BuildEdition = "stable",
133+
[ValidateSet("Stable", "Insider-System", "Insider-User")]
134+
[string]$BuildEdition = "Stable",
135+
136+
[Parameter()]
137+
[switch]$User,
131138

132139
[Parameter()]
133140
[ValidateNotNull()]
@@ -153,7 +160,7 @@ if (($PSVersionTable.PSVersion.Major -le 5) -or $IsWindows) {
153160
break;
154161
}
155162
"32-bit" {
156-
if ((Get-CimInstance -ClassName Win32_OperatingSystem).OSArchitecture -eq "32-bit"){
163+
if ((Get-CimInstance -ClassName Win32_OperatingSystem).OSArchitecture -eq "32-bit") {
157164
$codePath = $env:ProgramFiles
158165
$bitVersion = "win32"
159166
}
@@ -168,11 +175,21 @@ if (($PSVersionTable.PSVersion.Major -le 5) -or $IsWindows) {
168175
"Stable" {
169176
$codeCmdPath = "$codePath\Microsoft VS Code\bin\code.cmd"
170177
$appName = "Visual Studio Code ($($Architecture))"
178+
$fileUri = "https://vscode-update.azurewebsites.net/latest/$($bitVersion)/stable"
179+
171180
break;
172181
}
173-
"Insider" {
182+
"Insider-System" {
174183
$codeCmdPath = "$codePath\Microsoft VS Code Insiders\bin\code-insiders.cmd"
175184
$appName = "Visual Studio Code - Insiders Edition ($($Architecture))"
185+
$fileUri = "https://vscode-update.azurewebsites.net/latest/$($bitVersion)/insider"
186+
187+
break;
188+
}
189+
"Insider-User" {
190+
$codeCmdPath = "$env:LocalAppData\Programs\Microsoft VS Code Insiders\bin\code-insiders.cmd"
191+
$appName = "Visual Studio Code - Insiders Edition ($($Architecture) - User)"
192+
$fileUri = "https://vscode-update.azurewebsites.net/latest/$($bitVersion)-user/insider"
176193
break;
177194
}
178195
}
@@ -182,7 +199,21 @@ if (($PSVersionTable.PSVersion.Major -le 5) -or $IsWindows) {
182199
if (!(Test-Path $codeCmdPath)) {
183200
Write-Host "`nDownloading latest $appName..." -ForegroundColor Yellow
184201
Remove-Item -Force "$env:TEMP\vscode-$($BuildEdition).exe" -ErrorAction SilentlyContinue
185-
Invoke-WebRequest -Uri "https://vscode-update.azurewebsites.net/latest/$($bitVersion)/$($BuildEdition)" -OutFile "$env:TEMP\vscode-$($BuildEdition).exe"
202+
$bitsDl = Start-BitsTransfer $fileUri -Destination "$env:TEMP\vscode-$($BuildEdition).exe" -Asynchronous
203+
while (($bitsDL.JobState -eq "Transferring") -or ($bitsDL.JobState -eq "Connecting")) {
204+
Write-Progress -Activity "Downloading: $AppName" -Status "$([math]::round($bitsDl.BytesTransferred / 1mb))mb / $([math]::round($bitsDl.BytesTotal / 1mb))mb" -PercentComplete ($($bitsDl.BytesTransferred) / $($bitsDl.BytesTotal) * 100 )
205+
}
206+
switch ($bitsDl.JobSTate) {
207+
"Transferred" {
208+
Complete-BitsTransfer -BitsJob $bitsDl
209+
break;
210+
}
211+
"Error" {
212+
throw "Error downloading installation media."
213+
break;
214+
}
215+
}
216+
186217

187218
Write-Host "`nInstalling $appName..." -ForegroundColor Yellow
188219
if ($EnableContextMenus) {

0 commit comments

Comments
 (0)