[Wine-patches] [eterhack] [eter-1.0.12] shell32: Improve FolderItem::get_Path implementation.

Alexander Morozov amorozov на etersoft.ru
Ср Фев 2 21:51:55 MSK 2011


----------- следующая часть -----------
From cad5d20a493ea6fd4715958705cf4d41f917be86 Mon Sep 17 00:00:00 2001
From: Alexander Morozov <amorozov на etersoft.ru>
Date: Wed, 2 Feb 2011 21:38:15 +0300
Subject: [PATCH 2/2] shell32: Improve FolderItem::get_Path implementation.

---
 dlls/shell32/shelldispatch.c |   58 ++++++++++++++++++++++++++----------------
 1 files changed, 36 insertions(+), 22 deletions(-)

diff --git a/dlls/shell32/shelldispatch.c b/dlls/shell32/shelldispatch.c
index bef14d8..4aa7159 100644
--- a/dlls/shell32/shelldispatch.c
+++ b/dlls/shell32/shelldispatch.c
@@ -56,7 +56,7 @@ typedef struct {
     FolderItem FolderItem_iface;
     LONG ref;
     ITypeInfo *iTypeInfo;
-    BSTR path;
+    VARIANT dir;
 } FolderItemImpl;
 
 static inline ShellDispatch *impl_from_IShellDispatch(IShellDispatch *iface)
@@ -136,7 +136,7 @@ static ULONG WINAPI FolderItemImpl_Release(FolderItem *iface)
 
     if (!ref)
     {
-        SysFreeString(This->path);
+        VariantClear(&This->dir);
         ITypeInfo_Release(This->iTypeInfo);
         HeapFree(GetProcessHeap(), 0, This);
     }
@@ -226,11 +226,37 @@ static HRESULT WINAPI FolderItemImpl_put_Name(FolderItem *iface, BSTR bs)
 static HRESULT WINAPI FolderItemImpl_get_Path(FolderItem *iface, BSTR *pbs)
 {
     FolderItemImpl *This = impl_from_FolderItem(iface);
+    HRESULT ret = S_OK;
+    WCHAR *pathW;
+    int len;
 
     TRACE("(%p,%p)\n", iface, pbs);
 
-    *pbs = SysAllocString(This->path);
-    return *pbs ? S_OK : E_OUTOFMEMORY;
+    *pbs = NULL;
+    if (V_VT(&This->dir) == VT_I4)
+    {
+        pathW = HeapAlloc(GetProcessHeap(), 0, MAX_PATH * sizeof(WCHAR));
+        if (!pathW) return E_OUTOFMEMORY;
+        ret = SHGetFolderPathW(NULL, V_I4(&This->dir), NULL, SHGFP_TYPE_CURRENT,
+                pathW);
+        if (ret == S_OK)
+            *pbs = SysAllocString(pathW);
+        else if (ret == E_INVALIDARG)
+        {
+            FIXME("not implemented for %#x\n", V_I4(&This->dir));
+            ret = E_NOTIMPL;
+        }
+        HeapFree(GetProcessHeap(), 0, pathW);
+    }
+    else /* VT_BSTR */
+    {
+        pathW = V_BSTR(&This->dir);
+        len = lstrlenW(pathW);
+        *pbs = SysAllocStringLen(pathW, pathW[len - 1] == '\\' ? len - 1 : len);
+    }
+    if (ret == S_OK && !*pbs)
+        ret = E_OUTOFMEMORY;
+    return ret;
 }
 
 static HRESULT WINAPI FolderItemImpl_get_GetLink(FolderItem *iface,
@@ -357,7 +383,7 @@ static const FolderItemVtbl FolderItemImpl_Vtbl = {
     FolderItemImpl_InvokeVerb
 };
 
-static HRESULT FolderItem_Constructor(BSTR path, FolderItem **ppfi)
+static HRESULT FolderItem_Constructor(VARIANT *dir, FolderItem **ppfi)
 {
     FolderItemImpl *This;
     HRESULT ret;
@@ -376,9 +402,11 @@ static HRESULT FolderItem_Constructor(BSTR path, FolderItem **ppfi)
         return ret;
     }
 
-    This->path = SysAllocString(path);
-    if (!This->path)
+    VariantInit(&This->dir);
+    ret = VariantCopy(&This->dir, dir);
+    if (FAILED(ret))
     {
+        ITypeInfo_Release(This->iTypeInfo);
         HeapFree(GetProcessHeap(), 0, This);
         return E_OUTOFMEMORY;
     }
@@ -582,24 +610,10 @@ static HRESULT WINAPI FolderImpl_GetDetailsOf(Folder3 *iface, VARIANT vItem,
 static HRESULT WINAPI FolderImpl_get_Self(Folder3 *iface, FolderItem **ppfi)
 {
     FolderImpl *This = impl_from_Folder(iface);
-    WCHAR *pathW;
-    HRESULT ret;
 
     TRACE("(%p,%p)\n", iface, ppfi);
 
-    if (V_VT(&This->dir) == VT_I4)
-    {
-        pathW = HeapAlloc(GetProcessHeap(), 0, MAX_PATH * sizeof(WCHAR));
-        if (!pathW) return E_OUTOFMEMORY;
-        ret = SHGetFolderPathW(NULL, V_I4(&This->dir), NULL, SHGFP_TYPE_CURRENT,
-                pathW);
-        if (ret == S_OK)
-            ret = FolderItem_Constructor(pathW, ppfi);
-        HeapFree(GetProcessHeap(), 0, pathW);
-    }
-    else
-        ret = FolderItem_Constructor(V_BSTR(&This->dir), ppfi);
-    return ret;
+    return FolderItem_Constructor(&This->dir, ppfi);
 }
 
 static HRESULT WINAPI FolderImpl_get_OfflineStatus(Folder3 *iface, LONG *pul)
-- 
1.7.3.5



Подробная информация о списке рассылки Wine-patches