From e54f8a6285b92ce9aeb9a054400c928c52068d58 Mon Sep 17 00:00:00 2001 From: Ben Reader Date: Tue, 14 Aug 2018 18:59:34 +1000 Subject: [PATCH 1/7] adding BitsTransfer & user switch --- scripts/Install-VSCode.ps1 | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/scripts/Install-VSCode.ps1 b/scripts/Install-VSCode.ps1 index 9e392b052d..04fbd6fa14 100644 --- a/scripts/Install-VSCode.ps1 +++ b/scripts/Install-VSCode.ps1 @@ -56,6 +56,10 @@ 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. +.PARAMETER User + When present, the latest VSCode "User Profile" Insider Edition will be installed. + if BuildEdition is set to "stable" this will revert back to the current standard. + .PARAMETER AdditionalExtensions An array of strings that are the fully-qualified names of extensions to be installed in addition to the PowerShell extension. The fully qualified @@ -122,6 +126,10 @@ param( [ValidateSet("stable","insider")] [string]$BuildEdition = "stable", + [Parameter()] + [switch] + $User, + [Parameter()] [ValidateNotNull()] [string[]]$AdditionalExtensions = @(), @@ -167,13 +175,21 @@ if (!($IsLinux -or $IsOSX)) { break; } } + if (($User -eq $true) -and ($BuildEdition -eq "Insider")) { + $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)" + } + else { + $fileUri = "https://vscode-update.azurewebsites.net/latest/$($bitVersion)/$($BuildEdition)" + } try { $ProgressPreference = 'SilentlyContinue' 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" + Start-BitsTransfer $fileUri -Destination "$env:TEMP\vscode-$($BuildEdition).exe" Write-Host "`nInstalling $appName..." -ForegroundColor Yellow Start-Process -Wait "$env:TEMP\vscode-$($BuildEdition).exe" -ArgumentList /silent, /mergetasks=!runcode From 7ed335797d6504887bc9cb15e5e946c00664823f Mon Sep 17 00:00:00 2001 From: Ben Reader Date: Wed, 15 Aug 2018 11:20:29 +1000 Subject: [PATCH 2/7] fixed up formatting, added async to bits, added progress bar to download --- scripts/Install-VSCode.ps1 | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/scripts/Install-VSCode.ps1 b/scripts/Install-VSCode.ps1 index 04fbd6fa14..212cb2906e 100644 --- a/scripts/Install-VSCode.ps1 +++ b/scripts/Install-VSCode.ps1 @@ -127,8 +127,7 @@ param( [string]$BuildEdition = "stable", [Parameter()] - [switch] - $User, + [switch]$User, [Parameter()] [ValidateNotNull()] @@ -175,7 +174,7 @@ if (!($IsLinux -or $IsOSX)) { break; } } - if (($User -eq $true) -and ($BuildEdition -eq "Insider")) { + if ($User -and $BuildEdition -eq "Insider") { $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)" @@ -188,8 +187,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 - Start-BitsTransfer $fileUri -Destination "$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 From 878b190c68be1f4b21696c69fdfa550321c70474 Mon Sep 17 00:00:00 2001 From: Ben Reader Date: Wed, 15 Aug 2018 12:26:14 +1000 Subject: [PATCH 3/7] moved "user" switch into $buildEdition as a validate set option. --- scripts/Install-VSCode.ps1 | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/scripts/Install-VSCode.ps1 b/scripts/Install-VSCode.ps1 index 212cb2906e..4fb8cd4d5a 100644 --- a/scripts/Install-VSCode.ps1 +++ b/scripts/Install-VSCode.ps1 @@ -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. -- @@ -53,12 +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 User - When present, the latest VSCode "User Profile" Insider Edition will be installed. - if BuildEdition is set to "stable" this will revert back to the current standard. .PARAMETER AdditionalExtensions An array of strings that are the fully-qualified names of extensions to be @@ -88,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 @@ -123,8 +123,8 @@ param( [string]$Architecture = "64-bit", [parameter()] - [ValidateSet("stable","insider")] - [string]$BuildEdition = "stable", + [ValidateSet("Stable","Insider-System","Insider-User")] + [string]$BuildEdition = "Stable", [Parameter()] [switch]$User, @@ -166,21 +166,23 @@ 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; } - } - if ($User -and $BuildEdition -eq "Insider") { - $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)" - } - else { - $fileUri = "https://vscode-update.azurewebsites.net/latest/$($bitVersion)/$($BuildEdition)" } try { $ProgressPreference = 'SilentlyContinue' From b4b6e5ea5103b1e1ba4fe4a3c132a38bd64c7453 Mon Sep 17 00:00:00 2001 From: Ben Reader Date: Wed, 15 Aug 2018 17:35:49 +1000 Subject: [PATCH 4/7] fixed syntax issue with url forming & fixed Bits Transfer --- scripts/Install-VSCode.ps1 | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/scripts/Install-VSCode.ps1 b/scripts/Install-VSCode.ps1 index 4fb8cd4d5a..c14a1873f7 100644 --- a/scripts/Install-VSCode.ps1 +++ b/scripts/Install-VSCode.ps1 @@ -119,11 +119,11 @@ [CmdletBinding()] param( [parameter()] - [ValidateSet(,"64-bit","32-bit")] + [ValidateSet(, "64-bit", "32-bit")] [string]$Architecture = "64-bit", [parameter()] - [ValidateSet("Stable","Insider-System","Insider-User")] + [ValidateSet("Stable", "Insider-System", "Insider-User")] [string]$BuildEdition = "Stable", [Parameter()] @@ -151,7 +151,7 @@ if (!($IsLinux -or $IsOSX)) { break; } "32-bit" { - if ((Get-CimInstance -ClassName Win32_OperatingSystem).OSArchitecture -eq "32-bit"){ + if ((Get-CimInstance -ClassName Win32_OperatingSystem).OSArchitecture -eq "32-bit") { $codePath = $env:ProgramFiles $bitVersion = "win32" } @@ -166,21 +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)" + $fileUri = "https://vscode-update.azurewebsites.net/latest/$($bitVersion)/stable" break; } "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)" + $fileUri = "https://vscode-update.azurewebsites.net/latest/$($bitVersion)/insider" 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)" + $fileUri = "https://vscode-update.azurewebsites.net/latest/$($bitVersion)-user/insider" break; } } @@ -190,11 +190,21 @@ if (!($IsLinux -or $IsOSX)) { if (!(Test-Path $codeCmdPath)) { Write-Host "`nDownloading latest $appName..." -ForegroundColor Yellow Remove-Item -Force "$env:TEMP\vscode-$($BuildEdition).exe" -ErrorAction SilentlyContinuev - $bitsDl = Start-BitsTransfer $fileUri -Destination "$env:TEMP\vscode-$($BuildEdition).exe" -Asynchronous - do { + $bitsDl = Start-BitsTransfer $fileUri -Destination "C:\dev\vscode-$($BuildEdition).exe" -Asynchronous + while (($bitsDL.JobState -eq "Transferring") -or ($bitsDL.JobState -eq "Connecting")) { 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") + switch ($bitsDl.JobSTate) { + "Transferred" { + Complete-BitsTransfer -BitsJob $bitsDl + break; + } + "Error" { + throw "Error downloading installation media." + break; + } + } + Write-Host "`nInstalling $appName..." -ForegroundColor Yellow Start-Process -Wait "$env:TEMP\vscode-$($BuildEdition).exe" -ArgumentList /silent, /mergetasks=!runcode From e3939943ced71a9654df26f05a8c7577cedff304 Mon Sep 17 00:00:00 2001 From: Ben Reader Date: Wed, 15 Aug 2018 17:39:05 +1000 Subject: [PATCH 5/7] setting download path back to prod path! --- scripts/Install-VSCode.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Install-VSCode.ps1 b/scripts/Install-VSCode.ps1 index c14a1873f7..d32e74de34 100644 --- a/scripts/Install-VSCode.ps1 +++ b/scripts/Install-VSCode.ps1 @@ -190,7 +190,7 @@ if (!($IsLinux -or $IsOSX)) { if (!(Test-Path $codeCmdPath)) { Write-Host "`nDownloading latest $appName..." -ForegroundColor Yellow Remove-Item -Force "$env:TEMP\vscode-$($BuildEdition).exe" -ErrorAction SilentlyContinuev - $bitsDl = Start-BitsTransfer $fileUri -Destination "C:\dev\vscode-$($BuildEdition).exe" -Asynchronous + $bitsDl = Start-BitsTransfer $fileUri -Destination "$env:TEMP\vscode-$($BuildEdition).exe" -Asynchronous while (($bitsDL.JobState -eq "Transferring") -or ($bitsDL.JobState -eq "Connecting")) { Write-Progress -Activity "Downloading: $AppName" -Status "$([math]::round($bitsDl.BytesTransferred / 1mb))mb / $([math]::round($bitsDl.BytesTotal / 1mb))mb" -PercentComplete ($($bitsDl.BytesTransferred) / $($bitsDl.BytesTotal) * 100 ) } From b444e3218b6d9eb6078bc6cd0657fbb4ce04fef5 Mon Sep 17 00:00:00 2001 From: Ben Reader Date: Wed, 15 Aug 2018 17:40:13 +1000 Subject: [PATCH 6/7] fixed a drive by Cat related typo --- scripts/Install-VSCode.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Install-VSCode.ps1 b/scripts/Install-VSCode.ps1 index d32e74de34..93f87ccace 100644 --- a/scripts/Install-VSCode.ps1 +++ b/scripts/Install-VSCode.ps1 @@ -189,7 +189,7 @@ if (!($IsLinux -or $IsOSX)) { if (!(Test-Path $codeCmdPath)) { Write-Host "`nDownloading latest $appName..." -ForegroundColor Yellow - Remove-Item -Force "$env:TEMP\vscode-$($BuildEdition).exe" -ErrorAction SilentlyContinuev + Remove-Item -Force "$env:TEMP\vscode-$($BuildEdition).exe" -ErrorAction SilentlyContinue $bitsDl = Start-BitsTransfer $fileUri -Destination "$env:TEMP\vscode-$($BuildEdition).exe" -Asynchronous while (($bitsDL.JobState -eq "Transferring") -or ($bitsDL.JobState -eq "Connecting")) { Write-Progress -Activity "Downloading: $AppName" -Status "$([math]::round($bitsDl.BytesTransferred / 1mb))mb / $([math]::round($bitsDl.BytesTotal / 1mb))mb" -PercentComplete ($($bitsDl.BytesTransferred) / $($bitsDl.BytesTotal) * 100 ) From 854a2ce4fab8fbd7db87ad5718e0e5b7336a6d71 Mon Sep 17 00:00:00 2001 From: Ben Reader Date: Thu, 23 Aug 2018 17:47:31 +1000 Subject: [PATCH 7/7] fixing merge conflict --- scripts/Install-VSCode.ps1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/Install-VSCode.ps1 b/scripts/Install-VSCode.ps1 index 93f87ccace..f724ec77e9 100644 --- a/scripts/Install-VSCode.ps1 +++ b/scripts/Install-VSCode.ps1 @@ -27,6 +27,10 @@ .RELEASENOTES 15/08/2018 - added functionality to install the new "User Install" variant of Insiders Edition. -- + 21/03/2018 - added functionality to install the VSCode context menus. Also, VSCode is now always added to the search path + -- + 20/03/2018 - fix OS detection to prevent error + -- 28/12/2017 - added functionality to support 64-bit versions of VSCode & support for installation of VSCode Insiders Edition. --