From 3c47165946ebcad064a0bff3a8d4defbe17c8772 Mon Sep 17 00:00:00 2001 From: anders_k Date: Thu, 21 May 2020 00:44:39 +0000 Subject: [PATCH] Added UnpinShortcut and NotifyShell_AssocChanged macros git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@7183 212acab6-be3b-0410-9dea-997c60f758d6 --- Docs/src/history.but | 2 ++ Examples/install-per-user.nsi | 10 ++++---- Examples/install-shared.nsi | 10 ++++---- Examples/makensis.nsi | 12 ++++------ Include/Integration.nsh | 44 +++++++++++++++++++++++++++++++++++ Include/SConscript | 1 + 6 files changed, 63 insertions(+), 16 deletions(-) create mode 100644 Include/Integration.nsh diff --git a/Docs/src/history.but b/Docs/src/history.but index a37c4632..8d1cd4b2 100644 --- a/Docs/src/history.but +++ b/Docs/src/history.but @@ -16,6 +16,8 @@ Released on ? ?th, 2020 \b Added \R{getknownfolderpath}{GetKnownFolderPath} +\b Added UnpinShortcut macro (Integration.nsh) + \S2{} Minor Changes \b Added \R{ifshellvarcontextall}{IfShellVarContextAll} and \R{ifrtllanguage}{IfRtlLanguage} diff --git a/Examples/install-per-user.nsi b/Examples/install-per-user.nsi index 7fcebb42..b152245f 100644 --- a/Examples/install-per-user.nsi +++ b/Examples/install-per-user.nsi @@ -22,6 +22,7 @@ InstallDirRegKey HKCU "${REGPATH_UNINSTSUBKEY}" "UninstallString" !include LogicLib.nsh !include WinCore.nsh +!include Integration.nsh Page Directory @@ -103,7 +104,7 @@ Section -ShellAssoc WriteRegStr ShCtx "Software\RegisteredApplications" "Nullsoft Test App" "Software\Classes\Applications\${ASSOC_APPEXE}\Capabilities" !endif - System::Call 'SHELL32::SHChangeNotify(i0x08000000, i0, p0, p0)' ; Notify the shell with SHCNE_ASSOCCHANGED + ${NotifyShell_AssocChanged} SectionEnd @@ -153,14 +154,15 @@ Section -un.ShellAssoc ;DeleteRegKey HKCU "Software\Microsoft\Windows\Roaming\OpenWith\FileExts\${ASSOC_EXT}" ;DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\RecentDocs\${ASSOC_EXT}" - System::Call 'SHELL32::SHChangeNotify(i0x08000000, i0, p0, p0)' ; Notify the shell with SHCNE_ASSOCCHANGED + ${NotifyShell_AssocChanged} SectionEnd Section -Uninstall + ${UnpinShortcut} "$SMPrograms\${NAME}.lnk" + Delete "$SMPrograms\${NAME}.lnk" + Delete "$InstDir\MyApp.exe" Delete "$InstDir\Uninst.exe" RMDir "$InstDir" DeleteRegKey HKCU "${REGPATH_UNINSTSUBKEY}" - - Delete "$SMPrograms\${NAME}.lnk" SectionEnd diff --git a/Examples/install-shared.nsi b/Examples/install-shared.nsi index 55a4185e..7b88f099 100644 --- a/Examples/install-shared.nsi +++ b/Examples/install-shared.nsi @@ -21,14 +21,15 @@ RequestExecutionLevel Admin ; Request admin rights on WinVista+ (when UAC is tur InstallDir "$ProgramFiles\$(^Name)" InstallDirRegKey HKLM "${REGPATH_UNINSTSUBKEY}" "UninstallString" +!include LogicLib.nsh +!include Integration.nsh + Page Directory Page InstFiles Uninstpage UninstConfirm Uninstpage InstFiles -!include LogicLib.nsh - !macro EnsureAdminRights UserInfo::GetAccountType Pop $0 @@ -70,10 +71,11 @@ SectionEnd Section -Uninstall + ${UnpinShortcut} "$SMPrograms\${NAME}.lnk" + Delete "$SMPrograms\${NAME}.lnk" + Delete "$InstDir\MyApp.exe" Delete "$InstDir\Uninst.exe" RMDir "$InstDir" DeleteRegKey HKLM "${REGPATH_UNINSTSUBKEY}" - - Delete "$SMPrograms\${NAME}.lnk" SectionEnd diff --git a/Examples/makensis.nsi b/Examples/makensis.nsi index c35b443a..6b1d7997 100644 --- a/Examples/makensis.nsi +++ b/Examples/makensis.nsi @@ -49,12 +49,7 @@ RequestExecutionLevel admin !include "Memento.nsh" !include "WordFunc.nsh" !include "Util.nsh" - -;-------------------------------- -;Definitions - -!define SHCNE_ASSOCCHANGED 0x8000000 -!define SHCNF_IDLIST 0 +!include "Integration.nsh" ;-------------------------------- ;Configuration @@ -213,6 +208,7 @@ ${MementoSection} "NSIS Core Files (required)" SecCore File ..\Include\MultiUser.nsh File ..\Include\VB6RunTime.nsh File ..\Include\Util.nsh + File ..\Include\Integration.nsh File ..\Include\WinCore.nsh SetOutPath $INSTDIR\Include\Win @@ -296,7 +292,7 @@ ${MementoSection} "NSIS Core Files (required)" SecCore WriteRegStr HKCR "NSIS.Header\shell\open\command" "" 'notepad.exe "%1"' ${EndIf} - System::Call 'Shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_IDLIST}, p0, p0)' + ${NotifyShell_AssocChanged} ${MementoSectionEnd} @@ -1071,7 +1067,7 @@ Section Uninstall !insertmacro AssocDeleteFileExtAndProgId HKLM ".nsi" "NSIS.Script" !insertmacro AssocDeleteFileExtAndProgId HKLM ".nsh" "NSIS.Header" - System::Call 'Shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_IDLIST}, p0, p0)' + ${NotifyShell_AssocChanged} DeleteRegKey HKLM "${REG_UNINST_KEY}" DeleteRegKey HKLM "Software\NSIS" diff --git a/Include/Integration.nsh b/Include/Integration.nsh new file mode 100644 index 00000000..8ee6a382 --- /dev/null +++ b/Include/Integration.nsh @@ -0,0 +1,44 @@ +!verbose push 3 +!ifndef INTEGRATION_INCLUDED +!define INTEGRATION_INCLUDED 1 + +!include "Util.nsh" + + +!define NotifyShell_AssocChanged `System::Call 'SHELL32::SHChangeNotify(i0x8000000,i0,p0,p0)'` ; Notify the shell with SHCNE_ASSOCCHANGED + + +!define UnpinShortcut "!insertmacro UnpinShortcut " +!macro UnpinShortcut lnkpath +Push "${lnkpath}" +${CallArtificialFunction} UnpinShortcut_Implementation +!macroend +!macro UnpinShortcut_Implementation +!include "LogicLib.nsh" +!include "Win\COM.nsh" +Exch $0 +Push $1 +!insertmacro ComHlpr_CreateInProcInstance ${CLSID_StartMenuPin} ${IID_IStartMenuPinnedList} r1 "" +${If} $1 P<> 0 + System::Call 'SHELL32::SHCreateItemFromParsingName(wr0,p0,g"${IID_IShellItem}",*p0r0)' + ${If} $0 P<> 0 + ${IStartMenuPinnedList::RemoveFromList} $1 '(r0)' + ${IUnknown::Release} $0 "" + ${EndIf} + ${IUnknown::Release} $1 "" +!ifdef NSIS_IX86 | NSIS_AMD64 +${Else} + !insertmacro ComHlpr_CreateInProcInstance ${CLSID_StartMenuPin} "{ec35e37a-6579-4f3c-93cd-6e62c4ef7636}" r1 "" + ${If} $1 P<> 0 + ExecShellWait /INVOKEIDLIST "unpin" $0 ; WinXP + ${IUnknown::Release} $1 "" + ${EndIf} +!endif +${EndIf} +Pop $1 +Pop $0 +!macroend + + +!endif #!INCLUDED +!verbose pop diff --git a/Include/SConscript b/Include/SConscript index 531256b2..4557592a 100644 --- a/Include/SConscript +++ b/Include/SConscript @@ -1,6 +1,7 @@ includes = Split(""" Colors.nsh FileFunc.nsh + Integration.nsh LangFile.nsh Library.nsh LogicLib.nsh