ReactOS 0.4.16-dev-319-g6cf4263
aclistisf.cpp
Go to the documentation of this file.
1/*
2 * Shell AutoComplete list
3 *
4 * Copyright 2015 Thomas Faber
5 * Copyright 2020-2021 Katayama Hirofumi MZ
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22#include "precomp.h"
23
25 : m_dwOptions(ACLO_CURRENTDIR | ACLO_MYCOMPUTER)
26 , m_iNextLocation(LT_DIRECTORY)
27 , m_fShowHidden(FALSE)
28{
29}
30
32{
33}
34
36{
37 TRACE("(%p)\n", this);
38 HRESULT hr;
39 switch (m_iNextLocation)
40 {
41 case LT_DIRECTORY:
44 {
46 hr = SetLocation(pidl.Detach());
47 if (SUCCEEDED(hr))
48 {
49 TRACE("LT_DIRECTORY\n");
50 return hr;
51 }
52 }
53 // FALL THROUGH
54 case LT_DESKTOP:
57 {
61 return S_FALSE;
62 hr = SetLocation(pidl.Detach());
63 if (SUCCEEDED(hr))
64 {
65 TRACE("LT_DESKTOP\n");
66 return hr;
67 }
68 }
69 // FALL THROUGH
70 case LT_MYCOMPUTER:
73 {
77 return S_FALSE;
78 hr = SetLocation(pidl.Detach());
79 if (SUCCEEDED(hr))
80 {
81 TRACE("LT_MYCOMPUTER\n");
82 return hr;
83 }
84 }
85 // FALL THROUGH
86 case LT_FAVORITES:
89 {
93 return S_FALSE;
94 hr = SetLocation(pidl.Detach());
95 if (SUCCEEDED(hr))
96 {
97 TRACE("LT_FAVORITES\n");
98 return hr;
99 }
100 }
101 // FALL THROUGH
102 case LT_MAX:
103 default:
104 TRACE("LT_MAX\n");
105 return S_FALSE;
106 }
107}
108
110{
111 TRACE("(%p, %p)\n", this, pidl);
112
113 m_pEnumIDList.Release();
115 m_pidlLocation.Free();
116
117 if (!pidl)
118 return E_FAIL;
119
120 m_pidlLocation.Attach(pidl);
121
122 CComPtr<IShellFolder> pFolder;
123 HRESULT hr = SHGetDesktopFolder(&pFolder);
125 return hr;
126
127 if (!ILIsEmpty(pidl))
128 {
129 hr = pFolder->BindToObject(pidl, NULL, IID_PPV_ARG(IShellFolder, &m_pShellFolder));
131 return hr;
132 }
133 else
134 {
135 m_pShellFolder.Attach(pFolder.Detach());
136 }
137
138 SHCONTF Flags = SHCONTF_FOLDERS | SHCONTF_INIT_ON_FIRST_NEXT;
139 if (m_fShowHidden)
140 Flags |= SHCONTF_INCLUDEHIDDEN;
142 Flags |= SHCONTF_NONFOLDERS;
143
144 hr = m_pShellFolder->EnumObjects(NULL, Flags, &m_pEnumIDList);
145 if (hr != S_OK)
146 {
147 ERR("EnumObjects failed: 0x%lX\n", hr);
148 hr = E_FAIL;
149 }
150 return hr;
151}
152
154{
155 TRACE("(%p, %p)\n", this, pidlChild);
156 pszChild.Free();
157
159 DWORD dwFlags = SHGDN_INFOLDER | SHGDN_FORPARSING | SHGDN_FORADDRESSBAR;
160 HRESULT hr = m_pShellFolder->GetDisplayNameOf(pidlChild, dwFlags, &StrRet);
161 if (FAILED(hr))
162 {
163 dwFlags = SHGDN_INFOLDER | SHGDN_FORPARSING;
164 hr = m_pShellFolder->GetDisplayNameOf(pidlChild, dwFlags, &StrRet);
166 return hr;
167 }
168
169 hr = StrRetToStrW(&StrRet, NULL, &pszChild);
171 return hr;
172
173 TRACE("pszChild: '%S'\n", static_cast<LPCWSTR>(pszChild));
174 return hr;
175}
176
179 CComHeapPtr<WCHAR>& pszExpanded)
180{
181 TRACE("(%p, %p)\n", this, pidlChild);
182
183 CComHeapPtr<WCHAR> pszChild;
184 HRESULT hr = GetDisplayName(pidlChild, pszChild);
186 return hr;
187
188 CStringW szRawPath, szExpanded;
190 {
191 INT cchExpand = m_szRawPath.GetLength();
192 if (StrCmpNIW(pszChild, m_szRawPath, cchExpand) != 0 ||
193 pszChild[0] != L'\\' || pszChild[1] != L'\\')
194 {
195 szRawPath = m_szRawPath;
196 szExpanded = m_szExpanded;
197 }
198 }
199 szRawPath += pszChild;
200 szExpanded += pszChild;
201
202 SHStrDupW(szRawPath, &pszRaw);
203 SHStrDupW(szExpanded, &pszExpanded);
204 TRACE("pszRaw: '%S'\n", static_cast<LPCWSTR>(pszRaw));
205 TRACE("pszExpanded: '%S'\n", static_cast<LPCWSTR>(pszExpanded));
206 return S_OK;
207}
208
209// *** IEnumString methods ***
211{
212 TRACE("(%p, %d, %p, %p)\n", this, celt, rgelt, pceltFetched);
213
214 if (celt == 0)
215 return S_OK;
216 if (!rgelt)
217 return S_FALSE;
218
219 *rgelt = NULL;
220 if (pceltFetched)
221 *pceltFetched = 0;
222
223 if (!m_pEnumIDList)
224 {
225 NextLocation();
226 if (!m_pEnumIDList)
227 return S_FALSE;
228 }
229
230 HRESULT hr;
231 CComHeapPtr<ITEMIDLIST> pidlChild;
232 CComHeapPtr<WCHAR> pszRawPath, pszExpanded;
233
234 do
235 {
236 for (;;)
237 {
238 pidlChild.Free();
239 hr = m_pEnumIDList->Next(1, &pidlChild, NULL);
240 if (hr != S_OK)
241 break;
242
243 pszRawPath.Free();
244 pszExpanded.Free();
245 GetPaths(pidlChild, pszRawPath, pszExpanded);
246 if (!pszRawPath || !pszExpanded)
247 continue;
248
249 DWORD attrs = SFGAO_FOLDER | SFGAO_FILESYSTEM;
250 LPCITEMIDLIST pidlRef = pidlChild;
251 hr = m_pShellFolder->GetAttributesOf(1, &pidlRef, &attrs);
253 continue;
254
255 if ((m_dwOptions & ACLO_FILESYSDIRS) && !(attrs & SFGAO_FOLDER))
256 continue;
257 if ((m_dwOptions & (ACLO_FILESYSONLY | ACLO_FILESYSDIRS)) && !(attrs & SFGAO_FILESYSTEM))
258 continue;
259
260 hr = S_OK;
261 break;
262 }
263 } while (hr == S_FALSE && NextLocation() == S_OK);
264
265 if (hr == S_OK)
266 {
267 *rgelt = pszRawPath.Detach();
268 if (pceltFetched)
269 *pceltFetched = 1;
270 }
271 else
272 {
273 hr = S_FALSE;
274 }
275
276 TRACE("*rgelt: %S\n", *rgelt);
277 return hr;
278}
279
281{
282 TRACE("(%p)\n", this);
283
285 m_szRawPath = L"";
286
287 SHELLSTATE ss = { 0 };
289 m_fShowHidden = ss.fShowAllObjects;
290
292 {
295 {
296 m_pBrowserService->GetPidl(&pidl);
297 if (pidl)
298 Initialize(pidl);
299 }
300 HRESULT hr = SetLocation(pidl.Detach());
302 return S_FALSE;
303 }
304 return S_OK;
305}
306
308{
309 TRACE("(%p, %d)\n", this, celt);
310 return E_NOTIMPL;
311}
312
314{
315 TRACE("(%p, %p)\n", this, ppOut);
316 *ppOut = NULL;
317 return E_NOTIMPL;
318}
319
320// *** IACList methods ***
322{
323 TRACE("(%p, %ls)\n", this, pszExpand);
324
325 m_szRawPath = pszExpand;
327
328 // skip left space
329 while (*pszExpand == L' ')
330 ++pszExpand;
331
332 // expand environment variables (%WINDIR% etc.)
333 WCHAR szExpanded[MAX_PATH], szPath1[MAX_PATH], szPath2[MAX_PATH];
334 ExpandEnvironmentStringsW(pszExpand, szExpanded, _countof(szExpanded));
335 pszExpand = szExpanded;
336
337 // get full path
338 if (szExpanded[0] && szExpanded[1] == L':' && szExpanded[2] == 0)
339 {
340 // 'C:' --> 'C:\'
341 szExpanded[2] = L'\\';
342 szExpanded[3] = 0;
343 }
344 else
345 {
346 if (PathIsRelativeW(pszExpand) &&
348 PathCombineW(szPath2, szPath1, pszExpand) &&
349 PathFileExistsW(szPath2))
350 {
351 pszExpand = szPath2;
352 }
353 else if (PathFileExistsW(pszExpand))
354 {
355 GetFullPathNameW(pszExpand, _countof(szPath1), szPath1, NULL);
356 pszExpand = szPath1;
357 }
358 }
359
361 m_szExpanded = pszExpand;
363 if (SUCCEEDED(hr))
364 {
365 hr = SetLocation(pidl.Detach());
367 {
368 m_szRawPath = L"";
369 m_szExpanded = L"";
370 }
371 }
372 return hr;
373}
374
375// *** IACList2 methods ***
377{
378 TRACE("(%p, %lu)\n", this, dwFlag);
379 m_dwOptions = dwFlag;
380 return S_OK;
381}
382
384{
385 TRACE("(%p, %p)\n", this, pdwFlag);
386 if (pdwFlag)
387 {
388 *pdwFlag = m_dwOptions;
389 return S_OK;
390 }
391 return E_INVALIDARG;
392}
393
394// *** IShellService methods ***
396{
397 TRACE("(%p, %p)\n", this, punkOwner);
398 m_pBrowserService.Release();
400 return S_OK;
401}
402
403// *** IPersist methods ***
405{
406 TRACE("(%p, %p)\n", this, pClassID);
407 if (pClassID == NULL)
408 return E_POINTER;
409 *pClassID = CLSID_ACListISF;
410 return S_OK;
411}
412
413// *** IPersistFolder methods ***
415{
416 TRACE("(%p, %p)\n", this, pidl);
417 m_pidlCurDir.Free();
418 if (!pidl)
419 return S_OK;
420
421 LPITEMIDLIST pidlClone = ILClone(pidl);
422 if (!pidlClone)
423 {
424 ERR("Out of memory\n");
425 return E_OUTOFMEMORY;
426 }
427 m_pidlCurDir.Attach(pidlClone);
428 return S_OK;
429}
430
431// *** ICurrentWorkingDirectory methods ***
433{
434 TRACE("(%p, %p, %ld)\n", this, pwzPath, cchSize);
435 return E_NOTIMPL;
436}
437
439{
440 TRACE("(%p, %ls, %ld)\n", this, pwzPath);
441 LPITEMIDLIST pidl = ILCreateFromPathW(pwzPath);
442 if (!pidl)
443 {
444 ERR("Out of memory\n");
445 return E_OUTOFMEMORY;
446 }
447 m_pidlCurDir.Attach(pidl);
448 return S_OK;
449}
HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
#define ERR(fmt,...)
Definition: precomp.h:57
#define STDMETHODIMP
Definition: basetyps.h:43
void Release()
Definition: atlcomcli.h:170
void Attach(T *lp)
Definition: atlcomcli.h:179
T * Detach()
Definition: atlcomcli.h:186
int GetLength() const noexcept
Definition: atlsimpstr.h:362
CStringW m_szExpanded
Definition: aclistisf.h:47
CComPtr< IEnumIDList > m_pEnumIDList
Definition: aclistisf.h:50
STDMETHOD() Reset() override
Definition: aclistisf.cpp:280
STDMETHOD() GetDirectory(LPWSTR pwzPath, DWORD cchSize) override
Definition: aclistisf.cpp:432
CComPtr< IShellFolder > m_pShellFolder
Definition: aclistisf.h:51
BOOL m_fShowHidden
Definition: aclistisf.h:45
@ LT_DIRECTORY
Definition: aclistisf.h:36
@ LT_FAVORITES
Definition: aclistisf.h:39
@ LT_MYCOMPUTER
Definition: aclistisf.h:38
@ LT_DESKTOP
Definition: aclistisf.h:37
HRESULT SetLocation(LPITEMIDLIST pidl)
Definition: aclistisf.cpp:109
STDMETHOD() GetOptions(DWORD *pdwFlag) override
Definition: aclistisf.cpp:383
STDMETHOD() Skip(ULONG celt) override
Definition: aclistisf.cpp:307
STDMETHOD() GetClassID(CLSID *pClassID) override
Definition: aclistisf.cpp:404
CComHeapPtr< ITEMIDLIST > m_pidlCurDir
Definition: aclistisf.h:49
STDMETHOD() Expand(LPCOLESTR pszExpand) override
Definition: aclistisf.cpp:321
LOCATION_TYPE m_iNextLocation
Definition: aclistisf.h:44
CComPtr< IBrowserService > m_pBrowserService
Definition: aclistisf.h:52
STDMETHOD() SetDirectory(LPCWSTR pwzPath) override
Definition: aclistisf.cpp:438
CStringW m_szRawPath
Definition: aclistisf.h:46
STDMETHOD() SetOwner(IUnknown *punkOwner) override
Definition: aclistisf.cpp:395
STDMETHOD() Next(ULONG celt, LPOLESTR *rgelt, ULONG *pceltFetched) override
Definition: aclistisf.cpp:210
STDMETHOD() Clone(IEnumString **ppenum) override
Definition: aclistisf.cpp:313
HRESULT GetPaths(LPCITEMIDLIST pidlChild, CComHeapPtr< WCHAR > &pszRaw, CComHeapPtr< WCHAR > &pszExpanded)
Definition: aclistisf.cpp:178
HRESULT NextLocation()
Definition: aclistisf.cpp:35
DWORD m_dwOptions
Definition: aclistisf.h:43
HRESULT GetDisplayName(LPCITEMIDLIST pidlChild, CComHeapPtr< WCHAR > &pszChild)
Definition: aclistisf.cpp:153
CComHeapPtr< ITEMIDLIST > m_pidlLocation
Definition: aclistisf.h:48
STDMETHOD() Initialize(PCIDLIST_ABSOLUTE pidl) override
Definition: aclistisf.cpp:414
STDMETHOD() SetOptions(DWORD dwFlag) override
Definition: aclistisf.cpp:376
void Free()
Definition: atlalloc.h:153
T * Detach()
Definition: atlalloc.h:168
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_NOTIMPL
Definition: ddrawi.h:99
#define E_FAIL
Definition: ddrawi.h:102
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
INT WINAPI StrCmpNIW(LPCWSTR lpszStr, LPCWSTR lpszComp, INT iLen)
Definition: string.c:307
#define MAX_PATH
Definition: compat.h:34
#define FAILED_UNEXPECTEDLY(hr)
Definition: precomp.h:121
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
DWORD WINAPI GetFullPathNameW(IN LPCWSTR lpFileName, IN DWORD nBufferLength, OUT LPWSTR lpBuffer, OUT LPWSTR *lpFilePart)
Definition: path.c:1106
HRESULT WINAPI SHGetSpecialFolderLocation(HWND hwndOwner, INT nFolder, LPITEMIDLIST *ppidl)
Definition: shellpath.c:3257
BOOL WINAPI PathFileExistsW(LPCWSTR lpszPath)
Definition: path.c:1777
BOOL WINAPI PathIsRelativeW(LPCWSTR lpszPath)
Definition: path.c:1579
HRESULT WINAPI SHStrDupW(LPCWSTR src, LPWSTR *dest)
Definition: string.c:2018
HRESULT WINAPI StrRetToStrW(LPSTRRET lpStrRet, const ITEMIDLIST *pidl, LPWSTR *ppszName)
Definition: string.c:1631
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ss
Definition: i386-dis.c:441
HRESULT QueryInterface([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
static LPOLESTR
Definition: stg_prop.c:27
static SHCONTF
Definition: ordinal.c:64
#define L(x)
Definition: ntvdm.h:50
#define PathCombineW
Definition: pathcch.h:317
LPITEMIDLIST WINAPI ILClone(LPCITEMIDLIST pidl)
Definition: pidl.c:237
HRESULT WINAPI SHParseDisplayName(LPCWSTR pszName, IBindCtx *pbc, LPITEMIDLIST *ppidl, SFGAOF sfgaoIn, SFGAOF *psfgaoOut)
Definition: pidl.c:1504
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
Definition: pidl.c:1452
LPITEMIDLIST WINAPI ILCreateFromPathW(LPCWSTR path)
Definition: pidl.c:1099
#define StrRet
Definition: shellclasses.h:871
VOID WINAPI SHGetSetSettings(LPSHELLSTATE lpss, DWORD dwMask, BOOL bSet)
Definition: shellord.c:225
HRESULT hr
Definition: shlfolder.c:183
#define ACLO_MYCOMPUTER
Definition: shlobj.h:814
#define CSIDL_FAVORITES
Definition: shlobj.h:2179
#define ACLO_DESKTOP
Definition: shlobj.h:815
#define ACLO_FILESYSDIRS
Definition: shlobj.h:818
#define CSIDL_DESKTOP
Definition: shlobj.h:2173
static BOOL ILIsEmpty(_In_opt_ PCUIDLIST_RELATIVE pidl)
Definition: shlobj.h:2519
#define CSIDL_DRIVES
Definition: shlobj.h:2189
#define ACLO_FAVORITES
Definition: shlobj.h:816
#define SSF_SHOWALLOBJECTS
Definition: shlobj.h:1605
#define ACLO_FILESYSONLY
Definition: shlobj.h:817
#define ACLO_CURRENTDIR
Definition: shlobj.h:813
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
#define _countof(array)
Definition: sndvol32.h:70
#define TRACE(s)
Definition: solgame.cpp:4
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG
Definition: typedefs.h:59
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176
#define S_FALSE
Definition: winerror.h:2357
#define E_POINTER
Definition: winerror.h:2365
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
static void Initialize()
Definition: xlate.c:212
#define IID_PPV_ARG(Itype, ppType)
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185