Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 # Required Plugins:
6 # AppAssocReg
7 # CertCheck
8 # InetBgDL
9 # ShellLink
10 # UAC
12 ; Set verbosity to 3 (e.g. no script) to lessen the noise in the build logs
13 !verbose 3
15 SetDatablockOptimize on
16 SetCompress off
17 CRCCheck on
19 RequestExecutionLevel user
21 ; The commands inside this ifdef require NSIS 3.0a2 or greater so the ifdef can
22 ; be removed after we require NSIS 3.0a2 or greater.
23 !ifdef NSIS_PACKEDVERSION
24 Unicode true
25 ManifestSupportedOS all
26 ManifestDPIAware true
27 !endif
29 !addplugindir ./
31 Var Dialog
32 Var Progressbar
33 Var ProgressbarMarqueeIntervalMS
34 Var LabelDownloading
35 Var LabelInstalling
36 Var LabelFreeSpace
37 Var CheckboxSetAsDefault
38 Var CheckboxShortcutOnBar ; Used for Quicklaunch or Taskbar as appropriate
39 Var CheckboxShortcutInStartMenu
40 Var CheckboxShortcutOnDesktop
41 Var CheckboxSendPing
42 Var CheckboxInstallMaintSvc
43 Var DirRequest
44 Var ButtonBrowse
45 Var LabelBlurb1
46 Var LabelBlurb2
47 Var LabelBlurb3
48 Var BitmapBlurb1
49 Var BitmapBlurb2
50 Var BitmapBlurb3
51 Var HwndBitmapBlurb1
52 Var HwndBitmapBlurb2
53 Var HWndBitmapBlurb3
55 Var FontNormal
56 Var FontItalic
57 Var FontBlurb
59 Var WasOptionsButtonClicked
60 Var CanWriteToInstallDir
61 Var HasRequiredSpaceAvailable
62 Var IsDownloadFinished
63 Var DownloadSizeBytes
64 Var HalfOfDownload
65 Var DownloadReset
66 Var ExistingTopDir
67 Var SpaceAvailableBytes
68 Var InitialInstallDir
69 Var HandleDownload
70 Var CanSetAsDefault
71 Var InstallCounterStep
72 Var InstallStepSize
73 Var InstallTotalSteps
74 Var TmpVal
76 Var ExitCode
77 Var FirefoxLaunchCode
79 ; The first three tick counts are for the start of a phase and equate equate to
80 ; the display of individual installer pages.
81 Var StartIntroPhaseTickCount
82 Var StartOptionsPhaseTickCount
83 Var StartDownloadPhaseTickCount
84 ; Since the Intro and Options pages can be displayed multiple times the total
85 ; seconds spent on each of these pages is reported.
86 Var IntroPhaseSeconds
87 Var OptionsPhaseSeconds
88 ; The tick count for the last download.
89 Var StartLastDownloadTickCount
90 ; The number of seconds from the start of the download phase until the first
91 ; bytes are received. This is only recorded for first request so it is possible
92 ; to determine connection issues for the first request.
93 Var DownloadFirstTransferSeconds
94 ; The last four tick counts are for the end of a phase in the installation page.
95 Var EndDownloadPhaseTickCount
96 Var EndPreInstallPhaseTickCount
97 Var EndInstallPhaseTickCount
98 Var EndFinishPhaseTickCount
100 Var InitialInstallRequirementsCode
101 Var ExistingProfile
102 Var ExistingVersion
103 Var ExistingBuildID
104 Var DownloadedBytes
105 Var DownloadRetryCount
106 Var OpenedDownloadPage
107 Var DownloadServerIP
109 Var ControlHeightPX
110 Var ControlRightPX
112 ; Uncomment the following to prevent pinging the metrics server when testing
113 ; the stub installer
114 ;!define STUB_DEBUG
116 !define StubURLVersion "v6"
118 ; Successful install exit code
119 !define ERR_SUCCESS 0
121 /**
122 * The following errors prefixed with ERR_DOWNLOAD apply to the download phase.
123 */
124 ; The download was cancelled by the user
125 !define ERR_DOWNLOAD_CANCEL 10
127 ; Too many attempts to download. The maximum attempts is defined in
128 ; DownloadMaxRetries.
129 !define ERR_DOWNLOAD_TOO_MANY_RETRIES 11
131 /**
132 * The following errors prefixed with ERR_PREINSTALL apply to the pre-install
133 * check phase.
134 */
135 ; Unable to acquire a file handle to the downloaded file
136 !define ERR_PREINSTALL_INVALID_HANDLE 20
138 ; The downloaded file's certificate is not trusted by the certificate store.
139 !define ERR_PREINSTALL_CERT_UNTRUSTED 21
141 ; The downloaded file's certificate attribute values were incorrect.
142 !define ERR_PREINSTALL_CERT_ATTRIBUTES 22
144 ; The downloaded file's certificate is not trusted by the certificate store and
145 ; certificate attribute values were incorrect.
146 !define ERR_PREINSTALL_CERT_UNTRUSTED_AND_ATTRIBUTES 23
148 /**
149 * The following errors prefixed with ERR_INSTALL apply to the install phase.
150 */
151 ; The installation timed out. The installation timeout is defined by the number
152 ; of progress steps defined in InstallTotalSteps and the install timer
153 ; interval defined in InstallIntervalMS
154 !define ERR_INSTALL_TIMEOUT 30
156 ; Maximum times to retry the download before displaying an error
157 !define DownloadMaxRetries 9
159 ; Minimum size expected to download in bytes
160 !define DownloadMinSizeBytes 15728640 ; 15 MB
162 ; Maximum size expected to download in bytes
163 !define DownloadMaxSizeBytes 36700160 ; 35 MB
165 ; Interval before retrying to download. 3 seconds is used along with 10
166 ; attempted downloads (the first attempt along with 9 retries) to give a
167 ; minimum of 30 seconds or retrying before giving up.
168 !define DownloadRetryIntervalMS 3000
170 ; Interval for the download timer
171 !define DownloadIntervalMS 200
173 ; Interval for the install timer
174 !define InstallIntervalMS 100
176 ; The first step for the install progress bar. By starting with a large step
177 ; immediate feedback is given to the user.
178 !define InstallProgressFirstStep 20
180 ; The finish step size to quickly increment the progress bar after the
181 ; installation has finished.
182 !define InstallProgressFinishStep 40
184 ; Number of steps for the install progress.
185 ; This might not be enough when installing on a slow network drive so it will
186 ; fallback to downloading the full installer if it reaches this number. The size
187 ; of the install progress step is increased when the full installer finishes
188 ; instead of waiting.
190 ; Approximately 150 seconds with a 100 millisecond timer and a first step of 20
191 ; as defined by InstallProgressFirstStep.
192 !define /math InstallCleanTotalSteps ${InstallProgressFirstStep} + 1500
194 ; Approximately 165 seconds (minus 0.2 seconds for each file that is removed)
195 ; with a 100 millisecond timer and a first step of 20 as defined by
196 ; InstallProgressFirstStep .
197 !define /math InstallPaveOverTotalSteps ${InstallProgressFirstStep} + 1800
199 ; On Vista and above attempt to elevate Standard Users in addition to users that
200 ; are a member of the Administrators group.
201 !define NONADMIN_ELEVATE
203 !define CONFIG_INI "config.ini"
205 !ifndef FILE_SHARE_READ
206 !define FILE_SHARE_READ 1
207 !endif
208 !ifndef GENERIC_READ
209 !define GENERIC_READ 0x80000000
210 !endif
211 !ifndef OPEN_EXISTING
212 !define OPEN_EXISTING 3
213 !endif
214 !ifndef INVALID_HANDLE_VALUE
215 !define INVALID_HANDLE_VALUE -1
216 !endif
218 !include "nsDialogs.nsh"
219 !include "LogicLib.nsh"
220 !include "FileFunc.nsh"
221 !include "WinVer.nsh"
222 !include "WordFunc.nsh"
224 !insertmacro GetParameters
225 !insertmacro GetOptions
226 !insertmacro StrFilter
228 !include "locales.nsi"
229 !include "branding.nsi"
231 !include "defines.nsi"
233 ; Must be included after defines.nsi
234 !include "locale-fonts.nsh"
236 ; The OFFICIAL define is a workaround to support different urls for Release and
237 ; Beta since they share the same branding when building with other branches that
238 ; set the update channel to beta.
239 !ifdef OFFICIAL
240 !ifdef BETA_UPDATE_CHANNEL
241 !undef URLStubDownload
242 !define URLStubDownload "http://download.mozilla.org/?os=win&lang=${AB_CD}&product=firefox-beta-latest"
243 !undef URLManualDownload
244 !define URLManualDownload "https://www.mozilla.org/${AB_CD}/firefox/installer-help/?channel=beta&installer_lang=${AB_CD}"
245 !undef Channel
246 !define Channel "beta"
247 !endif
248 !endif
250 !include "common.nsh"
252 !insertmacro ElevateUAC
253 !insertmacro GetLongPath
254 !insertmacro GetPathFromString
255 !insertmacro GetParent
256 !insertmacro GetSingleInstallPath
257 !insertmacro GetTextWidthHeight
258 !insertmacro IsUserAdmin
259 !insertmacro OnStubInstallUninstall
260 !insertmacro SetBrandNameVars
261 !insertmacro UnloadUAC
263 VIAddVersionKey "FileDescription" "${BrandShortName} Stub Installer"
264 VIAddVersionKey "OriginalFilename" "setup-stub.exe"
266 Name "$BrandFullName"
267 OutFile "setup-stub.exe"
268 icon "setup.ico"
269 XPStyle on
270 BrandingText " "
271 ChangeUI all "nsisui.exe"
272 !ifdef HAVE_64BIT_OS
273 InstallDir "$PROGRAMFILES64\${BrandFullName}\"
274 !else
275 InstallDir "$PROGRAMFILES32\${BrandFullName}\"
276 !endif
278 !ifdef ${AB_CD}_rtl
279 LoadLanguageFile "locale-rtl.nlf"
280 !else
281 LoadLanguageFile "locale.nlf"
282 !endif
284 !include "nsisstrings.nlf"
286 !if "${AB_CD}" == "en-US"
287 ; Custom strings for en-US. This is done here so they aren't translated.
288 !include oneoff_en-US.nsh
289 !else
290 !define INTRO_BLURB "$(INTRO_BLURB1)"
291 !define INSTALL_BLURB1 "$(INSTALL_BLURB1)"
292 !define INSTALL_BLURB2 "$(INSTALL_BLURB2)"
293 !define INSTALL_BLURB3 "$(INSTALL_BLURB3)"
294 !endif
296 Caption "$(WIN_CAPTION)"
298 Page custom createDummy ; Needed to enable the Intro page's back button
299 Page custom createIntro leaveIntro ; Introduction page
300 Page custom createOptions leaveOptions ; Options page
301 Page custom createInstall ; Download / Installation page
303 Function .onInit
304 ; Remove the current exe directory from the search order.
305 ; This only effects LoadLibrary calls and not implicitly loaded DLLs.
306 System::Call 'kernel32::SetDllDirectoryW(w "")'
308 StrCpy $LANGUAGE 0
309 ; This macro is used to set the brand name variables but the ini file method
310 ; isn't supported for the stub installer.
311 ${SetBrandNameVars} "$PLUGINSDIR\ignored.ini"
313 !ifdef HAVE_64BIT_OS
314 ; Restrict x64 builds from being installed on x86 and pre Vista
315 ${Unless} ${RunningX64}
316 ${OrUnless} ${AtLeastWinVista}
317 MessageBox MB_OK|MB_ICONSTOP "$(WARN_MIN_SUPPORTED_OS_MSG)"
318 Quit
319 ${EndUnless}
321 SetRegView 64
322 !else
323 StrCpy $R8 "0"
324 ${If} ${AtMostWin2000}
325 StrCpy $R8 "1"
326 ${EndIf}
328 ${If} ${IsWinXP}
329 ${AndIf} ${AtMostServicePack} 1
330 StrCpy $R8 "1"
331 ${EndIf}
333 ${If} $R8 == "1"
334 ; XXX-rstrong - some systems failed the AtLeastWin2000 test that we
335 ; used to use for an unknown reason and likely fail the AtMostWin2000
336 ; and possibly the IsWinXP test as well. To work around this also
337 ; check if the Windows NT registry Key exists and if it does if the
338 ; first char in CurrentVersion is equal to 3 (Windows NT 3.5 and
339 ; 3.5.1), 4 (Windows NT 4), or 5 (Windows 2000 and Windows XP).
340 StrCpy $R8 ""
341 ClearErrors
342 ReadRegStr $R8 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" "CurrentVersion"
343 StrCpy $R8 "$R8" 1
344 ${If} ${Errors}
345 ${OrIf} "$R8" == "3"
346 ${OrIf} "$R8" == "4"
347 ${OrIf} "$R8" == "5"
348 MessageBox MB_OK|MB_ICONSTOP "$(WARN_MIN_SUPPORTED_OS_MSG)"
349 Quit
350 ${EndIf}
351 ${EndUnless}
352 !endif
354 ; Require elevation if the user can elevate
355 ${ElevateUAC}
357 ; The commands inside this ifndef are needed prior to NSIS 3.0a2 and can be
358 ; removed after we require NSIS 3.0a2 or greater.
359 !ifndef NSIS_PACKEDVERSION
360 ${If} ${AtLeastWinVista}
361 System::Call 'user32::SetProcessDPIAware()'
362 ${EndIf}
363 !endif
365 SetShellVarContext all ; Set SHCTX to HKLM
366 ${GetSingleInstallPath} "Software\Mozilla\${BrandFullNameInternal}" $R9
368 ${If} "$R9" == "false"
369 SetShellVarContext current ; Set SHCTX to HKCU
370 ${GetSingleInstallPath} "Software\Mozilla\${BrandFullNameInternal}" $R9
371 ${EndIf}
373 ${If} "$R9" != "false"
374 StrCpy $INSTDIR "$R9"
375 ${EndIf}
377 ; Used to determine if the default installation directory was used.
378 StrCpy $InitialInstallDir "$INSTDIR"
380 ClearErrors
381 WriteRegStr HKLM "Software\Mozilla" "${BrandShortName}InstallerTest" \
382 "Write Test"
384 ; Only display set as default when there is write access to HKLM and on Win7
385 ; and below.
386 ${If} ${Errors}
387 ${OrIf} ${AtLeastWin8}
388 StrCpy $CanSetAsDefault "false"
389 StrCpy $CheckboxSetAsDefault "0"
390 ${Else}
391 DeleteRegValue HKLM "Software\Mozilla" "${BrandShortName}InstallerTest"
392 StrCpy $CanSetAsDefault "true"
393 ${EndIf}
395 ; The interval in MS used for the progress bars set as marquee.
396 ${If} ${AtLeastWinVista}
397 StrCpy $ProgressbarMarqueeIntervalMS "10"
398 ${Else}
399 StrCpy $ProgressbarMarqueeIntervalMS "50"
400 ${EndIf}
402 ; Initialize the majority of variables except those that need to be reset
403 ; when a page is displayed.
404 StrCpy $IntroPhaseSeconds "0"
405 StrCpy $OptionsPhaseSeconds "0"
406 StrCpy $EndPreInstallPhaseTickCount "0"
407 StrCpy $EndInstallPhaseTickCount "0"
408 StrCpy $InitialInstallRequirementsCode ""
409 StrCpy $IsDownloadFinished ""
410 StrCpy $FirefoxLaunchCode "0"
411 StrCpy $CheckboxShortcutOnBar "1"
412 StrCpy $CheckboxShortcutInStartMenu "1"
413 StrCpy $CheckboxShortcutOnDesktop "1"
414 StrCpy $CheckboxSendPing "1"
415 !ifdef MOZ_MAINTENANCE_SERVICE
416 StrCpy $CheckboxInstallMaintSvc "1"
417 !else
418 StrCpy $CheckboxInstallMaintSvc "0"
419 !endif
420 StrCpy $WasOptionsButtonClicked "0"
422 StrCpy $0 ""
423 !ifdef FONT_FILE1
424 ${If} ${FileExists} "$FONTS\${FONT_FILE1}"
425 StrCpy $0 "${FONT_NAME1}"
426 ${EndIf}
427 !endif
429 !ifdef FONT_FILE2
430 ${If} $0 == ""
431 ${AndIf} ${FileExists} "$FONTS\${FONT_FILE2}"
432 StrCpy $0 "${FONT_NAME2}"
433 ${EndIf}
434 !endif
436 ${If} $0 == ""
437 StrCpy $0 "$(^Font)"
438 ${EndIf}
440 CreateFont $FontBlurb "$0" "12" "500"
441 CreateFont $FontNormal "$0" "11" "500"
442 CreateFont $FontItalic "$0" "11" "500" /ITALIC
444 InitPluginsDir
445 File /oname=$PLUGINSDIR\bgintro.bmp "bgintro.bmp"
446 File /oname=$PLUGINSDIR\appname.bmp "appname.bmp"
447 File /oname=$PLUGINSDIR\clock.bmp "clock.bmp"
448 File /oname=$PLUGINSDIR\particles.bmp "particles.bmp"
449 !ifdef ${AB_CD}_rtl
450 ; The horizontally flipped pencil looks better in RTL
451 File /oname=$PLUGINSDIR\pencil.bmp "pencil-rtl.bmp"
452 !else
453 File /oname=$PLUGINSDIR\pencil.bmp "pencil.bmp"
454 !endif
455 FunctionEnd
457 ; .onGUIInit isn't needed except for RTL locales
458 !ifdef ${AB_CD}_rtl
459 Function .onGUIInit
460 ; Since NSIS RTL support doesn't mirror progress bars use Windows mirroring.
461 ${NSD_AddExStyle} $HWNDPARENT ${WS_EX_LAYOUTRTL}
462 ${RemoveExStyle} $HWNDPARENT ${WS_EX_RTLREADING}
463 ${RemoveExStyle} $HWNDPARENT ${WS_EX_RIGHT}
464 ${NSD_AddExStyle} $HWNDPARENT ${WS_EX_LEFT}|${WS_EX_LTRREADING}
465 FunctionEnd
466 !endif
468 Function .onGUIEnd
469 Delete "$PLUGINSDIR\_temp"
470 Delete "$PLUGINSDIR\download.exe"
471 Delete "$PLUGINSDIR\${CONFIG_INI}"
473 ${UnloadUAC}
474 FunctionEnd
476 Function .onUserAbort
477 ${NSD_KillTimer} StartDownload
478 ${NSD_KillTimer} OnDownload
479 ${NSD_KillTimer} CheckInstall
480 ${NSD_KillTimer} FinishInstall
481 ${NSD_KillTimer} FinishProgressBar
482 ${NSD_KillTimer} DisplayDownloadError
484 ${If} "$IsDownloadFinished" != ""
485 Call DisplayDownloadError
486 ; Aborting the abort will allow SendPing which is called by
487 ; DisplayDownloadError to hide the installer window and close the installer
488 ; after it sends the metrics ping.
489 Abort
490 ${EndIf}
491 FunctionEnd
493 Function SendPing
494 HideWindow
495 ; Try to send a ping if a download was attempted
496 ${If} $CheckboxSendPing == 1
497 ${AndIf} $IsDownloadFinished != ""
498 ; Get the tick count for the completion of all phases.
499 System::Call "kernel32::GetTickCount()l .s"
500 Pop $EndFinishPhaseTickCount
502 ; When the value of $IsDownloadFinished is false the download was started
503 ; but didn't finish. In this case the tick count stored in
504 ; $EndFinishPhaseTickCount is used to determine how long the download was
505 ; in progress.
506 ${If} "$IsDownloadFinished" == "false"
507 ${OrIf} "$EndDownloadPhaseTickCount" == ""
508 StrCpy $EndDownloadPhaseTickCount "$EndFinishPhaseTickCount"
509 ; Cancel the download in progress
510 InetBgDL::Get /RESET /END
511 ${EndIf}
514 ; When $DownloadFirstTransferSeconds equals an empty string the download
515 ; never successfully started so set the value to 0. It will be possible to
516 ; determine that the download didn't successfully start from the seconds for
517 ; the last download.
518 ${If} "$DownloadFirstTransferSeconds" == ""
519 StrCpy $DownloadFirstTransferSeconds "0"
520 ${EndIf}
522 ; When $StartLastDownloadTickCount equals an empty string the download never
523 ; successfully started so set the value to $EndDownloadPhaseTickCount to
524 ; compute the correct value.
525 ${If} $StartLastDownloadTickCount == ""
526 ; This could happen if the download never successfully starts
527 StrCpy $StartLastDownloadTickCount "$EndDownloadPhaseTickCount"
528 ${EndIf}
530 ; When $EndPreInstallPhaseTickCount equals 0 the installation phase was
531 ; never completed so set its value to $EndFinishPhaseTickCount to compute
532 ; the correct value.
533 ${If} "$EndPreInstallPhaseTickCount" == "0"
534 StrCpy $EndPreInstallPhaseTickCount "$EndFinishPhaseTickCount"
535 ${EndIf}
537 ; When $EndInstallPhaseTickCount equals 0 the installation phase was never
538 ; completed so set its value to $EndFinishPhaseTickCount to compute the
539 ; correct value.
540 ${If} "$EndInstallPhaseTickCount" == "0"
541 StrCpy $EndInstallPhaseTickCount "$EndFinishPhaseTickCount"
542 ${EndIf}
544 ; Get the seconds elapsed from the start of the download phase to the end of
545 ; the download phase.
546 ${GetSecondsElapsed} "$StartDownloadPhaseTickCount" "$EndDownloadPhaseTickCount" $0
548 ; Get the seconds elapsed from the start of the last download to the end of
549 ; the last download.
550 ${GetSecondsElapsed} "$StartLastDownloadTickCount" "$EndDownloadPhaseTickCount" $1
552 ; Get the seconds elapsed from the end of the download phase to the
553 ; completion of the pre-installation check phase.
554 ${GetSecondsElapsed} "$EndDownloadPhaseTickCount" "$EndPreInstallPhaseTickCount" $2
556 ; Get the seconds elapsed from the end of the pre-installation check phase
557 ; to the completion of the installation phase.
558 ${GetSecondsElapsed} "$EndPreInstallPhaseTickCount" "$EndInstallPhaseTickCount" $3
560 ; Get the seconds elapsed from the end of the installation phase to the
561 ; completion of all phases.
562 ${GetSecondsElapsed} "$EndInstallPhaseTickCount" "$EndFinishPhaseTickCount" $4
564 !ifdef HAVE_64BIT_OS
565 StrCpy $R0 "1"
566 !else
567 StrCpy $R0 "0"
568 !endif
570 ${If} ${RunningX64}
571 StrCpy $R1 "1"
572 ${Else}
573 StrCpy $R1 "0"
574 ${EndIf}
576 ; Though these values are sometimes incorrect due to bug 444664 it happens
577 ; so rarely it isn't worth working around it by reading the registry values.
578 ${WinVerGetMajor} $5
579 ${WinVerGetMinor} $6
580 ${WinVerGetBuild} $7
581 ${WinVerGetServicePackLevel} $8
582 ${If} ${IsServerOS}
583 StrCpy $9 "1"
584 ${Else}
585 StrCpy $9 "0"
586 ${EndIf}
588 ${If} "$ExitCode" == "${ERR_SUCCESS}"
589 ReadINIStr $R5 "$INSTDIR\application.ini" "App" "Version"
590 ReadINIStr $R6 "$INSTDIR\application.ini" "App" "BuildID"
591 ${Else}
592 StrCpy $R5 "0"
593 StrCpy $R6 "0"
594 ${EndIf}
596 ; Whether installed into the default installation directory
597 ${GetLongPath} "$INSTDIR" $R7
598 ${GetLongPath} "$InitialInstallDir" $R8
599 ${If} "$R7" == "$R8"
600 StrCpy $R7 "1"
601 ${Else}
602 StrCpy $R7 "0"
603 ${EndIf}
605 ClearErrors
606 WriteRegStr HKLM "Software\Mozilla" "${BrandShortName}InstallerTest" \
607 "Write Test"
608 ${If} ${Errors}
609 StrCpy $R8 "0"
610 ${Else}
611 DeleteRegValue HKLM "Software\Mozilla" "${BrandShortName}InstallerTest"
612 StrCpy $R8 "1"
613 ${EndIf}
615 ${If} "$DownloadServerIP" == ""
616 StrCpy $DownloadServerIP "Unknown"
617 ${EndIf}
619 StrCpy $R2 ""
620 SetShellVarContext current ; Set SHCTX to the current user
621 ReadRegStr $R2 HKCU "Software\Classes\http\shell\open\command" ""
622 ${If} $R2 != ""
623 ${GetPathFromString} "$R2" $R2
624 ${GetParent} "$R2" $R3
625 ${GetLongPath} "$R3" $R3
626 ${If} $R3 == $INSTDIR
627 StrCpy $R2 "1" ; This Firefox install is set as default.
628 ${Else}
629 StrCpy $R2 "$R2" "" -11 # length of firefox.exe
630 ${If} "$R2" == "${FileMainEXE}"
631 StrCpy $R2 "2" ; Another Firefox install is set as default.
632 ${Else}
633 StrCpy $R2 "0"
634 ${EndIf}
635 ${EndIf}
636 ${Else}
637 StrCpy $R2 "0" ; Firefox is not set as default.
638 ${EndIf}
640 ${If} "$R2" == "0"
641 ${AndIf} ${AtLeastWinVista}
642 ; Check to see if this install location is currently set as the default
643 ; browser by Default Programs which is only available on Vista and above.
644 ClearErrors
645 ReadRegStr $R3 HKLM "Software\RegisteredApplications" "${AppRegName}"
646 ${Unless} ${Errors}
647 AppAssocReg::QueryAppIsDefaultAll "${AppRegName}" "effective"
648 Pop $R3
649 ${If} $R3 == "1"
650 StrCpy $R3 ""
651 ReadRegStr $R2 HKLM "Software\Classes\http\shell\open\command" ""
652 ${If} $R2 != ""
653 ${GetPathFromString} "$R2" $R2
654 ${GetParent} "$R2" $R3
655 ${GetLongPath} "$R3" $R3
656 ${If} $R3 == $INSTDIR
657 StrCpy $R2 "1" ; This Firefox install is set as default.
658 ${Else}
659 StrCpy $R2 "$R2" "" -11 # length of firefox.exe
660 ${If} "$R2" == "${FileMainEXE}"
661 StrCpy $R2 "2" ; Another Firefox install is set as default.
662 ${Else}
663 StrCpy $R2 "0"
664 ${EndIf}
665 ${EndIf}
666 ${Else}
667 StrCpy $R2 "0" ; Firefox is not set as default.
668 ${EndIf}
669 ${EndIf}
670 ${EndUnless}
671 ${EndIf}
673 ${If} $CanSetAsDefault == "true"
674 ${If} $CheckboxSetAsDefault == "1"
675 StrCpy $R3 "2"
676 ${Else}
677 StrCpy $R3 "3"
678 ${EndIf}
679 ${Else}
680 ${If} ${AtLeastWin8}
681 StrCpy $R3 "1"
682 ${Else}
683 StrCpy $R3 "0"
684 ${EndIf}
685 ${EndIf}
687 !ifdef STUB_DEBUG
688 MessageBox MB_OK "${BaseURLStubPing} \
689 $\nStub URL Version = ${StubURLVersion}${StubURLVersionAppend} \
690 $\nBuild Channel = ${Channel} \
691 $\nUpdate Channel = ${UpdateChannel} \
692 $\nLocale = ${AB_CD} \
693 $\nFirefox x64 = $R0 \
694 $\nRunning x64 Windows = $R1 \
695 $\nMajor = $5 \
696 $\nMinor = $6 \
697 $\nBuild = $7 \
698 $\nServicePack = $8 \
699 $\nIsServer = $9 \
700 $\nExit Code = $ExitCode \
701 $\nFirefox Launch Code = $FirefoxLaunchCode \
702 $\nDownload Retry Count = $DownloadRetryCount \
703 $\nDownloaded Bytes = $DownloadedBytes \
704 $\nDownload Size Bytes = $DownloadSizeBytes \
705 $\nIntroduction Phase Seconds = $IntroPhaseSeconds \
706 $\nOptions Phase Seconds = $OptionsPhaseSeconds \
707 $\nDownload Phase Seconds = $0 \
708 $\nLast Download Seconds = $1 \
709 $\nDownload First Transfer Seconds = $DownloadFirstTransferSeconds \
710 $\nPreinstall Phase Seconds = $2 \
711 $\nInstall Phase Seconds = $3 \
712 $\nFinish Phase Seconds = $4 \
713 $\nInitial Install Requirements Code = $InitialInstallRequirementsCode \
714 $\nOpened Download Page = $OpenedDownloadPage \
715 $\nExisting Profile = $ExistingProfile \
716 $\nExisting Version = $ExistingVersion \
717 $\nExisting Build ID = $ExistingBuildID \
718 $\nNew Version = $R5 \
719 $\nNew Build ID = $R6 \
720 $\nDefault Install Dir = $R7 \
721 $\nHas Admin = $R8 \
722 $\nDefault Status = $R2 \
723 $\nSet As Sefault Status = $R3 \
724 $\nDownload Server IP = $DownloadServerIP"
725 ; The following will exit the installer
726 SetAutoClose true
727 StrCpy $R9 "2"
728 Call RelativeGotoPage
729 !else
730 ${NSD_CreateTimer} OnPing ${DownloadIntervalMS}
731 InetBgDL::Get "${BaseURLStubPing}/${StubURLVersion}${StubURLVersionAppend}/${Channel}/${UpdateChannel}/${AB_CD}/$R0/$R1/$5/$6/$7/$8/$9/$ExitCode/$FirefoxLaunchCode/$DownloadRetryCount/$DownloadedBytes/$DownloadSizeBytes/$IntroPhaseSeconds/$OptionsPhaseSeconds/$0/$1/$DownloadFirstTransferSeconds/$2/$3/$4/$InitialInstallRequirementsCode/$OpenedDownloadPage/$ExistingProfile/$ExistingVersion/$ExistingBuildID/$R5/$R6/$R7/$R8/$R2/$R3/$DownloadServerIP" \
732 "$PLUGINSDIR\_temp" /END
733 !endif
734 ${Else}
735 ${If} "$IsDownloadFinished" == "false"
736 ; Cancel the download in progress
737 InetBgDL::Get /RESET /END
738 ${EndIf}
739 ; The following will exit the installer
740 SetAutoClose true
741 StrCpy $R9 "2"
742 Call RelativeGotoPage
743 ${EndIf}
744 FunctionEnd
746 Function createDummy
747 FunctionEnd
749 Function createIntro
750 nsDialogs::Create /NOUNLOAD 1018
751 Pop $Dialog
753 GetFunctionAddress $0 OnBack
754 nsDialogs::OnBack /NOUNLOAD $0
756 !ifdef ${AB_CD}_rtl
757 ; For RTL align the text with the top of the F in the Firefox bitmap
758 StrCpy $0 "${INTRO_BLURB_RTL_TOP_DU}"
759 !else
760 ; For LTR align the text with the top of the x in the Firefox bitmap
761 StrCpy $0 "${INTRO_BLURB_LTR_TOP_DU}"
762 !endif
763 ${NSD_CreateLabel} ${INTRO_BLURB_EDGE_DU} $0 ${INTRO_BLURB_WIDTH_DU} 76u "${INTRO_BLURB}"
764 Pop $0
765 SendMessage $0 ${WM_SETFONT} $FontBlurb 0
766 SetCtlColors $0 ${INTRO_BLURB_TEXT_COLOR} transparent
768 SetCtlColors $HWNDPARENT ${FOOTER_CONTROL_TEXT_COLOR_NORMAL} ${FOOTER_BKGRD_COLOR}
769 GetDlgItem $0 $HWNDPARENT 10 ; Default browser checkbox
770 ${If} "$CanSetAsDefault" == "true"
771 ; The uxtheme must be disabled on checkboxes in order to override the
772 ; system font color.
773 System::Call 'uxtheme::SetWindowTheme(i $0 , w " ", w " ")'
774 SendMessage $0 ${WM_SETFONT} $FontNormal 0
775 SendMessage $0 ${WM_SETTEXT} 0 "STR:$(MAKE_DEFAULT)"
776 SendMessage $0 ${BM_SETCHECK} 1 0
777 SetCtlColors $0 ${FOOTER_CONTROL_TEXT_COLOR_NORMAL} ${FOOTER_BKGRD_COLOR}
778 ${Else}
779 ShowWindow $0 ${SW_HIDE}
780 ${EndIf}
781 GetDlgItem $0 $HWNDPARENT 11
782 ShowWindow $0 ${SW_HIDE}
784 ${NSD_CreateBitmap} ${APPNAME_BMP_EDGE_DU} ${APPNAME_BMP_TOP_DU} \
785 ${APPNAME_BMP_WIDTH_DU} ${APPNAME_BMP_HEIGHT_DU} ""
786 Pop $2
787 ${SetStretchedTransparentImage} $2 $PLUGINSDIR\appname.bmp $0
789 ${NSD_CreateBitmap} 0 0 100% 100% ""
790 Pop $2
791 ${NSD_SetStretchedImage} $2 $PLUGINSDIR\bgintro.bmp $1
793 GetDlgItem $0 $HWNDPARENT 1 ; Install button
794 ${If} ${FileExists} "$INSTDIR\${FileMainEXE}"
795 SendMessage $0 ${WM_SETTEXT} 0 "STR:$(UPGRADE_BUTTON)"
796 ${Else}
797 SendMessage $0 ${WM_SETTEXT} 0 "STR:$(INSTALL_BUTTON)"
798 ${EndIf}
799 ${NSD_SetFocus} $0
801 GetDlgItem $0 $HWNDPARENT 2 ; Cancel button
802 SendMessage $0 ${WM_SETTEXT} 0 "STR:$(CANCEL_BUTTON)"
804 GetDlgItem $0 $HWNDPARENT 3 ; Back button used for Options
805 SendMessage $0 ${WM_SETTEXT} 0 "STR:$(OPTIONS_BUTTON)"
807 System::Call "kernel32::GetTickCount()l .s"
808 Pop $StartIntroPhaseTickCount
810 LockWindow off
811 nsDialogs::Show
813 ${NSD_FreeImage} $0
814 ${NSD_FreeImage} $1
815 FunctionEnd
817 Function leaveIntro
818 LockWindow on
820 System::Call "kernel32::GetTickCount()l .s"
821 Pop $0
822 ${GetSecondsElapsed} "$StartIntroPhaseTickCount" "$0" $IntroPhaseSeconds
823 ; It is possible for this value to be 0 if the user clicks fast enough so
824 ; increment the value by 1 if it is 0.
825 ${If} $IntroPhaseSeconds == 0
826 IntOp $IntroPhaseSeconds $IntroPhaseSeconds + 1
827 ${EndIf}
829 SetShellVarContext all ; Set SHCTX to All Users
830 ; If the user doesn't have write access to the installation directory set
831 ; the installation directory to a subdirectory of the All Users application
832 ; directory and if the user can't write to that location set the installation
833 ; directory to a subdirectory of the users local application directory
834 ; (e.g. non-roaming).
835 Call CanWrite
836 ${If} "$CanWriteToInstallDir" == "false"
837 StrCpy $INSTDIR "$APPDATA\${BrandFullName}\"
838 Call CanWrite
839 ${If} "$CanWriteToInstallDir" == "false"
840 ; This should never happen but just in case.
841 StrCpy $CanWriteToInstallDir "false"
842 ${Else}
843 StrCpy $INSTDIR "$LOCALAPPDATA\${BrandFullName}\"
844 Call CanWrite
845 ${EndIf}
846 ${EndIf}
848 Call CheckSpace
850 ${If} ${FileExists} "$INSTDIR"
851 ; Always display the long path if the path exists.
852 ${GetLongPath} "$INSTDIR" $INSTDIR
853 ${EndIf}
855 FunctionEnd
857 Function createOptions
858 ; Check whether the install requirements are satisfied using the default
859 ; values for metrics.
860 ${If} "$InitialInstallRequirementsCode" == ""
861 ${If} "$CanWriteToInstallDir" != "true"
862 ${AndIf} "$HasRequiredSpaceAvailable" != "true"
863 StrCpy $InitialInstallRequirementsCode "1"
864 ${ElseIf} "$CanWriteToInstallDir" != "true"
865 StrCpy $InitialInstallRequirementsCode "2"
866 ${ElseIf} "$HasRequiredSpaceAvailable" != "true"
867 StrCpy $InitialInstallRequirementsCode "3"
868 ${Else}
869 StrCpy $InitialInstallRequirementsCode "0"
870 ${EndIf}
871 ${EndIf}
873 ; Skip the options page unless the Options button was clicked as long as the
874 ; installation directory can be written to and there is the minimum required
875 ; space available.
876 ${If} "$WasOptionsButtonClicked" != "1"
877 ${If} "$CanWriteToInstallDir" == "true"
878 ${AndIf} "$HasRequiredSpaceAvailable" == "true"
879 Abort ; Skip the options page
880 ${EndIf}
881 ${EndIf}
883 StrCpy $ExistingTopDir ""
885 nsDialogs::Create /NOUNLOAD 1018
886 Pop $Dialog
887 ; Since the text color for controls is set in this Dialog the foreground and
888 ; background colors of the Dialog must also be hardcoded.
889 SetCtlColors $Dialog ${COMMON_TEXT_COLOR_NORMAL} ${COMMON_BKGRD_COLOR}
891 ${NSD_CreateLabel} ${OPTIONS_ITEM_EDGE_DU} 18u ${OPTIONS_ITEM_WIDTH_DU} \
892 12u "$(CREATE_SHORTCUTS)"
893 Pop $0
894 SetCtlColors $0 ${COMMON_TEXT_COLOR_NORMAL} ${COMMON_BKGRD_COLOR}
895 SendMessage $0 ${WM_SETFONT} $FontNormal 0
897 ${If} ${AtLeastWin7}
898 StrCpy $0 "$(ADD_SC_TASKBAR)"
899 ${Else}
900 StrCpy $0 "$(ADD_SC_QUICKLAUNCHBAR)"
901 ${EndIf}
902 ${NSD_CreateCheckbox} ${OPTIONS_SUBITEM_EDGE_DU} 38u \
903 ${OPTIONS_SUBITEM_WIDTH_DU} 12u "$0"
904 Pop $CheckboxShortcutOnBar
905 ; The uxtheme must be disabled on checkboxes in order to override the system
906 ; font color.
907 System::Call 'uxtheme::SetWindowTheme(i $CheckboxShortcutOnBar, w " ", w " ")'
908 SetCtlColors $CheckboxShortcutOnBar ${COMMON_TEXT_COLOR_NORMAL} ${COMMON_BKGRD_COLOR}
909 SendMessage $CheckboxShortcutOnBar ${WM_SETFONT} $FontNormal 0
910 ${NSD_Check} $CheckboxShortcutOnBar
912 ${NSD_CreateCheckbox} ${OPTIONS_SUBITEM_EDGE_DU} 54u ${OPTIONS_SUBITEM_WIDTH_DU} \
913 12u "$(ADD_CheckboxShortcutInStartMenu)"
914 Pop $CheckboxShortcutInStartMenu
915 ; The uxtheme must be disabled on checkboxes in order to override the system
916 ; font color.
917 System::Call 'uxtheme::SetWindowTheme(i $CheckboxShortcutInStartMenu, w " ", w " ")'
918 SetCtlColors $CheckboxShortcutInStartMenu ${COMMON_TEXT_COLOR_NORMAL} ${COMMON_BKGRD_COLOR}
919 SendMessage $CheckboxShortcutInStartMenu ${WM_SETFONT} $FontNormal 0
920 ${NSD_Check} $CheckboxShortcutInStartMenu
922 ${NSD_CreateCheckbox} ${OPTIONS_SUBITEM_EDGE_DU} 70u ${OPTIONS_SUBITEM_WIDTH_DU} \
923 12u "$(ADD_CheckboxShortcutOnDesktop)"
924 Pop $CheckboxShortcutOnDesktop
925 ; The uxtheme must be disabled on checkboxes in order to override the system
926 ; font color.
927 System::Call 'uxtheme::SetWindowTheme(i $CheckboxShortcutOnDesktop, w " ", w " ")'
928 SetCtlColors $CheckboxShortcutOnDesktop ${COMMON_TEXT_COLOR_NORMAL} ${COMMON_BKGRD_COLOR}
929 SendMessage $CheckboxShortcutOnDesktop ${WM_SETFONT} $FontNormal 0
930 ${NSD_Check} $CheckboxShortcutOnDesktop
932 ${NSD_CreateLabel} ${OPTIONS_ITEM_EDGE_DU} 100u ${OPTIONS_ITEM_WIDTH_DU} \
933 12u "$(DEST_FOLDER)"
934 Pop $0
935 SetCtlColors $0 ${COMMON_TEXT_COLOR_NORMAL} ${COMMON_BKGRD_COLOR}
936 SendMessage $0 ${WM_SETFONT} $FontNormal 0
938 ${NSD_CreateDirRequest} ${OPTIONS_SUBITEM_EDGE_DU} 116u 159u 14u "$INSTDIR"
939 Pop $DirRequest
940 SetCtlColors $DirRequest ${COMMON_TEXT_COLOR_NORMAL} ${COMMON_BKGRD_COLOR}
941 SendMessage $DirRequest ${WM_SETFONT} $FontNormal 0
942 System::Call shlwapi::SHAutoComplete(i $DirRequest, i ${SHACF_FILESYSTEM})
943 ${NSD_OnChange} $DirRequest OnChange_DirRequest
945 !ifdef ${AB_CD}_rtl
946 ; Remove the RTL styling from the directory request text box
947 ${RemoveStyle} $DirRequest ${SS_RIGHT}
948 ${RemoveExStyle} $DirRequest ${WS_EX_RIGHT}
949 ${RemoveExStyle} $DirRequest ${WS_EX_RTLREADING}
950 ${NSD_AddStyle} $DirRequest ${SS_LEFT}
951 ${NSD_AddExStyle} $DirRequest ${WS_EX_LTRREADING}|${WS_EX_LEFT}
952 !endif
954 ${NSD_CreateBrowseButton} 280u 116u 50u 14u "$(BROWSE_BUTTON)"
955 Pop $ButtonBrowse
956 SetCtlColors $ButtonBrowse "" ${COMMON_BKGRD_COLOR}
957 ${NSD_OnClick} $ButtonBrowse OnClick_ButtonBrowse
959 ; Get the number of pixels from the left of the Dialog to the right side of
960 ; the "Space Required:" and "Space Available:" labels prior to setting RTL so
961 ; the correct position of the controls can be set by NSIS for RTL locales.
963 ; Get the width and height of both labels and use the tallest for the height
964 ; and the widest to calculate where to place the labels after these labels.
965 ${GetTextExtent} "$(SPACE_REQUIRED)" $FontItalic $0 $1
966 ${GetTextExtent} "$(SPACE_AVAILABLE)" $FontItalic $2 $3
967 ${If} $1 > $3
968 StrCpy $ControlHeightPX "$1"
969 ${Else}
970 StrCpy $ControlHeightPX "$3"
971 ${EndIf}
973 IntOp $0 $0 + 8 ; Add padding to the control's width
974 ; Make both controls the same width as the widest control
975 ${NSD_CreateLabelCenter} ${OPTIONS_SUBITEM_EDGE_DU} 134u $0 $ControlHeightPX "$(SPACE_REQUIRED)"
976 Pop $5
977 SetCtlColors $5 ${COMMON_TEXT_COLOR_FADED} ${COMMON_BKGRD_COLOR}
978 SendMessage $5 ${WM_SETFONT} $FontItalic 0
980 IntOp $2 $2 + 8 ; Add padding to the control's width
981 ${NSD_CreateLabelCenter} ${OPTIONS_SUBITEM_EDGE_DU} 145u $2 $ControlHeightPX "$(SPACE_AVAILABLE)"
982 Pop $6
983 SetCtlColors $6 ${COMMON_TEXT_COLOR_FADED} ${COMMON_BKGRD_COLOR}
984 SendMessage $6 ${WM_SETFONT} $FontItalic 0
986 ; Use the widest label for aligning the labels next to them
987 ${If} $0 > $2
988 StrCpy $6 "$5"
989 ${EndIf}
990 FindWindow $1 "#32770" "" $HWNDPARENT
991 ${GetDlgItemEndPX} $6 $ControlRightPX
993 IntOp $ControlRightPX $ControlRightPX + 6
995 ${NSD_CreateLabel} $ControlRightPX 134u 100% $ControlHeightPX \
996 "${APPROXIMATE_REQUIRED_SPACE_MB} $(MEGA)$(BYTE)"
997 Pop $7
998 SetCtlColors $7 ${COMMON_TEXT_COLOR_NORMAL} ${COMMON_BKGRD_COLOR}
999 SendMessage $7 ${WM_SETFONT} $FontNormal 0
1001 ; Create the free space label with an empty string and update it by calling
1002 ; UpdateFreeSpaceLabel
1003 ${NSD_CreateLabel} $ControlRightPX 145u 100% $ControlHeightPX " "
1004 Pop $LabelFreeSpace
1005 SetCtlColors $LabelFreeSpace ${COMMON_TEXT_COLOR_NORMAL} ${COMMON_BKGRD_COLOR}
1006 SendMessage $LabelFreeSpace ${WM_SETFONT} $FontNormal 0
1008 Call UpdateFreeSpaceLabel
1010 ${NSD_CreateCheckbox} ${OPTIONS_ITEM_EDGE_DU} 168u ${OPTIONS_SUBITEM_WIDTH_DU} \
1011 12u "$(SEND_PING)"
1012 Pop $CheckboxSendPing
1013 ; The uxtheme must be disabled on checkboxes in order to override the system
1014 ; font color.
1015 System::Call 'uxtheme::SetWindowTheme(i $CheckboxSendPing, w " ", w " ")'
1016 SetCtlColors $CheckboxSendPing ${COMMON_TEXT_COLOR_NORMAL} ${COMMON_BKGRD_COLOR}
1017 SendMessage $CheckboxSendPing ${WM_SETFONT} $FontNormal 0
1018 ${NSD_Check} $CheckboxSendPing
1020 !ifdef MOZ_MAINTENANCE_SERVICE
1021 ; Only show the maintenance service checkbox if we have write access to HKLM
1022 Call IsUserAdmin
1023 Pop $0
1024 ClearErrors
1025 WriteRegStr HKLM "Software\Mozilla" "${BrandShortName}InstallerTest" \
1026 "Write Test"
1027 ${If} ${Errors}
1028 ${OrIf} $0 != "true"
1029 StrCpy $CheckboxInstallMaintSvc "0"
1030 ${Else}
1031 DeleteRegValue HKLM "Software\Mozilla" "${BrandShortName}InstallerTest"
1032 ; Read the registry instead of using ServicesHelper::IsInstalled so the
1033 ; plugin isn't included in the stub installer to lessen its size.
1034 ClearErrors
1035 ReadRegStr $0 HKLM "SYSTEM\CurrentControlSet\services\MozillaMaintenance" "ImagePath"
1036 ${If} ${Errors}
1037 ${NSD_CreateCheckbox} ${OPTIONS_ITEM_EDGE_DU} 184u ${OPTIONS_ITEM_WIDTH_DU} \
1038 12u "$(INSTALL_MAINT_SERVICE)"
1039 Pop $CheckboxInstallMaintSvc
1040 System::Call 'uxtheme::SetWindowTheme(i $CheckboxInstallMaintSvc, w " ", w " ")'
1041 SetCtlColors $CheckboxInstallMaintSvc ${COMMON_TEXT_COLOR_NORMAL} ${COMMON_BKGRD_COLOR}
1042 SendMessage $CheckboxInstallMaintSvc ${WM_SETFONT} $FontNormal 0
1043 ${NSD_Check} $CheckboxInstallMaintSvc
1044 ${EndIf}
1045 ${EndIf}
1046 !endif
1048 GetDlgItem $0 $HWNDPARENT 1 ; Install button
1049 ${If} ${FileExists} "$INSTDIR\${FileMainEXE}"
1050 SendMessage $0 ${WM_SETTEXT} 0 "STR:$(UPGRADE_BUTTON)"
1051 ${Else}
1052 SendMessage $0 ${WM_SETTEXT} 0 "STR:$(INSTALL_BUTTON)"
1053 ${EndIf}
1054 ${NSD_SetFocus} $0
1056 GetDlgItem $0 $HWNDPARENT 2 ; Cancel button
1057 SendMessage $0 ${WM_SETTEXT} 0 "STR:$(CANCEL_BUTTON)"
1059 GetDlgItem $0 $HWNDPARENT 3 ; Back button used for Options
1060 EnableWindow $0 0
1061 ShowWindow $0 ${SW_HIDE}
1063 ; If the option button was not clicked display the reason for what needs to be
1064 ; resolved to continue the installation.
1065 ${If} "$WasOptionsButtonClicked" != "1"
1066 ${If} "$CanWriteToInstallDir" == "false"
1067 MessageBox MB_OK|MB_ICONEXCLAMATION "$(WARN_WRITE_ACCESS)"
1068 ${ElseIf} "$HasRequiredSpaceAvailable" == "false"
1069 MessageBox MB_OK|MB_ICONEXCLAMATION "$(WARN_DISK_SPACE)"
1070 ${EndIf}
1071 ${EndIf}
1073 System::Call "kernel32::GetTickCount()l .s"
1074 Pop $StartOptionsPhaseTickCount
1076 LockWindow off
1077 nsDialogs::Show
1078 FunctionEnd
1080 Function leaveOptions
1081 LockWindow on
1083 ${GetRoot} "$INSTDIR" $0
1084 ${GetLongPath} "$INSTDIR" $INSTDIR
1085 ${GetLongPath} "$0" $0
1086 ${If} "$INSTDIR" == "$0"
1087 LockWindow off
1088 MessageBox MB_OK|MB_ICONEXCLAMATION "$(WARN_ROOT_INSTALL)"
1089 Abort ; Stay on the page
1090 ${EndIf}
1092 Call CanWrite
1093 ${If} "$CanWriteToInstallDir" == "false"
1094 LockWindow off
1095 MessageBox MB_OK|MB_ICONEXCLAMATION "$(WARN_WRITE_ACCESS)"
1096 Abort ; Stay on the page
1097 ${EndIf}
1099 Call CheckSpace
1100 ${If} "$HasRequiredSpaceAvailable" == "false"
1101 LockWindow off
1102 MessageBox MB_OK|MB_ICONEXCLAMATION "$(WARN_DISK_SPACE)"
1103 Abort ; Stay on the page
1104 ${EndIf}
1106 System::Call "kernel32::GetTickCount()l .s"
1107 Pop $0
1108 ${GetSecondsElapsed} "$StartOptionsPhaseTickCount" "$0" $OptionsPhaseSeconds
1109 ; It is possible for this value to be 0 if the user clicks fast enough so
1110 ; increment the value by 1 if it is 0.
1111 ${If} $OptionsPhaseSeconds == 0
1112 IntOp $OptionsPhaseSeconds $OptionsPhaseSeconds + 1
1113 ${EndIf}
1115 ${NSD_GetState} $CheckboxShortcutOnBar $CheckboxShortcutOnBar
1116 ${NSD_GetState} $CheckboxShortcutInStartMenu $CheckboxShortcutInStartMenu
1117 ${NSD_GetState} $CheckboxShortcutOnDesktop $CheckboxShortcutOnDesktop
1118 ${NSD_GetState} $CheckboxSendPing $CheckboxSendPing
1119 !ifdef MOZ_MAINTENANCE_SERVICE
1120 ${NSD_GetState} $CheckboxInstallMaintSvc $CheckboxInstallMaintSvc
1121 !endif
1123 FunctionEnd
1125 Function createInstall
1126 nsDialogs::Create /NOUNLOAD 1018
1127 Pop $Dialog
1128 ; Since the text color for controls is set in this Dialog the foreground and
1129 ; background colors of the Dialog must also be hardcoded.
1130 SetCtlColors $Dialog ${COMMON_TEXT_COLOR_NORMAL} ${COMMON_BKGRD_COLOR}
1132 ${NSD_CreateLabel} 0 0 49u 64u ""
1133 Pop $0
1134 ${GetDlgItemWidthHeight} $0 $1 $2
1135 System::Call 'user32::DestroyWindow(i r0)'
1137 ${NSD_CreateLabel} 0 0 11u 16u ""
1138 Pop $0
1139 ${GetDlgItemWidthHeight} $0 $3 $4
1140 System::Call 'user32::DestroyWindow(i r0)'
1142 FindWindow $7 "#32770" "" $HWNDPARENT
1143 ${GetDlgItemWidthHeight} $7 $8 $9
1145 ; Allow a maximum text width of half of the Dialog's width
1146 IntOp $R0 $8 / 2
1148 ${GetTextWidthHeight} "${INSTALL_BLURB1}" $FontBlurb $R0 $5 $6
1149 IntOp $R1 $1 + $3
1150 IntOp $R1 $R1 + $5
1151 IntOp $R1 $8 - $R1
1152 IntOp $R1 $R1 / 2
1153 ${NSD_CreateBitmap} $R1 ${INSTALL_BLURB_TOP_DU} 49u 64u ""
1154 Pop $BitmapBlurb1
1155 ${SetStretchedTransparentImage} $BitmapBlurb1 $PLUGINSDIR\clock.bmp $HwndBitmapBlurb1
1156 IntOp $R1 $R1 + $1
1157 IntOp $R1 $R1 + $3
1158 ${NSD_CreateLabel} $R1 ${INSTALL_BLURB_TOP_DU} $5 $6 "${INSTALL_BLURB1}"
1159 Pop $LabelBlurb1
1160 SendMessage $LabelBlurb1 ${WM_SETFONT} $FontBlurb 0
1161 SetCtlColors $LabelBlurb1 ${INSTALL_BLURB_TEXT_COLOR} transparent
1163 ${GetTextWidthHeight} "${INSTALL_BLURB2}" $FontBlurb $R0 $5 $6
1164 IntOp $R1 $1 + $3
1165 IntOp $R1 $R1 + $5
1166 IntOp $R1 $8 - $R1
1167 IntOp $R1 $R1 / 2
1168 ${NSD_CreateBitmap} $R1 ${INSTALL_BLURB_TOP_DU} 49u 64u ""
1169 Pop $BitmapBlurb2
1170 ${SetStretchedTransparentImage} $BitmapBlurb2 $PLUGINSDIR\particles.bmp $HwndBitmapBlurb2
1171 IntOp $R1 $R1 + $1
1172 IntOp $R1 $R1 + $3
1173 ${NSD_CreateLabel} $R1 ${INSTALL_BLURB_TOP_DU} $5 $6 "${INSTALL_BLURB2}"
1174 Pop $LabelBlurb2
1175 SendMessage $LabelBlurb2 ${WM_SETFONT} $FontBlurb 0
1176 SetCtlColors $LabelBlurb2 ${INSTALL_BLURB_TEXT_COLOR} transparent
1177 ShowWindow $BitmapBlurb2 ${SW_HIDE}
1178 ShowWindow $LabelBlurb2 ${SW_HIDE}
1180 ${GetTextWidthHeight} "${INSTALL_BLURB3}" $FontBlurb $R0 $5 $6
1181 IntOp $R1 $1 + $3
1182 IntOp $R1 $R1 + $5
1183 IntOp $R1 $8 - $R1
1184 IntOp $R1 $R1 / 2
1185 ${NSD_CreateBitmap} $R1 ${INSTALL_BLURB_TOP_DU} 49u 64u ""
1186 Pop $BitmapBlurb3
1187 ${SetStretchedTransparentImage} $BitmapBlurb3 $PLUGINSDIR\pencil.bmp $HWndBitmapBlurb3
1188 IntOp $R1 $R1 + $1
1189 IntOp $R1 $R1 + $3
1190 ${NSD_CreateLabel} $R1 ${INSTALL_BLURB_TOP_DU} $5 $6 "${INSTALL_BLURB3}"
1191 Pop $LabelBlurb3
1192 SendMessage $LabelBlurb3 ${WM_SETFONT} $FontBlurb 0
1193 SetCtlColors $LabelBlurb3 ${INSTALL_BLURB_TEXT_COLOR} transparent
1194 ShowWindow $BitmapBlurb3 ${SW_HIDE}
1195 ShowWindow $LabelBlurb3 ${SW_HIDE}
1197 ${NSD_CreateProgressBar} 103u 166u 241u 9u ""
1198 Pop $Progressbar
1199 ${NSD_AddStyle} $Progressbar ${PBS_MARQUEE}
1200 SendMessage $Progressbar ${PBM_SETMARQUEE} 1 \
1201 $ProgressbarMarqueeIntervalMS ; start=1|stop=0 interval(ms)=+N
1203 ${NSD_CreateLabelCenter} 103u 180u 241u 20u "$(DOWNLOADING_LABEL)"
1204 Pop $LabelDownloading
1205 SendMessage $LabelDownloading ${WM_SETFONT} $FontNormal 0
1206 SetCtlColors $LabelDownloading ${INSTALL_PROGRESS_TEXT_COLOR_NORMAL} transparent
1208 ${If} ${FileExists} "$INSTDIR\${FileMainEXE}"
1209 ${NSD_CreateLabelCenter} 103u 180u 241u 20u "$(UPGRADING_LABEL)"
1210 ${Else}
1211 ${NSD_CreateLabelCenter} 103u 180u 241u 20u "$(INSTALLING_LABEL)"
1212 ${EndIf}
1213 Pop $LabelInstalling
1214 SendMessage $LabelInstalling ${WM_SETFONT} $FontNormal 0
1215 SetCtlColors $LabelInstalling ${INSTALL_PROGRESS_TEXT_COLOR_NORMAL} transparent
1216 ShowWindow $LabelInstalling ${SW_HIDE}
1218 ${NSD_CreateBitmap} ${APPNAME_BMP_EDGE_DU} ${APPNAME_BMP_TOP_DU} \
1219 ${APPNAME_BMP_WIDTH_DU} ${APPNAME_BMP_HEIGHT_DU} ""
1220 Pop $2
1221 ${SetStretchedTransparentImage} $2 $PLUGINSDIR\appname.bmp $0
1223 GetDlgItem $0 $HWNDPARENT 1 ; Install button
1224 EnableWindow $0 0
1225 ShowWindow $0 ${SW_HIDE}
1227 GetDlgItem $0 $HWNDPARENT 3 ; Back button used for Options
1228 EnableWindow $0 0
1229 ShowWindow $0 ${SW_HIDE}
1231 GetDlgItem $0 $HWNDPARENT 2 ; Cancel button
1232 SendMessage $0 ${WM_SETTEXT} 0 "STR:$(CANCEL_BUTTON)"
1233 ; Focus the Cancel button otherwise it isn't possible to tab to it since it is
1234 ; the only control that can be tabbed to.
1235 ${NSD_SetFocus} $0
1236 ; Kill the Cancel button's focus so pressing enter won't cancel the install.
1237 SendMessage $0 ${WM_KILLFOCUS} 0 0
1239 ${If} "$CanSetAsDefault" == "true"
1240 GetDlgItem $0 $HWNDPARENT 10 ; Default browser checkbox
1241 SendMessage $0 ${BM_GETCHECK} 0 0 $CheckboxSetAsDefault
1242 EnableWindow $0 0
1243 ShowWindow $0 ${SW_HIDE}
1244 ${EndIf}
1246 GetDlgItem $0 $HWNDPARENT 11
1247 ${If} ${FileExists} "$INSTDIR\${FileMainEXE}"
1248 SendMessage $0 ${WM_SETTEXT} 0 "STR:$(ONE_MOMENT_UPGRADE)"
1249 ${Else}
1250 SendMessage $0 ${WM_SETTEXT} 0 "STR:$(ONE_MOMENT_INSTALL)"
1251 ${EndIf}
1252 SendMessage $0 ${WM_SETFONT} $FontNormal 0
1253 SetCtlColors $0 ${FOOTER_CONTROL_TEXT_COLOR_FADED} ${FOOTER_BKGRD_COLOR}
1254 ShowWindow $0 ${SW_SHOW}
1256 ; Set $DownloadReset to true so the first download tick count is measured.
1257 StrCpy $DownloadReset "true"
1258 StrCpy $IsDownloadFinished "false"
1259 StrCpy $DownloadRetryCount "0"
1260 StrCpy $DownloadedBytes "0"
1261 StrCpy $StartLastDownloadTickCount ""
1262 StrCpy $EndDownloadPhaseTickCount ""
1263 StrCpy $DownloadFirstTransferSeconds ""
1264 StrCpy $ExitCode "${ERR_DOWNLOAD_CANCEL}"
1265 StrCpy $OpenedDownloadPage "0"
1267 ClearErrors
1268 ReadINIStr $ExistingVersion "$INSTDIR\application.ini" "App" "Version"
1269 ${If} ${Errors}
1270 StrCpy $ExistingVersion "0"
1271 ${EndIf}
1273 ClearErrors
1274 ReadINIStr $ExistingBuildID "$INSTDIR\application.ini" "App" "BuildID"
1275 ${If} ${Errors}
1276 StrCpy $ExistingBuildID "0"
1277 ${EndIf}
1279 ${If} ${FileExists} "$LOCALAPPDATA\Mozilla\Firefox"
1280 StrCpy $ExistingProfile "1"
1281 ${Else}
1282 StrCpy $ExistingProfile "0"
1283 ${EndIf}
1285 StrCpy $DownloadServerIP ""
1287 System::Call "kernel32::GetTickCount()l .s"
1288 Pop $StartDownloadPhaseTickCount
1290 ${If} ${FileExists} "$INSTDIR\uninstall\uninstall.log"
1291 StrCpy $InstallTotalSteps ${InstallPaveOverTotalSteps}
1292 ${Else}
1293 StrCpy $InstallTotalSteps ${InstallCleanTotalSteps}
1294 ${EndIf}
1296 ${NSD_CreateTimer} StartDownload ${DownloadIntervalMS}
1298 LockWindow off
1299 nsDialogs::Show
1301 ${NSD_FreeImage} $0
1302 ${NSD_FreeImage} $HwndBitmapBlurb1
1303 ${NSD_FreeImage} $HwndBitmapBlurb2
1304 ${NSD_FreeImage} $HWndBitmapBlurb3
1305 FunctionEnd
1307 Function StartDownload
1308 ${NSD_KillTimer} StartDownload
1309 InetBgDL::Get "${URLStubDownload}${URLStubDownloadAppend}" "$PLUGINSDIR\download.exe" \
1310 /CONNECTTIMEOUT 120 /RECEIVETIMEOUT 120 /END
1311 StrCpy $4 ""
1312 ${NSD_CreateTimer} OnDownload ${DownloadIntervalMS}
1313 ${If} ${FileExists} "$INSTDIR\${TO_BE_DELETED}"
1314 RmDir /r "$INSTDIR\${TO_BE_DELETED}"
1315 ${EndIf}
1316 FunctionEnd
1318 Function OnDownload
1319 InetBgDL::GetStats
1320 # $0 = HTTP status code, 0=Completed
1321 # $1 = Completed files
1322 # $2 = Remaining files
1323 # $3 = Number of downloaded bytes for the current file
1324 # $4 = Size of current file (Empty string if the size is unknown)
1325 # /RESET must be used if status $0 > 299 (e.g. failure)
1326 # When status is $0 =< 299 it is handled by InetBgDL
1327 StrCpy $DownloadServerIP "$5"
1328 ${If} $0 > 299
1329 ${NSD_KillTimer} OnDownload
1330 IntOp $DownloadRetryCount $DownloadRetryCount + 1
1331 ${If} "$DownloadReset" != "true"
1332 StrCpy $DownloadedBytes "0"
1333 ${NSD_AddStyle} $Progressbar ${PBS_MARQUEE}
1334 SendMessage $Progressbar ${PBM_SETMARQUEE} 1 \
1335 $ProgressbarMarqueeIntervalMS ; start=1|stop=0 interval(ms)=+N
1336 ${EndIf}
1337 InetBgDL::Get /RESET /END
1338 StrCpy $DownloadSizeBytes ""
1339 StrCpy $DownloadReset "true"
1341 ${If} $DownloadRetryCount >= ${DownloadMaxRetries}
1342 StrCpy $ExitCode "${ERR_DOWNLOAD_TOO_MANY_RETRIES}"
1343 ; Use a timer so the UI has a chance to update
1344 ${NSD_CreateTimer} DisplayDownloadError ${InstallIntervalMS}
1345 ${Else}
1346 ${NSD_CreateTimer} StartDownload ${DownloadRetryIntervalMS}
1347 ${EndIf}
1348 Return
1349 ${EndIf}
1351 ${If} "$DownloadReset" == "true"
1352 System::Call "kernel32::GetTickCount()l .s"
1353 Pop $StartLastDownloadTickCount
1354 StrCpy $DownloadReset "false"
1355 ; The seconds elapsed from the start of the download phase until the first
1356 ; bytes are received are only recorded for the first request so it is
1357 ; possible to determine connection issues for the first request.
1358 ${If} "$DownloadFirstTransferSeconds" == ""
1359 ; Get the seconds elapsed from the start of the download phase until the
1360 ; first bytes are received.
1361 ${GetSecondsElapsed} "$StartDownloadPhaseTickCount" "$StartLastDownloadTickCount" $DownloadFirstTransferSeconds
1362 ${EndIf}
1363 ${EndIf}
1365 ${If} "$DownloadSizeBytes" == ""
1366 ${AndIf} "$4" != ""
1367 ; Handle the case where the size of the file to be downloaded is less than
1368 ; the minimum expected size or greater than the maximum expected size at the
1369 ; beginning of the download.
1370 ${If} $4 < ${DownloadMinSizeBytes}
1371 ${OrIf} $4 > ${DownloadMaxSizeBytes}
1372 ${NSD_KillTimer} OnDownload
1373 InetBgDL::Get /RESET /END
1374 StrCpy $DownloadReset "true"
1376 ${If} $DownloadRetryCount >= ${DownloadMaxRetries}
1377 ; Use a timer so the UI has a chance to update
1378 ${NSD_CreateTimer} DisplayDownloadError ${InstallIntervalMS}
1379 ${Else}
1380 ${NSD_CreateTimer} StartDownload ${DownloadIntervalMS}
1381 ${EndIf}
1382 Return
1383 ${EndIf}
1385 StrCpy $DownloadSizeBytes "$4"
1386 System::Int64Op $4 / 2
1387 Pop $HalfOfDownload
1388 System::Int64Op $HalfOfDownload / $InstallTotalSteps
1389 Pop $InstallStepSize
1390 SendMessage $Progressbar ${PBM_SETMARQUEE} 0 0 ; start=1|stop=0 interval(ms)=+N
1391 ${RemoveStyle} $Progressbar ${PBS_MARQUEE}
1392 System::Int64Op $HalfOfDownload + $DownloadSizeBytes
1393 Pop $R9
1394 SendMessage $Progressbar ${PBM_SETRANGE32} 0 $R9
1395 ${EndIf}
1397 ; Don't update the status until after the download starts
1398 ${If} $2 != 0
1399 ${AndIf} "$4" == ""
1400 Return
1401 ${EndIf}
1403 ; Handle the case where the downloaded size is greater than the maximum
1404 ; expected size during the download.
1405 ${If} $DownloadedBytes > ${DownloadMaxSizeBytes}
1406 InetBgDL::Get /RESET /END
1407 StrCpy $DownloadReset "true"
1409 ${If} $DownloadRetryCount >= ${DownloadMaxRetries}
1410 ; Use a timer so the UI has a chance to update
1411 ${NSD_CreateTimer} DisplayDownloadError ${InstallIntervalMS}
1412 ${Else}
1413 ${NSD_CreateTimer} StartDownload ${DownloadIntervalMS}
1414 ${EndIf}
1415 Return
1416 ${EndIf}
1418 ${If} $IsDownloadFinished != "true"
1419 ${If} $2 == 0
1420 ${NSD_KillTimer} OnDownload
1421 StrCpy $IsDownloadFinished "true"
1422 ; The first step of the install progress bar is determined by the
1423 ; InstallProgressFirstStep define and provides the user with immediate
1424 ; feedback.
1425 StrCpy $InstallCounterStep "${InstallProgressFirstStep}"
1426 System::Call "kernel32::GetTickCount()l .s"
1427 Pop $EndDownloadPhaseTickCount
1429 StrCpy $DownloadedBytes "$DownloadSizeBytes"
1431 ; When a download has finished handle the case where the downloaded size
1432 ; is less than the minimum expected size or greater than the maximum
1433 ; expected size during the download.
1434 ${If} $DownloadedBytes < ${DownloadMinSizeBytes}
1435 ${OrIf} $DownloadedBytes > ${DownloadMaxSizeBytes}
1436 InetBgDL::Get /RESET /END
1437 StrCpy $DownloadReset "true"
1439 ${If} $DownloadRetryCount >= ${DownloadMaxRetries}
1440 ; Use a timer so the UI has a chance to update
1441 ${NSD_CreateTimer} DisplayDownloadError ${InstallIntervalMS}
1442 ${Else}
1443 ${NSD_CreateTimer} StartDownload ${DownloadIntervalMS}
1444 ${EndIf}
1445 Return
1446 ${EndIf}
1448 LockWindow on
1449 ; Update the progress bars first in the UI change so they take affect
1450 ; before other UI changes.
1451 SendMessage $Progressbar ${PBM_SETPOS} $DownloadSizeBytes 0
1452 System::Int64Op $InstallStepSize * ${InstallProgressFirstStep}
1453 Pop $R9
1454 SendMessage $Progressbar ${PBM_SETSTEP} $R9 0
1455 SendMessage $Progressbar ${PBM_STEPIT} 0 0
1456 SendMessage $Progressbar ${PBM_SETSTEP} $InstallStepSize 0
1457 ShowWindow $LabelDownloading ${SW_HIDE}
1458 ShowWindow $LabelInstalling ${SW_SHOW}
1459 ShowWindow $LabelBlurb2 ${SW_HIDE}
1460 ShowWindow $BitmapBlurb2 ${SW_HIDE}
1461 ShowWindow $LabelBlurb3 ${SW_SHOW}
1462 ShowWindow $BitmapBlurb3 ${SW_SHOW}
1463 ; Disable the Cancel button during the install
1464 GetDlgItem $5 $HWNDPARENT 2
1465 EnableWindow $5 0
1466 LockWindow off
1468 ; Open a handle to prevent modification of the full installer
1469 StrCpy $R9 "${INVALID_HANDLE_VALUE}"
1470 System::Call 'kernel32::CreateFileW(w "$PLUGINSDIR\download.exe", \
1471 i ${GENERIC_READ}, \
1472 i ${FILE_SHARE_READ}, i 0, \
1473 i ${OPEN_EXISTING}, i 0, i 0) i .R9'
1474 StrCpy $HandleDownload "$R9"
1476 ${If} $HandleDownload == ${INVALID_HANDLE_VALUE}
1477 StrCpy $ExitCode "${ERR_PREINSTALL_INVALID_HANDLE}"
1478 StrCpy $0 "0"
1479 StrCpy $1 "0"
1480 ${Else}
1481 CertCheck::VerifyCertTrust "$PLUGINSDIR\download.exe"
1482 Pop $0
1483 CertCheck::VerifyCertNameIssuer "$PLUGINSDIR\download.exe" \
1484 "${CertNameDownload}" "${CertIssuerDownload}"
1485 Pop $1
1486 ${If} $0 == 0
1487 ${AndIf} $1 == 0
1488 StrCpy $ExitCode "${ERR_PREINSTALL_CERT_UNTRUSTED_AND_ATTRIBUTES}"
1489 ${ElseIf} $0 == 0
1490 StrCpy $ExitCode "${ERR_PREINSTALL_CERT_UNTRUSTED}"
1491 ${ElseIf} $1 == 0
1492 StrCpy $ExitCode "${ERR_PREINSTALL_CERT_ATTRIBUTES}"
1493 ${EndIf}
1494 ${EndIf}
1496 System::Call "kernel32::GetTickCount()l .s"
1497 Pop $EndPreInstallPhaseTickCount
1499 ${If} $0 == 0
1500 ${OrIf} $1 == 0
1501 ; Use a timer so the UI has a chance to update
1502 ${NSD_CreateTimer} DisplayDownloadError ${InstallIntervalMS}
1503 Return
1504 ${EndIf}
1506 ; Instead of extracting the files we use the downloaded installer to
1507 ; install in case it needs to perform operations that the stub doesn't
1508 ; know about.
1509 WriteINIStr "$PLUGINSDIR\${CONFIG_INI}" "Install" "InstallDirectoryPath" "$INSTDIR"
1510 ; Don't create the QuickLaunch or Taskbar shortcut from the launched installer
1511 WriteINIStr "$PLUGINSDIR\${CONFIG_INI}" "Install" "QuickLaunchShortcut" "false"
1512 ${If} $CheckboxShortcutOnDesktop == 1
1513 WriteINIStr "$PLUGINSDIR\${CONFIG_INI}" "Install" "DesktopShortcut" "true"
1514 ${Else}
1515 WriteINIStr "$PLUGINSDIR\${CONFIG_INI}" "Install" "DesktopShortcut" "false"
1516 ${EndIf}
1518 ${If} $CheckboxShortcutInStartMenu == 1
1519 WriteINIStr "$PLUGINSDIR\${CONFIG_INI}" "Install" "StartMenuShortcuts" "true"
1520 ${Else}
1521 WriteINIStr "$PLUGINSDIR\${CONFIG_INI}" "Install" "StartMenuShortcuts" "false"
1522 ${EndIf}
1524 !ifdef MOZ_MAINTENANCE_SERVICE
1525 ${If} $CheckboxInstallMaintSvc == 1
1526 WriteINIStr "$PLUGINSDIR\${CONFIG_INI}" "Install" "MaintenanceService" "true"
1527 ${Else}
1528 WriteINIStr "$PLUGINSDIR\${CONFIG_INI}" "Install" "MaintenanceService" "false"
1529 ${EndIf}
1530 !else
1531 WriteINIStr "$PLUGINSDIR\${CONFIG_INI}" "Install" "MaintenanceService" "false"
1532 !endif
1534 ; Write migrated to the shortcuts.ini file to prevent the installer
1535 ; from creating a taskbar shortcut (Bug 791613).
1536 ${GetShortcutsLogPath} $0
1537 Delete "$0"
1538 ; Workaround to prevent pinning to the taskbar.
1539 ${If} $CheckboxShortcutOnBar == 0
1540 WriteIniStr "$0" "TASKBAR" "Migrated" "true"
1541 ${EndIf}
1543 ${OnStubInstallUninstall} $Progressbar $InstallCounterStep
1545 ; Delete the install.log and let the full installer create it. When the
1546 ; installer closes it we can detect that it has completed.
1547 Delete "$INSTDIR\install.log"
1549 ; Delete firefox.exe.moz-upgrade if it exists since it being present will
1550 ; require an OS restart for the full installer.
1551 Delete "$INSTDIR\${FileMainEXE}.moz-upgrade"
1553 System::Call "kernel32::GetTickCount()l .s"
1554 Pop $EndPreInstallPhaseTickCount
1556 Exec "$\"$PLUGINSDIR\download.exe$\" /INI=$PLUGINSDIR\${CONFIG_INI}"
1557 ${NSD_CreateTimer} CheckInstall ${InstallIntervalMS}
1558 ${Else}
1559 ${If} $HalfOfDownload != "true"
1560 ${AndIf} $3 > $HalfOfDownload
1561 StrCpy $HalfOfDownload "true"
1562 LockWindow on
1563 ShowWindow $LabelBlurb1 ${SW_HIDE}
1564 ShowWindow $BitmapBlurb1 ${SW_HIDE}
1565 ShowWindow $LabelBlurb2 ${SW_SHOW}
1566 ShowWindow $BitmapBlurb2 ${SW_SHOW}
1567 LockWindow off
1568 ${EndIf}
1569 StrCpy $DownloadedBytes "$3"
1570 SendMessage $Progressbar ${PBM_SETPOS} $3 0
1571 ${EndIf}
1572 ${EndIf}
1573 FunctionEnd
1575 Function OnPing
1576 InetBgDL::GetStats
1577 # $0 = HTTP status code, 0=Completed
1578 # $1 = Completed files
1579 # $2 = Remaining files
1580 # $3 = Number of downloaded bytes for the current file
1581 # $4 = Size of current file (Empty string if the size is unknown)
1582 # /RESET must be used if status $0 > 299 (e.g. failure)
1583 # When status is $0 =< 299 it is handled by InetBgDL
1584 ${If} $2 == 0
1585 ${OrIf} $0 > 299
1586 ${NSD_KillTimer} OnPing
1587 ${If} $0 > 299
1588 InetBgDL::Get /RESET /END
1589 ${EndIf}
1590 ; The following will exit the installer
1591 SetAutoClose true
1592 StrCpy $R9 "2"
1593 Call RelativeGotoPage
1594 ${EndIf}
1595 FunctionEnd
1597 Function CheckInstall
1598 IntOp $InstallCounterStep $InstallCounterStep + 1
1599 ${If} $InstallCounterStep >= $InstallTotalSteps
1600 ${NSD_KillTimer} CheckInstall
1601 ; Close the handle that prevents modification of the full installer
1602 System::Call 'kernel32::CloseHandle(i $HandleDownload)'
1603 StrCpy $ExitCode "${ERR_INSTALL_TIMEOUT}"
1604 ; Use a timer so the UI has a chance to update
1605 ${NSD_CreateTimer} DisplayDownloadError ${InstallIntervalMS}
1606 Return
1607 ${EndIf}
1609 SendMessage $Progressbar ${PBM_STEPIT} 0 0
1611 ${If} ${FileExists} "$INSTDIR\install.log"
1612 Delete "$INSTDIR\install.tmp"
1613 CopyFiles /SILENT "$INSTDIR\install.log" "$INSTDIR\install.tmp"
1615 ; The unfocus and refocus that happens approximately here is caused by the
1616 ; installer calling SHChangeNotify to refresh the shortcut icons.
1618 ; When the full installer completes the installation the install.log will no
1619 ; longer be in use.
1620 ClearErrors
1621 Delete "$INSTDIR\install.log"
1622 ${Unless} ${Errors}
1623 ${NSD_KillTimer} CheckInstall
1624 ; Close the handle that prevents modification of the full installer
1625 System::Call 'kernel32::CloseHandle(i $HandleDownload)'
1626 Rename "$INSTDIR\install.tmp" "$INSTDIR\install.log"
1627 Delete "$PLUGINSDIR\download.exe"
1628 Delete "$PLUGINSDIR\${CONFIG_INI}"
1629 System::Call "kernel32::GetTickCount()l .s"
1630 Pop $EndInstallPhaseTickCount
1631 System::Int64Op $InstallStepSize * ${InstallProgressFinishStep}
1632 Pop $InstallStepSize
1633 SendMessage $Progressbar ${PBM_SETSTEP} $InstallStepSize 0
1634 ${NSD_CreateTimer} FinishInstall ${InstallIntervalMS}
1635 ${EndUnless}
1636 ${EndIf}
1637 FunctionEnd
1639 Function FinishInstall
1640 ; The full installer has completed but the progress bar still needs to finish
1641 ; so increase the size of the step.
1642 IntOp $InstallCounterStep $InstallCounterStep + ${InstallProgressFinishStep}
1643 ${If} $InstallTotalSteps < $InstallCounterStep
1644 StrCpy $InstallCounterStep "$InstallTotalSteps"
1645 ${EndIf}
1647 ${If} $InstallTotalSteps != $InstallCounterStep
1648 SendMessage $Progressbar ${PBM_STEPIT} 0 0
1649 Return
1650 ${EndIf}
1652 ${NSD_KillTimer} FinishInstall
1654 SendMessage $Progressbar ${PBM_GETRANGE} 0 0 $R9
1655 SendMessage $Progressbar ${PBM_SETPOS} $R9 0
1657 ${If} "$CheckboxSetAsDefault" == "1"
1658 ${GetParameters} $0
1659 ClearErrors
1660 ${GetOptions} "$0" "/UAC:" $0
1661 ${If} ${Errors} ; Not elevated
1662 Call ExecSetAsDefaultAppUser
1663 ${Else} ; Elevated - execute the function in the unelevated process
1664 GetFunctionAddress $0 ExecSetAsDefaultAppUser
1665 UAC::ExecCodeSegment $0
1666 ${EndIf}
1667 ${EndIf}
1669 ${If} $CheckboxShortcutOnBar == 1
1670 ${If} ${AtMostWinVista}
1671 ClearErrors
1672 ${GetParameters} $0
1673 ClearErrors
1674 ${GetOptions} "$0" "/UAC:" $0
1675 ${If} ${Errors}
1676 Call AddQuickLaunchShortcut
1677 ${Else}
1678 GetFunctionAddress $0 AddQuickLaunchShortcut
1679 UAC::ExecCodeSegment $0
1680 ${EndIf}
1681 ${EndIf}
1682 ${EndIf}
1684 ${If} ${FileExists} "$INSTDIR\${FileMainEXE}.moz-upgrade"
1685 Delete "$INSTDIR\${FileMainEXE}"
1686 Rename "$INSTDIR\${FileMainEXE}.moz-upgrade" "$INSTDIR\${FileMainEXE}"
1687 ${EndIf}
1689 StrCpy $ExitCode "${ERR_SUCCESS}"
1691 StrCpy $InstallCounterStep 0
1692 ${NSD_CreateTimer} FinishProgressBar ${InstallIntervalMS}
1693 FunctionEnd
1695 Function FinishProgressBar
1696 IntOp $InstallCounterStep $InstallCounterStep + 1
1698 ${If} $InstallCounterStep < 10
1699 Return
1700 ${EndIf}
1702 ${NSD_KillTimer} FinishProgressBar
1704 Call LaunchApp
1706 Call SendPing
1707 FunctionEnd
1709 Function OnBack
1710 StrCpy $WasOptionsButtonClicked "1"
1711 StrCpy $R9 "1" ; Goto the next page
1712 Call RelativeGotoPage
1713 ; The call to Abort prevents NSIS from trying to move to the previous or the
1714 ; next page.
1715 Abort
1716 FunctionEnd
1718 Function RelativeGotoPage
1719 IntCmp $R9 0 0 Move Move
1720 StrCmp $R9 "X" 0 Move
1721 StrCpy $R9 "120"
1723 Move:
1724 SendMessage $HWNDPARENT "0x408" "$R9" ""
1725 FunctionEnd
1727 Function UpdateFreeSpaceLabel
1728 ; Only update when $ExistingTopDir isn't set
1729 ${If} "$ExistingTopDir" != ""
1730 StrLen $5 "$ExistingTopDir"
1731 StrLen $6 "$INSTDIR"
1732 ${If} $5 <= $6
1733 StrCpy $7 "$INSTDIR" $5
1734 ${If} "$7" == "$ExistingTopDir"
1735 Return
1736 ${EndIf}
1737 ${EndIf}
1738 ${EndIf}
1740 Call CheckSpace
1742 StrCpy $0 "$SpaceAvailableBytes"
1744 StrCpy $1 "$(BYTE)"
1746 ${If} $0 > 1024
1747 ${OrIf} $0 < 0
1748 ; Multiply by 10 so it is possible to display a decimal in the size
1749 System::Int64Op $0 * 10
1750 Pop $0
1751 System::Int64Op $0 / 1024
1752 Pop $0
1753 StrCpy $1 "$(KILO)$(BYTE)"
1754 ${If} $0 > 10240
1755 ${OrIf} $0 < 0
1756 System::Int64Op $0 / 1024
1757 Pop $0
1758 StrCpy $1 "$(MEGA)$(BYTE)"
1759 ${If} $0 > 10240
1760 ${OrIf} $0 < 0
1761 System::Int64Op $0 / 1024
1762 Pop $0
1763 StrCpy $1 "$(GIGA)$(BYTE)"
1764 ${EndIf}
1765 ${EndIf}
1766 StrLen $3 "$0"
1767 ${If} $3 > 1
1768 StrCpy $2 "$0" -1 ; All characters except the last one
1769 StrCpy $0 "$0" "" -1 ; The last character
1770 ${If} "$0" == "0"
1771 StrCpy $0 "$2" ; Don't display the decimal if it is 0
1772 ${Else}
1773 StrCpy $0 "$2.$0"
1774 ${EndIf}
1775 ${ElseIf} $3 == 1
1776 StrCpy $0 "0.$0"
1777 ${Else}
1778 ; This should never happen
1779 System::Int64Op $0 / 10
1780 Pop $0
1781 ${EndIf}
1782 ${EndIf}
1784 SendMessage $LabelFreeSpace ${WM_SETTEXT} 0 "STR:$0 $1"
1786 FunctionEnd
1788 Function OnChange_DirRequest
1789 Pop $0
1790 System::Call 'user32::GetWindowTextW(i $DirRequest, w .r0, i ${NSIS_MAX_STRLEN})'
1791 StrCpy $1 "$0" 1 ; the first character
1792 ${If} "$1" == "$\""
1793 StrCpy $1 "$0" "" -1 ; the last character
1794 ${If} "$1" == "$\""
1795 StrCpy $0 "$0" "" 1 ; all but the first character
1796 StrCpy $0 "$0" -1 ; all but the last character
1797 ${EndIf}
1798 ${EndIf}
1800 StrCpy $INSTDIR "$0"
1801 Call UpdateFreeSpaceLabel
1803 GetDlgItem $0 $HWNDPARENT 1 ; Install button
1804 ${If} ${FileExists} "$INSTDIR\${FileMainEXE}"
1805 SendMessage $0 ${WM_SETTEXT} 0 "STR:$(UPGRADE_BUTTON)"
1806 ${Else}
1807 SendMessage $0 ${WM_SETTEXT} 0 "STR:$(INSTALL_BUTTON)"
1808 ${EndIf}
1809 FunctionEnd
1811 Function OnClick_ButtonBrowse
1812 StrCpy $0 "$INSTDIR"
1813 nsDialogs::SelectFolderDialog /NOUNLOAD "$(SELECT_FOLDER_TEXT)" $0
1814 Pop $0
1815 ${If} $0 == "error" ; returns 'error' if 'cancel' was pressed?
1816 Return
1817 ${EndIf}
1819 ${If} $0 != ""
1820 StrCpy $INSTDIR "$0"
1821 System::Call 'user32::SetWindowTextW(i $DirRequest, w "$INSTDIR")'
1822 ${EndIf}
1823 FunctionEnd
1825 Function CheckSpace
1826 ${If} "$ExistingTopDir" != ""
1827 StrLen $0 "$ExistingTopDir"
1828 StrLen $1 "$INSTDIR"
1829 ${If} $0 <= $1
1830 StrCpy $2 "$INSTDIR" $3
1831 ${If} "$2" == "$ExistingTopDir"
1832 Return
1833 ${EndIf}
1834 ${EndIf}
1835 ${EndIf}
1837 StrCpy $ExistingTopDir "$INSTDIR"
1838 ${DoUntil} ${FileExists} "$ExistingTopDir"
1839 ${GetParent} "$ExistingTopDir" $ExistingTopDir
1840 ${If} "$ExistingTopDir" == ""
1841 StrCpy $SpaceAvailableBytes "0"
1842 StrCpy $HasRequiredSpaceAvailable "false"
1843 Return
1844 ${EndIf}
1845 ${Loop}
1847 ${GetLongPath} "$ExistingTopDir" $ExistingTopDir
1849 ; GetDiskFreeSpaceExW requires a backslash.
1850 StrCpy $0 "$ExistingTopDir" "" -1 ; the last character
1851 ${If} "$0" != "\"
1852 StrCpy $0 "\"
1853 ${Else}
1854 StrCpy $0 ""
1855 ${EndIf}
1857 System::Call 'kernel32::GetDiskFreeSpaceExW(w, *l, *l, *l) i("$ExistingTopDir$0", .r1, .r2, .r3) .'
1858 StrCpy $SpaceAvailableBytes "$1"
1860 System::Int64Op $SpaceAvailableBytes / 1048576
1861 Pop $1
1862 System::Int64Op $1 > ${APPROXIMATE_REQUIRED_SPACE_MB}
1863 Pop $1
1864 ${If} $1 == 1
1865 StrCpy $HasRequiredSpaceAvailable "true"
1866 ${Else}
1867 StrCpy $HasRequiredSpaceAvailable "false"
1868 ${EndIf}
1869 FunctionEnd
1871 Function CanWrite
1872 StrCpy $CanWriteToInstallDir "false"
1874 StrCpy $0 "$INSTDIR"
1875 ; Use the existing directory when it exists
1876 ${Unless} ${FileExists} "$INSTDIR"
1877 ; Get the topmost directory that exists for new installs
1878 ${DoUntil} ${FileExists} "$0"
1879 ${GetParent} "$0" $0
1880 ${If} "$0" == ""
1881 Return
1882 ${EndIf}
1883 ${Loop}
1884 ${EndUnless}
1886 GetTempFileName $2 "$0"
1887 Delete $2
1888 CreateDirectory "$2"
1889 ${If} ${FileExists} "$2"
1890 ${If} ${FileExists} "$INSTDIR"
1891 GetTempFileName $3 "$INSTDIR"
1892 ${Else}
1893 GetTempFileName $3 "$2"
1894 ${EndIf}
1895 ${If} ${FileExists} "$3"
1896 Delete "$3"
1897 StrCpy $CanWriteToInstallDir "true"
1898 ${EndIf}
1899 RmDir "$2"
1900 ${EndIf}
1901 FunctionEnd
1903 Function AddQuickLaunchShortcut
1904 CreateShortCut "$QUICKLAUNCH\${BrandFullName}.lnk" "$INSTDIR\${FileMainEXE}"
1905 ${If} ${FileExists} "$QUICKLAUNCH\${BrandFullName}.lnk"
1906 ShellLink::SetShortCutWorkingDirectory "$QUICKLAUNCH\${BrandFullName}.lnk" \
1907 "$INSTDIR"
1908 ${EndIf}
1909 FunctionEnd
1911 Function ExecSetAsDefaultAppUser
1912 ; Using the helper.exe lessens the stub installer size.
1913 ; This could ask for elevatation when the user doesn't install as admin.
1914 Exec "$\"$INSTDIR\uninstall\helper.exe$\" /SetAsDefaultAppUser"
1915 FunctionEnd
1917 Function LaunchApp
1918 FindWindow $0 "${WindowClass}"
1919 ${If} $0 <> 0 ; integer comparison
1920 StrCpy $FirefoxLaunchCode "1"
1921 MessageBox MB_OK|MB_ICONQUESTION "$(WARN_MANUALLY_CLOSE_APP_LAUNCH)"
1922 Return
1923 ${EndIf}
1925 StrCpy $FirefoxLaunchCode "2"
1927 ; Set the current working directory to the installation directory
1928 SetOutPath "$INSTDIR"
1929 ClearErrors
1930 ${GetParameters} $0
1931 ${GetOptions} "$0" "/UAC:" $1
1932 ${If} ${Errors}
1933 Exec "$\"$INSTDIR\${FileMainEXE}$\""
1934 ${Else}
1935 GetFunctionAddress $0 LaunchAppFromElevatedProcess
1936 UAC::ExecCodeSegment $0
1937 ${EndIf}
1938 FunctionEnd
1940 Function LaunchAppFromElevatedProcess
1941 ; Find the installation directory when launching using GetFunctionAddress
1942 ; from an elevated installer since $INSTDIR will not be set in this installer
1943 ${StrFilter} "${FileMainEXE}" "+" "" "" $R9
1944 ReadRegStr $0 HKLM "Software\Clients\StartMenuInternet\$R9\DefaultIcon" ""
1945 ${GetPathFromString} "$0" $0
1946 ; Set the current working directory to the installation directory
1947 ${GetParent} "$0" $1
1948 SetOutPath "$1"
1949 Exec "$\"$0$\""
1950 FunctionEnd
1952 Function DisplayDownloadError
1953 ${NSD_KillTimer} DisplayDownloadError
1954 MessageBox MB_OKCANCEL|MB_ICONSTOP "$(ERROR_DOWNLOAD)" IDCANCEL +2 IDOK +1
1955 StrCpy $OpenedDownloadPage "1" ; Already initialized to 0
1957 ${If} "$OpenedDownloadPage" == "1"
1958 ClearErrors
1959 ${GetParameters} $0
1960 ${GetOptions} "$0" "/UAC:" $1
1961 ${If} ${Errors}
1962 Call OpenManualDownloadURL
1963 ${Else}
1964 GetFunctionAddress $0 OpenManualDownloadURL
1965 UAC::ExecCodeSegment $0
1966 ${EndIf}
1967 ${EndIf}
1969 Call SendPing
1970 FunctionEnd
1972 Function OpenManualDownloadURL
1973 ExecShell "open" "${URLManualDownload}${URLManualDownloadAppend}"
1974 FunctionEnd
1976 Section
1977 SectionEnd