Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[01231b]: win / jags.nsi Maximize Restore History

Download this file

jags.nsi    346 lines (281 with data), 10.7 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
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
!define APP_NAME "JAGS"
!define PUBLISHER "JAGS"
;Name used for JAGS registry keys
!define JAGS_KEYNAME "${APP_NAME}-${VERSION}"
;Name visible to users, for shortcuts, installation directories, etc.
!define JAGS_VISIBLE_NAME "${APP_NAME} ${VERSION}"
!define MULTIUSER_MUI
!define MULTIUSER_EXECUTIONLEVEL Highest
!define MULTIUSER_INSTALLMODE_COMMANDLINE
!define INSTDIR_REG_ROOT "SHELL_CONTEXT"
!define INSTDIR_REG_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${JAGS_KEYNAME}"
!define MULTIUSER_INSTALLMODE_INSTDIR "${PUBLISHER}\${JAGS_KEYNAME}"
!define MULTIUSER_INSTALLMODE_INSTDIR_REGISTRY_KEY "SOFTWARE\${PUBLISHER}\${JAGS_KEYNAME}"
!define MULTIUSER_INSTDIR_REGISTRY_VALUENAME "InstallDir"
!addincludedir ${JAGSINC}
!include AdvUninstLog.nsh
!include MultiUser64.nsh
!include "MUI2.nsh"
!include "Sections.nsh"
!include "x64.nsh"
Name "${JAGS_VISIBLE_NAME}"
OutFile "${APP_NAME}-${VERSION}.exe"
Var SM_FOLDER
!define APP_REG_KEY "Software\${PUBLISHER}\${JAGS_KEYNAME}"
!define PUB_REG_KEY "Software\${PUBLISHER}"
;Start Menu Folder Page Configuration
!define MUI_STARTMENUPAGE_DEFAULTFOLDER "${APP_NAME}"
!define MUI_STARTMENUPAGE_REGISTRY_ROOT "${INSTDIR_REG_ROOT}"
!define MUI_STARTMENUPAGE_REGISTRY_KEY "${APP_REG_KEY}"
!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "StartMenuFolder"
; Installer pages
!insertmacro UNATTENDED_UNINSTALL
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE ${LICENSE}
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_STARTMENU Application $SM_FOLDER
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
; Uninstaller pages
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
!insertmacro MUI_LANGUAGE "English"
Section #Default section
SetOutPath "$INSTDIR\include"
!insertmacro UNINSTALL.LOG_OPEN_INSTALL
File inst32\include\JAGS\*.h
File /r inst32\include\JAGS\*
!insertmacro UNINSTALL.LOG_CLOSE_INSTALL
WriteRegStr ${INSTDIR_REG_ROOT} "${INSTDIR_REG_KEY}" "InstallDir" "$INSTDIR"
WriteRegStr ${INSTDIR_REG_ROOT} "${INSTDIR_REG_KEY}" "DisplayName" "${JAGS_VISIBLE_NAME}"
WriteRegStr ${INSTDIR_REG_ROOT} "${INSTDIR_REG_KEY}" "UninstallString" "${UNINST_EXE}"
WriteRegStr ${INSTDIR_REG_ROOT} "${APP_REG_KEY}" "InstallDir" "$INSTDIR"
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
CreateDirectory "$SMPROGRAMS\$SM_FOLDER"
!insertmacro MUI_STARTMENU_WRITE_END
;create shortcut for uninstaller always use ${UNINST_EXE} instead of uninstall.exe
CreateShortCut "$SMPROGRAMS\$SM_FOLDER\Uninstall ${JAGS_VISIBLE_NAME}.lnk" "${UNINST_EXE}"
SectionEnd
Section "32-bit installation" Sec32
SetOutPath "$INSTDIR\i386"
!insertmacro UNINSTALL.LOG_OPEN_INSTALL
File /r inst32\bin
!insertmacro UNINSTALL.LOG_CLOSE_INSTALL
SetOutPath "$INSTDIR\i386\bin"
!insertmacro UNINSTALL.LOG_OPEN_INSTALL
File inst32\libexec\jags-terminal.exe
!insertmacro UNINSTALL.LOG_CLOSE_INSTALL
SetOutPath "$INSTDIR\i386\lib"
!insertmacro UNINSTALL.LOG_OPEN_INSTALL
File inst32\lib\*.dll.a
File inst32\lib\*.la
!insertmacro UNINSTALL.LOG_CLOSE_INSTALL
SetOutPath "$INSTDIR\i386\modules"
!insertmacro UNINSTALL.LOG_OPEN_INSTALL
File /r inst32\lib\JAGS\modules-${MAJOR}\*
!insertmacro UNINSTALL.LOG_CLOSE_INSTALL
Push @JAGS_HOME@ #text to be replaced
Push $INSTDIR\i386 #replace with
Push all #replace all occurrences
Push all #replace all occurrences
Push $INSTDIR\i386\bin\jags.bat #file to replace in
Call AdvReplaceInFile
AccessControl::GrantOnFile "$INSTDIR\i386\bin\jags.bat" "BUILTIN\USERS" "GenericRead + GenericExecute"
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
CreateDirectory "$SMPROGRAMS\$SM_FOLDER"
# The CreateShortCut function takes the current output path to be
# the working directory for the shortcut
SetOutPath "%USERPROFILE%"
${If} ${RunningX64}
CreateShortCut "$SMPROGRAMS\$SM_FOLDER\${JAGS_VISIBLE_NAME} (32-bit).lnk" "$INSTDIR\i386\bin\jags.bat"
${Else}
CreateShortCut "$SMPROGRAMS\$SM_FOLDER\${JAGS_VISIBLE_NAME}.lnk" "$INSTDIR\i386\bin\jags.bat"
${Endif}
SetOutPath ""
!insertmacro MUI_STARTMENU_WRITE_END
SectionEnd #32-bit installation
Section "64-bit installation" Sec64
SetOutPath "$INSTDIR\x64"
!insertmacro UNINSTALL.LOG_OPEN_INSTALL
File /r inst64\bin
!insertmacro UNINSTALL.LOG_CLOSE_INSTALL
SetOutPath "$INSTDIR\x64\bin"
!insertmacro UNINSTALL.LOG_OPEN_INSTALL
File inst64\libexec\jags-terminal.exe
!insertmacro UNINSTALL.LOG_CLOSE_INSTALL
SetOutPath "$INSTDIR\x64\lib"
!insertmacro UNINSTALL.LOG_OPEN_INSTALL
File inst64\lib\*.dll.a
File inst64\lib\*.la
!insertmacro UNINSTALL.LOG_CLOSE_INSTALL
SetOutPath "$INSTDIR\x64\modules"
!insertmacro UNINSTALL.LOG_OPEN_INSTALL
File /r inst64\lib\JAGS\modules-${MAJOR}\*
!insertmacro UNINSTALL.LOG_CLOSE_INSTALL
Push @JAGS_HOME@ #text to be replaced
Push $INSTDIR\x64 #replace with
Push all #replace all occurrences
Push all #replace all occurrences
Push $INSTDIR\x64\bin\jags.bat #file to replace in
Call AdvReplaceInFile
AccessControl::GrantOnFile "$INSTDIR\x64\bin\jags.bat" "BUILTIN\USERS" "GenericRead + GenericExecute"
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
# The CreateShortCut function takes the current output path to be
# the working directory for the shortcut
SetOutPath "%USERPROFILE%"
CreateShortCut "$SMPROGRAMS\$SM_FOLDER\${JAGS_VISIBLE_NAME} (64-bit).lnk" "$INSTDIR\x64\bin\jags.bat"
SetOutPath ""
!insertmacro MUI_STARTMENU_WRITE_END
SectionEnd #64-bit installation
Function .onInit
!insertmacro MULTIUSER_INIT
!insertmacro UNINSTALL.LOG_PREPARE_INSTALL
${If} ${RunningX64}
;Nothing to do
${Else}
; Deselect and hide 64-bit section
Push $0
SectionGetFlags ${Sec64} $0
IntOp $0 $0 & ${SECTION_OFF}
SectionSetFlags ${Sec64} $0
SectionSetText ${Sec64} ""
Pop $0
${EndIf}
FunctionEnd
Function .onInstSuccess
;create/update log always within .onInstSuccess function
!insertmacro UNINSTALL.LOG_UPDATE_INSTALL
FunctionEnd
Section "Uninstall"
;uninstall from path, must be repeated for every install logged path individually
!insertmacro UNINSTALL.LOG_UNINSTALL "$INSTDIR"
!insertmacro UNINSTALL.LOG_UNINSTALL "$INSTDIR\include"
!insertmacro UNINSTALL.LOG_UNINSTALL "$INSTDIR\modules"
!insertmacro UNINSTALL.LOG_UNINSTALL "$INSTDIR\i386\bin"
!insertmacro UNINSTALL.LOG_UNINSTALL "$INSTDIR\i386\lib"
!insertmacro UNINSTALL.LOG_UNINSTALL "$INSTDIR\i386\modules"
!insertmacro UNINSTALL.LOG_UNINSTALL "$INSTDIR\x64\bin"
!insertmacro UNINSTALL.LOG_UNINSTALL "$INSTDIR\x64\lib"
!insertmacro UNINSTALL.LOG_UNINSTALL "$INSTDIR\x64\modules"
!insertmacro UNINSTALL.LOG_END_UNINSTALL
RMDir "$INSTDIR\i386"
RMDir "$INSTDIR\x64"
RMDir "$INSTDIR"
!insertmacro MUI_STARTMENU_GETFOLDER Application $SM_FOLDER
${If} ${RunningX64}
Delete "$SMPROGRAMS\$SM_FOLDER\${JAGS_VISIBLE_NAME} (32-bit).lnk"
Delete "$SMPROGRAMS\$SM_FOLDER\${JAGS_VISIBLE_NAME} (64-bit).lnk"
${Else}
Delete "$SMPROGRAMS\$SM_FOLDER\${JAGS_VISIBLE_NAME}.lnk"
${EndIf}
Delete "$SMPROGRAMS\$SM_FOLDER\Uninstall ${JAGS_VISIBLE_NAME}.lnk"
;Delete empty start menu parent diretories
StrCpy $SM_FOLDER "$SMPROGRAMS\$SM_FOLDER"
startMenuDeleteLoop:
ClearErrors
RMDir $SM_FOLDER
GetFullPathName $SM_FOLDER "$SM_FOLDER\.."
IfErrors startMenuDeleteLoopDone
StrCmp $SM_FOLDER $SMPROGRAMS startMenuDeleteLoopDone startMenuDeleteLoop
startMenuDeleteLoopDone:
DeleteRegKey /ifempty ${INSTDIR_REG_ROOT} "${INSTDIR_REG_KEY}"
DeleteRegKey /ifempty ${INSTDIR_REG_ROOT} "${APP_REG_KEY}"
DeleteRegKey /ifempty ${INSTDIR_REG_ROOT} "${PUB_REG_KEY}"
SectionEnd # end of uninstall section
Function un.onInit
!insertmacro MULTIUSER_UNINIT
!insertmacro UNINSTALL.LOG_BEGIN_UNINSTALL
FunctionEnd
#This is a function taken from the NSIS Wiki to replace one text string
#with another. It doesn't work properly if there is more than one instance
#of the replacement string on a line
Function AdvReplaceInFile
Exch $0 ;file to replace in
Exch
Exch $1 ;number to replace after
Exch
Exch 2
Exch $2 ;replace and onwards
Exch 2
Exch 3
Exch $3 ;replace with
Exch 3
Exch 4
Exch $4 ;to replace
Exch 4
Push $5 ;minus count
Push $6 ;universal
Push $7 ;end string
Push $8 ;left string
Push $9 ;right string
Push $R0 ;file1
Push $R1 ;file2
Push $R2 ;read
Push $R3 ;universal
Push $R4 ;count (onwards)
Push $R5 ;count (after)
Push $R6 ;temp file name
GetTempFileName $R6
FileOpen $R1 $0 r ;file to search in
FileOpen $R0 $R6 w ;temp file
StrLen $R3 $4
StrCpy $R4 -1
StrCpy $R5 -1
loop_read:
ClearErrors
FileRead $R1 $R2 ;read line
IfErrors exit
StrCpy $5 0
StrCpy $7 $R2
loop_filter:
IntOp $5 $5 - 1
StrCpy $6 $7 $R3 $5 ;search
StrCmp $6 "" file_write2
StrCmp $6 $4 0 loop_filter
StrCpy $8 $7 $5 ;left part
IntOp $6 $5 + $R3
StrCpy $9 $7 "" $6 ;right part
StrCpy $7 $8$3$9 ;re-join
IntOp $R4 $R4 + 1
StrCmp $2 all file_write1
StrCmp $R4 $2 0 file_write2
IntOp $R4 $R4 - 1
IntOp $R5 $R5 + 1
StrCmp $1 all file_write1
StrCmp $R5 $1 0 file_write1
IntOp $R5 $R5 - 1
Goto file_write2
file_write1:
FileWrite $R0 $7 ;write modified line
Goto loop_read
file_write2:
FileWrite $R0 $R2 ;write unmodified line
Goto loop_read
exit:
FileClose $R0
FileClose $R1
SetDetailsPrint none
Delete $0
Rename $R6 $0
Delete $R6
SetDetailsPrint both
Pop $R6
Pop $R5
Pop $R4
Pop $R3
Pop $R2
Pop $R1
Pop $R0
Pop $9
Pop $8
Pop $7
Pop $6
Pop $5
Pop $4
Pop $3
Pop $2
Pop $1
Pop $0
FunctionEnd