Archive: Common function for Installer and uninstall


Common function for Installer and uninstall
Is there any way i can write a common function which can be called form Install and Uninstall section?
Actually i want to write a cleanup function. If the installer is already installed, it will first call celeanup function and then continue with installation. The same function will be called while uninstallation.

I went through the manual and it says
"Function names beginning with "un." are functions that will be generated in the Uninstaller. Hence, normal install Sections and functions cannot call uninstall functions, and the Uninstall Section and uninstall functions cannot call normal functions.
"


You can write the code in a macro and insert it in both an installer and an uninstaller function.


http://nsis.sourceforge.net/Sharing_...nd_Uninstaller
http://nsis.sourceforge.net/Macro_vs_Function

Using that, it's pretty simple to do something like...


!define myFunc `!insertmacro installFunc`
-installer code using ${myFunc} here-

!undef myFunc
!define myFunc `!insertmacro un.installFunc`
-uninstaller code, still using ${myFunc}, here-

Hijacking this thread as it seems the more sanely-subject'ed of threads on this topic.. :)

The more I'm using this stuff, the more I'm pondering the intentions of this separation of installer and uninstaller functions, and the more I'm getting confused.

There is no such thing as an installer variable vs an uninstaller variable, so either variables space gets included in both, or the compiler must be smart enough to know that it only has to reserve those variables actually used by the installer respectively uninstaller.

If the latter, couldn't that be extended to functions just as well?
If the former, I'm not sure what is lost if a function simply gets included in both. As per my own wiki page, yes, presumably it means a slightly smaller compiled installer; but are the savings that much worth it?

I feel that partially as a result of this split, there's quite a few pseudo-functions out there, including in the the Include folder of the standard NSIS distribution (CallArtificialFunction).
By pseudo-functions I mean macros that, if used more than once, get inserted into the source more than once, it gets loaded into memory more than once, etc. -and- the authors have to be very careful about dealing with goto labels (again, as per the wiki page). So there's certainly down sides to that approach (in execution and in authoring). So why is that road taken if not for the reason that having to explain to users that they -must- use two different function calls/macros/defines between the installer and the uninstaller is confusing?

I guess I'm just confused and wondering, quite seriously, whether a future NSIS couldn't handle this in either of the two methods mentioned before; either detect usage in the source code and include the function as necessary, or just include it in both installer and uninstaller and deal with the fact that the installer size and memory use go up a smidgen (and it really is a smidgen even for the most behemoth functions in otherwise tiny installers) - potentially unnecessarily.

Thoughts?


It's not that simple to implement. But it will come eventually. It's already working in my nobjs branch, if I recall correctly.


An alternative or perhaps temporary solution would be to allow functions whose names begin with say, "both." (or some other prefix) to be called from both installer and uninstaller code and allow the "both." functions to call any function, "un.", "both." and other functions. This will at least alleviate the problem. See also this feature request.