Skip to content
⌘ NSIS Forum Archive

Adding file from uninstfinalize

3 posts

arxot#

Adding file from uninstfinalize

Hi!

I use !uninstfinalize to produce a custom signature file (to verify the uninstaller). I need this signature file to be installed by the installer. Is this possible?

Whenever I think about this I end up with some sort of chicken-egg loop, but I don't completely understand when different things happen here, so maybe I'm missing something.

Cheers
JasonFriday13#
Maybe you can make it a two-step process: use a dummy installer that only has the uninstall code in it, and then in your installer you compile it with !makensis. In the dummy installer you can copy the uninstaller file to somewhere else using !uninstfinalize and run the sign tool on that. Then in the installer just include both files using 'File', and then use !finalize to delete the extra files.

Something like this:
; uninstall.nsi
OutFile dummy.exe
Name "dummy installer" ; Replace this with your actual product name
; Add MUI if you are using it
;!include "MUI2.nsh"
; You can probably use a common header for things that are shared
; between both installer and uninstaller
!addincludedir "."
!include "common.nsh"
!ifdef NSIS_WIN32_MAKENSIS
  !uninstfinalize 'copy /Y /B "%1" "./uninstall.exe"' ; I do not remember if this is right
  !uninstfinalize 'customsign "uninstall.exe" "uninstall.sig"'
!else
  ; Or if you are not on windows
  !uninstfinalize 'cp "%1" "./uninstall.exe"'
  !uninstfinalize 'customsign "uninstall.exe" "uninstall.sig"'
!endif
; Dummy page to keep the compiler happy
Page instfiles
; Add your uninstaller pages here
; Add your languages here
Section
  ; Dummy "WriteUninstaller" so that !uninstfinalize works
  WriteUninstaller "$EXEDIR\uninstall.exe"
SectionEnd
; All your uninstall code goes here
Section uninstall
SectionEnd 
;installer.nsi
; You can probably use a common header for things that are shared
; between both installer and uninstaller
!addincludedir "."
!include "common.nsh"
....
; Generate the uninstaller
!makensis "uninstall.nsi"
...
Section
  ; Set the out dir, then point this to your files from uninstall.nsi
  File "uninstall.exe"
  File "uninstall.sig"
SectionEnd
; Clean up
!ifdef NSIS_WIN32_MAKENSIS
  !finalize 'del dummy.exe'
  !finalize 'del uninstall.exe'
  !finalize 'del uninstall.sig'
!else
  ; Or not on windows
  !finalize 'rm dummy.exe'
  !finalize 'rm uninstall.exe'
  !finalize 'rm uninstall.sig'
!endif