Bug 598779 - Remove start menu directory and safe mode shortcut creation. r=jmathies, a=blocking2.0-betaN

This commit is contained in:
Robert Strong
2011-01-20 15:45:19 -08:00
parent 7403f238fe
commit 60ee4e95ec
4 changed files with 153 additions and 111 deletions

View File

@@ -54,13 +54,17 @@ RequestExecutionLevel user
!addplugindir ./
Var TmpVal
Var StartMenuDir
Var InstallType
Var AddStartMenuSC
Var AddQuickLaunchSC
Var AddDesktopSC
Var PageName
; By defining NO_STARTMENU_DIR an installer that doesn't provide an option for
; an application's Start Menu PROGRAMS directory and doesn't define the
; StartMenuDir variable can use the common InstallOnInitCommon macro.
!define NO_STARTMENU_DIR
; On Vista and above attempt to elevate Standard Users in addition to users that
; are a member of the Administrators group.
!define NONADMIN_ELEVATE
@@ -95,9 +99,6 @@ VIAddVersionKey "OriginalFilename" "setup.exe"
; Must be inserted before other macros that use logging
!insertmacro _LoggingCommon
; Most commonly used macros for managing shortcuts
!insertmacro _LoggingShortcutsCommon
!insertmacro AddDDEHandlerValues
!insertmacro ChangeMUIHeaderImage
!insertmacro CheckForFilesInUse
@@ -108,6 +109,9 @@ VIAddVersionKey "OriginalFilename" "setup.exe"
!insertmacro GetPathFromString
!insertmacro GetParent
!insertmacro IsHandlerForInstallDir
!insertmacro LogDesktopShortcut
!insertmacro LogQuickLaunchShortcut
!insertmacro LogStartMenuShortcut
!insertmacro ManualCloseAppPrompt
!insertmacro RegCleanAppHandler
!insertmacro RegCleanMain
@@ -178,12 +182,6 @@ Page custom preOptions leaveOptions
; Custom Shortcuts Page
Page custom preShortcuts leaveShortcuts
; Start Menu Folder Page Configuration
!define MUI_PAGE_CUSTOMFUNCTION_PRE preStartMenu
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE leaveStartMenu
!define MUI_STARTMENUPAGE_NODISABLE
!insertmacro MUI_PAGE_STARTMENU Application $StartMenuDir
; Custom Summary Page
Page custom preSummary leaveSummary
@@ -274,7 +272,7 @@ Section "-Application" APP_IDX
ClearErrors
; Default for creating Start Menu folder and shortcuts
; Default for creating Start Menu shortcut
; (1 = create, 0 = don't create)
${If} $AddStartMenuSC == ""
StrCpy $AddStartMenuSC "1"
@@ -382,15 +380,16 @@ Section "-Application" APP_IDX
; Create shortcuts
${LogHeader} "Adding Shortcuts"
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
; Remove the start menu shortcuts and directory if the SMPROGRAMS section
; exists in the shortcuts_log.ini and the SMPROGRAMS. The installer's shortcut
; creation code will create the shortcut in the root of the Start Menu
; Programs directory.
${RemoveStartMenuDir}
; Always add the relative path to the application's Start Menu directory and
; the application's shortcuts to the shortcuts log ini file. The
; DeleteShortcuts macro will do the right thing on uninstall if they don't
; exist.
${LogSMProgramsDirRelPath} "$StartMenuDir"
${LogSMProgramsShortcut} "${BrandFullName}.lnk"
${LogSMProgramsShortcut} "${BrandFullName} ($(SAFE_MODE)).lnk"
; Always add the application's shortcuts to the shortcuts log ini file. The
; DeleteShortcuts macro will do the right thing on uninstall if the
; shortcuts don't exist.
${LogStartMenuShortcut} "${BrandFullName}.lnk"
${LogQuickLaunchShortcut} "${BrandFullName}.lnk"
${LogDesktopShortcut} "${BrandFullName}.lnk"
@@ -399,22 +398,19 @@ Section "-Application" APP_IDX
; since this will either add it for the user if unelevated or All Users if
; elevated.
${If} $AddStartMenuSC == 1
${Unless} ${FileExists} "$SMPROGRAMS\$StartMenuDir"
CreateDirectory "$SMPROGRAMS\$StartMenuDir"
${LogMsg} "Added Start Menu Directory: $SMPROGRAMS\$StartMenuDir"
${EndUnless}
CreateShortCut "$SMPROGRAMS\$StartMenuDir\${BrandFullName}.lnk" "$INSTDIR\${FileMainEXE}" "" "$INSTDIR\${FileMainEXE}" 0
ApplicationID::Set "$SMPROGRAMS\$StartMenuDir\${BrandFullName}.lnk" "${AppUserModelID}"
CreateShortCut "$SMPROGRAMS\${BrandFullName}.lnk" "$INSTDIR\${FileMainEXE}" \
"" "$INSTDIR\${FileMainEXE}" 0
ShellLink::SetShortCutWorkingDirectory "$SMPROGRAMS\${BrandFullName}.lnk" \
"$INSTDIR"
ApplicationID::Set "$SMPROGRAMS\${BrandFullName}.lnk" "${AppUserModelID}"
${LogMsg} "Added Shortcut: $SMPROGRAMS\$StartMenuDir\${BrandFullName}.lnk"
CreateShortCut "$SMPROGRAMS\$StartMenuDir\${BrandFullName} ($(SAFE_MODE)).lnk" "$INSTDIR\${FileMainEXE}" "-safe-mode" "$INSTDIR\${FileMainEXE}" 0
ApplicationID::Set "$SMPROGRAMS\$StartMenuDir\${BrandFullName} ($(SAFE_MODE)).lnk" "${AppUserModelID}"
${LogMsg} "Added Shortcut: $SMPROGRAMS\$StartMenuDir\${BrandFullName} ($(SAFE_MODE)).lnk"
${EndIf}
!insertmacro MUI_STARTMENU_WRITE_END
${If} $AddDesktopSC == 1
CreateShortCut "$DESKTOP\${BrandFullName}.lnk" "$INSTDIR\${FileMainEXE}" "" "$INSTDIR\${FileMainEXE}" 0
CreateShortCut "$DESKTOP\${BrandFullName}.lnk" "$INSTDIR\${FileMainEXE}" \
"" "$INSTDIR\${FileMainEXE}" 0
ShellLink::SetShortCutWorkingDirectory "$DESKTOP\${BrandFullName}.lnk" \
"$INSTDIR"
ApplicationID::Set "$DESKTOP\${BrandFullName}.lnk" "${AppUserModelID}"
${LogMsg} "Added Shortcut: $DESKTOP\${BrandFullName}.lnk"
${EndIf}
@@ -523,8 +519,6 @@ Function CustomAbort
GetFunctionAddress $0 AbortSurveyDirectory
${ElseIf} "$PageName" == "Shortcuts"
GetFunctionAddress $0 AbortSurveyShortcuts
${ElseIf} "$PageName" == "StartMenu"
GetFunctionAddress $0 AbortSurveyStartMenu
${ElseIf} "$PageName" == "Summary"
GetFunctionAddress $0 AbortSurveySummary
${EndIf}
@@ -564,19 +558,18 @@ Function AbortSurveyShortcuts
ExecShell "open" "${AbortSurveyURL}step4"
FunctionEnd
Function AbortSurveyStartMenu
ExecShell "open" "${AbortSurveyURL}step5"
FunctionEnd
Function AbortSurveySummary
ExecShell "open" "${AbortSurveyURL}step6"
ExecShell "open" "${AbortSurveyURL}step5"
FunctionEnd
################################################################################
# Helper Functions
Function AddQuickLaunchShortcut
CreateShortCut "$QUICKLAUNCH\${BrandFullName}.lnk" "$INSTDIR\${FileMainEXE}" "" "$INSTDIR\${FileMainEXE}" 0
CreateShortCut "$QUICKLAUNCH\${BrandFullName}.lnk" "$INSTDIR\${FileMainEXE}" \
"" "$INSTDIR\${FileMainEXE}" 0
ShellLink::SetShortCutWorkingDirectory "$QUICKLAUNCH\${BrandFullName}.lnk" \
"$INSTDIR"
ApplicationID::Set "$QUICKLAUNCH\${BrandFullName}.lnk" "${AppUserModelID}"
FunctionEnd
@@ -746,49 +739,6 @@ Function leaveShortcuts
${MUI_INSTALLOPTIONS_READ} $AddStartMenuSC "shortcuts.ini" "Field 3" "State"
${MUI_INSTALLOPTIONS_READ} $AddQuickLaunchSC "shortcuts.ini" "Field 4" "State"
; If Start Menu shortcuts won't be created call CheckExistingInstall here
; since leaveStartMenu will not be called.
${If} $AddStartMenuSC != 1
${AndIf} $InstallType == ${INSTALLTYPE_CUSTOM}
Call CheckExistingInstall
${EndIf}
FunctionEnd
Function preStartMenu
StrCpy $PageName "StartMenu"
; With the Unicode installer the path to the application's Start Menu
; directory relative to the Start Menu's Programs directory is written to the
; shortcuts log ini file and is used to set the default Start Menu directory.
${GetSMProgramsDirRelPath} $0
${If} "$0" != ""
StrCpy $StartMenuDir "$0"
${Else}
; Prior to the Unicode installer the path to the application's Start Menu
; directory relative to the Start Menu's Programs directory was written to
; the registry and use this value to set the default Start Menu directory.
ClearErrors
ReadRegStr $0 HKLM "Software\Mozilla\${BrandFullNameInternal}\${AppVersion} (${AB_CD})\Main" "Start Menu Folder"
${If} ${Errors}
; Use the FindSMProgramsDir macro to find a previously used path to the
; application's Start Menu directory relative to the Start Menu's Programs
; directory in the uninstall log and use this value to set the default
; Start Menu directory.
${FindSMProgramsDir} $0
${If} "$0" != ""
StrCpy $StartMenuDir "$0"
${EndIf}
${Else}
StrCpy $StartMenuDir "$0"
${EndUnless}
${EndIf}
${CheckCustomCommon}
${If} $AddStartMenuSC != 1
Abort
${EndIf}
FunctionEnd
Function leaveStartMenu
${If} $InstallType == ${INSTALLTYPE_CUSTOM}
Call CheckExistingInstall
${EndIf}

View File

@@ -78,6 +78,10 @@
${EndIf}
${EndIf}
; Migrate the application's Start Menu directory to a single shortcut in the
; root of the Start Menu Programs directory.
${MigrateStartMenuShortcut}
${RemoveDeprecatedKeys}
${SetAppKeys}
@@ -156,22 +160,23 @@
WriteRegDWORD HKLM "$R1" "IconsVisible" 1
SetShellVarContext all ; Set $DESKTOP to All Users
${Unless} ${FileExists} "$DESKTOP\${BrandFullName}.lnk"
CreateShortCut "$DESKTOP\${BrandFullName}.lnk" "$INSTDIR\${FileMainEXE}" "" "$INSTDIR\${FileMainEXE}" 0
ApplicationID::Set "$DESKTOP\${BrandFullName}.lnk" "${AppUserModelID}"
CreateShortCut "$DESKTOP\${BrandFullName}.lnk" "$INSTDIR\${FileMainEXE}" \
"" "$INSTDIR\${FileMainEXE}" 0
ShellLink::SetShortCutWorkingDirectory "$DESKTOP\${BrandFullName}.lnk" "$INSTDIR"
ApplicationID::Set "$DESKTOP\${BrandFullName}.lnk" "${AppUserModelID}"
${Unless} ${FileExists} "$DESKTOP\${BrandFullName}.lnk"
SetShellVarContext current ; Set $DESKTOP to the current user's desktop
${Unless} ${FileExists} "$DESKTOP\${BrandFullName}.lnk"
CreateShortCut "$DESKTOP\${BrandFullName}.lnk" "$INSTDIR\${FileMainEXE}" "" "$INSTDIR\${FileMainEXE}" 0
ApplicationID::Set "$DESKTOP\${BrandFullName}.lnk" "${AppUserModelID}"
ShellLink::SetShortCutWorkingDirectory "$DESKTOP\${BrandFullName}.lnk" "$INSTDIR"
ApplicationID::Set "$DESKTOP\${BrandFullName}.lnk" "${AppUserModelID}"
${EndUnless}
${EndUnless}
${EndUnless}
${Unless} ${FileExists} "$QUICKLAUNCH\${BrandFullName}.lnk"
CreateShortCut "$QUICKLAUNCH\${BrandFullName}.lnk" "$INSTDIR\${FileMainEXE}" "" "$INSTDIR\${FileMainEXE}" 0
ApplicationID::Set "$QUICKLAUNCH\${BrandFullName}.lnk" "${AppUserModelID}"
ShellLink::SetShortCutWorkingDirectory "$QUICKLAUNCH\${BrandFullName}.lnk" "$INSTDIR"
ApplicationID::Set "$QUICKLAUNCH\${BrandFullName}.lnk" "${AppUserModelID}"
${EndUnless}
!macroend
!define ShowShortcuts "!insertmacro ShowShortcuts"
@@ -612,29 +617,114 @@
!macroend
!define RemoveDeprecatedFiles "!insertmacro RemoveDeprecatedFiles"
; Adds a shortcut to the root of the Start Menu Programs directory if the
; application's Start Menu Programs directory exists with a shortcut pointing to
; this installation directory. This will also remove the old shortcuts and the
; application's Start Menu Programs directory by calling the RemoveStartMenuDir
; macro.
!macro MigrateStartMenuShortcut
${GetShortcutsLogPath} $0
${If} ${FileExists} "$0"
ClearErrors
ReadINIStr $1 "$0" "SMPROGRAMS" "RelativePathToDir"
${Unless} ${Errors}
ClearErrors
ReadINIStr $1 "$0" "STARTMENU" "Shortcut0"
${If} ${Errors}
; The STARTMENU ini section doesn't exist.
${LogStartMenuShortcut} "${BrandFullName}.lnk"
${GetLongPath} "$SMPROGRAMS" $2
${GetLongPath} "$2\$1" $1
${If} "$1" != ""
ClearErrors
ReadINIStr $3 "$0" "SMPROGRAMS" "Shortcut0"
${Unless} ${Errors}
${If} ${FileExists} "$1\$3"
ShellLink::GetShortCutTarget "$1\$3"
Pop $4
${If} "$INSTDIR\${FileMainEXE}" == "$4"
CreateShortCut "$SMPROGRAMS\${BrandFullName}.lnk" \
"$INSTDIR\${FileMainEXE}" "" \
"$INSTDIR\${FileMainEXE}" 0
ShellLink::SetShortCutWorkingDirectory "$SMPROGRAMS\${BrandFullName}.lnk" \
"$INSTDIR"
ApplicationID::Set "$SMPROGRAMS\${BrandFullName}.lnk" \
"${AppUserModelID}"
${EndIf}
${EndIf}
${EndUnless}
${EndIf}
${EndIf}
; Remove the application's Start Menu Programs directory, shortcuts, and
; ini section.
${RemoveStartMenuDir}
${EndUnless}
${EndIf}
!macroend
!define MigrateStartMenuShortcut "!insertmacro MigrateStartMenuShortcut"
; Removes the application's start menu directory along with its shortcuts if
; they exist and if they exist creates a start menu shortcut in the root of the
; start menu directory (bug 598779). If the application's start menu directory
; is not empty after removing the shortucts the directory will not be removed
; since these additional items were not created by the installer (uses SHCTX).
!macro RemoveStartMenuDir
${GetShortcutsLogPath} $0
${If} ${FileExists} "$0"
; Delete Start Menu Programs shortcuts, directory if it is empty, and
; parent directories if they are empty up to but not including the start
; menu directory.
${GetLongPath} "$SMPROGRAMS" $1
ClearErrors
ReadINIStr $2 "$0" "SMPROGRAMS" "RelativePathToDir"
${Unless} ${Errors}
${GetLongPath} "$1\$2" $2
${If} "$2" != ""
; Delete shortucts in the Start Menu Programs directory.
StrCpy $3 0
${Do}
ClearErrors
ReadINIStr $4 "$0" "SMPROGRAMS" "Shortcut$3"
; Stop if there are no more entries
${If} ${Errors}
${ExitDo}
${EndIf}
${If} ${FileExists} "$2\$4"
ShellLink::GetShortCutTarget "$2\$4"
Pop $5
${If} "$INSTDIR\${FileMainEXE}" == "$5"
Delete "$2\$4"
${EndIf}
${EndIf}
IntOp $3 $3 + 1 ; Increment the counter
${Loop}
; Delete Start Menu Programs directory and parent directories
${Do}
; Stop if the current directory is the start menu directory
${If} "$1" == "$2"
${ExitDo}
${EndIf}
ClearErrors
RmDir "$2"
; Stop if removing the directory failed
${If} ${Errors}
${ExitDo}
${EndIf}
${GetParent} "$2" $2
${Loop}
${EndIf}
DeleteINISec "$0" "SMPROGRAMS"
${EndUnless}
${EndIf}
!macroend
!define RemoveStartMenuDir "!insertmacro RemoveStartMenuDir"
; Creates the shortcuts log ini file with the appropriate entries if it doesn't
; already exist.
!macro CreateShortcutsLog
${GetShortcutsLogPath} $0
${Unless} ${FileExists} "$0"
; Default to ${BrandFullName} for the Start Menu Folder
StrCpy $TmpVal "${BrandFullName}"
; Prior to Firefox 3.1 the Start Menu directory was written to the registry and
; this value can be used to set the Start Menu directory.
ClearErrors
ReadRegStr $0 SHCTX "Software\Mozilla\${BrandFullNameInternal}\${AppVersion} (${AB_CD})\Main" "Start Menu Folder"
${If} ${Errors}
${FindSMProgramsDir} $0
${If} "$0" != ""
StrCpy $TmpVal "$0"
${EndIf}
${Else}
StrCpy $TmpVal "$0"
${EndUnless}
${LogSMProgramsDirRelPath} "$TmpVal"
${LogSMProgramsShortcut} "${BrandFullName}.lnk"
${LogSMProgramsShortcut} "${BrandFullName} ($(SAFE_MODE)).lnk"
${LogStartMenuShortcut} "${BrandFullName}.lnk"
${LogQuickLaunchShortcut} "${BrandFullName}.lnk"
${LogDesktopShortcut} "${BrandFullName}.lnk"
${EndUnless}

View File

@@ -87,9 +87,6 @@ Var TmpVal
VIAddVersionKey "FileDescription" "${BrandShortName} Helper"
VIAddVersionKey "OriginalFilename" "helper.exe"
; Most commonly used macros for managing shortcuts
!insertmacro _LoggingShortcutsCommon
!insertmacro AddDDEHandlerValues
!insertmacro CleanVirtualStore
!insertmacro ElevateUAC
@@ -97,6 +94,9 @@ VIAddVersionKey "OriginalFilename" "helper.exe"
!insertmacro GetLongPath
!insertmacro GetPathFromString
!insertmacro IsHandlerForInstallDir
!insertmacro LogDesktopShortcut
!insertmacro LogQuickLaunchShortcut
!insertmacro LogStartMenuShortcut
!insertmacro RegCleanAppHandler
!insertmacro RegCleanMain
!insertmacro RegCleanUninstall