Bug 1004168 - Add an INI file option to prevent requiring a reboot when there are files in use. r=jmathies, a=lsblakk
authorRobert Strong <robert.bugzilla@gmail.com>
Thu, 01 May 2014 13:15:05 -0700
changeset 192250 afcec252f3b7
parent 192249 c81fd101b5a2
child 192251 63b001b6f985
push id3544
push userryanvm@gmail.com
push date2014-05-12 19:29 +0000
Treeherderresults
reviewersjmathies, lsblakk
bugs1004168
milestone30.0
Bug 1004168 - Add an INI file option to prevent requiring a reboot when there are files in use. r=jmathies, a=lsblakk
browser/installer/windows/nsis/installer.nsi
toolkit/mozapps/installer/windows/nsis/common.nsh
--- a/browser/installer/windows/nsis/installer.nsi
+++ b/browser/installer/windows/nsis/installer.nsi
@@ -25,16 +25,17 @@ RequestExecutionLevel user
 
 Var TmpVal
 Var InstallType
 Var AddStartMenuSC
 Var AddQuickLaunchSC
 Var AddDesktopSC
 Var InstallMaintenanceService
 Var PageName
+Var PreventRebootRequired
 
 ; By defining NO_STARTMENU_DIR an installer that doesn't provide an option for
 ; an application's Start Menu PROGRAMS directory and doesn't define the
 ; StartMenuDir variable can use the common InstallOnInitCommon macro.
 !define NO_STARTMENU_DIR
 
 ; On Vista and above attempt to elevate Standard Users in addition to users that
 ; are a member of the Administrators group.
@@ -82,16 +83,17 @@ VIAddVersionKey "OriginalFilename" "setu
 !insertmacro InitHashAppModelId
 !insertmacro IsHandlerForInstallDir
 !insertmacro IsPinnedToTaskBar
 !insertmacro IsUserAdmin
 !insertmacro LogDesktopShortcut
 !insertmacro LogQuickLaunchShortcut
 !insertmacro LogStartMenuShortcut
 !insertmacro ManualCloseAppPrompt
+!insertmacro OnStubInstallUninstall
 !insertmacro PinnedToStartMenuLnkCount
 !insertmacro RegCleanAppHandler
 !insertmacro RegCleanMain
 !insertmacro RegCleanUninstall
 !ifdef MOZ_METRO
 !insertmacro RemoveDEHRegistrationIfMatching
 !endif
 !insertmacro SetAppLSPCategories
@@ -190,17 +192,34 @@ ChangeUI IDD_VERIFY "${NSISDIR}\Contrib\
 Section "-InstallStartCleanup"
   SetDetailsPrint both
   DetailPrint $(STATUS_CLEANUP)
   SetDetailsPrint none
 
   SetOutPath "$INSTDIR"
   ${StartInstallLog} "${BrandFullName}" "${AB_CD}" "${AppVersion}" "${GREVersion}"
 
-  ; Delete the app exe to prevent launching the app while we are installing.
+  StrCpy $PreventRebootRequired "false"
+  ${GetParameters} $R8
+  ${GetOptions} "$R8" "/INI=" $R7
+  ${Unless} ${Errors}
+    ; The configuration file must also exist
+    ${If} ${FileExists} "$R7"
+      ReadINIStr $R8 $R7 "Install" "PreventRebootRequired"
+      ${If} $R8 == "true"
+        StrCpy $PreventRebootRequired "true"
+        StrCpy $R2 "false"
+        StrCpy $R3 "false"
+        ${OnStubInstallUninstall} "$R2" "$R3"
+      ${EndIf}
+    ${EndIf}
+  ${EndUnless}
+
+  ; Delete the app exe if present to prevent launching the app while we are
+  ; installing.
   ClearErrors
   ${DeleteFile} "$INSTDIR\${FileMainEXE}"
   ${If} ${Errors}
     ; If the user closed the application it can take several seconds for it to
     ; shut down completely. If the application is being used by another user we
     ; can rename the file and then delete is when the system is restarted.
     Sleep 5000
     ${DeleteFile} "$INSTDIR\${FileMainEXE}"
@@ -570,16 +589,20 @@ Section "-InstallEndCleanup"
   ${GetShortcutsLogPath} $0
   WriteIniStr "$0" "TASKBAR" "Migrated" "true"
 
   ; Refresh desktop icons
   System::Call "shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_DWORDFLUSH}, i 0, i 0)"
 
   ${InstallEndCleanupCommon}
 
+  ${If} $PreventRebootRequired == "true"
+    SetRebootFlag false
+  ${EndIf}
+
   ${If} ${RebootFlag}
     ; When a reboot is required give SHChangeNotify time to finish the
     ; refreshing the icons so the OS doesn't display the icons from helper.exe
     Sleep 10000
     ${LogHeader} "Reboot Required To Finish Installation"
     ; ${FileMainEXE}.moz-upgrade should never exist but just in case...
     ${Unless} ${FileExists} "$INSTDIR\${FileMainEXE}.moz-upgrade"
       Rename "$INSTDIR\${FileMainEXE}" "$INSTDIR\${FileMainEXE}.moz-upgrade"
--- a/toolkit/mozapps/installer/windows/nsis/common.nsh
+++ b/toolkit/mozapps/installer/windows/nsis/common.nsh
@@ -75,17 +75,17 @@
 !endif
 
 !include x64.nsh
 
 ; NSIS provided macros that we have overridden.
 !include overrides.nsh
 
 !define SHORTCUTS_LOG "shortcuts_log.ini"
-!define TO_BE_DELETED "to_be_deleted"
+!define TO_BE_DELETED "tobedeleted"
 
 ; !define SHCNF_DWORD     0x0003
 ; !define SHCNF_FLUSH     0x1000
 !ifndef SHCNF_DWORDFLUSH
   !define SHCNF_DWORDFLUSH 0x1003
 !endif
 !ifndef SHCNE_ASSOCCHANGED
   !define SHCNE_ASSOCCHANGED 0x08000000
@@ -4334,20 +4334,22 @@
 /**
  * Parses the uninstall.log for the stub installer on install to first remove a
  * previous installation's files prior to installing.
  *
  * When modifying this macro be aware that LineFind uses all registers except
  * $R0-$R3 so be cautious. Callers of this macro are not affected.
  *
  * @param   _PROGRESSBAR
- *          The progress bar to update using PBM_STEPIT.
+ *          The progress bar to update using PBM_STEPIT. Can also be "false" if
+ *          updating a progressbar isn't needed.
  * @param   _INSTALL_STEP_COUNTER
  *          The install step counter to increment. The variable specified in
- *          this parameter is also updated.
+ *          this parameter is also updated. Can also be "false" if a counter
+ *          isn't needed.
  *
  * $R2 = _INSTALL_STEP_COUNTER
  * $R3 = _PROGRESSBAR
  */
 !macro OnStubInstallUninstall
 
   !ifndef OnStubInstallUninstall
     !insertmacro GetParent
@@ -4415,19 +4417,23 @@
 
       StrCmp "$R0" "\" +1 end  ; If this isn't a relative path goto end
       StrCmp "$R9" "\MapiProxy_InUse.dll" end +1 ; Skip the MapiProxy_InUse.dll
       StrCmp "$R9" "\mozMapi32_InUse.dll" end +1 ; Skip the mozMapi32_InUse.dll
 
       StrCpy $R1 "$INSTDIR$R9" ; Copy the install dir path and suffix it with the string
       IfFileExists "$R1" +1 end
 
-      IntOp $R2 $R2 + 2
-      SendMessage $R3 ${PBM_STEPIT} 0 0
-      SendMessage $R3 ${PBM_STEPIT} 0 0
+      ${Unless} "$R2" == "false"
+        IntOp $R2 $R2 + 2
+      ${EndIf}
+      ${Unless} "$R3" == "false"
+        SendMessage $R3 ${PBM_STEPIT} 0 0
+        SendMessage $R3 ${PBM_STEPIT} 0 0
+      ${EndIf}
 
       ClearErrors
       Delete "$R1"
       ${Unless} ${Errors}
         Goto end
       ${EndUnless}
 
       GetTempFileName $R0 "$INSTDIR\${TO_BE_DELETED}"
@@ -5245,18 +5251,18 @@
       ; Prevents breaking apps that don't use SetBrandNameVars
       !ifdef SetBrandNameVars
         ${SetBrandNameVars} "$INSTDIR\distribution\setup.ini"
       !endif
 
       ; Application update uses a directory named tobedeleted in the $INSTDIR to
       ; delete files on OS reboot when they are in use. Try to delete this
       ; directory if it exists.
-      ${If} ${FileExists} "$INSTDIR\tobedeleted"
-        RmDir /r "$INSTDIR\tobedeleted"
+      ${If} ${FileExists} "$INSTDIR\${TO_BE_DELETED}"
+        RmDir /r "$INSTDIR\${TO_BE_DELETED}"
       ${EndIf}
 
       ; Prevent all operations (e.g. set as default, postupdate, etc.) when a
       ; reboot is required and the executable launched is helper.exe
       IfFileExists "$INSTDIR\${FileMainEXE}.moz-upgrade" +1 +4
       MessageBox MB_YESNO|MB_ICONEXCLAMATION "$(WARN_RESTART_REQUIRED_UPGRADE)" IDNO +2
       Reboot
       Quit ; Nothing initialized so no need to call OnEndCommon
@@ -5683,18 +5689,18 @@
       ; Since we write to the uninstall.log in this directory during the
       ; installation create the directory if it doesn't already exist.
       IfFileExists "$INSTDIR\uninstall" +2 +1
       CreateDirectory "$INSTDIR\uninstall"
 
       ; Application update uses a directory named tobedeleted in the $INSTDIR to
       ; delete files on OS reboot when they are in use. Try to delete this
       ; directory if it exists.
-      ${If} ${FileExists} "$INSTDIR\tobedeleted"
-        RmDir /r "$INSTDIR\tobedeleted"
+      ${If} ${FileExists} "$INSTDIR\${TO_BE_DELETED}"
+        RmDir /r "$INSTDIR\${TO_BE_DELETED}"
       ${EndIf}
 
       ; Remove files that may be left behind by the application in the
       ; VirtualStore directory.
       ${CleanVirtualStore}
     FunctionEnd
 
     !verbose pop