1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2006, 2009, 2011-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.
21 #include "ItemIDList.h"
24 ItemIDList::ItemIDList(PCUITEMID_CHILD item
, PCUIDLIST_RELATIVE parent
)
31 ItemIDList::ItemIDList(PCIDLIST_ABSOLUTE item
)
32 : item_((PCUITEMID_CHILD
)item
)
38 ItemIDList::~ItemIDList()
42 int ItemIDList::size() const
49 LPCSHITEMID ptr
= &item_
->mkid
;
50 while (ptr
!= 0 && ptr
->cb
!= 0)
53 LPBYTE byte
= (LPBYTE
) ptr
;
55 ptr
= (LPCSHITEMID
) byte
;
62 LPCSHITEMID
ItemIDList::get(int index
) const
68 LPCSHITEMID ptr
= &item_
->mkid
;
77 LPBYTE byte
= (LPBYTE
) ptr
;
79 ptr
= (LPCSHITEMID
) byte
;
85 tstring
ItemIDList::toString(bool resolveLibraries
/*= true*/)
87 CComPtr
<IShellFolder
> shellFolder
;
88 CComPtr
<IShellFolder
> parentFolder
;
91 HRESULT hr
= ::SHGetDesktopFolder(&shellFolder
);
96 hr
= shellFolder
->BindToObject(parent_
, 0, IID_IShellFolder
, (void**) &parentFolder
);
98 parentFolder
= shellFolder
;
102 parentFolder
= shellFolder
;
106 TCHAR
* szDisplayName
= NULL
;
107 if ((parentFolder
!= 0)&&(item_
!= 0))
109 hr
= parentFolder
->GetDisplayNameOf(item_
, SHGDN_NORMAL
| SHGDN_FORPARSING
, &name
);
112 hr
= StrRetToStr (&name
, item_
, &szDisplayName
);
116 if (szDisplayName
== NULL
)
121 CoTaskMemFree(szDisplayName
);
122 if ((resolveLibraries
) &&
123 (_tcsncmp(ret
.c_str(), _T("::{"), 3)==0))
125 CComPtr
<IShellLibrary
> plib
;
126 HRESULT hr
= CoCreateInstance(CLSID_ShellLibrary
,
128 CLSCTX_INPROC_SERVER
,
129 IID_PPV_ARGS(&plib
));
132 typedef HRESULT STDAPICALLTYPE
SHCreateItemFromParsingNameFN(__in PCWSTR pszPath
, __in_opt IBindCtx
*pbc
, __in REFIID riid
, __deref_out
void **ppv
);
133 CAutoLibrary hShell
= AtlLoadSystemLibraryUsingFullPath(_T("shell32.dll"));
136 SHCreateItemFromParsingNameFN
*pfnSHCreateItemFromParsingName
= (SHCreateItemFromParsingNameFN
*)GetProcAddress(hShell
, "SHCreateItemFromParsingName");
137 if (pfnSHCreateItemFromParsingName
)
139 CComPtr
<IShellItem
> psiLibrary
;
140 hr
= pfnSHCreateItemFromParsingName(ret
.c_str(), NULL
, IID_PPV_ARGS(&psiLibrary
));
143 hr
= plib
->LoadLibraryFromItem(psiLibrary
, STGM_READ
|STGM_SHARE_DENY_NONE
);
146 CComPtr
<IShellItem
> psiSaveLocation
;
147 hr
= plib
->GetDefaultSaveFolder(DSFT_DETECT
, IID_PPV_ARGS(&psiSaveLocation
));
150 PWSTR pszName
= NULL
;
151 hr
= psiSaveLocation
->GetDisplayName(SIGDN_FILESYSPATH
, &pszName
);
155 CoTaskMemFree(pszName
);
167 PCUITEMID_CHILD
ItemIDList::operator& ()