shared.nsh 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307
  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/.
  4. !macro PostUpdate
  5. ; PostUpdate is called from both session 0 and from the user session
  6. ; for service updates, make sure that we only register with the user session
  7. ; Otherwise ApplicationID::Set can fail intermittently with a file in use error.
  8. System::Call "kernel32::GetCurrentProcessId() i.r0"
  9. System::Call "kernel32::ProcessIdToSessionId(i $0, *i ${NSIS_MAX_STRLEN} r9)"
  10. ; Determine if we're the protected UserChoice default or not. If so fix the
  11. ; start menu tile. In case there are 2 PaleMoon installations, we only do
  12. ; this if the application being updated is the default.
  13. ReadRegStr $0 HKCU "Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice" "ProgId"
  14. ${If} $0 == "PaleMoonURL"
  15. ${AndIf} $9 != 0 ; We're not running in session 0
  16. ReadRegStr $0 HKCU "Software\Classes\PaleMoonURL\shell\open\command" ""
  17. ${GetPathFromString} "$0" $0
  18. ${GetParent} "$0" $0
  19. ${If} ${FileExists} "$0"
  20. ${GetLongPath} "$0" $0
  21. ${EndIf}
  22. ${EndIf}
  23. ${CreateShortcutsLog}
  24. ; Remove registry entries for non-existent apps and for apps that point to our
  25. ; install location in the Software\Mozilla key and uninstall registry entries
  26. ; that point to our install location for both HKCU and HKLM.
  27. SetShellVarContext current ; Set SHCTX to the current user (e.g. HKCU)
  28. ${RegCleanMain} "Software\Mozilla"
  29. ${RegCleanUninstall}
  30. ${UpdateProtocolHandlers}
  31. ; setup the application model id registration value
  32. ${InitHashAppModelId} "$INSTDIR" "Software\Mozilla\${AppName}\TaskBarIDs"
  33. ; Win7 taskbar and start menu link maintenance
  34. Call FixShortcutAppModelIDs
  35. ClearErrors
  36. WriteRegStr HKLM "Software\Mozilla" "${BrandShortName}InstallerTest" "Write Test"
  37. ${If} ${Errors}
  38. StrCpy $TmpVal "HKCU" ; used primarily for logging
  39. ${Else}
  40. SetShellVarContext all ; Set SHCTX to all users (e.g. HKLM)
  41. DeleteRegValue HKLM "Software\Mozilla" "${BrandShortName}InstallerTest"
  42. StrCpy $TmpVal "HKLM" ; used primarily for logging
  43. ${RegCleanMain} "Software\Mozilla"
  44. ${RegCleanUninstall}
  45. ${UpdateProtocolHandlers}
  46. ${FixShellIconHandler} "HKLM"
  47. ${SetAppLSPCategories} ${LSP_CATEGORIES}
  48. ; Win7 taskbar and start menu link maintenance
  49. Call FixShortcutAppModelIDs
  50. ; Add the Firewall entries after an update
  51. Call AddFirewallEntries
  52. ; Only update the Clients\StartMenuInternet registry key values in HKLM if
  53. ; they don't exist or this installation is the same as the one set in those
  54. ; keys.
  55. ${StrFilter} "${FileMainEXE}" "+" "" "" $1
  56. ReadRegStr $0 HKLM "Software\Clients\StartMenuInternet\$1\DefaultIcon" ""
  57. ${GetPathFromString} "$0" $0
  58. ${GetParent} "$0" $0
  59. ${If} ${FileExists} "$0"
  60. ${GetLongPath} "$0" $0
  61. ${EndIf}
  62. ${If} "$0" == "$INSTDIR"
  63. ${SetStartMenuInternet} "HKLM"
  64. ${EndIf}
  65. ; Only update the Clients\StartMenuInternet registry key values in HKCU if
  66. ; they don't exist or this installation is the same as the one set in those
  67. ; keys. This is only done in Windows 8 to avoid a UAC prompt.
  68. ${If} ${AtLeastWin8}
  69. ReadRegStr $0 HKCU "Software\Clients\StartMenuInternet\$1\DefaultIcon" ""
  70. ${GetPathFromString} "$0" $0
  71. ${GetParent} "$0" $0
  72. ${If} ${FileExists} "$0"
  73. ${GetLongPath} "$0" $0
  74. ${EndIf}
  75. ${If} "$0" == "$INSTDIR"
  76. ${SetStartMenuInternet} "HKCU"
  77. ${EndIf}
  78. ${EndIf}
  79. ReadRegStr $0 HKLM "Software\mozilla.org\Mozilla" "CurrentVersion"
  80. ${If} "$0" != "${GREVersion}"
  81. WriteRegStr HKLM "Software\mozilla.org\Mozilla" "CurrentVersion" "${GREVersion}"
  82. ${EndIf}
  83. ${EndIf}
  84. ; Migrate the application's Start Menu directory to a single shortcut in the
  85. ; root of the Start Menu Programs directory.
  86. ${MigrateStartMenuShortcut}
  87. ; Update lastwritetime of the Start Menu shortcut to clear the tile cache.
  88. ${If} ${AtLeastWin8}
  89. ${AndIf} ${FileExists} "$SMPROGRAMS\${BrandFullName}.lnk"
  90. FileOpen $0 "$SMPROGRAMS\${BrandFullName}.lnk" a
  91. FileClose $0
  92. ${EndIf}
  93. ; Adds a pinned Task Bar shortcut (see MigrateTaskBarShortcut for details).
  94. ${MigrateTaskBarShortcut}
  95. ${RemoveDeprecatedKeys}
  96. ${SetAppKeys}
  97. ${FixClassKeys}
  98. ${SetUninstallKeys}
  99. ; Remove files that may be left behind by the application in the
  100. ; VirtualStore directory.
  101. ${CleanVirtualStore}
  102. ${RemoveDeprecatedFiles}
  103. ; Fix the distribution.ini file if applicable
  104. ${FixDistributionsINI}
  105. RmDir /r /REBOOTOK "$INSTDIR\${TO_BE_DELETED}"
  106. !macroend
  107. !define PostUpdate "!insertmacro PostUpdate"
  108. !macro SetAsDefaultAppGlobal
  109. ${RemoveDeprecatedKeys} ; Does not use SHCTX
  110. SetShellVarContext all ; Set SHCTX to all users (e.g. HKLM)
  111. ${SetHandlers} ; Uses SHCTX
  112. ${SetStartMenuInternet} "HKLM"
  113. ${FixShellIconHandler} "HKLM"
  114. ${ShowShortcuts}
  115. ${StrFilter} "${FileMainEXE}" "+" "" "" $R9
  116. WriteRegStr HKLM "Software\Clients\StartMenuInternet" "" "$R9"
  117. !macroend
  118. !define SetAsDefaultAppGlobal "!insertmacro SetAsDefaultAppGlobal"
  119. ; Removes shortcuts for this installation. This should also remove the
  120. ; application from Open With for the file types the application handles
  121. ; (bug 370480).
  122. !macro HideShortcuts
  123. ${StrFilter} "${FileMainEXE}" "+" "" "" $0
  124. StrCpy $R1 "Software\Clients\StartMenuInternet\$0\InstallInfo"
  125. WriteRegDWORD HKLM "$R1" "IconsVisible" 0
  126. ${If} ${AtLeastWin8}
  127. WriteRegDWORD HKCU "$R1" "IconsVisible" 0
  128. ${EndIf}
  129. SetShellVarContext all ; Set $DESKTOP to All Users
  130. ${Unless} ${FileExists} "$DESKTOP\${BrandFullName}.lnk"
  131. SetShellVarContext current ; Set $DESKTOP to the current user's desktop
  132. ${EndUnless}
  133. ${If} ${FileExists} "$DESKTOP\${BrandFullName}.lnk"
  134. ShellLink::GetShortCutArgs "$DESKTOP\${BrandFullName}.lnk"
  135. Pop $0
  136. ${If} "$0" == ""
  137. ShellLink::GetShortCutTarget "$DESKTOP\${BrandFullName}.lnk"
  138. Pop $0
  139. ${GetLongPath} "$0" $0
  140. ${If} "$0" == "$INSTDIR\${FileMainEXE}"
  141. Delete "$DESKTOP\${BrandFullName}.lnk"
  142. ${EndIf}
  143. ${EndIf}
  144. ${EndIf}
  145. SetShellVarContext all ; Set $SMPROGRAMS to All Users
  146. ${Unless} ${FileExists} "$SMPROGRAMS\${BrandFullName}.lnk"
  147. SetShellVarContext current ; Set $SMPROGRAMS to the current user's Start
  148. ; Menu Programs directory
  149. ${EndUnless}
  150. ${If} ${FileExists} "$SMPROGRAMS\${BrandFullName}.lnk"
  151. ShellLink::GetShortCutArgs "$SMPROGRAMS\${BrandFullName}.lnk"
  152. Pop $0
  153. ${If} "$0" == ""
  154. ShellLink::GetShortCutTarget "$SMPROGRAMS\${BrandFullName}.lnk"
  155. Pop $0
  156. ${GetLongPath} "$0" $0
  157. ${If} "$0" == "$INSTDIR\${FileMainEXE}"
  158. Delete "$SMPROGRAMS\${BrandFullName}.lnk"
  159. ${EndIf}
  160. ${EndIf}
  161. ${EndIf}
  162. ${If} ${FileExists} "$QUICKLAUNCH\${BrandFullName}.lnk"
  163. ShellLink::GetShortCutArgs "$QUICKLAUNCH\${BrandFullName}.lnk"
  164. Pop $0
  165. ${If} "$0" == ""
  166. ShellLink::GetShortCutTarget "$QUICKLAUNCH\${BrandFullName}.lnk"
  167. Pop $0
  168. ${GetLongPath} "$0" $0
  169. ${If} "$0" == "$INSTDIR\${FileMainEXE}"
  170. Delete "$QUICKLAUNCH\${BrandFullName}.lnk"
  171. ${EndIf}
  172. ${EndIf}
  173. ${EndIf}
  174. !macroend
  175. !define HideShortcuts "!insertmacro HideShortcuts"
  176. ; Adds shortcuts for this installation. This should also add the application
  177. ; to Open With for the file types the application handles (bug 370480).
  178. !macro ShowShortcuts
  179. ${StrFilter} "${FileMainEXE}" "+" "" "" $0
  180. StrCpy $R1 "Software\Clients\StartMenuInternet\$0\InstallInfo"
  181. WriteRegDWORD HKLM "$R1" "IconsVisible" 1
  182. ${If} ${AtLeastWin8}
  183. WriteRegDWORD HKCU "$R1" "IconsVisible" 1
  184. ${EndIf}
  185. SetShellVarContext all ; Set $DESKTOP to All Users
  186. ${Unless} ${FileExists} "$DESKTOP\${BrandFullName}.lnk"
  187. CreateShortCut "$DESKTOP\${BrandFullName}.lnk" "$INSTDIR\${FileMainEXE}"
  188. ${If} ${FileExists} "$DESKTOP\${BrandFullName}.lnk"
  189. ShellLink::SetShortCutWorkingDirectory "$DESKTOP\${BrandFullName}.lnk" "$INSTDIR"
  190. ${If} ${AtLeastWin7}
  191. ${AndIf} "$AppUserModelID" != ""
  192. ApplicationID::Set "$DESKTOP\${BrandFullName}.lnk" "$AppUserModelID" "true"
  193. ${EndIf}
  194. ${Else}
  195. SetShellVarContext current ; Set $DESKTOP to the current user's desktop
  196. ${Unless} ${FileExists} "$DESKTOP\${BrandFullName}.lnk"
  197. CreateShortCut "$DESKTOP\${BrandFullName}.lnk" "$INSTDIR\${FileMainEXE}"
  198. ${If} ${FileExists} "$DESKTOP\${BrandFullName}.lnk"
  199. ShellLink::SetShortCutWorkingDirectory "$DESKTOP\${BrandFullName}.lnk" \
  200. "$INSTDIR"
  201. ${If} ${AtLeastWin7}
  202. ${AndIf} "$AppUserModelID" != ""
  203. ApplicationID::Set "$DESKTOP\${BrandFullName}.lnk" "$AppUserModelID" "true"
  204. ${EndIf}
  205. ${EndIf}
  206. ${EndUnless}
  207. ${EndIf}
  208. ${EndUnless}
  209. SetShellVarContext all ; Set $SMPROGRAMS to All Users
  210. ${Unless} ${FileExists} "$SMPROGRAMS\${BrandFullName}.lnk"
  211. CreateShortCut "$SMPROGRAMS\${BrandFullName}.lnk" "$INSTDIR\${FileMainEXE}"
  212. ${If} ${FileExists} "$SMPROGRAMS\${BrandFullName}.lnk"
  213. ShellLink::SetShortCutWorkingDirectory "$SMPROGRAMS\${BrandFullName}.lnk" \
  214. "$INSTDIR"
  215. ${If} ${AtLeastWin7}
  216. ${AndIf} "$AppUserModelID" != ""
  217. ApplicationID::Set "$SMPROGRAMS\${BrandFullName}.lnk" "$AppUserModelID" "true"
  218. ${EndIf}
  219. ${Else}
  220. SetShellVarContext current ; Set $SMPROGRAMS to the current user's Start
  221. ; Menu Programs directory
  222. ${Unless} ${FileExists} "$SMPROGRAMS\${BrandFullName}.lnk"
  223. CreateShortCut "$SMPROGRAMS\${BrandFullName}.lnk" "$INSTDIR\${FileMainEXE}"
  224. ${If} ${FileExists} "$SMPROGRAMS\${BrandFullName}.lnk"
  225. ShellLink::SetShortCutWorkingDirectory "$SMPROGRAMS\${BrandFullName}.lnk" \
  226. "$INSTDIR"
  227. ${If} ${AtLeastWin7}
  228. ${AndIf} "$AppUserModelID" != ""
  229. ApplicationID::Set "$SMPROGRAMS\${BrandFullName}.lnk" "$AppUserModelID" "true"
  230. ${EndIf}
  231. ${EndIf}
  232. ${EndUnless}
  233. ${EndIf}
  234. ${EndUnless}
  235. ; Windows 7 doesn't use the QuickLaunch directory
  236. ${Unless} ${AtLeastWin7}
  237. ${AndUnless} ${FileExists} "$QUICKLAUNCH\${BrandFullName}.lnk"
  238. CreateShortCut "$QUICKLAUNCH\${BrandFullName}.lnk" \
  239. "$INSTDIR\${FileMainEXE}"
  240. ${If} ${FileExists} "$QUICKLAUNCH\${BrandFullName}.lnk"
  241. ShellLink::SetShortCutWorkingDirectory "$QUICKLAUNCH\${BrandFullName}.lnk" \
  242. "$INSTDIR"
  243. ${EndIf}
  244. ${EndUnless}
  245. !macroend
  246. !define ShowShortcuts "!insertmacro ShowShortcuts"
  247. !macro AddAssociationIfNoneExist FILE_TYPE
  248. ClearErrors
  249. EnumRegKey $7 HKCR "${FILE_TYPE}" 0
  250. ${If} ${Errors}
  251. WriteRegStr SHCTX "SOFTWARE\Classes\${FILE_TYPE}" "" "PaleMoonHTML"
  252. ${EndIf}
  253. WriteRegStr SHCTX "SOFTWARE\Classes\${FILE_TYPE}\OpenWithProgids" "PaleMoonHTML" ""
  254. !macroend
  255. !define AddAssociationIfNoneExist "!insertmacro AddAssociationIfNoneExist"
  256. ; Adds the protocol and file handler registry entries for making PaleMoon the
  257. ; default handler (uses SHCTX).
  258. !macro SetHandlers
  259. ${GetLongPath} "$INSTDIR\${FileMainEXE}" $8
  260. StrCpy $0 "SOFTWARE\Classes"
  261. StrCpy $2 "$\"$8$\" -osint -url $\"%1$\""
  262. ; Associate the file handlers with PaleMoonHTML
  263. ReadRegStr $6 SHCTX "$0\.htm" ""
  264. ${If} "$6" != "PaleMoonHTML"
  265. WriteRegStr SHCTX "$0\.htm" "" "PaleMoonHTML"
  266. ${EndIf}
  267. ReadRegStr $6 SHCTX "$0\.html" ""
  268. ${If} "$6" != "PaleMoonHTML"
  269. WriteRegStr SHCTX "$0\.html" "" "PaleMoonHTML"
  270. ${EndIf}
  271. ReadRegStr $6 SHCTX "$0\.shtml" ""
  272. ${If} "$6" != "PaleMoonHTML"
  273. WriteRegStr SHCTX "$0\.shtml" "" "PaleMoonHTML"
  274. ${EndIf}
  275. ReadRegStr $6 SHCTX "$0\.xht" ""
  276. ${If} "$6" != "PaleMoonHTML"
  277. WriteRegStr SHCTX "$0\.xht" "" "PaleMoonHTML"
  278. ${EndIf}
  279. ReadRegStr $6 SHCTX "$0\.xhtml" ""
  280. ${If} "$6" != "PaleMoonHTML"
  281. WriteRegStr SHCTX "$0\.xhtml" "" "PaleMoonHTML"
  282. ${EndIf}
  283. ${AddAssociationIfNoneExist} ".oga"
  284. ${AddAssociationIfNoneExist} ".ogg"
  285. ${AddAssociationIfNoneExist} ".ogv"
  286. ${AddAssociationIfNoneExist} ".webm"
  287. ; An empty string is used for the 5th param because PaleMoonHTML is not a
  288. ; protocol handler
  289. ${AddDisabledDDEHandlerValues} "PaleMoonHTML" "$2" "$8,1" \
  290. "${AppRegName} HTML Document" ""
  291. ${AddDisabledDDEHandlerValues} "PaleMoonURL" "$2" "$8,1" "${AppRegName} URL" \
  292. "true"
  293. ; An empty string is used for the 4th & 5th params because the following
  294. ; protocol handlers already have a display name and the additional keys
  295. ; required for a protocol handler.
  296. ${AddDisabledDDEHandlerValues} "ftp" "$2" "$8,1" "" ""
  297. ${AddDisabledDDEHandlerValues} "http" "$2" "$8,1" "" ""
  298. ${AddDisabledDDEHandlerValues} "https" "$2" "$8,1" "" ""
  299. !macroend
  300. !define SetHandlers "!insertmacro SetHandlers"
  301. ; Adds the HKLM\Software\Clients\StartMenuInternet\PALEMOON.EXE registry
  302. ; entries (does not use SHCTX).
  303. ;
  304. ; The values for StartMenuInternet are only valid under HKLM and there can only
  305. ; be one installation registerred under StartMenuInternet per application since
  306. ; the key name is derived from the main application executable.
  307. ; http://support.microsoft.com/kb/297878
  308. ;
  309. ; In Windows 8 this changes slightly, you can store StartMenuInternet entries in
  310. ; HKCU. The icon in start menu for StartMenuInternet is deprecated as of Win7,
  311. ; but the subkeys are what's important. Control panel default programs looks
  312. ; for them only in HKLM pre win8.
  313. ;
  314. ; Note: we might be able to get away with using the full path to the
  315. ; application executable for the key name in order to support multiple
  316. ; installations.
  317. !macro SetStartMenuInternet RegKey
  318. ${GetLongPath} "$INSTDIR\${FileMainEXE}" $8
  319. ${GetLongPath} "$INSTDIR\uninstall\helper.exe" $7
  320. ${StrFilter} "${FileMainEXE}" "+" "" "" $R9
  321. StrCpy $0 "Software\Clients\StartMenuInternet\$R9"
  322. WriteRegStr ${RegKey} "$0" "" "${BrandFullName}"
  323. WriteRegStr ${RegKey} "$0\DefaultIcon" "" "$8,0"
  324. ; The Reinstall Command is defined at
  325. ; http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/programmersguide/shell_adv/registeringapps.asp
  326. WriteRegStr ${RegKey} "$0\InstallInfo" "HideIconsCommand" "$\"$7$\" /HideShortcuts"
  327. WriteRegStr ${RegKey} "$0\InstallInfo" "ShowIconsCommand" "$\"$7$\" /ShowShortcuts"
  328. WriteRegStr ${RegKey} "$0\InstallInfo" "ReinstallCommand" "$\"$7$\" /SetAsDefaultAppGlobal"
  329. ClearErrors
  330. ReadRegDWORD $1 ${RegKey} "$0\InstallInfo" "IconsVisible"
  331. ; If the IconsVisible name value pair doesn't exist add it otherwise the
  332. ; application won't be displayed in Set Program Access and Defaults.
  333. ${If} ${Errors}
  334. ${If} ${FileExists} "$QUICKLAUNCH\${BrandFullName}.lnk"
  335. WriteRegDWORD ${RegKey} "$0\InstallInfo" "IconsVisible" 1
  336. ${Else}
  337. WriteRegDWORD ${RegKey} "$0\InstallInfo" "IconsVisible" 0
  338. ${EndIf}
  339. ${EndIf}
  340. WriteRegStr ${RegKey} "$0\shell\open\command" "" "$\"$8$\""
  341. WriteRegStr ${RegKey} "$0\shell\properties" "" "$(CONTEXT_OPTIONS)"
  342. WriteRegStr ${RegKey} "$0\shell\properties\command" "" "$\"$8$\" -preferences"
  343. WriteRegStr ${RegKey} "$0\shell\safemode" "" "$(CONTEXT_SAFE_MODE)"
  344. WriteRegStr ${RegKey} "$0\shell\safemode\command" "" "$\"$8$\" -safe-mode"
  345. ; Vista Capabilities registry keys
  346. WriteRegStr ${RegKey} "$0\Capabilities" "ApplicationDescription" "$(REG_APP_DESC)"
  347. WriteRegStr ${RegKey} "$0\Capabilities" "ApplicationIcon" "$8,0"
  348. WriteRegStr ${RegKey} "$0\Capabilities" "ApplicationName" "${BrandShortName}"
  349. WriteRegStr ${RegKey} "$0\Capabilities\FileAssociations" ".htm" "PaleMoonHTML"
  350. WriteRegStr ${RegKey} "$0\Capabilities\FileAssociations" ".html" "PaleMoonHTML"
  351. WriteRegStr ${RegKey} "$0\Capabilities\FileAssociations" ".shtml" "PaleMoonHTML"
  352. WriteRegStr ${RegKey} "$0\Capabilities\FileAssociations" ".xht" "PaleMoonHTML"
  353. WriteRegStr ${RegKey} "$0\Capabilities\FileAssociations" ".xhtml" "PaleMoonHTML"
  354. WriteRegStr ${RegKey} "$0\Capabilities\StartMenu" "StartMenuInternet" "$R9"
  355. WriteRegStr ${RegKey} "$0\Capabilities\URLAssociations" "ftp" "PaleMoonURL"
  356. WriteRegStr ${RegKey} "$0\Capabilities\URLAssociations" "http" "PaleMoonURL"
  357. WriteRegStr ${RegKey} "$0\Capabilities\URLAssociations" "https" "PaleMoonURL"
  358. ; Vista Registered Application
  359. WriteRegStr ${RegKey} "Software\RegisteredApplications" "${AppRegName}" "$0\Capabilities"
  360. !macroend
  361. !define SetStartMenuInternet "!insertmacro SetStartMenuInternet"
  362. ; The IconHandler reference for PaleMoonHTML can end up in an inconsistent state
  363. ; due to changes not being detected by the IconHandler for side by side
  364. ; installs (see bug 268512). The symptoms can be either an incorrect icon or no
  365. ; icon being displayed for files associated with PaleMoon (does not use SHCTX).
  366. !macro FixShellIconHandler RegKey
  367. ClearErrors
  368. ReadRegStr $1 ${RegKey} "Software\Classes\PaleMoonHTML\ShellEx\IconHandler" ""
  369. ${Unless} ${Errors}
  370. ReadRegStr $1 ${RegKey} "Software\Classes\PaleMoonHTML\DefaultIcon" ""
  371. ${GetLongPath} "$INSTDIR\${FileMainEXE}" $2
  372. ${If} "$1" != "$2,1"
  373. WriteRegStr ${RegKey} "Software\Classes\PaleMoonHTML\DefaultIcon" "" "$2,1"
  374. ${EndIf}
  375. ${EndUnless}
  376. !macroend
  377. !define FixShellIconHandler "!insertmacro FixShellIconHandler"
  378. ; Add Software\Mozilla\ registry entries (uses SHCTX).
  379. !macro SetAppKeys
  380. ; Check if this is an ESR release and if so add registry values so it is
  381. ; possible to determine that this is an ESR install (bug 726781).
  382. ClearErrors
  383. ${WordFind} "${UpdateChannel}" "esr" "E#" $3
  384. ${If} ${Errors}
  385. StrCpy $3 ""
  386. ${Else}
  387. StrCpy $3 " ESR"
  388. ${EndIf}
  389. ${GetLongPath} "$INSTDIR" $8
  390. StrCpy $0 "Software\Mozilla\${BrandFullNameInternal}\${AppVersion}$3 (${ARCH} ${AB_CD})\Main"
  391. ${WriteRegStr2} $TmpVal "$0" "Install Directory" "$8" 0
  392. ${WriteRegStr2} $TmpVal "$0" "PathToExe" "$8\${FileMainEXE}" 0
  393. StrCpy $0 "Software\Mozilla\${BrandFullNameInternal}\${AppVersion}$3 (${ARCH} ${AB_CD})\Uninstall"
  394. ${WriteRegStr2} $TmpVal "$0" "Description" "${BrandFullNameInternal} ${AppVersion}$3 (${ARCH} ${AB_CD})" 0
  395. StrCpy $0 "Software\Mozilla\${BrandFullNameInternal}\${AppVersion}$3 (${ARCH} ${AB_CD})"
  396. ${WriteRegStr2} $TmpVal "$0" "" "${AppVersion}$3 (${ARCH} ${AB_CD})" 0
  397. ${If} "$3" == ""
  398. DeleteRegValue SHCTX "$0" "ESR"
  399. ${Else}
  400. ${WriteRegDWORD2} $TmpVal "$0" "ESR" 1 0
  401. ${EndIf}
  402. StrCpy $0 "Software\Mozilla\${BrandFullNameInternal} ${AppVersion}$3\bin"
  403. ${WriteRegStr2} $TmpVal "$0" "PathToExe" "$8\${FileMainEXE}" 0
  404. StrCpy $0 "Software\Mozilla\${BrandFullNameInternal} ${AppVersion}$3\extensions"
  405. ${WriteRegStr2} $TmpVal "$0" "Components" "$8\components" 0
  406. ${WriteRegStr2} $TmpVal "$0" "Plugins" "$8\plugins" 0
  407. StrCpy $0 "Software\Mozilla\${BrandFullNameInternal} ${AppVersion}$3"
  408. ${WriteRegStr2} $TmpVal "$0" "GeckoVer" "${GREVersion}" 0
  409. ${If} "$3" == ""
  410. DeleteRegValue SHCTX "$0" "ESR"
  411. ${Else}
  412. ${WriteRegDWORD2} $TmpVal "$0" "ESR" 1 0
  413. ${EndIf}
  414. StrCpy $0 "Software\Mozilla\${BrandFullNameInternal}$3"
  415. ${WriteRegStr2} $TmpVal "$0" "" "${GREVersion}" 0
  416. ${WriteRegStr2} $TmpVal "$0" "CurrentVersion" "${AppVersion}$3 (${ARCH} ${AB_CD})" 0
  417. !macroend
  418. !define SetAppKeys "!insertmacro SetAppKeys"
  419. ; Add uninstall registry entries. This macro tests for write access to determine
  420. ; if the uninstall keys should be added to HKLM or HKCU.
  421. !macro SetUninstallKeys
  422. ; Check if this is an ESR release and if so add registry values so it is
  423. ; possible to determine that this is an ESR install (bug 726781).
  424. ClearErrors
  425. ${WordFind} "${UpdateChannel}" "esr" "E#" $3
  426. ${If} ${Errors}
  427. StrCpy $3 ""
  428. ${Else}
  429. StrCpy $3 " ESR"
  430. ${EndIf}
  431. StrCpy $0 "Software\Microsoft\Windows\CurrentVersion\Uninstall\${BrandFullNameInternal} ${AppVersion}$3 (${ARCH} ${AB_CD})"
  432. StrCpy $2 ""
  433. ClearErrors
  434. WriteRegStr HKLM "$0" "${BrandShortName}InstallerTest" "Write Test"
  435. ${If} ${Errors}
  436. ; If the uninstall keys already exist in HKLM don't create them in HKCU
  437. ClearErrors
  438. ReadRegStr $2 "HKLM" $0 "DisplayName"
  439. ${If} $2 == ""
  440. ; Otherwise we don't have any keys for this product in HKLM so proceeed
  441. ; to create them in HKCU. Better handling for this will be done in:
  442. ; Bug 711044 - Better handling for 2 uninstall icons
  443. StrCpy $1 "HKCU"
  444. SetShellVarContext current ; Set SHCTX to the current user (e.g. HKCU)
  445. ${EndIf}
  446. ClearErrors
  447. ${Else}
  448. StrCpy $1 "HKLM"
  449. SetShellVarContext all ; Set SHCTX to all users (e.g. HKLM)
  450. DeleteRegValue HKLM "$0" "${BrandShortName}InstallerTest"
  451. ${EndIf}
  452. ${If} $2 == ""
  453. ${GetLongPath} "$INSTDIR" $8
  454. ; Write the uninstall registry keys
  455. ${WriteRegStr2} $1 "$0" "Comments" "${BrandFullNameInternal} ${AppVersion}$3 (${ARCH} ${AB_CD})" 0
  456. ${WriteRegStr2} $1 "$0" "DisplayIcon" "$8\${FileMainEXE},0" 0
  457. ${WriteRegStr2} $1 "$0" "DisplayName" "${BrandFullNameInternal} ${AppVersion}$3 (${ARCH} ${AB_CD})" 0
  458. ${WriteRegStr2} $1 "$0" "DisplayVersion" "${AppVersion}" 0
  459. ${WriteRegStr2} $1 "$0" "HelpLink" "${HelpLink}" 0
  460. ${WriteRegStr2} $1 "$0" "InstallLocation" "$8" 0
  461. ${WriteRegStr2} $1 "$0" "Publisher" "Moonchild Productions" 0
  462. ${WriteRegStr2} $1 "$0" "UninstallString" "$\"$8\uninstall\helper.exe$\"" 0
  463. DeleteRegValue SHCTX "$0" "URLInfoAbout"
  464. ; Don't add URLUpdateInfo which is the release notes url except for the release
  465. ; and esr channels since nightly, aurora, and beta do not have release notes.
  466. ; Note: URLUpdateInfo is only defined in the official branding.nsi.
  467. !ifdef URLUpdateInfo
  468. !ifndef BETA_UPDATE_CHANNEL
  469. ${WriteRegStr2} $1 "$0" "URLUpdateInfo" "${URLUpdateInfo}" 0
  470. !endif
  471. !endif
  472. ${WriteRegStr2} $1 "$0" "URLInfoAbout" "${URLInfoAbout}" 0
  473. ${WriteRegDWORD2} $1 "$0" "NoModify" 1 0
  474. ${WriteRegDWORD2} $1 "$0" "NoRepair" 1 0
  475. ${GetSize} "$8" "/S=0K" $R2 $R3 $R4
  476. ${WriteRegDWORD2} $1 "$0" "EstimatedSize" $R2 0
  477. ${If} "$TmpVal" == "HKLM"
  478. SetShellVarContext all ; Set SHCTX to all users (e.g. HKLM)
  479. ${Else}
  480. SetShellVarContext current ; Set SHCTX to the current user (e.g. HKCU)
  481. ${EndIf}
  482. ${EndIf}
  483. !macroend
  484. !define SetUninstallKeys "!insertmacro SetUninstallKeys"
  485. ; Due to a bug when associating some file handlers, only SHCTX was checked for
  486. ; some file types such as ".pdf". SHCTX is set to HKCU or HKLM depending on
  487. ; whether the installer has write access to HKLM. The bug would happen when
  488. ; HCKU was checked and didn't exist since programs aren't required to set the
  489. ; HKCU Software\Classes keys when associating handlers. The fix uses the merged
  490. ; view in HKCR to check for existance of an existing association. This macro
  491. ; cleans affected installations by removing the HKLM and HKCU value if it is set
  492. ; to PaleMoonHTML when there is a value for PersistentHandler or by removing the
  493. ; HKCU value when the HKLM value has a value other than an empty string.
  494. !macro FixBadFileAssociation FILE_TYPE
  495. ; Only delete the default value in case the key has values for OpenWithList,
  496. ; OpenWithProgids, PersistentHandler, etc.
  497. ReadRegStr $0 HKCU "Software\Classes\${FILE_TYPE}" ""
  498. ReadRegStr $1 HKLM "Software\Classes\${FILE_TYPE}" ""
  499. ReadRegStr $2 HKCR "${FILE_TYPE}\PersistentHandler" ""
  500. ${If} "$2" != ""
  501. ; Since there is a persistent handler remove PaleMoonHTML as the default
  502. ; value from both HKCU and HKLM if it set to PaleMoonHTML.
  503. ${If} "$0" == "PaleMoonHTML"
  504. DeleteRegValue HKCU "Software\Classes\${FILE_TYPE}" ""
  505. ${EndIf}
  506. ${If} "$1" == "PaleMoonHTML"
  507. DeleteRegValue HKLM "Software\Classes\${FILE_TYPE}" ""
  508. ${EndIf}
  509. ${ElseIf} "$0" == "PaleMoonHTML"
  510. ; Since KHCU is set to PaleMoonHTML remove PaleMoonHTML as the default value
  511. ; from HKCU if HKLM is set to a value other than an empty string.
  512. ${If} "$1" != ""
  513. DeleteRegValue HKCU "Software\Classes\${FILE_TYPE}" ""
  514. ${EndIf}
  515. ${EndIf}
  516. !macroend
  517. !define FixBadFileAssociation "!insertmacro FixBadFileAssociation"
  518. ; Add app specific handler registry entries under Software\Classes if they
  519. ; don't exist (does not use SHCTX).
  520. !macro FixClassKeys
  521. StrCpy $1 "SOFTWARE\Classes"
  522. ; File handler keys and name value pairs that may need to be created during
  523. ; install or upgrade.
  524. ReadRegStr $0 HKCR ".shtml" "Content Type"
  525. ${If} "$0" == ""
  526. StrCpy $0 "$1\.shtml"
  527. ${WriteRegStr2} $TmpVal "$1\.shtml" "" "shtmlfile" 0
  528. ${WriteRegStr2} $TmpVal "$1\.shtml" "Content Type" "text/html" 0
  529. ${WriteRegStr2} $TmpVal "$1\.shtml" "PerceivedType" "text" 0
  530. ${EndIf}
  531. ReadRegStr $0 HKCR ".xht" "Content Type"
  532. ${If} "$0" == ""
  533. ${WriteRegStr2} $TmpVal "$1\.xht" "" "xhtfile" 0
  534. ${WriteRegStr2} $TmpVal "$1\.xht" "Content Type" "application/xhtml+xml" 0
  535. ${EndIf}
  536. ReadRegStr $0 HKCR ".xhtml" "Content Type"
  537. ${If} "$0" == ""
  538. ${WriteRegStr2} $TmpVal "$1\.xhtml" "" "xhtmlfile" 0
  539. ${WriteRegStr2} $TmpVal "$1\.xhtml" "Content Type" "application/xhtml+xml" 0
  540. ${EndIf}
  541. ; Remove possibly badly associated file types
  542. ${FixBadFileAssociation} ".oga"
  543. ${FixBadFileAssociation} ".ogg"
  544. ${FixBadFileAssociation} ".ogv"
  545. ${FixBadFileAssociation} ".webm"
  546. !macroend
  547. !define FixClassKeys "!insertmacro FixClassKeys"
  548. ; Updates protocol handlers if their registry open command value is for this
  549. ; install location (uses SHCTX).
  550. !macro UpdateProtocolHandlers
  551. ; Store the command to open the app with an url in a register for easy access.
  552. ${GetLongPath} "$INSTDIR\${FileMainEXE}" $8
  553. StrCpy $2 "$\"$8$\" -osint -url $\"%1$\""
  554. ; Only set the file and protocol handlers if the existing one under HKCR is
  555. ; for this install location.
  556. ${IsHandlerForInstallDir} "PaleMoonHTML" $R9
  557. ${If} "$R9" == "true"
  558. ; An empty string is used for the 5th param because PaleMoonHTML is not a
  559. ; protocol handler.
  560. ${AddDisabledDDEHandlerValues} "PaleMoonHTML" "$2" "$8,1" \
  561. "${AppRegName} HTML Document" ""
  562. ${EndIf}
  563. ${IsHandlerForInstallDir} "PaleMoonURL" $R9
  564. ${If} "$R9" == "true"
  565. ${AddDisabledDDEHandlerValues} "PaleMoonURL" "$2" "$8,1" \
  566. "${AppRegName} URL" "true"
  567. ${EndIf}
  568. ; An empty string is used for the 4th & 5th params because the following
  569. ; protocol handlers already have a display name and the additional keys
  570. ; required for a protocol handler.
  571. ${IsHandlerForInstallDir} "ftp" $R9
  572. ${If} "$R9" == "true"
  573. ${AddDisabledDDEHandlerValues} "ftp" "$2" "$8,1" "" ""
  574. ${EndIf}
  575. ${IsHandlerForInstallDir} "http" $R9
  576. ${If} "$R9" == "true"
  577. ${AddDisabledDDEHandlerValues} "http" "$2" "$8,1" "" ""
  578. ${EndIf}
  579. ${IsHandlerForInstallDir} "https" $R9
  580. ${If} "$R9" == "true"
  581. ${AddDisabledDDEHandlerValues} "https" "$2" "$8,1" "" ""
  582. ${EndIf}
  583. !macroend
  584. !define UpdateProtocolHandlers "!insertmacro UpdateProtocolHandlers"
  585. ; Removes various registry entries for reasons noted below (does not use SHCTX).
  586. !macro RemoveDeprecatedKeys
  587. StrCpy $0 "SOFTWARE\Classes"
  588. ; Remove support for launching gopher urls from the shell during install or
  589. ; update if the DefaultIcon is from palemoon.exe.
  590. ${RegCleanAppHandler} "gopher"
  591. ; Remove support for launching chrome urls from the shell during install or
  592. ; update if the DefaultIcon is from palemoon.exe (Bug 301073).
  593. ${RegCleanAppHandler} "chrome"
  594. ; Remove protocol handler registry keys added by the MS shim
  595. DeleteRegKey HKLM "Software\Classes\PaleMoon.URL"
  596. DeleteRegKey HKCU "Software\Classes\PaleMoon.URL"
  597. ; Delete gopher from Capabilities\URLAssociations if it is present.
  598. ${StrFilter} "${FileMainEXE}" "+" "" "" $R9
  599. StrCpy $0 "Software\Clients\StartMenuInternet\$R9"
  600. ClearErrors
  601. ReadRegStr $2 HKLM "$0\Capabilities\URLAssociations" "gopher"
  602. ${Unless} ${Errors}
  603. DeleteRegValue HKLM "$0\Capabilities\URLAssociations" "gopher"
  604. ${EndUnless}
  605. ; Delete gopher from the user's UrlAssociations if it points to PaleMoonURL.
  606. StrCpy $0 "Software\Microsoft\Windows\Shell\Associations\UrlAssociations\gopher"
  607. ReadRegStr $2 HKCU "$0\UserChoice" "Progid"
  608. ${If} "$2" == "PaleMoonURL"
  609. DeleteRegKey HKCU "$0"
  610. ${EndIf}
  611. !macroend
  612. !define RemoveDeprecatedKeys "!insertmacro RemoveDeprecatedKeys"
  613. ; Removes various directories and files for reasons noted below.
  614. !macro RemoveDeprecatedFiles
  615. ; Remove talkback if it is present (remove after bug 386760 is fixed)
  616. ${If} ${FileExists} "$INSTDIR\extensions\talkback@mozilla.org"
  617. RmDir /r /REBOOTOK "$INSTDIR\extensions\talkback@mozilla.org"
  618. ${EndIf}
  619. ; Remove the Java Console extension (bug 1165156)
  620. ${If} ${FileExists} "$INSTDIR\extensions\{CAFEEFAC-0016-0000-0031-ABCDEFFEDCBA}"
  621. RmDir /r /REBOOTOK "$INSTDIR\extensions\{CAFEEFAC-0016-0000-0031-ABCDEFFEDCBA}"
  622. ${EndIf}
  623. ${If} ${FileExists} "$INSTDIR\extensions\{CAFEEFAC-0016-0000-0034-ABCDEFFEDCBA}"
  624. RmDir /r /REBOOTOK "$INSTDIR\extensions\{CAFEEFAC-0016-0000-0034-ABCDEFFEDCBA}"
  625. ${EndIf}
  626. ${If} ${FileExists} "$INSTDIR\extensions\{CAFEEFAC-0016-0000-0039-ABCDEFFEDCBA}"
  627. RmDir /r /REBOOTOK "$INSTDIR\extensions\{CAFEEFAC-0016-0000-0039-ABCDEFFEDCBA}"
  628. ${EndIf}
  629. ${If} ${FileExists} "$INSTDIR\extensions\{CAFEEFAC-0016-0000-0045-ABCDEFFEDCBA}"
  630. RmDir /r /REBOOTOK "$INSTDIR\extensions\{CAFEEFAC-0016-0000-0045-ABCDEFFEDCBA}"
  631. ${EndIf}
  632. ${If} ${FileExists} "$INSTDIR\extensions\{CAFEEFAC-0017-0000-0000-ABCDEFFEDCBA}"
  633. RmDir /r /REBOOTOK "$INSTDIR\extensions\{CAFEEFAC-0017-0000-0000-ABCDEFFEDCBA}"
  634. ${EndIf}
  635. !macroend
  636. !define RemoveDeprecatedFiles "!insertmacro RemoveDeprecatedFiles"
  637. ; Converts specific partner distribution.ini from ansi to utf-8 (bug 882989)
  638. !macro FixDistributionsINI
  639. StrCpy $1 "$INSTDIR\distribution\distribution.ini"
  640. StrCpy $2 "$INSTDIR\distribution\utf8fix"
  641. StrCpy $0 "0" ; Default to not attempting to fix
  642. ; Check if the distribution.ini settings are for a partner build that needs
  643. ; to have its distribution.ini converted from ansi to utf-8.
  644. ${If} ${FileExists} "$1"
  645. ${Unless} ${FileExists} "$2"
  646. ReadINIStr $3 "$1" "Preferences" "app.distributor"
  647. ${If} "$3" == "yahoo"
  648. ReadINIStr $3 "$1" "Preferences" "app.distributor.channel"
  649. ${If} "$3" == "de"
  650. ${OrIf} "$3" == "es"
  651. ${OrIf} "$3" == "e1"
  652. ${OrIf} "$3" == "mx"
  653. StrCpy $0 "1"
  654. ${EndIf}
  655. ${EndIf}
  656. ; Create the utf8fix so this only runs once
  657. FileOpen $3 "$2" w
  658. FileClose $3
  659. ${EndUnless}
  660. ${EndIf}
  661. ${If} "$0" == "1"
  662. StrCpy $0 "0"
  663. ClearErrors
  664. ReadINIStr $3 "$1" "Global" "version"
  665. ${Unless} ${Errors}
  666. StrCpy $4 "$3" 2
  667. ${If} "$4" == "1."
  668. StrCpy $4 "$3" "" 2 ; Everything after "1."
  669. ${If} $4 < 23
  670. StrCpy $0 "1"
  671. ${EndIf}
  672. ${EndIf}
  673. ${EndUnless}
  674. ${EndIf}
  675. ${If} "$0" == "1"
  676. ClearErrors
  677. FileOpen $3 "$1" r
  678. ${If} ${Errors}
  679. FileClose $3
  680. ${Else}
  681. StrCpy $2 "$INSTDIR\distribution\distribution.new"
  682. ClearErrors
  683. FileOpen $4 "$2" w
  684. ${If} ${Errors}
  685. FileClose $3
  686. FileClose $4
  687. ${Else}
  688. StrCpy $0 "0" ; Default to not replacing the original distribution.ini
  689. ${Do}
  690. FileReadByte $3 $5
  691. ${If} $5 == ""
  692. ${Break}
  693. ${EndIf}
  694. ${If} $5 == 233 ; ansi é
  695. StrCpy $0 "1"
  696. FileWriteByte $4 195
  697. FileWriteByte $4 169
  698. ${ElseIf} $5 == 241 ; ansi ñ
  699. StrCpy $0 "1"
  700. FileWriteByte $4 195
  701. FileWriteByte $4 177
  702. ${ElseIf} $5 == 252 ; ansi ü
  703. StrCpy $0 "1"
  704. FileWriteByte $4 195
  705. FileWriteByte $4 188
  706. ${ElseIf} $5 < 128
  707. FileWriteByte $4 $5
  708. ${EndIf}
  709. ${Loop}
  710. FileClose $3
  711. FileClose $4
  712. ${If} "$0" == "1"
  713. ClearErrors
  714. Rename "$1" "$1.bak"
  715. ${Unless} ${Errors}
  716. Rename "$2" "$1"
  717. Delete "$1.bak"
  718. ${EndUnless}
  719. ${Else}
  720. Delete "$2"
  721. ${EndIf}
  722. ${EndIf}
  723. ${EndIf}
  724. ${EndIf}
  725. !macroend
  726. !define FixDistributionsINI "!insertmacro FixDistributionsINI"
  727. ; Adds a pinned shortcut to Task Bar on update for Windows 7 and above if this
  728. ; macro has never been called before and the application is default (see
  729. ; PinToTaskBar for more details).
  730. ; Since defaults handling is handled by Windows in Win8 and later, we always
  731. ; attempt to pin a taskbar on that OS. If Windows sets the defaults at
  732. ; installation time, then we don't get the opportunity to run this code at
  733. ; that time.
  734. !macro MigrateTaskBarShortcut
  735. ${GetShortcutsLogPath} $0
  736. ${If} ${FileExists} "$0"
  737. ClearErrors
  738. ReadINIStr $1 "$0" "TASKBAR" "Migrated"
  739. ${If} ${Errors}
  740. ClearErrors
  741. WriteIniStr "$0" "TASKBAR" "Migrated" "true"
  742. ${If} ${AtLeastWin7}
  743. ; No need to check the default on Win8 and later
  744. ${If} ${AtMostWin2008R2}
  745. ; Check if the Pale Moon is the http handler for this user
  746. SetShellVarContext current ; Set SHCTX to the current user
  747. ${IsHandlerForInstallDir} "http" $R9
  748. ${If} $TmpVal == "HKLM"
  749. SetShellVarContext all ; Set SHCTX to all users
  750. ${EndIf}
  751. ${EndIf}
  752. ${If} "$R9" == "true"
  753. ${OrIf} ${AtLeastWin8}
  754. ${PinToTaskBar}
  755. ${EndIf}
  756. ${EndIf}
  757. ${EndIf}
  758. ${EndIf}
  759. !macroend
  760. !define MigrateTaskBarShortcut "!insertmacro MigrateTaskBarShortcut"
  761. ; Adds a pinned Task Bar shortcut on Windows 7 if there isn't one for the main
  762. ; application executable already. Existing pinned shortcuts for the same
  763. ; application model ID must be removed first to prevent breaking the pinned
  764. ; item's lists but multiple installations with the same application model ID is
  765. ; an edgecase. If removing existing pinned shortcuts with the same application
  766. ; model ID removes a pinned pinned Start Menu shortcut this will also add a
  767. ; pinned Start Menu shortcut.
  768. !macro PinToTaskBar
  769. ${If} ${AtLeastWin7}
  770. StrCpy $8 "false" ; Whether a shortcut had to be created
  771. ${IsPinnedToTaskBar} "$INSTDIR\${FileMainEXE}" $R9
  772. ${If} "$R9" == "false"
  773. ; Find an existing Start Menu shortcut or create one to use for pinning
  774. ${GetShortcutsLogPath} $0
  775. ${If} ${FileExists} "$0"
  776. ClearErrors
  777. ReadINIStr $1 "$0" "STARTMENU" "Shortcut0"
  778. ${Unless} ${Errors}
  779. SetShellVarContext all ; Set SHCTX to all users
  780. ${Unless} ${FileExists} "$SMPROGRAMS\$1"
  781. SetShellVarContext current ; Set SHCTX to the current user
  782. ${Unless} ${FileExists} "$SMPROGRAMS\$1"
  783. StrCpy $8 "true"
  784. CreateShortCut "$SMPROGRAMS\$1" "$INSTDIR\${FileMainEXE}"
  785. ${If} ${FileExists} "$SMPROGRAMS\$1"
  786. ShellLink::SetShortCutWorkingDirectory "$SMPROGRAMS\$1" \
  787. "$INSTDIR"
  788. ${If} "$AppUserModelID" != ""
  789. ApplicationID::Set "$SMPROGRAMS\$1" "$AppUserModelID" "true"
  790. ${EndIf}
  791. ${EndIf}
  792. ${EndUnless}
  793. ${EndUnless}
  794. ${If} ${FileExists} "$SMPROGRAMS\$1"
  795. ; Count of Start Menu pinned shortcuts before unpinning.
  796. ${PinnedToStartMenuLnkCount} $R9
  797. ; Having multiple shortcuts pointing to different installations with
  798. ; the same AppUserModelID (e.g. side by side installations of the
  799. ; same version) will make the TaskBar shortcut's lists into an bad
  800. ; state where the lists are not shown. To prevent this first
  801. ; uninstall the pinned item.
  802. ApplicationID::UninstallPinnedItem "$SMPROGRAMS\$1"
  803. ; Count of Start Menu pinned shortcuts after unpinning.
  804. ${PinnedToStartMenuLnkCount} $R8
  805. ; If there is a change in the number of Start Menu pinned shortcuts
  806. ; assume that unpinning unpinned a side by side installation from
  807. ; the Start Menu and pin this installation to the Start Menu.
  808. ${Unless} $R8 == $R9
  809. ; Pin the shortcut to the Start Menu. 5381 is the shell32.dll
  810. ; resource id for the "Pin to Start Menu" string.
  811. InvokeShellVerb::DoIt "$SMPROGRAMS" "$1" "5381"
  812. ${EndUnless}
  813. ; Pin the shortcut to the TaskBar. 5386 is the shell32.dll resource
  814. ; id for the "Pin to Taskbar" string.
  815. InvokeShellVerb::DoIt "$SMPROGRAMS" "$1" "5386"
  816. ; Delete the shortcut if it was created
  817. ${If} "$8" == "true"
  818. Delete "$SMPROGRAMS\$1"
  819. ${EndIf}
  820. ${EndIf}
  821. ${If} $TmpVal == "HKCU"
  822. SetShellVarContext current ; Set SHCTX to the current user
  823. ${Else}
  824. SetShellVarContext all ; Set SHCTX to all users
  825. ${EndIf}
  826. ${EndUnless}
  827. ${EndIf}
  828. ${EndIf}
  829. ${EndIf}
  830. !macroend
  831. !define PinToTaskBar "!insertmacro PinToTaskBar"
  832. ; Adds a shortcut to the root of the Start Menu Programs directory if the
  833. ; application's Start Menu Programs directory exists with a shortcut pointing to
  834. ; this installation directory. This will also remove the old shortcuts and the
  835. ; application's Start Menu Programs directory by calling the RemoveStartMenuDir
  836. ; macro.
  837. !macro MigrateStartMenuShortcut
  838. ${GetShortcutsLogPath} $0
  839. ${If} ${FileExists} "$0"
  840. ClearErrors
  841. ReadINIStr $5 "$0" "SMPROGRAMS" "RelativePathToDir"
  842. ${Unless} ${Errors}
  843. ClearErrors
  844. ReadINIStr $1 "$0" "STARTMENU" "Shortcut0"
  845. ${If} ${Errors}
  846. ; The STARTMENU ini section doesn't exist.
  847. ${LogStartMenuShortcut} "${BrandFullName}.lnk"
  848. ${GetLongPath} "$SMPROGRAMS" $2
  849. ${GetLongPath} "$2\$5" $1
  850. ${If} "$1" != ""
  851. ClearErrors
  852. ReadINIStr $3 "$0" "SMPROGRAMS" "Shortcut0"
  853. ${Unless} ${Errors}
  854. ${If} ${FileExists} "$1\$3"
  855. ShellLink::GetShortCutTarget "$1\$3"
  856. Pop $4
  857. ${If} "$INSTDIR\${FileMainEXE}" == "$4"
  858. CreateShortCut "$SMPROGRAMS\${BrandFullName}.lnk" \
  859. "$INSTDIR\${FileMainEXE}"
  860. ${If} ${FileExists} "$SMPROGRAMS\${BrandFullName}.lnk"
  861. ShellLink::SetShortCutWorkingDirectory "$SMPROGRAMS\${BrandFullName}.lnk" \
  862. "$INSTDIR"
  863. ${If} ${AtLeastWin7}
  864. ${AndIf} "$AppUserModelID" != ""
  865. ApplicationID::Set "$SMPROGRAMS\${BrandFullName}.lnk" \
  866. "$AppUserModelID" "true"
  867. ${EndIf}
  868. ${EndIf}
  869. ${EndIf}
  870. ${EndIf}
  871. ${EndUnless}
  872. ${EndIf}
  873. ${EndIf}
  874. ; Remove the application's Start Menu Programs directory, shortcuts, and
  875. ; ini section.
  876. ${RemoveStartMenuDir}
  877. ${EndUnless}
  878. ${EndIf}
  879. !macroend
  880. !define MigrateStartMenuShortcut "!insertmacro MigrateStartMenuShortcut"
  881. ; Removes the application's start menu directory along with its shortcuts if
  882. ; they exist and if they exist creates a start menu shortcut in the root of the
  883. ; start menu directory (bug 598779). If the application's start menu directory
  884. ; is not empty after removing the shortucts the directory will not be removed
  885. ; since these additional items were not created by the installer (uses SHCTX).
  886. !macro RemoveStartMenuDir
  887. ${GetShortcutsLogPath} $0
  888. ${If} ${FileExists} "$0"
  889. ; Delete Start Menu Programs shortcuts, directory if it is empty, and
  890. ; parent directories if they are empty up to but not including the start
  891. ; menu directory.
  892. ${GetLongPath} "$SMPROGRAMS" $1
  893. ClearErrors
  894. ReadINIStr $2 "$0" "SMPROGRAMS" "RelativePathToDir"
  895. ${Unless} ${Errors}
  896. ${GetLongPath} "$1\$2" $2
  897. ${If} "$2" != ""
  898. ; Delete shortucts in the Start Menu Programs directory.
  899. StrCpy $3 0
  900. ${Do}
  901. ClearErrors
  902. ReadINIStr $4 "$0" "SMPROGRAMS" "Shortcut$3"
  903. ; Stop if there are no more entries
  904. ${If} ${Errors}
  905. ${ExitDo}
  906. ${EndIf}
  907. ${If} ${FileExists} "$2\$4"
  908. ShellLink::GetShortCutTarget "$2\$4"
  909. Pop $5
  910. ${If} "$INSTDIR\${FileMainEXE}" == "$5"
  911. Delete "$2\$4"
  912. ${EndIf}
  913. ${EndIf}
  914. IntOp $3 $3 + 1 ; Increment the counter
  915. ${Loop}
  916. ; Delete Start Menu Programs directory and parent directories
  917. ${Do}
  918. ; Stop if the current directory is the start menu directory
  919. ${If} "$1" == "$2"
  920. ${ExitDo}
  921. ${EndIf}
  922. ClearErrors
  923. RmDir "$2"
  924. ; Stop if removing the directory failed
  925. ${If} ${Errors}
  926. ${ExitDo}
  927. ${EndIf}
  928. ${GetParent} "$2" $2
  929. ${Loop}
  930. ${EndIf}
  931. DeleteINISec "$0" "SMPROGRAMS"
  932. ${EndUnless}
  933. ${EndIf}
  934. !macroend
  935. !define RemoveStartMenuDir "!insertmacro RemoveStartMenuDir"
  936. ; Creates the shortcuts log ini file with the appropriate entries if it doesn't
  937. ; already exist.
  938. !macro CreateShortcutsLog
  939. ${GetShortcutsLogPath} $0
  940. ${Unless} ${FileExists} "$0"
  941. ${LogStartMenuShortcut} "${BrandFullName}.lnk"
  942. ${LogQuickLaunchShortcut} "${BrandFullName}.lnk"
  943. ${LogDesktopShortcut} "${BrandFullName}.lnk"
  944. ${EndUnless}
  945. !macroend
  946. !define CreateShortcutsLog "!insertmacro CreateShortcutsLog"
  947. ; The files to check if they are in use during (un)install so the restart is
  948. ; required message is displayed. All files must be located in the $INSTDIR
  949. ; directory.
  950. !macro PushFilesToCheck
  951. ; The first string to be pushed onto the stack MUST be "end" to indicate
  952. ; that there are no more files to check in $INSTDIR and the last string
  953. ; should be ${FileMainEXE} so if it is in use the CheckForFilesInUse macro
  954. ; returns after the first check.
  955. Push "end"
  956. Push "AccessibleMarshal.dll"
  957. Push "IA2Marshal.dll"
  958. Push "freebl3.dll"
  959. Push "nssckbi.dll"
  960. Push "nspr4.dll"
  961. Push "nssdbm3.dll"
  962. Push "mozsqlite3.dll"
  963. Push "xpcom.dll"
  964. Push "crashreporter.exe"
  965. Push "minidump-analyzer.exe"
  966. Push "updater.exe"
  967. Push "${FileMainEXE}"
  968. !macroend
  969. !define PushFilesToCheck "!insertmacro PushFilesToCheck"
  970. ; Pushes the string "true" to the top of the stack if the Firewall service is
  971. ; running and pushes the string "false" to the top of the stack if it isn't.
  972. !define SC_MANAGER_ALL_ACCESS 0x3F
  973. !define SERVICE_QUERY_CONFIG 0x0001
  974. !define SERVICE_QUERY_STATUS 0x0004
  975. !define SERVICE_RUNNING 0x4
  976. !macro IsFirewallSvcRunning
  977. Push $R9
  978. Push $R8
  979. Push $R7
  980. Push $R6
  981. Push "false"
  982. System::Call 'advapi32::OpenSCManagerW(n, n, i ${SC_MANAGER_ALL_ACCESS}) i.R6'
  983. ${If} $R6 != 0
  984. ; MpsSvc is the Firewall service on Windows Vista and above.
  985. ; When opening the service with SERVICE_QUERY_CONFIG the return value will
  986. ; be 0 if the service is not installed.
  987. System::Call 'advapi32::OpenServiceW(i R6, t "MpsSvc", i ${SERVICE_QUERY_CONFIG}) i.R7'
  988. ${If} $R7 != 0
  989. System::Call 'advapi32::CloseServiceHandle(i R7) n'
  990. ; Open the service with SERVICE_QUERY_CONFIG so its status can be queried.
  991. System::Call 'advapi32::OpenServiceW(i R6, t "MpsSvc", i ${SERVICE_QUERY_STATUS}) i.R7'
  992. ${Else}
  993. ; SharedAccess is the Firewall service on Windows XP.
  994. ; When opening the service with SERVICE_QUERY_CONFIG the return value will
  995. ; be 0 if the service is not installed.
  996. System::Call 'advapi32::OpenServiceW(i R6, t "SharedAccess", i ${SERVICE_QUERY_CONFIG}) i.R7'
  997. ${If} $R7 != 0
  998. System::Call 'advapi32::CloseServiceHandle(i R7) n'
  999. ; Open the service with SERVICE_QUERY_CONFIG so its status can be
  1000. ; queried.
  1001. System::Call 'advapi32::OpenServiceW(i R6, t "SharedAccess", i ${SERVICE_QUERY_STATUS}) i.R7'
  1002. ${EndIf}
  1003. ${EndIf}
  1004. ; Did the calls to OpenServiceW succeed?
  1005. ${If} $R7 != 0
  1006. System::Call '*(i,i,i,i,i,i,i) i.R9'
  1007. ; Query the current status of the service.
  1008. System::Call 'advapi32::QueryServiceStatus(i R7, i $R9) i'
  1009. System::Call '*$R9(i, i.R8)'
  1010. System::Free $R9
  1011. System::Call 'advapi32::CloseServiceHandle(i R7) n'
  1012. IntFmt $R8 "0x%X" $R8
  1013. ${If} $R8 == ${SERVICE_RUNNING}
  1014. Pop $R9
  1015. Push "true"
  1016. ${EndIf}
  1017. ${EndIf}
  1018. System::Call 'advapi32::CloseServiceHandle(i R6) n'
  1019. ${EndIf}
  1020. Exch 1
  1021. Pop $R6
  1022. Exch 1
  1023. Pop $R7
  1024. Exch 1
  1025. Pop $R8
  1026. Exch 1
  1027. Pop $R9
  1028. !macroend
  1029. !define IsFirewallSvcRunning "!insertmacro IsFirewallSvcRunning"
  1030. !define un.IsFirewallSvcRunning "!insertmacro IsFirewallSvcRunning"
  1031. ; Sets this installation as the default browser by setting the registry keys
  1032. ; under HKEY_CURRENT_USER via registry calls and using the AppAssocReg NSIS
  1033. ; plugin for Vista and above. This is a function instead of a macro so it is
  1034. ; easily called from an elevated instance of the binary. Since this can be
  1035. ; called by an elevated instance logging is not performed in this function.
  1036. Function SetAsDefaultAppUserHKCU
  1037. ; Only set as the user's StartMenuInternet browser if the StartMenuInternet
  1038. ; registry keys are for this install.
  1039. ${StrFilter} "${FileMainEXE}" "+" "" "" $R9
  1040. ClearErrors
  1041. ReadRegStr $0 HKCU "Software\Clients\StartMenuInternet\$R9\DefaultIcon" ""
  1042. ${If} ${Errors}
  1043. ${OrIf} ${AtMostWin2008R2}
  1044. ClearErrors
  1045. ReadRegStr $0 HKLM "Software\Clients\StartMenuInternet\$R9\DefaultIcon" ""
  1046. ${EndIf}
  1047. ${Unless} ${Errors}
  1048. ${GetPathFromString} "$0" $0
  1049. ${GetParent} "$0" $0
  1050. ${If} ${FileExists} "$0"
  1051. ${GetLongPath} "$0" $0
  1052. ${If} "$0" == "$INSTDIR"
  1053. WriteRegStr HKCU "Software\Clients\StartMenuInternet" "" "$R9"
  1054. ${EndIf}
  1055. ${EndIf}
  1056. ${EndUnless}
  1057. SetShellVarContext current ; Set SHCTX to the current user (e.g. HKCU)
  1058. ${If} ${AtLeastWin8}
  1059. ${SetStartMenuInternet} "HKCU"
  1060. ${FixShellIconHandler} "HKCU"
  1061. ${FixClassKeys} ; Does not use SHCTX
  1062. ${EndIf}
  1063. ${SetHandlers}
  1064. ${If} ${AtLeastWinVista}
  1065. ; Only register as the handler on Vista and above if the app registry name
  1066. ; exists under the RegisteredApplications registry key. The protocol and
  1067. ; file handlers set previously at the user level will associate this install
  1068. ; as the default browser.
  1069. ClearErrors
  1070. ReadRegStr $0 HKLM "Software\RegisteredApplications" "${AppRegName}"
  1071. ${Unless} ${Errors}
  1072. ; This is all protected by a user choice hash in Windows 8 so it won't
  1073. ; help, but it also won't hurt.
  1074. AppAssocReg::SetAppAsDefaultAll "${AppRegName}"
  1075. ${EndUnless}
  1076. ${EndIf}
  1077. ${RemoveDeprecatedKeys}
  1078. ${MigrateTaskBarShortcut}
  1079. FunctionEnd
  1080. ; Helper for updating the shortcut application model IDs.
  1081. Function FixShortcutAppModelIDs
  1082. ${If} ${AtLeastWin7}
  1083. ${AndIf} "$AppUserModelID" != ""
  1084. ${UpdateShortcutAppModelIDs} "$INSTDIR\${FileMainEXE}" "$AppUserModelID" $0
  1085. ${EndIf}
  1086. FunctionEnd
  1087. ; Helper for adding Firewall exceptions during install and after app update.
  1088. Function AddFirewallEntries
  1089. ${IsFirewallSvcRunning}
  1090. Pop $0
  1091. ${If} "$0" == "true"
  1092. liteFirewallW::AddRule "$INSTDIR\${FileMainEXE}" "${BrandShortName} ($INSTDIR)"
  1093. ${EndIf}
  1094. FunctionEnd
  1095. ; The !ifdef NO_LOG prevents warnings when compiling the installer.nsi due to
  1096. ; this function only being used by the uninstaller.nsi.
  1097. !ifdef NO_LOG
  1098. Function SetAsDefaultAppUser
  1099. ; On Win8, we want to avoid having a UAC prompt since we'll already have
  1100. ; another action for control panel default browser selection popping up
  1101. ; to the user. Win8 is the first OS where the start menu keys can be
  1102. ; added into HKCU. The call to SetAsDefaultAppUserHKCU will have already
  1103. ; set the HKCU keys for SetStartMenuInternet.
  1104. ${If} ${AtLeastWin8}
  1105. ; Check if this is running in an elevated process
  1106. ClearErrors
  1107. ${GetParameters} $0
  1108. ${GetOptions} "$0" "/UAC:" $0
  1109. ${If} ${Errors} ; Not elevated
  1110. Call SetAsDefaultAppUserHKCU
  1111. ${Else} ; Elevated - execute the function in the unelevated process
  1112. GetFunctionAddress $0 SetAsDefaultAppUserHKCU
  1113. UAC::ExecCodeSegment $0
  1114. ${EndIf}
  1115. Return ; Nothing more needs to be done
  1116. ${EndIf}
  1117. ; Before Win8, it is only possible to set this installation of the application
  1118. ; as the StartMenuInternet handler if it was added to the HKLM
  1119. ; StartMenuInternet registry keys.
  1120. ; http://support.microsoft.com/kb/297878
  1121. ; Check if this install location registered as the StartMenuInternet client
  1122. ${StrFilter} "${FileMainEXE}" "+" "" "" $R9
  1123. ClearErrors
  1124. ReadRegStr $0 HKCU "Software\Clients\StartMenuInternet\$R9\DefaultIcon" ""
  1125. ${If} ${Errors}
  1126. ${OrIf} ${AtMostWin2008R2}
  1127. ClearErrors
  1128. ReadRegStr $0 HKLM "Software\Clients\StartMenuInternet\$R9\DefaultIcon" ""
  1129. ${EndIf}
  1130. ${Unless} ${Errors}
  1131. ${GetPathFromString} "$0" $0
  1132. ${GetParent} "$0" $0
  1133. ${If} ${FileExists} "$0"
  1134. ${GetLongPath} "$0" $0
  1135. ${If} "$0" == "$INSTDIR"
  1136. ; Check if this is running in an elevated process
  1137. ClearErrors
  1138. ${GetParameters} $0
  1139. ${GetOptions} "$0" "/UAC:" $0
  1140. ${If} ${Errors} ; Not elevated
  1141. Call SetAsDefaultAppUserHKCU
  1142. ${Else} ; Elevated - execute the function in the unelevated process
  1143. GetFunctionAddress $0 SetAsDefaultAppUserHKCU
  1144. UAC::ExecCodeSegment $0
  1145. ${EndIf}
  1146. Return ; Nothing more needs to be done
  1147. ${EndIf}
  1148. ${EndIf}
  1149. ${EndUnless}
  1150. ; The code after ElevateUAC won't be executed on Vista and above when the
  1151. ; user:
  1152. ; a) is a member of the administrators group (e.g. elevation is required)
  1153. ; b) is not a member of the administrators group and chooses to elevate
  1154. ${ElevateUAC}
  1155. ${SetStartMenuInternet} "HKLM"
  1156. SetShellVarContext all ; Set SHCTX to all users (e.g. HKLM)
  1157. ${FixClassKeys} ; Does not use SHCTX
  1158. ${FixShellIconHandler} "HKLM"
  1159. ${RemoveDeprecatedKeys} ; Does not use SHCTX
  1160. ClearErrors
  1161. ${GetParameters} $0
  1162. ${GetOptions} "$0" "/UAC:" $0
  1163. ${If} ${Errors}
  1164. Call SetAsDefaultAppUserHKCU
  1165. ${Else}
  1166. GetFunctionAddress $0 SetAsDefaultAppUserHKCU
  1167. UAC::ExecCodeSegment $0
  1168. ${EndIf}
  1169. FunctionEnd
  1170. !define SetAsDefaultAppUser "Call SetAsDefaultAppUser"
  1171. !endif ; NO_LOG