storage.dll16: Fix get_nth_next_small_blocknr.
[wine.git] / dlls / shell32 / shellpath.c
blob8569b5393fcaa817a1ae4cd4370dd4936edfb6b0
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 HKEY userShellFolderKey, shellFolderKey;
3213 DWORD dwType, dwPathLen;
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 dwPathLen = MAX_PATH * sizeof(WCHAR);
3249 if (!RegQueryValueExW(userShellFolderKey, value, NULL, &dwType,
3250 (LPBYTE)path, &dwPathLen) && (dwType == REG_EXPAND_SZ || dwType == REG_SZ))
3252 LONG ret;
3254 path[dwPathLen / sizeof(WCHAR)] = '\0';
3255 if (dwType == REG_EXPAND_SZ && path[0] == '%')
3257 WCHAR szTemp[MAX_PATH];
3259 _SHExpandEnvironmentStrings(path, szTemp);
3260 lstrcpynW(path, szTemp, MAX_PATH);
3262 ret = RegSetValueExW(shellFolderKey, value, 0, REG_SZ, (LPBYTE)path,
3263 (strlenW(path) + 1) * sizeof(WCHAR));
3264 if (ret != ERROR_SUCCESS)
3265 hr = HRESULT_FROM_WIN32(ret);
3266 else
3267 hr = S_OK;
3269 else
3270 hr = E_FAIL;
3271 RegCloseKey(shellFolderKey);
3272 RegCloseKey(userShellFolderKey);
3273 TRACE("returning 0x%08x\n", hr);
3274 return hr;
3277 /* Gets a 'semi-expanded' default value of the CSIDL with index folder into
3278 * pszPath, based on the entries in CSIDL_Data. By semi-expanded, I mean:
3279 * - The entry's szDefaultPath may be either a string value or an integer
3280 * resource identifier. In the latter case, the string value of the resource
3281 * is written.
3282 * - Depending on the entry's type, the path may begin with an (unexpanded)
3283 * environment variable name. The caller is responsible for expanding
3284 * environment strings if so desired.
3285 * The types that are prepended with environment variables are:
3286 * CSIDL_Type_User: %USERPROFILE%
3287 * CSIDL_Type_AllUsers: %ALLUSERSPROFILE%
3288 * CSIDL_Type_CurrVer: %SystemDrive%
3289 * (Others might make sense too, but as yet are unneeded.)
3291 static HRESULT _SHGetDefaultValue(BYTE folder, LPWSTR pszPath)
3293 HRESULT hr;
3294 WCHAR resourcePath[MAX_PATH];
3295 LPCWSTR pDefaultPath = NULL;
3297 TRACE("0x%02x,%p\n", folder, pszPath);
3299 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
3300 return E_INVALIDARG;
3301 if (!pszPath)
3302 return E_INVALIDARG;
3304 if (!is_win64)
3306 BOOL is_wow64;
3308 switch (folder)
3310 case CSIDL_PROGRAM_FILES:
3311 case CSIDL_PROGRAM_FILESX86:
3312 IsWow64Process( GetCurrentProcess(), &is_wow64 );
3313 folder = is_wow64 ? CSIDL_PROGRAM_FILESX86 : CSIDL_PROGRAM_FILES;
3314 break;
3315 case CSIDL_PROGRAM_FILES_COMMON:
3316 case CSIDL_PROGRAM_FILES_COMMONX86:
3317 IsWow64Process( GetCurrentProcess(), &is_wow64 );
3318 folder = is_wow64 ? CSIDL_PROGRAM_FILES_COMMONX86 : CSIDL_PROGRAM_FILES_COMMON;
3319 break;
3323 if (CSIDL_Data[folder].szDefaultPath &&
3324 IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath))
3326 if (LoadStringW(shell32_hInstance,
3327 LOWORD(CSIDL_Data[folder].szDefaultPath), resourcePath, MAX_PATH))
3329 hr = S_OK;
3330 pDefaultPath = resourcePath;
3332 else
3334 FIXME("(%d,%s), LoadString failed, missing translation?\n", folder,
3335 debugstr_w(pszPath));
3336 hr = E_FAIL;
3339 else
3341 hr = S_OK;
3342 pDefaultPath = CSIDL_Data[folder].szDefaultPath;
3344 if (SUCCEEDED(hr))
3346 switch (CSIDL_Data[folder].type)
3348 case CSIDL_Type_User:
3349 strcpyW(pszPath, UserProfileW);
3350 break;
3351 case CSIDL_Type_AllUsers:
3352 strcpyW(pszPath, AllUsersProfileW);
3353 break;
3354 case CSIDL_Type_CurrVer:
3355 strcpyW(pszPath, SystemDriveW);
3356 break;
3357 default:
3358 ; /* no corresponding env. var, do nothing */
3360 if (pDefaultPath)
3362 PathAddBackslashW(pszPath);
3363 strcatW(pszPath, pDefaultPath);
3366 TRACE("returning 0x%08x\n", hr);
3367 return hr;
3370 /* Gets the (unexpanded) value of the folder with index folder into pszPath.
3371 * The folder's type is assumed to be CSIDL_Type_CurrVer. Its default value
3372 * can be overridden in the HKLM\\szCurrentVersion key.
3373 * If dwFlags has SHGFP_TYPE_DEFAULT set or if the value isn't overridden in
3374 * the registry, uses _SHGetDefaultValue to get the value.
3376 static HRESULT _SHGetCurrentVersionPath(DWORD dwFlags, BYTE folder,
3377 LPWSTR pszPath)
3379 HRESULT hr;
3381 TRACE("0x%08x,0x%02x,%p\n", dwFlags, folder, pszPath);
3383 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
3384 return E_INVALIDARG;
3385 if (CSIDL_Data[folder].type != CSIDL_Type_CurrVer)
3386 return E_INVALIDARG;
3387 if (!pszPath)
3388 return E_INVALIDARG;
3390 if (dwFlags & SHGFP_TYPE_DEFAULT)
3391 hr = _SHGetDefaultValue(folder, pszPath);
3392 else
3394 HKEY hKey;
3396 if (RegCreateKeyW(HKEY_LOCAL_MACHINE, szCurrentVersion, &hKey))
3397 hr = E_FAIL;
3398 else
3400 DWORD dwType, dwPathLen = MAX_PATH * sizeof(WCHAR);
3402 if (RegQueryValueExW(hKey, CSIDL_Data[folder].szValueName, NULL,
3403 &dwType, (LPBYTE)pszPath, &dwPathLen) ||
3404 (dwType != REG_SZ && dwType != REG_EXPAND_SZ))
3406 hr = _SHGetDefaultValue(folder, pszPath);
3407 dwType = REG_EXPAND_SZ;
3408 switch (folder)
3410 case CSIDL_PROGRAM_FILESX86:
3411 case CSIDL_PROGRAM_FILES_COMMONX86:
3412 /* these two should never be set on 32-bit setups */
3413 if (!is_win64)
3415 BOOL is_wow64;
3416 IsWow64Process( GetCurrentProcess(), &is_wow64 );
3417 if (!is_wow64) break;
3419 /* fall through */
3420 default:
3421 RegSetValueExW(hKey, CSIDL_Data[folder].szValueName, 0, dwType,
3422 (LPBYTE)pszPath, (strlenW(pszPath)+1)*sizeof(WCHAR));
3425 else
3427 pszPath[dwPathLen / sizeof(WCHAR)] = '\0';
3428 hr = S_OK;
3430 RegCloseKey(hKey);
3433 TRACE("returning 0x%08x (output path is %s)\n", hr, debugstr_w(pszPath));
3434 return hr;
3437 static LPWSTR _GetUserSidStringFromToken(HANDLE Token)
3439 char InfoBuffer[64];
3440 PTOKEN_USER UserInfo;
3441 DWORD InfoSize;
3442 LPWSTR SidStr;
3444 UserInfo = (PTOKEN_USER) InfoBuffer;
3445 if (! GetTokenInformation(Token, TokenUser, InfoBuffer, sizeof(InfoBuffer),
3446 &InfoSize))
3448 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
3449 return NULL;
3450 UserInfo = HeapAlloc(GetProcessHeap(), 0, InfoSize);
3451 if (UserInfo == NULL)
3452 return NULL;
3453 if (! GetTokenInformation(Token, TokenUser, UserInfo, InfoSize,
3454 &InfoSize))
3456 HeapFree(GetProcessHeap(), 0, UserInfo);
3457 return NULL;
3461 if (! ConvertSidToStringSidW(UserInfo->User.Sid, &SidStr))
3462 SidStr = NULL;
3464 if (UserInfo != (PTOKEN_USER) InfoBuffer)
3465 HeapFree(GetProcessHeap(), 0, UserInfo);
3467 return SidStr;
3470 /* Gets the user's path (unexpanded) for the CSIDL with index folder:
3471 * If SHGFP_TYPE_DEFAULT is set, calls _SHGetDefaultValue for it. Otherwise
3472 * calls _SHGetUserShellFolderPath for it. Where it looks depends on hToken:
3473 * - if hToken is -1, looks in HKEY_USERS\.Default
3474 * - otherwise looks first in HKEY_CURRENT_USER, followed by HKEY_LOCAL_MACHINE
3475 * if HKEY_CURRENT_USER doesn't contain any entries. If both fail, finally
3476 * calls _SHGetDefaultValue for it.
3478 static HRESULT _SHGetUserProfilePath(HANDLE hToken, DWORD dwFlags, BYTE folder,
3479 LPWSTR pszPath)
3481 const WCHAR *szValueName;
3482 WCHAR buffer[40];
3483 HRESULT hr;
3485 TRACE("%p,0x%08x,0x%02x,%p\n", hToken, dwFlags, folder, pszPath);
3487 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
3488 return E_INVALIDARG;
3489 if (CSIDL_Data[folder].type != CSIDL_Type_User)
3490 return E_INVALIDARG;
3491 if (!pszPath)
3492 return E_INVALIDARG;
3494 if (dwFlags & SHGFP_TYPE_DEFAULT)
3496 if (hToken != NULL && hToken != (HANDLE)-1)
3498 FIXME("unsupported for user other than current or default\n");
3499 return E_FAIL;
3501 hr = _SHGetDefaultValue(folder, pszPath);
3503 else
3505 LPCWSTR userPrefix = NULL;
3506 HKEY hRootKey;
3508 if (hToken == (HANDLE)-1)
3510 hRootKey = HKEY_USERS;
3511 userPrefix = DefaultW;
3513 else if (hToken == NULL)
3514 hRootKey = HKEY_CURRENT_USER;
3515 else
3517 hRootKey = HKEY_USERS;
3518 userPrefix = _GetUserSidStringFromToken(hToken);
3519 if (userPrefix == NULL)
3521 hr = E_FAIL;
3522 goto error;
3526 /* For CSIDL_Type_User we also use the GUID if no szValueName is provided */
3527 szValueName = CSIDL_Data[folder].szValueName;
3528 if (!szValueName)
3530 StringFromGUID2( CSIDL_Data[folder].id, buffer, 39 );
3531 szValueName = &buffer[0];
3534 hr = _SHGetUserShellFolderPath(hRootKey, userPrefix, szValueName, pszPath);
3535 if (FAILED(hr) && hRootKey != HKEY_LOCAL_MACHINE)
3536 hr = _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE, NULL, szValueName, pszPath);
3537 if (FAILED(hr))
3538 hr = _SHGetDefaultValue(folder, pszPath);
3539 if (userPrefix != NULL && userPrefix != DefaultW)
3540 LocalFree((HLOCAL) userPrefix);
3542 error:
3543 TRACE("returning 0x%08x (output path is %s)\n", hr, debugstr_w(pszPath));
3544 return hr;
3547 /* Gets the (unexpanded) path for the CSIDL with index folder. If dwFlags has
3548 * SHGFP_TYPE_DEFAULT set, calls _SHGetDefaultValue. Otherwise calls
3549 * _SHGetUserShellFolderPath for it, looking only in HKEY_LOCAL_MACHINE.
3550 * If this fails, falls back to _SHGetDefaultValue.
3552 static HRESULT _SHGetAllUsersProfilePath(DWORD dwFlags, BYTE folder,
3553 LPWSTR pszPath)
3555 HRESULT hr;
3557 TRACE("0x%08x,0x%02x,%p\n", dwFlags, folder, pszPath);
3559 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
3560 return E_INVALIDARG;
3561 if (CSIDL_Data[folder].type != CSIDL_Type_AllUsers)
3562 return E_INVALIDARG;
3563 if (!pszPath)
3564 return E_INVALIDARG;
3566 if (dwFlags & SHGFP_TYPE_DEFAULT)
3567 hr = _SHGetDefaultValue(folder, pszPath);
3568 else
3570 hr = _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE, NULL,
3571 CSIDL_Data[folder].szValueName, pszPath);
3572 if (FAILED(hr))
3573 hr = _SHGetDefaultValue(folder, pszPath);
3575 TRACE("returning 0x%08x (output path is %s)\n", hr, debugstr_w(pszPath));
3576 return hr;
3579 static HRESULT _SHOpenProfilesKey(PHKEY pKey)
3581 LONG lRet;
3582 DWORD disp;
3584 lRet = RegCreateKeyExW(HKEY_LOCAL_MACHINE, ProfileListW, 0, NULL, 0,
3585 KEY_ALL_ACCESS, NULL, pKey, &disp);
3586 return HRESULT_FROM_WIN32(lRet);
3589 /* Reads the value named szValueName from the key profilesKey (assumed to be
3590 * opened by _SHOpenProfilesKey) into szValue, which is assumed to be MAX_PATH
3591 * WCHARs in length. If it doesn't exist, returns szDefault (and saves
3592 * szDefault to the registry).
3594 static HRESULT _SHGetProfilesValue(HKEY profilesKey, LPCWSTR szValueName,
3595 LPWSTR szValue, LPCWSTR szDefault)
3597 HRESULT hr;
3598 DWORD type, dwPathLen = MAX_PATH * sizeof(WCHAR);
3599 LONG lRet;
3601 TRACE("%p,%s,%p,%s\n", profilesKey, debugstr_w(szValueName), szValue,
3602 debugstr_w(szDefault));
3603 lRet = RegQueryValueExW(profilesKey, szValueName, NULL, &type,
3604 (LPBYTE)szValue, &dwPathLen);
3605 if (!lRet && (type == REG_SZ || type == REG_EXPAND_SZ) && dwPathLen
3606 && *szValue)
3608 dwPathLen /= sizeof(WCHAR);
3609 szValue[dwPathLen] = '\0';
3610 hr = S_OK;
3612 else
3614 /* Missing or invalid value, set a default */
3615 lstrcpynW(szValue, szDefault, MAX_PATH);
3616 TRACE("Setting missing value %s to %s\n", debugstr_w(szValueName),
3617 debugstr_w(szValue));
3618 lRet = RegSetValueExW(profilesKey, szValueName, 0, REG_EXPAND_SZ,
3619 (LPBYTE)szValue,
3620 (strlenW(szValue) + 1) * sizeof(WCHAR));
3621 if (lRet)
3622 hr = HRESULT_FROM_WIN32(lRet);
3623 else
3624 hr = S_OK;
3626 TRACE("returning 0x%08x (output value is %s)\n", hr, debugstr_w(szValue));
3627 return hr;
3630 /* Attempts to expand environment variables from szSrc into szDest, which is
3631 * assumed to be MAX_PATH characters in length. Before referring to the
3632 * environment, handles a few variables directly, because the environment
3633 * variables may not be set when this is called (as during Wine's installation
3634 * when default values are being written to the registry).
3635 * The directly handled environment variables, and their source, are:
3636 * - ALLUSERSPROFILE, USERPROFILE: reads from the registry
3637 * - SystemDrive: uses GetSystemDirectoryW and uses the drive portion of its
3638 * path
3639 * If one of the directly handled environment variables is expanded, only
3640 * expands a single variable, and only in the beginning of szSrc.
3642 static HRESULT _SHExpandEnvironmentStrings(LPCWSTR szSrc, LPWSTR szDest)
3644 HRESULT hr;
3645 WCHAR szTemp[MAX_PATH], szProfilesPrefix[MAX_PATH] = { 0 };
3646 HKEY key = NULL;
3648 TRACE("%s, %p\n", debugstr_w(szSrc), szDest);
3650 if (!szSrc || !szDest) return E_INVALIDARG;
3652 /* short-circuit if there's nothing to expand */
3653 if (szSrc[0] != '%')
3655 strcpyW(szDest, szSrc);
3656 hr = S_OK;
3657 goto end;
3659 /* Get the profile prefix, we'll probably be needing it */
3660 hr = _SHOpenProfilesKey(&key);
3661 if (SUCCEEDED(hr))
3663 WCHAR def_val[MAX_PATH];
3665 /* get the system drive */
3666 GetSystemDirectoryW(def_val, MAX_PATH);
3667 if (def_val[1] == ':') strcpyW( def_val + 3, szDefaultProfileDirW );
3668 else FIXME("non-drive system paths unsupported\n");
3670 hr = _SHGetProfilesValue(key, ProfilesDirectoryW, szProfilesPrefix, def_val );
3673 *szDest = 0;
3674 strcpyW(szTemp, szSrc);
3675 while (SUCCEEDED(hr) && szTemp[0] == '%')
3677 if (!strncmpiW(szTemp, AllUsersProfileW, strlenW(AllUsersProfileW)))
3679 WCHAR szAllUsers[MAX_PATH];
3681 strcpyW(szDest, szProfilesPrefix);
3682 hr = _SHGetProfilesValue(key, AllUsersProfileValueW,
3683 szAllUsers, AllUsersW);
3684 PathAppendW(szDest, szAllUsers);
3685 PathAppendW(szDest, szTemp + strlenW(AllUsersProfileW));
3687 else if (!strncmpiW(szTemp, UserProfileW, strlenW(UserProfileW)))
3689 WCHAR userName[MAX_PATH];
3690 DWORD userLen = MAX_PATH;
3692 strcpyW(szDest, szProfilesPrefix);
3693 GetUserNameW(userName, &userLen);
3694 PathAppendW(szDest, userName);
3695 PathAppendW(szDest, szTemp + strlenW(UserProfileW));
3697 else if (!strncmpiW(szTemp, SystemDriveW, strlenW(SystemDriveW)))
3699 GetSystemDirectoryW(szDest, MAX_PATH);
3700 if (szDest[1] != ':')
3702 FIXME("non-drive system paths unsupported\n");
3703 hr = E_FAIL;
3705 else
3707 strcpyW(szDest + 3, szTemp + strlenW(SystemDriveW) + 1);
3708 hr = S_OK;
3711 else
3713 DWORD ret = ExpandEnvironmentStringsW(szSrc, szDest, MAX_PATH);
3715 if (ret > MAX_PATH)
3716 hr = E_NOT_SUFFICIENT_BUFFER;
3717 else if (ret == 0)
3718 hr = HRESULT_FROM_WIN32(GetLastError());
3719 else
3720 hr = S_OK;
3722 if (SUCCEEDED(hr) && szDest[0] == '%')
3723 strcpyW(szTemp, szDest);
3724 else
3726 /* terminate loop */
3727 szTemp[0] = '\0';
3730 end:
3731 if (key)
3732 RegCloseKey(key);
3733 TRACE("returning 0x%08x (input was %s, output is %s)\n", hr,
3734 debugstr_w(szSrc), debugstr_w(szDest));
3735 return hr;
3738 /*************************************************************************
3739 * SHGetFolderPathW [SHELL32.@]
3741 * Convert nFolder to path.
3743 * RETURNS
3744 * Success: S_OK
3745 * Failure: standard HRESULT error codes.
3747 * NOTES
3748 * Most values can be overridden in either
3749 * HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
3750 * or in the same location in HKLM.
3751 * The "Shell Folders" registry key was used in NT4 and earlier systems.
3752 * Beginning with Windows 2000, the "User Shell Folders" key is used, so
3753 * changes made to it are made to the former key too. This synchronization is
3754 * done on-demand: not until someone requests the value of one of these paths
3755 * (by calling one of the SHGet functions) is the value synchronized.
3756 * Furthermore, the HKCU paths take precedence over the HKLM paths.
3758 HRESULT WINAPI SHGetFolderPathW(
3759 HWND hwndOwner, /* [I] owner window */
3760 int nFolder, /* [I] CSIDL identifying the folder */
3761 HANDLE hToken, /* [I] access token */
3762 DWORD dwFlags, /* [I] which path to return */
3763 LPWSTR pszPath) /* [O] converted path */
3765 HRESULT hr = SHGetFolderPathAndSubDirW(hwndOwner, nFolder, hToken, dwFlags, NULL, pszPath);
3766 if(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) == hr)
3767 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
3768 return hr;
3771 HRESULT WINAPI SHGetFolderPathAndSubDirA(
3772 HWND hwndOwner, /* [I] owner window */
3773 int nFolder, /* [I] CSIDL identifying the folder */
3774 HANDLE hToken, /* [I] access token */
3775 DWORD dwFlags, /* [I] which path to return */
3776 LPCSTR pszSubPath, /* [I] sub directory of the specified folder */
3777 LPSTR pszPath) /* [O] converted path */
3779 int length;
3780 HRESULT hr = S_OK;
3781 LPWSTR pszSubPathW = NULL;
3782 LPWSTR pszPathW = NULL;
3783 TRACE("%08x,%08x,%s\n",nFolder, dwFlags, debugstr_w(pszSubPathW));
3785 if(pszPath) {
3786 pszPathW = HeapAlloc(GetProcessHeap(), 0, MAX_PATH * sizeof(WCHAR));
3787 if(!pszPathW) {
3788 hr = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
3789 goto cleanup;
3792 TRACE("%08x,%08x,%s\n",nFolder, dwFlags, debugstr_w(pszSubPathW));
3794 /* SHGetFolderPathAndSubDirW does not distinguish if pszSubPath isn't
3795 * set (null), or an empty string.therefore call it without the parameter set
3796 * if pszSubPath is an empty string
3798 if (pszSubPath && pszSubPath[0]) {
3799 length = MultiByteToWideChar(CP_ACP, 0, pszSubPath, -1, NULL, 0);
3800 pszSubPathW = HeapAlloc(GetProcessHeap(), 0, length * sizeof(WCHAR));
3801 if(!pszSubPathW) {
3802 hr = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
3803 goto cleanup;
3805 MultiByteToWideChar(CP_ACP, 0, pszSubPath, -1, pszSubPathW, length);
3808 hr = SHGetFolderPathAndSubDirW(hwndOwner, nFolder, hToken, dwFlags, pszSubPathW, pszPathW);
3810 if (SUCCEEDED(hr) && pszPath)
3811 WideCharToMultiByte(CP_ACP, 0, pszPathW, -1, pszPath, MAX_PATH, NULL, NULL);
3813 cleanup:
3814 HeapFree(GetProcessHeap(), 0, pszPathW);
3815 HeapFree(GetProcessHeap(), 0, pszSubPathW);
3816 return hr;
3819 /*************************************************************************
3820 * SHGetFolderPathAndSubDirW [SHELL32.@]
3822 HRESULT WINAPI SHGetFolderPathAndSubDirW(
3823 HWND hwndOwner, /* [I] owner window */
3824 int nFolder, /* [I] CSIDL identifying the folder */
3825 HANDLE hToken, /* [I] access token */
3826 DWORD dwFlags, /* [I] which path to return */
3827 LPCWSTR pszSubPath,/* [I] sub directory of the specified folder */
3828 LPWSTR pszPath) /* [O] converted path */
3830 HRESULT hr;
3831 WCHAR szBuildPath[MAX_PATH], szTemp[MAX_PATH];
3832 DWORD folder = nFolder & CSIDL_FOLDER_MASK;
3833 CSIDL_Type type;
3834 int ret;
3836 TRACE("%p,%p,nFolder=0x%04x,%s\n", hwndOwner,pszPath,nFolder,debugstr_w(pszSubPath));
3838 /* Windows always NULL-terminates the resulting path regardless of success
3839 * or failure, so do so first
3841 if (pszPath)
3842 *pszPath = '\0';
3844 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
3845 return E_INVALIDARG;
3846 if ((SHGFP_TYPE_CURRENT != dwFlags) && (SHGFP_TYPE_DEFAULT != dwFlags))
3847 return E_INVALIDARG;
3848 szTemp[0] = 0;
3849 type = CSIDL_Data[folder].type;
3850 switch (type)
3852 case CSIDL_Type_Disallowed:
3853 hr = E_INVALIDARG;
3854 break;
3855 case CSIDL_Type_NonExistent:
3856 hr = S_FALSE;
3857 break;
3858 case CSIDL_Type_WindowsPath:
3859 GetWindowsDirectoryW(szTemp, MAX_PATH);
3860 if (CSIDL_Data[folder].szDefaultPath &&
3861 !IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath) &&
3862 *CSIDL_Data[folder].szDefaultPath)
3864 PathAddBackslashW(szTemp);
3865 strcatW(szTemp, CSIDL_Data[folder].szDefaultPath);
3867 hr = S_OK;
3868 break;
3869 case CSIDL_Type_SystemPath:
3870 GetSystemDirectoryW(szTemp, MAX_PATH);
3871 if (CSIDL_Data[folder].szDefaultPath &&
3872 !IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath) &&
3873 *CSIDL_Data[folder].szDefaultPath)
3875 PathAddBackslashW(szTemp);
3876 strcatW(szTemp, CSIDL_Data[folder].szDefaultPath);
3878 hr = S_OK;
3879 break;
3880 case CSIDL_Type_SystemX86Path:
3881 if (!GetSystemWow64DirectoryW(szTemp, MAX_PATH)) GetSystemDirectoryW(szTemp, MAX_PATH);
3882 if (CSIDL_Data[folder].szDefaultPath &&
3883 !IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath) &&
3884 *CSIDL_Data[folder].szDefaultPath)
3886 PathAddBackslashW(szTemp);
3887 strcatW(szTemp, CSIDL_Data[folder].szDefaultPath);
3889 hr = S_OK;
3890 break;
3891 case CSIDL_Type_CurrVer:
3892 hr = _SHGetCurrentVersionPath(dwFlags, folder, szTemp);
3893 break;
3894 case CSIDL_Type_User:
3895 hr = _SHGetUserProfilePath(hToken, dwFlags, folder, szTemp);
3896 break;
3897 case CSIDL_Type_AllUsers:
3898 hr = _SHGetAllUsersProfilePath(dwFlags, folder, szTemp);
3899 break;
3900 default:
3901 FIXME("bogus type %d, please fix\n", type);
3902 hr = E_INVALIDARG;
3903 break;
3906 /* Expand environment strings if necessary */
3907 if (*szTemp == '%')
3908 hr = _SHExpandEnvironmentStrings(szTemp, szBuildPath);
3909 else
3910 strcpyW(szBuildPath, szTemp);
3912 if (FAILED(hr)) goto end;
3914 if(pszSubPath) {
3915 /* make sure the new path does not exceed the buffer length
3916 * and remember to backslash and terminate it */
3917 if(MAX_PATH < (lstrlenW(szBuildPath) + lstrlenW(pszSubPath) + 2)) {
3918 hr = HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE);
3919 goto end;
3921 PathAppendW(szBuildPath, pszSubPath);
3922 PathRemoveBackslashW(szBuildPath);
3924 /* Copy the path if it's available before we might return */
3925 if (SUCCEEDED(hr) && pszPath)
3926 strcpyW(pszPath, szBuildPath);
3928 /* if we don't care about existing directories we are ready */
3929 if(nFolder & CSIDL_FLAG_DONT_VERIFY) goto end;
3931 if (PathFileExistsW(szBuildPath)) goto end;
3933 /* not existing but we are not allowed to create it. The return value
3934 * is verified against shell32 version 6.0.
3936 if (!(nFolder & CSIDL_FLAG_CREATE))
3938 hr = HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND);
3939 goto end;
3942 /* create directory/directories */
3943 ret = SHCreateDirectoryExW(hwndOwner, szBuildPath, NULL);
3944 if (ret && ret != ERROR_ALREADY_EXISTS)
3946 ERR("Failed to create directory %s.\n", debugstr_w(szBuildPath));
3947 hr = E_FAIL;
3948 goto end;
3951 TRACE("Created missing system directory %s\n", debugstr_w(szBuildPath));
3952 end:
3953 TRACE("returning 0x%08x (final path is %s)\n", hr, debugstr_w(szBuildPath));
3954 return hr;
3957 /*************************************************************************
3958 * SHGetFolderPathA [SHELL32.@]
3960 * See SHGetFolderPathW.
3962 HRESULT WINAPI SHGetFolderPathA(
3963 HWND hwndOwner,
3964 int nFolder,
3965 HANDLE hToken,
3966 DWORD dwFlags,
3967 LPSTR pszPath)
3969 WCHAR szTemp[MAX_PATH];
3970 HRESULT hr;
3972 TRACE("%p,%p,nFolder=0x%04x\n",hwndOwner,pszPath,nFolder);
3974 if (pszPath)
3975 *pszPath = '\0';
3976 hr = SHGetFolderPathW(hwndOwner, nFolder, hToken, dwFlags, szTemp);
3977 if (SUCCEEDED(hr) && pszPath)
3978 WideCharToMultiByte(CP_ACP, 0, szTemp, -1, pszPath, MAX_PATH, NULL,
3979 NULL);
3981 return hr;
3984 /* For each folder in folders, if its value has not been set in the registry,
3985 * calls _SHGetUserProfilePath or _SHGetAllUsersProfilePath (depending on the
3986 * folder's type) to get the unexpanded value first.
3987 * Writes the unexpanded value to User Shell Folders, and queries it with
3988 * SHGetFolderPathW to force the creation of the directory if it doesn't
3989 * already exist. SHGetFolderPathW also returns the expanded value, which
3990 * this then writes to Shell Folders.
3992 static HRESULT _SHRegisterFolders(HKEY hRootKey, HANDLE hToken,
3993 LPCWSTR szUserShellFolderPath, LPCWSTR szShellFolderPath, const UINT folders[],
3994 UINT foldersLen)
3996 const WCHAR *szValueName;
3997 WCHAR buffer[40];
3998 UINT i;
3999 WCHAR path[MAX_PATH];
4000 HRESULT hr = S_OK;
4001 HKEY hUserKey = NULL, hKey = NULL;
4002 DWORD dwType, dwPathLen;
4003 LONG ret;
4005 TRACE("%p,%p,%s,%p,%u\n", hRootKey, hToken,
4006 debugstr_w(szUserShellFolderPath), folders, foldersLen);
4008 ret = RegCreateKeyW(hRootKey, szUserShellFolderPath, &hUserKey);
4009 if (ret)
4010 hr = HRESULT_FROM_WIN32(ret);
4011 else
4013 ret = RegCreateKeyW(hRootKey, szShellFolderPath, &hKey);
4014 if (ret)
4015 hr = HRESULT_FROM_WIN32(ret);
4017 for (i = 0; SUCCEEDED(hr) && i < foldersLen; i++)
4019 dwPathLen = MAX_PATH * sizeof(WCHAR);
4021 /* For CSIDL_Type_User we also use the GUID if no szValueName is provided */
4022 szValueName = CSIDL_Data[folders[i]].szValueName;
4023 if (!szValueName && CSIDL_Data[folders[i]].type == CSIDL_Type_User)
4025 StringFromGUID2( CSIDL_Data[folders[i]].id, buffer, 39 );
4026 szValueName = &buffer[0];
4029 if (RegQueryValueExW(hUserKey, szValueName, NULL,
4030 &dwType, (LPBYTE)path, &dwPathLen) || (dwType != REG_SZ &&
4031 dwType != REG_EXPAND_SZ))
4033 *path = '\0';
4034 if (CSIDL_Data[folders[i]].type == CSIDL_Type_User)
4035 _SHGetUserProfilePath(hToken, SHGFP_TYPE_DEFAULT, folders[i],
4036 path);
4037 else if (CSIDL_Data[folders[i]].type == CSIDL_Type_AllUsers)
4038 _SHGetAllUsersProfilePath(SHGFP_TYPE_DEFAULT, folders[i], path);
4039 else if (CSIDL_Data[folders[i]].type == CSIDL_Type_WindowsPath)
4041 GetWindowsDirectoryW(path, MAX_PATH);
4042 if (CSIDL_Data[folders[i]].szDefaultPath &&
4043 !IS_INTRESOURCE(CSIDL_Data[folders[i]].szDefaultPath))
4045 PathAddBackslashW(path);
4046 strcatW(path, CSIDL_Data[folders[i]].szDefaultPath);
4049 else
4050 hr = E_FAIL;
4051 if (*path)
4053 ret = RegSetValueExW(hUserKey, szValueName, 0, REG_EXPAND_SZ,
4054 (LPBYTE)path, (strlenW(path) + 1) * sizeof(WCHAR));
4055 if (ret)
4056 hr = HRESULT_FROM_WIN32(ret);
4057 else
4059 hr = SHGetFolderPathW(NULL, folders[i] | CSIDL_FLAG_CREATE,
4060 hToken, SHGFP_TYPE_DEFAULT, path);
4061 ret = RegSetValueExW(hKey, szValueName, 0, REG_SZ,
4062 (LPBYTE)path, (strlenW(path) + 1) * sizeof(WCHAR));
4063 if (ret)
4064 hr = HRESULT_FROM_WIN32(ret);
4069 if (hUserKey)
4070 RegCloseKey(hUserKey);
4071 if (hKey)
4072 RegCloseKey(hKey);
4074 TRACE("returning 0x%08x\n", hr);
4075 return hr;
4078 static HRESULT _SHRegisterUserShellFolders(BOOL bDefault)
4080 static const UINT folders[] = {
4081 CSIDL_PROGRAMS,
4082 CSIDL_PERSONAL,
4083 CSIDL_FAVORITES,
4084 CSIDL_APPDATA,
4085 CSIDL_STARTUP,
4086 CSIDL_RECENT,
4087 CSIDL_SENDTO,
4088 CSIDL_STARTMENU,
4089 CSIDL_MYMUSIC,
4090 CSIDL_MYVIDEO,
4091 CSIDL_DESKTOPDIRECTORY,
4092 CSIDL_NETHOOD,
4093 CSIDL_TEMPLATES,
4094 CSIDL_PRINTHOOD,
4095 CSIDL_LOCAL_APPDATA,
4096 CSIDL_INTERNET_CACHE,
4097 CSIDL_COOKIES,
4098 CSIDL_HISTORY,
4099 CSIDL_MYPICTURES,
4100 CSIDL_FONTS,
4101 CSIDL_ADMINTOOLS,
4102 CSIDL_CONTACTS,
4103 CSIDL_DOWNLOADS,
4104 CSIDL_LINKS,
4105 CSIDL_APPDATA_LOCALLOW,
4106 CSIDL_SAVED_GAMES,
4107 CSIDL_SEARCHES
4109 WCHAR userShellFolderPath[MAX_PATH], shellFolderPath[MAX_PATH];
4110 LPCWSTR pUserShellFolderPath, pShellFolderPath;
4111 HRESULT hr = S_OK;
4112 HKEY hRootKey;
4113 HANDLE hToken;
4115 TRACE("%s\n", bDefault ? "TRUE" : "FALSE");
4116 if (bDefault)
4118 hToken = (HANDLE)-1;
4119 hRootKey = HKEY_USERS;
4120 strcpyW(userShellFolderPath, DefaultW);
4121 PathAddBackslashW(userShellFolderPath);
4122 strcatW(userShellFolderPath, szSHUserFolders);
4123 pUserShellFolderPath = userShellFolderPath;
4124 strcpyW(shellFolderPath, DefaultW);
4125 PathAddBackslashW(shellFolderPath);
4126 strcatW(shellFolderPath, szSHFolders);
4127 pShellFolderPath = shellFolderPath;
4129 else
4131 hToken = NULL;
4132 hRootKey = HKEY_CURRENT_USER;
4133 pUserShellFolderPath = szSHUserFolders;
4134 pShellFolderPath = szSHFolders;
4137 hr = _SHRegisterFolders(hRootKey, hToken, pUserShellFolderPath,
4138 pShellFolderPath, folders, sizeof(folders) / sizeof(folders[0]));
4139 TRACE("returning 0x%08x\n", hr);
4140 return hr;
4143 static HRESULT _SHRegisterCommonShellFolders(void)
4145 static const UINT folders[] = {
4146 CSIDL_COMMON_STARTMENU,
4147 CSIDL_COMMON_PROGRAMS,
4148 CSIDL_COMMON_STARTUP,
4149 CSIDL_COMMON_DESKTOPDIRECTORY,
4150 CSIDL_COMMON_FAVORITES,
4151 CSIDL_COMMON_APPDATA,
4152 CSIDL_COMMON_TEMPLATES,
4153 CSIDL_COMMON_DOCUMENTS,
4154 CSIDL_COMMON_ADMINTOOLS,
4155 CSIDL_COMMON_MUSIC,
4156 CSIDL_COMMON_PICTURES,
4157 CSIDL_COMMON_VIDEO,
4159 HRESULT hr;
4161 TRACE("\n");
4162 hr = _SHRegisterFolders(HKEY_LOCAL_MACHINE, NULL, szSHUserFolders,
4163 szSHFolders, folders, sizeof(folders) / sizeof(folders[0]));
4164 TRACE("returning 0x%08x\n", hr);
4165 return hr;
4168 /******************************************************************************
4169 * _SHAppendToUnixPath [Internal]
4171 * Helper function for _SHCreateSymbolicLinks. Appends pwszSubPath (or the
4172 * corresponding resource, if IS_INTRESOURCE) to the unix base path 'szBasePath'
4173 * and replaces backslashes with slashes.
4175 * PARAMS
4176 * szBasePath [IO] The unix base path, which will be appended to (CP_UNXICP).
4177 * pwszSubPath [I] Sub-path or resource id (use MAKEINTRESOURCEW).
4179 * RETURNS
4180 * Success: TRUE,
4181 * Failure: FALSE
4183 static inline BOOL _SHAppendToUnixPath(char *szBasePath, LPCWSTR pwszSubPath) {
4184 WCHAR wszSubPath[MAX_PATH];
4185 int cLen = strlen(szBasePath);
4186 char *pBackslash;
4188 if (IS_INTRESOURCE(pwszSubPath)) {
4189 if (!LoadStringW(shell32_hInstance, LOWORD(pwszSubPath), wszSubPath, MAX_PATH)) {
4190 /* Fall back to hard coded defaults. */
4191 switch (LOWORD(pwszSubPath)) {
4192 case IDS_PERSONAL:
4193 lstrcpyW(wszSubPath, DocumentsW);
4194 break;
4195 case IDS_MYMUSIC:
4196 lstrcpyW(wszSubPath, My_MusicW);
4197 break;
4198 case IDS_MYPICTURES:
4199 lstrcpyW(wszSubPath, My_PicturesW);
4200 break;
4201 case IDS_MYVIDEOS:
4202 lstrcpyW(wszSubPath, My_VideosW);
4203 break;
4204 default:
4205 ERR("LoadString(%d) failed!\n", LOWORD(pwszSubPath));
4206 return FALSE;
4209 } else {
4210 lstrcpyW(wszSubPath, pwszSubPath);
4213 if (szBasePath[cLen-1] != '/') szBasePath[cLen++] = '/';
4215 if (!WideCharToMultiByte(CP_UNIXCP, 0, wszSubPath, -1, szBasePath + cLen,
4216 FILENAME_MAX - cLen, NULL, NULL))
4218 return FALSE;
4221 pBackslash = szBasePath + cLen;
4222 while ((pBackslash = strchr(pBackslash, '\\'))) *pBackslash = '/';
4224 return TRUE;
4227 /******************************************************************************
4228 * _SHCreateSymbolicLinks [Internal]
4230 * Sets up symbol links for various shell folders to point into the users home
4231 * directory. We do an educated guess about what the user would probably want:
4232 * - If there is a 'My Documents' directory in $HOME, the user probably wants
4233 * wine's 'My Documents' to point there. Furthermore, we imply that the user
4234 * is a Windows lover and has no problem with wine creating 'My Pictures',
4235 * 'My Music' and 'My Videos' subfolders under '$HOME/My Documents', if those
4236 * do not already exits. We put appropriate symbolic links in place for those,
4237 * too.
4238 * - If there is no 'My Documents' directory in $HOME, we let 'My Documents'
4239 * point directly to $HOME. We assume the user to be a unix hacker who does not
4240 * want wine to create anything anywhere besides the .wine directory. So, if
4241 * there already is a 'My Music' directory in $HOME, we symlink the 'My Music'
4242 * shell folder to it. But if not, then we check XDG_MUSIC_DIR - "well known"
4243 * directory, and try to link to that. If that fails, then we symlink to
4244 * $HOME directly. The same holds fo 'My Pictures' and 'My Videos'.
4245 * - The Desktop shell folder is symlinked to XDG_DESKTOP_DIR. If that does not
4246 * exist, then we try '$HOME/Desktop'. If that does not exist, then we leave
4247 * it alone.
4248 * ('My Music',... above in fact means LoadString(IDS_MYMUSIC))
4250 static void _SHCreateSymbolicLinks(void)
4252 UINT aidsMyStuff[] = { IDS_MYPICTURES, IDS_MYVIDEOS, IDS_MYMUSIC }, i;
4253 const WCHAR* MyOSXStuffW[] = { PicturesW, MoviesW, MusicW };
4254 int acsidlMyStuff[] = { CSIDL_MYPICTURES, CSIDL_MYVIDEO, CSIDL_MYMUSIC };
4255 static const char * const xdg_dirs[] = { "PICTURES", "VIDEOS", "MUSIC", "DOCUMENTS", "DESKTOP" };
4256 static const unsigned int num = sizeof(xdg_dirs) / sizeof(xdg_dirs[0]);
4257 WCHAR wszTempPath[MAX_PATH];
4258 char szPersonalTarget[FILENAME_MAX], *pszPersonal;
4259 char szMyStuffTarget[FILENAME_MAX], *pszMyStuff;
4260 char szDesktopTarget[FILENAME_MAX], *pszDesktop;
4261 struct stat statFolder;
4262 const char *pszHome;
4263 HRESULT hr;
4264 char ** xdg_results;
4265 char * xdg_desktop_dir;
4267 /* Create all necessary profile sub-dirs up to 'My Documents' and get the unix path. */
4268 hr = SHGetFolderPathW(NULL, CSIDL_PERSONAL|CSIDL_FLAG_CREATE, NULL,
4269 SHGFP_TYPE_DEFAULT, wszTempPath);
4270 if (FAILED(hr)) return;
4271 pszPersonal = wine_get_unix_file_name(wszTempPath);
4272 if (!pszPersonal) return;
4274 hr = XDG_UserDirLookup(xdg_dirs, num, &xdg_results);
4275 if (FAILED(hr)) xdg_results = NULL;
4277 pszHome = getenv("HOME");
4278 if (pszHome && !stat(pszHome, &statFolder) && S_ISDIR(statFolder.st_mode))
4280 while (1)
4282 /* Check if there's already a Wine-specific 'My Documents' folder */
4283 strcpy(szPersonalTarget, pszHome);
4284 if (_SHAppendToUnixPath(szPersonalTarget, MAKEINTRESOURCEW(IDS_PERSONAL)) &&
4285 !stat(szPersonalTarget, &statFolder) && S_ISDIR(statFolder.st_mode))
4287 /* '$HOME/My Documents' exists. Create 'My Pictures',
4288 * 'My Videos' and 'My Music' subfolders or fail silently if
4289 * they already exist.
4291 for (i = 0; i < sizeof(aidsMyStuff)/sizeof(*aidsMyStuff); i++)
4293 strcpy(szMyStuffTarget, szPersonalTarget);
4294 if (_SHAppendToUnixPath(szMyStuffTarget, MAKEINTRESOURCEW(aidsMyStuff[i])))
4295 mkdir(szMyStuffTarget, 0777);
4297 break;
4300 /* Try to point to the XDG Documents folder */
4301 if (xdg_results && xdg_results[num-2] &&
4302 !stat(xdg_results[num-2], &statFolder) &&
4303 S_ISDIR(statFolder.st_mode))
4305 strcpy(szPersonalTarget, xdg_results[num-2]);
4306 break;
4309 /* Or the hardcoded / OS X Documents folder */
4310 strcpy(szPersonalTarget, pszHome);
4311 if (_SHAppendToUnixPath(szPersonalTarget, DocumentsW) &&
4312 !stat(szPersonalTarget, &statFolder) &&
4313 S_ISDIR(statFolder.st_mode))
4314 break;
4316 /* As a last resort point to $HOME. */
4317 strcpy(szPersonalTarget, pszHome);
4318 break;
4321 /* Replace 'My Documents' directory with a symlink or fail silently if not empty. */
4322 remove(pszPersonal);
4323 symlink(szPersonalTarget, pszPersonal);
4325 else
4327 /* '$HOME' doesn't exist. Create 'My Pictures', 'My Videos' and 'My Music' subdirs
4328 * in '%USERPROFILE%\\My Documents' or fail silently if they already exist. */
4329 pszHome = NULL;
4330 strcpy(szPersonalTarget, pszPersonal);
4331 for (i = 0; i < sizeof(aidsMyStuff)/sizeof(aidsMyStuff[0]); i++) {
4332 strcpy(szMyStuffTarget, szPersonalTarget);
4333 if (_SHAppendToUnixPath(szMyStuffTarget, MAKEINTRESOURCEW(aidsMyStuff[i])))
4334 mkdir(szMyStuffTarget, 0777);
4338 /* Create symbolic links for 'My Pictures', 'My Videos' and 'My Music'. */
4339 for (i=0; i < sizeof(aidsMyStuff)/sizeof(aidsMyStuff[0]); i++)
4341 /* Create the current 'My Whatever' folder and get its unix path. */
4342 hr = SHGetFolderPathW(NULL, acsidlMyStuff[i]|CSIDL_FLAG_CREATE, NULL,
4343 SHGFP_TYPE_DEFAULT, wszTempPath);
4344 if (FAILED(hr)) continue;
4346 pszMyStuff = wine_get_unix_file_name(wszTempPath);
4347 if (!pszMyStuff) continue;
4349 while (1)
4351 /* Check for the Wine-specific '$HOME/My Documents' subfolder */
4352 strcpy(szMyStuffTarget, szPersonalTarget);
4353 if (_SHAppendToUnixPath(szMyStuffTarget, MAKEINTRESOURCEW(aidsMyStuff[i])) &&
4354 !stat(szMyStuffTarget, &statFolder) && S_ISDIR(statFolder.st_mode))
4355 break;
4357 /* Try the XDG_XXX_DIR folder */
4358 if (xdg_results && xdg_results[i])
4360 strcpy(szMyStuffTarget, xdg_results[i]);
4361 break;
4364 /* Or the OS X folder (these are never localized) */
4365 if (pszHome)
4367 strcpy(szMyStuffTarget, pszHome);
4368 if (_SHAppendToUnixPath(szMyStuffTarget, MyOSXStuffW[i]) &&
4369 !stat(szMyStuffTarget, &statFolder) &&
4370 S_ISDIR(statFolder.st_mode))
4371 break;
4374 /* As a last resort point to the same location as 'My Documents' */
4375 strcpy(szMyStuffTarget, szPersonalTarget);
4376 break;
4378 remove(pszMyStuff);
4379 symlink(szMyStuffTarget, pszMyStuff);
4380 HeapFree(GetProcessHeap(), 0, pszMyStuff);
4383 /* Last but not least, the Desktop folder */
4384 if (pszHome)
4385 strcpy(szDesktopTarget, pszHome);
4386 else
4387 strcpy(szDesktopTarget, pszPersonal);
4388 HeapFree(GetProcessHeap(), 0, pszPersonal);
4390 xdg_desktop_dir = xdg_results ? xdg_results[num - 1] : NULL;
4391 if (xdg_desktop_dir ||
4392 (_SHAppendToUnixPath(szDesktopTarget, DesktopW) &&
4393 !stat(szDesktopTarget, &statFolder) && S_ISDIR(statFolder.st_mode)))
4395 hr = SHGetFolderPathW(NULL, CSIDL_DESKTOPDIRECTORY|CSIDL_FLAG_CREATE, NULL,
4396 SHGFP_TYPE_DEFAULT, wszTempPath);
4397 if (SUCCEEDED(hr) && (pszDesktop = wine_get_unix_file_name(wszTempPath)))
4399 remove(pszDesktop);
4400 if (xdg_desktop_dir)
4401 symlink(xdg_desktop_dir, pszDesktop);
4402 else
4403 symlink(szDesktopTarget, pszDesktop);
4404 HeapFree(GetProcessHeap(), 0, pszDesktop);
4408 /* Free resources allocated by XDG_UserDirLookup() */
4409 if (xdg_results)
4411 for (i = 0; i < num; i++)
4412 HeapFree(GetProcessHeap(), 0, xdg_results[i]);
4413 HeapFree(GetProcessHeap(), 0, xdg_results);
4417 /******************************************************************************
4418 * create_extra_folders [Internal]
4420 * Create some extra folders that don't have a standard CSIDL definition.
4422 static HRESULT create_extra_folders(void)
4424 static const WCHAR environW[] = {'E','n','v','i','r','o','n','m','e','n','t',0};
4425 static const WCHAR microsoftW[] = {'M','i','c','r','o','s','o','f','t',0};
4426 static const WCHAR TempW[] = {'T','e','m','p',0};
4427 static const WCHAR TEMPW[] = {'T','E','M','P',0};
4428 static const WCHAR TMPW[] = {'T','M','P',0};
4429 WCHAR path[MAX_PATH+5];
4430 HRESULT hr;
4431 HKEY hkey;
4432 DWORD type, size, ret;
4434 ret = RegCreateKeyW( HKEY_CURRENT_USER, environW, &hkey );
4435 if (ret) return HRESULT_FROM_WIN32( ret );
4437 /* FIXME: should be under AppData, but we don't want spaces in the temp path */
4438 hr = SHGetFolderPathAndSubDirW( 0, CSIDL_PROFILE | CSIDL_FLAG_CREATE, NULL,
4439 SHGFP_TYPE_DEFAULT, TempW, path );
4440 if (SUCCEEDED(hr))
4442 size = sizeof(path);
4443 if (RegQueryValueExW( hkey, TEMPW, NULL, &type, (LPBYTE)path, &size ))
4444 RegSetValueExW( hkey, TEMPW, 0, REG_SZ, (LPBYTE)path, (strlenW(path) + 1) * sizeof(WCHAR) );
4445 size = sizeof(path);
4446 if (RegQueryValueExW( hkey, TMPW, NULL, &type, (LPBYTE)path, &size ))
4447 RegSetValueExW( hkey, TMPW, 0, REG_SZ, (LPBYTE)path, (strlenW(path) + 1) * sizeof(WCHAR) );
4449 RegCloseKey( hkey );
4451 if (SUCCEEDED(hr))
4453 hr = SHGetFolderPathAndSubDirW( 0, CSIDL_COMMON_APPDATA | CSIDL_FLAG_CREATE, NULL,
4454 SHGFP_TYPE_DEFAULT, microsoftW, path );
4456 return hr;
4460 /******************************************************************************
4461 * set_folder_attributes
4463 * Set the various folder attributes registry keys.
4465 static HRESULT set_folder_attributes(void)
4467 static const WCHAR clsidW[] = {'C','L','S','I','D','\\',0 };
4468 static const WCHAR shellfolderW[] = {'\\','S','h','e','l','l','F','o','l','d','e','r', 0 };
4469 static const WCHAR wfparsingW[] = {'W','a','n','t','s','F','O','R','P','A','R','S','I','N','G',0};
4470 static const WCHAR wfdisplayW[] = {'W','a','n','t','s','F','O','R','D','I','S','P','L','A','Y',0};
4471 static const WCHAR hideasdeleteW[] = {'H','i','d','e','A','s','D','e','l','e','t','e','P','e','r','U','s','e','r',0};
4472 static const WCHAR cfattributesW[] = {'C','a','l','l','F','o','r','A','t','t','r','i','b','u','t','e','s',0};
4473 static const WCHAR emptyW[] = {0};
4475 static const struct
4477 const CLSID *clsid;
4478 BOOL wfparsing : 1;
4479 BOOL wfdisplay : 1;
4480 BOOL hideasdel : 1;
4481 DWORD attr;
4482 DWORD call_for_attr;
4483 } folders[] =
4485 { &CLSID_UnixFolder, TRUE, FALSE, FALSE },
4486 { &CLSID_UnixDosFolder, TRUE, FALSE, FALSE,
4487 SFGAO_FILESYSANCESTOR|SFGAO_FOLDER|SFGAO_HASSUBFOLDER, SFGAO_FILESYSTEM },
4488 { &CLSID_FolderShortcut, FALSE, FALSE, FALSE,
4489 SFGAO_FILESYSTEM|SFGAO_FOLDER|SFGAO_LINK,
4490 SFGAO_HASSUBFOLDER|SFGAO_FILESYSTEM|SFGAO_FOLDER|SFGAO_FILESYSANCESTOR },
4491 { &CLSID_MyDocuments, TRUE, FALSE, FALSE,
4492 SFGAO_FILESYSANCESTOR|SFGAO_FOLDER|SFGAO_HASSUBFOLDER, SFGAO_FILESYSTEM },
4493 { &CLSID_RecycleBin, FALSE, FALSE, FALSE,
4494 SFGAO_FOLDER|SFGAO_DROPTARGET|SFGAO_HASPROPSHEET },
4495 { &CLSID_ControlPanel, FALSE, TRUE, TRUE,
4496 SFGAO_FOLDER|SFGAO_HASSUBFOLDER }
4499 unsigned int i;
4500 WCHAR buffer[39 + (sizeof(clsidW) + sizeof(shellfolderW)) / sizeof(WCHAR)];
4501 LONG res;
4502 HKEY hkey;
4504 for (i = 0; i < sizeof(folders)/sizeof(folders[0]); i++)
4506 strcpyW( buffer, clsidW );
4507 StringFromGUID2( folders[i].clsid, buffer + strlenW(buffer), 39 );
4508 strcatW( buffer, shellfolderW );
4509 res = RegCreateKeyExW( HKEY_CLASSES_ROOT, buffer, 0, NULL, 0,
4510 KEY_READ | KEY_WRITE, NULL, &hkey, NULL);
4511 if (res) return HRESULT_FROM_WIN32( res );
4512 if (folders[i].wfparsing)
4513 res = RegSetValueExW( hkey, wfparsingW, 0, REG_SZ, (const BYTE *)emptyW, sizeof(emptyW) );
4514 if (folders[i].wfdisplay)
4515 res = RegSetValueExW( hkey, wfdisplayW, 0, REG_SZ, (const BYTE *)emptyW, sizeof(emptyW) );
4516 if (folders[i].hideasdel)
4517 res = RegSetValueExW( hkey, hideasdeleteW, 0, REG_SZ, (const BYTE *)emptyW, sizeof(emptyW) );
4518 if (folders[i].attr)
4519 res = RegSetValueExW( hkey, szAttributes, 0, REG_DWORD,
4520 (const BYTE *)&folders[i].attr, sizeof(DWORD));
4521 if (folders[i].call_for_attr)
4522 res = RegSetValueExW( hkey, cfattributesW, 0, REG_DWORD,
4523 (const BYTE *)&folders[i].call_for_attr, sizeof(DWORD));
4524 RegCloseKey( hkey );
4526 return S_OK;
4529 /*************************************************************************
4530 * SHGetSpecialFolderPathA [SHELL32.@]
4532 BOOL WINAPI SHGetSpecialFolderPathA (
4533 HWND hwndOwner,
4534 LPSTR szPath,
4535 int nFolder,
4536 BOOL bCreate)
4538 return SHGetFolderPathA(hwndOwner, nFolder + (bCreate ? CSIDL_FLAG_CREATE : 0), NULL, 0,
4539 szPath) == S_OK;
4542 /*************************************************************************
4543 * SHGetSpecialFolderPathW
4545 BOOL WINAPI SHGetSpecialFolderPathW (
4546 HWND hwndOwner,
4547 LPWSTR szPath,
4548 int nFolder,
4549 BOOL bCreate)
4551 return SHGetFolderPathW(hwndOwner, nFolder + (bCreate ? CSIDL_FLAG_CREATE : 0), NULL, 0,
4552 szPath) == S_OK;
4555 /*************************************************************************
4556 * SHGetSpecialFolderPath (SHELL32.175)
4558 BOOL WINAPI SHGetSpecialFolderPathAW (
4559 HWND hwndOwner,
4560 LPVOID szPath,
4561 int nFolder,
4562 BOOL bCreate)
4565 if (SHELL_OsIsUnicode())
4566 return SHGetSpecialFolderPathW (hwndOwner, szPath, nFolder, bCreate);
4567 return SHGetSpecialFolderPathA (hwndOwner, szPath, nFolder, bCreate);
4570 /*************************************************************************
4571 * SHGetFolderLocation [SHELL32.@]
4573 * Gets the folder locations from the registry and creates a pidl.
4575 * PARAMS
4576 * hwndOwner [I]
4577 * nFolder [I] CSIDL_xxxxx
4578 * hToken [I] token representing user, or NULL for current user, or -1 for
4579 * default user
4580 * dwReserved [I] must be zero
4581 * ppidl [O] PIDL of a special folder
4583 * RETURNS
4584 * Success: S_OK
4585 * Failure: Standard OLE-defined error result, S_FALSE or E_INVALIDARG
4587 * NOTES
4588 * Creates missing reg keys and directories.
4589 * Mostly forwards to SHGetFolderPathW, but a few values of nFolder return
4590 * virtual folders that are handled here.
4592 HRESULT WINAPI SHGetFolderLocation(
4593 HWND hwndOwner,
4594 int nFolder,
4595 HANDLE hToken,
4596 DWORD dwReserved,
4597 LPITEMIDLIST *ppidl)
4599 HRESULT hr = E_INVALIDARG;
4601 TRACE("%p 0x%08x %p 0x%08x %p\n",
4602 hwndOwner, nFolder, hToken, dwReserved, ppidl);
4604 if (!ppidl)
4605 return E_INVALIDARG;
4606 if (dwReserved)
4607 return E_INVALIDARG;
4609 /* The virtual folders' locations are not user-dependent */
4610 *ppidl = NULL;
4611 switch (nFolder & CSIDL_FOLDER_MASK)
4613 case CSIDL_DESKTOP:
4614 *ppidl = _ILCreateDesktop();
4615 break;
4617 case CSIDL_PERSONAL:
4618 *ppidl = _ILCreateMyDocuments();
4619 break;
4621 case CSIDL_INTERNET:
4622 *ppidl = _ILCreateIExplore();
4623 break;
4625 case CSIDL_CONTROLS:
4626 *ppidl = _ILCreateControlPanel();
4627 break;
4629 case CSIDL_PRINTERS:
4630 *ppidl = _ILCreatePrinters();
4631 break;
4633 case CSIDL_BITBUCKET:
4634 *ppidl = _ILCreateBitBucket();
4635 break;
4637 case CSIDL_DRIVES:
4638 *ppidl = _ILCreateMyComputer();
4639 break;
4641 case CSIDL_NETWORK:
4642 *ppidl = _ILCreateNetwork();
4643 break;
4645 default:
4647 WCHAR szPath[MAX_PATH];
4649 hr = SHGetFolderPathW(hwndOwner, nFolder, hToken,
4650 SHGFP_TYPE_CURRENT, szPath);
4651 if (SUCCEEDED(hr))
4653 DWORD attributes=0;
4655 TRACE("Value=%s\n", debugstr_w(szPath));
4656 hr = SHILCreateFromPathW(szPath, ppidl, &attributes);
4658 else if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
4660 /* unlike SHGetFolderPath, SHGetFolderLocation in shell32
4661 * version 6.0 returns E_FAIL for nonexistent paths
4663 hr = E_FAIL;
4667 if(*ppidl)
4668 hr = S_OK;
4670 TRACE("-- (new pidl %p)\n",*ppidl);
4671 return hr;
4674 /*************************************************************************
4675 * SHGetSpecialFolderLocation [SHELL32.@]
4677 * NOTES
4678 * In NT5, SHGetSpecialFolderLocation needs the <winntdir>/Recent
4679 * directory.
4681 HRESULT WINAPI SHGetSpecialFolderLocation(
4682 HWND hwndOwner,
4683 INT nFolder,
4684 LPITEMIDLIST * ppidl)
4686 HRESULT hr = E_INVALIDARG;
4688 TRACE("(%p,0x%x,%p)\n", hwndOwner,nFolder,ppidl);
4690 if (!ppidl)
4691 return E_INVALIDARG;
4693 hr = SHGetFolderLocation(hwndOwner, nFolder, NULL, 0, ppidl);
4694 return hr;
4697 static int csidl_from_id( const KNOWNFOLDERID *id )
4699 int i;
4700 for (i = 0; i < sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]); i++)
4701 if (IsEqualGUID( CSIDL_Data[i].id, id )) return i;
4702 return -1;
4705 /*************************************************************************
4706 * SHGetKnownFolderPath [SHELL32.@]
4708 HRESULT WINAPI SHGetKnownFolderPath(REFKNOWNFOLDERID rfid, DWORD flags, HANDLE token, WCHAR **ret_path)
4710 WCHAR pathW[MAX_PATH], tempW[MAX_PATH];
4711 HRESULT hr;
4712 CSIDL_Type type;
4713 int ret;
4714 int folder = csidl_from_id(rfid), shgfp_flags;
4716 TRACE("%s, 0x%08x, %p, %p\n", debugstr_guid(rfid), flags, token, ret_path);
4718 *ret_path = NULL;
4720 if (folder < 0)
4721 return HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND );
4723 if (flags & ~(KF_FLAG_CREATE|KF_FLAG_DONT_VERIFY|KF_FLAG_NO_ALIAS|
4724 KF_FLAG_INIT|KF_FLAG_DEFAULT_PATH))
4726 FIXME("flags 0x%08x not supported\n", flags);
4727 return E_INVALIDARG;
4730 shgfp_flags = flags & KF_FLAG_DEFAULT_PATH ? SHGFP_TYPE_DEFAULT : SHGFP_TYPE_CURRENT;
4732 type = CSIDL_Data[folder].type;
4733 switch (type)
4735 case CSIDL_Type_Disallowed:
4736 hr = E_INVALIDARG;
4737 break;
4738 case CSIDL_Type_NonExistent:
4739 *tempW = 0;
4740 hr = S_FALSE;
4741 break;
4742 case CSIDL_Type_WindowsPath:
4743 GetWindowsDirectoryW(tempW, MAX_PATH);
4744 if (CSIDL_Data[folder].szDefaultPath &&
4745 !IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath) &&
4746 *CSIDL_Data[folder].szDefaultPath)
4748 PathAddBackslashW(tempW);
4749 strcatW(tempW, CSIDL_Data[folder].szDefaultPath);
4751 hr = S_OK;
4752 break;
4753 case CSIDL_Type_SystemPath:
4754 GetSystemDirectoryW(tempW, MAX_PATH);
4755 if (CSIDL_Data[folder].szDefaultPath &&
4756 !IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath) &&
4757 *CSIDL_Data[folder].szDefaultPath)
4759 PathAddBackslashW(tempW);
4760 strcatW(tempW, CSIDL_Data[folder].szDefaultPath);
4762 hr = S_OK;
4763 break;
4764 case CSIDL_Type_SystemX86Path:
4765 if (!GetSystemWow64DirectoryW(tempW, MAX_PATH)) GetSystemDirectoryW(tempW, MAX_PATH);
4766 if (CSIDL_Data[folder].szDefaultPath &&
4767 !IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath) &&
4768 *CSIDL_Data[folder].szDefaultPath)
4770 PathAddBackslashW(tempW);
4771 strcatW(tempW, CSIDL_Data[folder].szDefaultPath);
4773 hr = S_OK;
4774 break;
4775 case CSIDL_Type_CurrVer:
4776 hr = _SHGetCurrentVersionPath(shgfp_flags, folder, tempW);
4777 break;
4778 case CSIDL_Type_User:
4779 hr = _SHGetUserProfilePath(token, shgfp_flags, folder, tempW);
4780 break;
4781 case CSIDL_Type_AllUsers:
4782 hr = _SHGetAllUsersProfilePath(shgfp_flags, folder, tempW);
4783 break;
4784 default:
4785 FIXME("bogus type %d, please fix\n", type);
4786 hr = E_INVALIDARG;
4787 break;
4790 if (FAILED(hr))
4791 goto failed;
4793 /* Expand environment strings if necessary */
4794 if (*tempW == '%')
4796 hr = _SHExpandEnvironmentStrings(tempW, pathW);
4797 if (FAILED(hr))
4798 goto failed;
4800 else
4801 strcpyW(pathW, tempW);
4803 /* if we don't care about existing directories we are ready */
4804 if (flags & KF_FLAG_DONT_VERIFY) goto done;
4806 if (PathFileExistsW(pathW)) goto done;
4808 /* Does not exist but we are not allowed to create it. The return value
4809 * is verified against shell32 version 6.0.
4811 if (!(flags & KF_FLAG_CREATE))
4813 hr = HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND);
4814 goto done;
4817 /* create directory/directories */
4818 ret = SHCreateDirectoryExW(NULL, pathW, NULL);
4819 if (ret && ret != ERROR_ALREADY_EXISTS)
4821 ERR("Failed to create directory %s.\n", debugstr_w(pathW));
4822 hr = E_FAIL;
4823 goto failed;
4826 TRACE("Created missing system directory %s\n", debugstr_w(pathW));
4828 done:
4829 TRACE("Final path is %s, %#x\n", debugstr_w(pathW), hr);
4831 *ret_path = CoTaskMemAlloc((strlenW(pathW) + 1) * sizeof(WCHAR));
4832 if (!*ret_path)
4833 return E_OUTOFMEMORY;
4834 strcpyW(*ret_path, pathW);
4836 return hr;
4838 failed:
4839 TRACE("Failed to get folder path, %#x.\n", hr);
4841 return hr;
4844 /*************************************************************************
4845 * SHGetFolderPathEx [SHELL32.@]
4847 HRESULT WINAPI SHGetFolderPathEx(REFKNOWNFOLDERID rfid, DWORD flags, HANDLE token, LPWSTR path, DWORD len)
4849 HRESULT hr;
4850 WCHAR *buffer;
4852 TRACE("%s, 0x%08x, %p, %p, %u\n", debugstr_guid(rfid), flags, token, path, len);
4854 if (!path || !len) return E_INVALIDARG;
4856 hr = SHGetKnownFolderPath( rfid, flags, token, &buffer );
4857 if (SUCCEEDED( hr ))
4859 if (strlenW( buffer ) + 1 > len)
4861 CoTaskMemFree( buffer );
4862 return HRESULT_FROM_WIN32( ERROR_INSUFFICIENT_BUFFER );
4864 strcpyW( path, buffer );
4865 CoTaskMemFree( buffer );
4867 return hr;
4871 * Internal function to convert known folder identifier to path of registry key
4872 * associated with known folder.
4874 * Parameters:
4875 * rfid [I] pointer to known folder identifier (may be NULL)
4876 * lpStringGuid [I] string with known folder identifier (used when rfid is NULL)
4877 * lpPath [O] place to store string address. String should be
4878 * later freed using HeapFree(GetProcessHeap(),0, ... )
4880 static HRESULT get_known_folder_registry_path(
4881 REFKNOWNFOLDERID rfid,
4882 LPWSTR lpStringGuid,
4883 LPWSTR *lpPath)
4885 static const WCHAR sBackslash[] = {'\\',0};
4886 HRESULT hr = S_OK;
4887 int length;
4888 WCHAR sGuid[50];
4890 TRACE("(%s, %s, %p)\n", debugstr_guid(rfid), debugstr_w(lpStringGuid), lpPath);
4892 if(rfid)
4893 StringFromGUID2(rfid, sGuid, sizeof(sGuid)/sizeof(sGuid[0]));
4894 else
4895 lstrcpyW(sGuid, lpStringGuid);
4897 length = lstrlenW(szKnownFolderDescriptions)+51;
4898 *lpPath = HeapAlloc(GetProcessHeap(), 0, length*sizeof(WCHAR));
4899 if(!(*lpPath))
4900 hr = E_OUTOFMEMORY;
4902 if(SUCCEEDED(hr))
4904 lstrcpyW(*lpPath, szKnownFolderDescriptions);
4905 lstrcatW(*lpPath, sBackslash);
4906 lstrcatW(*lpPath, sGuid);
4909 return hr;
4912 static HRESULT get_known_folder_wstr(const WCHAR *regpath, const WCHAR *value, WCHAR **out)
4914 DWORD size = 0;
4915 HRESULT hr;
4917 size = 0;
4918 hr = HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, regpath, value, RRF_RT_REG_SZ, NULL, NULL, &size));
4919 if(FAILED(hr))
4920 return hr;
4922 *out = CoTaskMemAlloc(size);
4923 if(!*out)
4924 return E_OUTOFMEMORY;
4926 hr = HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, regpath, value, RRF_RT_REG_SZ, NULL, *out, &size));
4927 if(FAILED(hr)){
4928 CoTaskMemFree(*out);
4929 *out = NULL;
4932 return hr;
4935 static HRESULT get_known_folder_dword(const WCHAR *registryPath, const WCHAR *value, DWORD *out)
4937 DWORD dwSize = sizeof(DWORD);
4938 DWORD dwType;
4939 return HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, registryPath, value, RRF_RT_DWORD, &dwType, out, &dwSize));
4943 * Internal function to get place where folder redirection information are stored.
4945 * Parameters:
4946 * rfid [I] pointer to known folder identifier (may be NULL)
4947 * rootKey [O] root key where the redirection information are stored
4948 * It can be HKLM for COMMON folders, and HKCU for PERUSER folders.
4949 * However, besides root key, path is always that same, and is stored
4950 * as "szKnownFolderRedirections" constant
4952 static HRESULT get_known_folder_redirection_place(
4953 REFKNOWNFOLDERID rfid,
4954 HKEY *rootKey)
4956 HRESULT hr;
4957 LPWSTR lpRegistryPath = NULL;
4958 KF_CATEGORY category;
4960 /* first, get known folder's category */
4961 hr = get_known_folder_registry_path(rfid, NULL, &lpRegistryPath);
4963 if(SUCCEEDED(hr))
4964 hr = get_known_folder_dword(lpRegistryPath, szCategory, &category);
4966 if(SUCCEEDED(hr))
4968 if(category == KF_CATEGORY_COMMON)
4970 *rootKey = HKEY_LOCAL_MACHINE;
4971 hr = S_OK;
4973 else if(category == KF_CATEGORY_PERUSER)
4975 *rootKey = HKEY_CURRENT_USER;
4976 hr = S_OK;
4978 else
4979 hr = E_FAIL;
4982 HeapFree(GetProcessHeap(), 0, lpRegistryPath);
4983 return hr;
4986 static HRESULT get_known_folder_path_by_id(REFKNOWNFOLDERID folderId, LPWSTR lpRegistryPath, DWORD dwFlags, LPWSTR *ppszPath);
4988 static HRESULT redirect_known_folder(
4989 REFKNOWNFOLDERID rfid,
4990 HWND hwnd,
4991 KF_REDIRECT_FLAGS flags,
4992 LPCWSTR pszTargetPath,
4993 UINT cFolders,
4994 KNOWNFOLDERID const *pExclusion,
4995 LPWSTR *ppszError)
4997 HRESULT hr;
4998 HKEY rootKey = HKEY_LOCAL_MACHINE, hKey;
4999 WCHAR sGuid[39];
5000 LPWSTR lpRegistryPath = NULL, lpSrcPath = NULL;
5001 TRACE("(%s, %p, 0x%08x, %s, %d, %p, %p)\n", debugstr_guid(rfid), hwnd, flags, debugstr_w(pszTargetPath), cFolders, pExclusion, ppszError);
5003 if (ppszError) *ppszError = NULL;
5005 hr = get_known_folder_registry_path(rfid, NULL, &lpRegistryPath);
5007 if(SUCCEEDED(hr))
5008 hr = get_known_folder_path_by_id(rfid, lpRegistryPath, 0, &lpSrcPath);
5010 HeapFree(GetProcessHeap(), 0, lpRegistryPath);
5012 /* get path to redirection storage */
5013 if(SUCCEEDED(hr))
5014 hr = get_known_folder_redirection_place(rfid, &rootKey);
5016 /* write redirection information */
5017 if(SUCCEEDED(hr))
5018 hr = HRESULT_FROM_WIN32(RegCreateKeyExW(rootKey, szKnownFolderRedirections, 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL));
5020 if(SUCCEEDED(hr))
5022 StringFromGUID2(rfid, sGuid, sizeof(sGuid)/sizeof(sGuid[0]));
5024 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, sGuid, 0, REG_SZ, (LPBYTE)pszTargetPath, (lstrlenW(pszTargetPath)+1)*sizeof(WCHAR)));
5026 RegCloseKey(hKey);
5029 /* make sure destination path exists */
5030 SHCreateDirectory(NULL, pszTargetPath);
5032 /* copy content if required */
5033 if(SUCCEEDED(hr) && (flags & KF_REDIRECT_COPY_CONTENTS) )
5035 static const WCHAR sWildcard[] = {'\\','*',0};
5036 WCHAR srcPath[MAX_PATH+1], dstPath[MAX_PATH+1];
5037 SHFILEOPSTRUCTW fileOp;
5039 ZeroMemory(srcPath, sizeof(srcPath));
5040 lstrcpyW(srcPath, lpSrcPath);
5041 lstrcatW(srcPath, sWildcard);
5043 ZeroMemory(dstPath, sizeof(dstPath));
5044 lstrcpyW(dstPath, pszTargetPath);
5046 ZeroMemory(&fileOp, sizeof(fileOp));
5048 if(flags & KF_REDIRECT_DEL_SOURCE_CONTENTS)
5049 fileOp.wFunc = FO_MOVE;
5050 else
5051 fileOp.wFunc = FO_COPY;
5053 fileOp.pFrom = srcPath;
5054 fileOp.pTo = dstPath;
5055 fileOp.fFlags = FOF_NO_UI;
5057 hr = (SHFileOperationW(&fileOp)==0 ? S_OK : E_FAIL);
5059 if(flags & KF_REDIRECT_DEL_SOURCE_CONTENTS)
5061 ZeroMemory(srcPath, sizeof(srcPath));
5062 lstrcpyW(srcPath, lpSrcPath);
5064 ZeroMemory(&fileOp, sizeof(fileOp));
5065 fileOp.wFunc = FO_DELETE;
5066 fileOp.pFrom = srcPath;
5067 fileOp.fFlags = FOF_NO_UI;
5069 hr = (SHFileOperationW(&fileOp)==0 ? S_OK : E_FAIL);
5073 CoTaskMemFree(lpSrcPath);
5075 return hr;
5079 struct knownfolder
5081 IKnownFolder IKnownFolder_iface;
5082 LONG refs;
5083 KNOWNFOLDERID id;
5084 LPWSTR registryPath;
5087 static inline struct knownfolder *impl_from_IKnownFolder( IKnownFolder *iface )
5089 return CONTAINING_RECORD( iface, struct knownfolder, IKnownFolder_iface );
5092 static ULONG WINAPI knownfolder_AddRef(
5093 IKnownFolder *iface )
5095 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
5096 return InterlockedIncrement( &knownfolder->refs );
5099 static ULONG WINAPI knownfolder_Release(
5100 IKnownFolder *iface )
5102 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
5103 LONG refs = InterlockedDecrement( &knownfolder->refs );
5104 if (!refs)
5106 TRACE("destroying %p\n", knownfolder);
5107 HeapFree( GetProcessHeap(), 0, knownfolder->registryPath);
5108 HeapFree( GetProcessHeap(), 0, knownfolder );
5110 return refs;
5113 static HRESULT WINAPI knownfolder_QueryInterface(
5114 IKnownFolder *iface,
5115 REFIID riid,
5116 void **ppv )
5118 struct knownfolder *This = impl_from_IKnownFolder( iface );
5120 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppv );
5122 *ppv = NULL;
5123 if ( IsEqualGUID( riid, &IID_IKnownFolder ) ||
5124 IsEqualGUID( riid, &IID_IUnknown ) )
5126 *ppv = iface;
5128 else if ( IsEqualGUID( riid, &IID_IMarshal ) )
5130 TRACE("IID_IMarshal returning NULL.\n");
5131 return E_NOINTERFACE;
5133 else
5135 FIXME("interface %s not implemented\n", debugstr_guid(riid));
5136 return E_NOINTERFACE;
5138 IKnownFolder_AddRef( iface );
5139 return S_OK;
5142 static HRESULT knownfolder_set_id(
5143 struct knownfolder *knownfolder,
5144 const KNOWNFOLDERID *kfid)
5146 HKEY hKey;
5147 HRESULT hr;
5149 TRACE("%s\n", debugstr_guid(kfid));
5151 knownfolder->id = *kfid;
5153 /* check is it registry-registered folder */
5154 hr = get_known_folder_registry_path(kfid, NULL, &knownfolder->registryPath);
5155 if(SUCCEEDED(hr))
5156 hr = HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_LOCAL_MACHINE, knownfolder->registryPath, 0, 0, &hKey));
5158 if(SUCCEEDED(hr))
5160 hr = S_OK;
5161 RegCloseKey(hKey);
5163 else
5165 /* This known folder is not registered. To mark it, we set registryPath to NULL */
5166 HeapFree(GetProcessHeap(), 0, knownfolder->registryPath);
5167 knownfolder->registryPath = NULL;
5168 hr = S_OK;
5171 return hr;
5174 static HRESULT WINAPI knownfolder_GetId(
5175 IKnownFolder *iface,
5176 KNOWNFOLDERID *pkfid)
5178 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
5180 TRACE("%p\n", pkfid);
5182 *pkfid = knownfolder->id;
5183 return S_OK;
5186 static HRESULT WINAPI knownfolder_GetCategory(
5187 IKnownFolder *iface,
5188 KF_CATEGORY *pCategory)
5190 struct knownfolder *knownfolder = impl_from_IKnownFolder(iface);
5191 HRESULT hr = S_OK;
5193 TRACE("%p, %p\n", knownfolder, pCategory);
5195 /* we cannot get a category for a folder which is not registered */
5196 if(!knownfolder->registryPath)
5197 hr = E_FAIL;
5199 if(SUCCEEDED(hr))
5200 hr = get_known_folder_dword(knownfolder->registryPath, szCategory, pCategory);
5202 return hr;
5205 static HRESULT WINAPI knownfolder_GetShellItem(
5206 IKnownFolder *iface,
5207 DWORD flags,
5208 REFIID riid,
5209 void **ppv)
5211 struct knownfolder *knownfolder = impl_from_IKnownFolder(iface);
5212 TRACE("(%p, 0x%08x, %s, %p)\n", knownfolder, flags, debugstr_guid(riid), ppv);
5213 return SHGetKnownFolderItem(&knownfolder->id, flags, NULL, riid, ppv);
5216 static HRESULT get_known_folder_path(
5217 LPWSTR sFolderId,
5218 LPWSTR registryPath,
5219 LPWSTR *ppszPath)
5221 static const WCHAR sBackslash[] = {'\\',0};
5222 HRESULT hr;
5223 DWORD dwSize, dwType;
5224 WCHAR path[MAX_PATH] = {0};
5225 WCHAR parentGuid[39];
5226 KF_CATEGORY category;
5227 LPWSTR parentRegistryPath, parentPath;
5228 HKEY hRedirectionRootKey = NULL;
5230 TRACE("(%s, %p)\n", debugstr_w(registryPath), ppszPath);
5231 *ppszPath = NULL;
5233 /* check if folder has parent */
5234 dwSize = sizeof(parentGuid);
5235 hr = HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, registryPath, szParentFolder, RRF_RT_REG_SZ, &dwType, parentGuid, &dwSize));
5236 if(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) hr = S_FALSE;
5238 if(hr == S_OK)
5240 /* get parent's known folder path (recursive) */
5241 hr = get_known_folder_registry_path(NULL, parentGuid, &parentRegistryPath);
5242 if(FAILED(hr)) return hr;
5244 hr = get_known_folder_path(parentGuid, parentRegistryPath, &parentPath);
5245 if(FAILED(hr)) {
5246 HeapFree(GetProcessHeap(), 0, parentRegistryPath);
5247 return hr;
5250 lstrcatW(path, parentPath);
5251 lstrcatW(path, sBackslash);
5253 HeapFree(GetProcessHeap(), 0, parentRegistryPath);
5254 HeapFree(GetProcessHeap(), 0, parentPath);
5257 /* check, if folder was redirected */
5258 if(SUCCEEDED(hr))
5259 hr = get_known_folder_dword(registryPath, szCategory, &category);
5261 if(SUCCEEDED(hr))
5263 if(category == KF_CATEGORY_COMMON)
5264 hRedirectionRootKey = HKEY_LOCAL_MACHINE;
5265 else if(category == KF_CATEGORY_PERUSER)
5266 hRedirectionRootKey = HKEY_CURRENT_USER;
5268 if(hRedirectionRootKey)
5270 hr = HRESULT_FROM_WIN32(RegGetValueW(hRedirectionRootKey, szKnownFolderRedirections, sFolderId, RRF_RT_REG_SZ, NULL, NULL, &dwSize));
5272 if(SUCCEEDED(hr))
5274 *ppszPath = CoTaskMemAlloc(dwSize+(lstrlenW(path)+1)*sizeof(WCHAR));
5275 if(!*ppszPath) hr = E_OUTOFMEMORY;
5278 if(SUCCEEDED(hr))
5280 lstrcpyW(*ppszPath, path);
5281 hr = HRESULT_FROM_WIN32(RegGetValueW(hRedirectionRootKey, szKnownFolderRedirections, sFolderId, RRF_RT_REG_SZ, NULL, *ppszPath + lstrlenW(path), &dwSize));
5285 if(!*ppszPath)
5287 /* no redirection, use previous way - read the relative path from folder definition */
5288 hr = HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, registryPath, szRelativePath, RRF_RT_REG_SZ, &dwType, NULL, &dwSize));
5290 if(SUCCEEDED(hr))
5292 *ppszPath = CoTaskMemAlloc(dwSize+(lstrlenW(path)+1)*sizeof(WCHAR));
5293 if(!*ppszPath) hr = E_OUTOFMEMORY;
5296 if(SUCCEEDED(hr))
5298 lstrcpyW(*ppszPath, path);
5299 hr = HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, registryPath, szRelativePath, RRF_RT_REG_SZ, &dwType, *ppszPath + lstrlenW(path), &dwSize));
5304 TRACE("returning path: %s\n", debugstr_w(*ppszPath));
5305 return hr;
5308 static HRESULT get_known_folder_path_by_id(
5309 REFKNOWNFOLDERID folderId,
5310 LPWSTR lpRegistryPath,
5311 DWORD dwFlags,
5312 LPWSTR *ppszPath)
5314 HRESULT hr = E_FAIL;
5315 WCHAR sGuid[39];
5316 DWORD dwAttributes;
5318 TRACE("(%s, %s, 0x%08x, %p)\n", debugstr_guid(folderId), debugstr_w(lpRegistryPath), dwFlags, ppszPath);
5320 /* if this is registry-registered known folder, get path from registry */
5321 if(lpRegistryPath)
5323 StringFromGUID2(folderId, sGuid, sizeof(sGuid)/sizeof(sGuid[0]));
5325 hr = get_known_folder_path(sGuid, lpRegistryPath, ppszPath);
5327 /* in other case, use older way */
5329 if(FAILED(hr))
5330 hr = SHGetKnownFolderPath( folderId, dwFlags, NULL, ppszPath );
5332 if (FAILED(hr)) return hr;
5334 /* check if known folder really exists */
5335 dwAttributes = GetFileAttributesW(*ppszPath);
5336 if(dwAttributes == INVALID_FILE_ATTRIBUTES || !(dwAttributes & FILE_ATTRIBUTE_DIRECTORY) )
5338 TRACE("directory %s not found\n", debugstr_w(*ppszPath));
5339 CoTaskMemFree(*ppszPath);
5340 *ppszPath = NULL;
5341 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
5344 return hr;
5347 static HRESULT WINAPI knownfolder_GetPath(
5348 IKnownFolder *iface,
5349 DWORD dwFlags,
5350 LPWSTR *ppszPath)
5352 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
5353 TRACE("(%p, 0x%08x, %p)\n", knownfolder, dwFlags, ppszPath);
5355 return get_known_folder_path_by_id(&knownfolder->id, knownfolder->registryPath, dwFlags, ppszPath);
5358 static HRESULT WINAPI knownfolder_SetPath(
5359 IKnownFolder *iface,
5360 DWORD dwFlags,
5361 LPCWSTR pszPath)
5363 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
5364 HRESULT hr = S_OK;
5366 TRACE("(%p, 0x%08x, %s)\n", knownfolder, dwFlags, debugstr_w(pszPath));
5368 /* check if the known folder is registered */
5369 if(!knownfolder->registryPath)
5370 hr = E_FAIL;
5372 if(SUCCEEDED(hr))
5373 hr = redirect_known_folder(&knownfolder->id, NULL, 0, pszPath, 0, NULL, NULL);
5375 return hr;
5378 static HRESULT WINAPI knownfolder_GetIDList(
5379 IKnownFolder *iface,
5380 DWORD flags,
5381 PIDLIST_ABSOLUTE *ppidl)
5383 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
5384 TRACE("(%p, 0x%08x, %p)\n", knownfolder, flags, ppidl);
5385 return SHGetKnownFolderIDList(&knownfolder->id, flags, NULL, ppidl);
5388 static HRESULT WINAPI knownfolder_GetFolderType(
5389 IKnownFolder *iface,
5390 FOLDERTYPEID *pftid)
5392 FIXME("%p\n", pftid);
5393 return E_NOTIMPL;
5396 static HRESULT WINAPI knownfolder_GetRedirectionCapabilities(
5397 IKnownFolder *iface,
5398 KF_REDIRECTION_CAPABILITIES *pCapabilities)
5400 FIXME("%p\n", pCapabilities);
5401 return E_NOTIMPL;
5404 static HRESULT WINAPI knownfolder_GetFolderDefinition(
5405 IKnownFolder *iface,
5406 KNOWNFOLDER_DEFINITION *pKFD)
5408 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
5409 HRESULT hr;
5410 DWORD dwSize;
5411 WCHAR parentGuid[39];
5412 TRACE("(%p, %p)\n", knownfolder, pKFD);
5414 if(!pKFD) return E_INVALIDARG;
5416 ZeroMemory(pKFD, sizeof(*pKFD));
5418 /* required fields */
5419 hr = get_known_folder_dword(knownfolder->registryPath, szCategory, &pKFD->category);
5420 if(FAILED(hr))
5421 return hr;
5423 hr = get_known_folder_wstr(knownfolder->registryPath, szName, &pKFD->pszName);
5424 if(FAILED(hr))
5425 return hr;
5427 /* optional fields */
5428 dwSize = sizeof(parentGuid);
5429 hr = HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, knownfolder->registryPath, szParentFolder,
5430 RRF_RT_REG_SZ, NULL, parentGuid, &dwSize));
5431 if(SUCCEEDED(hr))
5433 hr = IIDFromString(parentGuid, &pKFD->fidParent);
5434 if(FAILED(hr))
5435 return hr;
5438 get_known_folder_dword(knownfolder->registryPath, szAttributes, &pKFD->dwAttributes);
5440 get_known_folder_wstr(knownfolder->registryPath, szRelativePath, &pKFD->pszRelativePath);
5442 get_known_folder_wstr(knownfolder->registryPath, szParsingName, &pKFD->pszParsingName);
5444 return S_OK;
5447 static const struct IKnownFolderVtbl knownfolder_vtbl =
5449 knownfolder_QueryInterface,
5450 knownfolder_AddRef,
5451 knownfolder_Release,
5452 knownfolder_GetId,
5453 knownfolder_GetCategory,
5454 knownfolder_GetShellItem,
5455 knownfolder_GetPath,
5456 knownfolder_SetPath,
5457 knownfolder_GetIDList,
5458 knownfolder_GetFolderType,
5459 knownfolder_GetRedirectionCapabilities,
5460 knownfolder_GetFolderDefinition
5463 static HRESULT knownfolder_create( struct knownfolder **knownfolder )
5465 struct knownfolder *kf;
5467 kf = HeapAlloc( GetProcessHeap(), 0, sizeof(*kf) );
5468 if (!kf) return E_OUTOFMEMORY;
5470 kf->IKnownFolder_iface.lpVtbl = &knownfolder_vtbl;
5471 kf->refs = 1;
5472 memset( &kf->id, 0, sizeof(kf->id) );
5473 kf->registryPath = NULL;
5475 *knownfolder = kf;
5477 TRACE("returning iface %p\n", &kf->IKnownFolder_iface);
5478 return S_OK;
5481 struct foldermanager
5483 IKnownFolderManager IKnownFolderManager_iface;
5484 LONG refs;
5485 UINT num_ids;
5486 KNOWNFOLDERID *ids;
5489 static inline struct foldermanager *impl_from_IKnownFolderManager( IKnownFolderManager *iface )
5491 return CONTAINING_RECORD( iface, struct foldermanager, IKnownFolderManager_iface );
5494 static ULONG WINAPI foldermanager_AddRef(
5495 IKnownFolderManager *iface )
5497 struct foldermanager *foldermanager = impl_from_IKnownFolderManager( iface );
5498 return InterlockedIncrement( &foldermanager->refs );
5501 static ULONG WINAPI foldermanager_Release(
5502 IKnownFolderManager *iface )
5504 struct foldermanager *foldermanager = impl_from_IKnownFolderManager( iface );
5505 LONG refs = InterlockedDecrement( &foldermanager->refs );
5506 if (!refs)
5508 TRACE("destroying %p\n", foldermanager);
5509 HeapFree( GetProcessHeap(), 0, foldermanager->ids );
5510 HeapFree( GetProcessHeap(), 0, foldermanager );
5512 return refs;
5515 static HRESULT WINAPI foldermanager_QueryInterface(
5516 IKnownFolderManager *iface,
5517 REFIID riid,
5518 void **ppv )
5520 struct foldermanager *This = impl_from_IKnownFolderManager( iface );
5522 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppv );
5524 *ppv = NULL;
5525 if ( IsEqualGUID( riid, &IID_IKnownFolderManager ) ||
5526 IsEqualGUID( riid, &IID_IUnknown ) )
5528 *ppv = iface;
5530 else if ( IsEqualGUID( riid, &IID_IMarshal ) )
5532 TRACE("IID_IMarshal returning NULL.\n");
5533 return E_NOINTERFACE;
5535 else
5537 FIXME("interface %s not implemented\n", debugstr_guid(riid));
5538 return E_NOINTERFACE;
5540 IKnownFolderManager_AddRef( iface );
5541 return S_OK;
5544 static HRESULT WINAPI foldermanager_FolderIdFromCsidl(
5545 IKnownFolderManager *iface,
5546 int nCsidl,
5547 KNOWNFOLDERID *pfid)
5549 TRACE("%d, %p\n", nCsidl, pfid);
5551 if (nCsidl >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
5552 return E_INVALIDARG;
5553 *pfid = *CSIDL_Data[nCsidl].id;
5554 return S_OK;
5557 static HRESULT WINAPI foldermanager_FolderIdToCsidl(
5558 IKnownFolderManager *iface,
5559 REFKNOWNFOLDERID rfid,
5560 int *pnCsidl)
5562 int csidl;
5564 TRACE("%s, %p\n", debugstr_guid(rfid), pnCsidl);
5566 csidl = csidl_from_id( rfid );
5567 if (csidl == -1) return E_INVALIDARG;
5568 *pnCsidl = csidl;
5569 return S_OK;
5572 static HRESULT WINAPI foldermanager_GetFolderIds(
5573 IKnownFolderManager *iface,
5574 KNOWNFOLDERID **ppKFId,
5575 UINT *pCount)
5577 struct foldermanager *fm = impl_from_IKnownFolderManager( iface );
5579 TRACE("%p, %p\n", ppKFId, pCount);
5581 *ppKFId = CoTaskMemAlloc(fm->num_ids * sizeof(KNOWNFOLDERID));
5582 memcpy(*ppKFId, fm->ids, fm->num_ids * sizeof(KNOWNFOLDERID));
5583 *pCount = fm->num_ids;
5584 return S_OK;
5587 static BOOL is_knownfolder( struct foldermanager *fm, const KNOWNFOLDERID *id )
5589 UINT i;
5590 HRESULT hr;
5591 LPWSTR registryPath = NULL;
5592 HKEY hKey;
5594 /* TODO: move all entries from "CSIDL_Data" static array to registry known folder descriptions */
5595 for (i = 0; i < fm->num_ids; i++)
5596 if (IsEqualGUID( &fm->ids[i], id )) return TRUE;
5598 hr = get_known_folder_registry_path(id, NULL, &registryPath);
5599 if(SUCCEEDED(hr))
5601 hr = HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_LOCAL_MACHINE, registryPath, 0, 0, &hKey));
5602 HeapFree(GetProcessHeap(), 0, registryPath);
5605 if(SUCCEEDED(hr))
5607 hr = S_OK;
5608 RegCloseKey(hKey);
5611 return hr == S_OK;
5614 static HRESULT WINAPI foldermanager_GetFolder(
5615 IKnownFolderManager *iface,
5616 REFKNOWNFOLDERID rfid,
5617 IKnownFolder **ppkf)
5619 struct foldermanager *fm = impl_from_IKnownFolderManager( iface );
5620 struct knownfolder *kf;
5621 HRESULT hr;
5623 TRACE("%s, %p\n", debugstr_guid(rfid), ppkf);
5625 if (!is_knownfolder( fm, rfid ))
5627 WARN("unknown folder\n");
5628 return E_INVALIDARG;
5630 hr = knownfolder_create( &kf );
5631 if (SUCCEEDED( hr ))
5633 hr = knownfolder_set_id( kf, rfid );
5634 *ppkf = &kf->IKnownFolder_iface;
5636 else
5637 *ppkf = NULL;
5639 return hr;
5642 static HRESULT WINAPI foldermanager_GetFolderByName(
5643 IKnownFolderManager *iface,
5644 LPCWSTR pszCanonicalName,
5645 IKnownFolder **ppkf)
5647 struct foldermanager *fm = impl_from_IKnownFolderManager( iface );
5648 struct knownfolder *kf;
5649 BOOL found = FALSE;
5650 HRESULT hr;
5651 UINT i;
5653 TRACE( "%s, %p\n", debugstr_w(pszCanonicalName), ppkf );
5655 for (i = 0; i < fm->num_ids; i++)
5657 WCHAR *path, *name;
5658 hr = get_known_folder_registry_path( &fm->ids[i], NULL, &path );
5659 if (FAILED( hr )) return hr;
5661 hr = get_known_folder_wstr( path, szName, &name );
5662 HeapFree( GetProcessHeap(), 0, path );
5663 if (FAILED( hr )) return hr;
5665 found = !strcmpiW( pszCanonicalName, name );
5666 CoTaskMemFree( name );
5667 if (found) break;
5670 if (found)
5672 hr = knownfolder_create( &kf );
5673 if (FAILED( hr )) return hr;
5675 hr = knownfolder_set_id( kf, &fm->ids[i] );
5676 if (FAILED( hr ))
5678 IKnownFolder_Release( &kf->IKnownFolder_iface );
5679 return hr;
5681 *ppkf = &kf->IKnownFolder_iface;
5683 else
5685 hr = HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND );
5686 *ppkf = NULL;
5689 return hr;
5692 static HRESULT register_folder(const KNOWNFOLDERID *rfid, const KNOWNFOLDER_DEFINITION *pKFD)
5694 HRESULT hr;
5695 HKEY hKey = NULL;
5696 DWORD dwDisp;
5697 LPWSTR registryPath = NULL;
5699 hr = get_known_folder_registry_path(rfid, NULL, &registryPath);
5700 TRACE("registry path: %s\n", debugstr_w(registryPath));
5702 if(SUCCEEDED(hr))
5703 hr = HRESULT_FROM_WIN32(RegCreateKeyExW(HKEY_LOCAL_MACHINE, registryPath, 0, NULL, 0, KEY_WRITE, 0, &hKey, &dwDisp));
5705 if(SUCCEEDED(hr))
5707 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, szCategory, 0, REG_DWORD, (LPBYTE)&pKFD->category, sizeof(pKFD->category)));
5709 if(SUCCEEDED(hr) && pKFD->dwAttributes != 0)
5710 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, szAttributes, 0, REG_DWORD, (LPBYTE)&pKFD->dwAttributes, sizeof(pKFD->dwAttributes)));
5712 if(SUCCEEDED(hr))
5713 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, szName, 0, REG_SZ, (LPBYTE)pKFD->pszName, (lstrlenW(pKFD->pszName)+1)*sizeof(WCHAR) ));
5715 if(SUCCEEDED(hr) && pKFD->pszParsingName)
5716 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, szParsingName, 0, REG_SZ, (LPBYTE)pKFD->pszParsingName, (lstrlenW(pKFD->pszParsingName)+1)*sizeof(WCHAR) ));
5718 if(SUCCEEDED(hr) && !IsEqualGUID(&pKFD->fidParent, &GUID_NULL))
5720 WCHAR sParentGuid[39];
5721 StringFromGUID2(&pKFD->fidParent, sParentGuid, sizeof(sParentGuid)/sizeof(sParentGuid[0]));
5723 /* this known folder has parent folder */
5724 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, szParentFolder, 0, REG_SZ, (LPBYTE)sParentGuid, sizeof(sParentGuid)));
5727 if(SUCCEEDED(hr) && pKFD->category != KF_CATEGORY_VIRTUAL && pKFD->pszRelativePath)
5728 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, szRelativePath, 0, REG_SZ, (LPBYTE)pKFD->pszRelativePath, (lstrlenW(pKFD->pszRelativePath)+1)*sizeof(WCHAR) ));
5730 RegCloseKey(hKey);
5732 if(FAILED(hr))
5733 SHDeleteKeyW(HKEY_LOCAL_MACHINE, registryPath);
5736 HeapFree(GetProcessHeap(), 0, registryPath);
5737 return hr;
5740 static HRESULT WINAPI foldermanager_RegisterFolder(
5741 IKnownFolderManager *iface,
5742 REFKNOWNFOLDERID rfid,
5743 KNOWNFOLDER_DEFINITION const *pKFD)
5745 TRACE("(%p, %s, %p)\n", iface, debugstr_guid(rfid), pKFD);
5746 return register_folder(rfid, pKFD);
5749 static HRESULT WINAPI foldermanager_UnregisterFolder(
5750 IKnownFolderManager *iface,
5751 REFKNOWNFOLDERID rfid)
5753 HRESULT hr;
5754 LPWSTR registryPath = NULL;
5755 TRACE("(%p, %s)\n", iface, debugstr_guid(rfid));
5757 hr = get_known_folder_registry_path(rfid, NULL, &registryPath);
5759 if(SUCCEEDED(hr))
5760 hr = HRESULT_FROM_WIN32(SHDeleteKeyW(HKEY_LOCAL_MACHINE, registryPath));
5762 HeapFree(GetProcessHeap(), 0, registryPath);
5763 return hr;
5766 static HRESULT WINAPI foldermanager_FindFolderFromPath(
5767 IKnownFolderManager *iface,
5768 LPCWSTR pszPath,
5769 FFFP_MODE mode,
5770 IKnownFolder **ppkf)
5772 FIXME("%s, 0x%08x, %p\n", debugstr_w(pszPath), mode, ppkf);
5773 return E_NOTIMPL;
5776 static HRESULT WINAPI foldermanager_FindFolderFromIDList(
5777 IKnownFolderManager *iface,
5778 PCIDLIST_ABSOLUTE pidl,
5779 IKnownFolder **ppkf)
5781 FIXME("%p, %p\n", pidl, ppkf);
5782 return E_NOTIMPL;
5785 static HRESULT WINAPI foldermanager_Redirect(
5786 IKnownFolderManager *iface,
5787 REFKNOWNFOLDERID rfid,
5788 HWND hwnd,
5789 KF_REDIRECT_FLAGS flags,
5790 LPCWSTR pszTargetPath,
5791 UINT cFolders,
5792 KNOWNFOLDERID const *pExclusion,
5793 LPWSTR *ppszError)
5795 return redirect_known_folder(rfid, hwnd, flags, pszTargetPath, cFolders, pExclusion, ppszError);
5798 static const struct IKnownFolderManagerVtbl foldermanager_vtbl =
5800 foldermanager_QueryInterface,
5801 foldermanager_AddRef,
5802 foldermanager_Release,
5803 foldermanager_FolderIdFromCsidl,
5804 foldermanager_FolderIdToCsidl,
5805 foldermanager_GetFolderIds,
5806 foldermanager_GetFolder,
5807 foldermanager_GetFolderByName,
5808 foldermanager_RegisterFolder,
5809 foldermanager_UnregisterFolder,
5810 foldermanager_FindFolderFromPath,
5811 foldermanager_FindFolderFromIDList,
5812 foldermanager_Redirect
5815 static HRESULT foldermanager_create( void **ppv )
5817 UINT i, j;
5818 struct foldermanager *fm;
5820 fm = HeapAlloc( GetProcessHeap(), 0, sizeof(*fm) );
5821 if (!fm) return E_OUTOFMEMORY;
5823 fm->IKnownFolderManager_iface.lpVtbl = &foldermanager_vtbl;
5824 fm->refs = 1;
5825 fm->num_ids = 0;
5827 for (i = 0; i < sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]); i++)
5829 if (!IsEqualGUID( CSIDL_Data[i].id, &GUID_NULL )) fm->num_ids++;
5831 fm->ids = HeapAlloc( GetProcessHeap(), 0, fm->num_ids * sizeof(KNOWNFOLDERID) );
5832 if (!fm->ids)
5834 HeapFree( GetProcessHeap(), 0, fm );
5835 return E_OUTOFMEMORY;
5837 for (i = j = 0; i < sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]); i++)
5839 if (!IsEqualGUID( CSIDL_Data[i].id, &GUID_NULL ))
5841 fm->ids[j] = *CSIDL_Data[i].id;
5842 j++;
5845 TRACE("found %u known folders\n", fm->num_ids);
5846 *ppv = &fm->IKnownFolderManager_iface;
5848 TRACE("returning iface %p\n", *ppv);
5849 return S_OK;
5852 HRESULT WINAPI KnownFolderManager_Constructor( IUnknown *punk, REFIID riid, void **ppv )
5854 TRACE("%p, %s, %p\n", punk, debugstr_guid(riid), ppv);
5856 if (!ppv)
5857 return E_POINTER;
5858 if (punk)
5859 return CLASS_E_NOAGGREGATION;
5861 return foldermanager_create( ppv );
5864 HRESULT WINAPI SHGetKnownFolderIDList(REFKNOWNFOLDERID rfid, DWORD flags, HANDLE token, PIDLIST_ABSOLUTE *pidl)
5866 TRACE("%s, 0x%08x, %p, %p\n", debugstr_guid(rfid), flags, token, pidl);
5868 if (!pidl)
5869 return E_INVALIDARG;
5871 if (flags)
5872 FIXME("unsupported flags: 0x%08x\n", flags);
5874 if (token)
5875 FIXME("user token is not used.\n");
5877 *pidl = NULL;
5878 if (IsEqualIID(rfid, &FOLDERID_Desktop))
5879 *pidl = _ILCreateDesktop();
5880 else if (IsEqualIID(rfid, &FOLDERID_RecycleBinFolder))
5881 *pidl = _ILCreateBitBucket();
5882 else if (IsEqualIID(rfid, &FOLDERID_ComputerFolder))
5883 *pidl = _ILCreateMyComputer();
5884 else if (IsEqualIID(rfid, &FOLDERID_PrintersFolder))
5885 *pidl = _ILCreatePrinters();
5886 else if (IsEqualIID(rfid, &FOLDERID_ControlPanelFolder))
5887 *pidl = _ILCreateControlPanel();
5888 else if (IsEqualIID(rfid, &FOLDERID_NetworkFolder))
5889 *pidl = _ILCreateNetwork();
5890 else if (IsEqualIID(rfid, &FOLDERID_Documents))
5891 *pidl = _ILCreateMyDocuments();
5892 else
5894 DWORD attributes = 0;
5895 WCHAR *pathW;
5896 HRESULT hr;
5898 hr = SHGetKnownFolderPath(rfid, flags, token, &pathW);
5899 if (FAILED(hr))
5900 return hr;
5902 hr = SHILCreateFromPathW(pathW, pidl, &attributes);
5903 CoTaskMemFree(pathW);
5904 return hr;
5907 return *pidl ? S_OK : E_FAIL;
5910 HRESULT WINAPI SHGetKnownFolderItem(REFKNOWNFOLDERID rfid, KNOWN_FOLDER_FLAG flags, HANDLE hToken,
5911 REFIID riid, void **ppv)
5913 PIDLIST_ABSOLUTE pidl;
5914 HRESULT hr;
5916 TRACE("%s, 0x%08x, %p, %s, %p\n", debugstr_guid(rfid), flags, hToken, debugstr_guid(riid), ppv);
5918 hr = SHGetKnownFolderIDList(rfid, flags, hToken, &pidl);
5919 if (FAILED(hr))
5921 *ppv = NULL;
5922 return hr;
5925 hr = SHCreateItemFromIDList(pidl, riid, ppv);
5926 CoTaskMemFree(pidl);
5927 return hr;
5930 static void register_system_knownfolders(void)
5932 int i;
5933 for(i = 0; i < sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]); ++i){
5934 const CSIDL_DATA *folder = &CSIDL_Data[i];
5935 if(folder->pszName){
5936 KNOWNFOLDER_DEFINITION kfd;
5938 /* register_folder won't modify kfd, so cast away const instead of
5939 * reallocating */
5940 kfd.category = folder->category;
5941 kfd.pszName = (WCHAR*)folder->pszName;
5942 kfd.pszDescription = (WCHAR*)folder->pszDescription;
5943 memcpy(&kfd.fidParent, folder->fidParent, sizeof(KNOWNFOLDERID));
5944 kfd.pszRelativePath = (WCHAR*)folder->pszRelativePath;
5945 kfd.pszParsingName = (WCHAR*)folder->pszParsingName;
5946 kfd.pszTooltip = (WCHAR*)folder->pszTooltip;
5947 kfd.pszLocalizedName = (WCHAR*)folder->pszLocalizedName;
5948 kfd.pszIcon = (WCHAR*)folder->pszIcon;
5949 kfd.pszSecurity = (WCHAR*)folder->pszSecurity;
5950 kfd.dwAttributes = folder->dwAttributes;
5951 kfd.kfdFlags = folder->kfdFlags;
5952 memcpy(&kfd.ftidType, folder->ftidType, sizeof(FOLDERTYPEID));
5954 register_folder(folder->id, &kfd);
5959 HRESULT SHELL_RegisterShellFolders(void)
5961 HRESULT hr;
5963 /* Set up '$HOME' targeted symlinks for 'My Documents', 'My Pictures',
5964 * 'My Videos', 'My Music' and 'Desktop' in advance, so that the
5965 * _SHRegister*ShellFolders() functions will find everything nice and clean
5966 * and thus will not attempt to create them in the profile directory. */
5967 _SHCreateSymbolicLinks();
5969 hr = _SHRegisterUserShellFolders(TRUE);
5970 if (SUCCEEDED(hr))
5971 hr = _SHRegisterUserShellFolders(FALSE);
5972 if (SUCCEEDED(hr))
5973 hr = _SHRegisterCommonShellFolders();
5974 if (SUCCEEDED(hr))
5975 hr = create_extra_folders();
5976 if (SUCCEEDED(hr))
5977 hr = set_folder_attributes();
5978 if (SUCCEEDED(hr))
5979 register_system_knownfolders();
5980 return hr;