Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit d54c124

Browse files
committed
Fix Visual Studio Code installation
- Detect existing installs and skip download/install - Perform system install by default as the installer is running elevated
1 parent 9f56af7 commit d54c124

File tree

6 files changed

+136
-54
lines changed

6 files changed

+136
-54
lines changed

build.ps1

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,26 @@ Section "-OpenOCD" SecOpenOCD
515515
516516
SectionEnd
517517
518+
!include "packages\pico-setup-windows\VSCodeUtils.nsh"
519+
520+
Section VSCode
521+
522+
`${FindVSCode}
523+
524+
`${If} `$VSCodeExePath != ""
525+
DetailPrint "Found VS Code: `$VSCodeExePath"
526+
`${Else}
527+
DetailPrint "Could not find VS Code. Installing..."
528+
`${InstallVSCode}
529+
`${EndIf}
530+
531+
$((Get-Content 'packages\pico-examples\ide\vscode\extensions.json' | ConvertFrom-Json).recommendations | ForEach-Object {
532+
"`${VSCodeCmd} '--install-extension $_'`r`n"
533+
"Pop `$0`r`n"
534+
})
535+
536+
SectionEnd
537+
518538
Section "-Pico environment" SecPico
519539
520540
SetOutPath "`$INSTDIR\pico-sdk"
@@ -545,26 +565,16 @@ Section "-Pico environment" SecPico
545565
WriteRegStr `${PICO_REG_ROOT} "`${UNINSTALL_KEY}" "DisplayVersion" "$version"
546566
WriteRegStr `${PICO_REG_ROOT} "`${UNINSTALL_KEY}" "Publisher" "$company"
547567
548-
# Find Visual Studio Code, so we can point our shortcut icon to code.exe
549-
nsExec::ExecToStack 'cmd.exe /c call "`$TEMP\RefreshEnv.cmd" && where code.cmd'
550-
Pop `$0 # return value/error/timeout
551-
Pop `$1 # stdout
552-
# Get the last line of output
553-
`${WordFind} "`$1" "`$\n" "-1" `$1
554-
`${GetParent} "`$1" `$1
555-
`${GetParent} "`$1" `$1
556-
StrCpy `$1 "`$1\Code.exe"
557-
558-
`${IfNot} `${FileExists} "`$1"
559-
# Just use the default install location for the icon, in case the user installs VS Code later
560-
StrCpy `$1 "%LOCALAPPDATA%\Programs\Microsoft VS Code\Code.exe"
568+
`${IfNot} `${FileExists} "`$VSCodeExePath"
569+
# Just use the default (user) install location for the icon, in case the user installs VS Code later
570+
StrCpy `$VSCodeExePath "%LOCALAPPDATA%\Programs\Microsoft VS Code\Code.exe"
561571
DetailPrint "Could not find Visual Studio Code."
562572
MessageBox MB_OK|MB_ICONEXCLAMATION "Installation of Visual Studio Code failed. Please install it manually by downloading the installer from:${endl}${endl}https://code.visualstudio.com/" /SD IDOK
563573
`${EndIf}
564574
565575
`${CreateShortcutEx} "`${PICO_SHORTCUTS_DIR}\Pico - Developer Command Prompt.lnk" "`${PICO_AppUserModel_ID}!cmd" ``"cmd.exe" '/k "`$INSTDIR\pico-env.cmd"'``
566576
`${CreateShortcutEx} "`${PICO_SHORTCUTS_DIR}\Pico - Developer PowerShell.lnk" "`${PICO_AppUserModel_ID}!powershell" ``"powershell.exe" '-NoExit -ExecutionPolicy Bypass -File "`$INSTDIR\pico-env.ps1"'``
567-
`${CreateShortcutEx} "`${PICO_SHORTCUTS_DIR}\Pico - Visual Studio Code.lnk" "`${PICO_AppUserModel_ID}!code" ``"powershell.exe" '-NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File "`$INSTDIR\pico-code.ps1"' "`$1" "" SW_SHOWMINIMIZED``
577+
`${CreateShortcutEx} "`${PICO_SHORTCUTS_DIR}\Pico - Visual Studio Code.lnk" "`${PICO_AppUserModel_ID}!code" ``"powershell.exe" '-NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File "`$INSTDIR\pico-code.ps1"' "`$VSCodeExePath" "" SW_SHOWMINIMIZED``
568578
569579
SetOutPath "`${PICO_WINTERM_DIR}"
570580
`${WordReplace} "`$INSTDIR" "\" "\\" "+" `$7

config/x64-standalone.json

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,6 @@
22
"bitness": 64,
33
"mingwArch": "x86_64",
44
"downloads": [
5-
{
6-
"name": "Visual Studio Code",
7-
"file": "Install-VSCode.ps1",
8-
"execToLog": "cmd.exe /c call \"$PLUGINSDIR\\install-vscode.cmd\" \"$0\"",
9-
"href": "https://raw.githubusercontent.com/PowerShell/vscode-powershell/main/scripts/Install-VSCode.ps1",
10-
"additionalFiles": [
11-
"packages\\pico-setup-windows\\install-vscode.cmd",
12-
"packages\\pico-examples\\ide\\vscode\\extensions.json"
13-
]
14-
},
155
{
166
"name": "GNU Arm Embedded Toolchain",
177
"file": "gcc-arm-none-eabi-10.3-2021.10-win32.zip",

config/x64.json

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,6 @@
33
"mingwArch": "x86_64",
44
"componentSelection": true,
55
"downloads": [
6-
{
7-
"name": "Visual Studio Code",
8-
"file": "Install-VSCode.ps1",
9-
"execToLog": "cmd.exe /c call \"$PLUGINSDIR\\install-vscode.cmd\" \"$0\"",
10-
"href": "https://raw.githubusercontent.com/PowerShell/vscode-powershell/main/scripts/Install-VSCode.ps1",
11-
"additionalFiles": [
12-
"packages\\pico-setup-windows\\install-vscode.cmd",
13-
"packages\\pico-examples\\ide\\vscode\\extensions.json"
14-
]
15-
},
166
{
177
"name": "GNU Arm Embedded Toolchain",
188
"file": "gcc-arm-none-eabi-10.3-2021.10-win32.exe",

config/x86.json

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,6 @@
33
"mingwArch": "i686",
44
"componentSelection": true,
55
"downloads": [
6-
{
7-
"name": "Visual Studio Code",
8-
"file": "Install-VSCode.ps1",
9-
"execToLog": "cmd.exe /c call \"$PLUGINSDIR\\install-vscode.cmd\" \"$0\"",
10-
"href": "https://raw.githubusercontent.com/PowerShell/vscode-powershell/main/scripts/Install-VSCode.ps1",
11-
"additionalFiles": [
12-
"packages\\pico-setup-windows\\install-vscode.cmd",
13-
"packages\\pico-examples\\ide\\vscode\\extensions.json"
14-
]
15-
},
166
{
177
"name": "GNU Arm Embedded Toolchain",
188
"file": "gcc-arm-none-eabi-10.3-2021.10-win32.exe",
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
!include "LogicLib.nsh"
2+
!include "x64.nsh"
3+
4+
!define /ifndef VSCODE_DOWNLOAD_URL https://code.visualstudio.com/sha/download?build=stable&os=win32
5+
!define /ifndef VSCODE_DOWNLOAD_PATH $TEMP\vscode-install.exe
6+
7+
Var VSCodeExePath
8+
Var VSCodeCmdPath
9+
10+
; Find VS Code
11+
; Based on https://github.com/microsoft/vcpkg-tool/blob/main/src/vcpkg/commands.edit.cpp
12+
13+
!macro _ReadUninstallRegStr root_key inno_app_id user_var
14+
${If} $VSCodeExePath == ""
15+
ReadRegStr $VSCodeExePath ${root_key} "Software\Microsoft\Windows\CurrentVersion\Uninstall\{${inno_app_id}}_is1" "InstallLocation"
16+
${EndIf}
17+
!macroend
18+
19+
!define FindVSCode '!insertmacro FindVSCode '
20+
!macro FindVSCode
21+
Push $R1
22+
Push $R2
23+
24+
StrCpy $VSCodeExePath ""
25+
StrCpy $VSCodeCmdPath ""
26+
27+
StrCpy $R1 "Code.exe"
28+
StrCpy $R2 "bin\code.cmd"
29+
30+
; x64-user
31+
!insertmacro _ReadUninstallRegStr HKCU 771FD6B0-FA20-440A-A002-3B3BAC16DC50 $VSCodeExePath
32+
; x86-user
33+
!insertmacro _ReadUninstallRegStr HKCU D628A17A-9713-46BF-8D57-E671B46A741E $VSCodeExePath
34+
; x86-system
35+
!insertmacro _ReadUninstallRegStr HKLM32 F8A2A208-72B3-4D61-95FC-8A65D340689B $VSCodeExePath
36+
; x64-system
37+
!insertmacro _ReadUninstallRegStr HKLM64 EA457B21-F73E-494C-ACAB-524FDE069978 $VSCodeExePath
38+
39+
!ifdef VSCODE_FIND_INSIDERS
40+
${If} $VSCodeExePath == ""
41+
StrCpy $R1 "Code - Insiders.exe"
42+
StrCpy $R2 "bin\code-insiders.cmd"
43+
${EndIf}
44+
45+
; x64-user insider
46+
!insertmacro _ReadUninstallRegStr HKCU 217B4C08-948D-4276-BFBB-BEE930AE5A2C $VSCodeExePath
47+
; x86-user insider
48+
!insertmacro _ReadUninstallRegStr HKCU 26F4A15E-E392-4887-8C09-7BC55712FD5B $VSCodeExePath
49+
; x86-system insider
50+
!insertmacro _ReadUninstallRegStr HKLM32 C26E74D1-022E-4238-8B9D-1E7564A36CC9 $VSCodeExePath
51+
; x64-system insider
52+
!insertmacro _ReadUninstallRegStr HKLM64 1287CAD5-7C8D-410D-88B9-0D1EE4A83FF2 $VSCodeExePath
53+
!endif
54+
55+
${If} $VSCodeExePath != ""
56+
Push $R0
57+
58+
StrCpy $R0 $VSCodeExePath "" -1
59+
${If} $R0 == "\"
60+
StrCpy $VSCodeExePath $VSCodeExePath -1
61+
${EndIf}
62+
63+
StrCpy $VSCodeCmdPath "$VSCodeExePath\$R2"
64+
StrCpy $VSCodeExePath "$VSCodeExePath\$R1"
65+
66+
Pop $R0
67+
${EndIf}
68+
69+
Pop $R2
70+
Pop $R1
71+
!macroend
72+
73+
!define InstallVSCode '!insertmacro InstallVSCode '
74+
!macro InstallVSCode
75+
76+
Push $R0
77+
78+
StrCpy $R0 ""
79+
${If} ${IsNativeAMD64}
80+
StrCpy $R0 "$R0-x64"
81+
${EndIf}
82+
${IfNot} ${ShellVarContextAll}
83+
StrCpy $R0 "$R0-user"
84+
${EndIf}
85+
86+
DetailPrint "Downloading ${VSCODE_DOWNLOAD_URL}$R0"
87+
nsExec::ExecToLog `powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "$$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest -Uri '${VSCODE_DOWNLOAD_URL}$R0' -OutFile '${VSCODE_DOWNLOAD_PATH}'"`
88+
Pop $R0
89+
90+
DetailPrint "Installing Visual Studio Code..."
91+
ExecWait `"${VSCODE_DOWNLOAD_PATH}" /VERYSILENT /NORESTART /NOCANCEL /SP- /CLOSEAPPLICATIONS /RESTARTAPPLICATIONS /MERGETASKS=!runcode` $R0
92+
93+
Delete /REBOOTOK "${VSCODE_DOWNLOAD_PATH}"
94+
95+
Pop $R0
96+
97+
!macroend
98+
99+
!define VSCodeCmd '!insertmacro VSCodeCmd '
100+
!macro VSCodeCmd args
101+
102+
${If} $VSCodeCmdPath == ""
103+
${FindVSCode}
104+
${EndIf}
105+
106+
${If} $VSCodeCmdPath != ""
107+
nsExec::ExecToLog `"$VSCodeCmdPath" ${args}`
108+
${Else}
109+
Push "notfound"
110+
${EndIf}
111+
112+
!macroend

packages/pico-setup-windows/install-vscode.cmd

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)