Skip to content

Commit

Permalink
Name shortcuts consistently
Browse files Browse the repository at this point in the history
- The VS Code shortcut now closes the terminal after Code is launched
  • Loading branch information
ndabas committed Nov 30, 2022
1 parent 3964bd6 commit 081c391
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 59 deletions.
52 changes: 21 additions & 31 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ $repositories | ForEach-Object {
}

$sdkVersion = (.\build\cmake\bin\cmake.exe -P .\packages\pico-setup-windows\pico-sdk-version.cmake -N | Select-String -Pattern 'PICO_SDK_VERSION_STRING=(.*)$').Matches.Groups[1].Value
$product = "Raspberry Pi Pico SDK $sdkVersion"
$product = "Raspberry Pi Pico SDK v$sdkVersion"

Write-Host "SDK version: $sdkVersion"
Write-Host "Installer version: $version"
Expand Down Expand Up @@ -164,8 +164,10 @@ if (-not (Test-Path ".\build\picotool-install\mingw$bitness")) {
; CMake generates build defs with long hashes in the paths. Both CMake and
; Ninja currently have problems working with long paths on Windows.
; !define PICO_REPOS_DIR "`$LOCALAPPDATA\Programs\$product"
!define PICO_REPOS_DIR "`$DOCUMENTS\Pico"
!define PICO_SHORTCUTS_DIR "`$SMPROGRAMS\$product"
!define PICO_REPOS_DIR "`$DOCUMENTS\Pico-v$sdkVersion"
!define PICO_SHORTCUTS_DIR "`$SMPROGRAMS\Raspberry Pi\Pico SDK v$sdkVersion"
!define PICO_REG_ROOT HKCU
!define PICO_REG_KEY "Software\Raspberry Pi\$basename"
Name "`${TITLE}"
Caption "`${TITLE}"
Expand All @@ -187,7 +189,7 @@ SpaceTexts "none"
InstallDir "`${PICO_INSTALL_DIR}"
;Get installation folder from registry if available
InstallDirRegKey HKCU "Software\$basename" "InstallPath"
InstallDirRegKey `${PICO_REG_ROOT} "`${PICO_REG_KEY}" "InstallPath"
!define MUI_ABORTWARNING
Expand Down Expand Up @@ -222,8 +224,8 @@ Section
InitPluginsDir
File /oname=`$TEMP\RefreshEnv.cmd "packages\pico-setup-windows\RefreshEnv.cmd"
WriteRegStr HKCU "Software\$basename" "InstallPath" "`$INSTDIR"
WriteRegStr HKCU "Software\$basename\v$version" "InstallPath" "`$INSTDIR"
WriteRegStr `${PICO_REG_ROOT} "`${PICO_REG_KEY}" "InstallPath" "`$INSTDIR"
WriteRegStr `${PICO_REG_ROOT} "`${PICO_REG_KEY}\v$version" "InstallPath" "`$INSTDIR"
CreateDirectory "`${PICO_REPOS_DIR}"
CreateDirectory "`${PICO_SHORTCUTS_DIR}"
Expand Down Expand Up @@ -290,6 +292,8 @@ Section "VS Code Extensions" SecCodeExts
Pop `$1
nsExec::ExecToLog '"`$0" /c call "`$TEMP\RefreshEnv.cmd" && code --install-extension ms-vscode.cpptools-extension-pack'
Pop `$1
nsExec::ExecToLog '"`$0" /c call "`$TEMP\RefreshEnv.cmd" && code --install-extension ms-vscode.vscode-serial-monitor'
Pop `$1
SectionEnd
Expand Down Expand Up @@ -319,32 +323,29 @@ Section "Pico environment" SecPico
SetOutPath "`$INSTDIR\pico-sdk-tools"
File "build\pico-sdk-tools\mingw$bitness\*.*"
WriteRegStr HKCU "Software\Kitware\CMake\Packages\pico-sdk-tools" "v$version" "`$INSTDIR\pico-sdk-tools"
WriteRegStr `${PICO_REG_ROOT} "Software\Kitware\CMake\Packages\pico-sdk-tools" "v$version" "`$INSTDIR\pico-sdk-tools"
SetOutPath "`$INSTDIR\picotool"
File "build\picotool-install\mingw$bitness\*.*"
SetOutPath "`${PICO_REPOS_DIR}"
File "version.txt"
File "packages\pico-setup-windows\pico-code.ps1"
File "packages\pico-setup-windows\pico-env.ps1"
File "packages\pico-setup-windows\pico-env.cmd"
File "packages\pico-setup-windows\pico-setup.cmd"
File "packages\pico-setup-windows\ReadMe.txt"
CreateShortcut "`${PICO_SHORTCUTS_DIR}\Developer Command Prompt for Pico.lnk" "cmd.exe" '/k "`${PICO_REPOS_DIR}\pico-env.cmd"'
CreateShortcut "`${PICO_SHORTCUTS_DIR}\Open pico-examples in Visual Studio Code.lnk" "cmd.exe" '/c (call "`${PICO_REPOS_DIR}\pico-env.cmd" && code --disable-workspace-trust "`${PICO_REPOS_DIR}\pico-examples") || pause' "`$INSTDIR\resources\vscode.ico"
WriteINIStr "`${PICO_SHORTCUTS_DIR}\Raspberry Pi microcontrollers documentation.url" "InternetShortcut" "URL" "https://www.raspberrypi.com/documentation/microcontrollers/"
CreateDirectory "`${PICO_SHORTCUTS_DIR}\Pico - Documentation"
WriteINIStr "`${PICO_SHORTCUTS_DIR}\Raspberry Pi Pico C-C++ SDK documentation.url" "InternetShortcut" "URL" "https://www.raspberrypi.com/documentation/microcontrollers/c_sdk.html"
CreateShortcut "`${PICO_SHORTCUTS_DIR}\Pico - Developer Command Prompt.lnk" "cmd.exe" '/k "`${PICO_REPOS_DIR}\pico-env.cmd"'
CreateShortcut "`${PICO_SHORTCUTS_DIR}\Pico - Developer PowerShell.lnk" "powershell.exe" '-NoExit -ExecutionPolicy Bypass -File "`${PICO_REPOS_DIR}\pico-env.ps1"'
CreateShortcut "`${PICO_SHORTCUTS_DIR}\Pico - Visual Studio Code.lnk" "powershell.exe" 'powershell -WindowStyle Hidden -ExecutionPolicy Bypass -File "`${PICO_REPOS_DIR}\pico-code.ps1"' "`$INSTDIR\resources\vscode.ico" "" SW_SHOWMINIMIZED
; Unconditionally create a shortcut for VS Code -- in case the user had it
; installed already, or if they install it later
CreateShortcut "`${PICO_SHORTCUTS_DIR}\Visual Studio Code for Pico.lnk" "cmd.exe" '/c (call "`${PICO_REPOS_DIR}\pico-env.cmd" && code) || pause' "`$INSTDIR\resources\vscode.ico"
; SetOutPath is needed here to set the working directory for the shortcut
SetOutPath "`$INSTDIR\pico-project-generator"
CreateShortcut "`${PICO_SHORTCUTS_DIR}\Pico Project Generator.lnk" "cmd.exe" '/c (call "`${PICO_REPOS_DIR}\pico-env.cmd" && python "`${PICO_REPOS_DIR}\pico-project-generator\pico_project.py" --gui) || pause'
WriteINIStr "`${PICO_SHORTCUTS_DIR}\Pico - Documentation\Pico Datasheet.url" "InternetShortcut" "URL" "https://datasheets.raspberrypi.com/pico/pico-datasheet.pdf"
WriteINIStr "`${PICO_SHORTCUTS_DIR}\Pico - Documentation\Pico W Datasheet.url" "InternetShortcut" "URL" "https://datasheets.raspberrypi.com/picow/pico-w-datasheet.pdf"
WriteINIStr "`${PICO_SHORTCUTS_DIR}\Pico - Documentation\Pico C C++ SDK.url" "InternetShortcut" "URL" "https://datasheets.raspberrypi.com/pico/raspberry-pi-pico-c-sdk.pdf"
WriteINIStr "`${PICO_SHORTCUTS_DIR}\Pico - Documentation\Pico Python SDK.url" "InternetShortcut" "URL" "https://datasheets.raspberrypi.com/pico/raspberry-pi-pico-python-sdk.pdf"
; Reset working dir for pico-setup.cmd launched from the finish page
SetOutPath "`${PICO_REPOS_DIR}"
Expand All @@ -353,28 +354,17 @@ SectionEnd
LangString DESC_SecPico `${LANG_ENGLISH} "Scripts for cloning the Pico SDK and tools repos, and for setting up your Pico development environment."
Section "Download documents and files" SecDocs
SetOutPath "`${PICO_REPOS_DIR}"
File "common.ps1"
File "packages\pico-setup-windows\pico-docs.ps1"
SectionEnd
Function RunBuild
ReadEnvStr `$0 COMSPEC
Exec '"`$0" /k call "`$TEMP\RefreshEnv.cmd" && del "`$TEMP\RefreshEnv.cmd" && call "`${PICO_REPOS_DIR}\pico-setup.cmd" 1'
FunctionEnd
LangString DESC_SecDocs `${LANG_ENGLISH} "Adds a script to download the latest Pico documents, design files, and UF2 files."
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT `${SecCodeExts} `$(DESC_SecCodeExts)
!insertmacro MUI_DESCRIPTION_TEXT `${SecOpenOCD} `$(DESC_SecOpenOCD)
!insertmacro MUI_DESCRIPTION_TEXT `${SecPico} `$(DESC_SecPico)
!insertmacro MUI_DESCRIPTION_TEXT `${SecDocs} `$(DESC_SecDocs)
$($downloads | ForEach-Object {
" !insertmacro MUI_DESCRIPTION_TEXT `${Sec$($_.shortName)} `$(DESC_Sec$($_.shortName))`n"
})
Expand Down
22 changes: 22 additions & 0 deletions packages/pico-setup-windows/pico-code.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue'

. "$PSScriptRoot\pico-env.ps1"

# On first run, open the pico-examples repo. Open a blank VS Code instance otherwise.
$openArgs = "--disable-workspace-trust `"$PSScriptRoot\pico-examples`""
$regPath = 'HKCU:\Software\Raspberry Pi\pico-setup-windows'
$regName = 'FirstRun'
$entries = Get-ItemProperty -Path $regPath
if ($entries | Get-Member $regName) {
$openArgs = ''
} else {
Set-ItemProperty -Path $regPath -Name $regName -Value '0'
}

$codeBinDir = Split-Path -Parent (Get-Command 'code.cmd').Path
$codeExeDir = Split-Path -Parent $codeBinDir
$codeExe = Join-Path $codeExeDir 'code.exe'

cmd /s /c "start `"`" `"$codeExe`" --new-window $openArgs"
27 changes: 0 additions & 27 deletions packages/pico-setup-windows/pico-docs.ps1

This file was deleted.

2 changes: 1 addition & 1 deletion packages/pico-setup-windows/pico-env.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ if not defined PICO_INSTALL_VERSION (

rem https://stackoverflow.com/questions/22352793/reading-a-registry-value-to-a-batch-variable-handling-spaces-in-value
for /f "usebackq skip=1 tokens=2,*" %%h in (
`reg query "HKCU\Software\pico-setup-windows\v%PICO_INSTALL_VERSION%" /v "InstallPath"`
`reg query "HKCU\Software\Raspberry Pi\pico-setup-windows\v%PICO_INSTALL_VERSION%" /v "InstallPath"`
) do (
echo PICO_INSTALL_PATH=%%i
set "PICO_INSTALL_PATH=%%i"
Expand Down
9 changes: 9 additions & 0 deletions packages/pico-setup-windows/pico-env.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$ProgressPreference = 'SilentlyContinue'

# https://github.com/microsoft/vswhere/wiki/Start-Developer-Command-Prompt#using-powershell
& "${env:COMSPEC}" /s /c "`"$PSScriptRoot\pico-env.cmd`" && set" | ForEach-Object {
$name, $value = $_ -split '=', 2
Set-Content env:\"$name" $value
}

0 comments on commit 081c391

Please sign in to comment.