-
Notifications
You must be signed in to change notification settings - Fork 1
/
ProcessEnvAppendPath.nsh
80 lines (61 loc) · 1.95 KB
/
ProcessEnvAppendPath.nsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
; Code from http://stackoverflow.com/questions/32382784/nsi-script-to-equivalent-to-bat-script/32384667#32384667
!define ERROR_ENVVAR_NOT_FOUND 203
!if "${NSIS_PTR_SIZE}" <= 4
!include LogicLib.nsh
!macro ProcessEnvAppendPath un
Function ${un}ProcessEnvAppendPath ; IN:Path OUT:N/A
System::Store S
Pop $1
System::Call 'KERNEL32::GetEnvironmentVariable(t "PATH", t, i0)i.r0'
${If} $0 = 0
System::Call 'KERNEL32::SetEnvironmentVariable(t "PATH", tr1)'
${Else}
StrLen $2 $1
System::Call '*(&t$0,&t1,&t$2)i.r9'
System::Call 'KERNEL32::GetEnvironmentVariable(t "PATH", ir9, ir0)i.r0'
StrCpy $2 0
${IfThen} $0 > 0 ${|} IntOp $2 $0 - 1 ${|}
System::Call '*$9(&t$2,&t1.r2)' ; Store the last character from %PATH% in $2
StrCpy $3 ';'
${IfThen} $2 == ';' ${|} StrCpy $3 "" ${|}
System::Call 'KERNEL32::lstrcat(ir9, tr3)' ; Append ";" or ""
System::Call 'KERNEL32::lstrcat(ir9, tr1)'
System::Call 'KERNEL32::SetEnvironmentVariable(t "PATH", ir9)'
System::Free $9
${EndIf}
System::Store L
FunctionEnd
!macroend
!insertmacro ProcessEnvAppendPath ""
!insertmacro ProcessEnvAppendPath "un."
!endif
!macro SetEnvironmentVariable un
Function ${un}SetEnvironmentVariable ; IN:name, value OUT:N/A
System::Store S
Pop $2
Pop $1
System::Call 'KERNEL32::SetEnvironmentVariable(tr1, tr2)'
System::Store L
FunctionEnd
!macroend
!insertmacro SetEnvironmentVariable ""
!insertmacro SetEnvironmentVariable "un."
!macro GetEnvironmentVariable un
Function ${un}GetEnvironmentVariable ; IN:name OUT:value
System::Store S
Pop $1
System::Call 'KERNEL32::GetEnvironmentVariable(tr1, t, i0)i.r0'
${If} $0 = 0
Push ""
${Else}
System::Call '*(&t$0)i.r9'
System::Call 'KERNEL32::GetEnvironmentVariable(tr1, ir9, ir0)i.r0'
StrCpy $2 0
System::Call '*$9(&t$2,&t$0.r2)' ; Store all the characters in $2
Push $2
${EndIf}
System::Store L
FunctionEnd
!macroend
!insertmacro GetEnvironmentVariable ""
!insertmacro GetEnvironmentVariable "un."