Skip to content

Commit

Permalink
Added functionality to install the User variant of Stable Edition (#2160
Browse files Browse the repository at this point in the history
)

Added functionality to install the User variant of Stable Edition
  • Loading branch information
Lothindir authored and rjmholt committed Sep 5, 2019
1 parent a11e27c commit 447a295
Showing 1 changed file with 40 additions and 18 deletions.
58 changes: 40 additions & 18 deletions scripts/Install-VSCode.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<#PSScriptInfo
.VERSION 1.3
.VERSION 1.4
.GUID 539e5585-7a02-4dd6-b9a6-5dd288d0a5d0
Expand All @@ -25,6 +25,8 @@
.EXTERNALSCRIPTDEPENDENCIES
.RELEASENOTES
30/08/2019 - added functionality to install the "User Install" variant of Stable Edition.
--
07/11/2018 - added support for PowerShell Core and macOS/Linux platforms.
--
15/08/2018 - added functionality to install the new "User Install" variant of Insiders Edition.
Expand Down Expand Up @@ -128,12 +130,12 @@
[CmdletBinding(SupportsShouldProcess=$true)]
param(
[parameter()]
[ValidateSet(, "64-bit", "32-bit")]
[string]$Architecture = "64-bit",
[ValidateSet('64-bit', '32-bit')]
[string]$Architecture = '64-bit',

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

[Parameter()]
[ValidateNotNull()]
Expand Down Expand Up @@ -166,7 +168,7 @@ gpgkey=https://packages.microsoft.com/keys/microsoft.asc

function Test-IsOsArchX64 {
if ($PSVersionTable.PSVersion.Major -lt 6) {
return (Get-CimInstance -ClassName Win32_OperatingSystem).OSArchitecture -eq "64-bit"
return (Get-CimInstance -ClassName Win32_OperatingSystem).OSArchitecture -eq '64-bit'
}

return [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture -eq [System.Runtime.InteropServices.Architecture]::X64
Expand Down Expand Up @@ -199,7 +201,7 @@ function Get-CodePlatformInformation {
$Bitness,

[Parameter(Mandatory=$true)]
[ValidateSet('Stable', 'Insider-System', 'Insider-User')]
[ValidateSet('Stable-System', 'Stable-User', 'Insider-System', 'Insider-User')]
[string]
$BuildEdition
)
Expand All @@ -226,11 +228,16 @@ function Get-CodePlatformInformation {
}

switch ($BuildEdition) {
'Stable' {
'Stable-System' {
$appName = "Visual Studio Code ($Bitness)"
break
}

'Stable-User' {
$appName = "Visual Studio Code ($($Architecture) - User)"
break
}

'Insider-System' {
$appName = "Visual Studio Code - Insiders Edition ($Bitness)"
break
Expand Down Expand Up @@ -318,10 +325,14 @@ function Get-CodePlatformInformation {
}

switch ($BuildEdition) {
'Stable' {
'Stable-System' {
$exePath = "$installBase\Microsoft VS Code\bin\code.cmd"
}

'Stable-User' {
$exePath = "${env:LocalAppData}\Programs\Microsoft VS Code\bin\code.cmd"
}

'Insider-System' {
$exePath = "$installBase\Microsoft VS Code Insiders\bin\code-insiders.cmd"
}
Expand All @@ -334,11 +345,17 @@ function Get-CodePlatformInformation {
}

switch ($BuildEdition) {
'Stable' {
'Stable-System' {
$channel = 'stable'
break
}

'Stable-User' {
$channel = 'stable'
$platform += '-user'
break
}

'Insider-System' {
$channel = 'insider'
break
Expand Down Expand Up @@ -388,19 +405,19 @@ function Save-WithBitsTransfer {

$bitsDl = Start-BitsTransfer $FileUri -Destination $Destination -Asynchronous

while (($bitsDL.JobState -eq "Transferring") -or ($bitsDL.JobState -eq "Connecting")) {
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 )
}

switch ($bitsDl.JobState) {

"Transferred" {
'Transferred' {
Complete-BitsTransfer -BitsJob $bitsDl
break
}

"Error" {
throw "Error downloading installation media."
'Error' {
throw 'Error downloading installation media.'
}
}
}
Expand All @@ -417,7 +434,7 @@ function Install-VSCodeFromTar {
)

$tarDir = Join-Path ([System.IO.Path]::GetTempPath()) 'VSCodeTar'
$destDir = "/opt/VSCode-linux-x64"
$destDir = '/opt/VSCode-linux-x64'

New-Item -ItemType Directory -Force -Path $tarDir
try {
Expand All @@ -439,7 +456,12 @@ function Install-VSCodeFromTar {

# We need to be running as elevated on *nix
if (($IsLinux -or $IsMacOS) -and (id -u) -ne 0) {
throw "Must be running as root to install VSCode.`nInvoke this script with (for example):`n`tsudo pwsh -f Install-VSCode.ps1 -BuildEdition Stable"
throw "Must be running as root to install VSCode.`nInvoke this script with (for example):`n`tsudo pwsh -f Install-VSCode.ps1 -BuildEdition Stable-System"
}

# User builds can only be installed on Windows systems
if ($BuildEdition.EndsWith('User') -and -not ($IsWindows -or $PSVersionTable.PSVersion.Major -lt 5)) {
throw 'User builds are not available for non-Windows systems'
}

try {
Expand Down Expand Up @@ -506,7 +528,7 @@ try {
}

switch ($BuildEdition) {
'Stable' {
'Stable-System' {
& $pacMan install -y code
}

Expand Down Expand Up @@ -550,7 +572,7 @@ try {
break
}

Install-VSCodeFromTar -TarPath $installerPath -Insiders:($BuildEdition -ne 'Stable')
Install-VSCodeFromTar -TarPath $installerPath -Insiders:($BuildEdition -ne 'Stable-System')
break
}

Expand Down

0 comments on commit 447a295

Please sign in to comment.