1
1
# 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
3
3
4
4
5
5
; --------------------------------------------------------------------
@@ -44,16 +44,19 @@ Function AddToPath
44
44
System::Call " advapi32::RegQueryValueEx(i $3, t'PATH', i 0, i 0, t.r1, *i ${NSIS_MAX_STRLEN} r2) i.r4"
45
45
System::Call " advapi32::RegCloseKey(i $3)"
46
46
47
- IntCmp $4 234 0 + 4 + 4 ; $4 == ERROR_MORE_DATA
47
+ ${If} $4 = 234 ; ERROR_MORE_DATA
48
48
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
50
50
Goto done
51
+ ${EndIf}
51
52
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
54
55
DetailPrint " AddToPath: unexpected error code $4"
55
56
Goto done
57
+ ${EndIf}
56
58
StrCpy $1 " "
59
+ ${EndIf}
57
60
58
61
; Check if already in PATH
59
62
Push " $1;"
@@ -72,18 +75,21 @@ Function AddToPath
72
75
StrLen $3 $1
73
76
IntOp $2 $2 + $3
74
77
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}
76
79
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
78
81
Goto done
82
+ ${EndIf}
79
83
80
84
; Append dir to PATH
81
85
DetailPrint " Add to PATH: $0"
82
86
StrCpy $2 $1 1 -1
83
- StrCmp $2 " ;" 0 + 2
87
+ ${If} $2 == " ;"
84
88
StrCpy $1 $1 -1 ; remove trailing ';'
85
- StrCmp $1 " " +2 ; no leading ';'
89
+ ${EndIf}
90
+ ${If} $1 != " " ; no leading ';'
86
91
StrCpy $0 " $1;$0"
92
+ ${EndIf}
87
93
WriteRegExpandStr ${Environ} " PATH" $0
88
94
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 " STR:Environment" /TIMEOUT= 5000
89
95
@@ -113,8 +119,9 @@ Function un.RemoveFromPath
113
119
114
120
ReadRegStr $1 ${Environ} " PATH"
115
121
StrCpy $5 $1 1 -1
116
- StrCmp $5 " ;" + 2
122
+ ${If} $5 != " ;"
117
123
StrCpy $1 " $1;" ; ensure trailing ';'
124
+ ${EndIf}
118
125
Push $1
119
126
Push " $0;"
120
127
Call un.StrStr
@@ -128,8 +135,9 @@ Function un.RemoveFromPath
128
135
StrCpy $6 $2 " " $3 ; $6 is now the part after the path to remove
129
136
StrCpy $3 " $5$6"
130
137
StrCpy $5 $3 1 -1
131
- StrCmp $5 " ;" 0 + 2
138
+ ${If} $5 == " ;"
132
139
StrCpy $3 $3 -1 ; remove trailing ';'
140
+ ${EndIf}
133
141
WriteRegExpandStr ${Environ} " PATH" $3
134
142
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 " STR:Environment" /TIMEOUT= 5000
135
143
@@ -164,13 +172,12 @@ Function ${un}StrStr
164
172
StrCpy $R4 0
165
173
; $R1=substring, $R2=string, $R3=strlen(substring)
166
174
; $R4=count, $R5=tmp
167
- loop:
175
+ ${Do}
168
176
StrCpy $R5 $R2 $R3 $R4
169
- StrCmp $R5 $R1 done
170
- StrCmp $R5 " " done
177
+ ${IfThen} $R5 == $R1 ${|} ${ExitDo} ${|}
178
+ ${IfThen} $R5 == " " ${|} ${ExitDo} ${|}
171
179
IntOp $R4 $R4 + 1
172
- Goto loop
173
- done:
180
+ ${Loop}
174
181
StrCpy $R1 $R2 " " $R4
175
182
Pop $R5
176
183
Pop $R4
0 commit comments