Road_House
Road_House

Reputation: 123

How to call an nsi function in uninstall section?

I have an nsi script with a function that returns output that I'm trying to call inside the uninstall section. Unfortunately however when I run it I get errors apparently because of the way I call this function. My understanding is that there is a special way to call functions in the uninstall section but i'm not sure how and I was wondering if someone could help me? my code looks like this:

Function TestFunction
   Push $R0
   Rush $R1
   ;do stuff
   Pop $R!
   Exch $R0
FunctionEnd

!macro TestFunction OUTPUT_VALUE
   Call TestFunction
   Pop `${OUTPUT_VALUE}`
!macroend

!define TestFunction'!insertmacro "TestFunction"' 

; Uninstaller

Section "Uninstall"
  ${TestFunction} $R0
  StrCmp $R0 "Test" istest isnottest 

Upvotes: 4

Views: 2497

Answers (2)

Anders
Anders

Reputation: 101569

The name of uninstaller functions must be prefixed with un.:

Function un.DoMagic
...
FunctionEnd

Section "un.Main"
Call un.DoMagic
SectionEnd

Upvotes: 6

Serge Z
Serge Z

Reputation: 425

NSIS has naming condition - function called from uninstaller has to have "un." prefix in name. This is boring when you have some function which can be called from both installer and uninstaller too. To avoid less copy-past, experienced folks usually use macroses. Something like this:

!macro TestFunction UN
Function ${UN}TestFunction
   ;do stuff
FunctionEnd
!macroend
!insertmacro TestFunction "" 
!insertmacro TestFunction "un."

Usings:

Section "Install"
  Call TestFunction
EndSection

Section "Uninstall"
  Call un.TestFuction
SecionEnd

Upvotes: 7

Related Questions