winemac: Don't process QUERY_IME_CHAR_RECT while waiting in OnMainThread().
[wine.git] / dlls / shell32 / shellpath.c
blobcb79d6f4b2ec6eb55f8cd10c7a6a55a7701c8108
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 const KNOWNFOLDERID *id;
1025 CSIDL_Type type;
1026 LPCWSTR szValueName;
1027 LPCWSTR szDefaultPath; /* fallback string or resource ID */
1029 /* KNOWNFOLDER_DEFINITION fields */
1030 KF_CATEGORY category;
1031 const WCHAR *pszName;
1032 const WCHAR *pszDescription;
1033 const KNOWNFOLDERID *fidParent;
1034 const WCHAR *pszRelativePath;
1035 const WCHAR *pszParsingName;
1036 const WCHAR *pszTooltip;
1037 const WCHAR *pszLocalizedName;
1038 const WCHAR *pszIcon;
1039 const WCHAR *pszSecurity;
1040 DWORD dwAttributes;
1041 KF_DEFINITION_FLAGS kfdFlags;
1042 const FOLDERTYPEID *ftidType;
1043 } CSIDL_DATA;
1045 static const CSIDL_DATA CSIDL_Data[] =
1047 { /* 0x00 - CSIDL_DESKTOP */
1048 &FOLDERID_Desktop,
1049 CSIDL_Type_User,
1050 DesktopW,
1051 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY),
1053 KF_CATEGORY_PERUSER, /* category */
1054 DesktopW, /* name */
1055 NULL, /* description */
1056 &GUID_NULL, /* parent */
1057 DesktopW, /* relative path */
1058 NULL, /* parsing */
1059 NULL, /* tooltip */
1060 NULL, /* localized */
1061 NULL, /* icon */
1062 NULL, /* security */
1063 FILE_ATTRIBUTE_READONLY, /* attributes */
1064 0, /* flags */
1065 &GUID_NULL /* typeid */
1067 { /* 0x01 - CSIDL_INTERNET */
1068 &FOLDERID_InternetFolder,
1069 CSIDL_Type_Disallowed,
1070 NULL,
1071 NULL,
1073 KF_CATEGORY_VIRTUAL, /* category */
1074 InternetFolderW, /* name */
1075 NULL, /* description */
1076 &GUID_NULL, /* parent */
1077 NULL, /* relative path */
1078 InternetFolderParsingNameW, /* parsing */
1079 NULL, /* tooltip */
1080 NULL, /* localized */
1081 NULL, /* icon */
1082 NULL, /* security */
1083 0, /* attributes */
1084 0, /* flags */
1085 &GUID_NULL /* typeid */
1087 { /* 0x02 - CSIDL_PROGRAMS */
1088 &FOLDERID_Programs,
1089 CSIDL_Type_User,
1090 ProgramsW,
1091 Start_Menu_ProgramsW,
1093 KF_CATEGORY_PERUSER, /* category */
1094 ProgramsW, /* name */
1095 NULL, /* description */
1096 &GUID_NULL, /* parent */
1097 ProgramsW, /* relative path */
1098 NULL, /* parsing */
1099 NULL, /* tooltip */
1100 NULL, /* localized */
1101 NULL, /* icon */
1102 NULL, /* security */
1103 FILE_ATTRIBUTE_READONLY, /* attributes */
1104 0, /* flags */
1105 &GUID_NULL /* typeid */
1107 { /* 0x03 - CSIDL_CONTROLS (.CPL files) */
1108 &FOLDERID_ControlPanelFolder,
1109 CSIDL_Type_SystemPath,
1110 NULL,
1111 NULL,
1113 KF_CATEGORY_VIRTUAL, /* category */
1114 ControlPanelFolderW, /* name */
1115 NULL, /* description */
1116 &GUID_NULL, /* parent */
1117 ControlPanelFolderRelativePathW, /* relative path */
1118 ControlPanelFolderParsingNameW, /* parsing */
1119 NULL, /* tooltip */
1120 NULL, /* localized */
1121 NULL, /* icon */
1122 NULL, /* security */
1123 0, /* attributes */
1124 0, /* flags */
1125 &GUID_NULL /* typeid */
1127 { /* 0x04 - CSIDL_PRINTERS */
1128 &FOLDERID_PrintersFolder,
1129 CSIDL_Type_SystemPath,
1130 NULL,
1131 NULL,
1133 KF_CATEGORY_VIRTUAL, /* category */
1134 PrintersFolderW, /* name */
1135 NULL, /* description */
1136 &GUID_NULL, /* parent */
1137 NULL, /* relative path */
1138 PrintersFolderParsingNameW, /* parsing */
1139 NULL, /* tooltip */
1140 NULL, /* localized */
1141 NULL, /* icon */
1142 NULL, /* security */
1143 0, /* attributes */
1144 0, /* flags */
1145 &GUID_NULL /* typeid */
1147 { /* 0x05 - CSIDL_PERSONAL */
1148 &FOLDERID_Documents,
1149 CSIDL_Type_User,
1150 PersonalW,
1151 MAKEINTRESOURCEW(IDS_PERSONAL),
1153 KF_CATEGORY_PERUSER, /* category */
1154 PersonalW, /* name */
1155 NULL, /* description */
1156 &GUID_NULL, /* parent */
1157 DocumentsW, /* relative path */
1158 DocumentsParsingNameW, /* parsing */
1159 NULL, /* tooltip */
1160 NULL, /* localized */
1161 NULL, /* icon */
1162 NULL, /* security */
1163 FILE_ATTRIBUTE_READONLY, /* attributes */
1164 KFDF_ROAMABLE | KFDF_PRECREATE, /* flags */
1165 &GUID_NULL /* typeid */
1167 { /* 0x06 - CSIDL_FAVORITES */
1168 &FOLDERID_Favorites,
1169 CSIDL_Type_User,
1170 FavoritesW,
1171 FavoritesW,
1173 KF_CATEGORY_PERUSER, /* category */
1174 FavoritesW, /* name */
1175 NULL, /* description */
1176 &GUID_NULL, /* parent */
1177 FavoritesW, /* relative path */
1178 NULL, /* parsing */
1179 NULL, /* tooltip */
1180 NULL, /* localized */
1181 NULL, /* icon */
1182 NULL, /* security */
1183 FILE_ATTRIBUTE_READONLY, /* attributes */
1184 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH, /* flags */
1185 &GUID_NULL /* typeid */
1187 { /* 0x07 - CSIDL_STARTUP */
1188 &FOLDERID_Startup,
1189 CSIDL_Type_User,
1190 StartUpW,
1191 Start_Menu_StartupW,
1193 KF_CATEGORY_PERUSER, /* category */
1194 StartupW, /* name */
1195 NULL, /* description */
1196 &GUID_NULL, /* parent */
1197 StartUpW, /* relative path */
1198 NULL, /* parsing */
1199 NULL, /* tooltip */
1200 NULL, /* localized */
1201 NULL, /* icon */
1202 NULL, /* security */
1203 FILE_ATTRIBUTE_READONLY, /* attributes */
1204 KFDF_PRECREATE, /* flags */
1205 &GUID_NULL /* typeid */
1207 { /* 0x08 - CSIDL_RECENT */
1208 &FOLDERID_Recent,
1209 CSIDL_Type_User,
1210 RecentW,
1211 RecentW,
1213 KF_CATEGORY_PERUSER, /* category */
1214 RecentW, /* name */
1215 NULL, /* description */
1216 &FOLDERID_RoamingAppData, /* parent */
1217 Microsoft_Windows_RecentW, /* relative path */
1218 NULL, /* parsing */
1219 NULL, /* tooltip */
1220 NULL, /* localized */
1221 NULL, /* icon */
1222 NULL, /* security */
1223 FILE_ATTRIBUTE_READONLY, /* attributes */
1224 KFDF_PRECREATE, /* flags */
1225 &GUID_NULL /* typeid */
1227 { /* 0x09 - CSIDL_SENDTO */
1228 &FOLDERID_SendTo,
1229 CSIDL_Type_User,
1230 SendToW,
1231 SendToW,
1233 KF_CATEGORY_PERUSER, /* category */
1234 SendToW, /* name */
1235 NULL, /* description */
1236 &FOLDERID_RoamingAppData, /* parent */
1237 Microsoft_Windows_SendToW, /* relative path */
1238 NULL, /* parsing */
1239 NULL, /* tooltip */
1240 NULL, /* localized */
1241 NULL, /* icon */
1242 NULL, /* security */
1243 0, /* attributes */
1244 KFDF_PRECREATE, /* flags */
1245 &GUID_NULL /* typeid */
1247 { /* 0x0a - CSIDL_BITBUCKET - Recycle Bin */
1248 &FOLDERID_RecycleBinFolder,
1249 CSIDL_Type_Disallowed,
1250 NULL,
1251 NULL,
1253 KF_CATEGORY_VIRTUAL, /* category */
1254 RecycleBinFolderW, /* name */
1255 NULL, /* description */
1256 &GUID_NULL, /* parent */
1257 NULL, /* relative path */
1258 RecycleBinFolderParsingNameW, /* parsing */
1259 NULL, /* tooltip */
1260 NULL, /* localized */
1261 NULL, /* icon */
1262 NULL, /* security */
1263 0, /* attributes */
1264 0, /* flags */
1265 &GUID_NULL /* typeid */
1267 { /* 0x0b - CSIDL_STARTMENU */
1268 &FOLDERID_StartMenu,
1269 CSIDL_Type_User,
1270 Start_MenuW,
1271 Start_MenuW,
1273 KF_CATEGORY_PERUSER, /* category */
1274 Start_MenuW, /* name */
1275 NULL, /* description */
1276 &FOLDERID_RoamingAppData, /* parent */
1277 Microsoft_Windows_Start_MenuW, /* relative path */
1278 NULL, /* parsing */
1279 NULL, /* tooltip */
1280 NULL, /* localized */
1281 NULL, /* icon */
1282 NULL, /* security */
1283 FILE_ATTRIBUTE_READONLY, /* attributes */
1284 KFDF_PRECREATE, /* flags */
1285 &GUID_NULL /* typeid */
1287 { /* 0x0c - CSIDL_MYDOCUMENTS */
1288 &GUID_NULL,
1289 CSIDL_Type_Disallowed, /* matches WinXP--can't get its path */
1290 NULL,
1291 NULL
1293 { /* 0x0d - CSIDL_MYMUSIC */
1294 &FOLDERID_Music,
1295 CSIDL_Type_User,
1296 My_MusicW,
1297 MAKEINTRESOURCEW(IDS_MYMUSIC),
1299 KF_CATEGORY_PERUSER, /* category */
1300 My_MusicW, /* name */
1301 NULL, /* description */
1302 &FOLDERID_Profile, /* parent */
1303 MusicW, /* relative path */
1304 MusicParsingNameW, /* parsing */
1305 NULL, /* tooltip */
1306 NULL, /* localized */
1307 NULL, /* icon */
1308 NULL, /* security */
1309 FILE_ATTRIBUTE_READONLY, /* attributes */
1310 KFDF_ROAMABLE | KFDF_PRECREATE, /* flags */
1311 &GUID_NULL /* typeid */
1313 { /* 0x0e - CSIDL_MYVIDEO */
1314 &FOLDERID_Videos,
1315 CSIDL_Type_User,
1316 My_VideosW,
1317 MAKEINTRESOURCEW(IDS_MYVIDEOS),
1319 KF_CATEGORY_PERUSER, /* category */
1320 My_VideoW, /* name */
1321 NULL, /* description */
1322 &FOLDERID_Profile, /* parent */
1323 VideosW, /* relative path */
1324 VideosParsingNameW, /* parsing */
1325 NULL, /* tooltip */
1326 NULL, /* localized */
1327 NULL, /* icon */
1328 NULL, /* security */
1329 FILE_ATTRIBUTE_READONLY, /* attributes */
1330 KFDF_ROAMABLE | KFDF_PRECREATE, /* flags */
1331 &GUID_NULL /* typeid */
1333 { /* 0x0f - unassigned */
1334 &GUID_NULL,
1335 CSIDL_Type_Disallowed,
1336 NULL,
1337 NULL,
1339 { /* 0x10 - CSIDL_DESKTOPDIRECTORY */
1340 &FOLDERID_Desktop,
1341 CSIDL_Type_User,
1342 DesktopW,
1343 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY),
1345 KF_CATEGORY_PERUSER, /* category */
1346 DesktopW, /* name */
1347 NULL, /* description */
1348 &FOLDERID_Profile, /* parent */
1349 DesktopW, /* relative path */
1350 NULL, /* parsing */
1351 NULL, /* tooltip */
1352 NULL, /* localized */
1353 NULL, /* icon */
1354 NULL, /* security */
1355 FILE_ATTRIBUTE_READONLY, /* attributes */
1356 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH, /* flags */
1357 &GUID_NULL /* typeid */
1359 { /* 0x11 - CSIDL_DRIVES */
1360 &FOLDERID_ComputerFolder,
1361 CSIDL_Type_Disallowed,
1362 NULL,
1363 NULL,
1365 KF_CATEGORY_VIRTUAL, /* category */
1366 MyComputerFolderW, /* name */
1367 NULL, /* description */
1368 &GUID_NULL, /* parent */
1369 NULL, /* relative path */
1370 ComputerFolderParsingNameW, /* parsing */
1371 NULL, /* tooltip */
1372 NULL, /* localized */
1373 NULL, /* icon */
1374 NULL, /* security */
1375 0, /* attributes */
1376 0, /* flags */
1377 &GUID_NULL /* typeid */
1379 { /* 0x12 - CSIDL_NETWORK */
1380 &FOLDERID_NetworkFolder,
1381 CSIDL_Type_Disallowed,
1382 NULL,
1383 NULL,
1385 KF_CATEGORY_VIRTUAL, /* category */
1386 NetworkPlacesFolderW, /* name */
1387 NULL, /* description */
1388 &GUID_NULL, /* parent */
1389 NULL, /* relative path */
1390 NetworkFolderParsingNameW, /* parsing */
1391 NULL, /* tooltip */
1392 NULL, /* localized */
1393 NULL, /* icon */
1394 NULL, /* security */
1395 0, /* attributes */
1396 0, /* flags */
1397 &GUID_NULL /* typeid */
1399 { /* 0x13 - CSIDL_NETHOOD */
1400 &FOLDERID_NetHood,
1401 CSIDL_Type_User,
1402 NetHoodW,
1403 NetHoodW,
1405 KF_CATEGORY_PERUSER, /* category */
1406 NetHoodW, /* name */
1407 NULL, /* description */
1408 &FOLDERID_RoamingAppData, /* parent */
1409 Microsoft_Windows_Network_ShortcutsW, /* relative path */
1410 NULL, /* parsing */
1411 NULL, /* tooltip */
1412 NULL, /* localized */
1413 NULL, /* icon */
1414 NULL, /* security */
1415 0, /* attributes */
1416 0, /* flags */
1417 &GUID_NULL /* typeid */
1419 { /* 0x14 - CSIDL_FONTS */
1420 &FOLDERID_Fonts,
1421 CSIDL_Type_WindowsPath,
1422 FontsW,
1423 FontsW,
1425 KF_CATEGORY_FIXED, /* category */
1426 FontsW, /* name */
1427 NULL, /* description */
1428 &GUID_NULL, /* parent */
1429 NULL, /* relative path */
1430 NULL, /* parsing */
1431 NULL, /* tooltip */
1432 NULL, /* localized */
1433 NULL, /* icon */
1434 NULL, /* security */
1435 0, /* attributes */
1436 0, /* flags */
1437 &FOLDERID_Windows/* typeid */
1439 { /* 0x15 - CSIDL_TEMPLATES */
1440 &FOLDERID_Templates,
1441 CSIDL_Type_User,
1442 TemplatesW,
1443 TemplatesW,
1445 KF_CATEGORY_PERUSER, /* category */
1446 TemplatesW, /* name */
1447 NULL, /* description */
1448 &FOLDERID_RoamingAppData, /* parent */
1449 Microsoft_Windows_TemplatesW, /* relative path */
1450 NULL, /* parsing */
1451 NULL, /* tooltip */
1452 NULL, /* localized */
1453 NULL, /* icon */
1454 NULL, /* security */
1455 0, /* attributes */
1456 0, /* flags */
1457 &GUID_NULL /* typeid */
1459 { /* 0x16 - CSIDL_COMMON_STARTMENU */
1460 &FOLDERID_CommonStartMenu,
1461 CSIDL_Type_AllUsers,
1462 Common_Start_MenuW,
1463 Start_MenuW,
1465 KF_CATEGORY_COMMON, /* category */
1466 Common_Start_MenuW, /* name */
1467 NULL, /* description */
1468 &FOLDERID_ProgramData, /* parent */
1469 Microsoft_Windows_Start_MenuW, /* relative path */
1470 NULL, /* parsing */
1471 NULL, /* tooltip */
1472 NULL, /* localized */
1473 NULL, /* icon */
1474 NULL, /* security */
1475 FILE_ATTRIBUTE_READONLY, /* attributes */
1476 0, /* flags */
1477 &GUID_NULL /* typeid */
1479 { /* 0x17 - CSIDL_COMMON_PROGRAMS */
1480 &FOLDERID_CommonPrograms,
1481 CSIDL_Type_AllUsers,
1482 Common_ProgramsW,
1483 Start_Menu_ProgramsW,
1485 KF_CATEGORY_COMMON, /* category */
1486 Common_ProgramsW, /* name */
1487 NULL, /* description */
1488 &FOLDERID_CommonStartMenu, /* parent */
1489 ProgramsW, /* relative path */
1490 NULL, /* parsing */
1491 NULL, /* tooltip */
1492 NULL, /* localized */
1493 NULL, /* icon */
1494 NULL, /* security */
1495 FILE_ATTRIBUTE_READONLY, /* attributes */
1496 0, /* flags */
1497 &GUID_NULL /* typeid */
1499 { /* 0x18 - CSIDL_COMMON_STARTUP */
1500 &FOLDERID_CommonStartup,
1501 CSIDL_Type_AllUsers,
1502 Common_StartUpW,
1503 Start_Menu_StartupW,
1505 KF_CATEGORY_COMMON, /* category */
1506 Common_StartupW, /* name */
1507 NULL, /* description */
1508 &FOLDERID_CommonPrograms, /* parent */
1509 StartUpW, /* relative path */
1510 NULL, /* parsing */
1511 NULL, /* tooltip */
1512 NULL, /* localized */
1513 NULL, /* icon */
1514 NULL, /* security */
1515 FILE_ATTRIBUTE_READONLY, /* attributes */
1516 KFDF_PRECREATE, /* flags */
1517 &GUID_NULL /* typeid */
1519 { /* 0x19 - CSIDL_COMMON_DESKTOPDIRECTORY */
1520 &FOLDERID_PublicDesktop,
1521 CSIDL_Type_AllUsers,
1522 Common_DesktopW,
1523 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY),
1525 KF_CATEGORY_COMMON, /* category */
1526 Common_DesktopW, /* name */
1527 NULL, /* description */
1528 &FOLDERID_Public, /* parent */
1529 DesktopW, /* relative path */
1530 NULL, /* parsing */
1531 NULL, /* tooltip */
1532 NULL, /* localized */
1533 NULL, /* icon */
1534 NULL, /* security */
1535 FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN, /* attributes */
1536 KFDF_PRECREATE, /* flags */
1537 &GUID_NULL /* typeid */
1539 { /* 0x1a - CSIDL_APPDATA */
1540 &FOLDERID_RoamingAppData,
1541 CSIDL_Type_User,
1542 AppDataW,
1543 Application_DataW,
1545 KF_CATEGORY_PERUSER, /* category */
1546 AppDataW, /* name */
1547 NULL, /* description */
1548 &FOLDERID_Profile, /* parent */
1549 AppData_RoamingW, /* relative path */
1550 NULL, /* parsing */
1551 NULL, /* tooltip */
1552 NULL, /* localized */
1553 NULL, /* icon */
1554 NULL, /* security */
1555 0, /* attributes */
1556 0, /* flags */
1557 &GUID_NULL /* typeid */
1559 { /* 0x1b - CSIDL_PRINTHOOD */
1560 &FOLDERID_PrintHood,
1561 CSIDL_Type_User,
1562 PrintHoodW,
1563 PrintHoodW,
1565 KF_CATEGORY_PERUSER, /* category */
1566 PrintHoodW, /* name */
1567 NULL, /* description */
1568 &FOLDERID_RoamingAppData, /* parent */
1569 Microsoft_Windows_Printer_ShortcutsW, /* relative path */
1570 NULL, /* parsing */
1571 NULL, /* tooltip */
1572 NULL, /* localized */
1573 NULL, /* icon */
1574 NULL, /* security */
1575 0, /* attributes */
1576 0, /* flags */
1577 &GUID_NULL /* typeid */
1579 { /* 0x1c - CSIDL_LOCAL_APPDATA */
1580 &FOLDERID_LocalAppData,
1581 CSIDL_Type_User,
1582 Local_AppDataW,
1583 Local_Settings_Application_DataW,
1585 KF_CATEGORY_PERUSER, /* category */
1586 Local_AppDataW, /* name */
1587 NULL, /* description */
1588 &FOLDERID_Profile, /* parent */
1589 AppData_LocalW, /* relative path */
1590 NULL, /* parsing */
1591 NULL, /* tooltip */
1592 NULL, /* localized */
1593 NULL, /* icon */
1594 NULL, /* security */
1595 0, /* attributes */
1596 KFDF_LOCAL_REDIRECT_ONLY | KFDF_PUBLISHEXPANDEDPATH, /* flags */
1597 &GUID_NULL /* typeid */
1599 { /* 0x1d - CSIDL_ALTSTARTUP */
1600 &GUID_NULL,
1601 CSIDL_Type_NonExistent,
1602 NULL,
1603 NULL
1605 { /* 0x1e - CSIDL_COMMON_ALTSTARTUP */
1606 &GUID_NULL,
1607 CSIDL_Type_NonExistent,
1608 NULL,
1609 NULL
1611 { /* 0x1f - CSIDL_COMMON_FAVORITES */
1612 &FOLDERID_Favorites,
1613 CSIDL_Type_AllUsers,
1614 Common_FavoritesW,
1615 FavoritesW,
1617 KF_CATEGORY_PERUSER, /* category */
1618 FavoritesW, /* name */
1619 NULL, /* description */
1620 &FOLDERID_Profile, /* parent */
1621 FavoritesW, /* relative path */
1622 NULL, /* parsing */
1623 NULL, /* tooltip */
1624 NULL, /* localized */
1625 NULL, /* icon */
1626 NULL, /* security */
1627 FILE_ATTRIBUTE_READONLY, /* attributes */
1628 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH, /* flags */
1629 &GUID_NULL /* typeid */
1631 { /* 0x20 - CSIDL_INTERNET_CACHE */
1632 &FOLDERID_InternetCache,
1633 CSIDL_Type_User,
1634 CacheW,
1635 Local_Settings_Temporary_Internet_FilesW,
1637 KF_CATEGORY_PERUSER, /* category */
1638 CacheW, /* name */
1639 NULL, /* description */
1640 &FOLDERID_LocalAppData, /* parent */
1641 Microsoft_Windows_Temporary_Internet_FilesW, /* relative path */
1642 NULL, /* parsing */
1643 NULL, /* tooltip */
1644 NULL, /* localized */
1645 NULL, /* icon */
1646 NULL, /* security */
1647 0, /* attributes */
1648 KFDF_LOCAL_REDIRECT_ONLY, /* flags */
1649 &GUID_NULL /* typeid */
1651 { /* 0x21 - CSIDL_COOKIES */
1652 &FOLDERID_Cookies,
1653 CSIDL_Type_User,
1654 CookiesW,
1655 CookiesW,
1657 KF_CATEGORY_PERUSER, /* category */
1658 CookiesW, /* name */
1659 NULL, /* description */
1660 &FOLDERID_RoamingAppData, /* parent */
1661 Microsoft_Windows_CookiesW, /* relative path */
1662 NULL, /* parsing */
1663 NULL, /* tooltip */
1664 NULL, /* localized */
1665 NULL, /* icon */
1666 NULL, /* security */
1667 0, /* attributes */
1668 0, /* flags */
1669 &GUID_NULL /* typeid */
1671 { /* 0x22 - CSIDL_HISTORY */
1672 &FOLDERID_History,
1673 CSIDL_Type_User,
1674 HistoryW,
1675 Local_Settings_HistoryW,
1677 KF_CATEGORY_PERUSER, /* category */
1678 HistoryW, /* name */
1679 NULL, /* description */
1680 &FOLDERID_LocalAppData, /* parent */
1681 Microsoft_Windows_HistoryW, /* relative path */
1682 NULL, /* parsing */
1683 NULL, /* tooltip */
1684 NULL, /* localized */
1685 NULL, /* icon */
1686 NULL, /* security */
1687 0, /* attributes */
1688 KFDF_LOCAL_REDIRECT_ONLY, /* flags */
1689 &GUID_NULL /* typeid */
1691 { /* 0x23 - CSIDL_COMMON_APPDATA */
1692 &FOLDERID_ProgramData,
1693 CSIDL_Type_AllUsers,
1694 Common_AppDataW,
1695 Application_DataW,
1697 KF_CATEGORY_FIXED, /* category */
1698 Common_AppDataW, /* name */
1699 NULL, /* description */
1700 &GUID_NULL, /* parent */
1701 NULL, /* relative path */
1702 NULL, /* parsing */
1703 NULL, /* tooltip */
1704 NULL, /* localized */
1705 NULL, /* icon */
1706 NULL, /* security */
1707 0, /* attributes */
1708 0, /* flags */
1709 &GUID_NULL /* typeid */
1711 { /* 0x24 - CSIDL_WINDOWS */
1712 &FOLDERID_Windows,
1713 CSIDL_Type_WindowsPath,
1714 NULL,
1715 NULL,
1717 KF_CATEGORY_FIXED, /* category */
1718 WindowsW, /* name */
1719 NULL, /* description */
1720 &GUID_NULL, /* parent */
1721 NULL, /* relative path */
1722 NULL, /* parsing */
1723 NULL, /* tooltip */
1724 NULL, /* localized */
1725 NULL, /* icon */
1726 NULL, /* security */
1727 0, /* attributes */
1728 0, /* flags */
1729 &GUID_NULL /* typeid */
1731 { /* 0x25 - CSIDL_SYSTEM */
1732 &FOLDERID_System,
1733 CSIDL_Type_SystemPath,
1734 NULL,
1735 NULL,
1737 KF_CATEGORY_FIXED, /* category */
1738 SystemW, /* name */
1739 NULL, /* description */
1740 &GUID_NULL, /* parent */
1741 NULL, /* relative path */
1742 NULL, /* parsing */
1743 NULL, /* tooltip */
1744 NULL, /* localized */
1745 NULL, /* icon */
1746 NULL, /* security */
1747 0, /* attributes */
1748 0, /* flags */
1749 &GUID_NULL /* typeid */
1751 { /* 0x26 - CSIDL_PROGRAM_FILES */
1752 &FOLDERID_ProgramFiles,
1753 CSIDL_Type_CurrVer,
1754 ProgramFilesDirW,
1755 Program_FilesW,
1757 KF_CATEGORY_FIXED, /* category */
1758 ProgramFilesW, /* name */
1759 NULL, /* description */
1760 &GUID_NULL, /* parent */
1761 NULL, /* relative path */
1762 NULL, /* parsing */
1763 NULL, /* tooltip */
1764 NULL, /* localized */
1765 NULL, /* icon */
1766 NULL, /* security */
1767 FILE_ATTRIBUTE_READONLY, /* attributes */
1768 0, /* flags */
1769 &GUID_NULL /* typeid */
1771 { /* 0x27 - CSIDL_MYPICTURES */
1772 &FOLDERID_Pictures,
1773 CSIDL_Type_User,
1774 My_PicturesW,
1775 MAKEINTRESOURCEW(IDS_MYPICTURES),
1777 KF_CATEGORY_PERUSER, /* category */
1778 My_PicturesW, /* name */
1779 NULL, /* description */
1780 &FOLDERID_Profile, /* parent */
1781 PicturesW, /* relative path */
1782 PicturesParsingNameW, /* parsing */
1783 NULL, /* tooltip */
1784 NULL, /* localized */
1785 NULL, /* icon */
1786 NULL, /* security */
1787 FILE_ATTRIBUTE_READONLY, /* attributes */
1788 KFDF_ROAMABLE | KFDF_PRECREATE, /* flags */
1789 &GUID_NULL /* typeid */
1791 { /* 0x28 - CSIDL_PROFILE */
1792 &FOLDERID_Profile,
1793 CSIDL_Type_User,
1794 NULL,
1795 NULL,
1797 KF_CATEGORY_FIXED, /* category */
1798 ProfileW, /* name */
1799 NULL, /* description */
1800 &GUID_NULL, /* parent */
1801 NULL, /* relative path */
1802 NULL, /* parsing */
1803 NULL, /* tooltip */
1804 NULL, /* localized */
1805 NULL, /* icon */
1806 NULL, /* security */
1807 0, /* attributes */
1808 0, /* flags */
1809 &GUID_NULL /* typeid */
1811 { /* 0x29 - CSIDL_SYSTEMX86 */
1812 &FOLDERID_SystemX86,
1813 CSIDL_Type_SystemX86Path,
1814 NULL,
1815 NULL,
1817 KF_CATEGORY_FIXED, /* category */
1818 SystemX86W, /* name */
1819 NULL, /* description */
1820 &GUID_NULL, /* parent */
1821 NULL, /* relative path */
1822 NULL, /* parsing */
1823 NULL, /* tooltip */
1824 NULL, /* localized */
1825 NULL, /* icon */
1826 NULL, /* security */
1827 0, /* attributes */
1828 0, /* flags */
1829 &GUID_NULL /* typeid */
1831 { /* 0x2a - CSIDL_PROGRAM_FILESX86 */
1832 &FOLDERID_ProgramFilesX86,
1833 CSIDL_Type_CurrVer,
1834 ProgramFilesDirX86W,
1835 Program_Files_x86W,
1837 KF_CATEGORY_FIXED, /* category */
1838 ProgramFilesX86W, /* name */
1839 NULL, /* description */
1840 &GUID_NULL, /* parent */
1841 NULL, /* relative path */
1842 NULL, /* parsing */
1843 NULL, /* tooltip */
1844 NULL, /* localized */
1845 NULL, /* icon */
1846 NULL, /* security */
1847 FILE_ATTRIBUTE_READONLY, /* attributes */
1848 0, /* flags */
1849 &GUID_NULL /* typeid */
1851 { /* 0x2b - CSIDL_PROGRAM_FILES_COMMON */
1852 &FOLDERID_ProgramFilesCommon,
1853 CSIDL_Type_CurrVer,
1854 CommonFilesDirW,
1855 Program_Files_Common_FilesW,
1857 KF_CATEGORY_FIXED, /* category */
1858 ProgramFilesCommonW, /* name */
1859 NULL, /* description */
1860 &GUID_NULL, /* parent */
1861 NULL, /* relative path */
1862 NULL, /* parsing */
1863 NULL, /* tooltip */
1864 NULL, /* localized */
1865 NULL, /* icon */
1866 NULL, /* security */
1867 0, /* attributes */
1868 0, /* flags */
1869 &GUID_NULL /* typeid */
1871 { /* 0x2c - CSIDL_PROGRAM_FILES_COMMONX86 */
1872 &FOLDERID_ProgramFilesCommonX86,
1873 CSIDL_Type_CurrVer,
1874 CommonFilesDirX86W,
1875 Program_Files_x86_Common_FilesW,
1877 KF_CATEGORY_FIXED, /* category */
1878 ProgramFilesCommonX86W, /* name */
1879 NULL, /* description */
1880 &GUID_NULL, /* parent */
1881 NULL, /* relative path */
1882 NULL, /* parsing */
1883 NULL, /* tooltip */
1884 NULL, /* localized */
1885 NULL, /* icon */
1886 NULL, /* security */
1887 0, /* attributes */
1888 0, /* flags */
1889 &GUID_NULL /* typeid */
1891 { /* 0x2d - CSIDL_COMMON_TEMPLATES */
1892 &FOLDERID_CommonTemplates,
1893 CSIDL_Type_AllUsers,
1894 Common_TemplatesW,
1895 TemplatesW,
1897 KF_CATEGORY_COMMON, /* category */
1898 Common_TemplatesW, /* name */
1899 NULL, /* description */
1900 &FOLDERID_ProgramData, /* parent */
1901 Microsoft_Windows_TemplatesW, /* relative path */
1902 NULL, /* parsing */
1903 NULL, /* tooltip */
1904 NULL, /* localized */
1905 NULL, /* icon */
1906 NULL, /* security */
1907 0, /* attributes */
1908 0, /* flags */
1909 &GUID_NULL /* typeid */
1911 { /* 0x2e - CSIDL_COMMON_DOCUMENTS */
1912 &FOLDERID_PublicDocuments,
1913 CSIDL_Type_AllUsers,
1914 Common_DocumentsW,
1915 DocumentsW,
1917 KF_CATEGORY_COMMON, /* category */
1918 Common_DocumentsW, /* name */
1919 NULL, /* description */
1920 &FOLDERID_Public, /* parent */
1921 DocumentsW, /* relative path */
1922 NULL, /* parsing */
1923 NULL, /* tooltip */
1924 NULL, /* localized */
1925 NULL, /* icon */
1926 NULL, /* security */
1927 FILE_ATTRIBUTE_READONLY, /* attributes */
1928 KFDF_PRECREATE, /* flags */
1929 &GUID_NULL /* typeid */
1931 { /* 0x2f - CSIDL_COMMON_ADMINTOOLS */
1932 &FOLDERID_CommonAdminTools,
1933 CSIDL_Type_AllUsers,
1934 Common_Administrative_ToolsW,
1935 Start_Menu_Admin_ToolsW,
1937 KF_CATEGORY_COMMON, /* category */
1938 Common_Administrative_ToolsW, /* name */
1939 NULL, /* description */
1940 &FOLDERID_CommonPrograms, /* parent */
1941 Administrative_ToolsW, /* relative path */
1942 NULL, /* parsing */
1943 NULL, /* tooltip */
1944 NULL, /* localized */
1945 NULL, /* icon */
1946 NULL, /* security */
1947 FILE_ATTRIBUTE_READONLY, /* attributes */
1948 KFDF_PRECREATE, /* flags */
1949 &GUID_NULL /* typeid */
1951 { /* 0x30 - CSIDL_ADMINTOOLS */
1952 &FOLDERID_AdminTools,
1953 CSIDL_Type_User,
1954 Administrative_ToolsW,
1955 Start_Menu_Admin_ToolsW,
1957 KF_CATEGORY_PERUSER, /* category */
1958 Administrative_ToolsW, /* name */
1959 NULL, /* description */
1960 &FOLDERID_Programs, /* parent */
1961 Administrative_ToolsW, /* relative path */
1962 NULL, /* parsing */
1963 NULL, /* tooltip */
1964 NULL, /* localized */
1965 NULL, /* icon */
1966 NULL, /* security */
1967 FILE_ATTRIBUTE_READONLY, /* attributes */
1968 KFDF_PRECREATE, /* flags */
1969 &GUID_NULL /* typeid */
1971 { /* 0x31 - CSIDL_CONNECTIONS */
1972 &FOLDERID_ConnectionsFolder,
1973 CSIDL_Type_Disallowed,
1974 NULL,
1975 NULL,
1977 KF_CATEGORY_VIRTUAL, /* category */
1978 ConnectionsFolderW, /* name */
1979 NULL, /* description */
1980 &GUID_NULL, /* parent */
1981 Administrative_ToolsW, /* relative path */
1982 ConnectionsFolderParsingNameW, /* parsing */
1983 NULL, /* tooltip */
1984 NULL, /* localized */
1985 NULL, /* icon */
1986 NULL, /* security */
1987 0, /* attributes */
1988 0, /* flags */
1989 &GUID_NULL /* typeid */
1991 { /* 0x32 - unassigned */
1992 &GUID_NULL,
1993 CSIDL_Type_Disallowed,
1994 NULL,
1995 NULL
1997 { /* 0x33 - unassigned */
1998 &GUID_NULL,
1999 CSIDL_Type_Disallowed,
2000 NULL,
2001 NULL
2003 { /* 0x34 - unassigned */
2004 &GUID_NULL,
2005 CSIDL_Type_Disallowed,
2006 NULL,
2007 NULL
2009 { /* 0x35 - CSIDL_COMMON_MUSIC */
2010 &FOLDERID_PublicMusic,
2011 CSIDL_Type_AllUsers,
2012 CommonMusicW,
2013 MusicW,
2015 KF_CATEGORY_COMMON, /* category */
2016 CommonMusicW, /* name */
2017 NULL, /* description */
2018 &FOLDERID_Public, /* parent */
2019 MusicW, /* relative path */
2020 NULL, /* parsing */
2021 NULL, /* tooltip */
2022 NULL, /* localized */
2023 NULL, /* icon */
2024 NULL, /* security */
2025 FILE_ATTRIBUTE_READONLY, /* attributes */
2026 KFDF_PRECREATE, /* flags */
2027 &GUID_NULL /* typeid */
2029 { /* 0x36 - CSIDL_COMMON_PICTURES */
2030 &FOLDERID_PublicPictures,
2031 CSIDL_Type_AllUsers,
2032 CommonPicturesW,
2033 PicturesW,
2035 KF_CATEGORY_COMMON, /* category */
2036 CommonPicturesW, /* name */
2037 NULL, /* description */
2038 &FOLDERID_Public, /* parent */
2039 PicturesW, /* relative path */
2040 NULL, /* parsing */
2041 NULL, /* tooltip */
2042 NULL, /* localized */
2043 NULL, /* icon */
2044 NULL, /* security */
2045 FILE_ATTRIBUTE_READONLY, /* attributes */
2046 KFDF_PRECREATE, /* flags */
2047 &GUID_NULL /* typeid */
2049 { /* 0x37 - CSIDL_COMMON_VIDEO */
2050 &FOLDERID_PublicVideos,
2051 CSIDL_Type_AllUsers,
2052 CommonVideoW,
2053 VideosW,
2055 KF_CATEGORY_COMMON, /* category */
2056 CommonVideoW, /* name */
2057 NULL, /* description */
2058 &FOLDERID_Public, /* parent */
2059 VideosW, /* relative path */
2060 NULL, /* parsing */
2061 NULL, /* tooltip */
2062 NULL, /* localized */
2063 NULL, /* icon */
2064 NULL, /* security */
2065 FILE_ATTRIBUTE_READONLY, /* attributes */
2066 KFDF_PRECREATE, /* flags */
2067 &GUID_NULL /* typeid */
2069 { /* 0x38 - CSIDL_RESOURCES */
2070 &FOLDERID_ResourceDir,
2071 CSIDL_Type_WindowsPath,
2072 NULL,
2073 ResourcesW,
2075 KF_CATEGORY_FIXED, /* category */
2076 ResourceDirW, /* name */
2077 NULL, /* description */
2078 &GUID_NULL, /* parent */
2079 NULL, /* relative path */
2080 NULL, /* parsing */
2081 NULL, /* tooltip */
2082 NULL, /* localized */
2083 NULL, /* icon */
2084 NULL, /* security */
2085 0, /* attributes */
2086 0, /* flags */
2087 &GUID_NULL /* typeid */
2089 { /* 0x39 - CSIDL_RESOURCES_LOCALIZED */
2090 &FOLDERID_LocalizedResourcesDir,
2091 CSIDL_Type_NonExistent,
2092 NULL,
2093 NULL,
2095 KF_CATEGORY_FIXED, /* category */
2096 LocalizedResourcesDirW, /* name */
2097 NULL, /* description */
2098 &GUID_NULL, /* parent */
2099 NULL, /* relative path */
2100 NULL, /* parsing */
2101 NULL, /* tooltip */
2102 NULL, /* localized */
2103 NULL, /* icon */
2104 NULL, /* security */
2105 0, /* attributes */
2106 0, /* flags */
2107 &GUID_NULL /* typeid */
2109 { /* 0x3a - CSIDL_COMMON_OEM_LINKS */
2110 &FOLDERID_CommonOEMLinks,
2111 CSIDL_Type_AllUsers,
2112 NULL,
2113 OEM_LinksW,
2115 KF_CATEGORY_COMMON, /* category */
2116 OEM_LinksW, /* name */
2117 NULL, /* description */
2118 &FOLDERID_ProgramData, /* parent */
2119 OEM_LinksW, /* relative path */
2120 NULL, /* parsing */
2121 NULL, /* tooltip */
2122 NULL, /* localized */
2123 NULL, /* icon */
2124 NULL, /* security */
2125 0, /* attributes */
2126 0, /* flags */
2127 &GUID_NULL /* typeid */
2129 { /* 0x3b - CSIDL_CDBURN_AREA */
2130 &FOLDERID_CDBurning,
2131 CSIDL_Type_User,
2132 CD_BurningW,
2133 Local_Settings_CD_BurningW,
2135 KF_CATEGORY_PERUSER, /* category */
2136 CD_BurningW, /* name */
2137 NULL, /* description */
2138 &FOLDERID_LocalAppData, /* parent */
2139 Microsoft_Windows_Burn_BurnW, /* relative path */
2140 NULL, /* parsing */
2141 NULL, /* tooltip */
2142 NULL, /* localized */
2143 NULL, /* icon */
2144 NULL, /* security */
2145 FILE_ATTRIBUTE_READONLY, /* attributes */
2146 KFDF_LOCAL_REDIRECT_ONLY, /* flags */
2147 &GUID_NULL /* typeid */
2149 { /* 0x3c unassigned */
2150 &GUID_NULL,
2151 CSIDL_Type_Disallowed,
2152 NULL,
2153 NULL
2155 { /* 0x3d - CSIDL_COMPUTERSNEARME */
2156 &GUID_NULL,
2157 CSIDL_Type_Disallowed, /* FIXME */
2158 NULL,
2159 NULL
2161 { /* 0x3e - CSIDL_PROFILES */
2162 &GUID_NULL,
2163 CSIDL_Type_Disallowed, /* oddly, this matches WinXP */
2164 NULL,
2165 NULL
2167 { /* 0x3f */
2168 &FOLDERID_AddNewPrograms,
2169 CSIDL_Type_Disallowed,
2170 NULL,
2171 NULL,
2173 KF_CATEGORY_VIRTUAL, /* category */
2174 AddNewProgramsFolderW, /* name */
2175 NULL, /* description */
2176 &GUID_NULL, /* parent */
2177 NULL, /* relative path */
2178 AddNewProgramsParsingNameW, /* parsing */
2179 NULL, /* tooltip */
2180 NULL, /* localized */
2181 NULL, /* icon */
2182 NULL, /* security */
2183 0, /* attributes */
2184 0, /* flags */
2185 &GUID_NULL /* typeid */
2187 { /* 0x40 */
2188 &FOLDERID_AppUpdates,
2189 CSIDL_Type_Disallowed,
2190 NULL,
2191 NULL,
2193 KF_CATEGORY_VIRTUAL, /* category */
2194 AppUpdatesFolderW, /* name */
2195 NULL, /* description */
2196 &GUID_NULL, /* parent */
2197 NULL, /* relative path */
2198 AppUpdatesParsingNameW, /* parsing */
2199 NULL, /* tooltip */
2200 NULL, /* localized */
2201 NULL, /* icon */
2202 NULL, /* security */
2203 0, /* attributes */
2204 0, /* flags */
2205 &GUID_NULL /* typeid */
2207 { /* 0x41 */
2208 &FOLDERID_ChangeRemovePrograms,
2209 CSIDL_Type_Disallowed,
2210 NULL,
2211 NULL,
2213 KF_CATEGORY_VIRTUAL, /* category */
2214 ChangeRemoveProgramsFolderW, /* name */
2215 NULL, /* description */
2216 &GUID_NULL, /* parent */
2217 NULL, /* relative path */
2218 ChangeRemoveProgramsParsingNameW, /* parsing */
2219 NULL, /* tooltip */
2220 NULL, /* localized */
2221 NULL, /* icon */
2222 NULL, /* security */
2223 0, /* attributes */
2224 0, /* flags */
2225 &GUID_NULL /* typeid */
2227 { /* 0x42 */
2228 &FOLDERID_ConflictFolder,
2229 CSIDL_Type_Disallowed,
2230 NULL,
2231 NULL,
2233 KF_CATEGORY_VIRTUAL, /* category */
2234 ConflictFolderW, /* name */
2235 NULL, /* description */
2236 &GUID_NULL, /* parent */
2237 NULL, /* relative path */
2238 ConflictFolderParsingNameW, /* parsing */
2239 NULL, /* tooltip */
2240 NULL, /* localized */
2241 NULL, /* icon */
2242 NULL, /* security */
2243 0, /* attributes */
2244 0, /* flags */
2245 &GUID_NULL /* typeid */
2247 { /* 0x43 - CSIDL_CONTACTS */
2248 &FOLDERID_Contacts,
2249 CSIDL_Type_User,
2250 NULL,
2251 ContactsW,
2253 KF_CATEGORY_PERUSER, /* category */
2254 ContactsW, /* name */
2255 NULL, /* description */
2256 &FOLDERID_Profile, /* parent */
2257 ContactsW, /* relative path */
2258 ContactsParsingNameW, /* parsing */
2259 NULL, /* tooltip */
2260 NULL, /* localized */
2261 NULL, /* icon */
2262 NULL, /* security */
2263 FILE_ATTRIBUTE_READONLY, /* attributes */
2264 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH, /* flags */
2265 &GUID_NULL /* typeid */
2267 { /* 0x44 */
2268 &FOLDERID_DeviceMetadataStore,
2269 CSIDL_Type_Disallowed, /* FIXME */
2270 NULL,
2271 NULL,
2273 KF_CATEGORY_COMMON, /* category */
2274 Device_Metadata_StoreW, /* name */
2275 NULL, /* description */
2276 &FOLDERID_ProgramData, /* parent */
2277 Microsoft_Windows_DeviceMetadataStoreW, /* relative path */
2278 NULL, /* parsing */
2279 NULL, /* tooltip */
2280 NULL, /* localized */
2281 NULL, /* icon */
2282 NULL, /* security */
2283 0, /* attributes */
2284 0, /* flags */
2285 &GUID_NULL /* typeid */
2287 { /* 0x45 */
2288 &GUID_NULL,
2289 CSIDL_Type_User,
2290 NULL,
2291 DocumentsW
2293 { /* 0x46 */
2294 &FOLDERID_DocumentsLibrary,
2295 CSIDL_Type_Disallowed, /* FIXME */
2296 NULL,
2297 NULL,
2299 KF_CATEGORY_PERUSER, /* category */
2300 DocumentsLibraryW, /* name */
2301 NULL, /* description */
2302 &FOLDERID_Libraries, /* parent */
2303 Documents_librarymsW, /* relative path */
2304 DocumentsLibraryParsingNameW, /* parsing */
2305 NULL, /* tooltip */
2306 NULL, /* localized */
2307 NULL, /* icon */
2308 NULL, /* security */
2309 0, /* attributes */
2310 KFDF_PRECREATE | KFDF_STREAM, /* flags */
2311 &GUID_NULL /* typeid */
2313 { /* 0x47 - CSIDL_DOWNLOADS */
2314 &FOLDERID_Downloads,
2315 CSIDL_Type_User,
2316 NULL,
2317 DownloadsW,
2319 KF_CATEGORY_PERUSER, /* category */
2320 DownloadsW, /* name */
2321 NULL, /* description */
2322 &FOLDERID_Profile, /* parent */
2323 DownloadsW, /* relative path */
2324 NULL, /* parsing */
2325 NULL, /* tooltip */
2326 NULL, /* localized */
2327 NULL, /* icon */
2328 NULL, /* security */
2329 FILE_ATTRIBUTE_READONLY, /* attributes */
2330 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH, /* flags */
2331 &GUID_NULL /* typeid */
2333 { /* 0x48 */
2334 &FOLDERID_Games,
2335 CSIDL_Type_Disallowed,
2336 NULL,
2337 NULL,
2339 KF_CATEGORY_VIRTUAL, /* category */
2340 GamesW, /* name */
2341 NULL, /* description */
2342 &GUID_NULL, /* parent */
2343 NULL, /* relative path */
2344 GamesParsingNameW, /* parsing */
2345 NULL, /* tooltip */
2346 NULL, /* localized */
2347 NULL, /* icon */
2348 NULL, /* security */
2349 0, /* attributes */
2350 0, /* flags */
2351 &GUID_NULL /* typeid */
2353 { /* 0x49 */
2354 &FOLDERID_GameTasks,
2355 CSIDL_Type_Disallowed, /* FIXME */
2356 NULL,
2357 NULL,
2359 KF_CATEGORY_PERUSER, /* category */
2360 GameTasksW, /* name */
2361 NULL, /* description */
2362 &FOLDERID_LocalAppData, /* parent */
2363 Microsoft_Windows_GameExplorerW, /* relative path */
2364 NULL, /* parsing */
2365 NULL, /* tooltip */
2366 NULL, /* localized */
2367 NULL, /* icon */
2368 NULL, /* security */
2369 0, /* attributes */
2370 KFDF_LOCAL_REDIRECT_ONLY, /* flags */
2371 &GUID_NULL /* typeid */
2373 { /* 0x4a */
2374 &FOLDERID_HomeGroup,
2375 CSIDL_Type_Disallowed,
2376 NULL,
2377 NULL,
2379 KF_CATEGORY_VIRTUAL, /* category */
2380 HomeGroupFolderW, /* name */
2381 NULL, /* description */
2382 &GUID_NULL, /* parent */
2383 NULL, /* relative path */
2384 HomeGroupParsingNameW, /* parsing */
2385 NULL, /* tooltip */
2386 NULL, /* localized */
2387 NULL, /* icon */
2388 NULL, /* security */
2389 0, /* attributes */
2390 0, /* flags */
2391 &GUID_NULL /* typeid */
2393 { /* 0x4b */
2394 &FOLDERID_ImplicitAppShortcuts,
2395 CSIDL_Type_Disallowed, /* FIXME */
2396 NULL,
2397 NULL,
2399 KF_CATEGORY_PERUSER, /* category */
2400 ImplicitAppShortcutsW, /* name */
2401 NULL, /* description */
2402 &FOLDERID_UserPinned, /* parent */
2403 ImplicitAppShortcutsW, /* relative path */
2404 NULL, /* parsing */
2405 NULL, /* tooltip */
2406 NULL, /* localized */
2407 NULL, /* icon */
2408 NULL, /* security */
2409 0, /* attributes */
2410 KFDF_PRECREATE, /* flags */
2411 &GUID_NULL /* typeid */
2413 { /* 0x4c */
2414 &FOLDERID_Libraries,
2415 CSIDL_Type_Disallowed, /* FIXME */
2416 NULL,
2417 NULL,
2419 KF_CATEGORY_PERUSER, /* category */
2420 LibrariesW, /* name */
2421 NULL, /* description */
2422 &FOLDERID_RoamingAppData, /* parent */
2423 Microsoft_Windows_LibrariesW, /* relative path */
2424 NULL, /* parsing */
2425 NULL, /* tooltip */
2426 NULL, /* localized */
2427 NULL, /* icon */
2428 NULL, /* security */
2429 0, /* attributes */
2430 KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH, /* flags */
2431 &GUID_NULL /* typeid */
2433 { /* 0x4d - CSIDL_LINKS */
2434 &FOLDERID_Links,
2435 CSIDL_Type_User,
2436 NULL,
2437 LinksW,
2439 KF_CATEGORY_PERUSER, /* category */
2440 LinksW, /* name */
2441 NULL, /* description */
2442 &FOLDERID_Profile, /* parent */
2443 LinksW, /* relative path */
2444 LinksParsingNameW, /* parsing */
2445 NULL, /* tooltip */
2446 NULL, /* localized */
2447 NULL, /* icon */
2448 NULL, /* security */
2449 FILE_ATTRIBUTE_READONLY, /* attributes */
2450 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH, /* flags */
2451 &GUID_NULL /* typeid */
2453 { /* 0x4e - CSIDL_APPDATA_LOCALLOW */
2454 &FOLDERID_LocalAppDataLow,
2455 CSIDL_Type_User,
2456 NULL,
2457 AppData_LocalLowW,
2459 KF_CATEGORY_PERUSER, /* category */
2460 LocalAppDataLowW, /* name */
2461 NULL, /* description */
2462 &FOLDERID_Profile, /* parent */
2463 AppData_LocalLowW, /* relative path */
2464 NULL, /* parsing */
2465 NULL, /* tooltip */
2466 NULL, /* localized */
2467 NULL, /* icon */
2468 NULL, /* security */
2469 FILE_ATTRIBUTE_NOT_CONTENT_INDEXED, /* attributes */
2470 KFDF_LOCAL_REDIRECT_ONLY | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH, /* flags */
2471 &GUID_NULL /* typeid */
2473 { /* 0x4f */
2474 &FOLDERID_MusicLibrary,
2475 CSIDL_Type_Disallowed, /* FIXME */
2476 NULL,
2477 NULL,
2479 KF_CATEGORY_PERUSER, /* category */
2480 MusicLibraryW, /* name */
2481 NULL, /* description */
2482 &FOLDERID_Libraries, /* parent */
2483 Music_librarymsW, /* relative path */
2484 MusicLibraryParsingNameW, /* parsing */
2485 NULL, /* tooltip */
2486 NULL, /* localized */
2487 NULL, /* icon */
2488 NULL, /* security */
2489 0, /* attributes */
2490 KFDF_PRECREATE | KFDF_STREAM, /* flags */
2491 &GUID_NULL /* typeid */
2493 { /* 0x50 */
2494 &FOLDERID_OriginalImages,
2495 CSIDL_Type_Disallowed, /* FIXME */
2496 NULL,
2497 NULL,
2499 KF_CATEGORY_PERUSER, /* category */
2500 Original_ImagesW, /* name */
2501 NULL, /* description */
2502 &FOLDERID_LocalAppData, /* parent */
2503 Microsoft_Windows_Photo_Gallery_Original_ImagesW, /* relative path */
2504 NULL, /* parsing */
2505 NULL, /* tooltip */
2506 NULL, /* localized */
2507 NULL, /* icon */
2508 NULL, /* security */
2509 0, /* attributes */
2510 0, /* flags */
2511 &GUID_NULL /* typeid */
2513 { /* 0x51 */
2514 &FOLDERID_PhotoAlbums,
2515 CSIDL_Type_User,
2516 NULL,
2517 Pictures_Slide_ShowsW,
2519 KF_CATEGORY_PERUSER, /* category */
2520 PhotoAlbumsW, /* name */
2521 NULL, /* description */
2522 &FOLDERID_Pictures, /* parent */
2523 Slide_ShowsW, /* relative path */
2524 NULL, /* parsing */
2525 NULL, /* tooltip */
2526 NULL, /* localized */
2527 NULL, /* icon */
2528 NULL, /* security */
2529 FILE_ATTRIBUTE_READONLY, /* attributes */
2530 0, /* flags */
2531 &GUID_NULL /* typeid */
2533 { /* 0x52 */
2534 &FOLDERID_PicturesLibrary,
2535 CSIDL_Type_Disallowed, /* FIXME */
2536 NULL,
2537 NULL,
2539 KF_CATEGORY_PERUSER, /* category */
2540 PicturesLibraryW, /* name */
2541 NULL, /* description */
2542 &FOLDERID_Libraries, /* parent */
2543 Pictures_librarymsW, /* relative path */
2544 PicturesLibraryParsingNameW, /* parsing */
2545 NULL, /* tooltip */
2546 NULL, /* localized */
2547 NULL, /* icon */
2548 NULL, /* security */
2549 0, /* attributes */
2550 KFDF_PRECREATE | KFDF_STREAM, /* flags */
2551 &GUID_NULL /* typeid */
2553 { /* 0x53 */
2554 &FOLDERID_Playlists,
2555 CSIDL_Type_User,
2556 NULL,
2557 Music_PlaylistsW,
2559 KF_CATEGORY_PERUSER, /* category */
2560 PlaylistsW, /* name */
2561 NULL, /* description */
2562 &FOLDERID_Music, /* parent */
2563 PlaylistsW, /* relative path */
2564 NULL, /* parsing */
2565 NULL, /* tooltip */
2566 NULL, /* localized */
2567 NULL, /* icon */
2568 NULL, /* security */
2569 FILE_ATTRIBUTE_READONLY, /* attributes */
2570 0, /* flags */
2571 &GUID_NULL /* typeid */
2573 { /* 0x54 */
2574 &FOLDERID_ProgramFilesX64,
2575 CSIDL_Type_NonExistent,
2576 NULL,
2577 NULL,
2579 KF_CATEGORY_FIXED, /* category */
2580 ProgramFilesX64W, /* name */
2581 NULL, /* description */
2582 &GUID_NULL, /* parent */
2583 NULL, /* relative path */
2584 NULL, /* parsing */
2585 NULL, /* tooltip */
2586 NULL, /* localized */
2587 NULL, /* icon */
2588 NULL, /* security */
2589 0, /* attributes */
2590 0, /* flags */
2591 &GUID_NULL /* typeid */
2593 { /* 0x55 */
2594 &FOLDERID_ProgramFilesCommonX64,
2595 CSIDL_Type_NonExistent,
2596 NULL,
2597 NULL,
2599 KF_CATEGORY_FIXED, /* category */
2600 ProgramFilesCommonX64W, /* name */
2601 NULL, /* description */
2602 &GUID_NULL, /* parent */
2603 NULL, /* relative path */
2604 NULL, /* parsing */
2605 NULL, /* tooltip */
2606 NULL, /* localized */
2607 NULL, /* icon */
2608 NULL, /* security */
2609 0, /* attributes */
2610 0, /* flags */
2611 &GUID_NULL /* typeid */
2613 { /* 0x56 */
2614 &FOLDERID_Public,
2615 CSIDL_Type_CurrVer, /* FIXME */
2616 NULL,
2617 UsersPublicW,
2619 KF_CATEGORY_FIXED, /* category */
2620 PublicW, /* name */
2621 NULL, /* description */
2622 &GUID_NULL, /* parent */
2623 NULL, /* relative path */
2624 PublicParsingNameW, /* parsing */
2625 NULL, /* tooltip */
2626 NULL, /* localized */
2627 NULL, /* icon */
2628 NULL, /* security */
2629 FILE_ATTRIBUTE_READONLY, /* attributes */
2630 KFDF_PRECREATE, /* flags */
2631 &GUID_NULL /* typeid */
2633 { /* 0x57 */
2634 &FOLDERID_PublicDownloads,
2635 CSIDL_Type_AllUsers,
2636 NULL,
2637 DownloadsW,
2639 KF_CATEGORY_COMMON, /* category */
2640 CommonDownloadsW, /* name */
2641 NULL, /* description */
2642 &FOLDERID_Public, /* parent */
2643 DownloadsW, /* relative path */
2644 NULL, /* parsing */
2645 NULL, /* tooltip */
2646 NULL, /* localized */
2647 NULL, /* icon */
2648 NULL, /* security */
2649 FILE_ATTRIBUTE_READONLY, /* attributes */
2650 KFDF_PRECREATE, /* flags */
2651 &GUID_NULL /* typeid */
2653 { /* 0x58 */
2654 &FOLDERID_PublicGameTasks,
2655 CSIDL_Type_AllUsers,
2656 NULL,
2657 Microsoft_Windows_GameExplorerW,
2659 KF_CATEGORY_COMMON, /* category */
2660 PublicGameTasksW, /* name */
2661 NULL, /* description */
2662 &FOLDERID_ProgramData, /* parent */
2663 Microsoft_Windows_GameExplorerW, /* relative path */
2664 NULL, /* parsing */
2665 NULL, /* tooltip */
2666 NULL, /* localized */
2667 NULL, /* icon */
2668 NULL, /* security */
2669 0, /* attributes */
2670 KFDF_LOCAL_REDIRECT_ONLY, /* flags */
2671 &GUID_NULL /* typeid */
2673 { /* 0x59 */
2674 &FOLDERID_PublicLibraries,
2675 CSIDL_Type_AllUsers,
2676 NULL,
2677 Microsoft_Windows_LibrariesW,
2679 KF_CATEGORY_COMMON, /* category */
2680 PublicLibrariesW, /* name */
2681 NULL, /* description */
2682 &FOLDERID_Public, /* parent */
2683 LibrariesW, /* relative path */
2684 NULL, /* parsing */
2685 NULL, /* tooltip */
2686 NULL, /* localized */
2687 NULL, /* icon */
2688 NULL, /* security */
2689 FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN, /* attributes */
2690 KFDF_PRECREATE, /* flags */
2691 &GUID_NULL /* typeid */
2693 { /* 0x5a */
2694 &FOLDERID_PublicRingtones,
2695 CSIDL_Type_AllUsers,
2696 NULL,
2697 Microsoft_Windows_RingtonesW,
2699 KF_CATEGORY_COMMON, /* category */
2700 CommonRingtonesW, /* name */
2701 NULL, /* description */
2702 &FOLDERID_ProgramData, /* parent */
2703 Microsoft_Windows_RingtonesW, /* relative path */
2704 NULL, /* parsing */
2705 NULL, /* tooltip */
2706 NULL, /* localized */
2707 NULL, /* icon */
2708 NULL, /* security */
2709 0, /* attributes */
2710 KFDF_PRECREATE, /* flags */
2711 &GUID_NULL /* typeid */
2713 { /* 0x5b */
2714 &FOLDERID_QuickLaunch,
2715 CSIDL_Type_Disallowed, /* FIXME */
2716 NULL,
2717 NULL,
2719 KF_CATEGORY_PERUSER, /* category */
2720 Quick_LaunchW, /* name */
2721 NULL, /* description */
2722 &FOLDERID_RoamingAppData, /* parent */
2723 Microsoft_Internet_Explorer_Quick_LaunchW, /* relative path */
2724 NULL, /* parsing */
2725 NULL, /* tooltip */
2726 NULL, /* localized */
2727 NULL, /* icon */
2728 NULL, /* security */
2729 0, /* attributes */
2730 0, /* flags */
2731 &GUID_NULL /* typeid */
2733 { /* 0x5c */
2734 &FOLDERID_RecordedTVLibrary,
2735 CSIDL_Type_Disallowed, /* FIXME */
2736 NULL,
2737 NULL,
2739 KF_CATEGORY_COMMON, /* category */
2740 RecordedTVLibraryW, /* name */
2741 NULL, /* description */
2742 &FOLDERID_PublicLibraries, /* parent */
2743 RecordedTV_librarymsW, /* relative path */
2744 NULL, /* parsing */
2745 NULL, /* tooltip */
2746 NULL, /* localized */
2747 NULL, /* icon */
2748 NULL, /* security */
2749 0, /* attributes */
2750 KFDF_PRECREATE | KFDF_STREAM, /* flags */
2751 &GUID_NULL /* typeid */
2753 { /* 0x5d */
2754 &FOLDERID_Ringtones,
2755 CSIDL_Type_Disallowed, /* FIXME */
2756 NULL,
2757 NULL,
2759 KF_CATEGORY_PERUSER, /* category */
2760 RingtonesW, /* name */
2761 NULL, /* description */
2762 &FOLDERID_LocalAppData, /* parent */
2763 Microsoft_Windows_RingtonesW, /* relative path */
2764 NULL, /* parsing */
2765 NULL, /* tooltip */
2766 NULL, /* localized */
2767 NULL, /* icon */
2768 NULL, /* security */
2769 0, /* attributes */
2770 KFDF_PRECREATE, /* flags */
2771 &GUID_NULL /* typeid */
2773 { /* 0x5e */
2774 &FOLDERID_SampleMusic,
2775 CSIDL_Type_AllUsers,
2776 NULL,
2777 Music_Sample_MusicW,
2779 KF_CATEGORY_COMMON, /* category */
2780 SampleMusicW, /* name */
2781 NULL, /* description */
2782 &FOLDERID_PublicMusic, /* parent */
2783 Sample_MusicW, /* relative path */
2784 NULL, /* parsing */
2785 NULL, /* tooltip */
2786 NULL, /* localized */
2787 NULL, /* icon */
2788 NULL, /* security */
2789 FILE_ATTRIBUTE_READONLY, /* attributes */
2790 KFDF_PRECREATE, /* flags */
2791 &GUID_NULL /* typeid */
2793 { /* 0x5f */
2794 &FOLDERID_SamplePictures,
2795 CSIDL_Type_AllUsers,
2796 NULL,
2797 Pictures_Sample_PicturesW,
2799 KF_CATEGORY_COMMON, /* category */
2800 SamplePicturesW, /* name */
2801 NULL, /* description */
2802 &FOLDERID_PublicPictures, /* parent */
2803 Sample_PicturesW, /* relative path */
2804 NULL, /* parsing */
2805 NULL, /* tooltip */
2806 NULL, /* localized */
2807 NULL, /* icon */
2808 NULL, /* security */
2809 FILE_ATTRIBUTE_READONLY, /* attributes */
2810 KFDF_PRECREATE, /* flags */
2811 &GUID_NULL /* typeid */
2813 { /* 0x60 */
2814 &FOLDERID_SamplePlaylists,
2815 CSIDL_Type_AllUsers,
2816 NULL,
2817 Music_Sample_PlaylistsW,
2819 KF_CATEGORY_COMMON, /* category */
2820 SamplePlaylistsW, /* name */
2821 NULL, /* description */
2822 &FOLDERID_PublicMusic, /* parent */
2823 Sample_PlaylistsW, /* relative path */
2824 NULL, /* parsing */
2825 NULL, /* tooltip */
2826 NULL, /* localized */
2827 NULL, /* icon */
2828 NULL, /* security */
2829 FILE_ATTRIBUTE_READONLY, /* attributes */
2830 KFDF_PRECREATE, /* flags */
2831 &GUID_NULL /* typeid */
2833 { /* 0x61 */
2834 &FOLDERID_SampleVideos,
2835 CSIDL_Type_AllUsers,
2836 NULL,
2837 Videos_Sample_VideosW,
2839 KF_CATEGORY_COMMON, /* category */
2840 SampleVideosW, /* name */
2841 NULL, /* description */
2842 &FOLDERID_PublicVideos, /* parent */
2843 Sample_VideosW, /* relative path */
2844 NULL, /* parsing */
2845 NULL, /* tooltip */
2846 NULL, /* localized */
2847 NULL, /* icon */
2848 NULL, /* security */
2849 FILE_ATTRIBUTE_READONLY, /* attributes */
2850 KFDF_PRECREATE, /* flags */
2851 &GUID_NULL /* typeid */
2853 { /* 0x62 - CSIDL_SAVED_GAMES */
2854 &FOLDERID_SavedGames,
2855 CSIDL_Type_User,
2856 NULL,
2857 Saved_GamesW,
2859 KF_CATEGORY_PERUSER, /* category */
2860 SavedGamesW, /* name */
2861 NULL, /* description */
2862 &FOLDERID_Profile, /* parent */
2863 Saved_GamesW, /* relative path */
2864 SavedGamesParsingNameW, /* parsing */
2865 NULL, /* tooltip */
2866 NULL, /* localized */
2867 NULL, /* icon */
2868 NULL, /* security */
2869 FILE_ATTRIBUTE_READONLY, /* attributes */
2870 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH, /* flags */
2871 &GUID_NULL /* typeid */
2873 { /* 0x63 - CSIDL_SEARCHES */
2874 &FOLDERID_SavedSearches,
2875 CSIDL_Type_User,
2876 NULL,
2877 SearchesW,
2879 KF_CATEGORY_PERUSER, /* category */
2880 SearchesW, /* name */
2881 NULL, /* description */
2882 &FOLDERID_Profile, /* parent */
2883 SearchesW, /* relative path */
2884 SavedSearchesParsingNameW, /* parsing */
2885 NULL, /* tooltip */
2886 NULL, /* localized */
2887 NULL, /* icon */
2888 NULL, /* security */
2889 FILE_ATTRIBUTE_READONLY, /* attributes */
2890 KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH, /* flags */
2891 &GUID_NULL /* typeid */
2893 { /* 0x64 */
2894 &FOLDERID_SEARCH_CSC,
2895 CSIDL_Type_Disallowed,
2896 NULL,
2897 NULL,
2899 KF_CATEGORY_VIRTUAL, /* category */
2900 CSCFolderW, /* name */
2901 NULL, /* description */
2902 &GUID_NULL, /* parent */
2903 NULL, /* relative path */
2904 SEARCH_CSCParsingNameW, /* parsing */
2905 NULL, /* tooltip */
2906 NULL, /* localized */
2907 NULL, /* icon */
2908 NULL, /* security */
2909 0, /* attributes */
2910 0, /* flags */
2911 &GUID_NULL /* typeid */
2913 { /* 0x65 */
2914 &FOLDERID_SEARCH_MAPI,
2915 CSIDL_Type_Disallowed,
2916 NULL,
2917 NULL,
2919 KF_CATEGORY_VIRTUAL, /* category */
2920 MAPIFolderW, /* name */
2921 NULL, /* description */
2922 &GUID_NULL, /* parent */
2923 NULL, /* relative path */
2924 SEARCH_MAPIParsingNameW, /* parsing */
2925 NULL, /* tooltip */
2926 NULL, /* localized */
2927 NULL, /* icon */
2928 NULL, /* security */
2929 0, /* attributes */
2930 0, /* flags */
2931 &GUID_NULL /* typeid */
2933 { /* 0x66 */
2934 &FOLDERID_SearchHome,
2935 CSIDL_Type_Disallowed,
2936 NULL,
2937 NULL,
2939 KF_CATEGORY_VIRTUAL, /* category */
2940 SearchHomeFolderW, /* name */
2941 NULL, /* description */
2942 &GUID_NULL, /* parent */
2943 NULL, /* relative path */
2944 SearchHomeParsingNameW, /* parsing */
2945 NULL, /* tooltip */
2946 NULL, /* localized */
2947 NULL, /* icon */
2948 NULL, /* security */
2949 0, /* attributes */
2950 0, /* flags */
2951 &GUID_NULL /* typeid */
2953 { /* 0x67 */
2954 &FOLDERID_SidebarDefaultParts,
2955 CSIDL_Type_Disallowed, /* FIXME */
2956 NULL,
2957 NULL,
2959 KF_CATEGORY_COMMON, /* category */
2960 Default_GadgetsW, /* name */
2961 NULL, /* description */
2962 &FOLDERID_ProgramFiles, /* parent */
2963 Windows_Sidebar_GadgetsW, /* relative path */
2964 NULL, /* parsing */
2965 NULL, /* tooltip */
2966 NULL, /* localized */
2967 NULL, /* icon */
2968 NULL, /* security */
2969 0, /* attributes */
2970 0, /* flags */
2971 &GUID_NULL /* typeid */
2973 { /* 0x68 */
2974 &FOLDERID_SidebarParts,
2975 CSIDL_Type_Disallowed, /* FIXME */
2976 NULL,
2977 NULL,
2979 KF_CATEGORY_PERUSER, /* category */
2980 GadgetsW, /* name */
2981 NULL, /* description */
2982 &FOLDERID_LocalAppData, /* parent */
2983 Microsoft_Windows_Sidebar_GadgetsW, /* relative path */
2984 NULL, /* parsing */
2985 NULL, /* tooltip */
2986 NULL, /* localized */
2987 NULL, /* icon */
2988 NULL, /* security */
2989 0, /* attributes */
2990 0, /* flags */
2991 &GUID_NULL /* typeid */
2993 { /* 0x69 */
2994 &FOLDERID_SyncManagerFolder,
2995 CSIDL_Type_Disallowed,
2996 NULL,
2997 NULL,
2999 KF_CATEGORY_VIRTUAL, /* category */
3000 SyncCenterFolderW, /* name */
3001 NULL, /* description */
3002 &GUID_NULL, /* parent */
3003 NULL, /* relative path */
3004 SyncManagerFolderParsingNameW, /* parsing */
3005 NULL, /* tooltip */
3006 NULL, /* localized */
3007 NULL, /* icon */
3008 NULL, /* security */
3009 0, /* attributes */
3010 0, /* flags */
3011 &GUID_NULL /* typeid */
3013 { /* 0x6a */
3014 &FOLDERID_SyncResultsFolder,
3015 CSIDL_Type_Disallowed,
3016 NULL,
3017 NULL,
3019 KF_CATEGORY_VIRTUAL, /* category */
3020 SyncResultsFolderW, /* name */
3021 NULL, /* description */
3022 &GUID_NULL, /* parent */
3023 NULL, /* relative path */
3024 SyncResultsFolderParsingNameW, /* parsing */
3025 NULL, /* tooltip */
3026 NULL, /* localized */
3027 NULL, /* icon */
3028 NULL, /* security */
3029 0, /* attributes */
3030 0, /* flags */
3031 &GUID_NULL /* typeid */
3033 { /* 0x6b */
3034 &FOLDERID_SyncSetupFolder,
3035 CSIDL_Type_Disallowed,
3036 NULL,
3037 NULL,
3039 KF_CATEGORY_VIRTUAL, /* category */
3040 SyncSetupFolderW, /* name */
3041 NULL, /* description */
3042 &GUID_NULL, /* parent */
3043 NULL, /* relative path */
3044 SyncSetupFolderParsingNameW, /* parsing */
3045 NULL, /* tooltip */
3046 NULL, /* localized */
3047 NULL, /* icon */
3048 NULL, /* security */
3049 0, /* attributes */
3050 0, /* flags */
3051 &GUID_NULL /* typeid */
3053 { /* 0x6c */
3054 &FOLDERID_UserPinned,
3055 CSIDL_Type_Disallowed, /* FIXME */
3056 NULL,
3057 NULL,
3059 KF_CATEGORY_PERUSER, /* category */
3060 User_PinnedW, /* name */
3061 NULL, /* description */
3062 &FOLDERID_QuickLaunch, /* parent */
3063 User_PinnedW, /* relative path */
3064 NULL, /* parsing */
3065 NULL, /* tooltip */
3066 NULL, /* localized */
3067 NULL, /* icon */
3068 NULL, /* security */
3069 FILE_ATTRIBUTE_HIDDEN, /* attributes */
3070 KFDF_PRECREATE, /* flags */
3071 &GUID_NULL /* typeid */
3073 { /* 0x6d */
3074 &FOLDERID_UserProfiles,
3075 CSIDL_Type_CurrVer,
3076 UsersW,
3077 UsersW,
3079 KF_CATEGORY_FIXED, /* category */
3080 UserProfilesW, /* name */
3081 NULL, /* description */
3082 &GUID_NULL, /* parent */
3083 NULL, /* relative path */
3084 NULL, /* parsing */
3085 NULL, /* tooltip */
3086 NULL, /* localized */
3087 NULL, /* icon */
3088 NULL, /* security */
3089 FILE_ATTRIBUTE_READONLY, /* attributes */
3090 KFDF_PRECREATE, /* flags */
3091 &GUID_NULL /* typeid */
3093 { /* 0x6e */
3094 &FOLDERID_UserProgramFiles,
3095 CSIDL_Type_Disallowed, /* FIXME */
3096 NULL,
3097 NULL,
3099 KF_CATEGORY_PERUSER, /* category */
3100 UserProgramFilesW, /* name */
3101 NULL, /* description */
3102 &FOLDERID_LocalAppData, /* parent */
3103 ProgramsW, /* relative path */
3104 NULL, /* parsing */
3105 NULL, /* tooltip */
3106 NULL, /* localized */
3107 NULL, /* icon */
3108 NULL, /* security */
3109 0, /* attributes */
3110 0, /* flags */
3111 &GUID_NULL /* typeid */
3113 { /* 0x6f */
3114 &FOLDERID_UserProgramFilesCommon,
3115 CSIDL_Type_Disallowed, /* FIXME */
3116 NULL,
3117 NULL,
3119 KF_CATEGORY_PERUSER, /* category */
3120 UserProgramFilesCommonW, /* name */
3121 NULL, /* description */
3122 &FOLDERID_UserProgramFiles, /* parent */
3123 CommonW, /* relative path */
3124 NULL, /* parsing */
3125 NULL, /* tooltip */
3126 NULL, /* localized */
3127 NULL, /* icon */
3128 NULL, /* security */
3129 0, /* attributes */
3130 0, /* flags */
3131 &GUID_NULL /* typeid */
3133 { /* 0x70 */
3134 &FOLDERID_UsersFiles,
3135 CSIDL_Type_Disallowed,
3136 NULL,
3137 NULL,
3139 KF_CATEGORY_VIRTUAL, /* category */
3140 UsersFilesFolderW, /* name */
3141 NULL, /* description */
3142 &GUID_NULL, /* parent */
3143 NULL, /* relative path */
3144 UsersFilesParsingNameW, /* parsing */
3145 NULL, /* tooltip */
3146 NULL, /* localized */
3147 NULL, /* icon */
3148 NULL, /* security */
3149 0, /* attributes */
3150 0, /* flags */
3151 &GUID_NULL /* typeid */
3153 { /* 0x71 */
3154 &FOLDERID_UsersLibraries,
3155 CSIDL_Type_Disallowed,
3156 NULL,
3157 NULL,
3159 KF_CATEGORY_VIRTUAL, /* category */
3160 UsersLibrariesFolderW, /* name */
3161 NULL, /* description */
3162 &GUID_NULL, /* parent */
3163 NULL, /* relative path */
3164 UsersLibrariesParsingNameW, /* parsing */
3165 NULL, /* tooltip */
3166 NULL, /* localized */
3167 NULL, /* icon */
3168 NULL, /* security */
3169 0, /* attributes */
3170 0, /* flags */
3171 &GUID_NULL /* typeid */
3173 { /* 0x72 */
3174 &FOLDERID_VideosLibrary,
3175 CSIDL_Type_Disallowed, /* FIXME */
3176 NULL,
3177 NULL,
3179 KF_CATEGORY_PERUSER, /* category */
3180 VideosLibraryW, /* name */
3181 NULL, /* description */
3182 &GUID_NULL, /* parent */
3183 Videos_librarymsW, /* relative path */
3184 VideosLibraryParsingNameW, /* parsing */
3185 NULL, /* tooltip */
3186 NULL, /* localized */
3187 NULL, /* icon */
3188 NULL, /* security */
3189 0, /* attributes */
3190 0, /* flags */
3191 &GUID_NULL /* typeid */
3195 static HRESULT _SHExpandEnvironmentStrings(LPCWSTR szSrc, LPWSTR szDest);
3197 /* Gets the value named value from the registry key
3198 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
3199 * (or from rootKey\userPrefix\... if userPrefix is not NULL) into path, which
3200 * is assumed to be MAX_PATH WCHARs in length.
3201 * If it exists, expands the value and writes the expanded value to
3202 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
3203 * Returns successful error code if the value was retrieved from the registry,
3204 * and a failure otherwise.
3206 static HRESULT _SHGetUserShellFolderPath(HKEY rootKey, LPCWSTR userPrefix,
3207 LPCWSTR value, LPWSTR path)
3209 HRESULT hr;
3210 WCHAR shellFolderPath[MAX_PATH], userShellFolderPath[MAX_PATH];
3211 LPCWSTR pShellFolderPath, pUserShellFolderPath;
3212 DWORD dwType, dwPathLen = MAX_PATH;
3213 HKEY userShellFolderKey, shellFolderKey;
3215 TRACE("%p,%s,%s,%p\n",rootKey, debugstr_w(userPrefix), debugstr_w(value),
3216 path);
3218 if (userPrefix)
3220 strcpyW(shellFolderPath, userPrefix);
3221 PathAddBackslashW(shellFolderPath);
3222 strcatW(shellFolderPath, szSHFolders);
3223 pShellFolderPath = shellFolderPath;
3224 strcpyW(userShellFolderPath, userPrefix);
3225 PathAddBackslashW(userShellFolderPath);
3226 strcatW(userShellFolderPath, szSHUserFolders);
3227 pUserShellFolderPath = userShellFolderPath;
3229 else
3231 pUserShellFolderPath = szSHUserFolders;
3232 pShellFolderPath = szSHFolders;
3235 if (RegCreateKeyW(rootKey, pShellFolderPath, &shellFolderKey))
3237 TRACE("Failed to create %s\n", debugstr_w(pShellFolderPath));
3238 return E_FAIL;
3240 if (RegCreateKeyW(rootKey, pUserShellFolderPath, &userShellFolderKey))
3242 TRACE("Failed to create %s\n",
3243 debugstr_w(pUserShellFolderPath));
3244 RegCloseKey(shellFolderKey);
3245 return E_FAIL;
3248 if (!RegQueryValueExW(userShellFolderKey, value, NULL, &dwType,
3249 (LPBYTE)path, &dwPathLen) && (dwType == REG_EXPAND_SZ || dwType == REG_SZ))
3251 LONG ret;
3253 path[dwPathLen / sizeof(WCHAR)] = '\0';
3254 if (dwType == REG_EXPAND_SZ && path[0] == '%')
3256 WCHAR szTemp[MAX_PATH];
3258 _SHExpandEnvironmentStrings(path, szTemp);
3259 lstrcpynW(path, szTemp, MAX_PATH);
3261 ret = RegSetValueExW(shellFolderKey, value, 0, REG_SZ, (LPBYTE)path,
3262 (strlenW(path) + 1) * sizeof(WCHAR));
3263 if (ret != ERROR_SUCCESS)
3264 hr = HRESULT_FROM_WIN32(ret);
3265 else
3266 hr = S_OK;
3268 else
3269 hr = E_FAIL;
3270 RegCloseKey(shellFolderKey);
3271 RegCloseKey(userShellFolderKey);
3272 TRACE("returning 0x%08x\n", hr);
3273 return hr;
3276 /* Gets a 'semi-expanded' default value of the CSIDL with index folder into
3277 * pszPath, based on the entries in CSIDL_Data. By semi-expanded, I mean:
3278 * - The entry's szDefaultPath may be either a string value or an integer
3279 * resource identifier. In the latter case, the string value of the resource
3280 * is written.
3281 * - Depending on the entry's type, the path may begin with an (unexpanded)
3282 * environment variable name. The caller is responsible for expanding
3283 * environment strings if so desired.
3284 * The types that are prepended with environment variables are:
3285 * CSIDL_Type_User: %USERPROFILE%
3286 * CSIDL_Type_AllUsers: %ALLUSERSPROFILE%
3287 * CSIDL_Type_CurrVer: %SystemDrive%
3288 * (Others might make sense too, but as yet are unneeded.)
3290 static HRESULT _SHGetDefaultValue(BYTE folder, LPWSTR pszPath)
3292 HRESULT hr;
3293 WCHAR resourcePath[MAX_PATH];
3294 LPCWSTR pDefaultPath = NULL;
3296 TRACE("0x%02x,%p\n", folder, pszPath);
3298 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
3299 return E_INVALIDARG;
3300 if (!pszPath)
3301 return E_INVALIDARG;
3303 if (!is_win64)
3305 BOOL is_wow64;
3307 switch (folder)
3309 case CSIDL_PROGRAM_FILES:
3310 case CSIDL_PROGRAM_FILESX86:
3311 IsWow64Process( GetCurrentProcess(), &is_wow64 );
3312 folder = is_wow64 ? CSIDL_PROGRAM_FILESX86 : CSIDL_PROGRAM_FILES;
3313 break;
3314 case CSIDL_PROGRAM_FILES_COMMON:
3315 case CSIDL_PROGRAM_FILES_COMMONX86:
3316 IsWow64Process( GetCurrentProcess(), &is_wow64 );
3317 folder = is_wow64 ? CSIDL_PROGRAM_FILES_COMMONX86 : CSIDL_PROGRAM_FILES_COMMON;
3318 break;
3322 if (CSIDL_Data[folder].szDefaultPath &&
3323 IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath))
3325 if (LoadStringW(shell32_hInstance,
3326 LOWORD(CSIDL_Data[folder].szDefaultPath), resourcePath, MAX_PATH))
3328 hr = S_OK;
3329 pDefaultPath = resourcePath;
3331 else
3333 FIXME("(%d,%s), LoadString failed, missing translation?\n", folder,
3334 debugstr_w(pszPath));
3335 hr = E_FAIL;
3338 else
3340 hr = S_OK;
3341 pDefaultPath = CSIDL_Data[folder].szDefaultPath;
3343 if (SUCCEEDED(hr))
3345 switch (CSIDL_Data[folder].type)
3347 case CSIDL_Type_User:
3348 strcpyW(pszPath, UserProfileW);
3349 break;
3350 case CSIDL_Type_AllUsers:
3351 strcpyW(pszPath, AllUsersProfileW);
3352 break;
3353 case CSIDL_Type_CurrVer:
3354 strcpyW(pszPath, SystemDriveW);
3355 break;
3356 default:
3357 ; /* no corresponding env. var, do nothing */
3359 if (pDefaultPath)
3361 PathAddBackslashW(pszPath);
3362 strcatW(pszPath, pDefaultPath);
3365 TRACE("returning 0x%08x\n", hr);
3366 return hr;
3369 /* Gets the (unexpanded) value of the folder with index folder into pszPath.
3370 * The folder's type is assumed to be CSIDL_Type_CurrVer. Its default value
3371 * can be overridden in the HKLM\\szCurrentVersion key.
3372 * If dwFlags has SHGFP_TYPE_DEFAULT set or if the value isn't overridden in
3373 * the registry, uses _SHGetDefaultValue to get the value.
3375 static HRESULT _SHGetCurrentVersionPath(DWORD dwFlags, BYTE folder,
3376 LPWSTR pszPath)
3378 HRESULT hr;
3380 TRACE("0x%08x,0x%02x,%p\n", dwFlags, folder, pszPath);
3382 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
3383 return E_INVALIDARG;
3384 if (CSIDL_Data[folder].type != CSIDL_Type_CurrVer)
3385 return E_INVALIDARG;
3386 if (!pszPath)
3387 return E_INVALIDARG;
3389 if (dwFlags & SHGFP_TYPE_DEFAULT)
3390 hr = _SHGetDefaultValue(folder, pszPath);
3391 else
3393 HKEY hKey;
3395 if (RegCreateKeyW(HKEY_LOCAL_MACHINE, szCurrentVersion, &hKey))
3396 hr = E_FAIL;
3397 else
3399 DWORD dwType, dwPathLen = MAX_PATH * sizeof(WCHAR);
3401 if (RegQueryValueExW(hKey, CSIDL_Data[folder].szValueName, NULL,
3402 &dwType, (LPBYTE)pszPath, &dwPathLen) ||
3403 (dwType != REG_SZ && dwType != REG_EXPAND_SZ))
3405 hr = _SHGetDefaultValue(folder, pszPath);
3406 dwType = REG_EXPAND_SZ;
3407 switch (folder)
3409 case CSIDL_PROGRAM_FILESX86:
3410 case CSIDL_PROGRAM_FILES_COMMONX86:
3411 /* these two should never be set on 32-bit setups */
3412 if (!is_win64)
3414 BOOL is_wow64;
3415 IsWow64Process( GetCurrentProcess(), &is_wow64 );
3416 if (!is_wow64) break;
3418 /* fall through */
3419 default:
3420 RegSetValueExW(hKey, CSIDL_Data[folder].szValueName, 0, dwType,
3421 (LPBYTE)pszPath, (strlenW(pszPath)+1)*sizeof(WCHAR));
3424 else
3426 pszPath[dwPathLen / sizeof(WCHAR)] = '\0';
3427 hr = S_OK;
3429 RegCloseKey(hKey);
3432 TRACE("returning 0x%08x (output path is %s)\n", hr, debugstr_w(pszPath));
3433 return hr;
3436 static LPWSTR _GetUserSidStringFromToken(HANDLE Token)
3438 char InfoBuffer[64];
3439 PTOKEN_USER UserInfo;
3440 DWORD InfoSize;
3441 LPWSTR SidStr;
3443 UserInfo = (PTOKEN_USER) InfoBuffer;
3444 if (! GetTokenInformation(Token, TokenUser, InfoBuffer, sizeof(InfoBuffer),
3445 &InfoSize))
3447 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
3448 return NULL;
3449 UserInfo = HeapAlloc(GetProcessHeap(), 0, InfoSize);
3450 if (UserInfo == NULL)
3451 return NULL;
3452 if (! GetTokenInformation(Token, TokenUser, UserInfo, InfoSize,
3453 &InfoSize))
3455 HeapFree(GetProcessHeap(), 0, UserInfo);
3456 return NULL;
3460 if (! ConvertSidToStringSidW(UserInfo->User.Sid, &SidStr))
3461 SidStr = NULL;
3463 if (UserInfo != (PTOKEN_USER) InfoBuffer)
3464 HeapFree(GetProcessHeap(), 0, UserInfo);
3466 return SidStr;
3469 /* Gets the user's path (unexpanded) for the CSIDL with index folder:
3470 * If SHGFP_TYPE_DEFAULT is set, calls _SHGetDefaultValue for it. Otherwise
3471 * calls _SHGetUserShellFolderPath for it. Where it looks depends on hToken:
3472 * - if hToken is -1, looks in HKEY_USERS\.Default
3473 * - otherwise looks first in HKEY_CURRENT_USER, followed by HKEY_LOCAL_MACHINE
3474 * if HKEY_CURRENT_USER doesn't contain any entries. If both fail, finally
3475 * calls _SHGetDefaultValue for it.
3477 static HRESULT _SHGetUserProfilePath(HANDLE hToken, DWORD dwFlags, BYTE folder,
3478 LPWSTR pszPath)
3480 const WCHAR *szValueName;
3481 WCHAR buffer[40];
3482 HRESULT hr;
3484 TRACE("%p,0x%08x,0x%02x,%p\n", hToken, dwFlags, folder, pszPath);
3486 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
3487 return E_INVALIDARG;
3488 if (CSIDL_Data[folder].type != CSIDL_Type_User)
3489 return E_INVALIDARG;
3490 if (!pszPath)
3491 return E_INVALIDARG;
3493 if (dwFlags & SHGFP_TYPE_DEFAULT)
3495 if (hToken != NULL && hToken != (HANDLE)-1)
3497 FIXME("unsupported for user other than current or default\n");
3498 return E_FAIL;
3500 hr = _SHGetDefaultValue(folder, pszPath);
3502 else
3504 LPCWSTR userPrefix = NULL;
3505 HKEY hRootKey;
3507 if (hToken == (HANDLE)-1)
3509 hRootKey = HKEY_USERS;
3510 userPrefix = DefaultW;
3512 else if (hToken == NULL)
3513 hRootKey = HKEY_CURRENT_USER;
3514 else
3516 hRootKey = HKEY_USERS;
3517 userPrefix = _GetUserSidStringFromToken(hToken);
3518 if (userPrefix == NULL)
3520 hr = E_FAIL;
3521 goto error;
3525 /* For CSIDL_Type_User we also use the GUID if no szValueName is provided */
3526 szValueName = CSIDL_Data[folder].szValueName;
3527 if (!szValueName)
3529 StringFromGUID2( CSIDL_Data[folder].id, buffer, 39 );
3530 szValueName = &buffer[0];
3533 hr = _SHGetUserShellFolderPath(hRootKey, userPrefix, szValueName, pszPath);
3534 if (FAILED(hr) && hRootKey != HKEY_LOCAL_MACHINE)
3535 hr = _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE, NULL, szValueName, pszPath);
3536 if (FAILED(hr))
3537 hr = _SHGetDefaultValue(folder, pszPath);
3538 if (userPrefix != NULL && userPrefix != DefaultW)
3539 LocalFree((HLOCAL) userPrefix);
3541 error:
3542 TRACE("returning 0x%08x (output path is %s)\n", hr, debugstr_w(pszPath));
3543 return hr;
3546 /* Gets the (unexpanded) path for the CSIDL with index folder. If dwFlags has
3547 * SHGFP_TYPE_DEFAULT set, calls _SHGetDefaultValue. Otherwise calls
3548 * _SHGetUserShellFolderPath for it, looking only in HKEY_LOCAL_MACHINE.
3549 * If this fails, falls back to _SHGetDefaultValue.
3551 static HRESULT _SHGetAllUsersProfilePath(DWORD dwFlags, BYTE folder,
3552 LPWSTR pszPath)
3554 HRESULT hr;
3556 TRACE("0x%08x,0x%02x,%p\n", dwFlags, folder, pszPath);
3558 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
3559 return E_INVALIDARG;
3560 if (CSIDL_Data[folder].type != CSIDL_Type_AllUsers)
3561 return E_INVALIDARG;
3562 if (!pszPath)
3563 return E_INVALIDARG;
3565 if (dwFlags & SHGFP_TYPE_DEFAULT)
3566 hr = _SHGetDefaultValue(folder, pszPath);
3567 else
3569 hr = _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE, NULL,
3570 CSIDL_Data[folder].szValueName, pszPath);
3571 if (FAILED(hr))
3572 hr = _SHGetDefaultValue(folder, pszPath);
3574 TRACE("returning 0x%08x (output path is %s)\n", hr, debugstr_w(pszPath));
3575 return hr;
3578 static HRESULT _SHOpenProfilesKey(PHKEY pKey)
3580 LONG lRet;
3581 DWORD disp;
3583 lRet = RegCreateKeyExW(HKEY_LOCAL_MACHINE, ProfileListW, 0, NULL, 0,
3584 KEY_ALL_ACCESS, NULL, pKey, &disp);
3585 return HRESULT_FROM_WIN32(lRet);
3588 /* Reads the value named szValueName from the key profilesKey (assumed to be
3589 * opened by _SHOpenProfilesKey) into szValue, which is assumed to be MAX_PATH
3590 * WCHARs in length. If it doesn't exist, returns szDefault (and saves
3591 * szDefault to the registry).
3593 static HRESULT _SHGetProfilesValue(HKEY profilesKey, LPCWSTR szValueName,
3594 LPWSTR szValue, LPCWSTR szDefault)
3596 HRESULT hr;
3597 DWORD type, dwPathLen = MAX_PATH * sizeof(WCHAR);
3598 LONG lRet;
3600 TRACE("%p,%s,%p,%s\n", profilesKey, debugstr_w(szValueName), szValue,
3601 debugstr_w(szDefault));
3602 lRet = RegQueryValueExW(profilesKey, szValueName, NULL, &type,
3603 (LPBYTE)szValue, &dwPathLen);
3604 if (!lRet && (type == REG_SZ || type == REG_EXPAND_SZ) && dwPathLen
3605 && *szValue)
3607 dwPathLen /= sizeof(WCHAR);
3608 szValue[dwPathLen] = '\0';
3609 hr = S_OK;
3611 else
3613 /* Missing or invalid value, set a default */
3614 lstrcpynW(szValue, szDefault, MAX_PATH);
3615 TRACE("Setting missing value %s to %s\n", debugstr_w(szValueName),
3616 debugstr_w(szValue));
3617 lRet = RegSetValueExW(profilesKey, szValueName, 0, REG_EXPAND_SZ,
3618 (LPBYTE)szValue,
3619 (strlenW(szValue) + 1) * sizeof(WCHAR));
3620 if (lRet)
3621 hr = HRESULT_FROM_WIN32(lRet);
3622 else
3623 hr = S_OK;
3625 TRACE("returning 0x%08x (output value is %s)\n", hr, debugstr_w(szValue));
3626 return hr;
3629 /* Attempts to expand environment variables from szSrc into szDest, which is
3630 * assumed to be MAX_PATH characters in length. Before referring to the
3631 * environment, handles a few variables directly, because the environment
3632 * variables may not be set when this is called (as during Wine's installation
3633 * when default values are being written to the registry).
3634 * The directly handled environment variables, and their source, are:
3635 * - ALLUSERSPROFILE, USERPROFILE: reads from the registry
3636 * - SystemDrive: uses GetSystemDirectoryW and uses the drive portion of its
3637 * path
3638 * If one of the directly handled environment variables is expanded, only
3639 * expands a single variable, and only in the beginning of szSrc.
3641 static HRESULT _SHExpandEnvironmentStrings(LPCWSTR szSrc, LPWSTR szDest)
3643 HRESULT hr;
3644 WCHAR szTemp[MAX_PATH], szProfilesPrefix[MAX_PATH] = { 0 };
3645 HKEY key = NULL;
3647 TRACE("%s, %p\n", debugstr_w(szSrc), szDest);
3649 if (!szSrc || !szDest) return E_INVALIDARG;
3651 /* short-circuit if there's nothing to expand */
3652 if (szSrc[0] != '%')
3654 strcpyW(szDest, szSrc);
3655 hr = S_OK;
3656 goto end;
3658 /* Get the profile prefix, we'll probably be needing it */
3659 hr = _SHOpenProfilesKey(&key);
3660 if (SUCCEEDED(hr))
3662 WCHAR def_val[MAX_PATH];
3664 /* get the system drive */
3665 GetSystemDirectoryW(def_val, MAX_PATH);
3666 if (def_val[1] == ':') strcpyW( def_val + 3, szDefaultProfileDirW );
3667 else FIXME("non-drive system paths unsupported\n");
3669 hr = _SHGetProfilesValue(key, ProfilesDirectoryW, szProfilesPrefix, def_val );
3672 *szDest = 0;
3673 strcpyW(szTemp, szSrc);
3674 while (SUCCEEDED(hr) && szTemp[0] == '%')
3676 if (!strncmpiW(szTemp, AllUsersProfileW, strlenW(AllUsersProfileW)))
3678 WCHAR szAllUsers[MAX_PATH];
3680 strcpyW(szDest, szProfilesPrefix);
3681 hr = _SHGetProfilesValue(key, AllUsersProfileValueW,
3682 szAllUsers, AllUsersW);
3683 PathAppendW(szDest, szAllUsers);
3684 PathAppendW(szDest, szTemp + strlenW(AllUsersProfileW));
3686 else if (!strncmpiW(szTemp, UserProfileW, strlenW(UserProfileW)))
3688 WCHAR userName[MAX_PATH];
3689 DWORD userLen = MAX_PATH;
3691 strcpyW(szDest, szProfilesPrefix);
3692 GetUserNameW(userName, &userLen);
3693 PathAppendW(szDest, userName);
3694 PathAppendW(szDest, szTemp + strlenW(UserProfileW));
3696 else if (!strncmpiW(szTemp, SystemDriveW, strlenW(SystemDriveW)))
3698 GetSystemDirectoryW(szDest, MAX_PATH);
3699 if (szDest[1] != ':')
3701 FIXME("non-drive system paths unsupported\n");
3702 hr = E_FAIL;
3704 else
3706 strcpyW(szDest + 3, szTemp + strlenW(SystemDriveW) + 1);
3707 hr = S_OK;
3710 else
3712 DWORD ret = ExpandEnvironmentStringsW(szSrc, szDest, MAX_PATH);
3714 if (ret > MAX_PATH)
3715 hr = E_NOT_SUFFICIENT_BUFFER;
3716 else if (ret == 0)
3717 hr = HRESULT_FROM_WIN32(GetLastError());
3718 else
3719 hr = S_OK;
3721 if (SUCCEEDED(hr) && szDest[0] == '%')
3722 strcpyW(szTemp, szDest);
3723 else
3725 /* terminate loop */
3726 szTemp[0] = '\0';
3729 end:
3730 if (key)
3731 RegCloseKey(key);
3732 TRACE("returning 0x%08x (input was %s, output is %s)\n", hr,
3733 debugstr_w(szSrc), debugstr_w(szDest));
3734 return hr;
3737 /*************************************************************************
3738 * SHGetFolderPathW [SHELL32.@]
3740 * Convert nFolder to path.
3742 * RETURNS
3743 * Success: S_OK
3744 * Failure: standard HRESULT error codes.
3746 * NOTES
3747 * Most values can be overridden in either
3748 * HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
3749 * or in the same location in HKLM.
3750 * The "Shell Folders" registry key was used in NT4 and earlier systems.
3751 * Beginning with Windows 2000, the "User Shell Folders" key is used, so
3752 * changes made to it are made to the former key too. This synchronization is
3753 * done on-demand: not until someone requests the value of one of these paths
3754 * (by calling one of the SHGet functions) is the value synchronized.
3755 * Furthermore, the HKCU paths take precedence over the HKLM paths.
3757 HRESULT WINAPI SHGetFolderPathW(
3758 HWND hwndOwner, /* [I] owner window */
3759 int nFolder, /* [I] CSIDL identifying the folder */
3760 HANDLE hToken, /* [I] access token */
3761 DWORD dwFlags, /* [I] which path to return */
3762 LPWSTR pszPath) /* [O] converted path */
3764 HRESULT hr = SHGetFolderPathAndSubDirW(hwndOwner, nFolder, hToken, dwFlags, NULL, pszPath);
3765 if(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) == hr)
3766 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
3767 return hr;
3770 HRESULT WINAPI SHGetFolderPathAndSubDirA(
3771 HWND hwndOwner, /* [I] owner window */
3772 int nFolder, /* [I] CSIDL identifying the folder */
3773 HANDLE hToken, /* [I] access token */
3774 DWORD dwFlags, /* [I] which path to return */
3775 LPCSTR pszSubPath, /* [I] sub directory of the specified folder */
3776 LPSTR pszPath) /* [O] converted path */
3778 int length;
3779 HRESULT hr = S_OK;
3780 LPWSTR pszSubPathW = NULL;
3781 LPWSTR pszPathW = NULL;
3782 TRACE("%08x,%08x,%s\n",nFolder, dwFlags, debugstr_w(pszSubPathW));
3784 if(pszPath) {
3785 pszPathW = HeapAlloc(GetProcessHeap(), 0, MAX_PATH * sizeof(WCHAR));
3786 if(!pszPathW) {
3787 hr = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
3788 goto cleanup;
3791 TRACE("%08x,%08x,%s\n",nFolder, dwFlags, debugstr_w(pszSubPathW));
3793 /* SHGetFolderPathAndSubDirW does not distinguish if pszSubPath isn't
3794 * set (null), or an empty string.therefore call it without the parameter set
3795 * if pszSubPath is an empty string
3797 if (pszSubPath && pszSubPath[0]) {
3798 length = MultiByteToWideChar(CP_ACP, 0, pszSubPath, -1, NULL, 0);
3799 pszSubPathW = HeapAlloc(GetProcessHeap(), 0, length * sizeof(WCHAR));
3800 if(!pszSubPathW) {
3801 hr = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
3802 goto cleanup;
3804 MultiByteToWideChar(CP_ACP, 0, pszSubPath, -1, pszSubPathW, length);
3807 hr = SHGetFolderPathAndSubDirW(hwndOwner, nFolder, hToken, dwFlags, pszSubPathW, pszPathW);
3809 if (SUCCEEDED(hr) && pszPath)
3810 WideCharToMultiByte(CP_ACP, 0, pszPathW, -1, pszPath, MAX_PATH, NULL, NULL);
3812 cleanup:
3813 HeapFree(GetProcessHeap(), 0, pszPathW);
3814 HeapFree(GetProcessHeap(), 0, pszSubPathW);
3815 return hr;
3818 /*************************************************************************
3819 * SHGetFolderPathAndSubDirW [SHELL32.@]
3821 HRESULT WINAPI SHGetFolderPathAndSubDirW(
3822 HWND hwndOwner, /* [I] owner window */
3823 int nFolder, /* [I] CSIDL identifying the folder */
3824 HANDLE hToken, /* [I] access token */
3825 DWORD dwFlags, /* [I] which path to return */
3826 LPCWSTR pszSubPath,/* [I] sub directory of the specified folder */
3827 LPWSTR pszPath) /* [O] converted path */
3829 HRESULT hr;
3830 WCHAR szBuildPath[MAX_PATH], szTemp[MAX_PATH];
3831 DWORD folder = nFolder & CSIDL_FOLDER_MASK;
3832 CSIDL_Type type;
3833 int ret;
3835 TRACE("%p,%p,nFolder=0x%04x,%s\n", hwndOwner,pszPath,nFolder,debugstr_w(pszSubPath));
3837 /* Windows always NULL-terminates the resulting path regardless of success
3838 * or failure, so do so first
3840 if (pszPath)
3841 *pszPath = '\0';
3843 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
3844 return E_INVALIDARG;
3845 if ((SHGFP_TYPE_CURRENT != dwFlags) && (SHGFP_TYPE_DEFAULT != dwFlags))
3846 return E_INVALIDARG;
3847 szTemp[0] = 0;
3848 type = CSIDL_Data[folder].type;
3849 switch (type)
3851 case CSIDL_Type_Disallowed:
3852 hr = E_INVALIDARG;
3853 break;
3854 case CSIDL_Type_NonExistent:
3855 hr = S_FALSE;
3856 break;
3857 case CSIDL_Type_WindowsPath:
3858 GetWindowsDirectoryW(szTemp, MAX_PATH);
3859 if (CSIDL_Data[folder].szDefaultPath &&
3860 !IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath) &&
3861 *CSIDL_Data[folder].szDefaultPath)
3863 PathAddBackslashW(szTemp);
3864 strcatW(szTemp, CSIDL_Data[folder].szDefaultPath);
3866 hr = S_OK;
3867 break;
3868 case CSIDL_Type_SystemPath:
3869 GetSystemDirectoryW(szTemp, MAX_PATH);
3870 if (CSIDL_Data[folder].szDefaultPath &&
3871 !IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath) &&
3872 *CSIDL_Data[folder].szDefaultPath)
3874 PathAddBackslashW(szTemp);
3875 strcatW(szTemp, CSIDL_Data[folder].szDefaultPath);
3877 hr = S_OK;
3878 break;
3879 case CSIDL_Type_SystemX86Path:
3880 if (!GetSystemWow64DirectoryW(szTemp, MAX_PATH)) GetSystemDirectoryW(szTemp, MAX_PATH);
3881 if (CSIDL_Data[folder].szDefaultPath &&
3882 !IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath) &&
3883 *CSIDL_Data[folder].szDefaultPath)
3885 PathAddBackslashW(szTemp);
3886 strcatW(szTemp, CSIDL_Data[folder].szDefaultPath);
3888 hr = S_OK;
3889 break;
3890 case CSIDL_Type_CurrVer:
3891 hr = _SHGetCurrentVersionPath(dwFlags, folder, szTemp);
3892 break;
3893 case CSIDL_Type_User:
3894 hr = _SHGetUserProfilePath(hToken, dwFlags, folder, szTemp);
3895 break;
3896 case CSIDL_Type_AllUsers:
3897 hr = _SHGetAllUsersProfilePath(dwFlags, folder, szTemp);
3898 break;
3899 default:
3900 FIXME("bogus type %d, please fix\n", type);
3901 hr = E_INVALIDARG;
3902 break;
3905 /* Expand environment strings if necessary */
3906 if (*szTemp == '%')
3907 hr = _SHExpandEnvironmentStrings(szTemp, szBuildPath);
3908 else
3909 strcpyW(szBuildPath, szTemp);
3911 if (FAILED(hr)) goto end;
3913 if(pszSubPath) {
3914 /* make sure the new path does not exceed the buffer length
3915 * and remember to backslash and terminate it */
3916 if(MAX_PATH < (lstrlenW(szBuildPath) + lstrlenW(pszSubPath) + 2)) {
3917 hr = HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE);
3918 goto end;
3920 PathAppendW(szBuildPath, pszSubPath);
3921 PathRemoveBackslashW(szBuildPath);
3923 /* Copy the path if it's available before we might return */
3924 if (SUCCEEDED(hr) && pszPath)
3925 strcpyW(pszPath, szBuildPath);
3927 /* if we don't care about existing directories we are ready */
3928 if(nFolder & CSIDL_FLAG_DONT_VERIFY) goto end;
3930 if (PathFileExistsW(szBuildPath)) goto end;
3932 /* not existing but we are not allowed to create it. The return value
3933 * is verified against shell32 version 6.0.
3935 if (!(nFolder & CSIDL_FLAG_CREATE))
3937 hr = HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND);
3938 goto end;
3941 /* create directory/directories */
3942 ret = SHCreateDirectoryExW(hwndOwner, szBuildPath, NULL);
3943 if (ret && ret != ERROR_ALREADY_EXISTS)
3945 ERR("Failed to create directory %s.\n", debugstr_w(szBuildPath));
3946 hr = E_FAIL;
3947 goto end;
3950 TRACE("Created missing system directory %s\n", debugstr_w(szBuildPath));
3951 end:
3952 TRACE("returning 0x%08x (final path is %s)\n", hr, debugstr_w(szBuildPath));
3953 return hr;
3956 /*************************************************************************
3957 * SHGetFolderPathA [SHELL32.@]
3959 * See SHGetFolderPathW.
3961 HRESULT WINAPI SHGetFolderPathA(
3962 HWND hwndOwner,
3963 int nFolder,
3964 HANDLE hToken,
3965 DWORD dwFlags,
3966 LPSTR pszPath)
3968 WCHAR szTemp[MAX_PATH];
3969 HRESULT hr;
3971 TRACE("%p,%p,nFolder=0x%04x\n",hwndOwner,pszPath,nFolder);
3973 if (pszPath)
3974 *pszPath = '\0';
3975 hr = SHGetFolderPathW(hwndOwner, nFolder, hToken, dwFlags, szTemp);
3976 if (SUCCEEDED(hr) && pszPath)
3977 WideCharToMultiByte(CP_ACP, 0, szTemp, -1, pszPath, MAX_PATH, NULL,
3978 NULL);
3980 return hr;
3983 /* For each folder in folders, if its value has not been set in the registry,
3984 * calls _SHGetUserProfilePath or _SHGetAllUsersProfilePath (depending on the
3985 * folder's type) to get the unexpanded value first.
3986 * Writes the unexpanded value to User Shell Folders, and queries it with
3987 * SHGetFolderPathW to force the creation of the directory if it doesn't
3988 * already exist. SHGetFolderPathW also returns the expanded value, which
3989 * this then writes to Shell Folders.
3991 static HRESULT _SHRegisterFolders(HKEY hRootKey, HANDLE hToken,
3992 LPCWSTR szUserShellFolderPath, LPCWSTR szShellFolderPath, const UINT folders[],
3993 UINT foldersLen)
3995 const WCHAR *szValueName;
3996 WCHAR buffer[40];
3997 UINT i;
3998 WCHAR path[MAX_PATH];
3999 HRESULT hr = S_OK;
4000 HKEY hUserKey = NULL, hKey = NULL;
4001 DWORD dwType, dwPathLen;
4002 LONG ret;
4004 TRACE("%p,%p,%s,%p,%u\n", hRootKey, hToken,
4005 debugstr_w(szUserShellFolderPath), folders, foldersLen);
4007 ret = RegCreateKeyW(hRootKey, szUserShellFolderPath, &hUserKey);
4008 if (ret)
4009 hr = HRESULT_FROM_WIN32(ret);
4010 else
4012 ret = RegCreateKeyW(hRootKey, szShellFolderPath, &hKey);
4013 if (ret)
4014 hr = HRESULT_FROM_WIN32(ret);
4016 for (i = 0; SUCCEEDED(hr) && i < foldersLen; i++)
4018 dwPathLen = MAX_PATH * sizeof(WCHAR);
4020 /* For CSIDL_Type_User we also use the GUID if no szValueName is provided */
4021 szValueName = CSIDL_Data[folders[i]].szValueName;
4022 if (!szValueName && CSIDL_Data[folders[i]].type == CSIDL_Type_User)
4024 StringFromGUID2( CSIDL_Data[folders[i]].id, buffer, 39 );
4025 szValueName = &buffer[0];
4028 if (RegQueryValueExW(hUserKey, szValueName, NULL,
4029 &dwType, (LPBYTE)path, &dwPathLen) || (dwType != REG_SZ &&
4030 dwType != REG_EXPAND_SZ))
4032 *path = '\0';
4033 if (CSIDL_Data[folders[i]].type == CSIDL_Type_User)
4034 _SHGetUserProfilePath(hToken, SHGFP_TYPE_DEFAULT, folders[i],
4035 path);
4036 else if (CSIDL_Data[folders[i]].type == CSIDL_Type_AllUsers)
4037 _SHGetAllUsersProfilePath(SHGFP_TYPE_DEFAULT, folders[i], path);
4038 else if (CSIDL_Data[folders[i]].type == CSIDL_Type_WindowsPath)
4040 GetWindowsDirectoryW(path, MAX_PATH);
4041 if (CSIDL_Data[folders[i]].szDefaultPath &&
4042 !IS_INTRESOURCE(CSIDL_Data[folders[i]].szDefaultPath))
4044 PathAddBackslashW(path);
4045 strcatW(path, CSIDL_Data[folders[i]].szDefaultPath);
4048 else
4049 hr = E_FAIL;
4050 if (*path)
4052 ret = RegSetValueExW(hUserKey, szValueName, 0, REG_EXPAND_SZ,
4053 (LPBYTE)path, (strlenW(path) + 1) * sizeof(WCHAR));
4054 if (ret)
4055 hr = HRESULT_FROM_WIN32(ret);
4056 else
4058 hr = SHGetFolderPathW(NULL, folders[i] | CSIDL_FLAG_CREATE,
4059 hToken, SHGFP_TYPE_DEFAULT, path);
4060 ret = RegSetValueExW(hKey, szValueName, 0, REG_SZ,
4061 (LPBYTE)path, (strlenW(path) + 1) * sizeof(WCHAR));
4062 if (ret)
4063 hr = HRESULT_FROM_WIN32(ret);
4068 if (hUserKey)
4069 RegCloseKey(hUserKey);
4070 if (hKey)
4071 RegCloseKey(hKey);
4073 TRACE("returning 0x%08x\n", hr);
4074 return hr;
4077 static HRESULT _SHRegisterUserShellFolders(BOOL bDefault)
4079 static const UINT folders[] = {
4080 CSIDL_PROGRAMS,
4081 CSIDL_PERSONAL,
4082 CSIDL_FAVORITES,
4083 CSIDL_APPDATA,
4084 CSIDL_STARTUP,
4085 CSIDL_RECENT,
4086 CSIDL_SENDTO,
4087 CSIDL_STARTMENU,
4088 CSIDL_MYMUSIC,
4089 CSIDL_MYVIDEO,
4090 CSIDL_DESKTOPDIRECTORY,
4091 CSIDL_NETHOOD,
4092 CSIDL_TEMPLATES,
4093 CSIDL_PRINTHOOD,
4094 CSIDL_LOCAL_APPDATA,
4095 CSIDL_INTERNET_CACHE,
4096 CSIDL_COOKIES,
4097 CSIDL_HISTORY,
4098 CSIDL_MYPICTURES,
4099 CSIDL_FONTS,
4100 CSIDL_ADMINTOOLS,
4101 CSIDL_CONTACTS,
4102 CSIDL_DOWNLOADS,
4103 CSIDL_LINKS,
4104 CSIDL_APPDATA_LOCALLOW,
4105 CSIDL_SAVED_GAMES,
4106 CSIDL_SEARCHES
4108 WCHAR userShellFolderPath[MAX_PATH], shellFolderPath[MAX_PATH];
4109 LPCWSTR pUserShellFolderPath, pShellFolderPath;
4110 HRESULT hr = S_OK;
4111 HKEY hRootKey;
4112 HANDLE hToken;
4114 TRACE("%s\n", bDefault ? "TRUE" : "FALSE");
4115 if (bDefault)
4117 hToken = (HANDLE)-1;
4118 hRootKey = HKEY_USERS;
4119 strcpyW(userShellFolderPath, DefaultW);
4120 PathAddBackslashW(userShellFolderPath);
4121 strcatW(userShellFolderPath, szSHUserFolders);
4122 pUserShellFolderPath = userShellFolderPath;
4123 strcpyW(shellFolderPath, DefaultW);
4124 PathAddBackslashW(shellFolderPath);
4125 strcatW(shellFolderPath, szSHFolders);
4126 pShellFolderPath = shellFolderPath;
4128 else
4130 hToken = NULL;
4131 hRootKey = HKEY_CURRENT_USER;
4132 pUserShellFolderPath = szSHUserFolders;
4133 pShellFolderPath = szSHFolders;
4136 hr = _SHRegisterFolders(hRootKey, hToken, pUserShellFolderPath,
4137 pShellFolderPath, folders, sizeof(folders) / sizeof(folders[0]));
4138 TRACE("returning 0x%08x\n", hr);
4139 return hr;
4142 static HRESULT _SHRegisterCommonShellFolders(void)
4144 static const UINT folders[] = {
4145 CSIDL_COMMON_STARTMENU,
4146 CSIDL_COMMON_PROGRAMS,
4147 CSIDL_COMMON_STARTUP,
4148 CSIDL_COMMON_DESKTOPDIRECTORY,
4149 CSIDL_COMMON_FAVORITES,
4150 CSIDL_COMMON_APPDATA,
4151 CSIDL_COMMON_TEMPLATES,
4152 CSIDL_COMMON_DOCUMENTS,
4153 CSIDL_COMMON_ADMINTOOLS,
4154 CSIDL_COMMON_MUSIC,
4155 CSIDL_COMMON_PICTURES,
4156 CSIDL_COMMON_VIDEO,
4158 HRESULT hr;
4160 TRACE("\n");
4161 hr = _SHRegisterFolders(HKEY_LOCAL_MACHINE, NULL, szSHUserFolders,
4162 szSHFolders, folders, sizeof(folders) / sizeof(folders[0]));
4163 TRACE("returning 0x%08x\n", hr);
4164 return hr;
4167 /******************************************************************************
4168 * _SHAppendToUnixPath [Internal]
4170 * Helper function for _SHCreateSymbolicLinks. Appends pwszSubPath (or the
4171 * corresponding resource, if IS_INTRESOURCE) to the unix base path 'szBasePath'
4172 * and replaces backslashes with slashes.
4174 * PARAMS
4175 * szBasePath [IO] The unix base path, which will be appended to (CP_UNXICP).
4176 * pwszSubPath [I] Sub-path or resource id (use MAKEINTRESOURCEW).
4178 * RETURNS
4179 * Success: TRUE,
4180 * Failure: FALSE
4182 static inline BOOL _SHAppendToUnixPath(char *szBasePath, LPCWSTR pwszSubPath) {
4183 WCHAR wszSubPath[MAX_PATH];
4184 int cLen = strlen(szBasePath);
4185 char *pBackslash;
4187 if (IS_INTRESOURCE(pwszSubPath)) {
4188 if (!LoadStringW(shell32_hInstance, LOWORD(pwszSubPath), wszSubPath, MAX_PATH)) {
4189 /* Fall back to hard coded defaults. */
4190 switch (LOWORD(pwszSubPath)) {
4191 case IDS_PERSONAL:
4192 lstrcpyW(wszSubPath, DocumentsW);
4193 break;
4194 case IDS_MYMUSIC:
4195 lstrcpyW(wszSubPath, My_MusicW);
4196 break;
4197 case IDS_MYPICTURES:
4198 lstrcpyW(wszSubPath, My_PicturesW);
4199 break;
4200 case IDS_MYVIDEOS:
4201 lstrcpyW(wszSubPath, My_VideosW);
4202 break;
4203 default:
4204 ERR("LoadString(%d) failed!\n", LOWORD(pwszSubPath));
4205 return FALSE;
4208 } else {
4209 lstrcpyW(wszSubPath, pwszSubPath);
4212 if (szBasePath[cLen-1] != '/') szBasePath[cLen++] = '/';
4214 if (!WideCharToMultiByte(CP_UNIXCP, 0, wszSubPath, -1, szBasePath + cLen,
4215 FILENAME_MAX - cLen, NULL, NULL))
4217 return FALSE;
4220 pBackslash = szBasePath + cLen;
4221 while ((pBackslash = strchr(pBackslash, '\\'))) *pBackslash = '/';
4223 return TRUE;
4226 /******************************************************************************
4227 * _SHCreateSymbolicLinks [Internal]
4229 * Sets up symbol links for various shell folders to point into the users home
4230 * directory. We do an educated guess about what the user would probably want:
4231 * - If there is a 'My Documents' directory in $HOME, the user probably wants
4232 * wine's 'My Documents' to point there. Furthermore, we imply that the user
4233 * is a Windows lover and has no problem with wine creating 'My Pictures',
4234 * 'My Music' and 'My Videos' subfolders under '$HOME/My Documents', if those
4235 * do not already exits. We put appropriate symbolic links in place for those,
4236 * too.
4237 * - If there is no 'My Documents' directory in $HOME, we let 'My Documents'
4238 * point directly to $HOME. We assume the user to be a unix hacker who does not
4239 * want wine to create anything anywhere besides the .wine directory. So, if
4240 * there already is a 'My Music' directory in $HOME, we symlink the 'My Music'
4241 * shell folder to it. But if not, then we check XDG_MUSIC_DIR - "well known"
4242 * directory, and try to link to that. If that fails, then we symlink to
4243 * $HOME directly. The same holds fo 'My Pictures' and 'My Videos'.
4244 * - The Desktop shell folder is symlinked to XDG_DESKTOP_DIR. If that does not
4245 * exist, then we try '$HOME/Desktop'. If that does not exist, then we leave
4246 * it alone.
4247 * ('My Music',... above in fact means LoadString(IDS_MYMUSIC))
4249 static void _SHCreateSymbolicLinks(void)
4251 UINT aidsMyStuff[] = { IDS_MYPICTURES, IDS_MYVIDEOS, IDS_MYMUSIC }, i;
4252 const WCHAR* MyOSXStuffW[] = { PicturesW, MoviesW, MusicW };
4253 int acsidlMyStuff[] = { CSIDL_MYPICTURES, CSIDL_MYVIDEO, CSIDL_MYMUSIC };
4254 static const char * const xdg_dirs[] = { "PICTURES", "VIDEOS", "MUSIC", "DOCUMENTS", "DESKTOP" };
4255 static const unsigned int num = sizeof(xdg_dirs) / sizeof(xdg_dirs[0]);
4256 WCHAR wszTempPath[MAX_PATH];
4257 char szPersonalTarget[FILENAME_MAX], *pszPersonal;
4258 char szMyStuffTarget[FILENAME_MAX], *pszMyStuff;
4259 char szDesktopTarget[FILENAME_MAX], *pszDesktop;
4260 struct stat statFolder;
4261 const char *pszHome;
4262 HRESULT hr;
4263 char ** xdg_results;
4264 char * xdg_desktop_dir;
4266 /* Create all necessary profile sub-dirs up to 'My Documents' and get the unix path. */
4267 hr = SHGetFolderPathW(NULL, CSIDL_PERSONAL|CSIDL_FLAG_CREATE, NULL,
4268 SHGFP_TYPE_DEFAULT, wszTempPath);
4269 if (FAILED(hr)) return;
4270 pszPersonal = wine_get_unix_file_name(wszTempPath);
4271 if (!pszPersonal) return;
4273 hr = XDG_UserDirLookup(xdg_dirs, num, &xdg_results);
4274 if (FAILED(hr)) xdg_results = NULL;
4276 pszHome = getenv("HOME");
4277 if (pszHome && !stat(pszHome, &statFolder) && S_ISDIR(statFolder.st_mode))
4279 while (1)
4281 /* Check if there's already a Wine-specific 'My Documents' folder */
4282 strcpy(szPersonalTarget, pszHome);
4283 if (_SHAppendToUnixPath(szPersonalTarget, MAKEINTRESOURCEW(IDS_PERSONAL)) &&
4284 !stat(szPersonalTarget, &statFolder) && S_ISDIR(statFolder.st_mode))
4286 /* '$HOME/My Documents' exists. Create 'My Pictures',
4287 * 'My Videos' and 'My Music' subfolders or fail silently if
4288 * they already exist.
4290 for (i = 0; i < sizeof(aidsMyStuff)/sizeof(*aidsMyStuff); i++)
4292 strcpy(szMyStuffTarget, szPersonalTarget);
4293 if (_SHAppendToUnixPath(szMyStuffTarget, MAKEINTRESOURCEW(aidsMyStuff[i])))
4294 mkdir(szMyStuffTarget, 0777);
4296 break;
4299 /* Try to point to the XDG Documents folder */
4300 if (xdg_results && xdg_results[num-2] &&
4301 !stat(xdg_results[num-2], &statFolder) &&
4302 S_ISDIR(statFolder.st_mode))
4304 strcpy(szPersonalTarget, xdg_results[num-2]);
4305 break;
4308 /* Or the hardcoded / OS X Documents folder */
4309 strcpy(szPersonalTarget, pszHome);
4310 if (_SHAppendToUnixPath(szPersonalTarget, DocumentsW) &&
4311 !stat(szPersonalTarget, &statFolder) &&
4312 S_ISDIR(statFolder.st_mode))
4313 break;
4315 /* As a last resort point to $HOME. */
4316 strcpy(szPersonalTarget, pszHome);
4317 break;
4320 /* Replace 'My Documents' directory with a symlink or fail silently if not empty. */
4321 rmdir(pszPersonal);
4322 symlink(szPersonalTarget, pszPersonal);
4324 else
4326 /* '$HOME' doesn't exist. Create 'My Pictures', 'My Videos' and 'My Music' subdirs
4327 * in '%USERPROFILE%\\My Documents' or fail silently if they already exist. */
4328 pszHome = NULL;
4329 strcpy(szPersonalTarget, pszPersonal);
4330 for (i = 0; i < sizeof(aidsMyStuff)/sizeof(aidsMyStuff[0]); i++) {
4331 strcpy(szMyStuffTarget, szPersonalTarget);
4332 if (_SHAppendToUnixPath(szMyStuffTarget, MAKEINTRESOURCEW(aidsMyStuff[i])))
4333 mkdir(szMyStuffTarget, 0777);
4337 /* Create symbolic links for 'My Pictures', 'My Videos' and 'My Music'. */
4338 for (i=0; i < sizeof(aidsMyStuff)/sizeof(aidsMyStuff[0]); i++)
4340 /* Create the current 'My Whatever' folder and get its unix path. */
4341 hr = SHGetFolderPathW(NULL, acsidlMyStuff[i]|CSIDL_FLAG_CREATE, NULL,
4342 SHGFP_TYPE_DEFAULT, wszTempPath);
4343 if (FAILED(hr)) continue;
4345 pszMyStuff = wine_get_unix_file_name(wszTempPath);
4346 if (!pszMyStuff) continue;
4348 while (1)
4350 /* Check for the Wine-specific '$HOME/My Documents' subfolder */
4351 strcpy(szMyStuffTarget, szPersonalTarget);
4352 if (_SHAppendToUnixPath(szMyStuffTarget, MAKEINTRESOURCEW(aidsMyStuff[i])) &&
4353 !stat(szMyStuffTarget, &statFolder) && S_ISDIR(statFolder.st_mode))
4354 break;
4356 /* Try the XDG_XXX_DIR folder */
4357 if (xdg_results && xdg_results[i])
4359 strcpy(szMyStuffTarget, xdg_results[i]);
4360 break;
4363 /* Or the OS X folder (these are never localized) */
4364 if (pszHome)
4366 strcpy(szMyStuffTarget, pszHome);
4367 if (_SHAppendToUnixPath(szMyStuffTarget, MyOSXStuffW[i]) &&
4368 !stat(szMyStuffTarget, &statFolder) &&
4369 S_ISDIR(statFolder.st_mode))
4370 break;
4373 /* As a last resort point to the same location as 'My Documents' */
4374 strcpy(szMyStuffTarget, szPersonalTarget);
4375 break;
4377 rmdir(pszMyStuff);
4378 symlink(szMyStuffTarget, pszMyStuff);
4379 HeapFree(GetProcessHeap(), 0, pszMyStuff);
4382 /* Last but not least, the Desktop folder */
4383 if (pszHome)
4384 strcpy(szDesktopTarget, pszHome);
4385 else
4386 strcpy(szDesktopTarget, pszPersonal);
4387 HeapFree(GetProcessHeap(), 0, pszPersonal);
4389 xdg_desktop_dir = xdg_results ? xdg_results[num - 1] : NULL;
4390 if (xdg_desktop_dir ||
4391 (_SHAppendToUnixPath(szDesktopTarget, DesktopW) &&
4392 !stat(szDesktopTarget, &statFolder) && S_ISDIR(statFolder.st_mode)))
4394 hr = SHGetFolderPathW(NULL, CSIDL_DESKTOPDIRECTORY|CSIDL_FLAG_CREATE, NULL,
4395 SHGFP_TYPE_DEFAULT, wszTempPath);
4396 if (SUCCEEDED(hr) && (pszDesktop = wine_get_unix_file_name(wszTempPath)))
4398 rmdir(pszDesktop);
4399 if (xdg_desktop_dir)
4400 symlink(xdg_desktop_dir, pszDesktop);
4401 else
4402 symlink(szDesktopTarget, pszDesktop);
4403 HeapFree(GetProcessHeap(), 0, pszDesktop);
4407 /* Free resources allocated by XDG_UserDirLookup() */
4408 if (xdg_results)
4410 for (i = 0; i < num; i++)
4411 HeapFree(GetProcessHeap(), 0, xdg_results[i]);
4412 HeapFree(GetProcessHeap(), 0, xdg_results);
4416 /******************************************************************************
4417 * create_extra_folders [Internal]
4419 * Create some extra folders that don't have a standard CSIDL definition.
4421 static HRESULT create_extra_folders(void)
4423 static const WCHAR environW[] = {'E','n','v','i','r','o','n','m','e','n','t',0};
4424 static const WCHAR microsoftW[] = {'M','i','c','r','o','s','o','f','t',0};
4425 static const WCHAR TempW[] = {'T','e','m','p',0};
4426 static const WCHAR TEMPW[] = {'T','E','M','P',0};
4427 static const WCHAR TMPW[] = {'T','M','P',0};
4428 WCHAR path[MAX_PATH+5];
4429 HRESULT hr;
4430 HKEY hkey;
4431 DWORD type, size, ret;
4433 ret = RegCreateKeyW( HKEY_CURRENT_USER, environW, &hkey );
4434 if (ret) return HRESULT_FROM_WIN32( ret );
4436 /* FIXME: should be under AppData, but we don't want spaces in the temp path */
4437 hr = SHGetFolderPathAndSubDirW( 0, CSIDL_PROFILE | CSIDL_FLAG_CREATE, NULL,
4438 SHGFP_TYPE_DEFAULT, TempW, path );
4439 if (SUCCEEDED(hr))
4441 size = sizeof(path);
4442 if (RegQueryValueExW( hkey, TEMPW, NULL, &type, (LPBYTE)path, &size ))
4443 RegSetValueExW( hkey, TEMPW, 0, REG_SZ, (LPBYTE)path, (strlenW(path) + 1) * sizeof(WCHAR) );
4444 size = sizeof(path);
4445 if (RegQueryValueExW( hkey, TMPW, NULL, &type, (LPBYTE)path, &size ))
4446 RegSetValueExW( hkey, TMPW, 0, REG_SZ, (LPBYTE)path, (strlenW(path) + 1) * sizeof(WCHAR) );
4448 RegCloseKey( hkey );
4450 if (SUCCEEDED(hr))
4452 hr = SHGetFolderPathAndSubDirW( 0, CSIDL_COMMON_APPDATA | CSIDL_FLAG_CREATE, NULL,
4453 SHGFP_TYPE_DEFAULT, microsoftW, path );
4455 return hr;
4459 /******************************************************************************
4460 * set_folder_attributes
4462 * Set the various folder attributes registry keys.
4464 static HRESULT set_folder_attributes(void)
4466 static const WCHAR clsidW[] = {'C','L','S','I','D','\\',0 };
4467 static const WCHAR shellfolderW[] = {'\\','S','h','e','l','l','F','o','l','d','e','r', 0 };
4468 static const WCHAR wfparsingW[] = {'W','a','n','t','s','F','O','R','P','A','R','S','I','N','G',0};
4469 static const WCHAR wfdisplayW[] = {'W','a','n','t','s','F','O','R','D','I','S','P','L','A','Y',0};
4470 static const WCHAR hideasdeleteW[] = {'H','i','d','e','A','s','D','e','l','e','t','e','P','e','r','U','s','e','r',0};
4471 static const WCHAR cfattributesW[] = {'C','a','l','l','F','o','r','A','t','t','r','i','b','u','t','e','s',0};
4472 static const WCHAR emptyW[] = {0};
4474 static const struct
4476 const CLSID *clsid;
4477 BOOL wfparsing : 1;
4478 BOOL wfdisplay : 1;
4479 BOOL hideasdel : 1;
4480 DWORD attr;
4481 DWORD call_for_attr;
4482 } folders[] =
4484 { &CLSID_UnixFolder, TRUE, FALSE, FALSE },
4485 { &CLSID_UnixDosFolder, TRUE, FALSE, FALSE,
4486 SFGAO_FILESYSANCESTOR|SFGAO_FOLDER|SFGAO_HASSUBFOLDER, SFGAO_FILESYSTEM },
4487 { &CLSID_FolderShortcut, FALSE, FALSE, FALSE,
4488 SFGAO_FILESYSTEM|SFGAO_FOLDER|SFGAO_LINK,
4489 SFGAO_HASSUBFOLDER|SFGAO_FILESYSTEM|SFGAO_FOLDER|SFGAO_FILESYSANCESTOR },
4490 { &CLSID_MyDocuments, TRUE, FALSE, FALSE,
4491 SFGAO_FILESYSANCESTOR|SFGAO_FOLDER|SFGAO_HASSUBFOLDER, SFGAO_FILESYSTEM },
4492 { &CLSID_RecycleBin, FALSE, FALSE, FALSE,
4493 SFGAO_FOLDER|SFGAO_DROPTARGET|SFGAO_HASPROPSHEET },
4494 { &CLSID_ControlPanel, FALSE, TRUE, TRUE,
4495 SFGAO_FOLDER|SFGAO_HASSUBFOLDER }
4498 unsigned int i;
4499 WCHAR buffer[39 + (sizeof(clsidW) + sizeof(shellfolderW)) / sizeof(WCHAR)];
4500 LONG res;
4501 HKEY hkey;
4503 for (i = 0; i < sizeof(folders)/sizeof(folders[0]); i++)
4505 strcpyW( buffer, clsidW );
4506 StringFromGUID2( folders[i].clsid, buffer + strlenW(buffer), 39 );
4507 strcatW( buffer, shellfolderW );
4508 res = RegCreateKeyExW( HKEY_CLASSES_ROOT, buffer, 0, NULL, 0,
4509 KEY_READ | KEY_WRITE, NULL, &hkey, NULL);
4510 if (res) return HRESULT_FROM_WIN32( res );
4511 if (folders[i].wfparsing)
4512 res = RegSetValueExW( hkey, wfparsingW, 0, REG_SZ, (const BYTE *)emptyW, sizeof(emptyW) );
4513 if (folders[i].wfdisplay)
4514 res = RegSetValueExW( hkey, wfdisplayW, 0, REG_SZ, (const BYTE *)emptyW, sizeof(emptyW) );
4515 if (folders[i].hideasdel)
4516 res = RegSetValueExW( hkey, hideasdeleteW, 0, REG_SZ, (const BYTE *)emptyW, sizeof(emptyW) );
4517 if (folders[i].attr)
4518 res = RegSetValueExW( hkey, szAttributes, 0, REG_DWORD,
4519 (const BYTE *)&folders[i].attr, sizeof(DWORD));
4520 if (folders[i].call_for_attr)
4521 res = RegSetValueExW( hkey, cfattributesW, 0, REG_DWORD,
4522 (const BYTE *)&folders[i].call_for_attr, sizeof(DWORD));
4523 RegCloseKey( hkey );
4525 return S_OK;
4528 /*************************************************************************
4529 * SHGetSpecialFolderPathA [SHELL32.@]
4531 BOOL WINAPI SHGetSpecialFolderPathA (
4532 HWND hwndOwner,
4533 LPSTR szPath,
4534 int nFolder,
4535 BOOL bCreate)
4537 return SHGetFolderPathA(hwndOwner, nFolder + (bCreate ? CSIDL_FLAG_CREATE : 0), NULL, 0,
4538 szPath) == S_OK;
4541 /*************************************************************************
4542 * SHGetSpecialFolderPathW
4544 BOOL WINAPI SHGetSpecialFolderPathW (
4545 HWND hwndOwner,
4546 LPWSTR szPath,
4547 int nFolder,
4548 BOOL bCreate)
4550 return SHGetFolderPathW(hwndOwner, nFolder + (bCreate ? CSIDL_FLAG_CREATE : 0), NULL, 0,
4551 szPath) == S_OK;
4554 /*************************************************************************
4555 * SHGetSpecialFolderPath (SHELL32.175)
4557 BOOL WINAPI SHGetSpecialFolderPathAW (
4558 HWND hwndOwner,
4559 LPVOID szPath,
4560 int nFolder,
4561 BOOL bCreate)
4564 if (SHELL_OsIsUnicode())
4565 return SHGetSpecialFolderPathW (hwndOwner, szPath, nFolder, bCreate);
4566 return SHGetSpecialFolderPathA (hwndOwner, szPath, nFolder, bCreate);
4569 /*************************************************************************
4570 * SHGetFolderLocation [SHELL32.@]
4572 * Gets the folder locations from the registry and creates a pidl.
4574 * PARAMS
4575 * hwndOwner [I]
4576 * nFolder [I] CSIDL_xxxxx
4577 * hToken [I] token representing user, or NULL for current user, or -1 for
4578 * default user
4579 * dwReserved [I] must be zero
4580 * ppidl [O] PIDL of a special folder
4582 * RETURNS
4583 * Success: S_OK
4584 * Failure: Standard OLE-defined error result, S_FALSE or E_INVALIDARG
4586 * NOTES
4587 * Creates missing reg keys and directories.
4588 * Mostly forwards to SHGetFolderPathW, but a few values of nFolder return
4589 * virtual folders that are handled here.
4591 HRESULT WINAPI SHGetFolderLocation(
4592 HWND hwndOwner,
4593 int nFolder,
4594 HANDLE hToken,
4595 DWORD dwReserved,
4596 LPITEMIDLIST *ppidl)
4598 HRESULT hr = E_INVALIDARG;
4600 TRACE("%p 0x%08x %p 0x%08x %p\n",
4601 hwndOwner, nFolder, hToken, dwReserved, ppidl);
4603 if (!ppidl)
4604 return E_INVALIDARG;
4605 if (dwReserved)
4606 return E_INVALIDARG;
4608 /* The virtual folders' locations are not user-dependent */
4609 *ppidl = NULL;
4610 switch (nFolder & CSIDL_FOLDER_MASK)
4612 case CSIDL_DESKTOP:
4613 *ppidl = _ILCreateDesktop();
4614 break;
4616 case CSIDL_PERSONAL:
4617 *ppidl = _ILCreateMyDocuments();
4618 break;
4620 case CSIDL_INTERNET:
4621 *ppidl = _ILCreateIExplore();
4622 break;
4624 case CSIDL_CONTROLS:
4625 *ppidl = _ILCreateControlPanel();
4626 break;
4628 case CSIDL_PRINTERS:
4629 *ppidl = _ILCreatePrinters();
4630 break;
4632 case CSIDL_BITBUCKET:
4633 *ppidl = _ILCreateBitBucket();
4634 break;
4636 case CSIDL_DRIVES:
4637 *ppidl = _ILCreateMyComputer();
4638 break;
4640 case CSIDL_NETWORK:
4641 *ppidl = _ILCreateNetwork();
4642 break;
4644 default:
4646 WCHAR szPath[MAX_PATH];
4648 hr = SHGetFolderPathW(hwndOwner, nFolder, hToken,
4649 SHGFP_TYPE_CURRENT, szPath);
4650 if (SUCCEEDED(hr))
4652 DWORD attributes=0;
4654 TRACE("Value=%s\n", debugstr_w(szPath));
4655 hr = SHILCreateFromPathW(szPath, ppidl, &attributes);
4657 else if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
4659 /* unlike SHGetFolderPath, SHGetFolderLocation in shell32
4660 * version 6.0 returns E_FAIL for nonexistent paths
4662 hr = E_FAIL;
4666 if(*ppidl)
4667 hr = S_OK;
4669 TRACE("-- (new pidl %p)\n",*ppidl);
4670 return hr;
4673 /*************************************************************************
4674 * SHGetSpecialFolderLocation [SHELL32.@]
4676 * NOTES
4677 * In NT5, SHGetSpecialFolderLocation needs the <winntdir>/Recent
4678 * directory.
4680 HRESULT WINAPI SHGetSpecialFolderLocation(
4681 HWND hwndOwner,
4682 INT nFolder,
4683 LPITEMIDLIST * ppidl)
4685 HRESULT hr = E_INVALIDARG;
4687 TRACE("(%p,0x%x,%p)\n", hwndOwner,nFolder,ppidl);
4689 if (!ppidl)
4690 return E_INVALIDARG;
4692 hr = SHGetFolderLocation(hwndOwner, nFolder, NULL, 0, ppidl);
4693 return hr;
4696 static int csidl_from_id( const KNOWNFOLDERID *id )
4698 int i;
4699 for (i = 0; i < sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]); i++)
4700 if (IsEqualGUID( CSIDL_Data[i].id, id )) return i;
4701 return -1;
4704 /*************************************************************************
4705 * SHGetKnownFolderPath [SHELL32.@]
4707 HRESULT WINAPI SHGetKnownFolderPath(REFKNOWNFOLDERID rfid, DWORD flags, HANDLE token, PWSTR *path)
4709 HRESULT hr;
4710 WCHAR folder[MAX_PATH];
4711 int index = csidl_from_id( rfid );
4713 TRACE("%s, 0x%08x, %p, %p\n", debugstr_guid(rfid), flags, token, path);
4715 *path = NULL;
4717 if (index < 0)
4718 return HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND );
4720 if (flags & KF_FLAG_CREATE)
4721 index |= CSIDL_FLAG_CREATE;
4723 if (flags & KF_FLAG_DONT_VERIFY)
4724 index |= CSIDL_FLAG_DONT_VERIFY;
4726 if (flags & KF_FLAG_NO_ALIAS)
4727 index |= CSIDL_FLAG_NO_ALIAS;
4729 if (flags & KF_FLAG_INIT)
4730 index |= CSIDL_FLAG_PER_USER_INIT;
4732 if (flags & ~(KF_FLAG_CREATE|KF_FLAG_DONT_VERIFY|KF_FLAG_NO_ALIAS|KF_FLAG_INIT))
4734 FIXME("flags 0x%08x not supported\n", flags);
4735 return E_INVALIDARG;
4738 hr = SHGetFolderPathW( NULL, index, token, 0, folder );
4739 if (SUCCEEDED(hr))
4741 *path = CoTaskMemAlloc( (strlenW( folder ) + 1) * sizeof(WCHAR) );
4742 if (!*path)
4743 return E_OUTOFMEMORY;
4744 strcpyW( *path, folder );
4746 return hr;
4749 /*************************************************************************
4750 * SHGetFolderPathEx [SHELL32.@]
4752 HRESULT WINAPI SHGetFolderPathEx(REFKNOWNFOLDERID rfid, DWORD flags, HANDLE token, LPWSTR path, DWORD len)
4754 HRESULT hr;
4755 WCHAR *buffer;
4757 TRACE("%s, 0x%08x, %p, %p, %u\n", debugstr_guid(rfid), flags, token, path, len);
4759 if (!path || !len) return E_INVALIDARG;
4761 hr = SHGetKnownFolderPath( rfid, flags, token, &buffer );
4762 if (SUCCEEDED( hr ))
4764 if (strlenW( buffer ) + 1 > len)
4766 CoTaskMemFree( buffer );
4767 return HRESULT_FROM_WIN32( ERROR_INSUFFICIENT_BUFFER );
4769 strcpyW( path, buffer );
4770 CoTaskMemFree( buffer );
4772 return hr;
4776 * Internal function to convert known folder identifier to path of registry key
4777 * associated with known folder.
4779 * Parameters:
4780 * rfid [I] pointer to known folder identifier (may be NULL)
4781 * lpStringGuid [I] string with known folder identifier (used when rfid is NULL)
4782 * lpPath [O] place to store string address. String should be
4783 * later freed using HeapFree(GetProcessHeap(),0, ... )
4785 static HRESULT get_known_folder_registry_path(
4786 REFKNOWNFOLDERID rfid,
4787 LPWSTR lpStringGuid,
4788 LPWSTR *lpPath)
4790 static const WCHAR sBackslash[] = {'\\',0};
4791 HRESULT hr = S_OK;
4792 int length;
4793 WCHAR sGuid[50];
4795 TRACE("(%s, %s, %p)\n", debugstr_guid(rfid), debugstr_w(lpStringGuid), lpPath);
4797 if(rfid)
4798 StringFromGUID2(rfid, sGuid, sizeof(sGuid)/sizeof(sGuid[0]));
4799 else
4800 lstrcpyW(sGuid, lpStringGuid);
4802 length = lstrlenW(szKnownFolderDescriptions)+51;
4803 *lpPath = HeapAlloc(GetProcessHeap(), 0, length*sizeof(WCHAR));
4804 if(!(*lpPath))
4805 hr = E_OUTOFMEMORY;
4807 if(SUCCEEDED(hr))
4809 lstrcpyW(*lpPath, szKnownFolderDescriptions);
4810 lstrcatW(*lpPath, sBackslash);
4811 lstrcatW(*lpPath, sGuid);
4814 return hr;
4817 static HRESULT get_known_folder_wstr(const WCHAR *regpath, const WCHAR *value, WCHAR **out)
4819 DWORD size = 0;
4820 HRESULT hr;
4822 size = 0;
4823 hr = HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, regpath, value, RRF_RT_REG_SZ, NULL, NULL, &size));
4824 if(FAILED(hr))
4825 return hr;
4827 *out = CoTaskMemAlloc(size);
4828 if(!*out)
4829 return E_OUTOFMEMORY;
4831 hr = HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, regpath, value, RRF_RT_REG_SZ, NULL, *out, &size));
4832 if(FAILED(hr)){
4833 CoTaskMemFree(*out);
4834 *out = NULL;
4837 return hr;
4840 static HRESULT get_known_folder_dword(const WCHAR *registryPath, const WCHAR *value, DWORD *out)
4842 DWORD dwSize = sizeof(DWORD);
4843 DWORD dwType;
4844 return HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, registryPath, value, RRF_RT_DWORD, &dwType, out, &dwSize));
4848 * Internal function to get place where folder redirection information are stored.
4850 * Parameters:
4851 * rfid [I] pointer to known folder identifier (may be NULL)
4852 * rootKey [O] root key where the redirection information are stored
4853 * It can be HKLM for COMMON folders, and HKCU for PERUSER folders.
4854 * However, besides root key, path is always that same, and is stored
4855 * as "szKnownFolderRedirections" constant
4857 static HRESULT get_known_folder_redirection_place(
4858 REFKNOWNFOLDERID rfid,
4859 HKEY *rootKey)
4861 HRESULT hr;
4862 LPWSTR lpRegistryPath = NULL;
4863 KF_CATEGORY category;
4865 /* first, get known folder's category */
4866 hr = get_known_folder_registry_path(rfid, NULL, &lpRegistryPath);
4868 if(SUCCEEDED(hr))
4869 hr = get_known_folder_dword(lpRegistryPath, szCategory, &category);
4871 if(SUCCEEDED(hr))
4873 if(category == KF_CATEGORY_COMMON)
4875 *rootKey = HKEY_LOCAL_MACHINE;
4876 hr = S_OK;
4878 else if(category == KF_CATEGORY_PERUSER)
4880 *rootKey = HKEY_CURRENT_USER;
4881 hr = S_OK;
4883 else
4884 hr = E_FAIL;
4887 HeapFree(GetProcessHeap(), 0, lpRegistryPath);
4888 return hr;
4891 static HRESULT get_known_folder_path_by_id(REFKNOWNFOLDERID folderId, LPWSTR lpRegistryPath, DWORD dwFlags, LPWSTR *ppszPath);
4893 static HRESULT redirect_known_folder(
4894 REFKNOWNFOLDERID rfid,
4895 HWND hwnd,
4896 KF_REDIRECT_FLAGS flags,
4897 LPCWSTR pszTargetPath,
4898 UINT cFolders,
4899 KNOWNFOLDERID const *pExclusion,
4900 LPWSTR *ppszError)
4902 HRESULT hr;
4903 HKEY rootKey = HKEY_LOCAL_MACHINE, hKey;
4904 WCHAR sGuid[39];
4905 LPWSTR lpRegistryPath = NULL, lpSrcPath = NULL;
4906 TRACE("(%s, %p, 0x%08x, %s, %d, %p, %p)\n", debugstr_guid(rfid), hwnd, flags, debugstr_w(pszTargetPath), cFolders, pExclusion, ppszError);
4908 if (ppszError) *ppszError = NULL;
4910 hr = get_known_folder_registry_path(rfid, NULL, &lpRegistryPath);
4912 if(SUCCEEDED(hr))
4913 hr = get_known_folder_path_by_id(rfid, lpRegistryPath, 0, &lpSrcPath);
4915 HeapFree(GetProcessHeap(), 0, lpRegistryPath);
4917 /* get path to redirection storage */
4918 if(SUCCEEDED(hr))
4919 hr = get_known_folder_redirection_place(rfid, &rootKey);
4921 /* write redirection information */
4922 if(SUCCEEDED(hr))
4923 hr = HRESULT_FROM_WIN32(RegCreateKeyExW(rootKey, szKnownFolderRedirections, 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL));
4925 if(SUCCEEDED(hr))
4927 StringFromGUID2(rfid, sGuid, sizeof(sGuid)/sizeof(sGuid[0]));
4929 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, sGuid, 0, REG_SZ, (LPBYTE)pszTargetPath, (lstrlenW(pszTargetPath)+1)*sizeof(WCHAR)));
4931 RegCloseKey(hKey);
4934 /* make sure destination path exists */
4935 SHCreateDirectory(NULL, pszTargetPath);
4937 /* copy content if required */
4938 if(SUCCEEDED(hr) && (flags & KF_REDIRECT_COPY_CONTENTS) )
4940 static const WCHAR sWildcard[] = {'\\','*',0};
4941 WCHAR srcPath[MAX_PATH+1], dstPath[MAX_PATH+1];
4942 SHFILEOPSTRUCTW fileOp;
4944 ZeroMemory(srcPath, sizeof(srcPath));
4945 lstrcpyW(srcPath, lpSrcPath);
4946 lstrcatW(srcPath, sWildcard);
4948 ZeroMemory(dstPath, sizeof(dstPath));
4949 lstrcpyW(dstPath, pszTargetPath);
4951 ZeroMemory(&fileOp, sizeof(fileOp));
4953 if(flags & KF_REDIRECT_DEL_SOURCE_CONTENTS)
4954 fileOp.wFunc = FO_MOVE;
4955 else
4956 fileOp.wFunc = FO_COPY;
4958 fileOp.pFrom = srcPath;
4959 fileOp.pTo = dstPath;
4960 fileOp.fFlags = FOF_NO_UI;
4962 hr = (SHFileOperationW(&fileOp)==0 ? S_OK : E_FAIL);
4964 if(flags & KF_REDIRECT_DEL_SOURCE_CONTENTS)
4966 ZeroMemory(srcPath, sizeof(srcPath));
4967 lstrcpyW(srcPath, lpSrcPath);
4969 ZeroMemory(&fileOp, sizeof(fileOp));
4970 fileOp.wFunc = FO_DELETE;
4971 fileOp.pFrom = srcPath;
4972 fileOp.fFlags = FOF_NO_UI;
4974 hr = (SHFileOperationW(&fileOp)==0 ? S_OK : E_FAIL);
4978 CoTaskMemFree(lpSrcPath);
4980 return hr;
4984 struct knownfolder
4986 IKnownFolder IKnownFolder_iface;
4987 LONG refs;
4988 KNOWNFOLDERID id;
4989 LPWSTR registryPath;
4992 static inline struct knownfolder *impl_from_IKnownFolder( IKnownFolder *iface )
4994 return CONTAINING_RECORD( iface, struct knownfolder, IKnownFolder_iface );
4997 static ULONG WINAPI knownfolder_AddRef(
4998 IKnownFolder *iface )
5000 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
5001 return InterlockedIncrement( &knownfolder->refs );
5004 static ULONG WINAPI knownfolder_Release(
5005 IKnownFolder *iface )
5007 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
5008 LONG refs = InterlockedDecrement( &knownfolder->refs );
5009 if (!refs)
5011 TRACE("destroying %p\n", knownfolder);
5012 HeapFree( GetProcessHeap(), 0, knownfolder->registryPath);
5013 HeapFree( GetProcessHeap(), 0, knownfolder );
5015 return refs;
5018 static HRESULT WINAPI knownfolder_QueryInterface(
5019 IKnownFolder *iface,
5020 REFIID riid,
5021 void **ppv )
5023 struct knownfolder *This = impl_from_IKnownFolder( iface );
5025 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppv );
5027 *ppv = NULL;
5028 if ( IsEqualGUID( riid, &IID_IKnownFolder ) ||
5029 IsEqualGUID( riid, &IID_IUnknown ) )
5031 *ppv = iface;
5033 else if ( IsEqualGUID( riid, &IID_IMarshal ) )
5035 TRACE("IID_IMarshal returning NULL.\n");
5036 return E_NOINTERFACE;
5038 else
5040 FIXME("interface %s not implemented\n", debugstr_guid(riid));
5041 return E_NOINTERFACE;
5043 IKnownFolder_AddRef( iface );
5044 return S_OK;
5047 static HRESULT knownfolder_set_id(
5048 struct knownfolder *knownfolder,
5049 const KNOWNFOLDERID *kfid)
5051 HKEY hKey;
5052 HRESULT hr;
5054 TRACE("%s\n", debugstr_guid(kfid));
5056 knownfolder->id = *kfid;
5058 /* check is it registry-registered folder */
5059 hr = get_known_folder_registry_path(kfid, NULL, &knownfolder->registryPath);
5060 if(SUCCEEDED(hr))
5061 hr = HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_LOCAL_MACHINE, knownfolder->registryPath, 0, 0, &hKey));
5063 if(SUCCEEDED(hr))
5065 hr = S_OK;
5066 RegCloseKey(hKey);
5068 else
5070 /* This known folder is not registered. To mark it, we set registryPath to NULL */
5071 HeapFree(GetProcessHeap(), 0, knownfolder->registryPath);
5072 knownfolder->registryPath = NULL;
5073 hr = S_OK;
5076 return hr;
5079 static HRESULT WINAPI knownfolder_GetId(
5080 IKnownFolder *iface,
5081 KNOWNFOLDERID *pkfid)
5083 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
5085 TRACE("%p\n", pkfid);
5087 *pkfid = knownfolder->id;
5088 return S_OK;
5091 static HRESULT WINAPI knownfolder_GetCategory(
5092 IKnownFolder *iface,
5093 KF_CATEGORY *pCategory)
5095 struct knownfolder *knownfolder = impl_from_IKnownFolder(iface);
5096 HRESULT hr = S_OK;
5098 TRACE("%p, %p\n", knownfolder, pCategory);
5100 /* we cannot get a category for a folder which is not registered */
5101 if(!knownfolder->registryPath)
5102 hr = E_FAIL;
5104 if(SUCCEEDED(hr))
5105 hr = get_known_folder_dword(knownfolder->registryPath, szCategory, pCategory);
5107 return hr;
5110 static HRESULT WINAPI knownfolder_GetShellItem(
5111 IKnownFolder *iface,
5112 DWORD flags,
5113 REFIID riid,
5114 void **ppv)
5116 struct knownfolder *knownfolder = impl_from_IKnownFolder(iface);
5117 TRACE("(%p, 0x%08x, %s, %p)\n", knownfolder, flags, debugstr_guid(riid), ppv);
5118 return SHGetKnownFolderItem(&knownfolder->id, flags, NULL, riid, ppv);
5121 static HRESULT get_known_folder_path(
5122 LPWSTR sFolderId,
5123 LPWSTR registryPath,
5124 LPWSTR *ppszPath)
5126 static const WCHAR sBackslash[] = {'\\',0};
5127 HRESULT hr;
5128 DWORD dwSize, dwType;
5129 WCHAR path[MAX_PATH] = {0};
5130 WCHAR parentGuid[39];
5131 KF_CATEGORY category;
5132 LPWSTR parentRegistryPath, parentPath;
5133 HKEY hRedirectionRootKey = NULL;
5135 TRACE("(%s, %p)\n", debugstr_w(registryPath), ppszPath);
5136 *ppszPath = NULL;
5138 /* check if folder has parent */
5139 dwSize = sizeof(parentGuid);
5140 hr = HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, registryPath, szParentFolder, RRF_RT_REG_SZ, &dwType, parentGuid, &dwSize));
5141 if(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) hr = S_FALSE;
5143 if(hr == S_OK)
5145 /* get parent's known folder path (recursive) */
5146 hr = get_known_folder_registry_path(NULL, parentGuid, &parentRegistryPath);
5147 if(FAILED(hr)) return hr;
5149 hr = get_known_folder_path(parentGuid, parentRegistryPath, &parentPath);
5150 if(FAILED(hr)) {
5151 HeapFree(GetProcessHeap(), 0, parentRegistryPath);
5152 return hr;
5155 lstrcatW(path, parentPath);
5156 lstrcatW(path, sBackslash);
5158 HeapFree(GetProcessHeap(), 0, parentRegistryPath);
5159 HeapFree(GetProcessHeap(), 0, parentPath);
5162 /* check, if folder was redirected */
5163 if(SUCCEEDED(hr))
5164 hr = get_known_folder_dword(registryPath, szCategory, &category);
5166 if(SUCCEEDED(hr))
5168 if(category == KF_CATEGORY_COMMON)
5169 hRedirectionRootKey = HKEY_LOCAL_MACHINE;
5170 else if(category == KF_CATEGORY_PERUSER)
5171 hRedirectionRootKey = HKEY_CURRENT_USER;
5173 if(hRedirectionRootKey)
5175 hr = HRESULT_FROM_WIN32(RegGetValueW(hRedirectionRootKey, szKnownFolderRedirections, sFolderId, RRF_RT_REG_SZ, NULL, NULL, &dwSize));
5177 if(SUCCEEDED(hr))
5179 *ppszPath = CoTaskMemAlloc(dwSize+(lstrlenW(path)+1)*sizeof(WCHAR));
5180 if(!*ppszPath) hr = E_OUTOFMEMORY;
5183 if(SUCCEEDED(hr))
5185 lstrcpyW(*ppszPath, path);
5186 hr = HRESULT_FROM_WIN32(RegGetValueW(hRedirectionRootKey, szKnownFolderRedirections, sFolderId, RRF_RT_REG_SZ, NULL, *ppszPath + lstrlenW(path), &dwSize));
5190 if(!*ppszPath)
5192 /* no redirection, use previous way - read the relative path from folder definition */
5193 hr = HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, registryPath, szRelativePath, RRF_RT_REG_SZ, &dwType, NULL, &dwSize));
5195 if(SUCCEEDED(hr))
5197 *ppszPath = CoTaskMemAlloc(dwSize+(lstrlenW(path)+1)*sizeof(WCHAR));
5198 if(!*ppszPath) hr = E_OUTOFMEMORY;
5201 if(SUCCEEDED(hr))
5203 lstrcpyW(*ppszPath, path);
5204 hr = HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, registryPath, szRelativePath, RRF_RT_REG_SZ, &dwType, *ppszPath + lstrlenW(path), &dwSize));
5209 TRACE("returning path: %s\n", debugstr_w(*ppszPath));
5210 return hr;
5213 static HRESULT get_known_folder_path_by_id(
5214 REFKNOWNFOLDERID folderId,
5215 LPWSTR lpRegistryPath,
5216 DWORD dwFlags,
5217 LPWSTR *ppszPath)
5219 HRESULT hr = E_FAIL;
5220 WCHAR sGuid[39];
5221 DWORD dwAttributes;
5223 TRACE("(%s, %s, 0x%08x, %p)\n", debugstr_guid(folderId), debugstr_w(lpRegistryPath), dwFlags, ppszPath);
5225 /* if this is registry-registered known folder, get path from registry */
5226 if(lpRegistryPath)
5228 StringFromGUID2(folderId, sGuid, sizeof(sGuid)/sizeof(sGuid[0]));
5230 hr = get_known_folder_path(sGuid, lpRegistryPath, ppszPath);
5232 /* in other case, use older way */
5234 if(FAILED(hr))
5235 hr = SHGetKnownFolderPath( folderId, dwFlags, NULL, ppszPath );
5237 if (FAILED(hr)) return hr;
5239 /* check if known folder really exists */
5240 dwAttributes = GetFileAttributesW(*ppszPath);
5241 if(dwAttributes == INVALID_FILE_ATTRIBUTES || !(dwAttributes & FILE_ATTRIBUTE_DIRECTORY) )
5243 TRACE("directory %s not found\n", debugstr_w(*ppszPath));
5244 CoTaskMemFree(*ppszPath);
5245 *ppszPath = NULL;
5246 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
5249 return hr;
5252 static HRESULT WINAPI knownfolder_GetPath(
5253 IKnownFolder *iface,
5254 DWORD dwFlags,
5255 LPWSTR *ppszPath)
5257 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
5258 TRACE("(%p, 0x%08x, %p)\n", knownfolder, dwFlags, ppszPath);
5260 return get_known_folder_path_by_id(&knownfolder->id, knownfolder->registryPath, dwFlags, ppszPath);
5263 static HRESULT WINAPI knownfolder_SetPath(
5264 IKnownFolder *iface,
5265 DWORD dwFlags,
5266 LPCWSTR pszPath)
5268 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
5269 HRESULT hr = S_OK;
5271 TRACE("(%p, 0x%08x, %s)\n", knownfolder, dwFlags, debugstr_w(pszPath));
5273 /* check if the known folder is registered */
5274 if(!knownfolder->registryPath)
5275 hr = E_FAIL;
5277 if(SUCCEEDED(hr))
5278 hr = redirect_known_folder(&knownfolder->id, NULL, 0, pszPath, 0, NULL, NULL);
5280 return hr;
5283 static HRESULT WINAPI knownfolder_GetIDList(
5284 IKnownFolder *iface,
5285 DWORD flags,
5286 PIDLIST_ABSOLUTE *ppidl)
5288 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
5289 TRACE("(%p, 0x%08x, %p)\n", knownfolder, flags, ppidl);
5290 return SHGetKnownFolderIDList(&knownfolder->id, flags, NULL, ppidl);
5293 static HRESULT WINAPI knownfolder_GetFolderType(
5294 IKnownFolder *iface,
5295 FOLDERTYPEID *pftid)
5297 FIXME("%p\n", pftid);
5298 return E_NOTIMPL;
5301 static HRESULT WINAPI knownfolder_GetRedirectionCapabilities(
5302 IKnownFolder *iface,
5303 KF_REDIRECTION_CAPABILITIES *pCapabilities)
5305 FIXME("%p\n", pCapabilities);
5306 return E_NOTIMPL;
5309 static HRESULT WINAPI knownfolder_GetFolderDefinition(
5310 IKnownFolder *iface,
5311 KNOWNFOLDER_DEFINITION *pKFD)
5313 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
5314 HRESULT hr;
5315 DWORD dwSize;
5316 WCHAR parentGuid[39];
5317 TRACE("(%p, %p)\n", knownfolder, pKFD);
5319 if(!pKFD) return E_INVALIDARG;
5321 ZeroMemory(pKFD, sizeof(*pKFD));
5323 /* required fields */
5324 hr = get_known_folder_dword(knownfolder->registryPath, szCategory, &pKFD->category);
5325 if(FAILED(hr))
5326 return hr;
5328 hr = get_known_folder_wstr(knownfolder->registryPath, szName, &pKFD->pszName);
5329 if(FAILED(hr))
5330 return hr;
5332 /* optional fields */
5333 dwSize = sizeof(parentGuid);
5334 hr = HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, knownfolder->registryPath, szParentFolder,
5335 RRF_RT_REG_SZ, NULL, parentGuid, &dwSize));
5336 if(SUCCEEDED(hr))
5338 hr = IIDFromString(parentGuid, &pKFD->fidParent);
5339 if(FAILED(hr))
5340 return hr;
5343 get_known_folder_dword(knownfolder->registryPath, szAttributes, &pKFD->dwAttributes);
5345 get_known_folder_wstr(knownfolder->registryPath, szRelativePath, &pKFD->pszRelativePath);
5347 get_known_folder_wstr(knownfolder->registryPath, szParsingName, &pKFD->pszParsingName);
5349 return S_OK;
5352 static const struct IKnownFolderVtbl knownfolder_vtbl =
5354 knownfolder_QueryInterface,
5355 knownfolder_AddRef,
5356 knownfolder_Release,
5357 knownfolder_GetId,
5358 knownfolder_GetCategory,
5359 knownfolder_GetShellItem,
5360 knownfolder_GetPath,
5361 knownfolder_SetPath,
5362 knownfolder_GetIDList,
5363 knownfolder_GetFolderType,
5364 knownfolder_GetRedirectionCapabilities,
5365 knownfolder_GetFolderDefinition
5368 static HRESULT knownfolder_create( struct knownfolder **knownfolder )
5370 struct knownfolder *kf;
5372 kf = HeapAlloc( GetProcessHeap(), 0, sizeof(*kf) );
5373 if (!kf) return E_OUTOFMEMORY;
5375 kf->IKnownFolder_iface.lpVtbl = &knownfolder_vtbl;
5376 kf->refs = 1;
5377 memset( &kf->id, 0, sizeof(kf->id) );
5378 kf->registryPath = NULL;
5380 *knownfolder = kf;
5382 TRACE("returning iface %p\n", &kf->IKnownFolder_iface);
5383 return S_OK;
5386 struct foldermanager
5388 IKnownFolderManager IKnownFolderManager_iface;
5389 LONG refs;
5390 UINT num_ids;
5391 KNOWNFOLDERID *ids;
5394 static inline struct foldermanager *impl_from_IKnownFolderManager( IKnownFolderManager *iface )
5396 return CONTAINING_RECORD( iface, struct foldermanager, IKnownFolderManager_iface );
5399 static ULONG WINAPI foldermanager_AddRef(
5400 IKnownFolderManager *iface )
5402 struct foldermanager *foldermanager = impl_from_IKnownFolderManager( iface );
5403 return InterlockedIncrement( &foldermanager->refs );
5406 static ULONG WINAPI foldermanager_Release(
5407 IKnownFolderManager *iface )
5409 struct foldermanager *foldermanager = impl_from_IKnownFolderManager( iface );
5410 LONG refs = InterlockedDecrement( &foldermanager->refs );
5411 if (!refs)
5413 TRACE("destroying %p\n", foldermanager);
5414 HeapFree( GetProcessHeap(), 0, foldermanager->ids );
5415 HeapFree( GetProcessHeap(), 0, foldermanager );
5417 return refs;
5420 static HRESULT WINAPI foldermanager_QueryInterface(
5421 IKnownFolderManager *iface,
5422 REFIID riid,
5423 void **ppv )
5425 struct foldermanager *This = impl_from_IKnownFolderManager( iface );
5427 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppv );
5429 *ppv = NULL;
5430 if ( IsEqualGUID( riid, &IID_IKnownFolderManager ) ||
5431 IsEqualGUID( riid, &IID_IUnknown ) )
5433 *ppv = iface;
5435 else if ( IsEqualGUID( riid, &IID_IMarshal ) )
5437 TRACE("IID_IMarshal returning NULL.\n");
5438 return E_NOINTERFACE;
5440 else
5442 FIXME("interface %s not implemented\n", debugstr_guid(riid));
5443 return E_NOINTERFACE;
5445 IKnownFolderManager_AddRef( iface );
5446 return S_OK;
5449 static HRESULT WINAPI foldermanager_FolderIdFromCsidl(
5450 IKnownFolderManager *iface,
5451 int nCsidl,
5452 KNOWNFOLDERID *pfid)
5454 TRACE("%d, %p\n", nCsidl, pfid);
5456 if (nCsidl >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
5457 return E_INVALIDARG;
5458 *pfid = *CSIDL_Data[nCsidl].id;
5459 return S_OK;
5462 static HRESULT WINAPI foldermanager_FolderIdToCsidl(
5463 IKnownFolderManager *iface,
5464 REFKNOWNFOLDERID rfid,
5465 int *pnCsidl)
5467 int csidl;
5469 TRACE("%s, %p\n", debugstr_guid(rfid), pnCsidl);
5471 csidl = csidl_from_id( rfid );
5472 if (csidl == -1) return E_INVALIDARG;
5473 *pnCsidl = csidl;
5474 return S_OK;
5477 static HRESULT WINAPI foldermanager_GetFolderIds(
5478 IKnownFolderManager *iface,
5479 KNOWNFOLDERID **ppKFId,
5480 UINT *pCount)
5482 struct foldermanager *fm = impl_from_IKnownFolderManager( iface );
5484 TRACE("%p, %p\n", ppKFId, pCount);
5486 *ppKFId = CoTaskMemAlloc(fm->num_ids * sizeof(KNOWNFOLDERID));
5487 memcpy(*ppKFId, fm->ids, fm->num_ids * sizeof(KNOWNFOLDERID));
5488 *pCount = fm->num_ids;
5489 return S_OK;
5492 static BOOL is_knownfolder( struct foldermanager *fm, const KNOWNFOLDERID *id )
5494 UINT i;
5495 HRESULT hr;
5496 LPWSTR registryPath = NULL;
5497 HKEY hKey;
5499 /* TODO: move all entries from "CSIDL_Data" static array to registry known folder descriptions */
5500 for (i = 0; i < fm->num_ids; i++)
5501 if (IsEqualGUID( &fm->ids[i], id )) return TRUE;
5503 hr = get_known_folder_registry_path(id, NULL, &registryPath);
5504 if(SUCCEEDED(hr))
5506 hr = HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_LOCAL_MACHINE, registryPath, 0, 0, &hKey));
5507 HeapFree(GetProcessHeap(), 0, registryPath);
5510 if(SUCCEEDED(hr))
5512 hr = S_OK;
5513 RegCloseKey(hKey);
5516 return hr == S_OK;
5519 static HRESULT WINAPI foldermanager_GetFolder(
5520 IKnownFolderManager *iface,
5521 REFKNOWNFOLDERID rfid,
5522 IKnownFolder **ppkf)
5524 struct foldermanager *fm = impl_from_IKnownFolderManager( iface );
5525 struct knownfolder *kf;
5526 HRESULT hr;
5528 TRACE("%s, %p\n", debugstr_guid(rfid), ppkf);
5530 if (!is_knownfolder( fm, rfid ))
5532 WARN("unknown folder\n");
5533 return E_INVALIDARG;
5535 hr = knownfolder_create( &kf );
5536 if (SUCCEEDED( hr ))
5538 hr = knownfolder_set_id( kf, rfid );
5539 *ppkf = &kf->IKnownFolder_iface;
5541 else
5542 *ppkf = NULL;
5544 return hr;
5547 static HRESULT WINAPI foldermanager_GetFolderByName(
5548 IKnownFolderManager *iface,
5549 LPCWSTR pszCanonicalName,
5550 IKnownFolder **ppkf)
5552 FIXME("%s, %p\n", debugstr_w(pszCanonicalName), ppkf);
5553 return E_NOTIMPL;
5556 static HRESULT register_folder(const KNOWNFOLDERID *rfid, const KNOWNFOLDER_DEFINITION *pKFD)
5558 HRESULT hr;
5559 HKEY hKey = NULL;
5560 DWORD dwDisp;
5561 LPWSTR registryPath = NULL;
5563 hr = get_known_folder_registry_path(rfid, NULL, &registryPath);
5564 TRACE("registry path: %s\n", debugstr_w(registryPath));
5566 if(SUCCEEDED(hr))
5567 hr = HRESULT_FROM_WIN32(RegCreateKeyExW(HKEY_LOCAL_MACHINE, registryPath, 0, NULL, 0, KEY_WRITE, 0, &hKey, &dwDisp));
5569 if(SUCCEEDED(hr))
5571 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, szCategory, 0, REG_DWORD, (LPBYTE)&pKFD->category, sizeof(pKFD->category)));
5573 if(SUCCEEDED(hr) && pKFD->dwAttributes != 0)
5574 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, szAttributes, 0, REG_DWORD, (LPBYTE)&pKFD->dwAttributes, sizeof(pKFD->dwAttributes)));
5576 if(SUCCEEDED(hr))
5577 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, szName, 0, REG_SZ, (LPBYTE)pKFD->pszName, (lstrlenW(pKFD->pszName)+1)*sizeof(WCHAR) ));
5579 if(SUCCEEDED(hr) && pKFD->pszParsingName)
5580 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, szParsingName, 0, REG_SZ, (LPBYTE)pKFD->pszParsingName, (lstrlenW(pKFD->pszParsingName)+1)*sizeof(WCHAR) ));
5582 if(SUCCEEDED(hr) && !IsEqualGUID(&pKFD->fidParent, &GUID_NULL))
5584 WCHAR sParentGuid[39];
5585 StringFromGUID2(&pKFD->fidParent, sParentGuid, sizeof(sParentGuid)/sizeof(sParentGuid[0]));
5587 /* this known folder has parent folder */
5588 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, szParentFolder, 0, REG_SZ, (LPBYTE)sParentGuid, sizeof(sParentGuid)));
5591 if(SUCCEEDED(hr) && pKFD->category != KF_CATEGORY_VIRTUAL && pKFD->pszRelativePath)
5592 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, szRelativePath, 0, REG_SZ, (LPBYTE)pKFD->pszRelativePath, (lstrlenW(pKFD->pszRelativePath)+1)*sizeof(WCHAR) ));
5594 RegCloseKey(hKey);
5596 if(FAILED(hr))
5597 SHDeleteKeyW(HKEY_LOCAL_MACHINE, registryPath);
5600 HeapFree(GetProcessHeap(), 0, registryPath);
5601 return hr;
5604 static HRESULT WINAPI foldermanager_RegisterFolder(
5605 IKnownFolderManager *iface,
5606 REFKNOWNFOLDERID rfid,
5607 KNOWNFOLDER_DEFINITION const *pKFD)
5609 TRACE("(%p, %s, %p)\n", iface, debugstr_guid(rfid), pKFD);
5610 return register_folder(rfid, pKFD);
5613 static HRESULT WINAPI foldermanager_UnregisterFolder(
5614 IKnownFolderManager *iface,
5615 REFKNOWNFOLDERID rfid)
5617 HRESULT hr;
5618 LPWSTR registryPath = NULL;
5619 TRACE("(%p, %s)\n", iface, debugstr_guid(rfid));
5621 hr = get_known_folder_registry_path(rfid, NULL, &registryPath);
5623 if(SUCCEEDED(hr))
5624 hr = HRESULT_FROM_WIN32(SHDeleteKeyW(HKEY_LOCAL_MACHINE, registryPath));
5626 HeapFree(GetProcessHeap(), 0, registryPath);
5627 return hr;
5630 static HRESULT WINAPI foldermanager_FindFolderFromPath(
5631 IKnownFolderManager *iface,
5632 LPCWSTR pszPath,
5633 FFFP_MODE mode,
5634 IKnownFolder **ppkf)
5636 FIXME("%s, 0x%08x, %p\n", debugstr_w(pszPath), mode, ppkf);
5637 return E_NOTIMPL;
5640 static HRESULT WINAPI foldermanager_FindFolderFromIDList(
5641 IKnownFolderManager *iface,
5642 PCIDLIST_ABSOLUTE pidl,
5643 IKnownFolder **ppkf)
5645 FIXME("%p, %p\n", pidl, ppkf);
5646 return E_NOTIMPL;
5649 static HRESULT WINAPI foldermanager_Redirect(
5650 IKnownFolderManager *iface,
5651 REFKNOWNFOLDERID rfid,
5652 HWND hwnd,
5653 KF_REDIRECT_FLAGS flags,
5654 LPCWSTR pszTargetPath,
5655 UINT cFolders,
5656 KNOWNFOLDERID const *pExclusion,
5657 LPWSTR *ppszError)
5659 return redirect_known_folder(rfid, hwnd, flags, pszTargetPath, cFolders, pExclusion, ppszError);
5662 static const struct IKnownFolderManagerVtbl foldermanager_vtbl =
5664 foldermanager_QueryInterface,
5665 foldermanager_AddRef,
5666 foldermanager_Release,
5667 foldermanager_FolderIdFromCsidl,
5668 foldermanager_FolderIdToCsidl,
5669 foldermanager_GetFolderIds,
5670 foldermanager_GetFolder,
5671 foldermanager_GetFolderByName,
5672 foldermanager_RegisterFolder,
5673 foldermanager_UnregisterFolder,
5674 foldermanager_FindFolderFromPath,
5675 foldermanager_FindFolderFromIDList,
5676 foldermanager_Redirect
5679 static HRESULT foldermanager_create( void **ppv )
5681 UINT i, j;
5682 struct foldermanager *fm;
5684 fm = HeapAlloc( GetProcessHeap(), 0, sizeof(*fm) );
5685 if (!fm) return E_OUTOFMEMORY;
5687 fm->IKnownFolderManager_iface.lpVtbl = &foldermanager_vtbl;
5688 fm->refs = 1;
5689 fm->num_ids = 0;
5691 for (i = 0; i < sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]); i++)
5693 if (!IsEqualGUID( CSIDL_Data[i].id, &GUID_NULL )) fm->num_ids++;
5695 fm->ids = HeapAlloc( GetProcessHeap(), 0, fm->num_ids * sizeof(KNOWNFOLDERID) );
5696 if (!fm->ids)
5698 HeapFree( GetProcessHeap(), 0, fm );
5699 return E_OUTOFMEMORY;
5701 for (i = j = 0; i < sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]); i++)
5703 if (!IsEqualGUID( CSIDL_Data[i].id, &GUID_NULL ))
5705 fm->ids[j] = *CSIDL_Data[i].id;
5706 j++;
5709 TRACE("found %u known folders\n", fm->num_ids);
5710 *ppv = &fm->IKnownFolderManager_iface;
5712 TRACE("returning iface %p\n", *ppv);
5713 return S_OK;
5716 HRESULT WINAPI KnownFolderManager_Constructor( IUnknown *punk, REFIID riid, void **ppv )
5718 TRACE("%p, %s, %p\n", punk, debugstr_guid(riid), ppv);
5720 if (!ppv)
5721 return E_POINTER;
5722 if (punk)
5723 return CLASS_E_NOAGGREGATION;
5725 return foldermanager_create( ppv );
5728 HRESULT WINAPI SHGetKnownFolderIDList(REFKNOWNFOLDERID rfid, DWORD flags, HANDLE token, PIDLIST_ABSOLUTE *pidl)
5730 TRACE("%s, 0x%08x, %p, %p\n", debugstr_guid(rfid), flags, token, pidl);
5732 if (!pidl)
5733 return E_INVALIDARG;
5735 if (flags)
5736 FIXME("unsupported flags: 0x%08x\n", flags);
5738 if (token)
5739 FIXME("user token is not used.\n");
5741 *pidl = NULL;
5742 if (IsEqualIID(rfid, &FOLDERID_Desktop))
5743 *pidl = _ILCreateDesktop();
5744 else if (IsEqualIID(rfid, &FOLDERID_RecycleBinFolder))
5745 *pidl = _ILCreateBitBucket();
5746 else if (IsEqualIID(rfid, &FOLDERID_ComputerFolder))
5747 *pidl = _ILCreateMyComputer();
5748 else if (IsEqualIID(rfid, &FOLDERID_PrintersFolder))
5749 *pidl = _ILCreatePrinters();
5750 else if (IsEqualIID(rfid, &FOLDERID_ControlPanelFolder))
5751 *pidl = _ILCreateControlPanel();
5752 else if (IsEqualIID(rfid, &FOLDERID_NetworkFolder))
5753 *pidl = _ILCreateNetwork();
5754 else if (IsEqualIID(rfid, &FOLDERID_Documents))
5755 *pidl = _ILCreateMyDocuments();
5756 else
5758 DWORD attributes = 0;
5759 WCHAR *pathW;
5760 HRESULT hr;
5762 hr = SHGetKnownFolderPath(rfid, flags, token, &pathW);
5763 if (FAILED(hr))
5764 return hr;
5766 hr = SHILCreateFromPathW(pathW, pidl, &attributes);
5767 CoTaskMemFree(pathW);
5768 return hr;
5771 return *pidl ? S_OK : E_FAIL;
5774 HRESULT WINAPI SHGetKnownFolderItem(REFKNOWNFOLDERID rfid, KNOWN_FOLDER_FLAG flags, HANDLE hToken,
5775 REFIID riid, void **ppv)
5777 PIDLIST_ABSOLUTE pidl;
5778 HRESULT hr;
5780 TRACE("%s, 0x%08x, %p, %s, %p\n", debugstr_guid(rfid), flags, hToken, debugstr_guid(riid), ppv);
5782 hr = SHGetKnownFolderIDList(rfid, flags, hToken, &pidl);
5783 if (FAILED(hr))
5785 *ppv = NULL;
5786 return hr;
5789 hr = SHCreateItemFromIDList(pidl, riid, ppv);
5790 CoTaskMemFree(pidl);
5791 return hr;
5794 static void register_system_knownfolders(void)
5796 int i;
5797 for(i = 0; i < sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]); ++i){
5798 const CSIDL_DATA *folder = &CSIDL_Data[i];
5799 if(folder->pszName){
5800 KNOWNFOLDER_DEFINITION kfd;
5802 /* register_folder won't modify kfd, so cast away const instead of
5803 * reallocating */
5804 kfd.category = folder->category;
5805 kfd.pszName = (WCHAR*)folder->pszName;
5806 kfd.pszDescription = (WCHAR*)folder->pszDescription;
5807 memcpy(&kfd.fidParent, folder->fidParent, sizeof(KNOWNFOLDERID));
5808 kfd.pszRelativePath = (WCHAR*)folder->pszRelativePath;
5809 kfd.pszParsingName = (WCHAR*)folder->pszParsingName;
5810 kfd.pszTooltip = (WCHAR*)folder->pszTooltip;
5811 kfd.pszLocalizedName = (WCHAR*)folder->pszLocalizedName;
5812 kfd.pszIcon = (WCHAR*)folder->pszIcon;
5813 kfd.pszSecurity = (WCHAR*)folder->pszSecurity;
5814 kfd.dwAttributes = folder->dwAttributes;
5815 kfd.kfdFlags = folder->kfdFlags;
5816 memcpy(&kfd.ftidType, folder->ftidType, sizeof(FOLDERTYPEID));
5818 register_folder(folder->id, &kfd);
5823 HRESULT SHELL_RegisterShellFolders(void)
5825 HRESULT hr;
5827 /* Set up '$HOME' targeted symlinks for 'My Documents', 'My Pictures',
5828 * 'My Videos', 'My Music' and 'Desktop' in advance, so that the
5829 * _SHRegister*ShellFolders() functions will find everything nice and clean
5830 * and thus will not attempt to create them in the profile directory. */
5831 _SHCreateSymbolicLinks();
5833 hr = _SHRegisterUserShellFolders(TRUE);
5834 if (SUCCEEDED(hr))
5835 hr = _SHRegisterUserShellFolders(FALSE);
5836 if (SUCCEEDED(hr))
5837 hr = _SHRegisterCommonShellFolders();
5838 if (SUCCEEDED(hr))
5839 hr = create_extra_folders();
5840 if (SUCCEEDED(hr))
5841 hr = set_folder_attributes();
5842 if (SUCCEEDED(hr))
5843 register_system_knownfolders();
5844 return hr;