2011-05-15 15:55:49 +00:00
|
|
|
/*
|
2011-09-08 22:43:43 +00:00
|
|
|
* Shell Folder stuff
|
2011-05-15 15:55:49 +00:00
|
|
|
*
|
2011-09-08 22:43:43 +00:00
|
|
|
* Copyright 1997 Marcus Meissner
|
|
|
|
* Copyright 1998, 1999, 2002 Juergen Schmied
|
2011-05-15 15:55:49 +00:00
|
|
|
*
|
2011-09-08 22:43:43 +00:00
|
|
|
* IShellFolder2 and related interfaces
|
2011-05-15 15:55:49 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2013-01-24 23:00:42 +00:00
|
|
|
#include "precomp.h"
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2011-09-06 23:52:38 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(shell);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
/***************************************************************************
|
2015-08-26 17:31:42 +00:00
|
|
|
* SHELL32_GetCustomFolderAttributeFromPath (internal function)
|
2011-05-15 15:55:49 +00:00
|
|
|
*
|
|
|
|
* Gets a value from the folder's desktop.ini file, if one exists.
|
|
|
|
*
|
|
|
|
* PARAMETERS
|
2015-08-26 17:31:42 +00:00
|
|
|
* pwszFolderPath[I] Folder containing the desktop.ini file.
|
2011-05-15 15:55:49 +00:00
|
|
|
* pwszHeading [I] Heading in .ini file.
|
|
|
|
* pwszAttribute [I] Attribute in .ini file.
|
|
|
|
* pwszValue [O] Buffer to store value into.
|
|
|
|
* cchValue [I] Size in characters including NULL of buffer pointed to
|
|
|
|
* by pwszValue.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE if returned non-NULL value.
|
|
|
|
* FALSE otherwise.
|
|
|
|
*/
|
|
|
|
static BOOL __inline SHELL32_GetCustomFolderAttributeFromPath(
|
|
|
|
LPWSTR pwszFolderPath, LPCWSTR pwszHeading, LPCWSTR pwszAttribute,
|
|
|
|
LPWSTR pwszValue, DWORD cchValue)
|
|
|
|
{
|
|
|
|
static const WCHAR wszDesktopIni[] =
|
|
|
|
{'d','e','s','k','t','o','p','.','i','n','i',0};
|
|
|
|
static const WCHAR wszDefault[] = {0};
|
|
|
|
|
|
|
|
PathAddBackslashW(pwszFolderPath);
|
|
|
|
PathAppendW(pwszFolderPath, wszDesktopIni);
|
|
|
|
return GetPrivateProfileStringW(pwszHeading, pwszAttribute, wszDefault,
|
|
|
|
pwszValue, cchValue, pwszFolderPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* GetNextElement (internal function)
|
|
|
|
*
|
|
|
|
* Gets a part of a string till the first backslash.
|
|
|
|
*
|
|
|
|
* PARAMETERS
|
|
|
|
* pszNext [IN] string to get the element from
|
|
|
|
* pszOut [IN] pointer to buffer which receives string
|
|
|
|
* dwOut [IN] length of pszOut
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* LPSTR pointer to first, not yet parsed char
|
|
|
|
*/
|
|
|
|
|
|
|
|
LPCWSTR GetNextElementW (LPCWSTR pszNext, LPWSTR pszOut, DWORD dwOut)
|
|
|
|
{
|
|
|
|
LPCWSTR pszTail = pszNext;
|
|
|
|
DWORD dwCopy;
|
|
|
|
|
|
|
|
TRACE ("(%s %p 0x%08x)\n", debugstr_w (pszNext), pszOut, dwOut);
|
|
|
|
|
|
|
|
*pszOut = 0x0000;
|
|
|
|
|
|
|
|
if (!pszNext || !*pszNext)
|
2011-09-08 22:43:43 +00:00
|
|
|
return NULL;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
while (*pszTail && (*pszTail != (WCHAR) '\\'))
|
2011-09-08 22:43:43 +00:00
|
|
|
pszTail++;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
dwCopy = pszTail - pszNext + 1;
|
|
|
|
lstrcpynW (pszOut, pszNext, (dwOut < dwCopy) ? dwOut : dwCopy);
|
|
|
|
|
|
|
|
if (*pszTail)
|
2011-09-08 22:43:43 +00:00
|
|
|
pszTail++;
|
2011-05-15 15:55:49 +00:00
|
|
|
else
|
2011-09-08 22:43:43 +00:00
|
|
|
pszTail = NULL;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
TRACE ("--(%s %s 0x%08x %p)\n", debugstr_w (pszNext), debugstr_w (pszOut), dwOut, pszTail);
|
|
|
|
return pszTail;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT SHELL32_ParseNextElement (IShellFolder2 * psf, HWND hwndOwner, LPBC pbc,
|
2011-09-08 22:43:43 +00:00
|
|
|
LPITEMIDLIST * pidlInOut, LPOLESTR szNext, DWORD * pEaten, DWORD * pdwAttributes)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
HRESULT hr = E_INVALIDARG;
|
2014-06-07 13:54:11 +00:00
|
|
|
LPITEMIDLIST pidlIn = pidlInOut ? *pidlInOut : NULL;
|
|
|
|
LPITEMIDLIST pidlOut = NULL;
|
|
|
|
LPITEMIDLIST pidlTemp = NULL;
|
|
|
|
CComPtr<IShellFolder> psfChild;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2014-06-07 13:54:11 +00:00
|
|
|
TRACE ("(%p, %p, %p, %s)\n", psf, pbc, pidlIn, debugstr_w (szNext));
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
/* get the shellfolder for the child pidl and let it analyse further */
|
2014-06-07 13:54:11 +00:00
|
|
|
hr = psf->BindToObject(pidlIn, pbc, IID_PPV_ARG(IShellFolder, &psfChild));
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2011-09-08 22:43:43 +00:00
|
|
|
hr = psfChild->ParseDisplayName(hwndOwner, pbc, szNext, pEaten, &pidlOut, pdwAttributes);
|
2014-06-07 13:54:11 +00:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2014-06-07 13:54:11 +00:00
|
|
|
pidlTemp = ILCombine (pidlIn, pidlOut);
|
|
|
|
if (!pidlTemp)
|
|
|
|
{
|
2011-09-08 22:43:43 +00:00
|
|
|
hr = E_OUTOFMEMORY;
|
2014-06-07 13:54:11 +00:00
|
|
|
if (pidlOut)
|
|
|
|
ILFree(pidlOut);
|
|
|
|
return hr;
|
2011-09-08 22:43:43 +00:00
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2011-09-08 22:43:43 +00:00
|
|
|
if (pidlOut)
|
|
|
|
ILFree (pidlOut);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2014-06-07 13:54:11 +00:00
|
|
|
if (pidlIn)
|
|
|
|
ILFree (pidlIn);
|
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
*pidlInOut = pidlTemp;
|
|
|
|
|
|
|
|
TRACE ("-- pidl=%p ret=0x%08x\n", pidlInOut ? *pidlInOut : NULL, hr);
|
2014-06-07 13:54:11 +00:00
|
|
|
return S_OK;
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2011-09-08 22:43:43 +00:00
|
|
|
* SHELL32_CoCreateInitSF
|
2011-05-15 15:55:49 +00:00
|
|
|
*
|
|
|
|
* Creates a shell folder and initializes it with a pidl and a root folder
|
|
|
|
* via IPersistFolder3 or IPersistFolder.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* pathRoot can be NULL for Folders being a drive.
|
|
|
|
* In this case the absolute path is built from pidlChild (eg. C:)
|
|
|
|
*/
|
2016-08-09 18:05:50 +00:00
|
|
|
HRESULT SHELL32_CoCreateInitSF (LPCITEMIDLIST pidlRoot, LPCWSTR pathRoot,
|
|
|
|
LPCITEMIDLIST pidlChild, const GUID* clsid, int csidl, REFIID riid, LPVOID *ppvOut)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
2014-08-20 12:25:09 +00:00
|
|
|
CComPtr<IShellFolder> pShellFolder;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
TRACE ("%p %s %p\n", pidlRoot, debugstr_w(pathRoot), pidlChild);
|
|
|
|
|
2016-08-09 18:05:50 +00:00
|
|
|
hr = SHCoCreateInstance(NULL, clsid, NULL, IID_PPV_ARG(IShellFolder, &pShellFolder));
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2016-08-09 18:05:50 +00:00
|
|
|
LPITEMIDLIST pidlAbsolute = ILCombine (pidlRoot, pidlChild);
|
|
|
|
CComPtr<IPersistFolder> ppf;
|
|
|
|
CComPtr<IPersistFolder3> ppf3;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2016-08-09 18:05:50 +00:00
|
|
|
if (SUCCEEDED(pShellFolder->QueryInterface(IID_PPV_ARG(IPersistFolder3, &ppf3))))
|
|
|
|
{
|
|
|
|
PERSIST_FOLDER_TARGET_INFO ppfti;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2016-08-09 18:05:50 +00:00
|
|
|
ZeroMemory (&ppfti, sizeof (ppfti));
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2016-08-09 18:05:50 +00:00
|
|
|
/* fill the PERSIST_FOLDER_TARGET_INFO */
|
|
|
|
ppfti.dwAttributes = -1;
|
|
|
|
ppfti.csidl = csidl;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2016-08-09 18:05:50 +00:00
|
|
|
/* build path */
|
|
|
|
if (pathRoot)
|
2011-09-06 23:52:38 +00:00
|
|
|
{
|
2016-08-09 18:05:50 +00:00
|
|
|
lstrcpynW (ppfti.szTargetParsingName, pathRoot, MAX_PATH - 1);
|
|
|
|
PathAddBackslashW(ppfti.szTargetParsingName); /* FIXME: why have drives a backslash here ? */
|
2011-09-08 22:43:43 +00:00
|
|
|
}
|
2013-11-11 16:42:16 +00:00
|
|
|
|
2016-08-09 18:05:50 +00:00
|
|
|
if (pidlChild)
|
|
|
|
{
|
|
|
|
int len = wcslen(ppfti.szTargetParsingName);
|
2013-11-11 16:42:16 +00:00
|
|
|
|
2016-08-09 18:05:50 +00:00
|
|
|
if (!_ILSimpleGetTextW(pidlChild, ppfti.szTargetParsingName + len, MAX_PATH - len))
|
|
|
|
hr = E_INVALIDARG;
|
|
|
|
}
|
2013-11-11 17:49:30 +00:00
|
|
|
|
2016-08-09 18:05:50 +00:00
|
|
|
ppf3->InitializeEx(NULL, pidlAbsolute, &ppfti);
|
|
|
|
}
|
|
|
|
else if (SUCCEEDED(pShellFolder->QueryInterface(IID_PPV_ARG(IPersistFolder, &ppf))))
|
|
|
|
{
|
|
|
|
ppf->Initialize(pidlAbsolute);
|
|
|
|
}
|
|
|
|
ILFree (pidlAbsolute);
|
|
|
|
|
|
|
|
return pShellFolder->QueryInterface(riid, ppvOut);
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|
|
|
|
|
2015-08-31 23:44:02 +00:00
|
|
|
void SHELL32_GetCLSIDForDirectory(LPCWSTR pathRoot, LPCITEMIDLIST pidl, CLSID* pclsidFolder)
|
|
|
|
{
|
|
|
|
static const WCHAR wszDotShellClassInfo[] = {
|
|
|
|
'.','S','h','e','l','l','C','l','a','s','s','I','n','f','o',0 };
|
|
|
|
static const WCHAR wszCLSID[] = {'C','L','S','I','D',0};
|
|
|
|
WCHAR wszCLSIDValue[CHARS_IN_GUID], wszFolderPath[MAX_PATH], *pwszPathTail = wszFolderPath;
|
|
|
|
|
|
|
|
/* see if folder CLSID should be overridden by desktop.ini file */
|
|
|
|
if (pathRoot) {
|
|
|
|
lstrcpynW(wszFolderPath, pathRoot, MAX_PATH);
|
|
|
|
pwszPathTail = PathAddBackslashW(wszFolderPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
_ILSimpleGetTextW(pidl,pwszPathTail,MAX_PATH - (int)(pwszPathTail - wszFolderPath));
|
|
|
|
|
|
|
|
if (SHELL32_GetCustomFolderAttributeFromPath (wszFolderPath,
|
|
|
|
wszDotShellClassInfo, wszCLSID, wszCLSIDValue, CHARS_IN_GUID))
|
|
|
|
CLSIDFromString (wszCLSIDValue, pclsidFolder);
|
|
|
|
}
|
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
/***********************************************************************
|
2015-08-31 23:44:02 +00:00
|
|
|
* SHELL32_BindToFS [Internal]
|
2011-05-15 15:55:49 +00:00
|
|
|
*
|
|
|
|
* Common code for IShellFolder_BindToObject.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pidlRoot [I] The parent shell folder's absolute pidl.
|
|
|
|
* pathRoot [I] Absolute dos path of the parent shell folder.
|
|
|
|
* pidlComplete [I] PIDL of the child. Relative to pidlRoot.
|
|
|
|
* riid [I] GUID of the interface, which ppvOut shall be bound to.
|
|
|
|
* ppvOut [O] A reference to the child's interface (riid).
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* pidlComplete has to contain at least one non empty SHITEMID.
|
|
|
|
* This function makes special assumptions on the shell namespace, which
|
|
|
|
* means you probably can't use it for your IShellFolder implementation.
|
|
|
|
*/
|
2015-08-31 23:44:02 +00:00
|
|
|
HRESULT SHELL32_BindToFS (LPCITEMIDLIST pidlRoot,
|
2011-05-15 15:55:49 +00:00
|
|
|
LPCWSTR pathRoot, LPCITEMIDLIST pidlComplete, REFIID riid, LPVOID * ppvOut)
|
|
|
|
{
|
2014-08-20 00:39:40 +00:00
|
|
|
CComPtr<IShellFolder> pSF;
|
2011-05-15 15:55:49 +00:00
|
|
|
HRESULT hr;
|
2015-08-31 23:44:02 +00:00
|
|
|
LPCITEMIDLIST pidlChild;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
if (!pidlRoot || !ppvOut || !pidlComplete || !pidlComplete->mkid.cb)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2015-08-31 23:44:02 +00:00
|
|
|
if (_ILIsValue(pidlComplete))
|
|
|
|
{
|
|
|
|
ERR("Binding to file is unimplemented\n");
|
|
|
|
return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
|
|
|
|
}
|
2016-11-06 21:51:46 +00:00
|
|
|
if (!_ILIsFolder(pidlComplete))
|
2015-08-31 23:44:02 +00:00
|
|
|
{
|
|
|
|
ERR("Got an unknown type of pidl!\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
*ppvOut = NULL;
|
|
|
|
|
2015-08-31 23:44:02 +00:00
|
|
|
pidlChild = (_ILIsPidlSimple (pidlComplete)) ? pidlComplete : ILCloneFirst (pidlComplete);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2015-08-31 23:44:02 +00:00
|
|
|
CLSID clsidFolder = CLSID_ShellFSFolder;
|
|
|
|
DWORD attributes = _ILGetFileAttributes(ILFindLastID(pidlChild), NULL, 0);
|
|
|
|
if ((attributes & (FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_READONLY)) != 0)
|
|
|
|
SHELL32_GetCLSIDForDirectory(pathRoot, pidlChild, &clsidFolder);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2016-08-09 18:05:50 +00:00
|
|
|
hr = SHELL32_CoCreateInitSF (pidlRoot, pathRoot, pidlChild, &clsidFolder, -1, IID_PPV_ARG(IShellFolder, &pSF));
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2015-08-31 23:44:02 +00:00
|
|
|
if (pidlChild != pidlComplete)
|
|
|
|
ILFree ((LPITEMIDLIST)pidlChild);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
if (SUCCEEDED (hr)) {
|
|
|
|
if (_ILIsPidlSimple (pidlComplete)) {
|
|
|
|
/* no sub folders */
|
|
|
|
hr = pSF->QueryInterface(riid, ppvOut);
|
|
|
|
} else {
|
|
|
|
/* go deeper */
|
|
|
|
hr = pSF->BindToObject(ILGetNext (pidlComplete), NULL, riid, ppvOut);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE ("-- returning (%p) %08x\n", *ppvOut, hr);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2011-09-08 22:43:43 +00:00
|
|
|
* SHELL32_GetDisplayNameOfChild
|
2011-05-15 15:55:49 +00:00
|
|
|
*
|
|
|
|
* Retrieves the display name of a child object of a shellfolder.
|
|
|
|
*
|
|
|
|
* For a pidl eg. [subpidl1][subpidl2][subpidl3]:
|
|
|
|
* - it binds to the child shellfolder [subpidl1]
|
|
|
|
* - asks it for the displayname of [subpidl2][subpidl3]
|
|
|
|
*
|
|
|
|
* Is possible the pidl is a simple pidl. In this case it asks the
|
|
|
|
* subfolder for the displayname of an empty pidl. The subfolder
|
|
|
|
* returns the own displayname eg. "::{guid}". This is used for
|
|
|
|
* virtual folders with the registry key WantsFORPARSING set.
|
|
|
|
*/
|
|
|
|
HRESULT SHELL32_GetDisplayNameOfChild (IShellFolder2 * psf,
|
2015-08-31 11:28:24 +00:00
|
|
|
LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet)
|
2011-05-15 15:55:49 +00:00
|
|
|
{
|
2015-08-31 11:28:24 +00:00
|
|
|
LPITEMIDLIST pidlFirst = ILCloneFirst(pidl);
|
|
|
|
if (!pidlFirst)
|
|
|
|
return E_OUTOFMEMORY;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2015-08-31 11:28:24 +00:00
|
|
|
CComPtr<IShellFolder> psfChild;
|
|
|
|
HRESULT hr = psf->BindToObject(pidlFirst, NULL, IID_PPV_ARG(IShellFolder, &psfChild));
|
|
|
|
if (SUCCEEDED (hr))
|
2011-12-17 22:48:16 +00:00
|
|
|
{
|
2015-08-31 11:28:24 +00:00
|
|
|
hr = psfChild->GetDisplayNameOf(ILGetNext (pidl), dwFlags, strRet);
|
|
|
|
}
|
|
|
|
ILFree (pidlFirst);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2015-09-22 18:11:32 +00:00
|
|
|
HRESULT HCR_GetClassName(REFIID riid, LPSTRRET strRet)
|
|
|
|
{
|
|
|
|
BOOL bRet;
|
|
|
|
WCHAR wstrName[MAX_PATH+1];
|
2016-06-03 21:00:59 +00:00
|
|
|
bRet = HCR_GetClassNameW(riid, wstrName, MAX_PATH);
|
2015-09-22 18:11:32 +00:00
|
|
|
if (!bRet)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
return SHSetStrRet(strRet, wstrName);
|
|
|
|
}
|
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* SHELL32_GetItemAttributes
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Observed values:
|
2011-09-08 22:43:43 +00:00
|
|
|
* folder: 0xE0000177 FILESYSTEM | HASSUBFOLDER | FOLDER
|
|
|
|
* file: 0x40000177 FILESYSTEM
|
|
|
|
* drive: 0xf0000144 FILESYSTEM | HASSUBFOLDER | FOLDER | FILESYSANCESTOR
|
|
|
|
* mycomputer: 0xb0000154 HASSUBFOLDER | FOLDER | FILESYSANCESTOR
|
2011-05-15 15:55:49 +00:00
|
|
|
* (seems to be default for shell extensions if no registry entry exists)
|
|
|
|
*
|
|
|
|
* win2k:
|
|
|
|
* folder: 0xF0400177 FILESYSTEM | HASSUBFOLDER | FOLDER | FILESYSANCESTOR | CANMONIKER
|
|
|
|
* file: 0x40400177 FILESYSTEM | CANMONIKER
|
|
|
|
* drive 0xF0400154 FILESYSTEM | HASSUBFOLDER | FOLDER | FILESYSANCESTOR | CANMONIKER | CANRENAME (LABEL)
|
|
|
|
*
|
|
|
|
* According to the MSDN documentation this function should not set flags. It claims only to reset flags when necessary.
|
|
|
|
* However it turns out the native shell32.dll _sets_ flags in several cases - so do we.
|
|
|
|
*/
|
|
|
|
|
2015-08-17 11:36:56 +00:00
|
|
|
static const DWORD dwSupportedAttr=
|
|
|
|
SFGAO_CANCOPY | /*0x00000001 */
|
|
|
|
SFGAO_CANMOVE | /*0x00000002 */
|
|
|
|
SFGAO_CANLINK | /*0x00000004 */
|
|
|
|
SFGAO_CANRENAME | /*0x00000010 */
|
|
|
|
SFGAO_CANDELETE | /*0x00000020 */
|
|
|
|
SFGAO_HASPROPSHEET | /*0x00000040 */
|
|
|
|
SFGAO_DROPTARGET | /*0x00000100 */
|
|
|
|
SFGAO_LINK | /*0x00010000 */
|
|
|
|
SFGAO_READONLY | /*0x00040000 */
|
|
|
|
SFGAO_HIDDEN | /*0x00080000 */
|
|
|
|
SFGAO_FILESYSANCESTOR | /*0x10000000 */
|
|
|
|
SFGAO_FOLDER | /*0x20000000 */
|
|
|
|
SFGAO_FILESYSTEM | /*0x40000000 */
|
|
|
|
SFGAO_HASSUBFOLDER; /*0x80000000 */
|
|
|
|
|
|
|
|
HRESULT SHELL32_GetFSItemAttributes(IShellFolder * psf, LPCITEMIDLIST pidl, LPDWORD pdwAttributes)
|
|
|
|
{
|
2015-08-28 15:08:19 +00:00
|
|
|
DWORD dwFileAttributes, dwShellAttributes;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2015-08-17 13:34:38 +00:00
|
|
|
if (!_ILIsFolder(pidl) && !_ILIsValue(pidl))
|
|
|
|
{
|
|
|
|
ERR("Got wrong type of pidl!\n");
|
|
|
|
*pdwAttributes &= SFGAO_CANLINK;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2015-08-17 11:36:56 +00:00
|
|
|
if (*pdwAttributes & ~dwSupportedAttr)
|
|
|
|
{
|
|
|
|
WARN ("attributes 0x%08x not implemented\n", (*pdwAttributes & ~dwSupportedAttr));
|
|
|
|
*pdwAttributes &= dwSupportedAttr;
|
|
|
|
}
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2015-08-28 15:08:19 +00:00
|
|
|
dwFileAttributes = _ILGetFileAttributes(pidl, NULL, 0);
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2015-08-17 11:36:56 +00:00
|
|
|
/* Set common attributes */
|
2015-08-28 15:08:19 +00:00
|
|
|
dwShellAttributes = *pdwAttributes;
|
|
|
|
dwShellAttributes |= SFGAO_FILESYSTEM | SFGAO_DROPTARGET | SFGAO_HASPROPSHEET | SFGAO_CANDELETE |
|
|
|
|
SFGAO_CANRENAME | SFGAO_CANLINK | SFGAO_CANMOVE | SFGAO_CANCOPY;
|
2011-05-15 15:55:49 +00:00
|
|
|
|
2015-08-28 15:08:19 +00:00
|
|
|
if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
2015-08-17 11:36:56 +00:00
|
|
|
{
|
2015-08-28 15:08:19 +00:00
|
|
|
dwShellAttributes |= (SFGAO_FOLDER | SFGAO_HASSUBFOLDER | SFGAO_FILESYSANCESTOR);
|
2015-08-17 11:36:56 +00:00
|
|
|
}
|
|
|
|
else
|
2015-08-28 15:08:19 +00:00
|
|
|
dwShellAttributes &= ~(SFGAO_FOLDER | SFGAO_HASSUBFOLDER | SFGAO_FILESYSANCESTOR);
|
2011-09-08 22:43:43 +00:00
|
|
|
|
2015-08-28 15:08:19 +00:00
|
|
|
if (dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
|
|
|
|
dwShellAttributes |= SFGAO_HIDDEN;
|
2015-08-17 11:36:56 +00:00
|
|
|
else
|
2015-08-28 15:08:19 +00:00
|
|
|
dwShellAttributes &= ~SFGAO_HIDDEN;
|
2011-09-08 22:43:43 +00:00
|
|
|
|
2015-08-28 15:08:19 +00:00
|
|
|
if (dwFileAttributes & FILE_ATTRIBUTE_READONLY)
|
|
|
|
dwShellAttributes |= SFGAO_READONLY;
|
2015-08-17 11:36:56 +00:00
|
|
|
else
|
2015-08-28 15:08:19 +00:00
|
|
|
dwShellAttributes &= ~SFGAO_READONLY;
|
2011-09-08 22:43:43 +00:00
|
|
|
|
2015-08-17 11:36:56 +00:00
|
|
|
if (SFGAO_LINK & *pdwAttributes)
|
|
|
|
{
|
|
|
|
char ext[MAX_PATH];
|
2011-09-08 22:43:43 +00:00
|
|
|
|
2015-08-17 11:36:56 +00:00
|
|
|
if (!_ILGetExtension(pidl, ext, MAX_PATH) || lstrcmpiA(ext, "lnk"))
|
2015-08-28 15:08:19 +00:00
|
|
|
dwShellAttributes &= ~SFGAO_LINK;
|
2015-08-17 11:36:56 +00:00
|
|
|
}
|
2011-09-08 22:43:43 +00:00
|
|
|
|
2015-08-17 11:36:56 +00:00
|
|
|
if (SFGAO_HASSUBFOLDER & *pdwAttributes)
|
|
|
|
{
|
|
|
|
CComPtr<IShellFolder> psf2;
|
|
|
|
if (SUCCEEDED(psf->BindToObject(pidl, 0, IID_PPV_ARG(IShellFolder, &psf2))))
|
2011-09-08 22:43:43 +00:00
|
|
|
{
|
2015-08-17 11:36:56 +00:00
|
|
|
CComPtr<IEnumIDList> pEnumIL;
|
|
|
|
if (SUCCEEDED(psf2->EnumObjects(0, SHCONTF_FOLDERS, &pEnumIL)))
|
2011-09-08 22:43:43 +00:00
|
|
|
{
|
2015-08-17 11:36:56 +00:00
|
|
|
if (pEnumIL->Skip(1) != S_OK)
|
2015-08-28 15:08:19 +00:00
|
|
|
dwShellAttributes &= ~SFGAO_HASSUBFOLDER;
|
2011-09-08 22:43:43 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-17 11:36:56 +00:00
|
|
|
}
|
|
|
|
|
2015-08-28 15:08:19 +00:00
|
|
|
*pdwAttributes &= dwShellAttributes;
|
|
|
|
|
2015-08-17 11:36:56 +00:00
|
|
|
TRACE ("-- 0x%08x\n", *pdwAttributes);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-11-04 23:11:29 +00:00
|
|
|
HRESULT SHELL32_CompareChildren(IShellFolder2* psf, LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
|
|
|
|
{
|
|
|
|
PUIDLIST_RELATIVE nextpidl1 = ILGetNext (pidl1);
|
|
|
|
PUIDLIST_RELATIVE nextpidl2 = ILGetNext (pidl2);
|
|
|
|
|
|
|
|
bool isEmpty1 = _ILIsDesktop(nextpidl1);
|
|
|
|
bool isEmpty2 = _ILIsDesktop(nextpidl2);
|
|
|
|
if (isEmpty1 || isEmpty2)
|
|
|
|
return MAKE_COMPARE_HRESULT(isEmpty2 - isEmpty1);
|
|
|
|
|
|
|
|
PITEMID_CHILD firstpidl = ILCloneFirst (pidl1);
|
|
|
|
if (!firstpidl)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
CComPtr<IShellFolder> psf2;
|
|
|
|
HRESULT hr = psf->BindToObject(firstpidl, 0, IID_PPV_ARG(IShellFolder, &psf2));
|
|
|
|
ILFree(firstpidl);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return MAKE_COMPARE_HRESULT(0);
|
|
|
|
|
|
|
|
return psf2->CompareIDs(lParam, nextpidl1, nextpidl2);
|
|
|
|
}
|
|
|
|
|
2015-10-26 15:07:44 +00:00
|
|
|
HRESULT SHELL32_CompareDetails(IShellFolder2* isf, LPARAM lParam, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
|
|
|
|
{
|
|
|
|
SHELLDETAILS sd;
|
|
|
|
WCHAR wszItem1[MAX_PATH], wszItem2[MAX_PATH];
|
2016-09-22 16:22:44 +00:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = isf->GetDetailsOf(pidl1, lParam, &sd);
|
|
|
|
if (FAILED(hres))
|
|
|
|
return MAKE_COMPARE_HRESULT(1);
|
|
|
|
|
|
|
|
hres = StrRetToBufW(&sd.str, pidl1, wszItem1, MAX_PATH);
|
|
|
|
if (FAILED(hres))
|
|
|
|
return MAKE_COMPARE_HRESULT(1);
|
|
|
|
|
|
|
|
hres = isf->GetDetailsOf(pidl2, lParam, &sd);
|
|
|
|
if (FAILED(hres))
|
|
|
|
return MAKE_COMPARE_HRESULT(1);
|
|
|
|
|
|
|
|
hres = StrRetToBufW(&sd.str, pidl2, wszItem2, MAX_PATH);
|
|
|
|
if (FAILED(hres))
|
|
|
|
return MAKE_COMPARE_HRESULT(1);
|
2015-10-26 15:07:44 +00:00
|
|
|
|
|
|
|
int ret = wcsicmp(wszItem1, wszItem2);
|
2016-11-04 23:11:29 +00:00
|
|
|
if (ret == 0)
|
|
|
|
return SHELL32_CompareChildren(isf, lParam, pidl1, pidl2);
|
2015-10-26 15:07:44 +00:00
|
|
|
|
|
|
|
return MAKE_COMPARE_HRESULT(ret);
|
|
|
|
}
|
|
|
|
|
2016-10-02 13:22:01 +00:00
|
|
|
void AddClassKeyToArray(const WCHAR * szClass, HKEY* array, UINT* cKeys)
|
|
|
|
{
|
|
|
|
if (*cKeys >= 16)
|
|
|
|
return;
|
|
|
|
|
|
|
|
HKEY hkey;
|
|
|
|
LSTATUS result = RegOpenKeyExW(HKEY_CLASSES_ROOT, szClass, 0, KEY_READ | KEY_QUERY_VALUE, &hkey);
|
|
|
|
if (result != ERROR_SUCCESS)
|
|
|
|
return;
|
|
|
|
|
|
|
|
array[*cKeys] = hkey;
|
|
|
|
*cKeys += 1;
|
|
|
|
}
|
|
|
|
|
2016-11-15 20:14:56 +00:00
|
|
|
void AddFSClassKeysToArray(PCUITEMID_CHILD pidl, HKEY* array, UINT* cKeys)
|
|
|
|
{
|
|
|
|
if (_ILIsValue(pidl))
|
|
|
|
{
|
|
|
|
FileStructW* pFileData = _ILGetFileStructW(pidl);
|
|
|
|
LPWSTR extension = PathFindExtension(pFileData->wszName);
|
|
|
|
|
|
|
|
if (extension)
|
|
|
|
{
|
|
|
|
AddClassKeyToArray(extension, array, cKeys);
|
|
|
|
|
|
|
|
WCHAR wszClass[40], wszClass2[40];
|
|
|
|
DWORD dwSize = sizeof(wszClass);
|
|
|
|
if (RegGetValueW(HKEY_CLASSES_ROOT, extension, NULL, RRF_RT_REG_SZ, NULL, wszClass, &dwSize) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
swprintf(wszClass2, L"%s//%s", extension, wszClass);
|
|
|
|
|
|
|
|
AddClassKeyToArray(wszClass, array, cKeys);
|
|
|
|
AddClassKeyToArray(wszClass2, array, cKeys);
|
|
|
|
}
|
|
|
|
|
|
|
|
swprintf(wszClass2, L"SystemFileAssociations//%s", extension);
|
|
|
|
AddClassKeyToArray(wszClass2, array, cKeys);
|
|
|
|
|
|
|
|
if (RegGetValueW(HKEY_CLASSES_ROOT, extension, L"PerceivedType ", RRF_RT_REG_SZ, NULL, wszClass, &dwSize) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
swprintf(wszClass2, L"SystemFileAssociations//%s", wszClass);
|
|
|
|
AddClassKeyToArray(wszClass2, array, cKeys);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AddClassKeyToArray(L"AllFilesystemObjects", array, cKeys);
|
|
|
|
AddClassKeyToArray(L"*", array, cKeys);
|
|
|
|
}
|
|
|
|
else if (_ILIsFolder(pidl))
|
|
|
|
{
|
|
|
|
AddClassKeyToArray(L"AllFilesystemObjects", array, cKeys);
|
|
|
|
AddClassKeyToArray(L"Directory", array, cKeys);
|
|
|
|
AddClassKeyToArray(L"Folder", array, cKeys);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("Got non FS pidl\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-17 14:35:19 +00:00
|
|
|
HRESULT SH_GetApidlFromDataObject(IDataObject *pDataObject, PIDLIST_ABSOLUTE* ppidlfolder, PUITEMID_CHILD **apidlItems, UINT *pcidl)
|
|
|
|
{
|
|
|
|
UINT cfShellIDList = RegisterClipboardFormatW(CFSTR_SHELLIDLIST);
|
|
|
|
if (!cfShellIDList)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
FORMATETC fmt;
|
|
|
|
InitFormatEtc (fmt, cfShellIDList, TYMED_HGLOBAL);
|
|
|
|
|
|
|
|
HRESULT hr = pDataObject->QueryGetData(&fmt);
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
STGMEDIUM medium;
|
|
|
|
hr = pDataObject->GetData(&fmt, &medium);
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
/* lock the handle */
|
|
|
|
LPIDA lpcida = (LPIDA)GlobalLock(medium.hGlobal);
|
|
|
|
if (!lpcida)
|
|
|
|
{
|
|
|
|
ReleaseStgMedium(&medium);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* convert the data into pidl */
|
|
|
|
LPITEMIDLIST pidl;
|
|
|
|
LPITEMIDLIST *apidl = _ILCopyCidaToaPidl(&pidl, lpcida);
|
|
|
|
if (!apidl)
|
|
|
|
{
|
|
|
|
ReleaseStgMedium(&medium);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ppidlfolder = pidl;
|
|
|
|
*apidlItems = apidl;
|
|
|
|
*pcidl = lpcida->cidl;
|
|
|
|
|
|
|
|
ReleaseStgMedium(&medium);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-15 15:55:49 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* SHCreateLinks
|
|
|
|
*
|
|
|
|
* Undocumented.
|
|
|
|
*/
|
2014-08-20 00:39:40 +00:00
|
|
|
HRESULT WINAPI SHCreateLinks( HWND hWnd, LPCSTR lpszDir, IDataObject * lpDataObject,
|
2011-05-15 15:55:49 +00:00
|
|
|
UINT uFlags, LPITEMIDLIST *lppidlLinks)
|
|
|
|
{
|
2014-08-20 00:39:40 +00:00
|
|
|
FIXME("%p %s %p %08x %p\n", hWnd, lpszDir, lpDataObject, uFlags, lppidlLinks);
|
2011-05-15 15:55:49 +00:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* SHOpenFolderAndSelectItems
|
|
|
|
*
|
|
|
|
* Unimplemented.
|
|
|
|
*/
|
|
|
|
EXTERN_C HRESULT
|
|
|
|
WINAPI
|
|
|
|
SHOpenFolderAndSelectItems(LPITEMIDLIST pidlFolder,
|
|
|
|
UINT cidl,
|
|
|
|
PCUITEMID_CHILD_ARRAY apidl,
|
|
|
|
DWORD dwFlags)
|
|
|
|
{
|
2016-11-06 21:51:46 +00:00
|
|
|
ERR("SHOpenFolderAndSelectItems() is hackplemented\n");
|
|
|
|
PCIDLIST_ABSOLUTE pidlItem;
|
|
|
|
if (cidl)
|
2016-11-06 22:25:02 +00:00
|
|
|
{
|
|
|
|
/* Firefox sends a full pidl here dispite the fact it is a PCUITEMID_CHILD_ARRAY -_- */
|
|
|
|
if (ILGetNext(apidl[0]) != NULL)
|
|
|
|
{
|
|
|
|
pidlItem = apidl[0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pidlItem = ILCombine(pidlFolder, apidl[0]);
|
|
|
|
}
|
|
|
|
}
|
2016-11-06 21:51:46 +00:00
|
|
|
else
|
2016-11-06 22:25:02 +00:00
|
|
|
{
|
2016-11-06 21:51:46 +00:00
|
|
|
pidlItem = pidlFolder;
|
2016-11-06 22:25:02 +00:00
|
|
|
}
|
2016-11-06 21:51:46 +00:00
|
|
|
|
|
|
|
CComPtr<IShellFolder> psfDesktop;
|
|
|
|
|
|
|
|
HRESULT hr = SHGetDesktopFolder(&psfDesktop);
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
STRRET strret;
|
|
|
|
hr = psfDesktop->GetDisplayNameOf(pidlItem, SHGDN_FORPARSING, &strret);
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
WCHAR wszBuf[MAX_PATH];
|
|
|
|
hr = StrRetToBufW(&strret, pidlItem, wszBuf, _countof(wszBuf));
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
WCHAR wszParams[MAX_PATH];
|
|
|
|
wcscpy(wszParams, L"/select,");
|
|
|
|
wcscat(wszParams, wszBuf);
|
|
|
|
|
|
|
|
SHELLEXECUTEINFOW sei;
|
|
|
|
memset(&sei, 0, sizeof sei);
|
|
|
|
sei.cbSize = sizeof sei;
|
|
|
|
sei.fMask = SEE_MASK_WAITFORINPUTIDLE;
|
|
|
|
sei.lpFile = L"explorer.exe";
|
|
|
|
sei.lpParameters = wszParams;
|
|
|
|
|
|
|
|
if (ShellExecuteExW(&sei))
|
|
|
|
return S_OK;
|
|
|
|
else
|
|
|
|
return E_FAIL;
|
2011-05-15 15:55:49 +00:00
|
|
|
}
|