Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding Bits-Transfer & user switch to install latest user profile insiders edition #1477

Merged
merged 8 commits into from
Aug 23, 2018
39 changes: 30 additions & 9 deletions scripts/Install-VSCode.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
.EXTERNALSCRIPTDEPENDENCIES

.RELEASENOTES
15/08/2018 - added functionality to install the new "User Install" variant of Insiders Edition.
--
28/12/2017 - added functionality to support 64-bit versions of VSCode
& support for installation of VSCode Insiders Edition.
--
Expand Down Expand Up @@ -53,8 +55,10 @@
downloaded instead. If parameter is not used, then 64-bit is used as default.

.PARAMETER BuildEdition
A validated string defining which build edition or "stream" to download - stable or
insiders edition. If the parameter is not used, then stable is downloaded as default.
A validated string defining which build edition or "stream" to download:
Stable or Insiders Edition (system install or user profile install).
If the parameter is not used, then stable is downloaded as default.


.PARAMETER AdditionalExtensions
An array of strings that are the fully-qualified names of extensions to be
Expand Down Expand Up @@ -84,9 +88,9 @@
extensions.

.EXAMPLE
Install-VSCode.ps1 -BuildEdition Insider -LaunchWhenDone
Install-VSCode.ps1 -BuildEdition Insider-User -LaunchWhenDone

Installs Visual Studio Code Insiders Edition (64-bit) and then launches the editor
Installs Visual Studio Code Insiders Edition (64-bit) to the user profile and then launches the editor
after installation completes.

.NOTES
Expand Down Expand Up @@ -119,8 +123,11 @@ param(
[string]$Architecture = "64-bit",

[parameter()]
[ValidateSet("stable","insider")]
[string]$BuildEdition = "stable",
[ValidateSet("Stable","Insider-System","Insider-User")]
[string]$BuildEdition = "Stable",

[Parameter()]
[switch]$User,

[Parameter()]
[ValidateNotNull()]
Expand Down Expand Up @@ -159,11 +166,21 @@ if (!($IsLinux -or $IsOSX)) {
"Stable" {
$codeCmdPath = "$codePath\Microsoft VS Code\bin\code.cmd"
$appName = "Visual Studio Code ($($Architecture))"
$fileUri = "https://vscode-update.azurewebsites.net/latest/$($bitVersion)/$($BuildEdition)"

break;
}
"Insider" {
"Insider-System" {
$codeCmdPath = "$codePath\Microsoft VS Code Insiders\bin\code-insiders.cmd"
$appName = "Visual Studio Code - Insiders Edition ($($Architecture))"
$fileUri = "https://vscode-update.azurewebsites.net/latest/$($bitVersion)/$($BuildEdition)"

break;
}
"Insider-User" {
$codeCmdPath = "$env:LocalAppData\Programs\Microsoft VS Code Insiders\bin\code-insiders.cmd"
$appName = "Visual Studio Code - Insiders Edition ($($Architecture) - User)"
$fileUri = "https://vscode-update.azurewebsites.net/latest/$($bitVersion)-user/$($BuildEdition)"
break;
}
}
Expand All @@ -172,8 +189,12 @@ if (!($IsLinux -or $IsOSX)) {

if (!(Test-Path $codeCmdPath)) {
Write-Host "`nDownloading latest $appName..." -ForegroundColor Yellow
Remove-Item -Force "$env:TEMP\vscode-$($BuildEdition).exe" -ErrorAction SilentlyContinue
Invoke-WebRequest -Uri "https://vscode-update.azurewebsites.net/latest/$($bitVersion)/$($BuildEdition)" -OutFile "$env:TEMP\vscode-$($BuildEdition).exe"
Remove-Item -Force "$env:TEMP\vscode-$($BuildEdition).exe" -ErrorAction SilentlyContinuev
$bitsDl = Start-BitsTransfer $fileUri -Destination "$env:TEMP\vscode-$($BuildEdition).exe" -Asynchronous
do {
Write-Progress -Activity "Downloading: $AppName" -Status "$([math]::round($bitsDl.BytesTransferred / 1mb))mb / $([math]::round($bitsDl.BytesTotal / 1mb))mb" -PercentComplete ($($bitsDl.BytesTransferred) / $($bitsDl.BytesTotal) * 100 )
}
until ($bitsDl.JobState -eq "Transferred")

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