Uninstalling older versions
I had NSIS 2.02 and just got NSIS 2.05, I noticed it has an uninstaller which uninstalls older versions.
Can someone please tell me how to do a thing like that?
Thanks
P.S. I found nothing useful in the search. :(
Archive: Uninstalling older versions
Uninstalling older versions
I had NSIS 2.02 and just got NSIS 2.05, I noticed it has an uninstaller which uninstalls older versions.
Can someone please tell me how to do a thing like that?
Thanks
P.S. I found nothing useful in the search. :(
P.S. I found nothing useful in the search.Why not? Search with unistall and older filters.
There are many examples, but none for what I need.
I need the same thing as in the NSIS installer, so I was hoping a dev could give me the code.
AFAIK, makensis.nsi IS the NSIS install script. Look for the PageReinstall function, and see how it is used.
I tried it but I get an error and my page doesn't show in the installer. :(
1 warning:
label "same_version" not used
>
Here's my codeThis installer is for a product with v1.3, it needs to check for 1.0 and 1.1. No minor versions or builds are needed.Function PageReinstall
insertmacro MUI_INSTALLOPTIONS_WRITE "makensis.ini" "Field 1" "Text" "An older version of NAME is installed on your system. It's recommended that you uninstall the current version before installing. Select the operation you want to perform and click Next to continue."
ReadRegStr $R0 HKLM "Software\NAME" ""
StrCmp $R0 "" 0 +2
Abortci8
;Detect version
ReadRegDWORD $R0 HKLM "Software\NAME" "VersionMajor"
IntCmp $R0 ${VER_MAJOR} minor_check new_version older_version
minor_check:
ReadRegDWORD $R0 HKLM "Software\NAME" "VersionMinor"
IntCmp $R0 ${VER_MINOR} new_version older_version
new_version:
!
!insertmacro MUI_INSTALLOPTIONS_WRITE "makensis.ini" "Field 2" "Text" "Uninstall before installing"
!insertmacro MUI_INSTALLOPTIONS_WRITE "makensis.ini" "Field 3" "Text" "Do not uninstall"
!insertmacro MUI_HEADER_TEXT "Already Installed" "Choose how you want to install NAME."
StrCpy $R0 "1"
Goto reinst_start
older_version:
!insertmacro MUI_INSTALLOPTIONS_WRITE "makensis.ini" "Field 1" "Text" "A newer version of NAME is already installed! It is not recommended that you install an older version. If you really want to install this older version, it's better to uninstall the current version first. Select the operation you want to perform and click Next to continue."
!insertmacro MUI_INSTALLOPTIONS_WRITE "makensis.ini" "Field 2" "Text" "Uninstall before installing"
!insertmacro MUI_INSTALLOPTIONS_WRITE "makensis.ini" "Field 3" "Text" "Do not uninstall"
!insertmacro MUI_HEADER_TEXT "Already Installed" "Choose how you want to install NAME."
StrCpy $R0 "1"
Goto reinst_start
same_version:
!insertmacro MUI_INSTALLOPTIONS_WRITE "makensis.ini" "Field 1" "Text" "NAME ${VER_DISPLAY} is already installed. Select the operation you want to perform and click Next to continue."
!insertmacro MUI_INSTALLOPTIONS_WRITE "makensis.ini" "Field 2" "Text" "Reinstall NAME ${VER_DISPLAY}"
!insertmacro MUI_INSTALLOPTIONS_WRITE "makensis.ini" "Field 3" "Text" "Uninstall NAME ${VER_DISPLAY}"
!insertmacro MUI_HEADER_TEXT "Already Installed" "Choose the maintenance option to perform."
StrCpy $R0 "2"
reinst_start:
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "makensis.ini"
>FunctionEnd
>Function PageLeaveReinstall
!insertmacro MUI_INSTALLOPTIONS_READ $R1 "makensis.ini" "Field 2" "State"
StrCmp $R0 "1" 0 +2
StrCmp $R1"1" reinst_uninstall reinst_done
StrCmp $R0"2" 0 +3
StrCmp $R1"1" reinst_done reinst_uninstall
reinst_uninstall:
ReadRegStr $R1 HKLM "Software\NAME" "UninstallString"
;Run uninstaller
HideWindow
ClearErrors
ExecWait '$R1 _?=$INSTDIR'
IfErrors no_remove_uninstaller
IfFileExists"$INSTDIR\NAME Uninstall.exe" no_remove_uninstaller
Delete $R1
RMDir $INSTDIR
no_remove_uninstaller:
StrCmp $R0 "2" 0 +2
Quit
BringToFront
reinst_done:
>FunctionEnd
>
The warning occurs because you removed checks for revision number and build number without correcting the previous code. Replace
minor_check:
ReadRegDWORD $R0 HKLM "SoftwareNAME" "VersionMinor"
IntCmp $R0 ${VER_MINOR} new_version older_version
with
minor_check:
ReadRegDWORD $R0 HKLM "SoftwareNAME" "VersionMinor"
IntCmp $R0 ${VER_MINOR} same_version new_version older_version
or simply define Revision and Build as 0, using the older code.
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "..\license.txt"
Page custom PageReinstall PageLeaveReinstall
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
as well as any variables (VersionMajor, etc.) and functions (PageReinstallLeave) used.
Thanks for your help. ;)
. Replaced that code, and added "Page custom PageReinstall PageLeaveReinstall" to my pages list.
. Made the installer make a reg key with VersionMajor, etc, . Defined VersionMajor, Minor, etc.
. Made the PageLeaveReinstall function so I think that's it...
I get NO errors, but it still doesn't show up when installing. :( What else could I have done wrong?
Would it help if I emailed you my entire script so you can see what the prob is?
Thanks again.
It would be better to post it here on the forums, so I'm not the only one who can help you - to be honest, I'm just working from what I see in makensis.nsi. If you click the "Post a Reply" button, you can attach your .NSI file to your post. If need be, it can also be zipped (to save space).
Of course, if you feel uncomfortable with doing that, go ahead and e-mail me.
I have attached it to this post.
Just so you know I'm using the default makensis.ini as my .ini file, if makes any difference.
Thanks again for the help. ;)
While you've correctly put the .ini file as ReserveFile, you don't initialize the InstallOptions plugin in .onInit. This is required to show custom pages (refer to the InstallOptions readme).
You need to insert this code in your .onInit:
!insertmacro MUI_INSTALLOPTIONS_EXTRACT "makensis.ini"
I already did all the things you mentioned about the .ini but I forgot about the custom page.
THANKS a million buddy, now everything works fine. :D