-
-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathinstaller.nsh
More file actions
127 lines (100 loc) · 2.94 KB
/
Copy pathinstaller.nsh
File metadata and controls
127 lines (100 loc) · 2.94 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
!include "nsDialogs.nsh"
!define ELECAP_REG_KEY "Software\ElectronCapture"
!define ELECAP_PATH_HELPER_TARGET "$INSTDIR\resources\installer-user-path.ps1"
!ifndef BUILD_UNINSTALLER
Var AddToPathCheckbox
Var AddToPathSelection
!macro customInit
; PATH changes are opt-in. Preserve the choice only when this installer manages an existing entry.
StrCpy $AddToPathSelection 0
ClearErrors
ReadRegStr $0 HKCU "${ELECAP_REG_KEY}" "PathEntry"
IfErrors 0 +2
StrCpy $0 ""
StrCmp $0 "" +2 0
StrCpy $AddToPathSelection 1
!macroend
!macro customPageAfterChangeDir
Page custom AddToPathPageCreate AddToPathPageLeave
!macroend
Function AddToPathPageCreate
nsDialogs::Create 1018
Pop $0
StrCmp $0 error 0 +2
Abort
${NSD_CreateLabel} 0 0 100% 24u "Optional setup step: make Electron Capture available from Command Prompt and PowerShell."
Pop $0
${NSD_CreateCheckbox} 0 32u 100% 12u "Add the install directory to my user PATH"
Pop $AddToPathCheckbox
${NSD_SetState} $AddToPathCheckbox $AddToPathSelection
${NSD_CreateLabel} 0 54u 100% 28u "This allows you to run elecap from a new terminal. The entry is removed when you uninstall."
Pop $0
nsDialogs::Show
FunctionEnd
Function AddToPathPageLeave
${NSD_GetState} $AddToPathCheckbox $AddToPathSelection
FunctionEnd
!macro AddPathHelperFile
Push $0
StrCpy $0 $OUTDIR
SetOutPath "$INSTDIR\resources"
File "/oname=installer-user-path.ps1" "${PROJECT_DIR}\scripts\installer-user-path.ps1"
SetOutPath "$0"
Pop $0
!macroend
!macro customFiles_x64
!insertmacro AddPathHelperFile
!macroend
!macro customFiles_ia32
!insertmacro AddPathHelperFile
!macroend
!macro customFiles_arm64
!insertmacro AddPathHelperFile
!macroend
Function RunPathHelper
Exch $0
Push $1
Push $2
StrCpy $1 "${ELECAP_PATH_HELPER_TARGET}"
IfFileExists "$1" 0 missing_helper
ExecWait '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$1" -Mode $0 -InstallDir "$INSTDIR" -Selected "$AddToPathSelection"' $2
Goto cleanup
missing_helper:
StrCpy $2 1
cleanup:
Pop $2
Pop $1
Pop $0
FunctionEnd
!macro customInstall
IfSilent 0 +6
ClearErrors
ReadRegStr $0 HKCU "${ELECAP_REG_KEY}" "PathEntry"
IfErrors 0 +2
StrCpy $0 ""
StrCmp $0 "" +2 0
StrCpy $AddToPathSelection 1
Push "install"
Call RunPathHelper
!macroend
!else
Function un.RunPathHelper
Exch $0
Push $1
Push $2
StrCpy $1 "${ELECAP_PATH_HELPER_TARGET}"
IfFileExists "$1" 0 missing_helper
ExecWait '"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File "$1" -Mode $0 -InstallDir "$INSTDIR" -Selected "0"' $2
Goto cleanup
missing_helper:
StrCpy $2 1
cleanup:
Pop $2
Pop $1
Pop $0
FunctionEnd
!macro customUnInstall
Push "uninstall"
Call un.RunPathHelper
!macroend
!endif