shell32: Use E_NOT_SUFFICIENT_BUFFER definition.
[wine/multimedia.git] / dlls / shell32 / tests / shellpath.c
blobe2277ecdb0f7bea09a675142be77a7c1974b2247
1 /*
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).
24 #define COBJMACROS
26 #include <stdarg.h>
27 #include <stdio.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "shlguid.h"
31 #include "shlobj.h"
32 #include "shlwapi.h"
33 #include "knownfolders.h"
34 #include "shellapi.h"
35 #include "wine/test.h"
37 #include "initguid.h"
39 /* CSIDL_MYDOCUMENTS is now the same as CSIDL_PERSONAL, but what we want
40 * here is its original value.
42 #define OLD_CSIDL_MYDOCUMENTS 0x000c
44 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
46 #ifndef ARRAY_SIZE
47 #define ARRAY_SIZE(x) ( sizeof(x) / sizeof((x)[0]) )
48 #endif
50 /* from pidl.h, not included here: */
51 #ifndef PT_CPL /* Guess, Win7 uses this for CSIDL_CONTROLS */
52 #define PT_CPL 0x01 /* no path */
53 #endif
54 #ifndef PT_GUID
55 #define PT_GUID 0x1f /* no path */
56 #endif
57 #ifndef PT_DRIVE
58 #define PT_DRIVE 0x23 /* has path */
59 #endif
60 #ifndef PT_DRIVE2
61 #define PT_DRIVE2 0x25 /* has path */
62 #endif
63 #ifndef PT_SHELLEXT
64 #define PT_SHELLEXT 0x2e /* no path */
65 #endif
66 #ifndef PT_FOLDER
67 #define PT_FOLDER 0x31 /* has path */
68 #endif
69 #ifndef PT_FOLDERW
70 #define PT_FOLDERW 0x35 /* has path */
71 #endif
72 #ifndef PT_WORKGRP
73 #define PT_WORKGRP 0x41 /* no path */
74 #endif
75 #ifndef PT_YAGUID
76 #define PT_YAGUID 0x70 /* no path */
77 #endif
78 /* FIXME: this is used for history/favorites folders; what's a better name? */
79 #ifndef PT_IESPECIAL2
80 #define PT_IESPECIAL2 0xb1 /* has path */
81 #endif
83 static GUID CLSID_CommonDocuments = { 0x0000000c, 0x0000, 0x0000, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x1a } };
85 struct shellExpectedValues {
86 int folder;
87 int numTypes;
88 const BYTE *types;
91 static HRESULT (WINAPI *pDllGetVersion)(DLLVERSIONINFO *);
92 static HRESULT (WINAPI *pSHGetFolderPathA)(HWND, int, HANDLE, DWORD, LPSTR);
93 static HRESULT (WINAPI *pSHGetFolderLocation)(HWND, int, HANDLE, DWORD,
94 LPITEMIDLIST *);
95 static BOOL (WINAPI *pSHGetSpecialFolderPathA)(HWND, LPSTR, int, BOOL);
96 static HRESULT (WINAPI *pSHGetSpecialFolderLocation)(HWND, int, LPITEMIDLIST *);
97 static LPITEMIDLIST (WINAPI *pILFindLastID)(LPCITEMIDLIST);
98 static int (WINAPI *pSHFileOperationA)(LPSHFILEOPSTRUCTA);
99 static HRESULT (WINAPI *pSHGetMalloc)(LPMALLOC *);
100 static UINT (WINAPI *pGetSystemWow64DirectoryA)(LPSTR,UINT);
101 static HRESULT (WINAPI *pSHGetKnownFolderPath)(REFKNOWNFOLDERID, DWORD, HANDLE, PWSTR *);
102 static HRESULT (WINAPI *pSHSetKnownFolderPath)(REFKNOWNFOLDERID, DWORD, HANDLE, PWSTR);
103 static HRESULT (WINAPI *pSHGetFolderPathEx)(REFKNOWNFOLDERID, DWORD, HANDLE, LPWSTR, DWORD);
104 static BOOL (WINAPI *pPathYetAnotherMakeUniqueName)(PWSTR, PCWSTR, PCWSTR, PCWSTR);
106 static DLLVERSIONINFO shellVersion = { 0 };
107 static LPMALLOC pMalloc;
108 static const BYTE guidType[] = { PT_GUID };
109 static const BYTE controlPanelType[] = { PT_SHELLEXT, PT_GUID, PT_CPL };
110 static const BYTE folderType[] = { PT_FOLDER, PT_FOLDERW };
111 static const BYTE favoritesType[] = { PT_FOLDER, PT_FOLDERW, 0, PT_IESPECIAL2 /* Win98 */ };
112 static const BYTE folderOrSpecialType[] = { PT_FOLDER, PT_IESPECIAL2 };
113 static const BYTE personalType[] = { PT_FOLDER, PT_GUID, PT_DRIVE, 0xff /* Win9x */,
114 PT_IESPECIAL2 /* Win98 */, 0 /* Vista */ };
115 /* FIXME: don't know the type of 0x71 returned by Vista/2008 for printers */
116 static const BYTE printersType[] = { PT_YAGUID, PT_SHELLEXT, 0x71 };
117 static const BYTE ieSpecialType[] = { PT_IESPECIAL2 };
118 static const BYTE shellExtType[] = { PT_SHELLEXT };
119 static const BYTE workgroupType[] = { PT_WORKGRP };
120 #define DECLARE_TYPE(x, y) { x, sizeof(y) / sizeof(y[0]), y }
121 static const struct shellExpectedValues requiredShellValues[] = {
122 DECLARE_TYPE(CSIDL_BITBUCKET, guidType),
123 DECLARE_TYPE(CSIDL_CONTROLS, controlPanelType),
124 DECLARE_TYPE(CSIDL_COOKIES, folderType),
125 DECLARE_TYPE(CSIDL_DESKTOPDIRECTORY, folderType),
126 DECLARE_TYPE(CSIDL_DRIVES, guidType),
127 DECLARE_TYPE(CSIDL_FAVORITES, favoritesType),
128 DECLARE_TYPE(CSIDL_FONTS, folderOrSpecialType),
129 /* FIXME: the following fails in Wine, returns type PT_FOLDER
130 DECLARE_TYPE(CSIDL_HISTORY, ieSpecialType),
132 DECLARE_TYPE(CSIDL_INTERNET, guidType),
133 DECLARE_TYPE(CSIDL_NETHOOD, folderType),
134 DECLARE_TYPE(CSIDL_NETWORK, guidType),
135 DECLARE_TYPE(CSIDL_PERSONAL, personalType),
136 DECLARE_TYPE(CSIDL_PRINTERS, printersType),
137 DECLARE_TYPE(CSIDL_PRINTHOOD, folderType),
138 DECLARE_TYPE(CSIDL_PROGRAMS, folderType),
139 DECLARE_TYPE(CSIDL_RECENT, folderOrSpecialType),
140 DECLARE_TYPE(CSIDL_SENDTO, folderType),
141 DECLARE_TYPE(CSIDL_STARTMENU, folderType),
142 DECLARE_TYPE(CSIDL_STARTUP, folderType),
143 DECLARE_TYPE(CSIDL_TEMPLATES, folderType),
145 static const struct shellExpectedValues optionalShellValues[] = {
146 /* FIXME: the following only semi-succeed; they return NULL PIDLs on XP.. hmm.
147 DECLARE_TYPE(CSIDL_ALTSTARTUP, folderType),
148 DECLARE_TYPE(CSIDL_COMMON_ALTSTARTUP, folderType),
149 DECLARE_TYPE(CSIDL_COMMON_OEM_LINKS, folderType),
151 /* Windows NT-only: */
152 DECLARE_TYPE(CSIDL_COMMON_DESKTOPDIRECTORY, folderType),
153 DECLARE_TYPE(CSIDL_COMMON_DOCUMENTS, shellExtType),
154 DECLARE_TYPE(CSIDL_COMMON_FAVORITES, folderType),
155 DECLARE_TYPE(CSIDL_COMMON_PROGRAMS, folderType),
156 DECLARE_TYPE(CSIDL_COMMON_STARTMENU, folderType),
157 DECLARE_TYPE(CSIDL_COMMON_STARTUP, folderType),
158 DECLARE_TYPE(CSIDL_COMMON_TEMPLATES, folderType),
159 /* first appearing in shell32 version 4.71: */
160 DECLARE_TYPE(CSIDL_APPDATA, folderType),
161 /* first appearing in shell32 version 4.72: */
162 DECLARE_TYPE(CSIDL_INTERNET_CACHE, ieSpecialType),
163 /* first appearing in shell32 version 5.0: */
164 DECLARE_TYPE(CSIDL_ADMINTOOLS, folderType),
165 DECLARE_TYPE(CSIDL_COMMON_APPDATA, folderType),
166 DECLARE_TYPE(CSIDL_LOCAL_APPDATA, folderType),
167 DECLARE_TYPE(OLD_CSIDL_MYDOCUMENTS, folderType),
168 DECLARE_TYPE(CSIDL_MYMUSIC, folderType),
169 DECLARE_TYPE(CSIDL_MYPICTURES, folderType),
170 DECLARE_TYPE(CSIDL_MYVIDEO, folderType),
171 DECLARE_TYPE(CSIDL_PROFILE, folderType),
172 DECLARE_TYPE(CSIDL_PROGRAM_FILES, folderType),
173 DECLARE_TYPE(CSIDL_PROGRAM_FILESX86, folderType),
174 DECLARE_TYPE(CSIDL_PROGRAM_FILES_COMMON, folderType),
175 DECLARE_TYPE(CSIDL_PROGRAM_FILES_COMMONX86, folderType),
176 DECLARE_TYPE(CSIDL_SYSTEM, folderType),
177 DECLARE_TYPE(CSIDL_WINDOWS, folderType),
178 /* first appearing in shell32 6.0: */
179 DECLARE_TYPE(CSIDL_CDBURN_AREA, folderType),
180 DECLARE_TYPE(CSIDL_COMMON_MUSIC, folderType),
181 DECLARE_TYPE(CSIDL_COMMON_PICTURES, folderType),
182 DECLARE_TYPE(CSIDL_COMMON_VIDEO, folderType),
183 DECLARE_TYPE(CSIDL_COMPUTERSNEARME, workgroupType),
184 DECLARE_TYPE(CSIDL_RESOURCES, folderType),
185 DECLARE_TYPE(CSIDL_RESOURCES_LOCALIZED, folderType),
187 #undef DECLARE_TYPE
189 static void loadShell32(void)
191 HMODULE hShell32 = GetModuleHandleA("shell32");
193 #define GET_PROC(func) \
194 p ## func = (void*)GetProcAddress(hShell32, #func); \
195 if(!p ## func) \
196 trace("GetProcAddress(%s) failed\n", #func);
198 GET_PROC(DllGetVersion)
199 GET_PROC(SHGetFolderPathA)
200 GET_PROC(SHGetFolderPathEx)
201 GET_PROC(SHGetFolderLocation)
202 GET_PROC(SHGetKnownFolderPath)
203 GET_PROC(SHSetKnownFolderPath)
204 GET_PROC(SHGetSpecialFolderPathA)
205 GET_PROC(SHGetSpecialFolderLocation)
206 GET_PROC(ILFindLastID)
207 if (!pILFindLastID)
208 pILFindLastID = (void *)GetProcAddress(hShell32, (LPCSTR)16);
209 GET_PROC(SHFileOperationA)
210 GET_PROC(SHGetMalloc)
211 GET_PROC(PathYetAnotherMakeUniqueName)
213 ok(pSHGetMalloc != NULL, "shell32 is missing SHGetMalloc\n");
214 if (pSHGetMalloc)
216 HRESULT hr = pSHGetMalloc(&pMalloc);
218 ok(hr == S_OK, "SHGetMalloc failed: 0x%08x\n", hr);
219 ok(pMalloc != NULL, "SHGetMalloc returned a NULL IMalloc\n");
222 if (pDllGetVersion)
224 shellVersion.cbSize = sizeof(shellVersion);
225 pDllGetVersion(&shellVersion);
226 trace("shell32 version is %d.%d\n",
227 shellVersion.dwMajorVersion, shellVersion.dwMinorVersion);
229 #undef GET_PROC
232 #ifndef CSIDL_PROFILES
233 #define CSIDL_PROFILES 0x003e
234 #endif
236 /* A couple utility printing functions */
237 static const char *getFolderName(int folder)
239 static char unknown[32];
241 #define CSIDL_TO_STR(x) case x: return#x;
242 switch (folder)
244 CSIDL_TO_STR(CSIDL_DESKTOP);
245 CSIDL_TO_STR(CSIDL_INTERNET);
246 CSIDL_TO_STR(CSIDL_PROGRAMS);
247 CSIDL_TO_STR(CSIDL_CONTROLS);
248 CSIDL_TO_STR(CSIDL_PRINTERS);
249 CSIDL_TO_STR(CSIDL_PERSONAL);
250 CSIDL_TO_STR(CSIDL_FAVORITES);
251 CSIDL_TO_STR(CSIDL_STARTUP);
252 CSIDL_TO_STR(CSIDL_RECENT);
253 CSIDL_TO_STR(CSIDL_SENDTO);
254 CSIDL_TO_STR(CSIDL_BITBUCKET);
255 CSIDL_TO_STR(CSIDL_STARTMENU);
256 CSIDL_TO_STR(OLD_CSIDL_MYDOCUMENTS);
257 CSIDL_TO_STR(CSIDL_MYMUSIC);
258 CSIDL_TO_STR(CSIDL_MYVIDEO);
259 CSIDL_TO_STR(CSIDL_DESKTOPDIRECTORY);
260 CSIDL_TO_STR(CSIDL_DRIVES);
261 CSIDL_TO_STR(CSIDL_NETWORK);
262 CSIDL_TO_STR(CSIDL_NETHOOD);
263 CSIDL_TO_STR(CSIDL_FONTS);
264 CSIDL_TO_STR(CSIDL_TEMPLATES);
265 CSIDL_TO_STR(CSIDL_COMMON_STARTMENU);
266 CSIDL_TO_STR(CSIDL_COMMON_PROGRAMS);
267 CSIDL_TO_STR(CSIDL_COMMON_STARTUP);
268 CSIDL_TO_STR(CSIDL_COMMON_DESKTOPDIRECTORY);
269 CSIDL_TO_STR(CSIDL_APPDATA);
270 CSIDL_TO_STR(CSIDL_PRINTHOOD);
271 CSIDL_TO_STR(CSIDL_LOCAL_APPDATA);
272 CSIDL_TO_STR(CSIDL_ALTSTARTUP);
273 CSIDL_TO_STR(CSIDL_COMMON_ALTSTARTUP);
274 CSIDL_TO_STR(CSIDL_COMMON_FAVORITES);
275 CSIDL_TO_STR(CSIDL_INTERNET_CACHE);
276 CSIDL_TO_STR(CSIDL_COOKIES);
277 CSIDL_TO_STR(CSIDL_HISTORY);
278 CSIDL_TO_STR(CSIDL_COMMON_APPDATA);
279 CSIDL_TO_STR(CSIDL_WINDOWS);
280 CSIDL_TO_STR(CSIDL_SYSTEM);
281 CSIDL_TO_STR(CSIDL_PROGRAM_FILES);
282 CSIDL_TO_STR(CSIDL_MYPICTURES);
283 CSIDL_TO_STR(CSIDL_PROFILE);
284 CSIDL_TO_STR(CSIDL_SYSTEMX86);
285 CSIDL_TO_STR(CSIDL_PROGRAM_FILESX86);
286 CSIDL_TO_STR(CSIDL_PROGRAM_FILES_COMMON);
287 CSIDL_TO_STR(CSIDL_PROGRAM_FILES_COMMONX86);
288 CSIDL_TO_STR(CSIDL_COMMON_TEMPLATES);
289 CSIDL_TO_STR(CSIDL_COMMON_DOCUMENTS);
290 CSIDL_TO_STR(CSIDL_COMMON_ADMINTOOLS);
291 CSIDL_TO_STR(CSIDL_ADMINTOOLS);
292 CSIDL_TO_STR(CSIDL_CONNECTIONS);
293 CSIDL_TO_STR(CSIDL_PROFILES);
294 CSIDL_TO_STR(CSIDL_COMMON_MUSIC);
295 CSIDL_TO_STR(CSIDL_COMMON_PICTURES);
296 CSIDL_TO_STR(CSIDL_COMMON_VIDEO);
297 CSIDL_TO_STR(CSIDL_RESOURCES);
298 CSIDL_TO_STR(CSIDL_RESOURCES_LOCALIZED);
299 CSIDL_TO_STR(CSIDL_COMMON_OEM_LINKS);
300 CSIDL_TO_STR(CSIDL_CDBURN_AREA);
301 CSIDL_TO_STR(CSIDL_COMPUTERSNEARME);
302 #undef CSIDL_TO_STR
303 default:
304 sprintf(unknown, "unknown (0x%04x)", folder);
305 return unknown;
309 static void test_parameters(void)
311 LPITEMIDLIST pidl = NULL;
312 char path[MAX_PATH];
313 HRESULT hr;
315 if (pSHGetFolderLocation)
317 /* check a bogus CSIDL: */
318 pidl = NULL;
319 hr = pSHGetFolderLocation(NULL, 0xeeee, NULL, 0, &pidl);
320 ok(hr == E_INVALIDARG, "got 0x%08x, expected E_INVALIDARG\n", hr);
321 if (hr == S_OK) IMalloc_Free(pMalloc, pidl);
323 /* check a bogus user token: */
324 pidl = NULL;
325 hr = pSHGetFolderLocation(NULL, CSIDL_FAVORITES, (HANDLE)2, 0, &pidl);
326 ok(hr == E_FAIL || hr == E_HANDLE, "got 0x%08x, expected E_FAIL or E_HANDLE\n", hr);
327 if (hr == S_OK) IMalloc_Free(pMalloc, pidl);
329 /* a NULL pidl pointer crashes, so don't test it */
332 if (pSHGetSpecialFolderLocation)
334 if (0)
335 /* crashes */
336 SHGetSpecialFolderLocation(NULL, 0, NULL);
338 hr = pSHGetSpecialFolderLocation(NULL, 0xeeee, &pidl);
339 ok(hr == E_INVALIDARG, "got returned 0x%08x\n", hr);
342 if (pSHGetFolderPathA)
344 /* expect 2's a bogus handle, especially since we didn't open it */
345 hr = pSHGetFolderPathA(NULL, CSIDL_DESKTOP, (HANDLE)2, SHGFP_TYPE_DEFAULT, path);
346 ok(hr == E_FAIL || hr == E_HANDLE || /* Vista and 2k8 */
347 broken(hr == S_OK), /* W2k and Me */ "got 0x%08x, expected E_FAIL\n", hr);
349 hr = pSHGetFolderPathA(NULL, 0xeeee, NULL, SHGFP_TYPE_DEFAULT, path);
350 ok(hr == E_INVALIDARG, "got 0x%08x, expected E_INVALIDARG\n", hr);
353 if (pSHGetSpecialFolderPathA)
355 BOOL ret;
357 if (0)
358 pSHGetSpecialFolderPathA(NULL, NULL, CSIDL_BITBUCKET, FALSE);
360 /* odd but true: calling with a NULL path still succeeds if it's a real
361 * dir (on some windows platform). on winME it generates exception.
363 ret = pSHGetSpecialFolderPathA(NULL, path, CSIDL_PROGRAMS, FALSE);
364 ok(ret, "got %d\n", ret);
366 ret = pSHGetSpecialFolderPathA(NULL, path, 0xeeee, FALSE);
367 ok(!ret, "got %d\n", ret);
371 /* Returns the folder's PIDL type, or 0xff if one can't be found. */
372 static BYTE testSHGetFolderLocation(int folder)
374 LPITEMIDLIST pidl;
375 HRESULT hr;
376 BYTE ret = 0xff;
378 /* treat absence of function as success */
379 if (!pSHGetFolderLocation) return TRUE;
381 pidl = NULL;
382 hr = pSHGetFolderLocation(NULL, folder, NULL, 0, &pidl);
383 if (hr == S_OK)
385 if (pidl)
387 LPITEMIDLIST pidlLast = pILFindLastID(pidl);
389 ok(pidlLast != NULL, "%s: ILFindLastID failed\n",
390 getFolderName(folder));
391 if (pidlLast)
392 ret = pidlLast->mkid.abID[0];
393 IMalloc_Free(pMalloc, pidl);
396 return ret;
399 /* Returns the folder's PIDL type, or 0xff if one can't be found. */
400 static BYTE testSHGetSpecialFolderLocation(int folder)
402 LPITEMIDLIST pidl;
403 HRESULT hr;
404 BYTE ret = 0xff;
406 /* treat absence of function as success */
407 if (!pSHGetSpecialFolderLocation) return TRUE;
409 pidl = NULL;
410 hr = pSHGetSpecialFolderLocation(NULL, folder, &pidl);
411 if (hr == S_OK)
413 if (pidl)
415 LPITEMIDLIST pidlLast = pILFindLastID(pidl);
417 ok(pidlLast != NULL,
418 "%s: ILFindLastID failed\n", getFolderName(folder));
419 if (pidlLast)
420 ret = pidlLast->mkid.abID[0];
421 IMalloc_Free(pMalloc, pidl);
424 return ret;
427 static void test_SHGetFolderPath(BOOL optional, int folder)
429 char path[MAX_PATH];
430 HRESULT hr;
432 if (!pSHGetFolderPathA) return;
434 hr = pSHGetFolderPathA(NULL, folder, NULL, SHGFP_TYPE_CURRENT, path);
435 ok(hr == S_OK || optional,
436 "SHGetFolderPathA(NULL, %s, NULL, SHGFP_TYPE_CURRENT, path) failed: 0x%08x\n", getFolderName(folder), hr);
439 static void test_SHGetSpecialFolderPath(BOOL optional, int folder)
441 char path[MAX_PATH];
442 BOOL ret;
444 if (!pSHGetSpecialFolderPathA) return;
446 ret = pSHGetSpecialFolderPathA(NULL, path, folder, FALSE);
447 if (ret && winetest_interactive)
448 printf("%s: %s\n", getFolderName(folder), path);
449 ok(ret || optional,
450 "SHGetSpecialFolderPathA(NULL, path, %s, FALSE) failed\n",
451 getFolderName(folder));
454 static void test_ShellValues(const struct shellExpectedValues testEntries[],
455 int numEntries, BOOL optional)
457 int i;
459 for (i = 0; i < numEntries; i++)
461 BYTE type;
462 int j;
463 BOOL foundTypeMatch = FALSE;
465 if (pSHGetFolderLocation)
467 type = testSHGetFolderLocation(testEntries[i].folder);
468 for (j = 0; !foundTypeMatch && j < testEntries[i].numTypes; j++)
469 if (testEntries[i].types[j] == type)
470 foundTypeMatch = TRUE;
471 ok(foundTypeMatch || optional || broken(type == 0xff) /* Win9x */,
472 "%s has unexpected type %d (0x%02x)\n",
473 getFolderName(testEntries[i].folder), type, type);
475 type = testSHGetSpecialFolderLocation(testEntries[i].folder);
476 for (j = 0, foundTypeMatch = FALSE; !foundTypeMatch &&
477 j < testEntries[i].numTypes; j++)
478 if (testEntries[i].types[j] == type)
479 foundTypeMatch = TRUE;
480 ok(foundTypeMatch || optional || broken(type == 0xff) /* Win9x */,
481 "%s has unexpected type %d (0x%02x)\n",
482 getFolderName(testEntries[i].folder), type, type);
483 switch (type)
485 case PT_FOLDER:
486 case PT_DRIVE:
487 case PT_DRIVE2:
488 case PT_IESPECIAL2:
489 test_SHGetFolderPath(optional, testEntries[i].folder);
490 test_SHGetSpecialFolderPath(optional, testEntries[i].folder);
491 break;
496 /* Attempts to verify that the folder path corresponding to the folder CSIDL
497 * value has the same value as the environment variable with name envVar.
498 * Doesn't mind if SHGetSpecialFolderPath fails for folder or if envVar isn't
499 * set in this environment; different OS and shell version behave differently.
500 * However, if both are present, fails if envVar's value is not the same
501 * (byte-for-byte) as what SHGetSpecialFolderPath returns.
503 static void matchSpecialFolderPathToEnv(int folder, const char *envVar)
505 char path[MAX_PATH];
507 if (!pSHGetSpecialFolderPathA) return;
509 if (pSHGetSpecialFolderPathA(NULL, path, folder, FALSE))
511 char *envVal = getenv(envVar);
513 ok(!envVal || !lstrcmpiA(envVal, path),
514 "%%%s%% does not match SHGetSpecialFolderPath:\n"
515 "%%%s%% is %s\nSHGetSpecialFolderPath returns %s\n",
516 envVar, envVar, envVal, path);
520 /* Attempts to match the GUID returned by SHGetFolderLocation for folder with
521 * GUID. Assumes the type of the returned PIDL is in fact a GUID, but doesn't
522 * fail if it isn't--that check should already have been done.
523 * Fails if the returned PIDL is a GUID whose value does not match guid.
525 static void matchGUID(int folder, const GUID *guid, const GUID *guid_alt)
527 LPITEMIDLIST pidl;
528 HRESULT hr;
530 if (!pSHGetFolderLocation) return;
531 if (!guid) return;
533 pidl = NULL;
534 hr = pSHGetFolderLocation(NULL, folder, NULL, 0, &pidl);
535 if (hr == S_OK)
537 LPITEMIDLIST pidlLast = pILFindLastID(pidl);
539 if (pidlLast && (pidlLast->mkid.abID[0] == PT_SHELLEXT ||
540 pidlLast->mkid.abID[0] == PT_GUID))
542 GUID *shellGuid = (GUID *)(pidlLast->mkid.abID + 2);
544 if (!guid_alt)
545 ok(IsEqualIID(shellGuid, guid),
546 "%s: got GUID %s, expected %s\n", getFolderName(folder),
547 wine_dbgstr_guid(shellGuid), wine_dbgstr_guid(guid));
548 else
549 ok(IsEqualIID(shellGuid, guid) ||
550 IsEqualIID(shellGuid, guid_alt),
551 "%s: got GUID %s, expected %s or %s\n", getFolderName(folder),
552 wine_dbgstr_guid(shellGuid), wine_dbgstr_guid(guid), wine_dbgstr_guid(guid_alt));
554 IMalloc_Free(pMalloc, pidl);
558 /* Checks the PIDL type of all the known values. */
559 static void test_PidlTypes(void)
561 /* Desktop */
562 test_SHGetFolderPath(FALSE, CSIDL_DESKTOP);
563 test_SHGetSpecialFolderPath(FALSE, CSIDL_DESKTOP);
565 test_ShellValues(requiredShellValues, ARRAY_SIZE(requiredShellValues), FALSE);
566 test_ShellValues(optionalShellValues, ARRAY_SIZE(optionalShellValues), TRUE);
569 /* FIXME: Should be in shobjidl.idl */
570 DEFINE_GUID(CLSID_NetworkExplorerFolder, 0xF02C1A0D, 0xBE21, 0x4350, 0x88, 0xB0, 0x73, 0x67, 0xFC, 0x96, 0xEF, 0x3C);
572 /* Verifies various shell virtual folders have the correct well-known GUIDs. */
573 static void test_GUIDs(void)
575 matchGUID(CSIDL_BITBUCKET, &CLSID_RecycleBin, NULL);
576 matchGUID(CSIDL_CONTROLS, &CLSID_ControlPanel, NULL);
577 matchGUID(CSIDL_DRIVES, &CLSID_MyComputer, NULL);
578 matchGUID(CSIDL_INTERNET, &CLSID_Internet, NULL);
579 matchGUID(CSIDL_NETWORK, &CLSID_NetworkPlaces, &CLSID_NetworkExplorerFolder); /* Vista and higher */
580 matchGUID(CSIDL_PERSONAL, &CLSID_MyDocuments, NULL);
581 matchGUID(CSIDL_COMMON_DOCUMENTS, &CLSID_CommonDocuments, NULL);
582 matchGUID(CSIDL_PRINTERS, &CLSID_Printers, NULL);
585 /* Verifies various shell paths match the environment variables to which they
586 * correspond.
588 static void test_EnvVars(void)
590 matchSpecialFolderPathToEnv(CSIDL_PROGRAM_FILES, "ProgramFiles");
591 matchSpecialFolderPathToEnv(CSIDL_APPDATA, "APPDATA");
592 matchSpecialFolderPathToEnv(CSIDL_PROFILE, "USERPROFILE");
593 matchSpecialFolderPathToEnv(CSIDL_WINDOWS, "SystemRoot");
594 matchSpecialFolderPathToEnv(CSIDL_WINDOWS, "windir");
595 matchSpecialFolderPathToEnv(CSIDL_PROGRAM_FILES_COMMON, "CommonProgramFiles");
596 /* this is only set on Wine, but can't hurt to verify it: */
597 matchSpecialFolderPathToEnv(CSIDL_SYSTEM, "winsysdir");
600 /* Loosely based on PathRemoveBackslashA from dlls/shlwapi/path.c */
601 static BOOL myPathIsRootA(LPCSTR lpszPath)
603 if (lpszPath && *lpszPath &&
604 lpszPath[1] == ':' && lpszPath[2] == '\\' && lpszPath[3] == '\0')
605 return TRUE; /* X:\ */
606 return FALSE;
608 static LPSTR myPathRemoveBackslashA( LPSTR lpszPath )
610 LPSTR szTemp = NULL;
612 if(lpszPath)
614 szTemp = CharPrevA(lpszPath, lpszPath + strlen(lpszPath));
615 if (!myPathIsRootA(lpszPath) && *szTemp == '\\')
616 *szTemp = '\0';
618 return szTemp;
621 /* Verifies the shell path for CSIDL_WINDOWS matches the return from
622 * GetWindowsDirectory. If SHGetSpecialFolderPath fails, no harm, no foul--not
623 * every shell32 version supports CSIDL_WINDOWS.
625 static void testWinDir(void)
627 char windowsShellPath[MAX_PATH], windowsDir[MAX_PATH] = { 0 };
629 if (!pSHGetSpecialFolderPathA) return;
631 if (pSHGetSpecialFolderPathA(NULL, windowsShellPath, CSIDL_WINDOWS, FALSE))
633 myPathRemoveBackslashA(windowsShellPath);
634 GetWindowsDirectoryA(windowsDir, sizeof(windowsDir));
635 myPathRemoveBackslashA(windowsDir);
636 ok(!lstrcmpiA(windowsDir, windowsShellPath),
637 "GetWindowsDirectory returns %s SHGetSpecialFolderPath returns %s\n",
638 windowsDir, windowsShellPath);
642 /* Verifies the shell path for CSIDL_SYSTEM matches the return from
643 * GetSystemDirectory. If SHGetSpecialFolderPath fails, no harm,
644 * no foul--not every shell32 version supports CSIDL_SYSTEM.
646 static void testSystemDir(void)
648 char systemShellPath[MAX_PATH], systemDir[MAX_PATH], systemDirx86[MAX_PATH];
650 if (!pSHGetSpecialFolderPathA) return;
652 GetSystemDirectoryA(systemDir, sizeof(systemDir));
653 myPathRemoveBackslashA(systemDir);
654 if (pSHGetSpecialFolderPathA(NULL, systemShellPath, CSIDL_SYSTEM, FALSE))
656 myPathRemoveBackslashA(systemShellPath);
657 ok(!lstrcmpiA(systemDir, systemShellPath),
658 "GetSystemDirectory returns %s SHGetSpecialFolderPath returns %s\n",
659 systemDir, systemShellPath);
662 if (!pGetSystemWow64DirectoryA || !pGetSystemWow64DirectoryA(systemDirx86, sizeof(systemDirx86)))
663 GetSystemDirectoryA(systemDirx86, sizeof(systemDirx86));
664 myPathRemoveBackslashA(systemDirx86);
665 if (pSHGetSpecialFolderPathA(NULL, systemShellPath, CSIDL_SYSTEMX86, FALSE))
667 myPathRemoveBackslashA(systemShellPath);
668 ok(!lstrcmpiA(systemDirx86, systemShellPath) || broken(!lstrcmpiA(systemDir, systemShellPath)),
669 "GetSystemDirectory returns %s SHGetSpecialFolderPath returns %s\n",
670 systemDir, systemShellPath);
674 /* Globals used by subprocesses */
675 static int myARGC;
676 static char **myARGV;
677 static char base[MAX_PATH];
678 static char selfname[MAX_PATH];
680 static BOOL init(void)
682 myARGC = winetest_get_mainargs(&myARGV);
683 if (!GetCurrentDirectoryA(sizeof(base), base)) return FALSE;
684 strcpy(selfname, myARGV[0]);
685 return TRUE;
688 static void doChild(const char *arg)
690 char path[MAX_PATH];
691 HRESULT hr;
693 if (arg[0] == '1')
695 LPITEMIDLIST pidl;
696 char *p;
698 /* test what happens when CSIDL_FAVORITES is set to a nonexistent directory */
700 /* test some failure cases first: */
701 hr = pSHGetFolderPathA(NULL, CSIDL_FAVORITES, NULL, SHGFP_TYPE_CURRENT, path);
702 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
703 "SHGetFolderPath returned 0x%08x, expected 0x80070002\n", hr);
705 pidl = NULL;
706 hr = pSHGetFolderLocation(NULL, CSIDL_FAVORITES, NULL, 0, &pidl);
707 ok(hr == E_FAIL || hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
708 "SHGetFolderLocation returned 0x%08x\n", hr);
709 if (hr == S_OK && pidl) IMalloc_Free(pMalloc, pidl);
711 ok(!pSHGetSpecialFolderPathA(NULL, path, CSIDL_FAVORITES, FALSE),
712 "SHGetSpecialFolderPath succeeded, expected failure\n");
714 pidl = NULL;
715 hr = pSHGetSpecialFolderLocation(NULL, CSIDL_FAVORITES, &pidl);
716 ok(hr == E_FAIL || hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
717 "SHGetFolderLocation returned 0x%08x\n", hr);
719 if (hr == S_OK && pidl) IMalloc_Free(pMalloc, pidl);
721 /* now test success: */
722 hr = pSHGetFolderPathA(NULL, CSIDL_FAVORITES | CSIDL_FLAG_CREATE, NULL,
723 SHGFP_TYPE_CURRENT, path);
724 ok (hr == S_OK, "got 0x%08x\n", hr);
725 if (hr == S_OK)
727 BOOL ret;
729 trace("CSIDL_FAVORITES was changed to %s\n", path);
730 ret = CreateDirectoryA(path, NULL);
731 ok(!ret, "expected failure with ERROR_ALREADY_EXISTS\n");
732 if (!ret)
733 ok(GetLastError() == ERROR_ALREADY_EXISTS,
734 "got %d, expected ERROR_ALREADY_EXISTS\n", GetLastError());
736 p = path + strlen(path);
737 strcpy(p, "\\desktop.ini");
738 DeleteFileA(path);
739 *p = 0;
740 SetFileAttributesA( path, FILE_ATTRIBUTE_NORMAL );
741 ret = RemoveDirectoryA(path);
742 ok( ret, "failed to remove %s error %u\n", path, GetLastError() );
745 else if (arg[0] == '2')
747 /* make sure SHGetFolderPath still succeeds when the
748 original value of CSIDL_FAVORITES is restored. */
749 hr = pSHGetFolderPathA(NULL, CSIDL_FAVORITES | CSIDL_FLAG_CREATE, NULL,
750 SHGFP_TYPE_CURRENT, path);
751 ok(hr == S_OK, "SHGetFolderPath failed: 0x%08x\n", hr);
755 /* Tests the return values from the various shell functions both with and
756 * without the use of the CSIDL_FLAG_CREATE flag. This flag only appeared in
757 * version 5 of the shell, so don't test unless it's at least version 5.
758 * The test reads a value from the registry, modifies it, calls
759 * SHGetFolderPath once with the CSIDL_FLAG_CREATE flag, and immediately
760 * afterward without it. Then it restores the registry and deletes the folder
761 * that was created.
762 * One oddity with respect to restoration: shell32 caches somehow, so it needs
763 * to be reloaded in order to see the correct (restored) value.
764 * Some APIs unrelated to the ones under test may fail, but I expect they're
765 * covered by other unit tests; I just print out something about failure to
766 * help trace what's going on.
768 static void test_NonExistentPath(void)
770 static const char userShellFolders[] =
771 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders";
772 char originalPath[MAX_PATH], modifiedPath[MAX_PATH];
773 HKEY key;
775 if (!pSHGetFolderPathA) return;
776 if (!pSHGetFolderLocation) return;
777 if (!pSHGetSpecialFolderPathA) return;
778 if (!pSHGetSpecialFolderLocation) return;
779 if (!pSHFileOperationA) return;
780 if (shellVersion.dwMajorVersion < 5) return;
782 if (!RegOpenKeyExA(HKEY_CURRENT_USER, userShellFolders, 0, KEY_ALL_ACCESS,
783 &key))
785 DWORD len, type;
787 len = sizeof(originalPath);
788 if (!RegQueryValueExA(key, "Favorites", NULL, &type,
789 (LPBYTE)&originalPath, &len))
791 size_t len = strlen(originalPath);
793 memcpy(modifiedPath, originalPath, len);
794 modifiedPath[len++] = '2';
795 modifiedPath[len++] = '\0';
796 trace("Changing CSIDL_FAVORITES to %s\n", modifiedPath);
797 if (!RegSetValueExA(key, "Favorites", 0, type,
798 (LPBYTE)modifiedPath, len))
800 char buffer[MAX_PATH+20];
801 STARTUPINFOA startup;
802 PROCESS_INFORMATION info;
804 sprintf(buffer, "%s tests/shellpath.c 1", selfname);
805 memset(&startup, 0, sizeof(startup));
806 startup.cb = sizeof(startup);
807 startup.dwFlags = STARTF_USESHOWWINDOW;
808 startup.dwFlags = SW_SHOWNORMAL;
809 CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL,
810 &startup, &info);
811 winetest_wait_child_process( info.hProcess );
813 /* restore original values: */
814 trace("Restoring CSIDL_FAVORITES to %s\n", originalPath);
815 RegSetValueExA(key, "Favorites", 0, type, (LPBYTE) originalPath,
816 strlen(originalPath) + 1);
817 RegFlushKey(key);
819 sprintf(buffer, "%s tests/shellpath.c 2", selfname);
820 memset(&startup, 0, sizeof(startup));
821 startup.cb = sizeof(startup);
822 startup.dwFlags = STARTF_USESHOWWINDOW;
823 startup.dwFlags = SW_SHOWNORMAL;
824 CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL,
825 &startup, &info);
826 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0,
827 "child process termination\n");
830 else skip("RegQueryValueExA(key, Favorites, ...) failed\n");
831 if (key)
832 RegCloseKey(key);
834 else skip("RegOpenKeyExA(HKEY_CURRENT_USER, %s, ...) failed\n", userShellFolders);
837 static void test_SHGetFolderPathEx(void)
839 HRESULT hr;
840 WCHAR buffer[MAX_PATH], *path;
841 DWORD len;
843 if (!pSHGetKnownFolderPath || !pSHGetFolderPathEx)
845 win_skip("SHGetKnownFolderPath or SHGetFolderPathEx not available\n");
846 return;
849 if (0) { /* crashes */
850 hr = pSHGetKnownFolderPath(&FOLDERID_Desktop, 0, NULL, NULL);
851 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
853 /* non-existent folder id */
854 path = (void *)0xdeadbeef;
855 hr = pSHGetKnownFolderPath(&IID_IOleObject, 0, NULL, &path);
856 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "got 0x%08x\n", hr);
857 ok(path == NULL, "got %p\n", path);
859 path = NULL;
860 hr = pSHGetKnownFolderPath(&FOLDERID_Desktop, 0, NULL, &path);
861 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
862 ok(path != NULL, "expected path != NULL\n");
864 hr = pSHGetFolderPathEx(&FOLDERID_Desktop, 0, NULL, buffer, MAX_PATH);
865 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
866 ok(!lstrcmpiW(path, buffer), "expected equal paths\n");
867 len = lstrlenW(buffer);
868 CoTaskMemFree(path);
870 hr = pSHGetFolderPathEx(&FOLDERID_Desktop, 0, NULL, buffer, 0);
871 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
873 if (0) { /* crashes */
874 hr = pSHGetFolderPathEx(&FOLDERID_Desktop, 0, NULL, NULL, len + 1);
875 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
877 hr = pSHGetFolderPathEx(NULL, 0, NULL, buffer, MAX_PATH);
878 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
880 hr = pSHGetFolderPathEx(&FOLDERID_Desktop, 0, NULL, buffer, len);
881 ok(hr == E_NOT_SUFFICIENT_BUFFER, "expected E_NOT_SUFFICIENT_BUFFER, got 0x%08x\n", hr);
883 hr = pSHGetFolderPathEx(&FOLDERID_Desktop, 0, NULL, buffer, len + 1);
884 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
887 /* Standard CSIDL values (and their flags) uses only two less-significant bytes */
888 #define NO_CSIDL 0x10000
889 #define CSIDL_TODO_WINE 0x20000
890 #define KNOWN_FOLDER(id, csidl, name, category, parent, relative_path, parsing_name, attributes, definitionFlags) \
891 { &id, # id, csidl, # csidl, name, category, &parent, # parent, relative_path, parsing_name, attributes, definitionFlags, __LINE__ }
893 /* non-published known folders test */
894 static const GUID _FOLDERID_CryptoKeys = {0xB88F4DAA, 0xE7BD, 0x49A9, {0xB7, 0x4D, 0x02, 0x88, 0x5A, 0x5D, 0xC7, 0x65} };
895 static const GUID _FOLDERID_DpapiKeys = {0x10C07CD0, 0xEF91, 0x4567, {0xB8, 0x50, 0x44, 0x8B, 0x77, 0xCB, 0x37, 0xF9} };
896 static const GUID _FOLDERID_SystemCertificates = {0x54EED2E0, 0xE7CA, 0x4FDB, {0x91, 0x48, 0x0F, 0x42, 0x47, 0x29, 0x1C, 0xFA} };
897 static const GUID _FOLDERID_CredentialManager = {0x915221FB, 0x9EFE, 0x4BDA, {0x8F, 0xD7, 0xF7, 0x8D, 0xCA, 0x77, 0x4F, 0x87} };
899 struct knownFolderDef {
900 const KNOWNFOLDERID *folderId;
901 const char *sFolderId;
902 const int csidl;
903 const char *sCsidl;
904 const char *sName;
905 const KF_CATEGORY category;
906 const KNOWNFOLDERID *fidParent;
907 const char *sParent;
908 const char *sRelativePath;
909 const char *sParsingName;
910 const DWORD attributes;
911 const KF_DEFINITION_FLAGS definitionFlags;
912 const int line;
915 /* Note: content of parsing name may vary between Windows versions.
916 * As a base, values from 6.0 (Vista) were used. Some entries may contain
917 * alternative values. In that case, Windows version where the value was
918 * found is noted.
920 * The list of values for parsing name was encoded as a number of null-
921 * terminated strings placed one by one (separated by null byte only).
922 * End of list is marked by two consecutive null bytes.
924 static const struct knownFolderDef known_folders[] = {
925 KNOWN_FOLDER(FOLDERID_AddNewPrograms,
926 NO_CSIDL,
927 "AddNewProgramsFolder",
928 KF_CATEGORY_VIRTUAL,
929 GUID_NULL,
930 NULL,
931 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{15eae92e-f17a-4431-9f28-805e482dafd4}\0"
932 "shell:::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{15eae92e-f17a-4431-9f28-805e482dafd4}\0\0" /* 6.1 */,
935 KNOWN_FOLDER(FOLDERID_AdminTools,
936 CSIDL_ADMINTOOLS,
937 "Administrative Tools",
938 KF_CATEGORY_PERUSER,
939 FOLDERID_Programs,
940 "Administrative Tools",
941 NULL,
942 FILE_ATTRIBUTE_READONLY,
943 KFDF_PRECREATE),
944 KNOWN_FOLDER(FOLDERID_AppUpdates,
945 NO_CSIDL,
946 "AppUpdatesFolder",
947 KF_CATEGORY_VIRTUAL,
948 GUID_NULL,
949 NULL,
950 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{7b81be6a-ce2b-4676-a29e-eb907a5126c5}\\::{d450a8a1-9568-45c7-9c0e-b4f9fb4537bd}\0"
951 "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{7b81be6a-ce2b-4676-a29e-eb907a5126c5}\\::{d450a8a1-9568-45c7-9c0e-b4f9fb4537bd}\0\0" /* 6.1 */,
954 KNOWN_FOLDER(FOLDERID_CDBurning,
955 CSIDL_CDBURN_AREA,
956 "CD Burning",
957 KF_CATEGORY_PERUSER,
958 FOLDERID_LocalAppData,
959 "Microsoft\\Windows\\Burn\\Burn",
960 NULL,
961 FILE_ATTRIBUTE_READONLY,
962 KFDF_LOCAL_REDIRECT_ONLY),
963 KNOWN_FOLDER(FOLDERID_ChangeRemovePrograms,
964 NO_CSIDL,
965 "ChangeRemoveProgramsFolder",
966 KF_CATEGORY_VIRTUAL,
967 GUID_NULL,
968 NULL,
969 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{7b81be6a-ce2b-4676-a29e-eb907a5126c5}\0"
970 "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{7b81be6a-ce2b-4676-a29e-eb907a5126c5}\0\0" /* 6.1 */,
973 KNOWN_FOLDER(FOLDERID_CommonAdminTools,
974 CSIDL_COMMON_ADMINTOOLS,
975 "Common Administrative Tools",
976 KF_CATEGORY_COMMON,
977 FOLDERID_CommonPrograms,
978 "Administrative Tools",
979 NULL,
980 FILE_ATTRIBUTE_READONLY,
981 KFDF_PRECREATE),
982 KNOWN_FOLDER(FOLDERID_CommonOEMLinks,
983 CSIDL_COMMON_OEM_LINKS,"OEM Links",
984 KF_CATEGORY_COMMON,
985 FOLDERID_ProgramData,
986 "OEM Links",
987 NULL,
990 KNOWN_FOLDER(FOLDERID_CommonPrograms,
991 CSIDL_COMMON_PROGRAMS,
992 "Common Programs",
993 KF_CATEGORY_COMMON,
994 FOLDERID_CommonStartMenu,
995 "Programs",
996 NULL,
997 FILE_ATTRIBUTE_READONLY,
998 KFDF_PRECREATE),
999 KNOWN_FOLDER(FOLDERID_CommonStartMenu,
1000 CSIDL_COMMON_STARTMENU,
1001 "Common Start Menu",
1002 KF_CATEGORY_COMMON,
1003 FOLDERID_ProgramData,
1004 "Microsoft\\Windows\\Start Menu",
1005 NULL,
1006 FILE_ATTRIBUTE_READONLY,
1007 KFDF_PRECREATE),
1008 KNOWN_FOLDER(FOLDERID_CommonStartup,
1009 CSIDL_COMMON_STARTUP,
1010 "Common Startup",
1011 KF_CATEGORY_COMMON,
1012 FOLDERID_CommonPrograms,
1013 "StartUp",
1014 NULL,
1015 FILE_ATTRIBUTE_READONLY,
1016 KFDF_PRECREATE),
1017 KNOWN_FOLDER(FOLDERID_CommonTemplates,
1018 CSIDL_COMMON_TEMPLATES,
1019 "Common Templates",
1020 KF_CATEGORY_COMMON,
1021 FOLDERID_ProgramData,
1022 "Microsoft\\Windows\\Templates",
1023 NULL,
1026 KNOWN_FOLDER(FOLDERID_ComputerFolder,
1027 CSIDL_DRIVES,
1028 "MyComputerFolder",
1029 KF_CATEGORY_VIRTUAL,
1030 GUID_NULL,
1031 NULL,
1032 "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\0\0",
1035 KNOWN_FOLDER(FOLDERID_ConflictFolder,
1036 NO_CSIDL,
1037 "ConflictFolder",
1038 KF_CATEGORY_VIRTUAL,
1039 GUID_NULL,
1040 NULL,
1041 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\\::{E413D040-6788-4C22-957E-175D1C513A34},\0"
1042 "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\\::{E413D040-6788-4C22-957E-175D1C513A34},\0\0" /* 6.1 */,
1045 KNOWN_FOLDER(FOLDERID_ConnectionsFolder,
1046 CSIDL_CONNECTIONS,
1047 "ConnectionsFolder",
1048 KF_CATEGORY_VIRTUAL,
1049 GUID_NULL,
1050 NULL,
1051 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{7007ACC7-3202-11D1-AAD2-00805FC1270E}\0"
1052 "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{7007ACC7-3202-11D1-AAD2-00805FC1270E}\0\0" /* 6.1 */,
1055 KNOWN_FOLDER(FOLDERID_Contacts,
1056 NO_CSIDL,
1057 "Contacts",
1058 KF_CATEGORY_PERUSER,
1059 FOLDERID_Profile,
1060 "Contacts",
1061 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{56784854-C6CB-462B-8169-88E350ACB882}\0\0",
1062 FILE_ATTRIBUTE_READONLY,
1063 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH),
1064 KNOWN_FOLDER(FOLDERID_ControlPanelFolder,
1065 CSIDL_CONTROLS,
1066 "ControlPanelFolder",
1067 KF_CATEGORY_VIRTUAL,
1068 GUID_NULL,
1069 NULL,
1070 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\0"
1071 "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\0\0" /* 6.1 */,
1074 KNOWN_FOLDER(FOLDERID_Cookies,
1075 CSIDL_COOKIES,
1076 "Cookies",
1077 KF_CATEGORY_PERUSER,
1078 FOLDERID_RoamingAppData,
1079 "Microsoft\\Windows\\Cookies",
1080 NULL,
1083 KNOWN_FOLDER(FOLDERID_Desktop,
1084 CSIDL_DESKTOP,
1085 "Desktop",
1086 KF_CATEGORY_PERUSER,
1087 FOLDERID_Profile,
1088 "Desktop",
1089 NULL,
1090 FILE_ATTRIBUTE_READONLY,
1091 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH),
1092 KNOWN_FOLDER(FOLDERID_DeviceMetadataStore,
1093 NO_CSIDL,
1094 "Device Metadata Store",
1095 KF_CATEGORY_COMMON,
1096 FOLDERID_ProgramData,
1097 "Microsoft\\Windows\\DeviceMetadataStore",
1098 NULL,
1101 KNOWN_FOLDER(FOLDERID_Documents,
1102 CSIDL_MYDOCUMENTS,
1103 "Personal",
1104 KF_CATEGORY_PERUSER,
1105 FOLDERID_Profile,
1106 "Documents",
1107 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{FDD39AD0-238F-46AF-ADB4-6C85480369C7}\0\0",
1108 FILE_ATTRIBUTE_READONLY,
1109 KFDF_ROAMABLE | KFDF_PRECREATE),
1110 KNOWN_FOLDER(FOLDERID_DocumentsLibrary,
1111 NO_CSIDL,
1112 "DocumentsLibrary",
1113 KF_CATEGORY_PERUSER,
1114 FOLDERID_Libraries,
1115 "Documents.library-ms",
1116 "::{031E4825-7B94-4dc3-B131-E946B44C8DD5}\\{7b0db17d-9cd2-4a93-9733-46cc89022e7c}\0\0",
1118 KFDF_PRECREATE | KFDF_STREAM),
1119 KNOWN_FOLDER(FOLDERID_Downloads,
1120 NO_CSIDL,
1121 "Downloads",
1122 KF_CATEGORY_PERUSER,
1123 FOLDERID_Profile,
1124 "Downloads",
1125 NULL,
1126 FILE_ATTRIBUTE_READONLY,
1127 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH),
1128 KNOWN_FOLDER(FOLDERID_Favorites,
1129 CSIDL_FAVORITES,
1130 "Favorites",
1131 KF_CATEGORY_PERUSER,
1132 FOLDERID_Profile,
1133 "Favorites",
1134 NULL,
1135 FILE_ATTRIBUTE_READONLY,
1136 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH),
1137 KNOWN_FOLDER(FOLDERID_Fonts,
1138 CSIDL_FONTS,
1139 "Fonts",
1140 KF_CATEGORY_FIXED,
1141 FOLDERID_Windows,
1142 NULL,
1143 NULL,
1146 KNOWN_FOLDER(FOLDERID_Games,
1147 NO_CSIDL,
1148 "Games",
1149 KF_CATEGORY_VIRTUAL,
1150 GUID_NULL,
1151 NULL,
1152 "::{ED228FDF-9EA8-4870-83b1-96b02CFE0D52}\0\0",
1155 KNOWN_FOLDER(FOLDERID_GameTasks,
1156 NO_CSIDL,
1157 "GameTasks",
1158 KF_CATEGORY_PERUSER,
1159 FOLDERID_LocalAppData,
1160 "Microsoft\\Windows\\GameExplorer",
1161 NULL,
1163 KFDF_LOCAL_REDIRECT_ONLY),
1164 KNOWN_FOLDER(FOLDERID_History,
1165 CSIDL_HISTORY,
1166 "History",
1167 KF_CATEGORY_PERUSER,
1168 FOLDERID_LocalAppData,
1169 "Microsoft\\Windows\\History",
1170 NULL,
1172 KFDF_LOCAL_REDIRECT_ONLY),
1173 KNOWN_FOLDER(FOLDERID_HomeGroup,
1174 NO_CSIDL,
1175 "HomeGroupFolder",
1176 KF_CATEGORY_VIRTUAL,
1177 GUID_NULL,
1178 NULL,
1179 "::{B4FB3F98-C1EA-428d-A78A-D1F5659CBA93}\0\0",
1182 KNOWN_FOLDER(FOLDERID_ImplicitAppShortcuts,
1183 NO_CSIDL,
1184 "ImplicitAppShortcuts",
1185 KF_CATEGORY_PERUSER,
1186 FOLDERID_UserPinned,
1187 "ImplicitAppShortcuts",
1188 NULL,
1190 KFDF_PRECREATE),
1191 KNOWN_FOLDER(FOLDERID_InternetCache,
1192 CSIDL_INTERNET_CACHE,
1193 "Cache",
1194 KF_CATEGORY_PERUSER,
1195 FOLDERID_LocalAppData,
1196 "Microsoft\\Windows\\Temporary Internet Files",
1197 NULL,
1199 KFDF_LOCAL_REDIRECT_ONLY),
1200 KNOWN_FOLDER(FOLDERID_InternetFolder,
1201 CSIDL_INTERNET,
1202 "InternetFolder",
1203 KF_CATEGORY_VIRTUAL,
1204 GUID_NULL,
1205 NULL,
1206 "::{871C5380-42A0-1069-A2EA-08002B30309D}\0\0",
1209 KNOWN_FOLDER(FOLDERID_Libraries,
1210 NO_CSIDL,
1211 "Libraries",
1212 KF_CATEGORY_PERUSER,
1213 FOLDERID_RoamingAppData,
1214 "Microsoft\\Windows\\Libraries",
1215 NULL,
1217 KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH),
1218 KNOWN_FOLDER(FOLDERID_Links,
1219 NO_CSIDL,
1220 "Links",
1221 KF_CATEGORY_PERUSER,
1222 FOLDERID_Profile,
1223 "Links",
1224 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{bfb9d5e0-c6a9-404c-b2b2-ae6db6af4968}\0\0",
1225 FILE_ATTRIBUTE_READONLY,
1226 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH),
1227 KNOWN_FOLDER(FOLDERID_LocalAppData,
1228 CSIDL_LOCAL_APPDATA,
1229 "Local AppData",
1230 KF_CATEGORY_PERUSER,
1231 FOLDERID_Profile,
1232 "AppData\\Local",
1233 NULL,
1235 KFDF_LOCAL_REDIRECT_ONLY | KFDF_PUBLISHEXPANDEDPATH),
1236 KNOWN_FOLDER(FOLDERID_LocalAppDataLow,
1237 NO_CSIDL,
1238 "LocalAppDataLow",
1239 KF_CATEGORY_PERUSER,
1240 FOLDERID_Profile,
1241 "AppData\\LocalLow",
1242 NULL,
1243 FILE_ATTRIBUTE_NOT_CONTENT_INDEXED,
1244 KFDF_LOCAL_REDIRECT_ONLY | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH),
1245 KNOWN_FOLDER(FOLDERID_LocalizedResourcesDir,
1246 CSIDL_RESOURCES_LOCALIZED,
1247 "LocalizedResourcesDir",
1248 KF_CATEGORY_FIXED,
1249 GUID_NULL,
1250 NULL,
1251 NULL,
1254 KNOWN_FOLDER(FOLDERID_Music,
1255 CSIDL_MYMUSIC,
1256 "My Music",
1257 KF_CATEGORY_PERUSER,
1258 FOLDERID_Profile,
1259 "Music",
1260 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{4BD8D571-6D19-48D3-BE97-422220080E43}\0\0",
1261 FILE_ATTRIBUTE_READONLY,
1262 KFDF_ROAMABLE | KFDF_PRECREATE),
1263 KNOWN_FOLDER(FOLDERID_MusicLibrary,
1264 NO_CSIDL,
1265 "MusicLibrary",
1266 KF_CATEGORY_PERUSER,
1267 FOLDERID_Libraries,
1268 "Music.library-ms",
1269 "::{031E4825-7B94-4dc3-B131-E946B44C8DD5}\\{2112AB0A-C86A-4ffe-A368-0DE96E47012E}\0\0",
1271 KFDF_PRECREATE | KFDF_STREAM),
1272 KNOWN_FOLDER(FOLDERID_NetHood,
1273 CSIDL_NETHOOD,
1274 "NetHood",
1275 KF_CATEGORY_PERUSER,
1276 FOLDERID_RoamingAppData,
1277 "Microsoft\\Windows\\Network Shortcuts",
1278 NULL,
1281 KNOWN_FOLDER(FOLDERID_NetworkFolder,
1282 CSIDL_NETWORK,
1283 "NetworkPlacesFolder",
1284 KF_CATEGORY_VIRTUAL,
1285 GUID_NULL,
1286 NULL,
1287 "::{F02C1A0D-BE21-4350-88B0-7367FC96EF3C}\0\0",
1290 KNOWN_FOLDER(FOLDERID_OriginalImages,
1291 NO_CSIDL,
1292 "Original Images",
1293 KF_CATEGORY_PERUSER,
1294 FOLDERID_LocalAppData,
1295 "Microsoft\\Windows Photo Gallery\\Original Images",
1296 NULL,
1299 KNOWN_FOLDER(FOLDERID_PhotoAlbums,
1300 NO_CSIDL,
1301 "PhotoAlbums",
1302 KF_CATEGORY_PERUSER,
1303 FOLDERID_Pictures,
1304 "Slide Shows",
1305 NULL,
1306 FILE_ATTRIBUTE_READONLY,
1308 KNOWN_FOLDER(FOLDERID_Pictures,
1309 CSIDL_MYPICTURES,
1310 "My Pictures",
1311 KF_CATEGORY_PERUSER,
1312 FOLDERID_Profile,
1313 "Pictures",
1314 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{33E28130-4E1E-4676-835A-98395C3BC3BB}\0\0",
1315 FILE_ATTRIBUTE_READONLY,
1316 KFDF_ROAMABLE | KFDF_PRECREATE),
1317 KNOWN_FOLDER(FOLDERID_PicturesLibrary,
1318 NO_CSIDL,
1319 "PicturesLibrary",
1320 KF_CATEGORY_PERUSER,
1321 FOLDERID_Libraries,
1322 "Pictures.library-ms",
1323 "::{031E4825-7B94-4dc3-B131-E946B44C8DD5}\\{A990AE9F-A03B-4e80-94BC-9912D7504104}\0\0",
1325 KFDF_PRECREATE | KFDF_STREAM),
1326 KNOWN_FOLDER(FOLDERID_Playlists,
1327 NO_CSIDL,
1328 "Playlists",
1329 KF_CATEGORY_PERUSER,
1330 FOLDERID_Music,
1331 "Playlists",
1332 NULL,
1333 FILE_ATTRIBUTE_READONLY,
1335 KNOWN_FOLDER(FOLDERID_PrintersFolder,
1336 CSIDL_PRINTERS,
1337 "PrintersFolder",
1338 KF_CATEGORY_VIRTUAL,
1339 GUID_NULL,
1340 NULL,
1341 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{2227A280-3AEA-1069-A2DE-08002B30309D}\0\0",
1344 KNOWN_FOLDER(FOLDERID_PrintHood,
1345 CSIDL_PRINTHOOD,
1346 "PrintHood",
1347 KF_CATEGORY_PERUSER,
1348 FOLDERID_RoamingAppData,
1349 "Microsoft\\Windows\\Printer Shortcuts",
1350 NULL,
1353 KNOWN_FOLDER(FOLDERID_Profile,
1354 CSIDL_PROFILE,
1355 "Profile",
1356 KF_CATEGORY_FIXED,
1357 GUID_NULL,
1358 NULL,
1359 NULL,
1362 KNOWN_FOLDER(FOLDERID_ProgramData,
1363 CSIDL_COMMON_APPDATA,
1364 "Common AppData",
1365 KF_CATEGORY_FIXED,
1366 GUID_NULL,
1367 NULL,
1368 NULL,
1371 KNOWN_FOLDER(FOLDERID_ProgramFiles,
1372 CSIDL_PROGRAM_FILES,
1373 "ProgramFiles",
1374 KF_CATEGORY_FIXED,
1375 GUID_NULL,
1376 NULL,
1377 NULL,
1378 FILE_ATTRIBUTE_READONLY,
1379 KFDF_PRECREATE
1381 KNOWN_FOLDER(FOLDERID_ProgramFilesCommon,
1382 CSIDL_PROGRAM_FILES_COMMON,
1383 "ProgramFilesCommon",
1384 KF_CATEGORY_FIXED,
1385 GUID_NULL,
1386 NULL,
1387 NULL,
1390 KNOWN_FOLDER(FOLDERID_ProgramFilesCommonX64,
1391 NO_CSIDL,
1392 "ProgramFilesCommonX64",
1393 KF_CATEGORY_FIXED,
1394 GUID_NULL,
1395 NULL,
1396 NULL,
1399 KNOWN_FOLDER(FOLDERID_ProgramFilesCommonX86,
1400 NO_CSIDL,
1401 "ProgramFilesCommonX86",
1402 KF_CATEGORY_FIXED,
1403 GUID_NULL,
1404 NULL,
1405 NULL,
1408 KNOWN_FOLDER(FOLDERID_ProgramFilesX64,
1409 NO_CSIDL,
1410 "ProgramFilesX64",
1411 KF_CATEGORY_FIXED,
1412 GUID_NULL,
1413 NULL,
1414 NULL,
1417 KNOWN_FOLDER(FOLDERID_ProgramFilesX86,
1418 CSIDL_PROGRAM_FILESX86,
1419 "ProgramFilesX86",
1420 KF_CATEGORY_FIXED,
1421 GUID_NULL,
1422 NULL,
1423 NULL,
1424 FILE_ATTRIBUTE_READONLY,
1425 KFDF_PRECREATE),
1426 KNOWN_FOLDER(FOLDERID_Programs,
1427 CSIDL_PROGRAMS,
1428 "Programs",
1429 KF_CATEGORY_PERUSER,
1430 FOLDERID_StartMenu,
1431 "Programs",
1432 NULL,
1433 FILE_ATTRIBUTE_READONLY,
1434 KFDF_PRECREATE),
1435 KNOWN_FOLDER(FOLDERID_Public,
1436 NO_CSIDL,
1437 "Public",
1438 KF_CATEGORY_FIXED,
1439 GUID_NULL,
1440 NULL,
1441 "::{4336a54d-038b-4685-ab02-99bb52d3fb8b}\0"
1442 "(null)\0\0" /* 6.1 */,
1443 FILE_ATTRIBUTE_READONLY,
1444 KFDF_PRECREATE),
1445 KNOWN_FOLDER(FOLDERID_PublicDesktop,
1446 CSIDL_COMMON_DESKTOPDIRECTORY,
1447 "Common Desktop",
1448 KF_CATEGORY_COMMON,
1449 FOLDERID_Public,
1450 "Desktop",
1451 NULL,
1452 FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN,
1453 KFDF_PRECREATE),
1454 KNOWN_FOLDER(FOLDERID_PublicDocuments,
1455 CSIDL_COMMON_DOCUMENTS,
1456 "Common Documents",
1457 KF_CATEGORY_COMMON,
1458 FOLDERID_Public,
1459 "Documents",
1460 NULL,
1461 FILE_ATTRIBUTE_READONLY,
1462 KFDF_PRECREATE),
1463 KNOWN_FOLDER(FOLDERID_PublicDownloads,
1464 NO_CSIDL,
1465 "CommonDownloads",
1466 KF_CATEGORY_COMMON,
1467 FOLDERID_Public,
1468 "Downloads",
1469 NULL,
1470 FILE_ATTRIBUTE_READONLY,
1471 KFDF_PRECREATE),
1472 KNOWN_FOLDER(FOLDERID_PublicGameTasks,
1473 NO_CSIDL,
1474 "PublicGameTasks",
1475 KF_CATEGORY_COMMON,
1476 FOLDERID_ProgramData,
1477 "Microsoft\\Windows\\GameExplorer",
1478 NULL,
1480 KFDF_LOCAL_REDIRECT_ONLY),
1481 KNOWN_FOLDER(FOLDERID_PublicLibraries,
1482 NO_CSIDL,
1483 "PublicLibraries",
1484 KF_CATEGORY_COMMON,
1485 FOLDERID_Public,
1486 "Libraries",
1487 NULL,
1488 FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN,
1489 KFDF_PRECREATE),
1490 KNOWN_FOLDER(FOLDERID_PublicMusic,
1491 CSIDL_COMMON_MUSIC,
1492 "CommonMusic",
1493 KF_CATEGORY_COMMON,
1494 FOLDERID_Public,
1495 "Music",
1496 NULL,
1497 FILE_ATTRIBUTE_READONLY,
1498 KFDF_PRECREATE),
1499 KNOWN_FOLDER(FOLDERID_PublicPictures,
1500 CSIDL_COMMON_PICTURES,
1501 "CommonPictures",
1502 KF_CATEGORY_COMMON,
1503 FOLDERID_Public,
1504 "Pictures",
1505 NULL,
1506 FILE_ATTRIBUTE_READONLY,
1507 KFDF_PRECREATE),
1508 KNOWN_FOLDER(FOLDERID_PublicRingtones,
1509 NO_CSIDL,
1510 "CommonRingtones",
1511 KF_CATEGORY_COMMON,
1512 FOLDERID_ProgramData,
1513 "Microsoft\\Windows\\Ringtones",
1514 NULL,
1516 KFDF_PRECREATE),
1517 KNOWN_FOLDER(FOLDERID_PublicVideos,
1518 CSIDL_COMMON_VIDEO,
1519 "CommonVideo",
1520 KF_CATEGORY_COMMON,
1521 FOLDERID_Public,
1522 "Videos",
1523 NULL,
1524 FILE_ATTRIBUTE_READONLY,
1525 KFDF_PRECREATE),
1526 KNOWN_FOLDER(FOLDERID_QuickLaunch,
1527 NO_CSIDL,
1528 "Quick Launch",
1529 KF_CATEGORY_PERUSER,
1530 FOLDERID_RoamingAppData,
1531 "Microsoft\\Internet Explorer\\Quick Launch",
1532 NULL,
1535 KNOWN_FOLDER(FOLDERID_Recent,
1536 CSIDL_RECENT,
1537 "Recent",
1538 KF_CATEGORY_PERUSER,
1539 FOLDERID_RoamingAppData,
1540 "Microsoft\\Windows\\Recent",
1541 NULL,
1542 FILE_ATTRIBUTE_READONLY,
1543 KFDF_PRECREATE),
1544 KNOWN_FOLDER(FOLDERID_RecordedTVLibrary,
1545 NO_CSIDL,
1546 "RecordedTVLibrary",
1547 KF_CATEGORY_COMMON,
1548 FOLDERID_PublicLibraries,
1549 "RecordedTV.library-ms",
1550 NULL,
1552 KFDF_PRECREATE | KFDF_STREAM),
1553 KNOWN_FOLDER(FOLDERID_RecycleBinFolder,
1554 CSIDL_BITBUCKET,
1555 "RecycleBinFolder",
1556 KF_CATEGORY_VIRTUAL,
1557 GUID_NULL,
1558 NULL,
1559 "::{645FF040-5081-101B-9F08-00AA002F954E}\0\0",
1562 KNOWN_FOLDER(FOLDERID_ResourceDir,
1563 CSIDL_RESOURCES,
1564 "ResourceDir",
1565 KF_CATEGORY_FIXED,
1566 GUID_NULL,
1567 NULL,
1568 NULL,
1571 KNOWN_FOLDER(FOLDERID_Ringtones,
1572 NO_CSIDL,
1573 "Ringtones",
1574 KF_CATEGORY_PERUSER,
1575 FOLDERID_LocalAppData,
1576 "Microsoft\\Windows\\Ringtones",
1577 NULL,
1579 KFDF_PRECREATE),
1580 KNOWN_FOLDER(FOLDERID_RoamingAppData,
1581 CSIDL_APPDATA,
1582 "AppData",
1583 KF_CATEGORY_PERUSER,
1584 FOLDERID_Profile,
1585 "AppData\\Roaming",
1586 NULL,
1589 KNOWN_FOLDER(FOLDERID_SampleMusic,
1590 NO_CSIDL,
1591 "SampleMusic",
1592 KF_CATEGORY_COMMON,
1593 FOLDERID_PublicMusic,
1594 "Sample Music",
1595 NULL,
1596 FILE_ATTRIBUTE_READONLY,
1597 KFDF_PRECREATE),
1598 KNOWN_FOLDER(FOLDERID_SamplePictures,
1599 NO_CSIDL,
1600 "SamplePictures",
1601 KF_CATEGORY_COMMON,
1602 FOLDERID_PublicPictures,
1603 "Sample Pictures",
1604 NULL,
1605 FILE_ATTRIBUTE_READONLY,
1606 KFDF_PRECREATE),
1607 KNOWN_FOLDER(FOLDERID_SamplePlaylists,
1608 NO_CSIDL,
1609 "SamplePlaylists",
1610 KF_CATEGORY_COMMON,
1611 FOLDERID_PublicMusic,
1612 "Sample Playlists",
1613 NULL,
1614 FILE_ATTRIBUTE_READONLY,
1616 KNOWN_FOLDER(FOLDERID_SampleVideos,
1617 NO_CSIDL,
1618 "SampleVideos",
1619 KF_CATEGORY_COMMON,
1620 FOLDERID_PublicVideos,
1621 "Sample Videos",
1622 NULL,
1623 FILE_ATTRIBUTE_READONLY,
1624 KFDF_PRECREATE),
1625 KNOWN_FOLDER(FOLDERID_SavedGames,
1626 NO_CSIDL,
1627 "SavedGames",
1628 KF_CATEGORY_PERUSER,
1629 FOLDERID_Profile,
1630 "Saved Games",
1631 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{4C5C32FF-BB9D-43b0-B5B4-2D72E54EAAA4}\0\0",
1632 FILE_ATTRIBUTE_READONLY,
1633 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH),
1634 KNOWN_FOLDER(FOLDERID_SavedSearches,
1635 NO_CSIDL,
1636 "Searches",
1637 KF_CATEGORY_PERUSER,
1638 FOLDERID_Profile,
1639 "Searches",
1640 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{7d1d3a04-debb-4115-95cf-2f29da2920da}\0\0",
1641 FILE_ATTRIBUTE_READONLY,
1642 KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH),
1643 KNOWN_FOLDER(FOLDERID_SEARCH_CSC,
1644 NO_CSIDL,
1645 "CSCFolder",
1646 KF_CATEGORY_VIRTUAL,
1647 GUID_NULL,
1648 NULL,
1649 "shell:::{BD7A2E7B-21CB-41b2-A086-B309680C6B7E}\\*\0\0",
1652 KNOWN_FOLDER(FOLDERID_SearchHome,
1653 NO_CSIDL,
1654 "SearchHomeFolder",
1655 KF_CATEGORY_VIRTUAL,
1656 GUID_NULL,
1657 NULL,
1658 "::{9343812e-1c37-4a49-a12e-4b2d810d956b}\0\0",
1661 KNOWN_FOLDER(FOLDERID_SEARCH_MAPI,
1662 NO_CSIDL,
1663 "MAPIFolder",
1664 KF_CATEGORY_VIRTUAL,
1665 GUID_NULL,
1666 NULL,
1667 "shell:::{89D83576-6BD1-4C86-9454-BEB04E94C819}\\*\0\0",
1670 KNOWN_FOLDER(FOLDERID_SendTo,
1671 CSIDL_SENDTO,
1672 "SendTo",
1673 KF_CATEGORY_PERUSER,
1674 FOLDERID_RoamingAppData,
1675 "Microsoft\\Windows\\SendTo",
1676 NULL,
1679 KNOWN_FOLDER(FOLDERID_SidebarDefaultParts,
1680 NO_CSIDL,
1681 "Default Gadgets",
1682 KF_CATEGORY_COMMON,
1683 FOLDERID_ProgramFiles,
1684 "Windows Sidebar\\Gadgets",
1685 NULL,
1688 KNOWN_FOLDER(FOLDERID_SidebarParts,
1689 NO_CSIDL,
1690 "Gadgets",
1691 KF_CATEGORY_PERUSER,
1692 FOLDERID_LocalAppData,
1693 "Microsoft\\Windows Sidebar\\Gadgets",
1694 NULL,
1697 KNOWN_FOLDER(FOLDERID_StartMenu,
1698 CSIDL_STARTMENU,
1699 "Start Menu",
1700 KF_CATEGORY_PERUSER,
1701 FOLDERID_RoamingAppData,
1702 "Microsoft\\Windows\\Start Menu",
1703 NULL,
1704 FILE_ATTRIBUTE_READONLY,
1705 KFDF_PRECREATE),
1706 KNOWN_FOLDER(FOLDERID_Startup,
1707 CSIDL_STARTUP,
1708 "Startup",
1709 KF_CATEGORY_PERUSER,
1710 FOLDERID_Programs,
1711 "StartUp",
1712 NULL,
1713 FILE_ATTRIBUTE_READONLY,
1714 KFDF_PRECREATE),
1715 KNOWN_FOLDER(FOLDERID_SyncManagerFolder,
1716 NO_CSIDL,
1717 "SyncCenterFolder",
1718 KF_CATEGORY_VIRTUAL,
1719 GUID_NULL,
1720 NULL,
1721 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\0"
1722 "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\0\0" /* 6.1 */,
1725 KNOWN_FOLDER(FOLDERID_SyncResultsFolder,
1726 NO_CSIDL,
1727 "SyncResultsFolder",
1728 KF_CATEGORY_VIRTUAL,
1729 GUID_NULL,
1730 NULL,
1731 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\\::{BC48B32F-5910-47F5-8570-5074A8A5636A},\0"
1732 "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\\::{BC48B32F-5910-47F5-8570-5074A8A5636A},\0\0",
1735 KNOWN_FOLDER(FOLDERID_SyncSetupFolder,
1736 NO_CSIDL,
1737 "SyncSetupFolder",
1738 KF_CATEGORY_VIRTUAL,
1739 GUID_NULL,
1740 NULL,
1741 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\\::{F1390A9A-A3F4-4E5D-9C5F-98F3BD8D935C},\0"
1742 "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\\::{F1390A9A-A3F4-4E5D-9C5F-98F3BD8D935C},\0\0" /* 6.1 */,
1745 KNOWN_FOLDER(FOLDERID_System,
1746 CSIDL_SYSTEM,
1747 "System",
1748 KF_CATEGORY_FIXED,
1749 GUID_NULL,
1750 NULL,
1751 NULL,
1754 KNOWN_FOLDER(FOLDERID_SystemX86,
1755 CSIDL_SYSTEMX86,
1756 "SystemX86",
1757 KF_CATEGORY_FIXED,
1758 GUID_NULL,
1759 NULL,
1760 NULL,
1763 KNOWN_FOLDER(FOLDERID_Templates,
1764 CSIDL_TEMPLATES,
1765 "Templates",
1766 KF_CATEGORY_PERUSER,
1767 FOLDERID_RoamingAppData,
1768 "Microsoft\\Windows\\Templates",
1769 NULL,
1772 KNOWN_FOLDER(FOLDERID_UserPinned,
1773 NO_CSIDL,
1774 "User Pinned",
1775 KF_CATEGORY_PERUSER,
1776 FOLDERID_QuickLaunch,
1777 "User Pinned",
1778 NULL,
1779 FILE_ATTRIBUTE_HIDDEN,
1780 KFDF_PRECREATE),
1781 KNOWN_FOLDER(FOLDERID_UserProfiles,
1782 NO_CSIDL,
1783 "UserProfiles",
1784 KF_CATEGORY_FIXED,
1785 GUID_NULL,
1786 NULL,
1787 NULL,
1788 FILE_ATTRIBUTE_READONLY,
1789 KFDF_PRECREATE),
1790 KNOWN_FOLDER(FOLDERID_UserProgramFiles,
1791 NO_CSIDL,
1792 "UserProgramFiles",
1793 KF_CATEGORY_PERUSER,
1794 FOLDERID_LocalAppData,
1795 "Programs",
1796 NULL,
1799 KNOWN_FOLDER(FOLDERID_UserProgramFilesCommon,
1800 NO_CSIDL,
1801 "UserProgramFilesCommon",
1802 KF_CATEGORY_PERUSER,
1803 FOLDERID_UserProgramFiles,
1804 "Common",
1805 NULL,
1808 KNOWN_FOLDER(FOLDERID_UsersFiles,
1809 NO_CSIDL,
1810 "UsersFilesFolder",
1811 KF_CATEGORY_VIRTUAL,
1812 GUID_NULL,
1813 NULL,
1814 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\0\0",
1817 KNOWN_FOLDER(FOLDERID_UsersLibraries,
1818 NO_CSIDL,
1819 "UsersLibrariesFolder",
1820 KF_CATEGORY_VIRTUAL,
1821 GUID_NULL,
1822 NULL,
1823 "::{031E4825-7B94-4dc3-B131-E946B44C8DD5}\0\0",
1826 KNOWN_FOLDER(FOLDERID_Videos,
1827 CSIDL_MYVIDEO,
1828 "My Video",
1829 KF_CATEGORY_PERUSER,
1830 FOLDERID_Profile,
1831 "Videos",
1832 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{18989B1D-99B5-455B-841C-AB7C74E4DDFC}\0\0",
1833 FILE_ATTRIBUTE_READONLY,
1834 KFDF_ROAMABLE | KFDF_PRECREATE),
1835 KNOWN_FOLDER(FOLDERID_VideosLibrary,
1836 NO_CSIDL,
1837 "VideosLibrary",
1838 KF_CATEGORY_PERUSER,
1839 FOLDERID_Libraries,
1840 "Videos.library-ms",
1841 "::{031E4825-7B94-4dc3-B131-E946B44C8DD5}\\{491E922F-5643-4af4-A7EB-4E7A138D8174}\0\0",
1843 KFDF_PRECREATE | KFDF_STREAM),
1844 KNOWN_FOLDER(FOLDERID_Windows,
1845 CSIDL_WINDOWS,
1846 "Windows",
1847 KF_CATEGORY_FIXED,
1848 GUID_NULL,
1849 NULL,
1850 NULL,
1853 KNOWN_FOLDER(_FOLDERID_CredentialManager,
1854 NO_CSIDL,
1855 "CredentialManager",
1856 KF_CATEGORY_FIXED,
1857 GUID_NULL,
1858 NULL,
1859 NULL,
1862 KNOWN_FOLDER(_FOLDERID_CryptoKeys,
1863 NO_CSIDL,
1864 "CryptoKeys",
1865 KF_CATEGORY_FIXED,
1866 GUID_NULL,
1867 NULL,
1868 NULL,
1871 KNOWN_FOLDER(_FOLDERID_DpapiKeys,
1872 NO_CSIDL,
1873 "DpapiKeys",
1874 KF_CATEGORY_FIXED,
1875 GUID_NULL,
1876 NULL,
1877 NULL,
1880 KNOWN_FOLDER(_FOLDERID_SystemCertificates,
1881 NO_CSIDL,
1882 "SystemCertificates",
1883 KF_CATEGORY_FIXED,
1884 GUID_NULL,
1885 NULL,
1886 NULL,
1889 { NULL, NULL, 0, NULL, NULL, 0, 0 }
1891 #undef KNOWN_FOLDER
1892 BOOL known_folder_found[sizeof(known_folders)/sizeof(known_folders[0])-1];
1894 static void check_known_folder(IKnownFolderManager *mgr, KNOWNFOLDERID *folderId)
1896 HRESULT hr;
1897 const struct knownFolderDef *known_folder = &known_folders[0];
1898 int csidl, expectedCsidl, ret;
1899 KNOWNFOLDER_DEFINITION kfd;
1900 IKnownFolder *folder;
1901 WCHAR sName[1024], sRelativePath[MAX_PATH], sParsingName[MAX_PATH];
1902 BOOL validPath;
1903 BOOL *current_known_folder_found = &known_folder_found[0];
1904 BOOL found = FALSE;
1905 const char *srcParsingName;
1907 while(known_folder->folderId != NULL)
1909 if(IsEqualGUID(known_folder->folderId, folderId))
1911 *current_known_folder_found = TRUE;
1912 found = TRUE;
1913 /* verify CSIDL */
1914 if(known_folder->csidl != NO_CSIDL)
1916 expectedCsidl = known_folder->csidl & (~CSIDL_TODO_WINE);
1918 hr = IKnownFolderManager_FolderIdToCsidl(mgr, folderId, &csidl);
1919 ok_(__FILE__, known_folder->line)(hr == S_OK, "cannot retrieve CSIDL for folder %s\n", known_folder->sFolderId);
1921 if(known_folder->csidl & CSIDL_TODO_WINE)
1922 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);
1923 else
1924 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);
1927 hr = IKnownFolderManager_GetFolder(mgr, folderId, &folder);
1928 ok_(__FILE__, known_folder->line)(hr == S_OK, "cannot get known folder for %s\n", known_folder->sFolderId);
1929 if(SUCCEEDED(hr))
1931 hr = IKnownFolder_GetFolderDefinition(folder, &kfd);
1932 todo_wine
1933 ok_(__FILE__, known_folder->line)(hr == S_OK, "cannot get known folder definition for %s\n", known_folder->sFolderId);
1934 if(SUCCEEDED(hr))
1936 ret = MultiByteToWideChar(CP_ACP, 0, known_folder->sName, -1, sName, sizeof(sName)/sizeof(sName[0]));
1937 ok_(__FILE__, known_folder->line)(ret != 0, "cannot convert known folder name \"%s\" to wide characters\n", known_folder->sName);
1939 todo_wine
1940 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));
1942 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);
1944 ok_(__FILE__, known_folder->line)(IsEqualGUID(known_folder->fidParent, &kfd.fidParent),
1945 "invalid known folder parent for %s: %s expected, but %s retrieved\n",
1946 known_folder->sFolderId, known_folder->sParent, wine_dbgstr_guid(&kfd.fidParent));
1948 if(!known_folder->sRelativePath)
1949 validPath = (kfd.pszRelativePath==NULL);
1950 else
1952 ret = MultiByteToWideChar(CP_ACP, 0, known_folder->sRelativePath, -1, sRelativePath, sizeof(sRelativePath)/sizeof(sRelativePath[0]));
1953 ok_(__FILE__, known_folder->line)(ret != 0, "cannot convert known folder path \"%s\" to wide characters\n", known_folder->sRelativePath);
1955 validPath = (lstrcmpW(kfd.pszRelativePath, sRelativePath)==0);
1958 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));
1960 /* to check parsing name, we need to iterate list */
1961 srcParsingName = known_folder->sParsingName;
1963 /* if we expect NULL, then we don't even check the list */
1964 validPath = (srcParsingName==NULL) && (kfd.pszParsingName==NULL);
1966 if(srcParsingName)
1967 while(*srcParsingName && !validPath)
1969 /* when NULL is only one of possible value, we mark path as valid */
1970 validPath = (strcmp(srcParsingName, "(null)")==0) && (kfd.pszParsingName==NULL);
1972 /* in the other case, we compare string from list with retrieved value */
1973 if(!validPath)
1975 ret = MultiByteToWideChar(CP_ACP, 0, srcParsingName, -1, sParsingName, sizeof(sParsingName)/sizeof(sParsingName[0]));
1976 ok_(__FILE__, known_folder->line)(ret != 0, "cannot convert known folder path \"%s\" to wide characters\n", srcParsingName);
1978 validPath = (lstrcmpW(kfd.pszParsingName, sParsingName)==0);
1981 srcParsingName += strlen(srcParsingName)+1;
1984 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));
1986 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);
1988 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);
1990 FreeKnownFolderDefinitionFields(&kfd);
1993 IKnownFolder_Release(folder);
1996 break;
1998 known_folder++;
1999 current_known_folder_found++;
2002 if(!found)
2004 trace("unknown known folder found: %s\n", wine_dbgstr_guid(folderId));
2006 hr = IKnownFolderManager_GetFolder(mgr, folderId, &folder);
2007 ok(hr == S_OK, "cannot get known folder for %s\n", wine_dbgstr_guid(folderId));
2008 if(SUCCEEDED(hr))
2010 hr = IKnownFolder_GetFolderDefinition(folder, &kfd);
2011 todo_wine
2012 ok(hr == S_OK, "cannot get known folder definition for %s\n", wine_dbgstr_guid(folderId));
2013 if(SUCCEEDED(hr))
2015 trace(" category: %d\n", kfd.category);
2016 trace(" name: %s\n", wine_dbgstr_w(kfd.pszName));
2017 trace(" description: %s\n", wine_dbgstr_w(kfd.pszDescription));
2018 trace(" parent: %s\n", wine_dbgstr_guid(&kfd.fidParent));
2019 trace(" relative path: %s\n", wine_dbgstr_w(kfd.pszRelativePath));
2020 trace(" parsing name: %s\n", wine_dbgstr_w(kfd.pszParsingName));
2021 trace(" tooltip: %s\n", wine_dbgstr_w(kfd.pszTooltip));
2022 trace(" localized name: %s\n", wine_dbgstr_w(kfd.pszLocalizedName));
2023 trace(" icon: %s\n", wine_dbgstr_w(kfd.pszIcon));
2024 trace(" security: %s\n", wine_dbgstr_w(kfd.pszSecurity));
2025 trace(" attributes: 0x%08x\n", kfd.dwAttributes);
2026 trace(" flags: 0x%08x\n", kfd.kfdFlags);
2027 trace(" type: %s\n", wine_dbgstr_guid(&kfd.ftidType));
2028 FreeKnownFolderDefinitionFields(&kfd);
2031 IKnownFolder_Release(folder);
2035 #undef NO_CSIDL
2036 #undef CSIDL_TODO_WINE
2038 static void test_knownFolders(void)
2040 static const WCHAR sWindows[] = {'W','i','n','d','o','w','s',0};
2041 static const WCHAR sExample[] = {'E','x','a','m','p','l','e',0};
2042 static const WCHAR sExample2[] = {'E','x','a','m','p','l','e','2',0};
2043 static const WCHAR sSubFolder[] = {'S','u','b','F','o','l','d','e','r',0};
2044 static const WCHAR sBackslash[] = {'\\',0};
2045 static const KNOWNFOLDERID newFolderId = {0x01234567, 0x89AB, 0xCDEF, {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x01} };
2046 static const KNOWNFOLDERID subFolderId = {0xFEDCBA98, 0x7654, 0x3210, {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF} };
2047 HRESULT hr;
2048 IKnownFolderManager *mgr = NULL;
2049 IKnownFolder *folder = NULL, *subFolder = NULL;
2050 KNOWNFOLDERID folderId, *folders;
2051 KF_CATEGORY cat = 0;
2052 KNOWNFOLDER_DEFINITION kfDefinition, kfSubDefinition;
2053 int csidl, i;
2054 UINT nCount = 0;
2055 LPWSTR folderPath, errorMsg;
2056 KF_REDIRECTION_CAPABILITIES redirectionCapabilities = 1;
2057 WCHAR sWinDir[MAX_PATH], sExamplePath[MAX_PATH], sExample2Path[MAX_PATH], sSubFolderPath[MAX_PATH], sSubFolder2Path[MAX_PATH];
2058 BOOL bRes;
2059 DWORD dwAttributes;
2061 GetWindowsDirectoryW( sWinDir, MAX_PATH );
2063 GetTempPathW(sizeof(sExamplePath)/sizeof(sExamplePath[0]), sExamplePath);
2064 lstrcatW(sExamplePath, sExample);
2066 GetTempPathW(sizeof(sExample2Path)/sizeof(sExample2Path[0]), sExample2Path);
2067 lstrcatW(sExample2Path, sExample2);
2069 lstrcpyW(sSubFolderPath, sExamplePath);
2070 lstrcatW(sSubFolderPath, sBackslash);
2071 lstrcatW(sSubFolderPath, sSubFolder);
2073 lstrcpyW(sSubFolder2Path, sExample2Path);
2074 lstrcatW(sSubFolder2Path, sBackslash);
2075 lstrcatW(sSubFolder2Path, sSubFolder);
2077 CoInitialize(NULL);
2079 hr = CoCreateInstance(&CLSID_KnownFolderManager, NULL, CLSCTX_INPROC_SERVER,
2080 &IID_IKnownFolderManager, (LPVOID*)&mgr);
2081 if(hr == REGDB_E_CLASSNOTREG)
2082 win_skip("IKnownFolderManager unavailable\n");
2083 else
2085 ok(hr == S_OK, "failed to create KnownFolderManager instance: 0x%08x\n", hr);
2087 hr = IKnownFolderManager_FolderIdFromCsidl(mgr, CSIDL_WINDOWS, &folderId);
2088 ok(hr == S_OK, "failed to convert CSIDL to KNOWNFOLDERID: 0x%08x\n", hr);
2089 ok(IsEqualGUID(&folderId, &FOLDERID_Windows)==TRUE, "invalid KNOWNFOLDERID returned\n");
2091 hr = IKnownFolderManager_FolderIdToCsidl(mgr, &FOLDERID_Windows, &csidl);
2092 ok(hr == S_OK, "failed to convert CSIDL to KNOWNFOLDERID: 0x%08x\n", hr);
2093 ok(csidl == CSIDL_WINDOWS, "invalid CSIDL returned\n");
2095 hr = IKnownFolderManager_GetFolder(mgr, &FOLDERID_Windows, &folder);
2096 ok(hr == S_OK, "failed to get known folder: 0x%08x\n", hr);
2097 if(SUCCEEDED(hr))
2099 hr = IKnownFolder_GetCategory(folder, &cat);
2100 todo_wine
2101 ok(hr == S_OK, "failed to get folder category: 0x%08x\n", hr);
2102 todo_wine
2103 ok(cat==KF_CATEGORY_FIXED, "invalid folder category: %d\n", cat);
2105 hr = IKnownFolder_GetId(folder, &folderId);
2106 ok(hr == S_OK, "failed to get folder id: 0x%08x\n", hr);
2107 ok(IsEqualGUID(&folderId, &FOLDERID_Windows)==TRUE, "invalid KNOWNFOLDERID returned\n");
2109 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
2110 ok(lstrcmpiW(sWinDir, folderPath)==0, "invalid path returned: \"%s\", expected: \"%s\"\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sWinDir));
2111 CoTaskMemFree(folderPath);
2113 hr = IKnownFolder_GetRedirectionCapabilities(folder, &redirectionCapabilities);
2114 todo_wine
2115 ok(hr == S_OK, "failed to get redirection capabilities: 0x%08x\n", hr);
2116 todo_wine
2117 ok(redirectionCapabilities==0, "invalid redirection capabilities returned: %d\n", redirectionCapabilities);
2119 hr = IKnownFolder_SetPath(folder, 0, sWinDir);
2120 todo_wine
2121 ok(hr == E_INVALIDARG, "unexpected value from SetPath: 0x%08x\n", hr);
2123 hr = IKnownFolder_GetFolderDefinition(folder, &kfDefinition);
2124 todo_wine
2125 ok(hr == S_OK, "failed to get folder definition: 0x%08x\n", hr);
2126 if(SUCCEEDED(hr))
2128 todo_wine
2129 ok(kfDefinition.category==KF_CATEGORY_FIXED, "invalid folder category: 0x%08x\n", kfDefinition.category);
2130 todo_wine
2131 ok(lstrcmpW(kfDefinition.pszName, sWindows)==0, "invalid folder name: %s\n", wine_dbgstr_w(kfDefinition.pszName));
2132 todo_wine
2133 ok(kfDefinition.dwAttributes==0, "invalid folder attributes: %d\n", kfDefinition.dwAttributes);
2134 FreeKnownFolderDefinitionFields(&kfDefinition);
2137 hr = IKnownFolder_Release(folder);
2138 ok(hr == S_OK, "failed to release KnownFolder instance: 0x%08x\n", hr);
2141 hr = IKnownFolderManager_GetFolderByName(mgr, sWindows, &folder);
2142 todo_wine
2143 ok(hr == S_OK, "failed to get known folder: 0x%08x\n", hr);
2144 if(SUCCEEDED(hr))
2146 hr = IKnownFolder_GetId(folder, &folderId);
2147 ok(hr == S_OK, "failed to get folder id: 0x%08x\n", hr);
2148 ok(IsEqualGUID(&folderId, &FOLDERID_Windows)==TRUE, "invalid KNOWNFOLDERID returned\n");
2150 hr = IKnownFolder_Release(folder);
2151 ok(hr == S_OK, "failed to release KnownFolder instance: 0x%08x\n", hr);
2154 for(i=0; i<sizeof(known_folder_found)/sizeof(known_folder_found[0]); ++i)
2155 known_folder_found[i] = FALSE;
2157 hr = IKnownFolderManager_GetFolderIds(mgr, &folders, &nCount);
2158 ok(hr == S_OK, "failed to get known folders: 0x%08x\n", hr);
2159 for(i=0;i<nCount;++i)
2160 check_known_folder(mgr, &folders[i]);
2162 for(i=0; i<sizeof(known_folder_found)/sizeof(known_folder_found[0]); ++i)
2163 if(!known_folder_found[i])
2164 trace("Known folder %s not found on current platform\n", known_folders[i].sFolderId);
2166 CoTaskMemFree(folders);
2168 /* test of registering new known folders */
2169 bRes = CreateDirectoryW(sExamplePath, NULL);
2170 ok(bRes, "cannot create example directory: %s\n", wine_dbgstr_w(sExamplePath));
2171 bRes = CreateDirectoryW(sExample2Path, NULL);
2172 ok(bRes, "cannot create example directory: %s\n", wine_dbgstr_w(sExample2Path));
2173 bRes = CreateDirectoryW(sSubFolderPath, NULL);
2174 ok(bRes, "cannot create example directory: %s\n", wine_dbgstr_w(sSubFolderPath));
2176 ZeroMemory(&kfDefinition, sizeof(kfDefinition));
2177 kfDefinition.category = KF_CATEGORY_PERUSER;
2178 kfDefinition.pszName = CoTaskMemAlloc(sizeof(sExample));
2179 lstrcpyW(kfDefinition.pszName, sExample);
2180 kfDefinition.pszDescription = CoTaskMemAlloc(sizeof(sExample));
2181 lstrcpyW(kfDefinition.pszDescription, sExample);
2182 kfDefinition.pszRelativePath = CoTaskMemAlloc(sizeof(sExamplePath));
2183 lstrcpyW(kfDefinition.pszRelativePath, sExamplePath);
2185 hr = IKnownFolderManager_RegisterFolder(mgr, &newFolderId, &kfDefinition);
2186 if(hr == HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED))
2187 win_skip("No permissions required to register custom known folder\n");
2188 else
2190 ok(hr == S_OK, "failed to register known folder: 0x%08x\n", hr);
2191 if(SUCCEEDED(hr))
2193 hr = IKnownFolderManager_GetFolder(mgr, &newFolderId, &folder);
2194 ok(hr == S_OK, "failed to get known folder: 0x%08x\n", hr);
2195 if(SUCCEEDED(hr))
2197 hr = IKnownFolder_GetCategory(folder, &cat);
2198 ok(hr == S_OK, "failed to get folder category: hr=0x%0x\n", hr);
2199 ok(cat == KF_CATEGORY_PERUSER, "invalid category returned: %d, while %d (KF_CATEGORY_PERUSER) expected\n", cat, KF_CATEGORY_PERUSER);
2201 hr = IKnownFolder_GetId(folder, &folderId);
2202 ok(hr == S_OK, "failed to get folder id: 0x%08x\n", hr);
2203 ok(IsEqualGUID(&folderId, &newFolderId)==TRUE, "invalid KNOWNFOLDERID returned\n");
2205 /* current path should be Temp\Example */
2206 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
2207 ok(hr == S_OK, "failed to get path from known folder: 0x%08x\n", hr);
2208 ok(lstrcmpiW(folderPath, sExamplePath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExamplePath));
2209 CoTaskMemFree(folderPath);
2211 /* register sub-folder and mark it as child of Example folder */
2212 ZeroMemory(&kfSubDefinition, sizeof(kfSubDefinition));
2213 kfSubDefinition.category = KF_CATEGORY_PERUSER;
2214 kfSubDefinition.pszName = CoTaskMemAlloc(sizeof(sSubFolder));
2215 lstrcpyW(kfSubDefinition.pszName, sSubFolder);
2216 kfSubDefinition.pszDescription = CoTaskMemAlloc(sizeof(sSubFolder));
2217 lstrcpyW(kfSubDefinition.pszDescription, sSubFolder);
2218 kfSubDefinition.pszRelativePath = CoTaskMemAlloc(sizeof(sSubFolder));
2219 lstrcpyW(kfSubDefinition.pszRelativePath, sSubFolder);
2220 kfSubDefinition.fidParent = newFolderId;
2222 hr = IKnownFolderManager_RegisterFolder(mgr, &subFolderId, &kfSubDefinition);
2223 ok(hr == S_OK, "failed to register known folder: 0x%08x\n", hr);
2224 if(SUCCEEDED(hr))
2227 hr = IKnownFolderManager_GetFolder(mgr, &subFolderId, &subFolder);
2228 ok(hr == S_OK, "failed to get known folder: 0x%08x\n", hr);
2229 if(SUCCEEDED(hr))
2231 /* check sub folder path */
2232 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
2233 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2234 ok(lstrcmpiW(folderPath, sSubFolderPath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolderPath));
2235 CoTaskMemFree(folderPath);
2238 /* try to redirect Example to Temp\Example2 */
2239 hr = IKnownFolderManager_Redirect(mgr, &newFolderId, NULL, 0, sExample2Path, 0, NULL, &errorMsg);
2240 ok(hr == S_OK, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr, wine_dbgstr_w(errorMsg));
2242 /* verify */
2243 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
2244 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2245 ok(lstrcmpiW(folderPath, sExample2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExample2Path));
2246 CoTaskMemFree(folderPath);
2248 /* verify sub folder - it should fail now, as we redirected its parent folder, but we have no sub folder in new location */
2249 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
2250 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "unexpected value from GetPath(): 0x%08x\n", hr);
2251 ok(folderPath==NULL, "invalid known folder path retrieved: \"%s\" when NULL pointer was expected\n", wine_dbgstr_w(folderPath));
2252 CoTaskMemFree(folderPath);
2255 /* set Example path to original. Using SetPath() is valid here, as it also uses redirection internally */
2256 hr = IKnownFolder_SetPath(folder, 0, sExamplePath);
2257 ok(hr == S_OK, "SetPath() failed: 0x%08x\n", hr);
2259 /* verify */
2260 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
2261 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2262 ok(lstrcmpiW(folderPath, sExamplePath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExamplePath));
2263 CoTaskMemFree(folderPath);
2266 /* create sub folder in Temp\Example2 */
2267 bRes = CreateDirectoryW(sSubFolder2Path, NULL);
2268 ok(bRes, "cannot create example directory: %s\n", wine_dbgstr_w(sSubFolder2Path));
2270 /* again perform that same redirection */
2271 hr = IKnownFolderManager_Redirect(mgr, &newFolderId, NULL, 0, sExample2Path, 0, NULL, &errorMsg);
2272 ok(hr == S_OK, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr, wine_dbgstr_w(errorMsg));
2274 /* verify sub folder. It should succeed now, as the required sub folder exists */
2275 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
2276 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2277 ok(lstrcmpiW(folderPath, sSubFolder2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolder2Path));
2278 CoTaskMemFree(folderPath);
2280 /* remove newly created directory */
2281 RemoveDirectoryW(sSubFolder2Path);
2283 /* verify sub folder. It still succeedes, so Windows does not check folder presence each time */
2284 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
2285 todo_wine
2286 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2287 todo_wine
2288 ok(lstrcmpiW(folderPath, sSubFolder2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolder2Path));
2289 CoTaskMemFree(folderPath);
2292 /* set Example path to original */
2293 hr = IKnownFolder_SetPath(folder, 0, sExamplePath);
2294 ok(hr == S_OK, "SetPath() failed: 0x%08x\n", hr);
2296 /* verify */
2297 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
2298 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2299 ok(lstrcmpiW(folderPath, sExamplePath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExamplePath));
2300 CoTaskMemFree(folderPath);
2302 /* verify sub folder */
2303 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
2304 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2305 ok(lstrcmpiW(folderPath, sSubFolderPath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolderPath));
2306 CoTaskMemFree(folderPath);
2309 /* create sub folder in Temp\Example2 */
2310 bRes = CreateDirectoryW(sSubFolder2Path, NULL);
2311 ok(bRes, "cannot create example directory: %s\n", wine_dbgstr_w(sSubFolder2Path));
2313 /* do that same redirection, but try to exclude sub-folder */
2314 hr = IKnownFolderManager_Redirect(mgr, &newFolderId, NULL, 0, sExample2Path, 1, &subFolderId, &errorMsg);
2315 ok(hr == S_OK, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr, wine_dbgstr_w(errorMsg));
2317 /* verify */
2318 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
2319 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2320 ok(lstrcmpiW(folderPath, sExample2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExample2Path));
2321 CoTaskMemFree(folderPath);
2323 /* 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 */
2324 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
2325 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2326 ok(lstrcmpiW(folderPath, sSubFolder2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolder2Path));
2327 CoTaskMemFree(folderPath);
2329 /* remove newly created directory */
2330 RemoveDirectoryW(sSubFolder2Path);
2333 /* set Example path to original */
2334 hr = IKnownFolder_SetPath(folder, 0, sExamplePath);
2335 ok(hr == S_OK, "SetPath() failed: 0x%08x\n", hr);
2337 /* verify */
2338 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
2339 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2340 ok(lstrcmpiW(folderPath, sExamplePath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExamplePath));
2341 CoTaskMemFree(folderPath);
2343 /* verify sub folder */
2344 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
2345 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2346 ok(lstrcmpiW(folderPath, sSubFolderPath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolderPath));
2347 CoTaskMemFree(folderPath);
2350 /* do that same redirection again, but set it to copy content. It should also copy the sub folder, so checking it would succeed now */
2351 hr = IKnownFolderManager_Redirect(mgr, &newFolderId, NULL, KF_REDIRECT_COPY_CONTENTS, sExample2Path, 0, NULL, &errorMsg);
2352 ok(hr == S_OK, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr, wine_dbgstr_w(errorMsg));
2354 /* verify */
2355 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
2356 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2357 ok(lstrcmpiW(folderPath, sExample2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExample2Path));
2358 CoTaskMemFree(folderPath);
2360 /* verify sub folder */
2361 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
2362 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2363 ok(lstrcmpiW(folderPath, sSubFolder2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolder2Path));
2364 CoTaskMemFree(folderPath);
2366 /* remove copied directory */
2367 RemoveDirectoryW(sSubFolder2Path);
2370 /* set Example path to original */
2371 hr = IKnownFolder_SetPath(folder, 0, sExamplePath);
2372 ok(hr == S_OK, "SetPath() failed: 0x%08x\n", hr);
2374 /* verify */
2375 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
2376 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2377 ok(lstrcmpiW(folderPath, sExamplePath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExamplePath));
2378 CoTaskMemFree(folderPath);
2380 /* verify sub folder */
2381 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
2382 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2383 ok(lstrcmpiW(folderPath, sSubFolderPath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolderPath));
2384 CoTaskMemFree(folderPath);
2387 /* redirect again, set it to copy content and remove originals */
2388 hr = IKnownFolderManager_Redirect(mgr, &newFolderId, NULL, KF_REDIRECT_COPY_CONTENTS | KF_REDIRECT_DEL_SOURCE_CONTENTS, sExample2Path, 0, NULL, &errorMsg);
2389 ok(hr == S_OK, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr, wine_dbgstr_w(errorMsg));
2391 /* verify */
2392 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
2393 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2394 ok(lstrcmpiW(folderPath, sExample2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExample2Path));
2395 CoTaskMemFree(folderPath);
2397 /* verify sub folder */
2398 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
2399 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2400 ok(lstrcmpiW(folderPath, sSubFolder2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolder2Path));
2401 CoTaskMemFree(folderPath);
2403 /* check if original directory was really removed */
2404 dwAttributes = GetFileAttributesW(sExamplePath);
2405 ok(dwAttributes==INVALID_FILE_ATTRIBUTES, "directory should not exist, but has attributes: 0x%08x\n", dwAttributes );
2408 /* redirect (with copy) to original path */
2409 hr = IKnownFolderManager_Redirect(mgr, &newFolderId, NULL, KF_REDIRECT_COPY_CONTENTS, sExamplePath, 0, NULL, &errorMsg);
2410 ok(hr == S_OK, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr, wine_dbgstr_w(errorMsg));
2412 /* verify */
2413 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
2414 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2415 ok(lstrcmpiW(folderPath, sExamplePath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExamplePath));
2416 CoTaskMemFree(folderPath);
2418 /* verify sub folder */
2419 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
2420 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2421 ok(lstrcmpiW(folderPath, sSubFolderPath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolderPath));
2422 CoTaskMemFree(folderPath);
2424 /* check shell utility functions */
2425 if(!pSHGetKnownFolderPath || !pSHSetKnownFolderPath)
2426 todo_wine
2427 win_skip("cannot get SHGet/SetKnownFolderPath routines\n");
2428 else
2430 /* try to get current known folder path */
2431 hr = pSHGetKnownFolderPath(&newFolderId, 0, NULL, &folderPath);
2432 todo_wine
2433 ok(hr==S_OK, "cannot get known folder path: hr=0x%0x\n", hr);
2434 todo_wine
2435 ok(lstrcmpW(folderPath, sExamplePath)==0, "invalid path returned: %s\n", wine_dbgstr_w(folderPath));
2437 /* set it to new value */
2438 hr = pSHSetKnownFolderPath(&newFolderId, 0, NULL, sExample2Path);
2439 todo_wine
2440 ok(hr==S_OK, "cannot set known folder path: hr=0x%0x\n", hr);
2442 /* check if it changed */
2443 hr = pSHGetKnownFolderPath(&newFolderId, 0, NULL, &folderPath);
2444 todo_wine
2445 ok(hr==S_OK, "cannot get known folder path: hr=0x%0x\n", hr);
2446 todo_wine
2447 ok(lstrcmpW(folderPath, sExample2Path)==0, "invalid path returned: %s\n", wine_dbgstr_w(folderPath));
2449 /* set it back */
2450 hr = pSHSetKnownFolderPath(&newFolderId, 0, NULL, sExamplePath);
2451 todo_wine
2452 ok(hr==S_OK, "cannot set known folder path: hr=0x%0x\n", hr);
2455 IKnownFolder_Release(subFolder);
2458 hr = IKnownFolderManager_UnregisterFolder(mgr, &subFolderId);
2459 ok(hr == S_OK, "failed to unregister folder: 0x%08x\n", hr);
2462 FreeKnownFolderDefinitionFields(&kfSubDefinition);
2464 hr = IKnownFolder_Release(folder);
2465 ok(hr == S_OK, "failed to release KnownFolder instance: 0x%08x\n", hr);
2468 hr = IKnownFolderManager_UnregisterFolder(mgr, &newFolderId);
2469 ok(hr == S_OK, "failed to unregister folder: 0x%08x\n", hr);
2472 FreeKnownFolderDefinitionFields(&kfDefinition);
2474 RemoveDirectoryW(sSubFolder2Path);
2475 RemoveDirectoryW(sSubFolderPath);
2476 RemoveDirectoryW(sExamplePath);
2477 RemoveDirectoryW(sExample2Path);
2479 hr = IKnownFolderManager_Release(mgr);
2480 ok(hr == S_OK, "failed to release KnownFolderManager instance: 0x%08x\n", hr);
2482 CoUninitialize();
2486 static void test_DoEnvironmentSubst(void)
2488 WCHAR expectedW[MAX_PATH];
2489 WCHAR bufferW[MAX_PATH];
2490 CHAR expectedA[MAX_PATH];
2491 CHAR bufferA[MAX_PATH];
2492 DWORD res;
2493 DWORD res2;
2494 DWORD len;
2495 INT i;
2496 static const WCHAR does_not_existW[] = {'%','D','O','E','S','_','N','O','T','_','E','X','I','S','T','%',0};
2497 static const CHAR does_not_existA[] = "%DOES_NOT_EXIST%";
2498 static const CHAR *names[] = {
2499 /* interactive apps and services (works on all windows versions) */
2500 "%ALLUSERSPROFILE%", "%APPDATA%", "%LOCALAPPDATA%",
2501 "%NUMBER_OF_PROCESSORS%", "%OS%", "%PROCESSOR_ARCHITECTURE%",
2502 "%PROCESSOR_IDENTIFIER%", "%PROCESSOR_LEVEL%", "%PROCESSOR_REVISION%",
2503 "%ProgramFiles%", "%SystemDrive%",
2504 "%SystemRoot%", "%USERPROFILE%", "%windir%",
2505 /* todo_wine: "%COMPUTERNAME%", "%ProgramData%", "%PUBLIC%", */
2507 /* replace more than one var is allowed */
2508 "%HOMEDRIVE%%HOMEPATH%",
2509 "%OS% %windir%"}; /* always the last entry in the table */
2511 for (i = 0; i < (sizeof(names)/sizeof(LPSTR)); i++)
2513 memset(bufferA, '#', MAX_PATH - 1);
2514 bufferA[MAX_PATH - 1] = 0;
2515 lstrcpyA(bufferA, names[i]);
2516 MultiByteToWideChar(CP_ACP, 0, bufferA, MAX_PATH, bufferW, sizeof(bufferW)/sizeof(WCHAR));
2518 res2 = ExpandEnvironmentStringsA(names[i], expectedA, MAX_PATH);
2519 res = DoEnvironmentSubstA(bufferA, MAX_PATH);
2521 /* is the space for the terminating 0 included? */
2522 if (!i && HIWORD(res) && (LOWORD(res) == (lstrlenA(bufferA))))
2524 win_skip("DoEnvironmentSubstA/W are broken on NT 4\n");
2525 return;
2527 ok(HIWORD(res) && (LOWORD(res) == res2),
2528 "%d: got %d/%d (expected TRUE/%d)\n", i, HIWORD(res), LOWORD(res), res2);
2529 ok(!lstrcmpA(bufferA, expectedA),
2530 "%d: got %s (expected %s)\n", i, bufferA, expectedA);
2532 res2 = ExpandEnvironmentStringsW(bufferW, expectedW, MAX_PATH);
2533 res = DoEnvironmentSubstW(bufferW, MAX_PATH);
2534 ok(HIWORD(res) && (LOWORD(res) == res2),
2535 "%d: got %d/%d (expected TRUE/%d)\n", i, HIWORD(res), LOWORD(res), res2);
2536 ok(!lstrcmpW(bufferW, expectedW),
2537 "%d: got %s (expected %s)\n", i, wine_dbgstr_w(bufferW), wine_dbgstr_w(expectedW));
2540 i--; /* reuse data in the last table entry */
2541 len = LOWORD(res); /* needed length */
2543 /* one character extra is fine */
2544 memset(bufferA, '#', MAX_PATH - 1);
2545 bufferA[len + 2] = 0;
2546 lstrcpyA(bufferA, names[i]);
2547 MultiByteToWideChar(CP_ACP, 0, bufferA, MAX_PATH, bufferW, sizeof(bufferW)/sizeof(WCHAR));
2549 res2 = ExpandEnvironmentStringsA(bufferA, expectedA, MAX_PATH);
2550 res = DoEnvironmentSubstA(bufferA, len + 1);
2551 ok(HIWORD(res) && (LOWORD(res) == res2),
2552 "+1: got %d/%d (expected TRUE/%d)\n", HIWORD(res), LOWORD(res), res2);
2553 ok(!lstrcmpA(bufferA, expectedA),
2554 "+1: got %s (expected %s)\n", bufferA, expectedA);
2556 res2 = ExpandEnvironmentStringsW(bufferW, expectedW, MAX_PATH);
2557 res = DoEnvironmentSubstW(bufferW, len + 1);
2558 ok(HIWORD(res) && (LOWORD(res) == res2),
2559 "+1: got %d/%d (expected TRUE/%d)\n", HIWORD(res), LOWORD(res), res2);
2560 ok(!lstrcmpW(bufferW, expectedW),
2561 "+1: got %s (expected %s)\n", wine_dbgstr_w(bufferW), wine_dbgstr_w(expectedW));
2564 /* minimal buffer length (result string and terminating 0) */
2565 memset(bufferA, '#', MAX_PATH - 1);
2566 bufferA[len + 2] = 0;
2567 lstrcpyA(bufferA, names[i]);
2568 MultiByteToWideChar(CP_ACP, 0, bufferA, MAX_PATH, bufferW, sizeof(bufferW)/sizeof(WCHAR));
2570 /* ANSI version failed without an extra byte, as documented on msdn */
2571 res = DoEnvironmentSubstA(bufferA, len);
2572 ok(!HIWORD(res) && (LOWORD(res) == len),
2573 " 0: got %d/%d (expected FALSE/%d)\n", HIWORD(res), LOWORD(res), len);
2574 ok(!lstrcmpA(bufferA, names[i]),
2575 " 0: got %s (expected %s)\n", bufferA, names[i]);
2577 /* DoEnvironmentSubstW works as expected */
2578 res2 = ExpandEnvironmentStringsW(bufferW, expectedW, MAX_PATH);
2579 res = DoEnvironmentSubstW(bufferW, len);
2580 ok(HIWORD(res) && (LOWORD(res) == res2),
2581 " 0: got %d/%d (expected TRUE/%d)\n", HIWORD(res), LOWORD(res), res2);
2582 ok(!lstrcmpW(bufferW, expectedW),
2583 " 0: got %s (expected %s)\n", wine_dbgstr_w(bufferW), wine_dbgstr_w(expectedW));
2586 /* Buffer too small */
2587 /* result: FALSE / provided buffer length / the buffer is untouched */
2588 memset(bufferA, '#', MAX_PATH - 1);
2589 bufferA[len + 2] = 0;
2590 lstrcpyA(bufferA, names[i]);
2591 MultiByteToWideChar(CP_ACP, 0, bufferA, MAX_PATH, bufferW, sizeof(bufferW)/sizeof(WCHAR));
2593 res = DoEnvironmentSubstA(bufferA, len - 1);
2594 ok(!HIWORD(res) && (LOWORD(res) == (len - 1)),
2595 "-1: got %d/%d (expected FALSE/%d)\n", HIWORD(res), LOWORD(res), len - 1);
2596 ok(!lstrcmpA(bufferA, names[i]),
2597 "-1: got %s (expected %s)\n", bufferA, names[i]);
2599 lstrcpyW(expectedW, bufferW);
2600 res = DoEnvironmentSubstW(bufferW, len - 1);
2601 ok(!HIWORD(res) && (LOWORD(res) == (len - 1)),
2602 "-1: got %d/%d (expected FALSE/%d)\n", HIWORD(res), LOWORD(res), len - 1);
2603 ok(!lstrcmpW(bufferW, expectedW),
2604 "-1: got %s (expected %s)\n", wine_dbgstr_w(bufferW), wine_dbgstr_w(expectedW));
2607 /* unknown variable */
2608 /* result: TRUE / string length including terminating 0 / the buffer is untouched */
2609 memset(bufferA, '#', MAX_PATH - 1);
2610 bufferA[MAX_PATH - 1] = 0;
2611 lstrcpyA(bufferA, does_not_existA);
2612 MultiByteToWideChar(CP_ACP, 0, bufferA, MAX_PATH, bufferW, sizeof(bufferW)/sizeof(WCHAR));
2614 res2 = lstrlenA(does_not_existA) + 1;
2615 res = DoEnvironmentSubstA(bufferA, MAX_PATH);
2616 ok(HIWORD(res) && (LOWORD(res) == res2),
2617 "%d: got %d/%d (expected TRUE/%d)\n", i, HIWORD(res), LOWORD(res), res2);
2618 ok(!lstrcmpA(bufferA, does_not_existA),
2619 "%d: got %s (expected %s)\n", i, bufferA, does_not_existA);
2621 res = DoEnvironmentSubstW(bufferW, MAX_PATH);
2622 ok(HIWORD(res) && (LOWORD(res) == res2),
2623 "%d: got %d/%d (expected TRUE/%d)\n", i, HIWORD(res), LOWORD(res), res2);
2624 ok(!lstrcmpW(bufferW, does_not_existW),
2625 "%d: got %s (expected %s)\n", i, wine_dbgstr_w(bufferW), wine_dbgstr_w(does_not_existW));
2628 if (0)
2630 /* NULL crashes on windows */
2631 res = DoEnvironmentSubstA(NULL, MAX_PATH);
2632 res = DoEnvironmentSubstW(NULL, MAX_PATH);
2636 static void test_PathYetAnotherMakeUniqueName(void)
2638 static const WCHAR shortW[] = {'f','i','l','e','.','t','s','t',0};
2639 static const WCHAR short2W[] = {'f','i','l','e',' ','(','2',')','.','t','s','t',0};
2640 static const WCHAR tmpW[] = {'t','m','p',0};
2641 static const WCHAR longW[] = {'n','a','m','e',0};
2642 static const WCHAR long2W[] = {'n','a','m','e',' ','(','2',')',0};
2643 WCHAR nameW[MAX_PATH], buffW[MAX_PATH], pathW[MAX_PATH];
2644 HANDLE file;
2645 BOOL ret;
2647 if (!pPathYetAnotherMakeUniqueName)
2649 win_skip("PathYetAnotherMakeUniqueName() is not available.\n");
2650 return;
2653 if (0)
2655 /* crashes on Windows */
2656 ret = pPathYetAnotherMakeUniqueName(NULL, NULL, NULL, NULL);
2657 ok(!ret, "got %d\n", ret);
2659 ret = pPathYetAnotherMakeUniqueName(nameW, NULL, NULL, NULL);
2660 ok(!ret, "got %d\n", ret);
2663 GetTempPathW(sizeof(pathW)/sizeof(WCHAR), pathW);
2665 /* Using short name only first */
2666 nameW[0] = 0;
2667 ret = pPathYetAnotherMakeUniqueName(nameW, pathW, shortW, NULL);
2668 ok(ret, "got %d\n", ret);
2669 lstrcpyW(buffW, pathW);
2670 lstrcatW(buffW, shortW);
2671 ok(!lstrcmpW(nameW, buffW), "got %s, expected %s\n", wine_dbgstr_w(nameW), wine_dbgstr_w(buffW));
2673 /* now create a file with this name and get next name */
2674 file = CreateFileW(nameW, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, NULL);
2675 ok(file != NULL, "got %p\n", file);
2677 nameW[0] = 0;
2678 ret = pPathYetAnotherMakeUniqueName(nameW, pathW, shortW, NULL);
2679 ok(ret, "got %d\n", ret);
2680 lstrcpyW(buffW, pathW);
2681 lstrcatW(buffW, short2W);
2682 ok(!lstrcmpW(nameW, buffW), "got %s, expected %s\n", wine_dbgstr_w(nameW), wine_dbgstr_w(buffW));
2684 CloseHandle(file);
2686 /* Using short and long */
2687 nameW[0] = 0;
2688 ret = pPathYetAnotherMakeUniqueName(nameW, pathW, tmpW, longW);
2689 ok(ret, "got %d\n", ret);
2690 lstrcpyW(buffW, pathW);
2691 lstrcatW(buffW, longW);
2692 ok(!lstrcmpW(nameW, buffW), "got %s, expected %s\n", wine_dbgstr_w(nameW), wine_dbgstr_w(buffW));
2694 file = CreateFileW(nameW, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, NULL);
2695 ok(file != NULL, "got %p\n", file);
2697 nameW[0] = 0;
2698 ret = pPathYetAnotherMakeUniqueName(nameW, pathW, tmpW, longW);
2699 ok(ret, "got %d\n", ret);
2700 lstrcpyW(buffW, pathW);
2701 lstrcatW(buffW, long2W);
2702 ok(!lstrcmpW(nameW, buffW), "got %s, expected %s\n", wine_dbgstr_w(nameW), wine_dbgstr_w(buffW));
2704 CloseHandle(file);
2706 /* Using long only */
2707 nameW[0] = 0;
2708 ret = pPathYetAnotherMakeUniqueName(nameW, pathW, NULL, longW);
2709 ok(ret, "got %d\n", ret);
2710 lstrcpyW(buffW, pathW);
2711 lstrcatW(buffW, longW);
2712 ok(!lstrcmpW(nameW, buffW), "got %s, expected %s\n", wine_dbgstr_w(nameW), wine_dbgstr_w(buffW));
2715 START_TEST(shellpath)
2717 if (!init()) return;
2719 loadShell32();
2720 pGetSystemWow64DirectoryA = (void *)GetProcAddress( GetModuleHandleA("kernel32.dll"),
2721 "GetSystemWow64DirectoryA" );
2722 if (myARGC >= 3)
2723 doChild(myARGV[2]);
2724 else
2726 /* Report missing functions once */
2727 if (!pSHGetFolderLocation)
2728 win_skip("SHGetFolderLocation is not available\n");
2730 /* first test various combinations of parameters: */
2731 test_parameters();
2733 /* check known values: */
2734 test_PidlTypes();
2735 test_GUIDs();
2736 test_EnvVars();
2737 testWinDir();
2738 testSystemDir();
2739 test_NonExistentPath();
2740 test_SHGetFolderPathEx();
2741 test_knownFolders();
2742 test_DoEnvironmentSubst();
2743 test_PathYetAnotherMakeUniqueName();