Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call an nsi function in uninstall section?

Tags:

windows

nsis

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 
like image 208
Road_House Avatar asked Oct 18 '25 08:10

Road_House


2 Answers

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
like image 199
Serge Z Avatar answered Oct 19 '25 20:10

Serge Z


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

Function un.DoMagic
...
FunctionEnd

Section "un.Main"
Call un.DoMagic
SectionEnd
like image 45
Anders Avatar answered Oct 19 '25 20:10

Anders



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!