Shared functions?
What's the easiest way to write a function which is called in both the installer and uninstaller sections without just duplicating the code?
8 posts
...
!macro _util.both
;
; Usage:
;
; call getNumColors
; pop $0
; MessageBox MB_OK "Number of Bits per Pixel: $0"
;
Function ${_UTIL_UNDOT}getNumColors
push "getScreenColors"
call ${_UTIL_UNDOT}_runDLL
FunctionEnd
;
; Usage:
;
; call getUserName
; pop $0
; MessageBox MB_OK "Current user: $0"
;
Function ${_UTIL_UNDOT}getUserName
push "getUserName"
call ${_UTIL_UNDOT}_runDLL
FunctionEnd
;
; Usage:
;
; call getPID
; pop $0
; MessageBox MB_OK "Current process ID: $0"
;
Function ${_UTIL_UNDOT}getPID
push "getPID"
call ${_UTIL_UNDOT}_runDLL
FunctionEnd
Function ${_UTIL_UNDOT}_removeDLL
Delete "$TEMP\NSISutil.dll"
FunctionEnd
Function ${_UTIL_UNDOT}_runDLL
IfFileExists "$TEMP\NSISutil.dll" ret
File "/oname=$TEMP\NSISutil.dll" "${INCLUDES}\NSISutil.dll"
!define _INIT_FUNC "${_UTIL_UNDOT}_removeDLL"
push "${_UTIL_UNDOT}onUserAbort"
!insertmacro ${_UTIL_UNDOT}multicallback.register_callback
!define _INIT_FUNC "${_UTIL_UNDOT}_removeDLL"
push "${_UTIL_UNDOT}on${_UTIL_INST}Failed"
!insertmacro ${_UTIL_UNDOT}multicallback.register_callback
!define _INIT_FUNC "${_UTIL_UNDOT}_removeDLL"
push "${_UTIL_UNDOT}on${_UTIL_INST}Success"
!insertmacro ${_UTIL_UNDOT}multicallback.register_callback
ret:
exch $R0
CallInstDLL "$TEMP\NSISutil.dll" $R0
exch
pop $R0
FunctionEnd
!undef _UTIL_UNDOT
!undef _UTIL_INST
!macroend ; _util.both
;
; Duplicate the whole stuff with and without "un." prefix
;
!define _UTIL_UNDOT ""
!define _UTIL_INST "Inst"
!insertmacro _util.both
!ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
!define _UTIL_UNDOT "un."
!define _UTIL_INST "Uninst"
!insertmacro _util.both
!endif
...