From 2ef383c01a4654683e167280aed5590e38f4ad1a Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Thu, 28 Sep 2017 11:25:44 +0300 Subject: [PATCH] shell32: Implement FolderItem::Name() property getter. Signed-off-by: Nikolay Sivov Signed-off-by: Alexandre Julliard --- dlls/shell32/shelldispatch.c | 36 ++++++++++++++++++++++++++---- dlls/shell32/tests/shelldispatch.c | 26 ++++++++++++++++++--- 2 files changed, 55 insertions(+), 7 deletions(-) diff --git a/dlls/shell32/shelldispatch.c b/dlls/shell32/shelldispatch.c index 3ff9ff09508..43e243e9210 100644 --- a/dlls/shell32/shelldispatch.c +++ b/dlls/shell32/shelldispatch.c @@ -748,12 +748,40 @@ static HRESULT WINAPI FolderItemImpl_get_Parent(FolderItem2 *iface, IDispatch ** return S_OK; } -static HRESULT WINAPI FolderItemImpl_get_Name(FolderItem2 *iface, BSTR *pbs) +static HRESULT WINAPI FolderItemImpl_get_Name(FolderItem2 *iface, BSTR *name) { - FIXME("(%p,%p)\n", iface, pbs); + FolderItemImpl *This = impl_from_FolderItem(iface); + LPCITEMIDLIST last_part; + IShellFolder2 *parent; + HRESULT hr = S_OK; + LPITEMIDLIST pidl; + STRRET strret; - *pbs = NULL; - return E_NOTIMPL; + TRACE("(%p,%p)\n", iface, name); + + *name = NULL; + + if (This->path) + hr = SHParseDisplayName(This->path, NULL, &pidl, 0, NULL); + else + pidl = This->folder->pidl; + + if (FAILED(hr)) + return S_FALSE; + + hr = SHBindToParent(pidl, &IID_IShellFolder2, (void **)&parent, &last_part); + if (hr == S_OK) + hr = IShellFolder2_GetDisplayNameOf(parent, last_part, SHGDN_INFOLDER, &strret); + + IShellFolder2_Release(parent); + + if (hr == S_OK) + hr = StrRetToBSTR(&strret, last_part, name); + + if (This->path) + ILFree(pidl); + + return hr; } static HRESULT WINAPI FolderItemImpl_put_Name(FolderItem2 *iface, BSTR bs) diff --git a/dlls/shell32/tests/shelldispatch.c b/dlls/shell32/tests/shelldispatch.c index 462be18e5a5..3735c9b47fb 100644 --- a/dlls/shell32/tests/shelldispatch.c +++ b/dlls/shell32/tests/shelldispatch.c @@ -49,12 +49,22 @@ static HRESULT (WINAPI *pSHGetNameFromIDList)(PCIDLIST_ABSOLUTE,SIGDN,PWSTR*); /* Updated Windows 7 has a new IShellDispatch6 in its typelib */ DEFINE_GUID(IID_IWin7ShellDispatch6, 0x34936ba1, 0x67ad, 0x4c41, 0x99,0xb8, 0x8c,0x12,0xdf,0xf1,0xe9,0x74); +static BSTR a2bstr(const char *str) +{ + BSTR ret; + int len; + + len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0); + ret = SysAllocStringLen(NULL, len); + MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len); + + return ret; +} + static void variant_set_string(VARIANT *v, const char *s) { - WCHAR wstr[MAX_PATH]; - MultiByteToWideChar(CP_ACP, 0, s, -1, wstr, MAX_PATH); V_VT(v) = VT_BSTR; - V_BSTR(v) = SysAllocString(wstr); + V_BSTR(v) = a2bstr(s); } static void init_function_pointers(void) @@ -595,6 +605,7 @@ static void test_items(void) for (i = 0; i < sizeof(file_defs)/sizeof(file_defs[0]); i++) { VARIANT_BOOL b; + BSTR name; V_I4(&int_index) = i; variant_set_string(&str_index, file_defs[i].name); @@ -618,6 +629,15 @@ static void test_items(void) "file_defs[%d]: expected %s, got %s\n", i, wine_dbgstr_w(path), wine_dbgstr_w(bstr)); SysFreeString(bstr); + bstr = a2bstr(file_defs[i].name); + r = FolderItem_get_Name(item, &name); + ok(r == S_OK, "Failed to get item name, hr %#x.\n", r); + /* Returned display name does not have to strictly match file name, e.g. extension could be omitted. */ + ok(lstrlenW(name) <= lstrlenW(bstr), "file_defs[%d]: unexpected name length.\n", i); + ok(!memcmp(bstr, name, lstrlenW(name) * sizeof(WCHAR)), "file_defs[%d]: unexpected name %s.\n", i, wine_dbgstr_w(name)); + SysFreeString(name); + SysFreeString(bstr); + item = NULL; r = FolderItems_Item(items, str_index, &item); ok(r == S_OK, "file_defs[%d]: FolderItems::Item failed: %08x\n", i, r);