1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2023 - TortoiseGit
4 // Copyright (C) 2009-2013 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "SmartHandle.h"
22 #include "JumpListHelpers.h"
23 #include "propvarutil.h"
27 HRESULT
SetAppID(LPCWSTR appID
)
29 HRESULT hRes
= S_FALSE
;
30 using SetCurrentProcessExplicitAppUserModelIDFN
= HRESULT(PCWSTR AppID
);
31 CAutoLibrary hShell
= AtlLoadSystemLibraryUsingFullPath(L
"shell32.dll");
34 auto pfnSetCurrentProcessExplicitAppUserModelID
= reinterpret_cast<SetCurrentProcessExplicitAppUserModelIDFN
*>(GetProcAddress(hShell
, "SetCurrentProcessExplicitAppUserModelID"));
35 if (pfnSetCurrentProcessExplicitAppUserModelID
)
36 hRes
= pfnSetCurrentProcessExplicitAppUserModelID(appID
);
41 HRESULT
CreateShellLink(PCWSTR pszArguments
, PCWSTR pszTitle
, int iconIndex
, IShellLink
**ppsl
)
43 ATL::CComPtr
<IShellLink
> psl
;
44 HRESULT hr
= psl
.CoCreateInstance(CLSID_ShellLink
, nullptr, CLSCTX_INPROC_SERVER
);
48 WCHAR szAppPath
[MAX_PATH
] = {0};
49 if (GetModuleFileName(nullptr, szAppPath
, ARRAYSIZE(szAppPath
)) == 0)
51 hr
= HRESULT_FROM_WIN32(GetLastError());
54 hr
= psl
->SetPath(szAppPath
);
58 hr
= psl
->SetArguments(pszArguments
);
62 hr
= psl
->SetIconLocation(szAppPath
, iconIndex
);
66 ATL::CComPtr
<IPropertyStore
> pps
;
67 hr
= psl
.QueryInterface(&pps
);
72 hr
= InitPropVariantFromString(pszTitle
, &propvar
);
75 hr
= pps
->SetValue(PKEY_Title
, propvar
);
79 hr
= psl
.QueryInterface(ppsl
);
82 PropVariantClear(&propvar
);
87 HRESULT
CreateSeparatorLink(IShellLink
**ppsl
)
89 ATL::CComPtr
<IPropertyStore
> pps
;
90 HRESULT hr
= pps
.CoCreateInstance(CLSID_ShellLink
, nullptr, CLSCTX_INPROC_SERVER
);
95 hr
= InitPropVariantFromBoolean(TRUE
, &propvar
);
99 hr
= pps
->SetValue(PKEY_AppUserModel_IsDestListSeparator
, propvar
);
104 hr
= pps
.QueryInterface(ppsl
);
107 PropVariantClear(&propvar
);
111 bool IsItemInArray(IShellItem
*psi
, IObjectArray
*poaRemoved
)
114 if (FAILED(poaRemoved
->GetCount(&cItems
)))
118 for (UINT i
= 0; !fRet
&& i
< cItems
; i
++) {
119 ATL::CComPtr
<IShellItem
> psiCompare
;
120 if (FAILED(poaRemoved
->GetAt(i
, IID_PPV_ARGS(&psiCompare
))))
123 fRet
= SUCCEEDED(psiCompare
->Compare(psi
, SICHINT_CANONICAL
, &iOrder
)) && (0 == iOrder
);
128 void DeleteJumpList(LPCWSTR appID
)
130 ATL::CComPtr
<ICustomDestinationList
> pcdl
;
131 HRESULT hr
= pcdl
.CoCreateInstance(CLSID_DestinationList
, nullptr, CLSCTX_INPROC_SERVER
);
133 pcdl
->DeleteList(appID
);