Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit aa9af6a

Browse files
committed
chore: update nsis AddToPath implementation
1 parent 466b0d3 commit aa9af6a

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

scripts/installer/path.nsh

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# PATH utilities. Taken from:
2-
# https://www.smartmontools.org/browser/trunk/smartmontools/os_win32/installer.nsi?rev=4110#L619
2+
# https://www.smartmontools.org/browser/trunk/smartmontools/os_win32/installer.nsi?rev=5310#L689
33

44

55
;--------------------------------------------------------------------
@@ -44,16 +44,19 @@ Function AddToPath
4444
System::Call "advapi32::RegQueryValueEx(i $3, t'PATH', i 0, i 0, t.r1, *i ${NSIS_MAX_STRLEN} r2) i.r4"
4545
System::Call "advapi32::RegCloseKey(i $3)"
4646

47-
IntCmp $4 234 0 +4 +4 ; $4 == ERROR_MORE_DATA
47+
${If} $4 = 234 ; ERROR_MORE_DATA
4848
DetailPrint "AddToPath: original length $2 > ${NSIS_MAX_STRLEN}"
49-
MessageBox MB_OK "PATH not updated, original length $2 > ${NSIS_MAX_STRLEN}"
49+
MessageBox MB_OK "PATH not updated, original length $2 > ${NSIS_MAX_STRLEN}" /SD IDOK
5050
Goto done
51+
${EndIf}
5152

52-
IntCmp $4 0 +5 ; $4 != NO_ERROR
53-
IntCmp $4 2 +3 ; $4 != ERROR_FILE_NOT_FOUND
53+
${If} $4 <> 0 ; NO_ERROR
54+
${If} $4 <> 2 ; ERROR_FILE_NOT_FOUND
5455
DetailPrint "AddToPath: unexpected error code $4"
5556
Goto done
57+
${EndIf}
5658
StrCpy $1 ""
59+
${EndIf}
5760

5861
; Check if already in PATH
5962
Push "$1;"
@@ -72,18 +75,21 @@ Function AddToPath
7275
StrLen $3 $1
7376
IntOp $2 $2 + $3
7477
IntOp $2 $2 + 2 ; $2 = strlen(dir) + strlen(PATH) + sizeof(";")
75-
IntCmp $2 ${NSIS_MAX_STRLEN} +4 +4 0
78+
${If} $2 > ${NSIS_MAX_STRLEN}
7679
DetailPrint "AddToPath: new length $2 > ${NSIS_MAX_STRLEN}"
77-
MessageBox MB_OK "PATH not updated, new length $2 > ${NSIS_MAX_STRLEN}."
80+
MessageBox MB_OK "PATH not updated, new length $2 > ${NSIS_MAX_STRLEN}." /SD IDOK
7881
Goto done
82+
${EndIf}
7983

8084
; Append dir to PATH
8185
DetailPrint "Add to PATH: $0"
8286
StrCpy $2 $1 1 -1
83-
StrCmp $2 ";" 0 +2
87+
${If} $2 == ";"
8488
StrCpy $1 $1 -1 ; remove trailing ';'
85-
StrCmp $1 "" +2 ; no leading ';'
89+
${EndIf}
90+
${If} $1 != "" ; no leading ';'
8691
StrCpy $0 "$1;$0"
92+
${EndIf}
8793
WriteRegExpandStr ${Environ} "PATH" $0
8894
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
8995

@@ -113,8 +119,9 @@ Function un.RemoveFromPath
113119

114120
ReadRegStr $1 ${Environ} "PATH"
115121
StrCpy $5 $1 1 -1
116-
StrCmp $5 ";" +2
122+
${If} $5 != ";"
117123
StrCpy $1 "$1;" ; ensure trailing ';'
124+
${EndIf}
118125
Push $1
119126
Push "$0;"
120127
Call un.StrStr
@@ -128,8 +135,9 @@ Function un.RemoveFromPath
128135
StrCpy $6 $2 "" $3 ; $6 is now the part after the path to remove
129136
StrCpy $3 "$5$6"
130137
StrCpy $5 $3 1 -1
131-
StrCmp $5 ";" 0 +2
138+
${If} $5 == ";"
132139
StrCpy $3 $3 -1 ; remove trailing ';'
140+
${EndIf}
133141
WriteRegExpandStr ${Environ} "PATH" $3
134142
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
135143

@@ -164,13 +172,12 @@ Function ${un}StrStr
164172
StrCpy $R4 0
165173
; $R1=substring, $R2=string, $R3=strlen(substring)
166174
; $R4=count, $R5=tmp
167-
loop:
175+
${Do}
168176
StrCpy $R5 $R2 $R3 $R4
169-
StrCmp $R5 $R1 done
170-
StrCmp $R5 "" done
177+
${IfThen} $R5 == $R1 ${|} ${ExitDo} ${|}
178+
${IfThen} $R5 == "" ${|} ${ExitDo} ${|}
171179
IntOp $R4 $R4 + 1
172-
Goto loop
173-
done:
180+
${Loop}
174181
StrCpy $R1 $R2 "" $R4
175182
Pop $R5
176183
Pop $R4

0 commit comments

Comments
 (0)