Uninstall old version on update
authorAndre Heinecke <aheinecke@intevation.de>
Tue, 8 Dec 2015 16:28:32 +0000 (17:28 +0100)
committerAndre Heinecke <aheinecke@intevation.de>
Tue, 8 Dec 2015 16:28:32 +0000 (17:28 +0100)
* src/inst-gpg4win.nsi (CheckExistingVersion): Remove message boxes.
* src/installer.nsi: Call uninstaller of old version if neccessary.
* src/uninst-gnupg-w32.nsi: Fix waiting for the uninstaller.

--
The messages provided no real information or choices. Uninstalling
is also cleaner then the usual case of overwriting.

src/inst-gpg4win.nsi
src/installer.nsi
src/uninst-gnupg-w32.nsi

index 0e63295..a7be820 100644 (file)
@@ -24,6 +24,19 @@ Section "-gpg4win" SEC_gpg4win
   SetOutPath "$INSTDIR"
   File "${BUILD_DIR}/../gpg4win-${VERSION}.tar.bz2"
 !else
+
+# Uninstall an old version if found.
+  ClearErrors
+  ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\GPG4Win" "DisplayVersion"
+  IfErrors skip_uninst 0
+  StrCmp $0 "" skip_uninst
+  DetailPrint  "$(T_UninstallingOldVersion)$0"
+  ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\GPG4Win" "UninstallString"
+  ReadRegStr $1 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\GPG4Win" "InstallLocation"
+  ExecWait '$0 /S _?=$1'
+  Delete "$0"
+  RmDir "$1"
+skip_uninst:
   SetOutPath "$INSTDIR\share\gpg4win"
 
   File "${BUILD_DIR}/README.en.txt"
index 865e6bf..ab89c33 100644 (file)
@@ -375,7 +375,7 @@ FunctionEnd
 Function CheckExistingVersion
   ClearErrors
   FileOpen $0 "$INSTDIR\VERSION" r
-  IfErrors nexttest
+  IfErrors leave
   FileRead $0 $R0
   FileRead $0 $R1
   FileClose $0
@@ -386,32 +386,10 @@ Function CheckExistingVersion
 
   # Extract major version.
   StrCpy $0 $R1 2
-  StrCmp $0 "1." 0 secondtest
+  StrCmp $0 "1." 0 leave
     MessageBox MB_YESNO "$(T_FoundExistingOldVersion)" IDYES leave
     Abort
 
- secondtest:
-  MessageBox MB_YESNO "$(T_FoundExistingVersion)" IDYES leave
-  Abort
-
- nexttest:
-  ClearErrors
-  ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\GPG4Win" "DisplayVersion"
-  IfErrors leave 0
-     StrCmp $0 ${VERSION} sameversion otherversion
-     otherversion:
-       MessageBox MB_YESNO "$(T_FoundExistingOldVersion)" IDYES uninstall
-       Abort
-     sameversion:
-       MessageBox MB_YESNO "$(T_FoundExistingVersionB)" IDYES leave
-       Abort
-
- uninstall:
-  ReadRegStr $0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\GPG4Win" "UninstallString"
-  ExecWait '$0 /S'
-
- # TODO This is the normal update case. Handle more gracefully.
- # Especially the install path change from 2.x to 3.x
  leave:
 FunctionEnd
 
@@ -522,12 +500,8 @@ LangString T_FoundExistingOldVersion ${LANG_ENGLISH} \
       strongly recommended to deinstall previous versions on \
       major upgrades. $\r$\n\
       Do you want to continue installing Gpg4win ${VERSION} anyway?"
-LangString T_FoundExistingVersionB ${LANG_ENGLISH} \
-     "A version of Gpg4Win has already been installed on the system. \
-      There will be no problem installing and thus overwriting this \
-      Version. $\r$\n\
-       $\r$\n\
-      Do you want to continue installing Gpg4win?"
+LangString T_UninstallingOldVersion ${LANG_ENGLISH} \
+     "Uninstalling Gpg4win-"
 
 
 #---------------------------------------------
index c7cea5a..0ec906e 100644 (file)
@@ -29,12 +29,16 @@ Section  "un.gnupg_w32"
   Push "${gpg4win_pkg_gnupg_w32}"
   Call un.SourceDelete
 !else
+  ClearErrors
   ReadRegStr $0 HKLM "Software\GnuPG" "Install Directory"
+  IfErrors gnupg_w32_not_installed 0
   # It is possible that someone uninstalled gnupg without uninstalling
   # gpg4win
   StrCmp $0 "" gnupg_w32_not_installed
   DetailPrint  "$(T_Uninstalling_GnuPG) ${gpg4win_pkg_gnupg_w32_version}"
-  ExecWait '"$0\gnupg-uninstall.exe" /S'
+  ExecWait '"$0\gnupg-uninstall.exe" /S _?=$0'
+  Delete "$0\gnupg-uninstall.exe"
+  RmDir "$0"
 gnupg_w32_not_installed:
 !endif
 SectionEnd