Archive: Installer and Uninstaller Redundancy


Installer and Uninstaller Redundancy
  I'm a newbie to NSIS and I can't figure out how
to use the same functions for the installer and the uninstaller. Since the uninstaller functions must start
with the un-prefix and the installer functions must not,
my code is starting look horrible. E.g, I'm using
the EnumUsersReg.nsh module/file in both the installer and in the uninstaller and I had to copy the file and rename
every macro and function. Since no sensible language could
force this kind of redundancy I assume that it can be solved somehow. But how?

/Tomas


It is not the language, but I agree sharing functions between Installer and Uninstaller could be improved.

Reason: Actually you are building TWO applications, an INSTALLER and an UNINSTALLER. Since you could need routines in your Installer you do not need in you uninstaller including them in both would make the unistaller unnessecair bigger filesize.


Ok. But is it possible to achieve my goal somehow? I cannot
implement two versions of every function I'm using. It is madness!


You can use a macro.

!macro myfunc un
Function ${un}myfunc
Call ${un}someotherfunc
DetailPrint something
FunctionEnd
!macroend

!insertmacro myfunc ""
!insertmacro myfunc "un."

Thanks, it works great!
You've saved my day.


Good codeing! Although obvious if you know it all....
.. but that is not the situation for everyone.

IDEA: Maybe somwhere to add example to the Wiki.


I have just made an example here.


Ah yes, but what happens if I want to use an existing function, like, say ${WordFind}?

!macro myfunc un

>Function ${un}myfunc
${WordFind} $CMDLINE "/" "E+$8" $7
DetailPrint something
FunctionEnd
>!macroend

>!insertmacro myfunc ""
>!insertmacro myfunc "un."
doesn't work (obviously)...

Then you adapt the existing function to a similar scheme :)

btw, this use of macros to create both an installer and an uninstaller function is in the NSIS help. It's sadly hidden in the "Scripting Structure > 2.3.6 Compiler Commands" topic, though.


!macro myfunc un
Function ${un}myfunc
${${un}WordFind} $CMDLINE "/" "E+$8" $7
DetailPrint something
FunctionEnd
!macroend

!insertmacro myfunc ""
!insertmacro myfunc "un."

${${un}WordFind} $CMDLINE "/" "E+$8" $7
Oooh, I didn't know I could do that (really I should have tried before assuming, or read TFM...).
Just out of interest, is there any limit to the number of levels?

Nope, no limit.


Similar problem, but with macro which take a variable
  I have following code in a .nsh file:

!define Test "!insertmacro Test"

!macro Test Var
Push "${Var}"
Call Test
!macroend

Function Test
Exch $0
.....
Pop $0
FunctionEnd

I call this macro from a .nsi file with:

${Test} "Value"

How should I use this in an Uninstall section? I have tried to do as explained in previous posts. I put my function Test inside a "DualFunction" macro like myfunc, but I got a error that said I have wrong number of parameters to my function call. Anyone that has a suggestion?

Best regards, Frode