1c2c66affSColin Finck /*
2c2c66affSColin Finck * Shell Folder stuff
3c2c66affSColin Finck *
4c2c66affSColin Finck * Copyright 1997 Marcus Meissner
5c2c66affSColin Finck * Copyright 1998, 1999, 2002 Juergen Schmied
655469633SKatayama Hirofumi MZ * Copyright 2018 Katayama Hirofumi MZ
7c2c66affSColin Finck *
8c2c66affSColin Finck * IShellFolder2 and related interfaces
9c2c66affSColin Finck *
10c2c66affSColin Finck * This library is free software; you can redistribute it and/or
11c2c66affSColin Finck * modify it under the terms of the GNU Lesser General Public
12c2c66affSColin Finck * License as published by the Free Software Foundation; either
13c2c66affSColin Finck * version 2.1 of the License, or (at your option) any later version.
14c2c66affSColin Finck *
15c2c66affSColin Finck * This library is distributed in the hope that it will be useful,
16c2c66affSColin Finck * but WITHOUT ANY WARRANTY; without even the implied warranty of
17c2c66affSColin Finck * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18c2c66affSColin Finck * Lesser General Public License for more details.
19c2c66affSColin Finck *
20c2c66affSColin Finck * You should have received a copy of the GNU Lesser General Public
21c2c66affSColin Finck * License along with this library; if not, write to the Free Software
22c2c66affSColin Finck * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23c2c66affSColin Finck */
24c2c66affSColin Finck
25c2c66affSColin Finck #include "precomp.h"
26c2c66affSColin Finck
27c2c66affSColin Finck WINE_DEFAULT_DEBUG_CHANNEL(shell);
28c2c66affSColin Finck
SHELL_GetDefaultFolderEnumSHCONTF()296ae11ba0SWhindmar Saksit SHCONTF SHELL_GetDefaultFolderEnumSHCONTF()
306ae11ba0SWhindmar Saksit {
316ae11ba0SWhindmar Saksit SHCONTF Flags = SHCONTF_FOLDERS | SHCONTF_NONFOLDERS;
326ae11ba0SWhindmar Saksit SHELLSTATE ss;
336ae11ba0SWhindmar Saksit SHGetSetSettings(&ss, SSF_SHOWALLOBJECTS | SSF_SHOWSUPERHIDDEN, FALSE);
346ae11ba0SWhindmar Saksit if (ss.fShowAllObjects)
356ae11ba0SWhindmar Saksit Flags |= SHCONTF_INCLUDEHIDDEN;
366ae11ba0SWhindmar Saksit if (ss.fShowSuperHidden)
376ae11ba0SWhindmar Saksit Flags |= SHCONTF_INCLUDESUPERHIDDEN;
386ae11ba0SWhindmar Saksit return Flags;
396ae11ba0SWhindmar Saksit }
406ae11ba0SWhindmar Saksit
SHELL_IncludeItemInFolderEnum(IShellFolder * pSF,PCUITEMID_CHILD pidl,SFGAOF Query,SHCONTF Flags)416ae11ba0SWhindmar Saksit BOOL SHELL_IncludeItemInFolderEnum(IShellFolder *pSF, PCUITEMID_CHILD pidl, SFGAOF Query, SHCONTF Flags)
426ae11ba0SWhindmar Saksit {
436ae11ba0SWhindmar Saksit if (SUCCEEDED(pSF->GetAttributesOf(1, &pidl, &Query)))
446ae11ba0SWhindmar Saksit {
456ae11ba0SWhindmar Saksit if (Query & SFGAO_NONENUMERATED)
466ae11ba0SWhindmar Saksit return FALSE;
476ae11ba0SWhindmar Saksit if ((Query & SFGAO_HIDDEN) && !(Flags & SHCONTF_INCLUDEHIDDEN))
486ae11ba0SWhindmar Saksit return FALSE;
496ae11ba0SWhindmar Saksit if ((Query & (SFGAO_HIDDEN | SFGAO_SYSTEM)) == (SFGAO_HIDDEN | SFGAO_SYSTEM) && !(Flags & SHCONTF_INCLUDESUPERHIDDEN))
506ae11ba0SWhindmar Saksit return FALSE;
516ae11ba0SWhindmar Saksit if ((Flags & (SHCONTF_FOLDERS | SHCONTF_NONFOLDERS)) != (SHCONTF_FOLDERS | SHCONTF_NONFOLDERS))
526ae11ba0SWhindmar Saksit return (Flags & SHCONTF_FOLDERS) ? (Query & SFGAO_FOLDER) : !(Query & SFGAO_FOLDER);
536ae11ba0SWhindmar Saksit }
546ae11ba0SWhindmar Saksit return TRUE;
556ae11ba0SWhindmar Saksit }
566ae11ba0SWhindmar Saksit
577fdec960SKatayama Hirofumi MZ HRESULT
Shell_NextElement(_Inout_ LPWSTR * ppch,_Out_ LPWSTR pszOut,_In_ INT cchOut,_In_ BOOL bValidate)587fdec960SKatayama Hirofumi MZ Shell_NextElement(
597fdec960SKatayama Hirofumi MZ _Inout_ LPWSTR *ppch,
607fdec960SKatayama Hirofumi MZ _Out_ LPWSTR pszOut,
617fdec960SKatayama Hirofumi MZ _In_ INT cchOut,
627fdec960SKatayama Hirofumi MZ _In_ BOOL bValidate)
63c2c66affSColin Finck {
647fdec960SKatayama Hirofumi MZ *pszOut = UNICODE_NULL;
65c2c66affSColin Finck
667fdec960SKatayama Hirofumi MZ if (!*ppch)
677fdec960SKatayama Hirofumi MZ return S_FALSE;
68c2c66affSColin Finck
697fdec960SKatayama Hirofumi MZ HRESULT hr;
707fdec960SKatayama Hirofumi MZ LPWSTR pchNext = wcschr(*ppch, L'\\');
717fdec960SKatayama Hirofumi MZ if (pchNext)
727fdec960SKatayama Hirofumi MZ {
737fdec960SKatayama Hirofumi MZ if (*ppch < pchNext)
747fdec960SKatayama Hirofumi MZ {
757fdec960SKatayama Hirofumi MZ /* Get an element */
767fdec960SKatayama Hirofumi MZ StringCchCopyNW(pszOut, cchOut, *ppch, pchNext - *ppch);
777fdec960SKatayama Hirofumi MZ ++pchNext;
78c2c66affSColin Finck
797fdec960SKatayama Hirofumi MZ if (!*pchNext)
807fdec960SKatayama Hirofumi MZ pchNext = NULL; /* No next */
81c2c66affSColin Finck
827fdec960SKatayama Hirofumi MZ hr = S_OK;
837fdec960SKatayama Hirofumi MZ }
847fdec960SKatayama Hirofumi MZ else /* Double backslashes found? */
857fdec960SKatayama Hirofumi MZ {
867fdec960SKatayama Hirofumi MZ pchNext = NULL;
877fdec960SKatayama Hirofumi MZ hr = E_INVALIDARG;
887fdec960SKatayama Hirofumi MZ }
897fdec960SKatayama Hirofumi MZ }
907fdec960SKatayama Hirofumi MZ else /* No more next */
917fdec960SKatayama Hirofumi MZ {
927fdec960SKatayama Hirofumi MZ StringCchCopyW(pszOut, cchOut, *ppch);
937fdec960SKatayama Hirofumi MZ hr = S_OK;
947fdec960SKatayama Hirofumi MZ }
95c2c66affSColin Finck
967fdec960SKatayama Hirofumi MZ *ppch = pchNext; /* Go next */
97c2c66affSColin Finck
987fdec960SKatayama Hirofumi MZ if (hr == S_OK && bValidate && !PathIsValidElement(pszOut))
997fdec960SKatayama Hirofumi MZ {
1007fdec960SKatayama Hirofumi MZ *pszOut = UNICODE_NULL;
1017fdec960SKatayama Hirofumi MZ hr = E_INVALIDARG;
1027fdec960SKatayama Hirofumi MZ }
103c2c66affSColin Finck
1047fdec960SKatayama Hirofumi MZ return hr;
105c2c66affSColin Finck }
106c2c66affSColin Finck
SHELL32_ParseNextElement(IShellFolder2 * psf,HWND hwndOwner,LPBC pbc,LPITEMIDLIST * pidlInOut,LPOLESTR szNext,DWORD * pEaten,DWORD * pdwAttributes)107c2c66affSColin Finck HRESULT SHELL32_ParseNextElement (IShellFolder2 * psf, HWND hwndOwner, LPBC pbc,
108c2c66affSColin Finck LPITEMIDLIST * pidlInOut, LPOLESTR szNext, DWORD * pEaten, DWORD * pdwAttributes)
109c2c66affSColin Finck {
110c2c66affSColin Finck HRESULT hr = E_INVALIDARG;
111c2c66affSColin Finck LPITEMIDLIST pidlIn = pidlInOut ? *pidlInOut : NULL;
112c2c66affSColin Finck LPITEMIDLIST pidlOut = NULL;
113c2c66affSColin Finck LPITEMIDLIST pidlTemp = NULL;
114c2c66affSColin Finck CComPtr<IShellFolder> psfChild;
115c2c66affSColin Finck
116c2c66affSColin Finck TRACE ("(%p, %p, %p, %s)\n", psf, pbc, pidlIn, debugstr_w (szNext));
117c2c66affSColin Finck
118c2c66affSColin Finck /* get the shellfolder for the child pidl and let it analyse further */
119c2c66affSColin Finck hr = psf->BindToObject(pidlIn, pbc, IID_PPV_ARG(IShellFolder, &psfChild));
120c2c66affSColin Finck if (FAILED(hr))
121c2c66affSColin Finck return hr;
122c2c66affSColin Finck
123c2c66affSColin Finck hr = psfChild->ParseDisplayName(hwndOwner, pbc, szNext, pEaten, &pidlOut, pdwAttributes);
124c2c66affSColin Finck if (FAILED(hr))
125c2c66affSColin Finck return hr;
126c2c66affSColin Finck
127c2c66affSColin Finck pidlTemp = ILCombine (pidlIn, pidlOut);
128c2c66affSColin Finck if (!pidlTemp)
129c2c66affSColin Finck {
130c2c66affSColin Finck hr = E_OUTOFMEMORY;
131c2c66affSColin Finck if (pidlOut)
132c2c66affSColin Finck ILFree(pidlOut);
133c2c66affSColin Finck return hr;
134c2c66affSColin Finck }
135c2c66affSColin Finck
136c2c66affSColin Finck if (pidlOut)
137c2c66affSColin Finck ILFree (pidlOut);
138c2c66affSColin Finck
139c2c66affSColin Finck if (pidlIn)
140c2c66affSColin Finck ILFree (pidlIn);
141c2c66affSColin Finck
142c2c66affSColin Finck *pidlInOut = pidlTemp;
143c2c66affSColin Finck
144c2c66affSColin Finck TRACE ("-- pidl=%p ret=0x%08x\n", pidlInOut ? *pidlInOut : NULL, hr);
145c2c66affSColin Finck return S_OK;
146c2c66affSColin Finck }
147c2c66affSColin Finck
148c2c66affSColin Finck /***********************************************************************
149c2c66affSColin Finck * SHELL32_CoCreateInitSF
150c2c66affSColin Finck *
151c2c66affSColin Finck * Creates a shell folder and initializes it with a pidl and a root folder
152c2c66affSColin Finck * via IPersistFolder3 or IPersistFolder.
153c2c66affSColin Finck *
154c2c66affSColin Finck * NOTES
155c2c66affSColin Finck * pathRoot can be NULL for Folders being a drive.
156c2c66affSColin Finck * In this case the absolute path is built from pidlChild (eg. C:)
157c2c66affSColin Finck */
SHELL32_CoCreateInitSF(LPCITEMIDLIST pidlRoot,PERSIST_FOLDER_TARGET_INFO * ppfti,LPCITEMIDLIST pidlChild,const GUID * clsid,REFIID riid,LPVOID * ppvOut)158c2c66affSColin Finck HRESULT SHELL32_CoCreateInitSF (LPCITEMIDLIST pidlRoot, PERSIST_FOLDER_TARGET_INFO* ppfti,
159c2c66affSColin Finck LPCITEMIDLIST pidlChild, const GUID* clsid, REFIID riid, LPVOID *ppvOut)
160c2c66affSColin Finck {
161c2c66affSColin Finck HRESULT hr;
162c2c66affSColin Finck CComPtr<IShellFolder> pShellFolder;
163c2c66affSColin Finck
164c2c66affSColin Finck hr = SHCoCreateInstance(NULL, clsid, NULL, IID_PPV_ARG(IShellFolder, &pShellFolder));
165c2c66affSColin Finck if (FAILED(hr))
166c2c66affSColin Finck return hr;
167c2c66affSColin Finck
168c2c66affSColin Finck LPITEMIDLIST pidlAbsolute = ILCombine (pidlRoot, pidlChild);
169c2c66affSColin Finck CComPtr<IPersistFolder> ppf;
170c2c66affSColin Finck CComPtr<IPersistFolder3> ppf3;
171c2c66affSColin Finck
172c2c66affSColin Finck if (ppfti && SUCCEEDED(pShellFolder->QueryInterface(IID_PPV_ARG(IPersistFolder3, &ppf3))))
173c2c66affSColin Finck {
174c2c66affSColin Finck ppf3->InitializeEx(NULL, pidlAbsolute, ppfti);
175c2c66affSColin Finck }
176c2c66affSColin Finck else if (SUCCEEDED(pShellFolder->QueryInterface(IID_PPV_ARG(IPersistFolder, &ppf))))
177c2c66affSColin Finck {
178c2c66affSColin Finck ppf->Initialize(pidlAbsolute);
179c2c66affSColin Finck }
180c2c66affSColin Finck ILFree (pidlAbsolute);
181c2c66affSColin Finck
182c2c66affSColin Finck return pShellFolder->QueryInterface(riid, ppvOut);
183c2c66affSColin Finck }
184c2c66affSColin Finck
SHELL32_CoCreateInitSF(LPCITEMIDLIST pidlRoot,const GUID * clsid,int csidl,REFIID riid,LPVOID * ppvOut)185c2c66affSColin Finck HRESULT SHELL32_CoCreateInitSF (LPCITEMIDLIST pidlRoot, const GUID* clsid,
186c2c66affSColin Finck int csidl, REFIID riid, LPVOID *ppvOut)
187c2c66affSColin Finck {
188c2c66affSColin Finck /* fill the PERSIST_FOLDER_TARGET_INFO */
189c2c66affSColin Finck PERSIST_FOLDER_TARGET_INFO pfti = {0};
190c2c66affSColin Finck pfti.dwAttributes = -1;
191c2c66affSColin Finck pfti.csidl = csidl;
192c2c66affSColin Finck
193c2c66affSColin Finck return SHELL32_CoCreateInitSF(pidlRoot, &pfti, NULL, clsid, riid, ppvOut);
194c2c66affSColin Finck }
195c2c66affSColin Finck
SHELL32_BindToSF(LPCITEMIDLIST pidlRoot,PERSIST_FOLDER_TARGET_INFO * ppfti,LPCITEMIDLIST pidl,const GUID * clsid,REFIID riid,LPVOID * ppvOut)196c2c66affSColin Finck HRESULT SHELL32_BindToSF (LPCITEMIDLIST pidlRoot, PERSIST_FOLDER_TARGET_INFO* ppfti,
197c2c66affSColin Finck LPCITEMIDLIST pidl, const GUID* clsid, REFIID riid, LPVOID *ppvOut)
198c2c66affSColin Finck {
199c2c66affSColin Finck PITEMID_CHILD pidlChild = ILCloneFirst (pidl);
200c2c66affSColin Finck if (!pidlChild)
201c2c66affSColin Finck return E_FAIL;
202c2c66affSColin Finck
203c2c66affSColin Finck CComPtr<IShellFolder> psf;
204c2c66affSColin Finck HRESULT hr = SHELL32_CoCreateInitSF(pidlRoot,
205c2c66affSColin Finck ppfti,
206c2c66affSColin Finck pidlChild,
207c2c66affSColin Finck clsid,
208c2c66affSColin Finck IID_PPV_ARG(IShellFolder, &psf));
209c2c66affSColin Finck ILFree(pidlChild);
210c2c66affSColin Finck
211c2c66affSColin Finck if (FAILED_UNEXPECTEDLY(hr))
212c2c66affSColin Finck return hr;
213c2c66affSColin Finck
214c2c66affSColin Finck if (_ILIsPidlSimple (pidl))
215c2c66affSColin Finck return psf->QueryInterface(riid, ppvOut);
216c2c66affSColin Finck else
217c2c66affSColin Finck return psf->BindToObject(ILGetNext (pidl), NULL, riid, ppvOut);
218c2c66affSColin Finck }
219c2c66affSColin Finck
220c2c66affSColin Finck /***********************************************************************
221c2c66affSColin Finck * SHELL32_GetDisplayNameOfChild
222c2c66affSColin Finck *
223c2c66affSColin Finck * Retrieves the display name of a child object of a shellfolder.
224c2c66affSColin Finck *
225c2c66affSColin Finck * For a pidl eg. [subpidl1][subpidl2][subpidl3]:
226c2c66affSColin Finck * - it binds to the child shellfolder [subpidl1]
227c2c66affSColin Finck * - asks it for the displayname of [subpidl2][subpidl3]
228c2c66affSColin Finck *
229c2c66affSColin Finck * Is possible the pidl is a simple pidl. In this case it asks the
230c2c66affSColin Finck * subfolder for the displayname of an empty pidl. The subfolder
231c2c66affSColin Finck * returns the own displayname eg. "::{guid}". This is used for
232c2c66affSColin Finck * virtual folders with the registry key WantsFORPARSING set.
233c2c66affSColin Finck */
SHELL32_GetDisplayNameOfChild(IShellFolder2 * psf,LPCITEMIDLIST pidl,DWORD dwFlags,LPSTRRET strRet)234c2c66affSColin Finck HRESULT SHELL32_GetDisplayNameOfChild (IShellFolder2 * psf,
235c2c66affSColin Finck LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
236c2c66affSColin Finck {
237c2c66affSColin Finck LPITEMIDLIST pidlFirst = ILCloneFirst(pidl);
238c2c66affSColin Finck if (!pidlFirst)
239c2c66affSColin Finck return E_OUTOFMEMORY;
240c2c66affSColin Finck
241c2c66affSColin Finck CComPtr<IShellFolder> psfChild;
242c2c66affSColin Finck HRESULT hr = psf->BindToObject(pidlFirst, NULL, IID_PPV_ARG(IShellFolder, &psfChild));
243c2c66affSColin Finck if (SUCCEEDED (hr))
244c2c66affSColin Finck {
245c2c66affSColin Finck hr = psfChild->GetDisplayNameOf(ILGetNext (pidl), dwFlags, strRet);
246c2c66affSColin Finck }
247c2c66affSColin Finck ILFree (pidlFirst);
248c2c66affSColin Finck
249c2c66affSColin Finck return hr;
250c2c66affSColin Finck }
251c2c66affSColin Finck
SHELL32_CompareChildren(IShellFolder2 * psf,LPARAM lParam,LPCITEMIDLIST pidl1,LPCITEMIDLIST pidl2)252c2c66affSColin Finck HRESULT SHELL32_CompareChildren(IShellFolder2* psf, LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
253c2c66affSColin Finck {
254c2c66affSColin Finck PUIDLIST_RELATIVE nextpidl1 = ILGetNext (pidl1);
255c2c66affSColin Finck PUIDLIST_RELATIVE nextpidl2 = ILGetNext (pidl2);
256c2c66affSColin Finck
257c2c66affSColin Finck bool isEmpty1 = _ILIsDesktop(nextpidl1);
258c2c66affSColin Finck bool isEmpty2 = _ILIsDesktop(nextpidl2);
259c2c66affSColin Finck if (isEmpty1 || isEmpty2)
260c2c66affSColin Finck return MAKE_COMPARE_HRESULT(isEmpty2 - isEmpty1);
261c2c66affSColin Finck
262c2c66affSColin Finck PITEMID_CHILD firstpidl = ILCloneFirst (pidl1);
263c2c66affSColin Finck if (!firstpidl)
264c2c66affSColin Finck return E_OUTOFMEMORY;
265c2c66affSColin Finck
266c2c66affSColin Finck CComPtr<IShellFolder> psf2;
267c2c66affSColin Finck HRESULT hr = psf->BindToObject(firstpidl, 0, IID_PPV_ARG(IShellFolder, &psf2));
268c2c66affSColin Finck ILFree(firstpidl);
269c2c66affSColin Finck if (FAILED(hr))
270c2c66affSColin Finck return MAKE_COMPARE_HRESULT(0);
271c2c66affSColin Finck
272c2c66affSColin Finck return psf2->CompareIDs(lParam, nextpidl1, nextpidl2);
273c2c66affSColin Finck }
274c2c66affSColin Finck
SHELL32_CompareDetails(IShellFolder2 * isf,LPARAM lParam,LPCITEMIDLIST pidl1,LPCITEMIDLIST pidl2)275c2c66affSColin Finck HRESULT SHELL32_CompareDetails(IShellFolder2* isf, LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
276c2c66affSColin Finck {
277c2c66affSColin Finck SHELLDETAILS sd;
278c2c66affSColin Finck WCHAR wszItem1[MAX_PATH], wszItem2[MAX_PATH];
279c2c66affSColin Finck HRESULT hres;
28034066e47SWhindmar Saksit UINT col = LOWORD(lParam); // Column index without SHCIDS_* flags
281c2c66affSColin Finck
28234066e47SWhindmar Saksit hres = isf->GetDetailsOf(pidl1, col, &sd);
283c2c66affSColin Finck if (FAILED(hres))
284c2c66affSColin Finck return MAKE_COMPARE_HRESULT(1);
285c2c66affSColin Finck
286c2c66affSColin Finck hres = StrRetToBufW(&sd.str, pidl1, wszItem1, MAX_PATH);
287c2c66affSColin Finck if (FAILED(hres))
288c2c66affSColin Finck return MAKE_COMPARE_HRESULT(1);
289c2c66affSColin Finck
29034066e47SWhindmar Saksit hres = isf->GetDetailsOf(pidl2, col, &sd);
291c2c66affSColin Finck if (FAILED(hres))
292c2c66affSColin Finck return MAKE_COMPARE_HRESULT(1);
293c2c66affSColin Finck
294c2c66affSColin Finck hres = StrRetToBufW(&sd.str, pidl2, wszItem2, MAX_PATH);
295c2c66affSColin Finck if (FAILED(hres))
296c2c66affSColin Finck return MAKE_COMPARE_HRESULT(1);
297c2c66affSColin Finck
298e4930be4STimo Kreuzer int ret = _wcsicmp(wszItem1, wszItem2);
299c2c66affSColin Finck if (ret == 0)
300c2c66affSColin Finck return SHELL32_CompareChildren(isf, lParam, pidl1, pidl2);
301c2c66affSColin Finck
302c2c66affSColin Finck return MAKE_COMPARE_HRESULT(ret);
303c2c66affSColin Finck }
304c2c66affSColin Finck
CloseRegKeyArray(HKEY * array,UINT cKeys)305*2aadf2ebSWhindmar Saksit void CloseRegKeyArray(HKEY* array, UINT cKeys)
306*2aadf2ebSWhindmar Saksit {
307*2aadf2ebSWhindmar Saksit for (UINT i = 0; i < cKeys; ++i)
308*2aadf2ebSWhindmar Saksit RegCloseKey(array[i]);
309*2aadf2ebSWhindmar Saksit }
310*2aadf2ebSWhindmar Saksit
AddClassKeyToArray(const WCHAR * szClass,HKEY * array,UINT * cKeys)311a83e40f6SWhindmar Saksit LSTATUS AddClassKeyToArray(const WCHAR* szClass, HKEY* array, UINT* cKeys)
312c2c66affSColin Finck {
313c2c66affSColin Finck if (*cKeys >= 16)
314a83e40f6SWhindmar Saksit return ERROR_MORE_DATA;
315c2c66affSColin Finck
316c2c66affSColin Finck HKEY hkey;
317c2c66affSColin Finck LSTATUS result = RegOpenKeyExW(HKEY_CLASSES_ROOT, szClass, 0, KEY_READ | KEY_QUERY_VALUE, &hkey);
318a83e40f6SWhindmar Saksit if (result == ERROR_SUCCESS)
319a83e40f6SWhindmar Saksit {
320c2c66affSColin Finck array[*cKeys] = hkey;
321c2c66affSColin Finck *cKeys += 1;
322c2c66affSColin Finck }
323a83e40f6SWhindmar Saksit return result;
324a83e40f6SWhindmar Saksit }
325c2c66affSColin Finck
AddClsidKeyToArray(REFCLSID clsid,HKEY * array,UINT * cKeys)32663935f85SWhindmar Saksit LSTATUS AddClsidKeyToArray(REFCLSID clsid, HKEY* array, UINT* cKeys)
32763935f85SWhindmar Saksit {
32863935f85SWhindmar Saksit WCHAR path[6 + 38 + 1] = L"CLSID\\";
32963935f85SWhindmar Saksit StringFromGUID2(clsid, path + 6, 38 + 1);
33063935f85SWhindmar Saksit return AddClassKeyToArray(path, array, cKeys);
33163935f85SWhindmar Saksit }
33263935f85SWhindmar Saksit
AddFSClassKeysToArray(UINT cidl,PCUITEMID_CHILD_ARRAY apidl,HKEY * array,UINT * cKeys)333a83e40f6SWhindmar Saksit void AddFSClassKeysToArray(UINT cidl, PCUITEMID_CHILD_ARRAY apidl, HKEY* array, UINT* cKeys)
334c2c66affSColin Finck {
335a83e40f6SWhindmar Saksit // This function opens the association array keys in canonical order for filesystem items.
336a83e40f6SWhindmar Saksit // The order is documented: learn.microsoft.com/en-us/windows/win32/shell/fa-associationarray
337a83e40f6SWhindmar Saksit
338a83e40f6SWhindmar Saksit ASSERT(cidl >= 1 && apidl);
339a83e40f6SWhindmar Saksit PCUITEMID_CHILD pidl = apidl[0];
340c2c66affSColin Finck if (_ILIsValue(pidl))
341c2c66affSColin Finck {
342a83e40f6SWhindmar Saksit WCHAR buf[MAX_PATH];
343a83e40f6SWhindmar Saksit PWSTR name;
344c2c66affSColin Finck FileStructW* pFileData = _ILGetFileStructW(pidl);
345a83e40f6SWhindmar Saksit if (pFileData)
346a83e40f6SWhindmar Saksit {
347a83e40f6SWhindmar Saksit name = pFileData->wszName;
348a83e40f6SWhindmar Saksit }
349a83e40f6SWhindmar Saksit else
350a83e40f6SWhindmar Saksit {
351a83e40f6SWhindmar Saksit _ILSimpleGetTextW(pidl, buf, _countof(buf));
352a83e40f6SWhindmar Saksit name = buf;
353a83e40f6SWhindmar Saksit }
354a83e40f6SWhindmar Saksit LPCWSTR extension = PathFindExtension(name);
355c2c66affSColin Finck
356c2c66affSColin Finck if (extension)
357c2c66affSColin Finck {
358a83e40f6SWhindmar Saksit WCHAR wszClass[MAX_PATH], wszSFA[23 + _countof(wszClass)];
359a83e40f6SWhindmar Saksit DWORD dwSize = sizeof(wszClass);
360a83e40f6SWhindmar Saksit if (RegGetValueW(HKEY_CLASSES_ROOT, extension, NULL, RRF_RT_REG_SZ, NULL, wszClass, &dwSize) != ERROR_SUCCESS ||
361a83e40f6SWhindmar Saksit !*wszClass || AddClassKeyToArray(wszClass, array, cKeys) != ERROR_SUCCESS)
362a83e40f6SWhindmar Saksit {
363a83e40f6SWhindmar Saksit // Only add the extension key if the ProgId is not valid
364c2c66affSColin Finck AddClassKeyToArray(extension, array, cKeys);
365c2c66affSColin Finck
366a83e40f6SWhindmar Saksit // "Open With" becomes the default when there are no verbs in the above keys
367a83e40f6SWhindmar Saksit if (cidl == 1)
368a83e40f6SWhindmar Saksit AddClassKeyToArray(L"Unknown", array, cKeys);
369c2c66affSColin Finck }
370c2c66affSColin Finck
371a83e40f6SWhindmar Saksit swprintf(wszSFA, L"SystemFileAssociations\\%s", extension);
372a83e40f6SWhindmar Saksit AddClassKeyToArray(wszSFA, array, cKeys);
373c2c66affSColin Finck
374a83e40f6SWhindmar Saksit dwSize = sizeof(wszClass);
375c2c66affSColin Finck if (RegGetValueW(HKEY_CLASSES_ROOT, extension, L"PerceivedType ", RRF_RT_REG_SZ, NULL, wszClass, &dwSize) == ERROR_SUCCESS)
376c2c66affSColin Finck {
377a83e40f6SWhindmar Saksit swprintf(wszSFA, L"SystemFileAssociations\\%s", wszClass);
378a83e40f6SWhindmar Saksit AddClassKeyToArray(wszSFA, array, cKeys);
379c2c66affSColin Finck }
380c2c66affSColin Finck }
381c2c66affSColin Finck
382c2c66affSColin Finck AddClassKeyToArray(L"*", array, cKeys);
383a83e40f6SWhindmar Saksit AddClassKeyToArray(L"AllFilesystemObjects", array, cKeys);
384c2c66affSColin Finck }
385c2c66affSColin Finck else if (_ILIsFolder(pidl))
386c2c66affSColin Finck {
387a83e40f6SWhindmar Saksit // FIXME: Directory > Folder > AFO is the correct order and it's
388a83e40f6SWhindmar Saksit // the order Windows reports in its undocumented association array
389a83e40f6SWhindmar Saksit // but it is somehow not the order Windows adds the items to its menu!
390a83e40f6SWhindmar Saksit // Until the correct algorithm in CDefaultContextMenu can be determined,
391a83e40f6SWhindmar Saksit // we add the folder keys in "menu order".
392a83e40f6SWhindmar Saksit AddClassKeyToArray(L"Folder", array, cKeys);
393c2c66affSColin Finck AddClassKeyToArray(L"AllFilesystemObjects", array, cKeys);
394c2c66affSColin Finck AddClassKeyToArray(L"Directory", array, cKeys);
395c2c66affSColin Finck }
396c2c66affSColin Finck else
397c2c66affSColin Finck {
398c2c66affSColin Finck ERR("Got non FS pidl\n");
399c2c66affSColin Finck }
400c2c66affSColin Finck }
401c2c66affSColin Finck
SH_GetApidlFromDataObject(IDataObject * pDataObject,PIDLIST_ABSOLUTE * ppidlfolder,PUITEMID_CHILD ** apidlItems,UINT * pcidl)402c2c66affSColin Finck HRESULT SH_GetApidlFromDataObject(IDataObject *pDataObject, PIDLIST_ABSOLUTE* ppidlfolder, PUITEMID_CHILD **apidlItems, UINT *pcidl)
403c2c66affSColin Finck {
404fa0f5cc4SMark Jansen CDataObjectHIDA cida(pDataObject);
405c2c66affSColin Finck
406fa0f5cc4SMark Jansen if (FAILED_UNEXPECTEDLY(cida.hr()))
407fa0f5cc4SMark Jansen return cida.hr();
408c2c66affSColin Finck
409c2c66affSColin Finck /* convert the data into pidl */
410c2c66affSColin Finck LPITEMIDLIST pidl;
411fa0f5cc4SMark Jansen LPITEMIDLIST *apidl = _ILCopyCidaToaPidl(&pidl, cida);
412c2c66affSColin Finck if (!apidl)
413c2c66affSColin Finck {
414c2c66affSColin Finck return E_OUTOFMEMORY;
415c2c66affSColin Finck }
416c2c66affSColin Finck
417c2c66affSColin Finck *ppidlfolder = pidl;
418c2c66affSColin Finck *apidlItems = apidl;
419fa0f5cc4SMark Jansen *pcidl = cida->cidl;
420c2c66affSColin Finck
421c2c66affSColin Finck return S_OK;
422c2c66affSColin Finck }
423c2c66affSColin Finck
424c2c66affSColin Finck /***********************************************************************
425c2c66affSColin Finck * SHCreateLinks
426c2c66affSColin Finck *
427c2c66affSColin Finck * Undocumented.
428c2c66affSColin Finck */
SHCreateLinks(HWND hWnd,LPCSTR lpszDir,IDataObject * lpDataObject,UINT uFlags,LPITEMIDLIST * lppidlLinks)429c2c66affSColin Finck HRESULT WINAPI SHCreateLinks( HWND hWnd, LPCSTR lpszDir, IDataObject * lpDataObject,
430c2c66affSColin Finck UINT uFlags, LPITEMIDLIST *lppidlLinks)
431c2c66affSColin Finck {
432c2c66affSColin Finck FIXME("%p %s %p %08x %p\n", hWnd, lpszDir, lpDataObject, uFlags, lppidlLinks);
433c2c66affSColin Finck return E_NOTIMPL;
434c2c66affSColin Finck }
435c2c66affSColin Finck
436c2c66affSColin Finck /***********************************************************************
437c2c66affSColin Finck * SHOpenFolderAndSelectItems
438c2c66affSColin Finck *
439c2c66affSColin Finck * Unimplemented.
440c2c66affSColin Finck */
441c2c66affSColin Finck EXTERN_C HRESULT
442c2c66affSColin Finck WINAPI
SHOpenFolderAndSelectItems(PCIDLIST_ABSOLUTE pidlFolder,UINT cidl,PCUITEMID_CHILD_ARRAY apidl,DWORD dwFlags)443aee6cbc5SThomas Faber SHOpenFolderAndSelectItems(PCIDLIST_ABSOLUTE pidlFolder,
444c2c66affSColin Finck UINT cidl,
445c2c66affSColin Finck PCUITEMID_CHILD_ARRAY apidl,
446c2c66affSColin Finck DWORD dwFlags)
447c2c66affSColin Finck {
448c2c66affSColin Finck ERR("SHOpenFolderAndSelectItems() is hackplemented\n");
4491408de02SWhindmar Saksit CComHeapPtr<ITEMIDLIST> freeItem;
450c2c66affSColin Finck PCIDLIST_ABSOLUTE pidlItem;
451c2c66affSColin Finck if (cidl)
452c2c66affSColin Finck {
453c2c66affSColin Finck /* Firefox sends a full pidl here dispite the fact it is a PCUITEMID_CHILD_ARRAY -_- */
4541408de02SWhindmar Saksit if (!ILIsSingle(apidl[0]))
455c2c66affSColin Finck {
456c2c66affSColin Finck pidlItem = apidl[0];
457c2c66affSColin Finck }
458c2c66affSColin Finck else
459c2c66affSColin Finck {
4601408de02SWhindmar Saksit HRESULT hr = SHILCombine(pidlFolder, apidl[0], &pidlItem);
4611408de02SWhindmar Saksit if (FAILED_UNEXPECTEDLY(hr))
4621408de02SWhindmar Saksit return hr;
4631408de02SWhindmar Saksit freeItem.Attach(const_cast<PIDLIST_ABSOLUTE>(pidlItem));
464c2c66affSColin Finck }
465c2c66affSColin Finck }
466c2c66affSColin Finck else
467c2c66affSColin Finck {
468c2c66affSColin Finck pidlItem = pidlFolder;
469c2c66affSColin Finck }
470c2c66affSColin Finck
471c2c66affSColin Finck CComPtr<IShellFolder> psfDesktop;
472c2c66affSColin Finck
473c2c66affSColin Finck HRESULT hr = SHGetDesktopFolder(&psfDesktop);
474c2c66affSColin Finck if (FAILED_UNEXPECTEDLY(hr))
475c2c66affSColin Finck return hr;
476c2c66affSColin Finck
477c2c66affSColin Finck STRRET strret;
478c2c66affSColin Finck hr = psfDesktop->GetDisplayNameOf(pidlItem, SHGDN_FORPARSING, &strret);
479c2c66affSColin Finck if (FAILED_UNEXPECTEDLY(hr))
480c2c66affSColin Finck return hr;
481c2c66affSColin Finck
482c2c66affSColin Finck WCHAR wszBuf[MAX_PATH];
483c2c66affSColin Finck hr = StrRetToBufW(&strret, pidlItem, wszBuf, _countof(wszBuf));
484c2c66affSColin Finck if (FAILED_UNEXPECTEDLY(hr))
485c2c66affSColin Finck return hr;
486c2c66affSColin Finck
487c2c66affSColin Finck WCHAR wszParams[MAX_PATH];
488c2c66affSColin Finck wcscpy(wszParams, L"/select,");
489c2c66affSColin Finck wcscat(wszParams, wszBuf);
490c2c66affSColin Finck
491c2c66affSColin Finck SHELLEXECUTEINFOW sei;
492c2c66affSColin Finck memset(&sei, 0, sizeof sei);
493c2c66affSColin Finck sei.cbSize = sizeof sei;
494c2c66affSColin Finck sei.fMask = SEE_MASK_WAITFORINPUTIDLE;
495c2c66affSColin Finck sei.lpFile = L"explorer.exe";
496c2c66affSColin Finck sei.lpParameters = wszParams;
497c2c66affSColin Finck
498c2c66affSColin Finck if (ShellExecuteExW(&sei))
499c2c66affSColin Finck return S_OK;
500c2c66affSColin Finck else
501c2c66affSColin Finck return E_FAIL;
502c2c66affSColin Finck }
50355469633SKatayama Hirofumi MZ
504bc5603d9SMark Jansen /*
505bc5603d9SMark Jansen * for internal use
506bc5603d9SMark Jansen */
507daf80680SWhindmar Saksit HRESULT
SHELL32_ShowPropertiesDialog(IDataObject * pdtobj)508daf80680SWhindmar Saksit SHELL32_ShowPropertiesDialog(IDataObject *pdtobj)
509bc5603d9SMark Jansen {
510daf80680SWhindmar Saksit if (!pdtobj)
511daf80680SWhindmar Saksit return E_INVALIDARG;
512daf80680SWhindmar Saksit
513*2aadf2ebSWhindmar Saksit CDataObjectHIDA cida(pdtobj);
514*2aadf2ebSWhindmar Saksit if (FAILED_UNEXPECTEDLY(cida.hr()))
515*2aadf2ebSWhindmar Saksit return cida.hr();
516*2aadf2ebSWhindmar Saksit if (cida->cidl > 1)
517bc5603d9SMark Jansen {
518*2aadf2ebSWhindmar Saksit ERR("SHMultiFileProperties is not yet implemented\n");
519*2aadf2ebSWhindmar Saksit return E_FAIL;
520bc5603d9SMark Jansen }
521*2aadf2ebSWhindmar Saksit return SHELL32_ShowFilesystemItemPropertiesDialogAsync(pdtobj);
52255469633SKatayama Hirofumi MZ }
523daf80680SWhindmar Saksit
524daf80680SWhindmar Saksit HRESULT
SHELL32_DefaultContextMenuCallBack(IShellFolder * psf,IDataObject * pdo,UINT msg)525daf80680SWhindmar Saksit SHELL32_DefaultContextMenuCallBack(IShellFolder *psf, IDataObject *pdo, UINT msg)
526daf80680SWhindmar Saksit {
527daf80680SWhindmar Saksit switch (msg)
528daf80680SWhindmar Saksit {
529daf80680SWhindmar Saksit case DFM_MERGECONTEXTMENU:
530daf80680SWhindmar Saksit return S_OK; // Yes, I want verbs
531daf80680SWhindmar Saksit case DFM_INVOKECOMMAND:
532daf80680SWhindmar Saksit return S_FALSE; // Do it for me please
533daf80680SWhindmar Saksit case DFM_GETDEFSTATICID:
534daf80680SWhindmar Saksit return S_FALSE; // Supposedly "required for Windows 7 to pick a default"
535daf80680SWhindmar Saksit }
536daf80680SWhindmar Saksit return E_NOTIMPL;
537daf80680SWhindmar Saksit }
538