Browse Source

delete existing files explicitly in windows installer

Earlier, we just removed the installation directory recursively.
The uninstallation code was refactored and reused at the time of
installation to remove files explicitly mentioned, which prevents
problems when the installation directory is incorrectly chosen i.e.
fixes #1585
Ashish Kulkarni 11 years ago
parent
commit
8229c4da8d
1 changed files with 35 additions and 15 deletions
  1. 35 15
      wkhtmltox.nsi

+ 35 - 15
wkhtmltox.nsi

@@ -28,9 +28,40 @@ RequestExecutionLevel admin
 
 !insertmacro MUI_LANGUAGE "English"
 
+!macro DeleteFiles un
+Function ${un}DeleteFiles
+; remove as per old installer layout
+  Delete "$INSTDIR\libgcc_s_dw2-1.dll"
+  Delete "$INSTDIR\mingwm10.dll"
+  Delete "$INSTDIR\ssleay32.dll"
+  Delete "$INSTDIR\libeay32.dll"
+  Delete "$INSTDIR\wkhtmltopdf.exe"
+  Delete "$INSTDIR\wkhtmltoimage.exe"
+; remove as per current installer layout
+  Delete "$INSTDIR\bin\wkhtmltoimage.exe"
+  Delete "$INSTDIR\bin\wkhtmltopdf.exe"
+  Delete "$INSTDIR\bin\wkhtmltox.dll"
+  Delete "$INSTDIR\lib\wkhtmltox.lib"
+  Delete "$INSTDIR\include\wkhtmltox\dllbegin.inc"
+  Delete "$INSTDIR\include\wkhtmltox\dllend.inc"
+  Delete "$INSTDIR\include\wkhtmltox\pdf.h"
+  Delete "$INSTDIR\include\wkhtmltox\image.h"
+  Delete "$INSTDIR\uninstall.exe"
+  RMDir  "$INSTDIR\bin"
+  RMDir  "$INSTDIR\include\wkhtmltox"
+  RMDir  "$INSTDIR\include"
+  RMDir  "$INSTDIR\lib"
+  RMDir  "$INSTDIR"
+FunctionEnd
+!macroend
+
+!insertmacro DeleteFiles ""
+!insertmacro DeleteFiles "un."
+
 Section "Install"
-  RMDir /r "$INSTDIR"
+  Call DeleteFiles
 
+  SetOutPath "$INSTDIR"
   SetOutPath "$INSTDIR\bin"
   File static-build\${TARGET}\app\bin\wkhtmltoimage.exe
   File static-build\${TARGET}\app\bin\wkhtmltopdf.exe
@@ -46,6 +77,8 @@ Section "Install"
   File include\wkhtmltox\image.h
 
   WriteRegStr HKLM "Software\wkhtmltopdf" "InstallPath" "$INSTDIR"
+  WriteRegStr HKLM "Software\wkhtmltopdf" "Version"     "${VERSION}"
+  WriteRegStr HKLM "Software\wkhtmltopdf" "DllPath"     "$INSTDIR\bin\wkhtmltox.dll"
   WriteRegStr HKLM "Software\wkhtmltopdf" "PdfPath"     "$INSTDIR\bin\wkhtmltopdf.exe"
   WriteRegStr HKLM "Software\wkhtmltopdf" "ImagePath"   "$INSTDIR\bin\wkhtmltoimage.exe"
   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\wkhtmltopdf" \
@@ -57,20 +90,7 @@ Section "Install"
 SectionEnd
 
 Section "Uninstall"
-  Delete "$INSTDIR\bin\wkhtmltoimage.exe"
-  Delete "$INSTDIR\bin\wkhtmltopdf.exe"
-  Delete "$INSTDIR\bin\wkhtmltox.dll"
-  Delete "$INSTDIR\lib\wkhtmltox.lib"
-  Delete "$INSTDIR\include\wkhtmltox\dllbegin.inc"
-  Delete "$INSTDIR\include\wkhtmltox\dllend.inc"
-  Delete "$INSTDIR\include\wkhtmltox\pdf.h"
-  Delete "$INSTDIR\include\wkhtmltox\image.h"
-  Delete "$INSTDIR\uninstall.exe"
-  RMDir  "$INSTDIR\bin"
-  RMDir  "$INSTDIR\include\wkhtmltox"
-  RMDir  "$INSTDIR\include"
-  RMDir  "$INSTDIR\lib"
-  RMDir  "$INSTDIR"
+  Call un.DeleteFiles
   DeleteRegKey HKLM "Software\wkhtmltopdf"
   DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\wkhtmltopdf"
 SectionEnd