- NSIS Discussion
- Installer and Uninstaller Redundancy
Archive: Installer and Uninstaller Redundancy
Don Tommaso
19th May 2006 10:51 UTC
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
onad
19th May 2006 12:07 UTC
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.
Don Tommaso
19th May 2006 12:27 UTC
Ok. But is it possible to achieve my goal somehow? I cannot
implement two versions of every function I'm using. It is madness!
kichik
19th May 2006 12:52 UTC
You can use a macro.
!macro myfunc un
Function ${un}myfunc
Call ${un}someotherfunc
DetailPrint something
FunctionEnd
!macroend
!insertmacro myfunc ""
!insertmacro myfunc "un."
Don Tommaso
19th May 2006 15:04 UTC
Thanks, it works great!
You've saved my day.
onad
21st May 2006 21:12 UTC
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.
JasonFriday13
22nd May 2006 01:57 UTC
I have just made an example here.
Wabiloo
13th September 2006 22:33 UTC
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)...
Animaether
14th September 2006 19:03 UTC
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.
kichik
15th September 2006 12:06 UTC
!macro myfunc un
Function ${un}myfunc
${${un}WordFind} $CMDLINE "/" "E+$8" $7
DetailPrint something
FunctionEnd
!macroend
!insertmacro myfunc ""
!insertmacro myfunc "un."
Wabiloo
15th September 2006 15:19 UTC
${${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?
kichik
15th September 2006 16:04 UTC
Nope, no limit.
frodelan
4th June 2009 13:04 UTC
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