Misc. changes to installer including:
[evergreen-equinox.git] / Open-ILS / xul / staff_client / windowssetup.nsi
index 1a7c038..6e1e08c 100644 (file)
@@ -1,15 +1,19 @@
 ; Script generated by the HM NIS Edit Script Wizard.
 
 ; HM NIS Edit Wizard helper defines
-!define PRODUCT_NAME "Evergreen Staff Client Trunk"
 ; Old versions of makensis don't like this, moved to Makefile
 ;!define /file PRODUCT_VERSION "client/VERSION"
+!define PRODUCT_TAG "Trunk"
+!define PRODUCT_NAME "Evergreen Staff Client ${PRODUCT_TAG}"
 !define PRODUCT_PUBLISHER "Evergreen Community"
 !define PRODUCT_WEB_SITE "http://evergreen-ils.org/"
 !define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\evergreen.exe"
 !define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
 !define PRODUCT_UNINST_ROOT_KEY "HKLM"
 !define PRODUCT_STARTMENU_REGVAL "NSIS:StartMenuDir"
+!ifndef PRODUCT_LICENSE
+  !define PRODUCT_LICENSE "..\..\..\LICENSE.txt"
+!endif
 
 ; MUI 1.67 compatible ------
 !include "MUI.nsh"
 
 ; Welcome page
 !insertmacro MUI_PAGE_WELCOME
-; License page
-!insertmacro MUI_PAGE_LICENSE "..\..\..\LICENSE.txt"
+; License page, if we have one
+!if "${PRODUCT_LICENSE}" != ""
+  !insertmacro MUI_PAGE_LICENSE "${PRODUCT_LICENSE}"
+!endif
 ; Components page
-!ifdef AUTOUPDATE | DEVELOPER
+!ifdef AUTOUPDATE | DEVELOPER | PERMACHINE
 !insertmacro MUI_PAGE_COMPONENTS
 !endif
 ; Directory page
@@ -40,7 +46,7 @@
 ; Start menu page
 var ICONS_GROUP
 !define MUI_STARTMENUPAGE_NODISABLE
-!define MUI_STARTMENUPAGE_DEFAULTFOLDER "Evergreen Staff Client Trunk"
+!define MUI_STARTMENUPAGE_DEFAULTFOLDER "Evergreen Staff Client ${PRODUCT_TAG}"
 !define MUI_STARTMENUPAGE_REGISTRY_ROOT "${PRODUCT_UNINST_ROOT_KEY}"
 !define MUI_STARTMENUPAGE_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"
 !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "${PRODUCT_STARTMENU_REGVAL}"
@@ -63,32 +69,58 @@ var ICONS_GROUP
 
 Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
 OutFile "evergreen_staff_client_setup.exe"
-InstallDir "$PROGRAMFILES\Evergreen Staff Client Trunk"
+InstallDir "$PROGRAMFILES\Evergreen Staff Client ${PRODUCT_TAG}"
 InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
 ShowInstDetails show
 ShowUnInstDetails show
 RequestExecutionLevel admin
 
 Section "Staff Client" SECMAIN
+  ; Uninstall old (inno) variant?
+  IfFileExists "$INSTDIR/unin000.exe" 0 +3
+    ExecWait '"$INSTDIR/unins000.exe" /VERYSILENT'
+    Sleep 5000 ; Wait five seconds in case the uninstaller returned before it was done
+  ; Uninstall old (nsis) version?
+  IfFileExists "$INSTDIR/uninst.exe" 0 +4
+    ExecWait '"$INSTDIR/uninst.exe" /S _?="$INSTDIR"'
+    Sleep 5000 ; Wait five seconds in case the uninstaller returned before it was done
+    Delete "$INSTDIR/uninst.exe"
   SetOutPath "$INSTDIR"
-  File /r /x "autoupdate.js" /x "autochannel.js" /x "developers.js" "client\*"
+  File /r /x "autoupdate.js" /x "autochannel.js" /x "developers.js" /x "aa_per_machine.js" "client\*"
 
-; Shortcuts
+  ; Shortcuts
   !insertmacro MUI_STARTMENU_WRITE_BEGIN Application
   CreateDirectory "$SMPROGRAMS\$ICONS_GROUP"
   !ifdef WICON
   CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Evergreen Staff Client.lnk" "$INSTDIR\evergreen.exe" "" "$INSTDIR\evergreen.ico"
   !ifdef PROFILES
-  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Evergreen Staff Client Profile Manager.lnk" "$INSTRDIR\evergreen.exe -profilemanager" "" "$INSTDIR\evergreen.ico"
+  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Evergreen Staff Client Profile Manager.lnk" "$INSTDIR\evergreen.exe" "-profilemanager" "$INSTDIR\evergreen.ico"
   !endif
   !else
   CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Evergreen Staff Client.lnk" "$INSTDIR\evergreen.exe"
   !ifdef PROFILES
-  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Evergreen Staff Client Profile Manager.lnk" "$INSTRDIR\evergreen.exe -profilemanager"
+  CreateShortCut "$SMPROGRAMS\$ICONS_GROUP\Evergreen Staff Client Profile Manager.lnk" "$INSTDIR\evergreen.exe" "-profilemanager"
   !endif
   !endif
-  CreateShortCut "$DESKTOP\Evergreen Staff Client Trunk.lnk" "$INSTDIR\evergreen.exe"
+  CreateShortCut "$DESKTOP\Evergreen Staff Client ${PRODUCT_TAG}.lnk" "$INSTDIR\evergreen.exe"
+  
+  ; External script for extra things.
+  !define EXTERNAL_EXTRAS_SECMAIN
+  !include /NONFATAL "extras.nsi"
+  !undef EXTERNAL_EXTRAS_SECMAIN
+
   !insertmacro MUI_STARTMENU_WRITE_END
+
+  !ifdef AUTOUPDATE | PERMACHINE
+  ; For autoupdate and/or registering per machine, make sure we can write to the install directory.
+  ; If the AccessControl plugin was packaged or part of nsis we would use it instead.
+  ; Also, as cacls.exe is depreciated when icacls.exe exists, try icacls.exe first.
+  IfFileExists "$SYSDIR/icacls.exe" 0 +3
+  ExecWait '"$SYSDIR/icacls.exe" "$INSTDIR" /grant Everyone:(OI)(CI)F'  
+  Goto +3
+  IfFileExists "$SYSDIR/cacls.exe" 0 +2
+  ExecWait '"$SYSDIR/cacls.exe" "$INSTDIR" /E /G Everyone:F'
+  !endif
 SectionEnd
 
 !ifdef AUTOUPDATE
@@ -108,12 +140,19 @@ Section /o "Developer Options" SECDEV
 SectionEnd
 !endif
 
+!ifdef PERMACHINE
+Section /o "Registration Per Machine" SECPERMAC
+  SetOutPath "$INSTDIR\defaults\preferences"
+  File "client\defaults\preferences\aa_per_machine.js"
+  SetOutPath "$INSTDIR"
+SectionEnd
+!endif
 
 Function .onInit
   !insertmacro MUI_LANGDLL_DISPLAY
   SectionSetFlags ${SECMAIN} 17
   ; This is mainly for silent installs
-  !ifdef AUTOUPDATE | DEVELOPER
+  !ifdef AUTOUPDATE | DEVELOPER | PERMACHINE
     Var /GLOBAL CMD_ARGS
     StrCpy $CMD_ARGS ""
     ${GetParameters} $CMD_ARGS
@@ -127,6 +166,16 @@ Function .onInit
       !endif
       SectionSetFlags ${SECAUTO} 1
     !endif
+    !ifdef PERMACHINE
+      !ifdef PERMACHINE_NODEFAULT
+        ${GetOptions} $CMD_ARGS "/permachine" $0
+        IfErrors +2 0
+      !else
+        ${GetOptions} $CMD_ARGS "/nopermachine" $0
+        IfErrors 0 +2
+      !endif
+      SectionSetFlags ${SECPERMAC} 1
+    !endif
     !ifdef DEVELOPER
       ${GetOptions} $CMD_ARGS "/developer" $0
       IfErrors +2 0
@@ -163,20 +212,32 @@ SectionEnd
   !ifdef DEVELOPER
   !insertmacro MUI_DESCRIPTION_TEXT ${SECDEV}  "Developer Options"
   !endif
+  !ifdef PERMACHINE
+  !insertmacro MUI_DESCRIPTION_TEXT ${SECPERMAC}  "Default registration and offline storage to per machine instead of per user"
+  !endif
 !insertmacro MUI_FUNCTION_DESCRIPTION_END
 
 
 Function un.onUninstSuccess
   HideWindow
-  MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) was successfully removed from your computer."
+  MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) was successfully removed from your computer." /SD IDOK
 FunctionEnd
 
 Function un.onInit
 !insertmacro MUI_UNGETLANGUAGE
-  MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to completely remove $(^Name) and all of its components?" IDYES +2
+  MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to completely remove $(^Name) and all of its components?" /SD IDYES IDYES +2
   Abort
 FunctionEnd
 
+Function "un.RemoveFileCheck"
+  StrCmp $R7 "open_ils_staff_client" +5
+  StrCmp $R6 "" +3
+  Delete "$R9"
+  Goto +2
+  RmDir /r "$R9"
+  Push $0
+FunctionEnd
+
 Section Uninstall
   !insertmacro MUI_STARTMENU_GETFOLDER "Application" $ICONS_GROUP
   Delete "$INSTDIR\${PRODUCT_NAME}.url"
@@ -191,19 +252,32 @@ Section Uninstall
   Delete "$INSTDIR\chrome.manifest"
   Delete "$INSTDIR\updates.xml"
   Delete "$INSTDIR\log.txt"
+  Delete "$INSTDIR\evergreen.ico"
 
   Delete "$SMPROGRAMS\$ICONS_GROUP\Uninstall.lnk"
   Delete "$SMPROGRAMS\$ICONS_GROUP\Website.lnk"
-  Delete "$DESKTOP\Evergreen Staff Client Trunk.lnk"
+  Delete "$DESKTOP\Evergreen Staff Client ${PRODUCT_TAG}.lnk"
   Delete "$SMPROGRAMS\$ICONS_GROUP\Evergreen Staff Client.lnk"
 
+  ; External script for removing extra files before we wipe out the install directory
+  !define EXTERNAL_EXTRAS_UNINSTALL
+  !include /NONFATAL "extras.nsi"
+  !undef EXTERNAL_EXTRAS_UNINSTALL
+
   RMDir "$SMPROGRAMS\$ICONS_GROUP"
   RMDir /r "$INSTDIR\updates"
   RMDir /r "$INSTDIR\xulrunner"
   RMDir /r "$INSTDIR\extensions"
-  RMDir /r "$INSTDIR\chrome"
+;  RMDir /r "$INSTDIR\chrome" ; We can't wipe out the chrome directory normally. Per-machine info would be lost on upgrade.
   RMDir /r "$INSTDIR\components"
   RMDir /r "$INSTDIR\defaults"
+
+  ; Basically, we want to remove everything but "open_ils_staff_client" from the chrome dir
+  ; So we pass over every file and folder in it. If it matches, we leave it alone.
+  ${Locate} "$INSTDIR\chrome" "/G=0" "un.RemoveFileCheck"
+  ; Then, we remove the folder non-recursively, which won't wipe out the folder if it is still there.
+  RMDir "$INSTDIR\chrome"
+
   RMDir "$INSTDIR"
 
   DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"