Skip to content

Commit 21e4ea2

Browse files
authored
fix(nsis): implement custom function to handle /D parameter with spaces (electron-userland#9196)
1 parent c9480bc commit 21e4ea2

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

.changeset/famous-berries-clap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"app-builder-lib": patch
3+
---
4+
5+
fix(nsis): implement custom function to handle /D parameter with spaces

packages/app-builder-lib/templates/nsis/multiUser.nsh

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Var installMode
4141
${endif}
4242

4343
# allow /D switch to override installation path https://github.com/electron-userland/electron-builder/issues/1551
44-
${StdUtils.GetParameter} $R0 "D" ""
44+
!insertmacro GetDParameter $R0
4545
${If} $R0 != ""
4646
StrCpy $INSTDIR $R0
4747
${endif}
@@ -84,10 +84,51 @@ Var installMode
8484
${endif}
8585

8686
# allow /D switch to override installation path https://github.com/electron-userland/electron-builder/issues/1551
87-
${StdUtils.GetParameter} $R0 "D" ""
87+
!insertmacro GetDParameter $R0
8888
${If} $R0 != ""
8989
StrCpy $INSTDIR $R0
9090
${endif}
9191

9292
!macroend
9393
!endif
94+
95+
# Custom function to handle /D parameter with spaces
96+
# The /D parameter is special in NSIS - it must be the last parameter and cannot have quotes
97+
# Use StdUtils.GetParameter to get the full command line, then parse /D= manually
98+
!macro GetDParameter outVar
99+
Push $R8
100+
Push $R9
101+
Push $R7
102+
Push $R6
103+
Push $R5
104+
105+
# Get the complete command line using StdUtils (including /D parameter)
106+
${StdUtils.GetAllParameters} $R8 "0"
107+
108+
# Initialize result
109+
StrCpy $R9 ""
110+
111+
# Search for /D= or /d= using a simple loop
112+
StrLen $R7 $R8
113+
IntOp $R7 $R7 - 2 # Don't check last 2 characters
114+
StrCpy $R6 0
115+
116+
${Do}
117+
StrCpy $R5 $R8 3 $R6 # Get 3 characters starting at position $R6
118+
${If} $R5 == "/D="
119+
${OrIf} $R5 == "/d="
120+
# Found /D= or /d=, extract everything after it
121+
IntOp $R6 $R6 + 3
122+
StrCpy $R9 $R8 "" $R6
123+
${Break}
124+
${EndIf}
125+
IntOp $R6 $R6 + 1
126+
${LoopUntil} $R6 > $R7
127+
128+
StrCpy ${outVar} $R9
129+
Pop $R5
130+
Pop $R6
131+
Pop $R7
132+
Pop $R9
133+
Pop $R8
134+
!macroend

0 commit comments

Comments
 (0)