-
Notifications
You must be signed in to change notification settings - Fork 25
/
nsf2x.nsi
251 lines (208 loc) · 6.8 KB
/
nsf2x.nsi
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
!define NAME "nsf2x"
!ifndef VERSION
!define VERSION "X.X.X"
!endif
!ifndef PUBLISHER
!define PUBLISHER "root@localhost"
!endif
!ifndef BITNESS
!define BITNESS "x86"
!endif
!define UNINSTKEY "${NAME}-${VERSION}-${BITNESS}"
!define DEFAULTNORMALDESTINATON "$ProgramFiles\${NAME}-${VERSION}-${BITNESS}"
!define DEFAULTPORTABLEDESTINATON "$LocalAppdata\Programs\${NAME}-${VERSION}-${BITNESS}"
; Keep NSIS v3.0 Happy
Unicode true
ManifestDPIAware true
Name "${NAME}"
Outfile "${NAME}-${VERSION}-${BITNESS}-setup.exe"
RequestExecutionlevel highest
SetCompressor LZMA
Var NormalDestDir
Var LocalDestDir
Var InstallAllUsers
Var InstallAllUsersCtrl
Var InstallShortcuts
Var InstallShortcutsCtrl
!include LogicLib.nsh
!include FileFunc.nsh
!include MUI2.nsh
!include nsDialogs.nsh
!include registry.nsh
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "LICENSE"
Page Custom OptionsPageCreate OptionsPageLeave
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!define MUI_FINISHPAGE_SHOWREADME $INSTDIR\README.txt
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
!include "nsf2x_lang.nsi"
Function .onInit
StrCpy $NormalDestDir "${DEFAULTNORMALDESTINATON}"
StrCpy $LocalDestDir "${DEFAULTPORTABLEDESTINATON}"
${GetParameters} $9
ClearErrors
${GetOptions} $9 "/?" $8
${IfNot} ${Errors}
MessageBox MB_ICONINFORMATION|MB_SETFOREGROUND "$(COMMANDLINE_HELP)"
Quit
${EndIf}
ClearErrors
${GetOptions} $9 "/ALL" $8
${IfNot} ${Errors}
StrCpy $0 $NormalDestDir
${If} ${Silent}
Call RequireAdmin
${EndIf}
SetShellVarContext all
StrCpy $InstallAllUsers ${BST_CHECKED}
${Else}
SetShellVarContext current
StrCpy $0 $LocalDestDir
StrCpy $InstallAllUsers ${BST_UNCHECKED}
${EndIf}
${GetOptions} $9 "/SHORTCUT" $8
${IfNot} ${Errors}
StrCpy $InstallShortCuts ${BST_CHECKED}
${Else}
StrCpy $InstallShortCuts ${BST_UNCHECKED}
${EndIf}
${If} $InstDir == ""
; User did not use /D to specify a directory,
; we need to set a default based on the install mode
StrCpy $InstDir $0
${EndIf}
Call SetModeDestinationFromInstdir
FunctionEnd
Function RequireAdmin
UserInfo::GetAccountType
Pop $8
${If} $8 != "admin"
MessageBox MB_ICONSTOP "$(ADMIN_RIGHTS)"
SetErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
Abort
${EndIf}
FunctionEnd
Function SetModeDestinationFromInstdir
${If} $InstallAllUsers == ${BST_CHECKED}
StrCpy $NormalDestDir $InstDir
${Else}
StrCpy $LocalDestDir $InstDir
${EndIf}
FunctionEnd
Function OptionsPageCreate
!insertmacro MUI_HEADER_TEXT "$(INSTALL_MODE)" "$(INSTALL_CHOOSE)"
Push $0
nsDialogs::Create 1018
Pop $0
${If} $0 == error
Abort
${EndIf}
Call SetModeDestinationFromInstdir ; If the user clicks BACK on the directory page we will remember their mode specific directory
${NSD_CreateCheckBox} 0 0 100% 12u "$(INSTALL_ADMIN)"
Pop $InstallAllUsersCtrl
UserInfo::GetAccountType
Pop $8
${If} $8 != "admin"
${NSD_SetState} $InstallAllUsersCtrl ${BST_UNCHECKED}
${Else}
${NSD_SetState} $InstallAllUsersCtrl ${BST_CHECKED}
${EndIf}
${NSD_CreateCheckBox} 0 20 100% 12u "$(INSTALL_SHORTCUT)"
Pop $InstallShortcutsCtrl
${NSD_SetState} $InstallShortcutsCtrl ${BST_CHECKED}
nsDialogs::Show
FunctionEnd
Function OptionsPageLeave
${NSD_GetState} $InstallAllUsersCtrl $InstallAllUsers
${NSD_GetState} $InstallShortcutsCtrl $InstallShortcuts
${If} $InstallAllUsers == ${BST_CHECKED}
StrCpy $InstDir $NormalDestDir
Call RequireAdmin
SetShellVarContext all
${Else}
StrCpy $InstDir $LocalDestDir
SetShellVarContext current
${EndIf}
; Check to see if already installed
ReadRegStr $R0 SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${UNINSTKEY}" "UninstallString"
${If} $R0 != ""
MessageBox MB_OKCANCEL|MB_TOPMOST "$(ALREADY_INSTALLED)" IDOK Ok IDCANCEL Cancel
Cancel:
Quit
Ok:
; Use SilentMode for the uninstall so that we can wait on the termination
${If} $InstallAllUsers == ${BST_CHECKED}
ExecWait "$R0 /S /ALL"
${Else}
ExecWait "$R0 /S"
${EndIf}
${EndIf}
FunctionEnd
Section "Install"
SetOutPath "$InstDir"
File /r dist\*
WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${UNINSTKEY}" "DisplayName" "${NAME}"
WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${UNINSTKEY}" "DisplayVersion" "${VERSION}"
WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${UNINSTKEY}" "Publisher" "${PUBLISHER}"
${If} $InstallAllUsers == ${BST_CHECKED}
WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${UNINSTKEY}" "UninstallString" '"$InstDir\uninstall.exe" /ALL'
${Else}
WriteRegStr SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${UNINSTKEY}" "UninstallString" '"$InstDir\uninstall.exe" /USER'
${EndIf}
${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
IntFmt $0 "0x%08X" $0
WriteRegDWORD SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${UNINSTKEY}" "EstimatedSize" "$0"
WriteUninstaller "$InstDir\uninstall.exe"
SectionEnd
Section "Shortcuts"
CreateDirectory "$SMPROGRAMS\${NAME}-${VERSION}"
CreateShortCut "$SMPROGRAMS\${NAME}-${VERSION}\nsf2x.lnk" "$InstDir\nsf2x.exe" "" "" 0
CreateShortCut "$SMPROGRAMS\${NAME}-${VERSION}\README.lnk" "$InstDir\README.txt" "" "" 0
${If} $InstallAllUsers == ${BST_CHECKED}
CreateShortCut "$SMPROGRAMS\${NAME}-${VERSION}\uninstall.lnk" "$InstDir\uninstall.exe" "/ALL" "" 0
${Else}
CreateShortCut "$SMPROGRAMS\${NAME}-${VERSION}\uninstall.lnk" "$InstDir\uninstall.exe" "/USER" "" 0
${EndIf}
${If} $InstallShortCuts == ${BST_CHECKED}
Delete "$DESKTOP\${NAME}.lnk"
CreateShortCut "$DESKTOP\${NAME}.lnk" "$InstDir\nsf2x.exe" "" "" 0
${Endif}
SectionEnd
Function un.onInit
${GetParameters} $9
ClearErrors
${GetOptions} $9 "/?" $8
${IfNot} ${Errors}
MessageBox MB_ICONINFORMATION|MB_SETFOREGROUND "$(COMMANDLINE_HELP2)"
Quit
${EndIf}
ReadRegStr $R0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${UNINSTKEY}" "UninstallString"
${If} $R0 != ""
SetShellVarContext all
${Else}
SetShellVarContext current
${EndIf}
ClearErrors
${GetOptions} $9 "/ALL" $8
${IfNot} ${Errors}
SetShellVarContext all
${EndIf}
${GetOptions} $9 "/USER" $8
${IfNot} ${Errors}
SetShellVarContext current
${EndIf}
FunctionEnd
Section "Uninstall"
DeleteRegKey SHCTX "Software\Microsoft\Windows\CurrentVersion\Uninstall\${UNINSTKEY}"
RMDir /r "$SMPROGRAMS\${NAME}-${VERSION}"
RMDir "$SMPROGRAMS\${NAME}-${VERSION}"
Delete "$InstDir\uninstall.exe"
RMDir /r "$InstDir"
RMDir "$InstDir"
Delete "$DESKTOP\${NAME}.lnk"
SectionEnd