SHELL32: fix SHSimpleIDListFromPath to do the correct thing for non-existing pathes

Mike McCormack mike at codeweavers.com
Wed Feb 23 21:17:32 CST 2005


ChangeLog:
* fix SHSimpleIDListFromPath to do the correct thing for non-existing pathes
-------------- next part --------------
Index: dlls/shell32/pidl.c
===================================================================
RCS file: /home/wine/wine/dlls/shell32/pidl.c,v
retrieving revision 1.127
diff -u -p -r1.127 pidl.c
--- dlls/shell32/pidl.c	22 Feb 2005 14:50:35 -0000	1.127
+++ dlls/shell32/pidl.c	24 Feb 2005 03:17:43 -0000
@@ -963,71 +963,6 @@ LPITEMIDLIST WINAPI ILCreateFromPathAW (
     return ILCreateFromPathA (path);
 }
 
-/*************************************************************************
- * _ILParsePathW             [internal]
- *
- * Creates an ItemIDList from a path and returns it.
- *
- * PARAMS
- *  path         [I]   path to parse and convert into an ItemIDList
- *  lpFindFile   [I]   pointer to buffer to initialize the FileSystem
- *                     Bind Data object with
- *  bBindCtx     [I]   indicates to create a BindContext and assign a
- *                     FileSystem Bind Data object
- *  ppidl        [O]   the newly create ItemIDList
- *  prgfInOut    [I/O] requested attributes on input and actual
- *                     attributes on return
- *
- * RETURNS
- *  NO_ERROR on success or an OLE error code
- *
- * NOTES
- *  If either lpFindFile is non-NULL or bBindCtx is TRUE, this function
- *  creates a BindContext object and assigns a FileSystem Bind Data object
- *  to it, passing the BindContext to IShellFolder_ParseDisplayName. Each
- *  IShellFolder uses that FileSystem Bind Data object of the BindContext
- *  to pass data about the current path element to the next object. This
- *  is used to avoid having to verify the current path element on disk, so
- *  that creating an ItemIDList from a nonexistent path still can work.
- */
-static HRESULT WINAPI _ILParsePathW(LPCWSTR path, LPWIN32_FIND_DATAW lpFindFile,
-                             BOOL bBindCtx, LPITEMIDLIST *ppidl, LPDWORD prgfInOut)
-{
-    LPSHELLFOLDER pSF = NULL;
-    LPBC pBC = NULL;
-    HRESULT ret;
-
-    TRACE("%s %p %d (%p)->%p (%p)->0x%lx\n", debugstr_w(path), lpFindFile, bBindCtx,
-                                             ppidl, ppidl ? *ppidl : NULL,
-                                             prgfInOut, prgfInOut ? *prgfInOut : 0);
-
-    ret = SHGetDesktopFolder(&pSF);
-    if (FAILED(ret))
-        return ret;
-
-    if (lpFindFile || bBindCtx)
-        ret = IFileSystemBindData_Constructor(lpFindFile, &pBC);
-
-    if (SUCCEEDED(ret))
-    {
-        ret = IShellFolder_ParseDisplayName(pSF, 0, pBC, (LPOLESTR)path, NULL, ppidl, prgfInOut);
-    }
-
-    if (pBC)
-    {
-        IBindCtx_Release(pBC);
-        pBC = NULL;
-    }
-
-    IShellFolder_Release(pSF);
-
-    if (!SUCCEEDED(ret) && ppidl)
-        *ppidl = NULL;
-
-    TRACE("%s %p 0x%lx\n", debugstr_w(path), ppidl ? *ppidl : NULL, prgfInOut ? *prgfInOut : 0);
-
-    return ret;
-}
 
 /*************************************************************************
  * SHSimpleIDListFromPath    [SHELL32.162]
@@ -1047,8 +982,55 @@ static HRESULT WINAPI _ILParsePathW(LPCW
  *  directory flag for those ItemID elements this is known about, eg.
  *  it is not the last element in the ItemIDList or the actual directory
  *  exists on disk.
- *  exported by ordinal.
+ *  Exported by ordinal.
  */
+LPITEMIDLIST WINAPI SHSimpleIDListFromPathW(LPCWSTR path)
+{
+    static const WCHAR szfsbc[] = { 
+        'F','i','l','e',' ','S','y','s','t','e','m',' ',
+        'B','i','n','d',' ','D','a','t','a',0 };
+    IFileSystemBindData *pfsbd = NULL;
+    LPITEMIDLIST pidl = NULL;
+    LPSHELLFOLDER psf = NULL;
+    LPBC pbc = NULL;
+    HRESULT r;
+
+    TRACE("%s\n", debugstr_w(path));
+
+    r = SHGetDesktopFolder(&psf);
+    if (FAILED(r))
+        goto end;
+
+    r = CreateBindCtx(0, &pbc);
+    if (FAILED(r))
+        goto end;
+    
+    pfsbd = IFileSystemBindData_Constructor();
+    if (!pfsbd)
+        goto end;
+
+    r = IBindCtx_RegisterObjectParam(pbc, (LPOLESTR) szfsbc, (IUnknown*) pfsbd);
+    if (FAILED(r))
+        goto end;
+
+    r = IShellFolder_ParseDisplayName( psf, 0, pbc, (LPOLESTR)path,
+                                       NULL, &pidl, NULL );
+
+end:
+    if (pfsbd)
+        IFileSystemBindData_Release(pfsbd);
+
+    if (pbc)
+        IBindCtx_Release(pbc);
+
+    if (psf)
+        IShellFolder_Release(psf);
+
+    TRACE("%s -> %p\n", debugstr_w(path), pidl);
+
+    return pidl;
+}
+
 LPITEMIDLIST WINAPI SHSimpleIDListFromPathA(LPCSTR lpszPath)
 {
     LPITEMIDLIST pidl = NULL;
@@ -1064,21 +1046,8 @@ LPITEMIDLIST WINAPI SHSimpleIDListFromPa
         MultiByteToWideChar(CP_ACP, 0, lpszPath, -1, wPath, len);
     }
 
-    _ILParsePathW(wPath, NULL, TRUE, &pidl, NULL);
-
+    pidl = SHSimpleIDListFromPathW(wPath);
     HeapFree(GetProcessHeap(), 0, wPath);
-    TRACE("%s %p\n", debugstr_a(lpszPath), pidl);
-    return pidl;
-}
-
-LPITEMIDLIST WINAPI SHSimpleIDListFromPathW(LPCWSTR lpszPath)
-{
-    LPITEMIDLIST pidl = NULL;
-
-    TRACE("%s\n", debugstr_w(lpszPath));
-
-    _ILParsePathW(lpszPath, NULL, TRUE, &pidl, NULL);
-    TRACE("%s %p\n", debugstr_w(lpszPath), pidl);
     return pidl;
 }
 
Index: dlls/shell32/shell32_main.h
===================================================================
RCS file: /home/wine/wine/dlls/shell32/shell32_main.h,v
retrieving revision 1.92
diff -u -p -r1.92 shell32_main.h
--- dlls/shell32/shell32_main.h	21 Oct 2004 19:59:46 -0000	1.92
+++ dlls/shell32/shell32_main.h	24 Feb 2005 03:17:43 -0000
@@ -90,7 +90,7 @@ HRESULT WINAPI IShellLink_ConstructFromF
 HRESULT WINAPI ISF_Desktop_Constructor(IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv);
 HRESULT WINAPI ISF_MyComputer_Constructor(IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv);
 HRESULT WINAPI IDropTargetHelper_Constructor (IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv);
-HRESULT WINAPI IFileSystemBindData_Constructor(const WIN32_FIND_DATAW *pfd, LPBC *ppV);
+extern IFileSystemBindData* IFileSystemBindData_Constructor(void);
 HRESULT WINAPI IControlPanel_Constructor(IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv);
 HRESULT WINAPI CPanel_GetIconLocationA(LPITEMIDLIST pidl, LPSTR szIconFile, UINT cchMax, int* piIndex);
 HRESULT WINAPI CPanel_GetIconLocationW(LPITEMIDLIST pidl, LPWSTR szIconFile, UINT cchMax, int* piIndex);
Index: dlls/shell32/shlfsbind.c
===================================================================
RCS file: /home/wine/wine/dlls/shell32/shlfsbind.c,v
retrieving revision 1.13
diff -u -p -r1.13 shlfsbind.c
--- dlls/shell32/shlfsbind.c	23 Feb 2005 15:41:39 -0000	1.13
+++ dlls/shell32/shlfsbind.c	24 Feb 2005 03:17:43 -0000
@@ -47,129 +47,24 @@ typedef struct
     WIN32_FIND_DATAW findFile;
 } IFileSystemBindDataImpl;
 
-static HRESULT WINAPI IFileSystemBindData_fnQueryInterface(IFileSystemBindData *, REFIID, LPVOID*);
-static ULONG WINAPI IFileSystemBindData_fnAddRef(IFileSystemBindData *);
-static ULONG WINAPI IFileSystemBindData_fnRelease(IFileSystemBindData *);
-static HRESULT WINAPI IFileSystemBindData_fnGetFindData(IFileSystemBindData *, WIN32_FIND_DATAW *);
-static HRESULT WINAPI IFileSystemBindData_fnSetFindData(IFileSystemBindData *, const WIN32_FIND_DATAW *);
-
-static struct IFileSystemBindDataVtbl sbvt =
-{
-    IFileSystemBindData_fnQueryInterface,
-    IFileSystemBindData_fnAddRef,
-    IFileSystemBindData_fnRelease,
-    IFileSystemBindData_fnSetFindData,
-    IFileSystemBindData_fnGetFindData,
-};
-
-static const WCHAR wFileSystemBindData[] = {
-    'F','i','l','e',' ','S','y','s','t','e','m',' ','B','i','n','d','D','a','t','a',0};
-
-HRESULT WINAPI IFileSystemBindData_Constructor(const WIN32_FIND_DATAW *pfd, LPBC *ppV)
-{
-    IFileSystemBindDataImpl *sb;
-    HRESULT ret = E_OUTOFMEMORY;
-
-    TRACE("%p, %p\n", pfd, ppV);
-
-    if (!ppV)
-       return E_INVALIDARG;
-
-    *ppV = NULL;
-
-    sb = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IFileSystemBindDataImpl));
-    if (!sb)
-        return ret;
-
-    sb->lpVtbl = &sbvt;
-    sb->ref = 1;
-    IFileSystemBindData_fnSetFindData((IFileSystemBindData*)sb, pfd);
-
-    ret = CreateBindCtx(0, ppV);
-    if (SUCCEEDED(ret))
-    {
-        BIND_OPTS bindOpts;
-
-        bindOpts.cbStruct = sizeof(BIND_OPTS);
-        bindOpts.grfFlags = 0;
-        bindOpts.grfMode = STGM_CREATE;
-        bindOpts.dwTickCountDeadline = 0;
-        IBindCtx_SetBindOptions(*ppV, &bindOpts);
-        IBindCtx_RegisterObjectParam(*ppV, (LPOLESTR)wFileSystemBindData, (LPUNKNOWN)sb);
-
-        IFileSystemBindData_Release((IFileSystemBindData*)sb);
-    }
-    else
-        HeapFree(GetProcessHeap(), 0, sb);
-    return ret;
-}
-
-HRESULT WINAPI FileSystemBindData_GetFindData(LPBC pbc, WIN32_FIND_DATAW *pfd)
-{
-    LPUNKNOWN pUnk;
-    IFileSystemBindData *pfsbd = NULL;
-    HRESULT ret;
-
-    TRACE("%p, %p\n", pbc, pfd);
-
-    if (!pfd)
-        return E_INVALIDARG;
-
-    ret = IBindCtx_GetObjectParam(pbc, (LPOLESTR)wFileSystemBindData, &pUnk);
-    if (SUCCEEDED(ret))
-    {
-        ret = IUnknown_QueryInterface(pUnk, &IID_IFileSystemBindData, (LPVOID *)&pfsbd);
-        if (SUCCEEDED(ret))
-        {
-            ret = IFileSystemBindData_GetFindData(pfsbd, pfd);
-            IFileSystemBindData_Release(pfsbd);
-        }
-        IUnknown_Release(pUnk);
-    }
-    return ret;
-}
-
-HRESULT WINAPI FileSystemBindData_SetFindData(LPBC pbc, const WIN32_FIND_DATAW *pfd)
-{
-    LPUNKNOWN pUnk;
-    IFileSystemBindData *pfsbd = NULL;
-    HRESULT ret;
-    
-    TRACE("%p, %p\n", pbc, pfd);
-
-    ret = IBindCtx_GetObjectParam(pbc, (LPOLESTR)wFileSystemBindData, &pUnk);
-    if (SUCCEEDED(ret))
-    {
-        ret = IUnknown_QueryInterface(pUnk, &IID_IFileSystemBindData, (LPVOID *)&pfsbd);
-        if (SUCCEEDED(ret))
-        {
-            ret = IFileSystemBindData_SetFindData(pfsbd, pfd);
-            IFileSystemBindData_Release(pfsbd);
-        }
-        IUnknown_Release(pUnk);
-    }
-    return ret;
-}
-
 static HRESULT WINAPI IFileSystemBindData_fnQueryInterface(
                 IFileSystemBindData *iface, REFIID riid, LPVOID *ppV)
 {
     IFileSystemBindDataImpl *This = (IFileSystemBindDataImpl *)iface;
+
     TRACE("(%p)->(\n\tIID:\t%s, %p)\n", This, debugstr_guid(riid), ppV);
 
     *ppV = NULL;
 
-    if (IsEqualIID(riid, &IID_IUnknown))
-        *ppV = This;
-    else if (IsEqualIID(riid, &IID_IFileSystemBindData))
-        *ppV = (IFileSystemBindData*)This;
-
-    if (*ppV)
+    if (IsEqualIID(riid, &IID_IUnknown) ||
+        IsEqualIID(riid, &IID_IFileSystemBindData))
     {
-        IUnknown_AddRef((IUnknown*)(*ppV));
-        TRACE("-- Interface: (%p)->(%p)\n", ppV, *ppV);
+        *ppV = This;
+        IUnknown_AddRef((IUnknown*)This);
+        TRACE("-- Interface: (%p)->(%p)\n", ppV, This);
         return S_OK;
     }
+
     TRACE("-- Interface: E_NOINTERFACE\n");
     return E_NOINTERFACE;
 }
@@ -223,4 +118,29 @@ static HRESULT WINAPI IFileSystemBindDat
     else
         memset(&This->findFile, 0, sizeof(WIN32_FIND_DATAW));
     return NOERROR;
+}
+
+static struct IFileSystemBindDataVtbl sbvt =
+{
+    IFileSystemBindData_fnQueryInterface,
+    IFileSystemBindData_fnAddRef,
+    IFileSystemBindData_fnRelease,
+    IFileSystemBindData_fnSetFindData,
+    IFileSystemBindData_fnGetFindData,
+};
+
+IFileSystemBindData* IFileSystemBindData_Constructor(void)
+{
+    IFileSystemBindDataImpl *sb;
+
+    TRACE("\n");
+
+    sb = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IFileSystemBindDataImpl));
+    if (!sb)
+        return NULL;
+
+    sb->lpVtbl = &sbvt;
+    sb->ref = 1;
+
+    return (IFileSystemBindData*) sb;
 }


More information about the wine-patches mailing list