[SHELL32]
authorGiannis Adamopoulos <gadamopoulos@reactos.org>
Sun, 1 May 2016 19:54:23 +0000 (19:54 +0000)
committerGiannis Adamopoulos <gadamopoulos@reactos.org>
Sun, 1 May 2016 19:54:23 +0000 (19:54 +0000)
- 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
reactos/dll/win32/shell32/folders/CControlPanelFolder.cpp
reactos/dll/win32/shell32/folders/CDesktopFolder.cpp
reactos/dll/win32/shell32/folders/CDrivesFolder.cpp
reactos/dll/win32/shell32/folders/CFSFolder.cpp
reactos/dll/win32/shell32/wine/shell32_main.h

index 3f63329..da89ff6 100644 (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);
 }
index 661b147..36a52ed 100644 (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)) {
index cd336ce..0494c73 100644 (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))
     {
index f1bf2fa..4066af6 100644 (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))
     {
index 4a76d0a..7944c90 100644 (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))
         {
index 1622d49..dbc93ce 100644 (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) \