1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-2013 - 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.
20 #include "SmartHandle.h"
21 #include "JumpListHelpers.h"
22 #include "propvarutil.h"
26 HRESULT
SetAppID(LPCTSTR appID
)
28 HRESULT hRes
= S_FALSE
;
29 typedef HRESULT STDAPICALLTYPE
SetCurrentProcessExplicitAppUserModelIDFN(PCWSTR AppID
);
30 CAutoLibrary hShell
= AtlLoadSystemLibraryUsingFullPath(_T("shell32.dll"));
33 SetCurrentProcessExplicitAppUserModelIDFN
*pfnSetCurrentProcessExplicitAppUserModelID
= (SetCurrentProcessExplicitAppUserModelIDFN
*)GetProcAddress(hShell
, "SetCurrentProcessExplicitAppUserModelID");
34 if (pfnSetCurrentProcessExplicitAppUserModelID
)
35 hRes
= pfnSetCurrentProcessExplicitAppUserModelID(appID
);
40 HRESULT
CreateShellLink(PCWSTR pszArguments
, PCWSTR pszTitle
, int iconIndex
, IShellLink
**ppsl
)
42 ATL::CComPtr
<IShellLink
> psl
;
43 HRESULT hr
= psl
.CoCreateInstance(CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
);
47 WCHAR szAppPath
[MAX_PATH
] = {0};
48 if (GetModuleFileName(NULL
, szAppPath
, ARRAYSIZE(szAppPath
)) == 0) {
49 hr
= HRESULT_FROM_WIN32(GetLastError());
52 hr
= psl
->SetPath(szAppPath
);
56 hr
= psl
->SetArguments(pszArguments
);
60 hr
= psl
->SetIconLocation(szAppPath
, iconIndex
);
64 ATL::CComPtr
<IPropertyStore
> pps
;
65 hr
= psl
.QueryInterface(&pps
);
70 hr
= InitPropVariantFromString(pszTitle
, &propvar
);
73 hr
= pps
->SetValue(PKEY_Title
, propvar
);
77 hr
= psl
.QueryInterface(ppsl
);
80 PropVariantClear(&propvar
);
85 HRESULT
CreateSeparatorLink(IShellLink
**ppsl
)
87 ATL::CComPtr
<IPropertyStore
> pps
;
88 HRESULT hr
= pps
.CoCreateInstance(CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
);
93 hr
= InitPropVariantFromBoolean(TRUE
, &propvar
);
97 hr
= pps
->SetValue(PKEY_AppUserModel_IsDestListSeparator
, propvar
);
102 hr
= pps
.QueryInterface(ppsl
);
105 PropVariantClear(&propvar
);
109 bool IsItemInArray(IShellItem
*psi
, IObjectArray
*poaRemoved
)
113 if (FAILED(poaRemoved
->GetCount(&cItems
)))
117 for (UINT i
= 0; !fRet
&& i
< cItems
; i
++) {
118 ATL::CComPtr
<IShellItem
> psiCompare
;
119 if (FAILED(poaRemoved
->GetAt(i
, IID_PPV_ARGS(&psiCompare
))))
122 fRet
= SUCCEEDED(psiCompare
->Compare(psi
, SICHINT_CANONICAL
, &iOrder
)) && (0 == iOrder
);
127 void DeleteJumpList(LPCTSTR appID
)
129 ATL::CComPtr
<ICustomDestinationList
> pcdl
;
130 HRESULT hr
= pcdl
.CoCreateInstance(CLSID_DestinationList
, NULL
, CLSCTX_INPROC_SERVER
);
132 pcdl
->DeleteList(appID
);