shell32: Implement IKnownFolderManager::GetFolderByName.

Signed-off-by: Hans Leidekker <hans@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Hans Leidekker 2016-11-22 16:27:07 +01:00 committed by Alexandre Julliard
parent f8450fae23
commit 567b52cd93
2 changed files with 62 additions and 3 deletions

View File

@ -5549,8 +5549,49 @@ static HRESULT WINAPI foldermanager_GetFolderByName(
LPCWSTR pszCanonicalName,
IKnownFolder **ppkf)
{
FIXME("%s, %p\n", debugstr_w(pszCanonicalName), ppkf);
return E_NOTIMPL;
struct foldermanager *fm = impl_from_IKnownFolderManager( iface );
struct knownfolder *kf;
BOOL found = FALSE;
HRESULT hr;
UINT i;
TRACE( "%s, %p\n", debugstr_w(pszCanonicalName), ppkf );
for (i = 0; i < fm->num_ids; i++)
{
WCHAR *path, *name;
hr = get_known_folder_registry_path( &fm->ids[i], NULL, &path );
if (FAILED( hr )) return hr;
hr = get_known_folder_wstr( path, szName, &name );
HeapFree( GetProcessHeap(), 0, path );
if (FAILED( hr )) return hr;
found = !strcmpiW( pszCanonicalName, name );
CoTaskMemFree( name );
if (found) break;
}
if (found)
{
hr = knownfolder_create( &kf );
if (FAILED( hr )) return hr;
hr = knownfolder_set_id( kf, &fm->ids[i] );
if (FAILED( hr ))
{
IKnownFolder_Release( &kf->IKnownFolder_iface );
return hr;
}
*ppkf = &kf->IKnownFolder_iface;
}
else
{
hr = HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND );
*ppkf = NULL;
}
return hr;
}
static HRESULT register_folder(const KNOWNFOLDERID *rfid, const KNOWNFOLDER_DEFINITION *pKFD)

View File

@ -2033,9 +2033,11 @@ static void check_known_folder(IKnownFolderManager *mgr, KNOWNFOLDERID *folderId
static void test_knownFolders(void)
{
static const WCHAR sWindows[] = {'W','i','n','d','o','w','s',0};
static const WCHAR sWindows2[] = {'w','i','n','d','o','w','s',0};
static const WCHAR sExample[] = {'E','x','a','m','p','l','e',0};
static const WCHAR sExample2[] = {'E','x','a','m','p','l','e','2',0};
static const WCHAR sSubFolder[] = {'S','u','b','F','o','l','d','e','r',0};
static const WCHAR sNoSuch[] = {'N','o','S','u','c','h',0};
static const WCHAR sBackslash[] = {'\\',0};
static const KNOWNFOLDERID newFolderId = {0x01234567, 0x89AB, 0xCDEF, {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x01} };
static const KNOWNFOLDERID subFolderId = {0xFEDCBA98, 0x7654, 0x3210, {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF} };
@ -2137,7 +2139,6 @@ static void test_knownFolders(void)
}
hr = IKnownFolderManager_GetFolderByName(mgr, sWindows, &folder);
todo_wine
ok(hr == S_OK, "failed to get known folder: 0x%08x\n", hr);
if(SUCCEEDED(hr))
{
@ -2149,6 +2150,23 @@ static void test_knownFolders(void)
ok(hr == S_OK, "failed to release KnownFolder instance: 0x%08x\n", hr);
}
hr = IKnownFolderManager_GetFolderByName(mgr, sWindows2, &folder);
ok(hr == S_OK, "failed to get known folder: 0x%08x\n", hr);
if(SUCCEEDED(hr))
{
hr = IKnownFolder_GetId(folder, &folderId);
ok(hr == S_OK, "failed to get folder id: 0x%08x\n", hr);
ok(IsEqualGUID(&folderId, &FOLDERID_Windows)==TRUE, "invalid KNOWNFOLDERID returned\n");
hr = IKnownFolder_Release(folder);
ok(hr == S_OK, "failed to release KnownFolder instance: 0x%08x\n", hr);
}
folder = (IKnownFolder *)0xdeadbeef;
hr = IKnownFolderManager_GetFolderByName(mgr, sNoSuch, &folder);
ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "got 0x%08x\n", hr);
ok(folder == NULL, "got %p\n", folder);
for(i=0; i<sizeof(known_folder_found)/sizeof(known_folder_found[0]); ++i)
known_folder_found[i] = FALSE;