1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2016, 2019, 2023 - 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"
23 #include "StringUtils.h"
25 ItemIDList::ItemIDList(PCUITEMID_CHILD item
, PCUIDLIST_RELATIVE parent
)
31 ItemIDList::ItemIDList(PCIDLIST_ABSOLUTE item
)
32 : item_(static_cast<PCUITEMID_CHILD
>(item
))
36 ItemIDList::~ItemIDList()
40 int ItemIDList::size() const
47 LPCSHITEMID ptr
= &item_
->mkid
;
48 while (ptr
&& ptr
->cb
!= 0)
51 LPCBYTE byte
= reinterpret_cast<LPCBYTE
>(ptr
);
53 ptr
= reinterpret_cast<LPCSHITEMID
>(byte
);
60 LPCSHITEMID
ItemIDList::get(int index
) const
66 LPCSHITEMID ptr
= &item_
->mkid
;
75 LPCBYTE byte
= reinterpret_cast<LPCBYTE
>(ptr
);
77 ptr
= reinterpret_cast<LPCSHITEMID
>(byte
);
82 std::wstring
ItemIDList::toString(bool resolveLibraries
/*= true*/)
84 CComPtr
<IShellFolder
> shellFolder
;
85 CComPtr
<IShellFolder
> parentFolder
;
88 if (FAILED(::SHGetDesktopFolder(&shellFolder
)))
90 if (!parent_
|| FAILED(shellFolder
->BindToObject(parent_
, 0, IID_IShellFolder
, reinterpret_cast<void**>(&parentFolder
))))
91 parentFolder
= shellFolder
;
93 if (parentFolder
&& item_
!= 0)
96 if (FAILED(parentFolder
->GetDisplayNameOf(item_
, SHGDN_NORMAL
| SHGDN_FORPARSING
, &name
)))
98 CComHeapPtr
<wchar_t> szDisplayName
;
99 if (FAILED(StrRetToStr(&name
, item_
, &szDisplayName
)) || !szDisplayName
)
106 if (!((resolveLibraries
) && (CStringUtils::StartsWith(ret
.c_str(), L
"::{"))))
109 CComPtr
<IShellLibrary
> plib
;
110 if (FAILED(plib
.CoCreateInstance(CLSID_ShellLibrary
, nullptr, CLSCTX_INPROC_SERVER
)))
113 CComPtr
<IShellItem
> psiLibrary
;
114 if (FAILED(SHCreateItemFromParsingName(ret
.c_str(), nullptr, IID_PPV_ARGS(&psiLibrary
))))
117 if (FAILED(plib
->LoadLibraryFromItem(psiLibrary
, STGM_READ
| STGM_SHARE_DENY_NONE
)))
120 CComPtr
<IShellItem
> psiSaveLocation
;
121 if (FAILED(plib
->GetDefaultSaveFolder(DSFT_DETECT
, IID_PPV_ARGS(&psiSaveLocation
))))
124 if (CComHeapPtr
<WCHAR
> pszName
; SUCCEEDED(psiSaveLocation
->GetDisplayName(SIGDN_FILESYSPATH
, &pszName
)))
125 return std::wstring(pszName
);
130 PCUITEMID_CHILD
ItemIDList::operator& ()