Bug 1357161 - Replace shortcut icons on application update. r?agashlin draft
authorMatt Howell <mhowell@mozilla.com>
Mon, 17 Apr 2017 16:06:46 -0700
changeset 564719 ae225fdd779749c1e2ec49a95933438e973ae350
parent 563687 05c212a94183838f12feebb2c3fd483a6eec18c2
child 624813 2b4686a6113bc2dc334bf2d3b61046cbdd7e0bfc
push id54676
push usermhowell@mozilla.com
push dateTue, 18 Apr 2017 22:07:35 +0000
reviewersagashlin
bugs1357161
milestone55.0a1
Bug 1357161 - Replace shortcut icons on application update. r?agashlin MozReview-Commit-ID: LHrN4eXwRFt
browser/installer/windows/nsis/shared.nsh
--- a/browser/installer/windows/nsis/shared.nsh
+++ b/browser/installer/windows/nsis/shared.nsh
@@ -75,17 +75,17 @@
   ${AndIf} ${FileExists} "$SMPROGRAMS\${BrandFullName}.lnk"
     FileOpen $0 "$SMPROGRAMS\${BrandFullName}.lnk" a
     FileClose $0
   ${EndIf}
 
   ; Adds a pinned Task Bar shortcut (see MigrateTaskBarShortcut for details).
   ${MigrateTaskBarShortcut}
 
-  ${UpdateShortcutNames}
+  ${UpdateShortcutBranding}
 
   ${RemoveDeprecatedKeys}
 
   ${SetAppKeys}
   ${FixClassKeys}
   ${SetUninstallKeys}
   ${If} $TmpVal == "HKLM"
     ${SetStartMenuInternet} HKLM
@@ -310,70 +310,134 @@
   ${EndUnless}
 !macroend
 !define ShowShortcuts "!insertmacro ShowShortcuts"
 
 ; Update the branding information on all shortcuts our installer created,
 ; in case the branding has changed between updates.
 ; This should only be called sometime after both MigrateStartMenuShortcut
 ; and MigrateTaskBarShurtcut
-!macro UpdateShortcutNames
+!macro UpdateShortcutBranding
   ${GetLongPath} "$INSTDIR\uninstall\${SHORTCUTS_LOG}" $R9
   ${If} ${FileExists} "$R9"
     ClearErrors
     ; The entries in the shortcut log are numbered, but we never actually
     ; create more than one shortcut (or log entry) in each location.
     ReadINIStr $R8 "$R9" "STARTMENU" "Shortcut0"
     ${IfNot} ${Errors}
       ${If} ${FileExists} "$SMPROGRAMS\$R8"
-      ${AndIf} $R8 != "${BrandFullName}.lnk"
         ShellLink::GetShortCutTarget "$SMPROGRAMS\$R8"
         Pop $R7
         ${GetLongPath} "$R7" $R7
-        ${If} "$INSTDIR\${FileMainEXE}" == "$R7"
-          Rename "$SMPROGRAMS\$R8" "$SMPROGRAMS\${BrandFullName}.lnk"
-          WriteINIStr "$R9" "STARTMENU" "Shortcut0" "${BrandFullName}.lnk"
+        ${If} $R7 == "$INSTDIR\${FileMainEXE}"
+          ShellLink::GetShortCutIconLocation "$SMPROGRAMS\$R8"
+          Pop $R6
+          ${GetLongPath} "$R6" $R6
+          ${If} $R6 != "$INSTDIR\firefox.ico"
+          ${AndIf} ${FileExists} "$INSTDIR\firefox.ico"
+            StrCpy $R5 "1"
+          ${ElseIf} $R6 == "$INSTDIR\firefox.ico"
+          ${AndIfNot} ${FileExists} "$INSTDIR\firefox.ico"
+            StrCpy $R5 "1"
+          ${Else}
+            StrCpy $R5 "0"
+          ${EndIf}
+
+          ${If} $R5 == "1"
+          ${OrIf} $R8 != "${BrandFullName}.lnk"
+            Delete "$SMPROGRAMS\$R8"
+            ${If} ${FileExists} "$INSTDIR\firefox.ico"
+              CreateShortcut "$SMPROGRAMS\${BrandFullName}.lnk" \
+                             "$INSTDIR\${FileMainEXE}" "" "$INSTDIR\firefox.ico"
+            ${Else}
+              CreateShortcut "$SMPROGRAMS\${BrandFullName}.lnk" \
+                             "$INSTDIR\${FileMainEXE}"
+            ${EndIf}
+            WriteINIStr "$R9" "STARTMENU" "Shortcut0" "${BrandFullName}.lnk"
+          ${EndIf}
         ${EndIf}
       ${EndIf}
     ${EndIf}
 
     ClearErrors
     ReadINIStr $R8 "$R9" "DESKTOP" "Shortcut0"
     ${IfNot} ${Errors}
       ${If} ${FileExists} "$DESKTOP\$R8"
-      ${AndIf} $R8 != "${BrandFullName}.lnk"
         ShellLink::GetShortCutTarget "$DESKTOP\$R8"
         Pop $R7
         ${GetLongPath} "$R7" $R7
-        ${If} "$INSTDIR\${FileMainEXE}" == "$R7"
-          Rename "$DESKTOP\$R8" "$DESKTOP\${BrandFullName}.lnk"
-          WriteINIStr "$R9" "DESKTOP" "Shortcut0" "${BrandFullName}.lnk"
+        ${If} $R7 == "$INSTDIR\${FileMainEXE}"
+          ShellLink::GetShortCutIconLocation "$DESKTOP\$R8"
+          Pop $R6
+          ${GetLongPath} "$R6" $R6
+          ${If} $R6 != "$INSTDIR\firefox.ico"
+          ${AndIf} ${FileExists} "$INSTDIR\firefox.ico"
+            StrCpy $R5 "1"
+          ${ElseIf} $R6 == "$INSTDIR\firefox.ico"
+          ${AndIfNot} ${FileExists} "$INSTDIR\firefox.ico"
+            StrCpy $R5 "1"
+          ${Else}
+            StrCpy $R5 "0"
+          ${EndIf}
+
+          ${If} $R5 == "1"
+          ${OrIf} $R8 != "${BrandFullName}.lnk"
+            Delete "$DESKTOP\$R8"
+            ${If} ${FileExists} "$INSTDIR\firefox.ico"
+              CreateShortcut "$DESKTOP\${BrandFullName}.lnk" \
+                             "$INSTDIR\${FileMainEXE}" "" "$INSTDIR\firefox.ico"
+            ${Else}
+              CreateShortcut "$DESKTOP\${BrandFullName}.lnk" \
+                             "$INSTDIR\${FileMainEXE}"
+            ${EndIf}
+            WriteINIStr "$R9" "DESKTOP" "Shortcut0" "${BrandFullName}.lnk"
+          ${EndIf}
         ${EndIf}
       ${EndIf}
     ${EndIf}
 
     ClearErrors
     ReadINIStr $R8 "$R9" "QUICKLAUNCH" "Shortcut0"
     ${IfNot} ${Errors}
       ; "QUICKLAUNCH" actually means a taskbar pin.
+      ; We can't simultaneously rename and change the icon for a taskbar pin
+      ; without the icon breaking, and the icon is more important than the name,
+      ; so we'll forget about changing the name and just overwrite the icon.
       ${If} ${FileExists} "$QUICKLAUNCH\User Pinned\TaskBar\$R8"
-      ${AndIf} $R8 != "${BrandFullName}.lnk"
         ShellLink::GetShortCutTarget "$QUICKLAUNCH\User Pinned\TaskBar\$R8"
         Pop $R7
         ${GetLongPath} "$R7" $R7
         ${If} "$INSTDIR\${FileMainEXE}" == "$R7"
-          Rename "$QUICKLAUNCH\User Pinned\TaskBar\$R8" \
-                 "$QUICKLAUNCH\User Pinned\TaskBar\${BrandFullName}.lnk"
-          WriteINIStr "$R9" "QUICKLAUNCH" "Shortcut0" "${BrandFullName}.lnk"
+          ShellLink::GetShortCutIconLocation "$QUICKLAUNCH\User Pinned\TaskBar\$R8"
+          Pop $R6
+          ${GetLongPath} "$R6" $R6
+          ${If} $R6 != "$INSTDIR\firefox.ico"
+          ${AndIf} ${FileExists} "$INSTDIR\firefox.ico"
+            StrCpy $R5 "1"
+          ${ElseIf} $R6 == "$INSTDIR\firefox.ico"
+          ${AndIfNot} ${FileExists} "$INSTDIR\firefox.ico"
+            StrCpy $R5 "1"
+          ${Else}
+            StrCpy $R5 "0"
+          ${EndIf}
+
+          ${If} $R5 == "1"
+            ${If} ${FileExists} "$INSTDIR\firefox.ico"
+              CreateShortcut "$QUICKLAUNCH\User Pinned\TaskBar\$R8" "$R7" "" \
+                             "$INSTDIR\firefox.ico"
+            ${Else}
+              CreateShortcut "$QUICKLAUNCH\User Pinned\TaskBar\$R8" "$R7"
+            ${EndIf}
+          ${EndIf}
         ${EndIf}
       ${EndIf}
     ${EndIf}
   ${EndIf}
 !macroend
-!define UpdateShortcutNames "!insertmacro UpdateShortcutNames"
+!define UpdateShortcutBranding "!insertmacro UpdateShortcutBranding"
 
 !macro AddAssociationIfNoneExist FILE_TYPE KEY
   ClearErrors
   EnumRegKey $7 HKCR "${FILE_TYPE}" 0
   ${If} ${Errors}
     WriteRegStr SHCTX "SOFTWARE\Classes\${FILE_TYPE}"  "" ${KEY}
   ${EndIf}
   WriteRegStr SHCTX "SOFTWARE\Classes\${FILE_TYPE}\OpenWithProgids" ${KEY} ""