Include version.h and CrashReport.h only where needed
[TortoiseGit.git] / src / Utils / JumpListHelpers.cpp
blob043e89c2746a2c0b7750ac4bd5de907de5cf6162
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-2012 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "stdafx.h"
20 #include "SmartHandle.h"
21 #include "JumpListHelpers.h"
22 #include "propvarutil.h"
23 #include "propsys.h"
25 HRESULT SetAppID(LPCTSTR appID)
27 HRESULT hRes = S_FALSE;
28 typedef HRESULT STDAPICALLTYPE SetCurrentProcessExplicitAppUserModelIDFN(PCWSTR AppID);
29 CAutoLibrary hShell = AtlLoadSystemLibraryUsingFullPath(_T("shell32.dll"));
30 if (hShell)
32 SetCurrentProcessExplicitAppUserModelIDFN *pfnSetCurrentProcessExplicitAppUserModelID = (SetCurrentProcessExplicitAppUserModelIDFN*)GetProcAddress(hShell, "SetCurrentProcessExplicitAppUserModelID");
33 if (pfnSetCurrentProcessExplicitAppUserModelID)
34 hRes = pfnSetCurrentProcessExplicitAppUserModelID(appID);
36 return hRes;
39 HRESULT CreateShellLink(PCWSTR pszArguments, PCWSTR pszTitle, int iconIndex, IShellLink **ppsl)
41 ATL::CComPtr<IShellLink> psl;
42 HRESULT hr = psl.CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER);
43 if (FAILED(hr))
44 return hr;
46 WCHAR szAppPath[MAX_PATH];
47 if (GetModuleFileName(NULL, szAppPath, ARRAYSIZE(szAppPath)) == 0) {
48 hr = HRESULT_FROM_WIN32(GetLastError());
49 return hr;
51 hr = psl->SetPath(szAppPath);
52 if (FAILED(hr))
53 return hr;
55 hr = psl->SetArguments(pszArguments);
56 if (FAILED(hr))
57 return hr;
59 hr = psl->SetIconLocation(szAppPath, iconIndex);
60 if (FAILED(hr))
61 return hr;
63 ATL::CComPtr<IPropertyStore> pps;
64 hr = psl.QueryInterface(&pps);
65 if (FAILED(hr))
66 return hr;
68 PROPVARIANT propvar;
69 hr = InitPropVariantFromString(pszTitle, &propvar);
70 if (SUCCEEDED(hr))
72 hr = pps->SetValue(PKEY_Title, propvar);
73 if (SUCCEEDED(hr)) {
74 hr = pps->Commit();
75 if (SUCCEEDED(hr)) {
76 hr = psl.QueryInterface(ppsl);
79 PropVariantClear(&propvar);
81 return hr;
84 HRESULT CreateSeparatorLink(IShellLink **ppsl)
86 ATL::CComPtr<IPropertyStore> pps;
87 HRESULT hr = pps.CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER);
88 if (FAILED(hr))
89 return hr;
91 PROPVARIANT propvar;
92 hr = InitPropVariantFromBoolean(TRUE, &propvar);
93 if (FAILED(hr))
94 return hr;
96 hr = pps->SetValue(PKEY_AppUserModel_IsDestListSeparator, propvar);
97 if (SUCCEEDED(hr)) {
98 hr = pps->Commit();
99 if (SUCCEEDED(hr))
101 hr = pps.QueryInterface(ppsl);
104 PropVariantClear(&propvar);
105 return hr;
108 bool IsItemInArray(IShellItem *psi, IObjectArray *poaRemoved)
111 UINT cItems;
112 if (FAILED(poaRemoved->GetCount(&cItems)))
113 return false;
115 bool fRet = false;
116 for (UINT i = 0; !fRet && i < cItems; i++) {
117 ATL::CComPtr<IShellItem> psiCompare;
118 if (FAILED(poaRemoved->GetAt(i, IID_PPV_ARGS(&psiCompare))))
119 continue;
120 int iOrder;
121 fRet = SUCCEEDED(psiCompare->Compare(psi, SICHINT_CANONICAL, &iOrder)) && (0 == iOrder);
123 return fRet;
126 void DeleteJumpList(LPCTSTR appID)
128 ATL::CComPtr<ICustomDestinationList> pcdl;
129 HRESULT hr = pcdl.CoCreateInstance(CLSID_DestinationList, NULL, CLSCTX_INPROC_SERVER);
130 if (SUCCEEDED(hr)) {
131 hr = pcdl->DeleteList(appID);