1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2016 - TortoiseGit
4 // Copyright (C) 2003-2006, 2009, 2011-2013, 2015-2016 - 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.
22 #include "ItemIDList.h"
25 ItemIDList::ItemIDList(PCUITEMID_CHILD item
, PCUIDLIST_RELATIVE parent
)
32 ItemIDList::ItemIDList(PCIDLIST_ABSOLUTE item
)
33 : item_((PCUITEMID_CHILD
)item
)
39 ItemIDList::~ItemIDList()
43 int ItemIDList::size() const
50 LPCSHITEMID ptr
= &item_
->mkid
;
51 while (ptr
&& ptr
->cb
!= 0)
54 LPBYTE byte
= (LPBYTE
) ptr
;
56 ptr
= (LPCSHITEMID
) byte
;
63 LPCSHITEMID
ItemIDList::get(int index
) const
69 LPCSHITEMID ptr
= &item_
->mkid
;
78 LPBYTE byte
= (LPBYTE
) ptr
;
80 ptr
= (LPCSHITEMID
) byte
;
85 tstring
ItemIDList::toString(bool resolveLibraries
/*= true*/)
87 CComPtr
<IShellFolder
> shellFolder
;
88 CComPtr
<IShellFolder
> parentFolder
;
91 if (FAILED(::SHGetDesktopFolder(&shellFolder
)))
93 if (!parent_
|| FAILED(shellFolder
->BindToObject(parent_
, 0, IID_IShellFolder
, (void**)&parentFolder
)))
94 parentFolder
= shellFolder
;
97 TCHAR
* szDisplayName
= nullptr;
98 if (parentFolder
&& item_
!= 0)
100 if (FAILED(parentFolder
->GetDisplayNameOf(item_
, SHGDN_NORMAL
| SHGDN_FORPARSING
, &name
)))
102 if (FAILED(StrRetToStr(&name
, item_
, &szDisplayName
)))
108 CoTaskMemFree(szDisplayName
);
110 if (!((resolveLibraries
) && (_tcsncmp(ret
.c_str(), _T("::{"), 3) == 0)))
113 CComPtr
<IShellLibrary
> plib
;
114 if (FAILED(plib
.CoCreateInstance(CLSID_ShellLibrary
, nullptr, CLSCTX_INPROC_SERVER
)))
117 CComPtr
<IShellItem
> psiLibrary
;
118 if (FAILED(SHCreateItemFromParsingName(ret
.c_str(), nullptr, IID_PPV_ARGS(&psiLibrary
))))
121 if (FAILED(plib
->LoadLibraryFromItem(psiLibrary
, STGM_READ
| STGM_SHARE_DENY_NONE
)))
124 CComPtr
<IShellItem
> psiSaveLocation
;
125 if (FAILED(plib
->GetDefaultSaveFolder(DSFT_DETECT
, IID_PPV_ARGS(&psiSaveLocation
))))
128 PWSTR pszName
= nullptr;
129 if (SUCCEEDED(psiSaveLocation
->GetDisplayName(SIGDN_FILESYSPATH
, &pszName
)))
132 CoTaskMemFree(pszName
);
138 PCUITEMID_CHILD
ItemIDList::operator& ()