Skip to content

Commit

Permalink
Resolve remarks Ryan
Browse files Browse the repository at this point in the history
  • Loading branch information
G.Reijn authored and G.Reijn committed Dec 21, 2024
1 parent f282499 commit d21c013
Showing 1 changed file with 45 additions and 20 deletions.
65 changes: 45 additions & 20 deletions resources/Microsoft.VSCode.Dsc/Microsoft.VSCode.Dsc.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -25,44 +25,69 @@ function TryGetRegistryValue {
}
}

function Get-OSArchitectureRegistryKey {
function Get-VSCodeRegistryKey {
[CmdletBinding()]
param (
[switch] $Insiders
[string] $Architecture
)

$architecture = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture

switch ($architecture) {
'X64' { return $Insiders ? @('{217B4C08-948D-4276-BFBB-BEE930AE5A2C}_is1', '{1287CAD5-7C8D-410D-88B9-0D1EE4A83FF2}_is1') : @('{771FD6B0-FA20-440A-A002-3B3BAC16DC50}_is1', '{EA457B21-F73E-494C-ACAB-524FDE069978}_is1') }
'X86' { return $Insiders ? @('{C26E74D1-022E-4238-8B9D-1E7564A36CC9}_is1', '{26F4A15E-E392-4887-8C09-7BC55712FD5B}_is1') : @('{D628A17A-9713-46BF-8D57-E671B46A741E}_is1', '{F8A2A208-72B3-4D61-95FC-8A65D340689B}_is1') }
'Arm' { Throw 'Not supported.' }
'Arm64' { return $Insiders ? @('{69BD8F7B-65EB-4C6F-A14E-44CFA83712C0}_is1', '{0AEDB616-9614-463B-97D7-119DD86CCA64}_is1') : @('{D9E514E7-1A56-452D-9337-2990C0DC4310}_is1', '{A5270FC5-65AD-483E-AC30-2C276B63D0AC}_is1') }
'X64' { return @('{771FD6B0-FA20-440A-A002-3B3BAC16DC50}_is1', '{EA457B21-F73E-494C-ACAB-524FDE069978}_is1') }
'X86' { return @('{D628A17A-9713-46BF-8D57-E671B46A741E}_is1', '{F8A2A208-72B3-4D61-95FC-8A65D340689B}_is1') }
'Arm64' { return @('{D9E514E7-1A56-452D-9337-2990C0DC4310}_is1', '{A5270FC5-65AD-483E-AC30-2C276B63D0AC}_is1') }
Default { Throw 'Could not determine architecture.' }
}
}

function Get-VSCodeInsidersRegistryKey {
param (
[string] $Architecture
)

switch ($Architecture) {
'X64' { return @('{217B4C08-948D-4276-BFBB-BEE930AE5A2C}_is1', '{1287CAD5-7C8D-410D-88B9-0D1EE4A83FF2}_is1') }
'X86' { return @('{C26E74D1-022E-4238-8B9D-1E7564A36CC9}_is1', '{26F4A15E-E392-4887-8C09-7BC55712FD5B}_is1') }
'Arm64' { return @('{69BD8F7B-65EB-4C6F-A14E-44CFA83712C0}_is1', '{0AEDB616-9614-463B-97D7-119DD86CCA64}_is1') }
Default { Throw 'Could not determine architecture.' }
}
}

function Get-OSArchitectureRegistryKey {
[CmdletBinding()]
param (
[ValidateSet('X64', 'X86', 'Arm64')]
[string] $Architecture,
[switch] $Insiders
)

$registryKey = if ($Insiders.IsPresent) {
Get-VSCodeInsidersRegistryKey -Architecture $architecture
} else {
Get-VSCodeRegistryKey -Architecture $architecture
}

return $registryKey
}

function Get-VSCodeCLIPath {
param (
[switch]$Insiders
)

$architecture = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture
# Get the available keys
$registryKeys = Get-OSArchitectureRegistryKey -Insiders:$Insiders.IsPresent
$registryKeys = Get-OSArchitectureRegistryKey -Insiders:$Insiders.IsPresent -Architecture $architecture
$registryHive = @('HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall', 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall', 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall')

if ($IsLinux) {
if ($Insiders) {
$InstallLocation = Join-Path ($env:PATH.Split([System.IO.Path]::PathSeparator) -match 'Microsoft VS Code Insiders') 'code-insiders'
if (Test-Path $InstallLocation -ErrorAction SilentlyContinue) {
return $InstallLocation

}
} else {
$InstallLocation = Join-Path ($env:PATH.Split([System.IO.Path]::PathSeparator) -match 'Microsoft VS Code') 'code'
if (Test-Path $InstallLocation -ErrorAction SilentlyContinue) {
return $InstallLocation
}
$command = 'code'
if ($Insiders.IsPresent) {
$command = 'code-insiders'
}
# Using Get-Command to find the path of the command instead of PATH environment variable because both can be installed
$commandPath = Get-Command -Name $command -ErrorAction SilentlyContinue
if ($commandPath) {
return $commandPath.Source
}
}

Expand Down

0 comments on commit d21c013

Please sign in to comment.