[PATCH v2 2/3] shell32: Implement FolderItems_Item.
Alex Henrie
alexhenrie24 at gmail.com
Thu Jul 21 22:51:09 CDT 2016
Signed-off-by: Alex Henrie <alexhenrie24 at gmail.com>
---
dlls/shell32/shelldispatch.c | 83 +++++++++++++++++++++++++++++++++++---
dlls/shell32/tests/shelldispatch.c | 17 +++++---
2 files changed, 89 insertions(+), 11 deletions(-)
diff --git a/dlls/shell32/shelldispatch.c b/dlls/shell32/shelldispatch.c
index ac79302..4b4c822 100644
--- a/dlls/shell32/shelldispatch.c
+++ b/dlls/shell32/shelldispatch.c
@@ -68,6 +68,8 @@ typedef struct {
typedef struct {
FolderItems3 FolderItems3_iface;
LONG ref;
+ BSTR *item_paths;
+ LONG item_count;
} FolderItemsImpl;
typedef struct {
@@ -989,11 +991,17 @@ static ULONG WINAPI FolderItemsImpl_Release(FolderItems3 *iface)
{
FolderItemsImpl *This = impl_from_FolderItems(iface);
ULONG ref = InterlockedDecrement(&This->ref);
+ int i;
TRACE("(%p), new refcount=%i\n", iface, ref);
if (!ref)
+ {
+ for (i = 0; i < This->item_count; i++)
+ SysFreeString(This->item_paths[i]);
+ HeapFree(GetProcessHeap(), 0, This->item_paths);
HeapFree(GetProcessHeap(), 0, This);
+ }
return ref;
}
@@ -1079,10 +1087,20 @@ static HRESULT WINAPI FolderItemsImpl_get_Parent(FolderItems3 *iface, IDispatch
static HRESULT WINAPI FolderItemsImpl_Item(FolderItems3 *iface, VARIANT index, FolderItem **ppid)
{
- FIXME("(%p,%s,%p)\n", iface, debugstr_variant(&index), ppid);
+ FolderItemsImpl *This = impl_from_FolderItems(iface);
+ VARIANT path;
+
+ TRACE("(%p,%s,%p)\n", iface, debugstr_variant(&index), ppid);
*ppid = NULL;
- return E_NOTIMPL;
+
+ if (V_I4(&index) >= This->item_count)
+ return S_FALSE;
+
+ V_VT(&path) = VT_BSTR;
+ V_BSTR(&path) = This->item_paths[V_I4(&index)];
+
+ return FolderItem_Constructor(&path, ppid);
}
static HRESULT WINAPI FolderItemsImpl__NewEnum(FolderItems3 *iface, IUnknown **ppunk)
@@ -1139,9 +1157,17 @@ static const FolderItems3Vtbl FolderItemsImpl_Vtbl = {
FolderItemsImpl_get_Verbs
};
-static HRESULT FolderItems_Constructor(FolderItems **ppfi)
+static HRESULT FolderItems_Constructor(VARIANT *dir, FolderItems **ppfi)
{
+ static const WCHAR backslash_star[] = {'\\','*',0};
+ static const WCHAR dot[] = {'.',0};
+ static const WCHAR dot_dot[] = {'.','.',0};
FolderItemsImpl *This;
+ WCHAR path[MAX_PATH];
+ HANDLE first_file;
+ WIN32_FIND_DATAW file_info;
+ BSTR *paths;
+ HRESULT ret = S_OK;
TRACE("\n");
@@ -1152,8 +1178,51 @@ static HRESULT FolderItems_Constructor(FolderItems **ppfi)
This->FolderItems3_iface.lpVtbl = &FolderItemsImpl_Vtbl;
This->ref = 1;
+ This->item_paths = HeapAlloc(GetProcessHeap(), 0, sizeof(BSTR));
+ if (!This->item_paths)
+ {
+ HeapFree(GetProcessHeap(), 0, This);
+ return E_OUTOFMEMORY;
+ }
+ This->item_count = 0;
+
+ lstrcpyW(path, V_BSTR(dir));
+ lstrcatW(path, backslash_star);
+ first_file = FindFirstFileW(path, &file_info);
+ if (first_file != INVALID_HANDLE_VALUE)
+ {
+ do
+ {
+ if (!lstrcmpW(file_info.cFileName, dot) || !lstrcmpW(file_info.cFileName, dot_dot))
+ continue;
+
+ if (!PathCombineW(path, V_BSTR(dir), file_info.cFileName))
+ {
+ ret = E_OUTOFMEMORY;
+ goto fail;
+ }
+
+ paths = HeapReAlloc(GetProcessHeap(), 0, This->item_paths, (This->item_count + 1) * sizeof(BSTR));
+ if (!paths)
+ {
+ ret = E_OUTOFMEMORY;
+ goto fail;
+ }
+ This->item_paths = paths;
+ This->item_paths[This->item_count] = SysAllocString(path);
+ This->item_count++;
+ }
+ while (FindNextFileW(first_file, &file_info));
+
+ FindClose(first_file);
+ }
+
*ppfi = (FolderItems*)&This->FolderItems3_iface;
- return S_OK;
+ return ret;
+
+fail:
+ FolderItems3_Release(&This->FolderItems3_iface);
+ return ret;
}
static HRESULT WINAPI FolderImpl_QueryInterface(Folder3 *iface, REFIID riid,
@@ -1308,9 +1377,11 @@ static HRESULT WINAPI FolderImpl_get_ParentFolder(Folder3 *iface, Folder **ppsf)
static HRESULT WINAPI FolderImpl_Items(Folder3 *iface, FolderItems **ppid)
{
- FIXME("(%p,%p)\n", iface, ppid);
+ FolderImpl *This = impl_from_Folder(iface);
+
+ TRACE("(%p,%p)\n", iface, ppid);
- return FolderItems_Constructor(ppid);
+ return FolderItems_Constructor(&This->dir, ppid);
}
static HRESULT WINAPI FolderImpl_ParseName(Folder3 *iface, BSTR name, FolderItem **item)
diff --git a/dlls/shell32/tests/shelldispatch.c b/dlls/shell32/tests/shelldispatch.c
index 03fa90d..be3db18 100644
--- a/dlls/shell32/tests/shelldispatch.c
+++ b/dlls/shell32/tests/shelldispatch.c
@@ -390,7 +390,6 @@ todo_wine
r = FolderItems_Item(items, var, NULL);
r = FolderItems_Item(items, var, &item);
-todo_wine
ok(r == S_FALSE, "expected S_FALSE, got %08x\n", r);
ok(!item, "item is not null\n");
@@ -460,11 +459,8 @@ todo_wine
item = NULL;
r = FolderItems_Item(items, var, &item);
-todo_wine
ok(r == S_OK, "file_defs[%d]: FolderItems::Item failed: %08x\n", i, r);
-todo_wine
ok(!!item, "file_defs[%d]: item is null\n", i);
- if (!item) continue;
r = FolderItems_Item(items, var, &item2);
ok(r == S_OK, "file_defs[%d]: FolderItems::Item failed: %08x\n", i, r);
@@ -473,13 +469,17 @@ todo_wine
disp = NULL;
r = FolderItem_get_Application(item, &disp);
+todo_wine
ok(r == S_OK, "file_defs[%d]: FolderItem::get_Application failed: %08x\n", i, r);
+todo_wine
ok(!!disp, "file_defs[%d]: disp is null\n", i);
if (disp) IDispatch_Release(disp);
disp = NULL;
r = FolderItem_get_Parent(item, &disp);
+todo_wine
ok(r == S_OK, "file_defs[%d]: FolderItem::get_Parent failed: %08x\n", i, r);
+todo_wine
ok(!!disp, "file_defs[%d]: disp is null\n", i);
if (disp) IDispatch_Release(disp);
@@ -501,7 +501,9 @@ todo_wine
r = FolderItem_get_GetLink(item, &disp);
if (!lstrcmpA(PathFindExtensionA(file_defs[i].name), ".lnk"))
{
+todo_wine
ok(r == S_OK, "file_defs[%d]: FolderItem::get_GetLink failed: %08x\n", i, r);
+todo_wine
ok(!!disp, "file_defs[%d]: disp is null\n", i);
}
else
@@ -516,11 +518,14 @@ todo_wine
r = FolderItem_get_GetFolder(item, &disp);
if (file_defs[i].type == DIRECTORY)
{
+todo_wine
ok(r == S_OK, "file_defs[%d]: FolderItem::get_GetFolder failed: %08x\n", i, r);
+todo_wine
ok(!!disp, "file_defs[%d]: disp is null\n", i);
}
else
{
+todo_wine
ok(r == E_FAIL || broken(r == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) /* xp */,
"file_defs[%d]: expected E_FAIL, got %08x\n", i, r);
ok(!disp, "file_defs[%d]: disp is not null\n", i);
@@ -529,10 +534,13 @@ todo_wine
lcount = -1;
r = FolderItem_get_Size(item, &lcount);
+todo_wine
ok(r == S_OK, "file_defs[%d]: FolderItem::get_Size failed: %08x\n", i, r);
if (file_defs[i].type == DIRECTORY || file_defs[i].type == EMPTY)
+todo_wine
ok(!lcount, "file_defs[%d]: got %d\n", i, lcount);
else
+todo_wine
ok(lcount > 0, "file_defs[%d]: got %d\n", i, lcount);
verbs = NULL;
@@ -547,7 +555,6 @@ todo_wine
V_I4(&var) = sizeof(file_defs)/sizeof(file_defs[0]);
item = NULL;
r = FolderItems_Item(items, var, &item);
-todo_wine
ok(r == S_FALSE, "expected S_FALSE, got %08x\n", r);
ok(!item, "item is not null\n");
--
2.9.0
More information about the wine-patches
mailing list