2 * Unit tests for shell32 SHGet{Special}Folder{Path|Location} functions.
4 * Copyright 2004 Juan Lang
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 * This is a test program for the SHGet{Special}Folder{Path|Location} functions
20 * of shell32, that get either a filesystem path or a LPITEMIDLIST (shell
21 * namespace) path for a given folder (CSIDL value).
33 #include "knownfolders.h"
34 #include "wine/test.h"
38 /* CSIDL_MYDOCUMENTS is now the same as CSIDL_PERSONAL, but what we want
39 * here is its original value.
41 #define OLD_CSIDL_MYDOCUMENTS 0x000c
43 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
46 #define ARRAY_SIZE(x) ( sizeof(x) / sizeof((x)[0]) )
49 /* from pidl.h, not included here: */
50 #ifndef PT_CPL /* Guess, Win7 uses this for CSIDL_CONTROLS */
51 #define PT_CPL 0x01 /* no path */
54 #define PT_GUID 0x1f /* no path */
57 #define PT_DRIVE 0x23 /* has path */
60 #define PT_DRIVE2 0x25 /* has path */
63 #define PT_SHELLEXT 0x2e /* no path */
66 #define PT_FOLDER 0x31 /* has path */
69 #define PT_FOLDERW 0x35 /* has path */
72 #define PT_WORKGRP 0x41 /* no path */
75 #define PT_YAGUID 0x70 /* no path */
77 /* FIXME: this is used for history/favorites folders; what's a better name? */
79 #define PT_IESPECIAL2 0xb1 /* has path */
82 static GUID CLSID_CommonDocuments = { 0x0000000c, 0x0000, 0x0000, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x1a } };
84 struct shellExpectedValues {
90 static HRESULT (WINAPI *pDllGetVersion)(DLLVERSIONINFO *);
91 static HRESULT (WINAPI *pSHGetFolderPathA)(HWND, int, HANDLE, DWORD, LPSTR);
92 static HRESULT (WINAPI *pSHGetFolderLocation)(HWND, int, HANDLE, DWORD,
94 static BOOL (WINAPI *pSHGetSpecialFolderPathA)(HWND, LPSTR, int, BOOL);
95 static HRESULT (WINAPI *pSHGetSpecialFolderLocation)(HWND, int, LPITEMIDLIST *);
96 static LPITEMIDLIST (WINAPI *pILFindLastID)(LPCITEMIDLIST);
97 static int (WINAPI *pSHFileOperationA)(LPSHFILEOPSTRUCTA);
98 static HRESULT (WINAPI *pSHGetMalloc)(LPMALLOC *);
99 static UINT (WINAPI *pGetSystemWow64DirectoryA)(LPSTR,UINT);
100 static HRESULT (WINAPI *pSHGetKnownFolderPath)(REFKNOWNFOLDERID, DWORD, HANDLE, PWSTR *);
101 static HRESULT (WINAPI *pSHSetKnownFolderPath)(REFKNOWNFOLDERID, DWORD, HANDLE, PWSTR);
102 static HRESULT (WINAPI *pSHGetFolderPathEx)(REFKNOWNFOLDERID, DWORD, HANDLE, LPWSTR, DWORD);
104 static DLLVERSIONINFO shellVersion = { 0 };
105 static LPMALLOC pMalloc;
106 static const BYTE guidType[] = { PT_GUID };
107 static const BYTE controlPanelType[] = { PT_SHELLEXT, PT_GUID, PT_CPL };
108 static const BYTE folderType[] = { PT_FOLDER, PT_FOLDERW };
109 static const BYTE favoritesType[] = { PT_FOLDER, PT_FOLDERW, 0, PT_IESPECIAL2 /* Win98 */ };
110 static const BYTE folderOrSpecialType[] = { PT_FOLDER, PT_IESPECIAL2 };
111 static const BYTE personalType[] = { PT_FOLDER, PT_GUID, PT_DRIVE, 0xff /* Win9x */,
112 PT_IESPECIAL2 /* Win98 */, 0 /* Vista */ };
113 /* FIXME: don't know the type of 0x71 returned by Vista/2008 for printers */
114 static const BYTE printersType[] = { PT_YAGUID, PT_SHELLEXT, 0x71 };
115 static const BYTE ieSpecialType[] = { PT_IESPECIAL2 };
116 static const BYTE shellExtType[] = { PT_SHELLEXT };
117 static const BYTE workgroupType[] = { PT_WORKGRP };
118 #define DECLARE_TYPE(x, y) { x, sizeof(y) / sizeof(y[0]), y }
119 static const struct shellExpectedValues requiredShellValues[] = {
120 DECLARE_TYPE(CSIDL_BITBUCKET, guidType),
121 DECLARE_TYPE(CSIDL_CONTROLS, controlPanelType),
122 DECLARE_TYPE(CSIDL_COOKIES, folderType),
123 DECLARE_TYPE(CSIDL_DESKTOPDIRECTORY, folderType),
124 DECLARE_TYPE(CSIDL_DRIVES, guidType),
125 DECLARE_TYPE(CSIDL_FAVORITES, favoritesType),
126 DECLARE_TYPE(CSIDL_FONTS, folderOrSpecialType),
127 /* FIXME: the following fails in Wine, returns type PT_FOLDER
128 DECLARE_TYPE(CSIDL_HISTORY, ieSpecialType),
130 DECLARE_TYPE(CSIDL_INTERNET, guidType),
131 DECLARE_TYPE(CSIDL_NETHOOD, folderType),
132 DECLARE_TYPE(CSIDL_NETWORK, guidType),
133 DECLARE_TYPE(CSIDL_PERSONAL, personalType),
134 DECLARE_TYPE(CSIDL_PRINTERS, printersType),
135 DECLARE_TYPE(CSIDL_PRINTHOOD, folderType),
136 DECLARE_TYPE(CSIDL_PROGRAMS, folderType),
137 DECLARE_TYPE(CSIDL_RECENT, folderOrSpecialType),
138 DECLARE_TYPE(CSIDL_SENDTO, folderType),
139 DECLARE_TYPE(CSIDL_STARTMENU, folderType),
140 DECLARE_TYPE(CSIDL_STARTUP, folderType),
141 DECLARE_TYPE(CSIDL_TEMPLATES, folderType),
143 static const struct shellExpectedValues optionalShellValues[] = {
144 /* FIXME: the following only semi-succeed; they return NULL PIDLs on XP.. hmm.
145 DECLARE_TYPE(CSIDL_ALTSTARTUP, folderType),
146 DECLARE_TYPE(CSIDL_COMMON_ALTSTARTUP, folderType),
147 DECLARE_TYPE(CSIDL_COMMON_OEM_LINKS, folderType),
149 /* Windows NT-only: */
150 DECLARE_TYPE(CSIDL_COMMON_DESKTOPDIRECTORY, folderType),
151 DECLARE_TYPE(CSIDL_COMMON_DOCUMENTS, shellExtType),
152 DECLARE_TYPE(CSIDL_COMMON_FAVORITES, folderType),
153 DECLARE_TYPE(CSIDL_COMMON_PROGRAMS, folderType),
154 DECLARE_TYPE(CSIDL_COMMON_STARTMENU, folderType),
155 DECLARE_TYPE(CSIDL_COMMON_STARTUP, folderType),
156 DECLARE_TYPE(CSIDL_COMMON_TEMPLATES, folderType),
157 /* first appearing in shell32 version 4.71: */
158 DECLARE_TYPE(CSIDL_APPDATA, folderType),
159 /* first appearing in shell32 version 4.72: */
160 DECLARE_TYPE(CSIDL_INTERNET_CACHE, ieSpecialType),
161 /* first appearing in shell32 version 5.0: */
162 DECLARE_TYPE(CSIDL_ADMINTOOLS, folderType),
163 DECLARE_TYPE(CSIDL_COMMON_APPDATA, folderType),
164 DECLARE_TYPE(CSIDL_LOCAL_APPDATA, folderType),
165 DECLARE_TYPE(OLD_CSIDL_MYDOCUMENTS, folderType),
166 DECLARE_TYPE(CSIDL_MYMUSIC, folderType),
167 DECLARE_TYPE(CSIDL_MYPICTURES, folderType),
168 DECLARE_TYPE(CSIDL_MYVIDEO, folderType),
169 DECLARE_TYPE(CSIDL_PROFILE, folderType),
170 DECLARE_TYPE(CSIDL_PROGRAM_FILES, folderType),
171 DECLARE_TYPE(CSIDL_PROGRAM_FILESX86, folderType),
172 DECLARE_TYPE(CSIDL_PROGRAM_FILES_COMMON, folderType),
173 DECLARE_TYPE(CSIDL_PROGRAM_FILES_COMMONX86, folderType),
174 DECLARE_TYPE(CSIDL_SYSTEM, folderType),
175 DECLARE_TYPE(CSIDL_WINDOWS, folderType),
176 /* first appearing in shell32 6.0: */
177 DECLARE_TYPE(CSIDL_CDBURN_AREA, folderType),
178 DECLARE_TYPE(CSIDL_COMMON_MUSIC, folderType),
179 DECLARE_TYPE(CSIDL_COMMON_PICTURES, folderType),
180 DECLARE_TYPE(CSIDL_COMMON_VIDEO, folderType),
181 DECLARE_TYPE(CSIDL_COMPUTERSNEARME, workgroupType),
182 DECLARE_TYPE(CSIDL_RESOURCES, folderType),
183 DECLARE_TYPE(CSIDL_RESOURCES_LOCALIZED, folderType),
187 static void loadShell32(void)
189 HMODULE hShell32 = GetModuleHandleA("shell32");
191 #define GET_PROC(func) \
192 p ## func = (void*)GetProcAddress(hShell32, #func); \
194 trace("GetProcAddress(%s) failed\n", #func);
196 GET_PROC(DllGetVersion)
197 GET_PROC(SHGetFolderPathA)
198 GET_PROC(SHGetFolderPathEx)
199 GET_PROC(SHGetFolderLocation)
200 GET_PROC(SHGetKnownFolderPath)
201 GET_PROC(SHSetKnownFolderPath)
202 GET_PROC(SHGetSpecialFolderPathA)
203 GET_PROC(SHGetSpecialFolderLocation)
204 GET_PROC(ILFindLastID)
206 pILFindLastID = (void *)GetProcAddress(hShell32, (LPCSTR)16);
207 GET_PROC(SHFileOperationA)
208 GET_PROC(SHGetMalloc)
210 ok(pSHGetMalloc != NULL, "shell32 is missing SHGetMalloc\n");
213 HRESULT hr = pSHGetMalloc(&pMalloc);
215 ok(hr == S_OK, "SHGetMalloc failed: 0x%08x\n", hr);
216 ok(pMalloc != NULL, "SHGetMalloc returned a NULL IMalloc\n");
221 shellVersion.cbSize = sizeof(shellVersion);
222 pDllGetVersion(&shellVersion);
223 trace("shell32 version is %d.%d\n",
224 shellVersion.dwMajorVersion, shellVersion.dwMinorVersion);
229 #ifndef CSIDL_PROFILES
230 #define CSIDL_PROFILES 0x003e
233 /* A couple utility printing functions */
234 static const char *getFolderName(int folder)
236 static char unknown[32];
238 #define CSIDL_TO_STR(x) case x: return#x;
241 CSIDL_TO_STR(CSIDL_DESKTOP);
242 CSIDL_TO_STR(CSIDL_INTERNET);
243 CSIDL_TO_STR(CSIDL_PROGRAMS);
244 CSIDL_TO_STR(CSIDL_CONTROLS);
245 CSIDL_TO_STR(CSIDL_PRINTERS);
246 CSIDL_TO_STR(CSIDL_PERSONAL);
247 CSIDL_TO_STR(CSIDL_FAVORITES);
248 CSIDL_TO_STR(CSIDL_STARTUP);
249 CSIDL_TO_STR(CSIDL_RECENT);
250 CSIDL_TO_STR(CSIDL_SENDTO);
251 CSIDL_TO_STR(CSIDL_BITBUCKET);
252 CSIDL_TO_STR(CSIDL_STARTMENU);
253 CSIDL_TO_STR(OLD_CSIDL_MYDOCUMENTS);
254 CSIDL_TO_STR(CSIDL_MYMUSIC);
255 CSIDL_TO_STR(CSIDL_MYVIDEO);
256 CSIDL_TO_STR(CSIDL_DESKTOPDIRECTORY);
257 CSIDL_TO_STR(CSIDL_DRIVES);
258 CSIDL_TO_STR(CSIDL_NETWORK);
259 CSIDL_TO_STR(CSIDL_NETHOOD);
260 CSIDL_TO_STR(CSIDL_FONTS);
261 CSIDL_TO_STR(CSIDL_TEMPLATES);
262 CSIDL_TO_STR(CSIDL_COMMON_STARTMENU);
263 CSIDL_TO_STR(CSIDL_COMMON_PROGRAMS);
264 CSIDL_TO_STR(CSIDL_COMMON_STARTUP);
265 CSIDL_TO_STR(CSIDL_COMMON_DESKTOPDIRECTORY);
266 CSIDL_TO_STR(CSIDL_APPDATA);
267 CSIDL_TO_STR(CSIDL_PRINTHOOD);
268 CSIDL_TO_STR(CSIDL_LOCAL_APPDATA);
269 CSIDL_TO_STR(CSIDL_ALTSTARTUP);
270 CSIDL_TO_STR(CSIDL_COMMON_ALTSTARTUP);
271 CSIDL_TO_STR(CSIDL_COMMON_FAVORITES);
272 CSIDL_TO_STR(CSIDL_INTERNET_CACHE);
273 CSIDL_TO_STR(CSIDL_COOKIES);
274 CSIDL_TO_STR(CSIDL_HISTORY);
275 CSIDL_TO_STR(CSIDL_COMMON_APPDATA);
276 CSIDL_TO_STR(CSIDL_WINDOWS);
277 CSIDL_TO_STR(CSIDL_SYSTEM);
278 CSIDL_TO_STR(CSIDL_PROGRAM_FILES);
279 CSIDL_TO_STR(CSIDL_MYPICTURES);
280 CSIDL_TO_STR(CSIDL_PROFILE);
281 CSIDL_TO_STR(CSIDL_SYSTEMX86);
282 CSIDL_TO_STR(CSIDL_PROGRAM_FILESX86);
283 CSIDL_TO_STR(CSIDL_PROGRAM_FILES_COMMON);
284 CSIDL_TO_STR(CSIDL_PROGRAM_FILES_COMMONX86);
285 CSIDL_TO_STR(CSIDL_COMMON_TEMPLATES);
286 CSIDL_TO_STR(CSIDL_COMMON_DOCUMENTS);
287 CSIDL_TO_STR(CSIDL_COMMON_ADMINTOOLS);
288 CSIDL_TO_STR(CSIDL_ADMINTOOLS);
289 CSIDL_TO_STR(CSIDL_CONNECTIONS);
290 CSIDL_TO_STR(CSIDL_PROFILES);
291 CSIDL_TO_STR(CSIDL_COMMON_MUSIC);
292 CSIDL_TO_STR(CSIDL_COMMON_PICTURES);
293 CSIDL_TO_STR(CSIDL_COMMON_VIDEO);
294 CSIDL_TO_STR(CSIDL_RESOURCES);
295 CSIDL_TO_STR(CSIDL_RESOURCES_LOCALIZED);
296 CSIDL_TO_STR(CSIDL_COMMON_OEM_LINKS);
297 CSIDL_TO_STR(CSIDL_CDBURN_AREA);
298 CSIDL_TO_STR(CSIDL_COMPUTERSNEARME);
301 sprintf(unknown, "unknown (0x%04x)", folder);
306 static const char *printGUID(const GUID *guid, char * guidSTR)
308 if (!guid) return NULL;
310 sprintf(guidSTR, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
311 guid->Data1, guid->Data2, guid->Data3,
312 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
313 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]);
317 static void test_parameters(void)
319 LPITEMIDLIST pidl = NULL;
323 if (pSHGetFolderLocation)
325 /* check a bogus CSIDL: */
327 hr = pSHGetFolderLocation(NULL, 0xeeee, NULL, 0, &pidl);
328 ok(hr == E_INVALIDARG, "got 0x%08x, expected E_INVALIDARG\n", hr);
329 if (hr == S_OK) IMalloc_Free(pMalloc, pidl);
331 /* check a bogus user token: */
333 hr = pSHGetFolderLocation(NULL, CSIDL_FAVORITES, (HANDLE)2, 0, &pidl);
334 ok(hr == E_FAIL || hr == E_HANDLE, "got 0x%08x, expected E_FAIL or E_HANDLE\n", hr);
335 if (hr == S_OK) IMalloc_Free(pMalloc, pidl);
337 /* a NULL pidl pointer crashes, so don't test it */
340 if (pSHGetSpecialFolderLocation)
344 SHGetSpecialFolderLocation(NULL, 0, NULL);
346 hr = pSHGetSpecialFolderLocation(NULL, 0xeeee, &pidl);
347 ok(hr == E_INVALIDARG, "got returned 0x%08x\n", hr);
350 if (pSHGetFolderPathA)
352 /* expect 2's a bogus handle, especially since we didn't open it */
353 hr = pSHGetFolderPathA(NULL, CSIDL_DESKTOP, (HANDLE)2, SHGFP_TYPE_DEFAULT, path);
354 ok(hr == E_FAIL || hr == E_HANDLE || /* Vista and 2k8 */
355 broken(hr == S_OK), /* W2k and Me */ "got 0x%08x, expected E_FAIL\n", hr);
357 hr = pSHGetFolderPathA(NULL, 0xeeee, NULL, SHGFP_TYPE_DEFAULT, path);
358 ok(hr == E_INVALIDARG, "got 0x%08x, expected E_INVALIDARG\n", hr);
361 if (pSHGetSpecialFolderPathA)
366 pSHGetSpecialFolderPathA(NULL, NULL, CSIDL_BITBUCKET, FALSE);
368 /* odd but true: calling with a NULL path still succeeds if it's a real
369 * dir (on some windows platform). on winME it generates exception.
371 ret = pSHGetSpecialFolderPathA(NULL, path, CSIDL_PROGRAMS, FALSE);
372 ok(ret, "got %d\n", ret);
374 ret = pSHGetSpecialFolderPathA(NULL, path, 0xeeee, FALSE);
375 ok(!ret, "got %d\n", ret);
379 /* Returns the folder's PIDL type, or 0xff if one can't be found. */
380 static BYTE testSHGetFolderLocation(int folder)
386 /* treat absence of function as success */
387 if (!pSHGetFolderLocation) return TRUE;
390 hr = pSHGetFolderLocation(NULL, folder, NULL, 0, &pidl);
395 LPITEMIDLIST pidlLast = pILFindLastID(pidl);
397 ok(pidlLast != NULL, "%s: ILFindLastID failed\n",
398 getFolderName(folder));
400 ret = pidlLast->mkid.abID[0];
401 IMalloc_Free(pMalloc, pidl);
407 /* Returns the folder's PIDL type, or 0xff if one can't be found. */
408 static BYTE testSHGetSpecialFolderLocation(int folder)
414 /* treat absence of function as success */
415 if (!pSHGetSpecialFolderLocation) return TRUE;
418 hr = pSHGetSpecialFolderLocation(NULL, folder, &pidl);
423 LPITEMIDLIST pidlLast = pILFindLastID(pidl);
426 "%s: ILFindLastID failed\n", getFolderName(folder));
428 ret = pidlLast->mkid.abID[0];
429 IMalloc_Free(pMalloc, pidl);
435 static void test_SHGetFolderPath(BOOL optional, int folder)
440 if (!pSHGetFolderPathA) return;
442 hr = pSHGetFolderPathA(NULL, folder, NULL, SHGFP_TYPE_CURRENT, path);
443 ok(hr == S_OK || optional,
444 "SHGetFolderPathA(NULL, %s, NULL, SHGFP_TYPE_CURRENT, path) failed: 0x%08x\n", getFolderName(folder), hr);
447 static void test_SHGetSpecialFolderPath(BOOL optional, int folder)
452 if (!pSHGetSpecialFolderPathA) return;
454 ret = pSHGetSpecialFolderPathA(NULL, path, folder, FALSE);
455 if (ret && winetest_interactive)
456 printf("%s: %s\n", getFolderName(folder), path);
458 "SHGetSpecialFolderPathA(NULL, path, %s, FALSE) failed\n",
459 getFolderName(folder));
462 static void test_ShellValues(const struct shellExpectedValues testEntries[],
463 int numEntries, BOOL optional)
467 for (i = 0; i < numEntries; i++)
471 BOOL foundTypeMatch = FALSE;
473 if (pSHGetFolderLocation)
475 type = testSHGetFolderLocation(testEntries[i].folder);
476 for (j = 0; !foundTypeMatch && j < testEntries[i].numTypes; j++)
477 if (testEntries[i].types[j] == type)
478 foundTypeMatch = TRUE;
479 ok(foundTypeMatch || optional || broken(type == 0xff) /* Win9x */,
480 "%s has unexpected type %d (0x%02x)\n",
481 getFolderName(testEntries[i].folder), type, type);
483 type = testSHGetSpecialFolderLocation(testEntries[i].folder);
484 for (j = 0, foundTypeMatch = FALSE; !foundTypeMatch &&
485 j < testEntries[i].numTypes; j++)
486 if (testEntries[i].types[j] == type)
487 foundTypeMatch = TRUE;
488 ok(foundTypeMatch || optional || broken(type == 0xff) /* Win9x */,
489 "%s has unexpected type %d (0x%02x)\n",
490 getFolderName(testEntries[i].folder), type, type);
497 test_SHGetFolderPath(optional, testEntries[i].folder);
498 test_SHGetSpecialFolderPath(optional, testEntries[i].folder);
504 /* Attempts to verify that the folder path corresponding to the folder CSIDL
505 * value has the same value as the environment variable with name envVar.
506 * Doesn't mind if SHGetSpecialFolderPath fails for folder or if envVar isn't
507 * set in this environment; different OS and shell version behave differently.
508 * However, if both are present, fails if envVar's value is not the same
509 * (byte-for-byte) as what SHGetSpecialFolderPath returns.
511 static void matchSpecialFolderPathToEnv(int folder, const char *envVar)
515 if (!pSHGetSpecialFolderPathA) return;
517 if (pSHGetSpecialFolderPathA(NULL, path, folder, FALSE))
519 char *envVal = getenv(envVar);
521 ok(!envVal || !lstrcmpiA(envVal, path),
522 "%%%s%% does not match SHGetSpecialFolderPath:\n"
523 "%%%s%% is %s\nSHGetSpecialFolderPath returns %s\n",
524 envVar, envVar, envVal, path);
528 /* Attempts to match the GUID returned by SHGetFolderLocation for folder with
529 * GUID. Assumes the type of the returned PIDL is in fact a GUID, but doesn't
530 * fail if it isn't--that check should already have been done.
531 * Fails if the returned PIDL is a GUID whose value does not match guid.
533 static void matchGUID(int folder, const GUID *guid, const GUID *guid_alt)
538 if (!pSHGetFolderLocation) return;
542 hr = pSHGetFolderLocation(NULL, folder, NULL, 0, &pidl);
545 LPITEMIDLIST pidlLast = pILFindLastID(pidl);
547 if (pidlLast && (pidlLast->mkid.abID[0] == PT_SHELLEXT ||
548 pidlLast->mkid.abID[0] == PT_GUID))
550 GUID *shellGuid = (GUID *)(pidlLast->mkid.abID + 2);
551 char shellGuidStr[39], guidStr[39], guid_altStr[39];
554 ok(IsEqualIID(shellGuid, guid),
555 "%s: got GUID %s, expected %s\n", getFolderName(folder),
556 printGUID(shellGuid, shellGuidStr), printGUID(guid, guidStr));
558 ok(IsEqualIID(shellGuid, guid) ||
559 IsEqualIID(shellGuid, guid_alt),
560 "%s: got GUID %s, expected %s or %s\n", getFolderName(folder),
561 printGUID(shellGuid, shellGuidStr), printGUID(guid, guidStr),
562 printGUID(guid_alt, guid_altStr));
564 IMalloc_Free(pMalloc, pidl);
568 /* Checks the PIDL type of all the known values. */
569 static void test_PidlTypes(void)
572 test_SHGetFolderPath(FALSE, CSIDL_DESKTOP);
573 test_SHGetSpecialFolderPath(FALSE, CSIDL_DESKTOP);
575 test_ShellValues(requiredShellValues, ARRAY_SIZE(requiredShellValues), FALSE);
576 test_ShellValues(optionalShellValues, ARRAY_SIZE(optionalShellValues), TRUE);
579 /* FIXME: Should be in shobjidl.idl */
580 DEFINE_GUID(CLSID_NetworkExplorerFolder, 0xF02C1A0D, 0xBE21, 0x4350, 0x88, 0xB0, 0x73, 0x67, 0xFC, 0x96, 0xEF, 0x3C);
582 /* Verifies various shell virtual folders have the correct well-known GUIDs. */
583 static void test_GUIDs(void)
585 matchGUID(CSIDL_BITBUCKET, &CLSID_RecycleBin, NULL);
586 matchGUID(CSIDL_CONTROLS, &CLSID_ControlPanel, NULL);
587 matchGUID(CSIDL_DRIVES, &CLSID_MyComputer, NULL);
588 matchGUID(CSIDL_INTERNET, &CLSID_Internet, NULL);
589 matchGUID(CSIDL_NETWORK, &CLSID_NetworkPlaces, &CLSID_NetworkExplorerFolder); /* Vista and higher */
590 matchGUID(CSIDL_PERSONAL, &CLSID_MyDocuments, NULL);
591 matchGUID(CSIDL_COMMON_DOCUMENTS, &CLSID_CommonDocuments, NULL);
592 matchGUID(CSIDL_PRINTERS, &CLSID_Printers, NULL);
595 /* Verifies various shell paths match the environment variables to which they
598 static void test_EnvVars(void)
600 matchSpecialFolderPathToEnv(CSIDL_PROGRAM_FILES, "ProgramFiles");
601 matchSpecialFolderPathToEnv(CSIDL_APPDATA, "APPDATA");
602 matchSpecialFolderPathToEnv(CSIDL_PROFILE, "USERPROFILE");
603 matchSpecialFolderPathToEnv(CSIDL_WINDOWS, "SystemRoot");
604 matchSpecialFolderPathToEnv(CSIDL_WINDOWS, "windir");
605 matchSpecialFolderPathToEnv(CSIDL_PROGRAM_FILES_COMMON, "CommonProgramFiles");
606 /* this is only set on Wine, but can't hurt to verify it: */
607 matchSpecialFolderPathToEnv(CSIDL_SYSTEM, "winsysdir");
610 /* Loosely based on PathRemoveBackslashA from dlls/shlwapi/path.c */
611 static BOOL myPathIsRootA(LPCSTR lpszPath)
613 if (lpszPath && *lpszPath &&
614 lpszPath[1] == ':' && lpszPath[2] == '\\' && lpszPath[3] == '\0')
615 return TRUE; /* X:\ */
618 static LPSTR myPathRemoveBackslashA( LPSTR lpszPath )
624 szTemp = CharPrevA(lpszPath, lpszPath + strlen(lpszPath));
625 if (!myPathIsRootA(lpszPath) && *szTemp == '\\')
631 /* Verifies the shell path for CSIDL_WINDOWS matches the return from
632 * GetWindowsDirectory. If SHGetSpecialFolderPath fails, no harm, no foul--not
633 * every shell32 version supports CSIDL_WINDOWS.
635 static void testWinDir(void)
637 char windowsShellPath[MAX_PATH], windowsDir[MAX_PATH] = { 0 };
639 if (!pSHGetSpecialFolderPathA) return;
641 if (pSHGetSpecialFolderPathA(NULL, windowsShellPath, CSIDL_WINDOWS, FALSE))
643 myPathRemoveBackslashA(windowsShellPath);
644 GetWindowsDirectoryA(windowsDir, sizeof(windowsDir));
645 myPathRemoveBackslashA(windowsDir);
646 ok(!lstrcmpiA(windowsDir, windowsShellPath),
647 "GetWindowsDirectory returns %s SHGetSpecialFolderPath returns %s\n",
648 windowsDir, windowsShellPath);
652 /* Verifies the shell path for CSIDL_SYSTEM matches the return from
653 * GetSystemDirectory. If SHGetSpecialFolderPath fails, no harm,
654 * no foul--not every shell32 version supports CSIDL_SYSTEM.
656 static void testSystemDir(void)
658 char systemShellPath[MAX_PATH], systemDir[MAX_PATH], systemDirx86[MAX_PATH];
660 if (!pSHGetSpecialFolderPathA) return;
662 GetSystemDirectoryA(systemDir, sizeof(systemDir));
663 myPathRemoveBackslashA(systemDir);
664 if (pSHGetSpecialFolderPathA(NULL, systemShellPath, CSIDL_SYSTEM, FALSE))
666 myPathRemoveBackslashA(systemShellPath);
667 ok(!lstrcmpiA(systemDir, systemShellPath),
668 "GetSystemDirectory returns %s SHGetSpecialFolderPath returns %s\n",
669 systemDir, systemShellPath);
672 if (!pGetSystemWow64DirectoryA || !pGetSystemWow64DirectoryA(systemDirx86, sizeof(systemDirx86)))
673 GetSystemDirectoryA(systemDirx86, sizeof(systemDirx86));
674 myPathRemoveBackslashA(systemDirx86);
675 if (pSHGetSpecialFolderPathA(NULL, systemShellPath, CSIDL_SYSTEMX86, FALSE))
677 myPathRemoveBackslashA(systemShellPath);
678 ok(!lstrcmpiA(systemDirx86, systemShellPath) || broken(!lstrcmpiA(systemDir, systemShellPath)),
679 "GetSystemDirectory returns %s SHGetSpecialFolderPath returns %s\n",
680 systemDir, systemShellPath);
684 /* Globals used by subprocesses */
686 static char **myARGV;
687 static char base[MAX_PATH];
688 static char selfname[MAX_PATH];
690 static int init(void)
692 myARGC = winetest_get_mainargs(&myARGV);
693 if (!GetCurrentDirectoryA(sizeof(base), base)) return 0;
694 strcpy(selfname, myARGV[0]);
698 static void doChild(const char *arg)
708 /* test what happens when CSIDL_FAVORITES is set to a nonexistent directory */
710 /* test some failure cases first: */
711 hr = pSHGetFolderPathA(NULL, CSIDL_FAVORITES, NULL, SHGFP_TYPE_CURRENT, path);
712 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
713 "SHGetFolderPath returned 0x%08x, expected 0x80070002\n", hr);
716 hr = pSHGetFolderLocation(NULL, CSIDL_FAVORITES, NULL, 0, &pidl);
717 ok(hr == E_FAIL || hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
718 "SHGetFolderLocation returned 0x%08x\n", hr);
719 if (hr == S_OK && pidl) IMalloc_Free(pMalloc, pidl);
721 ok(!pSHGetSpecialFolderPathA(NULL, path, CSIDL_FAVORITES, FALSE),
722 "SHGetSpecialFolderPath succeeded, expected failure\n");
725 hr = pSHGetSpecialFolderLocation(NULL, CSIDL_FAVORITES, &pidl);
726 ok(hr == E_FAIL || hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
727 "SHGetFolderLocation returned 0x%08x\n", hr);
729 if (hr == S_OK && pidl) IMalloc_Free(pMalloc, pidl);
731 /* now test success: */
732 hr = pSHGetFolderPathA(NULL, CSIDL_FAVORITES | CSIDL_FLAG_CREATE, NULL,
733 SHGFP_TYPE_CURRENT, path);
734 ok (hr == S_OK, "got 0x%08x\n", hr);
739 trace("CSIDL_FAVORITES was changed to %s\n", path);
740 ret = CreateDirectoryA(path, NULL);
741 ok(!ret, "expected failure with ERROR_ALREADY_EXISTS\n");
743 ok(GetLastError() == ERROR_ALREADY_EXISTS,
744 "got %d, expected ERROR_ALREADY_EXISTS\n", GetLastError());
746 p = path + strlen(path);
747 strcpy(p, "\\desktop.ini");
750 SetFileAttributesA( path, FILE_ATTRIBUTE_NORMAL );
751 ret = RemoveDirectoryA(path);
752 ok( ret, "failed to remove %s error %u\n", path, GetLastError() );
755 else if (arg[0] == '2')
757 /* make sure SHGetFolderPath still succeeds when the
758 original value of CSIDL_FAVORITES is restored. */
759 hr = pSHGetFolderPathA(NULL, CSIDL_FAVORITES | CSIDL_FLAG_CREATE, NULL,
760 SHGFP_TYPE_CURRENT, path);
761 ok(hr == S_OK, "SHGetFolderPath failed: 0x%08x\n", hr);
765 /* Tests the return values from the various shell functions both with and
766 * without the use of the CSIDL_FLAG_CREATE flag. This flag only appeared in
767 * version 5 of the shell, so don't test unless it's at least version 5.
768 * The test reads a value from the registry, modifies it, calls
769 * SHGetFolderPath once with the CSIDL_FLAG_CREATE flag, and immediately
770 * afterward without it. Then it restores the registry and deletes the folder
772 * One oddity with respect to restoration: shell32 caches somehow, so it needs
773 * to be reloaded in order to see the correct (restored) value.
774 * Some APIs unrelated to the ones under test may fail, but I expect they're
775 * covered by other unit tests; I just print out something about failure to
776 * help trace what's going on.
778 static void test_NonExistentPath(void)
780 static const char userShellFolders[] =
781 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders";
782 char originalPath[MAX_PATH], modifiedPath[MAX_PATH];
785 if (!pSHGetFolderPathA) return;
786 if (!pSHGetFolderLocation) return;
787 if (!pSHGetSpecialFolderPathA) return;
788 if (!pSHGetSpecialFolderLocation) return;
789 if (!pSHFileOperationA) return;
790 if (shellVersion.dwMajorVersion < 5) return;
792 if (!RegOpenKeyExA(HKEY_CURRENT_USER, userShellFolders, 0, KEY_ALL_ACCESS,
797 len = sizeof(originalPath);
798 if (!RegQueryValueExA(key, "Favorites", NULL, &type,
799 (LPBYTE)&originalPath, &len))
801 size_t len = strlen(originalPath);
803 memcpy(modifiedPath, originalPath, len);
804 modifiedPath[len++] = '2';
805 modifiedPath[len++] = '\0';
806 trace("Changing CSIDL_FAVORITES to %s\n", modifiedPath);
807 if (!RegSetValueExA(key, "Favorites", 0, type,
808 (LPBYTE)modifiedPath, len))
810 char buffer[MAX_PATH+20];
811 STARTUPINFOA startup;
812 PROCESS_INFORMATION info;
814 sprintf(buffer, "%s tests/shellpath.c 1", selfname);
815 memset(&startup, 0, sizeof(startup));
816 startup.cb = sizeof(startup);
817 startup.dwFlags = STARTF_USESHOWWINDOW;
818 startup.dwFlags = SW_SHOWNORMAL;
819 CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL,
821 winetest_wait_child_process( info.hProcess );
823 /* restore original values: */
824 trace("Restoring CSIDL_FAVORITES to %s\n", originalPath);
825 RegSetValueExA(key, "Favorites", 0, type, (LPBYTE) originalPath,
826 strlen(originalPath) + 1);
829 sprintf(buffer, "%s tests/shellpath.c 2", selfname);
830 memset(&startup, 0, sizeof(startup));
831 startup.cb = sizeof(startup);
832 startup.dwFlags = STARTF_USESHOWWINDOW;
833 startup.dwFlags = SW_SHOWNORMAL;
834 CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL,
836 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0,
837 "child process termination\n");
840 else skip("RegQueryValueExA(key, Favorites, ...) failed\n");
844 else skip("RegOpenKeyExA(HKEY_CURRENT_USER, %s, ...) failed\n", userShellFolders);
847 static void test_SHGetFolderPathEx(void)
850 WCHAR buffer[MAX_PATH], *path;
853 if (!pSHGetKnownFolderPath || !pSHGetFolderPathEx)
855 win_skip("SHGetKnownFolderPath or SHGetFolderPathEx not available\n");
859 if (0) { /* crashes */
860 hr = pSHGetKnownFolderPath(&FOLDERID_Desktop, 0, NULL, NULL);
861 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
864 hr = pSHGetKnownFolderPath(&FOLDERID_Desktop, 0, NULL, &path);
865 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
866 ok(path != NULL, "expected path != NULL\n");
868 hr = pSHGetFolderPathEx(&FOLDERID_Desktop, 0, NULL, buffer, MAX_PATH);
869 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
870 ok(!lstrcmpiW(path, buffer), "expected equal paths\n");
871 len = lstrlenW(buffer);
874 hr = pSHGetFolderPathEx(&FOLDERID_Desktop, 0, NULL, buffer, 0);
875 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
877 if (0) { /* crashes */
878 hr = pSHGetFolderPathEx(&FOLDERID_Desktop, 0, NULL, NULL, len + 1);
879 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
881 hr = pSHGetFolderPathEx(NULL, 0, NULL, buffer, MAX_PATH);
882 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
884 hr = pSHGetFolderPathEx(&FOLDERID_Desktop, 0, NULL, buffer, len);
885 ok(hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), "expected 0x8007007a, got 0x%08x\n", hr);
887 hr = pSHGetFolderPathEx(&FOLDERID_Desktop, 0, NULL, buffer, len + 1);
888 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
891 /* Standard CSIDL values (and their flags) uses only two less-significant bytes */
892 #define NO_CSIDL 0x10000
893 #define CSIDL_TODO_WINE 0x20000
894 #define KNOWN_FOLDER(id, csidl, name, category, parent, relative_path, parsing_name, attributes, definitionFlags) \
895 { &id, # id, csidl, # csidl, name, category, &parent, # parent, relative_path, parsing_name, attributes, definitionFlags, __LINE__ }
897 /* non-published known folders test */
898 static const GUID _FOLDERID_CryptoKeys = {0xB88F4DAA, 0xE7BD, 0x49A9, {0xB7, 0x4D, 0x02, 0x88, 0x5A, 0x5D, 0xC7, 0x65} };
899 static const GUID _FOLDERID_DpapiKeys = {0x10C07CD0, 0xEF91, 0x4567, {0xB8, 0x50, 0x44, 0x8B, 0x77, 0xCB, 0x37, 0xF9} };
900 static const GUID _FOLDERID_SystemCertificates = {0x54EED2E0, 0xE7CA, 0x4FDB, {0x91, 0x48, 0x0F, 0x42, 0x47, 0x29, 0x1C, 0xFA} };
901 static const GUID _FOLDERID_CredentialManager = {0x915221FB, 0x9EFE, 0x4BDA, {0x8F, 0xD7, 0xF7, 0x8D, 0xCA, 0x77, 0x4F, 0x87} };
903 struct knownFolderDef {
904 const KNOWNFOLDERID *folderId;
905 const char *sFolderId;
909 const KF_CATEGORY category;
910 const KNOWNFOLDERID *fidParent;
912 const char *sRelativePath;
913 const char *sParsingName;
914 const DWORD attributes;
915 const KF_DEFINITION_FLAGS definitionFlags;
919 /* Note: content of parsing name may vary between Windows versions.
920 * As a base, values from 6.0 (Vista) were used. Some entries may contain
921 * alternative values. In that case, Windows version where the value was
924 * The list of values for parsing name was encoded as a number of null-
925 * terminated strings placed one by one (separated by null byte only).
926 * End of list is marked by two consecutive null bytes.
928 static const struct knownFolderDef known_folders[] = {
929 KNOWN_FOLDER(FOLDERID_AddNewPrograms,
931 "AddNewProgramsFolder",
935 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{15eae92e-f17a-4431-9f28-805e482dafd4}\0"
936 "shell:::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{15eae92e-f17a-4431-9f28-805e482dafd4}\0\0" /* 6.1 */,
939 KNOWN_FOLDER(FOLDERID_AdminTools,
941 "Administrative Tools",
944 "Administrative Tools",
946 FILE_ATTRIBUTE_READONLY,
948 KNOWN_FOLDER(FOLDERID_AppUpdates,
954 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{7b81be6a-ce2b-4676-a29e-eb907a5126c5}\\::{d450a8a1-9568-45c7-9c0e-b4f9fb4537bd}\0"
955 "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{7b81be6a-ce2b-4676-a29e-eb907a5126c5}\\::{d450a8a1-9568-45c7-9c0e-b4f9fb4537bd}\0\0" /* 6.1 */,
958 KNOWN_FOLDER(FOLDERID_CDBurning,
962 FOLDERID_LocalAppData,
963 "Microsoft\\Windows\\Burn\\Burn",
965 FILE_ATTRIBUTE_READONLY,
966 KFDF_LOCAL_REDIRECT_ONLY),
967 KNOWN_FOLDER(FOLDERID_ChangeRemovePrograms,
969 "ChangeRemoveProgramsFolder",
973 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{7b81be6a-ce2b-4676-a29e-eb907a5126c5}\0"
974 "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{7b81be6a-ce2b-4676-a29e-eb907a5126c5}\0\0" /* 6.1 */,
977 KNOWN_FOLDER(FOLDERID_CommonAdminTools,
978 CSIDL_COMMON_ADMINTOOLS,
979 "Common Administrative Tools",
981 FOLDERID_CommonPrograms,
982 "Administrative Tools",
984 FILE_ATTRIBUTE_READONLY,
986 KNOWN_FOLDER(FOLDERID_CommonOEMLinks,
987 CSIDL_COMMON_OEM_LINKS,"OEM Links",
989 FOLDERID_ProgramData,
994 KNOWN_FOLDER(FOLDERID_CommonPrograms,
995 CSIDL_COMMON_PROGRAMS,
998 FOLDERID_CommonStartMenu,
1001 FILE_ATTRIBUTE_READONLY,
1003 KNOWN_FOLDER(FOLDERID_CommonStartMenu,
1004 CSIDL_COMMON_STARTMENU,
1005 "Common Start Menu",
1007 FOLDERID_ProgramData,
1008 "Microsoft\\Windows\\Start Menu",
1010 FILE_ATTRIBUTE_READONLY,
1012 KNOWN_FOLDER(FOLDERID_CommonStartup,
1013 CSIDL_COMMON_STARTUP,
1016 FOLDERID_CommonPrograms,
1019 FILE_ATTRIBUTE_READONLY,
1021 KNOWN_FOLDER(FOLDERID_CommonTemplates,
1022 CSIDL_COMMON_TEMPLATES,
1025 FOLDERID_ProgramData,
1026 "Microsoft\\Windows\\Templates",
1030 KNOWN_FOLDER(FOLDERID_ComputerFolder,
1033 KF_CATEGORY_VIRTUAL,
1036 "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\0\0",
1039 KNOWN_FOLDER(FOLDERID_ConflictFolder,
1042 KF_CATEGORY_VIRTUAL,
1045 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\\::{E413D040-6788-4C22-957E-175D1C513A34},\0"
1046 "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\\::{E413D040-6788-4C22-957E-175D1C513A34},\0\0" /* 6.1 */,
1049 KNOWN_FOLDER(FOLDERID_ConnectionsFolder,
1051 "ConnectionsFolder",
1052 KF_CATEGORY_VIRTUAL,
1055 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{7007ACC7-3202-11D1-AAD2-00805FC1270E}\0"
1056 "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{7007ACC7-3202-11D1-AAD2-00805FC1270E}\0\0" /* 6.1 */,
1059 KNOWN_FOLDER(FOLDERID_Contacts,
1062 KF_CATEGORY_PERUSER,
1065 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{56784854-C6CB-462B-8169-88E350ACB882}\0\0",
1066 FILE_ATTRIBUTE_READONLY,
1067 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH),
1068 KNOWN_FOLDER(FOLDERID_ControlPanelFolder,
1070 "ControlPanelFolder",
1071 KF_CATEGORY_VIRTUAL,
1074 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\0"
1075 "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\0\0" /* 6.1 */,
1078 KNOWN_FOLDER(FOLDERID_Cookies,
1081 KF_CATEGORY_PERUSER,
1082 FOLDERID_RoamingAppData,
1083 "Microsoft\\Windows\\Cookies",
1087 KNOWN_FOLDER(FOLDERID_Desktop,
1090 KF_CATEGORY_PERUSER,
1094 FILE_ATTRIBUTE_READONLY,
1095 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH),
1096 KNOWN_FOLDER(FOLDERID_DeviceMetadataStore,
1098 "Device Metadata Store",
1100 FOLDERID_ProgramData,
1101 "Microsoft\\Windows\\DeviceMetadataStore",
1105 KNOWN_FOLDER(FOLDERID_Documents,
1108 KF_CATEGORY_PERUSER,
1111 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{FDD39AD0-238F-46AF-ADB4-6C85480369C7}\0\0",
1112 FILE_ATTRIBUTE_READONLY,
1113 KFDF_ROAMABLE | KFDF_PRECREATE),
1114 KNOWN_FOLDER(FOLDERID_DocumentsLibrary,
1117 KF_CATEGORY_PERUSER,
1119 "Documents.library-ms",
1120 "::{031E4825-7B94-4dc3-B131-E946B44C8DD5}\\{7b0db17d-9cd2-4a93-9733-46cc89022e7c}\0\0",
1122 KFDF_PRECREATE | KFDF_STREAM),
1123 KNOWN_FOLDER(FOLDERID_Downloads,
1126 KF_CATEGORY_PERUSER,
1130 FILE_ATTRIBUTE_READONLY,
1131 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH),
1132 KNOWN_FOLDER(FOLDERID_Favorites,
1135 KF_CATEGORY_PERUSER,
1139 FILE_ATTRIBUTE_READONLY,
1140 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH),
1141 KNOWN_FOLDER(FOLDERID_Fonts,
1150 KNOWN_FOLDER(FOLDERID_Games,
1153 KF_CATEGORY_VIRTUAL,
1156 "::{ED228FDF-9EA8-4870-83b1-96b02CFE0D52}\0\0",
1159 KNOWN_FOLDER(FOLDERID_GameTasks,
1162 KF_CATEGORY_PERUSER,
1163 FOLDERID_LocalAppData,
1164 "Microsoft\\Windows\\GameExplorer",
1167 KFDF_LOCAL_REDIRECT_ONLY),
1168 KNOWN_FOLDER(FOLDERID_History,
1171 KF_CATEGORY_PERUSER,
1172 FOLDERID_LocalAppData,
1173 "Microsoft\\Windows\\History",
1176 KFDF_LOCAL_REDIRECT_ONLY),
1177 KNOWN_FOLDER(FOLDERID_HomeGroup,
1180 KF_CATEGORY_VIRTUAL,
1183 "::{B4FB3F98-C1EA-428d-A78A-D1F5659CBA93}\0\0",
1186 KNOWN_FOLDER(FOLDERID_ImplicitAppShortcuts,
1188 "ImplicitAppShortcuts",
1189 KF_CATEGORY_PERUSER,
1190 FOLDERID_UserPinned,
1191 "ImplicitAppShortcuts",
1195 KNOWN_FOLDER(FOLDERID_InternetCache,
1196 CSIDL_INTERNET_CACHE,
1198 KF_CATEGORY_PERUSER,
1199 FOLDERID_LocalAppData,
1200 "Microsoft\\Windows\\Temporary Internet Files",
1203 KFDF_LOCAL_REDIRECT_ONLY),
1204 KNOWN_FOLDER(FOLDERID_InternetFolder,
1207 KF_CATEGORY_VIRTUAL,
1210 "::{871C5380-42A0-1069-A2EA-08002B30309D}\0\0",
1213 KNOWN_FOLDER(FOLDERID_Libraries,
1216 KF_CATEGORY_PERUSER,
1217 FOLDERID_RoamingAppData,
1218 "Microsoft\\Windows\\Libraries",
1221 KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH),
1222 KNOWN_FOLDER(FOLDERID_Links,
1225 KF_CATEGORY_PERUSER,
1228 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{bfb9d5e0-c6a9-404c-b2b2-ae6db6af4968}\0\0",
1229 FILE_ATTRIBUTE_READONLY,
1230 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH),
1231 KNOWN_FOLDER(FOLDERID_LocalAppData,
1232 CSIDL_LOCAL_APPDATA,
1234 KF_CATEGORY_PERUSER,
1239 KFDF_LOCAL_REDIRECT_ONLY | KFDF_PUBLISHEXPANDEDPATH),
1240 KNOWN_FOLDER(FOLDERID_LocalAppDataLow,
1243 KF_CATEGORY_PERUSER,
1245 "AppData\\LocalLow",
1247 FILE_ATTRIBUTE_NOT_CONTENT_INDEXED,
1248 KFDF_LOCAL_REDIRECT_ONLY | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH),
1249 KNOWN_FOLDER(FOLDERID_LocalizedResourcesDir,
1250 CSIDL_RESOURCES_LOCALIZED,
1251 "LocalizedResourcesDir",
1258 KNOWN_FOLDER(FOLDERID_Music,
1261 KF_CATEGORY_PERUSER,
1264 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{4BD8D571-6D19-48D3-BE97-422220080E43}\0\0",
1265 FILE_ATTRIBUTE_READONLY,
1266 KFDF_ROAMABLE | KFDF_PRECREATE),
1267 KNOWN_FOLDER(FOLDERID_MusicLibrary,
1270 KF_CATEGORY_PERUSER,
1273 "::{031E4825-7B94-4dc3-B131-E946B44C8DD5}\\{2112AB0A-C86A-4ffe-A368-0DE96E47012E}\0\0",
1275 KFDF_PRECREATE | KFDF_STREAM),
1276 KNOWN_FOLDER(FOLDERID_NetHood,
1279 KF_CATEGORY_PERUSER,
1280 FOLDERID_RoamingAppData,
1281 "Microsoft\\Windows\\Network Shortcuts",
1285 KNOWN_FOLDER(FOLDERID_NetworkFolder,
1287 "NetworkPlacesFolder",
1288 KF_CATEGORY_VIRTUAL,
1291 "::{F02C1A0D-BE21-4350-88B0-7367FC96EF3C}\0\0",
1294 KNOWN_FOLDER(FOLDERID_OriginalImages,
1297 KF_CATEGORY_PERUSER,
1298 FOLDERID_LocalAppData,
1299 "Microsoft\\Windows Photo Gallery\\Original Images",
1303 KNOWN_FOLDER(FOLDERID_PhotoAlbums,
1306 KF_CATEGORY_PERUSER,
1310 FILE_ATTRIBUTE_READONLY,
1312 KNOWN_FOLDER(FOLDERID_Pictures,
1315 KF_CATEGORY_PERUSER,
1318 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{33E28130-4E1E-4676-835A-98395C3BC3BB}\0\0",
1319 FILE_ATTRIBUTE_READONLY,
1320 KFDF_ROAMABLE | KFDF_PRECREATE),
1321 KNOWN_FOLDER(FOLDERID_PicturesLibrary,
1324 KF_CATEGORY_PERUSER,
1326 "Pictures.library-ms",
1327 "::{031E4825-7B94-4dc3-B131-E946B44C8DD5}\\{A990AE9F-A03B-4e80-94BC-9912D7504104}\0\0",
1329 KFDF_PRECREATE | KFDF_STREAM),
1330 KNOWN_FOLDER(FOLDERID_Playlists,
1333 KF_CATEGORY_PERUSER,
1337 FILE_ATTRIBUTE_READONLY,
1339 KNOWN_FOLDER(FOLDERID_PrintersFolder,
1342 KF_CATEGORY_VIRTUAL,
1345 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{2227A280-3AEA-1069-A2DE-08002B30309D}\0\0",
1348 KNOWN_FOLDER(FOLDERID_PrintHood,
1351 KF_CATEGORY_PERUSER,
1352 FOLDERID_RoamingAppData,
1353 "Microsoft\\Windows\\Printer Shortcuts",
1357 KNOWN_FOLDER(FOLDERID_Profile,
1366 KNOWN_FOLDER(FOLDERID_ProgramData,
1367 CSIDL_COMMON_APPDATA,
1375 KNOWN_FOLDER(FOLDERID_ProgramFiles,
1376 CSIDL_PROGRAM_FILES,
1382 FILE_ATTRIBUTE_READONLY,
1385 KNOWN_FOLDER(FOLDERID_ProgramFilesCommon,
1386 CSIDL_PROGRAM_FILES_COMMON,
1387 "ProgramFilesCommon",
1394 KNOWN_FOLDER(FOLDERID_ProgramFilesCommonX64,
1396 "ProgramFilesCommonX64",
1403 KNOWN_FOLDER(FOLDERID_ProgramFilesCommonX86,
1405 "ProgramFilesCommonX86",
1412 KNOWN_FOLDER(FOLDERID_ProgramFilesX64,
1421 KNOWN_FOLDER(FOLDERID_ProgramFilesX86,
1422 CSIDL_PROGRAM_FILESX86,
1428 FILE_ATTRIBUTE_READONLY,
1430 KNOWN_FOLDER(FOLDERID_Programs,
1433 KF_CATEGORY_PERUSER,
1437 FILE_ATTRIBUTE_READONLY,
1439 KNOWN_FOLDER(FOLDERID_Public,
1445 "::{4336a54d-038b-4685-ab02-99bb52d3fb8b}\0"
1446 "(null)\0\0" /* 6.1 */,
1447 FILE_ATTRIBUTE_READONLY,
1449 KNOWN_FOLDER(FOLDERID_PublicDesktop,
1450 CSIDL_COMMON_DESKTOPDIRECTORY,
1456 FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN,
1458 KNOWN_FOLDER(FOLDERID_PublicDocuments,
1459 CSIDL_COMMON_DOCUMENTS,
1465 FILE_ATTRIBUTE_READONLY,
1467 KNOWN_FOLDER(FOLDERID_PublicDownloads,
1474 FILE_ATTRIBUTE_READONLY,
1476 KNOWN_FOLDER(FOLDERID_PublicGameTasks,
1480 FOLDERID_ProgramData,
1481 "Microsoft\\Windows\\GameExplorer",
1484 KFDF_LOCAL_REDIRECT_ONLY),
1485 KNOWN_FOLDER(FOLDERID_PublicLibraries,
1492 FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN,
1494 KNOWN_FOLDER(FOLDERID_PublicMusic,
1501 FILE_ATTRIBUTE_READONLY,
1503 KNOWN_FOLDER(FOLDERID_PublicPictures,
1504 CSIDL_COMMON_PICTURES,
1510 FILE_ATTRIBUTE_READONLY,
1512 KNOWN_FOLDER(FOLDERID_PublicRingtones,
1516 FOLDERID_ProgramData,
1517 "Microsoft\\Windows\\Ringtones",
1521 KNOWN_FOLDER(FOLDERID_PublicVideos,
1528 FILE_ATTRIBUTE_READONLY,
1530 KNOWN_FOLDER(FOLDERID_QuickLaunch,
1533 KF_CATEGORY_PERUSER,
1534 FOLDERID_RoamingAppData,
1535 "Microsoft\\Internet Explorer\\Quick Launch",
1539 KNOWN_FOLDER(FOLDERID_Recent,
1542 KF_CATEGORY_PERUSER,
1543 FOLDERID_RoamingAppData,
1544 "Microsoft\\Windows\\Recent",
1546 FILE_ATTRIBUTE_READONLY,
1548 KNOWN_FOLDER(FOLDERID_RecordedTVLibrary,
1550 "RecordedTVLibrary",
1552 FOLDERID_PublicLibraries,
1553 "RecordedTV.library-ms",
1556 KFDF_PRECREATE | KFDF_STREAM),
1557 KNOWN_FOLDER(FOLDERID_RecycleBinFolder,
1560 KF_CATEGORY_VIRTUAL,
1563 "::{645FF040-5081-101B-9F08-00AA002F954E}\0\0",
1566 KNOWN_FOLDER(FOLDERID_ResourceDir,
1575 KNOWN_FOLDER(FOLDERID_Ringtones,
1578 KF_CATEGORY_PERUSER,
1579 FOLDERID_LocalAppData,
1580 "Microsoft\\Windows\\Ringtones",
1584 KNOWN_FOLDER(FOLDERID_RoamingAppData,
1587 KF_CATEGORY_PERUSER,
1593 KNOWN_FOLDER(FOLDERID_SampleMusic,
1597 FOLDERID_PublicMusic,
1600 FILE_ATTRIBUTE_READONLY,
1602 KNOWN_FOLDER(FOLDERID_SamplePictures,
1606 FOLDERID_PublicPictures,
1609 FILE_ATTRIBUTE_READONLY,
1611 KNOWN_FOLDER(FOLDERID_SamplePlaylists,
1615 FOLDERID_PublicMusic,
1618 FILE_ATTRIBUTE_READONLY,
1620 KNOWN_FOLDER(FOLDERID_SampleVideos,
1624 FOLDERID_PublicVideos,
1627 FILE_ATTRIBUTE_READONLY,
1629 KNOWN_FOLDER(FOLDERID_SavedGames,
1632 KF_CATEGORY_PERUSER,
1635 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{4C5C32FF-BB9D-43b0-B5B4-2D72E54EAAA4}\0\0",
1636 FILE_ATTRIBUTE_READONLY,
1637 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH),
1638 KNOWN_FOLDER(FOLDERID_SavedSearches,
1641 KF_CATEGORY_PERUSER,
1644 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{7d1d3a04-debb-4115-95cf-2f29da2920da}\0\0",
1645 FILE_ATTRIBUTE_READONLY,
1646 KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH),
1647 KNOWN_FOLDER(FOLDERID_SEARCH_CSC,
1650 KF_CATEGORY_VIRTUAL,
1653 "shell:::{BD7A2E7B-21CB-41b2-A086-B309680C6B7E}\\*\0\0",
1656 KNOWN_FOLDER(FOLDERID_SearchHome,
1659 KF_CATEGORY_VIRTUAL,
1662 "::{9343812e-1c37-4a49-a12e-4b2d810d956b}\0\0",
1665 KNOWN_FOLDER(FOLDERID_SEARCH_MAPI,
1668 KF_CATEGORY_VIRTUAL,
1671 "shell:::{89D83576-6BD1-4C86-9454-BEB04E94C819}\\*\0\0",
1674 KNOWN_FOLDER(FOLDERID_SendTo,
1677 KF_CATEGORY_PERUSER,
1678 FOLDERID_RoamingAppData,
1679 "Microsoft\\Windows\\SendTo",
1683 KNOWN_FOLDER(FOLDERID_SidebarDefaultParts,
1687 FOLDERID_ProgramFiles,
1688 "Windows Sidebar\\Gadgets",
1692 KNOWN_FOLDER(FOLDERID_SidebarParts,
1695 KF_CATEGORY_PERUSER,
1696 FOLDERID_LocalAppData,
1697 "Microsoft\\Windows Sidebar\\Gadgets",
1701 KNOWN_FOLDER(FOLDERID_StartMenu,
1704 KF_CATEGORY_PERUSER,
1705 FOLDERID_RoamingAppData,
1706 "Microsoft\\Windows\\Start Menu",
1708 FILE_ATTRIBUTE_READONLY,
1710 KNOWN_FOLDER(FOLDERID_Startup,
1713 KF_CATEGORY_PERUSER,
1717 FILE_ATTRIBUTE_READONLY,
1719 KNOWN_FOLDER(FOLDERID_SyncManagerFolder,
1722 KF_CATEGORY_VIRTUAL,
1725 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\0"
1726 "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\0\0" /* 6.1 */,
1729 KNOWN_FOLDER(FOLDERID_SyncResultsFolder,
1731 "SyncResultsFolder",
1732 KF_CATEGORY_VIRTUAL,
1735 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\\::{BC48B32F-5910-47F5-8570-5074A8A5636A},\0"
1736 "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\\::{BC48B32F-5910-47F5-8570-5074A8A5636A},\0\0",
1739 KNOWN_FOLDER(FOLDERID_SyncSetupFolder,
1742 KF_CATEGORY_VIRTUAL,
1745 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\\::{F1390A9A-A3F4-4E5D-9C5F-98F3BD8D935C},\0"
1746 "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\\::{F1390A9A-A3F4-4E5D-9C5F-98F3BD8D935C},\0\0" /* 6.1 */,
1749 KNOWN_FOLDER(FOLDERID_System,
1758 KNOWN_FOLDER(FOLDERID_SystemX86,
1767 KNOWN_FOLDER(FOLDERID_Templates,
1770 KF_CATEGORY_PERUSER,
1771 FOLDERID_RoamingAppData,
1772 "Microsoft\\Windows\\Templates",
1776 KNOWN_FOLDER(FOLDERID_UserPinned,
1779 KF_CATEGORY_PERUSER,
1780 FOLDERID_QuickLaunch,
1783 FILE_ATTRIBUTE_HIDDEN,
1785 KNOWN_FOLDER(FOLDERID_UserProfiles,
1792 FILE_ATTRIBUTE_READONLY,
1794 KNOWN_FOLDER(FOLDERID_UserProgramFiles,
1797 KF_CATEGORY_PERUSER,
1798 FOLDERID_LocalAppData,
1803 KNOWN_FOLDER(FOLDERID_UserProgramFilesCommon,
1805 "UserProgramFilesCommon",
1806 KF_CATEGORY_PERUSER,
1807 FOLDERID_UserProgramFiles,
1812 KNOWN_FOLDER(FOLDERID_UsersFiles,
1815 KF_CATEGORY_VIRTUAL,
1818 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\0\0",
1821 KNOWN_FOLDER(FOLDERID_UsersLibraries,
1823 "UsersLibrariesFolder",
1824 KF_CATEGORY_VIRTUAL,
1827 "::{031E4825-7B94-4dc3-B131-E946B44C8DD5}\0\0",
1830 KNOWN_FOLDER(FOLDERID_Videos,
1833 KF_CATEGORY_PERUSER,
1836 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{18989B1D-99B5-455B-841C-AB7C74E4DDFC}\0\0",
1837 FILE_ATTRIBUTE_READONLY,
1838 KFDF_ROAMABLE | KFDF_PRECREATE),
1839 KNOWN_FOLDER(FOLDERID_VideosLibrary,
1842 KF_CATEGORY_PERUSER,
1844 "Videos.library-ms",
1845 "::{031E4825-7B94-4dc3-B131-E946B44C8DD5}\\{491E922F-5643-4af4-A7EB-4E7A138D8174}\0\0",
1847 KFDF_PRECREATE | KFDF_STREAM),
1848 KNOWN_FOLDER(FOLDERID_Windows,
1857 KNOWN_FOLDER(_FOLDERID_CredentialManager,
1859 "CredentialManager",
1866 KNOWN_FOLDER(_FOLDERID_CryptoKeys,
1875 KNOWN_FOLDER(_FOLDERID_DpapiKeys,
1884 KNOWN_FOLDER(_FOLDERID_SystemCertificates,
1886 "SystemCertificates",
1893 { NULL, NULL, 0, NULL, NULL, 0, 0 }
1896 BOOL known_folder_found[sizeof(known_folders)/sizeof(known_folders[0])-1];
1898 static void check_known_folder(IKnownFolderManager *mgr, KNOWNFOLDERID *folderId)
1901 const struct knownFolderDef *known_folder = &known_folders[0];
1902 int csidl, expectedCsidl, ret;
1903 KNOWNFOLDER_DEFINITION kfd;
1904 IKnownFolder *folder;
1905 WCHAR sName[1024], sRelativePath[MAX_PATH], sParsingName[MAX_PATH];
1907 char sParentGuid[39];
1908 BOOL *current_known_folder_found = &known_folder_found[0];
1910 const char *srcParsingName;
1912 while(known_folder->folderId != NULL)
1914 if(IsEqualGUID(known_folder->folderId, folderId))
1916 *current_known_folder_found = TRUE;
1919 if(known_folder->csidl != NO_CSIDL)
1921 expectedCsidl = known_folder->csidl & (~CSIDL_TODO_WINE);
1923 hr = IKnownFolderManager_FolderIdToCsidl(mgr, folderId, &csidl);
1924 ok_(__FILE__, known_folder->line)(hr == S_OK, "cannot retrieve CSIDL for folder %s\n", known_folder->sFolderId);
1926 if(known_folder->csidl & CSIDL_TODO_WINE)
1927 todo_wine ok_(__FILE__, known_folder->line)(csidl == expectedCsidl, "invalid CSIDL retrieved for folder %s. %d (%s) expected, but %d found\n", known_folder->sFolderId, expectedCsidl, known_folder->sCsidl, csidl);
1929 ok_(__FILE__, known_folder->line)(csidl == expectedCsidl, "invalid CSIDL retrieved for folder %s. %d (%s) expected, but %d found\n", known_folder->sFolderId, expectedCsidl, known_folder->sCsidl, csidl);
1932 hr = IKnownFolderManager_GetFolder(mgr, folderId, &folder);
1933 ok_(__FILE__, known_folder->line)(hr == S_OK, "cannot get known folder for %s\n", known_folder->sFolderId);
1936 hr = IKnownFolder_GetFolderDefinition(folder, &kfd);
1938 ok_(__FILE__, known_folder->line)(hr == S_OK, "cannot get known folder definition for %s\n", known_folder->sFolderId);
1941 ret = MultiByteToWideChar(CP_ACP, 0, known_folder->sName, -1, sName, sizeof(sName)/sizeof(sName[0]));
1942 ok_(__FILE__, known_folder->line)(ret != 0, "cannot convert known folder name \"%s\" to wide characters\n", known_folder->sName);
1945 ok_(__FILE__, known_folder->line)(lstrcmpW(kfd.pszName, sName)==0, "invalid known folder name returned for %s: %s expected, but %s retrieved\n", known_folder->sFolderId, wine_dbgstr_w(sName), wine_dbgstr_w(kfd.pszName));
1947 ok_(__FILE__, known_folder->line)(kfd.category == known_folder->category, "invalid known folder category for %s: %d expected, but %d retrieved\n", known_folder->sFolderId, known_folder->category, kfd.category);
1949 printGUID(&kfd.fidParent, sParentGuid);
1950 ok_(__FILE__, known_folder->line)(IsEqualGUID(known_folder->fidParent, &kfd.fidParent), "invalid known folder parent for %s: %s expected, but %s retrieved\n", known_folder->sFolderId, known_folder->sParent, sParentGuid);
1952 if(!known_folder->sRelativePath)
1953 validPath = (kfd.pszRelativePath==NULL);
1956 ret = MultiByteToWideChar(CP_ACP, 0, known_folder->sRelativePath, -1, sRelativePath, sizeof(sRelativePath)/sizeof(sRelativePath[0]));
1957 ok_(__FILE__, known_folder->line)(ret != 0, "cannot convert known folder path \"%s\" to wide characters\n", known_folder->sRelativePath);
1959 validPath = (lstrcmpW(kfd.pszRelativePath, sRelativePath)==0);
1962 ok_(__FILE__, known_folder->line)(validPath, "invalid known folder relative path returned for %s: %s expected, but %s retrieved\n", known_folder->sFolderId, known_folder->sRelativePath, wine_dbgstr_w(kfd.pszRelativePath));
1964 /* to check parsing name, we need to iterate list */
1965 srcParsingName = known_folder->sParsingName;
1967 /* if we expect NULL, then we don't even check the list */
1968 validPath = (srcParsingName==NULL) && (kfd.pszParsingName==NULL);
1971 while(*srcParsingName && !validPath)
1973 /* when NULL is only one of possible value, we mark path as valid */
1974 validPath = (strcmp(srcParsingName, "(null)")==0) && (kfd.pszParsingName==NULL);
1976 /* in the other case, we compare string from list with retrieved value */
1979 ret = MultiByteToWideChar(CP_ACP, 0, srcParsingName, -1, sParsingName, sizeof(sParsingName)/sizeof(sParsingName[0]));
1980 ok_(__FILE__, known_folder->line)(ret != 0, "cannot convert known folder path \"%s\" to wide characters\n", srcParsingName);
1982 validPath = (lstrcmpW(kfd.pszParsingName, sParsingName)==0);
1985 srcParsingName += strlen(srcParsingName)+1;
1988 ok_(__FILE__, known_folder->line)(validPath, "invalid known folder parsing name returned for %s: %s retrieved\n", known_folder->sFolderId, wine_dbgstr_w(kfd.pszParsingName));
1990 ok_(__FILE__, known_folder->line)(known_folder->attributes == kfd.dwAttributes, "invalid known folder attributes for %s: 0x%08x expected, but 0x%08x retrieved\n", known_folder->sFolderId, known_folder->attributes, kfd.dwAttributes);
1992 ok_(__FILE__, known_folder->line)(!(kfd.kfdFlags & (~known_folder->definitionFlags)), "invalid known folder flags for %s: 0x%08x expected, but 0x%08x retrieved\n", known_folder->sFolderId, known_folder->definitionFlags, kfd.kfdFlags);
1994 FreeKnownFolderDefinitionFields(&kfd);
1997 IKnownFolder_Release(folder);
2003 current_known_folder_found++;
2008 printGUID(folderId, sParentGuid);
2009 trace("unknown known folder found: %s\n", sParentGuid);
2011 hr = IKnownFolderManager_GetFolder(mgr, folderId, &folder);
2012 ok(hr == S_OK, "cannot get known folder for %s\n", sParentGuid);
2015 hr = IKnownFolder_GetFolderDefinition(folder, &kfd);
2017 ok(hr == S_OK, "cannot get known folder definition for %s\n", sParentGuid);
2020 trace(" category: %d\n", kfd.category);
2021 trace(" name: %s\n", wine_dbgstr_w(kfd.pszName));
2022 trace(" description: %s\n", wine_dbgstr_w(kfd.pszDescription));
2023 printGUID(&kfd.fidParent, sParentGuid);
2024 trace(" parent: %s\n", sParentGuid);
2025 trace(" relative path: %s\n", wine_dbgstr_w(kfd.pszRelativePath));
2026 trace(" parsing name: %s\n", wine_dbgstr_w(kfd.pszParsingName));
2027 trace(" tooltip: %s\n", wine_dbgstr_w(kfd.pszTooltip));
2028 trace(" localized name: %s\n", wine_dbgstr_w(kfd.pszLocalizedName));
2029 trace(" icon: %s\n", wine_dbgstr_w(kfd.pszIcon));
2030 trace(" security: %s\n", wine_dbgstr_w(kfd.pszSecurity));
2031 trace(" attributes: 0x%08x\n", kfd.dwAttributes);
2032 trace(" flags: 0x%08x\n", kfd.kfdFlags);
2033 printGUID(&kfd.ftidType, sParentGuid);
2034 trace(" type: %s\n", sParentGuid);
2035 FreeKnownFolderDefinitionFields(&kfd);
2038 IKnownFolder_Release(folder);
2043 #undef CSIDL_TODO_WINE
2045 static void test_knownFolders(void)
2047 static const WCHAR sWindows[] = {'W','i','n','d','o','w','s',0};
2048 static const WCHAR sExample[] = {'E','x','a','m','p','l','e',0};
2049 static const WCHAR sExample2[] = {'E','x','a','m','p','l','e','2',0};
2050 static const WCHAR sSubFolder[] = {'S','u','b','F','o','l','d','e','r',0};
2051 static const WCHAR sBackslash[] = {'\\',0};
2052 static const KNOWNFOLDERID newFolderId = {0x01234567, 0x89AB, 0xCDEF, {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x01} };
2053 static const KNOWNFOLDERID subFolderId = {0xFEDCBA98, 0x7654, 0x3210, {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF} };
2055 IKnownFolderManager *mgr = NULL;
2056 IKnownFolder *folder = NULL, *subFolder = NULL;
2057 KNOWNFOLDERID folderId, *folders;
2058 KF_CATEGORY cat = 0;
2059 KNOWNFOLDER_DEFINITION kfDefinition, kfSubDefinition;
2062 LPWSTR folderPath, errorMsg;
2063 KF_REDIRECTION_CAPABILITIES redirectionCapabilities = 1;
2064 WCHAR sWinDir[MAX_PATH], sExamplePath[MAX_PATH], sExample2Path[MAX_PATH], sSubFolderPath[MAX_PATH], sSubFolder2Path[MAX_PATH];
2068 GetWindowsDirectoryW( sWinDir, MAX_PATH );
2070 GetTempPathW(sizeof(sExamplePath)/sizeof(sExamplePath[0]), sExamplePath);
2071 lstrcatW(sExamplePath, sExample);
2073 GetTempPathW(sizeof(sExample2Path)/sizeof(sExample2Path[0]), sExample2Path);
2074 lstrcatW(sExample2Path, sExample2);
2076 lstrcpyW(sSubFolderPath, sExamplePath);
2077 lstrcatW(sSubFolderPath, sBackslash);
2078 lstrcatW(sSubFolderPath, sSubFolder);
2080 lstrcpyW(sSubFolder2Path, sExample2Path);
2081 lstrcatW(sSubFolder2Path, sBackslash);
2082 lstrcatW(sSubFolder2Path, sSubFolder);
2086 hr = CoCreateInstance(&CLSID_KnownFolderManager, NULL, CLSCTX_INPROC_SERVER,
2087 &IID_IKnownFolderManager, (LPVOID*)&mgr);
2088 if(hr == REGDB_E_CLASSNOTREG)
2089 win_skip("IKnownFolderManager unavailable\n");
2092 ok(hr == S_OK, "failed to create KnownFolderManager instance: 0x%08x\n", hr);
2094 hr = IKnownFolderManager_FolderIdFromCsidl(mgr, CSIDL_WINDOWS, &folderId);
2095 ok(hr == S_OK, "failed to convert CSIDL to KNOWNFOLDERID: 0x%08x\n", hr);
2096 ok(IsEqualGUID(&folderId, &FOLDERID_Windows)==TRUE, "invalid KNOWNFOLDERID returned\n");
2098 hr = IKnownFolderManager_FolderIdToCsidl(mgr, &FOLDERID_Windows, &csidl);
2099 ok(hr == S_OK, "failed to convert CSIDL to KNOWNFOLDERID: 0x%08x\n", hr);
2100 ok(csidl == CSIDL_WINDOWS, "invalid CSIDL returned\n");
2102 hr = IKnownFolderManager_GetFolder(mgr, &FOLDERID_Windows, &folder);
2103 ok(hr == S_OK, "failed to get known folder: 0x%08x\n", hr);
2106 hr = IKnownFolder_GetCategory(folder, &cat);
2108 ok(hr == S_OK, "failed to get folder category: 0x%08x\n", hr);
2110 ok(cat==KF_CATEGORY_FIXED, "invalid folder category: %d\n", cat);
2112 hr = IKnownFolder_GetId(folder, &folderId);
2113 ok(hr == S_OK, "failed to get folder id: 0x%08x\n", hr);
2114 ok(IsEqualGUID(&folderId, &FOLDERID_Windows)==TRUE, "invalid KNOWNFOLDERID returned\n");
2116 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
2117 ok(lstrcmpiW(sWinDir, folderPath)==0, "invalid path returned: \"%s\", expected: \"%s\"\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sWinDir));
2118 CoTaskMemFree(folderPath);
2120 hr = IKnownFolder_GetRedirectionCapabilities(folder, &redirectionCapabilities);
2122 ok(hr == S_OK, "failed to get redirection capabilities: 0x%08x\n", hr);
2124 ok(redirectionCapabilities==0, "invalid redirection capabilities returned: %d\n", redirectionCapabilities);
2126 hr = IKnownFolder_SetPath(folder, 0, sWinDir);
2128 ok(hr == E_INVALIDARG, "unexpected value from SetPath: 0x%08x\n", hr);
2130 hr = IKnownFolder_GetFolderDefinition(folder, &kfDefinition);
2132 ok(hr == S_OK, "failed to get folder definition: 0x%08x\n", hr);
2136 ok(kfDefinition.category==KF_CATEGORY_FIXED, "invalid folder category: 0x%08x\n", kfDefinition.category);
2138 ok(lstrcmpW(kfDefinition.pszName, sWindows)==0, "invalid folder name: %s\n", wine_dbgstr_w(kfDefinition.pszName));
2140 ok(kfDefinition.dwAttributes==0, "invalid folder attributes: %d\n", kfDefinition.dwAttributes);
2141 FreeKnownFolderDefinitionFields(&kfDefinition);
2144 hr = IKnownFolder_Release(folder);
2145 ok(hr == S_OK, "failed to release KnownFolder instance: 0x%08x\n", hr);
2148 hr = IKnownFolderManager_GetFolderByName(mgr, sWindows, &folder);
2150 ok(hr == S_OK, "failed to get known folder: 0x%08x\n", hr);
2153 hr = IKnownFolder_GetId(folder, &folderId);
2154 ok(hr == S_OK, "failed to get folder id: 0x%08x\n", hr);
2155 ok(IsEqualGUID(&folderId, &FOLDERID_Windows)==TRUE, "invalid KNOWNFOLDERID returned\n");
2157 hr = IKnownFolder_Release(folder);
2158 ok(hr == S_OK, "failed to release KnownFolder instance: 0x%08x\n", hr);
2161 for(i=0; i<sizeof(known_folder_found)/sizeof(known_folder_found[0]); ++i)
2162 known_folder_found[i] = FALSE;
2164 hr = IKnownFolderManager_GetFolderIds(mgr, &folders, &nCount);
2165 ok(hr == S_OK, "failed to get known folders: 0x%08x\n", hr);
2166 for(i=0;i<nCount;++i)
2167 check_known_folder(mgr, &folders[i]);
2169 for(i=0; i<sizeof(known_folder_found)/sizeof(known_folder_found[0]); ++i)
2170 if(!known_folder_found[i])
2171 trace("Known folder %s not found on current platform\n", known_folders[i].sFolderId);
2173 CoTaskMemFree(folders);
2175 /* test of registering new known folders */
2176 bRes = CreateDirectoryW(sExamplePath, NULL);
2177 ok(bRes, "cannot create example directory: %s\n", wine_dbgstr_w(sExamplePath));
2178 bRes = CreateDirectoryW(sExample2Path, NULL);
2179 ok(bRes, "cannot create example directory: %s\n", wine_dbgstr_w(sExample2Path));
2180 bRes = CreateDirectoryW(sSubFolderPath, NULL);
2181 ok(bRes, "cannot create example directory: %s\n", wine_dbgstr_w(sSubFolderPath));
2183 ZeroMemory(&kfDefinition, sizeof(kfDefinition));
2184 kfDefinition.category = KF_CATEGORY_PERUSER;
2185 kfDefinition.pszName = CoTaskMemAlloc(sizeof(sExample));
2186 lstrcpyW(kfDefinition.pszName, sExample);
2187 kfDefinition.pszDescription = CoTaskMemAlloc(sizeof(sExample));
2188 lstrcpyW(kfDefinition.pszDescription, sExample);
2189 kfDefinition.pszRelativePath = CoTaskMemAlloc(sizeof(sExamplePath));
2190 lstrcpyW(kfDefinition.pszRelativePath, sExamplePath);
2192 hr = IKnownFolderManager_RegisterFolder(mgr, &newFolderId, &kfDefinition);
2193 if(hr == HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED))
2194 win_skip("No permissions required to register custom known folder\n");
2197 ok(hr == S_OK, "failed to register known folder: 0x%08x\n", hr);
2200 hr = IKnownFolderManager_GetFolder(mgr, &newFolderId, &folder);
2201 ok(hr == S_OK, "failed to get known folder: 0x%08x\n", hr);
2204 hr = IKnownFolder_GetCategory(folder, &cat);
2205 ok(hr == S_OK, "failed to get folder category: hr=0x%0x\n", hr);
2206 ok(cat == KF_CATEGORY_PERUSER, "invalid category returned: %d, while %d (KF_CATEGORY_PERUSER) expected\n", cat, KF_CATEGORY_PERUSER);
2208 hr = IKnownFolder_GetId(folder, &folderId);
2209 ok(hr == S_OK, "failed to get folder id: 0x%08x\n", hr);
2210 ok(IsEqualGUID(&folderId, &newFolderId)==TRUE, "invalid KNOWNFOLDERID returned\n");
2212 /* current path should be Temp\Example */
2213 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
2214 ok(hr == S_OK, "failed to get path from known folder: 0x%08x\n", hr);
2215 ok(lstrcmpiW(folderPath, sExamplePath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExamplePath));
2216 CoTaskMemFree(folderPath);
2218 /* register sub-folder and mark it as child of Example folder */
2219 ZeroMemory(&kfSubDefinition, sizeof(kfSubDefinition));
2220 kfSubDefinition.category = KF_CATEGORY_PERUSER;
2221 kfSubDefinition.pszName = CoTaskMemAlloc(sizeof(sSubFolder));
2222 lstrcpyW(kfSubDefinition.pszName, sSubFolder);
2223 kfSubDefinition.pszDescription = CoTaskMemAlloc(sizeof(sSubFolder));
2224 lstrcpyW(kfSubDefinition.pszDescription, sSubFolder);
2225 kfSubDefinition.pszRelativePath = CoTaskMemAlloc(sizeof(sSubFolder));
2226 lstrcpyW(kfSubDefinition.pszRelativePath, sSubFolder);
2227 kfSubDefinition.fidParent = newFolderId;
2229 hr = IKnownFolderManager_RegisterFolder(mgr, &subFolderId, &kfSubDefinition);
2230 ok(hr == S_OK, "failed to register known folder: 0x%08x\n", hr);
2234 hr = IKnownFolderManager_GetFolder(mgr, &subFolderId, &subFolder);
2235 ok(hr == S_OK, "failed to get known folder: 0x%08x\n", hr);
2238 /* check sub folder path */
2239 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
2240 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2241 ok(lstrcmpiW(folderPath, sSubFolderPath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolderPath));
2242 CoTaskMemFree(folderPath);
2245 /* try to redirect Example to Temp\Example2 */
2246 hr = IKnownFolderManager_Redirect(mgr, &newFolderId, NULL, 0, sExample2Path, 0, NULL, &errorMsg);
2247 ok(hr == S_OK, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr, wine_dbgstr_w(errorMsg));
2250 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
2251 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2252 ok(lstrcmpiW(folderPath, sExample2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExample2Path));
2253 CoTaskMemFree(folderPath);
2255 /* verify sub folder - it should fail now, as we redirected it's parent folder, but we have no sub folder in new location */
2256 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
2257 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "unexpected value from GetPath(): 0x%08x\n", hr);
2258 ok(folderPath==NULL, "invalid known folder path retrieved: \"%s\" when NULL pointer was expected\n", wine_dbgstr_w(folderPath));
2259 CoTaskMemFree(folderPath);
2262 /* set Example path to original. Using SetPath() is valid here, as it also uses redirection internally */
2263 hr = IKnownFolder_SetPath(folder, 0, sExamplePath);
2264 ok(hr == S_OK, "SetPath() failed: 0x%08x\n", hr);
2267 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
2268 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2269 ok(lstrcmpiW(folderPath, sExamplePath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExamplePath));
2270 CoTaskMemFree(folderPath);
2273 /* create sub folder in Temp\Example2 */
2274 bRes = CreateDirectoryW(sSubFolder2Path, NULL);
2275 ok(bRes, "cannot create example directory: %s\n", wine_dbgstr_w(sSubFolder2Path));
2277 /* again perform that same redirection */
2278 hr = IKnownFolderManager_Redirect(mgr, &newFolderId, NULL, 0, sExample2Path, 0, NULL, &errorMsg);
2279 ok(hr == S_OK, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr, wine_dbgstr_w(errorMsg));
2281 /* verify sub folder. It should succeed now, as the required sub folder exists */
2282 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
2283 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2284 ok(lstrcmpiW(folderPath, sSubFolder2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolder2Path));
2285 CoTaskMemFree(folderPath);
2287 /* remove newly created directory */
2288 RemoveDirectoryW(sSubFolder2Path);
2290 /* verify sub folder. It still succeedes, so Windows does not check folder presence each time */
2291 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
2293 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2295 ok(lstrcmpiW(folderPath, sSubFolder2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolder2Path));
2296 CoTaskMemFree(folderPath);
2299 /* set Example path to original */
2300 hr = IKnownFolder_SetPath(folder, 0, sExamplePath);
2301 ok(hr == S_OK, "SetPath() failed: 0x%08x\n", hr);
2304 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
2305 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2306 ok(lstrcmpiW(folderPath, sExamplePath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExamplePath));
2307 CoTaskMemFree(folderPath);
2309 /* verify sub folder */
2310 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
2311 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2312 ok(lstrcmpiW(folderPath, sSubFolderPath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolderPath));
2313 CoTaskMemFree(folderPath);
2316 /* create sub folder in Temp\Example2 */
2317 bRes = CreateDirectoryW(sSubFolder2Path, NULL);
2318 ok(bRes, "cannot create example directory: %s\n", wine_dbgstr_w(sSubFolder2Path));
2320 /* do that same redirection, but try to exclude sub-folder */
2321 hr = IKnownFolderManager_Redirect(mgr, &newFolderId, NULL, 0, sExample2Path, 1, &subFolderId, &errorMsg);
2322 ok(hr == S_OK, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr, wine_dbgstr_w(errorMsg));
2325 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
2326 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2327 ok(lstrcmpiW(folderPath, sExample2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExample2Path));
2328 CoTaskMemFree(folderPath);
2330 /* verify sub folder. Unexpectedly, this path was also changed. So, exclusion seems to be ignored (Windows bug)? This test however will let us know, if this behavior is changed */
2331 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
2332 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2333 ok(lstrcmpiW(folderPath, sSubFolder2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolder2Path));
2334 CoTaskMemFree(folderPath);
2336 /* remove newly created directory */
2337 RemoveDirectoryW(sSubFolder2Path);
2340 /* set Example path to original */
2341 hr = IKnownFolder_SetPath(folder, 0, sExamplePath);
2342 ok(hr == S_OK, "SetPath() failed: 0x%08x\n", hr);
2345 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
2346 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2347 ok(lstrcmpiW(folderPath, sExamplePath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExamplePath));
2348 CoTaskMemFree(folderPath);
2350 /* verify sub folder */
2351 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
2352 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2353 ok(lstrcmpiW(folderPath, sSubFolderPath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolderPath));
2354 CoTaskMemFree(folderPath);
2357 /* do that same redirection again, but set it to copy content. It should also copy the sub folder, so checking it would succeed now */
2358 hr = IKnownFolderManager_Redirect(mgr, &newFolderId, NULL, KF_REDIRECT_COPY_CONTENTS, sExample2Path, 0, NULL, &errorMsg);
2359 ok(hr == S_OK, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr, wine_dbgstr_w(errorMsg));
2362 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
2363 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2364 ok(lstrcmpiW(folderPath, sExample2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExample2Path));
2365 CoTaskMemFree(folderPath);
2367 /* verify sub folder */
2368 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
2369 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2370 ok(lstrcmpiW(folderPath, sSubFolder2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolder2Path));
2371 CoTaskMemFree(folderPath);
2373 /* remove copied directory */
2374 RemoveDirectoryW(sSubFolder2Path);
2377 /* set Example path to original */
2378 hr = IKnownFolder_SetPath(folder, 0, sExamplePath);
2379 ok(hr == S_OK, "SetPath() failed: 0x%08x\n", hr);
2382 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
2383 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2384 ok(lstrcmpiW(folderPath, sExamplePath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExamplePath));
2385 CoTaskMemFree(folderPath);
2387 /* verify sub folder */
2388 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
2389 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2390 ok(lstrcmpiW(folderPath, sSubFolderPath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolderPath));
2391 CoTaskMemFree(folderPath);
2394 /* redirect again, set it to copy content and remove originals */
2395 hr = IKnownFolderManager_Redirect(mgr, &newFolderId, NULL, KF_REDIRECT_COPY_CONTENTS | KF_REDIRECT_DEL_SOURCE_CONTENTS, sExample2Path, 0, NULL, &errorMsg);
2396 ok(hr == S_OK, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr, wine_dbgstr_w(errorMsg));
2399 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
2400 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2401 ok(lstrcmpiW(folderPath, sExample2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExample2Path));
2402 CoTaskMemFree(folderPath);
2404 /* verify sub folder */
2405 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
2406 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2407 ok(lstrcmpiW(folderPath, sSubFolder2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolder2Path));
2408 CoTaskMemFree(folderPath);
2410 /* check if original directory was really removed */
2411 dwAttributes = GetFileAttributesW(sExamplePath);
2412 ok(dwAttributes==INVALID_FILE_ATTRIBUTES, "directory should not exist, but has attributes: 0x%08x\n", dwAttributes );
2415 /* redirect (with copy) to original path */
2416 hr = IKnownFolderManager_Redirect(mgr, &newFolderId, NULL, KF_REDIRECT_COPY_CONTENTS, sExamplePath, 0, NULL, &errorMsg);
2417 ok(hr == S_OK, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr, wine_dbgstr_w(errorMsg));
2420 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
2421 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2422 ok(lstrcmpiW(folderPath, sExamplePath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExamplePath));
2423 CoTaskMemFree(folderPath);
2425 /* verify sub folder */
2426 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
2427 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2428 ok(lstrcmpiW(folderPath, sSubFolderPath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolderPath));
2429 CoTaskMemFree(folderPath);
2431 /* check shell utility functions */
2432 if(!pSHGetKnownFolderPath || !pSHSetKnownFolderPath)
2434 win_skip("cannot get SHGet/SetKnownFolderPath routines\n");
2437 /* try to get current known folder path */
2438 hr = pSHGetKnownFolderPath(&newFolderId, 0, NULL, &folderPath);
2440 ok(hr==S_OK, "cannot get known folder path: hr=0x%0x\n", hr);
2442 ok(lstrcmpW(folderPath, sExamplePath)==0, "invalid path returned: %s\n", wine_dbgstr_w(folderPath));
2444 /* set it to new value */
2445 hr = pSHSetKnownFolderPath(&newFolderId, 0, NULL, sExample2Path);
2447 ok(hr==S_OK, "cannot set known folder path: hr=0x%0x\n", hr);
2449 /* check if it changed */
2450 hr = pSHGetKnownFolderPath(&newFolderId, 0, NULL, &folderPath);
2452 ok(hr==S_OK, "cannot get known folder path: hr=0x%0x\n", hr);
2454 ok(lstrcmpW(folderPath, sExample2Path)==0, "invalid path returned: %s\n", wine_dbgstr_w(folderPath));
2457 hr = pSHSetKnownFolderPath(&newFolderId, 0, NULL, sExamplePath);
2459 ok(hr==S_OK, "cannot set known folder path: hr=0x%0x\n", hr);
2462 IKnownFolder_Release(subFolder);
2465 hr = IKnownFolderManager_UnregisterFolder(mgr, &subFolderId);
2466 ok(hr == S_OK, "failed to unregister folder: 0x%08x\n", hr);
2469 FreeKnownFolderDefinitionFields(&kfSubDefinition);
2471 hr = IKnownFolder_Release(folder);
2472 ok(hr == S_OK, "failed to release KnownFolder instance: 0x%08x\n", hr);
2475 hr = IKnownFolderManager_UnregisterFolder(mgr, &newFolderId);
2476 ok(hr == S_OK, "failed to unregister folder: 0x%08x\n", hr);
2479 FreeKnownFolderDefinitionFields(&kfDefinition);
2481 RemoveDirectoryW(sSubFolder2Path);
2482 RemoveDirectoryW(sSubFolderPath);
2483 RemoveDirectoryW(sExamplePath);
2484 RemoveDirectoryW(sExample2Path);
2486 hr = IKnownFolderManager_Release(mgr);
2487 ok(hr == S_OK, "failed to release KnownFolderManager instance: 0x%08x\n", hr);
2492 START_TEST(shellpath)
2494 if (!init()) return;
2497 pGetSystemWow64DirectoryA = (void *)GetProcAddress( GetModuleHandleA("kernel32.dll"),
2498 "GetSystemWow64DirectoryA" );
2503 /* Report missing functions once */
2504 if (!pSHGetFolderLocation)
2505 win_skip("SHGetFolderLocation is not available\n");
2507 /* first test various combinations of parameters: */
2510 /* check known values: */
2516 test_NonExistentPath();
2517 test_SHGetFolderPathEx();
2518 test_knownFolders();