server: Do not accept sizeof(struct WS_sockaddr_in6_old).
[wine.git] / dlls / shell32 / shellpath.c
blob2ffd608f645673a3240cd99c6e6679e8fc8e969c
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 BOOL WINAPI PathFindOnPathExA(LPSTR,LPCSTR *,DWORD);
688 BOOL WINAPI PathFindOnPathExW(LPWSTR,LPCWSTR *,DWORD);
689 BOOL WINAPI PathFileExistsDefExtA(LPSTR,DWORD);
690 BOOL WINAPI PathFileExistsDefExtW(LPWSTR,DWORD);
692 static BOOL PathResolveA(char *path, const char **dirs, DWORD flags)
694 BOOL is_file_spec = PathIsFileSpecA(path);
695 DWORD dwWhich = flags & PRF_DONTFINDLNK ? 0xf : 0xff;
697 TRACE("(%s,%p,0x%08x)\n", debugstr_a(path), dirs, flags);
699 if (flags & PRF_VERIFYEXISTS && !PathFileExistsA(path))
701 if (PathFindOnPathExA(path, dirs, dwWhich))
702 return TRUE;
703 if (PathFileExistsDefExtA(path, dwWhich))
704 return TRUE;
705 if (!is_file_spec) GetFullPathNameA(path, MAX_PATH, path, NULL);
706 SetLastError(ERROR_FILE_NOT_FOUND);
707 return FALSE;
710 if (is_file_spec)
712 SetLastError(ERROR_FILE_NOT_FOUND);
713 return FALSE;
716 GetFullPathNameA(path, MAX_PATH, path, NULL);
718 return TRUE;
721 static BOOL PathResolveW(WCHAR *path, const WCHAR **dirs, DWORD flags)
723 BOOL is_file_spec = PathIsFileSpecW(path);
724 DWORD dwWhich = flags & PRF_DONTFINDLNK ? 0xf : 0xff;
726 TRACE("(%s,%p,0x%08x)\n", debugstr_w(path), dirs, flags);
728 if (flags & PRF_VERIFYEXISTS && !PathFileExistsW(path))
730 if (PathFindOnPathExW(path, dirs, dwWhich))
731 return TRUE;
732 if (PathFileExistsDefExtW(path, dwWhich))
733 return TRUE;
734 if (!is_file_spec) GetFullPathNameW(path, MAX_PATH, path, NULL);
735 SetLastError(ERROR_FILE_NOT_FOUND);
736 return FALSE;
739 if (is_file_spec)
741 SetLastError(ERROR_FILE_NOT_FOUND);
742 return FALSE;
745 GetFullPathNameW(path, MAX_PATH, path, NULL);
747 return TRUE;
750 /*************************************************************************
751 * PathResolve [SHELL32.51]
753 BOOL WINAPI PathResolveAW(void *path, const void **paths, DWORD flags)
755 if (SHELL_OsIsUnicode())
756 return PathResolveW(path, (const WCHAR **)paths, flags);
757 else
758 return PathResolveA(path, (const char **)paths, flags);
761 /*************************************************************************
762 * PathProcessCommandA
764 static LONG PathProcessCommandA (
765 LPCSTR lpszPath,
766 LPSTR lpszBuff,
767 DWORD dwBuffSize,
768 DWORD dwFlags)
770 FIXME("%s %p 0x%04x 0x%04x stub\n",
771 lpszPath, lpszBuff, dwBuffSize, dwFlags);
772 if(!lpszPath) return -1;
773 if(lpszBuff) strcpy(lpszBuff, lpszPath);
774 return strlen(lpszPath);
777 /*************************************************************************
778 * PathProcessCommandW
780 static LONG PathProcessCommandW (
781 LPCWSTR lpszPath,
782 LPWSTR lpszBuff,
783 DWORD dwBuffSize,
784 DWORD dwFlags)
786 FIXME("(%s, %p, 0x%04x, 0x%04x) stub\n",
787 debugstr_w(lpszPath), lpszBuff, dwBuffSize, dwFlags);
788 if(!lpszPath) return -1;
789 if(lpszBuff) strcpyW(lpszBuff, lpszPath);
790 return strlenW(lpszPath);
793 /*************************************************************************
794 * PathProcessCommand (SHELL32.653)
796 LONG WINAPI PathProcessCommandAW (
797 LPCVOID lpszPath,
798 LPVOID lpszBuff,
799 DWORD dwBuffSize,
800 DWORD dwFlags)
802 if (SHELL_OsIsUnicode())
803 return PathProcessCommandW(lpszPath, lpszBuff, dwBuffSize, dwFlags);
804 return PathProcessCommandA(lpszPath, lpszBuff, dwBuffSize, dwFlags);
808 ########## special ##########
811 /*************************************************************************
812 * PathSetDlgItemPath (SHELL32.48)
814 VOID WINAPI PathSetDlgItemPathAW(HWND hDlg, int id, LPCVOID pszPath)
816 if (SHELL_OsIsUnicode())
817 PathSetDlgItemPathW(hDlg, id, pszPath);
818 else
819 PathSetDlgItemPathA(hDlg, id, pszPath);
822 static const WCHAR szCategory[] = {'C','a','t','e','g','o','r','y',0};
823 static const WCHAR szAttributes[] = {'A','t','t','r','i','b','u','t','e','s',0};
824 static const WCHAR szName[] = {'N','a','m','e',0};
825 static const WCHAR szParsingName[] = {'P','a','r','s','i','n','g','N','a','m','e',0};
826 static const WCHAR szRelativePath[] = {'R','e','l','a','t','i','v','e','P','a','t','h',0};
827 static const WCHAR szParentFolder[] = {'P','a','r','e','n','t','F','o','l','d','e','r',0};
829 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'};
830 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};
831 static const WCHAR AppUpdatesFolderW[] = {'A','p','p','U','p','d','a','t','e','s','F','o','l','d','e','r',0};
832 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'};
833 static const WCHAR AppDataW[] = {'A','p','p','D','a','t','a','\0'};
834 static const WCHAR AppData_RoamingW[] = {'A','p','p','D','a','t','a','\\','R','o','a','m','i','n','g','\0'};
835 static const WCHAR AppData_LocalLowW[] = {'A','p','p','D','a','t','a','\\','L','o','c','a','l','L','o','w','\0'};
836 static const WCHAR AppData_LocalW[] = {'A','p','p','D','a','t','a','\\','L','o','c','a','l','\0'};
837 static const WCHAR CacheW[] = {'C','a','c','h','e','\0'};
838 static const WCHAR CD_BurningW[] = {'C','D',' ','B','u','r','n','i','n','g','\0'};
839 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};
840 static const WCHAR CommonW[] = {'C','o','m','m','o','n',0};
841 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'};
842 static const WCHAR Common_AppDataW[] = {'C','o','m','m','o','n',' ','A','p','p','D','a','t','a','\0'};
843 static const WCHAR Common_DesktopW[] = {'C','o','m','m','o','n',' ','D','e','s','k','t','o','p','\0'};
844 static const WCHAR Common_DocumentsW[] = {'C','o','m','m','o','n',' ','D','o','c','u','m','e','n','t','s','\0'};
845 static const WCHAR CommonDownloadsW[] = {'C','o','m','m','o','n','D','o','w','n','l','o','a','d','s',0};
846 static const WCHAR Common_FavoritesW[] = {'C','o','m','m','o','n',' ','F','a','v','o','r','i','t','e','s','\0'};
847 static const WCHAR CommonFilesDirW[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r','\0'};
848 static const WCHAR CommonFilesDirX86W[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r',' ','(','x','8','6',')','\0'};
849 static const WCHAR CommonMusicW[] = {'C','o','m','m','o','n','M','u','s','i','c','\0'};
850 static const WCHAR CommonPicturesW[] = {'C','o','m','m','o','n','P','i','c','t','u','r','e','s','\0'};
851 static const WCHAR Common_ProgramsW[] = {'C','o','m','m','o','n',' ','P','r','o','g','r','a','m','s','\0'};
852 static const WCHAR CommonRingtonesW[] = {'C','o','m','m','o','n','R','i','n','g','t','o','n','e','s',0};
853 static const WCHAR Common_StartUpW[] = {'C','o','m','m','o','n',' ','S','t','a','r','t','U','p','\0'};
854 static const WCHAR Common_StartupW[] = {'C','o','m','m','o','n',' ','S','t','a','r','t','u','p','\0'};
855 static const WCHAR Common_Start_MenuW[] = {'C','o','m','m','o','n',' ','S','t','a','r','t',' ','M','e','n','u','\0'};
856 static const WCHAR Common_TemplatesW[] = {'C','o','m','m','o','n',' ','T','e','m','p','l','a','t','e','s','\0'};
857 static const WCHAR CommonVideoW[] = {'C','o','m','m','o','n','V','i','d','e','o','\0'};
858 static const WCHAR ConflictFolderW[] = {'C','o','n','f','l','i','c','t','F','o','l','d','e','r',0};
859 static const WCHAR ConnectionsFolderW[] = {'C','o','n','n','e','c','t','i','o','n','s','F','o','l','d','e','r',0};
860 static const WCHAR ContactsW[] = {'C','o','n','t','a','c','t','s','\0'};
861 static const WCHAR ControlPanelFolderW[] = {'C','o','n','t','r','o','l','P','a','n','e','l','F','o','l','d','e','r',0};
862 static const WCHAR CookiesW[] = {'C','o','o','k','i','e','s','\0'};
863 static const WCHAR CSCFolderW[] = {'C','S','C','F','o','l','d','e','r',0};
864 static const WCHAR Default_GadgetsW[] = {'D','e','f','a','u','l','t',' ','G','a','d','g','e','t','s',0};
865 static const WCHAR DesktopW[] = {'D','e','s','k','t','o','p','\0'};
866 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};
867 static const WCHAR DocumentsW[] = {'D','o','c','u','m','e','n','t','s','\0'};
868 static const WCHAR DocumentsLibraryW[] = {'D','o','c','u','m','e','n','t','s','L','i','b','r','a','r','y','\0'};
869 static const WCHAR Documents_librarymsW[] = {'D','o','c','u','m','e','n','t','s','.','l','i','b','r','a','r','y','-','m','s',0};
870 static const WCHAR DownloadsW[] = {'D','o','w','n','l','o','a','d','s','\0'};
871 static const WCHAR FavoritesW[] = {'F','a','v','o','r','i','t','e','s','\0'};
872 static const WCHAR FontsW[] = {'F','o','n','t','s','\0'};
873 static const WCHAR GadgetsW[] = {'G','a','d','g','e','t','s',0};
874 static const WCHAR GamesW[] = {'G','a','m','e','s',0};
875 static const WCHAR GameTasksW[] = {'G','a','m','e','T','a','s','k','s',0};
876 static const WCHAR HistoryW[] = {'H','i','s','t','o','r','y','\0'};
877 static const WCHAR HomeGroupFolderW[] = {'H','o','m','e','G','r','o','u','p','F','o','l','d','e','r',0};
878 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};
879 static const WCHAR InternetFolderW[] = {'I','n','t','e','r','n','e','t','F','o','l','d','e','r',0};
880 static const WCHAR LibrariesW[] = {'L','i','b','r','a','r','i','e','s',0};
881 static const WCHAR LinksW[] = {'L','i','n','k','s','\0'};
882 static const WCHAR Local_AppDataW[] = {'L','o','c','a','l',' ','A','p','p','D','a','t','a','\0'};
883 static const WCHAR LocalAppDataLowW[] = {'L','o','c','a','l','A','p','p','D','a','t','a','L','o','w',0};
884 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};
885 static const WCHAR MAPIFolderW[] = {'M','A','P','I','F','o','l','d','e','r',0};
886 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};
887 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};
888 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'};
889 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};
890 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};
891 static const WCHAR Microsoft_Windows_INetCacheW[] = {'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','I','N','e','t','C','a','c','h','e',0};
892 static const WCHAR Microsoft_Windows_INetCookiesW[] = {'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','I','N','e','t','C','o','o','k','i','e','s',0};
893 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'};
894 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};
895 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};
896 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};
897 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'};
898 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'};
899 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};
900 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};
901 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};
902 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};
903 static const WCHAR Microsoft_Windows_ThemesW[] = {'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','T','h','e','m','e','s',0};
904 static const WCHAR MoviesW[] = {'M','o','v','i','e','s','\0'};
905 static const WCHAR MusicW[] = {'M','u','s','i','c','\0'};
906 static const WCHAR MusicLibraryW[] = {'M','u','s','i','c','L','i','b','r','a','r','y',0};
907 static const WCHAR Music_librarymsW[] = {'M','u','s','i','c','.','l','i','b','r','a','r','y','-','m','s',0};
908 static const WCHAR My_MusicW[] = {'M','y',' ','M','u','s','i','c','\0'};
909 static const WCHAR My_PicturesW[] = {'M','y',' ','P','i','c','t','u','r','e','s','\0'};
910 static const WCHAR My_VideosW[] = {'M','y',' ','V','i','d','e','o','s','\0'};
911 static const WCHAR My_VideoW[] = {'M','y',' ','V','i','d','e','o','\0'};
912 static const WCHAR MyComputerFolderW[] = {'M','y','C','o','m','p','u','t','e','r','F','o','l','d','e','r',0};
913 static const WCHAR NetHoodW[] = {'N','e','t','H','o','o','d','\0'};
914 static const WCHAR NetworkPlacesFolderW[] = {'N','e','t','w','o','r','k','P','l','a','c','e','s','F','o','l','d','e','r',0};
915 static const WCHAR OEM_LinksW[] = {'O','E','M',' ','L','i','n','k','s','\0'};
916 static const WCHAR Original_ImagesW[] = {'O','r','i','g','i','n','a','l',' ','I','m','a','g','e','s',0};
917 static const WCHAR PersonalW[] = {'P','e','r','s','o','n','a','l','\0'};
918 static const WCHAR PhotoAlbumsW[] = {'P','h','o','t','o','A','l','b','u','m','s',0};
919 static const WCHAR PicturesW[] = {'P','i','c','t','u','r','e','s','\0'};
920 static const WCHAR PicturesLibraryW[] = {'P','i','c','t','u','r','e','s','L','i','b','r','a','r','y',0};
921 static const WCHAR Pictures_librarymsW[] = {'P','i','c','t','u','r','e','s','.','l','i','b','r','a','r','y','-','m','s',0};
922 static const WCHAR PlaylistsW[] = {'P','l','a','y','l','i','s','t','s',0};
923 static const WCHAR PrintersFolderW[] = {'P','r','i','n','t','e','r','s','F','o','l','d','e','r',0};
924 static const WCHAR PrintHoodW[] = {'P','r','i','n','t','H','o','o','d','\0'};
925 static const WCHAR ProfileW[] = {'P','r','o','f','i','l','e',0};
926 static const WCHAR ProgramDataW[] = {'P','r','o','g','r','a','m','D','a','t','a','\0'};
927 static const WCHAR Program_FilesW[] = {'P','r','o','g','r','a','m',' ','F','i','l','e','s','\0'};
928 static const WCHAR ProgramFilesW[] = {'P','r','o','g','r','a','m','F','i','l','e','s','\0'};
929 static const WCHAR ProgramFilesX86W[] = {'P','r','o','g','r','a','m','F','i','l','e','s','X','8','6','\0'};
930 static const WCHAR ProgramFilesX64W[] = {'P','r','o','g','r','a','m','F','i','l','e','s','X','6','4','\0'};
931 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'};
932 static const WCHAR Program_Files_x86W[] = {'P','r','o','g','r','a','m',' ','F','i','l','e','s',' ','(','x','8','6',')','\0'};
933 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'};
934 static const WCHAR ProgramFilesCommonW[] = {'P','r','o','g','r','a','m','F','i','l','e','s','C','o','m','m','o','n',0};
935 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};
936 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};
937 static const WCHAR ProgramFilesDirW[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r','\0'};
938 static const WCHAR ProgramFilesDirX86W[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r',' ','(','x','8','6',')','\0'};
939 static const WCHAR ProgramsW[] = {'P','r','o','g','r','a','m','s','\0'};
940 static const WCHAR PublicW[] = {'P','u','b','l','i','c',0};
941 static const WCHAR PublicGameTasksW[] = {'P','u','b','l','i','c','G','a','m','e','T','a','s','k','s',0};
942 static const WCHAR PublicLibrariesW[] = {'P','u','b','l','i','c','L','i','b','r','a','r','i','e','s',0};
943 static const WCHAR Quick_LaunchW[] = {'Q','u','i','c','k',' ','L','a','u','n','c','h',0};
944 static const WCHAR RecentW[] = {'R','e','c','e','n','t','\0'};
945 static const WCHAR RecordedTVLibraryW[] = {'R','e','c','o','r','d','e','d','T','V','L','i','b','r','a','r','y',0};
946 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};
947 static const WCHAR RecycleBinFolderW[] = {'R','e','c','y','c','l','e','B','i','n','F','o','l','d','e','r',0};
948 static const WCHAR ResourceDirW[] = {'R','e','s','o','u','r','c','e','D','i','r','\0'};
949 static const WCHAR ResourcesW[] = {'R','e','s','o','u','r','c','e','s','\0'};
950 static const WCHAR RingtonesW[] = {'R','i','n','g','t','o','n','e','s',0};
951 static const WCHAR SampleMusicW[] = {'S','a','m','p','l','e','M','u','s','i','c',0};
952 static const WCHAR Sample_MusicW[] = {'S','a','m','p','l','e',' ','M','u','s','i','c',0};
953 static const WCHAR SamplePicturesW[] = {'S','a','m','p','l','e','P','i','c','t','u','r','e','s',0};
954 static const WCHAR Sample_PicturesW[] = {'S','a','m','p','l','e',' ','P','i','c','t','u','r','e','s',0};
955 static const WCHAR SamplePlaylistsW[] = {'S','a','m','p','l','e','P','l','a','y','l','i','s','t','s',0};
956 static const WCHAR Sample_PlaylistsW[] = {'S','a','m','p','l','e',' ','P','l','a','y','l','i','s','t','s',0};
957 static const WCHAR Sample_VideosW[] = {'S','a','m','p','l','e',' ','V','i','d','e','o','s',0};
958 static const WCHAR SampleVideosW[] = {'S','a','m','p','l','e','V','i','d','e','o','s',0};
959 static const WCHAR Saved_GamesW[] = {'S','a','v','e','d',' ','G','a','m','e','s','\0'};
960 static const WCHAR SavedGamesW[] = {'S','a','v','e','d','G','a','m','e','s','\0'};
961 static const WCHAR SearchesW[] = {'S','e','a','r','c','h','e','s','\0'};
962 static const WCHAR SearchHomeFolderW[] = {'S','e','a','r','c','h','H','o','m','e','F','o','l','d','e','r',0};
963 static const WCHAR SendToW[] = {'S','e','n','d','T','o','\0'};
964 static const WCHAR Slide_ShowsW[] = {'S','l','i','d','e',' ','S','h','o','w','s',0};
965 static const WCHAR StartUpW[] = {'S','t','a','r','t','U','p','\0'};
966 static const WCHAR StartupW[] = {'S','t','a','r','t','u','p','\0'};
967 static const WCHAR Start_MenuW[] = {'S','t','a','r','t',' ','M','e','n','u','\0'};
968 static const WCHAR SyncCenterFolderW[] = {'S','y','n','c','C','e','n','t','e','r','F','o','l','d','e','r',0};
969 static const WCHAR SyncResultsFolderW[] = {'S','y','n','c','R','e','s','u','l','t','s','F','o','l','d','e','r',0};
970 static const WCHAR SyncSetupFolderW[] = {'S','y','n','c','S','e','t','u','p','F','o','l','d','e','r',0};
971 static const WCHAR SystemW[] = {'S','y','s','t','e','m',0};
972 static const WCHAR SystemX86W[] = {'S','y','s','t','e','m','X','8','6',0};
973 static const WCHAR TemplatesW[] = {'T','e','m','p','l','a','t','e','s','\0'};
974 static const WCHAR User_PinnedW[] = {'U','s','e','r',' ','P','i','n','n','e','d',0};
975 static const WCHAR UsersW[] = {'U','s','e','r','s','\0'};
976 static const WCHAR UsersFilesFolderW[] = {'U','s','e','r','s','F','i','l','e','s','F','o','l','d','e','r',0};
977 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};
978 static const WCHAR UserProfilesW[] = {'U','s','e','r','P','r','o','f','i','l','e','s',0};
979 static const WCHAR UserProgramFilesW[] = {'U','s','e','r','P','r','o','g','r','a','m','F','i','l','e','s',0};
980 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};
981 static const WCHAR UsersPublicW[] = {'u','s','e','r','s','\\','P','u','b','l','i','c','\0'};
982 static const WCHAR VideosW[] = {'V','i','d','e','o','s','\0'};
983 static const WCHAR VideosLibraryW[] = {'V','i','d','e','o','s','L','i','b','r','a','r','y',0};
984 static const WCHAR Videos_librarymsW[] = {'V','i','d','e','o','s','.','l','i','b','r','a','r','y','-','m','s',0};
985 static const WCHAR WindowsW[] = {'W','i','n','d','o','w','s',0};
986 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};
987 static const WCHAR DefaultW[] = {'.','D','e','f','a','u','l','t','\0'};
988 static const WCHAR AllUsersProfileW[] = {'%','A','L','L','U','S','E','R','S','P','R','O','F','I','L','E','%','\0'};
989 static const WCHAR PublicProfileW[] = {'%','P','U','B','L','I','C','%',0};
990 static const WCHAR UserProfileW[] = {'%','U','S','E','R','P','R','O','F','I','L','E','%','\0'};
991 static const WCHAR ProgramDataVarW[] = {'%','P','r','o','g','r','a','m','D','a','t','a','%','\0'};
992 static const WCHAR SystemDriveW[] = {'%','S','y','s','t','e','m','D','r','i','v','e','%','\0'};
993 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};
994 static const WCHAR ProfilesDirectoryW[] = {'P','r','o','f','i','l','e','s','D','i','r','e','c','t','o','r','y',0};
995 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'};
996 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'};
997 static const WCHAR szDefaultProfileDirW[] = {'u','s','e','r','s',0};
998 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'};
999 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};
1001 #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','}'
1002 #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','}'
1003 #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','}'
1004 #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','}'
1005 #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','}'
1007 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};
1008 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};
1009 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};
1010 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};
1011 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};
1012 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};
1013 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};
1014 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};
1015 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};
1016 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};
1017 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};
1018 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};
1019 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};
1020 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};
1021 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};
1022 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};
1023 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};
1024 static const WCHAR ChangeRemoveProgramsParsingNameW[] = {':',':', SYSTEMFOLDERS_PARSING_GUID, '\\',':',':', CHANGEREMOVEPROGRAMS_PARSING_GUID, 0};
1025 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};
1026 static const WCHAR SyncManagerFolderParsingNameW[] = {':',':', SYSTEMFOLDERS_PARSING_GUID, '\\',':',':', SYNCMANAGER_PARSING_GUID, 0};
1027 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};
1028 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};
1029 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};
1030 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};
1031 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};
1032 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};
1033 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};
1034 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};
1035 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};
1036 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};
1037 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};
1038 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};
1039 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};
1040 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};
1041 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};
1043 typedef enum _CSIDL_Type {
1044 CSIDL_Type_User,
1045 CSIDL_Type_AllUsers,
1046 CSIDL_Type_CurrVer,
1047 CSIDL_Type_Disallowed,
1048 CSIDL_Type_NonExistent,
1049 CSIDL_Type_WindowsPath,
1050 CSIDL_Type_SystemPath,
1051 CSIDL_Type_SystemX86Path,
1052 CSIDL_Type_ProgramData,
1053 } CSIDL_Type;
1055 #define CSIDL_CONTACTS 0x0043
1056 #define CSIDL_DOWNLOADS 0x0047
1057 #define CSIDL_LINKS 0x004d
1058 #define CSIDL_APPDATA_LOCALLOW 0x004e
1059 #define CSIDL_SAVED_GAMES 0x0062
1060 #define CSIDL_SEARCHES 0x0063
1062 typedef struct
1064 IApplicationDestinations IApplicationDestinations_iface;
1065 LONG ref;
1066 } IApplicationDestinationsImpl;
1068 static inline IApplicationDestinationsImpl *impl_from_IApplicationDestinations( IApplicationDestinations *iface )
1070 return CONTAINING_RECORD(iface, IApplicationDestinationsImpl, IApplicationDestinations_iface);
1073 static HRESULT WINAPI ApplicationDestinations_QueryInterface(IApplicationDestinations *iface, REFIID riid,
1074 LPVOID *ppv)
1076 IApplicationDestinationsImpl *This = impl_from_IApplicationDestinations(iface);
1078 TRACE("(%p, %s, %p)\n", This, debugstr_guid(riid), ppv);
1080 if (ppv == NULL)
1081 return E_POINTER;
1083 if (IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IApplicationDestinations, riid))
1085 *ppv = &This->IApplicationDestinations_iface;
1086 IUnknown_AddRef((IUnknown*)*ppv);
1088 TRACE("Returning IApplicationDestinations: %p\n", *ppv);
1089 return S_OK;
1092 *ppv = NULL;
1093 FIXME("(%p)->(%s, %p) interface not supported.\n", This, debugstr_guid(riid), ppv);
1095 return E_NOINTERFACE;
1098 static ULONG WINAPI ApplicationDestinations_AddRef(IApplicationDestinations *iface)
1100 IApplicationDestinationsImpl *This = impl_from_IApplicationDestinations(iface);
1101 ULONG ref = InterlockedIncrement(&This->ref);
1103 TRACE("(%p), new refcount=%i\n", This, ref);
1105 return ref;
1108 static ULONG WINAPI ApplicationDestinations_Release(IApplicationDestinations *iface)
1110 IApplicationDestinationsImpl *This = impl_from_IApplicationDestinations(iface);
1111 ULONG ref = InterlockedDecrement(&This->ref);
1113 TRACE("(%p), new refcount=%i\n", This, ref);
1115 if (ref == 0)
1116 heap_free(This);
1118 return ref;
1121 static HRESULT WINAPI ApplicationDestinations_SetAppID(IApplicationDestinations *iface, const WCHAR *appid)
1123 IApplicationDestinationsImpl *This = impl_from_IApplicationDestinations(iface);
1125 FIXME("(%p, %s) stub!\n", This, debugstr_w(appid));
1127 return E_NOTIMPL;
1130 static HRESULT WINAPI ApplicationDestinations_RemoveDestination(IApplicationDestinations *iface, IUnknown *punk)
1132 IApplicationDestinationsImpl *This = impl_from_IApplicationDestinations(iface);
1134 FIXME("(%p, %p) stub!\n", This, punk);
1136 return E_NOTIMPL;
1139 static HRESULT WINAPI ApplicationDestinations_RemoveAllDestinations(IApplicationDestinations *iface)
1141 IApplicationDestinationsImpl *This = impl_from_IApplicationDestinations(iface);
1143 FIXME("(%p) stub!\n", This);
1145 return E_NOTIMPL;
1148 static const IApplicationDestinationsVtbl ApplicationDestinationsVtbl =
1150 ApplicationDestinations_QueryInterface,
1151 ApplicationDestinations_AddRef,
1152 ApplicationDestinations_Release,
1153 ApplicationDestinations_SetAppID,
1154 ApplicationDestinations_RemoveDestination,
1155 ApplicationDestinations_RemoveAllDestinations
1158 HRESULT WINAPI ApplicationDestinations_Constructor(IUnknown *outer, REFIID riid, LPVOID *ppv)
1160 IApplicationDestinationsImpl *This;
1161 HRESULT hr;
1163 TRACE("(%p, %s, %p)\n", outer, debugstr_guid(riid), ppv);
1165 if (outer)
1166 return CLASS_E_NOAGGREGATION;
1168 if (!(This = SHAlloc(sizeof(*This))))
1169 return E_OUTOFMEMORY;
1171 This->IApplicationDestinations_iface.lpVtbl = &ApplicationDestinationsVtbl;
1172 This->ref = 0;
1174 hr = IUnknown_QueryInterface(&This->IApplicationDestinations_iface, riid, ppv);
1175 if (FAILED(hr))
1176 SHFree(This);
1178 return hr;
1181 typedef struct
1183 const KNOWNFOLDERID *id;
1184 CSIDL_Type type;
1185 LPCWSTR szValueName;
1186 LPCWSTR szDefaultPath; /* fallback string or resource ID */
1188 /* KNOWNFOLDER_DEFINITION fields */
1189 KF_CATEGORY category;
1190 const WCHAR *pszName;
1191 const WCHAR *pszDescription;
1192 const KNOWNFOLDERID *fidParent;
1193 const WCHAR *pszRelativePath;
1194 const WCHAR *pszParsingName;
1195 const WCHAR *pszTooltip;
1196 const WCHAR *pszLocalizedName;
1197 const WCHAR *pszIcon;
1198 const WCHAR *pszSecurity;
1199 DWORD dwAttributes;
1200 KF_DEFINITION_FLAGS kfdFlags;
1201 const FOLDERTYPEID *ftidType;
1202 } CSIDL_DATA;
1204 static const CSIDL_DATA CSIDL_Data[] =
1206 { /* 0x00 - CSIDL_DESKTOP */
1207 &FOLDERID_Desktop,
1208 CSIDL_Type_User,
1209 DesktopW,
1210 NULL,
1212 KF_CATEGORY_PERUSER, /* category */
1213 DesktopW, /* name */
1214 NULL, /* description */
1215 &GUID_NULL, /* parent */
1216 DesktopW, /* relative path */
1217 NULL, /* parsing */
1218 NULL, /* tooltip */
1219 NULL, /* localized */
1220 NULL, /* icon */
1221 NULL, /* security */
1222 FILE_ATTRIBUTE_READONLY, /* attributes */
1223 0, /* flags */
1224 &GUID_NULL /* typeid */
1226 { /* 0x01 - CSIDL_INTERNET */
1227 &FOLDERID_InternetFolder,
1228 CSIDL_Type_Disallowed,
1229 NULL,
1230 NULL,
1232 KF_CATEGORY_VIRTUAL, /* category */
1233 InternetFolderW, /* name */
1234 NULL, /* description */
1235 &GUID_NULL, /* parent */
1236 NULL, /* relative path */
1237 InternetFolderParsingNameW, /* parsing */
1238 NULL, /* tooltip */
1239 NULL, /* localized */
1240 NULL, /* icon */
1241 NULL, /* security */
1242 0, /* attributes */
1243 0, /* flags */
1244 &GUID_NULL /* typeid */
1246 { /* 0x02 - CSIDL_PROGRAMS */
1247 &FOLDERID_Programs,
1248 CSIDL_Type_User,
1249 ProgramsW,
1250 NULL,
1252 KF_CATEGORY_PERUSER, /* category */
1253 ProgramsW, /* name */
1254 NULL, /* description */
1255 &FOLDERID_StartMenu, /* parent */
1256 ProgramsW, /* relative path */
1257 NULL, /* parsing */
1258 NULL, /* tooltip */
1259 NULL, /* localized */
1260 NULL, /* icon */
1261 NULL, /* security */
1262 FILE_ATTRIBUTE_READONLY, /* attributes */
1263 0, /* flags */
1264 &GUID_NULL /* typeid */
1266 { /* 0x03 - CSIDL_CONTROLS (.CPL files) */
1267 &FOLDERID_ControlPanelFolder,
1268 CSIDL_Type_SystemPath,
1269 NULL,
1270 NULL,
1272 KF_CATEGORY_VIRTUAL, /* category */
1273 ControlPanelFolderW, /* name */
1274 NULL, /* description */
1275 &GUID_NULL, /* parent */
1276 ControlPanelFolderRelativePathW, /* relative path */
1277 ControlPanelFolderParsingNameW, /* parsing */
1278 NULL, /* tooltip */
1279 NULL, /* localized */
1280 NULL, /* icon */
1281 NULL, /* security */
1282 0, /* attributes */
1283 0, /* flags */
1284 &GUID_NULL /* typeid */
1286 { /* 0x04 - CSIDL_PRINTERS */
1287 &FOLDERID_PrintersFolder,
1288 CSIDL_Type_SystemPath,
1289 NULL,
1290 NULL,
1292 KF_CATEGORY_VIRTUAL, /* category */
1293 PrintersFolderW, /* name */
1294 NULL, /* description */
1295 &GUID_NULL, /* parent */
1296 NULL, /* relative path */
1297 PrintersFolderParsingNameW, /* parsing */
1298 NULL, /* tooltip */
1299 NULL, /* localized */
1300 NULL, /* icon */
1301 NULL, /* security */
1302 0, /* attributes */
1303 0, /* flags */
1304 &GUID_NULL /* typeid */
1306 { /* 0x05 - CSIDL_PERSONAL */
1307 &FOLDERID_Documents,
1308 CSIDL_Type_User,
1309 PersonalW,
1310 NULL,
1312 KF_CATEGORY_PERUSER, /* category */
1313 PersonalW, /* name */
1314 NULL, /* description */
1315 &FOLDERID_Profile, /* parent */
1316 DocumentsW, /* relative path */
1317 DocumentsParsingNameW, /* parsing */
1318 NULL, /* tooltip */
1319 NULL, /* localized */
1320 NULL, /* icon */
1321 NULL, /* security */
1322 FILE_ATTRIBUTE_READONLY, /* attributes */
1323 KFDF_ROAMABLE | KFDF_PRECREATE, /* flags */
1324 &GUID_NULL /* typeid */
1326 { /* 0x06 - CSIDL_FAVORITES */
1327 &FOLDERID_Favorites,
1328 CSIDL_Type_User,
1329 FavoritesW,
1330 NULL,
1332 KF_CATEGORY_PERUSER, /* category */
1333 FavoritesW, /* name */
1334 NULL, /* description */
1335 &GUID_NULL, /* parent */
1336 FavoritesW, /* relative path */
1337 NULL, /* parsing */
1338 NULL, /* tooltip */
1339 NULL, /* localized */
1340 NULL, /* icon */
1341 NULL, /* security */
1342 FILE_ATTRIBUTE_READONLY, /* attributes */
1343 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH, /* flags */
1344 &GUID_NULL /* typeid */
1346 { /* 0x07 - CSIDL_STARTUP */
1347 &FOLDERID_Startup,
1348 CSIDL_Type_User,
1349 StartUpW,
1350 NULL,
1352 KF_CATEGORY_PERUSER, /* category */
1353 StartupW, /* name */
1354 NULL, /* description */
1355 &FOLDERID_Programs, /* parent */
1356 StartUpW, /* relative path */
1357 NULL, /* parsing */
1358 NULL, /* tooltip */
1359 NULL, /* localized */
1360 NULL, /* icon */
1361 NULL, /* security */
1362 FILE_ATTRIBUTE_READONLY, /* attributes */
1363 KFDF_PRECREATE, /* flags */
1364 &GUID_NULL /* typeid */
1366 { /* 0x08 - CSIDL_RECENT */
1367 &FOLDERID_Recent,
1368 CSIDL_Type_User,
1369 RecentW,
1370 NULL,
1372 KF_CATEGORY_PERUSER, /* category */
1373 RecentW, /* name */
1374 NULL, /* description */
1375 &FOLDERID_RoamingAppData, /* parent */
1376 Microsoft_Windows_RecentW, /* relative path */
1377 NULL, /* parsing */
1378 NULL, /* tooltip */
1379 NULL, /* localized */
1380 NULL, /* icon */
1381 NULL, /* security */
1382 FILE_ATTRIBUTE_READONLY, /* attributes */
1383 KFDF_PRECREATE, /* flags */
1384 &GUID_NULL /* typeid */
1386 { /* 0x09 - CSIDL_SENDTO */
1387 &FOLDERID_SendTo,
1388 CSIDL_Type_User,
1389 SendToW,
1390 NULL,
1392 KF_CATEGORY_PERUSER, /* category */
1393 SendToW, /* name */
1394 NULL, /* description */
1395 &FOLDERID_RoamingAppData, /* parent */
1396 Microsoft_Windows_SendToW, /* relative path */
1397 NULL, /* parsing */
1398 NULL, /* tooltip */
1399 NULL, /* localized */
1400 NULL, /* icon */
1401 NULL, /* security */
1402 0, /* attributes */
1403 KFDF_PRECREATE, /* flags */
1404 &GUID_NULL /* typeid */
1406 { /* 0x0a - CSIDL_BITBUCKET - Recycle Bin */
1407 &FOLDERID_RecycleBinFolder,
1408 CSIDL_Type_Disallowed,
1409 NULL,
1410 NULL,
1412 KF_CATEGORY_VIRTUAL, /* category */
1413 RecycleBinFolderW, /* name */
1414 NULL, /* description */
1415 &GUID_NULL, /* parent */
1416 NULL, /* relative path */
1417 RecycleBinFolderParsingNameW, /* parsing */
1418 NULL, /* tooltip */
1419 NULL, /* localized */
1420 NULL, /* icon */
1421 NULL, /* security */
1422 0, /* attributes */
1423 0, /* flags */
1424 &GUID_NULL /* typeid */
1426 { /* 0x0b - CSIDL_STARTMENU */
1427 &FOLDERID_StartMenu,
1428 CSIDL_Type_User,
1429 Start_MenuW,
1430 NULL,
1432 KF_CATEGORY_PERUSER, /* category */
1433 Start_MenuW, /* name */
1434 NULL, /* description */
1435 &FOLDERID_RoamingAppData, /* parent */
1436 Microsoft_Windows_Start_MenuW, /* relative path */
1437 NULL, /* parsing */
1438 NULL, /* tooltip */
1439 NULL, /* localized */
1440 NULL, /* icon */
1441 NULL, /* security */
1442 FILE_ATTRIBUTE_READONLY, /* attributes */
1443 KFDF_PRECREATE, /* flags */
1444 &GUID_NULL /* typeid */
1446 { /* 0x0c - CSIDL_MYDOCUMENTS */
1447 &GUID_NULL,
1448 CSIDL_Type_Disallowed, /* matches WinXP--can't get its path */
1449 NULL,
1450 NULL
1452 { /* 0x0d - CSIDL_MYMUSIC */
1453 &FOLDERID_Music,
1454 CSIDL_Type_User,
1455 My_MusicW,
1456 NULL,
1458 KF_CATEGORY_PERUSER, /* category */
1459 My_MusicW, /* name */
1460 NULL, /* description */
1461 &FOLDERID_Profile, /* parent */
1462 MusicW, /* relative path */
1463 MusicParsingNameW, /* parsing */
1464 NULL, /* tooltip */
1465 NULL, /* localized */
1466 NULL, /* icon */
1467 NULL, /* security */
1468 FILE_ATTRIBUTE_READONLY, /* attributes */
1469 KFDF_ROAMABLE | KFDF_PRECREATE, /* flags */
1470 &GUID_NULL /* typeid */
1472 { /* 0x0e - CSIDL_MYVIDEO */
1473 &FOLDERID_Videos,
1474 CSIDL_Type_User,
1475 My_VideosW,
1476 NULL,
1478 KF_CATEGORY_PERUSER, /* category */
1479 My_VideoW, /* name */
1480 NULL, /* description */
1481 &FOLDERID_Profile, /* parent */
1482 VideosW, /* relative path */
1483 VideosParsingNameW, /* parsing */
1484 NULL, /* tooltip */
1485 NULL, /* localized */
1486 NULL, /* icon */
1487 NULL, /* security */
1488 FILE_ATTRIBUTE_READONLY, /* attributes */
1489 KFDF_ROAMABLE | KFDF_PRECREATE, /* flags */
1490 &GUID_NULL /* typeid */
1492 { /* 0x0f - unassigned */
1493 &GUID_NULL,
1494 CSIDL_Type_Disallowed,
1495 NULL,
1496 NULL,
1498 { /* 0x10 - CSIDL_DESKTOPDIRECTORY */
1499 &FOLDERID_Desktop,
1500 CSIDL_Type_User,
1501 DesktopW,
1502 NULL,
1504 KF_CATEGORY_PERUSER, /* category */
1505 DesktopW, /* name */
1506 NULL, /* description */
1507 &FOLDERID_Profile, /* parent */
1508 DesktopW, /* relative path */
1509 NULL, /* parsing */
1510 NULL, /* tooltip */
1511 NULL, /* localized */
1512 NULL, /* icon */
1513 NULL, /* security */
1514 FILE_ATTRIBUTE_READONLY, /* attributes */
1515 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH, /* flags */
1516 &GUID_NULL /* typeid */
1518 { /* 0x11 - CSIDL_DRIVES */
1519 &FOLDERID_ComputerFolder,
1520 CSIDL_Type_Disallowed,
1521 NULL,
1522 NULL,
1524 KF_CATEGORY_VIRTUAL, /* category */
1525 MyComputerFolderW, /* name */
1526 NULL, /* description */
1527 &GUID_NULL, /* parent */
1528 NULL, /* relative path */
1529 ComputerFolderParsingNameW, /* parsing */
1530 NULL, /* tooltip */
1531 NULL, /* localized */
1532 NULL, /* icon */
1533 NULL, /* security */
1534 0, /* attributes */
1535 0, /* flags */
1536 &GUID_NULL /* typeid */
1538 { /* 0x12 - CSIDL_NETWORK */
1539 &FOLDERID_NetworkFolder,
1540 CSIDL_Type_Disallowed,
1541 NULL,
1542 NULL,
1544 KF_CATEGORY_VIRTUAL, /* category */
1545 NetworkPlacesFolderW, /* name */
1546 NULL, /* description */
1547 &GUID_NULL, /* parent */
1548 NULL, /* relative path */
1549 NetworkFolderParsingNameW, /* parsing */
1550 NULL, /* tooltip */
1551 NULL, /* localized */
1552 NULL, /* icon */
1553 NULL, /* security */
1554 0, /* attributes */
1555 0, /* flags */
1556 &GUID_NULL /* typeid */
1558 { /* 0x13 - CSIDL_NETHOOD */
1559 &FOLDERID_NetHood,
1560 CSIDL_Type_User,
1561 NetHoodW,
1562 NULL,
1564 KF_CATEGORY_PERUSER, /* category */
1565 NetHoodW, /* name */
1566 NULL, /* description */
1567 &FOLDERID_RoamingAppData, /* parent */
1568 Microsoft_Windows_Network_ShortcutsW, /* relative path */
1569 NULL, /* parsing */
1570 NULL, /* tooltip */
1571 NULL, /* localized */
1572 NULL, /* icon */
1573 NULL, /* security */
1574 0, /* attributes */
1575 0, /* flags */
1576 &GUID_NULL /* typeid */
1578 { /* 0x14 - CSIDL_FONTS */
1579 &FOLDERID_Fonts,
1580 CSIDL_Type_WindowsPath,
1581 FontsW,
1582 FontsW,
1584 KF_CATEGORY_FIXED, /* category */
1585 FontsW, /* name */
1586 NULL, /* description */
1587 &FOLDERID_Windows, /* parent */
1588 NULL, /* relative path */
1589 NULL, /* parsing */
1590 NULL, /* tooltip */
1591 NULL, /* localized */
1592 NULL, /* icon */
1593 NULL, /* security */
1594 0, /* attributes */
1595 0, /* flags */
1596 &FOLDERID_Windows/* typeid */
1598 { /* 0x15 - CSIDL_TEMPLATES */
1599 &FOLDERID_Templates,
1600 CSIDL_Type_User,
1601 TemplatesW,
1602 NULL,
1604 KF_CATEGORY_PERUSER, /* category */
1605 TemplatesW, /* name */
1606 NULL, /* description */
1607 &FOLDERID_RoamingAppData, /* parent */
1608 Microsoft_Windows_TemplatesW, /* relative path */
1609 NULL, /* parsing */
1610 NULL, /* tooltip */
1611 NULL, /* localized */
1612 NULL, /* icon */
1613 NULL, /* security */
1614 0, /* attributes */
1615 0, /* flags */
1616 &GUID_NULL /* typeid */
1618 { /* 0x16 - CSIDL_COMMON_STARTMENU */
1619 &FOLDERID_CommonStartMenu,
1620 CSIDL_Type_ProgramData,
1621 Common_Start_MenuW,
1622 NULL,
1624 KF_CATEGORY_COMMON, /* category */
1625 Common_Start_MenuW, /* name */
1626 NULL, /* description */
1627 &FOLDERID_ProgramData, /* parent */
1628 Microsoft_Windows_Start_MenuW, /* relative path */
1629 NULL, /* parsing */
1630 NULL, /* tooltip */
1631 NULL, /* localized */
1632 NULL, /* icon */
1633 NULL, /* security */
1634 FILE_ATTRIBUTE_READONLY, /* attributes */
1635 0, /* flags */
1636 &GUID_NULL /* typeid */
1638 { /* 0x17 - CSIDL_COMMON_PROGRAMS */
1639 &FOLDERID_CommonPrograms,
1640 CSIDL_Type_ProgramData,
1641 Common_ProgramsW,
1642 NULL,
1644 KF_CATEGORY_COMMON, /* category */
1645 Common_ProgramsW, /* name */
1646 NULL, /* description */
1647 &FOLDERID_CommonStartMenu, /* parent */
1648 ProgramsW, /* relative path */
1649 NULL, /* parsing */
1650 NULL, /* tooltip */
1651 NULL, /* localized */
1652 NULL, /* icon */
1653 NULL, /* security */
1654 FILE_ATTRIBUTE_READONLY, /* attributes */
1655 0, /* flags */
1656 &GUID_NULL /* typeid */
1658 { /* 0x18 - CSIDL_COMMON_STARTUP */
1659 &FOLDERID_CommonStartup,
1660 CSIDL_Type_ProgramData,
1661 Common_StartUpW,
1662 NULL,
1664 KF_CATEGORY_COMMON, /* category */
1665 Common_StartupW, /* name */
1666 NULL, /* description */
1667 &FOLDERID_CommonPrograms, /* parent */
1668 StartUpW, /* relative path */
1669 NULL, /* parsing */
1670 NULL, /* tooltip */
1671 NULL, /* localized */
1672 NULL, /* icon */
1673 NULL, /* security */
1674 FILE_ATTRIBUTE_READONLY, /* attributes */
1675 KFDF_PRECREATE, /* flags */
1676 &GUID_NULL /* typeid */
1678 { /* 0x19 - CSIDL_COMMON_DESKTOPDIRECTORY */
1679 &FOLDERID_PublicDesktop,
1680 CSIDL_Type_AllUsers,
1681 Common_DesktopW,
1682 NULL,
1684 KF_CATEGORY_COMMON, /* category */
1685 Common_DesktopW, /* name */
1686 NULL, /* description */
1687 &FOLDERID_Public, /* parent */
1688 DesktopW, /* relative path */
1689 NULL, /* parsing */
1690 NULL, /* tooltip */
1691 NULL, /* localized */
1692 NULL, /* icon */
1693 NULL, /* security */
1694 FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN, /* attributes */
1695 KFDF_PRECREATE, /* flags */
1696 &GUID_NULL /* typeid */
1698 { /* 0x1a - CSIDL_APPDATA */
1699 &FOLDERID_RoamingAppData,
1700 CSIDL_Type_User,
1701 AppDataW,
1702 NULL,
1704 KF_CATEGORY_PERUSER, /* category */
1705 AppDataW, /* name */
1706 NULL, /* description */
1707 &FOLDERID_Profile, /* parent */
1708 AppData_RoamingW, /* relative path */
1709 NULL, /* parsing */
1710 NULL, /* tooltip */
1711 NULL, /* localized */
1712 NULL, /* icon */
1713 NULL, /* security */
1714 0, /* attributes */
1715 0, /* flags */
1716 &GUID_NULL /* typeid */
1718 { /* 0x1b - CSIDL_PRINTHOOD */
1719 &FOLDERID_PrintHood,
1720 CSIDL_Type_User,
1721 PrintHoodW,
1722 NULL,
1724 KF_CATEGORY_PERUSER, /* category */
1725 PrintHoodW, /* name */
1726 NULL, /* description */
1727 &FOLDERID_RoamingAppData, /* parent */
1728 Microsoft_Windows_Printer_ShortcutsW, /* relative path */
1729 NULL, /* parsing */
1730 NULL, /* tooltip */
1731 NULL, /* localized */
1732 NULL, /* icon */
1733 NULL, /* security */
1734 0, /* attributes */
1735 0, /* flags */
1736 &GUID_NULL /* typeid */
1738 { /* 0x1c - CSIDL_LOCAL_APPDATA */
1739 &FOLDERID_LocalAppData,
1740 CSIDL_Type_User,
1741 Local_AppDataW,
1742 NULL,
1744 KF_CATEGORY_PERUSER, /* category */
1745 Local_AppDataW, /* name */
1746 NULL, /* description */
1747 &FOLDERID_Profile, /* parent */
1748 AppData_LocalW, /* relative path */
1749 NULL, /* parsing */
1750 NULL, /* tooltip */
1751 NULL, /* localized */
1752 NULL, /* icon */
1753 NULL, /* security */
1754 0, /* attributes */
1755 KFDF_LOCAL_REDIRECT_ONLY | KFDF_PUBLISHEXPANDEDPATH, /* flags */
1756 &GUID_NULL /* typeid */
1758 { /* 0x1d - CSIDL_ALTSTARTUP */
1759 &GUID_NULL,
1760 CSIDL_Type_NonExistent,
1761 NULL,
1762 NULL
1764 { /* 0x1e - CSIDL_COMMON_ALTSTARTUP */
1765 &GUID_NULL,
1766 CSIDL_Type_NonExistent,
1767 NULL,
1768 NULL
1770 { /* 0x1f - CSIDL_COMMON_FAVORITES */
1771 &FOLDERID_Favorites,
1772 CSIDL_Type_AllUsers,
1773 Common_FavoritesW,
1774 NULL,
1776 KF_CATEGORY_PERUSER, /* category */
1777 FavoritesW, /* name */
1778 NULL, /* description */
1779 &FOLDERID_Profile, /* parent */
1780 FavoritesW, /* relative path */
1781 NULL, /* parsing */
1782 NULL, /* tooltip */
1783 NULL, /* localized */
1784 NULL, /* icon */
1785 NULL, /* security */
1786 FILE_ATTRIBUTE_READONLY, /* attributes */
1787 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH, /* flags */
1788 &GUID_NULL /* typeid */
1790 { /* 0x20 - CSIDL_INTERNET_CACHE */
1791 &FOLDERID_InternetCache,
1792 CSIDL_Type_User,
1793 CacheW,
1794 NULL,
1796 KF_CATEGORY_PERUSER, /* category */
1797 CacheW, /* name */
1798 NULL, /* description */
1799 &FOLDERID_LocalAppData, /* parent */
1800 Microsoft_Windows_INetCacheW, /* relative path */
1801 NULL, /* parsing */
1802 NULL, /* tooltip */
1803 NULL, /* localized */
1804 NULL, /* icon */
1805 NULL, /* security */
1806 0, /* attributes */
1807 KFDF_LOCAL_REDIRECT_ONLY, /* flags */
1808 &GUID_NULL /* typeid */
1810 { /* 0x21 - CSIDL_COOKIES */
1811 &FOLDERID_Cookies,
1812 CSIDL_Type_User,
1813 CookiesW,
1814 NULL,
1816 KF_CATEGORY_PERUSER, /* category */
1817 CookiesW, /* name */
1818 NULL, /* description */
1819 &FOLDERID_LocalAppData, /* parent */
1820 Microsoft_Windows_INetCookiesW, /* relative path */
1821 NULL, /* parsing */
1822 NULL, /* tooltip */
1823 NULL, /* localized */
1824 NULL, /* icon */
1825 NULL, /* security */
1826 0, /* attributes */
1827 0, /* flags */
1828 &GUID_NULL /* typeid */
1830 { /* 0x22 - CSIDL_HISTORY */
1831 &FOLDERID_History,
1832 CSIDL_Type_User,
1833 HistoryW,
1834 NULL,
1836 KF_CATEGORY_PERUSER, /* category */
1837 HistoryW, /* name */
1838 NULL, /* description */
1839 &FOLDERID_LocalAppData, /* parent */
1840 Microsoft_Windows_HistoryW, /* relative path */
1841 NULL, /* parsing */
1842 NULL, /* tooltip */
1843 NULL, /* localized */
1844 NULL, /* icon */
1845 NULL, /* security */
1846 0, /* attributes */
1847 KFDF_LOCAL_REDIRECT_ONLY, /* flags */
1848 &GUID_NULL /* typeid */
1850 { /* 0x23 - CSIDL_COMMON_APPDATA */
1851 &FOLDERID_ProgramData,
1852 CSIDL_Type_ProgramData,
1853 Common_AppDataW,
1854 NULL,
1856 KF_CATEGORY_FIXED, /* category */
1857 Common_AppDataW, /* name */
1858 NULL, /* description */
1859 &GUID_NULL, /* parent */
1860 NULL, /* relative path */
1861 NULL, /* parsing */
1862 NULL, /* tooltip */
1863 NULL, /* localized */
1864 NULL, /* icon */
1865 NULL, /* security */
1866 0, /* attributes */
1867 0, /* flags */
1868 &GUID_NULL /* typeid */
1870 { /* 0x24 - CSIDL_WINDOWS */
1871 &FOLDERID_Windows,
1872 CSIDL_Type_WindowsPath,
1873 NULL,
1874 NULL,
1876 KF_CATEGORY_FIXED, /* category */
1877 WindowsW, /* name */
1878 NULL, /* description */
1879 &GUID_NULL, /* parent */
1880 NULL, /* relative path */
1881 NULL, /* parsing */
1882 NULL, /* tooltip */
1883 NULL, /* localized */
1884 NULL, /* icon */
1885 NULL, /* security */
1886 0, /* attributes */
1887 0, /* flags */
1888 &GUID_NULL /* typeid */
1890 { /* 0x25 - CSIDL_SYSTEM */
1891 &FOLDERID_System,
1892 CSIDL_Type_SystemPath,
1893 NULL,
1894 NULL,
1896 KF_CATEGORY_FIXED, /* category */
1897 SystemW, /* name */
1898 NULL, /* description */
1899 &GUID_NULL, /* parent */
1900 NULL, /* relative path */
1901 NULL, /* parsing */
1902 NULL, /* tooltip */
1903 NULL, /* localized */
1904 NULL, /* icon */
1905 NULL, /* security */
1906 0, /* attributes */
1907 0, /* flags */
1908 &GUID_NULL /* typeid */
1910 { /* 0x26 - CSIDL_PROGRAM_FILES */
1911 &FOLDERID_ProgramFiles,
1912 CSIDL_Type_CurrVer,
1913 ProgramFilesDirW,
1914 Program_FilesW,
1916 KF_CATEGORY_FIXED, /* category */
1917 ProgramFilesW, /* name */
1918 NULL, /* description */
1919 &GUID_NULL, /* parent */
1920 NULL, /* relative path */
1921 NULL, /* parsing */
1922 NULL, /* tooltip */
1923 NULL, /* localized */
1924 NULL, /* icon */
1925 NULL, /* security */
1926 FILE_ATTRIBUTE_READONLY, /* attributes */
1927 0, /* flags */
1928 &GUID_NULL /* typeid */
1930 { /* 0x27 - CSIDL_MYPICTURES */
1931 &FOLDERID_Pictures,
1932 CSIDL_Type_User,
1933 My_PicturesW,
1934 NULL,
1936 KF_CATEGORY_PERUSER, /* category */
1937 My_PicturesW, /* name */
1938 NULL, /* description */
1939 &FOLDERID_Profile, /* parent */
1940 PicturesW, /* relative path */
1941 PicturesParsingNameW, /* parsing */
1942 NULL, /* tooltip */
1943 NULL, /* localized */
1944 NULL, /* icon */
1945 NULL, /* security */
1946 FILE_ATTRIBUTE_READONLY, /* attributes */
1947 KFDF_ROAMABLE | KFDF_PRECREATE, /* flags */
1948 &GUID_NULL /* typeid */
1950 { /* 0x28 - CSIDL_PROFILE */
1951 &FOLDERID_Profile,
1952 CSIDL_Type_User,
1953 NULL,
1954 NULL,
1956 KF_CATEGORY_FIXED, /* category */
1957 ProfileW, /* name */
1958 NULL, /* description */
1959 &GUID_NULL, /* parent */
1960 NULL, /* relative path */
1961 NULL, /* parsing */
1962 NULL, /* tooltip */
1963 NULL, /* localized */
1964 NULL, /* icon */
1965 NULL, /* security */
1966 0, /* attributes */
1967 0, /* flags */
1968 &GUID_NULL /* typeid */
1970 { /* 0x29 - CSIDL_SYSTEMX86 */
1971 &FOLDERID_SystemX86,
1972 CSIDL_Type_SystemX86Path,
1973 NULL,
1974 NULL,
1976 KF_CATEGORY_FIXED, /* category */
1977 SystemX86W, /* name */
1978 NULL, /* description */
1979 &GUID_NULL, /* parent */
1980 NULL, /* relative path */
1981 NULL, /* parsing */
1982 NULL, /* tooltip */
1983 NULL, /* localized */
1984 NULL, /* icon */
1985 NULL, /* security */
1986 0, /* attributes */
1987 0, /* flags */
1988 &GUID_NULL /* typeid */
1990 { /* 0x2a - CSIDL_PROGRAM_FILESX86 */
1991 &FOLDERID_ProgramFilesX86,
1992 CSIDL_Type_CurrVer,
1993 ProgramFilesDirX86W,
1994 Program_Files_x86W,
1996 KF_CATEGORY_FIXED, /* category */
1997 ProgramFilesX86W, /* name */
1998 NULL, /* description */
1999 &GUID_NULL, /* parent */
2000 NULL, /* relative path */
2001 NULL, /* parsing */
2002 NULL, /* tooltip */
2003 NULL, /* localized */
2004 NULL, /* icon */
2005 NULL, /* security */
2006 FILE_ATTRIBUTE_READONLY, /* attributes */
2007 0, /* flags */
2008 &GUID_NULL /* typeid */
2010 { /* 0x2b - CSIDL_PROGRAM_FILES_COMMON */
2011 &FOLDERID_ProgramFilesCommon,
2012 CSIDL_Type_CurrVer,
2013 CommonFilesDirW,
2014 Program_Files_Common_FilesW,
2016 KF_CATEGORY_FIXED, /* category */
2017 ProgramFilesCommonW, /* name */
2018 NULL, /* description */
2019 &GUID_NULL, /* parent */
2020 NULL, /* relative path */
2021 NULL, /* parsing */
2022 NULL, /* tooltip */
2023 NULL, /* localized */
2024 NULL, /* icon */
2025 NULL, /* security */
2026 0, /* attributes */
2027 0, /* flags */
2028 &GUID_NULL /* typeid */
2030 { /* 0x2c - CSIDL_PROGRAM_FILES_COMMONX86 */
2031 &FOLDERID_ProgramFilesCommonX86,
2032 CSIDL_Type_CurrVer,
2033 CommonFilesDirX86W,
2034 Program_Files_x86_Common_FilesW,
2036 KF_CATEGORY_FIXED, /* category */
2037 ProgramFilesCommonX86W, /* name */
2038 NULL, /* description */
2039 &GUID_NULL, /* parent */
2040 NULL, /* relative path */
2041 NULL, /* parsing */
2042 NULL, /* tooltip */
2043 NULL, /* localized */
2044 NULL, /* icon */
2045 NULL, /* security */
2046 0, /* attributes */
2047 0, /* flags */
2048 &GUID_NULL /* typeid */
2050 { /* 0x2d - CSIDL_COMMON_TEMPLATES */
2051 &FOLDERID_CommonTemplates,
2052 CSIDL_Type_ProgramData,
2053 Common_TemplatesW,
2054 NULL,
2056 KF_CATEGORY_COMMON, /* category */
2057 Common_TemplatesW, /* name */
2058 NULL, /* description */
2059 &FOLDERID_ProgramData, /* parent */
2060 Microsoft_Windows_TemplatesW, /* relative path */
2061 NULL, /* parsing */
2062 NULL, /* tooltip */
2063 NULL, /* localized */
2064 NULL, /* icon */
2065 NULL, /* security */
2066 0, /* attributes */
2067 0, /* flags */
2068 &GUID_NULL /* typeid */
2070 { /* 0x2e - CSIDL_COMMON_DOCUMENTS */
2071 &FOLDERID_PublicDocuments,
2072 CSIDL_Type_AllUsers,
2073 Common_DocumentsW,
2074 NULL,
2076 KF_CATEGORY_COMMON, /* category */
2077 Common_DocumentsW, /* name */
2078 NULL, /* description */
2079 &FOLDERID_Public, /* parent */
2080 DocumentsW, /* relative path */
2081 NULL, /* parsing */
2082 NULL, /* tooltip */
2083 NULL, /* localized */
2084 NULL, /* icon */
2085 NULL, /* security */
2086 FILE_ATTRIBUTE_READONLY, /* attributes */
2087 KFDF_PRECREATE, /* flags */
2088 &GUID_NULL /* typeid */
2090 { /* 0x2f - CSIDL_COMMON_ADMINTOOLS */
2091 &FOLDERID_CommonAdminTools,
2092 CSIDL_Type_ProgramData,
2093 Common_Administrative_ToolsW,
2094 NULL,
2096 KF_CATEGORY_COMMON, /* category */
2097 Common_Administrative_ToolsW, /* name */
2098 NULL, /* description */
2099 &FOLDERID_CommonPrograms, /* parent */
2100 Administrative_ToolsW, /* relative path */
2101 NULL, /* parsing */
2102 NULL, /* tooltip */
2103 NULL, /* localized */
2104 NULL, /* icon */
2105 NULL, /* security */
2106 FILE_ATTRIBUTE_READONLY, /* attributes */
2107 KFDF_PRECREATE, /* flags */
2108 &GUID_NULL /* typeid */
2110 { /* 0x30 - CSIDL_ADMINTOOLS */
2111 &FOLDERID_AdminTools,
2112 CSIDL_Type_User,
2113 Administrative_ToolsW,
2114 NULL,
2116 KF_CATEGORY_PERUSER, /* category */
2117 Administrative_ToolsW, /* name */
2118 NULL, /* description */
2119 &FOLDERID_Programs, /* parent */
2120 Administrative_ToolsW, /* relative path */
2121 NULL, /* parsing */
2122 NULL, /* tooltip */
2123 NULL, /* localized */
2124 NULL, /* icon */
2125 NULL, /* security */
2126 FILE_ATTRIBUTE_READONLY, /* attributes */
2127 KFDF_PRECREATE, /* flags */
2128 &GUID_NULL /* typeid */
2130 { /* 0x31 - CSIDL_CONNECTIONS */
2131 &FOLDERID_ConnectionsFolder,
2132 CSIDL_Type_Disallowed,
2133 NULL,
2134 NULL,
2136 KF_CATEGORY_VIRTUAL, /* category */
2137 ConnectionsFolderW, /* name */
2138 NULL, /* description */
2139 &GUID_NULL, /* parent */
2140 Administrative_ToolsW, /* relative path */
2141 ConnectionsFolderParsingNameW, /* parsing */
2142 NULL, /* tooltip */
2143 NULL, /* localized */
2144 NULL, /* icon */
2145 NULL, /* security */
2146 0, /* attributes */
2147 0, /* flags */
2148 &GUID_NULL /* typeid */
2150 { /* 0x32 - unassigned */
2151 &GUID_NULL,
2152 CSIDL_Type_Disallowed,
2153 NULL,
2154 NULL
2156 { /* 0x33 - unassigned */
2157 &GUID_NULL,
2158 CSIDL_Type_Disallowed,
2159 NULL,
2160 NULL
2162 { /* 0x34 - unassigned */
2163 &GUID_NULL,
2164 CSIDL_Type_Disallowed,
2165 NULL,
2166 NULL
2168 { /* 0x35 - CSIDL_COMMON_MUSIC */
2169 &FOLDERID_PublicMusic,
2170 CSIDL_Type_AllUsers,
2171 CommonMusicW,
2172 NULL,
2174 KF_CATEGORY_COMMON, /* category */
2175 CommonMusicW, /* name */
2176 NULL, /* description */
2177 &FOLDERID_Public, /* parent */
2178 MusicW, /* relative path */
2179 NULL, /* parsing */
2180 NULL, /* tooltip */
2181 NULL, /* localized */
2182 NULL, /* icon */
2183 NULL, /* security */
2184 FILE_ATTRIBUTE_READONLY, /* attributes */
2185 KFDF_PRECREATE, /* flags */
2186 &GUID_NULL /* typeid */
2188 { /* 0x36 - CSIDL_COMMON_PICTURES */
2189 &FOLDERID_PublicPictures,
2190 CSIDL_Type_AllUsers,
2191 CommonPicturesW,
2192 NULL,
2194 KF_CATEGORY_COMMON, /* category */
2195 CommonPicturesW, /* name */
2196 NULL, /* description */
2197 &FOLDERID_Public, /* parent */
2198 PicturesW, /* relative path */
2199 NULL, /* parsing */
2200 NULL, /* tooltip */
2201 NULL, /* localized */
2202 NULL, /* icon */
2203 NULL, /* security */
2204 FILE_ATTRIBUTE_READONLY, /* attributes */
2205 KFDF_PRECREATE, /* flags */
2206 &GUID_NULL /* typeid */
2208 { /* 0x37 - CSIDL_COMMON_VIDEO */
2209 &FOLDERID_PublicVideos,
2210 CSIDL_Type_AllUsers,
2211 CommonVideoW,
2212 NULL,
2214 KF_CATEGORY_COMMON, /* category */
2215 CommonVideoW, /* name */
2216 NULL, /* description */
2217 &FOLDERID_Public, /* parent */
2218 VideosW, /* relative path */
2219 NULL, /* parsing */
2220 NULL, /* tooltip */
2221 NULL, /* localized */
2222 NULL, /* icon */
2223 NULL, /* security */
2224 FILE_ATTRIBUTE_READONLY, /* attributes */
2225 KFDF_PRECREATE, /* flags */
2226 &GUID_NULL /* typeid */
2228 { /* 0x38 - CSIDL_RESOURCES */
2229 &FOLDERID_ResourceDir,
2230 CSIDL_Type_WindowsPath,
2231 NULL,
2232 ResourcesW,
2234 KF_CATEGORY_FIXED, /* category */
2235 ResourceDirW, /* name */
2236 NULL, /* description */
2237 &GUID_NULL, /* parent */
2238 NULL, /* relative path */
2239 NULL, /* parsing */
2240 NULL, /* tooltip */
2241 NULL, /* localized */
2242 NULL, /* icon */
2243 NULL, /* security */
2244 0, /* attributes */
2245 0, /* flags */
2246 &GUID_NULL /* typeid */
2248 { /* 0x39 - CSIDL_RESOURCES_LOCALIZED */
2249 &FOLDERID_LocalizedResourcesDir,
2250 CSIDL_Type_NonExistent,
2251 NULL,
2252 NULL,
2254 KF_CATEGORY_FIXED, /* category */
2255 LocalizedResourcesDirW, /* name */
2256 NULL, /* description */
2257 &GUID_NULL, /* parent */
2258 NULL, /* relative path */
2259 NULL, /* parsing */
2260 NULL, /* tooltip */
2261 NULL, /* localized */
2262 NULL, /* icon */
2263 NULL, /* security */
2264 0, /* attributes */
2265 0, /* flags */
2266 &GUID_NULL /* typeid */
2268 { /* 0x3a - CSIDL_COMMON_OEM_LINKS */
2269 &FOLDERID_CommonOEMLinks,
2270 CSIDL_Type_ProgramData,
2271 NULL,
2272 NULL,
2274 KF_CATEGORY_COMMON, /* category */
2275 OEM_LinksW, /* name */
2276 NULL, /* description */
2277 &FOLDERID_ProgramData, /* parent */
2278 OEM_LinksW, /* relative path */
2279 NULL, /* parsing */
2280 NULL, /* tooltip */
2281 NULL, /* localized */
2282 NULL, /* icon */
2283 NULL, /* security */
2284 0, /* attributes */
2285 0, /* flags */
2286 &GUID_NULL /* typeid */
2288 { /* 0x3b - CSIDL_CDBURN_AREA */
2289 &FOLDERID_CDBurning,
2290 CSIDL_Type_User,
2291 CD_BurningW,
2292 NULL,
2294 KF_CATEGORY_PERUSER, /* category */
2295 CD_BurningW, /* name */
2296 NULL, /* description */
2297 &FOLDERID_LocalAppData, /* parent */
2298 Microsoft_Windows_Burn_BurnW, /* relative path */
2299 NULL, /* parsing */
2300 NULL, /* tooltip */
2301 NULL, /* localized */
2302 NULL, /* icon */
2303 NULL, /* security */
2304 FILE_ATTRIBUTE_READONLY, /* attributes */
2305 KFDF_LOCAL_REDIRECT_ONLY, /* flags */
2306 &GUID_NULL /* typeid */
2308 { /* 0x3c unassigned */
2309 &GUID_NULL,
2310 CSIDL_Type_Disallowed,
2311 NULL,
2312 NULL
2314 { /* 0x3d - CSIDL_COMPUTERSNEARME */
2315 &GUID_NULL,
2316 CSIDL_Type_Disallowed, /* FIXME */
2317 NULL,
2318 NULL
2320 { /* 0x3e - CSIDL_PROFILES */
2321 &GUID_NULL,
2322 CSIDL_Type_Disallowed, /* oddly, this matches WinXP */
2323 NULL,
2324 NULL
2326 { /* 0x3f */
2327 &FOLDERID_AddNewPrograms,
2328 CSIDL_Type_Disallowed,
2329 NULL,
2330 NULL,
2332 KF_CATEGORY_VIRTUAL, /* category */
2333 AddNewProgramsFolderW, /* name */
2334 NULL, /* description */
2335 &GUID_NULL, /* parent */
2336 NULL, /* relative path */
2337 AddNewProgramsParsingNameW, /* parsing */
2338 NULL, /* tooltip */
2339 NULL, /* localized */
2340 NULL, /* icon */
2341 NULL, /* security */
2342 0, /* attributes */
2343 0, /* flags */
2344 &GUID_NULL /* typeid */
2346 { /* 0x40 */
2347 &FOLDERID_AppUpdates,
2348 CSIDL_Type_Disallowed,
2349 NULL,
2350 NULL,
2352 KF_CATEGORY_VIRTUAL, /* category */
2353 AppUpdatesFolderW, /* name */
2354 NULL, /* description */
2355 &GUID_NULL, /* parent */
2356 NULL, /* relative path */
2357 AppUpdatesParsingNameW, /* parsing */
2358 NULL, /* tooltip */
2359 NULL, /* localized */
2360 NULL, /* icon */
2361 NULL, /* security */
2362 0, /* attributes */
2363 0, /* flags */
2364 &GUID_NULL /* typeid */
2366 { /* 0x41 */
2367 &FOLDERID_ChangeRemovePrograms,
2368 CSIDL_Type_Disallowed,
2369 NULL,
2370 NULL,
2372 KF_CATEGORY_VIRTUAL, /* category */
2373 ChangeRemoveProgramsFolderW, /* name */
2374 NULL, /* description */
2375 &GUID_NULL, /* parent */
2376 NULL, /* relative path */
2377 ChangeRemoveProgramsParsingNameW, /* parsing */
2378 NULL, /* tooltip */
2379 NULL, /* localized */
2380 NULL, /* icon */
2381 NULL, /* security */
2382 0, /* attributes */
2383 0, /* flags */
2384 &GUID_NULL /* typeid */
2386 { /* 0x42 */
2387 &FOLDERID_ConflictFolder,
2388 CSIDL_Type_Disallowed,
2389 NULL,
2390 NULL,
2392 KF_CATEGORY_VIRTUAL, /* category */
2393 ConflictFolderW, /* name */
2394 NULL, /* description */
2395 &GUID_NULL, /* parent */
2396 NULL, /* relative path */
2397 ConflictFolderParsingNameW, /* parsing */
2398 NULL, /* tooltip */
2399 NULL, /* localized */
2400 NULL, /* icon */
2401 NULL, /* security */
2402 0, /* attributes */
2403 0, /* flags */
2404 &GUID_NULL /* typeid */
2406 { /* 0x43 - CSIDL_CONTACTS */
2407 &FOLDERID_Contacts,
2408 CSIDL_Type_User,
2409 NULL,
2410 NULL,
2412 KF_CATEGORY_PERUSER, /* category */
2413 ContactsW, /* name */
2414 NULL, /* description */
2415 &FOLDERID_Profile, /* parent */
2416 ContactsW, /* relative path */
2417 ContactsParsingNameW, /* parsing */
2418 NULL, /* tooltip */
2419 NULL, /* localized */
2420 NULL, /* icon */
2421 NULL, /* security */
2422 FILE_ATTRIBUTE_READONLY, /* attributes */
2423 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH, /* flags */
2424 &GUID_NULL /* typeid */
2426 { /* 0x44 */
2427 &FOLDERID_DeviceMetadataStore,
2428 CSIDL_Type_Disallowed, /* FIXME */
2429 NULL,
2430 NULL,
2432 KF_CATEGORY_COMMON, /* category */
2433 Device_Metadata_StoreW, /* name */
2434 NULL, /* description */
2435 &FOLDERID_ProgramData, /* parent */
2436 Microsoft_Windows_DeviceMetadataStoreW, /* relative path */
2437 NULL, /* parsing */
2438 NULL, /* tooltip */
2439 NULL, /* localized */
2440 NULL, /* icon */
2441 NULL, /* security */
2442 0, /* attributes */
2443 0, /* flags */
2444 &GUID_NULL /* typeid */
2446 { /* 0x45 */
2447 &GUID_NULL,
2448 CSIDL_Type_Disallowed,
2449 NULL,
2450 NULL,
2452 { /* 0x46 */
2453 &FOLDERID_DocumentsLibrary,
2454 CSIDL_Type_Disallowed, /* FIXME */
2455 NULL,
2456 NULL,
2458 KF_CATEGORY_PERUSER, /* category */
2459 DocumentsLibraryW, /* name */
2460 NULL, /* description */
2461 &FOLDERID_Libraries, /* parent */
2462 Documents_librarymsW, /* relative path */
2463 DocumentsLibraryParsingNameW, /* parsing */
2464 NULL, /* tooltip */
2465 NULL, /* localized */
2466 NULL, /* icon */
2467 NULL, /* security */
2468 0, /* attributes */
2469 KFDF_PRECREATE | KFDF_STREAM, /* flags */
2470 &GUID_NULL /* typeid */
2472 { /* 0x47 - CSIDL_DOWNLOADS */
2473 &FOLDERID_Downloads,
2474 CSIDL_Type_User,
2475 NULL,
2476 NULL,
2478 KF_CATEGORY_PERUSER, /* category */
2479 DownloadsW, /* name */
2480 NULL, /* description */
2481 &FOLDERID_Profile, /* parent */
2482 DownloadsW, /* relative path */
2483 NULL, /* parsing */
2484 NULL, /* tooltip */
2485 NULL, /* localized */
2486 NULL, /* icon */
2487 NULL, /* security */
2488 FILE_ATTRIBUTE_READONLY, /* attributes */
2489 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH, /* flags */
2490 &GUID_NULL /* typeid */
2492 { /* 0x48 */
2493 &FOLDERID_Games,
2494 CSIDL_Type_Disallowed,
2495 NULL,
2496 NULL,
2498 KF_CATEGORY_VIRTUAL, /* category */
2499 GamesW, /* name */
2500 NULL, /* description */
2501 &GUID_NULL, /* parent */
2502 NULL, /* relative path */
2503 GamesParsingNameW, /* parsing */
2504 NULL, /* tooltip */
2505 NULL, /* localized */
2506 NULL, /* icon */
2507 NULL, /* security */
2508 0, /* attributes */
2509 0, /* flags */
2510 &GUID_NULL /* typeid */
2512 { /* 0x49 */
2513 &FOLDERID_GameTasks,
2514 CSIDL_Type_Disallowed, /* FIXME */
2515 NULL,
2516 NULL,
2518 KF_CATEGORY_PERUSER, /* category */
2519 GameTasksW, /* name */
2520 NULL, /* description */
2521 &FOLDERID_LocalAppData, /* parent */
2522 Microsoft_Windows_GameExplorerW, /* relative path */
2523 NULL, /* parsing */
2524 NULL, /* tooltip */
2525 NULL, /* localized */
2526 NULL, /* icon */
2527 NULL, /* security */
2528 0, /* attributes */
2529 KFDF_LOCAL_REDIRECT_ONLY, /* flags */
2530 &GUID_NULL /* typeid */
2532 { /* 0x4a */
2533 &FOLDERID_HomeGroup,
2534 CSIDL_Type_Disallowed,
2535 NULL,
2536 NULL,
2538 KF_CATEGORY_VIRTUAL, /* category */
2539 HomeGroupFolderW, /* name */
2540 NULL, /* description */
2541 &GUID_NULL, /* parent */
2542 NULL, /* relative path */
2543 HomeGroupParsingNameW, /* parsing */
2544 NULL, /* tooltip */
2545 NULL, /* localized */
2546 NULL, /* icon */
2547 NULL, /* security */
2548 0, /* attributes */
2549 0, /* flags */
2550 &GUID_NULL /* typeid */
2552 { /* 0x4b */
2553 &FOLDERID_ImplicitAppShortcuts,
2554 CSIDL_Type_Disallowed, /* FIXME */
2555 NULL,
2556 NULL,
2558 KF_CATEGORY_PERUSER, /* category */
2559 ImplicitAppShortcutsW, /* name */
2560 NULL, /* description */
2561 &FOLDERID_UserPinned, /* parent */
2562 ImplicitAppShortcutsW, /* relative path */
2563 NULL, /* parsing */
2564 NULL, /* tooltip */
2565 NULL, /* localized */
2566 NULL, /* icon */
2567 NULL, /* security */
2568 0, /* attributes */
2569 KFDF_PRECREATE, /* flags */
2570 &GUID_NULL /* typeid */
2572 { /* 0x4c */
2573 &FOLDERID_Libraries,
2574 CSIDL_Type_Disallowed, /* FIXME */
2575 NULL,
2576 NULL,
2578 KF_CATEGORY_PERUSER, /* category */
2579 LibrariesW, /* name */
2580 NULL, /* description */
2581 &FOLDERID_RoamingAppData, /* parent */
2582 Microsoft_Windows_LibrariesW, /* relative path */
2583 NULL, /* parsing */
2584 NULL, /* tooltip */
2585 NULL, /* localized */
2586 NULL, /* icon */
2587 NULL, /* security */
2588 0, /* attributes */
2589 KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH, /* flags */
2590 &GUID_NULL /* typeid */
2592 { /* 0x4d - CSIDL_LINKS */
2593 &FOLDERID_Links,
2594 CSIDL_Type_User,
2595 NULL,
2596 NULL,
2598 KF_CATEGORY_PERUSER, /* category */
2599 LinksW, /* name */
2600 NULL, /* description */
2601 &FOLDERID_Profile, /* parent */
2602 LinksW, /* relative path */
2603 LinksParsingNameW, /* parsing */
2604 NULL, /* tooltip */
2605 NULL, /* localized */
2606 NULL, /* icon */
2607 NULL, /* security */
2608 FILE_ATTRIBUTE_READONLY, /* attributes */
2609 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH, /* flags */
2610 &GUID_NULL /* typeid */
2612 { /* 0x4e - CSIDL_APPDATA_LOCALLOW */
2613 &FOLDERID_LocalAppDataLow,
2614 CSIDL_Type_User,
2615 NULL,
2616 NULL,
2618 KF_CATEGORY_PERUSER, /* category */
2619 LocalAppDataLowW, /* name */
2620 NULL, /* description */
2621 &FOLDERID_Profile, /* parent */
2622 AppData_LocalLowW, /* relative path */
2623 NULL, /* parsing */
2624 NULL, /* tooltip */
2625 NULL, /* localized */
2626 NULL, /* icon */
2627 NULL, /* security */
2628 FILE_ATTRIBUTE_NOT_CONTENT_INDEXED, /* attributes */
2629 KFDF_LOCAL_REDIRECT_ONLY | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH, /* flags */
2630 &GUID_NULL /* typeid */
2632 { /* 0x4f */
2633 &FOLDERID_MusicLibrary,
2634 CSIDL_Type_Disallowed, /* FIXME */
2635 NULL,
2636 NULL,
2638 KF_CATEGORY_PERUSER, /* category */
2639 MusicLibraryW, /* name */
2640 NULL, /* description */
2641 &FOLDERID_Libraries, /* parent */
2642 Music_librarymsW, /* relative path */
2643 MusicLibraryParsingNameW, /* parsing */
2644 NULL, /* tooltip */
2645 NULL, /* localized */
2646 NULL, /* icon */
2647 NULL, /* security */
2648 0, /* attributes */
2649 KFDF_PRECREATE | KFDF_STREAM, /* flags */
2650 &GUID_NULL /* typeid */
2652 { /* 0x50 */
2653 &FOLDERID_OriginalImages,
2654 CSIDL_Type_Disallowed, /* FIXME */
2655 NULL,
2656 NULL,
2658 KF_CATEGORY_PERUSER, /* category */
2659 Original_ImagesW, /* name */
2660 NULL, /* description */
2661 &FOLDERID_LocalAppData, /* parent */
2662 Microsoft_Windows_Photo_Gallery_Original_ImagesW, /* relative path */
2663 NULL, /* parsing */
2664 NULL, /* tooltip */
2665 NULL, /* localized */
2666 NULL, /* icon */
2667 NULL, /* security */
2668 0, /* attributes */
2669 0, /* flags */
2670 &GUID_NULL /* typeid */
2672 { /* 0x51 */
2673 &FOLDERID_PhotoAlbums,
2674 CSIDL_Type_User,
2675 NULL,
2676 NULL,
2678 KF_CATEGORY_PERUSER, /* category */
2679 PhotoAlbumsW, /* name */
2680 NULL, /* description */
2681 &FOLDERID_Pictures, /* parent */
2682 Slide_ShowsW, /* relative path */
2683 NULL, /* parsing */
2684 NULL, /* tooltip */
2685 NULL, /* localized */
2686 NULL, /* icon */
2687 NULL, /* security */
2688 FILE_ATTRIBUTE_READONLY, /* attributes */
2689 0, /* flags */
2690 &GUID_NULL /* typeid */
2692 { /* 0x52 */
2693 &FOLDERID_PicturesLibrary,
2694 CSIDL_Type_Disallowed, /* FIXME */
2695 NULL,
2696 NULL,
2698 KF_CATEGORY_PERUSER, /* category */
2699 PicturesLibraryW, /* name */
2700 NULL, /* description */
2701 &FOLDERID_Libraries, /* parent */
2702 Pictures_librarymsW, /* relative path */
2703 PicturesLibraryParsingNameW, /* parsing */
2704 NULL, /* tooltip */
2705 NULL, /* localized */
2706 NULL, /* icon */
2707 NULL, /* security */
2708 0, /* attributes */
2709 KFDF_PRECREATE | KFDF_STREAM, /* flags */
2710 &GUID_NULL /* typeid */
2712 { /* 0x53 */
2713 &FOLDERID_Playlists,
2714 CSIDL_Type_User,
2715 NULL,
2716 NULL,
2718 KF_CATEGORY_PERUSER, /* category */
2719 PlaylistsW, /* name */
2720 NULL, /* description */
2721 &FOLDERID_Music, /* parent */
2722 PlaylistsW, /* relative path */
2723 NULL, /* parsing */
2724 NULL, /* tooltip */
2725 NULL, /* localized */
2726 NULL, /* icon */
2727 NULL, /* security */
2728 FILE_ATTRIBUTE_READONLY, /* attributes */
2729 0, /* flags */
2730 &GUID_NULL /* typeid */
2732 { /* 0x54 */
2733 &FOLDERID_ProgramFilesX64,
2734 #ifdef _WIN64
2735 CSIDL_Type_CurrVer,
2736 ProgramFilesDirW,
2737 Program_FilesW,
2738 #else
2739 CSIDL_Type_NonExistent,
2740 NULL,
2741 NULL,
2742 #endif
2744 KF_CATEGORY_FIXED, /* category */
2745 ProgramFilesX64W, /* name */
2746 NULL, /* description */
2747 &GUID_NULL, /* parent */
2748 NULL, /* relative path */
2749 NULL, /* parsing */
2750 NULL, /* tooltip */
2751 NULL, /* localized */
2752 NULL, /* icon */
2753 NULL, /* security */
2754 0, /* attributes */
2755 0, /* flags */
2756 &GUID_NULL /* typeid */
2758 { /* 0x55 */
2759 &FOLDERID_ProgramFilesCommonX64,
2760 #ifdef _WIN64
2761 CSIDL_Type_CurrVer,
2762 ProgramFilesCommonX64W,
2763 Program_Files_Common_FilesW,
2764 #else
2765 CSIDL_Type_NonExistent,
2766 NULL,
2767 NULL,
2768 #endif
2770 KF_CATEGORY_FIXED, /* category */
2771 ProgramFilesCommonX64W, /* name */
2772 NULL, /* description */
2773 &GUID_NULL, /* parent */
2774 NULL, /* relative path */
2775 NULL, /* parsing */
2776 NULL, /* tooltip */
2777 NULL, /* localized */
2778 NULL, /* icon */
2779 NULL, /* security */
2780 0, /* attributes */
2781 0, /* flags */
2782 &GUID_NULL /* typeid */
2784 { /* 0x56 */
2785 &FOLDERID_Public,
2786 CSIDL_Type_AllUsers,
2787 NULL,
2788 NULL,
2790 KF_CATEGORY_FIXED, /* category */
2791 PublicW, /* name */
2792 NULL, /* description */
2793 &GUID_NULL, /* parent */
2794 NULL, /* relative path */
2795 PublicParsingNameW, /* parsing */
2796 NULL, /* tooltip */
2797 NULL, /* localized */
2798 NULL, /* icon */
2799 NULL, /* security */
2800 FILE_ATTRIBUTE_READONLY, /* attributes */
2801 KFDF_PRECREATE, /* flags */
2802 &GUID_NULL /* typeid */
2804 { /* 0x57 */
2805 &FOLDERID_PublicDownloads,
2806 CSIDL_Type_AllUsers,
2807 NULL,
2808 NULL,
2810 KF_CATEGORY_COMMON, /* category */
2811 CommonDownloadsW, /* name */
2812 NULL, /* description */
2813 &FOLDERID_Public, /* parent */
2814 DownloadsW, /* relative path */
2815 NULL, /* parsing */
2816 NULL, /* tooltip */
2817 NULL, /* localized */
2818 NULL, /* icon */
2819 NULL, /* security */
2820 FILE_ATTRIBUTE_READONLY, /* attributes */
2821 KFDF_PRECREATE, /* flags */
2822 &GUID_NULL /* typeid */
2824 { /* 0x58 */
2825 &FOLDERID_PublicGameTasks,
2826 CSIDL_Type_ProgramData,
2827 NULL,
2828 NULL,
2830 KF_CATEGORY_COMMON, /* category */
2831 PublicGameTasksW, /* name */
2832 NULL, /* description */
2833 &FOLDERID_ProgramData, /* parent */
2834 Microsoft_Windows_GameExplorerW, /* relative path */
2835 NULL, /* parsing */
2836 NULL, /* tooltip */
2837 NULL, /* localized */
2838 NULL, /* icon */
2839 NULL, /* security */
2840 0, /* attributes */
2841 KFDF_LOCAL_REDIRECT_ONLY, /* flags */
2842 &GUID_NULL /* typeid */
2844 { /* 0x59 */
2845 &FOLDERID_PublicLibraries,
2846 CSIDL_Type_AllUsers,
2847 NULL,
2848 NULL,
2850 KF_CATEGORY_COMMON, /* category */
2851 PublicLibrariesW, /* name */
2852 NULL, /* description */
2853 &FOLDERID_Public, /* parent */
2854 LibrariesW, /* relative path */
2855 NULL, /* parsing */
2856 NULL, /* tooltip */
2857 NULL, /* localized */
2858 NULL, /* icon */
2859 NULL, /* security */
2860 FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN, /* attributes */
2861 KFDF_PRECREATE, /* flags */
2862 &GUID_NULL /* typeid */
2864 { /* 0x5a */
2865 &FOLDERID_PublicRingtones,
2866 CSIDL_Type_ProgramData,
2867 NULL,
2868 NULL,
2870 KF_CATEGORY_COMMON, /* category */
2871 CommonRingtonesW, /* name */
2872 NULL, /* description */
2873 &FOLDERID_ProgramData, /* parent */
2874 Microsoft_Windows_RingtonesW, /* relative path */
2875 NULL, /* parsing */
2876 NULL, /* tooltip */
2877 NULL, /* localized */
2878 NULL, /* icon */
2879 NULL, /* security */
2880 0, /* attributes */
2881 KFDF_PRECREATE, /* flags */
2882 &GUID_NULL /* typeid */
2884 { /* 0x5b */
2885 &FOLDERID_QuickLaunch,
2886 CSIDL_Type_Disallowed, /* FIXME */
2887 NULL,
2888 NULL,
2890 KF_CATEGORY_PERUSER, /* category */
2891 Quick_LaunchW, /* name */
2892 NULL, /* description */
2893 &FOLDERID_RoamingAppData, /* parent */
2894 Microsoft_Internet_Explorer_Quick_LaunchW, /* relative path */
2895 NULL, /* parsing */
2896 NULL, /* tooltip */
2897 NULL, /* localized */
2898 NULL, /* icon */
2899 NULL, /* security */
2900 0, /* attributes */
2901 0, /* flags */
2902 &GUID_NULL /* typeid */
2904 { /* 0x5c */
2905 &FOLDERID_RecordedTVLibrary,
2906 CSIDL_Type_Disallowed, /* FIXME */
2907 NULL,
2908 NULL,
2910 KF_CATEGORY_COMMON, /* category */
2911 RecordedTVLibraryW, /* name */
2912 NULL, /* description */
2913 &FOLDERID_PublicLibraries, /* parent */
2914 RecordedTV_librarymsW, /* relative path */
2915 NULL, /* parsing */
2916 NULL, /* tooltip */
2917 NULL, /* localized */
2918 NULL, /* icon */
2919 NULL, /* security */
2920 0, /* attributes */
2921 KFDF_PRECREATE | KFDF_STREAM, /* flags */
2922 &GUID_NULL /* typeid */
2924 { /* 0x5d */
2925 &FOLDERID_Ringtones,
2926 CSIDL_Type_Disallowed, /* FIXME */
2927 NULL,
2928 NULL,
2930 KF_CATEGORY_PERUSER, /* category */
2931 RingtonesW, /* name */
2932 NULL, /* description */
2933 &FOLDERID_LocalAppData, /* parent */
2934 Microsoft_Windows_RingtonesW, /* relative path */
2935 NULL, /* parsing */
2936 NULL, /* tooltip */
2937 NULL, /* localized */
2938 NULL, /* icon */
2939 NULL, /* security */
2940 0, /* attributes */
2941 KFDF_PRECREATE, /* flags */
2942 &GUID_NULL /* typeid */
2944 { /* 0x5e */
2945 &FOLDERID_SampleMusic,
2946 CSIDL_Type_AllUsers,
2947 NULL,
2948 NULL,
2950 KF_CATEGORY_COMMON, /* category */
2951 SampleMusicW, /* name */
2952 NULL, /* description */
2953 &FOLDERID_PublicMusic, /* parent */
2954 Sample_MusicW, /* relative path */
2955 NULL, /* parsing */
2956 NULL, /* tooltip */
2957 NULL, /* localized */
2958 NULL, /* icon */
2959 NULL, /* security */
2960 FILE_ATTRIBUTE_READONLY, /* attributes */
2961 KFDF_PRECREATE, /* flags */
2962 &GUID_NULL /* typeid */
2964 { /* 0x5f */
2965 &FOLDERID_SamplePictures,
2966 CSIDL_Type_AllUsers,
2967 NULL,
2968 NULL,
2970 KF_CATEGORY_COMMON, /* category */
2971 SamplePicturesW, /* name */
2972 NULL, /* description */
2973 &FOLDERID_PublicPictures, /* parent */
2974 Sample_PicturesW, /* relative path */
2975 NULL, /* parsing */
2976 NULL, /* tooltip */
2977 NULL, /* localized */
2978 NULL, /* icon */
2979 NULL, /* security */
2980 FILE_ATTRIBUTE_READONLY, /* attributes */
2981 KFDF_PRECREATE, /* flags */
2982 &GUID_NULL /* typeid */
2984 { /* 0x60 */
2985 &FOLDERID_SamplePlaylists,
2986 CSIDL_Type_AllUsers,
2987 NULL,
2988 NULL,
2990 KF_CATEGORY_COMMON, /* category */
2991 SamplePlaylistsW, /* name */
2992 NULL, /* description */
2993 &FOLDERID_PublicMusic, /* parent */
2994 Sample_PlaylistsW, /* relative path */
2995 NULL, /* parsing */
2996 NULL, /* tooltip */
2997 NULL, /* localized */
2998 NULL, /* icon */
2999 NULL, /* security */
3000 FILE_ATTRIBUTE_READONLY, /* attributes */
3001 KFDF_PRECREATE, /* flags */
3002 &GUID_NULL /* typeid */
3004 { /* 0x61 */
3005 &FOLDERID_SampleVideos,
3006 CSIDL_Type_AllUsers,
3007 NULL,
3008 NULL,
3010 KF_CATEGORY_COMMON, /* category */
3011 SampleVideosW, /* name */
3012 NULL, /* description */
3013 &FOLDERID_PublicVideos, /* parent */
3014 Sample_VideosW, /* relative path */
3015 NULL, /* parsing */
3016 NULL, /* tooltip */
3017 NULL, /* localized */
3018 NULL, /* icon */
3019 NULL, /* security */
3020 FILE_ATTRIBUTE_READONLY, /* attributes */
3021 KFDF_PRECREATE, /* flags */
3022 &GUID_NULL /* typeid */
3024 { /* 0x62 - CSIDL_SAVED_GAMES */
3025 &FOLDERID_SavedGames,
3026 CSIDL_Type_User,
3027 NULL,
3028 NULL,
3030 KF_CATEGORY_PERUSER, /* category */
3031 SavedGamesW, /* name */
3032 NULL, /* description */
3033 &FOLDERID_Profile, /* parent */
3034 Saved_GamesW, /* relative path */
3035 SavedGamesParsingNameW, /* parsing */
3036 NULL, /* tooltip */
3037 NULL, /* localized */
3038 NULL, /* icon */
3039 NULL, /* security */
3040 FILE_ATTRIBUTE_READONLY, /* attributes */
3041 KFDF_ROAMABLE | KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH, /* flags */
3042 &GUID_NULL /* typeid */
3044 { /* 0x63 - CSIDL_SEARCHES */
3045 &FOLDERID_SavedSearches,
3046 CSIDL_Type_User,
3047 NULL,
3048 NULL,
3050 KF_CATEGORY_PERUSER, /* category */
3051 SearchesW, /* name */
3052 NULL, /* description */
3053 &FOLDERID_Profile, /* parent */
3054 SearchesW, /* relative path */
3055 SavedSearchesParsingNameW, /* parsing */
3056 NULL, /* tooltip */
3057 NULL, /* localized */
3058 NULL, /* icon */
3059 NULL, /* security */
3060 FILE_ATTRIBUTE_READONLY, /* attributes */
3061 KFDF_PRECREATE | KFDF_PUBLISHEXPANDEDPATH, /* flags */
3062 &GUID_NULL /* typeid */
3064 { /* 0x64 */
3065 &FOLDERID_SEARCH_CSC,
3066 CSIDL_Type_Disallowed,
3067 NULL,
3068 NULL,
3070 KF_CATEGORY_VIRTUAL, /* category */
3071 CSCFolderW, /* name */
3072 NULL, /* description */
3073 &GUID_NULL, /* parent */
3074 NULL, /* relative path */
3075 SEARCH_CSCParsingNameW, /* parsing */
3076 NULL, /* tooltip */
3077 NULL, /* localized */
3078 NULL, /* icon */
3079 NULL, /* security */
3080 0, /* attributes */
3081 0, /* flags */
3082 &GUID_NULL /* typeid */
3084 { /* 0x65 */
3085 &FOLDERID_SEARCH_MAPI,
3086 CSIDL_Type_Disallowed,
3087 NULL,
3088 NULL,
3090 KF_CATEGORY_VIRTUAL, /* category */
3091 MAPIFolderW, /* name */
3092 NULL, /* description */
3093 &GUID_NULL, /* parent */
3094 NULL, /* relative path */
3095 SEARCH_MAPIParsingNameW, /* parsing */
3096 NULL, /* tooltip */
3097 NULL, /* localized */
3098 NULL, /* icon */
3099 NULL, /* security */
3100 0, /* attributes */
3101 0, /* flags */
3102 &GUID_NULL /* typeid */
3104 { /* 0x66 */
3105 &FOLDERID_SearchHome,
3106 CSIDL_Type_Disallowed,
3107 NULL,
3108 NULL,
3110 KF_CATEGORY_VIRTUAL, /* category */
3111 SearchHomeFolderW, /* name */
3112 NULL, /* description */
3113 &GUID_NULL, /* parent */
3114 NULL, /* relative path */
3115 SearchHomeParsingNameW, /* parsing */
3116 NULL, /* tooltip */
3117 NULL, /* localized */
3118 NULL, /* icon */
3119 NULL, /* security */
3120 0, /* attributes */
3121 0, /* flags */
3122 &GUID_NULL /* typeid */
3124 { /* 0x67 */
3125 &FOLDERID_SidebarDefaultParts,
3126 CSIDL_Type_Disallowed, /* FIXME */
3127 NULL,
3128 NULL,
3130 KF_CATEGORY_COMMON, /* category */
3131 Default_GadgetsW, /* name */
3132 NULL, /* description */
3133 &FOLDERID_ProgramFiles, /* parent */
3134 Windows_Sidebar_GadgetsW, /* relative path */
3135 NULL, /* parsing */
3136 NULL, /* tooltip */
3137 NULL, /* localized */
3138 NULL, /* icon */
3139 NULL, /* security */
3140 0, /* attributes */
3141 0, /* flags */
3142 &GUID_NULL /* typeid */
3144 { /* 0x68 */
3145 &FOLDERID_SidebarParts,
3146 CSIDL_Type_Disallowed, /* FIXME */
3147 NULL,
3148 NULL,
3150 KF_CATEGORY_PERUSER, /* category */
3151 GadgetsW, /* name */
3152 NULL, /* description */
3153 &FOLDERID_LocalAppData, /* parent */
3154 Microsoft_Windows_Sidebar_GadgetsW, /* relative path */
3155 NULL, /* parsing */
3156 NULL, /* tooltip */
3157 NULL, /* localized */
3158 NULL, /* icon */
3159 NULL, /* security */
3160 0, /* attributes */
3161 0, /* flags */
3162 &GUID_NULL /* typeid */
3164 { /* 0x69 */
3165 &FOLDERID_SyncManagerFolder,
3166 CSIDL_Type_Disallowed,
3167 NULL,
3168 NULL,
3170 KF_CATEGORY_VIRTUAL, /* category */
3171 SyncCenterFolderW, /* name */
3172 NULL, /* description */
3173 &GUID_NULL, /* parent */
3174 NULL, /* relative path */
3175 SyncManagerFolderParsingNameW, /* parsing */
3176 NULL, /* tooltip */
3177 NULL, /* localized */
3178 NULL, /* icon */
3179 NULL, /* security */
3180 0, /* attributes */
3181 0, /* flags */
3182 &GUID_NULL /* typeid */
3184 { /* 0x6a */
3185 &FOLDERID_SyncResultsFolder,
3186 CSIDL_Type_Disallowed,
3187 NULL,
3188 NULL,
3190 KF_CATEGORY_VIRTUAL, /* category */
3191 SyncResultsFolderW, /* name */
3192 NULL, /* description */
3193 &GUID_NULL, /* parent */
3194 NULL, /* relative path */
3195 SyncResultsFolderParsingNameW, /* parsing */
3196 NULL, /* tooltip */
3197 NULL, /* localized */
3198 NULL, /* icon */
3199 NULL, /* security */
3200 0, /* attributes */
3201 0, /* flags */
3202 &GUID_NULL /* typeid */
3204 { /* 0x6b */
3205 &FOLDERID_SyncSetupFolder,
3206 CSIDL_Type_Disallowed,
3207 NULL,
3208 NULL,
3210 KF_CATEGORY_VIRTUAL, /* category */
3211 SyncSetupFolderW, /* name */
3212 NULL, /* description */
3213 &GUID_NULL, /* parent */
3214 NULL, /* relative path */
3215 SyncSetupFolderParsingNameW, /* parsing */
3216 NULL, /* tooltip */
3217 NULL, /* localized */
3218 NULL, /* icon */
3219 NULL, /* security */
3220 0, /* attributes */
3221 0, /* flags */
3222 &GUID_NULL /* typeid */
3224 { /* 0x6c */
3225 &FOLDERID_UserPinned,
3226 CSIDL_Type_Disallowed, /* FIXME */
3227 NULL,
3228 NULL,
3230 KF_CATEGORY_PERUSER, /* category */
3231 User_PinnedW, /* name */
3232 NULL, /* description */
3233 &FOLDERID_QuickLaunch, /* parent */
3234 User_PinnedW, /* relative path */
3235 NULL, /* parsing */
3236 NULL, /* tooltip */
3237 NULL, /* localized */
3238 NULL, /* icon */
3239 NULL, /* security */
3240 FILE_ATTRIBUTE_HIDDEN, /* attributes */
3241 KFDF_PRECREATE, /* flags */
3242 &GUID_NULL /* typeid */
3244 { /* 0x6d */
3245 &FOLDERID_UserProfiles,
3246 CSIDL_Type_CurrVer,
3247 UsersW,
3248 UsersW,
3250 KF_CATEGORY_FIXED, /* category */
3251 UserProfilesW, /* name */
3252 NULL, /* description */
3253 &GUID_NULL, /* parent */
3254 NULL, /* relative path */
3255 NULL, /* parsing */
3256 NULL, /* tooltip */
3257 NULL, /* localized */
3258 NULL, /* icon */
3259 NULL, /* security */
3260 FILE_ATTRIBUTE_READONLY, /* attributes */
3261 KFDF_PRECREATE, /* flags */
3262 &GUID_NULL /* typeid */
3264 { /* 0x6e */
3265 &FOLDERID_UserProgramFiles,
3266 CSIDL_Type_Disallowed, /* FIXME */
3267 NULL,
3268 NULL,
3270 KF_CATEGORY_PERUSER, /* category */
3271 UserProgramFilesW, /* name */
3272 NULL, /* description */
3273 &FOLDERID_LocalAppData, /* parent */
3274 ProgramsW, /* relative path */
3275 NULL, /* parsing */
3276 NULL, /* tooltip */
3277 NULL, /* localized */
3278 NULL, /* icon */
3279 NULL, /* security */
3280 0, /* attributes */
3281 0, /* flags */
3282 &GUID_NULL /* typeid */
3284 { /* 0x6f */
3285 &FOLDERID_UserProgramFilesCommon,
3286 CSIDL_Type_Disallowed, /* FIXME */
3287 NULL,
3288 NULL,
3290 KF_CATEGORY_PERUSER, /* category */
3291 UserProgramFilesCommonW, /* name */
3292 NULL, /* description */
3293 &FOLDERID_UserProgramFiles, /* parent */
3294 CommonW, /* relative path */
3295 NULL, /* parsing */
3296 NULL, /* tooltip */
3297 NULL, /* localized */
3298 NULL, /* icon */
3299 NULL, /* security */
3300 0, /* attributes */
3301 0, /* flags */
3302 &GUID_NULL /* typeid */
3304 { /* 0x70 */
3305 &FOLDERID_UsersFiles,
3306 CSIDL_Type_Disallowed,
3307 NULL,
3308 NULL,
3310 KF_CATEGORY_VIRTUAL, /* category */
3311 UsersFilesFolderW, /* name */
3312 NULL, /* description */
3313 &GUID_NULL, /* parent */
3314 NULL, /* relative path */
3315 UsersFilesParsingNameW, /* parsing */
3316 NULL, /* tooltip */
3317 NULL, /* localized */
3318 NULL, /* icon */
3319 NULL, /* security */
3320 0, /* attributes */
3321 0, /* flags */
3322 &GUID_NULL /* typeid */
3324 { /* 0x71 */
3325 &FOLDERID_UsersLibraries,
3326 CSIDL_Type_Disallowed,
3327 NULL,
3328 NULL,
3330 KF_CATEGORY_VIRTUAL, /* category */
3331 UsersLibrariesFolderW, /* name */
3332 NULL, /* description */
3333 &GUID_NULL, /* parent */
3334 NULL, /* relative path */
3335 UsersLibrariesParsingNameW, /* parsing */
3336 NULL, /* tooltip */
3337 NULL, /* localized */
3338 NULL, /* icon */
3339 NULL, /* security */
3340 0, /* attributes */
3341 0, /* flags */
3342 &GUID_NULL /* typeid */
3344 { /* 0x72 */
3345 &FOLDERID_VideosLibrary,
3346 CSIDL_Type_Disallowed, /* FIXME */
3347 NULL,
3348 NULL,
3350 KF_CATEGORY_PERUSER, /* category */
3351 VideosLibraryW, /* name */
3352 NULL, /* description */
3353 &GUID_NULL, /* parent */
3354 Videos_librarymsW, /* relative path */
3355 VideosLibraryParsingNameW, /* parsing */
3356 NULL, /* tooltip */
3357 NULL, /* localized */
3358 NULL, /* icon */
3359 NULL, /* security */
3360 0, /* attributes */
3361 0, /* flags */
3362 &GUID_NULL /* typeid */
3366 static int csidl_from_id( const KNOWNFOLDERID *id )
3368 int i;
3369 for (i = 0; i < ARRAY_SIZE(CSIDL_Data); i++)
3370 if (IsEqualGUID( CSIDL_Data[i].id, id )) return i;
3371 return -1;
3374 static HRESULT _SHExpandEnvironmentStrings(LPCWSTR szSrc, LPWSTR szDest);
3376 /* Gets the value named value from the registry key
3377 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
3378 * (or from rootKey\userPrefix\... if userPrefix is not NULL) into path, which
3379 * is assumed to be MAX_PATH WCHARs in length.
3380 * If it exists, expands the value and writes the expanded value to
3381 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
3382 * Returns successful error code if the value was retrieved from the registry,
3383 * and a failure otherwise.
3385 static HRESULT _SHGetUserShellFolderPath(HKEY rootKey, LPCWSTR userPrefix,
3386 LPCWSTR value, LPWSTR path)
3388 HRESULT hr;
3389 WCHAR shellFolderPath[MAX_PATH], userShellFolderPath[MAX_PATH];
3390 LPCWSTR pShellFolderPath, pUserShellFolderPath;
3391 HKEY userShellFolderKey, shellFolderKey;
3392 DWORD dwType, dwPathLen;
3394 TRACE("%p,%s,%s,%p\n",rootKey, debugstr_w(userPrefix), debugstr_w(value),
3395 path);
3397 if (userPrefix)
3399 strcpyW(shellFolderPath, userPrefix);
3400 PathAddBackslashW(shellFolderPath);
3401 strcatW(shellFolderPath, szSHFolders);
3402 pShellFolderPath = shellFolderPath;
3403 strcpyW(userShellFolderPath, userPrefix);
3404 PathAddBackslashW(userShellFolderPath);
3405 strcatW(userShellFolderPath, szSHUserFolders);
3406 pUserShellFolderPath = userShellFolderPath;
3408 else
3410 pUserShellFolderPath = szSHUserFolders;
3411 pShellFolderPath = szSHFolders;
3414 if (RegCreateKeyW(rootKey, pShellFolderPath, &shellFolderKey))
3416 TRACE("Failed to create %s\n", debugstr_w(pShellFolderPath));
3417 return E_FAIL;
3419 if (RegCreateKeyW(rootKey, pUserShellFolderPath, &userShellFolderKey))
3421 TRACE("Failed to create %s\n",
3422 debugstr_w(pUserShellFolderPath));
3423 RegCloseKey(shellFolderKey);
3424 return E_FAIL;
3427 dwPathLen = MAX_PATH * sizeof(WCHAR);
3428 if (!RegQueryValueExW(userShellFolderKey, value, NULL, &dwType,
3429 (LPBYTE)path, &dwPathLen) && (dwType == REG_EXPAND_SZ || dwType == REG_SZ))
3431 LONG ret;
3433 path[dwPathLen / sizeof(WCHAR)] = '\0';
3434 if (dwType == REG_EXPAND_SZ && path[0] == '%')
3436 WCHAR szTemp[MAX_PATH];
3438 _SHExpandEnvironmentStrings(path, szTemp);
3439 lstrcpynW(path, szTemp, MAX_PATH);
3441 ret = RegSetValueExW(shellFolderKey, value, 0, REG_SZ, (LPBYTE)path,
3442 (strlenW(path) + 1) * sizeof(WCHAR));
3443 if (ret != ERROR_SUCCESS)
3444 hr = HRESULT_FROM_WIN32(ret);
3445 else
3446 hr = S_OK;
3448 else
3449 hr = E_FAIL;
3450 RegCloseKey(shellFolderKey);
3451 RegCloseKey(userShellFolderKey);
3452 TRACE("returning 0x%08x\n", hr);
3453 return hr;
3456 static void append_relative_path(BYTE folder, WCHAR *pszPath)
3458 if (CSIDL_Data[folder].pszRelativePath)
3460 PathAddBackslashW(pszPath);
3461 strcatW(pszPath, CSIDL_Data[folder].pszRelativePath);
3463 else if (CSIDL_Data[folder].szDefaultPath)
3465 PathAddBackslashW(pszPath);
3466 strcatW(pszPath, CSIDL_Data[folder].szDefaultPath);
3470 /* Gets a 'semi-expanded' default value of the CSIDL with index folder into
3471 * pszPath, based on the entries in CSIDL_Data. By semi-expanded, I mean:
3472 * - Depending on the entry's type, the path may begin with an (unexpanded)
3473 * environment variable name. The caller is responsible for expanding
3474 * environment strings if so desired.
3475 * The types that are prepended with environment variables are:
3476 * CSIDL_Type_User: %USERPROFILE%
3477 * CSIDL_Type_AllUsers: %ALLUSERSPROFILE%
3478 * CSIDL_Type_CurrVer: %SystemDrive%
3479 * (Others might make sense too, but as yet are unneeded.)
3481 static HRESULT _SHGetDefaultValue(BYTE folder, LPWSTR pszPath)
3483 HRESULT hr;
3485 TRACE("0x%02x,%p\n", folder, pszPath);
3487 if (folder >= ARRAY_SIZE(CSIDL_Data))
3488 return E_INVALIDARG;
3490 if (!pszPath)
3491 return E_INVALIDARG;
3493 if (!is_win64)
3495 BOOL is_wow64;
3497 switch (folder)
3499 case CSIDL_PROGRAM_FILES:
3500 case CSIDL_PROGRAM_FILESX86:
3501 IsWow64Process( GetCurrentProcess(), &is_wow64 );
3502 folder = is_wow64 ? CSIDL_PROGRAM_FILESX86 : CSIDL_PROGRAM_FILES;
3503 break;
3504 case CSIDL_PROGRAM_FILES_COMMON:
3505 case CSIDL_PROGRAM_FILES_COMMONX86:
3506 IsWow64Process( GetCurrentProcess(), &is_wow64 );
3507 folder = is_wow64 ? CSIDL_PROGRAM_FILES_COMMONX86 : CSIDL_PROGRAM_FILES_COMMON;
3508 break;
3512 if (IsEqualGUID(CSIDL_Data[folder].fidParent, &GUID_NULL))
3514 /* hit the root, sub in env var */
3515 switch (CSIDL_Data[folder].type)
3517 case CSIDL_Type_User:
3518 strcpyW(pszPath, UserProfileW);
3519 break;
3520 case CSIDL_Type_AllUsers:
3521 strcpyW(pszPath, PublicProfileW);
3522 break;
3523 case CSIDL_Type_ProgramData:
3524 strcpyW(pszPath, ProgramDataVarW);
3525 break;
3526 case CSIDL_Type_CurrVer:
3527 strcpyW(pszPath, SystemDriveW);
3528 break;
3529 default:
3530 ; /* no corresponding env. var, do nothing */
3532 hr = S_OK;
3533 }else{
3534 /* prepend with parent */
3535 hr = _SHGetDefaultValue(csidl_from_id(CSIDL_Data[folder].fidParent), pszPath);
3538 if (SUCCEEDED(hr))
3539 append_relative_path(folder, pszPath);
3541 TRACE("returning 0x%08x\n", hr);
3542 return hr;
3545 /* Gets the (unexpanded) value of the folder with index folder into pszPath.
3546 * The folder's type is assumed to be CSIDL_Type_CurrVer. Its default value
3547 * can be overridden in the HKLM\\szCurrentVersion key.
3548 * If dwFlags has SHGFP_TYPE_DEFAULT set or if the value isn't overridden in
3549 * the registry, uses _SHGetDefaultValue to get the value.
3551 static HRESULT _SHGetCurrentVersionPath(DWORD dwFlags, BYTE folder,
3552 LPWSTR pszPath)
3554 HRESULT hr;
3556 TRACE("0x%08x,0x%02x,%p\n", dwFlags, folder, pszPath);
3558 if (folder >= ARRAY_SIZE(CSIDL_Data))
3559 return E_INVALIDARG;
3560 if (CSIDL_Data[folder].type != CSIDL_Type_CurrVer)
3561 return E_INVALIDARG;
3562 if (!pszPath)
3563 return E_INVALIDARG;
3565 if (dwFlags & SHGFP_TYPE_DEFAULT)
3566 hr = _SHGetDefaultValue(folder, pszPath);
3567 else
3569 HKEY hKey;
3571 if (RegCreateKeyW(HKEY_LOCAL_MACHINE, szCurrentVersion, &hKey))
3572 hr = E_FAIL;
3573 else
3575 DWORD dwType, dwPathLen = MAX_PATH * sizeof(WCHAR);
3577 if (RegQueryValueExW(hKey, CSIDL_Data[folder].szValueName, NULL,
3578 &dwType, (LPBYTE)pszPath, &dwPathLen) ||
3579 (dwType != REG_SZ && dwType != REG_EXPAND_SZ))
3581 hr = _SHGetDefaultValue(folder, pszPath);
3582 dwType = REG_EXPAND_SZ;
3583 switch (folder)
3585 case CSIDL_PROGRAM_FILESX86:
3586 case CSIDL_PROGRAM_FILES_COMMONX86:
3587 /* these two should never be set on 32-bit setups */
3588 if (!is_win64)
3590 BOOL is_wow64;
3591 IsWow64Process( GetCurrentProcess(), &is_wow64 );
3592 if (!is_wow64) break;
3594 /* fall through */
3595 default:
3596 RegSetValueExW(hKey, CSIDL_Data[folder].szValueName, 0, dwType,
3597 (LPBYTE)pszPath, (strlenW(pszPath)+1)*sizeof(WCHAR));
3600 else
3602 pszPath[dwPathLen / sizeof(WCHAR)] = '\0';
3603 hr = S_OK;
3605 RegCloseKey(hKey);
3608 TRACE("returning 0x%08x (output path is %s)\n", hr, debugstr_w(pszPath));
3609 return hr;
3612 static LPWSTR _GetUserSidStringFromToken(HANDLE Token)
3614 char InfoBuffer[64];
3615 PTOKEN_USER UserInfo;
3616 DWORD InfoSize;
3617 LPWSTR SidStr;
3619 UserInfo = (PTOKEN_USER) InfoBuffer;
3620 if (! GetTokenInformation(Token, TokenUser, InfoBuffer, sizeof(InfoBuffer),
3621 &InfoSize))
3623 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
3624 return NULL;
3625 UserInfo = heap_alloc(InfoSize);
3626 if (UserInfo == NULL)
3627 return NULL;
3628 if (! GetTokenInformation(Token, TokenUser, UserInfo, InfoSize,
3629 &InfoSize))
3631 heap_free(UserInfo);
3632 return NULL;
3636 if (! ConvertSidToStringSidW(UserInfo->User.Sid, &SidStr))
3637 SidStr = NULL;
3639 if (UserInfo != (PTOKEN_USER) InfoBuffer)
3640 heap_free(UserInfo);
3642 return SidStr;
3645 /* Gets the user's path (unexpanded) for the CSIDL with index folder:
3646 * If SHGFP_TYPE_DEFAULT is set, calls _SHGetDefaultValue for it. Otherwise
3647 * calls _SHGetUserShellFolderPath for it. Where it looks depends on hToken:
3648 * - if hToken is -1, looks in HKEY_USERS\.Default
3649 * - otherwise looks first in HKEY_CURRENT_USER, followed by HKEY_LOCAL_MACHINE
3650 * if HKEY_CURRENT_USER doesn't contain any entries. If both fail, finally
3651 * calls _SHGetDefaultValue for it.
3653 static HRESULT _SHGetUserProfilePath(HANDLE hToken, DWORD dwFlags, BYTE folder,
3654 LPWSTR pszPath)
3656 const WCHAR *szValueName;
3657 WCHAR buffer[40];
3658 HRESULT hr;
3660 TRACE("%p,0x%08x,0x%02x,%p\n", hToken, dwFlags, folder, pszPath);
3662 if (folder >= ARRAY_SIZE(CSIDL_Data))
3663 return E_INVALIDARG;
3664 if (CSIDL_Data[folder].type != CSIDL_Type_User)
3665 return E_INVALIDARG;
3666 if (!pszPath)
3667 return E_INVALIDARG;
3669 if (dwFlags & SHGFP_TYPE_DEFAULT)
3671 if (hToken != NULL && hToken != (HANDLE)-1)
3673 FIXME("unsupported for user other than current or default\n");
3674 return E_FAIL;
3676 hr = _SHGetDefaultValue(folder, pszPath);
3678 else
3680 LPCWSTR userPrefix = NULL;
3681 HKEY hRootKey;
3683 if (hToken == (HANDLE)-1)
3685 hRootKey = HKEY_USERS;
3686 userPrefix = DefaultW;
3688 else if (hToken == NULL)
3689 hRootKey = HKEY_CURRENT_USER;
3690 else
3692 hRootKey = HKEY_USERS;
3693 userPrefix = _GetUserSidStringFromToken(hToken);
3694 if (userPrefix == NULL)
3696 hr = E_FAIL;
3697 goto error;
3701 /* For CSIDL_Type_User we also use the GUID if no szValueName is provided */
3702 szValueName = CSIDL_Data[folder].szValueName;
3703 if (!szValueName)
3705 StringFromGUID2( CSIDL_Data[folder].id, buffer, 39 );
3706 szValueName = &buffer[0];
3709 hr = _SHGetUserShellFolderPath(hRootKey, userPrefix, szValueName, pszPath);
3710 if (FAILED(hr) && hRootKey != HKEY_LOCAL_MACHINE)
3711 hr = _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE, NULL, szValueName, pszPath);
3712 if (FAILED(hr))
3713 hr = _SHGetDefaultValue(folder, pszPath);
3714 if (userPrefix != NULL && userPrefix != DefaultW)
3715 LocalFree((HLOCAL) userPrefix);
3717 error:
3718 TRACE("returning 0x%08x (output path is %s)\n", hr, debugstr_w(pszPath));
3719 return hr;
3722 /* Gets the (unexpanded) path for the CSIDL with index folder. If dwFlags has
3723 * SHGFP_TYPE_DEFAULT set, calls _SHGetDefaultValue. Otherwise calls
3724 * _SHGetUserShellFolderPath for it, looking only in HKEY_LOCAL_MACHINE.
3725 * If this fails, falls back to _SHGetDefaultValue.
3727 static HRESULT _SHGetAllUsersProfilePath(DWORD dwFlags, BYTE folder,
3728 LPWSTR pszPath)
3730 HRESULT hr;
3732 TRACE("0x%08x,0x%02x,%p\n", dwFlags, folder, pszPath);
3734 if (folder >= ARRAY_SIZE(CSIDL_Data))
3735 return E_INVALIDARG;
3736 if (CSIDL_Data[folder].type != CSIDL_Type_AllUsers && CSIDL_Data[folder].type != CSIDL_Type_ProgramData)
3737 return E_INVALIDARG;
3738 if (!pszPath)
3739 return E_INVALIDARG;
3741 if (dwFlags & SHGFP_TYPE_DEFAULT)
3742 hr = _SHGetDefaultValue(folder, pszPath);
3743 else
3745 hr = _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE, NULL,
3746 CSIDL_Data[folder].szValueName, pszPath);
3747 if (FAILED(hr))
3748 hr = _SHGetDefaultValue(folder, pszPath);
3750 TRACE("returning 0x%08x (output path is %s)\n", hr, debugstr_w(pszPath));
3751 return hr;
3754 static HRESULT _SHOpenProfilesKey(PHKEY pKey)
3756 LONG lRet;
3757 DWORD disp;
3759 lRet = RegCreateKeyExW(HKEY_LOCAL_MACHINE, ProfileListW, 0, NULL, 0,
3760 KEY_ALL_ACCESS, NULL, pKey, &disp);
3761 return HRESULT_FROM_WIN32(lRet);
3764 /* Reads the value named szValueName from the key profilesKey (assumed to be
3765 * opened by _SHOpenProfilesKey) into szValue, which is assumed to be MAX_PATH
3766 * WCHARs in length. If it doesn't exist, returns szDefault (and saves
3767 * szDefault to the registry).
3769 static HRESULT _SHGetProfilesValue(HKEY profilesKey, LPCWSTR szValueName,
3770 LPWSTR szValue, LPCWSTR szDefault)
3772 HRESULT hr;
3773 DWORD type, dwPathLen = MAX_PATH * sizeof(WCHAR);
3774 LONG lRet;
3776 TRACE("%p,%s,%p,%s\n", profilesKey, debugstr_w(szValueName), szValue,
3777 debugstr_w(szDefault));
3778 lRet = RegQueryValueExW(profilesKey, szValueName, NULL, &type,
3779 (LPBYTE)szValue, &dwPathLen);
3780 if (!lRet && (type == REG_SZ || type == REG_EXPAND_SZ) && dwPathLen
3781 && *szValue)
3783 dwPathLen /= sizeof(WCHAR);
3784 szValue[dwPathLen] = '\0';
3785 hr = S_OK;
3787 else
3789 /* Missing or invalid value, set a default */
3790 lstrcpynW(szValue, szDefault, MAX_PATH);
3791 TRACE("Setting missing value %s to %s\n", debugstr_w(szValueName),
3792 debugstr_w(szValue));
3793 lRet = RegSetValueExW(profilesKey, szValueName, 0, REG_EXPAND_SZ,
3794 (LPBYTE)szValue,
3795 (strlenW(szValue) + 1) * sizeof(WCHAR));
3796 if (lRet)
3797 hr = HRESULT_FROM_WIN32(lRet);
3798 else
3799 hr = S_OK;
3801 TRACE("returning 0x%08x (output value is %s)\n", hr, debugstr_w(szValue));
3802 return hr;
3805 /* Attempts to expand environment variables from szSrc into szDest, which is
3806 * assumed to be MAX_PATH characters in length. Before referring to the
3807 * environment, handles a few variables directly, because the environment
3808 * variables may not be set when this is called (as during Wine's installation
3809 * when default values are being written to the registry).
3810 * The directly handled environment variables, and their source, are:
3811 * - ALLUSERSPROFILE, USERPROFILE: reads from the registry
3812 * - SystemDrive: uses GetSystemDirectoryW and uses the drive portion of its
3813 * path
3814 * If one of the directly handled environment variables is expanded, only
3815 * expands a single variable, and only in the beginning of szSrc.
3817 static HRESULT _SHExpandEnvironmentStrings(LPCWSTR szSrc, LPWSTR szDest)
3819 HRESULT hr;
3820 WCHAR szTemp[MAX_PATH], szProfilesPrefix[MAX_PATH] = { 0 };
3821 HKEY key = NULL;
3823 TRACE("%s, %p\n", debugstr_w(szSrc), szDest);
3825 if (!szSrc || !szDest) return E_INVALIDARG;
3827 /* short-circuit if there's nothing to expand */
3828 if (szSrc[0] != '%')
3830 strcpyW(szDest, szSrc);
3831 hr = S_OK;
3832 goto end;
3834 /* Get the profile prefix, we'll probably be needing it */
3835 hr = _SHOpenProfilesKey(&key);
3836 if (SUCCEEDED(hr))
3838 WCHAR def_val[MAX_PATH];
3840 /* get the system drive */
3841 GetSystemDirectoryW(def_val, MAX_PATH);
3842 strcpyW( def_val + 3, szDefaultProfileDirW );
3844 hr = _SHGetProfilesValue(key, ProfilesDirectoryW, szProfilesPrefix, def_val );
3847 *szDest = 0;
3848 strcpyW(szTemp, szSrc);
3849 while (SUCCEEDED(hr) && szTemp[0] == '%')
3851 if (!strncmpiW(szTemp, AllUsersProfileW, strlenW(AllUsersProfileW)))
3853 WCHAR szAllUsers[MAX_PATH], def_val[MAX_PATH];
3855 GetSystemDirectoryW(def_val, MAX_PATH);
3856 strcpyW( def_val + 3, UsersPublicW );
3858 hr = _SHGetProfilesValue(key, PublicW, szAllUsers, def_val);
3859 PathAppendW(szDest, szAllUsers);
3860 PathAppendW(szDest, szTemp + strlenW(AllUsersProfileW));
3862 else if (!strncmpiW(szTemp, PublicProfileW, strlenW(PublicProfileW)))
3864 WCHAR szAllUsers[MAX_PATH], def_val[MAX_PATH];
3866 GetSystemDirectoryW(def_val, MAX_PATH);
3867 strcpyW( def_val + 3, UsersPublicW );
3869 hr = _SHGetProfilesValue(key, PublicW, szAllUsers, def_val);
3870 PathAppendW(szDest, szAllUsers);
3871 PathAppendW(szDest, szTemp + strlenW(PublicProfileW));
3873 else if (!strncmpiW(szTemp, ProgramDataVarW, strlenW(ProgramDataVarW)))
3875 WCHAR szProgramData[MAX_PATH], def_val[MAX_PATH];
3876 HKEY shellFolderKey;
3877 DWORD dwType, dwPathLen = sizeof(def_val);
3878 BOOL in_registry = FALSE;
3880 if (!RegCreateKeyW(HKEY_LOCAL_MACHINE, szSHFolders, &shellFolderKey))
3882 if (!RegQueryValueExW(shellFolderKey, Common_AppDataW, NULL, &dwType,
3883 (LPBYTE)def_val, &dwPathLen) && (dwType == REG_EXPAND_SZ || dwType == REG_SZ))
3884 in_registry = TRUE;
3886 RegCloseKey(shellFolderKey);
3889 if (!in_registry)
3891 GetSystemDirectoryW(def_val, MAX_PATH);
3892 strcpyW( def_val + 3, ProgramDataW );
3895 hr = _SHGetProfilesValue(key, ProgramDataW, szProgramData, def_val);
3896 PathAppendW(szDest, szProgramData);
3897 PathAppendW(szDest, szTemp + strlenW(ProgramDataVarW));
3899 else if (!strncmpiW(szTemp, UserProfileW, strlenW(UserProfileW)))
3901 WCHAR userName[MAX_PATH];
3902 DWORD userLen = MAX_PATH;
3904 strcpyW(szDest, szProfilesPrefix);
3905 GetUserNameW(userName, &userLen);
3906 PathAppendW(szDest, userName);
3907 PathAppendW(szDest, szTemp + strlenW(UserProfileW));
3909 else if (!strncmpiW(szTemp, SystemDriveW, strlenW(SystemDriveW)))
3911 GetSystemDirectoryW(szDest, MAX_PATH);
3912 strcpyW(szDest + 3, szTemp + strlenW(SystemDriveW) + 1);
3914 else
3916 DWORD ret = ExpandEnvironmentStringsW(szTemp, szDest, MAX_PATH);
3918 if (ret > MAX_PATH)
3919 hr = E_NOT_SUFFICIENT_BUFFER;
3920 else if (ret == 0)
3921 hr = HRESULT_FROM_WIN32(GetLastError());
3922 else if (!strcmpW( szTemp, szDest )) break; /* nothing expanded */
3924 if (SUCCEEDED(hr)) strcpyW(szTemp, szDest);
3926 end:
3927 if (key)
3928 RegCloseKey(key);
3929 TRACE("returning 0x%08x (input was %s, output is %s)\n", hr,
3930 debugstr_w(szSrc), debugstr_w(szDest));
3931 return hr;
3934 /*************************************************************************
3935 * _SHGetXDGUserDirs [Internal]
3937 * Get XDG directories paths from XDG configuration.
3939 * PARAMS
3940 * xdg_dirs [I] Array of XDG directories to look for.
3941 * num_dirs [I] Number of elements in xdg_dirs.
3942 * xdg_results [O] An array of the XDG directories paths.
3944 static inline void _SHGetXDGUserDirs(const char * const *xdg_dirs, const unsigned int num_dirs, char *** xdg_results) {
3945 HRESULT hr;
3947 hr = XDG_UserDirLookup(xdg_dirs, num_dirs, xdg_results);
3948 if (FAILED(hr)) *xdg_results = NULL;
3951 /*************************************************************************
3952 * _SHFreeXDGUserDirs [Internal]
3954 * Free resources allocated by XDG_UserDirLookup().
3956 * PARAMS
3957 * num_dirs [I] Number of elements in xdg_results.
3958 * xdg_results [I] An array of the XDG directories paths.
3960 static inline void _SHFreeXDGUserDirs(const unsigned int num_dirs, char ** xdg_results) {
3961 UINT i;
3963 if (xdg_results)
3965 for (i = 0; i < num_dirs; i++)
3966 heap_free(xdg_results[i]);
3967 heap_free(xdg_results);
3971 /*************************************************************************
3972 * _SHAppendToUnixPath [Internal]
3974 * Helper function for _SHCreateSymbolicLinks. Appends pwszSubPath (or the
3975 * corresponding resource, if IS_INTRESOURCE) to the unix base path 'szBasePath'
3976 * and replaces backslashes with slashes.
3978 * PARAMS
3979 * szBasePath [IO] The unix base path, which will be appended to (CP_UNXICP).
3980 * pwszSubPath [I] Sub-path or resource id (use MAKEINTRESOURCEW).
3982 * RETURNS
3983 * Success: TRUE,
3984 * Failure: FALSE
3986 static inline BOOL _SHAppendToUnixPath(char *szBasePath, LPCWSTR pwszSubPath) {
3987 WCHAR wszSubPath[MAX_PATH];
3988 int cLen = strlen(szBasePath);
3989 char *pBackslash;
3991 if (IS_INTRESOURCE(pwszSubPath)) {
3992 if (!LoadStringW(shell32_hInstance, LOWORD(pwszSubPath), wszSubPath, MAX_PATH)) {
3993 /* Fall back to hard coded defaults. */
3994 switch (LOWORD(pwszSubPath)) {
3995 case IDS_PERSONAL:
3996 lstrcpyW(wszSubPath, DocumentsW);
3997 break;
3998 case IDS_MYMUSIC:
3999 lstrcpyW(wszSubPath, My_MusicW);
4000 break;
4001 case IDS_MYPICTURES:
4002 lstrcpyW(wszSubPath, My_PicturesW);
4003 break;
4004 case IDS_MYVIDEOS:
4005 lstrcpyW(wszSubPath, My_VideosW);
4006 break;
4007 case IDS_DOWNLOADS:
4008 lstrcpyW(wszSubPath, DownloadsW);
4009 break;
4010 case IDS_TEMPLATES:
4011 lstrcpyW(wszSubPath, TemplatesW);
4012 break;
4013 default:
4014 ERR("LoadString(%d) failed!\n", LOWORD(pwszSubPath));
4015 return FALSE;
4018 } else {
4019 lstrcpyW(wszSubPath, pwszSubPath);
4022 if (szBasePath[cLen-1] != '/') szBasePath[cLen++] = '/';
4024 if (!WideCharToMultiByte(CP_UNIXCP, 0, wszSubPath, -1, szBasePath + cLen,
4025 FILENAME_MAX - cLen, NULL, NULL))
4027 return FALSE;
4030 pBackslash = szBasePath + cLen;
4031 while ((pBackslash = strchr(pBackslash, '\\'))) *pBackslash = '/';
4033 return TRUE;
4036 /******************************************************************************
4037 * _SHGetFolderUnixPath [Internal]
4039 * Create a shell folder and get its unix path.
4041 * PARAMS
4042 * nFolder [I] CSIDL identifying the folder.
4044 static inline char * _SHGetFolderUnixPath(const int nFolder)
4046 WCHAR wszTempPath[MAX_PATH];
4047 HRESULT hr;
4049 hr = SHGetFolderPathW(NULL, nFolder, NULL,
4050 SHGFP_TYPE_CURRENT, wszTempPath);
4051 if (FAILED(hr)) return NULL;
4053 return wine_get_unix_file_name(wszTempPath);
4056 /******************************************************************************
4057 * _SHCreateMyDocumentsSubDirs [Internal]
4059 * Create real directories for various shell folders under 'My Documents'. For
4060 * Windows and homeless styles. Fails silently for already existing sub dirs.
4062 * PARAMS
4063 * aidsMyStuff [I] Array of IDS_* resources to create sub dirs for.
4064 * num [I] Number of elements in aidsMyStuff.
4065 * szPersonalTarget [I] Unix path to 'My Documents' directory.
4067 static void _SHCreateMyDocumentsSubDirs(const UINT * aidsMyStuff, const UINT num, const char * szPersonalTarget)
4069 char szMyStuffTarget[FILENAME_MAX];
4070 UINT i;
4072 if (aidsMyStuff && szPersonalTarget)
4074 for (i = 0; i < num; i++)
4076 strcpy(szMyStuffTarget, szPersonalTarget);
4077 if (_SHAppendToUnixPath(szMyStuffTarget, MAKEINTRESOURCEW(aidsMyStuff[i])))
4078 mkdir(szMyStuffTarget, 0777);
4083 /******************************************************************************
4084 * _SHCreateMyDocumentsSymbolicLink [Internal]
4086 * Sets up a symbolic link for the 'My Documents' shell folder to point into
4087 * the users home directory.
4089 * PARAMS
4090 * aidsMyStuff [I] Array of IDS_* resources to create sub dirs for.
4091 * aids_num [I] Number of elements in aidsMyStuff.
4093 static void _SHCreateMyDocumentsSymbolicLink(const UINT * aidsMyStuff, const UINT aids_num)
4095 static const char * const xdg_dirs[] = { "DOCUMENTS" };
4096 static const unsigned int num = ARRAY_SIZE(xdg_dirs);
4097 char szPersonalTarget[FILENAME_MAX], *pszPersonal;
4098 struct stat statFolder;
4099 const char *pszHome;
4100 char ** xdg_results;
4102 /* Get the unix path of 'My Documents'. */
4103 pszPersonal = _SHGetFolderUnixPath(CSIDL_PERSONAL|CSIDL_FLAG_DONT_VERIFY);
4104 if (!pszPersonal) return;
4106 _SHGetXDGUserDirs(xdg_dirs, num, &xdg_results);
4108 pszHome = getenv("HOME");
4109 if (pszHome && !stat(pszHome, &statFolder) && S_ISDIR(statFolder.st_mode))
4111 while (1)
4113 /* Check if there's already a Wine-specific 'My Documents' folder */
4114 strcpy(szPersonalTarget, pszHome);
4115 if (_SHAppendToUnixPath(szPersonalTarget, MAKEINTRESOURCEW(IDS_PERSONAL)) &&
4116 !stat(szPersonalTarget, &statFolder) && S_ISDIR(statFolder.st_mode))
4118 /* '$HOME/My Documents' exists. Create subfolders for
4119 * 'My Pictures', 'My Videos', 'My Music' etc. or fail silently
4120 * if they already exist.
4122 _SHCreateMyDocumentsSubDirs(aidsMyStuff, aids_num, szPersonalTarget);
4123 break;
4126 /* Try to point to the XDG Documents folder */
4127 if (xdg_results && xdg_results[0] &&
4128 !stat(xdg_results[0], &statFolder) &&
4129 S_ISDIR(statFolder.st_mode))
4131 strcpy(szPersonalTarget, xdg_results[0]);
4132 break;
4135 /* Or the hardcoded / OS X Documents folder */
4136 strcpy(szPersonalTarget, pszHome);
4137 if (_SHAppendToUnixPath(szPersonalTarget, DocumentsW) &&
4138 !stat(szPersonalTarget, &statFolder) &&
4139 S_ISDIR(statFolder.st_mode))
4140 break;
4142 /* As a last resort point to $HOME. */
4143 strcpy(szPersonalTarget, pszHome);
4144 break;
4147 /* Create symbolic link to 'My Documents' or fail silently if a directory
4148 * or symlink exists. */
4149 symlink(szPersonalTarget, pszPersonal);
4151 else
4153 /* '$HOME' doesn't exist. Create subdirs for 'My Pictures', 'My Videos',
4154 * 'My Music' etc. in '%USERPROFILE%\My Documents' or fail silently if
4155 * they already exist. */
4156 pszHome = NULL;
4157 strcpy(szPersonalTarget, pszPersonal);
4158 _SHCreateMyDocumentsSubDirs(aidsMyStuff, aids_num, szPersonalTarget);
4161 heap_free(pszPersonal);
4163 _SHFreeXDGUserDirs(num, xdg_results);
4166 /******************************************************************************
4167 * _SHCreateMyStuffSymbolicLink [Internal]
4169 * Sets up a symbolic link for one of the 'My Whatever' shell folders to point
4170 * into the users home directory.
4172 * PARAMS
4173 * nFolder [I] CSIDL identifying the folder.
4175 static void _SHCreateMyStuffSymbolicLink(int nFolder)
4177 static const UINT aidsMyStuff[] = {
4178 IDS_MYPICTURES, IDS_MYVIDEOS, IDS_MYMUSIC, IDS_DOWNLOADS, IDS_TEMPLATES
4180 static const WCHAR * const MyOSXStuffW[] = {
4181 PicturesW, MoviesW, MusicW, DownloadsW, TemplatesW
4183 static const int acsidlMyStuff[] = {
4184 CSIDL_MYPICTURES, CSIDL_MYVIDEO, CSIDL_MYMUSIC, CSIDL_DOWNLOADS, CSIDL_TEMPLATES
4186 static const char * const xdg_dirs[] = {
4187 "PICTURES", "VIDEOS", "MUSIC", "DOWNLOAD", "TEMPLATES"
4189 static const unsigned int num = ARRAY_SIZE(xdg_dirs);
4190 char szPersonalTarget[FILENAME_MAX], *pszPersonal;
4191 char szMyStuffTarget[FILENAME_MAX], *pszMyStuff;
4192 struct stat statFolder;
4193 const char *pszHome;
4194 char ** xdg_results;
4195 DWORD folder = nFolder & CSIDL_FOLDER_MASK;
4196 UINT i;
4198 for (i = 0; i < ARRAY_SIZE(acsidlMyStuff) && acsidlMyStuff[i] != folder; i++);
4199 if (i >= ARRAY_SIZE(acsidlMyStuff)) return;
4201 /* Create all necessary profile sub-dirs up to 'My Documents' and get the unix path. */
4202 pszPersonal = _SHGetFolderUnixPath(CSIDL_PERSONAL|CSIDL_FLAG_CREATE);
4203 if (!pszPersonal) return;
4205 strcpy(szPersonalTarget, pszPersonal);
4206 if (!stat(pszPersonal, &statFolder) && S_ISLNK(statFolder.st_mode))
4208 int cLen = readlink(pszPersonal, szPersonalTarget, FILENAME_MAX-1);
4209 if (cLen >= 0) szPersonalTarget[cLen] = '\0';
4211 heap_free(pszPersonal);
4213 _SHGetXDGUserDirs(xdg_dirs, num, &xdg_results);
4215 pszHome = getenv("HOME");
4217 while (1)
4219 /* Get the current 'My Whatever' folder unix path. */
4220 pszMyStuff = _SHGetFolderUnixPath(acsidlMyStuff[i]|CSIDL_FLAG_DONT_VERIFY);
4221 if (!pszMyStuff) break;
4223 while (1)
4225 /* Check for the Wine-specific '$HOME/My Documents' subfolder */
4226 strcpy(szMyStuffTarget, szPersonalTarget);
4227 if (_SHAppendToUnixPath(szMyStuffTarget, MAKEINTRESOURCEW(aidsMyStuff[i])) &&
4228 !stat(szMyStuffTarget, &statFolder) && S_ISDIR(statFolder.st_mode))
4229 break;
4231 /* Try the XDG_XXX_DIR folder */
4232 if (xdg_results && xdg_results[i])
4234 strcpy(szMyStuffTarget, xdg_results[i]);
4235 break;
4238 /* Or the OS X folder (these are never localized) */
4239 if (pszHome)
4241 strcpy(szMyStuffTarget, pszHome);
4242 if (_SHAppendToUnixPath(szMyStuffTarget, MyOSXStuffW[i]) &&
4243 !stat(szMyStuffTarget, &statFolder) &&
4244 S_ISDIR(statFolder.st_mode))
4245 break;
4248 /* As a last resort point to the same location as 'My Documents' */
4249 strcpy(szMyStuffTarget, szPersonalTarget);
4250 break;
4252 symlink(szMyStuffTarget, pszMyStuff);
4253 heap_free(pszMyStuff);
4254 break;
4257 _SHFreeXDGUserDirs(num, xdg_results);
4260 /******************************************************************************
4261 * _SHCreateDesktopSymbolicLink [Internal]
4263 * Sets up a symbolic link for the 'Desktop' shell folder to point into the
4264 * users home directory.
4266 static void _SHCreateDesktopSymbolicLink(void)
4268 static const char * const xdg_dirs[] = { "DESKTOP" };
4269 static const unsigned int num = ARRAY_SIZE(xdg_dirs);
4270 char *pszPersonal;
4271 char szDesktopTarget[FILENAME_MAX], *pszDesktop;
4272 struct stat statFolder;
4273 const char *pszHome;
4274 char ** xdg_results;
4275 char * xdg_desktop_dir;
4277 /* Create all necessary profile sub-dirs up to 'My Documents' and get the unix path. */
4278 pszPersonal = _SHGetFolderUnixPath(CSIDL_PERSONAL|CSIDL_FLAG_CREATE);
4279 if (!pszPersonal) return;
4281 _SHGetXDGUserDirs(xdg_dirs, num, &xdg_results);
4283 pszHome = getenv("HOME");
4285 if (pszHome)
4286 strcpy(szDesktopTarget, pszHome);
4287 else
4288 strcpy(szDesktopTarget, pszPersonal);
4289 heap_free(pszPersonal);
4291 xdg_desktop_dir = xdg_results ? xdg_results[0] : NULL;
4292 if (xdg_desktop_dir ||
4293 (_SHAppendToUnixPath(szDesktopTarget, DesktopW) &&
4294 !stat(szDesktopTarget, &statFolder) && S_ISDIR(statFolder.st_mode)))
4296 pszDesktop = _SHGetFolderUnixPath(CSIDL_DESKTOPDIRECTORY|CSIDL_FLAG_DONT_VERIFY);
4297 if (pszDesktop)
4299 if (xdg_desktop_dir)
4300 symlink(xdg_desktop_dir, pszDesktop);
4301 else
4302 symlink(szDesktopTarget, pszDesktop);
4303 heap_free(pszDesktop);
4307 _SHFreeXDGUserDirs(num, xdg_results);
4310 /******************************************************************************
4311 * _SHCreateSymbolicLink [Internal]
4313 * Sets up a symbolic link for one of the special shell folders to point into
4314 * the users home directory.
4316 * PARAMS
4317 * nFolder [I] CSIDL identifying the folder.
4319 static void _SHCreateSymbolicLink(int nFolder)
4321 static const UINT aidsMyStuff[] = {
4322 IDS_MYPICTURES, IDS_MYVIDEOS, IDS_MYMUSIC, IDS_DOWNLOADS, IDS_TEMPLATES
4324 DWORD folder = nFolder & CSIDL_FOLDER_MASK;
4326 switch (folder) {
4327 case CSIDL_PERSONAL:
4328 _SHCreateMyDocumentsSymbolicLink(aidsMyStuff, ARRAY_SIZE(aidsMyStuff));
4329 break;
4330 case CSIDL_MYPICTURES:
4331 case CSIDL_MYVIDEO:
4332 case CSIDL_MYMUSIC:
4333 case CSIDL_DOWNLOADS:
4334 case CSIDL_TEMPLATES:
4335 _SHCreateMyStuffSymbolicLink(folder);
4336 break;
4337 case CSIDL_DESKTOPDIRECTORY:
4338 _SHCreateDesktopSymbolicLink();
4339 break;
4343 /******************************************************************************
4344 * _SHCreateSymbolicLinks [Internal]
4346 * Sets up symbol links for various shell folders to point into the user's home
4347 * directory. We do an educated guess about what the user would probably want:
4348 * - If there is a 'My Documents' directory in $HOME, the user probably wants
4349 * wine's 'My Documents' to point there. Furthermore, we infer that the user
4350 * is a Windows lover and has no problem with wine creating subfolders for
4351 * 'My Pictures', 'My Music', 'My Videos' etc. under '$HOME/My Documents', if
4352 * those do not already exist. We put appropriate symbolic links in place for
4353 * those, too.
4354 * - If there is no 'My Documents' directory in $HOME, we let 'My Documents'
4355 * point directly to $HOME. We assume the user to be a unix hacker who does not
4356 * want wine to create anything anywhere besides the .wine directory. So, if
4357 * there already is a 'My Music' directory in $HOME, we symlink the 'My Music'
4358 * shell folder to it. But if not, then we check XDG_MUSIC_DIR - "well known"
4359 * directory, and try to link to that. If that fails, then we symlink to
4360 * $HOME directly. The same holds for 'My Pictures', 'My Videos' etc.
4361 * - The Desktop shell folder is symlinked to XDG_DESKTOP_DIR. If that does not
4362 * exist, then we try '$HOME/Desktop'. If that does not exist, then we leave
4363 * it alone.
4364 * ('My Music',... above in fact means LoadString(IDS_MYMUSIC))
4366 static void _SHCreateSymbolicLinks(void)
4368 static const int acsidlMyStuff[] = {
4369 CSIDL_MYPICTURES, CSIDL_MYVIDEO, CSIDL_MYMUSIC, CSIDL_DOWNLOADS, CSIDL_TEMPLATES, CSIDL_PERSONAL, CSIDL_DESKTOPDIRECTORY
4371 UINT i;
4373 for (i=0; i < ARRAY_SIZE(acsidlMyStuff); i++)
4374 _SHCreateSymbolicLink(acsidlMyStuff[i]);
4377 /******************************************************************************
4378 * SHGetFolderPathW [SHELL32.@]
4380 * Convert nFolder to path.
4382 * RETURNS
4383 * Success: S_OK
4384 * Failure: standard HRESULT error codes.
4386 * NOTES
4387 * Most values can be overridden in either
4388 * HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
4389 * or in the same location in HKLM.
4390 * The "Shell Folders" registry key was used in NT4 and earlier systems.
4391 * Beginning with Windows 2000, the "User Shell Folders" key is used, so
4392 * changes made to it are made to the former key too. This synchronization is
4393 * done on-demand: not until someone requests the value of one of these paths
4394 * (by calling one of the SHGet functions) is the value synchronized.
4395 * Furthermore, the HKCU paths take precedence over the HKLM paths.
4397 HRESULT WINAPI SHGetFolderPathW(
4398 HWND hwndOwner, /* [I] owner window */
4399 int nFolder, /* [I] CSIDL identifying the folder */
4400 HANDLE hToken, /* [I] access token */
4401 DWORD dwFlags, /* [I] which path to return */
4402 LPWSTR pszPath) /* [O] converted path */
4404 HRESULT hr = SHGetFolderPathAndSubDirW(hwndOwner, nFolder, hToken, dwFlags, NULL, pszPath);
4405 if(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) == hr)
4406 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
4407 return hr;
4410 HRESULT WINAPI SHGetFolderPathAndSubDirA(
4411 HWND hwndOwner, /* [I] owner window */
4412 int nFolder, /* [I] CSIDL identifying the folder */
4413 HANDLE hToken, /* [I] access token */
4414 DWORD dwFlags, /* [I] which path to return */
4415 LPCSTR pszSubPath, /* [I] sub directory of the specified folder */
4416 LPSTR pszPath) /* [O] converted path */
4418 int length;
4419 HRESULT hr = S_OK;
4420 LPWSTR pszSubPathW = NULL;
4421 LPWSTR pszPathW = NULL;
4423 TRACE("%p,%#x,%p,%#x,%s,%p\n", hwndOwner, nFolder, hToken, dwFlags, debugstr_a(pszSubPath), pszPath);
4425 if(pszPath) {
4426 pszPathW = heap_alloc(MAX_PATH * sizeof(WCHAR));
4427 if(!pszPathW) {
4428 hr = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
4429 goto cleanup;
4432 TRACE("%08x,%08x,%s\n",nFolder, dwFlags, debugstr_w(pszSubPathW));
4434 /* SHGetFolderPathAndSubDirW does not distinguish if pszSubPath isn't
4435 * set (null), or an empty string.therefore call it without the parameter set
4436 * if pszSubPath is an empty string
4438 if (pszSubPath && pszSubPath[0]) {
4439 length = MultiByteToWideChar(CP_ACP, 0, pszSubPath, -1, NULL, 0);
4440 pszSubPathW = heap_alloc(length * sizeof(WCHAR));
4441 if(!pszSubPathW) {
4442 hr = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
4443 goto cleanup;
4445 MultiByteToWideChar(CP_ACP, 0, pszSubPath, -1, pszSubPathW, length);
4448 hr = SHGetFolderPathAndSubDirW(hwndOwner, nFolder, hToken, dwFlags, pszSubPathW, pszPathW);
4450 if (SUCCEEDED(hr) && pszPath)
4451 WideCharToMultiByte(CP_ACP, 0, pszPathW, -1, pszPath, MAX_PATH, NULL, NULL);
4453 cleanup:
4454 heap_free(pszPathW);
4455 heap_free(pszSubPathW);
4456 return hr;
4459 /*************************************************************************
4460 * SHGetFolderPathAndSubDirW [SHELL32.@]
4462 HRESULT WINAPI SHGetFolderPathAndSubDirW(
4463 HWND hwndOwner, /* [I] owner window */
4464 int nFolder, /* [I] CSIDL identifying the folder */
4465 HANDLE hToken, /* [I] access token */
4466 DWORD dwFlags, /* [I] which path to return */
4467 LPCWSTR pszSubPath,/* [I] sub directory of the specified folder */
4468 LPWSTR pszPath) /* [O] converted path */
4470 HRESULT hr;
4471 WCHAR szBuildPath[MAX_PATH], szTemp[MAX_PATH];
4472 DWORD folder = nFolder & CSIDL_FOLDER_MASK;
4473 CSIDL_Type type;
4474 int ret;
4476 TRACE("%p,%#x,%p,%#x,%s,%p\n", hwndOwner, nFolder, hToken, dwFlags, debugstr_w(pszSubPath), pszPath);
4478 /* Windows always NULL-terminates the resulting path regardless of success
4479 * or failure, so do so first
4481 if (pszPath)
4482 *pszPath = '\0';
4484 if (folder >= ARRAY_SIZE(CSIDL_Data))
4485 return E_INVALIDARG;
4486 if ((SHGFP_TYPE_CURRENT != dwFlags) && (SHGFP_TYPE_DEFAULT != dwFlags))
4487 return E_INVALIDARG;
4488 szTemp[0] = 0;
4489 type = CSIDL_Data[folder].type;
4490 switch (type)
4492 case CSIDL_Type_Disallowed:
4493 hr = E_INVALIDARG;
4494 break;
4495 case CSIDL_Type_NonExistent:
4496 hr = S_FALSE;
4497 break;
4498 case CSIDL_Type_WindowsPath:
4499 GetWindowsDirectoryW(szTemp, MAX_PATH);
4500 append_relative_path(folder, szTemp);
4501 hr = S_OK;
4502 break;
4503 case CSIDL_Type_SystemPath:
4504 GetSystemDirectoryW(szTemp, MAX_PATH);
4505 append_relative_path(folder, szTemp);
4506 hr = S_OK;
4507 break;
4508 case CSIDL_Type_SystemX86Path:
4509 if (!GetSystemWow64DirectoryW(szTemp, MAX_PATH)) GetSystemDirectoryW(szTemp, MAX_PATH);
4510 append_relative_path(folder, szTemp);
4511 hr = S_OK;
4512 break;
4513 case CSIDL_Type_CurrVer:
4514 hr = _SHGetCurrentVersionPath(dwFlags, folder, szTemp);
4515 break;
4516 case CSIDL_Type_User:
4517 hr = _SHGetUserProfilePath(hToken, dwFlags, folder, szTemp);
4518 break;
4519 case CSIDL_Type_AllUsers:
4520 case CSIDL_Type_ProgramData:
4521 hr = _SHGetAllUsersProfilePath(dwFlags, folder, szTemp);
4522 break;
4523 default:
4524 FIXME("bogus type %d, please fix\n", type);
4525 hr = E_INVALIDARG;
4526 break;
4529 /* Expand environment strings if necessary */
4530 if (*szTemp == '%')
4531 hr = _SHExpandEnvironmentStrings(szTemp, szBuildPath);
4532 else
4533 strcpyW(szBuildPath, szTemp);
4535 if (FAILED(hr)) goto end;
4537 if(pszSubPath) {
4538 /* make sure the new path does not exceed the buffer length
4539 * and remember to backslash and terminate it */
4540 if(MAX_PATH < (lstrlenW(szBuildPath) + lstrlenW(pszSubPath) + 2)) {
4541 hr = HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE);
4542 goto end;
4544 PathAppendW(szBuildPath, pszSubPath);
4545 PathRemoveBackslashW(szBuildPath);
4547 /* Copy the path if it's available before we might return */
4548 if (SUCCEEDED(hr) && pszPath)
4549 strcpyW(pszPath, szBuildPath);
4551 /* if we don't care about existing directories we are ready */
4552 if(nFolder & CSIDL_FLAG_DONT_VERIFY) goto end;
4554 if (PathFileExistsW(szBuildPath)) goto end;
4556 /* not existing but we are not allowed to create it. The return value
4557 * is verified against shell32 version 6.0.
4559 if (!(nFolder & CSIDL_FLAG_CREATE))
4561 hr = HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND);
4562 goto end;
4565 /* create symbolic links rather than directories for specific
4566 * user shell folders */
4567 _SHCreateSymbolicLink(folder);
4569 /* create directory/directories */
4570 ret = SHCreateDirectoryExW(hwndOwner, szBuildPath, NULL);
4571 if (ret && ret != ERROR_ALREADY_EXISTS)
4573 ERR("Failed to create directory %s.\n", debugstr_w(szBuildPath));
4574 hr = E_FAIL;
4575 goto end;
4578 TRACE("Created missing system directory %s\n", debugstr_w(szBuildPath));
4579 end:
4580 TRACE("returning 0x%08x (final path is %s)\n", hr, debugstr_w(szBuildPath));
4581 return hr;
4584 /*************************************************************************
4585 * SHGetFolderPathA [SHELL32.@]
4587 * See SHGetFolderPathW.
4589 HRESULT WINAPI SHGetFolderPathA(
4590 HWND hwndOwner,
4591 int nFolder,
4592 HANDLE hToken,
4593 DWORD dwFlags,
4594 LPSTR pszPath)
4596 WCHAR szTemp[MAX_PATH];
4597 HRESULT hr;
4599 TRACE("%p,%d,%p,%#x,%p\n", hwndOwner, nFolder, hToken, dwFlags, pszPath);
4601 if (pszPath)
4602 *pszPath = '\0';
4603 hr = SHGetFolderPathW(hwndOwner, nFolder, hToken, dwFlags, szTemp);
4604 if (SUCCEEDED(hr) && pszPath)
4605 WideCharToMultiByte(CP_ACP, 0, szTemp, -1, pszPath, MAX_PATH, NULL,
4606 NULL);
4608 return hr;
4611 /* For each folder in folders, if its value has not been set in the registry,
4612 * calls _SHGetUserProfilePath or _SHGetAllUsersProfilePath (depending on the
4613 * folder's type) to get the unexpanded value first.
4614 * Writes the unexpanded value to User Shell Folders, and queries it with
4615 * SHGetFolderPathW to force the creation of the directory if it doesn't
4616 * already exist. SHGetFolderPathW also returns the expanded value, which
4617 * this then writes to Shell Folders.
4619 static HRESULT _SHRegisterFolders(HKEY hRootKey, HANDLE hToken,
4620 LPCWSTR szUserShellFolderPath, LPCWSTR szShellFolderPath, const UINT folders[],
4621 UINT foldersLen)
4623 const WCHAR *szValueName;
4624 WCHAR buffer[40];
4625 UINT i;
4626 WCHAR path[MAX_PATH];
4627 HRESULT hr = S_OK;
4628 HKEY hUserKey = NULL, hKey = NULL;
4629 DWORD dwType, dwPathLen;
4630 LONG ret;
4632 TRACE("%p,%p,%s,%p,%u\n", hRootKey, hToken,
4633 debugstr_w(szUserShellFolderPath), folders, foldersLen);
4635 ret = RegCreateKeyW(hRootKey, szUserShellFolderPath, &hUserKey);
4636 if (ret)
4637 hr = HRESULT_FROM_WIN32(ret);
4638 else
4640 ret = RegCreateKeyW(hRootKey, szShellFolderPath, &hKey);
4641 if (ret)
4642 hr = HRESULT_FROM_WIN32(ret);
4644 for (i = 0; SUCCEEDED(hr) && i < foldersLen; i++)
4646 dwPathLen = MAX_PATH * sizeof(WCHAR);
4648 /* For CSIDL_Type_User we also use the GUID if no szValueName is provided */
4649 szValueName = CSIDL_Data[folders[i]].szValueName;
4650 if (!szValueName && CSIDL_Data[folders[i]].type == CSIDL_Type_User)
4652 StringFromGUID2( CSIDL_Data[folders[i]].id, buffer, 39 );
4653 szValueName = &buffer[0];
4656 if (RegQueryValueExW(hUserKey, szValueName, NULL,
4657 &dwType, (LPBYTE)path, &dwPathLen) || (dwType != REG_SZ &&
4658 dwType != REG_EXPAND_SZ))
4660 *path = '\0';
4661 if (CSIDL_Data[folders[i]].type == CSIDL_Type_User)
4662 _SHGetUserProfilePath(hToken, SHGFP_TYPE_DEFAULT, folders[i],
4663 path);
4664 else if (CSIDL_Data[folders[i]].type == CSIDL_Type_AllUsers ||
4665 CSIDL_Data[folders[i]].type == CSIDL_Type_ProgramData)
4666 _SHGetAllUsersProfilePath(SHGFP_TYPE_DEFAULT, folders[i], path);
4667 else if (CSIDL_Data[folders[i]].type == CSIDL_Type_WindowsPath)
4669 GetWindowsDirectoryW(path, MAX_PATH);
4670 append_relative_path(folders[i], path);
4672 else
4673 hr = E_FAIL;
4674 if (*path)
4676 ret = RegSetValueExW(hUserKey, szValueName, 0, REG_EXPAND_SZ,
4677 (LPBYTE)path, (strlenW(path) + 1) * sizeof(WCHAR));
4678 if (ret)
4679 hr = HRESULT_FROM_WIN32(ret);
4680 else
4682 hr = SHGetFolderPathW(NULL, folders[i] | CSIDL_FLAG_CREATE,
4683 hToken, SHGFP_TYPE_DEFAULT, path);
4684 ret = RegSetValueExW(hKey, szValueName, 0, REG_SZ,
4685 (LPBYTE)path, (strlenW(path) + 1) * sizeof(WCHAR));
4686 if (ret)
4687 hr = HRESULT_FROM_WIN32(ret);
4691 else
4693 /* create the default dir, which may be different from the path
4694 * stored in the registry. */
4695 SHGetFolderPathW(NULL, folders[i] | CSIDL_FLAG_CREATE,
4696 hToken, SHGFP_TYPE_DEFAULT, path);
4699 if (hUserKey)
4700 RegCloseKey(hUserKey);
4701 if (hKey)
4702 RegCloseKey(hKey);
4704 TRACE("returning 0x%08x\n", hr);
4705 return hr;
4708 static HRESULT _SHRegisterUserShellFolders(BOOL bDefault)
4710 static const UINT folders[] = {
4711 CSIDL_PROGRAMS,
4712 CSIDL_PERSONAL,
4713 CSIDL_FAVORITES,
4714 CSIDL_APPDATA,
4715 CSIDL_STARTUP,
4716 CSIDL_RECENT,
4717 CSIDL_SENDTO,
4718 CSIDL_STARTMENU,
4719 CSIDL_MYMUSIC,
4720 CSIDL_MYVIDEO,
4721 CSIDL_DESKTOPDIRECTORY,
4722 CSIDL_NETHOOD,
4723 CSIDL_TEMPLATES,
4724 CSIDL_PRINTHOOD,
4725 CSIDL_LOCAL_APPDATA,
4726 CSIDL_INTERNET_CACHE,
4727 CSIDL_COOKIES,
4728 CSIDL_HISTORY,
4729 CSIDL_MYPICTURES,
4730 CSIDL_FONTS,
4731 CSIDL_ADMINTOOLS,
4732 CSIDL_CONTACTS,
4733 CSIDL_DOWNLOADS,
4734 CSIDL_LINKS,
4735 CSIDL_APPDATA_LOCALLOW,
4736 CSIDL_SAVED_GAMES,
4737 CSIDL_SEARCHES
4739 WCHAR userShellFolderPath[MAX_PATH], shellFolderPath[MAX_PATH];
4740 LPCWSTR pUserShellFolderPath, pShellFolderPath;
4741 HRESULT hr = S_OK;
4742 HKEY hRootKey;
4743 HANDLE hToken;
4745 TRACE("%s\n", bDefault ? "TRUE" : "FALSE");
4746 if (bDefault)
4748 hToken = (HANDLE)-1;
4749 hRootKey = HKEY_USERS;
4750 strcpyW(userShellFolderPath, DefaultW);
4751 PathAddBackslashW(userShellFolderPath);
4752 strcatW(userShellFolderPath, szSHUserFolders);
4753 pUserShellFolderPath = userShellFolderPath;
4754 strcpyW(shellFolderPath, DefaultW);
4755 PathAddBackslashW(shellFolderPath);
4756 strcatW(shellFolderPath, szSHFolders);
4757 pShellFolderPath = shellFolderPath;
4759 else
4761 hToken = NULL;
4762 hRootKey = HKEY_CURRENT_USER;
4763 pUserShellFolderPath = szSHUserFolders;
4764 pShellFolderPath = szSHFolders;
4767 hr = _SHRegisterFolders(hRootKey, hToken, pUserShellFolderPath,
4768 pShellFolderPath, folders, ARRAY_SIZE(folders));
4769 TRACE("returning 0x%08x\n", hr);
4770 return hr;
4773 static HRESULT _SHRegisterCommonShellFolders(void)
4775 static const UINT folders[] = {
4776 CSIDL_COMMON_STARTMENU,
4777 CSIDL_COMMON_PROGRAMS,
4778 CSIDL_COMMON_STARTUP,
4779 CSIDL_COMMON_DESKTOPDIRECTORY,
4780 CSIDL_COMMON_FAVORITES,
4781 CSIDL_COMMON_APPDATA,
4782 CSIDL_COMMON_TEMPLATES,
4783 CSIDL_COMMON_DOCUMENTS,
4784 CSIDL_COMMON_ADMINTOOLS,
4785 CSIDL_COMMON_MUSIC,
4786 CSIDL_COMMON_PICTURES,
4787 CSIDL_COMMON_VIDEO,
4789 HRESULT hr;
4791 TRACE("\n");
4792 hr = _SHRegisterFolders(HKEY_LOCAL_MACHINE, NULL, szSHUserFolders,
4793 szSHFolders, folders, ARRAY_SIZE(folders));
4794 TRACE("returning 0x%08x\n", hr);
4795 return hr;
4798 /******************************************************************************
4799 * create_extra_folders [Internal]
4801 * Create some extra folders that don't have a standard CSIDL definition.
4803 static HRESULT create_extra_folders(void)
4805 static const WCHAR environW[] = {'E','n','v','i','r','o','n','m','e','n','t',0};
4806 static const WCHAR microsoftW[] = {'M','i','c','r','o','s','o','f','t',0};
4807 static const WCHAR TempW[] = {'T','e','m','p',0};
4808 static const WCHAR TEMPW[] = {'T','E','M','P',0};
4809 static const WCHAR TMPW[] = {'T','M','P',0};
4810 WCHAR path[MAX_PATH+5];
4811 HRESULT hr;
4812 HKEY hkey;
4813 DWORD type, size, ret;
4815 ret = RegCreateKeyW( HKEY_CURRENT_USER, environW, &hkey );
4816 if (ret) return HRESULT_FROM_WIN32( ret );
4818 /* FIXME: should be under AppData, but we don't want spaces in the temp path */
4819 hr = SHGetFolderPathAndSubDirW( 0, CSIDL_PROFILE | CSIDL_FLAG_CREATE, NULL,
4820 SHGFP_TYPE_DEFAULT, TempW, path );
4821 if (SUCCEEDED(hr))
4823 size = sizeof(path);
4824 if (RegQueryValueExW( hkey, TEMPW, NULL, &type, (LPBYTE)path, &size ))
4825 RegSetValueExW( hkey, TEMPW, 0, REG_SZ, (LPBYTE)path, (strlenW(path) + 1) * sizeof(WCHAR) );
4826 size = sizeof(path);
4827 if (RegQueryValueExW( hkey, TMPW, NULL, &type, (LPBYTE)path, &size ))
4828 RegSetValueExW( hkey, TMPW, 0, REG_SZ, (LPBYTE)path, (strlenW(path) + 1) * sizeof(WCHAR) );
4830 RegCloseKey( hkey );
4832 if (SUCCEEDED(hr))
4834 hr = SHGetFolderPathAndSubDirW( 0, CSIDL_COMMON_APPDATA | CSIDL_FLAG_CREATE, NULL,
4835 SHGFP_TYPE_DEFAULT, microsoftW, path );
4837 if (SUCCEEDED(hr))
4839 hr = SHGetFolderPathAndSubDirW(0, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL,
4840 SHGFP_TYPE_DEFAULT, Microsoft_Windows_ThemesW, path);
4842 return hr;
4846 /******************************************************************************
4847 * set_folder_attributes
4849 * Set the various folder attributes registry keys.
4851 static HRESULT set_folder_attributes(void)
4853 static const WCHAR clsidW[] = {'C','L','S','I','D','\\',0 };
4854 static const WCHAR shellfolderW[] = {'\\','S','h','e','l','l','F','o','l','d','e','r', 0 };
4855 static const WCHAR wfparsingW[] = {'W','a','n','t','s','F','O','R','P','A','R','S','I','N','G',0};
4856 static const WCHAR wfdisplayW[] = {'W','a','n','t','s','F','O','R','D','I','S','P','L','A','Y',0};
4857 static const WCHAR hideasdeleteW[] = {'H','i','d','e','A','s','D','e','l','e','t','e','P','e','r','U','s','e','r',0};
4858 static const WCHAR cfattributesW[] = {'C','a','l','l','F','o','r','A','t','t','r','i','b','u','t','e','s',0};
4859 static const WCHAR emptyW[] = {0};
4861 static const struct
4863 const CLSID *clsid;
4864 BOOL wfparsing : 1;
4865 BOOL wfdisplay : 1;
4866 BOOL hideasdel : 1;
4867 DWORD attr;
4868 DWORD call_for_attr;
4869 } folders[] =
4871 { &CLSID_UnixFolder, TRUE, FALSE, FALSE },
4872 { &CLSID_UnixDosFolder, TRUE, FALSE, FALSE,
4873 SFGAO_FILESYSANCESTOR|SFGAO_FOLDER|SFGAO_HASSUBFOLDER, SFGAO_FILESYSTEM },
4874 { &CLSID_FolderShortcut, FALSE, FALSE, FALSE,
4875 SFGAO_FILESYSTEM|SFGAO_FOLDER|SFGAO_LINK,
4876 SFGAO_HASSUBFOLDER|SFGAO_FILESYSTEM|SFGAO_FOLDER|SFGAO_FILESYSANCESTOR },
4877 { &CLSID_MyDocuments, TRUE, FALSE, FALSE,
4878 SFGAO_FILESYSANCESTOR|SFGAO_FOLDER|SFGAO_HASSUBFOLDER, SFGAO_FILESYSTEM },
4879 { &CLSID_RecycleBin, FALSE, FALSE, FALSE,
4880 SFGAO_FOLDER|SFGAO_DROPTARGET|SFGAO_HASPROPSHEET },
4881 { &CLSID_ControlPanel, FALSE, TRUE, TRUE,
4882 SFGAO_FOLDER|SFGAO_HASSUBFOLDER }
4885 unsigned int i;
4886 WCHAR buffer[39 + ARRAY_SIZE(clsidW) + ARRAY_SIZE(shellfolderW)];
4887 LONG res;
4888 HKEY hkey;
4890 for (i = 0; i < ARRAY_SIZE(folders); i++)
4892 strcpyW( buffer, clsidW );
4893 StringFromGUID2( folders[i].clsid, buffer + strlenW(buffer), 39 );
4894 strcatW( buffer, shellfolderW );
4895 res = RegCreateKeyExW( HKEY_CLASSES_ROOT, buffer, 0, NULL, 0,
4896 KEY_READ | KEY_WRITE, NULL, &hkey, NULL);
4897 if (res) return HRESULT_FROM_WIN32( res );
4898 if (folders[i].wfparsing)
4899 res = RegSetValueExW( hkey, wfparsingW, 0, REG_SZ, (const BYTE *)emptyW, sizeof(emptyW) );
4900 if (folders[i].wfdisplay)
4901 res = RegSetValueExW( hkey, wfdisplayW, 0, REG_SZ, (const BYTE *)emptyW, sizeof(emptyW) );
4902 if (folders[i].hideasdel)
4903 res = RegSetValueExW( hkey, hideasdeleteW, 0, REG_SZ, (const BYTE *)emptyW, sizeof(emptyW) );
4904 if (folders[i].attr)
4905 res = RegSetValueExW( hkey, szAttributes, 0, REG_DWORD,
4906 (const BYTE *)&folders[i].attr, sizeof(DWORD));
4907 if (folders[i].call_for_attr)
4908 res = RegSetValueExW( hkey, cfattributesW, 0, REG_DWORD,
4909 (const BYTE *)&folders[i].call_for_attr, sizeof(DWORD));
4910 RegCloseKey( hkey );
4912 return S_OK;
4915 /*************************************************************************
4916 * SHGetSpecialFolderPathA [SHELL32.@]
4918 BOOL WINAPI SHGetSpecialFolderPathA (
4919 HWND hwndOwner,
4920 LPSTR szPath,
4921 int nFolder,
4922 BOOL bCreate)
4924 return SHGetFolderPathA(hwndOwner, nFolder + (bCreate ? CSIDL_FLAG_CREATE : 0), NULL, 0,
4925 szPath) == S_OK;
4928 /*************************************************************************
4929 * SHGetSpecialFolderPathW
4931 BOOL WINAPI SHGetSpecialFolderPathW (
4932 HWND hwndOwner,
4933 LPWSTR szPath,
4934 int nFolder,
4935 BOOL bCreate)
4937 return SHGetFolderPathW(hwndOwner, nFolder + (bCreate ? CSIDL_FLAG_CREATE : 0), NULL, 0,
4938 szPath) == S_OK;
4941 /*************************************************************************
4942 * SHGetSpecialFolderPath (SHELL32.175)
4944 BOOL WINAPI SHGetSpecialFolderPathAW (
4945 HWND hwndOwner,
4946 LPVOID szPath,
4947 int nFolder,
4948 BOOL bCreate)
4951 if (SHELL_OsIsUnicode())
4952 return SHGetSpecialFolderPathW (hwndOwner, szPath, nFolder, bCreate);
4953 return SHGetSpecialFolderPathA (hwndOwner, szPath, nFolder, bCreate);
4956 /*************************************************************************
4957 * SHGetFolderLocation [SHELL32.@]
4959 * Gets the folder locations from the registry and creates a pidl.
4961 * PARAMS
4962 * hwndOwner [I]
4963 * nFolder [I] CSIDL_xxxxx
4964 * hToken [I] token representing user, or NULL for current user, or -1 for
4965 * default user
4966 * dwReserved [I] must be zero
4967 * ppidl [O] PIDL of a special folder
4969 * RETURNS
4970 * Success: S_OK
4971 * Failure: Standard OLE-defined error result, S_FALSE or E_INVALIDARG
4973 * NOTES
4974 * Creates missing reg keys and directories.
4975 * Mostly forwards to SHGetFolderPathW, but a few values of nFolder return
4976 * virtual folders that are handled here.
4978 HRESULT WINAPI SHGetFolderLocation(
4979 HWND hwndOwner,
4980 int nFolder,
4981 HANDLE hToken,
4982 DWORD dwReserved,
4983 LPITEMIDLIST *ppidl)
4985 HRESULT hr = E_INVALIDARG;
4987 TRACE("%p 0x%08x %p 0x%08x %p\n",
4988 hwndOwner, nFolder, hToken, dwReserved, ppidl);
4990 if (!ppidl)
4991 return E_INVALIDARG;
4992 if (dwReserved)
4993 return E_INVALIDARG;
4995 /* The virtual folders' locations are not user-dependent */
4996 *ppidl = NULL;
4997 switch (nFolder & CSIDL_FOLDER_MASK)
4999 case CSIDL_DESKTOP:
5000 *ppidl = _ILCreateDesktop();
5001 break;
5003 case CSIDL_PERSONAL:
5004 *ppidl = _ILCreateMyDocuments();
5005 break;
5007 case CSIDL_INTERNET:
5008 *ppidl = _ILCreateIExplore();
5009 break;
5011 case CSIDL_CONTROLS:
5012 *ppidl = _ILCreateControlPanel();
5013 break;
5015 case CSIDL_PRINTERS:
5016 *ppidl = _ILCreatePrinters();
5017 break;
5019 case CSIDL_BITBUCKET:
5020 *ppidl = _ILCreateBitBucket();
5021 break;
5023 case CSIDL_DRIVES:
5024 *ppidl = _ILCreateMyComputer();
5025 break;
5027 case CSIDL_NETWORK:
5028 *ppidl = _ILCreateNetwork();
5029 break;
5031 default:
5033 WCHAR szPath[MAX_PATH];
5035 hr = SHGetFolderPathW(hwndOwner, nFolder, hToken,
5036 SHGFP_TYPE_CURRENT, szPath);
5037 if (SUCCEEDED(hr))
5039 DWORD attributes=0;
5041 TRACE("Value=%s\n", debugstr_w(szPath));
5042 hr = SHILCreateFromPathW(szPath, ppidl, &attributes);
5044 else if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
5046 /* unlike SHGetFolderPath, SHGetFolderLocation in shell32
5047 * version 6.0 returns E_FAIL for nonexistent paths
5049 hr = E_FAIL;
5053 if(*ppidl)
5054 hr = S_OK;
5056 TRACE("-- (new pidl %p)\n",*ppidl);
5057 return hr;
5060 /*************************************************************************
5061 * SHGetSpecialFolderLocation [SHELL32.@]
5063 * NOTES
5064 * In NT5, SHGetSpecialFolderLocation needs the <winntdir>/Recent
5065 * directory.
5067 HRESULT WINAPI SHGetSpecialFolderLocation(
5068 HWND hwndOwner,
5069 INT nFolder,
5070 LPITEMIDLIST * ppidl)
5072 HRESULT hr = E_INVALIDARG;
5074 TRACE("(%p,0x%x,%p)\n", hwndOwner,nFolder,ppidl);
5076 if (!ppidl)
5077 return E_INVALIDARG;
5079 hr = SHGetFolderLocation(hwndOwner, nFolder, NULL, 0, ppidl);
5080 return hr;
5083 /*************************************************************************
5084 * SHGetKnownFolderPath [SHELL32.@]
5086 HRESULT WINAPI SHGetKnownFolderPath(REFKNOWNFOLDERID rfid, DWORD flags, HANDLE token, WCHAR **ret_path)
5088 WCHAR pathW[MAX_PATH], tempW[MAX_PATH];
5089 HRESULT hr;
5090 CSIDL_Type type;
5091 int ret;
5092 int folder = csidl_from_id(rfid), shgfp_flags;
5094 TRACE("%s, 0x%08x, %p, %p\n", debugstr_guid(rfid), flags, token, ret_path);
5096 *ret_path = NULL;
5098 if (folder < 0)
5099 return HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND );
5101 if (flags & ~(KF_FLAG_CREATE|KF_FLAG_SIMPLE_IDLIST|KF_FLAG_DONT_UNEXPAND|
5102 KF_FLAG_DONT_VERIFY|KF_FLAG_NO_ALIAS|KF_FLAG_INIT|KF_FLAG_DEFAULT_PATH))
5104 FIXME("flags 0x%08x not supported\n", flags);
5105 return E_INVALIDARG;
5108 shgfp_flags = flags & KF_FLAG_DEFAULT_PATH ? SHGFP_TYPE_DEFAULT : SHGFP_TYPE_CURRENT;
5110 type = CSIDL_Data[folder].type;
5111 switch (type)
5113 case CSIDL_Type_Disallowed:
5114 hr = E_INVALIDARG;
5115 break;
5116 case CSIDL_Type_NonExistent:
5117 *tempW = 0;
5118 hr = S_FALSE;
5119 break;
5120 case CSIDL_Type_WindowsPath:
5121 GetWindowsDirectoryW(tempW, MAX_PATH);
5122 append_relative_path(folder, tempW);
5123 hr = S_OK;
5124 break;
5125 case CSIDL_Type_SystemPath:
5126 GetSystemDirectoryW(tempW, MAX_PATH);
5127 append_relative_path(folder, tempW);
5128 hr = S_OK;
5129 break;
5130 case CSIDL_Type_SystemX86Path:
5131 if (!GetSystemWow64DirectoryW(tempW, MAX_PATH)) GetSystemDirectoryW(tempW, MAX_PATH);
5132 append_relative_path(folder, tempW);
5133 hr = S_OK;
5134 break;
5135 case CSIDL_Type_CurrVer:
5136 hr = _SHGetCurrentVersionPath(shgfp_flags, folder, tempW);
5137 break;
5138 case CSIDL_Type_User:
5139 hr = _SHGetUserProfilePath(token, shgfp_flags, folder, tempW);
5140 break;
5141 case CSIDL_Type_AllUsers:
5142 case CSIDL_Type_ProgramData:
5143 hr = _SHGetAllUsersProfilePath(shgfp_flags, folder, tempW);
5144 break;
5145 default:
5146 FIXME("bogus type %d, please fix\n", type);
5147 hr = E_INVALIDARG;
5148 break;
5151 if (FAILED(hr))
5152 goto failed;
5154 /* Expand environment strings if necessary */
5155 if (*tempW == '%')
5157 hr = _SHExpandEnvironmentStrings(tempW, pathW);
5158 if (FAILED(hr))
5159 goto failed;
5161 else
5162 strcpyW(pathW, tempW);
5164 /* if we don't care about existing directories we are ready */
5165 if (flags & KF_FLAG_DONT_VERIFY) goto done;
5167 if (PathFileExistsW(pathW)) goto done;
5169 /* Does not exist but we are not allowed to create it. The return value
5170 * is verified against shell32 version 6.0.
5172 if (!(flags & KF_FLAG_CREATE))
5174 hr = HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND);
5175 goto failed;
5178 /* create symbolic links rather than directories for specific
5179 * user shell folders */
5180 _SHCreateSymbolicLink(folder);
5182 /* create directory/directories */
5183 ret = SHCreateDirectoryExW(NULL, pathW, NULL);
5184 if (ret && ret != ERROR_ALREADY_EXISTS)
5186 ERR("Failed to create directory %s.\n", debugstr_w(pathW));
5187 hr = E_FAIL;
5188 goto failed;
5191 TRACE("Created missing system directory %s\n", debugstr_w(pathW));
5193 done:
5194 TRACE("Final path is %s, %#x\n", debugstr_w(pathW), hr);
5196 *ret_path = CoTaskMemAlloc((strlenW(pathW) + 1) * sizeof(WCHAR));
5197 if (!*ret_path)
5198 return E_OUTOFMEMORY;
5199 strcpyW(*ret_path, pathW);
5201 return hr;
5203 failed:
5204 TRACE("Failed to get folder path, %#x.\n", hr);
5206 return hr;
5209 /*************************************************************************
5210 * SHGetFolderPathEx [SHELL32.@]
5212 HRESULT WINAPI SHGetFolderPathEx(REFKNOWNFOLDERID rfid, DWORD flags, HANDLE token, LPWSTR path, DWORD len)
5214 HRESULT hr;
5215 WCHAR *buffer;
5217 TRACE("%s, 0x%08x, %p, %p, %u\n", debugstr_guid(rfid), flags, token, path, len);
5219 if (!path || !len) return E_INVALIDARG;
5221 hr = SHGetKnownFolderPath( rfid, flags, token, &buffer );
5222 if (SUCCEEDED( hr ))
5224 if (strlenW( buffer ) + 1 > len)
5226 CoTaskMemFree( buffer );
5227 return HRESULT_FROM_WIN32( ERROR_INSUFFICIENT_BUFFER );
5229 strcpyW( path, buffer );
5230 CoTaskMemFree( buffer );
5232 return hr;
5236 * Internal function to convert known folder identifier to path of registry key
5237 * associated with known folder.
5239 * Parameters:
5240 * rfid [I] pointer to known folder identifier (may be NULL)
5241 * lpStringGuid [I] string with known folder identifier (used when rfid is NULL)
5242 * lpPath [O] place to store string address. String should be
5243 * later freed using HeapFree(GetProcessHeap(),0, ... )
5245 static HRESULT get_known_folder_registry_path(
5246 REFKNOWNFOLDERID rfid,
5247 LPWSTR lpStringGuid,
5248 LPWSTR *lpPath)
5250 static const WCHAR sBackslash[] = {'\\',0};
5251 HRESULT hr = S_OK;
5252 int length;
5253 WCHAR sGuid[50];
5255 TRACE("(%s, %s, %p)\n", debugstr_guid(rfid), debugstr_w(lpStringGuid), lpPath);
5257 if(rfid)
5258 StringFromGUID2(rfid, sGuid, ARRAY_SIZE(sGuid));
5259 else
5260 lstrcpyW(sGuid, lpStringGuid);
5262 length = lstrlenW(szKnownFolderDescriptions)+51;
5263 *lpPath = heap_alloc(length*sizeof(WCHAR));
5264 if(!(*lpPath))
5265 hr = E_OUTOFMEMORY;
5267 if(SUCCEEDED(hr))
5269 lstrcpyW(*lpPath, szKnownFolderDescriptions);
5270 lstrcatW(*lpPath, sBackslash);
5271 lstrcatW(*lpPath, sGuid);
5274 return hr;
5277 static HRESULT get_known_folder_wstr(const WCHAR *regpath, const WCHAR *value, WCHAR **out)
5279 DWORD size = 0;
5280 HRESULT hr;
5282 size = 0;
5283 hr = HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, regpath, value, RRF_RT_REG_SZ, NULL, NULL, &size));
5284 if(FAILED(hr))
5285 return hr;
5287 *out = CoTaskMemAlloc(size);
5288 if(!*out)
5289 return E_OUTOFMEMORY;
5291 hr = HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, regpath, value, RRF_RT_REG_SZ, NULL, *out, &size));
5292 if(FAILED(hr)){
5293 CoTaskMemFree(*out);
5294 *out = NULL;
5297 return hr;
5300 static HRESULT get_known_folder_dword(const WCHAR *registryPath, const WCHAR *value, DWORD *out)
5302 DWORD dwSize = sizeof(DWORD);
5303 DWORD dwType;
5304 return HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, registryPath, value, RRF_RT_DWORD, &dwType, out, &dwSize));
5308 * Internal function to get place where folder redirection information are stored.
5310 * Parameters:
5311 * rfid [I] pointer to known folder identifier (may be NULL)
5312 * rootKey [O] root key where the redirection information are stored
5313 * It can be HKLM for COMMON folders, and HKCU for PERUSER folders.
5314 * However, besides root key, path is always that same, and is stored
5315 * as "szKnownFolderRedirections" constant
5317 static HRESULT get_known_folder_redirection_place(
5318 REFKNOWNFOLDERID rfid,
5319 HKEY *rootKey)
5321 HRESULT hr;
5322 LPWSTR lpRegistryPath = NULL;
5323 KF_CATEGORY category;
5325 /* first, get known folder's category */
5326 hr = get_known_folder_registry_path(rfid, NULL, &lpRegistryPath);
5328 if(SUCCEEDED(hr))
5329 hr = get_known_folder_dword(lpRegistryPath, szCategory, &category);
5331 if(SUCCEEDED(hr))
5333 if(category == KF_CATEGORY_COMMON)
5335 *rootKey = HKEY_LOCAL_MACHINE;
5336 hr = S_OK;
5338 else if(category == KF_CATEGORY_PERUSER)
5340 *rootKey = HKEY_CURRENT_USER;
5341 hr = S_OK;
5343 else
5344 hr = E_FAIL;
5347 heap_free(lpRegistryPath);
5348 return hr;
5351 static HRESULT get_known_folder_path_by_id(REFKNOWNFOLDERID folderId, LPWSTR lpRegistryPath, DWORD dwFlags, LPWSTR *ppszPath);
5353 static HRESULT redirect_known_folder(
5354 REFKNOWNFOLDERID rfid,
5355 HWND hwnd,
5356 KF_REDIRECT_FLAGS flags,
5357 LPCWSTR pszTargetPath,
5358 UINT cFolders,
5359 KNOWNFOLDERID const *pExclusion,
5360 LPWSTR *ppszError)
5362 HRESULT hr;
5363 HKEY rootKey = HKEY_LOCAL_MACHINE, hKey;
5364 WCHAR sGuid[39];
5365 LPWSTR lpRegistryPath = NULL, lpSrcPath = NULL;
5366 TRACE("(%s, %p, 0x%08x, %s, %d, %p, %p)\n", debugstr_guid(rfid), hwnd, flags, debugstr_w(pszTargetPath), cFolders, pExclusion, ppszError);
5368 if (ppszError) *ppszError = NULL;
5370 hr = get_known_folder_registry_path(rfid, NULL, &lpRegistryPath);
5372 if(SUCCEEDED(hr))
5373 hr = get_known_folder_path_by_id(rfid, lpRegistryPath, 0, &lpSrcPath);
5375 heap_free(lpRegistryPath);
5377 /* get path to redirection storage */
5378 if(SUCCEEDED(hr))
5379 hr = get_known_folder_redirection_place(rfid, &rootKey);
5381 /* write redirection information */
5382 if(SUCCEEDED(hr))
5383 hr = HRESULT_FROM_WIN32(RegCreateKeyExW(rootKey, szKnownFolderRedirections, 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL));
5385 if(SUCCEEDED(hr))
5387 StringFromGUID2(rfid, sGuid, ARRAY_SIZE(sGuid));
5389 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, sGuid, 0, REG_SZ, (LPBYTE)pszTargetPath, (lstrlenW(pszTargetPath)+1)*sizeof(WCHAR)));
5391 RegCloseKey(hKey);
5394 /* make sure destination path exists */
5395 SHCreateDirectory(NULL, pszTargetPath);
5397 /* copy content if required */
5398 if(SUCCEEDED(hr) && (flags & KF_REDIRECT_COPY_CONTENTS) )
5400 static const WCHAR sWildcard[] = {'\\','*',0};
5401 WCHAR srcPath[MAX_PATH+1], dstPath[MAX_PATH+1];
5402 SHFILEOPSTRUCTW fileOp;
5404 ZeroMemory(srcPath, sizeof(srcPath));
5405 lstrcpyW(srcPath, lpSrcPath);
5406 lstrcatW(srcPath, sWildcard);
5408 ZeroMemory(dstPath, sizeof(dstPath));
5409 lstrcpyW(dstPath, pszTargetPath);
5411 ZeroMemory(&fileOp, sizeof(fileOp));
5413 if(flags & KF_REDIRECT_DEL_SOURCE_CONTENTS)
5414 fileOp.wFunc = FO_MOVE;
5415 else
5416 fileOp.wFunc = FO_COPY;
5418 fileOp.pFrom = srcPath;
5419 fileOp.pTo = dstPath;
5420 fileOp.fFlags = FOF_NO_UI;
5422 hr = (SHFileOperationW(&fileOp)==0 ? S_OK : E_FAIL);
5424 if(flags & KF_REDIRECT_DEL_SOURCE_CONTENTS)
5426 ZeroMemory(srcPath, sizeof(srcPath));
5427 lstrcpyW(srcPath, lpSrcPath);
5429 ZeroMemory(&fileOp, sizeof(fileOp));
5430 fileOp.wFunc = FO_DELETE;
5431 fileOp.pFrom = srcPath;
5432 fileOp.fFlags = FOF_NO_UI;
5434 hr = (SHFileOperationW(&fileOp)==0 ? S_OK : E_FAIL);
5438 CoTaskMemFree(lpSrcPath);
5440 return hr;
5444 struct knownfolder
5446 IKnownFolder IKnownFolder_iface;
5447 LONG refs;
5448 KNOWNFOLDERID id;
5449 LPWSTR registryPath;
5452 static inline struct knownfolder *impl_from_IKnownFolder( IKnownFolder *iface )
5454 return CONTAINING_RECORD( iface, struct knownfolder, IKnownFolder_iface );
5457 static ULONG WINAPI knownfolder_AddRef(
5458 IKnownFolder *iface )
5460 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
5461 return InterlockedIncrement( &knownfolder->refs );
5464 static ULONG WINAPI knownfolder_Release(
5465 IKnownFolder *iface )
5467 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
5468 LONG refs = InterlockedDecrement( &knownfolder->refs );
5469 if (!refs)
5471 TRACE("destroying %p\n", knownfolder);
5472 heap_free( knownfolder->registryPath );
5473 heap_free( knownfolder );
5475 return refs;
5478 static HRESULT WINAPI knownfolder_QueryInterface(
5479 IKnownFolder *iface,
5480 REFIID riid,
5481 void **ppv )
5483 struct knownfolder *This = impl_from_IKnownFolder( iface );
5485 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppv );
5487 *ppv = NULL;
5488 if ( IsEqualGUID( riid, &IID_IKnownFolder ) ||
5489 IsEqualGUID( riid, &IID_IUnknown ) )
5491 *ppv = iface;
5493 else if ( IsEqualGUID( riid, &IID_IMarshal ) )
5495 TRACE("IID_IMarshal returning NULL.\n");
5496 return E_NOINTERFACE;
5498 else
5500 FIXME("interface %s not implemented\n", debugstr_guid(riid));
5501 return E_NOINTERFACE;
5503 IKnownFolder_AddRef( iface );
5504 return S_OK;
5507 static HRESULT knownfolder_set_id(
5508 struct knownfolder *knownfolder,
5509 const KNOWNFOLDERID *kfid)
5511 HKEY hKey;
5512 HRESULT hr;
5514 TRACE("%s\n", debugstr_guid(kfid));
5516 knownfolder->id = *kfid;
5518 /* check is it registry-registered folder */
5519 hr = get_known_folder_registry_path(kfid, NULL, &knownfolder->registryPath);
5520 if(SUCCEEDED(hr))
5521 hr = HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_LOCAL_MACHINE, knownfolder->registryPath, 0, 0, &hKey));
5523 if(SUCCEEDED(hr))
5525 hr = S_OK;
5526 RegCloseKey(hKey);
5528 else
5530 /* This known folder is not registered. To mark it, we set registryPath to NULL */
5531 heap_free(knownfolder->registryPath);
5532 knownfolder->registryPath = NULL;
5533 hr = S_OK;
5536 return hr;
5539 static HRESULT WINAPI knownfolder_GetId(
5540 IKnownFolder *iface,
5541 KNOWNFOLDERID *pkfid)
5543 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
5545 TRACE("%p\n", pkfid);
5547 *pkfid = knownfolder->id;
5548 return S_OK;
5551 static HRESULT WINAPI knownfolder_GetCategory(
5552 IKnownFolder *iface,
5553 KF_CATEGORY *pCategory)
5555 struct knownfolder *knownfolder = impl_from_IKnownFolder(iface);
5556 HRESULT hr = S_OK;
5558 TRACE("%p, %p\n", knownfolder, pCategory);
5560 /* we cannot get a category for a folder which is not registered */
5561 if(!knownfolder->registryPath)
5562 hr = E_FAIL;
5564 if(SUCCEEDED(hr))
5565 hr = get_known_folder_dword(knownfolder->registryPath, szCategory, pCategory);
5567 return hr;
5570 static HRESULT WINAPI knownfolder_GetShellItem(
5571 IKnownFolder *iface,
5572 DWORD flags,
5573 REFIID riid,
5574 void **ppv)
5576 struct knownfolder *knownfolder = impl_from_IKnownFolder(iface);
5577 TRACE("(%p, 0x%08x, %s, %p)\n", knownfolder, flags, debugstr_guid(riid), ppv);
5578 return SHGetKnownFolderItem(&knownfolder->id, flags, NULL, riid, ppv);
5581 static HRESULT get_known_folder_path(
5582 LPWSTR sFolderId,
5583 LPWSTR registryPath,
5584 LPWSTR *ppszPath)
5586 static const WCHAR sBackslash[] = {'\\',0};
5587 HRESULT hr;
5588 DWORD dwSize, dwType;
5589 WCHAR path[MAX_PATH] = {0};
5590 WCHAR parentGuid[39];
5591 KF_CATEGORY category;
5592 LPWSTR parentRegistryPath, parentPath;
5593 HKEY hRedirectionRootKey = NULL;
5595 TRACE("(%s, %p)\n", debugstr_w(registryPath), ppszPath);
5596 *ppszPath = NULL;
5598 /* check if folder has parent */
5599 dwSize = sizeof(parentGuid);
5600 hr = HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, registryPath, szParentFolder, RRF_RT_REG_SZ, &dwType, parentGuid, &dwSize));
5601 if(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) hr = S_FALSE;
5603 if(hr == S_OK)
5605 /* get parent's known folder path (recursive) */
5606 hr = get_known_folder_registry_path(NULL, parentGuid, &parentRegistryPath);
5607 if(FAILED(hr)) return hr;
5609 hr = get_known_folder_path(parentGuid, parentRegistryPath, &parentPath);
5610 if(FAILED(hr)) {
5611 heap_free(parentRegistryPath);
5612 return hr;
5615 lstrcatW(path, parentPath);
5616 lstrcatW(path, sBackslash);
5618 heap_free(parentRegistryPath);
5619 heap_free(parentPath);
5622 /* check, if folder was redirected */
5623 if(SUCCEEDED(hr))
5624 hr = get_known_folder_dword(registryPath, szCategory, &category);
5626 if(SUCCEEDED(hr))
5628 if(category == KF_CATEGORY_COMMON)
5629 hRedirectionRootKey = HKEY_LOCAL_MACHINE;
5630 else if(category == KF_CATEGORY_PERUSER)
5631 hRedirectionRootKey = HKEY_CURRENT_USER;
5633 if(hRedirectionRootKey)
5635 hr = HRESULT_FROM_WIN32(RegGetValueW(hRedirectionRootKey, szKnownFolderRedirections, sFolderId, RRF_RT_REG_SZ, NULL, NULL, &dwSize));
5637 if(SUCCEEDED(hr))
5639 *ppszPath = CoTaskMemAlloc(dwSize+(lstrlenW(path)+1)*sizeof(WCHAR));
5640 if(!*ppszPath) hr = E_OUTOFMEMORY;
5643 if(SUCCEEDED(hr))
5645 lstrcpyW(*ppszPath, path);
5646 hr = HRESULT_FROM_WIN32(RegGetValueW(hRedirectionRootKey, szKnownFolderRedirections, sFolderId, RRF_RT_REG_SZ, NULL, *ppszPath + lstrlenW(path), &dwSize));
5650 if(!*ppszPath)
5652 /* no redirection, use previous way - read the relative path from folder definition */
5653 hr = HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, registryPath, szRelativePath, RRF_RT_REG_SZ, &dwType, NULL, &dwSize));
5655 if(SUCCEEDED(hr))
5657 *ppszPath = CoTaskMemAlloc(dwSize+(lstrlenW(path)+1)*sizeof(WCHAR));
5658 if(!*ppszPath) hr = E_OUTOFMEMORY;
5661 if(SUCCEEDED(hr))
5663 lstrcpyW(*ppszPath, path);
5664 hr = HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, registryPath, szRelativePath, RRF_RT_REG_SZ, &dwType, *ppszPath + lstrlenW(path), &dwSize));
5669 TRACE("returning path: %s\n", debugstr_w(*ppszPath));
5670 return hr;
5673 static HRESULT get_known_folder_path_by_id(
5674 REFKNOWNFOLDERID folderId,
5675 LPWSTR lpRegistryPath,
5676 DWORD dwFlags,
5677 LPWSTR *ppszPath)
5679 HRESULT hr = E_FAIL;
5680 WCHAR sGuid[39];
5681 DWORD dwAttributes;
5683 TRACE("(%s, %s, 0x%08x, %p)\n", debugstr_guid(folderId), debugstr_w(lpRegistryPath), dwFlags, ppszPath);
5685 /* if this is registry-registered known folder, get path from registry */
5686 if(lpRegistryPath)
5688 StringFromGUID2(folderId, sGuid, ARRAY_SIZE(sGuid));
5690 hr = get_known_folder_path(sGuid, lpRegistryPath, ppszPath);
5692 /* in other case, use older way */
5694 if(FAILED(hr))
5695 hr = SHGetKnownFolderPath( folderId, dwFlags, NULL, ppszPath );
5697 if (FAILED(hr)) return hr;
5699 /* check if known folder really exists */
5700 dwAttributes = GetFileAttributesW(*ppszPath);
5701 if(dwAttributes == INVALID_FILE_ATTRIBUTES || !(dwAttributes & FILE_ATTRIBUTE_DIRECTORY) )
5703 TRACE("directory %s not found\n", debugstr_w(*ppszPath));
5704 CoTaskMemFree(*ppszPath);
5705 *ppszPath = NULL;
5706 hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
5709 return hr;
5712 static HRESULT WINAPI knownfolder_GetPath(
5713 IKnownFolder *iface,
5714 DWORD dwFlags,
5715 LPWSTR *ppszPath)
5717 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
5718 TRACE("(%p, 0x%08x, %p)\n", knownfolder, dwFlags, ppszPath);
5720 return get_known_folder_path_by_id(&knownfolder->id, knownfolder->registryPath, dwFlags, ppszPath);
5723 static HRESULT WINAPI knownfolder_SetPath(
5724 IKnownFolder *iface,
5725 DWORD dwFlags,
5726 LPCWSTR pszPath)
5728 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
5729 HRESULT hr = S_OK;
5731 TRACE("(%p, 0x%08x, %s)\n", knownfolder, dwFlags, debugstr_w(pszPath));
5733 /* check if the known folder is registered */
5734 if(!knownfolder->registryPath)
5735 hr = E_FAIL;
5737 if(SUCCEEDED(hr))
5738 hr = redirect_known_folder(&knownfolder->id, NULL, 0, pszPath, 0, NULL, NULL);
5740 return hr;
5743 static HRESULT WINAPI knownfolder_GetIDList(
5744 IKnownFolder *iface,
5745 DWORD flags,
5746 PIDLIST_ABSOLUTE *ppidl)
5748 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
5749 TRACE("(%p, 0x%08x, %p)\n", knownfolder, flags, ppidl);
5750 return SHGetKnownFolderIDList(&knownfolder->id, flags, NULL, ppidl);
5753 static HRESULT WINAPI knownfolder_GetFolderType(
5754 IKnownFolder *iface,
5755 FOLDERTYPEID *pftid)
5757 FIXME("%p\n", pftid);
5758 return E_NOTIMPL;
5761 static HRESULT WINAPI knownfolder_GetRedirectionCapabilities(
5762 IKnownFolder *iface,
5763 KF_REDIRECTION_CAPABILITIES *pCapabilities)
5765 FIXME("%p stub\n", pCapabilities);
5766 if(!pCapabilities) return E_INVALIDARG;
5767 *pCapabilities = KF_REDIRECTION_CAPABILITIES_DENY_ALL;
5768 return S_OK;
5771 static HRESULT WINAPI knownfolder_GetFolderDefinition(
5772 IKnownFolder *iface,
5773 KNOWNFOLDER_DEFINITION *pKFD)
5775 struct knownfolder *knownfolder = impl_from_IKnownFolder( iface );
5776 HRESULT hr;
5777 DWORD dwSize;
5778 WCHAR parentGuid[39];
5779 TRACE("(%p, %p)\n", knownfolder, pKFD);
5781 if(!pKFD) return E_INVALIDARG;
5783 ZeroMemory(pKFD, sizeof(*pKFD));
5785 /* required fields */
5786 hr = get_known_folder_dword(knownfolder->registryPath, szCategory, &pKFD->category);
5787 if(FAILED(hr))
5788 return hr;
5790 hr = get_known_folder_wstr(knownfolder->registryPath, szName, &pKFD->pszName);
5791 if(FAILED(hr))
5792 return hr;
5794 /* optional fields */
5795 dwSize = sizeof(parentGuid);
5796 hr = HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE, knownfolder->registryPath, szParentFolder,
5797 RRF_RT_REG_SZ, NULL, parentGuid, &dwSize));
5798 if(SUCCEEDED(hr))
5800 hr = IIDFromString(parentGuid, &pKFD->fidParent);
5801 if(FAILED(hr))
5802 return hr;
5805 get_known_folder_dword(knownfolder->registryPath, szAttributes, &pKFD->dwAttributes);
5807 get_known_folder_wstr(knownfolder->registryPath, szRelativePath, &pKFD->pszRelativePath);
5809 get_known_folder_wstr(knownfolder->registryPath, szParsingName, &pKFD->pszParsingName);
5811 return S_OK;
5814 static const struct IKnownFolderVtbl knownfolder_vtbl =
5816 knownfolder_QueryInterface,
5817 knownfolder_AddRef,
5818 knownfolder_Release,
5819 knownfolder_GetId,
5820 knownfolder_GetCategory,
5821 knownfolder_GetShellItem,
5822 knownfolder_GetPath,
5823 knownfolder_SetPath,
5824 knownfolder_GetIDList,
5825 knownfolder_GetFolderType,
5826 knownfolder_GetRedirectionCapabilities,
5827 knownfolder_GetFolderDefinition
5830 static HRESULT knownfolder_create( struct knownfolder **knownfolder )
5832 struct knownfolder *kf;
5834 kf = heap_alloc( sizeof(*kf) );
5835 if (!kf) return E_OUTOFMEMORY;
5837 kf->IKnownFolder_iface.lpVtbl = &knownfolder_vtbl;
5838 kf->refs = 1;
5839 memset( &kf->id, 0, sizeof(kf->id) );
5840 kf->registryPath = NULL;
5842 *knownfolder = kf;
5844 TRACE("returning iface %p\n", &kf->IKnownFolder_iface);
5845 return S_OK;
5848 struct foldermanager
5850 IKnownFolderManager IKnownFolderManager_iface;
5851 LONG refs;
5852 UINT num_ids;
5853 KNOWNFOLDERID *ids;
5856 static inline struct foldermanager *impl_from_IKnownFolderManager( IKnownFolderManager *iface )
5858 return CONTAINING_RECORD( iface, struct foldermanager, IKnownFolderManager_iface );
5861 static ULONG WINAPI foldermanager_AddRef(
5862 IKnownFolderManager *iface )
5864 struct foldermanager *foldermanager = impl_from_IKnownFolderManager( iface );
5865 return InterlockedIncrement( &foldermanager->refs );
5868 static ULONG WINAPI foldermanager_Release(
5869 IKnownFolderManager *iface )
5871 struct foldermanager *foldermanager = impl_from_IKnownFolderManager( iface );
5872 LONG refs = InterlockedDecrement( &foldermanager->refs );
5873 if (!refs)
5875 TRACE("destroying %p\n", foldermanager);
5876 heap_free( foldermanager->ids );
5877 heap_free( foldermanager );
5879 return refs;
5882 static HRESULT WINAPI foldermanager_QueryInterface(
5883 IKnownFolderManager *iface,
5884 REFIID riid,
5885 void **ppv )
5887 struct foldermanager *This = impl_from_IKnownFolderManager( iface );
5889 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppv );
5891 *ppv = NULL;
5892 if ( IsEqualGUID( riid, &IID_IKnownFolderManager ) ||
5893 IsEqualGUID( riid, &IID_IUnknown ) )
5895 *ppv = iface;
5897 else if ( IsEqualGUID( riid, &IID_IMarshal ) )
5899 TRACE("IID_IMarshal returning NULL.\n");
5900 return E_NOINTERFACE;
5902 else
5904 FIXME("interface %s not implemented\n", debugstr_guid(riid));
5905 return E_NOINTERFACE;
5907 IKnownFolderManager_AddRef( iface );
5908 return S_OK;
5911 static HRESULT WINAPI foldermanager_FolderIdFromCsidl(
5912 IKnownFolderManager *iface,
5913 int nCsidl,
5914 KNOWNFOLDERID *pfid)
5916 TRACE("%d, %p\n", nCsidl, pfid);
5918 if (nCsidl >= ARRAY_SIZE(CSIDL_Data))
5919 return E_INVALIDARG;
5920 *pfid = *CSIDL_Data[nCsidl].id;
5921 return S_OK;
5924 static HRESULT WINAPI foldermanager_FolderIdToCsidl(
5925 IKnownFolderManager *iface,
5926 REFKNOWNFOLDERID rfid,
5927 int *pnCsidl)
5929 int csidl;
5931 TRACE("%s, %p\n", debugstr_guid(rfid), pnCsidl);
5933 csidl = csidl_from_id( rfid );
5934 if (csidl == -1) return E_INVALIDARG;
5935 *pnCsidl = csidl;
5936 return S_OK;
5939 static HRESULT WINAPI foldermanager_GetFolderIds(
5940 IKnownFolderManager *iface,
5941 KNOWNFOLDERID **ppKFId,
5942 UINT *pCount)
5944 struct foldermanager *fm = impl_from_IKnownFolderManager( iface );
5946 TRACE("%p, %p\n", ppKFId, pCount);
5948 *ppKFId = CoTaskMemAlloc(fm->num_ids * sizeof(KNOWNFOLDERID));
5949 memcpy(*ppKFId, fm->ids, fm->num_ids * sizeof(KNOWNFOLDERID));
5950 *pCount = fm->num_ids;
5951 return S_OK;
5954 static BOOL is_knownfolder( struct foldermanager *fm, const KNOWNFOLDERID *id )
5956 UINT i;
5957 HRESULT hr;
5958 LPWSTR registryPath = NULL;
5959 HKEY hKey;
5961 /* TODO: move all entries from "CSIDL_Data" static array to registry known folder descriptions */
5962 for (i = 0; i < fm->num_ids; i++)
5963 if (IsEqualGUID( &fm->ids[i], id )) return TRUE;
5965 hr = get_known_folder_registry_path(id, NULL, &registryPath);
5966 if(SUCCEEDED(hr))
5968 hr = HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_LOCAL_MACHINE, registryPath, 0, 0, &hKey));
5969 heap_free(registryPath);
5972 if(SUCCEEDED(hr))
5974 hr = S_OK;
5975 RegCloseKey(hKey);
5978 return hr == S_OK;
5981 static HRESULT WINAPI foldermanager_GetFolder(
5982 IKnownFolderManager *iface,
5983 REFKNOWNFOLDERID rfid,
5984 IKnownFolder **ppkf)
5986 struct foldermanager *fm = impl_from_IKnownFolderManager( iface );
5987 struct knownfolder *kf;
5988 HRESULT hr;
5990 TRACE("%s, %p\n", debugstr_guid(rfid), ppkf);
5992 if (!is_knownfolder( fm, rfid ))
5994 WARN("unknown folder\n");
5995 return E_INVALIDARG;
5997 hr = knownfolder_create( &kf );
5998 if (SUCCEEDED( hr ))
6000 hr = knownfolder_set_id( kf, rfid );
6001 *ppkf = &kf->IKnownFolder_iface;
6003 else
6004 *ppkf = NULL;
6006 return hr;
6009 static HRESULT WINAPI foldermanager_GetFolderByName(
6010 IKnownFolderManager *iface,
6011 LPCWSTR pszCanonicalName,
6012 IKnownFolder **ppkf)
6014 struct foldermanager *fm = impl_from_IKnownFolderManager( iface );
6015 struct knownfolder *kf;
6016 BOOL found = FALSE;
6017 HRESULT hr;
6018 UINT i;
6020 TRACE( "%s, %p\n", debugstr_w(pszCanonicalName), ppkf );
6022 for (i = 0; i < fm->num_ids; i++)
6024 WCHAR *path, *name;
6025 hr = get_known_folder_registry_path( &fm->ids[i], NULL, &path );
6026 if (FAILED( hr )) return hr;
6028 hr = get_known_folder_wstr( path, szName, &name );
6029 heap_free( path );
6030 if (FAILED( hr )) return hr;
6032 found = !strcmpiW( pszCanonicalName, name );
6033 CoTaskMemFree( name );
6034 if (found) break;
6037 if (found)
6039 hr = knownfolder_create( &kf );
6040 if (FAILED( hr )) return hr;
6042 hr = knownfolder_set_id( kf, &fm->ids[i] );
6043 if (FAILED( hr ))
6045 IKnownFolder_Release( &kf->IKnownFolder_iface );
6046 return hr;
6048 *ppkf = &kf->IKnownFolder_iface;
6050 else
6052 hr = HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND );
6053 *ppkf = NULL;
6056 return hr;
6059 static HRESULT register_folder(const KNOWNFOLDERID *rfid, const KNOWNFOLDER_DEFINITION *pKFD)
6061 HRESULT hr;
6062 HKEY hKey = NULL;
6063 DWORD dwDisp;
6064 LPWSTR registryPath = NULL;
6066 hr = get_known_folder_registry_path(rfid, NULL, &registryPath);
6067 TRACE("registry path: %s\n", debugstr_w(registryPath));
6069 if(SUCCEEDED(hr))
6070 hr = HRESULT_FROM_WIN32(RegCreateKeyExW(HKEY_LOCAL_MACHINE, registryPath, 0, NULL, 0, KEY_WRITE, 0, &hKey, &dwDisp));
6072 if(SUCCEEDED(hr))
6074 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, szCategory, 0, REG_DWORD, (LPBYTE)&pKFD->category, sizeof(pKFD->category)));
6076 if(SUCCEEDED(hr) && pKFD->dwAttributes != 0)
6077 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, szAttributes, 0, REG_DWORD, (LPBYTE)&pKFD->dwAttributes, sizeof(pKFD->dwAttributes)));
6079 if(SUCCEEDED(hr))
6080 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, szName, 0, REG_SZ, (LPBYTE)pKFD->pszName, (lstrlenW(pKFD->pszName)+1)*sizeof(WCHAR) ));
6082 if(SUCCEEDED(hr) && pKFD->pszParsingName)
6083 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, szParsingName, 0, REG_SZ, (LPBYTE)pKFD->pszParsingName, (lstrlenW(pKFD->pszParsingName)+1)*sizeof(WCHAR) ));
6085 if(SUCCEEDED(hr) && !IsEqualGUID(&pKFD->fidParent, &GUID_NULL))
6087 WCHAR sParentGuid[39];
6088 StringFromGUID2(&pKFD->fidParent, sParentGuid, ARRAY_SIZE(sParentGuid));
6090 /* this known folder has parent folder */
6091 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, szParentFolder, 0, REG_SZ, (LPBYTE)sParentGuid, sizeof(sParentGuid)));
6094 if(SUCCEEDED(hr) && pKFD->category != KF_CATEGORY_VIRTUAL && pKFD->pszRelativePath)
6095 hr = HRESULT_FROM_WIN32(RegSetValueExW(hKey, szRelativePath, 0, REG_SZ, (LPBYTE)pKFD->pszRelativePath, (lstrlenW(pKFD->pszRelativePath)+1)*sizeof(WCHAR) ));
6097 RegCloseKey(hKey);
6099 if(FAILED(hr))
6100 SHDeleteKeyW(HKEY_LOCAL_MACHINE, registryPath);
6103 heap_free(registryPath);
6104 return hr;
6107 static HRESULT WINAPI foldermanager_RegisterFolder(
6108 IKnownFolderManager *iface,
6109 REFKNOWNFOLDERID rfid,
6110 KNOWNFOLDER_DEFINITION const *pKFD)
6112 TRACE("(%p, %s, %p)\n", iface, debugstr_guid(rfid), pKFD);
6113 return register_folder(rfid, pKFD);
6116 static HRESULT WINAPI foldermanager_UnregisterFolder(
6117 IKnownFolderManager *iface,
6118 REFKNOWNFOLDERID rfid)
6120 HRESULT hr;
6121 LPWSTR registryPath = NULL;
6122 TRACE("(%p, %s)\n", iface, debugstr_guid(rfid));
6124 hr = get_known_folder_registry_path(rfid, NULL, &registryPath);
6126 if(SUCCEEDED(hr))
6127 hr = HRESULT_FROM_WIN32(SHDeleteKeyW(HKEY_LOCAL_MACHINE, registryPath));
6129 heap_free(registryPath);
6130 return hr;
6133 static HRESULT WINAPI foldermanager_FindFolderFromPath(
6134 IKnownFolderManager *iface,
6135 LPCWSTR pszPath,
6136 FFFP_MODE mode,
6137 IKnownFolder **ppkf)
6139 FIXME("%s, 0x%08x, %p\n", debugstr_w(pszPath), mode, ppkf);
6140 return E_NOTIMPL;
6143 static HRESULT WINAPI foldermanager_FindFolderFromIDList(
6144 IKnownFolderManager *iface,
6145 PCIDLIST_ABSOLUTE pidl,
6146 IKnownFolder **ppkf)
6148 FIXME("%p, %p\n", pidl, ppkf);
6149 return E_NOTIMPL;
6152 static HRESULT WINAPI foldermanager_Redirect(
6153 IKnownFolderManager *iface,
6154 REFKNOWNFOLDERID rfid,
6155 HWND hwnd,
6156 KF_REDIRECT_FLAGS flags,
6157 LPCWSTR pszTargetPath,
6158 UINT cFolders,
6159 KNOWNFOLDERID const *pExclusion,
6160 LPWSTR *ppszError)
6162 return redirect_known_folder(rfid, hwnd, flags, pszTargetPath, cFolders, pExclusion, ppszError);
6165 static const struct IKnownFolderManagerVtbl foldermanager_vtbl =
6167 foldermanager_QueryInterface,
6168 foldermanager_AddRef,
6169 foldermanager_Release,
6170 foldermanager_FolderIdFromCsidl,
6171 foldermanager_FolderIdToCsidl,
6172 foldermanager_GetFolderIds,
6173 foldermanager_GetFolder,
6174 foldermanager_GetFolderByName,
6175 foldermanager_RegisterFolder,
6176 foldermanager_UnregisterFolder,
6177 foldermanager_FindFolderFromPath,
6178 foldermanager_FindFolderFromIDList,
6179 foldermanager_Redirect
6182 static HRESULT foldermanager_create( void **ppv )
6184 UINT i, j;
6185 struct foldermanager *fm;
6187 fm = heap_alloc( sizeof(*fm) );
6188 if (!fm) return E_OUTOFMEMORY;
6190 fm->IKnownFolderManager_iface.lpVtbl = &foldermanager_vtbl;
6191 fm->refs = 1;
6192 fm->num_ids = 0;
6194 for (i = 0; i < ARRAY_SIZE(CSIDL_Data); i++)
6196 if (!IsEqualGUID( CSIDL_Data[i].id, &GUID_NULL )) fm->num_ids++;
6198 fm->ids = heap_alloc( fm->num_ids * sizeof(KNOWNFOLDERID) );
6199 if (!fm->ids)
6201 heap_free( fm );
6202 return E_OUTOFMEMORY;
6204 for (i = j = 0; i < ARRAY_SIZE(CSIDL_Data); i++)
6206 if (!IsEqualGUID( CSIDL_Data[i].id, &GUID_NULL ))
6208 fm->ids[j] = *CSIDL_Data[i].id;
6209 j++;
6212 TRACE("found %u known folders\n", fm->num_ids);
6213 *ppv = &fm->IKnownFolderManager_iface;
6215 TRACE("returning iface %p\n", *ppv);
6216 return S_OK;
6219 HRESULT WINAPI KnownFolderManager_Constructor( IUnknown *punk, REFIID riid, void **ppv )
6221 TRACE("%p, %s, %p\n", punk, debugstr_guid(riid), ppv);
6223 if (!ppv)
6224 return E_POINTER;
6225 if (punk)
6226 return CLASS_E_NOAGGREGATION;
6228 return foldermanager_create( ppv );
6231 HRESULT WINAPI SHGetKnownFolderIDList(REFKNOWNFOLDERID rfid, DWORD flags, HANDLE token, PIDLIST_ABSOLUTE *pidl)
6233 TRACE("%s, 0x%08x, %p, %p\n", debugstr_guid(rfid), flags, token, pidl);
6235 if (!pidl)
6236 return E_INVALIDARG;
6238 if (flags)
6239 FIXME("unsupported flags: 0x%08x\n", flags);
6241 if (token)
6242 FIXME("user token is not used.\n");
6244 *pidl = NULL;
6245 if (IsEqualIID(rfid, &FOLDERID_Desktop))
6246 *pidl = _ILCreateDesktop();
6247 else if (IsEqualIID(rfid, &FOLDERID_RecycleBinFolder))
6248 *pidl = _ILCreateBitBucket();
6249 else if (IsEqualIID(rfid, &FOLDERID_ComputerFolder))
6250 *pidl = _ILCreateMyComputer();
6251 else if (IsEqualIID(rfid, &FOLDERID_PrintersFolder))
6252 *pidl = _ILCreatePrinters();
6253 else if (IsEqualIID(rfid, &FOLDERID_ControlPanelFolder))
6254 *pidl = _ILCreateControlPanel();
6255 else if (IsEqualIID(rfid, &FOLDERID_NetworkFolder))
6256 *pidl = _ILCreateNetwork();
6257 else if (IsEqualIID(rfid, &FOLDERID_Documents))
6258 *pidl = _ILCreateMyDocuments();
6259 else
6261 DWORD attributes = 0;
6262 WCHAR *pathW;
6263 HRESULT hr;
6265 hr = SHGetKnownFolderPath(rfid, flags, token, &pathW);
6266 if (FAILED(hr))
6267 return hr;
6269 hr = SHILCreateFromPathW(pathW, pidl, &attributes);
6270 CoTaskMemFree(pathW);
6271 return hr;
6274 return *pidl ? S_OK : E_FAIL;
6277 HRESULT WINAPI SHGetKnownFolderItem(REFKNOWNFOLDERID rfid, KNOWN_FOLDER_FLAG flags, HANDLE hToken,
6278 REFIID riid, void **ppv)
6280 PIDLIST_ABSOLUTE pidl;
6281 HRESULT hr;
6283 TRACE("%s, 0x%08x, %p, %s, %p\n", debugstr_guid(rfid), flags, hToken, debugstr_guid(riid), ppv);
6285 hr = SHGetKnownFolderIDList(rfid, flags, hToken, &pidl);
6286 if (FAILED(hr))
6288 *ppv = NULL;
6289 return hr;
6292 hr = SHCreateItemFromIDList(pidl, riid, ppv);
6293 CoTaskMemFree(pidl);
6294 return hr;
6297 static void register_system_knownfolders(void)
6299 int i;
6301 for (i = 0; i < ARRAY_SIZE(CSIDL_Data); ++i)
6303 const CSIDL_DATA *folder = &CSIDL_Data[i];
6304 if(folder->pszName){
6305 KNOWNFOLDER_DEFINITION kfd;
6307 /* register_folder won't modify kfd, so cast away const instead of
6308 * reallocating */
6309 kfd.category = folder->category;
6310 kfd.pszName = (WCHAR*)folder->pszName;
6311 kfd.pszDescription = (WCHAR*)folder->pszDescription;
6312 memcpy(&kfd.fidParent, folder->fidParent, sizeof(KNOWNFOLDERID));
6313 kfd.pszRelativePath = (WCHAR*)folder->pszRelativePath;
6314 kfd.pszParsingName = (WCHAR*)folder->pszParsingName;
6315 kfd.pszTooltip = (WCHAR*)folder->pszTooltip;
6316 kfd.pszLocalizedName = (WCHAR*)folder->pszLocalizedName;
6317 kfd.pszIcon = (WCHAR*)folder->pszIcon;
6318 kfd.pszSecurity = (WCHAR*)folder->pszSecurity;
6319 kfd.dwAttributes = folder->dwAttributes;
6320 kfd.kfdFlags = folder->kfdFlags;
6321 memcpy(&kfd.ftidType, folder->ftidType, sizeof(FOLDERTYPEID));
6323 register_folder(folder->id, &kfd);
6328 HRESULT SHELL_RegisterShellFolders(void)
6330 HRESULT hr;
6332 /* Set up '$HOME' targeted symlinks for 'My Documents', 'My Pictures',
6333 * 'My Videos', 'My Music', 'Desktop' etc. in advance, so that the
6334 * _SHRegister*ShellFolders() functions will find everything nice and clean
6335 * and thus will not attempt to create them in the profile directory. */
6336 _SHCreateSymbolicLinks();
6338 hr = _SHRegisterUserShellFolders(TRUE);
6339 if (SUCCEEDED(hr))
6340 hr = _SHRegisterUserShellFolders(FALSE);
6341 if (SUCCEEDED(hr))
6342 hr = _SHRegisterCommonShellFolders();
6343 if (SUCCEEDED(hr))
6344 hr = create_extra_folders();
6345 if (SUCCEEDED(hr))
6346 hr = set_folder_attributes();
6347 if (SUCCEEDED(hr))
6348 register_system_knownfolders();
6349 return hr;