michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: ; Set verbosity to 3 (e.g. no script) to lessen the noise in the build logs michael@0: !verbose 3 michael@0: michael@0: ; 7-Zip provides better compression than the lzma from NSIS so we add the files michael@0: ; uncompressed and use 7-Zip to create a SFX archive of it michael@0: SetDatablockOptimize on michael@0: SetCompress off michael@0: CRCCheck on michael@0: michael@0: RequestExecutionLevel admin michael@0: michael@0: ; The commands inside this ifdef require NSIS 3.0a2 or greater so the ifdef can michael@0: ; be removed after we require NSIS 3.0a2 or greater. michael@0: !ifdef NSIS_PACKEDVERSION michael@0: Unicode true michael@0: ManifestSupportedOS all michael@0: ManifestDPIAware true michael@0: !endif michael@0: michael@0: !addplugindir ./ michael@0: michael@0: ; Variables michael@0: Var TempMaintServiceName michael@0: Var BrandFullNameDA michael@0: Var BrandFullName michael@0: michael@0: ; Other included files may depend upon these includes! michael@0: ; The following includes are provided by NSIS. michael@0: !include FileFunc.nsh michael@0: !include LogicLib.nsh michael@0: !include MUI.nsh michael@0: !include WinMessages.nsh michael@0: !include WinVer.nsh michael@0: !include WordFunc.nsh michael@0: michael@0: !insertmacro GetOptions michael@0: !insertmacro GetParameters michael@0: !insertmacro GetSize michael@0: michael@0: ; The test slaves use this fallback key to run tests. michael@0: ; And anyone that wants to run tests themselves should already have michael@0: ; this installed. michael@0: !define FallbackKey \ michael@0: "SOFTWARE\Mozilla\MaintenanceService\3932ecacee736d366d6436db0f55bce4" michael@0: michael@0: !define CompanyName "Mozilla Corporation" michael@0: !define BrandFullNameInternal "" michael@0: michael@0: ; The following includes are custom. michael@0: !include defines.nsi michael@0: ; We keep defines.nsi defined so that we get other things like michael@0: ; the version number, but we redefine BrandFullName michael@0: !define MaintFullName "Mozilla Maintenance Service" michael@0: !undef BrandFullName michael@0: !define BrandFullName "${MaintFullName}" michael@0: michael@0: !include common.nsh michael@0: !include locales.nsi michael@0: michael@0: VIAddVersionKey "FileDescription" "${MaintFullName} Installer" michael@0: VIAddVersionKey "OriginalFilename" "maintenanceservice_installer.exe" michael@0: michael@0: Name "${MaintFullName}" michael@0: OutFile "maintenanceservice_installer.exe" michael@0: michael@0: ; Get installation folder from registry if available michael@0: InstallDirRegKey HKLM "Software\Mozilla\MaintenanceService" "" michael@0: michael@0: SetOverwrite on michael@0: michael@0: !define MaintUninstallKey \ michael@0: "Software\Microsoft\Windows\CurrentVersion\Uninstall\MozillaMaintenanceService" michael@0: michael@0: ; The HAVE_64BIT_OS define also means that we have an x64 build, michael@0: ; not just an x64 OS. michael@0: !ifdef HAVE_64BIT_OS michael@0: ; See below, we actually abort the install for x64 builds currently. michael@0: InstallDir "$PROGRAMFILES64\${MaintFullName}\" michael@0: !else michael@0: InstallDir "$PROGRAMFILES32\${MaintFullName}\" michael@0: !endif michael@0: ShowUnInstDetails nevershow michael@0: michael@0: ################################################################################ michael@0: # Modern User Interface - MUI michael@0: michael@0: !define MUI_ICON setup.ico michael@0: !define MUI_UNICON setup.ico michael@0: !define MUI_WELCOMEPAGE_TITLE_3LINES michael@0: !define MUI_UNWELCOMEFINISHPAGE_BITMAP wizWatermark.bmp michael@0: michael@0: ;Interface Settings michael@0: !define MUI_ABORTWARNING michael@0: michael@0: ; Uninstaller Pages michael@0: !insertmacro MUI_UNPAGE_CONFIRM michael@0: !insertmacro MUI_UNPAGE_INSTFILES michael@0: michael@0: ################################################################################ michael@0: # Language michael@0: michael@0: !insertmacro MOZ_MUI_LANGUAGE 'baseLocale' michael@0: !verbose push michael@0: !verbose 3 michael@0: !include "overrideLocale.nsh" michael@0: !include "customLocale.nsh" michael@0: !verbose pop michael@0: michael@0: ; Set this after the locale files to override it if it is in the locale michael@0: ; using " " for BrandingText will hide the "Nullsoft Install System..." branding michael@0: BrandingText " " michael@0: michael@0: Function .onInit michael@0: ; Remove the current exe directory from the search order. michael@0: ; This only effects LoadLibrary calls and not implicitly loaded DLLs. michael@0: System::Call 'kernel32::SetDllDirectoryW(w "")' michael@0: michael@0: SetSilent silent michael@0: michael@0: !ifdef HAVE_64BIT_OS michael@0: ; We plan to eventually enable 64bit native builds to use the maintenance michael@0: ; service, but for the initial release, to reduce testing and development, michael@0: ; 64-bit builds will not install the maintenanceservice. michael@0: Abort michael@0: !endif michael@0: michael@0: ; On Windows 2000 we do not install the maintenance service. michael@0: ; We won't run this installer from the parent installer, but just in case michael@0: ; someone tries to execute it on Windows 2000... michael@0: ${Unless} ${AtLeastWinXP} michael@0: Abort michael@0: ${EndUnless} michael@0: FunctionEnd michael@0: michael@0: Function un.onInit michael@0: ; Remove the current exe directory from the search order. michael@0: ; This only effects LoadLibrary calls and not implicitly loaded DLLs. michael@0: System::Call 'kernel32::SetDllDirectoryW(w "")' michael@0: michael@0: ; The commands inside this ifndef are needed prior to NSIS 3.0a2 and can be michael@0: ; removed after we require NSIS 3.0a2 or greater. michael@0: !ifndef NSIS_PACKEDVERSION michael@0: ${If} ${AtLeastWinVista} michael@0: System::Call 'user32::SetProcessDPIAware()' michael@0: ${EndIf} michael@0: !endif michael@0: michael@0: StrCpy $BrandFullNameDA "${MaintFullName}" michael@0: StrCpy $BrandFullName "${MaintFullName}" michael@0: FunctionEnd michael@0: michael@0: Section "MaintenanceService" michael@0: AllowSkipFiles off michael@0: michael@0: CreateDirectory $INSTDIR michael@0: SetOutPath $INSTDIR michael@0: michael@0: ; If the service already exists, then it will be stopped when upgrading it michael@0: ; via the maintenanceservice_tmp.exe command executed below. michael@0: ; The maintenanceservice_tmp.exe command will rename the file to michael@0: ; maintenanceservice.exe if maintenanceservice_tmp.exe is newer. michael@0: ; If the service does not exist yet, we install it and drop the file on michael@0: ; disk as maintenanceservice.exe directly. michael@0: StrCpy $TempMaintServiceName "maintenanceservice.exe" michael@0: IfFileExists "$INSTDIR\maintenanceservice.exe" 0 skipAlreadyExists michael@0: StrCpy $TempMaintServiceName "maintenanceservice_tmp.exe" michael@0: skipAlreadyExists: michael@0: michael@0: ; We always write out a copy and then decide whether to install it or michael@0: ; not via calling its 'install' cmdline which works by version comparison. michael@0: CopyFiles "$EXEDIR\maintenanceservice.exe" "$INSTDIR\$TempMaintServiceName" michael@0: michael@0: ; The updater.ini file is only used when performing an install or upgrade, michael@0: ; and only if that install or upgrade is successful. If an old updater.ini michael@0: ; happened to be copied into the maintenance service installation directory michael@0: ; but the service was not newer, the updater.ini file would be unused. michael@0: ; It is used to fill the description of the service on success. michael@0: CopyFiles "$EXEDIR\updater.ini" "$INSTDIR\updater.ini" michael@0: michael@0: ; Install the application maintenance service. michael@0: ; If a service already exists, the command line parameter will stop the michael@0: ; service and only install itself if it is newer than the already installed michael@0: ; service. If successful it will remove the old maintenanceservice.exe michael@0: ; and replace it with maintenanceservice_tmp.exe. michael@0: ClearErrors michael@0: ${GetParameters} $0 michael@0: ${GetOptions} "$0" "/Upgrade" $0 michael@0: ${If} ${Errors} michael@0: nsExec::Exec '"$INSTDIR\$TempMaintServiceName" install' michael@0: ${Else} michael@0: ; The upgrade cmdline is the same as install except michael@0: ; It will fail if the service isn't already installed. michael@0: nsExec::Exec '"$INSTDIR\$TempMaintServiceName" upgrade' michael@0: ${EndIf} michael@0: michael@0: WriteUninstaller "$INSTDIR\Uninstall.exe" michael@0: WriteRegStr HKLM "${MaintUninstallKey}" "DisplayName" "${MaintFullName}" michael@0: WriteRegStr HKLM "${MaintUninstallKey}" "UninstallString" \ michael@0: '"$INSTDIR\uninstall.exe"' michael@0: WriteRegStr HKLM "${MaintUninstallKey}" "DisplayIcon" \ michael@0: "$INSTDIR\Uninstall.exe,0" michael@0: WriteRegStr HKLM "${MaintUninstallKey}" "DisplayVersion" "${AppVersion}" michael@0: WriteRegStr HKLM "${MaintUninstallKey}" "Publisher" "Mozilla" michael@0: WriteRegStr HKLM "${MaintUninstallKey}" "Comments" \ michael@0: "${BrandFullName} ${AppVersion} (${ARCH} ${AB_CD})" michael@0: WriteRegDWORD HKLM "${MaintUninstallKey}" "NoModify" 1 michael@0: ${GetSize} "$INSTDIR" "/S=0K" $R2 $R3 $R4 michael@0: WriteRegDWORD HKLM "${MaintUninstallKey}" "EstimatedSize" $R2 michael@0: michael@0: ; Write out that a maintenance service was attempted. michael@0: ; We do this because on upgrades we will check this value and we only michael@0: ; want to install once on the first upgrade to maintenance service. michael@0: ; Also write out that we are currently installed, preferences will check michael@0: ; this value to determine if we should show the service update pref. michael@0: ; Since the Maintenance service can be installed either x86 or x64, michael@0: ; always use the 64-bit registry for checking if an attempt was made. michael@0: ${If} ${RunningX64} michael@0: SetRegView 64 michael@0: ${EndIf} michael@0: WriteRegDWORD HKLM "Software\Mozilla\MaintenanceService" "Attempted" 1 michael@0: WriteRegDWORD HKLM "Software\Mozilla\MaintenanceService" "Installed" 1 michael@0: DeleteRegValue HKLM "Software\Mozilla\MaintenanceService" "FFPrefetchDisabled" michael@0: michael@0: ; Included here for debug purposes only. michael@0: ; These keys are used to bypass the installation dir is a valid installation michael@0: ; check from the service so that tests can be run. michael@0: ; WriteRegStr HKLM "${FallbackKey}\0" "name" "Mozilla Corporation" michael@0: ; WriteRegStr HKLM "${FallbackKey}\0" "issuer" "DigiCert Assured ID Code Signing CA-1" michael@0: ${If} ${RunningX64} michael@0: SetRegView lastused michael@0: ${EndIf} michael@0: SectionEnd michael@0: michael@0: ; By renaming before deleting we improve things slightly in case michael@0: ; there is a file in use error. In this case a new install can happen. michael@0: Function un.RenameDelete michael@0: Pop $9 michael@0: ; If the .moz-delete file already exists previously, delete it michael@0: ; If it doesn't exist, the call is ignored. michael@0: ; We don't need to pass /REBOOTOK here since it was already marked that way michael@0: ; if it exists. michael@0: Delete "$9.moz-delete" michael@0: Rename "$9" "$9.moz-delete" michael@0: ${If} ${Errors} michael@0: Delete /REBOOTOK "$9" michael@0: ${Else} michael@0: Delete /REBOOTOK "$9.moz-delete" michael@0: ${EndIf} michael@0: ClearErrors michael@0: FunctionEnd michael@0: michael@0: Section "Uninstall" michael@0: ; Delete the service so that no updates will be attempted michael@0: nsExec::Exec '"$INSTDIR\maintenanceservice.exe" uninstall' michael@0: michael@0: Push "$INSTDIR\updater.ini" michael@0: Call un.RenameDelete michael@0: Push "$INSTDIR\maintenanceservice.exe" michael@0: Call un.RenameDelete michael@0: Push "$INSTDIR\maintenanceservice_tmp.exe" michael@0: Call un.RenameDelete michael@0: Push "$INSTDIR\maintenanceservice.old" michael@0: Call un.RenameDelete michael@0: Push "$INSTDIR\Uninstall.exe" michael@0: Call un.RenameDelete michael@0: Push "$INSTDIR\update\updater.ini" michael@0: Call un.RenameDelete michael@0: Push "$INSTDIR\update\updater.exe" michael@0: Call un.RenameDelete michael@0: RMDir /REBOOTOK "$INSTDIR\update" michael@0: RMDir /REBOOTOK "$INSTDIR" michael@0: michael@0: DeleteRegKey HKLM "${MaintUninstallKey}" michael@0: michael@0: ${If} ${RunningX64} michael@0: SetRegView 64 michael@0: ${EndIf} michael@0: DeleteRegValue HKLM "Software\Mozilla\MaintenanceService" "Installed" michael@0: DeleteRegValue HKLM "Software\Mozilla\MaintenanceService" "FFPrefetchDisabled" michael@0: DeleteRegKey HKLM "${FallbackKey}\" michael@0: ${If} ${RunningX64} michael@0: SetRegView lastused michael@0: ${EndIf} michael@0: SectionEnd