Fix typos
[TortoiseGit.git] / src / Utils / JumpListHelpers.cpp
blob53201eac793aa95eb548eb23afdcc12871cd8936
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.
20 #include "stdafx.h"
21 #include "SmartHandle.h"
22 #include "JumpListHelpers.h"
23 #include "propvarutil.h"
24 #include "propsys.h"
25 #include <propkey.h>
27 HRESULT SetAppID(LPCWSTR appID)
29 HRESULT hRes = S_FALSE;
30 using SetCurrentProcessExplicitAppUserModelIDFN = HRESULT(PCWSTR AppID);
31 CAutoLibrary hShell = AtlLoadSystemLibraryUsingFullPath(L"shell32.dll");
32 if (hShell)
34 auto pfnSetCurrentProcessExplicitAppUserModelID = reinterpret_cast<SetCurrentProcessExplicitAppUserModelIDFN*>(GetProcAddress(hShell, "SetCurrentProcessExplicitAppUserModelID"));
35 if (pfnSetCurrentProcessExplicitAppUserModelID)
36 hRes = pfnSetCurrentProcessExplicitAppUserModelID(appID);
38 return hRes;
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);
45 if (FAILED(hr))
46 return hr;
48 WCHAR szAppPath[MAX_PATH] = {0};
49 if (GetModuleFileName(nullptr, szAppPath, ARRAYSIZE(szAppPath)) == 0)
51 hr = HRESULT_FROM_WIN32(GetLastError());
52 return hr;
54 hr = psl->SetPath(szAppPath);
55 if (FAILED(hr))
56 return hr;
58 hr = psl->SetArguments(pszArguments);
59 if (FAILED(hr))
60 return hr;
62 hr = psl->SetIconLocation(szAppPath, iconIndex);
63 if (FAILED(hr))
64 return hr;
66 ATL::CComPtr<IPropertyStore> pps;
67 hr = psl.QueryInterface(&pps);
68 if (FAILED(hr))
69 return hr;
71 PROPVARIANT propvar;
72 hr = InitPropVariantFromString(pszTitle, &propvar);
73 if (SUCCEEDED(hr))
75 hr = pps->SetValue(PKEY_Title, propvar);
76 if (SUCCEEDED(hr)) {
77 hr = pps->Commit();
78 if (SUCCEEDED(hr)) {
79 hr = psl.QueryInterface(ppsl);
82 PropVariantClear(&propvar);
84 return hr;
87 HRESULT CreateSeparatorLink(IShellLink **ppsl)
89 ATL::CComPtr<IPropertyStore> pps;
90 HRESULT hr = pps.CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER);
91 if (FAILED(hr))
92 return hr;
94 PROPVARIANT propvar;
95 hr = InitPropVariantFromBoolean(TRUE, &propvar);
96 if (FAILED(hr))
97 return hr;
99 hr = pps->SetValue(PKEY_AppUserModel_IsDestListSeparator, propvar);
100 if (SUCCEEDED(hr)) {
101 hr = pps->Commit();
102 if (SUCCEEDED(hr))
104 hr = pps.QueryInterface(ppsl);
107 PropVariantClear(&propvar);
108 return hr;
111 bool IsItemInArray(IShellItem *psi, IObjectArray *poaRemoved)
113 UINT cItems;
114 if (FAILED(poaRemoved->GetCount(&cItems)))
115 return false;
117 bool fRet = false;
118 for (UINT i = 0; !fRet && i < cItems; i++) {
119 ATL::CComPtr<IShellItem> psiCompare;
120 if (FAILED(poaRemoved->GetAt(i, IID_PPV_ARGS(&psiCompare))))
121 continue;
122 int iOrder;
123 fRet = SUCCEEDED(psiCompare->Compare(psi, SICHINT_CANONICAL, &iOrder)) && (0 == iOrder);
125 return fRet;
128 void DeleteJumpList(LPCWSTR appID)
130 ATL::CComPtr<ICustomDestinationList> pcdl;
131 HRESULT hr = pcdl.CoCreateInstance(CLSID_DestinationList, nullptr, CLSCTX_INPROC_SERVER);
132 if (SUCCEEDED(hr)) {
133 pcdl->DeleteList(appID);