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

Commit dba57c0

Browse files
committed
Allow user to choose folder for example code
1 parent 387c69b commit dba57c0

File tree

5 files changed

+138
-52
lines changed

5 files changed

+138
-52
lines changed

build.ps1

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ $ExecutionContext.InvokeCommand.ExpandString($template) | Set-Content ".\build\p
208208

209209
exec { .\build\pandoc\pandoc.exe --from gfm --to gfm --output .\build\ReadMe.txt .\docs\tutorial.md }
210210

211+
mkdirp .\build\pico-examples\.vscode
212+
Copy-Item .\packages\pico-examples\ide\vscode\*.json .\build\pico-examples\.vscode\ -Force
213+
exec { tar -a -cf "build\pico-examples.zip" -C "build" "pico-examples" }
214+
211215
$endl = '$\r$\n'
212216

213217
function writeFile {
@@ -239,7 +243,7 @@ function writeFile {
239243
; The repos need to be cloned into a dir with a fairly short name, because
240244
; CMake generates build defs with long hashes in the paths. Both CMake and
241245
; Ninja currently have problems working with long paths on Windows.
242-
!define PICO_REPOS_DIR "`$LOCALAPPDATA\$productDir"
246+
!define PICO_REPOS_DIR "`$DOCUMENTS\Pico-v$sdkVersion"
243247
!define PICO_SHORTCUTS_DIR "`$SMPROGRAMS\$product"
244248
!define PICO_WINTERM_DIR "`$LOCALAPPDATA\Microsoft\Windows Terminal\Fragments\$product"
245249
!define PICO_REG_ROOT SHELL_CONTEXT
@@ -274,6 +278,8 @@ InstallDir "`${PICO_INSTALL_DIR}"
274278
; We use a version-specific key here so that multiple versions can be installed side-by-side
275279
InstallDirRegKey HKLM "`${PICO_REG_KEY}" "InstallPath"
276280
281+
Var ReposDir
282+
277283
!ifdef BUILD_UNINSTALLER
278284
279285
OutFile "build\build-uninstaller-$suffix.exe"
@@ -298,8 +304,8 @@ Function un.onInit
298304
DetailPrint "Install path: `$R0"
299305
StrCpy `$INSTDIR `$R0
300306
301-
ReadRegStr `$R1 `${PICO_REG_ROOT} "`${PICO_REG_KEY}" "ReposPath"
302-
DetailPrint "Repos path: `$R1"
307+
ReadRegStr `$ReposDir HKCU "`${PICO_REG_KEY}" "ReposPath"
308+
DetailPrint "Repos path: `$ReposDir"
303309
304310
SetRegView $bitness
305311
@@ -337,16 +343,12 @@ Section "Uninstall"
337343
`${GetParent} "`$INSTDIR" `$R0
338344
RMDir `$R0
339345
340-
RMDir /r /REBOOTOK "`$R1\pico-examples"
341-
RMDir /r /REBOOTOK "`$R1\pico-extras"
342-
RMDir /r /REBOOTOK "`$R1\pico-playground"
343-
RMDir /r /REBOOTOK "`$R1\pico-project-generator"
344-
RMDir /r /REBOOTOK "`$R1\pico-sdk"
345-
346-
RMDir /REBOOTOK "`$R1"
347-
; Remove the C:\ProgramData\Raspberry Pi directory if it is empty
348-
`${GetParent} "`$R1" `$R0
349-
RMDir `$R0
346+
`${If} `$ReposDir != ""
347+
RMDir /r /REBOOTOK "`$ReposDir\pico-examples"
348+
RMDir /r /REBOOTOK "`$ReposDir\pico-extras"
349+
RMDir /r /REBOOTOK "`$ReposDir\pico-playground"
350+
RMDir "`$ReposDir"
351+
`${EndIf}
350352
351353
DeleteRegValue `${PICO_REG_ROOT} "Software\Kitware\CMake\Packages\pico-sdk-tools" "v$sdkVersion"
352354
DeleteRegKey /ifempty `${PICO_REG_ROOT} "Software\Kitware\CMake\Packages\pico-sdk-tools"
@@ -370,32 +372,41 @@ SectionEnd
370372
OutFile "$binfile"
371373
372374
!define MUI_ICON "resources\raspberrypi.ico"
373-
374375
!define MUI_ABORTWARNING
375-
376376
!define MUI_WELCOMEPAGE_TITLE "`${TITLE}"
377377
378-
;!define MUI_COMPONENTSPAGE_SMALLDESC
379-
380-
!define MUI_FINISHPAGE_RUN_TEXT "Clone and build Pico repos"
381-
!define MUI_FINISHPAGE_RUN
382-
!define MUI_FINISHPAGE_RUN_FUNCTION RunBuild
383-
384-
!define MUI_FINISHPAGE_SHOWREADME "`$INSTDIR\ReadMe.txt"
385-
!define MUI_FINISHPAGE_SHOWREADME_TEXT "Show ReadMe"
386-
387-
!define MUI_FINISHPAGE_NOAUTOCLOSE
388-
389378
!insertmacro MUI_PAGE_WELCOME
390379
$($componentSelection ? '!insertmacro MUI_PAGE_COMPONENTS' : '')
391380
!insertmacro MUI_PAGE_DIRECTORY
381+
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE DumpLog
392382
!insertmacro MUI_PAGE_INSTFILES
383+
384+
!define FINISHPAGE_RUN_FUNCTION RunBuild
385+
!define MUI_FINISHPAGE_SHOWREADME "`$INSTDIR\ReadMe.txt"
386+
!define MUI_FINISHPAGE_SHOWREADME_TEXT "Show ReadMe"
387+
!include "packages\pico-setup-windows\FinishPage.nsh"
393388
!insertmacro MUI_PAGE_FINISH
394389
395390
!insertmacro MUI_LANGUAGE "English"
396391
397392
Function .onInit
398393
394+
StrCpy `$ReposDir "`${PICO_REPOS_DIR}"
395+
396+
ReadRegStr `$R0 HKCU "`${PICO_REG_KEY}" "ReposPath"
397+
`${If} `$R0 != ""
398+
StrCpy `$ReposDir "`$R0"
399+
`${EndIf}
400+
401+
ClearErrors
402+
`${GetParameters} `$R1
403+
`${GetOptions} "`$R1" "/REPOSDIR=" `$R0
404+
`${IfNot} `${Errors}
405+
StrCpy `$ReposDir "`$R0"
406+
`${EndIf}
407+
408+
DetailPrint "Repos path: `$ReposDir"
409+
399410
SetShellVarContext all
400411
SetRegView $bitness
401412
@@ -430,10 +441,8 @@ Section
430441
; Save install paths in the 32-bit registry for ease of access from NSIS (un)installers
431442
SetRegView 32
432443
WriteRegStr `${PICO_REG_ROOT} "`${PICO_REG_KEY}" "InstallPath" "`$INSTDIR"
433-
WriteRegStr `${PICO_REG_ROOT} "`${PICO_REG_KEY}" "ReposPath" "`${PICO_REPOS_DIR}"
434444
SetRegView $bitness
435445
436-
CreateDirectory "`${PICO_REPOS_DIR}"
437446
CreateDirectory "`${PICO_SHORTCUTS_DIR}"
438447
439448
SetOutPath `$INSTDIR\resources
@@ -510,18 +519,9 @@ SectionEnd
510519
511520
Section "-Pico environment" SecPico
512521
513-
SetOutPath "`${PICO_REPOS_DIR}\pico-sdk"
522+
SetOutPath "`$INSTDIR\pico-sdk"
514523
File /r "build\pico-sdk\*.*"
515524
516-
SetOutPath "`${PICO_REPOS_DIR}\pico-examples"
517-
File /r "build\pico-examples\*.*"
518-
SetOutPath "`${PICO_REPOS_DIR}\pico-examples\.vscode"
519-
File "packages\pico-examples\ide\vscode\cmake-kits.json"
520-
File "packages\pico-examples\ide\vscode\extensions.json"
521-
File "packages\pico-examples\ide\vscode\launch.json"
522-
File "packages\pico-examples\ide\vscode\settings.json"
523-
File "packages\pico-examples\ide\vscode\tasks.json"
524-
525525
SetOutPath "`$INSTDIR\pico-sdk-tools"
526526
File "build\pico-sdk-tools\mingw$bitness\*.*"
527527
WriteRegStr `${PICO_REG_ROOT} "Software\Kitware\CMake\Packages\pico-sdk-tools" "v$sdkVersion" "`$INSTDIR\pico-sdk-tools"
@@ -530,15 +530,15 @@ Section "-Pico environment" SecPico
530530
File "build\picotool-install\mingw$bitness\*.*"
531531
532532
SetOutPath "`$INSTDIR"
533+
File "build\pico-examples.zip"
533534
WriteINIStr "`$INSTDIR\version.ini" "pico-setup-windows" "PICO_SDK_VERSION" "$sdkVersion"
534-
WriteINIStr "`$INSTDIR\version.ini" "pico-setup-windows" "PICO_REPOS_PATH" "`${PICO_REPOS_DIR}"
535535
WriteINIStr "`$INSTDIR\version.ini" "pico-setup-windows" "PICO_INSTALL_PATH" "`$INSTDIR"
536+
WriteINIStr "`$INSTDIR\version.ini" "pico-setup-windows" "PICO_REG_KEY" "`${PICO_REG_KEY}"
536537
File "packages\pico-setup-windows\pico-code.ps1"
537538
File "packages\pico-setup-windows\pico-env.ps1"
538539
File "packages\pico-setup-windows\pico-env.cmd"
539540
File "packages\pico-setup-windows\pico-setup.cmd"
540541
File "build\ReadMe.txt"
541-
CreateShortcut "`$INSTDIR\pico-setup.lnk" "cmd.exe" '/k call "`$INSTDIR\pico-setup.cmd" 1'
542542
543543
File /oname=uninstall.exe "build\uninstall-$suffix.exe"
544544
WriteRegStr `${PICO_REG_ROOT} "`${UNINSTALL_KEY}" "DisplayName" "$product"
@@ -563,29 +563,26 @@ Section "-Pico environment" SecPico
563563
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
564564
`${EndIf}
565565
566-
; Set the working directory for our terminals to the repos directory
567-
SetOutPath "`${PICO_REPOS_DIR}"
568566
`${CreateShortcutEx} "`${PICO_SHORTCUTS_DIR}\Pico - Developer Command Prompt.lnk" "`${PICO_AppUserModel_ID}!cmd" ``"cmd.exe" '/k "`$INSTDIR\pico-env.cmd"'``
569567
`${CreateShortcutEx} "`${PICO_SHORTCUTS_DIR}\Pico - Developer PowerShell.lnk" "`${PICO_AppUserModel_ID}!powershell" ``"powershell.exe" '-NoExit -ExecutionPolicy Bypass -File "`$INSTDIR\pico-env.ps1"'``
570568
`${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``
571569
572570
SetOutPath "`${PICO_WINTERM_DIR}"
573571
`${WordReplace} "`$INSTDIR" "\" "\\" "+" `$7
574-
`${WordReplace} "`${PICO_REPOS_DIR}" "\" "\\" "+" `$8
575572
$( @"
576573
{
577574
"profiles": [
578575
{
579576
"name": "Pico - Developer Command Prompt (SDK v$sdkVersion)",
580577
"commandline": "cmd.exe /k \"`$7\\pico-env.cmd\"",
581578
"icon": "`$7\\resources\\raspberrypi.ico",
582-
"startingDirectory": "`$8"
579+
"startingDirectory": "`$7"
583580
},
584581
{
585582
"name": "Pico - Developer PowerShell (SDK v$sdkVersion)",
586583
"commandline": "powershell.exe -NoExit -ExecutionPolicy Bypass -File \"`$7\\pico-env.ps1\"",
587584
"icon": "`$7\\resources\\raspberrypi.ico",
588-
"startingDirectory": "`$8"
585+
"startingDirectory": "`$7"
589586
}
590587
]
591588
}
@@ -607,6 +604,8 @@ Function RunBuild
607604
; We need to run pico-setup.cmd un-elevated, to avoid problems with builds later on.
608605
; So we create a shortcut with the command line to use, and have explorer.exe launch it.
609606
; http://mdb-blog.blogspot.com/2013/01/nsis-lunch-program-as-user-from-uac.html
607+
SetShellVarContext current
608+
CreateShortcut "`$INSTDIR\pico-setup.lnk" "cmd.exe" '/k call "`$INSTDIR\pico-setup.cmd" "`$ReposDir" 1'
610609
Exec '"`$WINDIR\explorer.exe" "`$INSTDIR\pico-setup.lnk"'
611610
612611
FunctionEnd
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
!define MUI_FINISHPAGE_NOREBOOTSUPPORT
2+
!define MUI_PAGE_CUSTOMFUNCTION_SHOW OnFinishPageShow
3+
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE OnFinishPageLeave
4+
5+
Var FinishPage.CloneCheckbox
6+
Var FinishPage.ReposDirTextBox
7+
Var FinishPage.BrowseButton
8+
9+
Function OnFinishPageShow
10+
11+
${NSD_CreateCheckbox} 120u 110u 195u 10u "Clone and build examples in this folder:"
12+
Pop $FinishPage.CloneCheckbox
13+
SetCtlColors $FinishPage.CloneCheckbox "${MUI_TEXTCOLOR}" "${MUI_BGCOLOR}"
14+
${NSD_SetState} $FinishPage.CloneCheckbox ${BST_CHECKED}
15+
${NSD_OnClick} $FinishPage.CloneCheckbox OnCloneCheckboxChange
16+
17+
${NSD_CreateText} 120u 130u 125u 12u "$ReposDir"
18+
Pop $FinishPage.ReposDirTextBox
19+
SetCtlColors $FinishPage.ReposDirTextBox "${MUI_TEXTCOLOR}" "${MUI_BGCOLOR}"
20+
21+
${NSD_CreateButton} 255u 128u 60u 15u "Browse..."
22+
Pop $FinishPage.BrowseButton
23+
${NSD_OnClick} $FinishPage.BrowseButton OnBrowseButtonClick
24+
25+
FunctionEnd
26+
27+
Function OnCloneCheckboxChange
28+
29+
Pop $R0
30+
${NSD_GetState} $R0 $R1
31+
${If} $R1 == ${BST_CHECKED}
32+
StrCpy $R2 1
33+
${Else}
34+
StrCpy $R2 0
35+
${EndIf}
36+
EnableWindow $FinishPage.ReposDirTextBox $R2
37+
EnableWindow $FinishPage.BrowseButton $R2
38+
39+
FunctionEnd
40+
41+
Function OnBrowseButtonClick
42+
43+
Pop $R0
44+
${NSD_GetText} $FinishPage.ReposDirTextBox $R1
45+
nsDialogs::SelectFolderDialog "Select example code folder" "$R1"
46+
Pop $R1
47+
${If} "$R1" != "error"
48+
${NSD_SetText} $FinishPage.ReposDirTextBox "$R1"
49+
${EndIf}
50+
51+
FunctionEnd
52+
53+
Function OnFinishPageLeave
54+
55+
${NSD_GetState} $FinishPage.CloneCheckbox $R1
56+
${If} $R1 == ${BST_CHECKED}
57+
${NSD_GetText} $FinishPage.ReposDirTextBox $ReposDir
58+
Call ${FINISHPAGE_RUN_FUNCTION}
59+
${EndIf}
60+
61+
FunctionEnd

packages/pico-setup-windows/pico-code.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ $ProgressPreference = 'SilentlyContinue'
66

77
# On first run, open the pico-examples repo. Open a blank VS Code instance otherwise.
88
$openArgs = "--disable-workspace-trust --new-window `"$env:PICO_EXAMPLES_PATH`""
9-
$regPath = "HKCU:\Software\Raspberry Pi\Pico SDK v$env:PICO_SDK_VERSION"
9+
$regPath = "HKCU:\$env:PICO_REG_KEY"
1010

1111
if (-not (Test-Path $regPath)) {
1212
New-Item -Path $regPath -Force

packages/pico-setup-windows/pico-env.cmd

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ goto main
2222

2323
goto :EOF
2424

25+
:SetEnvFromRegistry
26+
27+
rem https://stackoverflow.com/questions/22352793/reading-a-registry-value-to-a-batch-variable-handling-spaces-in-value
28+
for /f "usebackq tokens=2,*" %%h in (
29+
`"reg query "HKCU\%PICO_REG_KEY%" /v "%1Path" 2>NUL | find /i "%1Path""`
30+
) do (
31+
echo PICO_%1_PATH=%%i
32+
set "PICO_%1_PATH=%%i"
33+
)
34+
35+
goto :EOF
36+
2537
:main
2638

2739
pushd "%~dp0"
@@ -31,12 +43,22 @@ for /f "skip=1 tokens=*" %%i in (version.ini) do (
3143
set "%%i"
3244
)
3345

46+
popd
47+
3448
if not defined PICO_SDK_VERSION (
3549
echo ERROR: Unable to determine Pico SDK version.
3650
set /a errors += 1
3751
)
3852

39-
for %%i in (sdk examples extras playground) do (
53+
if "%~1" neq "" (
54+
reg add "HKCU\%PICO_REG_KEY%" /v ReposPath /d "%~1" /f
55+
)
56+
57+
set "PICO_SDK_PATH=%PICO_INSTALL_PATH%\pico-sdk"
58+
59+
call :SetEnvFromRegistry repos
60+
61+
for %%i in (examples extras playground) do (
4062
rem Environment variables in Windows aren't case-sensitive, so we don't need
4163
rem to bother with uppercasing the env var name.
4264
if exist "%PICO_REPOS_PATH%\pico-%%i" (
@@ -45,8 +67,6 @@ for %%i in (sdk examples extras playground) do (
4567
)
4668
)
4769

48-
popd
49-
5070
if exist "%PICO_INSTALL_PATH%\openocd" (
5171
echo OPENOCD_SCRIPTS=%PICO_INSTALL_PATH%\openocd\scripts
5272
set "OPENOCD_SCRIPTS=%PICO_INSTALL_PATH%\openocd\scripts"

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
set interactive=%~1
1+
@if not defined _echo echo off
22

3-
call "%~dp0pico-env.cmd" || exit /b 1
3+
set interactive=%~2
4+
5+
mkdir "%~1"
6+
echo Copying pico-examples...
7+
powershell -NoProfile -ExecutionPolicy Bypass -Command "Expand-Archive """%~dp0pico-examples.zip""" -DestinationPath """%~1""" -Force" || exit /b 1
8+
9+
call "%~dp0pico-env.cmd" "%~1" || exit /b 1
410
setlocal enabledelayedexpansion
511

612
rem This is mostly a port of pico-setup
@@ -12,7 +18,7 @@ set "SDK_BRANCH=master"
1218

1319
pushd "%PICO_REPOS_PATH%"
1420

15-
for %%i in (sdk examples extras playground project-generator) do (
21+
for %%i in (examples extras playground) do (
1622
set "DEST=%PICO_REPOS_PATH%\pico-%%i"
1723

1824
if exist "!DEST!\.git" (

0 commit comments

Comments
 (0)