advapi32/tests: Show that child processes do not inherit mandatory labels.
[wine.git] / dlls / shell32 / shellpath.c
blobd2ebc66bc444df565b8fef629c14ee8c2531be9d
1 /*
2 * Path Functions
4 * Copyright 1998, 1999, 2000 Juergen Schmied
5 * Copyright 2004 Juan Lang
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 * NOTES:
23 * Many of these functions are in SHLWAPI.DLL also
27 #define COBJMACROS
29 #include "config.h"
30 #include "wine/port.h"
32 #include <stdio.h>
33 #include <stdarg.h>
34 #include <string.h>
35 #include <ctype.h>
36 #include "wine/debug.h"
37 #include "windef.h"
38 #include "winbase.h"
39 #include "winnls.h"
40 #include "winreg.h"
41 #include "wingdi.h"
42 #include "winuser.h"
44 #include "shlobj.h"
45 #include "shtypes.h"
46 #include "shresdef.h"
47 #include "shell32_main.h"
48 #include "undocshell.h"
49 #include "pidl.h"
50 #include "wine/unicode.h"
51 #include "shlwapi.h"
52 #include "xdg.h"
53 #include "sddl.h"
54 #include "knownfolders.h"
55 #include "initguid.h"
56 #include "shobjidl.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(shell);
60 static const BOOL is_win64 = sizeof(void *) > sizeof(int);
63 ########## Combining and Constructing paths ##########
66 /*************************************************************************
67 * PathAppend [SHELL32.36]
69 BOOL WINAPI PathAppendAW(
70 LPVOID lpszPath1,
71 LPCVOID lpszPath2)
73 if (SHELL_OsIsUnicode())
74 return PathAppendW(lpszPath1, lpszPath2);
75 return PathAppendA(lpszPath1, lpszPath2);
78 /*************************************************************************
79 * PathCombine [SHELL32.37]
81 LPVOID WINAPI PathCombineAW(
82 LPVOID szDest,
83 LPCVOID lpszDir,
84 LPCVOID lpszFile)
86 if (SHELL_OsIsUnicode())
87 return PathCombineW( szDest, lpszDir, lpszFile );
88 return PathCombineA( szDest, lpszDir, lpszFile );
91 /*************************************************************************
92 * PathAddBackslash [SHELL32.32]
94 LPVOID WINAPI PathAddBackslashAW(LPVOID lpszPath)
96 if(SHELL_OsIsUnicode())
97 return PathAddBackslashW(lpszPath);
98 return PathAddBackslashA(lpszPath);
101 /*************************************************************************
102 * PathBuildRoot [SHELL32.30]
104 LPVOID WINAPI PathBuildRootAW(LPVOID lpszPath, int drive)
106 if(SHELL_OsIsUnicode())
107 return PathBuildRootW(lpszPath, drive);
108 return PathBuildRootA(lpszPath, drive);
112 Extracting Component Parts
115 /*************************************************************************
116 * PathFindFileName [SHELL32.34]
118 LPVOID WINAPI PathFindFileNameAW(LPCVOID lpszPath)
120 if(SHELL_OsIsUnicode())
121 return PathFindFileNameW(lpszPath);
122 return PathFindFileNameA(lpszPath);
125 /*************************************************************************
126 * PathFindExtension [SHELL32.31]
128 LPVOID WINAPI PathFindExtensionAW(LPCVOID lpszPath)
130 if (SHELL_OsIsUnicode())
131 return PathFindExtensionW(lpszPath);
132 return PathFindExtensionA(lpszPath);
136 /*************************************************************************
137 * PathGetExtensionA [internal]
139 * NOTES
140 * exported by ordinal
141 * return value points to the first char after the dot
143 static LPSTR PathGetExtensionA(LPCSTR lpszPath)
145 TRACE("(%s)\n",lpszPath);
147 lpszPath = PathFindExtensionA(lpszPath);
148 return (LPSTR)(*lpszPath?(lpszPath+1):lpszPath);
151 /*************************************************************************
152 * PathGetExtensionW [internal]
154 static LPWSTR PathGetExtensionW(LPCWSTR lpszPath)
156 TRACE("(%s)\n",debugstr_w(lpszPath));
158 lpszPath = PathFindExtensionW(lpszPath);
159 return (LPWSTR)(*lpszPath?(lpszPath+1):lpszPath);
162 /*************************************************************************
163 * PathGetExtension [SHELL32.158]
165 LPVOID WINAPI PathGetExtensionAW(LPCVOID lpszPath,DWORD void1, DWORD void2)
167 if (SHELL_OsIsUnicode())
168 return PathGetExtensionW(lpszPath);
169 return PathGetExtensionA(lpszPath);
172 /*************************************************************************
173 * PathGetArgs [SHELL32.52]
175 LPVOID WINAPI PathGetArgsAW(LPVOID lpszPath)
177 if (SHELL_OsIsUnicode())
178 return PathGetArgsW(lpszPath);
179 return PathGetArgsA(lpszPath);
182 /*************************************************************************
183 * PathGetDriveNumber [SHELL32.57]
185 int WINAPI PathGetDriveNumberAW(LPVOID lpszPath)
187 if (SHELL_OsIsUnicode())
188 return PathGetDriveNumberW(lpszPath);
189 return PathGetDriveNumberA(lpszPath);
192 /*************************************************************************
193 * PathRemoveFileSpec [SHELL32.35]
195 BOOL WINAPI PathRemoveFileSpecAW(LPVOID lpszPath)
197 if (SHELL_OsIsUnicode())
198 return PathRemoveFileSpecW(lpszPath);
199 return PathRemoveFileSpecA(lpszPath);
202 /*************************************************************************
203 * PathStripPath [SHELL32.38]
205 void WINAPI PathStripPathAW(LPVOID lpszPath)
207 if (SHELL_OsIsUnicode())
208 PathStripPathW(lpszPath);
209 else
210 PathStripPathA(lpszPath);
213 /*************************************************************************
214 * PathStripToRoot [SHELL32.50]
216 BOOL WINAPI PathStripToRootAW(LPVOID lpszPath)
218 if (SHELL_OsIsUnicode())
219 return PathStripToRootW(lpszPath);
220 return PathStripToRootA(lpszPath);
223 /*************************************************************************
224 * PathRemoveArgs [SHELL32.251]
226 void WINAPI PathRemoveArgsAW(LPVOID lpszPath)
228 if (SHELL_OsIsUnicode())
229 PathRemoveArgsW(lpszPath);
230 else
231 PathRemoveArgsA(lpszPath);
234 /*************************************************************************
235 * PathRemoveExtension [SHELL32.250]
237 void WINAPI PathRemoveExtensionAW(LPVOID lpszPath)
239 if (SHELL_OsIsUnicode())
240 PathRemoveExtensionW(lpszPath);
241 else
242 PathRemoveExtensionA(lpszPath);
247 Path Manipulations
250 /*************************************************************************
251 * PathGetShortPathA [internal]
253 static void PathGetShortPathA(LPSTR pszPath)
255 CHAR path[MAX_PATH];
257 TRACE("%s\n", pszPath);
259 if (GetShortPathNameA(pszPath, path, MAX_PATH))
261 lstrcpyA(pszPath, path);
265 /*************************************************************************
266 * PathGetShortPathW [internal]
268 static void PathGetShortPathW(LPWSTR pszPath)
270 WCHAR path[MAX_PATH];
272 TRACE("%s\n", debugstr_w(pszPath));
274 if (GetShortPathNameW(pszPath, path, MAX_PATH))
276 lstrcpyW(pszPath, path);
280 /*************************************************************************
281 * PathGetShortPath [SHELL32.92]
283 VOID WINAPI PathGetShortPathAW(LPVOID pszPath)
285 if(SHELL_OsIsUnicode())
286 PathGetShortPathW(pszPath);
287 PathGetShortPathA(pszPath);
290 /*************************************************************************
291 * PathRemoveBlanks [SHELL32.33]
293 void WINAPI PathRemoveBlanksAW(LPVOID str)
295 if(SHELL_OsIsUnicode())
296 PathRemoveBlanksW(str);
297 else
298 PathRemoveBlanksA(str);
301 /*************************************************************************
302 * PathQuoteSpaces [SHELL32.55]
304 VOID WINAPI PathQuoteSpacesAW (LPVOID lpszPath)
306 if(SHELL_OsIsUnicode())
307 PathQuoteSpacesW(lpszPath);
308 else
309 PathQuoteSpacesA(lpszPath);
312 /*************************************************************************
313 * PathUnquoteSpaces [SHELL32.56]
315 VOID WINAPI PathUnquoteSpacesAW(LPVOID str)
317 if(SHELL_OsIsUnicode())
318 PathUnquoteSpacesW(str);
319 else
320 PathUnquoteSpacesA(str);
323 /*************************************************************************
324 * PathParseIconLocation [SHELL32.249]
326 int WINAPI PathParseIconLocationAW (LPVOID lpszPath)
328 if(SHELL_OsIsUnicode())
329 return PathParseIconLocationW(lpszPath);
330 return PathParseIconLocationA(lpszPath);
334 ########## Path Testing ##########
336 /*************************************************************************
337 * PathIsUNC [SHELL32.39]
339 BOOL WINAPI PathIsUNCAW (LPCVOID lpszPath)
341 if (SHELL_OsIsUnicode())
342 return PathIsUNCW( lpszPath );
343 return PathIsUNCA( lpszPath );
346 /*************************************************************************
347 * PathIsRelative [SHELL32.40]
349 BOOL WINAPI PathIsRelativeAW (LPCVOID lpszPath)
351 if (SHELL_OsIsUnicode())
352 return PathIsRelativeW( lpszPath );
353 return PathIsRelativeA( lpszPath );
356 /*************************************************************************
357 * PathIsRoot [SHELL32.29]
359 BOOL WINAPI PathIsRootAW(LPCVOID lpszPath)
361 if (SHELL_OsIsUnicode())
362 return PathIsRootW(lpszPath);
363 return PathIsRootA(lpszPath);
366 /*************************************************************************
367 * PathIsExeA [internal]
369 static BOOL PathIsExeA (LPCSTR lpszPath)
371 LPCSTR lpszExtension = PathGetExtensionA(lpszPath);
372 int i;
373 static const char * const lpszExtensions[] =
374 {"exe", "com", "pif", "cmd", "bat", "scf", "scr", NULL };
376 TRACE("path=%s\n",lpszPath);
378 for(i=0; lpszExtensions[i]; i++)
379 if (!lstrcmpiA(lpszExtension,lpszExtensions[i])) return TRUE;
381 return FALSE;
384 /*************************************************************************
385 * PathIsExeW [internal]
387 static BOOL PathIsExeW (LPCWSTR lpszPath)
389 LPCWSTR lpszExtension = PathGetExtensionW(lpszPath);
390 int i;
391 static const WCHAR lpszExtensions[][4] =
392 {{'e','x','e','\0'}, {'c','o','m','\0'}, {'p','i','f','\0'},
393 {'c','m','d','\0'}, {'b','a','t','\0'}, {'s','c','f','\0'},
394 {'s','c','r','\0'}, {'\0'} };
396 TRACE("path=%s\n",debugstr_w(lpszPath));
398 for(i=0; lpszExtensions[i][0]; i++)
399 if (!strcmpiW(lpszExtension,lpszExtensions[i])) return TRUE;
401 return FALSE;
404 /*************************************************************************
405 * PathIsExe [SHELL32.43]
407 BOOL WINAPI PathIsExeAW (LPCVOID path)
409 if (SHELL_OsIsUnicode())
410 return PathIsExeW (path);
411 return PathIsExeA(path);
414 /*************************************************************************
415 * PathIsDirectory [SHELL32.159]
417 BOOL WINAPI PathIsDirectoryAW (LPCVOID lpszPath)
419 if (SHELL_OsIsUnicode())
420 return PathIsDirectoryW (lpszPath);
421 return PathIsDirectoryA (lpszPath);
424 /*************************************************************************
425 * PathFileExists [SHELL32.45]
427 BOOL WINAPI PathFileExistsAW (LPCVOID lpszPath)
429 if (SHELL_OsIsUnicode())
430 return PathFileExistsW (lpszPath);
431 return PathFileExistsA (lpszPath);
434 /*************************************************************************
435 * PathMatchSpec [SHELL32.46]
437 BOOL WINAPI PathMatchSpecAW(LPVOID name, LPVOID mask)
439 if (SHELL_OsIsUnicode())
440 return PathMatchSpecW( name, mask );
441 return PathMatchSpecA( name, mask );
444 /*************************************************************************
445 * PathIsSameRoot [SHELL32.650]
447 BOOL WINAPI PathIsSameRootAW(LPCVOID lpszPath1, LPCVOID lpszPath2)
449 if (SHELL_OsIsUnicode())
450 return PathIsSameRootW(lpszPath1, lpszPath2);
451 return PathIsSameRootA(lpszPath1, lpszPath2);
454 /*************************************************************************
455 * IsLFNDriveA [SHELL32.41]
457 BOOL WINAPI IsLFNDriveA(LPCSTR lpszPath)
459 DWORD fnlen;
461 if (!GetVolumeInformationA(lpszPath, NULL, 0, NULL, &fnlen, NULL, NULL, 0))
462 return FALSE;
463 return fnlen > 12;
466 /*************************************************************************
467 * IsLFNDriveW [SHELL32.42]
469 BOOL WINAPI IsLFNDriveW(LPCWSTR lpszPath)
471 DWORD fnlen;
473 if (!GetVolumeInformationW(lpszPath, NULL, 0, NULL, &fnlen, NULL, NULL, 0))
474 return FALSE;
475 return fnlen > 12;
478 /*************************************************************************
479 * IsLFNDrive [SHELL32.119]
481 BOOL WINAPI IsLFNDriveAW(LPCVOID lpszPath)
483 if (SHELL_OsIsUnicode())
484 return IsLFNDriveW(lpszPath);
485 return IsLFNDriveA(lpszPath);
489 ########## Creating Something Unique ##########
491 /*************************************************************************
492 * PathMakeUniqueNameA [internal]
494 static BOOL PathMakeUniqueNameA(
495 LPSTR lpszBuffer,
496 DWORD dwBuffSize,
497 LPCSTR lpszShortName,
498 LPCSTR lpszLongName,
499 LPCSTR lpszPathName)
501 FIXME("%p %u %s %s %s stub\n",
502 lpszBuffer, dwBuffSize, debugstr_a(lpszShortName),
503 debugstr_a(lpszLongName), debugstr_a(lpszPathName));
504 return TRUE;
507 /*************************************************************************
508 * PathMakeUniqueNameW [internal]
510 static BOOL PathMakeUniqueNameW(
511 LPWSTR lpszBuffer,
512 DWORD dwBuffSize,
513 LPCWSTR lpszShortName,
514 LPCWSTR lpszLongName,
515 LPCWSTR lpszPathName)
517 FIXME("%p %u %s %s %s stub\n",
518 lpszBuffer, dwBuffSize, debugstr_w(lpszShortName),
519 debugstr_w(lpszLongName), debugstr_w(lpszPathName));
520 return TRUE;
523 /*************************************************************************
524 * PathMakeUniqueName [SHELL32.47]
526 BOOL WINAPI PathMakeUniqueNameAW(
527 LPVOID lpszBuffer,
528 DWORD dwBuffSize,
529 LPCVOID lpszShortName,
530 LPCVOID lpszLongName,
531 LPCVOID lpszPathName)
533 if (SHELL_OsIsUnicode())
534 return PathMakeUniqueNameW(lpszBuffer,dwBuffSize, lpszShortName,lpszLongName,lpszPathName);
535 return PathMakeUniqueNameA(lpszBuffer,dwBuffSize, lpszShortName,lpszLongName,lpszPathName);
538 /*************************************************************************
539 * PathYetAnotherMakeUniqueName [SHELL32.75]
541 BOOL WINAPI PathYetAnotherMakeUniqueName(LPWSTR buffer, LPCWSTR path, LPCWSTR shortname, LPCWSTR longname)
543 WCHAR pathW[MAX_PATH], retW[MAX_PATH];
544 const WCHAR *file, *ext;
545 int i = 2;
547 TRACE("(%p, %s, %s, %s)\n", buffer, debugstr_w(path), debugstr_w(shortname), debugstr_w(longname));
549 file = longname ? longname : shortname;
550 PathCombineW(pathW, path, file);
551 strcpyW(retW, pathW);
552 PathRemoveExtensionW(pathW);
554 ext = PathFindExtensionW(file);
556 /* now try to make it unique */
557 while (PathFileExistsW(retW))
559 static const WCHAR fmtW[] = {'%','s',' ','(','%','d',')','%','s',0};
561 sprintfW(retW, fmtW, pathW, i, ext);
562 i++;
565 strcpyW(buffer, retW);
566 TRACE("ret - %s\n", debugstr_w(buffer));
568 return TRUE;
572 ########## cleaning and resolving paths ##########
575 /*************************************************************************
576 * PathFindOnPath [SHELL32.145]
578 BOOL WINAPI PathFindOnPathAW(LPVOID sFile, LPCVOID *sOtherDirs)
580 if (SHELL_OsIsUnicode())
581 return PathFindOnPathW(sFile, (LPCWSTR *)sOtherDirs);
582 return PathFindOnPathA(sFile, (LPCSTR *)sOtherDirs);
585 /*************************************************************************
586 * PathCleanupSpec [SHELL32.171]
588 * lpszFile is changed in place.
590 int WINAPI PathCleanupSpec( LPCWSTR lpszPathW, LPWSTR lpszFileW )
592 int i = 0;
593 DWORD rc = 0;
594 int length = 0;
596 if (SHELL_OsIsUnicode())
598 LPWSTR p = lpszFileW;
600 TRACE("Cleanup %s\n",debugstr_w(lpszFileW));
602 if (lpszPathW)
603 length = strlenW(lpszPathW);
605 while (*p)
607 int gct = PathGetCharTypeW(*p);
608 if (gct == GCT_INVALID || gct == GCT_WILD || gct == GCT_SEPARATOR)
610 lpszFileW[i]='-';
611 rc |= PCS_REPLACEDCHAR;
613 else
614 lpszFileW[i]=*p;
615 i++;
616 p++;
617 if (length + i == MAX_PATH)
619 rc |= PCS_FATAL | PCS_PATHTOOLONG;
620 break;
623 lpszFileW[i]=0;
625 else
627 LPSTR lpszFileA = (LPSTR)lpszFileW;
628 LPCSTR lpszPathA = (LPCSTR)lpszPathW;
629 LPSTR p = lpszFileA;
631 TRACE("Cleanup %s\n",debugstr_a(lpszFileA));
633 if (lpszPathA)
634 length = strlen(lpszPathA);
636 while (*p)
638 int gct = PathGetCharTypeA(*p);
639 if (gct == GCT_INVALID || gct == GCT_WILD || gct == GCT_SEPARATOR)
641 lpszFileA[i]='-';
642 rc |= PCS_REPLACEDCHAR;
644 else
645 lpszFileA[i]=*p;
646 i++;
647 p++;
648 if (length + i == MAX_PATH)
650 rc |= PCS_FATAL | PCS_PATHTOOLONG;
651 break;
654 lpszFileA[i]=0;
656 return rc;
659 /*************************************************************************
660 * PathQualifyA [SHELL32]
662 static BOOL PathQualifyA(LPCSTR pszPath)
664 FIXME("%s\n",pszPath);
665 return FALSE;
668 /*************************************************************************
669 * PathQualifyW [SHELL32]
671 static BOOL PathQualifyW(LPCWSTR pszPath)
673 FIXME("%s\n",debugstr_w(pszPath));
674 return FALSE;
677 /*************************************************************************
678 * PathQualify [SHELL32.49]
680 BOOL WINAPI PathQualifyAW(LPCVOID pszPath)
682 if (SHELL_OsIsUnicode())
683 return PathQualifyW(pszPath);
684 return PathQualifyA(pszPath);
687 static BOOL PathResolveA(LPSTR path, LPCSTR *paths, DWORD flags)
689 FIXME("(%s,%p,0x%08x),stub!\n", debugstr_a(path), paths, flags);
690 return FALSE;
693 static BOOL PathResolveW(LPWSTR path, LPCWSTR *paths, DWORD flags)
695 FIXME("(%s,%p,0x%08x),stub!\n", debugstr_w(path), paths, flags);
696 return FALSE;
699 /*************************************************************************
700 * PathResolve [SHELL32.51]
702 BOOL WINAPI PathResolveAW(LPVOID path, LPCVOID *paths, DWORD flags)
704 if (SHELL_OsIsUnicode())
705 return PathResolveW(path, (LPCWSTR*)paths, flags);
706 else
707 return PathResolveA(path, (LPCSTR*)paths, flags);
710 /*************************************************************************
711 * PathProcessCommandA
713 static LONG PathProcessCommandA (
714 LPCSTR lpszPath,
715 LPSTR lpszBuff,
716 DWORD dwBuffSize,
717 DWORD dwFlags)
719 FIXME("%s %p 0x%04x 0x%04x stub\n",
720 lpszPath, lpszBuff, dwBuffSize, dwFlags);
721 if(!lpszPath) return -1;
722 if(lpszBuff) strcpy(lpszBuff, lpszPath);
723 return strlen(lpszPath);
726 /*************************************************************************
727 * PathProcessCommandW
729 static LONG PathProcessCommandW (
730 LPCWSTR lpszPath,
731 LPWSTR lpszBuff,
732 DWORD dwBuffSize,
733 DWORD dwFlags)
735 FIXME("(%s, %p, 0x%04x, 0x%04x) stub\n",
736 debugstr_w(lpszPath), lpszBuff, dwBuffSize, dwFlags);
737 if(!lpszPath) return -1;
738 if(lpszBuff) strcpyW(lpszBuff, lpszPath);
739 return strlenW(lpszPath);
742 /*************************************************************************
743 * PathProcessCommand (SHELL32.653)
745 LONG WINAPI PathProcessCommandAW (
746 LPCVOID lpszPath,
747 LPVOID lpszBuff,
748 DWORD dwBuffSize,
749 DWORD dwFlags)
751 if (SHELL_OsIsUnicode())
752 return PathProcessCommandW(lpszPath, lpszBuff, dwBuffSize, dwFlags);
753 return PathProcessCommandA(lpszPath, lpszBuff, dwBuffSize, dwFlags);
757 ########## special ##########
760 /*************************************************************************
761 * PathSetDlgItemPath (SHELL32.48)
763 VOID WINAPI PathSetDlgItemPathAW(HWND hDlg, int id, LPCVOID pszPath)
765 if (SHELL_OsIsUnicode())
766 PathSetDlgItemPathW(hDlg, id, pszPath);
767 else
768 PathSetDlgItemPathA(hDlg, id, pszPath);
771 static const WCHAR szCategory[] = {'C','a','t','e','g','o','r','y',0};
772 static const WCHAR szAttributes[] = {'A','t','t','r','i','b','u','t','e','s',0};
773 static const WCHAR szName[] = {'N','a','m','e',0};
774 static const WCHAR szParsingName[] = {'P','a','r','s','i','n','g','N','a','m','e',0};
775 static const WCHAR szRelativePath[] = {'R','e','l','a','t','i','v','e','P','a','t','h',0};
776 static const WCHAR szParentFolder[] = {'P','a','r','e','n','t','F','o','l','d','e','r',0};
778 static const WCHAR szCurrentVersion[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\0'};
779 static const WCHAR AddNewProgramsFolderW[] = {'A','d','d','N','e','w','P','r','o','g','r','a','m','s','F','o','l','d','e','r',0};
780 static const WCHAR AppUpdatesFolderW[] = {'A','p','p','U','p','d','a','t','e','s','F','o','l','d','e','r',0};
781 static const WCHAR Administrative_ToolsW[] = {'A','d','m','i','n','i','s','t','r','a','t','i','v','e',' ','T','o','o','l','s','\0'};
782 static const WCHAR AppDataW[] = {'A','p','p','D','a','t','a','\0'};
783 static const WCHAR AppData_RoamingW[] = {'A','p','p','D','a','t','a','\\','R','o','a','m','i','n','g','\0'};
784 static const WCHAR AppData_LocalLowW[] = {'A','p','p','D','a','t','a','\\','L','o','c','a','l','L','o','w','\0'};
785 static const WCHAR AppData_LocalW[] = {'A','p','p','D','a','t','a','\\','L','o','c','a','l','\0'};
786 static const WCHAR Application_DataW[] = {'A','p','p','l','i','c','a','t','i','o','n',' ','D','a','t','a','\0'};
787 static const WCHAR CacheW[] = {'C','a','c','h','e','\0'};
788 static const WCHAR CD_BurningW[] = {'C','D',' ','B','u','r','n','i','n','g','\0'};
789 static const WCHAR ChangeRemoveProgramsFolderW[] = {'C','h','a','n','g','e','R','e','m','o','v','e','P','r','o','g','r','a','m','s','F','o','l','d','e','r',0};
790 static const WCHAR CommonW[] = {'C','o','m','m','o','n',0};
791 static const WCHAR Common_Administrative_ToolsW[] = {'C','o','m','m','o','n',' ','A','d','m','i','n','i','s','t','r','a','t','i','v','e',' ','T','o','o','l','s','\0'};
792 static const WCHAR Common_AppDataW[] = {'C','o','m','m','o','n',' ','A','p','p','D','a','t','a','\0'};
793 static const WCHAR Common_DesktopW[] = {'C','o','m','m','o','n',' ','D','e','s','k','t','o','p','\0'};
794 static const WCHAR Common_DocumentsW[] = {'C','o','m','m','o','n',' ','D','o','c','u','m','e','n','t','s','\0'};
795 static const WCHAR CommonDownloadsW[] = {'C','o','m','m','o','n','D','o','w','n','l','o','a','d','s',0};
796 static const WCHAR Common_FavoritesW[] = {'C','o','m','m','o','n',' ','F','a','v','o','r','i','t','e','s','\0'};
797 static const WCHAR CommonFilesDirW[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r','\0'};
798 static const WCHAR CommonFilesDirX86W[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r',' ','(','x','8','6',')','\0'};
799 static const WCHAR CommonMusicW[] = {'C','o','m','m','o','n','M','u','s','i','c','\0'};
800 static const WCHAR CommonPicturesW[] = {'C','o','m','m','o','n','P','i','c','t','u','r','e','s','\0'};
801 static const WCHAR Common_ProgramsW[] = {'C','o','m','m','o','n',' ','P','r','o','g','r','a','m','s','\0'};
802 static const WCHAR CommonRingtonesW[] = {'C','o','m','m','o','n','R','i','n','g','t','o','n','e','s',0};
803 static const WCHAR Common_StartUpW[] = {'C','o','m','m','o','n',' ','S','t','a','r','t','U','p','\0'};
804 static const WCHAR Common_StartupW[] = {'C','o','m','m','o','n',' ','S','t','a','r','t','u','p','\0'};
805 static const WCHAR Common_Start_MenuW[] = {'C','o','m','m','o','n',' ','S','t','a','r','t',' ','M','e','n','u','\0'};
806 static const WCHAR Common_TemplatesW[] = {'C','o','m','m','o','n',' ','T','e','m','p','l','a','t','e','s','\0'};
807 static const WCHAR CommonVideoW[] = {'C','o','m','m','o','n','V','i','d','e','o','\0'};
808 static const WCHAR ConflictFolderW[] = {'C','o','n','f','l','i','c','t','F','o','l','d','e','r',0};
809 static const WCHAR ConnectionsFolderW[] = {'C','o','n','n','e','c','t','i','o','n','s','F','o','l','d','e','r',0};
810 static const WCHAR ContactsW[] = {'C','o','n','t','a','c','t','s','\0'};
811 static const WCHAR ControlPanelFolderW[] = {'C','o','n','t','r','o','l','P','a','n','e','l','F','o','l','d','e','r',0};
812 static const WCHAR CookiesW[] = {'C','o','o','k','i','e','s','\0'};
813 static const WCHAR CSCFolderW[] = {'C','S','C','F','o','l','d','e','r',0};
814 static const WCHAR Default_GadgetsW[] = {'D','e','f','a','u','l','t',' ','G','a','d','g','e','t','s',0};
815 static const WCHAR DesktopW[] = {'D','e','s','k','t','o','p','\0'};
816 static const WCHAR Device_Metadata_StoreW[] = {'D','e','v','i','c','e',' ','M','e','t','a','d','a','t','a',' ','S','t','o','r','e',0};
817 static const WCHAR DocumentsW[] = {'D','o','c','u','m','e','n','t','s','\0'};
818 static const WCHAR DocumentsLibraryW[] = {'D','o','c','u','m','e','n','t','s','L','i','b','r','a','r','y','\0'};
819 static const WCHAR Documents_librarymsW[] = {'D','o','c','u','m','e','n','t','s','.','l','i','b','r','a','r','y','-','m','s',0};
820 static const WCHAR DownloadsW[] = {'D','o','w','n','l','o','a','d','s','\0'};
821 static const WCHAR FavoritesW[] = {'F','a','v','o','r','i','t','e','s','\0'};
822 static const WCHAR FontsW[] = {'F','o','n','t','s','\0'};
823 static const WCHAR GadgetsW[] = {'G','a','d','g','e','t','s',0};
824 static const WCHAR GamesW[] = {'G','a','m','e','s',0};
825 static const WCHAR GameTasksW[] = {'G','a','m','e','T','a','s','k','s',0};
826 static const WCHAR HistoryW[] = {'H','i','s','t','o','r','y','\0'};
827 static const WCHAR HomeGroupFolderW[] = {'H','o','m','e','G','r','o','u','p','F','o','l','d','e','r',0};
828 static const WCHAR ImplicitAppShortcutsW[] = {'I','m','p','l','i','c','i','t','A','p','p','S','h','o','r','t','c','u','t','s',0};
829 static const WCHAR InternetFolderW[] = {'I','n','t','e','r','n','e','t','F','o','l','d','e','r',0};
830 static const WCHAR LibrariesW[] = {'L','i','b','r','a','r','i','e','s',0};
831 static const WCHAR LinksW[] = {'L','i','n','k','s','\0'};
832 static const WCHAR Local_AppDataW[] = {'L','o','c','a','l',' ','A','p','p','D','a','t','a','\0'};
833 static const WCHAR Local_Settings_Application_DataW[] = {'L','o','c','a','l',' ','S','e','t','t','i','n','g','s','\\','A','p','p','l','i','c','a','t','i','o','n',' ','D','a','t','a','\0'};
834 static const WCHAR Local_Settings_CD_BurningW[] = {'L','o','c','a','l',' ','S','e','t','t','i','n','g','s','\\','A','p','p','l','i','c','a','t','i','o','n',' ','D','a','t','a','\\','M','i','c','r','o','s','o','f','t','\\','C','D',' ','B','u','r','n','i','n','g','\0'};
835 static const WCHAR Local_Settings_HistoryW[] = {'L','o','c','a','l',' ','S','e','t','t','i','n','g','s','\\','H','i','s','t','o','r','y','\0'};
836 static const WCHAR Local_Settings_Temporary_Internet_FilesW[] = {'L','o','c','a','l',' ','S','e','t','t','i','n','g','s','\\','T','e','m','p','o','r','a','r','y',' ','I','n','t','e','r','n','e','t',' ','F','i','l','e','s','\0'};
837 static const WCHAR LocalAppDataLowW[] = {'L','o','c','a','l','A','p','p','D','a','t','a','L','o','w',0};
838 static const WCHAR LocalizedResourcesDirW[] = {'L','o','c','a','l','i','z','e','d','R','e','s','o','u','r','c','e','s','D','i','r',0};
839 static const WCHAR MAPIFolderW[] = {'M','A','P','I','F','o','l','d','e','r',0};
840 static const WCHAR Microsoft_Internet_Explorer_Quick_LaunchW[] = {'M','i','c','r','o','s','o','f','t','\\','I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r','\\','Q','u','i','c','k',' ','L','a','u','n','c','h',0};
841 static const WCHAR Microsoft_Windows_Burn_BurnW[] = {'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','B','u','r','n','\\','B','u','r','n',0};
842 static const WCHAR Microsoft_Windows_CookiesW[] = {'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','C','o','o','k','i','e','s',0};
843 static const WCHAR Microsoft_Windows_GameExplorerW[] = {'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','G','a','m','e','E','x','p','l','o','r','e','r','\0'};
844 static const WCHAR Microsoft_Windows_DeviceMetadataStoreW[] = {'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','D','e','v','i','c','e','M','e','t','a','d','a','t','a','S','t','o','r','e',0};
845 static const WCHAR Microsoft_Windows_HistoryW[] = {'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','H','i','s','t','o','r','y',0};
846 static const WCHAR Microsoft_Windows_LibrariesW[] = {'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','L','i','b','r','a','r','i','e','s','\0'};
847 static const WCHAR Microsoft_Windows_Network_ShortcutsW[] = {'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','N','e','t','w','o','r','k',' ','S','h','o','r','t','c','u','t','s',0};
848 static const WCHAR Microsoft_Windows_Photo_Gallery_Original_ImagesW[] = {'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s',' ','P','h','o','t','o',' ','G','a','l','l','e','r','y','\\','O','r','i','g','i','n','a','l',' ','I','m','a','g','e','s',0};
849 static const WCHAR Microsoft_Windows_Printer_ShortcutsW[] = {'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','P','r','i','n','t','e','r',' ','S','h','o','r','t','c','u','t','s',0};
850 static const WCHAR Microsoft_Windows_RecentW[] = {'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','R','e','c','e','n','t','\0'};
851 static const WCHAR Microsoft_Windows_RingtonesW[] = {'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','R','i','n','g','t','o','n','e','s','\0'};
852 static const WCHAR Microsoft_Windows_SendToW[] = {'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','S','e','n','d','T','o',0};
853 static const WCHAR Microsoft_Windows_Sidebar_GadgetsW[] = {'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s',' ','S','i','d','e','b','a','r','\\','G','a','d','g','e','t','s',0};
854 static const WCHAR Microsoft_Windows_Start_MenuW[] = {'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','S','t','a','r','t',' ','M','e','n','u',0};
855 static const WCHAR Microsoft_Windows_TemplatesW[] = {'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','T','e','m','p','l','a','t','e','s',0};
856 static const WCHAR Microsoft_Windows_Temporary_Internet_FilesW[] = {'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','T','e','m','p','o','r','a','r','y',' ','I','n','t','e','r','n','e','t',' ','F','i','l','e','s',0};
857 static const WCHAR MoviesW[] = {'M','o','v','i','e','s','\0'};
858 static const WCHAR MusicW[] = {'M','u','s','i','c','\0'};
859 static const WCHAR MusicLibraryW[] = {'M','u','s','i','c','L','i','b','r','a','r','y',0};
860 static const WCHAR Music_librarymsW[] = {'M','u','s','i','c','.','l','i','b','r','a','r','y','-','m','s',0};
861 static const WCHAR Music_PlaylistsW[] = {'M','u','s','i','c','\\','P','l','a','y','l','i','s','t','s','\0'};
862 static const WCHAR Music_Sample_MusicW[] = {'M','u','s','i','c','\\','S','a','m','p','l','e',' ','M','u','s','i','c','\0'};
863 static const WCHAR Music_Sample_PlaylistsW[] = {'M','u','s','i','c','\\','S','a','m','p','l','e',' ','P','l','a','y','l','i','s','t','s','\0'};
864 static const WCHAR My_MusicW[] = {'M','y',' ','M','u','s','i','c','\0'};
865 static const WCHAR My_PicturesW[] = {'M','y',' ','P','i','c','t','u','r','e','s','\0'};
866 static const WCHAR My_VideosW[] = {'M','y',' ','V','i','d','e','o','s','\0'};
867 static const WCHAR My_VideoW[] = {'M','y',' ','V','i','d','e','o','\0'};
868 static const WCHAR MyComputerFolderW[] = {'M','y','C','o','m','p','u','t','e','r','F','o','l','d','e','r',0};
869 static const WCHAR NetHoodW[] = {'N','e','t','H','o','o','d','\0'};
870 static const WCHAR NetworkPlacesFolderW[] = {'N','e','t','w','o','r','k','P','l','a','c','e','s','F','o','l','d','e','r',0};
871 static const WCHAR OEM_LinksW[] = {'O','E','M',' ','L','i','n','k','s','\0'};
872 static const WCHAR Original_ImagesW[] = {'O','r','i','g','i','n','a','l',' ','I','m','a','g','e','s',0};
873 static const WCHAR PersonalW[] = {'P','e','r','s','o','n','a','l','\0'};
874 static const WCHAR PhotoAlbumsW[] = {'P','h','o','t','o','A','l','b','u','m','s',0};
875 static const WCHAR PicturesW[] = {'P','i','c','t','u','r','e','s','\0'};
876 static const WCHAR PicturesLibraryW[] = {'P','i','c','t','u','r','e','s','L','i','b','r','a','r','y',0};
877 static const WCHAR Pictures_librarymsW[] = {'P','i','c','t','u','r','e','s','.','l','i','b','r','a','r','y','-','m','s',0};
878 static const WCHAR Pictures_Sample_PicturesW[] = {'P','i','c','t','u','r','e','s','\\','S','a','m','p','l','e',' ','P','i','c','t','u','r','e','s','\0'};
879 static const WCHAR Pictures_Slide_ShowsW[] = {'P','i','c','t','u','r','e','s','\\','S','l','i','d','e',' ','S','h','o','w','s','\0'};
880 static const WCHAR PlaylistsW[] = {'P','l','a','y','l','i','s','t','s',0};
881 static const WCHAR PrintersFolderW[] = {'P','r','i','n','t','e','r','s','F','o','l','d','e','r',0};
882 static const WCHAR PrintHoodW[] = {'P','r','i','n','t','H','o','o','d','\0'};
883 static const WCHAR ProfileW[] = {'P','r','o','f','i','l','e',0};
884 static const WCHAR Program_FilesW[] = {'P','r','o','g','r','a','m',' ','F','i','l','e','s','\0'};
885 static const WCHAR ProgramFilesW[] = {'P','r','o','g','r','a','m','F','i','l','e','s','\0'};
886 static const WCHAR ProgramFilesX86W[] = {'P','r','o','g','r','a','m','F','i','l','e','s','X','8','6','\0'};
887 static const WCHAR ProgramFilesX64W[] = {'P','r','o','g','r','a','m','F','i','l','e','s','X','6','4','\0'};
888 static const WCHAR Program_Files_Common_FilesW[] = {'P','r','o','g','r','a','m',' ','F','i','l','e','s','\\','C','o','m','m','o','n',' ','F','i','l','e','s','\0'};
889 static const WCHAR Program_Files_x86W[] = {'P','r','o','g','r','a','m',' ','F','i','l','e','s',' ','(','x','8','6',')','\0'};
890 static const WCHAR Program_Files_x86_Common_FilesW[] = {'P','r','o','g','r','a','m',' ','F','i','l','e','s',' ','(','x','8','6',')','\\','C','o','m','m','o','n',' ','F','i','l','e','s','\0'};
891 static const WCHAR ProgramFilesCommonW[] = {'P','r','o','g','r','a','m','F','i','l','e','s','C','o','m','m','o','n',0};
892 static const WCHAR ProgramFilesCommonX86W[] = {'P','r','o','g','r','a','m','F','i','l','e','s','C','o','m','m','o','n','X','8','6',0};
893 static const WCHAR ProgramFilesCommonX64W[] = {'P','r','o','g','r','a','m','F','i','l','e','s','C','o','m','m','o','n','X','6','4',0};
894 static const WCHAR ProgramFilesDirW[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r','\0'};
895 static const WCHAR ProgramFilesDirX86W[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r',' ','(','x','8','6',')','\0'};
896 static const WCHAR ProgramsW[] = {'P','r','o','g','r','a','m','s','\0'};
897 static const WCHAR PublicW[] = {'P','u','b','l','i','c',0};
898 static const WCHAR PublicGameTasksW[] = {'P','u','b','l','i','c','G','a','m','e','T','a','s','k','s',0};
899 static const WCHAR PublicLibrariesW[] = {'P','u','b','l','i','c','L','i','b','r','a','r','i','e','s',0};
900 static const WCHAR Quick_LaunchW[] = {'Q','u','i','c','k',' ','L','a','u','n','c','h',0};
901 static const WCHAR RecentW[] = {'R','e','c','e','n','t','\0'};
902 static const WCHAR RecordedTVLibraryW[] = {'R','e','c','o','r','d','e','d','T','V','L','i','b','r','a','r','y',0};
903 static const WCHAR RecordedTV_librarymsW[] = {'R','e','c','o','r','d','e','d','T','V','.','l','i','b','r','a','r','y','-','m','s',0};
904 static const WCHAR RecycleBinFolderW[] = {'R','e','c','y','c','l','e','B','i','n','F','o','l','d','e','r',0};
905 static const WCHAR ResourceDirW[] = {'R','e','s','o','u','r','c','e','D','i','r','\0'};
906 static const WCHAR ResourcesW[] = {'R','e','s','o','u','r','c','e','s','\0'};
907 static const WCHAR RingtonesW[] = {'R','i','n','g','t','o','n','e','s',0};
908 static const WCHAR SampleMusicW[] = {'S','a','m','p','l','e','M','u','s','i','c',0};
909 static const WCHAR Sample_MusicW[] = {'S','a','m','p','l','e',' ','M','u','s','i','c',0};
910 static const WCHAR SamplePicturesW[] = {'S','a','m','p','l','e','P','i','c','t','u','r','e','s',0};
911 static const WCHAR Sample_PicturesW[] = {'S','a','m','p','l','e',' ','P','i','c','t','u','r','e','s',0};
912 static const WCHAR SamplePlaylistsW[] = {'S','a','m','p','l','e','P','l','a','y','l','i','s','t','s',0};
913 static const WCHAR Sample_PlaylistsW[] = {'S','a','m','p','l','e',' ','P','l','a','y','l','i','s','t','s',0};
914 static const WCHAR Sample_VideosW[] = {'S','a','m','p','l','e',' ','V','i','d','e','o','s',0};
915 static const WCHAR SampleVideosW[] = {'S','a','m','p','l','e','V','i','d','e','o','s',0};
916 static const WCHAR Saved_GamesW[] = {'S','a','v','e','d',' ','G','a','m','e','s','\0'};
917 static const WCHAR SavedGamesW[] = {'S','a','v','e','d','G','a','m','e','s','\0'};
918 static const WCHAR SearchesW[] = {'S','e','a','r','c','h','e','s','\0'};
919 static const WCHAR SearchHomeFolderW[] = {'S','e','a','r','c','h','H','o','m','e','F','o','l','d','e','r',0};
920 static const WCHAR SendToW[] = {'S','e','n','d','T','o','\0'};
921 static const WCHAR Slide_ShowsW[] = {'S','l','i','d','e',' ','S','h','o','w','s',0};
922 static const WCHAR StartUpW[] = {'S','t','a','r','t','U','p','\0'};
923 static const WCHAR StartupW[] = {'S','t','a','r','t','u','p','\0'};
924 static const WCHAR Start_MenuW[] = {'S','t','a','r','t',' ','M','e','n','u','\0'};
925 static const WCHAR Start_Menu_ProgramsW[] = {'S','t','a','r','t',' ','M','e','n','u','\\','P','r','o','g','r','a','m','s','\0'};
926 static const WCHAR Start_Menu_Admin_ToolsW[] = {'S','t','a','r','t',' ','M','e','n','u','\\','P','r','o','g','r','a','m','s','\\','A','d','m','i','n','i','s','t','r','a','t','i','v','e',' ','T','o','o','l','s','\0'};
927 static const WCHAR Start_Menu_StartupW[] = {'S','t','a','r','t',' ','M','e','n','u','\\','P','r','o','g','r','a','m','s','\\','S','t','a','r','t','U','p','\0'};
928 static const WCHAR SyncCenterFolderW[] = {'S','y','n','c','C','e','n','t','e','r','F','o','l','d','e','r',0};
929 static const WCHAR SyncResultsFolderW[] = {'S','y','n','c','R','e','s','u','l','t','s','F','o','l','d','e','r',0};
930 static const WCHAR SyncSetupFolderW[] = {'S','y','n','c','S','e','t','u','p','F','o','l','d','e','r',0};
931 static const WCHAR SystemW[] = {'S','y','s','t','e','m',0};
932 static const WCHAR SystemX86W[] = {'S','y','s','t','e','m','X','8','6',0};
933 static const WCHAR TemplatesW[] = {'T','e','m','p','l','a','t','e','s','\0'};
934 static const WCHAR User_PinnedW[] = {'U','s','e','r',' ','P','i','n','n','e','d',0};
935 static const WCHAR UsersW[] = {'U','s','e','r','s','\0'};
936 static const WCHAR UsersFilesFolderW[] = {'U','s','e','r','s','F','i','l','e','s','F','o','l','d','e','r',0};
937 static const WCHAR UsersLibrariesFolderW[] = {'U','s','e','r','s','L','i','b','r','a','r','i','e','s','F','o','l','d','e','r',0};
938 static const WCHAR UserProfilesW[] = {'U','s','e','r','P','r','o','f','i','l','e','s',0};
939 static const WCHAR UserProgramFilesW[] = {'U','s','e','r','P','r','o','g','r','a','m','F','i','l','e','s',0};
940 static const WCHAR UserProgramFilesCommonW[] = {'U','s','e','r','P','r','o','g','r','a','m','F','i','l','e','s','C','o','m','m','o','n',0};
941 static const WCHAR UsersPublicW[] = {'U','s','e','r','s','\\','P','u','b','l','i','c','\0'};
942 static const WCHAR VideosW[] = {'V','i','d','e','o','s','\0'};
943 static const WCHAR VideosLibraryW[] = {'V','i','d','e','o','s','L','i','b','r','a','r','y',0};
944 static const WCHAR Videos_librarymsW[] = {'V','i','d','e','o','s','.','l','i','b','r','a','r','y','-','m','s',0};
945 static const WCHAR Videos_Sample_VideosW[] = {'V','i','d','e','o','s','\\','S','a','m','p','l','e',' ','V','i','d','e','o','s','\0'};
946 static const WCHAR WindowsW[] = {'W','i','n','d','o','w','s',0};
947 static const WCHAR Windows_Sidebar_GadgetsW[] = {'W','i','n','d','o','w','s',' ','S','i','d','e','b','a','r','\\','G','a','d','g','e','t','s',0};
948 static const WCHAR DefaultW[] = {'.','D','e','f','a','u','l','t','\0'};
949 static const WCHAR AllUsersProfileW[] = {'%','A','L','L','U','S','E','R','S','P','R','O','F','I','L','E','%','\0'};
950 static const WCHAR UserProfileW[] = {'%','U','S','E','R','P','R','O','F','I','L','E','%','\0'};
951 static const WCHAR SystemDriveW[] = {'%','S','y','s','t','e','m','D','r','i','v','e','%','\0'};
952 static const WCHAR ProfileListW[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','P','r','o','f','i','l','e','L','i','s','t',0};
953 static const WCHAR ProfilesDirectoryW[] = {'P','r','o','f','i','l','e','s','D','i','r','e','c','t','o','r','y',0};
954 static const WCHAR AllUsersProfileValueW[] = {'A','l','l','U','s','e','r','s','P','r','o','f','i','l','e','\0'};
955 static const WCHAR szSHFolders[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l','o','r','e','r','\\','S','h','e','l','l',' ','F','o','l','d','e','r','s','\0'};
956 static const WCHAR szSHUserFolders[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l','o','r','e','r','\\','U','s','e','r',' ','S','h','e','l','l',' ','F','o','l','d','e','r','s','\0'};
957 static const WCHAR szDefaultProfileDirW[] = {'u','s','e','r','s',0};
958 static const WCHAR szKnownFolderDescriptions[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l','o','r','e','r','\\','F','o','l','d','e','r','D','e','s','c','r','i','p','t','i','o','n','s','\0'};
959 static const WCHAR szKnownFolderRedirections[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l','o','r','e','r','\\','U','s','e','r',' ','S','h','e','l','l',' ','F','o','l','d','e','r','s',0};
960 static const WCHAR AllUsersW[] = {'P','u','b','l','i','c',0};
962 #define CHANGEREMOVEPROGRAMS_PARSING_GUID '{','7','b','8','1','b','e','6','a','-','c','e','2','b','-','4','6','7','6','-','a','2','9','e','-','e','b','9','0','7','a','5','1','2','6','c','5','}'
963 #define SYNCMANAGER_PARSING_GUID '{','9','C','7','3','F','5','E','5','-','7','A','E','7','-','4','E','3','2','-','A','8','E','8','-','8','D','2','3','B','8','5','2','5','5','B','F','}'
964 #define SYSTEMFOLDERS_PARSING_GUID '{','2','1','E','C','2','0','2','0','-','3','A','E','A','-','1','0','6','9','-','A','2','D','D','-','0','8','0','0','2','B','3','0','3','0','9','D','}'
965 #define USERFOLDERS_PARSING_GUID '{','5','9','0','3','1','a','4','7','-','3','f','7','2','-','4','4','a','7','-','8','9','c','5','-','5','5','9','5','f','e','6','b','3','0','e','e','}'
966 #define USERSLIBRARIES_PARSING_GUID '{','0','3','1','E','4','8','2','5','-','7','B','9','4','-','4','d','c','3','-','B','1','3','1','-','E','9','4','6','B','4','4','C','8','D','D','5','}'
968 static const WCHAR ComputerFolderParsingNameW[] = {':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-','A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0};
969 static const WCHAR ControlPanelFolderParsingNameW[] = {':',':','{','2','6','E','E','0','6','6','8','-','A','0','0','A','-','4','4','D','7','-','9','3','7','1','-','B','E','B','0','6','4','C','9','8','6','8','3','}','\\','0',0};
970 static const WCHAR ControlPanelFolderRelativePathW[] = {':',':','{','2','1','E','C','2','0','2','0','-','3','A','E','A','-','1','0','6','9','-','A','2','D','D','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0};
971 static const WCHAR GamesParsingNameW[] = {':',':','{','E','D','2','2','8','F','D','F','-','9','E','A','8','-','4','8','7','0','-','8','3','b','1','-','9','6','b','0','2','C','F','E','0','D','5','2','}',0};
972 static const WCHAR HomeGroupParsingNameW[] = {':',':','{','B','4','F','B','3','F','9','8','-','C','1','E','A','-','4','2','8','d','-','A','7','8','A','-','D','1','F','5','6','5','9','C','B','A','9','3','}',0};
973 static const WCHAR InternetFolderParsingNameW[] = {':',':','{','8','7','1','C','5','3','8','0','-','4','2','A','0','-','1','0','6','9','-','A','2','E','A','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0};
974 static const WCHAR NetworkFolderParsingNameW[] = {':',':','{','F','0','2','C','1','A','0','D','-','B','E','2','1','-','4','3','5','0','-','8','8','B','0','-','7','3','6','7','F','C','9','6','E','F','3','C','}',0};
975 static const WCHAR PublicParsingNameW[] = {':',':','{','4','3','3','6','a','5','4','d','-','0','3','8','b','-','4','6','8','5','-','a','b','0','2','-','9','9','b','b','5','2','d','3','f','b','8','b','}',0};
976 static const WCHAR RecycleBinFolderParsingNameW[] = {':',':','{','6','4','5','F','F','0','4','0','-','5','0','8','1','-','1','0','1','B','-','9','F','0','8','-','0','0','A','A','0','0','2','F','9','5','4','E','}',0};
977 static const WCHAR SearchHomeParsingNameW[] = {':',':','{','9','3','4','3','8','1','2','e','-','1','c','3','7','-','4','a','4','9','-','a','1','2','e','-','4','b','2','d','8','1','0','d','9','5','6','b','}',0};
978 static const WCHAR SEARCH_CSCParsingNameW[] = {'s','h','e','l','l',':',':',':','{','B','D','7','A','2','E','7','B','-','2','1','C','B','-','4','1','b','2','-','A','0','8','6','-','B','3','0','9','6','8','0','C','6','B','7','E','}','\\','*',0};
979 static const WCHAR SEARCH_MAPIParsingNameW[] = {'s','h','e','l','l',':',':',':','{','8','9','D','8','3','5','7','6','-','6','B','D','1','-','4','C','8','6','-','9','4','5','4','-','B','E','B','0','4','E','9','4','C','8','1','9','}','\\','*',0};
980 static const WCHAR UsersFilesParsingNameW[] = {':',':','{','5','9','0','3','1','a','4','7','-','3','f','7','2','-','4','4','a','7','-','8','9','c','5','-','5','5','9','5','f','e','6','b','3','0','e','e','}',0};
981 static const WCHAR UsersLibrariesParsingNameW[] = {':',':','{','0','3','1','E','4','8','2','5','-','7','B','9','4','-','4','d','c','3','-','B','1','3','1','-','E','9','4','6','B','4','4','C','8','D','D','5','}',0};
982 static const WCHAR AddNewProgramsParsingNameW[] = {':',':', SYSTEMFOLDERS_PARSING_GUID, '\\',':',':','{','1','5','e','a','e','9','2','e','-','f','1','7','a','-','4','4','3','1','-','9','f','2','8','-','8','0','5','e','4','8','2','d','a','f','d','4','}',0};
983 static const WCHAR ConnectionsFolderParsingNameW[] = {':',':', SYSTEMFOLDERS_PARSING_GUID, '\\',':',':','{','7','0','0','7','A','C','C','7','-','3','2','0','2','-','1','1','D','1','-','A','A','D','2','-','0','0','8','0','5','F','C','1','2','7','0','E','}',0};
984 static const WCHAR PrintersFolderParsingNameW[] = {':',':', SYSTEMFOLDERS_PARSING_GUID, '\\',':',':','{','2','2','2','7','A','2','8','0','-','3','A','E','A','-','1','0','6','9','-','A','2','D','E','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0};
985 static const WCHAR ChangeRemoveProgramsParsingNameW[] = {':',':', SYSTEMFOLDERS_PARSING_GUID, '\\',':',':', CHANGEREMOVEPROGRAMS_PARSING_GUID, 0};
986 static const WCHAR AppUpdatesParsingNameW[] = {':',':', SYSTEMFOLDERS_PARSING_GUID, '\\',':',':', CHANGEREMOVEPROGRAMS_PARSING_GUID, '\\',':',':','{','d','4','5','0','a','8','a','1','-','9','5','6','8','-','4','5','c','7','-','9','c','0','e','-','b','4','f','9','f','b','4','5','3','7','b','d','}',0};
987 static const WCHAR SyncManagerFolderParsingNameW[] = {':',':', SYSTEMFOLDERS_PARSING_GUID, '\\',':',':', SYNCMANAGER_PARSING_GUID, 0};
988 static const WCHAR ConflictFolderParsingNameW[] = {':',':', SYSTEMFOLDERS_PARSING_GUID, '\\',':',':', SYNCMANAGER_PARSING_GUID, '\\',':',':','{','E','4','1','3','D','0','4','0','-','6','7','8','8','-','4','C','2','2','-','9','5','7','E','-','1','7','5','D','1','C','5','1','3','A','3','4','}',',',0};
989 static const WCHAR SyncResultsFolderParsingNameW[] = {':',':', SYSTEMFOLDERS_PARSING_GUID, '\\',':',':', SYNCMANAGER_PARSING_GUID, '\\',':',':','{','B','C','4','8','B','3','2','F','-','5','9','1','0','-','4','7','F','5','-','8','5','7','0','-','5','0','7','4','A','8','A','5','6','3','6','A','}',',',0};
990 static const WCHAR SyncSetupFolderParsingNameW[] = {':',':', SYSTEMFOLDERS_PARSING_GUID, '\\',':',':', SYNCMANAGER_PARSING_GUID, '\\',':',':','{','F','1','3','9','0','A','9','A','-','A','3','F','4','-','4','E','5','D','-','9','C','5','F','-','9','8','F','3','B','D','8','D','9','3','5','C','}',',',0};
991 static const WCHAR ContactsParsingNameW[] = {':',':', USERFOLDERS_PARSING_GUID, '\\','{','5','6','7','8','4','8','5','4','-','C','6','C','B','-','4','6','2','B','-','8','1','6','9','-','8','8','E','3','5','0','A','C','B','8','8','2','}',0};
992 static const WCHAR DocumentsParsingNameW[] = {':',':', USERFOLDERS_PARSING_GUID, '\\','{','F','D','D','3','9','A','D','0','-','2','3','8','F','-','4','6','A','F','-','A','D','B','4','-','6','C','8','5','4','8','0','3','6','9','C','7','}',0};
993 static const WCHAR LinksParsingNameW[] = {':',':', USERFOLDERS_PARSING_GUID, '\\','{','b','f','b','9','d','5','e','0','-','c','6','a','9','-','4','0','4','c','-','b','2','b','2','-','a','e','6','d','b','6','a','f','4','9','6','8','}',0};
994 static const WCHAR MusicParsingNameW[] = {':',':', USERFOLDERS_PARSING_GUID, '\\','{','4','B','D','8','D','5','7','1','-','6','D','1','9','-','4','8','D','3','-','B','E','9','7','-','4','2','2','2','2','0','0','8','0','E','4','3','}',0};
995 static const WCHAR PicturesParsingNameW[] = {':',':', USERFOLDERS_PARSING_GUID, '\\','{','3','3','E','2','8','1','3','0','-','4','E','1','E','-','4','6','7','6','-','8','3','5','A','-','9','8','3','9','5','C','3','B','C','3','B','B','}',0};
996 static const WCHAR SavedGamesParsingNameW[] = {':',':', USERFOLDERS_PARSING_GUID, '\\','{','4','C','5','C','3','2','F','F','-','B','B','9','D','-','4','3','b','0','-','B','5','B','4','-','2','D','7','2','E','5','4','E','A','A','A','4','}',0};
997 static const WCHAR SavedSearchesParsingNameW[] = {':',':', USERFOLDERS_PARSING_GUID, '\\','{','7','d','1','d','3','a','0','4','-','d','e','b','b','-','4','1','1','5','-','9','5','c','f','-','2','f','2','9','d','a','2','9','2','0','d','a','}',0};
998 static const WCHAR VideosParsingNameW[] = {':',':', USERFOLDERS_PARSING_GUID, '\\','{','1','8','9','8','9','B','1','D','-','9','9','B','5','-','4','5','5','B','-','8','4','1','C','-','A','B','7','C','7','4','E','4','D','D','F','C','}',0};
999 static const WCHAR DocumentsLibraryParsingNameW[] = {':',':', USERSLIBRARIES_PARSING_GUID, '\\','{','7','b','0','d','b','1','7','d','-','9','c','d','2','-','4','a','9','3','-','9','7','3','3','-','4','6','c','c','8','9','0','2','2','e','7','c','}',0};
1000 static const WCHAR MusicLibraryParsingNameW[] = {':',':', USERSLIBRARIES_PARSING_GUID, '\\','{','2','1','1','2','A','B','0','A','-','C','8','6','A','-','4','f','f','e','-','A','3','6','8','-','0','D','E','9','6','E','4','7','0','1','2','E','}',0};
1001 static const WCHAR PicturesLibraryParsingNameW[] = {':',':', USERSLIBRARIES_PARSING_GUID, '\\','{','A','9','9','0','A','E','9','F','-','A','0','3','B','-','4','e','8','0','-','9','4','B','C','-','9','9','1','2','D','7','5','0','4','1','0','4','}',0};
1002 static const WCHAR VideosLibraryParsingNameW[] = {':',':', USERSLIBRARIES_PARSING_GUID, '\\','{','4','9','1','E','9','2','2','F','-','5','6','4','3','-','4','a','f','4','-','A','7','E','B','-','4','E','7','A','1','3','8','D','8','1','7','4','}',0};
1004 typedef enum _CSIDL_Type {
1005 CSIDL_Type_User,
1006 CSIDL_Type_AllUsers,
1007 CSIDL_Type_CurrVer,
1008 CSIDL_Type_Disallowed,
1009 CSIDL_Type_NonExistent,
1010 CSIDL_Type_WindowsPath,
1011 CSIDL_Type_SystemPath,
1012 CSIDL_Type_SystemX86Path,
1013 } CSIDL_Type;
1015 #define CSIDL_CONTACTS 0x0043
1016 #define CSIDL_DOWNLOADS 0x0047
1017 #define CSIDL_LINKS 0x004d
1018 #define CSIDL_APPDATA_LOCALLOW 0x004e
1019 #define CSIDL_SAVED_GAMES 0x0062
1020 #define CSIDL_SEARCHES 0x0063
1022 typedef struct
1024 IApplicationDestinations IApplicationDestinations_iface;
1025 LONG ref;
1026 } IApplicationDestinationsImpl;
1028 static inline IApplicationDestinationsImpl *impl_from_IApplicationDestinations( IApplicationDestinations *iface )
1030 return CONTAINING_RECORD(iface, IApplicationDestinationsImpl, IApplicationDestinations_iface);
1033 static HRESULT WINAPI ApplicationDestinations_QueryInterface(IApplicationDestinations *iface, REFIID riid,
1034 LPVOID *ppv)
1036 IApplicationDestinationsImpl *This = impl_from_IApplicationDestinations(iface);
1038 TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppv);
1040 if (ppv == NULL)
1041 return E_POINTER;
1043 if (IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IApplicationDestinations, riid))
1045 *ppv = &This->IApplicationDestinations_iface;
1046 IUnknown_AddRef((IUnknown*)*ppv);
1048 TRACE("Returning IApplicationDestinations: %p\n", *ppv);
1049 return S_OK;
1052 *ppv = NULL;
1053 FIXME("(%p)->(%s, %p) interface not supported.\n", This, debugstr_guid(riid), ppv);
1055 return E_NOINTERFACE;
1058 static ULONG WINAPI ApplicationDestinations_AddRef(IApplicationDestinations *iface)
1060 IApplicationDestinationsImpl *This = impl_from_IApplicationDestinations(iface);
1061 ULONG ref = InterlockedIncrement(&This->ref);
1063 TRACE("(%p), new refcount=%i\n", This, ref);
1065 return ref;
1068 static ULONG WINAPI ApplicationDestinations_Release(IApplicationDestinations *iface)
1070 IApplicationDestinationsImpl *This = impl_from_IApplicationDestinations(iface);
1071 ULONG ref = InterlockedDecrement(&This->ref);
1073 TRACE("(%p), new refcount=%i\n", This, ref);
1075 if (ref == 0)
1076 HeapFree(GetProcessHeap(), 0, This);
1078 return ref;
1081 static HRESULT WINAPI ApplicationDestinations_SetAppID(IApplicationDestinations *iface, const WCHAR *appid)
1083 IApplicationDestinationsImpl *This = impl_from_IApplicationDestinations(iface);
1085 FIXME("(%p, %s) stub!\n", This, debugstr_w(appid));
1087 return E_NOTIMPL;
1090 static HRESULT WINAPI ApplicationDestinations_RemoveDestination(IApplicationDestinations *iface, IUnknown *punk)
1092 IApplicationDestinationsImpl *This = impl_from_IApplicationDestinations(iface);
1094 FIXME("(%p, %p) stub!\n", This, punk);
1096 return E_NOTIMPL;
1099 static HRESULT WINAPI ApplicationDestinations_RemoveAllDestinations(IApplicationDestinations *iface)
1101 IApplicationDestinationsImpl *This = impl_from_IApplicationDestinations(iface);
1103 FIXME("(%p) stub!\n", This);
1105 return E_NOTIMPL;
1108 static const IApplicationDestinationsVtbl ApplicationDestinationsVtbl =
1110 ApplicationDestinations_QueryInterface,
1111 ApplicationDestinations_AddRef,
1112 ApplicationDestinations_Release,
1113 ApplicationDestinations_SetAppID,
1114 ApplicationDestinations_RemoveDestination,
1115 ApplicationDestinations_RemoveAllDestinations
1118 HRESULT WINAPI ApplicationDestinations_Constructor(IUnknown *outer, REFIID riid, LPVOID *ppv)
1120 IApplicationDestinationsImpl *This;
1121 HRESULT hr;
1123 TRACE("(%p, %s, %p)\n", outer, debugstr_guid(riid), ppv);
1125 if (outer)
1126 return CLASS_E_NOAGGREGATION;
1128 if (!(This = SHAlloc(sizeof(*This))))
1129 return E_OUTOFMEMORY;
1131 This->IApplicationDestinations_iface.lpVtbl = &ApplicationDestinationsVtbl;
1132 This->ref = 0;
1134 hr = IUnknown_QueryInterface(&This->IApplicationDestinations_iface, riid, ppv);
1135 if (FAILED(hr))
1136 SHFree(This);
1138 return hr;
1141 typedef struct
1143 const KNOWNFOLDERID *id;
1144 CSIDL_Type type;
1145 LPCWSTR szValueName;
1146 LPCWSTR szDefaultPath; /* fallback string or resource ID */
1148 /* KNOWNFOLDER_DEFINITION fields */
1149 KF_CATEGORY category;
1150 const WCHAR *pszName;
1151 const WCHAR *pszDescription;
1152 const KNOWNFOLDERID *fidParent;
1153 const WCHAR *pszRelativePath;
1154 const WCHAR *pszParsingName;
1155 const WCHAR *pszTooltip;
1156 const WCHAR *pszLocalizedName;
1157 const WCHAR *pszIcon;
1158 const WCHAR *pszSecurity;
1159 DWORD dwAttributes;
1160 KF_DEFINITION_FLAGS kfdFlags;
1161 const FOLDERTYPEID *ftidType;
1162 } CSIDL_DATA;
1164 static const CSIDL_DATA CSIDL_Data[] =
1166 { /* 0x00 - CSIDL_DESKTOP */
1167 &FOLDERID_Desktop,
1168 CSIDL_Type_User,
1169 DesktopW,
1170 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY),
1172 KF_CATEGORY_PERUSER, /* category */
1173 DesktopW, /* name */
1174 NULL, /* description */
1175 &GUID_NULL, /* parent */
1176 DesktopW, /* relative path */
1177 NULL, /* parsing */
1178 NULL, /* tooltip */
1179 NULL, /* localized */
1180 NULL, /* icon */
1181 NULL, /* security */
1182 FILE_ATTRIBUTE_READONLY, /* attributes */
1183 0, /* flags */
1184 &GUID_NULL /* typeid */
1186 { /* 0x01 - CSIDL_INTERNET */
1187 &FOLDERID_InternetFolder,
1188 CSIDL_Type_Disallowed,
1189 NULL,
1190 NULL,
1192 KF_CATEGORY_VIRTUAL, /* category */
1193 InternetFolderW, /* name */
1194 NULL, /* description */
1195 &GUID_NULL, /* parent */
1196 NULL, /* relative path */
1197 InternetFolderParsingNameW, /* parsing */
1198 NULL, /* tooltip */
1199 NULL, /* localized */
1200 NULL, /* icon */
1201 NULL, /* security */
1202 0, /* attributes */
1203 0, /* flags */
1204 &GUID_NULL /* typeid */
1206 { /* 0x02 - CSIDL_PROGRAMS */
1207 &FOLDERID_Programs,
1208 CSIDL_Type_User,
1209 ProgramsW,
1210 Start_Menu_ProgramsW,
1212 KF_CATEGORY_PERUSER, /* category */
1213 ProgramsW, /* name */
1214 NULL, /* description */
1215 &GUID_NULL, /* parent */
1216 ProgramsW, /* relative path */
1217 NULL, /* parsing */
1218 NULL, /* tooltip */
1219 NULL, /* localized */
1220 NULL, /* icon */
1221 NULL, /* security */
1222 FILE_ATTRIBUTE_READONLY, /* attributes */
1223 0, /* flags */
1224 &GUID_NULL /* typeid */
1226 { /* 0x03 - CSIDL_CONTROLS (.CPL files) */
1227 &FOLDERID_ControlPanelFolder,
1228 CSIDL_Type_SystemPath,
1229 NULL,
1230 NULL,
1232 KF_CATEGORY_VIRTUAL, /* category */
1233 ControlPanelFolderW, /* name */
1234 NULL, /* description */
1235 &GUID_NULL, /* parent */
1236 ControlPanelFolderRelativePathW, /* relative path */
1237 ControlPanelFolderParsingNameW, /* parsing */
1238 NULL, /* tooltip */
1239 NULL, /* localized */
1240 NULL, /* icon */
1241 NULL, /* security */
1242 0, /* attributes */
1243 0, /* flags */
1244 &GUID_NULL /* typeid */
1246 { /* 0x04 - CSIDL_PRINTERS */
1247 &FOLDERID_PrintersFolder,
1248 CSIDL_Type_SystemPath,
1249 NULL,
1250 NULL,
1252 KF_CATEGORY_VIRTUAL, /* category */
1253 PrintersFolderW, /* name */
1254 NULL, /* description */
1255 &GUID_NULL, /* parent */
1256 NULL, /* relative path */
1257 PrintersFolderParsingNameW, /* parsing */
1258 NULL, /* tooltip */
1259 NULL, /* localized */
1260 NULL, /* icon */
1261 NULL, /* security */
1262 0, /* attributes */
1263 0, /* flags */
1264 &GUID_NULL /* typeid */
1266 { /* 0x05 - CSIDL_PERSONAL */
1267 &FOLDERID_Documents,
1268 CSIDL_Type_User,
1269 PersonalW,
1270 MAKEINTRESOURCEW(IDS_PERSONAL),
1272 KF_CATEGORY_PERUSER, /* category */
1273 PersonalW, /* name */
1274 NULL, /* description */
1275 &GUID_NULL, /* parent */
1276 DocumentsW, /* relative path */
1277 DocumentsParsingNameW, /* parsing */
1278 NULL, /* tooltip */
1279 NULL, /* localized */
1280 NULL, /* icon */
1281 NULL, /* security */
1282 FILE_ATTRIBUTE_READONLY, /* attributes */
1283 KFDF_ROAMABLE | KFDF_PRECREATE, /* flags */
1284 &GUID_NULL /* typeid */
1286 { /* 0x06 - CSIDL_FAVORITES */
1287 &FOLDERID_Favorites,
1288 CSIDL_Type_User,
1289 FavoritesW,
1290 FavoritesW,
1292 KF_CATEGORY_PERUSER, /* category */
1293 FavoritesW, /* name */
1294 NULL, /* description */
1295 &GUID_NULL, /* parent */
1296 FavoritesW, /* relative path */
1297 NULL, /* parsing */
1298 NULL, /* tooltip */
1299 NULL, /* localized */
1300 NULL, /* icon */
1301 NULL, /* security */
1302 FILE_ATTRIBUTE_READONLY, /* attributes */
1303 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH, /* flags */
1304 &GUID_NULL /* typeid */
1306 { /* 0x07 - CSIDL_STARTUP */
1307 &FOLDERID_Startup,
1308 CSIDL_Type_User,
1309 StartUpW,
1310 Start_Menu_StartupW,
1312 KF_CATEGORY_PERUSER, /* category */
1313 StartupW, /* name */
1314 NULL, /* description */
1315 &GUID_NULL, /* parent */
1316 StartUpW, /* relative path */
1317 NULL, /* parsing */
1318 NULL, /* tooltip */
1319 NULL, /* localized */
1320 NULL, /* icon */
1321 NULL, /* security */
1322 FILE_ATTRIBUTE_READONLY, /* attributes */
1323 KFDF_PRECREATE, /* flags */
1324 &GUID_NULL /* typeid */
1326 { /* 0x08 - CSIDL_RECENT */
1327 &FOLDERID_Recent,
1328 CSIDL_Type_User,
1329 RecentW,
1330 RecentW,
1332 KF_CATEGORY_PERUSER, /* category */
1333 RecentW, /* name */
1334 NULL, /* description */
1335 &FOLDERID_RoamingAppData, /* parent */
1336 Microsoft_Windows_RecentW, /* relative path */
1337 NULL, /* parsing */
1338 NULL, /* tooltip */
1339 NULL, /* localized */
1340 NULL, /* icon */
1341 NULL, /* security */
1342 FILE_ATTRIBUTE_READONLY, /* attributes */
1343 KFDF_PRECREATE, /* flags */
1344 &GUID_NULL /* typeid */
1346 { /* 0x09 - CSIDL_SENDTO */
1347 &FOLDERID_SendTo,
1348 CSIDL_Type_User,
1349 SendToW,
1350 SendToW,
1352 KF_CATEGORY_PERUSER, /* category */
1353 SendToW, /* name */
1354 NULL, /* description */
1355 &FOLDERID_RoamingAppData, /* parent */
1356 Microsoft_Windows_SendToW, /* relative path */
1357 NULL, /* parsing */
1358 NULL, /* tooltip */
1359 NULL, /* localized */
1360 NULL, /* icon */
1361 NULL, /* security */
1362 0, /* attributes */
1363 KFDF_PRECREATE, /* flags */
1364 &GUID_NULL /* typeid */
1366 { /* 0x0a - CSIDL_BITBUCKET - Recycle Bin */
1367 &FOLDERID_RecycleBinFolder,
1368 CSIDL_Type_Disallowed,
1369 NULL,
1370 NULL,
1372 KF_CATEGORY_VIRTUAL, /* category */
1373 RecycleBinFolderW, /* name */
1374 NULL, /* description */
1375 &GUID_NULL, /* parent */
1376 NULL, /* relative path */
1377 RecycleBinFolderParsingNameW, /* parsing */
1378 NULL, /* tooltip */
1379 NULL, /* localized */
1380 NULL, /* icon */
1381 NULL, /* security */
1382 0, /* attributes */
1383 0, /* flags */
1384 &GUID_NULL /* typeid */
1386 { /* 0x0b - CSIDL_STARTMENU */
1387 &FOLDERID_StartMenu,
1388 CSIDL_Type_User,
1389 Start_MenuW,
1390 Start_MenuW,
1392 KF_CATEGORY_PERUSER, /* category */
1393 Start_MenuW, /* name */
1394 NULL, /* description */
1395 &FOLDERID_RoamingAppData, /* parent */
1396 Microsoft_Windows_Start_MenuW, /* relative path */
1397 NULL, /* parsing */
1398 NULL, /* tooltip */
1399 NULL, /* localized */
1400 NULL, /* icon */
1401 NULL, /* security */
1402 FILE_ATTRIBUTE_READONLY, /* attributes */
1403 KFDF_PRECREATE, /* flags */
1404 &GUID_NULL /* typeid */
1406 { /* 0x0c - CSIDL_MYDOCUMENTS */
1407 &GUID_NULL,
1408 CSIDL_Type_Disallowed, /* matches WinXP--can't get its path */
1409 NULL,
1410 NULL
1412 { /* 0x0d - CSIDL_MYMUSIC */
1413 &FOLDERID_Music,
1414 CSIDL_Type_User,
1415 My_MusicW,
1416 MAKEINTRESOURCEW(IDS_MYMUSIC),
1418 KF_CATEGORY_PERUSER, /* category */
1419 My_MusicW, /* name */
1420 NULL, /* description */
1421 &FOLDERID_Profile, /* parent */
1422 MusicW, /* relative path */
1423 MusicParsingNameW, /* parsing */
1424 NULL, /* tooltip */
1425 NULL, /* localized */
1426 NULL, /* icon */
1427 NULL, /* security */
1428 FILE_ATTRIBUTE_READONLY, /* attributes */
1429 KFDF_ROAMABLE | KFDF_PRECREATE, /* flags */
1430 &GUID_NULL /* typeid */
1432 { /* 0x0e - CSIDL_MYVIDEO */
1433 &FOLDERID_Videos,
1434 CSIDL_Type_User,
1435 My_VideosW,
1436 MAKEINTRESOURCEW(IDS_MYVIDEOS),
1438 KF_CATEGORY_PERUSER, /* category */
1439 My_VideoW, /* name */
1440 NULL, /* description */
1441 &FOLDERID_Profile, /* parent */
1442 VideosW, /* relative path */
1443 VideosParsingNameW, /* parsing */
1444 NULL, /* tooltip */
1445 NULL, /* localized */
1446 NULL, /* icon */
1447 NULL, /* security */
1448 FILE_ATTRIBUTE_READONLY, /* attributes */
1449 KFDF_ROAMABLE | KFDF_PRECREATE, /* flags */
1450 &GUID_NULL /* typeid */
1452 { /* 0x0f - unassigned */
1453 &GUID_NULL,
1454 CSIDL_Type_Disallowed,
1455 NULL,
1456 NULL,
1458 { /* 0x10 - CSIDL_DESKTOPDIRECTORY */
1459 &FOLDERID_Desktop,
1460 CSIDL_Type_User,
1461 DesktopW,
1462 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY),
1464 KF_CATEGORY_PERUSER, /* category */
1465 DesktopW, /* name */
1466 NULL, /* description */
1467 &FOLDERID_Profile, /* parent */
1468 DesktopW, /* relative path */
1469 NULL, /* parsing */
1470 NULL, /* tooltip */
1471 NULL, /* localized */
1472 NULL, /* icon */
1473 NULL, /* security */
1474 FILE_ATTRIBUTE_READONLY, /* attributes */
1475 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH, /* flags */
1476 &GUID_NULL /* typeid */
1478 { /* 0x11 - CSIDL_DRIVES */
1479 &FOLDERID_ComputerFolder,
1480 CSIDL_Type_Disallowed,
1481 NULL,
1482 NULL,
1484 KF_CATEGORY_VIRTUAL, /* category */
1485 MyComputerFolderW, /* name */
1486 NULL, /* description */
1487 &GUID_NULL, /* parent */
1488 NULL, /* relative path */
1489 ComputerFolderParsingNameW, /* parsing */
1490 NULL, /* tooltip */
1491 NULL, /* localized */
1492 NULL, /* icon */
1493 NULL, /* security */
1494 0, /* attributes */
1495 0, /* flags */
1496 &GUID_NULL /* typeid */
1498 { /* 0x12 - CSIDL_NETWORK */
1499 &FOLDERID_NetworkFolder,
1500 CSIDL_Type_Disallowed,
1501 NULL,
1502 NULL,
1504 KF_CATEGORY_VIRTUAL, /* category */
1505 NetworkPlacesFolderW, /* name */
1506 NULL, /* description */
1507 &GUID_NULL, /* parent */
1508 NULL, /* relative path */
1509 NetworkFolderParsingNameW, /* parsing */
1510 NULL, /* tooltip */
1511 NULL, /* localized */
1512 NULL, /* icon */
1513 NULL, /* security */
1514 0, /* attributes */
1515 0, /* flags */
1516 &GUID_NULL /* typeid */
1518 { /* 0x13 - CSIDL_NETHOOD */
1519 &FOLDERID_NetHood,
1520 CSIDL_Type_User,
1521 NetHoodW,
1522 NetHoodW,
1524 KF_CATEGORY_PERUSER, /* category */
1525 NetHoodW, /* name */
1526 NULL, /* description */
1527 &FOLDERID_RoamingAppData, /* parent */
1528 Microsoft_Windows_Network_ShortcutsW, /* relative path */
1529 NULL, /* parsing */
1530 NULL, /* tooltip */
1531 NULL, /* localized */
1532 NULL, /* icon */
1533 NULL, /* security */
1534 0, /* attributes */
1535 0, /* flags */
1536 &GUID_NULL /* typeid */
1538 { /* 0x14 - CSIDL_FONTS */
1539 &FOLDERID_Fonts,
1540 CSIDL_Type_WindowsPath,
1541 FontsW,
1542 FontsW,
1544 KF_CATEGORY_FIXED, /* category */
1545 FontsW, /* name */
1546 NULL, /* description */
1547 &GUID_NULL, /* parent */
1548 NULL, /* relative path */
1549 NULL, /* parsing */
1550 NULL, /* tooltip */
1551 NULL, /* localized */
1552 NULL, /* icon */
1553 NULL, /* security */
1554 0, /* attributes */
1555 0, /* flags */
1556 &FOLDERID_Windows/* typeid */
1558 { /* 0x15 - CSIDL_TEMPLATES */
1559 &FOLDERID_Templates,
1560 CSIDL_Type_User,
1561 TemplatesW,
1562 TemplatesW,
1564 KF_CATEGORY_PERUSER, /* category */
1565 TemplatesW, /* name */
1566 NULL, /* description */
1567 &FOLDERID_RoamingAppData, /* parent */
1568 Microsoft_Windows_TemplatesW, /* relative path */
1569 NULL, /* parsing */
1570 NULL, /* tooltip */
1571 NULL, /* localized */
1572 NULL, /* icon */
1573 NULL, /* security */
1574 0, /* attributes */
1575 0, /* flags */
1576 &GUID_NULL /* typeid */
1578 { /* 0x16 - CSIDL_COMMON_STARTMENU */
1579 &FOLDERID_CommonStartMenu,
1580 CSIDL_Type_AllUsers,
1581 Common_Start_MenuW,
1582 Start_MenuW,
1584 KF_CATEGORY_COMMON, /* category */
1585 Common_Start_MenuW, /* name */
1586 NULL, /* description */
1587 &FOLDERID_ProgramData, /* parent */
1588 Microsoft_Windows_Start_MenuW, /* relative path */
1589 NULL, /* parsing */
1590 NULL, /* tooltip */
1591 NULL, /* localized */
1592 NULL, /* icon */
1593 NULL, /* security */
1594 FILE_ATTRIBUTE_READONLY, /* attributes */
1595 0, /* flags */
1596 &GUID_NULL /* typeid */
1598 { /* 0x17 - CSIDL_COMMON_PROGRAMS */
1599 &FOLDERID_CommonPrograms,
1600 CSIDL_Type_AllUsers,
1601 Common_ProgramsW,
1602 Start_Menu_ProgramsW,
1604 KF_CATEGORY_COMMON, /* category */
1605 Common_ProgramsW, /* name */
1606 NULL, /* description */
1607 &FOLDERID_CommonStartMenu, /* parent */
1608 ProgramsW, /* relative path */
1609 NULL, /* parsing */
1610 NULL, /* tooltip */
1611 NULL, /* localized */
1612 NULL, /* icon */
1613 NULL, /* security */
1614 FILE_ATTRIBUTE_READONLY, /* attributes */
1615 0, /* flags */
1616 &GUID_NULL /* typeid */
1618 { /* 0x18 - CSIDL_COMMON_STARTUP */
1619 &FOLDERID_CommonStartup,
1620 CSIDL_Type_AllUsers,
1621 Common_StartUpW,
1622 Start_Menu_StartupW,
1624 KF_CATEGORY_COMMON, /* category */
1625 Common_StartupW, /* name */
1626 NULL, /* description */
1627 &FOLDERID_CommonPrograms, /* parent */
1628 StartUpW, /* relative path */
1629 NULL, /* parsing */
1630 NULL, /* tooltip */
1631 NULL, /* localized */
1632 NULL, /* icon */
1633 NULL, /* security */
1634 FILE_ATTRIBUTE_READONLY, /* attributes */
1635 KFDF_PRECREATE, /* flags */
1636 &GUID_NULL /* typeid */
1638 { /* 0x19 - CSIDL_COMMON_DESKTOPDIRECTORY */
1639 &FOLDERID_PublicDesktop,
1640 CSIDL_Type_AllUsers,
1641 Common_DesktopW,
1642 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY),
1644 KF_CATEGORY_COMMON, /* category */
1645 Common_DesktopW, /* name */
1646 NULL, /* description */
1647 &FOLDERID_Public, /* parent */
1648 DesktopW, /* relative path */
1649 NULL, /* parsing */
1650 NULL, /* tooltip */
1651 NULL, /* localized */
1652 NULL, /* icon */
1653 NULL, /* security */
1654 FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN, /* attributes */
1655 KFDF_PRECREATE, /* flags */
1656 &GUID_NULL /* typeid */
1658 { /* 0x1a - CSIDL_APPDATA */
1659 &FOLDERID_RoamingAppData,
1660 CSIDL_Type_User,
1661 AppDataW,
1662 Application_DataW,
1664 KF_CATEGORY_PERUSER, /* category */
1665 AppDataW, /* name */
1666 NULL, /* description */
1667 &FOLDERID_Profile, /* parent */
1668 AppData_RoamingW, /* relative path */
1669 NULL, /* parsing */
1670 NULL, /* tooltip */
1671 NULL, /* localized */
1672 NULL, /* icon */
1673 NULL, /* security */
1674 0, /* attributes */
1675 0, /* flags */
1676 &GUID_NULL /* typeid */
1678 { /* 0x1b - CSIDL_PRINTHOOD */
1679 &FOLDERID_PrintHood,
1680 CSIDL_Type_User,
1681 PrintHoodW,
1682 PrintHoodW,
1684 KF_CATEGORY_PERUSER, /* category */
1685 PrintHoodW, /* name */
1686 NULL, /* description */
1687 &FOLDERID_RoamingAppData, /* parent */
1688 Microsoft_Windows_Printer_ShortcutsW, /* relative path */
1689 NULL, /* parsing */
1690 NULL, /* tooltip */
1691 NULL, /* localized */
1692 NULL, /* icon */
1693 NULL, /* security */
1694 0, /* attributes */
1695 0, /* flags */
1696 &GUID_NULL /* typeid */
1698 { /* 0x1c - CSIDL_LOCAL_APPDATA */
1699 &FOLDERID_LocalAppData,
1700 CSIDL_Type_User,
1701 Local_AppDataW,
1702 Local_Settings_Application_DataW,
1704 KF_CATEGORY_PERUSER, /* category */
1705 Local_AppDataW, /* name */
1706 NULL, /* description */
1707 &FOLDERID_Profile, /* parent */
1708 AppData_LocalW, /* relative path */
1709 NULL, /* parsing */
1710 NULL, /* tooltip */
1711 NULL, /* localized */
1712 NULL, /* icon */
1713 NULL, /* security */
1714 0, /* attributes */
1715 KFDF_LOCAL_REDIRECT_ONLY | KFDF_PUBLISHEXPANDEDPATH, /* flags */
1716 &GUID_NULL /* typeid */
1718 { /* 0x1d - CSIDL_ALTSTARTUP */
1719 &GUID_NULL,
1720 CSIDL_Type_NonExistent,
1721 NULL,
1722 NULL
1724 { /* 0x1e - CSIDL_COMMON_ALTSTARTUP */
1725 &GUID_NULL,
1726 CSIDL_Type_NonExistent,
1727 NULL,
1728 NULL
1730 { /* 0x1f - CSIDL_COMMON_FAVORITES */
1731 &FOLDERID_Favorites,
1732 CSIDL_Type_AllUsers,
1733 Common_FavoritesW,
1734 FavoritesW,
1736 KF_CATEGORY_PERUSER, /* category */
1737 FavoritesW, /* name */
1738 NULL, /* description */
1739 &FOLDERID_Profile, /* parent */
1740 FavoritesW, /* relative path */
1741 NULL, /* parsing */
1742 NULL, /* tooltip */
1743 NULL, /* localized */
1744 NULL, /* icon */
1745 NULL, /* security */
1746 FILE_ATTRIBUTE_READONLY, /* attributes */
1747 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH, /* flags */
1748 &GUID_NULL /* typeid */
1750 { /* 0x20 - CSIDL_INTERNET_CACHE */
1751 &FOLDERID_InternetCache,
1752 CSIDL_Type_User,
1753 CacheW,
1754 Local_Settings_Temporary_Internet_FilesW,
1756 KF_CATEGORY_PERUSER, /* category */
1757 CacheW, /* name */
1758 NULL, /* description */
1759 &FOLDERID_LocalAppData, /* parent */
1760 Microsoft_Windows_Temporary_Internet_FilesW, /* relative path */
1761 NULL, /* parsing */
1762 NULL, /* tooltip */
1763 NULL, /* localized */
1764 NULL, /* icon */
1765 NULL, /* security */
1766 0, /* attributes */
1767 KFDF_LOCAL_REDIRECT_ONLY, /* flags */
1768 &GUID_NULL /* typeid */
1770 { /* 0x21 - CSIDL_COOKIES */
1771 &FOLDERID_Cookies,
1772 CSIDL_Type_User,
1773 CookiesW,
1774 CookiesW,
1776 KF_CATEGORY_PERUSER, /* category */
1777 CookiesW, /* name */
1778 NULL, /* description */
1779 &FOLDERID_RoamingAppData, /* parent */
1780 Microsoft_Windows_CookiesW, /* relative path */
1781 NULL, /* parsing */
1782 NULL, /* tooltip */
1783 NULL, /* localized */
1784 NULL, /* icon */
1785 NULL, /* security */
1786 0, /* attributes */
1787 0, /* flags */
1788 &GUID_NULL /* typeid */
1790 { /* 0x22 - CSIDL_HISTORY */
1791 &FOLDERID_History,
1792 CSIDL_Type_User,
1793 HistoryW,
1794 Local_Settings_HistoryW,
1796 KF_CATEGORY_PERUSER, /* category */
1797 HistoryW, /* name */
1798 NULL, /* description */
1799 &FOLDERID_LocalAppData, /* parent */
1800 Microsoft_Windows_HistoryW, /* relative path */
1801 NULL, /* parsing */
1802 NULL, /* tooltip */
1803 NULL, /* localized */
1804 NULL, /* icon */
1805 NULL, /* security */
1806 0, /* attributes */
1807 KFDF_LOCAL_REDIRECT_ONLY, /* flags */
1808 &GUID_NULL /* typeid */
1810 { /* 0x23 - CSIDL_COMMON_APPDATA */
1811 &FOLDERID_ProgramData,
1812 CSIDL_Type_AllUsers,
1813 Common_AppDataW,
1814 Application_DataW,
1816 KF_CATEGORY_FIXED, /* category */
1817 Common_AppDataW, /* name */
1818 NULL, /* description */
1819 &GUID_NULL, /* parent */
1820 NULL, /* relative path */
1821 NULL, /* parsing */
1822 NULL, /* tooltip */
1823 NULL, /* localized */
1824 NULL, /* icon */
1825 NULL, /* security */
1826 0, /* attributes */
1827 0, /* flags */
1828 &GUID_NULL /* typeid */
1830 { /* 0x24 - CSIDL_WINDOWS */
1831 &FOLDERID_Windows,
1832 CSIDL_Type_WindowsPath,
1833 NULL,
1834 NULL,
1836 KF_CATEGORY_FIXED, /* category */
1837 WindowsW, /* name */
1838 NULL, /* description */
1839 &GUID_NULL, /* parent */
1840 NULL, /* relative path */
1841 NULL, /* parsing */
1842 NULL, /* tooltip */
1843 NULL, /* localized */
1844 NULL, /* icon */
1845 NULL, /* security */
1846 0, /* attributes */
1847 0, /* flags */
1848 &GUID_NULL /* typeid */
1850 { /* 0x25 - CSIDL_SYSTEM */
1851 &FOLDERID_System,
1852 CSIDL_Type_SystemPath,
1853 NULL,
1854 NULL,
1856 KF_CATEGORY_FIXED, /* category */
1857 SystemW, /* name */
1858 NULL, /* description */
1859 &GUID_NULL, /* parent */
1860 NULL, /* relative path */
1861 NULL, /* parsing */
1862 NULL, /* tooltip */
1863 NULL, /* localized */
1864 NULL, /* icon */
1865 NULL, /* security */
1866 0, /* attributes */
1867 0, /* flags */
1868 &GUID_NULL /* typeid */
1870 { /* 0x26 - CSIDL_PROGRAM_FILES */
1871 &FOLDERID_ProgramFiles,
1872 CSIDL_Type_CurrVer,
1873 ProgramFilesDirW,
1874 Program_FilesW,
1876 KF_CATEGORY_FIXED, /* category */
1877 ProgramFilesW, /* name */
1878 NULL, /* description */
1879 &GUID_NULL, /* parent */
1880 NULL, /* relative path */
1881 NULL, /* parsing */
1882 NULL, /* tooltip */
1883 NULL, /* localized */
1884 NULL, /* icon */
1885 NULL, /* security */
1886 FILE_ATTRIBUTE_READONLY, /* attributes */
1887 0, /* flags */
1888 &GUID_NULL /* typeid */
1890 { /* 0x27 - CSIDL_MYPICTURES */
1891 &FOLDERID_Pictures,
1892 CSIDL_Type_User,
1893 My_PicturesW,
1894 MAKEINTRESOURCEW(IDS_MYPICTURES),
1896 KF_CATEGORY_PERUSER, /* category */
1897 My_PicturesW, /* name */
1898 NULL, /* description */
1899 &FOLDERID_Profile, /* parent */
1900 PicturesW, /* relative path */
1901 PicturesParsingNameW, /* parsing */
1902 NULL, /* tooltip */
1903 NULL, /* localized */
1904 NULL, /* icon */
1905 NULL, /* security */
1906 FILE_ATTRIBUTE_READONLY, /* attributes */
1907 KFDF_ROAMABLE | KFDF_PRECREATE, /* flags */
1908 &GUID_NULL /* typeid */
1910 { /* 0x28 - CSIDL_PROFILE */
1911 &FOLDERID_Profile,
1912 CSIDL_Type_User,
1913 NULL,
1914 NULL,
1916 KF_CATEGORY_FIXED, /* category */
1917 ProfileW, /* name */
1918 NULL, /* description */
1919 &GUID_NULL, /* parent */
1920 NULL, /* relative path */
1921 NULL, /* parsing */
1922 NULL, /* tooltip */
1923 NULL, /* localized */
1924 NULL, /* icon */
1925 NULL, /* security */
1926 0, /* attributes */
1927 0, /* flags */
1928 &GUID_NULL /* typeid */
1930 { /* 0x29 - CSIDL_SYSTEMX86 */
1931 &FOLDERID_SystemX86,
1932 CSIDL_Type_SystemX86Path,
1933 NULL,
1934 NULL,
1936 KF_CATEGORY_FIXED, /* category */
1937 SystemX86W, /* name */
1938 NULL, /* description */
1939 &GUID_NULL, /* parent */
1940 NULL, /* relative path */
1941 NULL, /* parsing */
1942 NULL, /* tooltip */
1943 NULL, /* localized */
1944 NULL, /* icon */
1945 NULL, /* security */
1946 0, /* attributes */
1947 0, /* flags */
1948 &GUID_NULL /* typeid */
1950 { /* 0x2a - CSIDL_PROGRAM_FILESX86 */
1951 &FOLDERID_ProgramFilesX86,
1952 CSIDL_Type_CurrVer,
1953 ProgramFilesDirX86W,
1954 Program_Files_x86W,
1956 KF_CATEGORY_FIXED, /* category */
1957 ProgramFilesX86W, /* name */
1958 NULL, /* description */
1959 &GUID_NULL, /* parent */
1960 NULL, /* relative path */
1961 NULL, /* parsing */
1962 NULL, /* tooltip */
1963 NULL, /* localized */
1964 NULL, /* icon */
1965 NULL, /* security */
1966 FILE_ATTRIBUTE_READONLY, /* attributes */
1967 0, /* flags */
1968 &GUID_NULL /* typeid */
1970 { /* 0x2b - CSIDL_PROGRAM_FILES_COMMON */
1971 &FOLDERID_ProgramFilesCommon,
1972 CSIDL_Type_CurrVer,
1973 CommonFilesDirW,
1974 Program_Files_Common_FilesW,
1976 KF_CATEGORY_FIXED, /* category */
1977 ProgramFilesCommonW, /* name */
1978 NULL, /* description */
1979 &GUID_NULL, /* parent */
1980 NULL, /* relative path */
1981 NULL, /* parsing */
1982 NULL, /* tooltip */
1983 NULL, /* localized */
1984 NULL, /* icon */
1985 NULL, /* security */
1986 0, /* attributes */
1987 0, /* flags */
1988 &GUID_NULL /* typeid */
1990 { /* 0x2c - CSIDL_PROGRAM_FILES_COMMONX86 */
1991 &FOLDERID_ProgramFilesCommonX86,
1992 CSIDL_Type_CurrVer,
1993 CommonFilesDirX86W,
1994 Program_Files_x86_Common_FilesW,
1996 KF_CATEGORY_FIXED, /* category */
1997 ProgramFilesCommonX86W, /* name */
1998 NULL, /* description */
1999 &GUID_NULL, /* parent */
2000 NULL, /* relative path */
2001 NULL, /* parsing */
2002 NULL, /* tooltip */
2003 NULL, /* localized */
2004 NULL, /* icon */
2005 NULL, /* security */
2006 0, /* attributes */
2007 0, /* flags */
2008 &GUID_NULL /* typeid */
2010 { /* 0x2d - CSIDL_COMMON_TEMPLATES */
2011 &FOLDERID_CommonTemplates,
2012 CSIDL_Type_AllUsers,
2013 Common_TemplatesW,
2014 TemplatesW,
2016 KF_CATEGORY_COMMON, /* category */
2017 Common_TemplatesW, /* name */
2018 NULL, /* description */
2019 &FOLDERID_ProgramData, /* parent */
2020 Microsoft_Windows_TemplatesW, /* relative path */
2021 NULL, /* parsing */
2022 NULL, /* tooltip */
2023 NULL, /* localized */
2024 NULL, /* icon */
2025 NULL, /* security */
2026 0, /* attributes */
2027 0, /* flags */
2028 &GUID_NULL /* typeid */
2030 { /* 0x2e - CSIDL_COMMON_DOCUMENTS */
2031 &FOLDERID_PublicDocuments,
2032 CSIDL_Type_AllUsers,
2033 Common_DocumentsW,
2034 DocumentsW,
2036 KF_CATEGORY_COMMON, /* category */
2037 Common_DocumentsW, /* name */
2038 NULL, /* description */
2039 &FOLDERID_Public, /* parent */
2040 DocumentsW, /* relative path */
2041 NULL, /* parsing */
2042 NULL, /* tooltip */
2043 NULL, /* localized */
2044 NULL, /* icon */
2045 NULL, /* security */
2046 FILE_ATTRIBUTE_READONLY, /* attributes */
2047 KFDF_PRECREATE, /* flags */
2048 &GUID_NULL /* typeid */
2050 { /* 0x2f - CSIDL_COMMON_ADMINTOOLS */
2051 &FOLDERID_CommonAdminTools,
2052 CSIDL_Type_AllUsers,
2053 Common_Administrative_ToolsW,
2054 Start_Menu_Admin_ToolsW,
2056 KF_CATEGORY_COMMON, /* category */
2057 Common_Administrative_ToolsW, /* name */
2058 NULL, /* description */
2059 &FOLDERID_CommonPrograms, /* parent */
2060 Administrative_ToolsW, /* relative path */
2061 NULL, /* parsing */
2062 NULL, /* tooltip */
2063 NULL, /* localized */
2064 NULL, /* icon */
2065 NULL, /* security */
2066 FILE_ATTRIBUTE_READONLY, /* attributes */
2067 KFDF_PRECREATE, /* flags */
2068 &GUID_NULL /* typeid */
2070 { /* 0x30 - CSIDL_ADMINTOOLS */
2071 &FOLDERID_AdminTools,
2072 CSIDL_Type_User,
2073 Administrative_ToolsW,
2074 Start_Menu_Admin_ToolsW,
2076 KF_CATEGORY_PERUSER, /* category */
2077 Administrative_ToolsW, /* name */
2078 NULL, /* description */
2079 &FOLDERID_Programs, /* parent */
2080 Administrative_ToolsW, /* relative path */
2081 NULL, /* parsing */
2082 NULL, /* tooltip */
2083 NULL, /* localized */
2084 NULL, /* icon */
2085 NULL, /* security */
2086 FILE_ATTRIBUTE_READONLY, /* attributes */
2087 KFDF_PRECREATE, /* flags */
2088 &GUID_NULL /* typeid */
2090 { /* 0x31 - CSIDL_CONNECTIONS */
2091 &FOLDERID_ConnectionsFolder,
2092 CSIDL_Type_Disallowed,
2093 NULL,
2094 NULL,
2096 KF_CATEGORY_VIRTUAL, /* category */
2097 ConnectionsFolderW, /* name */
2098 NULL, /* description */
2099 &GUID_NULL, /* parent */
2100 Administrative_ToolsW, /* relative path */
2101 ConnectionsFolderParsingNameW, /* parsing */
2102 NULL, /* tooltip */
2103 NULL, /* localized */
2104 NULL, /* icon */
2105 NULL, /* security */
2106 0, /* attributes */
2107 0, /* flags */
2108 &GUID_NULL /* typeid */
2110 { /* 0x32 - unassigned */
2111 &GUID_NULL,
2112 CSIDL_Type_Disallowed,
2113 NULL,
2114 NULL
2116 { /* 0x33 - unassigned */
2117 &GUID_NULL,
2118 CSIDL_Type_Disallowed,
2119 NULL,
2120 NULL
2122 { /* 0x34 - unassigned */
2123 &GUID_NULL,
2124 CSIDL_Type_Disallowed,
2125 NULL,
2126 NULL
2128 { /* 0x35 - CSIDL_COMMON_MUSIC */
2129 &FOLDERID_PublicMusic,
2130 CSIDL_Type_AllUsers,
2131 CommonMusicW,
2132 MusicW,
2134 KF_CATEGORY_COMMON, /* category */
2135 CommonMusicW, /* name */
2136 NULL, /* description */
2137 &FOLDERID_Public, /* parent */
2138 MusicW, /* relative path */
2139 NULL, /* parsing */
2140 NULL, /* tooltip */
2141 NULL, /* localized */
2142 NULL, /* icon */
2143 NULL, /* security */
2144 FILE_ATTRIBUTE_READONLY, /* attributes */
2145 KFDF_PRECREATE, /* flags */
2146 &GUID_NULL /* typeid */
2148 { /* 0x36 - CSIDL_COMMON_PICTURES */
2149 &FOLDERID_PublicPictures,
2150 CSIDL_Type_AllUsers,
2151 CommonPicturesW,
2152 PicturesW,
2154 KF_CATEGORY_COMMON, /* category */
2155 CommonPicturesW, /* name */
2156 NULL, /* description */
2157 &FOLDERID_Public, /* parent */
2158 PicturesW, /* relative path */
2159 NULL, /* parsing */
2160 NULL, /* tooltip */
2161 NULL, /* localized */
2162 NULL, /* icon */
2163 NULL, /* security */
2164 FILE_ATTRIBUTE_READONLY, /* attributes */
2165 KFDF_PRECREATE, /* flags */
2166 &GUID_NULL /* typeid */
2168 { /* 0x37 - CSIDL_COMMON_VIDEO */
2169 &FOLDERID_PublicVideos,
2170 CSIDL_Type_AllUsers,
2171 CommonVideoW,
2172 VideosW,
2174 KF_CATEGORY_COMMON, /* category */
2175 CommonVideoW, /* name */
2176 NULL, /* description */
2177 &FOLDERID_Public, /* parent */
2178 VideosW, /* relative path */
2179 NULL, /* parsing */
2180 NULL, /* tooltip */
2181 NULL, /* localized */
2182 NULL, /* icon */
2183 NULL, /* security */
2184 FILE_ATTRIBUTE_READONLY, /* attributes */
2185 KFDF_PRECREATE, /* flags */
2186 &GUID_NULL /* typeid */
2188 { /* 0x38 - CSIDL_RESOURCES */
2189 &FOLDERID_ResourceDir,
2190 CSIDL_Type_WindowsPath,
2191 NULL,
2192 ResourcesW,
2194 KF_CATEGORY_FIXED, /* category */
2195 ResourceDirW, /* name */
2196 NULL, /* description */
2197 &GUID_NULL, /* parent */
2198 NULL, /* relative path */
2199 NULL, /* parsing */
2200 NULL, /* tooltip */
2201 NULL, /* localized */
2202 NULL, /* icon */
2203 NULL, /* security */
2204 0, /* attributes */
2205 0, /* flags */
2206 &GUID_NULL /* typeid */
2208 { /* 0x39 - CSIDL_RESOURCES_LOCALIZED */
2209 &FOLDERID_LocalizedResourcesDir,
2210 CSIDL_Type_NonExistent,
2211 NULL,
2212 NULL,
2214 KF_CATEGORY_FIXED, /* category */
2215 LocalizedResourcesDirW, /* name */
2216 NULL, /* description */
2217 &GUID_NULL, /* parent */
2218 NULL, /* relative path */
2219 NULL, /* parsing */
2220 NULL, /* tooltip */
2221 NULL, /* localized */
2222 NULL, /* icon */
2223 NULL, /* security */
2224 0, /* attributes */
2225 0, /* flags */
2226 &GUID_NULL /* typeid */
2228 { /* 0x3a - CSIDL_COMMON_OEM_LINKS */
2229 &FOLDERID_CommonOEMLinks,
2230 CSIDL_Type_AllUsers,
2231 NULL,
2232 OEM_LinksW,
2234 KF_CATEGORY_COMMON, /* category */
2235 OEM_LinksW, /* name */
2236 NULL, /* description */
2237 &FOLDERID_ProgramData, /* parent */
2238 OEM_LinksW, /* relative path */
2239 NULL, /* parsing */
2240 NULL, /* tooltip */
2241 NULL, /* localized */
2242 NULL, /* icon */
2243 NULL, /* security */
2244 0, /* attributes */
2245 0, /* flags */
2246 &GUID_NULL /* typeid */
2248 { /* 0x3b - CSIDL_CDBURN_AREA */
2249 &FOLDERID_CDBurning,
2250 CSIDL_Type_User,
2251 CD_BurningW,
2252 Local_Settings_CD_BurningW,
2254 KF_CATEGORY_PERUSER, /* category */
2255 CD_BurningW, /* name */
2256 NULL, /* description */
2257 &FOLDERID_LocalAppData, /* parent */
2258 Microsoft_Windows_Burn_BurnW, /* relative path */
2259 NULL, /* parsing */
2260 NULL, /* tooltip */
2261 NULL, /* localized */
2262 NULL, /* icon */
2263 NULL, /* security */
2264 FILE_ATTRIBUTE_READONLY, /* attributes */
2265 KFDF_LOCAL_REDIRECT_ONLY, /* flags */
2266 &GUID_NULL /* typeid */
2268 { /* 0x3c unassigned */
2269 &GUID_NULL,
2270 CSIDL_Type_Disallowed,
2271 NULL,
2272 NULL
2274 { /* 0x3d - CSIDL_COMPUTERSNEARME */
2275 &GUID_NULL,
2276 CSIDL_Type_Disallowed, /* FIXME */
2277 NULL,
2278 NULL
2280 { /* 0x3e - CSIDL_PROFILES */
2281 &GUID_NULL,
2282 CSIDL_Type_Disallowed, /* oddly, this matches WinXP */
2283 NULL,
2284 NULL
2286 { /* 0x3f */
2287 &FOLDERID_AddNewPrograms,
2288 CSIDL_Type_Disallowed,
2289 NULL,
2290 NULL,
2292 KF_CATEGORY_VIRTUAL, /* category */
2293 AddNewProgramsFolderW, /* name */
2294 NULL, /* description */
2295 &GUID_NULL, /* parent */
2296 NULL, /* relative path */
2297 AddNewProgramsParsingNameW, /* parsing */
2298 NULL, /* tooltip */
2299 NULL, /* localized */
2300 NULL, /* icon */
2301 NULL, /* security */
2302 0, /* attributes */
2303 0, /* flags */
2304 &GUID_NULL /* typeid */
2306 { /* 0x40 */
2307 &FOLDERID_AppUpdates,
2308 CSIDL_Type_Disallowed,
2309 NULL,
2310 NULL,
2312 KF_CATEGORY_VIRTUAL, /* category */
2313 AppUpdatesFolderW, /* name */
2314 NULL, /* description */
2315 &GUID_NULL, /* parent */
2316 NULL, /* relative path */
2317 AppUpdatesParsingNameW, /* parsing */
2318 NULL, /* tooltip */
2319 NULL, /* localized */
2320 NULL, /* icon */
2321 NULL, /* security */
2322 0, /* attributes */
2323 0, /* flags */
2324 &GUID_NULL /* typeid */
2326 { /* 0x41 */
2327 &FOLDERID_ChangeRemovePrograms,
2328 CSIDL_Type_Disallowed,
2329 NULL,
2330 NULL,
2332 KF_CATEGORY_VIRTUAL, /* category */
2333 ChangeRemoveProgramsFolderW, /* name */
2334 NULL, /* description */
2335 &GUID_NULL, /* parent */
2336 NULL, /* relative path */
2337 ChangeRemoveProgramsParsingNameW, /* parsing */
2338 NULL, /* tooltip */
2339 NULL, /* localized */
2340 NULL, /* icon */
2341 NULL, /* security */
2342 0, /* attributes */
2343 0, /* flags */
2344 &GUID_NULL /* typeid */
2346 { /* 0x42 */
2347 &FOLDERID_ConflictFolder,
2348 CSIDL_Type_Disallowed,
2349 NULL,
2350 NULL,
2352 KF_CATEGORY_VIRTUAL, /* category */
2353 ConflictFolderW, /* name */
2354 NULL, /* description */
2355 &GUID_NULL, /* parent */
2356 NULL, /* relative path */
2357 ConflictFolderParsingNameW, /* parsing */
2358 NULL, /* tooltip */
2359 NULL, /* localized */
2360 NULL, /* icon */
2361 NULL, /* security */
2362 0, /* attributes */
2363 0, /* flags */
2364 &GUID_NULL /* typeid */
2366 { /* 0x43 - CSIDL_CONTACTS */
2367 &FOLDERID_Contacts,
2368 CSIDL_Type_User,
2369 NULL,
2370 ContactsW,
2372 KF_CATEGORY_PERUSER, /* category */
2373 ContactsW, /* name */
2374 NULL, /* description */
2375 &FOLDERID_Profile, /* parent */
2376 ContactsW, /* relative path */
2377 ContactsParsingNameW, /* parsing */
2378 NULL, /* tooltip */
2379 NULL, /* localized */
2380 NULL, /* icon */
2381 NULL, /* security */
2382 FILE_ATTRIBUTE_READONLY, /* attributes */
2383 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH, /* flags */
2384 &GUID_NULL /* typeid */
2386 { /* 0x44 */
2387 &FOLDERID_DeviceMetadataStore,
2388 CSIDL_Type_Disallowed, /* FIXME */
2389 NULL,
2390 NULL,
2392 KF_CATEGORY_COMMON, /* category */
2393 Device_Metadata_StoreW, /* name */
2394 NULL, /* description */
2395 &FOLDERID_ProgramData, /* parent */
2396 Microsoft_Windows_DeviceMetadataStoreW, /* relative path */
2397 NULL, /* parsing */
2398 NULL, /* tooltip */
2399 NULL, /* localized */
2400 NULL, /* icon */
2401 NULL, /* security */
2402 0, /* attributes */
2403 0, /* flags */
2404 &GUID_NULL /* typeid */
2406 { /* 0x45 */
2407 &GUID_NULL,
2408 CSIDL_Type_User,
2409 NULL,
2410 DocumentsW
2412 { /* 0x46 */
2413 &FOLDERID_DocumentsLibrary,
2414 CSIDL_Type_Disallowed, /* FIXME */
2415 NULL,
2416 NULL,
2418 KF_CATEGORY_PERUSER, /* category */
2419 DocumentsLibraryW, /* name */
2420 NULL, /* description */
2421 &FOLDERID_Libraries, /* parent */
2422 Documents_librarymsW, /* relative path */
2423 DocumentsLibraryParsingNameW, /* parsing */
2424 NULL, /* tooltip */
2425 NULL, /* localized */
2426 NULL, /* icon */
2427 NULL, /* security */
2428 0, /* attributes */
2429 KFDF_PRECREATE | KFDF_STREAM, /* flags */
2430 &GUID_NULL /* typeid */
2432 { /* 0x47 - CSIDL_DOWNLOADS */
2433 &FOLDERID_Downloads,
2434 CSIDL_Type_User,
2435 NULL,
2436 DownloadsW,
2438 KF_CATEGORY_PERUSER, /* category */
2439 DownloadsW, /* name */
2440 NULL, /* description */
2441 &FOLDERID_Profile, /* parent */
2442 DownloadsW, /* relative path */
2443 NULL, /* parsing */
2444 NULL, /* tooltip */
2445 NULL, /* localized */
2446 NULL, /* icon */
2447 NULL, /* security */
2448 FILE_ATTRIBUTE_READONLY, /* attributes */
2449 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH, /* flags */
2450 &GUID_NULL /* typeid */
2452 { /* 0x48 */
2453 &FOLDERID_Games,
2454 CSIDL_Type_Disallowed,
2455 NULL,
2456 NULL,
2458 KF_CATEGORY_VIRTUAL, /* category */
2459 GamesW, /* name */
2460 NULL, /* description */
2461 &GUID_NULL, /* parent */
2462 NULL, /* relative path */
2463 GamesParsingNameW, /* parsing */
2464 NULL, /* tooltip */
2465 NULL, /* localized */
2466 NULL, /* icon */
2467 NULL, /* security */
2468 0, /* attributes */
2469 0, /* flags */
2470 &GUID_NULL /* typeid */
2472 { /* 0x49 */
2473 &FOLDERID_GameTasks,
2474 CSIDL_Type_Disallowed, /* FIXME */
2475 NULL,
2476 NULL,
2478 KF_CATEGORY_PERUSER, /* category */
2479 GameTasksW, /* name */
2480 NULL, /* description */
2481 &FOLDERID_LocalAppData, /* parent */
2482 Microsoft_Windows_GameExplorerW, /* relative path */
2483 NULL, /* parsing */
2484 NULL, /* tooltip */
2485 NULL, /* localized */
2486 NULL, /* icon */
2487 NULL, /* security */
2488 0, /* attributes */
2489 KFDF_LOCAL_REDIRECT_ONLY, /* flags */
2490 &GUID_NULL /* typeid */
2492 { /* 0x4a */
2493 &FOLDERID_HomeGroup,
2494 CSIDL_Type_Disallowed,
2495 NULL,
2496 NULL,
2498 KF_CATEGORY_VIRTUAL, /* category */
2499 HomeGroupFolderW, /* name */
2500 NULL, /* description */
2501 &GUID_NULL, /* parent */
2502 NULL, /* relative path */
2503 HomeGroupParsingNameW, /* parsing */
2504 NULL, /* tooltip */
2505 NULL, /* localized */
2506 NULL, /* icon */
2507 NULL, /* security */
2508 0, /* attributes */
2509 0, /* flags */
2510 &GUID_NULL /* typeid */
2512 { /* 0x4b */
2513 &FOLDERID_ImplicitAppShortcuts,
2514 CSIDL_Type_Disallowed, /* FIXME */
2515 NULL,
2516 NULL,
2518 KF_CATEGORY_PERUSER, /* category */
2519 ImplicitAppShortcutsW, /* name */
2520 NULL, /* description */
2521 &FOLDERID_UserPinned, /* parent */
2522 ImplicitAppShortcutsW, /* relative path */
2523 NULL, /* parsing */
2524 NULL, /* tooltip */
2525 NULL, /* localized */
2526 NULL, /* icon */
2527 NULL, /* security */
2528 0, /* attributes */
2529 KFDF_PRECREATE, /* flags */
2530 &GUID_NULL /* typeid */
2532 { /* 0x4c */
2533 &FOLDERID_Libraries,
2534 CSIDL_Type_Disallowed, /* FIXME */
2535 NULL,
2536 NULL,
2538 KF_CATEGORY_PERUSER, /* category */
2539 LibrariesW, /* name */
2540 NULL, /* description */
2541 &FOLDERID_RoamingAppData, /* parent */
2542 Microsoft_Windows_LibrariesW, /* relative path */
2543 NULL, /* parsing */
2544 NULL, /* tooltip */
2545 NULL, /* localized */
2546 NULL, /* icon */
2547 NULL, /* security */
2548 0, /* attributes */
2549 KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH, /* flags */
2550 &GUID_NULL /* typeid */
2552 { /* 0x4d - CSIDL_LINKS */
2553 &FOLDERID_Links,
2554 CSIDL_Type_User,
2555 NULL,
2556 LinksW,
2558 KF_CATEGORY_PERUSER, /* category */
2559 LinksW, /* name */
2560 NULL, /* description */
2561 &FOLDERID_Profile, /* parent */
2562 LinksW, /* relative path */
2563 LinksParsingNameW, /* parsing */
2564 NULL, /* tooltip */
2565 NULL, /* localized */
2566 NULL, /* icon */
2567 NULL, /* security */
2568 FILE_ATTRIBUTE_READONLY, /* attributes */
2569 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH, /* flags */
2570 &GUID_NULL /* typeid */
2572 { /* 0x4e - CSIDL_APPDATA_LOCALLOW */
2573 &FOLDERID_LocalAppDataLow,
2574 CSIDL_Type_User,
2575 NULL,
2576 AppData_LocalLowW,
2578 KF_CATEGORY_PERUSER, /* category */
2579 LocalAppDataLowW, /* name */
2580 NULL, /* description */
2581 &FOLDERID_Profile, /* parent */
2582 AppData_LocalLowW, /* relative path */
2583 NULL, /* parsing */
2584 NULL, /* tooltip */
2585 NULL, /* localized */
2586 NULL, /* icon */
2587 NULL, /* security */
2588 FILE_ATTRIBUTE_NOT_CONTENT_INDEXED, /* attributes */
2589 KFDF_LOCAL_REDIRECT_ONLY | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH, /* flags */
2590 &GUID_NULL /* typeid */
2592 { /* 0x4f */
2593 &FOLDERID_MusicLibrary,
2594 CSIDL_Type_Disallowed, /* FIXME */
2595 NULL,
2596 NULL,
2598 KF_CATEGORY_PERUSER, /* category */
2599 MusicLibraryW, /* name */
2600 NULL, /* description */
2601 &FOLDERID_Libraries, /* parent */
2602 Music_librarymsW, /* relative path */
2603 MusicLibraryParsingNameW, /* parsing */
2604 NULL, /* tooltip */
2605 NULL, /* localized */
2606 NULL, /* icon */
2607 NULL, /* security */
2608 0, /* attributes */
2609 KFDF_PRECREATE | KFDF_STREAM, /* flags */
2610 &GUID_NULL /* typeid */
2612 { /* 0x50 */
2613 &FOLDERID_OriginalImages,
2614 CSIDL_Type_Disallowed, /* FIXME */
2615 NULL,
2616 NULL,
2618 KF_CATEGORY_PERUSER, /* category */
2619 Original_ImagesW, /* name */
2620 NULL, /* description */
2621 &FOLDERID_LocalAppData, /* parent */
2622 Microsoft_Windows_Photo_Gallery_Original_ImagesW, /* relative path */
2623 NULL, /* parsing */
2624 NULL, /* tooltip */
2625 NULL, /* localized */
2626 NULL, /* icon */
2627 NULL, /* security */
2628 0, /* attributes */
2629 0, /* flags */
2630 &GUID_NULL /* typeid */
2632 { /* 0x51 */
2633 &FOLDERID_PhotoAlbums,
2634 CSIDL_Type_User,
2635 NULL,
2636 Pictures_Slide_ShowsW,
2638 KF_CATEGORY_PERUSER, /* category */
2639 PhotoAlbumsW, /* name */
2640 NULL, /* description */
2641 &FOLDERID_Pictures, /* parent */
2642 Slide_ShowsW, /* relative path */
2643 NULL, /* parsing */
2644 NULL, /* tooltip */
2645 NULL, /* localized */
2646 NULL, /* icon */
2647 NULL, /* security */
2648 FILE_ATTRIBUTE_READONLY, /* attributes */
2649 0, /* flags */
2650 &GUID_NULL /* typeid */
2652 { /* 0x52 */
2653 &FOLDERID_PicturesLibrary,
2654 CSIDL_Type_Disallowed, /* FIXME */
2655 NULL,
2656 NULL,
2658 KF_CATEGORY_PERUSER, /* category */
2659 PicturesLibraryW, /* name */
2660 NULL, /* description */
2661 &FOLDERID_Libraries, /* parent */
2662 Pictures_librarymsW, /* relative path */
2663 PicturesLibraryParsingNameW, /* parsing */
2664 NULL, /* tooltip */
2665 NULL, /* localized */
2666 NULL, /* icon */
2667 NULL, /* security */
2668 0, /* attributes */
2669 KFDF_PRECREATE | KFDF_STREAM, /* flags */
2670 &GUID_NULL /* typeid */
2672 { /* 0x53 */
2673 &FOLDERID_Playlists,
2674 CSIDL_Type_User,
2675 NULL,
2676 Music_PlaylistsW,
2678 KF_CATEGORY_PERUSER, /* category */
2679 PlaylistsW, /* name */
2680 NULL, /* description */
2681 &FOLDERID_Music, /* parent */
2682 PlaylistsW, /* relative path */
2683 NULL, /* parsing */
2684 NULL, /* tooltip */
2685 NULL, /* localized */
2686 NULL, /* icon */
2687 NULL, /* security */
2688 FILE_ATTRIBUTE_READONLY, /* attributes */
2689 0, /* flags */
2690 &GUID_NULL /* typeid */
2692 { /* 0x54 */
2693 &FOLDERID_ProgramFilesX64,
2694 CSIDL_Type_NonExistent,
2695 NULL,
2696 NULL,
2698 KF_CATEGORY_FIXED, /* category */
2699 ProgramFilesX64W, /* name */
2700 NULL, /* description */
2701 &GUID_NULL, /* parent */
2702 NULL, /* relative path */
2703 NULL, /* parsing */
2704 NULL, /* tooltip */
2705 NULL, /* localized */
2706 NULL, /* icon */
2707 NULL, /* security */
2708 0, /* attributes */
2709 0, /* flags */
2710 &GUID_NULL /* typeid */
2712 { /* 0x55 */
2713 &FOLDERID_ProgramFilesCommonX64,
2714 CSIDL_Type_NonExistent,
2715 NULL,
2716 NULL,
2718 KF_CATEGORY_FIXED, /* category */
2719 ProgramFilesCommonX64W, /* name */
2720 NULL, /* description */
2721 &GUID_NULL, /* parent */
2722 NULL, /* relative path */
2723 NULL, /* parsing */
2724 NULL, /* tooltip */
2725 NULL, /* localized */
2726 NULL, /* icon */
2727 NULL, /* security */
2728 0, /* attributes */
2729 0, /* flags */
2730 &GUID_NULL /* typeid */
2732 { /* 0x56 */
2733 &FOLDERID_Public,
2734 CSIDL_Type_CurrVer, /* FIXME */
2735 NULL,
2736 UsersPublicW,
2738 KF_CATEGORY_FIXED, /* category */
2739 PublicW, /* name */
2740 NULL, /* description */
2741 &GUID_NULL, /* parent */
2742 NULL, /* relative path */
2743 PublicParsingNameW, /* parsing */
2744 NULL, /* tooltip */
2745 NULL, /* localized */
2746 NULL, /* icon */
2747 NULL, /* security */
2748 FILE_ATTRIBUTE_READONLY, /* attributes */
2749 KFDF_PRECREATE, /* flags */
2750 &GUID_NULL /* typeid */
2752 { /* 0x57 */
2753 &FOLDERID_PublicDownloads,
2754 CSIDL_Type_AllUsers,
2755 NULL,
2756 DownloadsW,
2758 KF_CATEGORY_COMMON, /* category */
2759 CommonDownloadsW, /* name */
2760 NULL, /* description */
2761 &FOLDERID_Public, /* parent */
2762 DownloadsW, /* relative path */
2763 NULL, /* parsing */
2764 NULL, /* tooltip */
2765 NULL, /* localized */
2766 NULL, /* icon */
2767 NULL, /* security */
2768 FILE_ATTRIBUTE_READONLY, /* attributes */
2769 KFDF_PRECREATE, /* flags */
2770 &GUID_NULL /* typeid */
2772 { /* 0x58 */
2773 &FOLDERID_PublicGameTasks,
2774 CSIDL_Type_AllUsers,
2775 NULL,
2776 Microsoft_Windows_GameExplorerW,
2778 KF_CATEGORY_COMMON, /* category */
2779 PublicGameTasksW, /* name */
2780 NULL, /* description */
2781 &FOLDERID_ProgramData, /* parent */
2782 Microsoft_Windows_GameExplorerW, /* relative path */
2783 NULL, /* parsing */
2784 NULL, /* tooltip */
2785 NULL, /* localized */
2786 NULL, /* icon */
2787 NULL, /* security */
2788 0, /* attributes */
2789 KFDF_LOCAL_REDIRECT_ONLY, /* flags */
2790 &GUID_NULL /* typeid */
2792 { /* 0x59 */
2793 &FOLDERID_PublicLibraries,
2794 CSIDL_Type_AllUsers,
2795 NULL,
2796 Microsoft_Windows_LibrariesW,
2798 KF_CATEGORY_COMMON, /* category */
2799 PublicLibrariesW, /* name */
2800 NULL, /* description */
2801 &FOLDERID_Public, /* parent */
2802 LibrariesW, /* relative path */
2803 NULL, /* parsing */
2804 NULL, /* tooltip */
2805 NULL, /* localized */
2806 NULL, /* icon */
2807 NULL, /* security */
2808 FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN, /* attributes */
2809 KFDF_PRECREATE, /* flags */
2810 &GUID_NULL /* typeid */
2812 { /* 0x5a */
2813 &FOLDERID_PublicRingtones,
2814 CSIDL_Type_AllUsers,
2815 NULL,
2816 Microsoft_Windows_RingtonesW,
2818 KF_CATEGORY_COMMON, /* category */
2819 CommonRingtonesW, /* name */
2820 NULL, /* description */
2821 &FOLDERID_ProgramData, /* parent */
2822 Microsoft_Windows_RingtonesW, /* relative path */
2823 NULL, /* parsing */
2824 NULL, /* tooltip */
2825 NULL, /* localized */
2826 NULL, /* icon */
2827 NULL, /* security */
2828 0, /* attributes */
2829 KFDF_PRECREATE, /* flags */
2830 &GUID_NULL /* typeid */
2832 { /* 0x5b */
2833 &FOLDERID_QuickLaunch,
2834 CSIDL_Type_Disallowed, /* FIXME */
2835 NULL,
2836 NULL,
2838 KF_CATEGORY_PERUSER, /* category */
2839 Quick_LaunchW, /* name */
2840 NULL, /* description */
2841 &FOLDERID_RoamingAppData, /* parent */
2842 Microsoft_Internet_Explorer_Quick_LaunchW, /* relative path */
2843 NULL, /* parsing */
2844 NULL, /* tooltip */
2845 NULL, /* localized */
2846 NULL, /* icon */
2847 NULL, /* security */
2848 0, /* attributes */
2849 0, /* flags */
2850 &GUID_NULL /* typeid */
2852 { /* 0x5c */
2853 &FOLDERID_RecordedTVLibrary,
2854 CSIDL_Type_Disallowed, /* FIXME */
2855 NULL,
2856 NULL,
2858 KF_CATEGORY_COMMON, /* category */
2859 RecordedTVLibraryW, /* name */
2860 NULL, /* description */
2861 &FOLDERID_PublicLibraries, /* parent */
2862 RecordedTV_librarymsW, /* relative path */
2863 NULL, /* parsing */
2864 NULL, /* tooltip */
2865 NULL, /* localized */
2866 NULL, /* icon */
2867 NULL, /* security */
2868 0, /* attributes */
2869 KFDF_PRECREATE | KFDF_STREAM, /* flags */
2870 &GUID_NULL /* typeid */
2872 { /* 0x5d */
2873 &FOLDERID_Ringtones,
2874 CSIDL_Type_Disallowed, /* FIXME */
2875 NULL,
2876 NULL,
2878 KF_CATEGORY_PERUSER, /* category */
2879 RingtonesW, /* name */
2880 NULL, /* description */
2881 &FOLDERID_LocalAppData, /* parent */
2882 Microsoft_Windows_RingtonesW, /* relative path */
2883 NULL, /* parsing */
2884 NULL, /* tooltip */
2885 NULL, /* localized */
2886 NULL, /* icon */
2887 NULL, /* security */
2888 0, /* attributes */
2889 KFDF_PRECREATE, /* flags */
2890 &GUID_NULL /* typeid */
2892 { /* 0x5e */
2893 &FOLDERID_SampleMusic,
2894 CSIDL_Type_AllUsers,
2895 NULL,
2896 Music_Sample_MusicW,
2898 KF_CATEGORY_COMMON, /* category */
2899 SampleMusicW, /* name */
2900 NULL, /* description */
2901 &FOLDERID_PublicMusic, /* parent */
2902 Sample_MusicW, /* relative path */
2903 NULL, /* parsing */
2904 NULL, /* tooltip */
2905 NULL, /* localized */
2906 NULL, /* icon */
2907 NULL, /* security */
2908 FILE_ATTRIBUTE_READONLY, /* attributes */
2909 KFDF_PRECREATE, /* flags */
2910 &GUID_NULL /* typeid */
2912 { /* 0x5f */
2913 &FOLDERID_SamplePictures,
2914 CSIDL_Type_AllUsers,
2915 NULL,
2916 Pictures_Sample_PicturesW,
2918 KF_CATEGORY_COMMON, /* category */
2919 SamplePicturesW, /* name */
2920 NULL, /* description */
2921 &FOLDERID_PublicPictures, /* parent */
2922 Sample_PicturesW, /* relative path */
2923 NULL, /* parsing */
2924 NULL, /* tooltip */
2925 NULL, /* localized */
2926 NULL, /* icon */
2927 NULL, /* security */
2928 FILE_ATTRIBUTE_READONLY, /* attributes */
2929 KFDF_PRECREATE, /* flags */
2930 &GUID_NULL /* typeid */
2932 { /* 0x60 */
2933 &FOLDERID_SamplePlaylists,
2934 CSIDL_Type_AllUsers,
2935 NULL,
2936 Music_Sample_PlaylistsW,
2938 KF_CATEGORY_COMMON, /* category */
2939 SamplePlaylistsW, /* name */
2940 NULL, /* description */
2941 &FOLDERID_PublicMusic, /* parent */
2942 Sample_PlaylistsW, /* relative path */
2943 NULL, /* parsing */
2944 NULL, /* tooltip */
2945 NULL, /* localized */
2946 NULL, /* icon */
2947 NULL, /* security */
2948 FILE_ATTRIBUTE_READONLY, /* attributes */
2949 KFDF_PRECREATE, /* flags */
2950 &GUID_NULL /* typeid */
2952 { /* 0x61 */
2953 &FOLDERID_SampleVideos,
2954 CSIDL_Type_AllUsers,
2955 NULL,
2956 Videos_Sample_VideosW,
2958 KF_CATEGORY_COMMON, /* category */
2959 SampleVideosW, /* name */
2960 NULL, /* description */
2961 &FOLDERID_PublicVideos, /* parent */
2962 Sample_VideosW, /* relative path */
2963 NULL, /* parsing */
2964 NULL, /* tooltip */
2965 NULL, /* localized */
2966 NULL, /* icon */
2967 NULL, /* security */
2968 FILE_ATTRIBUTE_READONLY, /* attributes */
2969 KFDF_PRECREATE, /* flags */
2970 &GUID_NULL /* typeid */
2972 { /* 0x62 - CSIDL_SAVED_GAMES */
2973 &FOLDERID_SavedGames,
2974 CSIDL_Type_User,
2975 NULL,
2976 Saved_GamesW,
2978 KF_CATEGORY_PERUSER, /* category */
2979 SavedGamesW, /* name */
2980 NULL, /* description */
2981 &FOLDERID_Profile, /* parent */
2982 Saved_GamesW, /* relative path */
2983 SavedGamesParsingNameW, /* parsing */
2984 NULL, /* tooltip */
2985 NULL, /* localized */
2986 NULL, /* icon */
2987 NULL, /* security */
2988 FILE_ATTRIBUTE_READONLY, /* attributes */
2989 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH, /* flags */
2990 &GUID_NULL /* typeid */
2992 { /* 0x63 - CSIDL_SEARCHES */
2993 &FOLDERID_SavedSearches,
2994 CSIDL_Type_User,
2995 NULL,
2996 SearchesW,
2998 KF_CATEGORY_PERUSER, /* category */
2999 SearchesW, /* name */
3000 NULL, /* description */
3001 &FOLDERID_Profile, /* parent */
3002 SearchesW, /* relative path */
3003 SavedSearchesParsingNameW, /* parsing */
3004 NULL, /* tooltip */
3005 NULL, /* localized */
3006 NULL, /* icon */
3007 NULL, /* security */
3008 FILE_ATTRIBUTE_READONLY, /* attributes */
3009 KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH, /* flags */
3010 &GUID_NULL /* typeid */
3012 { /* 0x64 */
3013 &FOLDERID_SEARCH_CSC,
3014 CSIDL_Type_Disallowed,
3015 NULL,
3016 NULL,
3018 KF_CATEGORY_VIRTUAL, /* category */
3019 CSCFolderW, /* name */
3020 NULL, /* description */
3021 &GUID_NULL, /* parent */
3022 NULL, /* relative path */
3023 SEARCH_CSCParsingNameW, /* parsing */
3024 NULL, /* tooltip */
3025 NULL, /* localized */
3026 NULL, /* icon */
3027 NULL, /* security */
3028 0, /* attributes */
3029 0, /* flags */
3030 &GUID_NULL /* typeid */
3032 { /* 0x65 */
3033 &FOLDERID_SEARCH_MAPI,
3034 CSIDL_Type_Disallowed,
3035 NULL,
3036 NULL,
3038 KF_CATEGORY_VIRTUAL, /* category */
3039 MAPIFolderW, /* name */
3040 NULL, /* description */
3041 &GUID_NULL, /* parent */
3042 NULL, /* relative path */
3043 SEARCH_MAPIParsingNameW, /* parsing */
3044 NULL, /* tooltip */
3045 NULL, /* localized */
3046 NULL, /* icon */
3047 NULL, /* security */
3048 0, /* attributes */
3049 0, /* flags */
3050 &GUID_NULL /* typeid */
3052 { /* 0x66 */
3053 &FOLDERID_SearchHome,
3054 CSIDL_Type_Disallowed,
3055 NULL,
3056 NULL,
3058 KF_CATEGORY_VIRTUAL, /* category */
3059 SearchHomeFolderW, /* name */
3060 NULL, /* description */
3061 &GUID_NULL, /* parent */
3062 NULL, /* relative path */
3063 SearchHomeParsingNameW, /* parsing */
3064 NULL, /* tooltip */
3065 NULL, /* localized */
3066 NULL, /* icon */
3067 NULL, /* security */
3068 0, /* attributes */
3069 0, /* flags */
3070 &GUID_NULL /* typeid */
3072 { /* 0x67 */
3073 &FOLDERID_SidebarDefaultParts,
3074 CSIDL_Type_Disallowed, /* FIXME */
3075 NULL,
3076 NULL,
3078 KF_CATEGORY_COMMON, /* category */
3079 Default_GadgetsW, /* name */
3080 NULL, /* description */
3081 &FOLDERID_ProgramFiles, /* parent */
3082 Windows_Sidebar_GadgetsW, /* relative path */
3083 NULL, /* parsing */
3084 NULL, /* tooltip */
3085 NULL, /* localized */
3086 NULL, /* icon */
3087 NULL, /* security */
3088 0, /* attributes */
3089 0, /* flags */
3090 &GUID_NULL /* typeid */
3092 { /* 0x68 */
3093 &FOLDERID_SidebarParts,
3094 CSIDL_Type_Disallowed, /* FIXME */
3095 NULL,
3096 NULL,
3098 KF_CATEGORY_PERUSER, /* category */
3099 GadgetsW, /* name */
3100 NULL, /* description */
3101 &FOLDERID_LocalAppData, /* parent */
3102 Microsoft_Windows_Sidebar_GadgetsW, /* relative path */
3103 NULL, /* parsing */
3104 NULL, /* tooltip */
3105 NULL, /* localized */
3106 NULL, /* icon */
3107 NULL, /* security */
3108 0, /* attributes */
3109 0, /* flags */
3110 &GUID_NULL /* typeid */
3112 { /* 0x69 */
3113 &FOLDERID_SyncManagerFolder,
3114 CSIDL_Type_Disallowed,
3115 NULL,
3116 NULL,
3118 KF_CATEGORY_VIRTUAL, /* category */
3119 SyncCenterFolderW, /* name */
3120 NULL, /* description */
3121 &GUID_NULL, /* parent */
3122 NULL, /* relative path */
3123 SyncManagerFolderParsingNameW, /* parsing */
3124 NULL, /* tooltip */
3125 NULL, /* localized */
3126 NULL, /* icon */
3127 NULL, /* security */
3128 0, /* attributes */
3129 0, /* flags */
3130 &GUID_NULL /* typeid */
3132 { /* 0x6a */
3133 &FOLDERID_SyncResultsFolder,
3134 CSIDL_Type_Disallowed,
3135 NULL,
3136 NULL,
3138 KF_CATEGORY_VIRTUAL, /* category */
3139 SyncResultsFolderW, /* name */
3140 NULL, /* description */
3141 &GUID_NULL, /* parent */
3142 NULL, /* relative path */
3143 SyncResultsFolderParsingNameW, /* parsing */
3144 NULL, /* tooltip */
3145 NULL, /* localized */
3146 NULL, /* icon */
3147 NULL, /* security */
3148 0, /* attributes */
3149 0, /* flags */
3150 &GUID_NULL /* typeid */
3152 { /* 0x6b */
3153 &FOLDERID_SyncSetupFolder,
3154 CSIDL_Type_Disallowed,
3155 NULL,
3156 NULL,
3158 KF_CATEGORY_VIRTUAL, /* category */
3159 SyncSetupFolderW, /* name */
3160 NULL, /* description */
3161 &GUID_NULL, /* parent */
3162 NULL, /* relative path */
3163 SyncSetupFolderParsingNameW, /* parsing */
3164 NULL, /* tooltip */
3165 NULL, /* localized */
3166 NULL, /* icon */
3167 NULL, /* security */
3168 0, /* attributes */
3169 0, /* flags */
3170 &GUID_NULL /* typeid */
3172 { /* 0x6c */
3173 &FOLDERID_UserPinned,
3174 CSIDL_Type_Disallowed, /* FIXME */
3175 NULL,
3176 NULL,
3178 KF_CATEGORY_PERUSER, /* category */
3179 User_PinnedW, /* name */
3180 NULL, /* description */
3181 &FOLDERID_QuickLaunch, /* parent */
3182 User_PinnedW, /* relative path */
3183 NULL, /* parsing */
3184 NULL, /* tooltip */
3185 NULL, /* localized */
3186 NULL, /* icon */
3187 NULL, /* security */
3188 FILE_ATTRIBUTE_HIDDEN, /* attributes */
3189 KFDF_PRECREATE, /* flags */
3190 &GUID_NULL /* typeid */
3192 { /* 0x6d */
3193 &FOLDERID_UserProfiles,
3194 CSIDL_Type_CurrVer,
3195 UsersW,
3196 UsersW,
3198 KF_CATEGORY_FIXED, /* category */
3199 UserProfilesW, /* name */
3200 NULL, /* description */
3201 &GUID_NULL, /* parent */
3202 NULL, /* relative path */
3203 NULL, /* parsing */
3204 NULL, /* tooltip */
3205 NULL, /* localized */
3206 NULL, /* icon */
3207 NULL, /* security */
3208 FILE_ATTRIBUTE_READONLY, /* attributes */
3209 KFDF_PRECREATE, /* flags */
3210 &GUID_NULL /* typeid */
3212 { /* 0x6e */
3213 &FOLDERID_UserProgramFiles,
3214 CSIDL_Type_Disallowed, /* FIXME */
3215 NULL,
3216 NULL,
3218 KF_CATEGORY_PERUSER, /* category */
3219 UserProgramFilesW, /* name */
3220 NULL, /* description */
3221 &FOLDERID_LocalAppData, /* parent */
3222 ProgramsW, /* relative path */
3223 NULL, /* parsing */
3224 NULL, /* tooltip */
3225 NULL, /* localized */
3226 NULL, /* icon */
3227 NULL, /* security */
3228 0, /* attributes */
3229 0, /* flags */
3230 &GUID_NULL /* typeid */
3232 { /* 0x6f */
3233 &FOLDERID_UserProgramFilesCommon,
3234 CSIDL_Type_Disallowed, /* FIXME */
3235 NULL,
3236 NULL,
3238 KF_CATEGORY_PERUSER, /* category */
3239 UserProgramFilesCommonW, /* name */
3240 NULL, /* description */
3241 &FOLDERID_UserProgramFiles, /* parent */
3242 CommonW, /* relative path */
3243 NULL, /* parsing */
3244 NULL, /* tooltip */
3245 NULL, /* localized */
3246 NULL, /* icon */
3247 NULL, /* security */
3248 0, /* attributes */
3249 0, /* flags */
3250 &GUID_NULL /* typeid */
3252 { /* 0x70 */
3253 &FOLDERID_UsersFiles,
3254 CSIDL_Type_Disallowed,
3255 NULL,
3256 NULL,
3258 KF_CATEGORY_VIRTUAL, /* category */
3259 UsersFilesFolderW, /* name */
3260 NULL, /* description */
3261 &GUID_NULL, /* parent */
3262 NULL, /* relative path */
3263 UsersFilesParsingNameW, /* parsing */
3264 NULL, /* tooltip */
3265 NULL, /* localized */
3266 NULL, /* icon */
3267 NULL, /* security */
3268 0, /* attributes */
3269 0, /* flags */
3270 &GUID_NULL /* typeid */
3272 { /* 0x71 */
3273 &FOLDERID_UsersLibraries,
3274 CSIDL_Type_Disallowed,
3275 NULL,
3276 NULL,
3278 KF_CATEGORY_VIRTUAL, /* category */
3279 UsersLibrariesFolderW, /* name */
3280 NULL, /* description */
3281 &GUID_NULL, /* parent */
3282 NULL, /* relative path */
3283 UsersLibrariesParsingNameW, /* parsing */
3284 NULL, /* tooltip */
3285 NULL, /* localized */
3286 NULL, /* icon */
3287 NULL, /* security */
3288 0, /* attributes */
3289 0, /* flags */
3290 &GUID_NULL /* typeid */
3292 { /* 0x72 */
3293 &FOLDERID_VideosLibrary,
3294 CSIDL_Type_Disallowed, /* FIXME */
3295 NULL,
3296 NULL,
3298 KF_CATEGORY_PERUSER, /* category */
3299 VideosLibraryW, /* name */
3300 NULL, /* description */
3301 &GUID_NULL, /* parent */
3302 Videos_librarymsW, /* relative path */
3303 VideosLibraryParsingNameW, /* parsing */
3304 NULL, /* tooltip */
3305 NULL, /* localized */
3306 NULL, /* icon */
3307 NULL, /* security */
3308 0, /* attributes */
3309 0, /* flags */
3310 &GUID_NULL /* typeid */
3314 static HRESULT _SHExpandEnvironmentStrings(LPCWSTR szSrc, LPWSTR szDest);
3316 /* Gets the value named value from the registry key
3317 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
3318 * (or from rootKey\userPrefix\... if userPrefix is not NULL) into path, which
3319 * is assumed to be MAX_PATH WCHARs in length.
3320 * If it exists, expands the value and writes the expanded value to
3321 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
3322 * Returns successful error code if the value was retrieved from the registry,
3323 * and a failure otherwise.
3325 static HRESULT _SHGetUserShellFolderPath(HKEY rootKey, LPCWSTR userPrefix,
3326 LPCWSTR value, LPWSTR path)
3328 HRESULT hr;
3329 WCHAR shellFolderPath[MAX_PATH], userShellFolderPath[MAX_PATH];
3330 LPCWSTR pShellFolderPath, pUserShellFolderPath;
3331 HKEY userShellFolderKey, shellFolderKey;
3332 DWORD dwType, dwPathLen;
3334 TRACE("%p,%s,%s,%p\n",rootKey, debugstr_w(userPrefix), debugstr_w(value),
3335 path);
3337 if (userPrefix)
3339 strcpyW(shellFolderPath, userPrefix);
3340 PathAddBackslashW(shellFolderPath);
3341 strcatW(shellFolderPath, szSHFolders);
3342 pShellFolderPath = shellFolderPath;
3343 strcpyW(userShellFolderPath, userPrefix);
3344 PathAddBackslashW(userShellFolderPath);
3345 strcatW(userShellFolderPath, szSHUserFolders);
3346 pUserShellFolderPath = userShellFolderPath;
3348 else
3350 pUserShellFolderPath = szSHUserFolders;
3351 pShellFolderPath = szSHFolders;
3354 if (RegCreateKeyW(rootKey, pShellFolderPath, &shellFolderKey))
3356 TRACE("Failed to create %s\n", debugstr_w(pShellFolderPath));
3357 return E_FAIL;
3359 if (RegCreateKeyW(rootKey, pUserShellFolderPath, &userShellFolderKey))
3361 TRACE("Failed to create %s\n",
3362 debugstr_w(pUserShellFolderPath));
3363 RegCloseKey(shellFolderKey);
3364 return E_FAIL;
3367 dwPathLen = MAX_PATH * sizeof(WCHAR);
3368 if (!RegQueryValueExW(userShellFolderKey, value, NULL, &dwType,
3369 (LPBYTE)path, &dwPathLen) && (dwType == REG_EXPAND_SZ || dwType == REG_SZ))
3371 LONG ret;
3373 path[dwPathLen / sizeof(WCHAR)] = '\0';
3374 if (dwType == REG_EXPAND_SZ && path[0] == '%')
3376 WCHAR szTemp[MAX_PATH];
3378 _SHExpandEnvironmentStrings(path, szTemp);
3379 lstrcpynW(path, szTemp, MAX_PATH);
3381 ret = RegSetValueExW(shellFolderKey, value, 0, REG_SZ, (LPBYTE)path,
3382 (strlenW(path) + 1) * sizeof(WCHAR));
3383 if (ret != ERROR_SUCCESS)
3384 hr = HRESULT_FROM_WIN32(ret);
3385 else
3386 hr = S_OK;
3388 else
3389 hr = E_FAIL;
3390 RegCloseKey(shellFolderKey);
3391 RegCloseKey(userShellFolderKey);
3392 TRACE("returning 0x%08x\n", hr);
3393 return hr;
3396 /* Gets a 'semi-expanded' default value of the CSIDL with index folder into
3397 * pszPath, based on the entries in CSIDL_Data. By semi-expanded, I mean:
3398 * - The entry's szDefaultPath may be either a string value or an integer
3399 * resource identifier. In the latter case, the string value of the resource
3400 * is written.
3401 * - Depending on the entry's type, the path may begin with an (unexpanded)
3402 * environment variable name. The caller is responsible for expanding
3403 * environment strings if so desired.
3404 * The types that are prepended with environment variables are:
3405 * CSIDL_Type_User: %USERPROFILE%
3406 * CSIDL_Type_AllUsers: %ALLUSERSPROFILE%
3407 * CSIDL_Type_CurrVer: %SystemDrive%
3408 * (Others might make sense too, but as yet are unneeded.)
3410 static HRESULT _SHGetDefaultValue(BYTE folder, LPWSTR pszPath)
3412 HRESULT hr;
3413 WCHAR resourcePath[MAX_PATH];
3414 LPCWSTR pDefaultPath = NULL;
3416 TRACE("0x%02x,%p\n", folder, pszPath);
3418 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
3419 return E_INVALIDARG;
3420 if (!pszPath)
3421 return E_INVALIDARG;
3423 if (!is_win64)
3425 BOOL is_wow64;
3427 switch (folder)
3429 case CSIDL_PROGRAM_FILES:
3430 case CSIDL_PROGRAM_FILESX86:
3431 IsWow64Process( GetCurrentProcess(), &is_wow64 );
3432 folder = is_wow64 ? CSIDL_PROGRAM_FILESX86 : CSIDL_PROGRAM_FILES;
3433 break;
3434 case CSIDL_PROGRAM_FILES_COMMON:
3435 case CSIDL_PROGRAM_FILES_COMMONX86:
3436 IsWow64Process( GetCurrentProcess(), &is_wow64 );
3437 folder = is_wow64 ? CSIDL_PROGRAM_FILES_COMMONX86 : CSIDL_PROGRAM_FILES_COMMON;
3438 break;
3442 if (CSIDL_Data[folder].szDefaultPath &&
3443 IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath))
3445 if (LoadStringW(shell32_hInstance,
3446 LOWORD(CSIDL_Data[folder].szDefaultPath), resourcePath, MAX_PATH))
3448 hr = S_OK;
3449 pDefaultPath = resourcePath;
3451 else
3453 FIXME("(%d,%s), LoadString failed, missing translation?\n", folder,
3454 debugstr_w(pszPath));
3455 hr = E_FAIL;
3458 else
3460 hr = S_OK;
3461 pDefaultPath = CSIDL_Data[folder].szDefaultPath;
3463 if (SUCCEEDED(hr))
3465 switch (CSIDL_Data[folder].type)
3467 case CSIDL_Type_User:
3468 strcpyW(pszPath, UserProfileW);
3469 break;
3470 case CSIDL_Type_AllUsers:
3471 strcpyW(pszPath, AllUsersProfileW);
3472 break;
3473 case CSIDL_Type_CurrVer:
3474 strcpyW(pszPath, SystemDriveW);
3475 break;
3476 default:
3477 ; /* no corresponding env. var, do nothing */
3479 if (pDefaultPath)
3481 PathAddBackslashW(pszPath);
3482 strcatW(pszPath, pDefaultPath);
3485 TRACE("returning 0x%08x\n", hr);
3486 return hr;
3489 /* Gets the (unexpanded) value of the folder with index folder into pszPath.
3490 * The folder's type is assumed to be CSIDL_Type_CurrVer. Its default value
3491 * can be overridden in the HKLM\\szCurrentVersion key.
3492 * If dwFlags has SHGFP_TYPE_DEFAULT set or if the value isn't overridden in
3493 * the registry, uses _SHGetDefaultValue to get the value.
3495 static HRESULT _SHGetCurrentVersionPath(DWORD dwFlags, BYTE folder,
3496 LPWSTR pszPath)
3498 HRESULT hr;
3500 TRACE("0x%08x,0x%02x,%p\n", dwFlags, folder, pszPath);
3502 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
3503 return E_INVALIDARG;
3504 if (CSIDL_Data[folder].type != CSIDL_Type_CurrVer)
3505 return E_INVALIDARG;
3506 if (!pszPath)
3507 return E_INVALIDARG;
3509 if (dwFlags & SHGFP_TYPE_DEFAULT)
3510 hr = _SHGetDefaultValue(folder, pszPath);
3511 else
3513 HKEY hKey;
3515 if (RegCreateKeyW(HKEY_LOCAL_MACHINE, szCurrentVersion, &hKey))
3516 hr = E_FAIL;
3517 else
3519 DWORD dwType, dwPathLen = MAX_PATH * sizeof(WCHAR);
3521 if (RegQueryValueExW(hKey, CSIDL_Data[folder].szValueName, NULL,
3522 &dwType, (LPBYTE)pszPath, &dwPathLen) ||
3523 (dwType != REG_SZ && dwType != REG_EXPAND_SZ))
3525 hr = _SHGetDefaultValue(folder, pszPath);
3526 dwType = REG_EXPAND_SZ;
3527 switch (folder)
3529 case CSIDL_PROGRAM_FILESX86:
3530 case CSIDL_PROGRAM_FILES_COMMONX86:
3531 /* these two should never be set on 32-bit setups */
3532 if (!is_win64)
3534 BOOL is_wow64;
3535 IsWow64Process( GetCurrentProcess(), &is_wow64 );
3536 if (!is_wow64) break;
3538 /* fall through */
3539 default:
3540 RegSetValueExW(hKey, CSIDL_Data[folder].szValueName, 0, dwType,
3541 (LPBYTE)pszPath, (strlenW(pszPath)+1)*sizeof(WCHAR));
3544 else
3546 pszPath[dwPathLen / sizeof(WCHAR)] = '\0';
3547 hr = S_OK;
3549 RegCloseKey(hKey);
3552 TRACE("returning 0x%08x (output path is %s)\n", hr, debugstr_w(pszPath));
3553 return hr;
3556 static LPWSTR _GetUserSidStringFromToken(HANDLE Token)
3558 char InfoBuffer[64];
3559 PTOKEN_USER UserInfo;
3560 DWORD InfoSize;
3561 LPWSTR SidStr;
3563 UserInfo = (PTOKEN_USER) InfoBuffer;
3564 if (! GetTokenInformation(Token, TokenUser, InfoBuffer, sizeof(InfoBuffer),
3565 &InfoSize))
3567 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
3568 return NULL;
3569 UserInfo = HeapAlloc(GetProcessHeap(), 0, InfoSize);
3570 if (UserInfo == NULL)
3571 return NULL;
3572 if (! GetTokenInformation(Token, TokenUser, UserInfo, InfoSize,
3573 &InfoSize))
3575 HeapFree(GetProcessHeap(), 0, UserInfo);
3576 return NULL;
3580 if (! ConvertSidToStringSidW(UserInfo->User.Sid, &SidStr))
3581 SidStr = NULL;
3583 if (UserInfo != (PTOKEN_USER) InfoBuffer)
3584 HeapFree(GetProcessHeap(), 0, UserInfo);
3586 return SidStr;
3589 /* Gets the user's path (unexpanded) for the CSIDL with index folder:
3590 * If SHGFP_TYPE_DEFAULT is set, calls _SHGetDefaultValue for it. Otherwise
3591 * calls _SHGetUserShellFolderPath for it. Where it looks depends on hToken:
3592 * - if hToken is -1, looks in HKEY_USERS\.Default
3593 * - otherwise looks first in HKEY_CURRENT_USER, followed by HKEY_LOCAL_MACHINE
3594 * if HKEY_CURRENT_USER doesn't contain any entries. If both fail, finally
3595 * calls _SHGetDefaultValue for it.
3597 static HRESULT _SHGetUserProfilePath(HANDLE hToken, DWORD dwFlags, BYTE folder,
3598 LPWSTR pszPath)
3600 const WCHAR *szValueName;
3601 WCHAR buffer[40];
3602 HRESULT hr;
3604 TRACE("%p,0x%08x,0x%02x,%p\n", hToken, dwFlags, folder, pszPath);
3606 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
3607 return E_INVALIDARG;
3608 if (CSIDL_Data[folder].type != CSIDL_Type_User)
3609 return E_INVALIDARG;
3610 if (!pszPath)
3611 return E_INVALIDARG;
3613 if (dwFlags & SHGFP_TYPE_DEFAULT)
3615 if (hToken != NULL && hToken != (HANDLE)-1)
3617 FIXME("unsupported for user other than current or default\n");
3618 return E_FAIL;
3620 hr = _SHGetDefaultValue(folder, pszPath);
3622 else
3624 LPCWSTR userPrefix = NULL;
3625 HKEY hRootKey;
3627 if (hToken == (HANDLE)-1)
3629 hRootKey = HKEY_USERS;
3630 userPrefix = DefaultW;
3632 else if (hToken == NULL)
3633 hRootKey = HKEY_CURRENT_USER;
3634 else
3636 hRootKey = HKEY_USERS;
3637 userPrefix = _GetUserSidStringFromToken(hToken);
3638 if (userPrefix == NULL)
3640 hr = E_FAIL;
3641 goto error;
3645 /* For CSIDL_Type_User we also use the GUID if no szValueName is provided */
3646 szValueName = CSIDL_Data[folder].szValueName;
3647 if (!szValueName)
3649 StringFromGUID2( CSIDL_Data[folder].id, buffer, 39 );
3650 szValueName = &buffer[0];
3653 hr = _SHGetUserShellFolderPath(hRootKey, userPrefix, szValueName, pszPath);
3654 if (FAILED(hr) && hRootKey != HKEY_LOCAL_MACHINE)
3655 hr = _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE, NULL, szValueName, pszPath);
3656 if (FAILED(hr))
3657 hr = _SHGetDefaultValue(folder, pszPath);
3658 if (userPrefix != NULL && userPrefix != DefaultW)
3659 LocalFree((HLOCAL) userPrefix);
3661 error:
3662 TRACE("returning 0x%08x (output path is %s)\n", hr, debugstr_w(pszPath));
3663 return hr;
3666 /* Gets the (unexpanded) path for the CSIDL with index folder. If dwFlags has
3667 * SHGFP_TYPE_DEFAULT set, calls _SHGetDefaultValue. Otherwise calls
3668 * _SHGetUserShellFolderPath for it, looking only in HKEY_LOCAL_MACHINE.
3669 * If this fails, falls back to _SHGetDefaultValue.
3671 static HRESULT _SHGetAllUsersProfilePath(DWORD dwFlags, BYTE folder,
3672 LPWSTR pszPath)
3674 HRESULT hr;
3676 TRACE("0x%08x,0x%02x,%p\n", dwFlags, folder, pszPath);
3678 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
3679 return E_INVALIDARG;
3680 if (CSIDL_Data[folder].type != CSIDL_Type_AllUsers)
3681 return E_INVALIDARG;
3682 if (!pszPath)
3683 return E_INVALIDARG;
3685 if (dwFlags & SHGFP_TYPE_DEFAULT)
3686 hr = _SHGetDefaultValue(folder, pszPath);
3687 else
3689 hr = _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE, NULL,
3690 CSIDL_Data[folder].szValueName, pszPath);
3691 if (FAILED(hr))
3692 hr = _SHGetDefaultValue(folder, pszPath);
3694 TRACE("returning 0x%08x (output path is %s)\n", hr, debugstr_w(pszPath));
3695 return hr;
3698 static HRESULT _SHOpenProfilesKey(PHKEY pKey)
3700 LONG lRet;
3701 DWORD disp;
3703 lRet = RegCreateKeyExW(HKEY_LOCAL_MACHINE, ProfileListW, 0, NULL, 0,
3704 KEY_ALL_ACCESS, NULL, pKey, &disp);
3705 return HRESULT_FROM_WIN32(lRet);
3708 /* Reads the value named szValueName from the key profilesKey (assumed to be
3709 * opened by _SHOpenProfilesKey) into szValue, which is assumed to be MAX_PATH
3710 * WCHARs in length. If it doesn't exist, returns szDefault (and saves
3711 * szDefault to the registry).
3713 static HRESULT _SHGetProfilesValue(HKEY profilesKey, LPCWSTR szValueName,
3714 LPWSTR szValue, LPCWSTR szDefault)
3716 HRESULT hr;
3717 DWORD type, dwPathLen = MAX_PATH * sizeof(WCHAR);
3718 LONG lRet;
3720 TRACE("%p,%s,%p,%s\n", profilesKey, debugstr_w(szValueName), szValue,
3721 debugstr_w(szDefault));
3722 lRet = RegQueryValueExW(profilesKey, szValueName, NULL, &type,
3723 (LPBYTE)szValue, &dwPathLen);
3724 if (!lRet && (type == REG_SZ || type == REG_EXPAND_SZ) && dwPathLen
3725 && *szValue)
3727 dwPathLen /= sizeof(WCHAR);
3728 szValue[dwPathLen] = '\0';
3729 hr = S_OK;
3731 else
3733 /* Missing or invalid value, set a default */
3734 lstrcpynW(szValue, szDefault, MAX_PATH);
3735 TRACE("Setting missing value %s to %s\n", debugstr_w(szValueName),
3736 debugstr_w(szValue));
3737 lRet = RegSetValueExW(profilesKey, szValueName, 0, REG_EXPAND_SZ,
3738 (LPBYTE)szValue,
3739 (strlenW(szValue) + 1) * sizeof(WCHAR));
3740 if (lRet)
3741 hr = HRESULT_FROM_WIN32(lRet);
3742 else
3743 hr = S_OK;
3745 TRACE("returning 0x%08x (output value is %s)\n", hr, debugstr_w(szValue));
3746 return hr;
3749 /* Attempts to expand environment variables from szSrc into szDest, which is
3750 * assumed to be MAX_PATH characters in length. Before referring to the
3751 * environment, handles a few variables directly, because the environment
3752 * variables may not be set when this is called (as during Wine's installation
3753 * when default values are being written to the registry).
3754 * The directly handled environment variables, and their source, are:
3755 * - ALLUSERSPROFILE, USERPROFILE: reads from the registry
3756 * - SystemDrive: uses GetSystemDirectoryW and uses the drive portion of its
3757 * path
3758 * If one of the directly handled environment variables is expanded, only
3759 * expands a single variable, and only in the beginning of szSrc.
3761 static HRESULT _SHExpandEnvironmentStrings(LPCWSTR szSrc, LPWSTR szDest)
3763 HRESULT hr;
3764 WCHAR szTemp[MAX_PATH], szProfilesPrefix[MAX_PATH] = { 0 };
3765 HKEY key = NULL;
3767 TRACE("%s, %p\n", debugstr_w(szSrc), szDest);
3769 if (!szSrc || !szDest) return E_INVALIDARG;
3771 /* short-circuit if there's nothing to expand */
3772 if (szSrc[0] != '%')
3774 strcpyW(szDest, szSrc);
3775 hr = S_OK;
3776 goto end;
3778 /* Get the profile prefix, we'll probably be needing it */
3779 hr = _SHOpenProfilesKey(&key);
3780 if (SUCCEEDED(hr))
3782 WCHAR def_val[MAX_PATH];
3784 /* get the system drive */
3785 GetSystemDirectoryW(def_val, MAX_PATH);
3786 if (def_val[1] == ':') strcpyW( def_val + 3, szDefaultProfileDirW );
3787 else FIXME("non-drive system paths unsupported\n");
3789 hr = _SHGetProfilesValue(key, ProfilesDirectoryW, szProfilesPrefix, def_val );
3792 *szDest = 0;
3793 strcpyW(szTemp, szSrc);
3794 while (SUCCEEDED(hr) && szTemp[0] == '%')
3796 if (!strncmpiW(szTemp, AllUsersProfileW, strlenW(AllUsersProfileW)))
3798 WCHAR szAllUsers[MAX_PATH];
3800 strcpyW(szDest, szProfilesPrefix);
3801 hr = _SHGetProfilesValue(key, AllUsersProfileValueW,
3802 szAllUsers, AllUsersW);
3803 PathAppendW(szDest, szAllUsers);
3804 PathAppendW(szDest, szTemp + strlenW(AllUsersProfileW));
3806 else if (!strncmpiW(szTemp, UserProfileW, strlenW(UserProfileW)))
3808 WCHAR userName[MAX_PATH];
3809 DWORD userLen = MAX_PATH;
3811 strcpyW(szDest, szProfilesPrefix);
3812 GetUserNameW(userName, &userLen);
3813 PathAppendW(szDest, userName);
3814 PathAppendW(szDest, szTemp + strlenW(UserProfileW));
3816 else if (!strncmpiW(szTemp, SystemDriveW, strlenW(SystemDriveW)))
3818 GetSystemDirectoryW(szDest, MAX_PATH);
3819 if (szDest[1] != ':')
3821 FIXME("non-drive system paths unsupported\n");
3822 hr = E_FAIL;
3824 else
3826 strcpyW(szDest + 3, szTemp + strlenW(SystemDriveW) + 1);
3827 hr = S_OK;
3830 else
3832 DWORD ret = ExpandEnvironmentStringsW(szSrc, szDest, MAX_PATH);
3834 if (ret > MAX_PATH)
3835 hr = E_NOT_SUFFICIENT_BUFFER;
3836 else if (ret == 0)
3837 hr = HRESULT_FROM_WIN32(GetLastError());
3838 else
3839 hr = S_OK;
3841 if (SUCCEEDED(hr) && szDest[0] == '%')
3842 strcpyW(szTemp, szDest);
3843 else
3845 /* terminate loop */
3846 szTemp[0] = '\0';
3849 end:
3850 if (key)
3851 RegCloseKey(key);
3852 TRACE("returning 0x%08x (input was %s, output is %s)\n", hr,
3853 debugstr_w(szSrc), debugstr_w(szDest));
3854 return hr;
3857 /*************************************************************************
3858 * SHGetFolderPathW [SHELL32.@]
3860 * Convert nFolder to path.
3862 * RETURNS
3863 * Success: S_OK
3864 * Failure: standard HRESULT error codes.
3866 * NOTES
3867 * Most values can be overridden in either
3868 * HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
3869 * or in the same location in HKLM.
3870 * The "Shell Folders" registry key was used in NT4 and earlier systems.
3871 * Beginning with Windows 2000, the "User Shell Folders" key is used, so
3872 * changes made to it are made to the former key too. This synchronization is
3873 * done on-demand: not until someone requests the value of one of these paths
3874 * (by calling one of the SHGet functions) is the value synchronized.
3875 * Furthermore, the HKCU paths take precedence over the HKLM paths.
3877 HRESULT WINAPI SHGetFolderPathW(
3878 HWND hwndOwner, /* [I] owner window */
3879 int nFolder, /* [I] CSIDL identifying the folder */
3880 HANDLE hToken, /* [I] access token */
3881 DWORD dwFlags, /* [I] which path to return */
3882 LPWSTR pszPath) /* [O] converted path */
3884 HRESULT hr = SHGetFolderPathAndSubDirW(hwndOwner, nFolder, hToken, dwFlags, NULL, pszPath);
3885 if(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) == hr)
3886 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
3887 return hr;
3890 HRESULT WINAPI SHGetFolderPathAndSubDirA(
3891 HWND hwndOwner, /* [I] owner window */
3892 int nFolder, /* [I] CSIDL identifying the folder */
3893 HANDLE hToken, /* [I] access token */
3894 DWORD dwFlags, /* [I] which path to return */
3895 LPCSTR pszSubPath, /* [I] sub directory of the specified folder */
3896 LPSTR pszPath) /* [O] converted path */
3898 int length;
3899 HRESULT hr = S_OK;
3900 LPWSTR pszSubPathW = NULL;
3901 LPWSTR pszPathW = NULL;
3902 TRACE("%08x,%08x,%s\n",nFolder, dwFlags, debugstr_w(pszSubPathW));
3904 if(pszPath) {
3905 pszPathW = HeapAlloc(GetProcessHeap(), 0, MAX_PATH * sizeof(WCHAR));
3906 if(!pszPathW) {
3907 hr = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
3908 goto cleanup;
3911 TRACE("%08x,%08x,%s\n",nFolder, dwFlags, debugstr_w(pszSubPathW));
3913 /* SHGetFolderPathAndSubDirW does not distinguish if pszSubPath isn't
3914 * set (null), or an empty string.therefore call it without the parameter set
3915 * if pszSubPath is an empty string
3917 if (pszSubPath && pszSubPath[0]) {
3918 length = MultiByteToWideChar(CP_ACP, 0, pszSubPath, -1, NULL, 0);
3919 pszSubPathW = HeapAlloc(GetProcessHeap(), 0, length * sizeof(WCHAR));
3920 if(!pszSubPathW) {
3921 hr = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
3922 goto cleanup;
3924 MultiByteToWideChar(CP_ACP, 0, pszSubPath, -1, pszSubPathW, length);
3927 hr = SHGetFolderPathAndSubDirW(hwndOwner, nFolder, hToken, dwFlags, pszSubPathW, pszPathW);
3929 if (SUCCEEDED(hr) && pszPath)
3930 WideCharToMultiByte(CP_ACP, 0, pszPathW, -1, pszPath, MAX_PATH, NULL, NULL);
3932 cleanup:
3933 HeapFree(GetProcessHeap(), 0, pszPathW);
3934 HeapFree(GetProcessHeap(), 0, pszSubPathW);
3935 return hr;
3938 /*************************************************************************
3939 * SHGetFolderPathAndSubDirW [SHELL32.@]
3941 HRESULT WINAPI SHGetFolderPathAndSubDirW(
3942 HWND hwndOwner, /* [I] owner window */
3943 int nFolder, /* [I] CSIDL identifying the folder */
3944 HANDLE hToken, /* [I] access token */
3945 DWORD dwFlags, /* [I] which path to return */
3946 LPCWSTR pszSubPath,/* [I] sub directory of the specified folder */
3947 LPWSTR pszPath) /* [O] converted path */
3949 HRESULT hr;
3950 WCHAR szBuildPath[MAX_PATH], szTemp[MAX_PATH];
3951 DWORD folder = nFolder & CSIDL_FOLDER_MASK;
3952 CSIDL_Type type;
3953 int ret;
3955 TRACE("%p,%p,nFolder=0x%04x,%s\n", hwndOwner,pszPath,nFolder,debugstr_w(pszSubPath));
3957 /* Windows always NULL-terminates the resulting path regardless of success
3958 * or failure, so do so first
3960 if (pszPath)
3961 *pszPath = '\0';
3963 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
3964 return E_INVALIDARG;
3965 if ((SHGFP_TYPE_CURRENT != dwFlags) && (SHGFP_TYPE_DEFAULT != dwFlags))
3966 return E_INVALIDARG;
3967 szTemp[0] = 0;
3968 type = CSIDL_Data[folder].type;
3969 switch (type)
3971 case CSIDL_Type_Disallowed:
3972 hr = E_INVALIDARG;
3973 break;
3974 case CSIDL_Type_NonExistent:
3975 hr = S_FALSE;
3976 break;
3977 case CSIDL_Type_WindowsPath:
3978 GetWindowsDirectoryW(szTemp, MAX_PATH);
3979 if (CSIDL_Data[folder].szDefaultPath &&
3980 !IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath) &&
3981 *CSIDL_Data[folder].szDefaultPath)
3983 PathAddBackslashW(szTemp);
3984 strcatW(szTemp, CSIDL_Data[folder].szDefaultPath);
3986 hr = S_OK;
3987 break;
3988 case CSIDL_Type_SystemPath:
3989 GetSystemDirectoryW(szTemp, MAX_PATH);
3990 if (CSIDL_Data[folder].szDefaultPath &&
3991 !IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath) &&
3992 *CSIDL_Data[folder].szDefaultPath)
3994 PathAddBackslashW(szTemp);
3995 strcatW(szTemp, CSIDL_Data[folder].szDefaultPath);
3997 hr = S_OK;
3998 break;
3999 case CSIDL_Type_SystemX86Path:
4000 if (!GetSystemWow64DirectoryW(szTemp, MAX_PATH)) GetSystemDirectoryW(szTemp, MAX_PATH);
4001 if (CSIDL_Data[folder].szDefaultPath &&
4002 !IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath) &&
4003 *CSIDL_Data[folder].szDefaultPath)
4005 PathAddBackslashW(szTemp);
4006 strcatW(szTemp, CSIDL_Data[folder].szDefaultPath);
4008 hr = S_OK;
4009 break;
4010 case CSIDL_Type_CurrVer:
4011 hr = _SHGetCurrentVersionPath(dwFlags, folder, szTemp);
4012 break;
4013 case CSIDL_Type_User:
4014 hr = _SHGetUserProfilePath(hToken, dwFlags, folder, szTemp);
4015 break;
4016 case CSIDL_Type_AllUsers:
4017 hr = _SHGetAllUsersProfilePath(dwFlags, folder, szTemp);
4018 break;
4019 default:
4020 FIXME("bogus type %d, please fix\n", type);
4021 hr = E_INVALIDARG;
4022 break;
4025 /* Expand environment strings if necessary */
4026 if (*szTemp == '%')
4027 hr = _SHExpandEnvironmentStrings(szTemp, szBuildPath);
4028 else
4029 strcpyW(szBuildPath, szTemp);
4031 if (FAILED(hr)) goto end;
4033 if(pszSubPath) {
4034 /* make sure the new path does not exceed the buffer length
4035 * and remember to backslash and terminate it */
4036 if(MAX_PATH < (lstrlenW(szBuildPath) + lstrlenW(pszSubPath) + 2)) {
4037 hr = HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE);
4038 goto end;
4040 PathAppendW(szBuildPath, pszSubPath);
4041 PathRemoveBackslashW(szBuildPath);
4043 /* Copy the path if it's available before we might return */
4044 if (SUCCEEDED(hr) && pszPath)
4045 strcpyW(pszPath, szBuildPath);
4047 /* if we don't care about existing directories we are ready */
4048 if(nFolder & CSIDL_FLAG_DONT_VERIFY) goto end;
4050 if (PathFileExistsW(szBuildPath)) goto end;
4052 /* not existing but we are not allowed to create it. The return value
4053 * is verified against shell32 version 6.0.
4055 if (!(nFolder & CSIDL_FLAG_CREATE))
4057 hr = HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND);
4058 goto end;
4061 /* create directory/directories */
4062 ret = SHCreateDirectoryExW(hwndOwner, szBuildPath, NULL);
4063 if (ret && ret != ERROR_ALREADY_EXISTS)
4065 ERR("Failed to create directory %s.\n", debugstr_w(szBuildPath));
4066 hr = E_FAIL;
4067 goto end;
4070 TRACE("Created missing system directory %s\n", debugstr_w(szBuildPath));
4071 end:
4072 TRACE("returning 0x%08x (final path is %s)\n", hr, debugstr_w(szBuildPath));
4073 return hr;
4076 /*************************************************************************
4077 * SHGetFolderPathA [SHELL32.@]
4079 * See SHGetFolderPathW.
4081 HRESULT WINAPI SHGetFolderPathA(
4082 HWND hwndOwner,
4083 int nFolder,
4084 HANDLE hToken,
4085 DWORD dwFlags,
4086 LPSTR pszPath)
4088 WCHAR szTemp[MAX_PATH];
4089 HRESULT hr;
4091 TRACE("%p,%p,nFolder=0x%04x\n",hwndOwner,pszPath,nFolder);
4093 if (pszPath)
4094 *pszPath = '\0';
4095 hr = SHGetFolderPathW(hwndOwner, nFolder, hToken, dwFlags, szTemp);
4096 if (SUCCEEDED(hr) && pszPath)
4097 WideCharToMultiByte(CP_ACP, 0, szTemp, -1, pszPath, MAX_PATH, NULL,
4098 NULL);
4100 return hr;
4103 /* For each folder in folders, if its value has not been set in the registry,
4104 * calls _SHGetUserProfilePath or _SHGetAllUsersProfilePath (depending on the
4105 * folder's type) to get the unexpanded value first.
4106 * Writes the unexpanded value to User Shell Folders, and queries it with
4107 * SHGetFolderPathW to force the creation of the directory if it doesn't
4108 * already exist. SHGetFolderPathW also returns the expanded value, which
4109 * this then writes to Shell Folders.
4111 static HRESULT _SHRegisterFolders(HKEY hRootKey, HANDLE hToken,
4112 LPCWSTR szUserShellFolderPath, LPCWSTR szShellFolderPath, const UINT folders[],
4113 UINT foldersLen)
4115 const WCHAR *szValueName;
4116 WCHAR buffer[40];
4117 UINT i;
4118 WCHAR path[MAX_PATH];
4119 HRESULT hr = S_OK;
4120 HKEY hUserKey = NULL, hKey = NULL;
4121 DWORD dwType, dwPathLen;
4122 LONG ret;
4124 TRACE("%p,%p,%s,%p,%u\n", hRootKey, hToken,
4125 debugstr_w(szUserShellFolderPath), folders, foldersLen);
4127 ret = RegCreateKeyW(hRootKey, szUserShellFolderPath, &hUserKey);
4128 if (ret)
4129 hr = HRESULT_FROM_WIN32(ret);
4130 else
4132 ret = RegCreateKeyW(hRootKey, szShellFolderPath, &hKey);
4133 if (ret)
4134 hr = HRESULT_FROM_WIN32(ret);
4136 for (i = 0; SUCCEEDED(hr) && i < foldersLen; i++)
4138 dwPathLen = MAX_PATH * sizeof(WCHAR);
4140 /* For CSIDL_Type_User we also use the GUID if no szValueName is provided */
4141 szValueName = CSIDL_Data[folders[i]].szValueName;
4142 if (!szValueName && CSIDL_Data[folders[i]].type == CSIDL_Type_User)
4144 StringFromGUID2( CSIDL_Data[folders[i]].id, buffer, 39 );
4145 szValueName = &buffer[0];
4148 if (RegQueryValueExW(hUserKey, szValueName, NULL,
4149 &dwType, (LPBYTE)path, &dwPathLen) || (dwType != REG_SZ &&
4150 dwType != REG_EXPAND_SZ))
4152 *path = '\0';
4153 if (CSIDL_Data[folders[i]].type == CSIDL_Type_User)
4154 _SHGetUserProfilePath(hToken, SHGFP_TYPE_DEFAULT, folders[i],
4155 path);
4156 else if (CSIDL_Data[folders[i]].type == CSIDL_Type_AllUsers)
4157 _SHGetAllUsersProfilePath(SHGFP_TYPE_DEFAULT, folders[i], path);
4158 else if (CSIDL_Data[folders[i]].type == CSIDL_Type_WindowsPath)
4160 GetWindowsDirectoryW(path, MAX_PATH);
4161 if (CSIDL_Data[folders[i]].szDefaultPath &&
4162 !IS_INTRESOURCE(CSIDL_Data[folders[i]].szDefaultPath))
4164 PathAddBackslashW(path);
4165 strcatW(path, CSIDL_Data[folders[i]].szDefaultPath);
4168 else
4169 hr = E_FAIL;
4170 if (*path)
4172 ret = RegSetValueExW(hUserKey, szValueName, 0, REG_EXPAND_SZ,
4173 (LPBYTE)path, (strlenW(path) + 1) * sizeof(WCHAR));
4174 if (ret)
4175 hr = HRESULT_FROM_WIN32(ret);
4176 else
4178 hr = SHGetFolderPathW(NULL, folders[i] | CSIDL_FLAG_CREATE,
4179 hToken, SHGFP_TYPE_DEFAULT, path);
4180 ret = RegSetValueExW(hKey, szValueName, 0, REG_SZ,
4181 (LPBYTE)path, (strlenW(path) + 1) * sizeof(WCHAR));
4182 if (ret)
4183 hr = HRESULT_FROM_WIN32(ret);
4188 if (hUserKey)
4189 RegCloseKey(hUserKey);
4190 if (hKey)
4191 RegCloseKey(hKey);
4193 TRACE("returning 0x%08x\n", hr);
4194 return hr;
4197 static HRESULT _SHRegisterUserShellFolders(BOOL bDefault)
4199 static const UINT folders[] = {
4200 CSIDL_PROGRAMS,
4201 CSIDL_PERSONAL,
4202 CSIDL_FAVORITES,
4203 CSIDL_APPDATA,
4204 CSIDL_STARTUP,
4205 CSIDL_RECENT,
4206 CSIDL_SENDTO,
4207 CSIDL_STARTMENU,
4208 CSIDL_MYMUSIC,
4209 CSIDL_MYVIDEO,
4210 CSIDL_DESKTOPDIRECTORY,
4211 CSIDL_NETHOOD,
4212 CSIDL_TEMPLATES,
4213 CSIDL_PRINTHOOD,
4214 CSIDL_LOCAL_APPDATA,
4215 CSIDL_INTERNET_CACHE,
4216 CSIDL_COOKIES,
4217 CSIDL_HISTORY,
4218 CSIDL_MYPICTURES,
4219 CSIDL_FONTS,
4220 CSIDL_ADMINTOOLS,
4221 CSIDL_CONTACTS,
4222 CSIDL_DOWNLOADS,
4223 CSIDL_LINKS,
4224 CSIDL_APPDATA_LOCALLOW,
4225 CSIDL_SAVED_GAMES,
4226 CSIDL_SEARCHES
4228 WCHAR userShellFolderPath[MAX_PATH], shellFolderPath[MAX_PATH];
4229 LPCWSTR pUserShellFolderPath, pShellFolderPath;
4230 HRESULT hr = S_OK;
4231 HKEY hRootKey;
4232 HANDLE hToken;
4234 TRACE("%s\n", bDefault ? "TRUE" : "FALSE");
4235 if (bDefault)
4237 hToken = (HANDLE)-1;
4238 hRootKey = HKEY_USERS;
4239 strcpyW(userShellFolderPath, DefaultW);
4240 PathAddBackslashW(userShellFolderPath);
4241 strcatW(userShellFolderPath, szSHUserFolders);
4242 pUserShellFolderPath = userShellFolderPath;
4243 strcpyW(shellFolderPath, DefaultW);
4244 PathAddBackslashW(shellFolderPath);
4245 strcatW(shellFolderPath, szSHFolders);
4246 pShellFolderPath = shellFolderPath;
4248 else
4250 hToken = NULL;
4251 hRootKey = HKEY_CURRENT_USER;
4252 pUserShellFolderPath = szSHUserFolders;
4253 pShellFolderPath = szSHFolders;
4256 hr = _SHRegisterFolders(hRootKey, hToken, pUserShellFolderPath,
4257 pShellFolderPath, folders, sizeof(folders) / sizeof(folders[0]));
4258 TRACE("returning 0x%08x\n", hr);
4259 return hr;
4262 static HRESULT _SHRegisterCommonShellFolders(void)
4264 static const UINT folders[] = {
4265 CSIDL_COMMON_STARTMENU,
4266 CSIDL_COMMON_PROGRAMS,
4267 CSIDL_COMMON_STARTUP,
4268 CSIDL_COMMON_DESKTOPDIRECTORY,
4269 CSIDL_COMMON_FAVORITES,
4270 CSIDL_COMMON_APPDATA,
4271 CSIDL_COMMON_TEMPLATES,
4272 CSIDL_COMMON_DOCUMENTS,
4273 CSIDL_COMMON_ADMINTOOLS,
4274 CSIDL_COMMON_MUSIC,
4275 CSIDL_COMMON_PICTURES,
4276 CSIDL_COMMON_VIDEO,
4278 HRESULT hr;
4280 TRACE("\n");
4281 hr = _SHRegisterFolders(HKEY_LOCAL_MACHINE, NULL, szSHUserFolders,
4282 szSHFolders, folders, sizeof(folders) / sizeof(folders[0]));
4283 TRACE("returning 0x%08x\n", hr);
4284 return hr;
4287 /******************************************************************************
4288 * _SHAppendToUnixPath [Internal]
4290 * Helper function for _SHCreateSymbolicLinks. Appends pwszSubPath (or the
4291 * corresponding resource, if IS_INTRESOURCE) to the unix base path 'szBasePath'
4292 * and replaces backslashes with slashes.
4294 * PARAMS
4295 * szBasePath [IO] The unix base path, which will be appended to (CP_UNXICP).
4296 * pwszSubPath [I] Sub-path or resource id (use MAKEINTRESOURCEW).
4298 * RETURNS
4299 * Success: TRUE,
4300 * Failure: FALSE
4302 static inline BOOL _SHAppendToUnixPath(char *szBasePath, LPCWSTR pwszSubPath) {
4303 WCHAR wszSubPath[MAX_PATH];
4304 int cLen = strlen(szBasePath);
4305 char *pBackslash;
4307 if (IS_INTRESOURCE(pwszSubPath)) {
4308 if (!LoadStringW(shell32_hInstance, LOWORD(pwszSubPath), wszSubPath, MAX_PATH)) {
4309 /* Fall back to hard coded defaults. */
4310 switch (LOWORD(pwszSubPath)) {
4311 case IDS_PERSONAL:
4312 lstrcpyW(wszSubPath, DocumentsW);
4313 break;
4314 case IDS_MYMUSIC:
4315 lstrcpyW(wszSubPath, My_MusicW);
4316 break;
4317 case IDS_MYPICTURES:
4318 lstrcpyW(wszSubPath, My_PicturesW);
4319 break;
4320 case IDS_MYVIDEOS:
4321 lstrcpyW(wszSubPath, My_VideosW);
4322 break;
4323 default:
4324 ERR("LoadString(%d) failed!\n", LOWORD(pwszSubPath));
4325 return FALSE;
4328 } else {
4329 lstrcpyW(wszSubPath, pwszSubPath);
4332 if (szBasePath[cLen-1] != '/') szBasePath[cLen++] = '/';
4334 if (!WideCharToMultiByte(CP_UNIXCP, 0, wszSubPath, -1, szBasePath + cLen,
4335 FILENAME_MAX - cLen, NULL, NULL))
4337 return FALSE;
4340 pBackslash = szBasePath + cLen;
4341 while ((pBackslash = strchr(pBackslash, '\\'))) *pBackslash = '/';
4343 return TRUE;
4346 /******************************************************************************
4347 * _SHCreateSymbolicLinks [Internal]
4349 * Sets up symbol links for various shell folders to point into the users home
4350 * directory. We do an educated guess about what the user would probably want:
4351 * - If there is a 'My Documents' directory in $HOME, the user probably wants
4352 * wine's 'My Documents' to point there. Furthermore, we imply that the user
4353 * is a Windows lover and has no problem with wine creating 'My Pictures',
4354 * 'My Music' and 'My Videos' subfolders under '$HOME/My Documents', if those
4355 * do not already exits. We put appropriate symbolic links in place for those,
4356 * too.
4357 * - If there is no 'My Documents' directory in $HOME, we let 'My Documents'
4358 * point directly to $HOME. We assume the user to be a unix hacker who does not
4359 * want wine to create anything anywhere besides the .wine directory. So, if
4360 * there already is a 'My Music' directory in $HOME, we symlink the 'My Music'
4361 * shell folder to it. But if not, then we check XDG_MUSIC_DIR - "well known"
4362 * directory, and try to link to that. If that fails, then we symlink to
4363 * $HOME directly. The same holds fo 'My Pictures' and 'My Videos'.
4364 * - The Desktop shell folder is symlinked to XDG_DESKTOP_DIR. If that does not
4365 * exist, then we try '$HOME/Desktop'. If that does not exist, then we leave
4366 * it alone.
4367 * ('My Music',... above in fact means LoadString(IDS_MYMUSIC))
4369 static void _SHCreateSymbolicLinks(void)
4371 UINT aidsMyStuff[] = { IDS_MYPICTURES, IDS_MYVIDEOS, IDS_MYMUSIC }, i;
4372 const WCHAR* MyOSXStuffW[] = { PicturesW, MoviesW, MusicW };
4373 int acsidlMyStuff[] = { CSIDL_MYPICTURES, CSIDL_MYVIDEO, CSIDL_MYMUSIC };
4374 static const char * const xdg_dirs[] = { "PICTURES", "VIDEOS", "MUSIC", "DOCUMENTS", "DESKTOP" };
4375 static const unsigned int num = sizeof(xdg_dirs) / sizeof(xdg_dirs[0]);
4376 WCHAR wszTempPath[MAX_PATH];
4377 char szPersonalTarget[FILENAME_MAX], *pszPersonal;
4378 char szMyStuffTarget[FILENAME_MAX], *pszMyStuff;
4379 char szDesktopTarget[FILENAME_MAX], *pszDesktop;
4380 struct stat statFolder;
4381 const char *pszHome;
4382 HRESULT hr;
4383 char ** xdg_results;
4384 char * xdg_desktop_dir;
4386 /* Create all necessary profile sub-dirs up to 'My Documents' and get the unix path. */
4387 hr = SHGetFolderPathW(NULL, CSIDL_PERSONAL|CSIDL_FLAG_CREATE, NULL,
4388 SHGFP_TYPE_DEFAULT, wszTempPath);
4389 if (FAILED(hr)) return;
4390 pszPersonal = wine_get_unix_file_name(wszTempPath);
4391 if (!pszPersonal) return;
4393 hr = XDG_UserDirLookup(xdg_dirs, num, &xdg_results);
4394 if (FAILED(hr)) xdg_results = NULL;
4396 pszHome = getenv("HOME");
4397 if (pszHome && !stat(pszHome, &statFolder) && S_ISDIR(statFolder.st_mode))
4399 while (1)
4401 /* Check if there's already a Wine-specific 'My Documents' folder */
4402 strcpy(szPersonalTarget, pszHome);
4403 if (_SHAppendToUnixPath(szPersonalTarget, MAKEINTRESOURCEW(IDS_PERSONAL)) &&
4404 !stat(szPersonalTarget, &statFolder) && S_ISDIR(statFolder.st_mode))
4406 /* '$HOME/My Documents' exists. Create 'My Pictures',
4407 * 'My Videos' and 'My Music' subfolders or fail silently if
4408 * they already exist.
4410 for (i = 0; i < sizeof(aidsMyStuff)/sizeof(*aidsMyStuff); i++)
4412 strcpy(szMyStuffTarget, szPersonalTarget);
4413 if (_SHAppendToUnixPath(szMyStuffTarget, MAKEINTRESOURCEW(aidsMyStuff[i])))
4414 mkdir(szMyStuffTarget, 0777);
4416 break;
4419 /* Try to point to the XDG Documents folder */
4420 if (xdg_results && xdg_results[num-2] &&
4421 !stat(xdg_results[num-2], &statFolder) &&
4422 S_ISDIR(statFolder.st_mode))
4424 strcpy(szPersonalTarget, xdg_results[num-2]);
4425 break;
4428 /* Or the hardcoded / OS X Documents folder */
4429 strcpy(szPersonalTarget, pszHome);
4430 if (_SHAppendToUnixPath(szPersonalTarget, DocumentsW) &&
4431 !stat(szPersonalTarget, &statFolder) &&
4432 S_ISDIR(statFolder.st_mode))
4433 break;
4435 /* As a last resort point to $HOME. */
4436 strcpy(szPersonalTarget, pszHome);
4437 break;
4440 /* Replace 'My Documents' directory with a symlink or fail silently if not empty. */
4441 remove(pszPersonal);
4442 symlink(szPersonalTarget, pszPersonal);
4444 else
4446 /* '$HOME' doesn't exist. Create 'My Pictures', 'My Videos' and 'My Music' subdirs
4447 * in '%USERPROFILE%\\My Documents' or fail silently if they already exist. */
4448 pszHome = NULL;
4449 strcpy(szPersonalTarget, pszPersonal);
4450 for (i = 0; i < sizeof(aidsMyStuff)/sizeof(aidsMyStuff[0]); i++) {
4451 strcpy(szMyStuffTarget, szPersonalTarget);
4452 if (_SHAppendToUnixPath(szMyStuffTarget, MAKEINTRESOURCEW(aidsMyStuff[i])))
4453 mkdir(szMyStuffTarget, 0777);
4457 /* Create symbolic links for 'My Pictures', 'My Videos' and 'My Music'. */
4458 for (i=0; i < sizeof(aidsMyStuff)/sizeof(aidsMyStuff[0]); i++)
4460 /* Create the current 'My Whatever' folder and get its unix path. */
4461 hr = SHGetFolderPathW(NULL, acsidlMyStuff[i]|CSIDL_FLAG_CREATE, NULL,
4462 SHGFP_TYPE_DEFAULT, wszTempPath);
4463 if (FAILED(hr)) continue;
4465 pszMyStuff = wine_get_unix_file_name(wszTempPath);
4466 if (!pszMyStuff) continue;
4468 while (1)
4470 /* Check for the Wine-specific '$HOME/My Documents' subfolder */
4471 strcpy(szMyStuffTarget, szPersonalTarget);
4472 if (_SHAppendToUnixPath(szMyStuffTarget, MAKEINTRESOURCEW(aidsMyStuff[i])) &&
4473 !stat(szMyStuffTarget, &statFolder) && S_ISDIR(statFolder.st_mode))
4474 break;
4476 /* Try the XDG_XXX_DIR folder */
4477 if (xdg_results && xdg_results[i])
4479 strcpy(szMyStuffTarget, xdg_results[i]);
4480 break;
4483 /* Or the OS X folder (these are never localized) */
4484 if (pszHome)
4486 strcpy(szMyStuffTarget, pszHome);
4487 if (_SHAppendToUnixPath(szMyStuffTarget, MyOSXStuffW[i]) &&
4488 !stat(szMyStuffTarget, &statFolder) &&
4489 S_ISDIR(statFolder.st_mode))
4490 break;
4493 /* As a last resort point to the same location as 'My Documents' */
4494 strcpy(szMyStuffTarget, szPersonalTarget);
4495 break;
4497 remove(pszMyStuff);
4498 symlink(szMyStuffTarget, pszMyStuff);
4499 HeapFree(GetProcessHeap(), 0, pszMyStuff);
4502 /* Last but not least, the Desktop folder */
4503 if (pszHome)
4504 strcpy(szDesktopTarget, pszHome);
4505 else
4506 strcpy(szDesktopTarget, pszPersonal);
4507 HeapFree(GetProcessHeap(), 0, pszPersonal);
4509 xdg_desktop_dir = xdg_results ? xdg_results[num - 1] : NULL;
4510 if (xdg_desktop_dir ||
4511 (_SHAppendToUnixPath(szDesktopTarget, DesktopW) &&
4512 !stat(szDesktopTarget, &statFolder) && S_ISDIR(statFolder.st_mode)))
4514 hr = SHGetFolderPathW(NULL, CSIDL_DESKTOPDIRECTORY|CSIDL_FLAG_CREATE, NULL,
4515 SHGFP_TYPE_DEFAULT, wszTempPath);
4516 if (SUCCEEDED(hr) && (pszDesktop = wine_get_unix_file_name(wszTempPath)))
4518 remove(pszDesktop);
4519 if (xdg_desktop_dir)
4520 symlink(xdg_desktop_dir, pszDesktop);
4521 else
4522 symlink(szDesktopTarget, pszDesktop);
4523 HeapFree(GetProcessHeap(), 0, pszDesktop);
4527 /* Free resources allocated by XDG_UserDirLookup() */
4528 if (xdg_results)
4530 for (i = 0; i < num; i++)
4531 HeapFree(GetProcessHeap(), 0, xdg_results[i]);
4532 HeapFree(GetProcessHeap(), 0, xdg_results);
4536 /******************************************************************************
4537 * create_extra_folders [Internal]
4539 * Create some extra folders that don't have a standard CSIDL definition.
4541 static HRESULT create_extra_folders(void)
4543 static const WCHAR environW[] = {'E','n','v','i','r','o','n','m','e','n','t',0};
4544 static const WCHAR microsoftW[] = {'M','i','c','r','o','s','o','f','t',0};
4545 static const WCHAR TempW[] = {'T','e','m','p',0};
4546 static const WCHAR TEMPW[] = {'T','E','M','P',0};
4547 static const WCHAR TMPW[] = {'T','M','P',0};
4548 WCHAR path[MAX_PATH+5];
4549 HRESULT hr;
4550 HKEY hkey;
4551 DWORD type, size, ret;
4553 ret = RegCreateKeyW( HKEY_CURRENT_USER, environW, &hkey );
4554 if (ret) return HRESULT_FROM_WIN32( ret );
4556 /* FIXME: should be under AppData, but we don't want spaces in the temp path */
4557 hr = SHGetFolderPathAndSubDirW( 0, CSIDL_PROFILE | CSIDL_FLAG_CREATE, NULL,
4558 SHGFP_TYPE_DEFAULT, TempW, path );
4559 if (SUCCEEDED(hr))
4561 size = sizeof(path);
4562 if (RegQueryValueExW( hkey, TEMPW, NULL, &type, (LPBYTE)path, &size ))
4563 RegSetValueExW( hkey, TEMPW, 0, REG_SZ, (LPBYTE)path, (strlenW(path) + 1) * sizeof(WCHAR) );
4564 size = sizeof(path);
4565 if (RegQueryValueExW( hkey, TMPW, NULL, &type, (LPBYTE)path, &size ))
4566 RegSetValueExW( hkey, TMPW, 0, REG_SZ, (LPBYTE)path, (strlenW(path) + 1) * sizeof(WCHAR) );
4568 RegCloseKey( hkey );
4570 if (SUCCEEDED(hr))
4572 hr = SHGetFolderPathAndSubDirW( 0, CSIDL_COMMON_APPDATA | CSIDL_FLAG_CREATE, NULL,
4573 SHGFP_TYPE_DEFAULT, microsoftW, path );
4575 return hr;
4579 /******************************************************************************
4580 * set_folder_attributes
4582 * Set the various folder attributes registry keys.
4584 static HRESULT set_folder_attributes(void)
4586 static const WCHAR clsidW[] = {'C','L','S','I','D','\\',0 };
4587 static const WCHAR shellfolderW[] = {'\\','S','h','e','l','l','F','o','l','d','e','r', 0 };
4588 static const WCHAR wfparsingW[] = {'W','a','n','t','s','F','O','R','P','A','R','S','I','N','G',0};
4589 static const WCHAR wfdisplayW[] = {'W','a','n','t','s','F','O','R','D','I','S','P','L','A','Y',0};
4590 static const WCHAR hideasdeleteW[] = {'H','i','d','e','A','s','D','e','l','e','t','e','P','e','r','U','s','e','r',0};
4591 static const WCHAR cfattributesW[] = {'C','a','l','l','F','o','r','A','t','t','r','i','b','u','t','e','s',0};
4592 static const WCHAR emptyW[] = {0};
4594 static const struct
4596 const CLSID *clsid;
4597 BOOL wfparsing : 1;
4598 BOOL wfdisplay : 1;
4599 BOOL hideasdel : 1;
4600 DWORD attr;
4601 DWORD call_for_attr;
4602 } folders[] =
4604 { &CLSID_UnixFolder, TRUE, FALSE, FALSE },
4605 { &CLSID_UnixDosFolder, TRUE, FALSE, FALSE,
4606 SFGAO_FILESYSANCESTOR|SFGAO_FOLDER|SFGAO_HASSUBFOLDER, SFGAO_FILESYSTEM },
4607 { &CLSID_FolderShortcut, FALSE, FALSE, FALSE,
4608 SFGAO_FILESYSTEM|SFGAO_FOLDER|SFGAO_LINK,
4609 SFGAO_HASSUBFOLDER|SFGAO_FILESYSTEM|SFGAO_FOLDER|SFGAO_FILESYSANCESTOR },
4610 { &CLSID_MyDocuments, TRUE, FALSE, FALSE,
4611 SFGAO_FILESYSANCESTOR|SFGAO_FOLDER|SFGAO_HASSUBFOLDER, SFGAO_FILESYSTEM },
4612 { &CLSID_RecycleBin, FALSE, FALSE, FALSE,
4613 SFGAO_FOLDER|SFGAO_DROPTARGET|SFGAO_HASPROPSHEET },
4614 { &CLSID_ControlPanel, FALSE, TRUE, TRUE,
4615 SFGAO_FOLDER|SFGAO_HASSUBFOLDER }
4618 unsigned int i;
4619 WCHAR buffer[39 + (sizeof(clsidW) + sizeof(shellfolderW)) / sizeof(WCHAR)];
4620 LONG res;
4621 HKEY hkey;
4623 for (i = 0; i < sizeof(folders)/sizeof(folders[0]); i++)
4625 strcpyW( buffer, clsidW );
4626 StringFromGUID2( folders[i].clsid, buffer + strlenW(buffer), 39 );
4627 strcatW( buffer, shellfolderW );
4628 res = RegCreateKeyExW( HKEY_CLASSES_ROOT, buffer, 0, NULL, 0,
4629 KEY_READ | KEY_WRITE, NULL, &hkey, NULL);
4630 if (res) return HRESULT_FROM_WIN32( res );
4631 if (folders[i].wfparsing)
4632 res = RegSetValueExW( hkey, wfparsingW, 0, REG_SZ, (const BYTE *)emptyW, sizeof(emptyW) );
4633 if (folders[i].wfdisplay)
4634 res = RegSetValueExW( hkey, wfdisplayW, 0, REG_SZ, (const BYTE *)emptyW, sizeof(emptyW) );
4635 if (folders[i].hideasdel)
4636 res = RegSetValueExW( hkey, hideasdeleteW, 0, REG_SZ, (const BYTE *)emptyW, sizeof(emptyW) );
4637 if (folders[i].attr)
4638 res = RegSetValueExW( hkey, szAttributes, 0, REG_DWORD,
4639 (const BYTE *)&folders[i].attr, sizeof(DWORD));
4640 if (folders[i].call_for_attr)
4641 res = RegSetValueExW( hkey, cfattributesW, 0, REG_DWORD,
4642 (const BYTE *)&folders[i].call_for_attr, sizeof(DWORD));
4643 RegCloseKey( hkey );
4645 return S_OK;
4648 /*************************************************************************
4649 * SHGetSpecialFolderPathA [SHELL32.@]
4651 BOOL WINAPI SHGetSpecialFolderPathA (
4652 HWND hwndOwner,
4653 LPSTR szPath,
4654 int nFolder,
4655 BOOL bCreate)
4657 return SHGetFolderPathA(hwndOwner, nFolder + (bCreate ? CSIDL_FLAG_CREATE : 0), NULL, 0,
4658 szPath) == S_OK;
4661 /*************************************************************************
4662 * SHGetSpecialFolderPathW
4664 BOOL WINAPI SHGetSpecialFolderPathW (
4665 HWND hwndOwner,
4666 LPWSTR szPath,
4667 int nFolder,
4668 BOOL bCreate)
4670 return SHGetFolderPathW(hwndOwner, nFolder + (bCreate ? CSIDL_FLAG_CREATE : 0), NULL, 0,
4671 szPath) == S_OK;
4674 /*************************************************************************
4675 * SHGetSpecialFolderPath (SHELL32.175)
4677 BOOL WINAPI SHGetSpecialFolderPathAW (
4678 HWND hwndOwner,
4679 LPVOID szPath,
4680 int nFolder,
4681 BOOL bCreate)
4684 if (SHELL_OsIsUnicode())
4685 return SHGetSpecialFolderPathW (hwndOwner, szPath, nFolder, bCreate);
4686 return SHGetSpecialFolderPathA (hwndOwner, szPath, nFolder, bCreate);
4689 /*************************************************************************
4690 * SHGetFolderLocation [SHELL32.@]
4692 * Gets the folder locations from the registry and creates a pidl.
4694 * PARAMS
4695 * hwndOwner [I]
4696 * nFolder [I] CSIDL_xxxxx
4697 * hToken [I] token representing user, or NULL for current user, or -1 for
4698 * default user
4699 * dwReserved [I] must be zero
4700 * ppidl [O] PIDL of a special folder
4702 * RETURNS
4703 * Success: S_OK
4704 * Failure: Standard OLE-defined error result, S_FALSE or E_INVALIDARG
4706 * NOTES
4707 * Creates missing reg keys and directories.
4708 * Mostly forwards to SHGetFolderPathW, but a few values of nFolder return
4709 * virtual folders that are handled here.
4711 HRESULT WINAPI SHGetFolderLocation(
4712 HWND hwndOwner,
4713 int nFolder,
4714 HANDLE hToken,
4715 DWORD dwReserved,
4716 LPITEMIDLIST *ppidl)
4718 HRESULT hr = E_INVALIDARG;
4720 TRACE("%p 0x%08x %p 0x%08x %p\n",
4721 hwndOwner, nFolder, hToken, dwReserved, ppidl);
4723 if (!ppidl)
4724 return E_INVALIDARG;
4725 if (dwReserved)
4726 return E_INVALIDARG;
4728 /* The virtual folders' locations are not user-dependent */
4729 *ppidl = NULL;
4730 switch (nFolder & CSIDL_FOLDER_MASK)
4732 case CSIDL_DESKTOP:
4733 *ppidl = _ILCreateDesktop();
4734 break;
4736 case CSIDL_PERSONAL:
4737 *ppidl = _ILCreateMyDocuments();
4738 break;
4740 case CSIDL_INTERNET:
4741 *ppidl = _ILCreateIExplore();
4742 break;
4744 case CSIDL_CONTROLS:
4745 *ppidl = _ILCreateControlPanel();
4746 break;
4748 case CSIDL_PRINTERS:
4749 *ppidl = _ILCreatePrinters();
4750 break;
4752 case CSIDL_BITBUCKET:
4753 *ppidl = _ILCreateBitBucket();
4754 break;
4756 case CSIDL_DRIVES:
4757 *ppidl = _ILCreateMyComputer();
4758 break;
4760 case CSIDL_NETWORK:
4761 *ppidl = _ILCreateNetwork();
4762 break;
4764 default:
4766 WCHAR szPath[MAX_PATH];
4768 hr = SHGetFolderPathW(hwndOwner, nFolder, hToken,
4769 SHGFP_TYPE_CURRENT, szPath);
4770 if (SUCCEEDED(hr))
4772 DWORD attributes=0;
4774 TRACE("Value=%s\n", debugstr_w(szPath));
4775 hr = SHILCreateFromPathW(szPath, ppidl, &attributes);
4777 else if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
4779 /* unlike SHGetFolderPath, SHGetFolderLocation in shell32
4780 * version 6.0 returns E_FAIL for nonexistent paths
4782 hr = E_FAIL;
4786 if(*ppidl)
4787 hr = S_OK;
4789 TRACE("-- (new pidl %p)\n",*ppidl);
4790 return hr;
4793 /*************************************************************************
4794 * SHGetSpecialFolderLocation [SHELL32.@]
4796 * NOTES
4797 * In NT5, SHGetSpecialFolderLocation needs the <winntdir>/Recent
4798 * directory.
4800 HRESULT WINAPI SHGetSpecialFolderLocation(
4801 HWND hwndOwner,
4802 INT nFolder,
4803 LPITEMIDLIST * ppidl)
4805 HRESULT hr = E_INVALIDARG;
4807 TRACE("(%p,0x%x,%p)\n", hwndOwner,nFolder,ppidl);
4809 if (!ppidl)
4810 return E_INVALIDARG;
4812 hr = SHGetFolderLocation(hwndOwner, nFolder, NULL, 0, ppidl);
4813 return hr;
4816 static int csidl_from_id( const KNOWNFOLDERID *id )
4818 int i;
4819 for (i = 0; i < sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]); i++)
4820 if (IsEqualGUID( CSIDL_Data[i].id, id )) return i;
4821 return -1;
4824 /*************************************************************************
4825 * SHGetKnownFolderPath [SHELL32.@]
4827 HRESULT WINAPI SHGetKnownFolderPath(REFKNOWNFOLDERID rfid, DWORD flags, HANDLE token, WCHAR **ret_path)
4829 WCHAR pathW[MAX_PATH], tempW[MAX_PATH];
4830 HRESULT hr;
4831 CSIDL_Type type;
4832 int ret;
4833 int folder = csidl_from_id(rfid), shgfp_flags;
4835 TRACE("%s, 0x%08x, %p, %p\n", debugstr_guid(rfid), flags, token, ret_path);
4837 *ret_path = NULL;
4839 if (folder < 0)
4840 return HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND );
4842 if (flags & ~(KF_FLAG_CREATE|KF_FLAG_DONT_VERIFY|KF_FLAG_NO_ALIAS|
4843 KF_FLAG_INIT|KF_FLAG_DEFAULT_PATH))
4845 FIXME("flags 0x%08x not supported\n", flags);
4846 return E_INVALIDARG;
4849 shgfp_flags = flags & KF_FLAG_DEFAULT_PATH ? SHGFP_TYPE_DEFAULT : SHGFP_TYPE_CURRENT;
4851 type = CSIDL_Data[folder].type;
4852 switch (type)
4854 case CSIDL_Type_Disallowed:
4855 hr = E_INVALIDARG;
4856 break;
4857 case CSIDL_Type_NonExistent:
4858 *tempW = 0;
4859 hr = S_FALSE;
4860 break;
4861 case CSIDL_Type_WindowsPath:
4862 GetWindowsDirectoryW(tempW, MAX_PATH);
4863 if (CSIDL_Data[folder].szDefaultPath &&
4864 !IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath) &&
4865 *CSIDL_Data[folder].szDefaultPath)
4867 PathAddBackslashW(tempW);
4868 strcatW(tempW, CSIDL_Data[folder].szDefaultPath);
4870 hr = S_OK;
4871 break;
4872 case CSIDL_Type_SystemPath:
4873 GetSystemDirectoryW(tempW, MAX_PATH);
4874 if (CSIDL_Data[folder].szDefaultPath &&
4875 !IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath) &&
4876 *CSIDL_Data[folder].szDefaultPath)
4878 PathAddBackslashW(tempW);
4879 strcatW(tempW, CSIDL_Data[folder].szDefaultPath);
4881 hr = S_OK;
4882 break;
4883 case CSIDL_Type_SystemX86Path:
4884 if (!GetSystemWow64DirectoryW(tempW, MAX_PATH)) GetSystemDirectoryW(tempW, MAX_PATH);
4885 if (CSIDL_Data[folder].szDefaultPath &&
4886 !IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath) &&
4887 *CSIDL_Data[folder].szDefaultPath)
4889 PathAddBackslashW(tempW);
4890 strcatW(tempW, CSIDL_Data[folder].szDefaultPath);
4892 hr = S_OK;
4893 break;
4894 case CSIDL_Type_CurrVer:
4895 hr = _SHGetCurrentVersionPath(shgfp_flags, folder, tempW);
4896 break;
4897 case CSIDL_Type_User:
4898 hr = _SHGetUserProfilePath(token, shgfp_flags, folder, tempW);
4899 break;
4900 case CSIDL_Type_AllUsers:
4901 hr = _SHGetAllUsersProfilePath(shgfp_flags, folder, tempW);
4902 break;
4903 default:
4904 FIXME("bogus type %d, please fix\n", type);
4905 hr = E_INVALIDARG;
4906 break;
4909 if (FAILED(hr))
4910 goto failed;
4912 /* Expand environment strings if necessary */
4913 if (*tempW == '%')
4915 hr = _SHExpandEnvironmentStrings(tempW, pathW);
4916 if (FAILED(hr))
4917 goto failed;
4919 else
4920 strcpyW(pathW, tempW);
4922 /* if we don't care about existing directories we are ready */
4923 if (flags & KF_FLAG_DONT_VERIFY) goto done;
4925 if (PathFileExistsW(pathW)) goto done;
4927 /* Does not exist but we are not allowed to create it. The return value
4928 * is verified against shell32 version 6.0.
4930 if (!(flags & KF_FLAG_CREATE))
4932 hr = HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND);
4933 goto done;
4936 /* create directory/directories */
4937 ret = SHCreateDirectoryExW(NULL, pathW, NULL);
4938 if (ret && ret != ERROR_ALREADY_EXISTS)
4940 ERR("Failed to create directory %s.\n", debugstr_w(pathW));
4941 hr = E_FAIL;
4942 goto failed;
4945 TRACE("Created missing system directory %s\n", debugstr_w(pathW));
4947 done:
4948 TRACE("Final path is %s, %#x\n", debugstr_w(pathW), hr);
4950 *ret_path = CoTaskMemAlloc((strlenW(pathW) + 1) * sizeof(WCHAR));
4951 if (!*ret_path)
4952 return E_OUTOFMEMORY;
4953 strcpyW(*ret_path, pathW);
4955 return hr;
4957 failed:
4958 TRACE("Failed to get folder path, %#x.\n", hr);
4960 return hr;
4963 /*************************************************************************
4964 * SHGetFolderPathEx [SHELL32.@]
4966 HRESULT WINAPI SHGetFolderPathEx(REFKNOWNFOLDERID rfid, DWORD flags, HANDLE token, LPWSTR path, DWORD len)
4968 HRESULT hr;
4969 WCHAR *buffer;
4971 TRACE("%s, 0x%08x, %p, %p, %u\n", debugstr_guid(rfid), flags, token, path, len);
4973 if (!path || !len) return E_INVALIDARG;
4975 hr = SHGetKnownFolderPath( rfid, flags, token, &buffer );
4976 if (SUCCEEDED( hr ))
4978 if (strlenW( buffer ) + 1 > len)
4980 CoTaskMemFree( buffer );
4981 return HRESULT_FROM_WIN32( ERROR_INSUFFICIENT_BUFFER );
4983 strcpyW( path, buffer );
4984 CoTaskMemFree( buffer );
4986 return hr;
4990 * Internal function to convert known folder identifier to path of registry key
4991 * associated with known folder.
4993 * Parameters:
4994 * rfid [I] pointer to known folder identifier (may be NULL)
4995 * lpStringGuid [I] string with known folder identifier (used when rfid is NULL)
4996 * lpPath [O] place to store string address. String should be
4997 * later freed using HeapFree(GetProcessHeap(),0, ... )
4999 static HRESULT get_known_folder_registry_path(
5000 REFKNOWNFOLDERID rfid,
5001 LPWSTR lpStringGuid,
5002 LPWSTR *lpPath)
5004 static const WCHAR sBackslash[] = {'\\',0};
5005 HRESULT hr = S_OK;
5006 int length;
5007 WCHAR sGuid[50];
5009 TRACE("(%s, %s, %p)\n", debugstr_guid(rfid), debugstr_w(lpStringGuid), lpPath);
5011 if(rfid)
5012 StringFromGUID2(rfid, sGuid, sizeof(sGuid)/sizeof(sGuid[0]));
5013 else
5014 lstrcpyW(sGuid, lpStringGuid);
5016 length = lstrlenW(szKnownFolderDescriptions)+51;
5017 *lpPath = HeapAlloc(GetProcessHeap(), 0, length*sizeof(WCHAR));
5018 if(!(*lpPath))
5019 hr = E_OUTOFMEMORY;
5021 if(SUCCEEDED(hr))
5023 lstrcpyW(*lpPath, szKnownFolderDescriptions);
5024 lstrcatW(*lpPath, sBackslash);
5025 lstrcatW(*lpPath, sGuid);
5028 return hr;
5031 static HRESULT get_known_folder_wstr(const WCHAR *regpath, const WCHAR *value, WCHAR **out)
5033 DWORD size = 0;
5034 HRESULT hr;
5036 size = 0;
5037 hr = HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, regpath, value, RRF_RT_REG_SZ, NULL, NULL, &size));
5038 if(FAILED(hr))
5039 return hr;
5041 *out = CoTaskMemAlloc(size);
5042 if(!*out)
5043 return E_OUTOFMEMORY;
5045 hr = HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, regpath, value, RRF_RT_REG_SZ, NULL, *out, &size));
5046 if(FAILED(hr)){
5047 CoTaskMemFree(*out);
5048 *out = NULL;
5051 return hr;
5054 static HRESULT get_known_folder_dword(const WCHAR *registryPath, const WCHAR *value, DWORD *out)
5056 DWORD dwSize = sizeof(DWORD);
5057 DWORD dwType;
5058 return HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, registryPath, value, RRF_RT_DWORD, &dwType, out, &dwSize));
5062 * Internal function to get place where folder redirection information are stored.
5064 * Parameters:
5065 * rfid [I] pointer to known folder identifier (may be NULL)
5066 * rootKey [O] root key where the redirection information are stored
5067 * It can be HKLM for COMMON folders, and HKCU for PERUSER folders.
5068 * However, besides root key, path is always that same, and is stored
5069 * as "szKnownFolderRedirections" constant
5071 static HRESULT get_known_folder_redirection_place(
5072 REFKNOWNFOLDERID rfid,
5073 HKEY *rootKey)
5075 HRESULT hr;
5076 LPWSTR lpRegistryPath = NULL;
5077 KF_CATEGORY category;
5079 /* first, get known folder's category */
5080 hr = get_known_folder_registry_path(rfid, NULL, &lpRegistryPath);
5082 if(SUCCEEDED(hr))
5083 hr = get_known_folder_dword(lpRegistryPath, szCategory, &category);
5085 if(SUCCEEDED(hr))
5087 if(category == KF_CATEGORY_COMMON)
5089 *rootKey = HKEY_LOCAL_MACHINE;
5090 hr = S_OK;
5092 else if(category == KF_CATEGORY_PERUSER)
5094 *rootKey = HKEY_CURRENT_USER;
5095 hr = S_OK;
5097 else
5098 hr = E_FAIL;
5101 HeapFree(GetProcessHeap(), 0, lpRegistryPath);
5102 return hr;
5105 static HRESULT get_known_folder_path_by_id(REFKNOWNFOLDERID folderId, LPWSTR lpRegistryPath, DWORD dwFlags, LPWSTR *ppszPath);
5107 static HRESULT redirect_known_folder(
5108 REFKNOWNFOLDERID rfid,
5109 HWND hwnd,
5110 KF_REDIRECT_FLAGS flags,
5111 LPCWSTR pszTargetPath,
5112 UINT cFolders,
5113 KNOWNFOLDERID const *pExclusion,
5114 LPWSTR *ppszError)
5116 HRESULT hr;
5117 HKEY rootKey = HKEY_LOCAL_MACHINE, hKey;
5118 WCHAR sGuid[39];
5119 LPWSTR lpRegistryPath = NULL, lpSrcPath = NULL;
5120 TRACE("(%s, %p, 0x%08x, %s, %d, %p, %p)\n", debugstr_guid(rfid), hwnd, flags, debugstr_w(pszTargetPath), cFolders, pExclusion, ppszError);
5122 if (ppszError) *ppszError = NULL;
5124 hr = get_known_folder_registry_path(rfid, NULL, &lpRegistryPath);
5126 if(SUCCEEDED(hr))
5127 hr = get_known_folder_path_by_id(rfid, lpRegistryPath, 0, &lpSrcPath);
5129 HeapFree(GetProcessHeap(), 0, lpRegistryPath);
5131 /* get path to redirection storage */
5132 if(SUCCEEDED(hr))
5133 hr = get_known_folder_redirection_place(rfid, &rootKey);
5135 /* write redirection information */
5136 if(SUCCEEDED(hr))
5137 hr = HRESULT_FROM_WIN32(RegCreateKeyExW(rootKey, szKnownFolderRedirections, 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL));
5139 if(SUCCEEDED(hr))
5141 StringFromGUID2(rfid, sGuid, sizeof(sGuid)/sizeof(sGuid[0]));
5143 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, sGuid, 0, REG_SZ, (LPBYTE)pszTargetPath, (lstrlenW(pszTargetPath)+1)*sizeof(WCHAR)));
5145 RegCloseKey(hKey);
5148 /* make sure destination path exists */
5149 SHCreateDirectory(NULL, pszTargetPath);
5151 /* copy content if required */
5152 if(SUCCEEDED(hr) && (flags & KF_REDIRECT_COPY_CONTENTS) )
5154 static const WCHAR sWildcard[] = {'\\','*',0};
5155 WCHAR srcPath[MAX_PATH+1], dstPath[MAX_PATH+1];
5156 SHFILEOPSTRUCTW fileOp;
5158 ZeroMemory(srcPath, sizeof(srcPath));
5159 lstrcpyW(srcPath, lpSrcPath);
5160 lstrcatW(srcPath, sWildcard);
5162 ZeroMemory(dstPath, sizeof(dstPath));
5163 lstrcpyW(dstPath, pszTargetPath);
5165 ZeroMemory(&fileOp, sizeof(fileOp));
5167 if(flags & KF_REDIRECT_DEL_SOURCE_CONTENTS)
5168 fileOp.wFunc = FO_MOVE;
5169 else
5170 fileOp.wFunc = FO_COPY;
5172 fileOp.pFrom = srcPath;
5173 fileOp.pTo = dstPath;
5174 fileOp.fFlags = FOF_NO_UI;
5176 hr = (SHFileOperationW(&fileOp)==0 ? S_OK : E_FAIL);
5178 if(flags & KF_REDIRECT_DEL_SOURCE_CONTENTS)
5180 ZeroMemory(srcPath, sizeof(srcPath));
5181 lstrcpyW(srcPath, lpSrcPath);
5183 ZeroMemory(&fileOp, sizeof(fileOp));
5184 fileOp.wFunc = FO_DELETE;
5185 fileOp.pFrom = srcPath;
5186 fileOp.fFlags = FOF_NO_UI;
5188 hr = (SHFileOperationW(&fileOp)==0 ? S_OK : E_FAIL);
5192 CoTaskMemFree(lpSrcPath);
5194 return hr;
5198 struct knownfolder
5200 IKnownFolder IKnownFolder_iface;
5201 LONG refs;
5202 KNOWNFOLDERID id;
5203 LPWSTR registryPath;
5206 static inline struct knownfolder *impl_from_IKnownFolder( IKnownFolder *iface )
5208 return CONTAINING_RECORD( iface, struct knownfolder, IKnownFolder_iface );
5211 static ULONG WINAPI knownfolder_AddRef(
5212 IKnownFolder *iface )
5214 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
5215 return InterlockedIncrement( &knownfolder->refs );
5218 static ULONG WINAPI knownfolder_Release(
5219 IKnownFolder *iface )
5221 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
5222 LONG refs = InterlockedDecrement( &knownfolder->refs );
5223 if (!refs)
5225 TRACE("destroying %p\n", knownfolder);
5226 HeapFree( GetProcessHeap(), 0, knownfolder->registryPath);
5227 HeapFree( GetProcessHeap(), 0, knownfolder );
5229 return refs;
5232 static HRESULT WINAPI knownfolder_QueryInterface(
5233 IKnownFolder *iface,
5234 REFIID riid,
5235 void **ppv )
5237 struct knownfolder *This = impl_from_IKnownFolder( iface );
5239 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppv );
5241 *ppv = NULL;
5242 if ( IsEqualGUID( riid, &IID_IKnownFolder ) ||
5243 IsEqualGUID( riid, &IID_IUnknown ) )
5245 *ppv = iface;
5247 else if ( IsEqualGUID( riid, &IID_IMarshal ) )
5249 TRACE("IID_IMarshal returning NULL.\n");
5250 return E_NOINTERFACE;
5252 else
5254 FIXME("interface %s not implemented\n", debugstr_guid(riid));
5255 return E_NOINTERFACE;
5257 IKnownFolder_AddRef( iface );
5258 return S_OK;
5261 static HRESULT knownfolder_set_id(
5262 struct knownfolder *knownfolder,
5263 const KNOWNFOLDERID *kfid)
5265 HKEY hKey;
5266 HRESULT hr;
5268 TRACE("%s\n", debugstr_guid(kfid));
5270 knownfolder->id = *kfid;
5272 /* check is it registry-registered folder */
5273 hr = get_known_folder_registry_path(kfid, NULL, &knownfolder->registryPath);
5274 if(SUCCEEDED(hr))
5275 hr = HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_LOCAL_MACHINE, knownfolder->registryPath, 0, 0, &hKey));
5277 if(SUCCEEDED(hr))
5279 hr = S_OK;
5280 RegCloseKey(hKey);
5282 else
5284 /* This known folder is not registered. To mark it, we set registryPath to NULL */
5285 HeapFree(GetProcessHeap(), 0, knownfolder->registryPath);
5286 knownfolder->registryPath = NULL;
5287 hr = S_OK;
5290 return hr;
5293 static HRESULT WINAPI knownfolder_GetId(
5294 IKnownFolder *iface,
5295 KNOWNFOLDERID *pkfid)
5297 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
5299 TRACE("%p\n", pkfid);
5301 *pkfid = knownfolder->id;
5302 return S_OK;
5305 static HRESULT WINAPI knownfolder_GetCategory(
5306 IKnownFolder *iface,
5307 KF_CATEGORY *pCategory)
5309 struct knownfolder *knownfolder = impl_from_IKnownFolder(iface);
5310 HRESULT hr = S_OK;
5312 TRACE("%p, %p\n", knownfolder, pCategory);
5314 /* we cannot get a category for a folder which is not registered */
5315 if(!knownfolder->registryPath)
5316 hr = E_FAIL;
5318 if(SUCCEEDED(hr))
5319 hr = get_known_folder_dword(knownfolder->registryPath, szCategory, pCategory);
5321 return hr;
5324 static HRESULT WINAPI knownfolder_GetShellItem(
5325 IKnownFolder *iface,
5326 DWORD flags,
5327 REFIID riid,
5328 void **ppv)
5330 struct knownfolder *knownfolder = impl_from_IKnownFolder(iface);
5331 TRACE("(%p, 0x%08x, %s, %p)\n", knownfolder, flags, debugstr_guid(riid), ppv);
5332 return SHGetKnownFolderItem(&knownfolder->id, flags, NULL, riid, ppv);
5335 static HRESULT get_known_folder_path(
5336 LPWSTR sFolderId,
5337 LPWSTR registryPath,
5338 LPWSTR *ppszPath)
5340 static const WCHAR sBackslash[] = {'\\',0};
5341 HRESULT hr;
5342 DWORD dwSize, dwType;
5343 WCHAR path[MAX_PATH] = {0};
5344 WCHAR parentGuid[39];
5345 KF_CATEGORY category;
5346 LPWSTR parentRegistryPath, parentPath;
5347 HKEY hRedirectionRootKey = NULL;
5349 TRACE("(%s, %p)\n", debugstr_w(registryPath), ppszPath);
5350 *ppszPath = NULL;
5352 /* check if folder has parent */
5353 dwSize = sizeof(parentGuid);
5354 hr = HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, registryPath, szParentFolder, RRF_RT_REG_SZ, &dwType, parentGuid, &dwSize));
5355 if(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) hr = S_FALSE;
5357 if(hr == S_OK)
5359 /* get parent's known folder path (recursive) */
5360 hr = get_known_folder_registry_path(NULL, parentGuid, &parentRegistryPath);
5361 if(FAILED(hr)) return hr;
5363 hr = get_known_folder_path(parentGuid, parentRegistryPath, &parentPath);
5364 if(FAILED(hr)) {
5365 HeapFree(GetProcessHeap(), 0, parentRegistryPath);
5366 return hr;
5369 lstrcatW(path, parentPath);
5370 lstrcatW(path, sBackslash);
5372 HeapFree(GetProcessHeap(), 0, parentRegistryPath);
5373 HeapFree(GetProcessHeap(), 0, parentPath);
5376 /* check, if folder was redirected */
5377 if(SUCCEEDED(hr))
5378 hr = get_known_folder_dword(registryPath, szCategory, &category);
5380 if(SUCCEEDED(hr))
5382 if(category == KF_CATEGORY_COMMON)
5383 hRedirectionRootKey = HKEY_LOCAL_MACHINE;
5384 else if(category == KF_CATEGORY_PERUSER)
5385 hRedirectionRootKey = HKEY_CURRENT_USER;
5387 if(hRedirectionRootKey)
5389 hr = HRESULT_FROM_WIN32(RegGetValueW(hRedirectionRootKey, szKnownFolderRedirections, sFolderId, RRF_RT_REG_SZ, NULL, NULL, &dwSize));
5391 if(SUCCEEDED(hr))
5393 *ppszPath = CoTaskMemAlloc(dwSize+(lstrlenW(path)+1)*sizeof(WCHAR));
5394 if(!*ppszPath) hr = E_OUTOFMEMORY;
5397 if(SUCCEEDED(hr))
5399 lstrcpyW(*ppszPath, path);
5400 hr = HRESULT_FROM_WIN32(RegGetValueW(hRedirectionRootKey, szKnownFolderRedirections, sFolderId, RRF_RT_REG_SZ, NULL, *ppszPath + lstrlenW(path), &dwSize));
5404 if(!*ppszPath)
5406 /* no redirection, use previous way - read the relative path from folder definition */
5407 hr = HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, registryPath, szRelativePath, RRF_RT_REG_SZ, &dwType, NULL, &dwSize));
5409 if(SUCCEEDED(hr))
5411 *ppszPath = CoTaskMemAlloc(dwSize+(lstrlenW(path)+1)*sizeof(WCHAR));
5412 if(!*ppszPath) hr = E_OUTOFMEMORY;
5415 if(SUCCEEDED(hr))
5417 lstrcpyW(*ppszPath, path);
5418 hr = HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, registryPath, szRelativePath, RRF_RT_REG_SZ, &dwType, *ppszPath + lstrlenW(path), &dwSize));
5423 TRACE("returning path: %s\n", debugstr_w(*ppszPath));
5424 return hr;
5427 static HRESULT get_known_folder_path_by_id(
5428 REFKNOWNFOLDERID folderId,
5429 LPWSTR lpRegistryPath,
5430 DWORD dwFlags,
5431 LPWSTR *ppszPath)
5433 HRESULT hr = E_FAIL;
5434 WCHAR sGuid[39];
5435 DWORD dwAttributes;
5437 TRACE("(%s, %s, 0x%08x, %p)\n", debugstr_guid(folderId), debugstr_w(lpRegistryPath), dwFlags, ppszPath);
5439 /* if this is registry-registered known folder, get path from registry */
5440 if(lpRegistryPath)
5442 StringFromGUID2(folderId, sGuid, sizeof(sGuid)/sizeof(sGuid[0]));
5444 hr = get_known_folder_path(sGuid, lpRegistryPath, ppszPath);
5446 /* in other case, use older way */
5448 if(FAILED(hr))
5449 hr = SHGetKnownFolderPath( folderId, dwFlags, NULL, ppszPath );
5451 if (FAILED(hr)) return hr;
5453 /* check if known folder really exists */
5454 dwAttributes = GetFileAttributesW(*ppszPath);
5455 if(dwAttributes == INVALID_FILE_ATTRIBUTES || !(dwAttributes & FILE_ATTRIBUTE_DIRECTORY) )
5457 TRACE("directory %s not found\n", debugstr_w(*ppszPath));
5458 CoTaskMemFree(*ppszPath);
5459 *ppszPath = NULL;
5460 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
5463 return hr;
5466 static HRESULT WINAPI knownfolder_GetPath(
5467 IKnownFolder *iface,
5468 DWORD dwFlags,
5469 LPWSTR *ppszPath)
5471 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
5472 TRACE("(%p, 0x%08x, %p)\n", knownfolder, dwFlags, ppszPath);
5474 return get_known_folder_path_by_id(&knownfolder->id, knownfolder->registryPath, dwFlags, ppszPath);
5477 static HRESULT WINAPI knownfolder_SetPath(
5478 IKnownFolder *iface,
5479 DWORD dwFlags,
5480 LPCWSTR pszPath)
5482 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
5483 HRESULT hr = S_OK;
5485 TRACE("(%p, 0x%08x, %s)\n", knownfolder, dwFlags, debugstr_w(pszPath));
5487 /* check if the known folder is registered */
5488 if(!knownfolder->registryPath)
5489 hr = E_FAIL;
5491 if(SUCCEEDED(hr))
5492 hr = redirect_known_folder(&knownfolder->id, NULL, 0, pszPath, 0, NULL, NULL);
5494 return hr;
5497 static HRESULT WINAPI knownfolder_GetIDList(
5498 IKnownFolder *iface,
5499 DWORD flags,
5500 PIDLIST_ABSOLUTE *ppidl)
5502 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
5503 TRACE("(%p, 0x%08x, %p)\n", knownfolder, flags, ppidl);
5504 return SHGetKnownFolderIDList(&knownfolder->id, flags, NULL, ppidl);
5507 static HRESULT WINAPI knownfolder_GetFolderType(
5508 IKnownFolder *iface,
5509 FOLDERTYPEID *pftid)
5511 FIXME("%p\n", pftid);
5512 return E_NOTIMPL;
5515 static HRESULT WINAPI knownfolder_GetRedirectionCapabilities(
5516 IKnownFolder *iface,
5517 KF_REDIRECTION_CAPABILITIES *pCapabilities)
5519 FIXME("%p\n", pCapabilities);
5520 return E_NOTIMPL;
5523 static HRESULT WINAPI knownfolder_GetFolderDefinition(
5524 IKnownFolder *iface,
5525 KNOWNFOLDER_DEFINITION *pKFD)
5527 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
5528 HRESULT hr;
5529 DWORD dwSize;
5530 WCHAR parentGuid[39];
5531 TRACE("(%p, %p)\n", knownfolder, pKFD);
5533 if(!pKFD) return E_INVALIDARG;
5535 ZeroMemory(pKFD, sizeof(*pKFD));
5537 /* required fields */
5538 hr = get_known_folder_dword(knownfolder->registryPath, szCategory, &pKFD->category);
5539 if(FAILED(hr))
5540 return hr;
5542 hr = get_known_folder_wstr(knownfolder->registryPath, szName, &pKFD->pszName);
5543 if(FAILED(hr))
5544 return hr;
5546 /* optional fields */
5547 dwSize = sizeof(parentGuid);
5548 hr = HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, knownfolder->registryPath, szParentFolder,
5549 RRF_RT_REG_SZ, NULL, parentGuid, &dwSize));
5550 if(SUCCEEDED(hr))
5552 hr = IIDFromString(parentGuid, &pKFD->fidParent);
5553 if(FAILED(hr))
5554 return hr;
5557 get_known_folder_dword(knownfolder->registryPath, szAttributes, &pKFD->dwAttributes);
5559 get_known_folder_wstr(knownfolder->registryPath, szRelativePath, &pKFD->pszRelativePath);
5561 get_known_folder_wstr(knownfolder->registryPath, szParsingName, &pKFD->pszParsingName);
5563 return S_OK;
5566 static const struct IKnownFolderVtbl knownfolder_vtbl =
5568 knownfolder_QueryInterface,
5569 knownfolder_AddRef,
5570 knownfolder_Release,
5571 knownfolder_GetId,
5572 knownfolder_GetCategory,
5573 knownfolder_GetShellItem,
5574 knownfolder_GetPath,
5575 knownfolder_SetPath,
5576 knownfolder_GetIDList,
5577 knownfolder_GetFolderType,
5578 knownfolder_GetRedirectionCapabilities,
5579 knownfolder_GetFolderDefinition
5582 static HRESULT knownfolder_create( struct knownfolder **knownfolder )
5584 struct knownfolder *kf;
5586 kf = HeapAlloc( GetProcessHeap(), 0, sizeof(*kf) );
5587 if (!kf) return E_OUTOFMEMORY;
5589 kf->IKnownFolder_iface.lpVtbl = &knownfolder_vtbl;
5590 kf->refs = 1;
5591 memset( &kf->id, 0, sizeof(kf->id) );
5592 kf->registryPath = NULL;
5594 *knownfolder = kf;
5596 TRACE("returning iface %p\n", &kf->IKnownFolder_iface);
5597 return S_OK;
5600 struct foldermanager
5602 IKnownFolderManager IKnownFolderManager_iface;
5603 LONG refs;
5604 UINT num_ids;
5605 KNOWNFOLDERID *ids;
5608 static inline struct foldermanager *impl_from_IKnownFolderManager( IKnownFolderManager *iface )
5610 return CONTAINING_RECORD( iface, struct foldermanager, IKnownFolderManager_iface );
5613 static ULONG WINAPI foldermanager_AddRef(
5614 IKnownFolderManager *iface )
5616 struct foldermanager *foldermanager = impl_from_IKnownFolderManager( iface );
5617 return InterlockedIncrement( &foldermanager->refs );
5620 static ULONG WINAPI foldermanager_Release(
5621 IKnownFolderManager *iface )
5623 struct foldermanager *foldermanager = impl_from_IKnownFolderManager( iface );
5624 LONG refs = InterlockedDecrement( &foldermanager->refs );
5625 if (!refs)
5627 TRACE("destroying %p\n", foldermanager);
5628 HeapFree( GetProcessHeap(), 0, foldermanager->ids );
5629 HeapFree( GetProcessHeap(), 0, foldermanager );
5631 return refs;
5634 static HRESULT WINAPI foldermanager_QueryInterface(
5635 IKnownFolderManager *iface,
5636 REFIID riid,
5637 void **ppv )
5639 struct foldermanager *This = impl_from_IKnownFolderManager( iface );
5641 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppv );
5643 *ppv = NULL;
5644 if ( IsEqualGUID( riid, &IID_IKnownFolderManager ) ||
5645 IsEqualGUID( riid, &IID_IUnknown ) )
5647 *ppv = iface;
5649 else if ( IsEqualGUID( riid, &IID_IMarshal ) )
5651 TRACE("IID_IMarshal returning NULL.\n");
5652 return E_NOINTERFACE;
5654 else
5656 FIXME("interface %s not implemented\n", debugstr_guid(riid));
5657 return E_NOINTERFACE;
5659 IKnownFolderManager_AddRef( iface );
5660 return S_OK;
5663 static HRESULT WINAPI foldermanager_FolderIdFromCsidl(
5664 IKnownFolderManager *iface,
5665 int nCsidl,
5666 KNOWNFOLDERID *pfid)
5668 TRACE("%d, %p\n", nCsidl, pfid);
5670 if (nCsidl >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
5671 return E_INVALIDARG;
5672 *pfid = *CSIDL_Data[nCsidl].id;
5673 return S_OK;
5676 static HRESULT WINAPI foldermanager_FolderIdToCsidl(
5677 IKnownFolderManager *iface,
5678 REFKNOWNFOLDERID rfid,
5679 int *pnCsidl)
5681 int csidl;
5683 TRACE("%s, %p\n", debugstr_guid(rfid), pnCsidl);
5685 csidl = csidl_from_id( rfid );
5686 if (csidl == -1) return E_INVALIDARG;
5687 *pnCsidl = csidl;
5688 return S_OK;
5691 static HRESULT WINAPI foldermanager_GetFolderIds(
5692 IKnownFolderManager *iface,
5693 KNOWNFOLDERID **ppKFId,
5694 UINT *pCount)
5696 struct foldermanager *fm = impl_from_IKnownFolderManager( iface );
5698 TRACE("%p, %p\n", ppKFId, pCount);
5700 *ppKFId = CoTaskMemAlloc(fm->num_ids * sizeof(KNOWNFOLDERID));
5701 memcpy(*ppKFId, fm->ids, fm->num_ids * sizeof(KNOWNFOLDERID));
5702 *pCount = fm->num_ids;
5703 return S_OK;
5706 static BOOL is_knownfolder( struct foldermanager *fm, const KNOWNFOLDERID *id )
5708 UINT i;
5709 HRESULT hr;
5710 LPWSTR registryPath = NULL;
5711 HKEY hKey;
5713 /* TODO: move all entries from "CSIDL_Data" static array to registry known folder descriptions */
5714 for (i = 0; i < fm->num_ids; i++)
5715 if (IsEqualGUID( &fm->ids[i], id )) return TRUE;
5717 hr = get_known_folder_registry_path(id, NULL, &registryPath);
5718 if(SUCCEEDED(hr))
5720 hr = HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_LOCAL_MACHINE, registryPath, 0, 0, &hKey));
5721 HeapFree(GetProcessHeap(), 0, registryPath);
5724 if(SUCCEEDED(hr))
5726 hr = S_OK;
5727 RegCloseKey(hKey);
5730 return hr == S_OK;
5733 static HRESULT WINAPI foldermanager_GetFolder(
5734 IKnownFolderManager *iface,
5735 REFKNOWNFOLDERID rfid,
5736 IKnownFolder **ppkf)
5738 struct foldermanager *fm = impl_from_IKnownFolderManager( iface );
5739 struct knownfolder *kf;
5740 HRESULT hr;
5742 TRACE("%s, %p\n", debugstr_guid(rfid), ppkf);
5744 if (!is_knownfolder( fm, rfid ))
5746 WARN("unknown folder\n");
5747 return E_INVALIDARG;
5749 hr = knownfolder_create( &kf );
5750 if (SUCCEEDED( hr ))
5752 hr = knownfolder_set_id( kf, rfid );
5753 *ppkf = &kf->IKnownFolder_iface;
5755 else
5756 *ppkf = NULL;
5758 return hr;
5761 static HRESULT WINAPI foldermanager_GetFolderByName(
5762 IKnownFolderManager *iface,
5763 LPCWSTR pszCanonicalName,
5764 IKnownFolder **ppkf)
5766 struct foldermanager *fm = impl_from_IKnownFolderManager( iface );
5767 struct knownfolder *kf;
5768 BOOL found = FALSE;
5769 HRESULT hr;
5770 UINT i;
5772 TRACE( "%s, %p\n", debugstr_w(pszCanonicalName), ppkf );
5774 for (i = 0; i < fm->num_ids; i++)
5776 WCHAR *path, *name;
5777 hr = get_known_folder_registry_path( &fm->ids[i], NULL, &path );
5778 if (FAILED( hr )) return hr;
5780 hr = get_known_folder_wstr( path, szName, &name );
5781 HeapFree( GetProcessHeap(), 0, path );
5782 if (FAILED( hr )) return hr;
5784 found = !strcmpiW( pszCanonicalName, name );
5785 CoTaskMemFree( name );
5786 if (found) break;
5789 if (found)
5791 hr = knownfolder_create( &kf );
5792 if (FAILED( hr )) return hr;
5794 hr = knownfolder_set_id( kf, &fm->ids[i] );
5795 if (FAILED( hr ))
5797 IKnownFolder_Release( &kf->IKnownFolder_iface );
5798 return hr;
5800 *ppkf = &kf->IKnownFolder_iface;
5802 else
5804 hr = HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND );
5805 *ppkf = NULL;
5808 return hr;
5811 static HRESULT register_folder(const KNOWNFOLDERID *rfid, const KNOWNFOLDER_DEFINITION *pKFD)
5813 HRESULT hr;
5814 HKEY hKey = NULL;
5815 DWORD dwDisp;
5816 LPWSTR registryPath = NULL;
5818 hr = get_known_folder_registry_path(rfid, NULL, &registryPath);
5819 TRACE("registry path: %s\n", debugstr_w(registryPath));
5821 if(SUCCEEDED(hr))
5822 hr = HRESULT_FROM_WIN32(RegCreateKeyExW(HKEY_LOCAL_MACHINE, registryPath, 0, NULL, 0, KEY_WRITE, 0, &hKey, &dwDisp));
5824 if(SUCCEEDED(hr))
5826 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, szCategory, 0, REG_DWORD, (LPBYTE)&pKFD->category, sizeof(pKFD->category)));
5828 if(SUCCEEDED(hr) && pKFD->dwAttributes != 0)
5829 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, szAttributes, 0, REG_DWORD, (LPBYTE)&pKFD->dwAttributes, sizeof(pKFD->dwAttributes)));
5831 if(SUCCEEDED(hr))
5832 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, szName, 0, REG_SZ, (LPBYTE)pKFD->pszName, (lstrlenW(pKFD->pszName)+1)*sizeof(WCHAR) ));
5834 if(SUCCEEDED(hr) && pKFD->pszParsingName)
5835 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, szParsingName, 0, REG_SZ, (LPBYTE)pKFD->pszParsingName, (lstrlenW(pKFD->pszParsingName)+1)*sizeof(WCHAR) ));
5837 if(SUCCEEDED(hr) && !IsEqualGUID(&pKFD->fidParent, &GUID_NULL))
5839 WCHAR sParentGuid[39];
5840 StringFromGUID2(&pKFD->fidParent, sParentGuid, sizeof(sParentGuid)/sizeof(sParentGuid[0]));
5842 /* this known folder has parent folder */
5843 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, szParentFolder, 0, REG_SZ, (LPBYTE)sParentGuid, sizeof(sParentGuid)));
5846 if(SUCCEEDED(hr) && pKFD->category != KF_CATEGORY_VIRTUAL && pKFD->pszRelativePath)
5847 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, szRelativePath, 0, REG_SZ, (LPBYTE)pKFD->pszRelativePath, (lstrlenW(pKFD->pszRelativePath)+1)*sizeof(WCHAR) ));
5849 RegCloseKey(hKey);
5851 if(FAILED(hr))
5852 SHDeleteKeyW(HKEY_LOCAL_MACHINE, registryPath);
5855 HeapFree(GetProcessHeap(), 0, registryPath);
5856 return hr;
5859 static HRESULT WINAPI foldermanager_RegisterFolder(
5860 IKnownFolderManager *iface,
5861 REFKNOWNFOLDERID rfid,
5862 KNOWNFOLDER_DEFINITION const *pKFD)
5864 TRACE("(%p, %s, %p)\n", iface, debugstr_guid(rfid), pKFD);
5865 return register_folder(rfid, pKFD);
5868 static HRESULT WINAPI foldermanager_UnregisterFolder(
5869 IKnownFolderManager *iface,
5870 REFKNOWNFOLDERID rfid)
5872 HRESULT hr;
5873 LPWSTR registryPath = NULL;
5874 TRACE("(%p, %s)\n", iface, debugstr_guid(rfid));
5876 hr = get_known_folder_registry_path(rfid, NULL, &registryPath);
5878 if(SUCCEEDED(hr))
5879 hr = HRESULT_FROM_WIN32(SHDeleteKeyW(HKEY_LOCAL_MACHINE, registryPath));
5881 HeapFree(GetProcessHeap(), 0, registryPath);
5882 return hr;
5885 static HRESULT WINAPI foldermanager_FindFolderFromPath(
5886 IKnownFolderManager *iface,
5887 LPCWSTR pszPath,
5888 FFFP_MODE mode,
5889 IKnownFolder **ppkf)
5891 FIXME("%s, 0x%08x, %p\n", debugstr_w(pszPath), mode, ppkf);
5892 return E_NOTIMPL;
5895 static HRESULT WINAPI foldermanager_FindFolderFromIDList(
5896 IKnownFolderManager *iface,
5897 PCIDLIST_ABSOLUTE pidl,
5898 IKnownFolder **ppkf)
5900 FIXME("%p, %p\n", pidl, ppkf);
5901 return E_NOTIMPL;
5904 static HRESULT WINAPI foldermanager_Redirect(
5905 IKnownFolderManager *iface,
5906 REFKNOWNFOLDERID rfid,
5907 HWND hwnd,
5908 KF_REDIRECT_FLAGS flags,
5909 LPCWSTR pszTargetPath,
5910 UINT cFolders,
5911 KNOWNFOLDERID const *pExclusion,
5912 LPWSTR *ppszError)
5914 return redirect_known_folder(rfid, hwnd, flags, pszTargetPath, cFolders, pExclusion, ppszError);
5917 static const struct IKnownFolderManagerVtbl foldermanager_vtbl =
5919 foldermanager_QueryInterface,
5920 foldermanager_AddRef,
5921 foldermanager_Release,
5922 foldermanager_FolderIdFromCsidl,
5923 foldermanager_FolderIdToCsidl,
5924 foldermanager_GetFolderIds,
5925 foldermanager_GetFolder,
5926 foldermanager_GetFolderByName,
5927 foldermanager_RegisterFolder,
5928 foldermanager_UnregisterFolder,
5929 foldermanager_FindFolderFromPath,
5930 foldermanager_FindFolderFromIDList,
5931 foldermanager_Redirect
5934 static HRESULT foldermanager_create( void **ppv )
5936 UINT i, j;
5937 struct foldermanager *fm;
5939 fm = HeapAlloc( GetProcessHeap(), 0, sizeof(*fm) );
5940 if (!fm) return E_OUTOFMEMORY;
5942 fm->IKnownFolderManager_iface.lpVtbl = &foldermanager_vtbl;
5943 fm->refs = 1;
5944 fm->num_ids = 0;
5946 for (i = 0; i < sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]); i++)
5948 if (!IsEqualGUID( CSIDL_Data[i].id, &GUID_NULL )) fm->num_ids++;
5950 fm->ids = HeapAlloc( GetProcessHeap(), 0, fm->num_ids * sizeof(KNOWNFOLDERID) );
5951 if (!fm->ids)
5953 HeapFree( GetProcessHeap(), 0, fm );
5954 return E_OUTOFMEMORY;
5956 for (i = j = 0; i < sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]); i++)
5958 if (!IsEqualGUID( CSIDL_Data[i].id, &GUID_NULL ))
5960 fm->ids[j] = *CSIDL_Data[i].id;
5961 j++;
5964 TRACE("found %u known folders\n", fm->num_ids);
5965 *ppv = &fm->IKnownFolderManager_iface;
5967 TRACE("returning iface %p\n", *ppv);
5968 return S_OK;
5971 HRESULT WINAPI KnownFolderManager_Constructor( IUnknown *punk, REFIID riid, void **ppv )
5973 TRACE("%p, %s, %p\n", punk, debugstr_guid(riid), ppv);
5975 if (!ppv)
5976 return E_POINTER;
5977 if (punk)
5978 return CLASS_E_NOAGGREGATION;
5980 return foldermanager_create( ppv );
5983 HRESULT WINAPI SHGetKnownFolderIDList(REFKNOWNFOLDERID rfid, DWORD flags, HANDLE token, PIDLIST_ABSOLUTE *pidl)
5985 TRACE("%s, 0x%08x, %p, %p\n", debugstr_guid(rfid), flags, token, pidl);
5987 if (!pidl)
5988 return E_INVALIDARG;
5990 if (flags)
5991 FIXME("unsupported flags: 0x%08x\n", flags);
5993 if (token)
5994 FIXME("user token is not used.\n");
5996 *pidl = NULL;
5997 if (IsEqualIID(rfid, &FOLDERID_Desktop))
5998 *pidl = _ILCreateDesktop();
5999 else if (IsEqualIID(rfid, &FOLDERID_RecycleBinFolder))
6000 *pidl = _ILCreateBitBucket();
6001 else if (IsEqualIID(rfid, &FOLDERID_ComputerFolder))
6002 *pidl = _ILCreateMyComputer();
6003 else if (IsEqualIID(rfid, &FOLDERID_PrintersFolder))
6004 *pidl = _ILCreatePrinters();
6005 else if (IsEqualIID(rfid, &FOLDERID_ControlPanelFolder))
6006 *pidl = _ILCreateControlPanel();
6007 else if (IsEqualIID(rfid, &FOLDERID_NetworkFolder))
6008 *pidl = _ILCreateNetwork();
6009 else if (IsEqualIID(rfid, &FOLDERID_Documents))
6010 *pidl = _ILCreateMyDocuments();
6011 else
6013 DWORD attributes = 0;
6014 WCHAR *pathW;
6015 HRESULT hr;
6017 hr = SHGetKnownFolderPath(rfid, flags, token, &pathW);
6018 if (FAILED(hr))
6019 return hr;
6021 hr = SHILCreateFromPathW(pathW, pidl, &attributes);
6022 CoTaskMemFree(pathW);
6023 return hr;
6026 return *pidl ? S_OK : E_FAIL;
6029 HRESULT WINAPI SHGetKnownFolderItem(REFKNOWNFOLDERID rfid, KNOWN_FOLDER_FLAG flags, HANDLE hToken,
6030 REFIID riid, void **ppv)
6032 PIDLIST_ABSOLUTE pidl;
6033 HRESULT hr;
6035 TRACE("%s, 0x%08x, %p, %s, %p\n", debugstr_guid(rfid), flags, hToken, debugstr_guid(riid), ppv);
6037 hr = SHGetKnownFolderIDList(rfid, flags, hToken, &pidl);
6038 if (FAILED(hr))
6040 *ppv = NULL;
6041 return hr;
6044 hr = SHCreateItemFromIDList(pidl, riid, ppv);
6045 CoTaskMemFree(pidl);
6046 return hr;
6049 static void register_system_knownfolders(void)
6051 int i;
6052 for(i = 0; i < sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]); ++i){
6053 const CSIDL_DATA *folder = &CSIDL_Data[i];
6054 if(folder->pszName){
6055 KNOWNFOLDER_DEFINITION kfd;
6057 /* register_folder won't modify kfd, so cast away const instead of
6058 * reallocating */
6059 kfd.category = folder->category;
6060 kfd.pszName = (WCHAR*)folder->pszName;
6061 kfd.pszDescription = (WCHAR*)folder->pszDescription;
6062 memcpy(&kfd.fidParent, folder->fidParent, sizeof(KNOWNFOLDERID));
6063 kfd.pszRelativePath = (WCHAR*)folder->pszRelativePath;
6064 kfd.pszParsingName = (WCHAR*)folder->pszParsingName;
6065 kfd.pszTooltip = (WCHAR*)folder->pszTooltip;
6066 kfd.pszLocalizedName = (WCHAR*)folder->pszLocalizedName;
6067 kfd.pszIcon = (WCHAR*)folder->pszIcon;
6068 kfd.pszSecurity = (WCHAR*)folder->pszSecurity;
6069 kfd.dwAttributes = folder->dwAttributes;
6070 kfd.kfdFlags = folder->kfdFlags;
6071 memcpy(&kfd.ftidType, folder->ftidType, sizeof(FOLDERTYPEID));
6073 register_folder(folder->id, &kfd);
6078 HRESULT SHELL_RegisterShellFolders(void)
6080 HRESULT hr;
6082 /* Set up '$HOME' targeted symlinks for 'My Documents', 'My Pictures',
6083 * 'My Videos', 'My Music' and 'Desktop' in advance, so that the
6084 * _SHRegister*ShellFolders() functions will find everything nice and clean
6085 * and thus will not attempt to create them in the profile directory. */
6086 _SHCreateSymbolicLinks();
6088 hr = _SHRegisterUserShellFolders(TRUE);
6089 if (SUCCEEDED(hr))
6090 hr = _SHRegisterUserShellFolders(FALSE);
6091 if (SUCCEEDED(hr))
6092 hr = _SHRegisterCommonShellFolders();
6093 if (SUCCEEDED(hr))
6094 hr = create_extra_folders();
6095 if (SUCCEEDED(hr))
6096 hr = set_folder_attributes();
6097 if (SUCCEEDED(hr))
6098 register_system_knownfolders();
6099 return hr;