mfplat/tests: Add a separate test function for MFGetPlaneSize().
[wine.git] / dlls / shell32 / tests / shellpath.c
blob7d0f725158a824837384fb33985af31f0ea52eef
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 /* from pidl.h, not included here: */
47 #ifndef PT_CPL /* Guess, Win7 uses this for CSIDL_CONTROLS */
48 #define PT_CPL 0x01 /* no path */
49 #endif
50 #ifndef PT_GUID
51 #define PT_GUID 0x1f /* no path */
52 #endif
53 #ifndef PT_DRIVE
54 #define PT_DRIVE 0x23 /* has path */
55 #endif
56 #ifndef PT_DRIVE2
57 #define PT_DRIVE2 0x25 /* has path */
58 #endif
59 #ifndef PT_SHELLEXT
60 #define PT_SHELLEXT 0x2e /* no path */
61 #endif
62 #ifndef PT_FOLDER
63 #define PT_FOLDER 0x31 /* has path */
64 #endif
65 #ifndef PT_FOLDERW
66 #define PT_FOLDERW 0x35 /* has path */
67 #endif
68 #ifndef PT_WORKGRP
69 #define PT_WORKGRP 0x41 /* no path */
70 #endif
71 #ifndef PT_YAGUID
72 #define PT_YAGUID 0x70 /* no path */
73 #endif
74 /* FIXME: this is used for history/favorites folders; what's a better name? */
75 #ifndef PT_IESPECIAL2
76 #define PT_IESPECIAL2 0xb1 /* has path */
77 #endif
79 static GUID CLSID_CommonDocuments = { 0x0000000c, 0x0000, 0x0000, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x1a } };
81 struct shellExpectedValues {
82 int folder;
83 int numTypes;
84 const BYTE *types;
87 static HRESULT (WINAPI *pDllGetVersion)(DLLVERSIONINFO *);
88 static HRESULT (WINAPI *pSHGetFolderPathA)(HWND, int, HANDLE, DWORD, LPSTR);
89 static BOOL (WINAPI *pSHGetSpecialFolderPathA)(HWND, LPSTR, int, BOOL);
90 static HRESULT (WINAPI *pSHGetSpecialFolderLocation)(HWND, int, LPITEMIDLIST *);
91 static LPITEMIDLIST (WINAPI *pILFindLastID)(LPCITEMIDLIST);
92 static int (WINAPI *pSHFileOperationA)(LPSHFILEOPSTRUCTA);
93 static UINT (WINAPI *pGetSystemWow64DirectoryA)(LPSTR,UINT);
94 static HRESULT (WINAPI *pSHGetKnownFolderPath)(REFKNOWNFOLDERID, DWORD, HANDLE, PWSTR *);
95 static HRESULT (WINAPI *pSHSetKnownFolderPath)(REFKNOWNFOLDERID, DWORD, HANDLE, PWSTR);
96 static HRESULT (WINAPI *pSHGetFolderPathEx)(REFKNOWNFOLDERID, DWORD, HANDLE, LPWSTR, DWORD);
97 static BOOL (WINAPI *pPathYetAnotherMakeUniqueName)(PWSTR, PCWSTR, PCWSTR, PCWSTR);
98 static HRESULT (WINAPI *pSHGetKnownFolderIDList)(REFKNOWNFOLDERID, DWORD, HANDLE, PIDLIST_ABSOLUTE*);
99 static BOOL (WINAPI *pPathResolve)(PWSTR, PZPCWSTR, UINT);
101 static DLLVERSIONINFO shellVersion = { 0 };
102 static const BYTE guidType[] = { PT_GUID };
103 static const BYTE controlPanelType[] = { PT_SHELLEXT, PT_GUID, PT_CPL };
104 static const BYTE folderType[] = { PT_FOLDER, PT_FOLDERW };
105 static const BYTE favoritesType[] = { PT_FOLDER, PT_FOLDERW, 0, PT_IESPECIAL2 /* Win98 */ };
106 static const BYTE folderOrSpecialType[] = { PT_FOLDER, PT_IESPECIAL2 };
107 static const BYTE personalType[] = { PT_FOLDER, PT_GUID, PT_DRIVE, 0xff /* Win9x */,
108 PT_IESPECIAL2 /* Win98 */, 0 /* Vista */, PT_SHELLEXT /* win8 */ };
109 /* FIXME: don't know the type of 0x71 returned by Vista/2008 for printers */
110 static const BYTE printersType[] = { PT_YAGUID, PT_SHELLEXT, 0x71 };
111 static const BYTE ieSpecialType[] = { PT_IESPECIAL2 };
112 static const BYTE shellExtType[] = { PT_SHELLEXT };
113 static const BYTE workgroupType[] = { PT_WORKGRP };
114 static const BYTE missingType[] = { 0xff };
115 #define DECLARE_TYPE(x, y) { x, ARRAY_SIZE(y), y }
116 static const struct shellExpectedValues requiredShellValues[] = {
117 DECLARE_TYPE(CSIDL_BITBUCKET, guidType),
118 DECLARE_TYPE(CSIDL_CONTROLS, controlPanelType),
119 DECLARE_TYPE(CSIDL_COOKIES, folderType),
120 DECLARE_TYPE(CSIDL_DESKTOPDIRECTORY, folderType),
121 DECLARE_TYPE(CSIDL_DRIVES, guidType),
122 DECLARE_TYPE(CSIDL_FAVORITES, favoritesType),
123 DECLARE_TYPE(CSIDL_FONTS, folderOrSpecialType),
124 /* FIXME: the following fails in Wine, returns type PT_FOLDER
125 DECLARE_TYPE(CSIDL_HISTORY, ieSpecialType),
127 DECLARE_TYPE(CSIDL_INTERNET, guidType),
128 DECLARE_TYPE(CSIDL_NETHOOD, folderType),
129 DECLARE_TYPE(CSIDL_NETWORK, guidType),
130 DECLARE_TYPE(CSIDL_PERSONAL, personalType),
131 DECLARE_TYPE(CSIDL_PRINTERS, printersType),
132 DECLARE_TYPE(CSIDL_PRINTHOOD, folderType),
133 DECLARE_TYPE(CSIDL_PROGRAMS, folderType),
134 DECLARE_TYPE(CSIDL_RECENT, folderOrSpecialType),
135 DECLARE_TYPE(CSIDL_SENDTO, folderType),
136 DECLARE_TYPE(CSIDL_STARTMENU, folderType),
137 DECLARE_TYPE(CSIDL_STARTUP, folderType),
138 DECLARE_TYPE(CSIDL_TEMPLATES, folderType),
140 static const struct shellExpectedValues optionalShellValues[] = {
141 /* FIXME: the following only semi-succeed; they return NULL PIDLs on XP.. hmm.
142 DECLARE_TYPE(CSIDL_ALTSTARTUP, folderType),
143 DECLARE_TYPE(CSIDL_COMMON_ALTSTARTUP, folderType),
144 DECLARE_TYPE(CSIDL_COMMON_OEM_LINKS, folderType),
146 /* Windows NT-only: */
147 DECLARE_TYPE(CSIDL_COMMON_DESKTOPDIRECTORY, folderType),
148 DECLARE_TYPE(CSIDL_COMMON_DOCUMENTS, shellExtType),
149 DECLARE_TYPE(CSIDL_COMMON_FAVORITES, folderType),
150 DECLARE_TYPE(CSIDL_COMMON_PROGRAMS, folderType),
151 DECLARE_TYPE(CSIDL_COMMON_STARTMENU, folderType),
152 DECLARE_TYPE(CSIDL_COMMON_STARTUP, folderType),
153 DECLARE_TYPE(CSIDL_COMMON_TEMPLATES, folderType),
154 /* first appearing in shell32 version 4.71: */
155 DECLARE_TYPE(CSIDL_APPDATA, folderType),
156 /* first appearing in shell32 version 4.72: */
157 DECLARE_TYPE(CSIDL_INTERNET_CACHE, ieSpecialType),
158 /* first appearing in shell32 version 5.0: */
159 DECLARE_TYPE(CSIDL_ADMINTOOLS, folderType),
160 DECLARE_TYPE(CSIDL_COMMON_APPDATA, folderType),
161 DECLARE_TYPE(CSIDL_LOCAL_APPDATA, folderType),
162 DECLARE_TYPE(OLD_CSIDL_MYDOCUMENTS, folderType),
163 DECLARE_TYPE(CSIDL_MYMUSIC, folderType),
164 DECLARE_TYPE(CSIDL_MYPICTURES, folderType),
165 DECLARE_TYPE(CSIDL_MYVIDEO, folderType),
166 DECLARE_TYPE(CSIDL_PROFILE, folderType),
167 DECLARE_TYPE(CSIDL_PROGRAM_FILES, folderType),
168 DECLARE_TYPE(CSIDL_PROGRAM_FILESX86, folderType),
169 DECLARE_TYPE(CSIDL_PROGRAM_FILES_COMMON, folderType),
170 DECLARE_TYPE(CSIDL_PROGRAM_FILES_COMMONX86, folderType),
171 DECLARE_TYPE(CSIDL_SYSTEM, folderType),
172 DECLARE_TYPE(CSIDL_WINDOWS, folderType),
173 /* first appearing in shell32 6.0: */
174 DECLARE_TYPE(CSIDL_CDBURN_AREA, folderType),
175 DECLARE_TYPE(CSIDL_COMMON_MUSIC, folderType),
176 DECLARE_TYPE(CSIDL_COMMON_PICTURES, folderType),
177 DECLARE_TYPE(CSIDL_COMMON_VIDEO, folderType),
178 DECLARE_TYPE(CSIDL_COMPUTERSNEARME, workgroupType),
179 DECLARE_TYPE(CSIDL_RESOURCES, folderType),
180 DECLARE_TYPE(CSIDL_RESOURCES_LOCALIZED, folderType),
182 static const struct shellExpectedValues undefinedShellValues[] = {
183 DECLARE_TYPE(0x0f, missingType),
184 DECLARE_TYPE(0x32, missingType),
185 DECLARE_TYPE(0x33, missingType),
186 DECLARE_TYPE(0x34, missingType),
187 DECLARE_TYPE(0x3c, missingType),
188 DECLARE_TYPE(0x45, missingType),
190 #undef DECLARE_TYPE
192 static void loadShell32(void)
194 HMODULE hShell32 = GetModuleHandleA("shell32");
196 #define GET_PROC(func) \
197 p ## func = (void*)GetProcAddress(hShell32, #func); \
198 if(!p ## func) \
199 trace("GetProcAddress(%s) failed\n", #func);
201 GET_PROC(DllGetVersion)
202 GET_PROC(SHGetFolderPathA)
203 GET_PROC(SHGetFolderPathEx)
204 GET_PROC(SHGetKnownFolderPath)
205 GET_PROC(SHSetKnownFolderPath)
206 GET_PROC(SHGetSpecialFolderPathA)
207 GET_PROC(SHGetSpecialFolderLocation)
208 GET_PROC(ILFindLastID)
209 if (!pILFindLastID)
210 pILFindLastID = (void *)GetProcAddress(hShell32, (LPCSTR)16);
211 GET_PROC(SHFileOperationA)
212 GET_PROC(PathYetAnotherMakeUniqueName)
213 GET_PROC(SHGetKnownFolderIDList)
214 GET_PROC(PathResolve);
216 if (pDllGetVersion)
218 shellVersion.cbSize = sizeof(shellVersion);
219 pDllGetVersion(&shellVersion);
220 trace("shell32 version is %d.%d\n",
221 shellVersion.dwMajorVersion, shellVersion.dwMinorVersion);
223 #undef GET_PROC
226 #ifndef CSIDL_PROFILES
227 #define CSIDL_PROFILES 0x003e
228 #endif
230 /* A couple utility printing functions */
231 static const char *getFolderName(int folder)
233 static char unknown[32];
235 #define CSIDL_TO_STR(x) case x: return#x;
236 switch (folder)
238 CSIDL_TO_STR(CSIDL_DESKTOP);
239 CSIDL_TO_STR(CSIDL_INTERNET);
240 CSIDL_TO_STR(CSIDL_PROGRAMS);
241 CSIDL_TO_STR(CSIDL_CONTROLS);
242 CSIDL_TO_STR(CSIDL_PRINTERS);
243 CSIDL_TO_STR(CSIDL_PERSONAL);
244 CSIDL_TO_STR(CSIDL_FAVORITES);
245 CSIDL_TO_STR(CSIDL_STARTUP);
246 CSIDL_TO_STR(CSIDL_RECENT);
247 CSIDL_TO_STR(CSIDL_SENDTO);
248 CSIDL_TO_STR(CSIDL_BITBUCKET);
249 CSIDL_TO_STR(CSIDL_STARTMENU);
250 CSIDL_TO_STR(OLD_CSIDL_MYDOCUMENTS);
251 CSIDL_TO_STR(CSIDL_MYMUSIC);
252 CSIDL_TO_STR(CSIDL_MYVIDEO);
253 CSIDL_TO_STR(CSIDL_DESKTOPDIRECTORY);
254 CSIDL_TO_STR(CSIDL_DRIVES);
255 CSIDL_TO_STR(CSIDL_NETWORK);
256 CSIDL_TO_STR(CSIDL_NETHOOD);
257 CSIDL_TO_STR(CSIDL_FONTS);
258 CSIDL_TO_STR(CSIDL_TEMPLATES);
259 CSIDL_TO_STR(CSIDL_COMMON_STARTMENU);
260 CSIDL_TO_STR(CSIDL_COMMON_PROGRAMS);
261 CSIDL_TO_STR(CSIDL_COMMON_STARTUP);
262 CSIDL_TO_STR(CSIDL_COMMON_DESKTOPDIRECTORY);
263 CSIDL_TO_STR(CSIDL_APPDATA);
264 CSIDL_TO_STR(CSIDL_PRINTHOOD);
265 CSIDL_TO_STR(CSIDL_LOCAL_APPDATA);
266 CSIDL_TO_STR(CSIDL_ALTSTARTUP);
267 CSIDL_TO_STR(CSIDL_COMMON_ALTSTARTUP);
268 CSIDL_TO_STR(CSIDL_COMMON_FAVORITES);
269 CSIDL_TO_STR(CSIDL_INTERNET_CACHE);
270 CSIDL_TO_STR(CSIDL_COOKIES);
271 CSIDL_TO_STR(CSIDL_HISTORY);
272 CSIDL_TO_STR(CSIDL_COMMON_APPDATA);
273 CSIDL_TO_STR(CSIDL_WINDOWS);
274 CSIDL_TO_STR(CSIDL_SYSTEM);
275 CSIDL_TO_STR(CSIDL_PROGRAM_FILES);
276 CSIDL_TO_STR(CSIDL_MYPICTURES);
277 CSIDL_TO_STR(CSIDL_PROFILE);
278 CSIDL_TO_STR(CSIDL_SYSTEMX86);
279 CSIDL_TO_STR(CSIDL_PROGRAM_FILESX86);
280 CSIDL_TO_STR(CSIDL_PROGRAM_FILES_COMMON);
281 CSIDL_TO_STR(CSIDL_PROGRAM_FILES_COMMONX86);
282 CSIDL_TO_STR(CSIDL_COMMON_TEMPLATES);
283 CSIDL_TO_STR(CSIDL_COMMON_DOCUMENTS);
284 CSIDL_TO_STR(CSIDL_COMMON_ADMINTOOLS);
285 CSIDL_TO_STR(CSIDL_ADMINTOOLS);
286 CSIDL_TO_STR(CSIDL_CONNECTIONS);
287 CSIDL_TO_STR(CSIDL_PROFILES);
288 CSIDL_TO_STR(CSIDL_COMMON_MUSIC);
289 CSIDL_TO_STR(CSIDL_COMMON_PICTURES);
290 CSIDL_TO_STR(CSIDL_COMMON_VIDEO);
291 CSIDL_TO_STR(CSIDL_RESOURCES);
292 CSIDL_TO_STR(CSIDL_RESOURCES_LOCALIZED);
293 CSIDL_TO_STR(CSIDL_COMMON_OEM_LINKS);
294 CSIDL_TO_STR(CSIDL_CDBURN_AREA);
295 CSIDL_TO_STR(CSIDL_COMPUTERSNEARME);
296 #undef CSIDL_TO_STR
297 default:
298 sprintf(unknown, "unknown (0x%04x)", folder);
299 return unknown;
303 static LPWSTR wcscasestr( LPCWSTR str, LPCWSTR sub )
305 while (*str)
307 const WCHAR *p1 = str, *p2 = sub;
308 while (*p1 && *p2 && towlower(*p1) == towlower(*p2)) { p1++; p2++; }
309 if (!*p2) return (WCHAR *)str;
310 str++;
312 return NULL;
315 /* Standard CSIDL values (and their flags) uses only two less-significant bytes */
316 #define NO_CSIDL 0x10000
317 #define WINE_ATTRIBUTES_OPTIONAL 0x20000
318 #define KNOWN_FOLDER(id, csidl, name, category, parent1, parent2, relative_path, parsing_name, attributes, definitionFlags) \
319 { &id, # id, csidl, # csidl, name, category, {&parent1, &parent2}, relative_path, parsing_name, attributes, definitionFlags, __LINE__ }
321 /* non-published known folders test */
322 static const GUID _FOLDERID_CryptoKeys = {0xB88F4DAA, 0xE7BD, 0x49A9, {0xB7, 0x4D, 0x02, 0x88, 0x5A, 0x5D, 0xC7, 0x65} };
323 static const GUID _FOLDERID_DpapiKeys = {0x10C07CD0, 0xEF91, 0x4567, {0xB8, 0x50, 0x44, 0x8B, 0x77, 0xCB, 0x37, 0xF9} };
324 static const GUID _FOLDERID_SystemCertificates = {0x54EED2E0, 0xE7CA, 0x4FDB, {0x91, 0x48, 0x0F, 0x42, 0x47, 0x29, 0x1C, 0xFA} };
325 static const GUID _FOLDERID_CredentialManager = {0x915221FB, 0x9EFE, 0x4BDA, {0x8F, 0xD7, 0xF7, 0x8D, 0xCA, 0x77, 0x4F, 0x87} };
327 struct knownFolderDef {
328 const KNOWNFOLDERID *folderId;
329 const char *sFolderId;
330 const int csidl;
331 const char *sCsidl;
332 const char *sName;
333 const KF_CATEGORY category;
334 const KNOWNFOLDERID *fidParents[2];
335 const char *sRelativePath;
336 const char *sParsingName;
337 const DWORD attributes;
338 const KF_DEFINITION_FLAGS definitionFlags;
339 const int line;
342 /* Note: content of parsing name may vary between Windows versions.
343 * As a base, values from 6.0 (Vista) were used. Some entries may contain
344 * alternative values. In that case, Windows version where the value was
345 * found is noted.
347 * The list of values for parsing name was encoded as a number of null-
348 * terminated strings placed one by one (separated by null byte only).
349 * End of list is marked by two consecutive null bytes.
351 static const struct knownFolderDef known_folders[] = {
352 KNOWN_FOLDER(FOLDERID_AddNewPrograms,
353 NO_CSIDL,
354 "AddNewProgramsFolder",
355 KF_CATEGORY_VIRTUAL,
356 GUID_NULL, GUID_NULL,
357 NULL,
358 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{15eae92e-f17a-4431-9f28-805e482dafd4}\0"
359 "shell:::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{15eae92e-f17a-4431-9f28-805e482dafd4}\0\0" /* 6.1 */,
362 KNOWN_FOLDER(FOLDERID_AdminTools,
363 CSIDL_ADMINTOOLS,
364 "Administrative Tools",
365 KF_CATEGORY_PERUSER,
366 FOLDERID_Programs, GUID_NULL,
367 "Administrative Tools",
368 NULL,
369 FILE_ATTRIBUTE_READONLY,
370 KFDF_PRECREATE),
371 KNOWN_FOLDER(FOLDERID_AppUpdates,
372 NO_CSIDL,
373 "AppUpdatesFolder",
374 KF_CATEGORY_VIRTUAL,
375 GUID_NULL, GUID_NULL,
376 NULL,
377 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{7b81be6a-ce2b-4676-a29e-eb907a5126c5}\\::{d450a8a1-9568-45c7-9c0e-b4f9fb4537bd}\0"
378 "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{7b81be6a-ce2b-4676-a29e-eb907a5126c5}\\::{d450a8a1-9568-45c7-9c0e-b4f9fb4537bd}\0\0" /* 6.1 */,
381 KNOWN_FOLDER(FOLDERID_CDBurning,
382 CSIDL_CDBURN_AREA,
383 "CD Burning",
384 KF_CATEGORY_PERUSER,
385 FOLDERID_LocalAppData, GUID_NULL,
386 "Microsoft\\Windows\\Burn\\Burn",
387 NULL,
388 FILE_ATTRIBUTE_READONLY,
389 KFDF_LOCAL_REDIRECT_ONLY),
390 KNOWN_FOLDER(FOLDERID_ChangeRemovePrograms,
391 NO_CSIDL,
392 "ChangeRemoveProgramsFolder",
393 KF_CATEGORY_VIRTUAL,
394 GUID_NULL, GUID_NULL,
395 NULL,
396 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{7b81be6a-ce2b-4676-a29e-eb907a5126c5}\0"
397 "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{7b81be6a-ce2b-4676-a29e-eb907a5126c5}\0\0" /* 6.1 */,
400 KNOWN_FOLDER(FOLDERID_CommonAdminTools,
401 CSIDL_COMMON_ADMINTOOLS,
402 "Common Administrative Tools",
403 KF_CATEGORY_COMMON,
404 FOLDERID_CommonPrograms, GUID_NULL,
405 "Administrative Tools",
406 NULL,
407 FILE_ATTRIBUTE_READONLY,
408 KFDF_PRECREATE),
409 KNOWN_FOLDER(FOLDERID_CommonOEMLinks,
410 CSIDL_COMMON_OEM_LINKS,
411 "OEM Links",
412 KF_CATEGORY_COMMON,
413 FOLDERID_ProgramData, GUID_NULL,
414 "OEM Links",
415 NULL,
418 KNOWN_FOLDER(FOLDERID_CommonPrograms,
419 CSIDL_COMMON_PROGRAMS,
420 "Common Programs",
421 KF_CATEGORY_COMMON,
422 FOLDERID_CommonStartMenu, GUID_NULL,
423 "Programs",
424 NULL,
425 FILE_ATTRIBUTE_READONLY,
426 KFDF_PRECREATE),
427 KNOWN_FOLDER(FOLDERID_CommonStartMenu,
428 CSIDL_COMMON_STARTMENU,
429 "Common Start Menu",
430 KF_CATEGORY_COMMON,
431 FOLDERID_ProgramData, GUID_NULL,
432 "Microsoft\\Windows\\Start Menu\0",
433 NULL,
434 FILE_ATTRIBUTE_READONLY,
435 KFDF_PRECREATE),
436 KNOWN_FOLDER(FOLDERID_CommonStartup,
437 CSIDL_COMMON_STARTUP,
438 "Common Startup",
439 KF_CATEGORY_COMMON,
440 FOLDERID_CommonPrograms, GUID_NULL,
441 "StartUp",
442 NULL,
443 FILE_ATTRIBUTE_READONLY,
444 KFDF_PRECREATE),
445 KNOWN_FOLDER(FOLDERID_CommonTemplates,
446 CSIDL_COMMON_TEMPLATES,
447 "Common Templates",
448 KF_CATEGORY_COMMON,
449 FOLDERID_ProgramData, GUID_NULL,
450 "Microsoft\\Windows\\Templates\0",
451 NULL,
454 KNOWN_FOLDER(FOLDERID_ComputerFolder,
455 CSIDL_DRIVES,
456 "MyComputerFolder",
457 KF_CATEGORY_VIRTUAL,
458 GUID_NULL, GUID_NULL,
459 NULL,
460 "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\0\0",
463 KNOWN_FOLDER(FOLDERID_ConflictFolder,
464 NO_CSIDL,
465 "ConflictFolder",
466 KF_CATEGORY_VIRTUAL,
467 GUID_NULL, GUID_NULL,
468 NULL,
469 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\\::{E413D040-6788-4C22-957E-175D1C513A34},\0"
470 "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\\::{E413D040-6788-4C22-957E-175D1C513A34},\0\0" /* 6.1 */,
473 KNOWN_FOLDER(FOLDERID_ConnectionsFolder,
474 CSIDL_CONNECTIONS,
475 "ConnectionsFolder",
476 KF_CATEGORY_VIRTUAL,
477 GUID_NULL, GUID_NULL,
478 NULL,
479 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{7007ACC7-3202-11D1-AAD2-00805FC1270E}\0"
480 "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{7007ACC7-3202-11D1-AAD2-00805FC1270E}\0\0" /* 6.1 */,
483 KNOWN_FOLDER(FOLDERID_Contacts,
484 NO_CSIDL,
485 "Contacts",
486 KF_CATEGORY_PERUSER,
487 FOLDERID_Profile, GUID_NULL,
488 "Contacts",
489 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{56784854-C6CB-462B-8169-88E350ACB882}\0\0",
490 FILE_ATTRIBUTE_READONLY,
491 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH),
492 KNOWN_FOLDER(FOLDERID_ControlPanelFolder,
493 CSIDL_CONTROLS,
494 "ControlPanelFolder",
495 KF_CATEGORY_VIRTUAL,
496 GUID_NULL, GUID_NULL,
497 NULL,
498 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\0"
499 "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\0\0" /* 6.1 */,
502 KNOWN_FOLDER(FOLDERID_Cookies,
503 CSIDL_COOKIES,
504 "Cookies",
505 KF_CATEGORY_PERUSER,
506 FOLDERID_RoamingAppData, FOLDERID_LocalAppData,
507 "Microsoft\\Windows\\Cookies\0Microsoft\\Windows\\INetCookies\0" /* win8 */,
508 NULL,
511 KNOWN_FOLDER(FOLDERID_Desktop,
512 CSIDL_DESKTOP,
513 "Desktop",
514 KF_CATEGORY_PERUSER,
515 FOLDERID_Profile, GUID_NULL,
516 "Desktop",
517 NULL,
518 FILE_ATTRIBUTE_READONLY,
519 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH),
520 KNOWN_FOLDER(FOLDERID_DeviceMetadataStore,
521 NO_CSIDL,
522 "Device Metadata Store",
523 KF_CATEGORY_COMMON,
524 FOLDERID_ProgramData, GUID_NULL,
525 "Microsoft\\Windows\\DeviceMetadataStore\0",
526 NULL,
529 KNOWN_FOLDER(FOLDERID_Documents,
530 CSIDL_MYDOCUMENTS,
531 "Personal",
532 KF_CATEGORY_PERUSER,
533 FOLDERID_Profile, GUID_NULL,
534 "Documents\0",
535 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{FDD39AD0-238F-46AF-ADB4-6C85480369C7}\0shell:::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{A8CDFF1C-4878-43be-B5FD-F8091C1C60D0}\0\0", /* win8 */
536 FILE_ATTRIBUTE_READONLY,
537 KFDF_ROAMABLE | KFDF_PRECREATE),
538 KNOWN_FOLDER(FOLDERID_DocumentsLibrary,
539 NO_CSIDL,
540 "DocumentsLibrary",
541 KF_CATEGORY_PERUSER,
542 FOLDERID_Libraries, GUID_NULL,
543 "Documents.library-ms\0",
544 "::{031E4825-7B94-4dc3-B131-E946B44C8DD5}\\{7b0db17d-9cd2-4a93-9733-46cc89022e7c}\0\0",
546 KFDF_PRECREATE | KFDF_STREAM),
547 KNOWN_FOLDER(FOLDERID_Downloads,
548 NO_CSIDL,
549 "Downloads",
550 KF_CATEGORY_PERUSER,
551 FOLDERID_Profile, GUID_NULL,
552 "Downloads\0",
553 "(null)\0shell:::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{374DE290-123F-4565-9164-39C4925E467B}\0\0", /* win8 */
554 FILE_ATTRIBUTE_READONLY,
555 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH),
556 KNOWN_FOLDER(FOLDERID_Favorites,
557 CSIDL_FAVORITES,
558 "Favorites",
559 KF_CATEGORY_PERUSER,
560 FOLDERID_Profile, GUID_NULL,
561 "Favorites\0",
562 NULL,
563 FILE_ATTRIBUTE_READONLY,
564 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH),
565 KNOWN_FOLDER(FOLDERID_Fonts,
566 CSIDL_FONTS,
567 "Fonts",
568 KF_CATEGORY_FIXED,
569 FOLDERID_Windows, GUID_NULL,
570 NULL,
571 NULL,
574 KNOWN_FOLDER(FOLDERID_Games,
575 NO_CSIDL,
576 "Games",
577 KF_CATEGORY_VIRTUAL,
578 GUID_NULL, GUID_NULL,
579 NULL,
580 "::{ED228FDF-9EA8-4870-83b1-96b02CFE0D52}\0\0",
583 KNOWN_FOLDER(FOLDERID_GameTasks,
584 NO_CSIDL,
585 "GameTasks",
586 KF_CATEGORY_PERUSER,
587 FOLDERID_LocalAppData, GUID_NULL,
588 "Microsoft\\Windows\\GameExplorer\0",
589 NULL,
591 KFDF_LOCAL_REDIRECT_ONLY),
592 KNOWN_FOLDER(FOLDERID_History,
593 CSIDL_HISTORY,
594 "History",
595 KF_CATEGORY_PERUSER,
596 FOLDERID_LocalAppData, GUID_NULL,
597 "Microsoft\\Windows\\History\0",
598 NULL,
600 KFDF_LOCAL_REDIRECT_ONLY),
601 KNOWN_FOLDER(FOLDERID_HomeGroup,
602 NO_CSIDL,
603 "HomeGroupFolder",
604 KF_CATEGORY_VIRTUAL,
605 GUID_NULL, GUID_NULL,
606 NULL,
607 "::{B4FB3F98-C1EA-428d-A78A-D1F5659CBA93}\0\0",
610 KNOWN_FOLDER(FOLDERID_ImplicitAppShortcuts,
611 NO_CSIDL,
612 "ImplicitAppShortcuts",
613 KF_CATEGORY_PERUSER,
614 FOLDERID_UserPinned, GUID_NULL,
615 "ImplicitAppShortcuts\0",
616 NULL,
618 KFDF_PRECREATE),
619 KNOWN_FOLDER(FOLDERID_InternetCache,
620 CSIDL_INTERNET_CACHE,
621 "Cache",
622 KF_CATEGORY_PERUSER,
623 FOLDERID_LocalAppData, GUID_NULL,
624 "Microsoft\\Windows\\Temporary Internet Files\0Microsoft\\Windows\\INetCache\0\0", /* win8 */
625 NULL,
627 KFDF_LOCAL_REDIRECT_ONLY),
628 KNOWN_FOLDER(FOLDERID_InternetFolder,
629 CSIDL_INTERNET,
630 "InternetFolder",
631 KF_CATEGORY_VIRTUAL,
632 GUID_NULL, GUID_NULL,
633 NULL,
634 "::{871C5380-42A0-1069-A2EA-08002B30309D}\0\0",
637 KNOWN_FOLDER(FOLDERID_Libraries,
638 NO_CSIDL,
639 "Libraries",
640 KF_CATEGORY_PERUSER,
641 FOLDERID_RoamingAppData, GUID_NULL,
642 "Microsoft\\Windows\\Libraries\0",
643 NULL,
645 KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH),
646 KNOWN_FOLDER(FOLDERID_Links,
647 NO_CSIDL,
648 "Links",
649 KF_CATEGORY_PERUSER,
650 FOLDERID_Profile, GUID_NULL,
651 "Links\0",
652 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{bfb9d5e0-c6a9-404c-b2b2-ae6db6af4968}\0\0",
653 FILE_ATTRIBUTE_READONLY,
654 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH),
655 KNOWN_FOLDER(FOLDERID_LocalAppData,
656 CSIDL_LOCAL_APPDATA,
657 "Local AppData",
658 KF_CATEGORY_PERUSER,
659 FOLDERID_Profile, GUID_NULL,
660 "AppData\\Local\0",
661 NULL,
663 KFDF_LOCAL_REDIRECT_ONLY | KFDF_PUBLISHEXPANDEDPATH),
664 KNOWN_FOLDER(FOLDERID_LocalAppDataLow,
665 NO_CSIDL,
666 "LocalAppDataLow",
667 KF_CATEGORY_PERUSER,
668 FOLDERID_Profile, GUID_NULL,
669 "AppData\\LocalLow\0",
670 NULL,
671 FILE_ATTRIBUTE_NOT_CONTENT_INDEXED,
672 KFDF_LOCAL_REDIRECT_ONLY | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH),
673 KNOWN_FOLDER(FOLDERID_LocalizedResourcesDir,
674 CSIDL_RESOURCES_LOCALIZED,
675 "LocalizedResourcesDir",
676 KF_CATEGORY_FIXED,
677 GUID_NULL, GUID_NULL,
678 NULL,
679 NULL,
682 KNOWN_FOLDER(FOLDERID_Music,
683 CSIDL_MYMUSIC,
684 "My Music",
685 KF_CATEGORY_PERUSER,
686 FOLDERID_Profile, GUID_NULL,
687 "Music\0",
688 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{4BD8D571-6D19-48D3-BE97-422220080E43}\0shell:::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{1CF1260C-4DD0-4EBB-811F-33C572699FDE}\0\0", /* win8 */
689 FILE_ATTRIBUTE_READONLY,
690 KFDF_ROAMABLE | KFDF_PRECREATE),
691 KNOWN_FOLDER(FOLDERID_MusicLibrary,
692 NO_CSIDL,
693 "MusicLibrary",
694 KF_CATEGORY_PERUSER,
695 FOLDERID_Libraries, GUID_NULL,
696 "Music.library-ms\0",
697 "::{031E4825-7B94-4dc3-B131-E946B44C8DD5}\\{2112AB0A-C86A-4ffe-A368-0DE96E47012E}\0\0",
699 KFDF_PRECREATE | KFDF_STREAM),
700 KNOWN_FOLDER(FOLDERID_NetHood,
701 CSIDL_NETHOOD,
702 "NetHood",
703 KF_CATEGORY_PERUSER,
704 FOLDERID_RoamingAppData, GUID_NULL,
705 "Microsoft\\Windows\\Network Shortcuts\0",
706 NULL,
709 KNOWN_FOLDER(FOLDERID_NetworkFolder,
710 CSIDL_NETWORK,
711 "NetworkPlacesFolder",
712 KF_CATEGORY_VIRTUAL,
713 GUID_NULL, GUID_NULL,
714 NULL,
715 "::{F02C1A0D-BE21-4350-88B0-7367FC96EF3C}\0\0",
718 KNOWN_FOLDER(FOLDERID_OriginalImages,
719 NO_CSIDL,
720 "Original Images",
721 KF_CATEGORY_PERUSER,
722 FOLDERID_LocalAppData, GUID_NULL,
723 "Microsoft\\Windows Photo Gallery\\Original Images\0",
724 NULL,
727 KNOWN_FOLDER(FOLDERID_PhotoAlbums,
728 NO_CSIDL,
729 "PhotoAlbums",
730 KF_CATEGORY_PERUSER,
731 FOLDERID_Pictures, GUID_NULL,
732 "Slide Shows\0",
733 NULL,
734 FILE_ATTRIBUTE_READONLY,
736 KNOWN_FOLDER(FOLDERID_Pictures,
737 CSIDL_MYPICTURES,
738 "My Pictures",
739 KF_CATEGORY_PERUSER,
740 FOLDERID_Profile, GUID_NULL,
741 "Pictures\0",
742 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{33E28130-4E1E-4676-835A-98395C3BC3BB}\0shell:::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{3ADD1653-EB32-4CB0-BBD7-DFA0ABB5ACCA}\0\0", /* win8 */
743 FILE_ATTRIBUTE_READONLY,
744 KFDF_ROAMABLE | KFDF_PRECREATE),
745 KNOWN_FOLDER(FOLDERID_PicturesLibrary,
746 NO_CSIDL,
747 "PicturesLibrary",
748 KF_CATEGORY_PERUSER,
749 FOLDERID_Libraries, GUID_NULL,
750 "Pictures.library-ms\0",
751 "::{031E4825-7B94-4dc3-B131-E946B44C8DD5}\\{A990AE9F-A03B-4e80-94BC-9912D7504104}\0\0",
753 KFDF_PRECREATE | KFDF_STREAM),
754 KNOWN_FOLDER(FOLDERID_Playlists,
755 NO_CSIDL,
756 "Playlists",
757 KF_CATEGORY_PERUSER,
758 FOLDERID_Music, GUID_NULL,
759 "Playlists\0",
760 NULL,
761 FILE_ATTRIBUTE_READONLY,
763 KNOWN_FOLDER(FOLDERID_PrintersFolder,
764 CSIDL_PRINTERS,
765 "PrintersFolder",
766 KF_CATEGORY_VIRTUAL,
767 GUID_NULL, GUID_NULL,
768 NULL,
769 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{2227A280-3AEA-1069-A2DE-08002B30309D}\0\0",
772 KNOWN_FOLDER(FOLDERID_PrintHood,
773 CSIDL_PRINTHOOD,
774 "PrintHood",
775 KF_CATEGORY_PERUSER,
776 FOLDERID_RoamingAppData, GUID_NULL,
777 "Microsoft\\Windows\\Printer Shortcuts\0",
778 NULL,
781 KNOWN_FOLDER(FOLDERID_Profile,
782 CSIDL_PROFILE,
783 "Profile",
784 KF_CATEGORY_FIXED,
785 GUID_NULL, GUID_NULL,
786 NULL,
787 NULL,
790 KNOWN_FOLDER(FOLDERID_ProgramData,
791 CSIDL_COMMON_APPDATA,
792 "Common AppData",
793 KF_CATEGORY_FIXED,
794 GUID_NULL, GUID_NULL,
795 NULL,
796 NULL,
799 KNOWN_FOLDER(FOLDERID_ProgramFiles,
800 CSIDL_PROGRAM_FILES,
801 "ProgramFiles",
802 KF_CATEGORY_FIXED,
803 GUID_NULL, GUID_NULL,
804 NULL,
805 NULL,
806 FILE_ATTRIBUTE_READONLY,
807 KFDF_PRECREATE
809 KNOWN_FOLDER(FOLDERID_ProgramFilesCommon,
810 CSIDL_PROGRAM_FILES_COMMON,
811 "ProgramFilesCommon",
812 KF_CATEGORY_FIXED,
813 GUID_NULL, GUID_NULL,
814 NULL,
815 NULL,
818 KNOWN_FOLDER(FOLDERID_ProgramFilesCommonX64,
819 NO_CSIDL,
820 "ProgramFilesCommonX64",
821 KF_CATEGORY_FIXED,
822 GUID_NULL, GUID_NULL,
823 NULL,
824 NULL,
827 KNOWN_FOLDER(FOLDERID_ProgramFilesCommonX86,
828 NO_CSIDL,
829 "ProgramFilesCommonX86",
830 KF_CATEGORY_FIXED,
831 GUID_NULL, GUID_NULL,
832 NULL,
833 NULL,
836 KNOWN_FOLDER(FOLDERID_ProgramFilesX64,
837 NO_CSIDL,
838 "ProgramFilesX64",
839 KF_CATEGORY_FIXED,
840 GUID_NULL, GUID_NULL,
841 NULL,
842 NULL,
845 KNOWN_FOLDER(FOLDERID_ProgramFilesX86,
846 CSIDL_PROGRAM_FILESX86,
847 "ProgramFilesX86",
848 KF_CATEGORY_FIXED,
849 GUID_NULL, GUID_NULL,
850 NULL,
851 NULL,
852 FILE_ATTRIBUTE_READONLY,
853 KFDF_PRECREATE),
854 KNOWN_FOLDER(FOLDERID_Programs,
855 CSIDL_PROGRAMS,
856 "Programs",
857 KF_CATEGORY_PERUSER,
858 FOLDERID_StartMenu, GUID_NULL,
859 "Programs\0",
860 NULL,
861 FILE_ATTRIBUTE_READONLY,
862 KFDF_PRECREATE),
863 KNOWN_FOLDER(FOLDERID_Public,
864 NO_CSIDL,
865 "Public",
866 KF_CATEGORY_FIXED,
867 GUID_NULL, GUID_NULL,
868 NULL,
869 "::{4336a54d-038b-4685-ab02-99bb52d3fb8b}\0"
870 "(null)\0\0" /* 6.1 */,
871 FILE_ATTRIBUTE_READONLY,
872 KFDF_PRECREATE),
873 KNOWN_FOLDER(FOLDERID_PublicDesktop,
874 CSIDL_COMMON_DESKTOPDIRECTORY,
875 "Common Desktop",
876 KF_CATEGORY_COMMON,
877 FOLDERID_Public, GUID_NULL,
878 "Desktop\0",
879 NULL,
880 FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN,
881 KFDF_PRECREATE),
882 KNOWN_FOLDER(FOLDERID_PublicDocuments,
883 CSIDL_COMMON_DOCUMENTS,
884 "Common Documents",
885 KF_CATEGORY_COMMON,
886 FOLDERID_Public, GUID_NULL,
887 "Documents\0",
888 NULL,
889 FILE_ATTRIBUTE_READONLY,
890 KFDF_PRECREATE),
891 KNOWN_FOLDER(FOLDERID_PublicDownloads,
892 NO_CSIDL,
893 "CommonDownloads",
894 KF_CATEGORY_COMMON,
895 FOLDERID_Public, GUID_NULL,
896 "Downloads\0",
897 NULL,
898 FILE_ATTRIBUTE_READONLY,
899 KFDF_PRECREATE),
900 KNOWN_FOLDER(FOLDERID_PublicGameTasks,
901 NO_CSIDL,
902 "PublicGameTasks",
903 KF_CATEGORY_COMMON,
904 FOLDERID_ProgramData, GUID_NULL,
905 "Microsoft\\Windows\\GameExplorer\0",
906 NULL,
908 KFDF_LOCAL_REDIRECT_ONLY),
909 KNOWN_FOLDER(FOLDERID_PublicLibraries,
910 NO_CSIDL,
911 "PublicLibraries",
912 KF_CATEGORY_COMMON,
913 FOLDERID_Public, GUID_NULL,
914 "Libraries\0",
915 NULL,
916 FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN,
917 KFDF_PRECREATE),
918 KNOWN_FOLDER(FOLDERID_PublicMusic,
919 CSIDL_COMMON_MUSIC,
920 "CommonMusic",
921 KF_CATEGORY_COMMON,
922 FOLDERID_Public, GUID_NULL,
923 "Music\0",
924 NULL,
925 FILE_ATTRIBUTE_READONLY,
926 KFDF_PRECREATE),
927 KNOWN_FOLDER(FOLDERID_PublicPictures,
928 CSIDL_COMMON_PICTURES,
929 "CommonPictures",
930 KF_CATEGORY_COMMON,
931 FOLDERID_Public, GUID_NULL,
932 "Pictures\0",
933 NULL,
934 FILE_ATTRIBUTE_READONLY,
935 KFDF_PRECREATE),
936 KNOWN_FOLDER(FOLDERID_PublicRingtones,
937 NO_CSIDL,
938 "CommonRingtones",
939 KF_CATEGORY_COMMON,
940 FOLDERID_ProgramData, GUID_NULL,
941 "Microsoft\\Windows\\Ringtones\0",
942 NULL,
944 KFDF_PRECREATE),
945 KNOWN_FOLDER(FOLDERID_PublicVideos,
946 CSIDL_COMMON_VIDEO,
947 "CommonVideo",
948 KF_CATEGORY_COMMON,
949 FOLDERID_Public, GUID_NULL,
950 "Videos\0",
951 NULL,
952 FILE_ATTRIBUTE_READONLY,
953 KFDF_PRECREATE),
954 KNOWN_FOLDER(FOLDERID_QuickLaunch,
955 NO_CSIDL,
956 "Quick Launch",
957 KF_CATEGORY_PERUSER,
958 FOLDERID_RoamingAppData, GUID_NULL,
959 "Microsoft\\Internet Explorer\\Quick Launch\0",
960 NULL,
963 KNOWN_FOLDER(FOLDERID_Recent,
964 CSIDL_RECENT,
965 "Recent",
966 KF_CATEGORY_PERUSER,
967 FOLDERID_RoamingAppData, GUID_NULL,
968 "Microsoft\\Windows\\Recent\0",
969 NULL,
970 FILE_ATTRIBUTE_READONLY,
971 KFDF_PRECREATE),
972 KNOWN_FOLDER(FOLDERID_RecordedTVLibrary,
973 NO_CSIDL,
974 "RecordedTVLibrary",
975 KF_CATEGORY_COMMON,
976 FOLDERID_PublicLibraries, GUID_NULL,
977 "RecordedTV.library-ms\0",
978 NULL,
980 KFDF_PRECREATE | KFDF_STREAM),
981 KNOWN_FOLDER(FOLDERID_RecycleBinFolder,
982 CSIDL_BITBUCKET,
983 "RecycleBinFolder",
984 KF_CATEGORY_VIRTUAL,
985 GUID_NULL, GUID_NULL,
986 NULL,
987 "::{645FF040-5081-101B-9F08-00AA002F954E}\0\0",
990 KNOWN_FOLDER(FOLDERID_ResourceDir,
991 CSIDL_RESOURCES,
992 "ResourceDir",
993 KF_CATEGORY_FIXED,
994 GUID_NULL, GUID_NULL,
995 NULL,
996 NULL,
999 KNOWN_FOLDER(FOLDERID_Ringtones,
1000 NO_CSIDL,
1001 "Ringtones",
1002 KF_CATEGORY_PERUSER,
1003 FOLDERID_LocalAppData, GUID_NULL,
1004 "Microsoft\\Windows\\Ringtones\0",
1005 NULL,
1007 KFDF_PRECREATE),
1008 KNOWN_FOLDER(FOLDERID_RoamingAppData,
1009 CSIDL_APPDATA,
1010 "AppData",
1011 KF_CATEGORY_PERUSER,
1012 FOLDERID_Profile, GUID_NULL,
1013 "AppData\\Roaming\0",
1014 NULL,
1017 KNOWN_FOLDER(FOLDERID_SampleMusic,
1018 NO_CSIDL|WINE_ATTRIBUTES_OPTIONAL /* win8 */,
1019 "SampleMusic",
1020 KF_CATEGORY_COMMON,
1021 FOLDERID_PublicMusic, GUID_NULL,
1022 "Sample Music\0",
1023 NULL,
1024 FILE_ATTRIBUTE_READONLY,
1025 KFDF_PRECREATE),
1026 KNOWN_FOLDER(FOLDERID_SamplePictures,
1027 NO_CSIDL|WINE_ATTRIBUTES_OPTIONAL /* win8 */,
1028 "SamplePictures",
1029 KF_CATEGORY_COMMON,
1030 FOLDERID_PublicPictures, GUID_NULL,
1031 "Sample Pictures\0",
1032 NULL,
1033 FILE_ATTRIBUTE_READONLY,
1034 KFDF_PRECREATE),
1035 KNOWN_FOLDER(FOLDERID_SamplePlaylists,
1036 NO_CSIDL,
1037 "SamplePlaylists",
1038 KF_CATEGORY_COMMON,
1039 FOLDERID_PublicMusic, GUID_NULL,
1040 "Sample Playlists\0",
1041 NULL,
1042 FILE_ATTRIBUTE_READONLY,
1044 KNOWN_FOLDER(FOLDERID_SampleVideos,
1045 NO_CSIDL|WINE_ATTRIBUTES_OPTIONAL /* win8 */,
1046 "SampleVideos",
1047 KF_CATEGORY_COMMON,
1048 FOLDERID_PublicVideos, GUID_NULL,
1049 "Sample Videos\0",
1050 NULL,
1051 FILE_ATTRIBUTE_READONLY,
1052 KFDF_PRECREATE),
1053 KNOWN_FOLDER(FOLDERID_SavedGames,
1054 NO_CSIDL,
1055 "SavedGames",
1056 KF_CATEGORY_PERUSER,
1057 FOLDERID_Profile, GUID_NULL,
1058 "Saved Games\0",
1059 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{4C5C32FF-BB9D-43b0-B5B4-2D72E54EAAA4}\0\0",
1060 FILE_ATTRIBUTE_READONLY,
1061 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH),
1062 KNOWN_FOLDER(FOLDERID_SavedSearches,
1063 NO_CSIDL,
1064 "Searches",
1065 KF_CATEGORY_PERUSER,
1066 FOLDERID_Profile, GUID_NULL,
1067 "Searches\0",
1068 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{7d1d3a04-debb-4115-95cf-2f29da2920da}\0\0",
1069 FILE_ATTRIBUTE_READONLY,
1070 KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH),
1071 KNOWN_FOLDER(FOLDERID_SEARCH_CSC,
1072 NO_CSIDL,
1073 "CSCFolder",
1074 KF_CATEGORY_VIRTUAL,
1075 GUID_NULL, GUID_NULL,
1076 NULL,
1077 "shell:::{BD7A2E7B-21CB-41b2-A086-B309680C6B7E}\\*\0\0",
1080 KNOWN_FOLDER(FOLDERID_SearchHome,
1081 NO_CSIDL,
1082 "SearchHomeFolder",
1083 KF_CATEGORY_VIRTUAL,
1084 GUID_NULL, GUID_NULL,
1085 NULL,
1086 "::{9343812e-1c37-4a49-a12e-4b2d810d956b}\0\0",
1089 KNOWN_FOLDER(FOLDERID_SEARCH_MAPI,
1090 NO_CSIDL,
1091 "MAPIFolder",
1092 KF_CATEGORY_VIRTUAL,
1093 GUID_NULL, GUID_NULL,
1094 NULL,
1095 "shell:::{89D83576-6BD1-4C86-9454-BEB04E94C819}\\*\0\0",
1098 KNOWN_FOLDER(FOLDERID_SendTo,
1099 CSIDL_SENDTO,
1100 "SendTo",
1101 KF_CATEGORY_PERUSER,
1102 FOLDERID_RoamingAppData, GUID_NULL,
1103 "Microsoft\\Windows\\SendTo\0",
1104 NULL,
1107 KNOWN_FOLDER(FOLDERID_SidebarDefaultParts,
1108 NO_CSIDL,
1109 "Default Gadgets",
1110 KF_CATEGORY_COMMON,
1111 FOLDERID_ProgramFiles, GUID_NULL,
1112 "Windows Sidebar\\Gadgets\0",
1113 NULL,
1116 KNOWN_FOLDER(FOLDERID_SidebarParts,
1117 NO_CSIDL,
1118 "Gadgets",
1119 KF_CATEGORY_PERUSER,
1120 FOLDERID_LocalAppData, GUID_NULL,
1121 "Microsoft\\Windows Sidebar\\Gadgets\0",
1122 NULL,
1125 KNOWN_FOLDER(FOLDERID_StartMenu,
1126 CSIDL_STARTMENU,
1127 "Start Menu",
1128 KF_CATEGORY_PERUSER,
1129 FOLDERID_RoamingAppData, GUID_NULL,
1130 "Microsoft\\Windows\\Start Menu\0",
1131 NULL,
1132 FILE_ATTRIBUTE_READONLY,
1133 KFDF_PRECREATE),
1134 KNOWN_FOLDER(FOLDERID_Startup,
1135 CSIDL_STARTUP,
1136 "Startup",
1137 KF_CATEGORY_PERUSER,
1138 FOLDERID_Programs, GUID_NULL,
1139 "StartUp\0",
1140 NULL,
1141 FILE_ATTRIBUTE_READONLY,
1142 KFDF_PRECREATE),
1143 KNOWN_FOLDER(FOLDERID_SyncManagerFolder,
1144 NO_CSIDL,
1145 "SyncCenterFolder",
1146 KF_CATEGORY_VIRTUAL,
1147 GUID_NULL, GUID_NULL,
1148 NULL,
1149 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\0"
1150 "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\0\0" /* 6.1 */,
1153 KNOWN_FOLDER(FOLDERID_SyncResultsFolder,
1154 NO_CSIDL,
1155 "SyncResultsFolder",
1156 KF_CATEGORY_VIRTUAL,
1157 GUID_NULL, GUID_NULL,
1158 NULL,
1159 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\\::{BC48B32F-5910-47F5-8570-5074A8A5636A},\0"
1160 "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\\::{BC48B32F-5910-47F5-8570-5074A8A5636A},\0\0",
1163 KNOWN_FOLDER(FOLDERID_SyncSetupFolder,
1164 NO_CSIDL,
1165 "SyncSetupFolder",
1166 KF_CATEGORY_VIRTUAL,
1167 GUID_NULL, GUID_NULL,
1168 NULL,
1169 "::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\\::{F1390A9A-A3F4-4E5D-9C5F-98F3BD8D935C},\0"
1170 "::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\\::{F1390A9A-A3F4-4E5D-9C5F-98F3BD8D935C},\0\0" /* 6.1 */,
1173 KNOWN_FOLDER(FOLDERID_System,
1174 CSIDL_SYSTEM,
1175 "System",
1176 KF_CATEGORY_FIXED,
1177 GUID_NULL, GUID_NULL,
1178 NULL,
1179 NULL,
1182 KNOWN_FOLDER(FOLDERID_SystemX86,
1183 CSIDL_SYSTEMX86,
1184 "SystemX86",
1185 KF_CATEGORY_FIXED,
1186 GUID_NULL, GUID_NULL,
1187 NULL,
1188 NULL,
1191 KNOWN_FOLDER(FOLDERID_Templates,
1192 CSIDL_TEMPLATES,
1193 "Templates",
1194 KF_CATEGORY_PERUSER,
1195 FOLDERID_RoamingAppData, GUID_NULL,
1196 "Microsoft\\Windows\\Templates\0",
1197 NULL,
1200 KNOWN_FOLDER(FOLDERID_UserPinned,
1201 NO_CSIDL,
1202 "User Pinned",
1203 KF_CATEGORY_PERUSER,
1204 FOLDERID_QuickLaunch, GUID_NULL,
1205 "User Pinned\0",
1206 NULL,
1207 FILE_ATTRIBUTE_HIDDEN,
1208 KFDF_PRECREATE),
1209 KNOWN_FOLDER(FOLDERID_UserProfiles,
1210 NO_CSIDL,
1211 "UserProfiles",
1212 KF_CATEGORY_FIXED,
1213 GUID_NULL, GUID_NULL,
1214 NULL,
1215 NULL,
1216 FILE_ATTRIBUTE_READONLY,
1217 KFDF_PRECREATE),
1218 KNOWN_FOLDER(FOLDERID_UserProgramFiles,
1219 NO_CSIDL,
1220 "UserProgramFiles",
1221 KF_CATEGORY_PERUSER,
1222 FOLDERID_LocalAppData, GUID_NULL,
1223 "Programs\0",
1224 NULL,
1227 KNOWN_FOLDER(FOLDERID_UserProgramFilesCommon,
1228 NO_CSIDL,
1229 "UserProgramFilesCommon",
1230 KF_CATEGORY_PERUSER,
1231 FOLDERID_UserProgramFiles, GUID_NULL,
1232 "Common\0",
1233 NULL,
1236 KNOWN_FOLDER(FOLDERID_UsersFiles,
1237 NO_CSIDL,
1238 "UsersFilesFolder",
1239 KF_CATEGORY_VIRTUAL,
1240 GUID_NULL, GUID_NULL,
1241 NULL,
1242 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\0\0",
1245 KNOWN_FOLDER(FOLDERID_UsersLibraries,
1246 NO_CSIDL,
1247 "UsersLibrariesFolder",
1248 KF_CATEGORY_VIRTUAL,
1249 GUID_NULL, GUID_NULL,
1250 NULL,
1251 "::{031E4825-7B94-4dc3-B131-E946B44C8DD5}\0\0",
1254 KNOWN_FOLDER(FOLDERID_Videos,
1255 CSIDL_MYVIDEO,
1256 "My Video",
1257 KF_CATEGORY_PERUSER,
1258 FOLDERID_Profile, GUID_NULL,
1259 "Videos\0",
1260 "::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{18989B1D-99B5-455B-841C-AB7C74E4DDFC}\0shell:::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{A0953C92-50DC-43BF-BE83-3742FED03C9C}\0\0", /* win8 */
1261 FILE_ATTRIBUTE_READONLY,
1262 KFDF_ROAMABLE | KFDF_PRECREATE),
1263 KNOWN_FOLDER(FOLDERID_VideosLibrary,
1264 NO_CSIDL,
1265 "VideosLibrary",
1266 KF_CATEGORY_PERUSER,
1267 FOLDERID_Libraries, GUID_NULL,
1268 "Videos.library-ms\0",
1269 "::{031E4825-7B94-4dc3-B131-E946B44C8DD5}\\{491E922F-5643-4af4-A7EB-4E7A138D8174}\0\0",
1271 KFDF_PRECREATE | KFDF_STREAM),
1272 KNOWN_FOLDER(FOLDERID_Windows,
1273 CSIDL_WINDOWS,
1274 "Windows",
1275 KF_CATEGORY_FIXED,
1276 GUID_NULL, GUID_NULL,
1277 NULL,
1278 NULL,
1281 KNOWN_FOLDER(_FOLDERID_CredentialManager,
1282 NO_CSIDL,
1283 "CredentialManager",
1284 KF_CATEGORY_FIXED,
1285 GUID_NULL, GUID_NULL,
1286 NULL,
1287 NULL,
1290 KNOWN_FOLDER(_FOLDERID_CryptoKeys,
1291 NO_CSIDL,
1292 "CryptoKeys",
1293 KF_CATEGORY_FIXED,
1294 GUID_NULL, GUID_NULL,
1295 NULL,
1296 NULL,
1299 KNOWN_FOLDER(_FOLDERID_DpapiKeys,
1300 NO_CSIDL,
1301 "DpapiKeys",
1302 KF_CATEGORY_FIXED,
1303 GUID_NULL, GUID_NULL,
1304 NULL,
1305 NULL,
1308 KNOWN_FOLDER(_FOLDERID_SystemCertificates,
1309 NO_CSIDL,
1310 "SystemCertificates",
1311 KF_CATEGORY_FIXED,
1312 GUID_NULL, GUID_NULL,
1313 NULL,
1314 NULL,
1318 #undef KNOWN_FOLDER
1319 BOOL known_folder_found[ARRAY_SIZE(known_folders)];
1321 static void test_parameters(void)
1323 LPITEMIDLIST pidl = NULL;
1324 char path[MAX_PATH];
1325 HRESULT hr;
1327 /* check a bogus CSIDL: */
1328 pidl = NULL;
1329 hr = SHGetFolderLocation(NULL, 0xeeee, NULL, 0, &pidl);
1330 ok(hr == E_INVALIDARG, "got 0x%08x, expected E_INVALIDARG\n", hr);
1332 /* check a bogus user token: */
1333 pidl = NULL;
1334 hr = SHGetFolderLocation(NULL, CSIDL_FAVORITES, (HANDLE)2, 0, &pidl);
1335 ok(hr == E_FAIL || hr == E_HANDLE, "got 0x%08x, expected E_FAIL or E_HANDLE\n", hr);
1337 /* a NULL pidl pointer crashes, so don't test it */
1339 if (pSHGetSpecialFolderLocation)
1341 if (0)
1342 /* crashes */
1343 SHGetSpecialFolderLocation(NULL, 0, NULL);
1345 hr = pSHGetSpecialFolderLocation(NULL, 0xeeee, &pidl);
1346 ok(hr == E_INVALIDARG, "got returned 0x%08x\n", hr);
1349 if (pSHGetFolderPathA)
1351 /* expect 2's a bogus handle, especially since we didn't open it */
1352 hr = pSHGetFolderPathA(NULL, CSIDL_DESKTOP, (HANDLE)2, SHGFP_TYPE_DEFAULT, path);
1353 ok(hr == E_FAIL || hr == E_HANDLE || /* Vista and 2k8 */
1354 broken(hr == S_OK), /* W2k and Me */ "got 0x%08x, expected E_FAIL\n", hr);
1356 hr = pSHGetFolderPathA(NULL, 0xeeee, NULL, SHGFP_TYPE_DEFAULT, path);
1357 ok(hr == E_INVALIDARG, "got 0x%08x, expected E_INVALIDARG\n", hr);
1360 if (pSHGetSpecialFolderPathA)
1362 BOOL ret;
1364 if (0)
1365 pSHGetSpecialFolderPathA(NULL, NULL, CSIDL_BITBUCKET, FALSE);
1367 /* odd but true: calling with a NULL path still succeeds if it's a real
1368 * dir (on some windows platform). on winME it generates exception.
1370 ret = pSHGetSpecialFolderPathA(NULL, path, CSIDL_PROGRAMS, FALSE);
1371 ok(ret, "got %d\n", ret);
1373 ret = pSHGetSpecialFolderPathA(NULL, path, 0xeeee, FALSE);
1374 ok(!ret, "got %d\n", ret);
1378 /* Returns the folder's PIDL type, or 0xff if one can't be found. */
1379 static BYTE testSHGetFolderLocation(int folder)
1381 LPITEMIDLIST pidl;
1382 HRESULT hr;
1383 BYTE ret = 0xff;
1385 pidl = NULL;
1386 hr = SHGetFolderLocation(NULL, folder, NULL, 0, &pidl);
1387 if (hr == S_OK)
1389 if (pidl)
1391 LPITEMIDLIST pidlLast = pILFindLastID(pidl);
1393 ok(pidlLast != NULL, "%s: ILFindLastID failed\n",
1394 getFolderName(folder));
1395 if (pidlLast)
1396 ret = pidlLast->mkid.abID[0];
1397 ILFree(pidl);
1401 return ret;
1404 /* Returns the folder's PIDL type, or 0xff if one can't be found. */
1405 static BYTE testSHGetSpecialFolderLocation(int folder)
1407 LPITEMIDLIST pidl;
1408 HRESULT hr;
1409 BYTE ret = 0xff;
1411 if (!pSHGetSpecialFolderLocation) return ret;
1413 pidl = NULL;
1414 hr = pSHGetSpecialFolderLocation(NULL, folder, &pidl);
1415 if (hr == S_OK)
1417 if (pidl)
1419 LPITEMIDLIST pidlLast = pILFindLastID(pidl);
1421 ok(pidlLast != NULL,
1422 "%s: ILFindLastID failed\n", getFolderName(folder));
1423 if (pidlLast)
1424 ret = pidlLast->mkid.abID[0];
1425 ILFree(pidl);
1428 return ret;
1431 static void test_SHGetFolderPath(BOOL optional, int folder)
1433 char path[MAX_PATH];
1434 HRESULT hr;
1436 if (!pSHGetFolderPathA) return;
1438 hr = pSHGetFolderPathA(NULL, folder, NULL, SHGFP_TYPE_CURRENT, path);
1439 ok(hr == S_OK || optional,
1440 "SHGetFolderPathA(NULL, %s, NULL, SHGFP_TYPE_CURRENT, path) failed: 0x%08x\n", getFolderName(folder), hr);
1443 static void test_SHGetSpecialFolderPath(BOOL optional, int folder)
1445 char path[MAX_PATH];
1446 BOOL ret;
1448 if (!pSHGetSpecialFolderPathA) return;
1450 ret = pSHGetSpecialFolderPathA(NULL, path, folder, FALSE);
1451 if (ret && winetest_interactive)
1452 printf("%s: %s\n", getFolderName(folder), path);
1453 ok(ret || optional,
1454 "SHGetSpecialFolderPathA(NULL, path, %s, FALSE) failed\n",
1455 getFolderName(folder));
1458 enum ShellValuesTestExpect {
1459 ShellValuesTestExpect_Required,
1460 ShellValuesTestExpect_Optional,
1461 ShellValuesTestExpect_Missing,
1464 static void test_ShellValues(const struct shellExpectedValues testEntries[],
1465 int numEntries, enum ShellValuesTestExpect expect)
1467 int i;
1469 for (i = 0; i < numEntries; i++)
1471 BYTE type;
1472 int j;
1473 BOOL foundTypeMatch = FALSE;
1475 type = testSHGetFolderLocation(testEntries[i].folder);
1476 for (j = 0; !foundTypeMatch && j < testEntries[i].numTypes; j++)
1477 if (testEntries[i].types[j] == type)
1478 foundTypeMatch = TRUE;
1479 ok((expect == ShellValuesTestExpect_Required && foundTypeMatch) ||
1480 (expect == ShellValuesTestExpect_Optional) ||
1481 (expect == ShellValuesTestExpect_Missing && type == 0xff),
1482 "%s has unexpected type %d (0x%02x)\n",
1483 getFolderName(testEntries[i].folder), type, type);
1485 type = testSHGetSpecialFolderLocation(testEntries[i].folder);
1486 for (j = 0, foundTypeMatch = FALSE; !foundTypeMatch &&
1487 j < testEntries[i].numTypes; j++)
1488 if (testEntries[i].types[j] == type)
1489 foundTypeMatch = TRUE;
1490 ok((expect == ShellValuesTestExpect_Required && foundTypeMatch) ||
1491 (expect == ShellValuesTestExpect_Optional) ||
1492 (expect == ShellValuesTestExpect_Missing && type == 0xff),
1493 "%s has unexpected type %d (0x%02x)\n",
1494 getFolderName(testEntries[i].folder), type, type);
1495 if (expect != ShellValuesTestExpect_Missing)
1497 switch (type)
1499 case PT_FOLDER:
1500 case PT_DRIVE:
1501 case PT_DRIVE2:
1502 case PT_IESPECIAL2:
1503 test_SHGetFolderPath(expect == ShellValuesTestExpect_Optional, testEntries[i].folder);
1504 test_SHGetSpecialFolderPath(expect == ShellValuesTestExpect_Optional, testEntries[i].folder);
1505 break;
1511 /* Attempts to verify that the folder path corresponding to the folder CSIDL
1512 * value has the same value as the environment variable with name envVar.
1513 * Doesn't mind if SHGetSpecialFolderPath fails for folder or if envVar isn't
1514 * set in this environment; different OS and shell version behave differently.
1515 * However, if both are present, fails if envVar's value is not the same
1516 * (byte-for-byte) as what SHGetSpecialFolderPath returns.
1518 static void matchSpecialFolderPathToEnv(int folder, const char *envVar)
1520 char path[MAX_PATH];
1522 if (!pSHGetSpecialFolderPathA) return;
1524 if (pSHGetSpecialFolderPathA(NULL, path, folder, FALSE))
1526 char *envVal = getenv(envVar);
1528 ok(!envVal || !lstrcmpiA(envVal, path),
1529 "%%%s%% does not match SHGetSpecialFolderPath:\n"
1530 "%%%s%% is %s\nSHGetSpecialFolderPath returns %s\n",
1531 envVar, envVar, envVal, path);
1535 /* Attempts to match the GUID returned by SHGetFolderLocation for folder with
1536 * GUID. Assumes the type of the returned PIDL is in fact a GUID, but doesn't
1537 * fail if it isn't--that check should already have been done.
1538 * Fails if the returned PIDL is a GUID whose value does not match guid.
1540 static void matchGUID(int folder, const GUID *guid, const GUID *guid_alt)
1542 LPITEMIDLIST pidl;
1543 HRESULT hr;
1545 if (!guid) return;
1547 pidl = NULL;
1548 hr = SHGetFolderLocation(NULL, folder, NULL, 0, &pidl);
1549 if (hr == S_OK)
1551 LPITEMIDLIST pidlLast = pILFindLastID(pidl);
1553 if (pidlLast && (pidlLast->mkid.abID[0] == PT_SHELLEXT ||
1554 pidlLast->mkid.abID[0] == PT_GUID))
1556 GUID *shellGuid = (GUID *)(pidlLast->mkid.abID + 2);
1558 if (!guid_alt)
1559 ok(IsEqualIID(shellGuid, guid),
1560 "%s: got GUID %s, expected %s\n", getFolderName(folder),
1561 wine_dbgstr_guid(shellGuid), wine_dbgstr_guid(guid));
1562 else
1563 ok(IsEqualIID(shellGuid, guid) ||
1564 IsEqualIID(shellGuid, guid_alt),
1565 "%s: got GUID %s, expected %s or %s\n", getFolderName(folder),
1566 wine_dbgstr_guid(shellGuid), wine_dbgstr_guid(guid), wine_dbgstr_guid(guid_alt));
1568 ILFree(pidl);
1572 /* Checks the PIDL type of all the known values. */
1573 static void test_PidlTypes(void)
1575 /* Desktop */
1576 test_SHGetFolderPath(FALSE, CSIDL_DESKTOP);
1577 test_SHGetSpecialFolderPath(FALSE, CSIDL_DESKTOP);
1579 test_ShellValues(requiredShellValues, ARRAY_SIZE(requiredShellValues), ShellValuesTestExpect_Required);
1580 test_ShellValues(optionalShellValues, ARRAY_SIZE(optionalShellValues), ShellValuesTestExpect_Optional);
1581 test_ShellValues(undefinedShellValues, ARRAY_SIZE(undefinedShellValues), ShellValuesTestExpect_Missing);
1584 /* FIXME: Should be in shobjidl.idl */
1585 DEFINE_GUID(CLSID_NetworkExplorerFolder, 0xF02C1A0D, 0xBE21, 0x4350, 0x88, 0xB0, 0x73, 0x67, 0xFC, 0x96, 0xEF, 0x3C);
1586 DEFINE_GUID(_CLSID_Documents, 0xA8CDFF1C, 0x4878, 0x43be, 0xB5, 0xFD, 0xF8, 0x09, 0x1C, 0x1C, 0x60, 0xD0);
1588 /* Verifies various shell virtual folders have the correct well-known GUIDs. */
1589 static void test_GUIDs(void)
1591 matchGUID(CSIDL_BITBUCKET, &CLSID_RecycleBin, NULL);
1592 matchGUID(CSIDL_CONTROLS, &CLSID_ControlPanel, NULL);
1593 matchGUID(CSIDL_DRIVES, &CLSID_MyComputer, NULL);
1594 matchGUID(CSIDL_INTERNET, &CLSID_Internet, NULL);
1595 matchGUID(CSIDL_NETWORK, &CLSID_NetworkPlaces, &CLSID_NetworkExplorerFolder); /* Vista and higher */
1596 matchGUID(CSIDL_PERSONAL, &CLSID_MyDocuments, &_CLSID_Documents /* win8 */);
1597 matchGUID(CSIDL_COMMON_DOCUMENTS, &CLSID_CommonDocuments, NULL);
1598 matchGUID(CSIDL_PRINTERS, &CLSID_Printers, NULL);
1601 /* Verifies various shell paths match the environment variables to which they
1602 * correspond.
1604 static void test_EnvVars(void)
1606 matchSpecialFolderPathToEnv(CSIDL_PROGRAM_FILES, "ProgramFiles");
1607 matchSpecialFolderPathToEnv(CSIDL_APPDATA, "APPDATA");
1608 matchSpecialFolderPathToEnv(CSIDL_PROFILE, "USERPROFILE");
1609 matchSpecialFolderPathToEnv(CSIDL_WINDOWS, "SystemRoot");
1610 matchSpecialFolderPathToEnv(CSIDL_WINDOWS, "windir");
1611 matchSpecialFolderPathToEnv(CSIDL_PROGRAM_FILES_COMMON, "CommonProgramFiles");
1612 /* this is only set on Wine, but can't hurt to verify it: */
1613 matchSpecialFolderPathToEnv(CSIDL_SYSTEM, "winsysdir");
1616 /* Loosely based on PathRemoveBackslashA from dlls/shlwapi/path.c */
1617 static BOOL myPathIsRootA(LPCSTR lpszPath)
1619 if (lpszPath && *lpszPath &&
1620 lpszPath[1] == ':' && lpszPath[2] == '\\' && lpszPath[3] == '\0')
1621 return TRUE; /* X:\ */
1622 return FALSE;
1624 static LPSTR myPathRemoveBackslashA( LPSTR lpszPath )
1626 LPSTR szTemp = NULL;
1628 if(lpszPath)
1630 szTemp = CharPrevA(lpszPath, lpszPath + strlen(lpszPath));
1631 if (!myPathIsRootA(lpszPath) && *szTemp == '\\')
1632 *szTemp = '\0';
1634 return szTemp;
1637 /* Verifies the shell path for CSIDL_WINDOWS matches the return from
1638 * GetWindowsDirectory. If SHGetSpecialFolderPath fails, no harm, no foul--not
1639 * every shell32 version supports CSIDL_WINDOWS.
1641 static void testWinDir(void)
1643 char windowsShellPath[MAX_PATH], windowsDir[MAX_PATH] = { 0 };
1645 if (!pSHGetSpecialFolderPathA) return;
1647 if (pSHGetSpecialFolderPathA(NULL, windowsShellPath, CSIDL_WINDOWS, FALSE))
1649 myPathRemoveBackslashA(windowsShellPath);
1650 GetWindowsDirectoryA(windowsDir, sizeof(windowsDir));
1651 myPathRemoveBackslashA(windowsDir);
1652 ok(!lstrcmpiA(windowsDir, windowsShellPath),
1653 "GetWindowsDirectory returns %s SHGetSpecialFolderPath returns %s\n",
1654 windowsDir, windowsShellPath);
1658 /* Verifies the shell path for CSIDL_SYSTEM matches the return from
1659 * GetSystemDirectory. If SHGetSpecialFolderPath fails, no harm,
1660 * no foul--not every shell32 version supports CSIDL_SYSTEM.
1662 static void testSystemDir(void)
1664 char systemShellPath[MAX_PATH], systemDir[MAX_PATH], systemDirx86[MAX_PATH];
1666 if (!pSHGetSpecialFolderPathA) return;
1668 GetSystemDirectoryA(systemDir, sizeof(systemDir));
1669 myPathRemoveBackslashA(systemDir);
1670 if (pSHGetSpecialFolderPathA(NULL, systemShellPath, CSIDL_SYSTEM, FALSE))
1672 myPathRemoveBackslashA(systemShellPath);
1673 ok(!lstrcmpiA(systemDir, systemShellPath),
1674 "GetSystemDirectory returns %s SHGetSpecialFolderPath returns %s\n",
1675 systemDir, systemShellPath);
1678 if (!pGetSystemWow64DirectoryA || !pGetSystemWow64DirectoryA(systemDirx86, sizeof(systemDirx86)))
1679 GetSystemDirectoryA(systemDirx86, sizeof(systemDirx86));
1680 myPathRemoveBackslashA(systemDirx86);
1681 if (pSHGetSpecialFolderPathA(NULL, systemShellPath, CSIDL_SYSTEMX86, FALSE))
1683 myPathRemoveBackslashA(systemShellPath);
1684 ok(!lstrcmpiA(systemDirx86, systemShellPath) || broken(!lstrcmpiA(systemDir, systemShellPath)),
1685 "GetSystemDirectory returns %s SHGetSpecialFolderPath returns %s\n",
1686 systemDir, systemShellPath);
1690 /* Globals used by subprocesses */
1691 static int myARGC;
1692 static char **myARGV;
1693 static char base[MAX_PATH];
1694 static char selfname[MAX_PATH];
1696 static BOOL init(void)
1698 myARGC = winetest_get_mainargs(&myARGV);
1699 if (!GetCurrentDirectoryA(sizeof(base), base)) return FALSE;
1700 strcpy(selfname, myARGV[0]);
1701 return TRUE;
1704 static void doChild(const char *arg)
1706 char path[MAX_PATH];
1707 HRESULT hr;
1709 if (arg[0] == '1')
1711 LPITEMIDLIST pidl;
1712 char *p;
1714 /* test what happens when CSIDL_FAVORITES is set to a nonexistent directory */
1716 /* test some failure cases first: */
1717 hr = pSHGetFolderPathA(NULL, CSIDL_FAVORITES, NULL, SHGFP_TYPE_CURRENT, path);
1718 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
1719 "SHGetFolderPath returned 0x%08x, expected 0x80070002\n", hr);
1721 pidl = NULL;
1722 hr = SHGetFolderLocation(NULL, CSIDL_FAVORITES, NULL, 0, &pidl);
1723 ok(hr == E_FAIL || hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
1724 "SHGetFolderLocation returned 0x%08x\n", hr);
1726 ok(!pSHGetSpecialFolderPathA(NULL, path, CSIDL_FAVORITES, FALSE),
1727 "SHGetSpecialFolderPath succeeded, expected failure\n");
1729 pidl = NULL;
1730 hr = pSHGetSpecialFolderLocation(NULL, CSIDL_FAVORITES, &pidl);
1731 ok(hr == E_FAIL || hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
1732 "SHGetFolderLocation returned 0x%08x\n", hr);
1734 /* now test success: */
1735 hr = pSHGetFolderPathA(NULL, CSIDL_FAVORITES | CSIDL_FLAG_CREATE, NULL,
1736 SHGFP_TYPE_CURRENT, path);
1737 ok (hr == S_OK, "got 0x%08x\n", hr);
1738 if (hr == S_OK)
1740 BOOL ret;
1742 trace("CSIDL_FAVORITES was changed to %s\n", path);
1743 ret = CreateDirectoryA(path, NULL);
1744 ok(!ret, "expected failure with ERROR_ALREADY_EXISTS\n");
1745 if (!ret)
1746 ok(GetLastError() == ERROR_ALREADY_EXISTS,
1747 "got %d, expected ERROR_ALREADY_EXISTS\n", GetLastError());
1749 p = path + strlen(path);
1750 strcpy(p, "\\desktop.ini");
1751 DeleteFileA(path);
1752 *p = 0;
1753 SetFileAttributesA( path, FILE_ATTRIBUTE_NORMAL );
1754 ret = RemoveDirectoryA(path);
1755 ok( ret, "failed to remove %s error %u\n", path, GetLastError() );
1758 else if (arg[0] == '2')
1760 /* make sure SHGetFolderPath still succeeds when the
1761 original value of CSIDL_FAVORITES is restored. */
1762 hr = pSHGetFolderPathA(NULL, CSIDL_FAVORITES | CSIDL_FLAG_CREATE, NULL,
1763 SHGFP_TYPE_CURRENT, path);
1764 ok(hr == S_OK, "SHGetFolderPath failed: 0x%08x\n", hr);
1768 /* Tests the return values from the various shell functions both with and
1769 * without the use of the CSIDL_FLAG_CREATE flag. This flag only appeared in
1770 * version 5 of the shell, so don't test unless it's at least version 5.
1771 * The test reads a value from the registry, modifies it, calls
1772 * SHGetFolderPath once with the CSIDL_FLAG_CREATE flag, and immediately
1773 * afterward without it. Then it restores the registry and deletes the folder
1774 * that was created.
1775 * One oddity with respect to restoration: shell32 caches somehow, so it needs
1776 * to be reloaded in order to see the correct (restored) value.
1777 * Some APIs unrelated to the ones under test may fail, but I expect they're
1778 * covered by other unit tests; I just print out something about failure to
1779 * help trace what's going on.
1781 static void test_NonExistentPath(void)
1783 static const char userShellFolders[] =
1784 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders";
1785 char originalPath[MAX_PATH], modifiedPath[MAX_PATH];
1786 HKEY key;
1788 if (!pSHGetFolderPathA) return;
1789 if (!pSHGetSpecialFolderPathA) return;
1790 if (!pSHGetSpecialFolderLocation) return;
1791 if (!pSHFileOperationA) return;
1792 if (shellVersion.dwMajorVersion < 5) return;
1794 if (!RegOpenKeyExA(HKEY_CURRENT_USER, userShellFolders, 0, KEY_ALL_ACCESS,
1795 &key))
1797 DWORD len, type;
1799 len = sizeof(originalPath);
1800 if (!RegQueryValueExA(key, "Favorites", NULL, &type,
1801 (LPBYTE)&originalPath, &len))
1803 size_t len = strlen(originalPath);
1805 memcpy(modifiedPath, originalPath, len);
1806 modifiedPath[len++] = '2';
1807 modifiedPath[len++] = '\0';
1808 trace("Changing CSIDL_FAVORITES to %s\n", modifiedPath);
1809 if (!RegSetValueExA(key, "Favorites", 0, type,
1810 (LPBYTE)modifiedPath, len))
1812 char buffer[MAX_PATH+20];
1813 STARTUPINFOA startup;
1814 PROCESS_INFORMATION info;
1816 sprintf(buffer, "%s shellpath 1", selfname);
1817 memset(&startup, 0, sizeof(startup));
1818 startup.cb = sizeof(startup);
1819 startup.dwFlags = STARTF_USESHOWWINDOW;
1820 startup.wShowWindow = SW_SHOWNORMAL;
1821 CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL,
1822 &startup, &info);
1823 wait_child_process( info.hProcess );
1825 /* restore original values: */
1826 trace("Restoring CSIDL_FAVORITES to %s\n", originalPath);
1827 RegSetValueExA(key, "Favorites", 0, type, (LPBYTE) originalPath,
1828 strlen(originalPath) + 1);
1829 RegFlushKey(key);
1831 sprintf(buffer, "%s shellpath 2", selfname);
1832 memset(&startup, 0, sizeof(startup));
1833 startup.cb = sizeof(startup);
1834 startup.dwFlags = STARTF_USESHOWWINDOW;
1835 startup.wShowWindow = SW_SHOWNORMAL;
1836 CreateProcessA(NULL, buffer, NULL, NULL, FALSE, 0L, NULL, NULL,
1837 &startup, &info);
1838 ok(WaitForSingleObject(info.hProcess, 30000) == WAIT_OBJECT_0,
1839 "child process termination\n");
1842 else skip("RegQueryValueExA(key, Favorites, ...) failed\n");
1843 if (key)
1844 RegCloseKey(key);
1846 else skip("RegOpenKeyExA(HKEY_CURRENT_USER, %s, ...) failed\n", userShellFolders);
1849 static void test_SHGetFolderPathEx(void)
1851 WCHAR buffer[MAX_PATH], *path, *path2;
1852 unsigned int i;
1853 HRESULT hr;
1854 DWORD len;
1856 if (!pSHGetKnownFolderPath || !pSHGetFolderPathEx)
1858 win_skip("SHGetKnownFolderPath or SHGetFolderPathEx not available\n");
1859 return;
1862 if (0) { /* crashes */
1863 hr = pSHGetKnownFolderPath(&FOLDERID_Desktop, 0, NULL, NULL);
1864 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
1866 /* non-existent folder id */
1867 path = (void *)0xdeadbeef;
1868 hr = pSHGetKnownFolderPath(&IID_IOleObject, 0, NULL, &path);
1869 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "got 0x%08x\n", hr);
1870 ok(path == NULL, "got %p\n", path);
1872 path = NULL;
1873 hr = pSHGetKnownFolderPath(&FOLDERID_Desktop, KF_FLAG_DEFAULT_PATH, NULL, &path);
1874 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1875 ok(path != NULL, "expected path != NULL\n");
1876 CoTaskMemFree(path);
1878 for (i = 0; i < ARRAY_SIZE(known_folders); ++i)
1880 const KNOWNFOLDERID *folder_id = known_folders[i].folderId;
1882 path = NULL;
1883 hr = pSHGetKnownFolderPath(folder_id, KF_FLAG_DEFAULT, NULL, &path);
1884 if (FAILED(hr))
1886 ok(path == NULL, "expected path == NULL\n");
1887 continue;
1889 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1890 ok(path != NULL, "expected path != NULL\n");
1892 path2 = NULL;
1893 hr = pSHGetKnownFolderPath(folder_id, KF_FLAG_SIMPLE_IDLIST, NULL, &path2);
1894 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1895 ok(path2 != NULL, "expected path != NULL\n");
1896 ok(!lstrcmpiW(path, path2), "expected equal paths: %s, %s\n", wine_dbgstr_w(path), wine_dbgstr_w(path2));
1897 CoTaskMemFree(path2);
1899 path2 = NULL;
1900 hr = pSHGetKnownFolderPath(folder_id, KF_FLAG_DONT_UNEXPAND, NULL, &path2);
1901 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1902 ok(path2 != NULL, "expected path != NULL\n");
1903 ok(!lstrcmpiW(path, path2), "expected equal paths: %s, %s\n", wine_dbgstr_w(path), wine_dbgstr_w(path2));
1904 CoTaskMemFree(path2);
1906 path2 = NULL;
1907 hr = pSHGetKnownFolderPath(folder_id, KF_FLAG_SIMPLE_IDLIST | KF_FLAG_DONT_UNEXPAND, NULL, &path2);
1908 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1909 ok(path2 != NULL, "expected path != NULL\n");
1910 ok(!lstrcmpiW(path, path2), "expected equal paths: %s, %s\n", wine_dbgstr_w(path), wine_dbgstr_w(path2));
1911 CoTaskMemFree(path2);
1913 hr = pSHGetKnownFolderPath(folder_id, KF_FLAG_DEFAULT_PATH, NULL, &path2);
1914 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1915 ok(path2 != NULL, "expected path != NULL\n");
1916 CoTaskMemFree(path2);
1918 hr = pSHGetKnownFolderPath(folder_id, KF_FLAG_NOT_PARENT_RELATIVE, NULL, &path2);
1919 ok(hr == E_INVALIDARG, "expected S_OK, got 0x%08x\n", hr);
1921 hr = pSHGetKnownFolderPath(folder_id, KF_FLAG_DEFAULT_PATH | KF_FLAG_NOT_PARENT_RELATIVE, NULL, &path2);
1922 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1923 ok(path2 != NULL, "expected path != NULL\n");
1924 CoTaskMemFree(path2);
1926 CoTaskMemFree(path);
1929 path = NULL;
1930 hr = pSHGetKnownFolderPath(&FOLDERID_Desktop, 0, NULL, &path);
1931 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1932 ok(path != NULL, "expected path != NULL\n");
1934 hr = pSHGetFolderPathEx(&FOLDERID_Desktop, 0, NULL, buffer, MAX_PATH);
1935 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1936 ok(!lstrcmpiW(path, buffer), "expected equal paths\n");
1937 len = lstrlenW(buffer);
1938 CoTaskMemFree(path);
1940 hr = pSHGetFolderPathEx(&FOLDERID_Desktop, 0, NULL, buffer, 0);
1941 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
1943 if (0) { /* crashes */
1944 hr = pSHGetFolderPathEx(&FOLDERID_Desktop, 0, NULL, NULL, len + 1);
1945 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
1947 hr = pSHGetFolderPathEx(NULL, 0, NULL, buffer, MAX_PATH);
1948 ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got 0x%08x\n", hr);
1950 hr = pSHGetFolderPathEx(&FOLDERID_Desktop, 0, NULL, buffer, len);
1951 ok(hr == E_NOT_SUFFICIENT_BUFFER, "expected E_NOT_SUFFICIENT_BUFFER, got 0x%08x\n", hr);
1953 hr = pSHGetFolderPathEx(&FOLDERID_Desktop, 0, NULL, buffer, len + 1);
1954 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1956 path = NULL;
1957 hr = pSHGetKnownFolderPath(&FOLDERID_ProgramFilesX64, 0, NULL, &path);
1958 #ifdef _WIN64
1959 ok(hr == S_OK, "got 0x%08x\n", hr);
1960 ok(path != NULL, "path not set\n");
1961 CoTaskMemFree(path);
1962 #else
1963 todo_wine ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "got 0x%08x\n", hr);
1964 ok(path == NULL, "path set\n");
1965 #endif
1967 path = NULL;
1968 hr = pSHGetKnownFolderPath(&FOLDERID_ProgramFilesCommonX64, 0, NULL, &path);
1969 #ifdef _WIN64
1970 ok(hr == S_OK, "expected S_OK, got 0x%08x\n", hr);
1971 ok(path != NULL, "path not set\n");
1972 CoTaskMemFree(path);
1973 #else
1974 todo_wine ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "got 0x%08x\n", hr);
1975 ok(path == NULL, "path set\n");
1976 #endif
1979 static BOOL is_in_strarray(const WCHAR *needle, const char *hay)
1981 WCHAR wstr[MAX_PATH];
1983 if(!needle && !hay)
1984 return TRUE;
1986 while(hay && *hay)
1988 DWORD ret;
1990 if(strcmp(hay, "(null)") == 0 && !needle)
1991 return TRUE;
1993 ret = MultiByteToWideChar(CP_ACP, 0, hay, -1, wstr, ARRAY_SIZE(wstr));
1994 if(ret == 0)
1996 ok(0, "Failed to convert string\n");
1997 return FALSE;
2000 if(lstrcmpW(wstr, needle) == 0)
2001 return TRUE;
2003 hay += strlen(hay) + 1;
2006 return FALSE;
2009 static void check_known_folder(IKnownFolderManager *mgr, KNOWNFOLDERID *folderId)
2011 HRESULT hr;
2012 int csidl, expectedCsidl, ret;
2013 KNOWNFOLDER_DEFINITION kfd;
2014 IKnownFolder *folder, *kf_parent;
2015 WCHAR sName[1024];
2016 BOOL found = FALSE;
2017 unsigned int i;
2018 WCHAR *ikf_path, *gkfp_path, *ikf_parent_path;
2020 for (i = 0; i < ARRAY_SIZE(known_folders); ++i)
2022 const struct knownFolderDef *known_folder = &known_folders[i];
2024 if(IsEqualGUID(known_folder->folderId, folderId))
2026 known_folder_found[i] = TRUE;
2027 found = TRUE;
2028 /* verify CSIDL */
2029 if(!(known_folder->csidl & NO_CSIDL))
2031 /* mask off winetest flags */
2032 expectedCsidl = known_folder->csidl & 0xFFFF;
2034 hr = IKnownFolderManager_FolderIdToCsidl(mgr, folderId, &csidl);
2035 ok_(__FILE__, known_folder->line)(hr == S_OK, "cannot retrieve CSIDL for folder %s\n", known_folder->sFolderId);
2037 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);
2040 hr = IKnownFolderManager_GetFolder(mgr, folderId, &folder);
2041 ok_(__FILE__, known_folder->line)(hr == S_OK, "cannot get known folder for %s\n", known_folder->sFolderId);
2042 if(SUCCEEDED(hr))
2044 hr = IKnownFolder_GetFolderDefinition(folder, &kfd);
2045 ok_(__FILE__, known_folder->line)(hr == S_OK, "cannot get known folder definition for %s\n", known_folder->sFolderId);
2046 if(SUCCEEDED(hr))
2048 ret = MultiByteToWideChar(CP_ACP, 0, known_folder->sName, -1, sName, ARRAY_SIZE(sName));
2049 ok_(__FILE__, known_folder->line)(ret != 0, "cannot convert known folder name \"%s\" to wide characters\n", known_folder->sName);
2051 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));
2053 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);
2055 ok_(__FILE__, known_folder->line)(IsEqualGUID(known_folder->fidParents[0], &kfd.fidParent) ||
2056 IsEqualGUID(known_folder->fidParents[1], &kfd.fidParent),
2057 "invalid known folder parent for %s: %s retrieved\n",
2058 known_folder->sFolderId, wine_dbgstr_guid(&kfd.fidParent));
2060 ok_(__FILE__, known_folder->line)(is_in_strarray(kfd.pszRelativePath, known_folder->sRelativePath), "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));
2062 ok_(__FILE__, known_folder->line)(is_in_strarray(kfd.pszParsingName, known_folder->sParsingName), "invalid known folder parsing name returned for %s: %s retrieved\n", known_folder->sFolderId, wine_dbgstr_w(kfd.pszParsingName));
2064 ok_(__FILE__, known_folder->line)(known_folder->attributes == kfd.dwAttributes ||
2065 (known_folder->csidl & WINE_ATTRIBUTES_OPTIONAL && kfd.dwAttributes == 0),
2066 "invalid known folder attributes for %s: 0x%08x expected, but 0x%08x retrieved\n", known_folder->sFolderId, known_folder->attributes, kfd.dwAttributes);
2068 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);
2070 gkfp_path = NULL;
2071 hr = pSHGetKnownFolderPath(folderId, KF_FLAG_DEFAULT, NULL, &gkfp_path);
2072 if(SUCCEEDED(hr))
2074 ikf_path = NULL;
2075 hr = IKnownFolder_GetPath(folder, KF_FLAG_DEFAULT, &ikf_path);
2076 ok_(__FILE__, known_folder->line)(hr == S_OK, "IKnownFolder::GetPath failed: 0x%08x\n", hr);
2077 ok_(__FILE__, known_folder->line)(ikf_path != NULL, "SHGetKnownFolderPath gave NULL path\n");
2079 /* IKnownFolder::GetPath and SHGetKnownFolderPath should be the same */
2080 ok_(__FILE__, known_folder->line)(lstrcmpW(gkfp_path, ikf_path) == 0, "Got different paths: %s vs %s\n",
2081 debugstr_w(gkfp_path), debugstr_w(ikf_path));
2083 if(kfd.pszRelativePath)
2085 /* RelativePath should be a substring of the path */
2086 ok_(__FILE__, known_folder->line)(wcscasestr(ikf_path, kfd.pszRelativePath) != NULL,
2087 "KNOWNFOLDER_DEFINITION.pszRelativePath %s is not a substring of full path %s\n",
2088 debugstr_w(kfd.pszRelativePath), debugstr_w(ikf_path));
2090 hr = IKnownFolderManager_GetFolder(mgr, &kfd.fidParent, &kf_parent);
2091 ok_(__FILE__, known_folder->line)(hr == S_OK, "IKnownFolderManager::GetFolder(parent) failed: 0x%08x\n", hr);
2093 if(SUCCEEDED(hr))
2095 ikf_parent_path = NULL;
2096 hr = IKnownFolder_GetPath(kf_parent, KF_FLAG_DEFAULT, &ikf_parent_path);
2097 ok_(__FILE__, known_folder->line)(hr == S_OK, "IKnownFolder::GetPath(parent) failed: 0x%08x\n", hr);
2099 /* Parent path + pszRelativePath should give the full path */
2100 ok_(__FILE__, known_folder->line)(memcmp(ikf_parent_path, ikf_path, lstrlenW(ikf_parent_path) * sizeof(WCHAR)) == 0,
2101 "Full path %s does not start with parent path %s\n",
2102 debugstr_w(ikf_path), debugstr_w(ikf_parent_path));
2103 ok_(__FILE__, known_folder->line)(*(ikf_path + lstrlenW(ikf_parent_path)) == '\\',
2104 "Missing slash\n");
2105 ok_(__FILE__, known_folder->line)(
2106 wcsicmp(kfd.pszRelativePath, ikf_path + lstrlenW(ikf_parent_path) + 1) == 0 ||
2107 /* With multiple drives, there are multiple CD-burning folders */
2108 (IsEqualGUID(folderId, &FOLDERID_CDBurning) &&
2109 wcsnicmp(kfd.pszRelativePath, ikf_path + lstrlenW(ikf_parent_path) + 1, wcslen(kfd.pszRelativePath)) == 0),
2110 "Full path %s does not end with relative path %s\n",
2111 debugstr_w(ikf_path), debugstr_w(kfd.pszRelativePath));
2113 CoTaskMemFree(ikf_parent_path);
2114 IKnownFolder_Release(kf_parent);
2118 CoTaskMemFree(ikf_path);
2119 CoTaskMemFree(gkfp_path);
2121 FreeKnownFolderDefinitionFields(&kfd);
2124 IKnownFolder_Release(folder);
2127 break;
2131 if(!found)
2133 trace("unknown known folder found: %s\n", wine_dbgstr_guid(folderId));
2135 hr = IKnownFolderManager_GetFolder(mgr, folderId, &folder);
2136 ok(hr == S_OK, "cannot get known folder for %s\n", wine_dbgstr_guid(folderId));
2137 if(SUCCEEDED(hr))
2139 hr = IKnownFolder_GetFolderDefinition(folder, &kfd);
2140 todo_wine
2141 ok(hr == S_OK, "cannot get known folder definition for %s\n", wine_dbgstr_guid(folderId));
2142 if(SUCCEEDED(hr))
2144 trace(" category: %d\n", kfd.category);
2145 trace(" name: %s\n", wine_dbgstr_w(kfd.pszName));
2146 trace(" description: %s\n", wine_dbgstr_w(kfd.pszDescription));
2147 trace(" parent: %s\n", wine_dbgstr_guid(&kfd.fidParent));
2148 trace(" relative path: %s\n", wine_dbgstr_w(kfd.pszRelativePath));
2149 trace(" parsing name: %s\n", wine_dbgstr_w(kfd.pszParsingName));
2150 trace(" tooltip: %s\n", wine_dbgstr_w(kfd.pszTooltip));
2151 trace(" localized name: %s\n", wine_dbgstr_w(kfd.pszLocalizedName));
2152 trace(" icon: %s\n", wine_dbgstr_w(kfd.pszIcon));
2153 trace(" security: %s\n", wine_dbgstr_w(kfd.pszSecurity));
2154 trace(" attributes: 0x%08x\n", kfd.dwAttributes);
2155 trace(" flags: 0x%08x\n", kfd.kfdFlags);
2156 trace(" type: %s\n", wine_dbgstr_guid(&kfd.ftidType));
2157 FreeKnownFolderDefinitionFields(&kfd);
2160 IKnownFolder_Release(folder);
2164 #undef NO_CSIDL
2166 static void test_knownFolders(void)
2168 static const WCHAR sWindows[] = {'W','i','n','d','o','w','s',0};
2169 static const WCHAR sWindows2[] = {'w','i','n','d','o','w','s',0};
2170 static const WCHAR sExample[] = {'E','x','a','m','p','l','e',0};
2171 static const WCHAR sExample2[] = {'E','x','a','m','p','l','e','2',0};
2172 static const WCHAR sSubFolder[] = {'S','u','b','F','o','l','d','e','r',0};
2173 static const WCHAR sNoSuch[] = {'N','o','S','u','c','h',0};
2174 static const WCHAR sBackslash[] = {'\\',0};
2175 static const KNOWNFOLDERID newFolderId = {0x01234567, 0x89AB, 0xCDEF, {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x01} };
2176 static const KNOWNFOLDERID subFolderId = {0xFEDCBA98, 0x7654, 0x3210, {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF} };
2177 HRESULT hr;
2178 IKnownFolderManager *mgr = NULL;
2179 IKnownFolder *folder = NULL, *subFolder = NULL;
2180 KNOWNFOLDERID folderId, *folders;
2181 KF_CATEGORY cat = 0;
2182 KNOWNFOLDER_DEFINITION kfDefinition, kfSubDefinition;
2183 int csidl, i;
2184 UINT nCount = 0;
2185 LPWSTR folderPath, errorMsg;
2186 KF_REDIRECTION_CAPABILITIES redirectionCapabilities = 1;
2187 WCHAR sWinDir[MAX_PATH], sExamplePath[MAX_PATH], sExample2Path[MAX_PATH], sSubFolderPath[MAX_PATH], sSubFolder2Path[MAX_PATH];
2188 BOOL bRes;
2189 DWORD dwAttributes;
2191 GetWindowsDirectoryW( sWinDir, MAX_PATH );
2193 GetTempPathW(ARRAY_SIZE(sExamplePath), sExamplePath);
2194 lstrcatW(sExamplePath, sExample);
2196 GetTempPathW(ARRAY_SIZE(sExample2Path), sExample2Path);
2197 lstrcatW(sExample2Path, sExample2);
2199 lstrcpyW(sSubFolderPath, sExamplePath);
2200 lstrcatW(sSubFolderPath, sBackslash);
2201 lstrcatW(sSubFolderPath, sSubFolder);
2203 lstrcpyW(sSubFolder2Path, sExample2Path);
2204 lstrcatW(sSubFolder2Path, sBackslash);
2205 lstrcatW(sSubFolder2Path, sSubFolder);
2207 CoInitialize(NULL);
2209 hr = CoCreateInstance(&CLSID_KnownFolderManager, NULL, CLSCTX_INPROC_SERVER,
2210 &IID_IKnownFolderManager, (LPVOID*)&mgr);
2211 if(hr == REGDB_E_CLASSNOTREG)
2212 win_skip("IKnownFolderManager unavailable\n");
2213 else
2215 IUnknown *unk;
2217 ok(hr == S_OK, "failed to create KnownFolderManager instance: 0x%08x\n", hr);
2219 hr = IKnownFolderManager_QueryInterface(mgr, &IID_IMarshal, (void**)&unk);
2220 ok(hr == E_NOINTERFACE, "got 0x%08x\n", hr);
2222 hr = IKnownFolderManager_FolderIdFromCsidl(mgr, CSIDL_WINDOWS, &folderId);
2223 ok(hr == S_OK, "failed to convert CSIDL to KNOWNFOLDERID: 0x%08x\n", hr);
2224 ok(IsEqualGUID(&folderId, &FOLDERID_Windows)==TRUE, "invalid KNOWNFOLDERID returned\n");
2226 hr = IKnownFolderManager_FolderIdToCsidl(mgr, &FOLDERID_Windows, &csidl);
2227 ok(hr == S_OK, "failed to convert CSIDL to KNOWNFOLDERID: 0x%08x\n", hr);
2228 ok(csidl == CSIDL_WINDOWS, "invalid CSIDL returned\n");
2230 hr = IKnownFolderManager_GetFolder(mgr, &FOLDERID_Windows, &folder);
2231 ok(hr == S_OK, "failed to get known folder: 0x%08x\n", hr);
2232 if(SUCCEEDED(hr))
2234 hr = IKnownFolder_QueryInterface(folder, &IID_IMarshal, (void**)&unk);
2235 ok(hr == E_NOINTERFACE, "got 0x%08x\n", hr);
2237 hr = IKnownFolder_GetCategory(folder, &cat);
2238 ok(hr == S_OK, "failed to get folder category: 0x%08x\n", hr);
2239 ok(cat==KF_CATEGORY_FIXED, "invalid folder category: %d\n", cat);
2241 hr = IKnownFolder_GetId(folder, &folderId);
2242 ok(hr == S_OK, "failed to get folder id: 0x%08x\n", hr);
2243 ok(IsEqualGUID(&folderId, &FOLDERID_Windows)==TRUE, "invalid KNOWNFOLDERID returned\n");
2245 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
2246 ok(hr == S_OK, "failed to get path from known folder: 0x%08x\n", hr);
2247 ok(lstrcmpiW(sWinDir, folderPath)==0, "invalid path returned: \"%s\", expected: \"%s\"\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sWinDir));
2248 CoTaskMemFree(folderPath);
2250 hr = IKnownFolder_GetRedirectionCapabilities(folder, &redirectionCapabilities);
2251 ok(hr == S_OK, "failed to get redirection capabilities: 0x%08x\n", hr);
2252 todo_wine
2253 ok(redirectionCapabilities==0, "invalid redirection capabilities returned: %d\n", redirectionCapabilities);
2255 hr = IKnownFolder_SetPath(folder, 0, sWinDir);
2256 todo_wine
2257 ok(hr == E_INVALIDARG, "unexpected value from SetPath: 0x%08x\n", hr);
2259 hr = IKnownFolder_GetFolderDefinition(folder, &kfDefinition);
2260 ok(hr == S_OK, "failed to get folder definition: 0x%08x\n", hr);
2261 if(SUCCEEDED(hr))
2263 ok(kfDefinition.category==KF_CATEGORY_FIXED, "invalid folder category: 0x%08x\n", kfDefinition.category);
2264 ok(lstrcmpW(kfDefinition.pszName, sWindows)==0, "invalid folder name: %s\n", wine_dbgstr_w(kfDefinition.pszName));
2265 ok(kfDefinition.dwAttributes==0, "invalid folder attributes: %d\n", kfDefinition.dwAttributes);
2266 FreeKnownFolderDefinitionFields(&kfDefinition);
2269 hr = IKnownFolder_Release(folder);
2270 ok(hr == S_OK, "failed to release KnownFolder instance: 0x%08x\n", hr);
2273 hr = IKnownFolderManager_GetFolderByName(mgr, sWindows, &folder);
2274 ok(hr == S_OK, "failed to get known folder: 0x%08x\n", hr);
2275 if(SUCCEEDED(hr))
2277 hr = IKnownFolder_GetId(folder, &folderId);
2278 ok(hr == S_OK, "failed to get folder id: 0x%08x\n", hr);
2279 ok(IsEqualGUID(&folderId, &FOLDERID_Windows)==TRUE, "invalid KNOWNFOLDERID returned\n");
2281 hr = IKnownFolder_Release(folder);
2282 ok(hr == S_OK, "failed to release KnownFolder instance: 0x%08x\n", hr);
2285 hr = IKnownFolderManager_GetFolderByName(mgr, sWindows2, &folder);
2286 ok(hr == S_OK, "failed to get known folder: 0x%08x\n", hr);
2287 if(SUCCEEDED(hr))
2289 hr = IKnownFolder_GetId(folder, &folderId);
2290 ok(hr == S_OK, "failed to get folder id: 0x%08x\n", hr);
2291 ok(IsEqualGUID(&folderId, &FOLDERID_Windows)==TRUE, "invalid KNOWNFOLDERID returned\n");
2293 hr = IKnownFolder_Release(folder);
2294 ok(hr == S_OK, "failed to release KnownFolder instance: 0x%08x\n", hr);
2297 folder = (IKnownFolder *)0xdeadbeef;
2298 hr = IKnownFolderManager_GetFolderByName(mgr, sNoSuch, &folder);
2299 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "got 0x%08x\n", hr);
2300 ok(folder == NULL, "got %p\n", folder);
2302 for(i=0; i < ARRAY_SIZE(known_folder_found); ++i)
2303 known_folder_found[i] = FALSE;
2305 hr = IKnownFolderManager_GetFolderIds(mgr, &folders, &nCount);
2306 ok(hr == S_OK, "failed to get known folders: 0x%08x\n", hr);
2307 for(i=0;i<nCount;++i)
2308 check_known_folder(mgr, &folders[i]);
2310 for(i=0; i < ARRAY_SIZE(known_folder_found); ++i)
2311 if(!known_folder_found[i])
2312 trace("Known folder %s not found on current platform\n", known_folders[i].sFolderId);
2314 CoTaskMemFree(folders);
2316 /* test of registering new known folders */
2317 bRes = CreateDirectoryW(sExamplePath, NULL);
2318 ok(bRes, "cannot create example directory: %s\n", wine_dbgstr_w(sExamplePath));
2319 bRes = CreateDirectoryW(sExample2Path, NULL);
2320 ok(bRes, "cannot create example directory: %s\n", wine_dbgstr_w(sExample2Path));
2321 bRes = CreateDirectoryW(sSubFolderPath, NULL);
2322 ok(bRes, "cannot create example directory: %s\n", wine_dbgstr_w(sSubFolderPath));
2324 ZeroMemory(&kfDefinition, sizeof(kfDefinition));
2325 kfDefinition.category = KF_CATEGORY_PERUSER;
2326 kfDefinition.pszName = CoTaskMemAlloc(sizeof(sExample));
2327 lstrcpyW(kfDefinition.pszName, sExample);
2328 kfDefinition.pszDescription = CoTaskMemAlloc(sizeof(sExample));
2329 lstrcpyW(kfDefinition.pszDescription, sExample);
2330 kfDefinition.pszRelativePath = CoTaskMemAlloc(sizeof(sExamplePath));
2331 lstrcpyW(kfDefinition.pszRelativePath, sExamplePath);
2333 hr = IKnownFolderManager_RegisterFolder(mgr, &newFolderId, &kfDefinition);
2334 if(hr == HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED))
2335 win_skip("No permissions required to register custom known folder\n");
2336 else
2338 ok(hr == S_OK, "failed to register known folder: 0x%08x\n", hr);
2339 if(SUCCEEDED(hr))
2341 hr = IKnownFolderManager_GetFolder(mgr, &newFolderId, &folder);
2342 ok(hr == S_OK, "failed to get known folder: 0x%08x\n", hr);
2343 if(SUCCEEDED(hr))
2345 hr = IKnownFolder_GetCategory(folder, &cat);
2346 ok(hr == S_OK, "failed to get folder category: hr=0x%0x\n", hr);
2347 ok(cat == KF_CATEGORY_PERUSER, "invalid category returned: %d, while %d (KF_CATEGORY_PERUSER) expected\n", cat, KF_CATEGORY_PERUSER);
2349 hr = IKnownFolder_GetId(folder, &folderId);
2350 ok(hr == S_OK, "failed to get folder id: 0x%08x\n", hr);
2351 ok(IsEqualGUID(&folderId, &newFolderId)==TRUE, "invalid KNOWNFOLDERID returned\n");
2353 /* current path should be Temp\Example */
2354 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
2355 ok(hr == S_OK, "failed to get path from known folder: 0x%08x\n", hr);
2356 ok(lstrcmpiW(folderPath, sExamplePath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExamplePath));
2357 CoTaskMemFree(folderPath);
2359 /* register sub-folder and mark it as child of Example folder */
2360 ZeroMemory(&kfSubDefinition, sizeof(kfSubDefinition));
2361 kfSubDefinition.category = KF_CATEGORY_PERUSER;
2362 kfSubDefinition.pszName = CoTaskMemAlloc(sizeof(sSubFolder));
2363 lstrcpyW(kfSubDefinition.pszName, sSubFolder);
2364 kfSubDefinition.pszDescription = CoTaskMemAlloc(sizeof(sSubFolder));
2365 lstrcpyW(kfSubDefinition.pszDescription, sSubFolder);
2366 kfSubDefinition.pszRelativePath = CoTaskMemAlloc(sizeof(sSubFolder));
2367 lstrcpyW(kfSubDefinition.pszRelativePath, sSubFolder);
2368 kfSubDefinition.fidParent = newFolderId;
2370 hr = IKnownFolderManager_RegisterFolder(mgr, &subFolderId, &kfSubDefinition);
2371 ok(hr == S_OK, "failed to register known folder: 0x%08x\n", hr);
2372 if(SUCCEEDED(hr))
2375 hr = IKnownFolderManager_GetFolder(mgr, &subFolderId, &subFolder);
2376 ok(hr == S_OK, "failed to get known folder: 0x%08x\n", hr);
2377 if(SUCCEEDED(hr))
2379 /* check sub folder path */
2380 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
2381 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2382 ok(lstrcmpiW(folderPath, sSubFolderPath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolderPath));
2383 CoTaskMemFree(folderPath);
2386 /* try to redirect Example to Temp\Example2 */
2387 hr = IKnownFolderManager_Redirect(mgr, &newFolderId, NULL, 0, sExample2Path, 0, NULL, &errorMsg);
2388 ok(hr == S_OK, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr, wine_dbgstr_w(errorMsg));
2390 /* verify */
2391 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
2392 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2393 ok(lstrcmpiW(folderPath, sExample2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExample2Path));
2394 CoTaskMemFree(folderPath);
2396 /* verify sub folder - it should fail now, as we redirected its parent folder, but we have no sub folder in new location */
2397 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
2398 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "unexpected value from GetPath(): 0x%08x\n", hr);
2399 ok(folderPath==NULL, "invalid known folder path retrieved: \"%s\" when NULL pointer was expected\n", wine_dbgstr_w(folderPath));
2400 CoTaskMemFree(folderPath);
2403 /* set Example path to original. Using SetPath() is valid here, as it also uses redirection internally */
2404 hr = IKnownFolder_SetPath(folder, 0, sExamplePath);
2405 ok(hr == S_OK, "SetPath() failed: 0x%08x\n", hr);
2407 /* verify */
2408 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
2409 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2410 ok(lstrcmpiW(folderPath, sExamplePath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExamplePath));
2411 CoTaskMemFree(folderPath);
2414 /* create sub folder in Temp\Example2 */
2415 bRes = CreateDirectoryW(sSubFolder2Path, NULL);
2416 ok(bRes, "cannot create example directory: %s\n", wine_dbgstr_w(sSubFolder2Path));
2418 /* again perform that same redirection */
2419 hr = IKnownFolderManager_Redirect(mgr, &newFolderId, NULL, 0, sExample2Path, 0, NULL, &errorMsg);
2420 ok(hr == S_OK, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr, wine_dbgstr_w(errorMsg));
2422 /* verify sub folder. It should succeed now, as the required sub folder exists */
2423 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
2424 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2425 ok(lstrcmpiW(folderPath, sSubFolder2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolder2Path));
2426 CoTaskMemFree(folderPath);
2428 /* remove newly created directory */
2429 RemoveDirectoryW(sSubFolder2Path);
2431 /* verify subfolder. It still succeeds, so Windows does not check folder presence each time */
2432 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
2433 todo_wine
2434 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2435 todo_wine
2436 ok(lstrcmpiW(folderPath, sSubFolder2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolder2Path));
2437 CoTaskMemFree(folderPath);
2440 /* set Example path to original */
2441 hr = IKnownFolder_SetPath(folder, 0, sExamplePath);
2442 ok(hr == S_OK, "SetPath() failed: 0x%08x\n", hr);
2444 /* verify */
2445 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
2446 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2447 ok(lstrcmpiW(folderPath, sExamplePath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExamplePath));
2448 CoTaskMemFree(folderPath);
2450 /* verify sub folder */
2451 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
2452 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2453 ok(lstrcmpiW(folderPath, sSubFolderPath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolderPath));
2454 CoTaskMemFree(folderPath);
2457 /* create sub folder in Temp\Example2 */
2458 bRes = CreateDirectoryW(sSubFolder2Path, NULL);
2459 ok(bRes, "cannot create example directory: %s\n", wine_dbgstr_w(sSubFolder2Path));
2461 /* do that same redirection, but try to exclude sub-folder */
2462 hr = IKnownFolderManager_Redirect(mgr, &newFolderId, NULL, 0, sExample2Path, 1, &subFolderId, &errorMsg);
2463 ok(hr == S_OK, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr, wine_dbgstr_w(errorMsg));
2465 /* verify */
2466 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
2467 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2468 ok(lstrcmpiW(folderPath, sExample2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExample2Path));
2469 CoTaskMemFree(folderPath);
2471 /* 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 */
2472 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
2473 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2474 ok(lstrcmpiW(folderPath, sSubFolder2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolder2Path));
2475 CoTaskMemFree(folderPath);
2477 /* remove newly created directory */
2478 RemoveDirectoryW(sSubFolder2Path);
2481 /* set Example path to original */
2482 hr = IKnownFolder_SetPath(folder, 0, sExamplePath);
2483 ok(hr == S_OK, "SetPath() failed: 0x%08x\n", hr);
2485 /* verify */
2486 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
2487 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2488 ok(lstrcmpiW(folderPath, sExamplePath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExamplePath));
2489 CoTaskMemFree(folderPath);
2491 /* verify sub folder */
2492 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
2493 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2494 ok(lstrcmpiW(folderPath, sSubFolderPath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolderPath));
2495 CoTaskMemFree(folderPath);
2498 /* do that same redirection again, but set it to copy content. It should also copy the sub folder, so checking it would succeed now */
2499 hr = IKnownFolderManager_Redirect(mgr, &newFolderId, NULL, KF_REDIRECT_COPY_CONTENTS, sExample2Path, 0, NULL, &errorMsg);
2500 ok(hr == S_OK, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr, wine_dbgstr_w(errorMsg));
2502 /* verify */
2503 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
2504 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2505 ok(lstrcmpiW(folderPath, sExample2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExample2Path));
2506 CoTaskMemFree(folderPath);
2508 /* verify sub folder */
2509 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
2510 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2511 ok(lstrcmpiW(folderPath, sSubFolder2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolder2Path));
2512 CoTaskMemFree(folderPath);
2514 /* remove copied directory */
2515 RemoveDirectoryW(sSubFolder2Path);
2518 /* set Example path to original */
2519 hr = IKnownFolder_SetPath(folder, 0, sExamplePath);
2520 ok(hr == S_OK, "SetPath() failed: 0x%08x\n", hr);
2522 /* verify */
2523 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
2524 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2525 ok(lstrcmpiW(folderPath, sExamplePath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExamplePath));
2526 CoTaskMemFree(folderPath);
2528 /* verify sub folder */
2529 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
2530 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2531 ok(lstrcmpiW(folderPath, sSubFolderPath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolderPath));
2532 CoTaskMemFree(folderPath);
2535 /* redirect again, set it to copy content and remove originals */
2536 hr = IKnownFolderManager_Redirect(mgr, &newFolderId, NULL, KF_REDIRECT_COPY_CONTENTS | KF_REDIRECT_DEL_SOURCE_CONTENTS, sExample2Path, 0, NULL, &errorMsg);
2537 ok(hr == S_OK, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr, wine_dbgstr_w(errorMsg));
2539 /* verify */
2540 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
2541 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2542 ok(lstrcmpiW(folderPath, sExample2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExample2Path));
2543 CoTaskMemFree(folderPath);
2545 /* verify sub folder */
2546 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
2547 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2548 ok(lstrcmpiW(folderPath, sSubFolder2Path)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolder2Path));
2549 CoTaskMemFree(folderPath);
2551 /* check if original directory was really removed */
2552 dwAttributes = GetFileAttributesW(sExamplePath);
2553 ok(dwAttributes==INVALID_FILE_ATTRIBUTES, "directory should not exist, but has attributes: 0x%08x\n", dwAttributes );
2556 /* redirect (with copy) to original path */
2557 hr = IKnownFolderManager_Redirect(mgr, &newFolderId, NULL, KF_REDIRECT_COPY_CONTENTS, sExamplePath, 0, NULL, &errorMsg);
2558 ok(hr == S_OK, "failed to redirect known folder: 0x%08x, errorMsg: %s\n", hr, wine_dbgstr_w(errorMsg));
2560 /* verify */
2561 hr = IKnownFolder_GetPath(folder, 0, &folderPath);
2562 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2563 ok(lstrcmpiW(folderPath, sExamplePath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sExamplePath));
2564 CoTaskMemFree(folderPath);
2566 /* verify sub folder */
2567 hr = IKnownFolder_GetPath(subFolder, 0, &folderPath);
2568 ok(hr == S_OK, "failed to get known folder path: 0x%08x\n", hr);
2569 ok(lstrcmpiW(folderPath, sSubFolderPath)==0, "invalid known folder path retrieved: \"%s\" when \"%s\" was expected\n", wine_dbgstr_w(folderPath), wine_dbgstr_w(sSubFolderPath));
2570 CoTaskMemFree(folderPath);
2572 /* check shell utility functions */
2573 if(!pSHGetKnownFolderPath || !pSHSetKnownFolderPath)
2574 todo_wine
2575 win_skip("cannot get SHGet/SetKnownFolderPath routines\n");
2576 else
2578 /* try to get current known folder path */
2579 hr = pSHGetKnownFolderPath(&newFolderId, 0, NULL, &folderPath);
2580 todo_wine
2581 ok(hr==S_OK, "cannot get known folder path: hr=0x%0x\n", hr);
2582 todo_wine
2583 ok(lstrcmpW(folderPath, sExamplePath)==0, "invalid path returned: %s\n", wine_dbgstr_w(folderPath));
2585 /* set it to new value */
2586 hr = pSHSetKnownFolderPath(&newFolderId, 0, NULL, sExample2Path);
2587 todo_wine
2588 ok(hr==S_OK, "cannot set known folder path: hr=0x%0x\n", hr);
2590 /* check if it changed */
2591 hr = pSHGetKnownFolderPath(&newFolderId, 0, NULL, &folderPath);
2592 todo_wine
2593 ok(hr==S_OK, "cannot get known folder path: hr=0x%0x\n", hr);
2594 todo_wine
2595 ok(lstrcmpW(folderPath, sExample2Path)==0, "invalid path returned: %s\n", wine_dbgstr_w(folderPath));
2597 /* set it back */
2598 hr = pSHSetKnownFolderPath(&newFolderId, 0, NULL, sExamplePath);
2599 todo_wine
2600 ok(hr==S_OK, "cannot set known folder path: hr=0x%0x\n", hr);
2603 IKnownFolder_Release(subFolder);
2606 hr = IKnownFolderManager_UnregisterFolder(mgr, &subFolderId);
2607 ok(hr == S_OK, "failed to unregister folder: 0x%08x\n", hr);
2610 FreeKnownFolderDefinitionFields(&kfSubDefinition);
2612 hr = IKnownFolder_Release(folder);
2613 ok(hr == S_OK, "failed to release KnownFolder instance: 0x%08x\n", hr);
2615 /* update the folder */
2616 CoTaskMemFree(kfDefinition.pszName);
2617 kfDefinition.pszName = CoTaskMemAlloc(sizeof(sExample2));
2618 lstrcpyW(kfDefinition.pszName, sExample2);
2619 hr = IKnownFolderManager_RegisterFolder(mgr, &newFolderId, &kfDefinition);
2620 ok(hr == S_OK, "failed to re-register known folder: 0x%08x\n", hr);
2622 hr = IKnownFolderManager_GetFolder(mgr, &newFolderId, &folder);
2623 ok(hr == S_OK, "failed to get known folder: 0x%08x\n", hr);
2625 hr = IKnownFolder_GetFolderDefinition(folder, &kfSubDefinition);
2626 ok(hr == S_OK, "failed to get folder definition: 0x%08x\n", hr);
2627 ok(!memcmp(kfDefinition.pszName, kfSubDefinition.pszName, sizeof(sExample2)),
2628 "Got wrong updated name: %s\n", wine_dbgstr_w(kfSubDefinition.pszName));
2630 FreeKnownFolderDefinitionFields(&kfSubDefinition);
2632 hr = IKnownFolder_Release(folder);
2633 ok(hr == S_OK, "failed to release KnownFolder instance: 0x%08x\n", hr);
2636 hr = IKnownFolderManager_UnregisterFolder(mgr, &newFolderId);
2637 ok(hr == S_OK, "failed to unregister folder: 0x%08x\n", hr);
2640 FreeKnownFolderDefinitionFields(&kfDefinition);
2642 RemoveDirectoryW(sSubFolder2Path);
2643 RemoveDirectoryW(sSubFolderPath);
2644 RemoveDirectoryW(sExamplePath);
2645 RemoveDirectoryW(sExample2Path);
2647 hr = IKnownFolderManager_Release(mgr);
2648 ok(hr == S_OK, "failed to release KnownFolderManager instance: 0x%08x\n", hr);
2650 CoUninitialize();
2654 static void test_DoEnvironmentSubst(void)
2656 WCHAR expectedW[MAX_PATH];
2657 WCHAR bufferW[MAX_PATH];
2658 CHAR expectedA[MAX_PATH];
2659 CHAR bufferA[MAX_PATH];
2660 DWORD res;
2661 DWORD res2;
2662 DWORD len;
2663 INT i;
2664 static const WCHAR does_not_existW[] = {'%','D','O','E','S','_','N','O','T','_','E','X','I','S','T','%',0};
2665 static const CHAR does_not_existA[] = "%DOES_NOT_EXIST%";
2666 static const CHAR *names[] = {
2667 /* interactive apps and services (works on all windows versions) */
2668 "%ALLUSERSPROFILE%", "%APPDATA%", "%LOCALAPPDATA%",
2669 "%NUMBER_OF_PROCESSORS%", "%OS%", "%PROCESSOR_ARCHITECTURE%",
2670 "%PROCESSOR_IDENTIFIER%", "%PROCESSOR_LEVEL%", "%PROCESSOR_REVISION%",
2671 "%ProgramFiles%", "%SystemDrive%",
2672 "%SystemRoot%", "%USERPROFILE%", "%windir%",
2673 /* todo_wine: "%COMPUTERNAME%", "%ProgramData%", "%PUBLIC%", */
2675 /* replace more than one var is allowed */
2676 "%HOMEDRIVE%%HOMEPATH%",
2677 "%OS% %windir%"}; /* always the last entry in the table */
2679 for (i = 0; i < ARRAY_SIZE(names); i++)
2681 winetest_push_context("%d", i);
2682 memset(bufferA, '#', MAX_PATH - 1);
2683 bufferA[MAX_PATH - 1] = 0;
2684 lstrcpyA(bufferA, names[i]);
2685 MultiByteToWideChar(CP_ACP, 0, bufferA, MAX_PATH, bufferW, ARRAY_SIZE(bufferW));
2687 res2 = ExpandEnvironmentStringsA(names[i], expectedA, MAX_PATH);
2688 res = DoEnvironmentSubstA(bufferA, MAX_PATH);
2690 /* is the space for the terminating 0 included? */
2691 if (!i && HIWORD(res) && (LOWORD(res) == (lstrlenA(bufferA))))
2693 win_skip("DoEnvironmentSubstA/W are broken on NT 4\n");
2694 winetest_pop_context();
2695 return;
2697 ok(HIWORD(res) && (LOWORD(res) == res2),
2698 "got %d/%d (expected TRUE/%d)\n", HIWORD(res), LOWORD(res), res2);
2699 ok(!lstrcmpA(bufferA, expectedA),
2700 "got %s (expected %s)\n", bufferA, expectedA);
2702 res2 = ExpandEnvironmentStringsW(bufferW, expectedW, MAX_PATH);
2703 res = DoEnvironmentSubstW(bufferW, MAX_PATH);
2704 ok(HIWORD(res) && (LOWORD(res) == res2),
2705 "got %d/%d (expected TRUE/%d)\n", HIWORD(res), LOWORD(res), res2);
2706 ok(!lstrcmpW(bufferW, expectedW),
2707 "got %s (expected %s)\n", wine_dbgstr_w(bufferW), wine_dbgstr_w(expectedW));
2708 winetest_pop_context();
2711 i--; /* reuse data in the last table entry */
2712 len = LOWORD(res); /* needed length */
2714 /* one character extra is fine */
2715 memset(bufferA, '#', MAX_PATH - 1);
2716 bufferA[len + 2] = 0;
2717 lstrcpyA(bufferA, names[i]);
2718 MultiByteToWideChar(CP_ACP, 0, bufferA, MAX_PATH, bufferW, ARRAY_SIZE(bufferW));
2720 res2 = ExpandEnvironmentStringsA(bufferA, expectedA, MAX_PATH);
2721 res = DoEnvironmentSubstA(bufferA, len + 1);
2722 ok(HIWORD(res) && (LOWORD(res) == res2),
2723 "+1: got %d/%d (expected TRUE/%d)\n", HIWORD(res), LOWORD(res), res2);
2724 ok(!lstrcmpA(bufferA, expectedA),
2725 "+1: got %s (expected %s)\n", bufferA, expectedA);
2727 res2 = ExpandEnvironmentStringsW(bufferW, expectedW, MAX_PATH);
2728 res = DoEnvironmentSubstW(bufferW, len + 1);
2729 ok(HIWORD(res) && (LOWORD(res) == res2),
2730 "+1: got %d/%d (expected TRUE/%d)\n", HIWORD(res), LOWORD(res), res2);
2731 ok(!lstrcmpW(bufferW, expectedW),
2732 "+1: got %s (expected %s)\n", wine_dbgstr_w(bufferW), wine_dbgstr_w(expectedW));
2735 /* minimal buffer length (result string and terminating 0) */
2736 memset(bufferA, '#', MAX_PATH - 1);
2737 bufferA[len + 2] = 0;
2738 lstrcpyA(bufferA, names[i]);
2739 MultiByteToWideChar(CP_ACP, 0, bufferA, MAX_PATH, bufferW, ARRAY_SIZE(bufferW));
2741 /* ANSI version failed without an extra byte, as documented on msdn */
2742 res = DoEnvironmentSubstA(bufferA, len);
2743 ok(!HIWORD(res) && (LOWORD(res) == len),
2744 " 0: got %d/%d (expected FALSE/%d)\n", HIWORD(res), LOWORD(res), len);
2745 ok(!lstrcmpA(bufferA, names[i]),
2746 " 0: got %s (expected %s)\n", bufferA, names[i]);
2748 /* DoEnvironmentSubstW works as expected */
2749 res2 = ExpandEnvironmentStringsW(bufferW, expectedW, MAX_PATH);
2750 res = DoEnvironmentSubstW(bufferW, len);
2751 ok(HIWORD(res) && (LOWORD(res) == res2),
2752 " 0: got %d/%d (expected TRUE/%d)\n", HIWORD(res), LOWORD(res), res2);
2753 ok(!lstrcmpW(bufferW, expectedW),
2754 " 0: got %s (expected %s)\n", wine_dbgstr_w(bufferW), wine_dbgstr_w(expectedW));
2757 /* Buffer too small */
2758 /* result: FALSE / provided buffer length / the buffer is untouched */
2759 memset(bufferA, '#', MAX_PATH - 1);
2760 bufferA[len + 2] = 0;
2761 lstrcpyA(bufferA, names[i]);
2762 MultiByteToWideChar(CP_ACP, 0, bufferA, MAX_PATH, bufferW, ARRAY_SIZE(bufferW));
2764 res = DoEnvironmentSubstA(bufferA, len - 1);
2765 ok(!HIWORD(res) && (LOWORD(res) == (len - 1)),
2766 "-1: got %d/%d (expected FALSE/%d)\n", HIWORD(res), LOWORD(res), len - 1);
2767 ok(!lstrcmpA(bufferA, names[i]),
2768 "-1: got %s (expected %s)\n", bufferA, names[i]);
2770 lstrcpyW(expectedW, bufferW);
2771 res = DoEnvironmentSubstW(bufferW, len - 1);
2772 ok(!HIWORD(res) && (LOWORD(res) == (len - 1)),
2773 "-1: got %d/%d (expected FALSE/%d)\n", HIWORD(res), LOWORD(res), len - 1);
2774 ok(!lstrcmpW(bufferW, expectedW),
2775 "-1: got %s (expected %s)\n", wine_dbgstr_w(bufferW), wine_dbgstr_w(expectedW));
2778 /* unknown variable */
2779 /* result: TRUE / string length including terminating 0 / the buffer is untouched */
2780 memset(bufferA, '#', MAX_PATH - 1);
2781 bufferA[MAX_PATH - 1] = 0;
2782 lstrcpyA(bufferA, does_not_existA);
2783 MultiByteToWideChar(CP_ACP, 0, bufferA, MAX_PATH, bufferW, ARRAY_SIZE(bufferW));
2785 res2 = lstrlenA(does_not_existA) + 1;
2786 res = DoEnvironmentSubstA(bufferA, MAX_PATH);
2787 ok(HIWORD(res) && (LOWORD(res) == res2),
2788 "%d: got %d/%d (expected TRUE/%d)\n", i, HIWORD(res), LOWORD(res), res2);
2789 ok(!lstrcmpA(bufferA, does_not_existA),
2790 "%d: got %s (expected %s)\n", i, bufferA, does_not_existA);
2792 res = DoEnvironmentSubstW(bufferW, MAX_PATH);
2793 ok(HIWORD(res) && (LOWORD(res) == res2),
2794 "%d: got %d/%d (expected TRUE/%d)\n", i, HIWORD(res), LOWORD(res), res2);
2795 ok(!lstrcmpW(bufferW, does_not_existW),
2796 "%d: got %s (expected %s)\n", i, wine_dbgstr_w(bufferW), wine_dbgstr_w(does_not_existW));
2799 if (0)
2801 /* NULL crashes on windows */
2802 res = DoEnvironmentSubstA(NULL, MAX_PATH);
2803 res = DoEnvironmentSubstW(NULL, MAX_PATH);
2807 static void test_PathYetAnotherMakeUniqueName(void)
2809 static const WCHAR shortW[] = {'f','i','l','e','.','t','s','t',0};
2810 static const WCHAR short2W[] = {'f','i','l','e',' ','(','2',')','.','t','s','t',0};
2811 static const WCHAR tmpW[] = {'t','m','p',0};
2812 static const WCHAR longW[] = {'n','a','m','e',0};
2813 static const WCHAR long2W[] = {'n','a','m','e',' ','(','2',')',0};
2814 WCHAR nameW[MAX_PATH], buffW[MAX_PATH], pathW[MAX_PATH];
2815 HANDLE file;
2816 BOOL ret;
2818 if (!pPathYetAnotherMakeUniqueName)
2820 win_skip("PathYetAnotherMakeUniqueName() is not available.\n");
2821 return;
2824 if (0)
2826 /* crashes on Windows */
2827 ret = pPathYetAnotherMakeUniqueName(NULL, NULL, NULL, NULL);
2828 ok(!ret, "got %d\n", ret);
2830 ret = pPathYetAnotherMakeUniqueName(nameW, NULL, NULL, NULL);
2831 ok(!ret, "got %d\n", ret);
2834 GetTempPathW(ARRAY_SIZE(pathW), pathW);
2836 /* Using short name only first */
2837 nameW[0] = 0;
2838 ret = pPathYetAnotherMakeUniqueName(nameW, pathW, shortW, NULL);
2839 ok(ret, "got %d\n", ret);
2840 lstrcpyW(buffW, pathW);
2841 lstrcatW(buffW, shortW);
2842 ok(!lstrcmpW(nameW, buffW), "got %s, expected %s\n", wine_dbgstr_w(nameW), wine_dbgstr_w(buffW));
2844 /* now create a file with this name and get next name */
2845 file = CreateFileW(nameW, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, NULL);
2846 ok(file != NULL, "got %p\n", file);
2848 nameW[0] = 0;
2849 ret = pPathYetAnotherMakeUniqueName(nameW, pathW, shortW, NULL);
2850 ok(ret, "got %d\n", ret);
2851 lstrcpyW(buffW, pathW);
2852 lstrcatW(buffW, short2W);
2853 ok(!lstrcmpW(nameW, buffW), "got %s, expected %s\n", wine_dbgstr_w(nameW), wine_dbgstr_w(buffW));
2855 CloseHandle(file);
2857 /* Using short and long */
2858 nameW[0] = 0;
2859 ret = pPathYetAnotherMakeUniqueName(nameW, pathW, tmpW, longW);
2860 ok(ret, "got %d\n", ret);
2861 lstrcpyW(buffW, pathW);
2862 lstrcatW(buffW, longW);
2863 ok(!lstrcmpW(nameW, buffW), "got %s, expected %s\n", wine_dbgstr_w(nameW), wine_dbgstr_w(buffW));
2865 file = CreateFileW(nameW, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, NULL);
2866 ok(file != NULL, "got %p\n", file);
2868 nameW[0] = 0;
2869 ret = pPathYetAnotherMakeUniqueName(nameW, pathW, tmpW, longW);
2870 ok(ret, "got %d\n", ret);
2871 lstrcpyW(buffW, pathW);
2872 lstrcatW(buffW, long2W);
2873 ok(!lstrcmpW(nameW, buffW), "got %s, expected %s\n", wine_dbgstr_w(nameW), wine_dbgstr_w(buffW));
2875 CloseHandle(file);
2877 /* Using long only */
2878 nameW[0] = 0;
2879 ret = pPathYetAnotherMakeUniqueName(nameW, pathW, NULL, longW);
2880 ok(ret, "got %d\n", ret);
2881 lstrcpyW(buffW, pathW);
2882 lstrcatW(buffW, longW);
2883 ok(!lstrcmpW(nameW, buffW), "got %s, expected %s\n", wine_dbgstr_w(nameW), wine_dbgstr_w(buffW));
2886 static void test_SHGetKnownFolderIDList(void)
2888 PIDLIST_ABSOLUTE pidl;
2889 HRESULT hr;
2891 if (!pSHGetKnownFolderIDList)
2893 win_skip("SHGetKnownFolderIDList is not available.\n");
2894 return;
2897 hr = pSHGetKnownFolderIDList(NULL, 0, NULL, NULL);
2898 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
2900 if (0) { /* crashes on native */
2901 pidl = (void*)0xdeadbeef;
2902 hr = pSHGetKnownFolderIDList(NULL, 0, NULL, &pidl);
2904 /* not a known folder */
2905 pidl = (void*)0xdeadbeef;
2906 hr = pSHGetKnownFolderIDList(&IID_IUnknown, 0, NULL, &pidl);
2907 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "got 0x%08x\n", hr);
2908 ok(pidl == NULL, "got %p\n", pidl);
2910 hr = pSHGetKnownFolderIDList(&FOLDERID_Desktop, 0, NULL, NULL);
2911 ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
2913 pidl = (void*)0xdeadbeef;
2914 hr = pSHGetKnownFolderIDList(&FOLDERID_Desktop, 0, NULL, &pidl);
2915 ok(hr == S_OK, "SHGetKnownFolderIDList failed: 0x%08x\n", hr);
2916 ok(ILIsEmpty(pidl), "pidl should be empty.\n");
2917 ok(pidl->mkid.cb == 0, "get wrong value: %d\n", pidl->mkid.cb);
2918 ILFree(pidl);
2920 pidl = (void*)0xdeadbeef;
2921 hr = pSHGetKnownFolderIDList(&FOLDERID_Desktop, KF_FLAG_NO_ALIAS, NULL, &pidl);
2922 ok(hr == S_OK, "SHGetKnownFolderIDList failed: 0x%08x\n", hr);
2923 todo_wine ok(!ILIsEmpty(pidl), "pidl should not be empty.\n");
2924 todo_wine ok(pidl->mkid.cb == 20, "get wrong value: %d\n", pidl->mkid.cb);
2925 ILFree(pidl);
2927 pidl = (void*)0xdeadbeef;
2928 hr = pSHGetKnownFolderIDList(&FOLDERID_Documents, 0, NULL, &pidl);
2929 ok(hr == S_OK, "SHGetKnownFolderIDList failed: 0x%08x\n", hr);
2930 ok(!ILIsEmpty(pidl), "pidl should not be empty.\n");
2931 ok(pidl->mkid.cb == 20, "get wrong value: %d\n", pidl->mkid.cb);
2932 ILFree(pidl);
2934 pidl = (void*)0xdeadbeef;
2935 hr = pSHGetKnownFolderIDList(&FOLDERID_Documents, KF_FLAG_NO_ALIAS, NULL, &pidl);
2936 ok(hr == S_OK, "SHGetKnownFolderIDList failed: 0x%08x\n", hr);
2937 ok(!ILIsEmpty(pidl), "pidl should not be empty.\n");
2938 ok(pidl->mkid.cb == 20, "get wrong value: %d\n", pidl->mkid.cb);
2939 ILFree(pidl);
2942 static void test_PathResolve(void)
2944 WCHAR testfile[MAX_PATH], testfile_lnk[MAX_PATH], regedit_in_testdir[MAX_PATH], regedit_cmd[MAX_PATH];
2945 WCHAR tempdir[MAX_PATH], path[MAX_PATH];
2946 const WCHAR *dirs[2] = { tempdir, NULL };
2947 HANDLE file, file2;
2948 BOOL ret;
2949 int i;
2950 struct {
2951 const WCHAR *path;
2952 UINT flags;
2953 BOOL expected;
2954 const WCHAR *expected_path;
2955 } tests[] = {
2956 /* no flags */
2957 { L"test", 0, FALSE, L"test" },
2958 { L"C:\\test", 0, TRUE, L"C:\\test" },
2959 { L"regedit", 0, FALSE, L"regedit" },
2960 { testfile, 0, TRUE, testfile },
2962 /* PRF_VERIFYEXISTS */
2963 { L"test", PRF_VERIFYEXISTS, TRUE, testfile_lnk },
2964 { L"C:\\test", PRF_VERIFYEXISTS, FALSE, L"C:\\test" },
2965 /* common extensions are tried even if PRF_TRYPROGRAMEXTENSIONS isn't passed */
2966 /* directories in dirs parameter are always searched first even if PRF_FIRSTDIRDEF isn't passed */
2967 { L"regedit", PRF_VERIFYEXISTS, TRUE, regedit_cmd },
2968 /* .dll is not tried */
2969 { L"bcrypt", PRF_VERIFYEXISTS, FALSE, L"bcrypt" },
2970 { testfile, PRF_VERIFYEXISTS, TRUE, testfile_lnk },
2971 { regedit_in_testdir, PRF_VERIFYEXISTS, TRUE, regedit_cmd },
2973 /* PRF_FIRSTDIRDEF */
2974 { L"regedit", PRF_FIRSTDIRDEF, FALSE, L"regedit" },
2976 /* RF_VERIFYEXISTS | PRF_FIRSTDIRDEF */
2977 { L"regedit", PRF_VERIFYEXISTS | PRF_FIRSTDIRDEF, TRUE, regedit_cmd },
2979 /* PRF_DONTFINDLNK */
2980 { testfile, PRF_DONTFINDLNK, TRUE, testfile },
2981 { regedit_in_testdir, PRF_DONTFINDLNK, TRUE, regedit_in_testdir },
2983 /* RF_VERIFYEXISTS | PRF_DONTFINDLNK */
2984 { testfile, PRF_VERIFYEXISTS | PRF_DONTFINDLNK, FALSE, testfile },
2985 /* cmd is also ignored when passing PRF_VERIFYEXISTS | PRF_DONTFINDLNK */
2986 { regedit_in_testdir, PRF_VERIFYEXISTS | PRF_DONTFINDLNK, FALSE, regedit_in_testdir },
2988 /* PRF_VERIFYEXISTS | PRF_REQUIREABSOLUTE */
2989 /* only PRF_VERIFYEXISTS matters*/
2990 { L"test", PRF_VERIFYEXISTS | PRF_REQUIREABSOLUTE, TRUE, testfile_lnk },
2991 { L"C:\\test", PRF_VERIFYEXISTS | PRF_REQUIREABSOLUTE, FALSE, L"C:\\test" },
2992 { L"regedit", PRF_VERIFYEXISTS | PRF_REQUIREABSOLUTE, TRUE, regedit_cmd },
2993 { testfile, PRF_VERIFYEXISTS | PRF_REQUIREABSOLUTE, TRUE, testfile_lnk },
2995 /* PRF_TRYPROGRAMEXTENSIONS */
2996 { L"test", PRF_TRYPROGRAMEXTENSIONS, TRUE, testfile_lnk},
2997 { L"C:\\test", PRF_TRYPROGRAMEXTENSIONS, FALSE, L"C:\\test" },
2998 { L"regedit", PRF_TRYPROGRAMEXTENSIONS, TRUE, regedit_cmd },
2999 /* .dll is not tried */
3000 { L"bcrypt", PRF_TRYPROGRAMEXTENSIONS, FALSE, L"bcrypt" },
3001 { testfile, PRF_TRYPROGRAMEXTENSIONS, TRUE, testfile_lnk },
3002 { regedit_in_testdir, PRF_TRYPROGRAMEXTENSIONS, TRUE, regedit_cmd },
3004 /* PRF_TRYPROGRAMEXTENSIONS | PRF_DONTFINDLNK */
3005 { testfile, PRF_TRYPROGRAMEXTENSIONS | PRF_DONTFINDLNK, FALSE, testfile },
3006 /* cmd is also ignored when passing PRF_TRYPROGRAMEXTENSIONS | PRF_DONTFINDLNK */
3007 { regedit_in_testdir, PRF_TRYPROGRAMEXTENSIONS | PRF_DONTFINDLNK, FALSE, regedit_in_testdir }
3010 if (!pPathResolve)
3012 win_skip("PathResolve not available\n");
3013 return;
3016 GetTempPathW(MAX_PATH, tempdir);
3018 lstrcpyW(testfile, tempdir);
3019 lstrcatW(testfile, L"test");
3020 lstrcpyW(testfile_lnk, testfile);
3021 lstrcatW(testfile_lnk, L".lnk");
3023 file = CreateFileW(testfile_lnk, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, NULL);
3024 ok(file != INVALID_HANDLE_VALUE, "got %p\n", file);
3026 lstrcpyW(regedit_in_testdir, tempdir);
3027 lstrcatW(regedit_in_testdir, L"regedit");
3028 lstrcpyW(regedit_cmd, regedit_in_testdir);
3029 lstrcatW(regedit_cmd, L".cmd");
3031 file2 = CreateFileW(regedit_cmd, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, NULL);
3032 ok(file2 != INVALID_HANDLE_VALUE, "got %p\n", file);
3034 /* show that resolving regedit with NULL dirs returns regedit.exe */
3035 lstrcpyW(path, L"regedit");
3036 ret = pPathResolve(path, NULL, PRF_VERIFYEXISTS);
3037 ok(ret, "resolving regedit failed unexpectedly\n");
3038 ok(!lstrcmpiW(path, L"C:\\windows\\regedit.exe") || !lstrcmpiW(path, L"C:\\windows\\system32\\regedit.exe"),
3039 "unexpected path %s\n", wine_dbgstr_w(path));
3041 for (i = 0; i < ARRAY_SIZE(tests); i++)
3043 winetest_push_context("test %d", i);
3044 lstrcpyW(path, tests[i].path);
3046 if (!tests[i].expected) SetLastError(0xdeadbeef);
3047 ret = pPathResolve(path, dirs, tests[i].flags);
3048 ok(ret == tests[i].expected, "expected %d, got %d\n", tests[i].expected, ret);
3049 ok(!lstrcmpiW(path, tests[i].expected_path),
3050 "expected %s, got %s\n", wine_dbgstr_w(tests[i].expected_path), wine_dbgstr_w(path));
3051 if (!tests[i].expected)
3052 ok(GetLastError() == ERROR_FILE_NOT_FOUND ||
3053 broken(GetLastError() == ERROR_PATH_NOT_FOUND /* some win 8.1 & 10 */),
3054 "expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
3055 winetest_pop_context();
3058 CloseHandle(file);
3059 CloseHandle(file2);
3062 START_TEST(shellpath)
3064 if (!init()) return;
3066 loadShell32();
3067 pGetSystemWow64DirectoryA = (void *)GetProcAddress( GetModuleHandleA("kernel32.dll"),
3068 "GetSystemWow64DirectoryA" );
3069 if (myARGC >= 3)
3070 doChild(myARGV[2]);
3071 else
3073 /* first test various combinations of parameters: */
3074 test_parameters();
3076 /* check known values: */
3077 test_PidlTypes();
3078 test_GUIDs();
3079 test_EnvVars();
3080 testWinDir();
3081 testSystemDir();
3082 test_NonExistentPath();
3083 test_SHGetFolderPathEx();
3084 test_knownFolders();
3085 test_DoEnvironmentSubst();
3086 test_PathYetAnotherMakeUniqueName();
3087 test_SHGetKnownFolderIDList();
3088 test_PathResolve();