From d21c013bbf0e71a792c15fb44c49776b728500cd Mon Sep 17 00:00:00 2001 From: "G.Reijn" Date: Sat, 21 Dec 2024 14:33:50 +0100 Subject: [PATCH] Resolve remarks Ryan --- .../Microsoft.VSCode.Dsc.psm1 | 65 +++++++++++++------ 1 file changed, 45 insertions(+), 20 deletions(-) diff --git a/resources/Microsoft.VSCode.Dsc/Microsoft.VSCode.Dsc.psm1 b/resources/Microsoft.VSCode.Dsc/Microsoft.VSCode.Dsc.psm1 index 04561d2..dcc80c8 100644 --- a/resources/Microsoft.VSCode.Dsc/Microsoft.VSCode.Dsc.psm1 +++ b/resources/Microsoft.VSCode.Dsc/Microsoft.VSCode.Dsc.psm1 @@ -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 } }