From 72a9b73970c8a492779cfd469f1f157ba3b21d66 Mon Sep 17 00:00:00 2001 From: Giannis Adamopoulos Date: Sun, 1 May 2016 19:54:23 +0000 Subject: [PATCH] [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 --- reactos/dll/win32/shell32/folders.cpp | 51 +++++-------------- .../shell32/folders/CControlPanelFolder.cpp | 13 ++--- .../win32/shell32/folders/CDesktopFolder.cpp | 16 ++---- .../win32/shell32/folders/CDrivesFolder.cpp | 16 ++---- .../dll/win32/shell32/folders/CFSFolder.cpp | 16 ++---- reactos/dll/win32/shell32/wine/shell32_main.h | 3 +- 6 files changed, 25 insertions(+), 90 deletions(-) diff --git a/reactos/dll/win32/shell32/folders.cpp b/reactos/dll/win32/shell32/folders.cpp index 3f63329f759..da89ff660e2 100644 --- a/reactos/dll/win32/shell32/folders.cpp +++ b/reactos/dll/win32/shell32/folders.cpp @@ -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 initIcon; - CComPtr 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 extractIconW; - CComPtr 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); } diff --git a/reactos/dll/win32/shell32/folders/CControlPanelFolder.cpp b/reactos/dll/win32/shell32/folders/CControlPanelFolder.cpp index 661b1470058..36a52ed57ab 100644 --- a/reactos/dll/win32/shell32/folders/CControlPanelFolder.cpp +++ b/reactos/dll/win32/shell32/folders/CControlPanelFolder.cpp @@ -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 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)) { diff --git a/reactos/dll/win32/shell32/folders/CDesktopFolder.cpp b/reactos/dll/win32/shell32/folders/CDesktopFolder.cpp index cd336cee56d..0494c7350ad 100644 --- a/reactos/dll/win32/shell32/folders/CDesktopFolder.cpp +++ b/reactos/dll/win32/shell32/folders/CDesktopFolder.cpp @@ -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)) { diff --git a/reactos/dll/win32/shell32/folders/CDrivesFolder.cpp b/reactos/dll/win32/shell32/folders/CDrivesFolder.cpp index f1bf2fa018b..4066af6ef2b 100644 --- a/reactos/dll/win32/shell32/folders/CDrivesFolder.cpp +++ b/reactos/dll/win32/shell32/folders/CDrivesFolder.cpp @@ -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)) { diff --git a/reactos/dll/win32/shell32/folders/CFSFolder.cpp b/reactos/dll/win32/shell32/folders/CFSFolder.cpp index 4a76d0a8cd6..7944c9005fe 100644 --- a/reactos/dll/win32/shell32/folders/CFSFolder.cpp +++ b/reactos/dll/win32/shell32/folders/CFSFolder.cpp @@ -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)) { diff --git a/reactos/dll/win32/shell32/wine/shell32_main.h b/reactos/dll/win32/shell32/wine/shell32_main.h index 1622d49a54d..dbc93ce970f 100644 --- a/reactos/dll/win32/shell32/wine/shell32_main.h +++ b/reactos/dll/win32/shell32/wine/shell32_main.h @@ -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) \ -- 2.17.1