[SHELL32]

- Remove IExtractIconA_Constructor and rename IExtractIconW_Constructor to GenericExtractIcon_CreateInstance which will handle both A and W.
- Make GenericExtractIcon_CreateInstance accept a pointer to a IShellFolder and a simple pidl.
- Avoid using SHGetPathFromIDListW. Use ILGetDisplayNameExW instead. May make loading icons for folders and exe files slightly faster as it does fewer I/O and less allocations.

svn path=/trunk/; revision=71227
This commit is contained in:
Giannis Adamopoulos 2016-05-01 19:54:23 +00:00
parent 78280ad21f
commit 72a9b73970
6 changed files with 25 additions and 90 deletions

View file

@ -24,7 +24,7 @@ WCHAR swShell32Name[MAX_PATH];
DWORD NumIconOverlayHandlers = 0;
IShellIconOverlayIdentifier ** Handlers = NULL;
static HRESULT getIconLocationForFolder(LPCITEMIDLIST pidl, UINT uFlags,
static HRESULT getIconLocationForFolder(IShellFolder * psf, LPCITEMIDLIST pidl, UINT uFlags,
LPWSTR szIconFile, UINT cchMax, int *piIndex, UINT *pwFlags)
{
static const WCHAR shellClassInfo[] = { '.', 'S', 'h', 'e', 'l', 'l', 'C', 'l', 'a', 's', 's', 'I', 'n', 'f', 'o', 0 };
@ -39,7 +39,7 @@ static HRESULT getIconLocationForFolder(LPCITEMIDLIST pidl, UINT uFlags,
{
WCHAR wszFolderPath[MAX_PATH];
if (!SHGetPathFromIDListW(pidl, wszFolderPath))
if (!ILGetDisplayNameExW(psf, pidl, wszFolderPath, 0))
return FALSE;
PathAppendW(wszFolderPath, wszDesktopIni);
@ -192,28 +192,20 @@ GetIconOverlay(LPCITEMIDLIST pidl, WCHAR * wTemp, int* pIndex)
return FALSE;
}
/**************************************************************************
* IExtractIconW_Constructor
*/
IExtractIconW* IExtractIconW_Constructor(LPCITEMIDLIST pidl)
HRESULT GenericExtractIcon_CreateInstance(IShellFolder * psf, LPCITEMIDLIST pidl, REFIID iid, LPVOID * ppvOut)
{
CComPtr<IDefaultExtractIconInit> initIcon;
CComPtr<IExtractIconW> extractIcon;
GUID const * riid;
int icon_idx;
UINT flags;
CHAR sTemp[MAX_PATH];
WCHAR wTemp[MAX_PATH];
LPITEMIDLIST pSimplePidl = ILFindLastID(pidl);
LPCITEMIDLIST pSimplePidl = pidl;
HRESULT hr;
hr = SHCreateDefaultExtractIcon(IID_PPV_ARG(IDefaultExtractIconInit,&initIcon));
if (FAILED(hr))
return NULL;
hr = initIcon->QueryInterface(IID_PPV_ARG(IExtractIconW,&extractIcon));
if (FAILED(hr))
return NULL;
return hr;
if (_ILIsDesktop(pSimplePidl))
{
@ -321,7 +313,7 @@ IExtractIconW* IExtractIconW_Constructor(LPCITEMIDLIST pidl)
else if (_ILIsFolder (pSimplePidl))
{
if (SUCCEEDED(getIconLocationForFolder(
if (SUCCEEDED(getIconLocationForFolder(psf,
pidl, 0, wTemp, MAX_PATH,
&icon_idx,
&flags)))
@ -332,21 +324,21 @@ IExtractIconW* IExtractIconW_Constructor(LPCITEMIDLIST pidl)
// the following line removed.
initIcon->SetShortcutIcon(wTemp, icon_idx);
}
if (SUCCEEDED(getIconLocationForFolder(
if (SUCCEEDED(getIconLocationForFolder(psf,
pidl, GIL_DEFAULTICON, wTemp, MAX_PATH,
&icon_idx,
&flags)))
{
initIcon->SetDefaultIcon(wTemp, icon_idx);
}
// if (SUCCEEDED(getIconLocationForFolder(
// if (SUCCEEDED(getIconLocationForFolder(psf,
// pidl, GIL_FORSHORTCUT, wTemp, MAX_PATH,
// &icon_idx,
// &flags)))
// {
// initIcon->SetShortcutIcon(wTemp, icon_idx);
// }
if (SUCCEEDED(getIconLocationForFolder(
if (SUCCEEDED(getIconLocationForFolder(psf,
pidl, GIL_OPENICON, wTemp, MAX_PATH,
&icon_idx,
&flags)))
@ -365,7 +357,7 @@ IExtractIconW* IExtractIconW_Constructor(LPCITEMIDLIST pidl)
{
if (!lstrcmpA("%1", sTemp)) /* icon is in the file */
{
SHGetPathFromIDListW(pidl, wTemp);
ILGetDisplayNameExW(psf, pidl, wTemp, 0);
icon_idx = 0;
}
else
@ -383,7 +375,7 @@ IExtractIconW* IExtractIconW_Constructor(LPCITEMIDLIST pidl)
if (SUCCEEDED(SHGetDesktopFolder(&dsf)))
{
HRESULT hr = dsf->GetUIObjectOf(NULL, 1, (LPCITEMIDLIST*) &pidl, IID_NULL_PPV_ARG(IShellLinkW, &psl));
HRESULT hr = dsf->GetUIObjectOf(NULL, 1, &pidl, IID_NULL_PPV_ARG(IShellLinkW, &psl));
if (SUCCEEDED(hr))
{
@ -404,24 +396,5 @@ IExtractIconW* IExtractIconW_Constructor(LPCITEMIDLIST pidl)
initIcon->SetNormalIcon(wTemp, icon_idx);
}
return extractIcon.Detach();
}
/**************************************************************************
* IExtractIconA_Constructor
*/
IExtractIconA* IExtractIconA_Constructor(LPCITEMIDLIST pidl)
{
CComPtr<IExtractIconW> extractIconW;
CComPtr<IExtractIconA> extractIconA;
HRESULT hr;
extractIconW = IExtractIconW_Constructor(pidl);
if (!extractIconW)
return NULL;
hr = extractIconW->QueryInterface(IID_PPV_ARG(IExtractIconA, &extractIconA));
if (FAILED(hr))
return NULL;
return extractIconA.Detach();
return initIcon->QueryInterface(iid, ppvOut);
}

View file

@ -125,19 +125,12 @@ static PIDLCPanelStruct *_ILGetCPanelPointer(LPCITEMIDLIST pidl)
return NULL;
}
HRESULT CCPLExtractIcon_CreateInstance(LPCITEMIDLIST pidlRoot, LPCITEMIDLIST pidl, REFIID riid, LPVOID * ppvOut)
HRESULT CCPLExtractIcon_CreateInstance(IShellFolder * psf, LPCITEMIDLIST pidl, REFIID riid, LPVOID * ppvOut)
{
PIDLCPanelStruct *pData = _ILGetCPanelPointer(pidl);
if (!pData)
{
LPITEMIDLIST pidlComplete = ILCombine(pidlRoot, pidl);
if (!pidlComplete)
return E_OUTOFMEMORY;
*ppvOut = IExtractIconW_Constructor(pidlComplete);
SHFree(pidlComplete);
return *ppvOut ? S_OK : E_FAIL;
return GenericExtractIcon_CreateInstance(psf, pidl, riid, ppvOut);
}
CComPtr<IDefaultExtractIconInit> initIcon;
@ -508,7 +501,7 @@ HRESULT WINAPI CControlPanelFolder::GetUIObjectOf(HWND hwndOwner,
} else if (IsEqualIID(riid, IID_IDataObject) && (cidl >= 1)) {
hr = IDataObject_Constructor(hwndOwner, pidlRoot, apidl, cidl, (IDataObject **)&pObj);
} else if ((IsEqualIID(riid, IID_IExtractIconA) || IsEqualIID(riid, IID_IExtractIconW)) && (cidl == 1)) {
hr = CCPLExtractIcon_CreateInstance(pidlRoot, apidl[0], riid, &pObj);
hr = CCPLExtractIcon_CreateInstance(this, apidl[0], riid, &pObj);
} else if ((IsEqualIID(riid, IID_IShellLinkW) || IsEqualIID(riid, IID_IShellLinkA))
&& (cidl == 1)) {

View file

@ -590,7 +590,7 @@ HRESULT WINAPI CDesktopFolder::GetUIObjectOf(
LPVOID *ppvOut)
{
LPITEMIDLIST pidl;
IUnknown *pObj = NULL;
LPVOID pObj = NULL;
HRESULT hr = E_INVALIDARG;
TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
@ -609,19 +609,9 @@ HRESULT WINAPI CDesktopFolder::GetUIObjectOf(
{
hr = IDataObject_Constructor( hwndOwner, pidlRoot, apidl, cidl, (IDataObject **)&pObj);
}
else if (IsEqualIID (riid, IID_IExtractIconA) && (cidl == 1))
else if ((IsEqualIID (riid, IID_IExtractIconA) || IsEqualIID (riid, IID_IExtractIconW)) && (cidl == 1))
{
pidl = ILCombine (pidlRoot, apidl[0]);
pObj = IExtractIconA_Constructor (pidl);
SHFree (pidl);
hr = S_OK;
}
else if (IsEqualIID (riid, IID_IExtractIconW) && (cidl == 1))
{
pidl = ILCombine (pidlRoot, apidl[0]);
pObj = IExtractIconW_Constructor (pidl);
SHFree (pidl);
hr = S_OK;
hr = GenericExtractIcon_CreateInstance(this, apidl[0], riid, &pObj);
}
else if (IsEqualIID (riid, IID_IDropTarget))
{

View file

@ -436,7 +436,7 @@ HRESULT WINAPI CDrivesFolder::GetUIObjectOf(HWND hwndOwner,
REFIID riid, UINT *prgfInOut, LPVOID *ppvOut)
{
LPITEMIDLIST pidl;
IUnknown *pObj = NULL;
LPVOID pObj = NULL;
HRESULT hr = E_INVALIDARG;
TRACE("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n", this,
@ -456,19 +456,9 @@ HRESULT WINAPI CDrivesFolder::GetUIObjectOf(HWND hwndOwner,
hr = IDataObject_Constructor (hwndOwner,
pidlRoot, apidl, cidl, (IDataObject **)&pObj);
}
else if (IsEqualIID (riid, IID_IExtractIconA) && (cidl == 1))
else if ((IsEqualIID (riid, IID_IExtractIconA) || IsEqualIID (riid, IID_IExtractIconW)) && (cidl == 1))
{
pidl = ILCombine (pidlRoot, apidl[0]);
pObj = IExtractIconA_Constructor (pidl);
SHFree (pidl);
hr = S_OK;
}
else if (IsEqualIID (riid, IID_IExtractIconW) && (cidl == 1))
{
pidl = ILCombine (pidlRoot, apidl[0]);
pObj = IExtractIconW_Constructor (pidl);
SHFree (pidl);
hr = S_OK;
hr = GenericExtractIcon_CreateInstance(this, apidl[0], riid, &pObj);
}
else if (IsEqualIID (riid, IID_IDropTarget) && (cidl >= 1))
{

View file

@ -488,7 +488,7 @@ HRESULT WINAPI CFSFolder::GetUIObjectOf(HWND hwndOwner,
LPVOID * ppvOut)
{
LPITEMIDLIST pidl;
IUnknown *pObj = NULL;
LPVOID pObj = NULL;
HRESULT hr = E_INVALIDARG;
TRACE ("(%p)->(%p,%u,apidl=%p,%s,%p,%p)\n",
@ -515,19 +515,9 @@ HRESULT WINAPI CFSFolder::GetUIObjectOf(HWND hwndOwner,
hr = IDataObject_Constructor (hwndOwner, pidlRoot, (LPCITEMIDLIST*)&pidlRoot, 1, (IDataObject **)&pObj);
}
}
else if (IsEqualIID (riid, IID_IExtractIconA) && (cidl == 1))
else if ((IsEqualIID (riid, IID_IExtractIconA) || IsEqualIID (riid, IID_IExtractIconW)) && (cidl == 1))
{
pidl = ILCombine (pidlRoot, apidl[0]);
pObj = IExtractIconA_Constructor (pidl);
SHFree (pidl);
hr = S_OK;
}
else if (IsEqualIID (riid, IID_IExtractIconW) && (cidl == 1))
{
pidl = ILCombine (pidlRoot, apidl[0]);
pObj = IExtractIconW_Constructor (pidl);
SHFree (pidl);
hr = S_OK;
hr = GenericExtractIcon_CreateInstance(this, apidl[0], riid, &pObj);
}
else if (IsEqualIID (riid, IID_IDropTarget))
{

View file

@ -79,8 +79,7 @@ HRESULT WINAPI IFileSystemBindData_Constructor(const WIN32_FIND_DATAW *pfd, LPBC
HRESULT WINAPI CPanel_ExtractIconA(LPITEMIDLIST pidl, LPCSTR pszFile, UINT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize) DECLSPEC_HIDDEN;
HRESULT WINAPI CPanel_ExtractIconW(LPITEMIDLIST pidl, LPCWSTR pszFile, UINT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize) DECLSPEC_HIDDEN;
LPEXTRACTICONA IExtractIconA_Constructor(LPCITEMIDLIST) DECLSPEC_HIDDEN;
LPEXTRACTICONW IExtractIconW_Constructor(LPCITEMIDLIST) DECLSPEC_HIDDEN;
HRESULT GenericExtractIcon_CreateInstance(IShellFolder * psf, LPCITEMIDLIST pidl, REFIID iid, LPVOID * ppvOut);
/* initialisation for FORMATETC */
#define InitFormatEtc(fe, cf, med) \