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
23 * Many of these functions are in SHLWAPI.DLL also
42 #define WINE_MOUNTMGR_EXTENSIONS
43 #include "ddk/mountmgr.h"
48 #include "shell32_main.h"
52 #include "knownfolders.h"
55 #include "wine/debug.h"
57 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
59 static const BOOL is_win64
= sizeof(void *) > sizeof(int);
62 ########## Combining and Constructing paths ##########
65 /*************************************************************************
66 * PathAppend [SHELL32.36]
68 BOOL WINAPI
PathAppendAW(
72 if (SHELL_OsIsUnicode())
73 return PathAppendW(lpszPath1
, lpszPath2
);
74 return PathAppendA(lpszPath1
, lpszPath2
);
77 /*************************************************************************
78 * PathCombine [SHELL32.37]
80 LPVOID WINAPI
PathCombineAW(
85 if (SHELL_OsIsUnicode())
86 return PathCombineW( szDest
, lpszDir
, lpszFile
);
87 return PathCombineA( szDest
, lpszDir
, lpszFile
);
90 /*************************************************************************
91 * PathAddBackslash [SHELL32.32]
93 LPVOID WINAPI
PathAddBackslashAW(LPVOID lpszPath
)
95 if(SHELL_OsIsUnicode())
96 return PathAddBackslashW(lpszPath
);
97 return PathAddBackslashA(lpszPath
);
100 /*************************************************************************
101 * PathBuildRoot [SHELL32.30]
103 LPVOID WINAPI
PathBuildRootAW(LPVOID lpszPath
, int drive
)
105 if(SHELL_OsIsUnicode())
106 return PathBuildRootW(lpszPath
, drive
);
107 return PathBuildRootA(lpszPath
, drive
);
111 Extracting Component Parts
114 /*************************************************************************
115 * PathFindFileName [SHELL32.34]
117 LPVOID WINAPI
PathFindFileNameAW(LPCVOID lpszPath
)
119 if(SHELL_OsIsUnicode())
120 return PathFindFileNameW(lpszPath
);
121 return PathFindFileNameA(lpszPath
);
124 /*************************************************************************
125 * PathFindExtension [SHELL32.31]
127 LPVOID WINAPI
PathFindExtensionAW(LPCVOID lpszPath
)
129 if (SHELL_OsIsUnicode())
130 return PathFindExtensionW(lpszPath
);
131 return PathFindExtensionA(lpszPath
);
135 /*************************************************************************
136 * PathGetExtensionA [internal]
139 * exported by ordinal
140 * return value points to the first char after the dot
142 static LPSTR
PathGetExtensionA(LPCSTR lpszPath
)
144 TRACE("(%s)\n",lpszPath
);
146 lpszPath
= PathFindExtensionA(lpszPath
);
147 return (LPSTR
)(*lpszPath
?(lpszPath
+1):lpszPath
);
150 /*************************************************************************
151 * PathGetExtensionW [internal]
153 static LPWSTR
PathGetExtensionW(LPCWSTR lpszPath
)
155 TRACE("(%s)\n",debugstr_w(lpszPath
));
157 lpszPath
= PathFindExtensionW(lpszPath
);
158 return (LPWSTR
)(*lpszPath
?(lpszPath
+1):lpszPath
);
161 /*************************************************************************
162 * PathGetExtension [SHELL32.158]
164 LPVOID WINAPI
PathGetExtensionAW(LPCVOID lpszPath
,DWORD void1
, DWORD void2
)
166 if (SHELL_OsIsUnicode())
167 return PathGetExtensionW(lpszPath
);
168 return PathGetExtensionA(lpszPath
);
171 /*************************************************************************
172 * PathGetArgs [SHELL32.52]
174 LPVOID WINAPI
PathGetArgsAW(LPVOID lpszPath
)
176 if (SHELL_OsIsUnicode())
177 return PathGetArgsW(lpszPath
);
178 return PathGetArgsA(lpszPath
);
181 /*************************************************************************
182 * PathGetDriveNumber [SHELL32.57]
184 int WINAPI
PathGetDriveNumberAW(LPVOID lpszPath
)
186 if (SHELL_OsIsUnicode())
187 return PathGetDriveNumberW(lpszPath
);
188 return PathGetDriveNumberA(lpszPath
);
191 /*************************************************************************
192 * PathRemoveFileSpec [SHELL32.35]
194 BOOL WINAPI
PathRemoveFileSpecAW(LPVOID lpszPath
)
196 if (SHELL_OsIsUnicode())
197 return PathRemoveFileSpecW(lpszPath
);
198 return PathRemoveFileSpecA(lpszPath
);
201 /*************************************************************************
202 * PathStripPath [SHELL32.38]
204 void WINAPI
PathStripPathAW(LPVOID lpszPath
)
206 if (SHELL_OsIsUnicode())
207 PathStripPathW(lpszPath
);
209 PathStripPathA(lpszPath
);
212 /*************************************************************************
213 * PathStripToRoot [SHELL32.50]
215 BOOL WINAPI
PathStripToRootAW(LPVOID lpszPath
)
217 if (SHELL_OsIsUnicode())
218 return PathStripToRootW(lpszPath
);
219 return PathStripToRootA(lpszPath
);
222 /*************************************************************************
223 * PathRemoveArgs [SHELL32.251]
225 void WINAPI
PathRemoveArgsAW(LPVOID lpszPath
)
227 if (SHELL_OsIsUnicode())
228 PathRemoveArgsW(lpszPath
);
230 PathRemoveArgsA(lpszPath
);
233 /*************************************************************************
234 * PathRemoveExtension [SHELL32.250]
236 void WINAPI
PathRemoveExtensionAW(LPVOID lpszPath
)
238 if (SHELL_OsIsUnicode())
239 PathRemoveExtensionW(lpszPath
);
241 PathRemoveExtensionA(lpszPath
);
249 /*************************************************************************
250 * PathGetShortPathA [internal]
252 static void PathGetShortPathA(LPSTR pszPath
)
256 TRACE("%s\n", pszPath
);
258 if (GetShortPathNameA(pszPath
, path
, MAX_PATH
))
260 lstrcpyA(pszPath
, path
);
264 /*************************************************************************
265 * PathGetShortPathW [internal]
267 static void PathGetShortPathW(LPWSTR pszPath
)
269 WCHAR path
[MAX_PATH
];
271 TRACE("%s\n", debugstr_w(pszPath
));
273 if (GetShortPathNameW(pszPath
, path
, MAX_PATH
))
275 lstrcpyW(pszPath
, path
);
279 /*************************************************************************
280 * PathGetShortPath [SHELL32.92]
282 VOID WINAPI
PathGetShortPathAW(LPVOID pszPath
)
284 if(SHELL_OsIsUnicode())
285 PathGetShortPathW(pszPath
);
286 PathGetShortPathA(pszPath
);
289 /*************************************************************************
290 * PathRemoveBlanks [SHELL32.33]
292 void WINAPI
PathRemoveBlanksAW(LPVOID str
)
294 if(SHELL_OsIsUnicode())
295 PathRemoveBlanksW(str
);
297 PathRemoveBlanksA(str
);
300 /*************************************************************************
301 * PathQuoteSpaces [SHELL32.55]
303 VOID WINAPI
PathQuoteSpacesAW (LPVOID lpszPath
)
305 if(SHELL_OsIsUnicode())
306 PathQuoteSpacesW(lpszPath
);
308 PathQuoteSpacesA(lpszPath
);
311 /*************************************************************************
312 * PathUnquoteSpaces [SHELL32.56]
314 VOID WINAPI
PathUnquoteSpacesAW(LPVOID str
)
316 if(SHELL_OsIsUnicode())
317 PathUnquoteSpacesW(str
);
319 PathUnquoteSpacesA(str
);
322 /*************************************************************************
323 * PathParseIconLocation [SHELL32.249]
325 int WINAPI
PathParseIconLocationAW (LPVOID lpszPath
)
327 if(SHELL_OsIsUnicode())
328 return PathParseIconLocationW(lpszPath
);
329 return PathParseIconLocationA(lpszPath
);
333 ########## Path Testing ##########
335 /*************************************************************************
336 * PathIsUNC [SHELL32.39]
338 BOOL WINAPI
PathIsUNCAW (LPCVOID lpszPath
)
340 if (SHELL_OsIsUnicode())
341 return PathIsUNCW( lpszPath
);
342 return PathIsUNCA( lpszPath
);
345 /*************************************************************************
346 * PathIsRelative [SHELL32.40]
348 BOOL WINAPI
PathIsRelativeAW (LPCVOID lpszPath
)
350 if (SHELL_OsIsUnicode())
351 return PathIsRelativeW( lpszPath
);
352 return PathIsRelativeA( lpszPath
);
355 /*************************************************************************
356 * PathIsRoot [SHELL32.29]
358 BOOL WINAPI
PathIsRootAW(LPCVOID lpszPath
)
360 if (SHELL_OsIsUnicode())
361 return PathIsRootW(lpszPath
);
362 return PathIsRootA(lpszPath
);
365 /*************************************************************************
366 * PathIsExeA [internal]
368 static BOOL
PathIsExeA (LPCSTR lpszPath
)
370 LPCSTR lpszExtension
= PathGetExtensionA(lpszPath
);
372 static const char * const lpszExtensions
[] =
373 {"exe", "com", "pif", "cmd", "bat", "scf", "scr", NULL
};
375 TRACE("path=%s\n",lpszPath
);
377 for(i
=0; lpszExtensions
[i
]; i
++)
378 if (!lstrcmpiA(lpszExtension
,lpszExtensions
[i
])) return TRUE
;
383 /*************************************************************************
384 * PathIsExeW [internal]
386 static BOOL
PathIsExeW (LPCWSTR lpszPath
)
388 LPCWSTR lpszExtension
= PathGetExtensionW(lpszPath
);
390 static const WCHAR lpszExtensions
[][4] =
391 {L
"exe", L
"com", L
"pif",L
"cmd", L
"bat", L
"scf",L
"scr",L
"" };
393 TRACE("path=%s\n",debugstr_w(lpszPath
));
395 for(i
=0; lpszExtensions
[i
][0]; i
++)
396 if (!wcsicmp(lpszExtension
,lpszExtensions
[i
])) return TRUE
;
401 /*************************************************************************
402 * PathIsExe [SHELL32.43]
404 BOOL WINAPI
PathIsExeAW (LPCVOID path
)
406 if (SHELL_OsIsUnicode())
407 return PathIsExeW (path
);
408 return PathIsExeA(path
);
411 /*************************************************************************
412 * PathIsDirectory [SHELL32.159]
414 BOOL WINAPI
PathIsDirectoryAW (LPCVOID lpszPath
)
416 if (SHELL_OsIsUnicode())
417 return PathIsDirectoryW (lpszPath
);
418 return PathIsDirectoryA (lpszPath
);
421 /*************************************************************************
422 * PathFileExists [SHELL32.45]
424 BOOL WINAPI
PathFileExistsAW (LPCVOID lpszPath
)
426 if (SHELL_OsIsUnicode())
427 return PathFileExistsW (lpszPath
);
428 return PathFileExistsA (lpszPath
);
431 /*************************************************************************
432 * PathMatchSpec [SHELL32.46]
434 BOOL WINAPI
PathMatchSpecAW(LPVOID name
, LPVOID mask
)
436 if (SHELL_OsIsUnicode())
437 return PathMatchSpecW( name
, mask
);
438 return PathMatchSpecA( name
, mask
);
441 /*************************************************************************
442 * PathIsSameRoot [SHELL32.650]
444 BOOL WINAPI
PathIsSameRootAW(LPCVOID lpszPath1
, LPCVOID lpszPath2
)
446 if (SHELL_OsIsUnicode())
447 return PathIsSameRootW(lpszPath1
, lpszPath2
);
448 return PathIsSameRootA(lpszPath1
, lpszPath2
);
451 /*************************************************************************
452 * IsLFNDriveA [SHELL32.41]
454 BOOL WINAPI
IsLFNDriveA(LPCSTR lpszPath
)
458 if (!GetVolumeInformationA(lpszPath
, NULL
, 0, NULL
, &fnlen
, NULL
, NULL
, 0))
463 /*************************************************************************
464 * IsLFNDriveW [SHELL32.42]
466 BOOL WINAPI
IsLFNDriveW(LPCWSTR lpszPath
)
470 if (!GetVolumeInformationW(lpszPath
, NULL
, 0, NULL
, &fnlen
, NULL
, NULL
, 0))
475 /*************************************************************************
476 * IsLFNDrive [SHELL32.119]
478 BOOL WINAPI
IsLFNDriveAW(LPCVOID lpszPath
)
480 if (SHELL_OsIsUnicode())
481 return IsLFNDriveW(lpszPath
);
482 return IsLFNDriveA(lpszPath
);
486 ########## Creating Something Unique ##########
488 /*************************************************************************
489 * PathMakeUniqueNameA [internal]
491 static BOOL
PathMakeUniqueNameA(
494 LPCSTR lpszShortName
,
498 FIXME("%p %lu %s %s %s stub\n",
499 lpszBuffer
, dwBuffSize
, debugstr_a(lpszShortName
),
500 debugstr_a(lpszLongName
), debugstr_a(lpszPathName
));
504 /*************************************************************************
505 * PathMakeUniqueNameW [internal]
507 static BOOL
PathMakeUniqueNameW(
510 LPCWSTR lpszShortName
,
511 LPCWSTR lpszLongName
,
512 LPCWSTR lpszPathName
)
514 FIXME("%p %lu %s %s %s stub\n",
515 lpszBuffer
, dwBuffSize
, debugstr_w(lpszShortName
),
516 debugstr_w(lpszLongName
), debugstr_w(lpszPathName
));
520 /*************************************************************************
521 * PathMakeUniqueName [SHELL32.47]
523 BOOL WINAPI
PathMakeUniqueNameAW(
526 LPCVOID lpszShortName
,
527 LPCVOID lpszLongName
,
528 LPCVOID lpszPathName
)
530 if (SHELL_OsIsUnicode())
531 return PathMakeUniqueNameW(lpszBuffer
,dwBuffSize
, lpszShortName
,lpszLongName
,lpszPathName
);
532 return PathMakeUniqueNameA(lpszBuffer
,dwBuffSize
, lpszShortName
,lpszLongName
,lpszPathName
);
535 /*************************************************************************
536 * PathYetAnotherMakeUniqueName [SHELL32.75]
538 BOOL WINAPI
PathYetAnotherMakeUniqueName(LPWSTR buffer
, LPCWSTR path
, LPCWSTR shortname
, LPCWSTR longname
)
540 WCHAR pathW
[MAX_PATH
], retW
[MAX_PATH
];
541 const WCHAR
*file
, *ext
;
544 TRACE("(%p, %s, %s, %s)\n", buffer
, debugstr_w(path
), debugstr_w(shortname
), debugstr_w(longname
));
546 file
= longname
? longname
: shortname
;
547 PathCombineW(pathW
, path
, file
);
548 lstrcpyW(retW
, pathW
);
549 PathRemoveExtensionW(pathW
);
551 ext
= PathFindExtensionW(file
);
553 /* now try to make it unique */
554 while (PathFileExistsW(retW
))
556 swprintf(retW
, ARRAY_SIZE(retW
), L
"%s (%d)%s", pathW
, i
, ext
);
560 lstrcpyW(buffer
, retW
);
561 TRACE("ret - %s\n", debugstr_w(buffer
));
567 ########## cleaning and resolving paths ##########
570 /*************************************************************************
571 * PathFindOnPath [SHELL32.145]
573 BOOL WINAPI
PathFindOnPathAW(LPVOID sFile
, LPCVOID
*sOtherDirs
)
575 if (SHELL_OsIsUnicode())
576 return PathFindOnPathW(sFile
, (LPCWSTR
*)sOtherDirs
);
577 return PathFindOnPathA(sFile
, (LPCSTR
*)sOtherDirs
);
580 /*************************************************************************
581 * PathCleanupSpec [SHELL32.171]
583 * lpszFile is changed in place.
585 int WINAPI
PathCleanupSpec( LPCWSTR lpszPathW
, LPWSTR lpszFileW
)
591 if (SHELL_OsIsUnicode())
593 LPWSTR p
= lpszFileW
;
595 TRACE("Cleanup %s\n",debugstr_w(lpszFileW
));
598 length
= lstrlenW(lpszPathW
);
602 int gct
= PathGetCharTypeW(*p
);
603 if (gct
== GCT_INVALID
|| gct
== GCT_WILD
|| gct
== GCT_SEPARATOR
)
606 rc
|= PCS_REPLACEDCHAR
;
612 if (length
+ i
== MAX_PATH
)
614 rc
|= PCS_FATAL
| PCS_PATHTOOLONG
;
622 LPSTR lpszFileA
= (LPSTR
)lpszFileW
;
623 LPCSTR lpszPathA
= (LPCSTR
)lpszPathW
;
626 TRACE("Cleanup %s\n",debugstr_a(lpszFileA
));
629 length
= strlen(lpszPathA
);
633 int gct
= PathGetCharTypeA(*p
);
634 if (gct
== GCT_INVALID
|| gct
== GCT_WILD
|| gct
== GCT_SEPARATOR
)
637 rc
|= PCS_REPLACEDCHAR
;
643 if (length
+ i
== MAX_PATH
)
645 rc
|= PCS_FATAL
| PCS_PATHTOOLONG
;
654 /*************************************************************************
655 * PathQualifyA [SHELL32]
657 static BOOL
PathQualifyA(LPCSTR pszPath
)
659 FIXME("%s\n",pszPath
);
663 /*************************************************************************
664 * PathQualifyW [SHELL32]
666 static BOOL
PathQualifyW(LPCWSTR pszPath
)
668 FIXME("%s\n",debugstr_w(pszPath
));
672 /*************************************************************************
673 * PathQualify [SHELL32.49]
675 BOOL WINAPI
PathQualifyAW(LPCVOID pszPath
)
677 if (SHELL_OsIsUnicode())
678 return PathQualifyW(pszPath
);
679 return PathQualifyA(pszPath
);
682 BOOL WINAPI
PathFindOnPathExA(LPSTR
,LPCSTR
*,DWORD
);
683 BOOL WINAPI
PathFindOnPathExW(LPWSTR
,LPCWSTR
*,DWORD
);
684 BOOL WINAPI
PathFileExistsDefExtA(LPSTR
,DWORD
);
685 BOOL WINAPI
PathFileExistsDefExtW(LPWSTR
,DWORD
);
687 static BOOL
PathResolveA(char *path
, const char **dirs
, DWORD flags
)
689 BOOL is_file_spec
= PathIsFileSpecA(path
);
690 DWORD dwWhich
= flags
& PRF_DONTFINDLNK
? 0xf : 0xff;
692 TRACE("(%s,%p,0x%08lx)\n", debugstr_a(path
), dirs
, flags
);
694 if (flags
& PRF_VERIFYEXISTS
&& !PathFileExistsA(path
))
696 if (PathFindOnPathExA(path
, dirs
, dwWhich
))
698 if (PathFileExistsDefExtA(path
, dwWhich
))
700 if (!is_file_spec
) GetFullPathNameA(path
, MAX_PATH
, path
, NULL
);
701 SetLastError(ERROR_FILE_NOT_FOUND
);
707 SetLastError(ERROR_FILE_NOT_FOUND
);
711 GetFullPathNameA(path
, MAX_PATH
, path
, NULL
);
716 static BOOL
PathResolveW(WCHAR
*path
, const WCHAR
**dirs
, DWORD flags
)
718 BOOL is_file_spec
= PathIsFileSpecW(path
);
719 DWORD dwWhich
= flags
& PRF_DONTFINDLNK
? 0xf : 0xff;
721 TRACE("(%s,%p,0x%08lx)\n", debugstr_w(path
), dirs
, flags
);
723 if (flags
& PRF_VERIFYEXISTS
&& !PathFileExistsW(path
))
725 if (PathFindOnPathExW(path
, dirs
, dwWhich
))
727 if (PathFileExistsDefExtW(path
, dwWhich
))
729 if (!is_file_spec
) GetFullPathNameW(path
, MAX_PATH
, path
, NULL
);
730 SetLastError(ERROR_FILE_NOT_FOUND
);
736 SetLastError(ERROR_FILE_NOT_FOUND
);
740 GetFullPathNameW(path
, MAX_PATH
, path
, NULL
);
745 /*************************************************************************
746 * PathResolve [SHELL32.51]
748 BOOL WINAPI
PathResolveAW(void *path
, const void **paths
, DWORD flags
)
750 if (SHELL_OsIsUnicode())
751 return PathResolveW(path
, (const WCHAR
**)paths
, flags
);
753 return PathResolveA(path
, (const char **)paths
, flags
);
756 /*************************************************************************
757 * PathProcessCommandA
759 static LONG
PathProcessCommandA (
765 FIXME("%s %p 0x%04lx 0x%04lx stub\n",
766 lpszPath
, lpszBuff
, dwBuffSize
, dwFlags
);
767 if(!lpszPath
) return -1;
768 if(lpszBuff
) strcpy(lpszBuff
, lpszPath
);
769 return strlen(lpszPath
);
772 /*************************************************************************
773 * PathProcessCommandW
775 static LONG
PathProcessCommandW (
781 FIXME("(%s, %p, 0x%04lx, 0x%04lx) stub\n",
782 debugstr_w(lpszPath
), lpszBuff
, dwBuffSize
, dwFlags
);
783 if(!lpszPath
) return -1;
784 if(lpszBuff
) lstrcpyW(lpszBuff
, lpszPath
);
785 return lstrlenW(lpszPath
);
788 /*************************************************************************
789 * PathProcessCommand (SHELL32.653)
791 LONG WINAPI
PathProcessCommandAW (
797 if (SHELL_OsIsUnicode())
798 return PathProcessCommandW(lpszPath
, lpszBuff
, dwBuffSize
, dwFlags
);
799 return PathProcessCommandA(lpszPath
, lpszBuff
, dwBuffSize
, dwFlags
);
803 ########## special ##########
806 /*************************************************************************
807 * PathSetDlgItemPath (SHELL32.48)
809 VOID WINAPI
PathSetDlgItemPathAW(HWND hDlg
, int id
, LPCVOID pszPath
)
811 if (SHELL_OsIsUnicode())
812 PathSetDlgItemPathW(hDlg
, id
, pszPath
);
814 PathSetDlgItemPathA(hDlg
, id
, pszPath
);
817 typedef enum _CSIDL_Type
{
821 CSIDL_Type_Disallowed
,
822 CSIDL_Type_NonExistent
,
823 CSIDL_Type_WindowsPath
,
824 CSIDL_Type_SystemPath
,
825 CSIDL_Type_SystemX86Path
,
826 CSIDL_Type_ProgramData
,
829 #define CSIDL_CONTACTS 0x0043
830 #define CSIDL_DOWNLOADS 0x0047
831 #define CSIDL_LINKS 0x004d
832 #define CSIDL_APPDATA_LOCALLOW 0x004e
833 #define CSIDL_SAVED_GAMES 0x0062
834 #define CSIDL_SEARCHES 0x0063
838 IApplicationDestinations IApplicationDestinations_iface
;
840 } IApplicationDestinationsImpl
;
842 static inline IApplicationDestinationsImpl
*impl_from_IApplicationDestinations( IApplicationDestinations
*iface
)
844 return CONTAINING_RECORD(iface
, IApplicationDestinationsImpl
, IApplicationDestinations_iface
);
847 static HRESULT WINAPI
ApplicationDestinations_QueryInterface(IApplicationDestinations
*iface
, REFIID riid
,
850 IApplicationDestinationsImpl
*This
= impl_from_IApplicationDestinations(iface
);
852 TRACE("(%p, %s, %p)\n", This
, debugstr_guid(riid
), ppv
);
857 if (IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IApplicationDestinations
, riid
))
859 *ppv
= &This
->IApplicationDestinations_iface
;
860 IUnknown_AddRef((IUnknown
*)*ppv
);
862 TRACE("Returning IApplicationDestinations: %p\n", *ppv
);
867 FIXME("(%p)->(%s, %p) interface not supported.\n", This
, debugstr_guid(riid
), ppv
);
869 return E_NOINTERFACE
;
872 static ULONG WINAPI
ApplicationDestinations_AddRef(IApplicationDestinations
*iface
)
874 IApplicationDestinationsImpl
*This
= impl_from_IApplicationDestinations(iface
);
875 ULONG ref
= InterlockedIncrement(&This
->ref
);
877 TRACE("(%p), new refcount=%li\n", This
, ref
);
882 static ULONG WINAPI
ApplicationDestinations_Release(IApplicationDestinations
*iface
)
884 IApplicationDestinationsImpl
*This
= impl_from_IApplicationDestinations(iface
);
885 ULONG ref
= InterlockedDecrement(&This
->ref
);
887 TRACE("(%p), new refcount=%li\n", This
, ref
);
895 static HRESULT WINAPI
ApplicationDestinations_SetAppID(IApplicationDestinations
*iface
, const WCHAR
*appid
)
897 IApplicationDestinationsImpl
*This
= impl_from_IApplicationDestinations(iface
);
899 FIXME("(%p, %s) stub!\n", This
, debugstr_w(appid
));
904 static HRESULT WINAPI
ApplicationDestinations_RemoveDestination(IApplicationDestinations
*iface
, IUnknown
*punk
)
906 IApplicationDestinationsImpl
*This
= impl_from_IApplicationDestinations(iface
);
908 FIXME("(%p, %p) stub!\n", This
, punk
);
913 static HRESULT WINAPI
ApplicationDestinations_RemoveAllDestinations(IApplicationDestinations
*iface
)
915 IApplicationDestinationsImpl
*This
= impl_from_IApplicationDestinations(iface
);
917 FIXME("(%p) stub!\n", This
);
922 static const IApplicationDestinationsVtbl ApplicationDestinationsVtbl
=
924 ApplicationDestinations_QueryInterface
,
925 ApplicationDestinations_AddRef
,
926 ApplicationDestinations_Release
,
927 ApplicationDestinations_SetAppID
,
928 ApplicationDestinations_RemoveDestination
,
929 ApplicationDestinations_RemoveAllDestinations
932 HRESULT WINAPI
ApplicationDestinations_Constructor(IUnknown
*outer
, REFIID riid
, LPVOID
*ppv
)
934 IApplicationDestinationsImpl
*This
;
937 TRACE("(%p, %s, %p)\n", outer
, debugstr_guid(riid
), ppv
);
940 return CLASS_E_NOAGGREGATION
;
942 if (!(This
= SHAlloc(sizeof(*This
))))
943 return E_OUTOFMEMORY
;
945 This
->IApplicationDestinations_iface
.lpVtbl
= &ApplicationDestinationsVtbl
;
948 hr
= IUnknown_QueryInterface(&This
->IApplicationDestinations_iface
, riid
, ppv
);
957 IApplicationDocumentLists IApplicationDocumentLists_iface
;
959 } IApplicationDocumentListsImpl
;
961 static inline IApplicationDocumentListsImpl
*impl_from_IApplicationDocumentLists( IApplicationDocumentLists
*iface
)
963 return CONTAINING_RECORD(iface
, IApplicationDocumentListsImpl
, IApplicationDocumentLists_iface
);
966 static HRESULT WINAPI
ApplicationDocumentLists_QueryInterface(IApplicationDocumentLists
*iface
,
967 REFIID riid
, LPVOID
*ppv
)
969 IApplicationDocumentListsImpl
*This
= impl_from_IApplicationDocumentLists(iface
);
971 TRACE("(%p, %s, %p)\n", This
, debugstr_guid(riid
), ppv
);
976 if (IsEqualGUID(&IID_IUnknown
, riid
) || IsEqualGUID(&IID_IApplicationDocumentLists
, riid
))
978 *ppv
= &This
->IApplicationDocumentLists_iface
;
979 IUnknown_AddRef((IUnknown
*)*ppv
);
981 TRACE("Returning IApplicationDocumentLists: %p\n", *ppv
);
986 FIXME("(%p)->(%s, %p) interface not supported.\n", This
, debugstr_guid(riid
), ppv
);
988 return E_NOINTERFACE
;
991 static ULONG WINAPI
ApplicationDocumentLists_AddRef(IApplicationDocumentLists
*iface
)
993 IApplicationDocumentListsImpl
*This
= impl_from_IApplicationDocumentLists(iface
);
994 ULONG ref
= InterlockedIncrement(&This
->ref
);
996 TRACE("(%p), new refcount=%li\n", This
, ref
);
1001 static ULONG WINAPI
ApplicationDocumentLists_Release(IApplicationDocumentLists
*iface
)
1003 IApplicationDocumentListsImpl
*This
= impl_from_IApplicationDocumentLists(iface
);
1004 ULONG ref
= InterlockedDecrement(&This
->ref
);
1006 TRACE("(%p), new refcount=%li\n", This
, ref
);
1014 static HRESULT WINAPI
ApplicationDocumentLists_SetAppID(IApplicationDocumentLists
*iface
,
1017 IApplicationDocumentListsImpl
*This
= impl_from_IApplicationDocumentLists(iface
);
1019 FIXME("(%p, %s) stub!\n", This
, debugstr_w(appid
));
1024 static HRESULT WINAPI
ApplicationDocumentLists_GetList(IApplicationDocumentLists
*iface
,
1025 APPDOCLISTTYPE list_type
, UINT item_count
,
1026 REFIID riid
, void **obj
)
1028 IApplicationDocumentListsImpl
*This
= impl_from_IApplicationDocumentLists(iface
);
1030 FIXME("(%p, %u, %u, %s, %p): stub\n", This
, list_type
, item_count
, debugstr_guid(riid
), obj
);
1035 static const IApplicationDocumentListsVtbl ApplicationDocumentListsVtbl
=
1037 ApplicationDocumentLists_QueryInterface
,
1038 ApplicationDocumentLists_AddRef
,
1039 ApplicationDocumentLists_Release
,
1040 ApplicationDocumentLists_SetAppID
,
1041 ApplicationDocumentLists_GetList
1044 HRESULT WINAPI
ApplicationDocumentLists_Constructor(IUnknown
*outer
, REFIID riid
, LPVOID
*ppv
)
1046 IApplicationDocumentListsImpl
*This
;
1049 TRACE("(%p, %s, %p)\n", outer
, debugstr_guid(riid
), ppv
);
1052 return CLASS_E_NOAGGREGATION
;
1054 if (!(This
= SHAlloc(sizeof(*This
))))
1055 return E_OUTOFMEMORY
;
1057 This
->IApplicationDocumentLists_iface
.lpVtbl
= &ApplicationDocumentListsVtbl
;
1060 hr
= IUnknown_QueryInterface(&This
->IApplicationDocumentLists_iface
, riid
, ppv
);
1069 const KNOWNFOLDERID
*id
;
1072 const WCHAR
*def_path
; /* fallback string or resource ID */
1073 KF_CATEGORY category
;
1075 const KNOWNFOLDERID
*parent
;
1077 const WCHAR
*parsing
;
1079 KF_DEFINITION_FLAGS flags
;
1080 const FOLDERTYPEID
*typeid;
1083 static const CSIDL_DATA CSIDL_Data
[] =
1085 { /* 0x00 - CSIDL_DESKTOP */
1086 .id
= &FOLDERID_Desktop
,
1087 .type
= CSIDL_Type_User
,
1088 .value
= L
"Desktop",
1089 .category
= KF_CATEGORY_PERUSER
,
1092 .attributes
= FILE_ATTRIBUTE_READONLY
,
1094 { /* 0x01 - CSIDL_INTERNET */
1095 .id
= &FOLDERID_InternetFolder
,
1096 .type
= CSIDL_Type_Disallowed
,
1097 .category
= KF_CATEGORY_VIRTUAL
,
1098 .name
= L
"InternetFolder",
1099 .parsing
= L
"::{871C5380-42A0-1069-A2EA-08002B30309D}",
1101 { /* 0x02 - CSIDL_PROGRAMS */
1102 .id
= &FOLDERID_Programs
,
1103 .type
= CSIDL_Type_User
,
1104 .value
= L
"Programs",
1105 .category
= KF_CATEGORY_PERUSER
,
1106 .name
= L
"Programs",
1107 .parent
= &FOLDERID_StartMenu
,
1108 .path
= L
"Programs",
1109 .attributes
= FILE_ATTRIBUTE_READONLY
,
1111 { /* 0x03 - CSIDL_CONTROLS (.CPL files) */
1112 .id
= &FOLDERID_ControlPanelFolder
,
1113 .type
= CSIDL_Type_SystemPath
,
1114 .category
= KF_CATEGORY_VIRTUAL
,
1115 .name
= L
"ControlPanelFolder",
1116 .path
= L
"::{21EC2020-3AEA-1069-A2DD-08002B30309D}",
1117 .parsing
= L
"::{26EE0668-A00A-44D7-9371-BEB064C98683}\\0",
1119 { /* 0x04 - CSIDL_PRINTERS */
1120 .id
= &FOLDERID_PrintersFolder
,
1121 .type
= CSIDL_Type_SystemPath
,
1122 .category
= KF_CATEGORY_VIRTUAL
,
1123 .name
= L
"PrintersFolder",
1124 .parsing
= L
"::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{2227A280-3AEA-1069-A2DE-08002B30309D}",
1126 { /* 0x05 - CSIDL_PERSONAL */
1127 .id
= &FOLDERID_Documents
,
1128 .type
= CSIDL_Type_User
,
1129 .value
= L
"Personal",
1130 .category
= KF_CATEGORY_PERUSER
,
1131 .name
= L
"Personal",
1132 .parent
= &FOLDERID_Profile
,
1133 .path
= L
"Documents",
1134 .parsing
= L
"::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{FDD39AD0-238F-46AF-ADB4-6C85480369C7}",
1135 .attributes
= FILE_ATTRIBUTE_READONLY
,
1136 .flags
= KFDF_ROAMABLE
| KFDF_PRECREATE
,
1138 { /* 0x06 - CSIDL_FAVORITES */
1139 .id
= &FOLDERID_Favorites
,
1140 .type
= CSIDL_Type_User
,
1141 .value
= L
"Favorites",
1142 .category
= KF_CATEGORY_PERUSER
,
1143 .name
= L
"Favorites",
1144 .path
= L
"Favorites",
1145 .attributes
= FILE_ATTRIBUTE_READONLY
,
1146 .flags
= KFDF_ROAMABLE
| KFDF_PRECREATE
| KFDF_PUBLISHEXPANDEDPATH
,
1148 { /* 0x07 - CSIDL_STARTUP */
1149 .id
= &FOLDERID_Startup
,
1150 .type
= CSIDL_Type_User
,
1151 .value
= L
"StartUp",
1152 .category
= KF_CATEGORY_PERUSER
,
1154 .parent
= &FOLDERID_Programs
,
1156 .attributes
= FILE_ATTRIBUTE_READONLY
,
1157 .flags
= KFDF_PRECREATE
,
1159 { /* 0x08 - CSIDL_RECENT */
1160 .id
= &FOLDERID_Recent
,
1161 .type
= CSIDL_Type_User
,
1163 .category
= KF_CATEGORY_PERUSER
,
1165 .parent
= &FOLDERID_RoamingAppData
,
1166 .path
= L
"Microsoft\\Windows\\Recent",
1167 .attributes
= FILE_ATTRIBUTE_READONLY
,
1168 .flags
= KFDF_PRECREATE
,
1170 { /* 0x09 - CSIDL_SENDTO */
1171 .id
= &FOLDERID_SendTo
,
1172 .type
= CSIDL_Type_User
,
1174 .category
= KF_CATEGORY_PERUSER
,
1176 .parent
= &FOLDERID_RoamingAppData
,
1177 .path
= L
"Microsoft\\Windows\\SendTo",
1178 .flags
= KFDF_PRECREATE
,
1180 { /* 0x0a - CSIDL_BITBUCKET - Recycle Bin */
1181 .id
= &FOLDERID_RecycleBinFolder
,
1182 .type
= CSIDL_Type_Disallowed
,
1183 .category
= KF_CATEGORY_VIRTUAL
,
1184 .name
= L
"RecycleBinFolder",
1185 .parsing
= L
"::{645FF040-5081-101B-9F08-00AA002F954E}",
1187 { /* 0x0b - CSIDL_STARTMENU */
1188 .id
= &FOLDERID_StartMenu
,
1189 .type
= CSIDL_Type_User
,
1190 .value
= L
"Start Menu",
1191 .category
= KF_CATEGORY_PERUSER
,
1192 .name
= L
"Start Menu",
1193 .parent
= &FOLDERID_RoamingAppData
,
1194 .path
= L
"Microsoft\\Windows\\Start Menu",
1195 .attributes
= FILE_ATTRIBUTE_READONLY
,
1196 .flags
= KFDF_PRECREATE
,
1198 { /* 0x0c - CSIDL_MYDOCUMENTS */
1200 .type
= CSIDL_Type_Disallowed
, /* matches WinXP--can't get its path */
1202 { /* 0x0d - CSIDL_MYMUSIC */
1203 .id
= &FOLDERID_Music
,
1204 .type
= CSIDL_Type_User
,
1205 .value
= L
"My Music",
1206 .category
= KF_CATEGORY_PERUSER
,
1207 .name
= L
"My Music",
1208 .parent
= &FOLDERID_Profile
,
1210 .parsing
= L
"::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{4BD8D571-6D19-48D3-BE97-422220080E43}",
1211 .attributes
= FILE_ATTRIBUTE_READONLY
,
1212 .flags
= KFDF_ROAMABLE
| KFDF_PRECREATE
,
1214 { /* 0x0e - CSIDL_MYVIDEO */
1215 .id
= &FOLDERID_Videos
,
1216 .type
= CSIDL_Type_User
,
1217 .value
= L
"My Videos",
1218 .category
= KF_CATEGORY_PERUSER
,
1219 .name
= L
"My Video",
1220 .parent
= &FOLDERID_Profile
,
1222 .parsing
= L
"::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{18989B1D-99B5-455B-841C-AB7C74E4DDFC}",
1223 .attributes
= FILE_ATTRIBUTE_READONLY
,
1224 .flags
= KFDF_ROAMABLE
| KFDF_PRECREATE
,
1226 { /* 0x0f - unassigned */
1228 .type
= CSIDL_Type_Disallowed
,
1230 { /* 0x10 - CSIDL_DESKTOPDIRECTORY */
1231 .id
= &FOLDERID_Desktop
,
1232 .type
= CSIDL_Type_User
,
1233 .value
= L
"Desktop",
1234 .category
= KF_CATEGORY_PERUSER
,
1236 .parent
= &FOLDERID_Profile
,
1238 .attributes
= FILE_ATTRIBUTE_READONLY
,
1239 .flags
= KFDF_ROAMABLE
| KFDF_PRECREATE
| KFDF_PUBLISHEXPANDEDPATH
,
1241 { /* 0x11 - CSIDL_DRIVES */
1242 .id
= &FOLDERID_ComputerFolder
,
1243 .type
= CSIDL_Type_Disallowed
,
1244 .category
= KF_CATEGORY_VIRTUAL
,
1245 .name
= L
"MyComputerFolder",
1246 .parsing
= L
"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}",
1248 { /* 0x12 - CSIDL_NETWORK */
1249 .id
= &FOLDERID_NetworkFolder
,
1250 .type
= CSIDL_Type_Disallowed
,
1251 .category
= KF_CATEGORY_VIRTUAL
,
1252 .name
= L
"NetworkPlacesFolder",
1253 .parsing
= L
"::{F02C1A0D-BE21-4350-88B0-7367FC96EF3C}",
1255 { /* 0x13 - CSIDL_NETHOOD */
1256 .id
= &FOLDERID_NetHood
,
1257 .type
= CSIDL_Type_User
,
1258 .value
= L
"NetHood",
1259 .category
= KF_CATEGORY_PERUSER
,
1261 .parent
= &FOLDERID_RoamingAppData
,
1262 .path
= L
"Microsoft\\Windows\\Network Shortcuts",
1264 { /* 0x14 - CSIDL_FONTS */
1265 .id
= &FOLDERID_Fonts
,
1266 .type
= CSIDL_Type_WindowsPath
,
1268 .def_path
= L
"Fonts",
1269 .category
= KF_CATEGORY_FIXED
,
1271 .parent
= &FOLDERID_Windows
,
1272 .typeid = &FOLDERID_Windows
1274 { /* 0x15 - CSIDL_TEMPLATES */
1275 .id
= &FOLDERID_Templates
,
1276 .type
= CSIDL_Type_User
,
1277 .value
= L
"Templates",
1278 .category
= KF_CATEGORY_PERUSER
,
1279 .name
= L
"Templates",
1280 .parent
= &FOLDERID_RoamingAppData
,
1281 .path
= L
"Microsoft\\Windows\\Templates",
1283 { /* 0x16 - CSIDL_COMMON_STARTMENU */
1284 .id
= &FOLDERID_CommonStartMenu
,
1285 .type
= CSIDL_Type_ProgramData
,
1286 .value
= L
"Common Start Menu",
1287 .category
= KF_CATEGORY_COMMON
,
1288 .name
= L
"Common Start Menu",
1289 .parent
= &FOLDERID_ProgramData
,
1290 .path
= L
"Microsoft\\Windows\\Start Menu",
1291 .attributes
= FILE_ATTRIBUTE_READONLY
,
1293 { /* 0x17 - CSIDL_COMMON_PROGRAMS */
1294 .id
= &FOLDERID_CommonPrograms
,
1295 .type
= CSIDL_Type_ProgramData
,
1296 .value
= L
"Common Programs",
1297 .category
= KF_CATEGORY_COMMON
,
1298 .name
= L
"Common Programs",
1299 .parent
= &FOLDERID_CommonStartMenu
,
1300 .path
= L
"Programs",
1301 .attributes
= FILE_ATTRIBUTE_READONLY
,
1303 { /* 0x18 - CSIDL_COMMON_STARTUP */
1304 .id
= &FOLDERID_CommonStartup
,
1305 .type
= CSIDL_Type_ProgramData
,
1306 .value
= L
"Common StartUp",
1307 .category
= KF_CATEGORY_COMMON
,
1308 .name
= L
"Common Startup",
1309 .parent
= &FOLDERID_CommonPrograms
,
1311 .attributes
= FILE_ATTRIBUTE_READONLY
,
1312 .flags
= KFDF_PRECREATE
,
1314 { /* 0x19 - CSIDL_COMMON_DESKTOPDIRECTORY */
1315 .id
= &FOLDERID_PublicDesktop
,
1316 .type
= CSIDL_Type_AllUsers
,
1317 .value
= L
"Common Desktop",
1318 .category
= KF_CATEGORY_COMMON
,
1319 .name
= L
"Common Desktop",
1320 .parent
= &FOLDERID_Public
,
1322 .attributes
= FILE_ATTRIBUTE_READONLY
| FILE_ATTRIBUTE_HIDDEN
,
1323 .flags
= KFDF_PRECREATE
,
1325 { /* 0x1a - CSIDL_APPDATA */
1326 .id
= &FOLDERID_RoamingAppData
,
1327 .type
= CSIDL_Type_User
,
1328 .value
= L
"AppData",
1329 .category
= KF_CATEGORY_PERUSER
,
1331 .parent
= &FOLDERID_Profile
,
1332 .path
= L
"AppData\\Roaming",
1334 { /* 0x1b - CSIDL_PRINTHOOD */
1335 .id
= &FOLDERID_PrintHood
,
1336 .type
= CSIDL_Type_User
,
1337 .value
= L
"PrintHood",
1338 .category
= KF_CATEGORY_PERUSER
,
1339 .name
= L
"PrintHood",
1340 .parent
= &FOLDERID_RoamingAppData
,
1341 .path
= L
"Microsoft\\Windows\\Printer Shortcuts",
1343 { /* 0x1c - CSIDL_LOCAL_APPDATA */
1344 .id
= &FOLDERID_LocalAppData
,
1345 .type
= CSIDL_Type_User
,
1346 .value
= L
"Local AppData",
1347 .category
= KF_CATEGORY_PERUSER
,
1348 .name
= L
"Local AppData",
1349 .parent
= &FOLDERID_Profile
,
1350 .path
= L
"AppData\\Local",
1351 .flags
= KFDF_LOCAL_REDIRECT_ONLY
| KFDF_PUBLISHEXPANDEDPATH
,
1353 { /* 0x1d - CSIDL_ALTSTARTUP */
1355 .type
= CSIDL_Type_NonExistent
,
1357 { /* 0x1e - CSIDL_COMMON_ALTSTARTUP */
1359 .type
= CSIDL_Type_NonExistent
,
1361 { /* 0x1f - CSIDL_COMMON_FAVORITES */
1362 .id
= &FOLDERID_Favorites
,
1363 .type
= CSIDL_Type_AllUsers
,
1364 .value
= L
"Common Favorites",
1365 .category
= KF_CATEGORY_PERUSER
,
1366 .name
= L
"Favorites",
1367 .parent
= &FOLDERID_Profile
,
1368 .path
= L
"Favorites",
1369 .attributes
= FILE_ATTRIBUTE_READONLY
,
1370 .flags
= KFDF_ROAMABLE
| KFDF_PRECREATE
| KFDF_PUBLISHEXPANDEDPATH
,
1372 { /* 0x20 - CSIDL_INTERNET_CACHE */
1373 .id
= &FOLDERID_InternetCache
,
1374 .type
= CSIDL_Type_User
,
1376 .category
= KF_CATEGORY_PERUSER
,
1378 .parent
= &FOLDERID_LocalAppData
,
1379 .path
= L
"Microsoft\\Windows\\INetCache",
1380 .flags
= KFDF_LOCAL_REDIRECT_ONLY
,
1382 { /* 0x21 - CSIDL_COOKIES */
1383 .id
= &FOLDERID_Cookies
,
1384 .type
= CSIDL_Type_User
,
1385 .value
= L
"Cookies",
1386 .category
= KF_CATEGORY_PERUSER
,
1388 .parent
= &FOLDERID_LocalAppData
,
1389 .path
= L
"Microsoft\\Windows\\INetCookies",
1391 { /* 0x22 - CSIDL_HISTORY */
1392 .id
= &FOLDERID_History
,
1393 .type
= CSIDL_Type_User
,
1394 .value
= L
"History",
1395 .category
= KF_CATEGORY_PERUSER
,
1397 .parent
= &FOLDERID_LocalAppData
,
1398 .path
= L
"Microsoft\\Windows\\History",
1399 .flags
= KFDF_LOCAL_REDIRECT_ONLY
,
1401 { /* 0x23 - CSIDL_COMMON_APPDATA */
1402 .id
= &FOLDERID_ProgramData
,
1403 .type
= CSIDL_Type_ProgramData
,
1404 .value
= L
"Common AppData",
1405 .category
= KF_CATEGORY_FIXED
,
1406 .name
= L
"Common AppData",
1408 { /* 0x24 - CSIDL_WINDOWS */
1409 .id
= &FOLDERID_Windows
,
1410 .type
= CSIDL_Type_WindowsPath
,
1411 .category
= KF_CATEGORY_FIXED
,
1414 { /* 0x25 - CSIDL_SYSTEM */
1415 .id
= &FOLDERID_System
,
1416 .type
= CSIDL_Type_SystemPath
,
1417 .category
= KF_CATEGORY_FIXED
,
1420 { /* 0x26 - CSIDL_PROGRAM_FILES */
1421 .id
= &FOLDERID_ProgramFiles
,
1422 .type
= CSIDL_Type_CurrVer
,
1423 .value
= L
"ProgramFilesDir",
1424 .def_path
= L
"Program Files",
1425 .category
= KF_CATEGORY_FIXED
,
1426 .name
= L
"ProgramFiles",
1427 .attributes
= FILE_ATTRIBUTE_READONLY
,
1429 { /* 0x27 - CSIDL_MYPICTURES */
1430 .id
= &FOLDERID_Pictures
,
1431 .type
= CSIDL_Type_User
,
1432 .value
= L
"My Pictures",
1433 .category
= KF_CATEGORY_PERUSER
,
1434 .name
= L
"My Pictures",
1435 .parent
= &FOLDERID_Profile
,
1436 .path
= L
"Pictures",
1437 .parsing
= L
"::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{33E28130-4E1E-4676-835A-98395C3BC3BB}",
1438 .attributes
= FILE_ATTRIBUTE_READONLY
,
1439 .flags
= KFDF_ROAMABLE
| KFDF_PRECREATE
,
1441 { /* 0x28 - CSIDL_PROFILE */
1442 .id
= &FOLDERID_Profile
,
1443 .type
= CSIDL_Type_User
,
1444 .category
= KF_CATEGORY_FIXED
,
1447 { /* 0x29 - CSIDL_SYSTEMX86 */
1448 .id
= &FOLDERID_SystemX86
,
1449 .type
= CSIDL_Type_SystemX86Path
,
1450 .category
= KF_CATEGORY_FIXED
,
1451 .name
= L
"SystemX86",
1453 { /* 0x2a - CSIDL_PROGRAM_FILESX86 */
1454 .id
= &FOLDERID_ProgramFilesX86
,
1455 .type
= CSIDL_Type_CurrVer
,
1456 .value
= L
"ProgramFilesDir (x86)",
1457 .def_path
= L
"Program Files (x86)",
1458 .category
= KF_CATEGORY_FIXED
,
1459 .name
= L
"ProgramFilesX86",
1460 .attributes
= FILE_ATTRIBUTE_READONLY
,
1462 { /* 0x2b - CSIDL_PROGRAM_FILES_COMMON */
1463 .id
= &FOLDERID_ProgramFilesCommon
,
1464 .type
= CSIDL_Type_CurrVer
,
1465 .value
= L
"CommonFilesDir",
1466 .def_path
= L
"Program Files\\Common Files",
1467 .category
= KF_CATEGORY_FIXED
,
1468 .name
= L
"ProgramFilesCommon",
1470 { /* 0x2c - CSIDL_PROGRAM_FILES_COMMONX86 */
1471 .id
= &FOLDERID_ProgramFilesCommonX86
,
1472 .type
= CSIDL_Type_CurrVer
,
1473 .value
= L
"CommonFilesDir (x86)",
1474 .def_path
= L
"Program Files (x86)\\Common Files",
1475 .category
= KF_CATEGORY_FIXED
,
1476 .name
= L
"ProgramFilesCommonX86",
1478 { /* 0x2d - CSIDL_COMMON_TEMPLATES */
1479 .id
= &FOLDERID_CommonTemplates
,
1480 .type
= CSIDL_Type_ProgramData
,
1481 .value
= L
"Common Templates",
1482 .category
= KF_CATEGORY_COMMON
,
1483 .name
= L
"Common Templates",
1484 .parent
= &FOLDERID_ProgramData
,
1485 .path
= L
"Microsoft\\Windows\\Templates",
1487 { /* 0x2e - CSIDL_COMMON_DOCUMENTS */
1488 .id
= &FOLDERID_PublicDocuments
,
1489 .type
= CSIDL_Type_AllUsers
,
1490 .value
= L
"Common Documents",
1491 .category
= KF_CATEGORY_COMMON
,
1492 .name
= L
"Common Documents",
1493 .parent
= &FOLDERID_Public
,
1494 .path
= L
"Documents",
1495 .attributes
= FILE_ATTRIBUTE_READONLY
,
1496 .flags
= KFDF_PRECREATE
,
1498 { /* 0x2f - CSIDL_COMMON_ADMINTOOLS */
1499 .id
= &FOLDERID_CommonAdminTools
,
1500 .type
= CSIDL_Type_ProgramData
,
1501 .value
= L
"Common Administrative Tools",
1502 .category
= KF_CATEGORY_COMMON
,
1503 .name
= L
"Common Administrative Tools",
1504 .parent
= &FOLDERID_CommonPrograms
,
1505 .path
= L
"Administrative Tools",
1506 .attributes
= FILE_ATTRIBUTE_READONLY
,
1507 .flags
= KFDF_PRECREATE
,
1509 { /* 0x30 - CSIDL_ADMINTOOLS */
1510 .id
= &FOLDERID_AdminTools
,
1511 .type
= CSIDL_Type_User
,
1512 .value
= L
"Administrative Tools",
1513 .category
= KF_CATEGORY_PERUSER
,
1514 .name
= L
"Administrative Tools",
1515 .parent
= &FOLDERID_Programs
,
1516 .path
= L
"Administrative Tools",
1517 .attributes
= FILE_ATTRIBUTE_READONLY
,
1518 .flags
= KFDF_PRECREATE
,
1520 { /* 0x31 - CSIDL_CONNECTIONS */
1521 .id
= &FOLDERID_ConnectionsFolder
,
1522 .type
= CSIDL_Type_Disallowed
,
1523 .category
= KF_CATEGORY_VIRTUAL
,
1524 .name
= L
"ConnectionsFolder",
1525 .path
= L
"Administrative Tools",
1526 .parsing
= L
"::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{7007ACC7-3202-11D1-AAD2-00805FC1270E}",
1528 { /* 0x32 - unassigned */
1530 .type
= CSIDL_Type_Disallowed
,
1532 { /* 0x33 - unassigned */
1534 .type
= CSIDL_Type_Disallowed
,
1536 { /* 0x34 - unassigned */
1538 .type
= CSIDL_Type_Disallowed
,
1540 { /* 0x35 - CSIDL_COMMON_MUSIC */
1541 .id
= &FOLDERID_PublicMusic
,
1542 .type
= CSIDL_Type_AllUsers
,
1543 .value
= L
"CommonMusic",
1544 .category
= KF_CATEGORY_COMMON
,
1545 .name
= L
"CommonMusic",
1546 .parent
= &FOLDERID_Public
,
1548 .attributes
= FILE_ATTRIBUTE_READONLY
,
1549 .flags
= KFDF_PRECREATE
,
1551 { /* 0x36 - CSIDL_COMMON_PICTURES */
1552 .id
= &FOLDERID_PublicPictures
,
1553 .type
= CSIDL_Type_AllUsers
,
1554 .value
= L
"CommonPictures",
1555 .category
= KF_CATEGORY_COMMON
,
1556 .name
= L
"CommonPictures",
1557 .parent
= &FOLDERID_Public
,
1558 .path
= L
"Pictures",
1559 .attributes
= FILE_ATTRIBUTE_READONLY
,
1560 .flags
= KFDF_PRECREATE
,
1562 { /* 0x37 - CSIDL_COMMON_VIDEO */
1563 .id
= &FOLDERID_PublicVideos
,
1564 .type
= CSIDL_Type_AllUsers
,
1565 .value
= L
"CommonVideo",
1566 .category
= KF_CATEGORY_COMMON
,
1567 .name
= L
"CommonVideo",
1568 .parent
= &FOLDERID_Public
,
1570 .attributes
= FILE_ATTRIBUTE_READONLY
,
1571 .flags
= KFDF_PRECREATE
,
1573 { /* 0x38 - CSIDL_RESOURCES */
1574 .id
= &FOLDERID_ResourceDir
,
1575 .type
= CSIDL_Type_WindowsPath
,
1576 .def_path
= L
"Resources",
1577 .category
= KF_CATEGORY_FIXED
,
1578 .name
= L
"ResourceDir",
1580 { /* 0x39 - CSIDL_RESOURCES_LOCALIZED */
1581 .id
= &FOLDERID_LocalizedResourcesDir
,
1582 .type
= CSIDL_Type_NonExistent
,
1583 .category
= KF_CATEGORY_FIXED
,
1584 .name
= L
"LocalizedResourcesDir",
1586 { /* 0x3a - CSIDL_COMMON_OEM_LINKS */
1587 .id
= &FOLDERID_CommonOEMLinks
,
1588 .type
= CSIDL_Type_ProgramData
,
1589 .category
= KF_CATEGORY_COMMON
,
1590 .name
= L
"OEM Links",
1591 .parent
= &FOLDERID_ProgramData
,
1592 .path
= L
"OEM Links",
1594 { /* 0x3b - CSIDL_CDBURN_AREA */
1595 .id
= &FOLDERID_CDBurning
,
1596 .type
= CSIDL_Type_User
,
1597 .value
= L
"CD Burning",
1598 .category
= KF_CATEGORY_PERUSER
,
1599 .name
= L
"CD Burning",
1600 .parent
= &FOLDERID_LocalAppData
,
1601 .path
= L
"Microsoft\\Windows\\Burn\\Burn",
1602 .attributes
= FILE_ATTRIBUTE_READONLY
,
1603 .flags
= KFDF_LOCAL_REDIRECT_ONLY
,
1605 { /* 0x3c unassigned */
1607 .type
= CSIDL_Type_Disallowed
,
1609 { /* 0x3d - CSIDL_COMPUTERSNEARME */
1611 .type
= CSIDL_Type_Disallowed
, /* FIXME */
1613 { /* 0x3e - CSIDL_PROFILES */
1615 .type
= CSIDL_Type_Disallowed
, /* oddly, this matches WinXP */
1618 .id
= &FOLDERID_AddNewPrograms
,
1619 .type
= CSIDL_Type_Disallowed
,
1620 .category
= KF_CATEGORY_VIRTUAL
,
1621 .name
= L
"AddNewProgramsFolder",
1622 .parsing
= L
"::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{15eae92e-f17a-4431-9f28-805e482dafd4}",
1625 .id
= &FOLDERID_AppUpdates
,
1626 .type
= CSIDL_Type_Disallowed
,
1627 .category
= KF_CATEGORY_VIRTUAL
,
1628 .name
= L
"AppUpdatesFolder",
1629 .parsing
= L
"::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{7b81be6a-ce2b-4676-a29e-eb907a5126c5}\\::{d450a8a1-9568-45c7-9c0e-b4f9fb4537bd}",
1632 .id
= &FOLDERID_ChangeRemovePrograms
,
1633 .type
= CSIDL_Type_Disallowed
,
1634 .category
= KF_CATEGORY_VIRTUAL
,
1635 .name
= L
"ChangeRemoveProgramsFolder",
1636 .parsing
= L
"::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{7b81be6a-ce2b-4676-a29e-eb907a5126c5}",
1639 .id
= &FOLDERID_ConflictFolder
,
1640 .type
= CSIDL_Type_Disallowed
,
1641 .category
= KF_CATEGORY_VIRTUAL
,
1642 .name
= L
"ConflictFolder",
1643 .parsing
= L
"::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\\::{E413D040-6788-4C22-957E-175D1C513A34},",
1645 { /* 0x43 - CSIDL_CONTACTS */
1646 .id
= &FOLDERID_Contacts
,
1647 .type
= CSIDL_Type_User
,
1648 .category
= KF_CATEGORY_PERUSER
,
1649 .name
= L
"Contacts",
1650 .parent
= &FOLDERID_Profile
,
1651 .path
= L
"Contacts",
1652 .parsing
= L
"::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{56784854-C6CB-462B-8169-88E350ACB882}",
1653 .attributes
= FILE_ATTRIBUTE_READONLY
,
1654 .flags
= KFDF_ROAMABLE
| KFDF_PRECREATE
| KFDF_PUBLISHEXPANDEDPATH
,
1657 .id
= &FOLDERID_DeviceMetadataStore
,
1658 .type
= CSIDL_Type_Disallowed
, /* FIXME */
1659 .category
= KF_CATEGORY_COMMON
,
1660 .name
= L
"Device Metadata Store",
1661 .parent
= &FOLDERID_ProgramData
,
1662 .path
= L
"Microsoft\\Windows\\DeviceMetadataStore",
1666 .type
= CSIDL_Type_Disallowed
,
1669 .id
= &FOLDERID_DocumentsLibrary
,
1670 .type
= CSIDL_Type_Disallowed
, /* FIXME */
1671 .category
= KF_CATEGORY_PERUSER
,
1672 .name
= L
"DocumentsLibrary",
1673 .parent
= &FOLDERID_Libraries
,
1674 .path
= L
"Documents.library-ms",
1675 .parsing
= L
"::{031E4825-7B94-4dc3-B131-E946B44C8DD5}\\{7b0db17d-9cd2-4a93-9733-46cc89022e7c}",
1676 .flags
= KFDF_PRECREATE
| KFDF_STREAM
,
1678 { /* 0x47 - CSIDL_DOWNLOADS */
1679 .id
= &FOLDERID_Downloads
,
1680 .type
= CSIDL_Type_User
,
1681 .category
= KF_CATEGORY_PERUSER
,
1682 .name
= L
"Downloads",
1683 .parent
= &FOLDERID_Profile
,
1684 .path
= L
"Downloads",
1685 .attributes
= FILE_ATTRIBUTE_READONLY
,
1686 .flags
= KFDF_ROAMABLE
| KFDF_PRECREATE
| KFDF_PUBLISHEXPANDEDPATH
,
1689 .id
= &FOLDERID_Games
,
1690 .type
= CSIDL_Type_Disallowed
,
1691 .category
= KF_CATEGORY_VIRTUAL
,
1693 .parsing
= L
"::{ED228FDF-9EA8-4870-83b1-96b02CFE0D52}",
1696 .id
= &FOLDERID_GameTasks
,
1697 .type
= CSIDL_Type_Disallowed
, /* FIXME */
1698 .category
= KF_CATEGORY_PERUSER
,
1699 .name
= L
"GameTasks",
1700 .parent
= &FOLDERID_LocalAppData
,
1701 .path
= L
"Microsoft\\Windows\\GameExplorer",
1702 .flags
= KFDF_LOCAL_REDIRECT_ONLY
,
1705 .id
= &FOLDERID_HomeGroup
,
1706 .type
= CSIDL_Type_Disallowed
,
1707 .category
= KF_CATEGORY_VIRTUAL
,
1708 .name
= L
"HomeGroupFolder",
1709 .parsing
= L
"::{B4FB3F98-C1EA-428d-A78A-D1F5659CBA93}",
1712 .id
= &FOLDERID_ImplicitAppShortcuts
,
1713 .type
= CSIDL_Type_Disallowed
, /* FIXME */
1714 .category
= KF_CATEGORY_PERUSER
,
1715 .name
= L
"ImplicitAppShortcuts",
1716 .parent
= &FOLDERID_UserPinned
,
1717 .path
= L
"ImplicitAppShortcuts",
1718 .flags
= KFDF_PRECREATE
,
1721 .id
= &FOLDERID_Libraries
,
1722 .type
= CSIDL_Type_Disallowed
, /* FIXME */
1723 .category
= KF_CATEGORY_PERUSER
,
1724 .name
= L
"Libraries",
1725 .parent
= &FOLDERID_RoamingAppData
,
1726 .path
= L
"Microsoft\\Windows\\Libraries",
1727 .flags
= KFDF_PRECREATE
| KFDF_PUBLISHEXPANDEDPATH
,
1729 { /* 0x4d - CSIDL_LINKS */
1730 .id
= &FOLDERID_Links
,
1731 .type
= CSIDL_Type_User
,
1732 .category
= KF_CATEGORY_PERUSER
,
1734 .parent
= &FOLDERID_Profile
,
1736 .parsing
= L
"::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{bfb9d5e0-c6a9-404c-b2b2-ae6db6af4968}",
1737 .attributes
= FILE_ATTRIBUTE_READONLY
,
1738 .flags
= KFDF_ROAMABLE
| KFDF_PRECREATE
| KFDF_PUBLISHEXPANDEDPATH
,
1740 { /* 0x4e - CSIDL_APPDATA_LOCALLOW */
1741 .id
= &FOLDERID_LocalAppDataLow
,
1742 .type
= CSIDL_Type_User
,
1743 .category
= KF_CATEGORY_PERUSER
,
1744 .name
= L
"LocalAppDataLow",
1745 .parent
= &FOLDERID_Profile
,
1746 .path
= L
"AppData\\LocalLow",
1747 .attributes
= FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
,
1748 .flags
= KFDF_LOCAL_REDIRECT_ONLY
| KFDF_PRECREATE
| KFDF_PUBLISHEXPANDEDPATH
,
1751 .id
= &FOLDERID_MusicLibrary
,
1752 .type
= CSIDL_Type_Disallowed
, /* FIXME */
1753 .category
= KF_CATEGORY_PERUSER
,
1754 .name
= L
"MusicLibrary",
1755 .parent
= &FOLDERID_Libraries
,
1756 .path
= L
"Music.library-ms",
1757 .parsing
= L
"::{031E4825-7B94-4dc3-B131-E946B44C8DD5}\\{2112AB0A-C86A-4ffe-A368-0DE96E47012E}",
1758 .flags
= KFDF_PRECREATE
| KFDF_STREAM
,
1761 .id
= &FOLDERID_OriginalImages
,
1762 .type
= CSIDL_Type_Disallowed
, /* FIXME */
1763 .category
= KF_CATEGORY_PERUSER
,
1764 .name
= L
"Original Images",
1765 .parent
= &FOLDERID_LocalAppData
,
1766 .path
= L
"Microsoft\\Windows Photo Gallery\\Original Images",
1769 .id
= &FOLDERID_PhotoAlbums
,
1770 .type
= CSIDL_Type_User
,
1771 .category
= KF_CATEGORY_PERUSER
,
1772 .name
= L
"PhotoAlbums",
1773 .parent
= &FOLDERID_Pictures
,
1774 .path
= L
"Slide Shows",
1775 .attributes
= FILE_ATTRIBUTE_READONLY
,
1778 .id
= &FOLDERID_PicturesLibrary
,
1779 .type
= CSIDL_Type_Disallowed
, /* FIXME */
1780 .category
= KF_CATEGORY_PERUSER
,
1781 .name
= L
"PicturesLibrary",
1782 .parent
= &FOLDERID_Libraries
,
1783 .path
= L
"Pictures.library-ms",
1784 .parsing
= L
"::{031E4825-7B94-4dc3-B131-E946B44C8DD5}\\{A990AE9F-A03B-4e80-94BC-9912D7504104}",
1785 .flags
= KFDF_PRECREATE
| KFDF_STREAM
,
1788 .id
= &FOLDERID_Playlists
,
1789 .type
= CSIDL_Type_User
,
1790 .category
= KF_CATEGORY_PERUSER
,
1791 .name
= L
"Playlists",
1792 .parent
= &FOLDERID_Music
,
1793 .path
= L
"Playlists",
1794 .attributes
= FILE_ATTRIBUTE_READONLY
,
1797 .id
= &FOLDERID_ProgramFilesX64
,
1799 .type
= CSIDL_Type_CurrVer
,
1800 .value
= L
"ProgramFilesDir",
1801 .def_path
= L
"Program Files",
1803 .type
= CSIDL_Type_NonExistent
,
1805 .category
= KF_CATEGORY_FIXED
,
1806 .name
= L
"ProgramFilesX64",
1809 .id
= &FOLDERID_ProgramFilesCommonX64
,
1811 .type
= CSIDL_Type_CurrVer
,
1812 .value
= L
"ProgramFilesCommonX64",
1813 .def_path
= L
"Program Files\\Common Files",
1815 .type
= CSIDL_Type_NonExistent
,
1817 .category
= KF_CATEGORY_FIXED
,
1818 .name
= L
"ProgramFilesCommonX64",
1821 .id
= &FOLDERID_Public
,
1822 .type
= CSIDL_Type_AllUsers
,
1823 .category
= KF_CATEGORY_FIXED
,
1825 .parsing
= L
"::{4336a54d-038b-4685-ab02-99bb52d3fb8b}",
1826 .attributes
= FILE_ATTRIBUTE_READONLY
,
1827 .flags
= KFDF_PRECREATE
,
1830 .id
= &FOLDERID_PublicDownloads
,
1831 .type
= CSIDL_Type_AllUsers
,
1832 .category
= KF_CATEGORY_COMMON
,
1833 .name
= L
"CommonDownloads",
1834 .parent
= &FOLDERID_Public
,
1835 .path
= L
"Downloads",
1836 .attributes
= FILE_ATTRIBUTE_READONLY
,
1837 .flags
= KFDF_PRECREATE
,
1840 .id
= &FOLDERID_PublicGameTasks
,
1841 .type
= CSIDL_Type_ProgramData
,
1842 .category
= KF_CATEGORY_COMMON
,
1843 .name
= L
"PublicGameTasks",
1844 .parent
= &FOLDERID_ProgramData
,
1845 .path
= L
"Microsoft\\Windows\\GameExplorer",
1846 .flags
= KFDF_LOCAL_REDIRECT_ONLY
,
1849 .id
= &FOLDERID_PublicLibraries
,
1850 .type
= CSIDL_Type_AllUsers
,
1851 .category
= KF_CATEGORY_COMMON
,
1852 .name
= L
"PublicLibraries",
1853 .parent
= &FOLDERID_Public
,
1854 .path
= L
"Libraries",
1855 .attributes
= FILE_ATTRIBUTE_READONLY
| FILE_ATTRIBUTE_HIDDEN
,
1856 .flags
= KFDF_PRECREATE
,
1859 .id
= &FOLDERID_PublicRingtones
,
1860 .type
= CSIDL_Type_ProgramData
,
1861 .category
= KF_CATEGORY_COMMON
,
1862 .name
= L
"CommonRingtones",
1863 .parent
= &FOLDERID_ProgramData
,
1864 .path
= L
"Microsoft\\Windows\\Ringtones",
1865 .flags
= KFDF_PRECREATE
,
1868 .id
= &FOLDERID_QuickLaunch
,
1869 .type
= CSIDL_Type_Disallowed
, /* FIXME */
1870 .category
= KF_CATEGORY_PERUSER
,
1871 .name
= L
"Quick Launch",
1872 .parent
= &FOLDERID_RoamingAppData
,
1873 .path
= L
"Microsoft\\Internet Explorer\\Quick Launch",
1876 .id
= &FOLDERID_RecordedTVLibrary
,
1877 .type
= CSIDL_Type_Disallowed
, /* FIXME */
1878 .category
= KF_CATEGORY_COMMON
,
1879 .name
= L
"RecordedTVLibrary",
1880 .parent
= &FOLDERID_PublicLibraries
,
1881 .path
= L
"RecordedTV.library-ms",
1882 .flags
= KFDF_PRECREATE
| KFDF_STREAM
,
1885 .id
= &FOLDERID_Ringtones
,
1886 .type
= CSIDL_Type_Disallowed
, /* FIXME */
1887 .category
= KF_CATEGORY_PERUSER
,
1888 .name
= L
"Ringtones",
1889 .parent
= &FOLDERID_LocalAppData
,
1890 .path
= L
"Microsoft\\Windows\\Ringtones",
1891 .flags
= KFDF_PRECREATE
,
1894 .id
= &FOLDERID_SampleMusic
,
1895 .type
= CSIDL_Type_AllUsers
,
1896 .category
= KF_CATEGORY_COMMON
,
1897 .name
= L
"SampleMusic",
1898 .parent
= &FOLDERID_PublicMusic
,
1899 .path
= L
"Sample Music",
1900 .attributes
= FILE_ATTRIBUTE_READONLY
,
1901 .flags
= KFDF_PRECREATE
,
1904 .id
= &FOLDERID_SamplePictures
,
1905 .type
= CSIDL_Type_AllUsers
,
1906 .category
= KF_CATEGORY_COMMON
,
1907 .name
= L
"SamplePictures",
1908 .parent
= &FOLDERID_PublicPictures
,
1909 .path
= L
"Sample Pictures",
1910 .attributes
= FILE_ATTRIBUTE_READONLY
,
1911 .flags
= KFDF_PRECREATE
,
1914 .id
= &FOLDERID_SamplePlaylists
,
1915 .type
= CSIDL_Type_AllUsers
,
1916 .category
= KF_CATEGORY_COMMON
,
1917 .name
= L
"SamplePlaylists",
1918 .parent
= &FOLDERID_PublicMusic
,
1919 .path
= L
"Sample Playlists",
1920 .attributes
= FILE_ATTRIBUTE_READONLY
,
1921 .flags
= KFDF_PRECREATE
,
1924 .id
= &FOLDERID_SampleVideos
,
1925 .type
= CSIDL_Type_AllUsers
,
1926 .category
= KF_CATEGORY_COMMON
,
1927 .name
= L
"SampleVideos",
1928 .parent
= &FOLDERID_PublicVideos
,
1929 .path
= L
"Sample Videos",
1930 .attributes
= FILE_ATTRIBUTE_READONLY
,
1931 .flags
= KFDF_PRECREATE
,
1933 { /* 0x62 - CSIDL_SAVED_GAMES */
1934 .id
= &FOLDERID_SavedGames
,
1935 .type
= CSIDL_Type_User
,
1936 .category
= KF_CATEGORY_PERUSER
,
1937 .name
= L
"SavedGames",
1938 .parent
= &FOLDERID_Profile
,
1939 .path
= L
"Saved Games",
1940 .parsing
= L
"::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{4C5C32FF-BB9D-43b0-B5B4-2D72E54EAAA4}",
1941 .attributes
= FILE_ATTRIBUTE_READONLY
,
1942 .flags
= KFDF_ROAMABLE
| KFDF_PRECREATE
| KFDF_PUBLISHEXPANDEDPATH
,
1944 { /* 0x63 - CSIDL_SEARCHES */
1945 .id
= &FOLDERID_SavedSearches
,
1946 .type
= CSIDL_Type_User
,
1947 .category
= KF_CATEGORY_PERUSER
,
1948 .name
= L
"Searches",
1949 .parent
= &FOLDERID_Profile
,
1950 .path
= L
"Searches",
1951 .parsing
= L
"::{59031a47-3f72-44a7-89c5-5595fe6b30ee}\\{7d1d3a04-debb-4115-95cf-2f29da2920da}",
1952 .attributes
= FILE_ATTRIBUTE_READONLY
,
1953 .flags
= KFDF_PRECREATE
| KFDF_PUBLISHEXPANDEDPATH
,
1956 .id
= &FOLDERID_SEARCH_CSC
,
1957 .type
= CSIDL_Type_Disallowed
,
1958 .category
= KF_CATEGORY_VIRTUAL
,
1959 .name
= L
"CSCFolder",
1960 .parsing
= L
"shell:::{BD7A2E7B-21CB-41b2-A086-B309680C6B7E}\\*",
1963 .id
= &FOLDERID_SEARCH_MAPI
,
1964 .type
= CSIDL_Type_Disallowed
,
1965 .category
= KF_CATEGORY_VIRTUAL
,
1966 .name
= L
"MAPIFolder",
1967 .parsing
= L
"shell:::{89D83576-6BD1-4C86-9454-BEB04E94C819}\\*",
1970 .id
= &FOLDERID_SearchHome
,
1971 .type
= CSIDL_Type_Disallowed
,
1972 .category
= KF_CATEGORY_VIRTUAL
,
1973 .name
= L
"SearchHomeFolder",
1974 .parsing
= L
"::{9343812e-1c37-4a49-a12e-4b2d810d956b}",
1977 .id
= &FOLDERID_SidebarDefaultParts
,
1978 .type
= CSIDL_Type_Disallowed
, /* FIXME */
1979 .category
= KF_CATEGORY_COMMON
,
1980 .name
= L
"Default Gadgets",
1981 .parent
= &FOLDERID_ProgramFiles
,
1982 .path
= L
"Windows Sidebar\\Gadgets",
1985 .id
= &FOLDERID_SidebarParts
,
1986 .type
= CSIDL_Type_Disallowed
, /* FIXME */
1987 .category
= KF_CATEGORY_PERUSER
,
1989 .parent
= &FOLDERID_LocalAppData
,
1990 .path
= L
"Microsoft\\Windows Sidebar\\Gadgets",
1993 .id
= &FOLDERID_SyncManagerFolder
,
1994 .type
= CSIDL_Type_Disallowed
,
1995 .category
= KF_CATEGORY_VIRTUAL
,
1996 .name
= L
"SyncCenterFolder",
1997 .parsing
= L
"::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}",
2000 .id
= &FOLDERID_SyncResultsFolder
,
2001 .type
= CSIDL_Type_Disallowed
,
2002 .category
= KF_CATEGORY_VIRTUAL
,
2003 .name
= L
"SyncResultsFolder",
2004 .parsing
= L
"::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\\::{BC48B32F-5910-47F5-8570-5074A8A5636A},",
2007 .id
= &FOLDERID_SyncSetupFolder
,
2008 .type
= CSIDL_Type_Disallowed
,
2009 .category
= KF_CATEGORY_VIRTUAL
,
2010 .name
= L
"SyncSetupFolder",
2011 .parsing
= L
"::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{9C73F5E5-7AE7-4E32-A8E8-8D23B85255BF}\\::{F1390A9A-A3F4-4E5D-9C5F-98F3BD8D935C},",
2014 .id
= &FOLDERID_UserPinned
,
2015 .type
= CSIDL_Type_Disallowed
, /* FIXME */
2016 .category
= KF_CATEGORY_PERUSER
,
2017 .name
= L
"User Pinned",
2018 .parent
= &FOLDERID_QuickLaunch
,
2019 .path
= L
"User Pinned",
2020 .attributes
= FILE_ATTRIBUTE_HIDDEN
,
2021 .flags
= KFDF_PRECREATE
,
2024 .id
= &FOLDERID_UserProfiles
,
2025 .type
= CSIDL_Type_CurrVer
,
2027 .def_path
= L
"Users",
2028 .category
= KF_CATEGORY_FIXED
,
2029 .name
= L
"UserProfiles",
2030 .attributes
= FILE_ATTRIBUTE_READONLY
,
2031 .flags
= KFDF_PRECREATE
,
2034 .id
= &FOLDERID_UserProgramFiles
,
2035 .type
= CSIDL_Type_Disallowed
, /* FIXME */
2036 .category
= KF_CATEGORY_PERUSER
,
2037 .name
= L
"UserProgramFiles",
2038 .parent
= &FOLDERID_LocalAppData
,
2039 .path
= L
"Programs",
2042 .id
= &FOLDERID_UserProgramFilesCommon
,
2043 .type
= CSIDL_Type_Disallowed
, /* FIXME */
2044 .category
= KF_CATEGORY_PERUSER
,
2045 .name
= L
"UserProgramFilesCommon",
2046 .parent
= &FOLDERID_UserProgramFiles
,
2050 .id
= &FOLDERID_UsersFiles
,
2051 .type
= CSIDL_Type_Disallowed
,
2052 .category
= KF_CATEGORY_VIRTUAL
,
2053 .name
= L
"UsersFilesFolder",
2054 .parsing
= L
"::{59031a47-3f72-44a7-89c5-5595fe6b30ee}",
2057 .id
= &FOLDERID_UsersLibraries
,
2058 .type
= CSIDL_Type_Disallowed
,
2059 .category
= KF_CATEGORY_VIRTUAL
,
2060 .name
= L
"UsersLibrariesFolder",
2061 .parsing
= L
"::{031E4825-7B94-4dc3-B131-E946B44C8DD5}",
2064 .id
= &FOLDERID_VideosLibrary
,
2065 .type
= CSIDL_Type_Disallowed
, /* FIXME */
2066 .category
= KF_CATEGORY_PERUSER
,
2067 .name
= L
"VideosLibrary",
2068 .path
= L
"Videos.library-ms",
2069 .parsing
= L
"::{031E4825-7B94-4dc3-B131-E946B44C8DD5}\\{491E922F-5643-4af4-A7EB-4E7A138D8174}",
2073 static int csidl_from_id( const KNOWNFOLDERID
*id
)
2076 for (i
= 0; i
< ARRAY_SIZE(CSIDL_Data
); i
++)
2077 if (IsEqualGUID( CSIDL_Data
[i
].id
, id
)) return i
;
2081 static HRESULT
_SHExpandEnvironmentStrings(LPCWSTR szSrc
, LPWSTR szDest
);
2083 /* Gets the value named value from the registry key
2084 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
2085 * (or from rootKey\userPrefix\... if userPrefix is not NULL) into path, which
2086 * is assumed to be MAX_PATH WCHARs in length.
2087 * If it exists, expands the value and writes the expanded value to
2088 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
2089 * Returns successful error code if the value was retrieved from the registry,
2090 * and a failure otherwise.
2092 static HRESULT
_SHGetUserShellFolderPath(HKEY rootKey
, LPCWSTR userPrefix
,
2093 LPCWSTR value
, LPWSTR path
)
2096 WCHAR shellFolderPath
[MAX_PATH
], userShellFolderPath
[MAX_PATH
];
2097 LPCWSTR pShellFolderPath
, pUserShellFolderPath
;
2098 HKEY userShellFolderKey
, shellFolderKey
;
2099 DWORD dwType
, dwPathLen
;
2101 TRACE("%p,%s,%s,%p\n",rootKey
, debugstr_w(userPrefix
), debugstr_w(value
),
2106 lstrcpyW(shellFolderPath
, userPrefix
);
2107 PathAddBackslashW(shellFolderPath
);
2108 lstrcatW(shellFolderPath
, L
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders");
2109 pShellFolderPath
= shellFolderPath
;
2110 lstrcpyW(userShellFolderPath
, userPrefix
);
2111 PathAddBackslashW(userShellFolderPath
);
2112 lstrcatW(userShellFolderPath
, L
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders");
2113 pUserShellFolderPath
= userShellFolderPath
;
2117 pUserShellFolderPath
= L
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders";
2118 pShellFolderPath
= L
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
2121 if (RegCreateKeyW(rootKey
, pShellFolderPath
, &shellFolderKey
))
2123 TRACE("Failed to create %s\n", debugstr_w(pShellFolderPath
));
2126 if (RegCreateKeyW(rootKey
, pUserShellFolderPath
, &userShellFolderKey
))
2128 TRACE("Failed to create %s\n",
2129 debugstr_w(pUserShellFolderPath
));
2130 RegCloseKey(shellFolderKey
);
2134 dwPathLen
= MAX_PATH
* sizeof(WCHAR
);
2135 if (!RegQueryValueExW(userShellFolderKey
, value
, NULL
, &dwType
,
2136 (LPBYTE
)path
, &dwPathLen
) && (dwType
== REG_EXPAND_SZ
|| dwType
== REG_SZ
))
2140 path
[dwPathLen
/ sizeof(WCHAR
)] = '\0';
2141 if (dwType
== REG_EXPAND_SZ
&& path
[0] == '%')
2143 WCHAR szTemp
[MAX_PATH
];
2145 _SHExpandEnvironmentStrings(path
, szTemp
);
2146 lstrcpynW(path
, szTemp
, MAX_PATH
);
2148 ret
= RegSetValueExW(shellFolderKey
, value
, 0, REG_SZ
, (LPBYTE
)path
,
2149 (lstrlenW(path
) + 1) * sizeof(WCHAR
));
2150 if (ret
!= ERROR_SUCCESS
)
2151 hr
= HRESULT_FROM_WIN32(ret
);
2157 RegCloseKey(shellFolderKey
);
2158 RegCloseKey(userShellFolderKey
);
2159 TRACE("returning 0x%08lx\n", hr
);
2163 static void append_relative_path(BYTE folder
, WCHAR
*pszPath
)
2165 if (CSIDL_Data
[folder
].path
)
2167 PathAddBackslashW(pszPath
);
2168 lstrcatW(pszPath
, CSIDL_Data
[folder
].path
);
2170 else if (CSIDL_Data
[folder
].def_path
)
2172 PathAddBackslashW(pszPath
);
2173 lstrcatW(pszPath
, CSIDL_Data
[folder
].def_path
);
2177 /* Gets a 'semi-expanded' default value of the CSIDL with index folder into
2178 * pszPath, based on the entries in CSIDL_Data. By semi-expanded, I mean:
2179 * - Depending on the entry's type, the path may begin with an (unexpanded)
2180 * environment variable name. The caller is responsible for expanding
2181 * environment strings if so desired.
2182 * The types that are prepended with environment variables are:
2183 * CSIDL_Type_User: %USERPROFILE%
2184 * CSIDL_Type_AllUsers: %ALLUSERSPROFILE%
2185 * CSIDL_Type_CurrVer: %SystemDrive%
2186 * (Others might make sense too, but as yet are unneeded.)
2188 static HRESULT
_SHGetDefaultValue(BYTE folder
, LPWSTR pszPath
)
2192 TRACE("0x%02x,%p\n", folder
, pszPath
);
2194 if (folder
>= ARRAY_SIZE(CSIDL_Data
))
2195 return E_INVALIDARG
;
2198 return E_INVALIDARG
;
2206 case CSIDL_PROGRAM_FILES
:
2207 case CSIDL_PROGRAM_FILESX86
:
2208 IsWow64Process( GetCurrentProcess(), &is_wow64
);
2209 folder
= is_wow64
? CSIDL_PROGRAM_FILESX86
: CSIDL_PROGRAM_FILES
;
2211 case CSIDL_PROGRAM_FILES_COMMON
:
2212 case CSIDL_PROGRAM_FILES_COMMONX86
:
2213 IsWow64Process( GetCurrentProcess(), &is_wow64
);
2214 folder
= is_wow64
? CSIDL_PROGRAM_FILES_COMMONX86
: CSIDL_PROGRAM_FILES_COMMON
;
2219 if (!CSIDL_Data
[folder
].parent
)
2221 /* hit the root, sub in env var */
2222 switch (CSIDL_Data
[folder
].type
)
2224 case CSIDL_Type_User
:
2225 lstrcpyW(pszPath
, L
"%USERPROFILE%");
2227 case CSIDL_Type_AllUsers
:
2228 lstrcpyW(pszPath
, L
"%PUBLIC%");
2230 case CSIDL_Type_ProgramData
:
2231 lstrcpyW(pszPath
, L
"%ProgramData%");
2233 case CSIDL_Type_CurrVer
:
2234 lstrcpyW(pszPath
, L
"%SystemDrive%");
2237 ; /* no corresponding env. var, do nothing */
2241 /* prepend with parent */
2242 hr
= _SHGetDefaultValue(csidl_from_id(CSIDL_Data
[folder
].parent
), pszPath
);
2246 append_relative_path(folder
, pszPath
);
2248 TRACE("returning 0x%08lx\n", hr
);
2252 /* Gets the (unexpanded) value of the folder with index folder into pszPath.
2253 * The folder's type is assumed to be CSIDL_Type_CurrVer. Its default value
2254 * can be overridden in the HKLM\\Software\\Microsoft\\Windows\\CurrentVersion key.
2255 * If dwFlags has SHGFP_TYPE_DEFAULT set or if the value isn't overridden in
2256 * the registry, uses _SHGetDefaultValue to get the value.
2258 static HRESULT
_SHGetCurrentVersionPath(DWORD dwFlags
, BYTE folder
,
2263 TRACE("0x%08lx,0x%02x,%p\n", dwFlags
, folder
, pszPath
);
2265 if (folder
>= ARRAY_SIZE(CSIDL_Data
))
2266 return E_INVALIDARG
;
2267 if (CSIDL_Data
[folder
].type
!= CSIDL_Type_CurrVer
)
2268 return E_INVALIDARG
;
2270 return E_INVALIDARG
;
2272 if (dwFlags
& SHGFP_TYPE_DEFAULT
)
2273 hr
= _SHGetDefaultValue(folder
, pszPath
);
2278 if (RegCreateKeyW(HKEY_LOCAL_MACHINE
, L
"Software\\Microsoft\\Windows\\CurrentVersion", &hKey
))
2282 DWORD dwType
, dwPathLen
= MAX_PATH
* sizeof(WCHAR
);
2284 if (RegQueryValueExW(hKey
, CSIDL_Data
[folder
].value
, NULL
,
2285 &dwType
, (LPBYTE
)pszPath
, &dwPathLen
) ||
2286 (dwType
!= REG_SZ
&& dwType
!= REG_EXPAND_SZ
))
2288 hr
= _SHGetDefaultValue(folder
, pszPath
);
2289 dwType
= REG_EXPAND_SZ
;
2292 case CSIDL_PROGRAM_FILESX86
:
2293 case CSIDL_PROGRAM_FILES_COMMONX86
:
2294 /* these two should never be set on 32-bit setups */
2298 IsWow64Process( GetCurrentProcess(), &is_wow64
);
2299 if (!is_wow64
) break;
2303 RegSetValueExW(hKey
, CSIDL_Data
[folder
].value
, 0, dwType
,
2304 (LPBYTE
)pszPath
, (lstrlenW(pszPath
)+1)*sizeof(WCHAR
));
2309 pszPath
[dwPathLen
/ sizeof(WCHAR
)] = '\0';
2315 TRACE("returning 0x%08lx (output path is %s)\n", hr
, debugstr_w(pszPath
));
2319 static LPWSTR
_GetUserSidStringFromToken(HANDLE Token
)
2321 char InfoBuffer
[64];
2322 PTOKEN_USER UserInfo
;
2326 UserInfo
= (PTOKEN_USER
) InfoBuffer
;
2327 if (! GetTokenInformation(Token
, TokenUser
, InfoBuffer
, sizeof(InfoBuffer
),
2330 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
2332 UserInfo
= heap_alloc(InfoSize
);
2333 if (UserInfo
== NULL
)
2335 if (! GetTokenInformation(Token
, TokenUser
, UserInfo
, InfoSize
,
2338 heap_free(UserInfo
);
2343 if (! ConvertSidToStringSidW(UserInfo
->User
.Sid
, &SidStr
))
2346 if (UserInfo
!= (PTOKEN_USER
) InfoBuffer
)
2347 heap_free(UserInfo
);
2352 /* Gets the user's path (unexpanded) for the CSIDL with index folder:
2353 * If SHGFP_TYPE_DEFAULT is set, calls _SHGetDefaultValue for it. Otherwise
2354 * calls _SHGetUserShellFolderPath for it. Where it looks depends on hToken:
2355 * - if hToken is -1, looks in HKEY_USERS\.Default
2356 * - otherwise looks first in HKEY_CURRENT_USER, followed by HKEY_LOCAL_MACHINE
2357 * if HKEY_CURRENT_USER doesn't contain any entries. If both fail, finally
2358 * calls _SHGetDefaultValue for it.
2360 static HRESULT
_SHGetUserProfilePath(HANDLE hToken
, DWORD dwFlags
, BYTE folder
,
2363 const WCHAR
*szValueName
;
2367 TRACE("%p,0x%08lx,0x%02x,%p\n", hToken
, dwFlags
, folder
, pszPath
);
2369 if (folder
>= ARRAY_SIZE(CSIDL_Data
))
2370 return E_INVALIDARG
;
2371 if (CSIDL_Data
[folder
].type
!= CSIDL_Type_User
)
2372 return E_INVALIDARG
;
2374 return E_INVALIDARG
;
2376 if (dwFlags
& SHGFP_TYPE_DEFAULT
)
2378 if (hToken
!= NULL
&& hToken
!= (HANDLE
)-1)
2380 FIXME("unsupported for user other than current or default\n");
2383 hr
= _SHGetDefaultValue(folder
, pszPath
);
2387 static const WCHAR DefaultW
[] = L
".Default";
2388 LPCWSTR userPrefix
= NULL
;
2391 if (hToken
== (HANDLE
)-1)
2393 hRootKey
= HKEY_USERS
;
2394 userPrefix
= DefaultW
;
2396 else if (hToken
== NULL
)
2397 hRootKey
= HKEY_CURRENT_USER
;
2400 hRootKey
= HKEY_USERS
;
2401 userPrefix
= _GetUserSidStringFromToken(hToken
);
2402 if (userPrefix
== NULL
)
2409 /* For CSIDL_Type_User we also use the GUID if no szValueName is provided */
2410 szValueName
= CSIDL_Data
[folder
].value
;
2413 StringFromGUID2( CSIDL_Data
[folder
].id
, buffer
, 39 );
2414 szValueName
= &buffer
[0];
2417 hr
= _SHGetUserShellFolderPath(hRootKey
, userPrefix
, szValueName
, pszPath
);
2418 if (FAILED(hr
) && hRootKey
!= HKEY_LOCAL_MACHINE
)
2419 hr
= _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE
, NULL
, szValueName
, pszPath
);
2421 hr
= _SHGetDefaultValue(folder
, pszPath
);
2422 if (userPrefix
!= NULL
&& userPrefix
!= DefaultW
)
2423 LocalFree((HLOCAL
) userPrefix
);
2426 TRACE("returning 0x%08lx (output path is %s)\n", hr
, debugstr_w(pszPath
));
2430 /* Gets the (unexpanded) path for the CSIDL with index folder. If dwFlags has
2431 * SHGFP_TYPE_DEFAULT set, calls _SHGetDefaultValue. Otherwise calls
2432 * _SHGetUserShellFolderPath for it, looking only in HKEY_LOCAL_MACHINE.
2433 * If this fails, falls back to _SHGetDefaultValue.
2435 static HRESULT
_SHGetAllUsersProfilePath(DWORD dwFlags
, BYTE folder
,
2440 TRACE("0x%08lx,0x%02x,%p\n", dwFlags
, folder
, pszPath
);
2442 if (folder
>= ARRAY_SIZE(CSIDL_Data
))
2443 return E_INVALIDARG
;
2444 if (CSIDL_Data
[folder
].type
!= CSIDL_Type_AllUsers
&& CSIDL_Data
[folder
].type
!= CSIDL_Type_ProgramData
)
2445 return E_INVALIDARG
;
2447 return E_INVALIDARG
;
2449 if (dwFlags
& SHGFP_TYPE_DEFAULT
)
2450 hr
= _SHGetDefaultValue(folder
, pszPath
);
2453 hr
= _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE
, NULL
,
2454 CSIDL_Data
[folder
].value
, pszPath
);
2456 hr
= _SHGetDefaultValue(folder
, pszPath
);
2458 TRACE("returning 0x%08lx (output path is %s)\n", hr
, debugstr_w(pszPath
));
2462 static HRESULT
_SHOpenProfilesKey(PHKEY pKey
)
2467 lRet
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, L
"Software\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList", 0, NULL
, 0,
2468 KEY_ALL_ACCESS
, NULL
, pKey
, &disp
);
2469 return HRESULT_FROM_WIN32(lRet
);
2472 /* Reads the value named szValueName from the key profilesKey (assumed to be
2473 * opened by _SHOpenProfilesKey) into szValue, which is assumed to be MAX_PATH
2474 * WCHARs in length. If it doesn't exist, returns szDefault (and saves
2475 * szDefault to the registry).
2477 static HRESULT
_SHGetProfilesValue(HKEY profilesKey
, LPCWSTR szValueName
,
2478 LPWSTR szValue
, LPCWSTR szDefault
)
2481 DWORD type
, dwPathLen
= MAX_PATH
* sizeof(WCHAR
);
2484 TRACE("%p,%s,%p,%s\n", profilesKey
, debugstr_w(szValueName
), szValue
,
2485 debugstr_w(szDefault
));
2486 lRet
= RegQueryValueExW(profilesKey
, szValueName
, NULL
, &type
,
2487 (LPBYTE
)szValue
, &dwPathLen
);
2488 if (!lRet
&& (type
== REG_SZ
|| type
== REG_EXPAND_SZ
) && dwPathLen
2491 dwPathLen
/= sizeof(WCHAR
);
2492 szValue
[dwPathLen
] = '\0';
2497 /* Missing or invalid value, set a default */
2498 lstrcpynW(szValue
, szDefault
, MAX_PATH
);
2499 TRACE("Setting missing value %s to %s\n", debugstr_w(szValueName
),
2500 debugstr_w(szValue
));
2501 lRet
= RegSetValueExW(profilesKey
, szValueName
, 0, REG_EXPAND_SZ
,
2503 (lstrlenW(szValue
) + 1) * sizeof(WCHAR
));
2505 hr
= HRESULT_FROM_WIN32(lRet
);
2509 TRACE("returning 0x%08lx (output value is %s)\n", hr
, debugstr_w(szValue
));
2513 /* Attempts to expand environment variables from szSrc into szDest, which is
2514 * assumed to be MAX_PATH characters in length. Before referring to the
2515 * environment, handles a few variables directly, because the environment
2516 * variables may not be set when this is called (as during Wine's installation
2517 * when default values are being written to the registry).
2518 * The directly handled environment variables, and their source, are:
2519 * - ALLUSERSPROFILE, USERPROFILE: reads from the registry
2520 * - SystemDrive: uses GetSystemDirectoryW and uses the drive portion of its
2522 * If one of the directly handled environment variables is expanded, only
2523 * expands a single variable, and only in the beginning of szSrc.
2525 static HRESULT
_SHExpandEnvironmentStrings(LPCWSTR szSrc
, LPWSTR szDest
)
2528 WCHAR szTemp
[MAX_PATH
], szProfilesPrefix
[MAX_PATH
] = { 0 };
2531 TRACE("%s, %p\n", debugstr_w(szSrc
), szDest
);
2533 if (!szSrc
|| !szDest
) return E_INVALIDARG
;
2535 /* short-circuit if there's nothing to expand */
2536 if (szSrc
[0] != '%')
2538 lstrcpyW(szDest
, szSrc
);
2542 /* Get the profile prefix, we'll probably be needing it */
2543 hr
= _SHOpenProfilesKey(&key
);
2546 WCHAR def_val
[MAX_PATH
];
2548 /* get the system drive */
2549 GetSystemDirectoryW(def_val
, MAX_PATH
);
2550 lstrcpyW( def_val
+ 3, L
"users" );
2552 hr
= _SHGetProfilesValue(key
, L
"ProfilesDirectory", szProfilesPrefix
, def_val
);
2556 lstrcpyW(szTemp
, szSrc
);
2557 while (SUCCEEDED(hr
) && szTemp
[0] == '%')
2559 if (!wcsnicmp(szTemp
, L
"%ALLUSERSPROFILE%", lstrlenW(L
"%ALLUSERSPROFILE%")))
2561 WCHAR szAllUsers
[MAX_PATH
], def_val
[MAX_PATH
];
2563 GetSystemDirectoryW(def_val
, MAX_PATH
);
2564 lstrcpyW( def_val
+ 3, L
"users\\Public" );
2566 hr
= _SHGetProfilesValue(key
, L
"Public", szAllUsers
, def_val
);
2567 PathAppendW(szDest
, szAllUsers
);
2568 PathAppendW(szDest
, szTemp
+ lstrlenW(L
"%ALLUSERSPROFILE%"));
2570 else if (!wcsnicmp(szTemp
, L
"%PUBLIC%", lstrlenW(L
"%PUBLIC%")))
2572 WCHAR szAllUsers
[MAX_PATH
], def_val
[MAX_PATH
];
2574 GetSystemDirectoryW(def_val
, MAX_PATH
);
2575 lstrcpyW( def_val
+ 3, L
"users\\Public" );
2577 hr
= _SHGetProfilesValue(key
, L
"Public", szAllUsers
, def_val
);
2578 PathAppendW(szDest
, szAllUsers
);
2579 PathAppendW(szDest
, szTemp
+ lstrlenW(L
"%PUBLIC%"));
2581 else if (!wcsnicmp(szTemp
, L
"%ProgramData%", lstrlenW(L
"%ProgramData%")))
2583 WCHAR szProgramData
[MAX_PATH
], def_val
[MAX_PATH
];
2584 HKEY shellFolderKey
;
2585 DWORD dwType
, dwPathLen
= sizeof(def_val
);
2586 BOOL in_registry
= FALSE
;
2588 if (!RegCreateKeyW(HKEY_LOCAL_MACHINE
, L
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", &shellFolderKey
))
2590 if (!RegQueryValueExW(shellFolderKey
, L
"Common AppData", NULL
, &dwType
,
2591 (LPBYTE
)def_val
, &dwPathLen
) && (dwType
== REG_EXPAND_SZ
|| dwType
== REG_SZ
))
2594 RegCloseKey(shellFolderKey
);
2599 GetSystemDirectoryW(def_val
, MAX_PATH
);
2600 lstrcpyW( def_val
+ 3, L
"ProgramData" );
2603 hr
= _SHGetProfilesValue(key
, L
"ProgramData", szProgramData
, def_val
);
2604 PathAppendW(szDest
, szProgramData
);
2605 PathAppendW(szDest
, szTemp
+ lstrlenW(L
"%ProgramData%"));
2607 else if (!wcsnicmp(szTemp
, L
"%USERPROFILE%", lstrlenW(L
"%USERPROFILE%")))
2609 WCHAR userName
[MAX_PATH
];
2610 DWORD userLen
= MAX_PATH
;
2612 lstrcpyW(szDest
, szProfilesPrefix
);
2613 GetUserNameW(userName
, &userLen
);
2614 PathAppendW(szDest
, userName
);
2615 PathAppendW(szDest
, szTemp
+ lstrlenW(L
"%USERPROFILE%"));
2617 else if (!wcsnicmp(szTemp
, L
"%SystemDrive%", lstrlenW(L
"%SystemDrive%")))
2619 GetSystemDirectoryW(szDest
, MAX_PATH
);
2620 lstrcpyW(szDest
+ 3, szTemp
+ lstrlenW(L
"%SystemDrive%") + 1);
2624 DWORD ret
= ExpandEnvironmentStringsW(szTemp
, szDest
, MAX_PATH
);
2627 hr
= E_NOT_SUFFICIENT_BUFFER
;
2629 hr
= HRESULT_FROM_WIN32(GetLastError());
2630 else if (!wcscmp( szTemp
, szDest
)) break; /* nothing expanded */
2632 if (SUCCEEDED(hr
)) lstrcpyW(szTemp
, szDest
);
2637 TRACE("returning 0x%08lx (input was %s, output is %s)\n", hr
,
2638 debugstr_w(szSrc
), debugstr_w(szDest
));
2642 static char *xdg_config
;
2643 static DWORD xdg_config_len
;
2645 static BOOL WINAPI
init_xdg_dirs( INIT_ONCE
*once
, void *param
, void **context
)
2647 const WCHAR
*var
, *fmt
= L
"\\??\\unix%s/user-dirs.dirs";
2653 if (!(var
= _wgetenv( L
"XDG_CONFIG_HOME" )) || var
[0] != '/')
2655 if (!(var
= _wgetenv( L
"WINEHOMEDIR" ))) return TRUE
;
2656 fmt
= L
"%s/.config/user-dirs.dirs";
2658 len
= lstrlenW(var
) + lstrlenW(fmt
);
2659 name
= heap_alloc( len
* sizeof(WCHAR
) );
2660 swprintf( name
, len
, fmt
, var
);
2661 name
[1] = '\\'; /* change \??\ to \\?\ */
2662 for (ptr
= name
; *ptr
; ptr
++) if (*ptr
== '/') *ptr
= '\\';
2664 file
= CreateFileW( name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, 0 );
2666 if (file
!= INVALID_HANDLE_VALUE
)
2668 len
= GetFileSize( file
, NULL
);
2669 if (!(xdg_config
= heap_alloc( len
+ 1 ))) return TRUE
;
2670 if (!ReadFile( file
, xdg_config
, len
, &xdg_config_len
, NULL
))
2672 heap_free( xdg_config
);
2677 for (p
= xdg_config
; p
< xdg_config
+ xdg_config_len
; p
++) if (*p
== '\n') *p
= 0;
2678 *p
= 0; /* append null to simplify string parsing */
2680 CloseHandle( file
);
2685 static char *get_xdg_path( const char *var
)
2687 static INIT_ONCE once
;
2688 char *p
, *ret
= NULL
;
2691 InitOnceExecuteOnce( &once
, init_xdg_dirs
, NULL
, NULL
);
2692 if (!xdg_config
) return NULL
;
2694 for (p
= xdg_config
; p
< xdg_config
+ xdg_config_len
; p
+= strlen(p
) + 1)
2696 while (*p
== ' ' || *p
== '\t') p
++;
2697 if (strncmp( p
, var
, strlen(var
) )) continue;
2699 while (*p
== ' ' || *p
== '\t') p
++;
2700 if (*p
!= '=') continue;
2702 while (*p
== ' ' || *p
== '\t') p
++;
2703 if (*p
!= '"') continue;
2705 if (*p
!= '/' && strncmp( p
, "$HOME/", 6 )) continue;
2707 if (!(ret
= heap_alloc( strlen(p
) + 1 ))) break;
2708 for (i
= 0; *p
&& *p
!= '"'; i
++, p
++)
2710 if (*p
== '\\' && p
[1]) p
++;
2724 static BOOL
link_folder( HANDLE mgr
, const UNICODE_STRING
*path
, const char *link
)
2726 struct mountmgr_shell_folder
*ioctl
;
2727 DWORD len
= sizeof(*ioctl
) + path
->Length
+ strlen(link
) + 1;
2730 if (!(ioctl
= heap_alloc( len
))) return FALSE
;
2731 ioctl
->create_backup
= FALSE
;
2732 ioctl
->folder_offset
= sizeof(*ioctl
);
2733 ioctl
->folder_size
= path
->Length
;
2734 memcpy( (char *)ioctl
+ ioctl
->folder_offset
, path
->Buffer
, ioctl
->folder_size
);
2735 ioctl
->symlink_offset
= ioctl
->folder_offset
+ ioctl
->folder_size
;
2736 strcpy( (char *)ioctl
+ ioctl
->symlink_offset
, link
);
2738 ret
= DeviceIoControl( mgr
, IOCTL_MOUNTMGR_DEFINE_SHELL_FOLDER
, ioctl
, len
, NULL
, 0, NULL
, NULL
);
2743 /******************************************************************************
2746 * Sets up a symbolic link for one of the 'My Whatever' shell folders to point
2747 * into the corresponding XDG directory.
2749 static void create_link( const WCHAR
*path
, const char *xdg_name
, const char *default_name
)
2751 UNICODE_STRING nt_name
;
2752 char *target
= NULL
;
2755 if ((mgr
= CreateFileW( MOUNTMGR_DOS_DEVICE_NAME
, GENERIC_READ
| GENERIC_WRITE
,
2756 FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
2757 0, 0 )) == INVALID_HANDLE_VALUE
)
2759 FIXME( "failed to connect to mount manager\n" );
2763 nt_name
.Buffer
= NULL
;
2764 if (!RtlDosPathNameToNtPathName_U( path
, &nt_name
, NULL
, NULL
)) goto done
;
2766 if ((target
= get_xdg_path( xdg_name
)))
2768 if (link_folder( mgr
, &nt_name
, target
)) goto done
;
2770 if (link_folder( mgr
, &nt_name
, default_name
)) goto done
;
2772 /* fall back to HOME */
2773 link_folder( mgr
, &nt_name
, "$HOME" );
2776 RtlFreeUnicodeString( &nt_name
);
2777 heap_free( target
);
2781 /******************************************************************************
2782 * _SHCreateSymbolicLink [Internal]
2784 * Sets up a symbolic link for one of the special shell folders to point into
2785 * the users home directory.
2788 * nFolder [I] CSIDL identifying the folder.
2790 static void _SHCreateSymbolicLink(int nFolder
, const WCHAR
*path
)
2792 DWORD folder
= nFolder
& CSIDL_FOLDER_MASK
;
2795 case CSIDL_PERSONAL
:
2796 create_link( path
, "XDG_DOCUMENTS_DIR", "$HOME/Documents" );
2798 case CSIDL_DESKTOPDIRECTORY
:
2799 create_link( path
, "XDG_DESKTOP_DIR", "$HOME/Desktop" );
2801 case CSIDL_MYPICTURES
:
2802 create_link( path
, "XDG_PICTURES_DIR", "$HOME/Pictures" );
2805 create_link( path
, "XDG_VIDEOS_DIR", "$HOME/Movies" );
2808 create_link( path
, "XDG_MUSIC_DIR", "$HOME/Music" );
2810 case CSIDL_DOWNLOADS
:
2811 create_link( path
, "XDG_DOWNLOAD_DIR", "$HOME/Downloads" );
2813 case CSIDL_TEMPLATES
:
2814 create_link( path
, "XDG_TEMPLATES_DIR", "$HOME/Templates" );
2819 /******************************************************************************
2820 * SHGetFolderPathW [SHELL32.@]
2822 * Convert nFolder to path.
2826 * Failure: standard HRESULT error codes.
2829 * Most values can be overridden in either
2830 * HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
2831 * or in the same location in HKLM.
2832 * The "Shell Folders" registry key was used in NT4 and earlier systems.
2833 * Beginning with Windows 2000, the "User Shell Folders" key is used, so
2834 * changes made to it are made to the former key too. This synchronization is
2835 * done on-demand: not until someone requests the value of one of these paths
2836 * (by calling one of the SHGet functions) is the value synchronized.
2837 * Furthermore, the HKCU paths take precedence over the HKLM paths.
2839 HRESULT WINAPI
SHGetFolderPathW(
2840 HWND hwndOwner
, /* [I] owner window */
2841 int nFolder
, /* [I] CSIDL identifying the folder */
2842 HANDLE hToken
, /* [I] access token */
2843 DWORD dwFlags
, /* [I] which path to return */
2844 LPWSTR pszPath
) /* [O] converted path */
2846 HRESULT hr
= SHGetFolderPathAndSubDirW(hwndOwner
, nFolder
, hToken
, dwFlags
, NULL
, pszPath
);
2847 if(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
) == hr
)
2848 hr
= HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
2852 HRESULT WINAPI
SHGetFolderPathAndSubDirA(
2853 HWND hwndOwner
, /* [I] owner window */
2854 int nFolder
, /* [I] CSIDL identifying the folder */
2855 HANDLE hToken
, /* [I] access token */
2856 DWORD dwFlags
, /* [I] which path to return */
2857 LPCSTR pszSubPath
, /* [I] sub directory of the specified folder */
2858 LPSTR pszPath
) /* [O] converted path */
2862 LPWSTR pszSubPathW
= NULL
;
2863 LPWSTR pszPathW
= NULL
;
2865 TRACE("%p,%#x,%p,%#lx,%s,%p\n", hwndOwner
, nFolder
, hToken
, dwFlags
, debugstr_a(pszSubPath
), pszPath
);
2868 pszPathW
= heap_alloc(MAX_PATH
* sizeof(WCHAR
));
2870 hr
= HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY
);
2874 TRACE("%08x,%08lx,%s\n",nFolder
, dwFlags
, debugstr_w(pszSubPathW
));
2876 /* SHGetFolderPathAndSubDirW does not distinguish if pszSubPath isn't
2877 * set (null), or an empty string.therefore call it without the parameter set
2878 * if pszSubPath is an empty string
2880 if (pszSubPath
&& pszSubPath
[0]) {
2881 length
= MultiByteToWideChar(CP_ACP
, 0, pszSubPath
, -1, NULL
, 0);
2882 pszSubPathW
= heap_alloc(length
* sizeof(WCHAR
));
2884 hr
= HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY
);
2887 MultiByteToWideChar(CP_ACP
, 0, pszSubPath
, -1, pszSubPathW
, length
);
2890 hr
= SHGetFolderPathAndSubDirW(hwndOwner
, nFolder
, hToken
, dwFlags
, pszSubPathW
, pszPathW
);
2892 if (SUCCEEDED(hr
) && pszPath
)
2893 WideCharToMultiByte(CP_ACP
, 0, pszPathW
, -1, pszPath
, MAX_PATH
, NULL
, NULL
);
2896 heap_free(pszPathW
);
2897 heap_free(pszSubPathW
);
2901 /*************************************************************************
2902 * SHGetFolderPathAndSubDirW [SHELL32.@]
2904 HRESULT WINAPI
SHGetFolderPathAndSubDirW(
2905 HWND hwndOwner
, /* [I] owner window */
2906 int nFolder
, /* [I] CSIDL identifying the folder */
2907 HANDLE hToken
, /* [I] access token */
2908 DWORD dwFlags
, /* [I] which path to return */
2909 LPCWSTR pszSubPath
,/* [I] sub directory of the specified folder */
2910 LPWSTR pszPath
) /* [O] converted path */
2913 WCHAR szBuildPath
[MAX_PATH
], szTemp
[MAX_PATH
];
2914 DWORD folder
= nFolder
& CSIDL_FOLDER_MASK
;
2918 TRACE("%p,%#x,%p,%#lx,%s,%p\n", hwndOwner
, nFolder
, hToken
, dwFlags
, debugstr_w(pszSubPath
), pszPath
);
2920 /* Windows always NULL-terminates the resulting path regardless of success
2921 * or failure, so do so first
2926 if (folder
>= ARRAY_SIZE(CSIDL_Data
))
2927 return E_INVALIDARG
;
2928 if ((SHGFP_TYPE_CURRENT
!= dwFlags
) && (SHGFP_TYPE_DEFAULT
!= dwFlags
))
2929 return E_INVALIDARG
;
2931 type
= CSIDL_Data
[folder
].type
;
2934 case CSIDL_Type_Disallowed
:
2937 case CSIDL_Type_NonExistent
:
2940 case CSIDL_Type_WindowsPath
:
2941 GetWindowsDirectoryW(szTemp
, MAX_PATH
);
2942 append_relative_path(folder
, szTemp
);
2945 case CSIDL_Type_SystemPath
:
2946 GetSystemDirectoryW(szTemp
, MAX_PATH
);
2947 append_relative_path(folder
, szTemp
);
2950 case CSIDL_Type_SystemX86Path
:
2951 if (!GetSystemWow64DirectoryW(szTemp
, MAX_PATH
)) GetSystemDirectoryW(szTemp
, MAX_PATH
);
2952 append_relative_path(folder
, szTemp
);
2955 case CSIDL_Type_CurrVer
:
2956 hr
= _SHGetCurrentVersionPath(dwFlags
, folder
, szTemp
);
2958 case CSIDL_Type_User
:
2959 hr
= _SHGetUserProfilePath(hToken
, dwFlags
, folder
, szTemp
);
2961 case CSIDL_Type_AllUsers
:
2962 case CSIDL_Type_ProgramData
:
2963 hr
= _SHGetAllUsersProfilePath(dwFlags
, folder
, szTemp
);
2966 FIXME("bogus type %d, please fix\n", type
);
2971 /* Expand environment strings if necessary */
2973 hr
= _SHExpandEnvironmentStrings(szTemp
, szBuildPath
);
2975 lstrcpyW(szBuildPath
, szTemp
);
2977 if (FAILED(hr
)) goto end
;
2980 /* make sure the new path does not exceed the buffer length
2981 * and remember to backslash and terminate it */
2982 if(MAX_PATH
< (lstrlenW(szBuildPath
) + lstrlenW(pszSubPath
) + 2)) {
2983 hr
= HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE
);
2986 PathAppendW(szBuildPath
, pszSubPath
);
2987 PathRemoveBackslashW(szBuildPath
);
2989 /* Copy the path if it's available before we might return */
2990 if (SUCCEEDED(hr
) && pszPath
)
2991 lstrcpyW(pszPath
, szBuildPath
);
2993 /* if we don't care about existing directories we are ready */
2994 if(nFolder
& CSIDL_FLAG_DONT_VERIFY
) goto end
;
2996 if (PathFileExistsW(szBuildPath
)) goto end
;
2998 /* not existing but we are not allowed to create it. The return value
2999 * is verified against shell32 version 6.0.
3001 if (!(nFolder
& CSIDL_FLAG_CREATE
))
3003 hr
= HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
);
3007 /* create symbolic links rather than directories for specific
3008 * user shell folders */
3009 _SHCreateSymbolicLink(folder
, szBuildPath
);
3011 /* create directory/directories */
3012 ret
= SHCreateDirectoryExW(hwndOwner
, szBuildPath
, NULL
);
3013 if (ret
&& ret
!= ERROR_ALREADY_EXISTS
)
3015 ERR("Failed to create directory %s.\n", debugstr_w(szBuildPath
));
3020 TRACE("Created missing system directory %s\n", debugstr_w(szBuildPath
));
3022 TRACE("returning 0x%08lx (final path is %s)\n", hr
, debugstr_w(szBuildPath
));
3026 /*************************************************************************
3027 * SHGetFolderPathA [SHELL32.@]
3029 * See SHGetFolderPathW.
3031 HRESULT WINAPI
SHGetFolderPathA(
3038 WCHAR szTemp
[MAX_PATH
];
3041 TRACE("%p,%d,%p,%#lx,%p\n", hwndOwner
, nFolder
, hToken
, dwFlags
, pszPath
);
3045 hr
= SHGetFolderPathW(hwndOwner
, nFolder
, hToken
, dwFlags
, szTemp
);
3046 if (SUCCEEDED(hr
) && pszPath
)
3047 WideCharToMultiByte(CP_ACP
, 0, szTemp
, -1, pszPath
, MAX_PATH
, NULL
,
3053 /* For each folder in folders, if its value has not been set in the registry,
3054 * calls _SHGetUserProfilePath or _SHGetAllUsersProfilePath (depending on the
3055 * folder's type) to get the unexpanded value first.
3056 * Writes the unexpanded value to User Shell Folders, and queries it with
3057 * SHGetFolderPathW to force the creation of the directory if it doesn't
3058 * already exist. SHGetFolderPathW also returns the expanded value, which
3059 * this then writes to Shell Folders.
3061 static HRESULT
_SHRegisterFolders(HKEY hRootKey
, HANDLE hToken
,
3062 LPCWSTR szUserShellFolderPath
, LPCWSTR szShellFolderPath
, const UINT folders
[],
3065 const WCHAR
*szValueName
;
3068 WCHAR path
[MAX_PATH
];
3070 HKEY hUserKey
= NULL
, hKey
= NULL
;
3071 DWORD dwType
, dwPathLen
;
3074 TRACE("%p,%p,%s,%p,%u\n", hRootKey
, hToken
,
3075 debugstr_w(szUserShellFolderPath
), folders
, foldersLen
);
3077 ret
= RegCreateKeyW(hRootKey
, szUserShellFolderPath
, &hUserKey
);
3079 hr
= HRESULT_FROM_WIN32(ret
);
3082 ret
= RegCreateKeyW(hRootKey
, szShellFolderPath
, &hKey
);
3084 hr
= HRESULT_FROM_WIN32(ret
);
3086 for (i
= 0; SUCCEEDED(hr
) && i
< foldersLen
; i
++)
3088 dwPathLen
= MAX_PATH
* sizeof(WCHAR
);
3090 /* For CSIDL_Type_User we also use the GUID if no szValueName is provided */
3091 szValueName
= CSIDL_Data
[folders
[i
]].value
;
3092 if (!szValueName
&& CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_User
)
3094 StringFromGUID2( CSIDL_Data
[folders
[i
]].id
, buffer
, 39 );
3095 szValueName
= &buffer
[0];
3098 if (RegQueryValueExW(hUserKey
, szValueName
, NULL
,
3099 &dwType
, (LPBYTE
)path
, &dwPathLen
) || (dwType
!= REG_SZ
&&
3100 dwType
!= REG_EXPAND_SZ
))
3103 if (CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_User
)
3104 _SHGetUserProfilePath(hToken
, SHGFP_TYPE_DEFAULT
, folders
[i
],
3106 else if (CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_AllUsers
||
3107 CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_ProgramData
)
3108 _SHGetAllUsersProfilePath(SHGFP_TYPE_DEFAULT
, folders
[i
], path
);
3109 else if (CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_WindowsPath
)
3111 GetWindowsDirectoryW(path
, MAX_PATH
);
3112 append_relative_path(folders
[i
], path
);
3118 ret
= RegSetValueExW(hUserKey
, szValueName
, 0, REG_EXPAND_SZ
,
3119 (LPBYTE
)path
, (lstrlenW(path
) + 1) * sizeof(WCHAR
));
3121 hr
= HRESULT_FROM_WIN32(ret
);
3124 hr
= SHGetFolderPathW(NULL
, folders
[i
] | CSIDL_FLAG_CREATE
,
3125 hToken
, SHGFP_TYPE_DEFAULT
, path
);
3126 ret
= RegSetValueExW(hKey
, szValueName
, 0, REG_SZ
,
3127 (LPBYTE
)path
, (lstrlenW(path
) + 1) * sizeof(WCHAR
));
3129 hr
= HRESULT_FROM_WIN32(ret
);
3135 /* create the default dir, which may be different from the path
3136 * stored in the registry. */
3137 SHGetFolderPathW(NULL
, folders
[i
] | CSIDL_FLAG_CREATE
,
3138 hToken
, SHGFP_TYPE_DEFAULT
, path
);
3142 RegCloseKey(hUserKey
);
3146 TRACE("returning 0x%08lx\n", hr
);
3150 static HRESULT
_SHRegisterUserShellFolders(BOOL bDefault
)
3152 static const UINT folders
[] = {
3163 CSIDL_DESKTOPDIRECTORY
,
3167 CSIDL_LOCAL_APPDATA
,
3168 CSIDL_INTERNET_CACHE
,
3177 CSIDL_APPDATA_LOCALLOW
,
3181 WCHAR userShellFolderPath
[MAX_PATH
], shellFolderPath
[MAX_PATH
];
3182 LPCWSTR pUserShellFolderPath
, pShellFolderPath
;
3187 TRACE("%s\n", bDefault
? "TRUE" : "FALSE");
3190 hToken
= (HANDLE
)-1;
3191 hRootKey
= HKEY_USERS
;
3192 lstrcpyW(userShellFolderPath
, L
".Default");
3193 PathAddBackslashW(userShellFolderPath
);
3194 lstrcatW(userShellFolderPath
, L
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders");
3195 pUserShellFolderPath
= userShellFolderPath
;
3196 lstrcpyW(shellFolderPath
, L
".Default");
3197 PathAddBackslashW(shellFolderPath
);
3198 lstrcatW(shellFolderPath
, L
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders");
3199 pShellFolderPath
= shellFolderPath
;
3204 hRootKey
= HKEY_CURRENT_USER
;
3205 pUserShellFolderPath
= L
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders";
3206 pShellFolderPath
= L
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
3209 hr
= _SHRegisterFolders(hRootKey
, hToken
, pUserShellFolderPath
,
3210 pShellFolderPath
, folders
, ARRAY_SIZE(folders
));
3211 TRACE("returning 0x%08lx\n", hr
);
3215 static HRESULT
_SHRegisterCommonShellFolders(void)
3217 static const UINT folders
[] = {
3218 CSIDL_COMMON_STARTMENU
,
3219 CSIDL_COMMON_PROGRAMS
,
3220 CSIDL_COMMON_STARTUP
,
3221 CSIDL_COMMON_DESKTOPDIRECTORY
,
3222 CSIDL_COMMON_FAVORITES
,
3223 CSIDL_COMMON_APPDATA
,
3224 CSIDL_COMMON_TEMPLATES
,
3225 CSIDL_COMMON_DOCUMENTS
,
3226 CSIDL_COMMON_ADMINTOOLS
,
3228 CSIDL_COMMON_PICTURES
,
3234 hr
= _SHRegisterFolders(HKEY_LOCAL_MACHINE
, NULL
,
3235 L
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders",
3236 L
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
3237 folders
, ARRAY_SIZE(folders
));
3238 TRACE("returning 0x%08lx\n", hr
);
3242 /******************************************************************************
3243 * create_extra_folders [Internal]
3245 * Create some extra folders that don't have a standard CSIDL definition.
3247 static HRESULT
create_extra_folders(void)
3249 WCHAR path
[MAX_PATH
+5];
3252 DWORD type
, size
, ret
;
3254 ret
= RegCreateKeyW( HKEY_CURRENT_USER
, L
"Environment", &hkey
);
3255 if (ret
) return HRESULT_FROM_WIN32( ret
);
3257 /* FIXME: should be under AppData, but we don't want spaces in the temp path */
3258 hr
= SHGetFolderPathAndSubDirW( 0, CSIDL_PROFILE
| CSIDL_FLAG_CREATE
, NULL
,
3259 SHGFP_TYPE_DEFAULT
, L
"Temp", path
);
3262 size
= sizeof(path
);
3263 if (RegQueryValueExW( hkey
, L
"TEMP", NULL
, &type
, (LPBYTE
)path
, &size
))
3264 RegSetValueExW( hkey
, L
"TEMP", 0, REG_SZ
, (LPBYTE
)path
, (lstrlenW(path
) + 1) * sizeof(WCHAR
) );
3265 size
= sizeof(path
);
3266 if (RegQueryValueExW( hkey
, L
"TMP", NULL
, &type
, (LPBYTE
)path
, &size
))
3267 RegSetValueExW( hkey
, L
"TMP", 0, REG_SZ
, (LPBYTE
)path
, (lstrlenW(path
) + 1) * sizeof(WCHAR
) );
3269 RegCloseKey( hkey
);
3273 hr
= SHGetFolderPathAndSubDirW( 0, CSIDL_COMMON_APPDATA
| CSIDL_FLAG_CREATE
, NULL
,
3274 SHGFP_TYPE_DEFAULT
, L
"Microsoft", path
);
3278 hr
= SHGetFolderPathAndSubDirW(0, CSIDL_APPDATA
| CSIDL_FLAG_CREATE
, NULL
,
3279 SHGFP_TYPE_DEFAULT
, L
"Microsoft\\Windows\\Themes", path
);
3285 /******************************************************************************
3286 * set_folder_attributes
3288 * Set the various folder attributes registry keys.
3290 static HRESULT
set_folder_attributes(void)
3299 DWORD call_for_attr
;
3302 { &CLSID_UnixFolder
, TRUE
, FALSE
, FALSE
},
3303 { &CLSID_UnixDosFolder
, TRUE
, FALSE
, FALSE
,
3304 SFGAO_FILESYSANCESTOR
|SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
, SFGAO_FILESYSTEM
},
3305 { &CLSID_FolderShortcut
, FALSE
, FALSE
, FALSE
,
3306 SFGAO_FILESYSTEM
|SFGAO_FOLDER
|SFGAO_LINK
,
3307 SFGAO_HASSUBFOLDER
|SFGAO_FILESYSTEM
|SFGAO_FOLDER
|SFGAO_FILESYSANCESTOR
},
3308 { &CLSID_MyDocuments
, TRUE
, FALSE
, FALSE
,
3309 SFGAO_FILESYSANCESTOR
|SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
, SFGAO_FILESYSTEM
},
3310 { &CLSID_RecycleBin
, FALSE
, FALSE
, FALSE
,
3311 SFGAO_FOLDER
|SFGAO_DROPTARGET
|SFGAO_HASPROPSHEET
},
3312 { &CLSID_ControlPanel
, FALSE
, TRUE
, TRUE
,
3313 SFGAO_FOLDER
|SFGAO_HASSUBFOLDER
}
3317 WCHAR buffer
[39 + ARRAY_SIZE(L
"CLSID\\") + ARRAY_SIZE(L
"\\ShellFolder")];
3321 for (i
= 0; i
< ARRAY_SIZE(folders
); i
++)
3323 lstrcpyW( buffer
, L
"CLSID\\" );
3324 StringFromGUID2( folders
[i
].clsid
, buffer
+ lstrlenW(buffer
), 39 );
3325 lstrcatW( buffer
, L
"\\ShellFolder" );
3326 res
= RegCreateKeyExW( HKEY_CLASSES_ROOT
, buffer
, 0, NULL
, 0,
3327 KEY_READ
| KEY_WRITE
, NULL
, &hkey
, NULL
);
3328 if (res
) return HRESULT_FROM_WIN32( res
);
3329 if (folders
[i
].wfparsing
)
3330 res
= RegSetValueExW( hkey
, L
"WantsFORPARSING", 0, REG_SZ
, (const BYTE
*)L
"", sizeof(WCHAR
) );
3331 if (folders
[i
].wfdisplay
)
3332 res
= RegSetValueExW( hkey
, L
"WantsFORDISPLAY", 0, REG_SZ
, (const BYTE
*)L
"", sizeof(WCHAR
) );
3333 if (folders
[i
].hideasdel
)
3334 res
= RegSetValueExW( hkey
, L
"HideAsDeletePerUser", 0, REG_SZ
, (const BYTE
*)L
"", sizeof(WCHAR
) );
3335 if (folders
[i
].attr
)
3336 res
= RegSetValueExW( hkey
, L
"Attributes", 0, REG_DWORD
,
3337 (const BYTE
*)&folders
[i
].attr
, sizeof(DWORD
));
3338 if (folders
[i
].call_for_attr
)
3339 res
= RegSetValueExW( hkey
, L
"CallForAttributes", 0, REG_DWORD
,
3340 (const BYTE
*)&folders
[i
].call_for_attr
, sizeof(DWORD
));
3341 RegCloseKey( hkey
);
3346 /*************************************************************************
3347 * SHGetSpecialFolderPathA [SHELL32.@]
3349 BOOL WINAPI
SHGetSpecialFolderPathA (
3355 return SHGetFolderPathA(hwndOwner
, nFolder
+ (bCreate
? CSIDL_FLAG_CREATE
: 0), NULL
, 0,
3359 /*************************************************************************
3360 * SHGetSpecialFolderPathW
3362 BOOL WINAPI
SHGetSpecialFolderPathW (
3368 return SHGetFolderPathW(hwndOwner
, nFolder
+ (bCreate
? CSIDL_FLAG_CREATE
: 0), NULL
, 0,
3372 /*************************************************************************
3373 * SHGetSpecialFolderPath (SHELL32.175)
3375 BOOL WINAPI
SHGetSpecialFolderPathAW (
3382 if (SHELL_OsIsUnicode())
3383 return SHGetSpecialFolderPathW (hwndOwner
, szPath
, nFolder
, bCreate
);
3384 return SHGetSpecialFolderPathA (hwndOwner
, szPath
, nFolder
, bCreate
);
3387 /*************************************************************************
3388 * SHGetFolderLocation [SHELL32.@]
3390 * Gets the folder locations from the registry and creates a pidl.
3394 * nFolder [I] CSIDL_xxxxx
3395 * hToken [I] token representing user, or NULL for current user, or -1 for
3397 * dwReserved [I] must be zero
3398 * ppidl [O] PIDL of a special folder
3402 * Failure: Standard OLE-defined error result, S_FALSE or E_INVALIDARG
3405 * Creates missing reg keys and directories.
3406 * Mostly forwards to SHGetFolderPathW, but a few values of nFolder return
3407 * virtual folders that are handled here.
3409 HRESULT WINAPI
SHGetFolderLocation(
3414 LPITEMIDLIST
*ppidl
)
3416 HRESULT hr
= E_INVALIDARG
;
3418 TRACE("%p 0x%08x %p 0x%08lx %p\n",
3419 hwndOwner
, nFolder
, hToken
, dwReserved
, ppidl
);
3422 return E_INVALIDARG
;
3424 return E_INVALIDARG
;
3426 /* The virtual folders' locations are not user-dependent */
3428 switch (nFolder
& CSIDL_FOLDER_MASK
)
3431 *ppidl
= _ILCreateDesktop();
3434 case CSIDL_PERSONAL
:
3435 *ppidl
= _ILCreateMyDocuments();
3438 case CSIDL_INTERNET
:
3439 *ppidl
= _ILCreateIExplore();
3442 case CSIDL_CONTROLS
:
3443 *ppidl
= _ILCreateControlPanel();
3446 case CSIDL_PRINTERS
:
3447 *ppidl
= _ILCreatePrinters();
3450 case CSIDL_BITBUCKET
:
3451 *ppidl
= _ILCreateBitBucket();
3455 *ppidl
= _ILCreateMyComputer();
3459 *ppidl
= _ILCreateNetwork();
3464 WCHAR szPath
[MAX_PATH
];
3466 hr
= SHGetFolderPathW(hwndOwner
, nFolder
, hToken
,
3467 SHGFP_TYPE_CURRENT
, szPath
);
3472 TRACE("Value=%s\n", debugstr_w(szPath
));
3473 hr
= SHILCreateFromPathW(szPath
, ppidl
, &attributes
);
3475 else if (hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
))
3477 /* unlike SHGetFolderPath, SHGetFolderLocation in shell32
3478 * version 6.0 returns E_FAIL for nonexistent paths
3487 TRACE("-- (new pidl %p)\n",*ppidl
);
3491 /*************************************************************************
3492 * SHGetSpecialFolderLocation [SHELL32.@]
3495 * In NT5, SHGetSpecialFolderLocation needs the <winntdir>/Recent
3498 HRESULT WINAPI
SHGetSpecialFolderLocation(
3501 LPITEMIDLIST
* ppidl
)
3503 HRESULT hr
= E_INVALIDARG
;
3505 TRACE("(%p,0x%x,%p)\n", hwndOwner
,nFolder
,ppidl
);
3508 return E_INVALIDARG
;
3510 hr
= SHGetFolderLocation(hwndOwner
, nFolder
, NULL
, 0, ppidl
);
3514 /*************************************************************************
3515 * SHGetKnownFolderPath [SHELL32.@]
3517 HRESULT WINAPI
SHGetKnownFolderPath(REFKNOWNFOLDERID rfid
, DWORD flags
, HANDLE token
, WCHAR
**ret_path
)
3519 WCHAR pathW
[MAX_PATH
];
3521 int folder
= csidl_from_id(rfid
), shgfp_flags
;
3523 TRACE("%s, 0x%08lx, %p, %p\n", debugstr_guid(rfid
), flags
, token
, ret_path
);
3528 return HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND
);
3530 if (flags
& ~(KF_FLAG_CREATE
|KF_FLAG_SIMPLE_IDLIST
|KF_FLAG_DONT_UNEXPAND
|
3531 KF_FLAG_DONT_VERIFY
|KF_FLAG_NO_ALIAS
|KF_FLAG_INIT
|KF_FLAG_DEFAULT_PATH
|KF_FLAG_NOT_PARENT_RELATIVE
))
3533 FIXME("flags 0x%08lx not supported\n", flags
);
3534 return E_INVALIDARG
;
3537 if ((flags
& (KF_FLAG_DEFAULT_PATH
| KF_FLAG_NOT_PARENT_RELATIVE
)) == KF_FLAG_NOT_PARENT_RELATIVE
)
3539 WARN("Invalid flags mask %#lx.\n", flags
);
3540 return E_INVALIDARG
;
3543 if (flags
& KF_FLAG_NOT_PARENT_RELATIVE
)
3545 FIXME("Ignoring KF_FLAG_NOT_PARENT_RELATIVE.\n");
3546 flags
&= ~KF_FLAG_NOT_PARENT_RELATIVE
;
3549 folder
|= flags
& CSIDL_FLAG_MASK
;
3550 shgfp_flags
= flags
& KF_FLAG_DEFAULT_PATH
? SHGFP_TYPE_DEFAULT
: SHGFP_TYPE_CURRENT
;
3552 hr
= SHGetFolderPathAndSubDirW( 0, folder
, token
, shgfp_flags
, NULL
, pathW
);
3555 TRACE("Failed to get folder path, %#lx.\n", hr
);
3559 TRACE("Final path is %s, %#lx\n", debugstr_w(pathW
), hr
);
3561 *ret_path
= CoTaskMemAlloc((lstrlenW(pathW
) + 1) * sizeof(WCHAR
));
3563 return E_OUTOFMEMORY
;
3564 lstrcpyW(*ret_path
, pathW
);
3569 /*************************************************************************
3570 * SHGetFolderPathEx [SHELL32.@]
3572 HRESULT WINAPI
SHGetFolderPathEx(REFKNOWNFOLDERID rfid
, DWORD flags
, HANDLE token
, LPWSTR path
, DWORD len
)
3577 TRACE("%s, 0x%08lx, %p, %p, %lu\n", debugstr_guid(rfid
), flags
, token
, path
, len
);
3579 if (!path
|| !len
) return E_INVALIDARG
;
3581 hr
= SHGetKnownFolderPath( rfid
, flags
, token
, &buffer
);
3582 if (SUCCEEDED( hr
))
3584 if (lstrlenW( buffer
) + 1 > len
)
3586 CoTaskMemFree( buffer
);
3587 return HRESULT_FROM_WIN32( ERROR_INSUFFICIENT_BUFFER
);
3589 lstrcpyW( path
, buffer
);
3590 CoTaskMemFree( buffer
);
3596 * Internal function to convert known folder identifier to path of registry key
3597 * associated with known folder.
3600 * rfid [I] pointer to known folder identifier (may be NULL)
3601 * lpStringGuid [I] string with known folder identifier (used when rfid is NULL)
3602 * lpPath [O] place to store string address. String should be
3603 * later freed using HeapFree(GetProcessHeap(),0, ... )
3605 static HRESULT
get_known_folder_registry_path(
3606 REFKNOWNFOLDERID rfid
,
3607 LPWSTR lpStringGuid
,
3614 TRACE("(%s, %s, %p)\n", debugstr_guid(rfid
), debugstr_w(lpStringGuid
), lpPath
);
3617 StringFromGUID2(rfid
, sGuid
, ARRAY_SIZE(sGuid
));
3619 lstrcpyW(sGuid
, lpStringGuid
);
3621 length
= lstrlenW(L
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FolderDescriptions")+51;
3622 *lpPath
= heap_alloc(length
*sizeof(WCHAR
));
3628 lstrcpyW(*lpPath
, L
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FolderDescriptions\\");
3629 lstrcatW(*lpPath
, sGuid
);
3635 static HRESULT
get_known_folder_wstr(const WCHAR
*regpath
, const WCHAR
*value
, WCHAR
**out
)
3641 hr
= HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, regpath
, value
, RRF_RT_REG_SZ
, NULL
, NULL
, &size
));
3645 *out
= CoTaskMemAlloc(size
);
3647 return E_OUTOFMEMORY
;
3649 hr
= HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, regpath
, value
, RRF_RT_REG_SZ
, NULL
, *out
, &size
));
3651 CoTaskMemFree(*out
);
3658 static HRESULT
get_known_folder_dword(const WCHAR
*registryPath
, const WCHAR
*value
, DWORD
*out
)
3660 DWORD dwSize
= sizeof(DWORD
);
3662 return HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, registryPath
, value
, RRF_RT_DWORD
, &dwType
, out
, &dwSize
));
3666 * Internal function to get place where folder redirection information are stored.
3669 * rfid [I] pointer to known folder identifier (may be NULL)
3670 * rootKey [O] root key where the redirection information are stored
3671 * It can be HKLM for COMMON folders, and HKCU for PERUSER folders.
3673 static HRESULT
get_known_folder_redirection_place(
3674 REFKNOWNFOLDERID rfid
,
3678 LPWSTR lpRegistryPath
= NULL
;
3681 /* first, get known folder's category */
3682 hr
= get_known_folder_registry_path(rfid
, NULL
, &lpRegistryPath
);
3685 hr
= get_known_folder_dword(lpRegistryPath
, L
"Category", &category
);
3689 if(category
== KF_CATEGORY_COMMON
)
3691 *rootKey
= HKEY_LOCAL_MACHINE
;
3694 else if(category
== KF_CATEGORY_PERUSER
)
3696 *rootKey
= HKEY_CURRENT_USER
;
3703 heap_free(lpRegistryPath
);
3707 static HRESULT
get_known_folder_path_by_id(REFKNOWNFOLDERID folderId
, LPWSTR lpRegistryPath
, DWORD dwFlags
, LPWSTR
*ppszPath
);
3709 static HRESULT
redirect_known_folder(
3710 REFKNOWNFOLDERID rfid
,
3712 KF_REDIRECT_FLAGS flags
,
3713 LPCWSTR pszTargetPath
,
3715 KNOWNFOLDERID
const *pExclusion
,
3719 HKEY rootKey
= HKEY_LOCAL_MACHINE
, hKey
;
3721 LPWSTR lpRegistryPath
= NULL
, lpSrcPath
= NULL
;
3722 TRACE("(%s, %p, 0x%08x, %s, %d, %p, %p)\n", debugstr_guid(rfid
), hwnd
, flags
, debugstr_w(pszTargetPath
), cFolders
, pExclusion
, ppszError
);
3724 if (ppszError
) *ppszError
= NULL
;
3726 hr
= get_known_folder_registry_path(rfid
, NULL
, &lpRegistryPath
);
3729 hr
= get_known_folder_path_by_id(rfid
, lpRegistryPath
, 0, &lpSrcPath
);
3731 heap_free(lpRegistryPath
);
3733 /* get path to redirection storage */
3735 hr
= get_known_folder_redirection_place(rfid
, &rootKey
);
3737 /* write redirection information */
3739 hr
= HRESULT_FROM_WIN32(RegCreateKeyExW(rootKey
, L
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders", 0, NULL
, 0, KEY_WRITE
, NULL
, &hKey
, NULL
));
3743 StringFromGUID2(rfid
, sGuid
, ARRAY_SIZE(sGuid
));
3745 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, sGuid
, 0, REG_SZ
, (LPBYTE
)pszTargetPath
, (lstrlenW(pszTargetPath
)+1)*sizeof(WCHAR
)));
3750 /* make sure destination path exists */
3751 SHCreateDirectory(NULL
, pszTargetPath
);
3753 /* copy content if required */
3754 if(SUCCEEDED(hr
) && (flags
& KF_REDIRECT_COPY_CONTENTS
) )
3756 WCHAR srcPath
[MAX_PATH
+1], dstPath
[MAX_PATH
+1];
3757 SHFILEOPSTRUCTW fileOp
;
3759 ZeroMemory(srcPath
, sizeof(srcPath
));
3760 lstrcpyW(srcPath
, lpSrcPath
);
3761 lstrcatW(srcPath
, L
"\\*");
3763 ZeroMemory(dstPath
, sizeof(dstPath
));
3764 lstrcpyW(dstPath
, pszTargetPath
);
3766 ZeroMemory(&fileOp
, sizeof(fileOp
));
3768 if(flags
& KF_REDIRECT_DEL_SOURCE_CONTENTS
)
3769 fileOp
.wFunc
= FO_MOVE
;
3771 fileOp
.wFunc
= FO_COPY
;
3773 fileOp
.pFrom
= srcPath
;
3774 fileOp
.pTo
= dstPath
;
3775 fileOp
.fFlags
= FOF_NO_UI
;
3777 hr
= (SHFileOperationW(&fileOp
)==0 ? S_OK
: E_FAIL
);
3779 if(flags
& KF_REDIRECT_DEL_SOURCE_CONTENTS
)
3781 ZeroMemory(srcPath
, sizeof(srcPath
));
3782 lstrcpyW(srcPath
, lpSrcPath
);
3784 ZeroMemory(&fileOp
, sizeof(fileOp
));
3785 fileOp
.wFunc
= FO_DELETE
;
3786 fileOp
.pFrom
= srcPath
;
3787 fileOp
.fFlags
= FOF_NO_UI
;
3789 hr
= (SHFileOperationW(&fileOp
)==0 ? S_OK
: E_FAIL
);
3793 CoTaskMemFree(lpSrcPath
);
3801 IKnownFolder IKnownFolder_iface
;
3804 LPWSTR registryPath
;
3807 static inline struct knownfolder
*impl_from_IKnownFolder( IKnownFolder
*iface
)
3809 return CONTAINING_RECORD( iface
, struct knownfolder
, IKnownFolder_iface
);
3812 static ULONG WINAPI
knownfolder_AddRef(
3813 IKnownFolder
*iface
)
3815 struct knownfolder
*knownfolder
= impl_from_IKnownFolder( iface
);
3816 return InterlockedIncrement( &knownfolder
->refs
);
3819 static ULONG WINAPI
knownfolder_Release(
3820 IKnownFolder
*iface
)
3822 struct knownfolder
*knownfolder
= impl_from_IKnownFolder( iface
);
3823 LONG refs
= InterlockedDecrement( &knownfolder
->refs
);
3826 TRACE("destroying %p\n", knownfolder
);
3827 heap_free( knownfolder
->registryPath
);
3828 heap_free( knownfolder
);
3833 static HRESULT WINAPI
knownfolder_QueryInterface(
3834 IKnownFolder
*iface
,
3838 struct knownfolder
*This
= impl_from_IKnownFolder( iface
);
3840 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppv
);
3843 if ( IsEqualGUID( riid
, &IID_IKnownFolder
) ||
3844 IsEqualGUID( riid
, &IID_IUnknown
) )
3848 else if ( IsEqualGUID( riid
, &IID_IMarshal
) )
3850 TRACE("IID_IMarshal returning NULL.\n");
3851 return E_NOINTERFACE
;
3855 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
3856 return E_NOINTERFACE
;
3858 IKnownFolder_AddRef( iface
);
3862 static HRESULT
knownfolder_set_id(
3863 struct knownfolder
*knownfolder
,
3864 const KNOWNFOLDERID
*kfid
)
3869 TRACE("%s\n", debugstr_guid(kfid
));
3871 knownfolder
->id
= *kfid
;
3873 /* check is it registry-registered folder */
3874 hr
= get_known_folder_registry_path(kfid
, NULL
, &knownfolder
->registryPath
);
3876 hr
= HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_LOCAL_MACHINE
, knownfolder
->registryPath
, 0, 0, &hKey
));
3885 /* This known folder is not registered. To mark it, we set registryPath to NULL */
3886 heap_free(knownfolder
->registryPath
);
3887 knownfolder
->registryPath
= NULL
;
3894 static HRESULT WINAPI
knownfolder_GetId(
3895 IKnownFolder
*iface
,
3896 KNOWNFOLDERID
*pkfid
)
3898 struct knownfolder
*knownfolder
= impl_from_IKnownFolder( iface
);
3900 TRACE("%p\n", pkfid
);
3902 *pkfid
= knownfolder
->id
;
3906 static HRESULT WINAPI
knownfolder_GetCategory(
3907 IKnownFolder
*iface
,
3908 KF_CATEGORY
*pCategory
)
3910 struct knownfolder
*knownfolder
= impl_from_IKnownFolder(iface
);
3913 TRACE("%p, %p\n", knownfolder
, pCategory
);
3915 /* we cannot get a category for a folder which is not registered */
3916 if(!knownfolder
->registryPath
)
3920 hr
= get_known_folder_dword(knownfolder
->registryPath
, L
"Category", (DWORD
*)pCategory
);
3925 static HRESULT WINAPI
knownfolder_GetShellItem(
3926 IKnownFolder
*iface
,
3931 struct knownfolder
*knownfolder
= impl_from_IKnownFolder(iface
);
3932 TRACE("(%p, 0x%08lx, %s, %p)\n", knownfolder
, flags
, debugstr_guid(riid
), ppv
);
3933 return SHGetKnownFolderItem(&knownfolder
->id
, flags
, NULL
, riid
, ppv
);
3936 static HRESULT
get_known_folder_path(
3938 LPWSTR registryPath
,
3942 DWORD dwSize
, dwType
;
3943 WCHAR path
[MAX_PATH
] = {0};
3944 WCHAR parentGuid
[39];
3946 LPWSTR parentRegistryPath
, parentPath
;
3947 HKEY hRedirectionRootKey
= NULL
;
3949 TRACE("(%s, %p)\n", debugstr_w(registryPath
), ppszPath
);
3952 /* check if folder has parent */
3953 dwSize
= sizeof(parentGuid
);
3954 hr
= HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, registryPath
, L
"ParentFolder", RRF_RT_REG_SZ
, &dwType
, parentGuid
, &dwSize
));
3955 if(hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
)) hr
= S_FALSE
;
3959 /* get parent's known folder path (recursive) */
3960 hr
= get_known_folder_registry_path(NULL
, parentGuid
, &parentRegistryPath
);
3961 if(FAILED(hr
)) return hr
;
3963 hr
= get_known_folder_path(parentGuid
, parentRegistryPath
, &parentPath
);
3965 heap_free(parentRegistryPath
);
3969 lstrcatW(path
, parentPath
);
3970 lstrcatW(path
, L
"\\");
3972 heap_free(parentRegistryPath
);
3973 heap_free(parentPath
);
3976 /* check, if folder was redirected */
3978 hr
= get_known_folder_dword(registryPath
, L
"Category", &category
);
3982 if(category
== KF_CATEGORY_COMMON
)
3983 hRedirectionRootKey
= HKEY_LOCAL_MACHINE
;
3984 else if(category
== KF_CATEGORY_PERUSER
)
3985 hRedirectionRootKey
= HKEY_CURRENT_USER
;
3987 if(hRedirectionRootKey
)
3989 hr
= HRESULT_FROM_WIN32(RegGetValueW(hRedirectionRootKey
, L
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders", sFolderId
, RRF_RT_REG_SZ
, NULL
, NULL
, &dwSize
));
3993 *ppszPath
= CoTaskMemAlloc(dwSize
+(lstrlenW(path
)+1)*sizeof(WCHAR
));
3994 if(!*ppszPath
) hr
= E_OUTOFMEMORY
;
3999 lstrcpyW(*ppszPath
, path
);
4000 hr
= HRESULT_FROM_WIN32(RegGetValueW(hRedirectionRootKey
, L
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders", sFolderId
, RRF_RT_REG_SZ
, NULL
, *ppszPath
+ lstrlenW(path
), &dwSize
));
4006 /* no redirection, use previous way - read the relative path from folder definition */
4007 hr
= HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, registryPath
, L
"RelativePath", RRF_RT_REG_SZ
, &dwType
, NULL
, &dwSize
));
4011 *ppszPath
= CoTaskMemAlloc(dwSize
+(lstrlenW(path
)+1)*sizeof(WCHAR
));
4012 if(!*ppszPath
) hr
= E_OUTOFMEMORY
;
4017 lstrcpyW(*ppszPath
, path
);
4018 hr
= HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, registryPath
, L
"RelativePath", RRF_RT_REG_SZ
, &dwType
, *ppszPath
+ lstrlenW(path
), &dwSize
));
4023 TRACE("returning path: %s\n", debugstr_w(*ppszPath
));
4027 static HRESULT
get_known_folder_path_by_id(
4028 REFKNOWNFOLDERID folderId
,
4029 LPWSTR lpRegistryPath
,
4033 HRESULT hr
= E_FAIL
;
4037 TRACE("(%s, %s, 0x%08lx, %p)\n", debugstr_guid(folderId
), debugstr_w(lpRegistryPath
), dwFlags
, ppszPath
);
4039 /* if this is registry-registered known folder, get path from registry */
4042 StringFromGUID2(folderId
, sGuid
, ARRAY_SIZE(sGuid
));
4044 hr
= get_known_folder_path(sGuid
, lpRegistryPath
, ppszPath
);
4046 /* in other case, use older way */
4049 hr
= SHGetKnownFolderPath( folderId
, dwFlags
, NULL
, ppszPath
);
4051 if (FAILED(hr
)) return hr
;
4053 /* check if known folder really exists */
4054 dwAttributes
= GetFileAttributesW(*ppszPath
);
4055 if(dwAttributes
== INVALID_FILE_ATTRIBUTES
|| !(dwAttributes
& FILE_ATTRIBUTE_DIRECTORY
) )
4057 TRACE("directory %s not found\n", debugstr_w(*ppszPath
));
4058 CoTaskMemFree(*ppszPath
);
4060 hr
= HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
4066 static HRESULT WINAPI
knownfolder_GetPath(
4067 IKnownFolder
*iface
,
4071 struct knownfolder
*knownfolder
= impl_from_IKnownFolder( iface
);
4072 TRACE("(%p, 0x%08lx, %p)\n", knownfolder
, dwFlags
, ppszPath
);
4074 return get_known_folder_path_by_id(&knownfolder
->id
, knownfolder
->registryPath
, dwFlags
, ppszPath
);
4077 static HRESULT WINAPI
knownfolder_SetPath(
4078 IKnownFolder
*iface
,
4082 struct knownfolder
*knownfolder
= impl_from_IKnownFolder( iface
);
4085 TRACE("(%p, 0x%08lx, %s)\n", knownfolder
, dwFlags
, debugstr_w(pszPath
));
4087 /* check if the known folder is registered */
4088 if(!knownfolder
->registryPath
)
4092 hr
= redirect_known_folder(&knownfolder
->id
, NULL
, 0, pszPath
, 0, NULL
, NULL
);
4097 static HRESULT WINAPI
knownfolder_GetIDList(
4098 IKnownFolder
*iface
,
4100 PIDLIST_ABSOLUTE
*ppidl
)
4102 struct knownfolder
*knownfolder
= impl_from_IKnownFolder( iface
);
4103 TRACE("(%p, 0x%08lx, %p)\n", knownfolder
, flags
, ppidl
);
4104 return SHGetKnownFolderIDList(&knownfolder
->id
, flags
, NULL
, ppidl
);
4107 static HRESULT WINAPI
knownfolder_GetFolderType(
4108 IKnownFolder
*iface
,
4109 FOLDERTYPEID
*pftid
)
4111 FIXME("%p\n", pftid
);
4115 static HRESULT WINAPI
knownfolder_GetRedirectionCapabilities(
4116 IKnownFolder
*iface
,
4117 KF_REDIRECTION_CAPABILITIES
*pCapabilities
)
4119 FIXME("%p stub\n", pCapabilities
);
4120 if(!pCapabilities
) return E_INVALIDARG
;
4121 *pCapabilities
= KF_REDIRECTION_CAPABILITIES_DENY_ALL
;
4125 static HRESULT WINAPI
knownfolder_GetFolderDefinition(
4126 IKnownFolder
*iface
,
4127 KNOWNFOLDER_DEFINITION
*pKFD
)
4129 struct knownfolder
*knownfolder
= impl_from_IKnownFolder( iface
);
4132 WCHAR parentGuid
[39];
4133 TRACE("(%p, %p)\n", knownfolder
, pKFD
);
4135 if(!pKFD
) return E_INVALIDARG
;
4137 ZeroMemory(pKFD
, sizeof(*pKFD
));
4139 /* required fields */
4140 hr
= get_known_folder_dword(knownfolder
->registryPath
, L
"Category", (DWORD
*)&pKFD
->category
);
4144 hr
= get_known_folder_wstr(knownfolder
->registryPath
, L
"Name", &pKFD
->pszName
);
4148 /* optional fields */
4149 dwSize
= sizeof(parentGuid
);
4150 hr
= HRESULT_FROM_WIN32(RegGetValueW(HKEY_LOCAL_MACHINE
, knownfolder
->registryPath
, L
"ParentFolder",
4151 RRF_RT_REG_SZ
, NULL
, parentGuid
, &dwSize
));
4154 hr
= IIDFromString(parentGuid
, &pKFD
->fidParent
);
4159 get_known_folder_dword(knownfolder
->registryPath
, L
"Attributes", &pKFD
->dwAttributes
);
4161 get_known_folder_wstr(knownfolder
->registryPath
, L
"RelativePath", &pKFD
->pszRelativePath
);
4163 get_known_folder_wstr(knownfolder
->registryPath
, L
"ParsingName", &pKFD
->pszParsingName
);
4168 static const struct IKnownFolderVtbl knownfolder_vtbl
=
4170 knownfolder_QueryInterface
,
4172 knownfolder_Release
,
4174 knownfolder_GetCategory
,
4175 knownfolder_GetShellItem
,
4176 knownfolder_GetPath
,
4177 knownfolder_SetPath
,
4178 knownfolder_GetIDList
,
4179 knownfolder_GetFolderType
,
4180 knownfolder_GetRedirectionCapabilities
,
4181 knownfolder_GetFolderDefinition
4184 static HRESULT
knownfolder_create( struct knownfolder
**knownfolder
)
4186 struct knownfolder
*kf
;
4188 kf
= heap_alloc( sizeof(*kf
) );
4189 if (!kf
) return E_OUTOFMEMORY
;
4191 kf
->IKnownFolder_iface
.lpVtbl
= &knownfolder_vtbl
;
4193 memset( &kf
->id
, 0, sizeof(kf
->id
) );
4194 kf
->registryPath
= NULL
;
4198 TRACE("returning iface %p\n", &kf
->IKnownFolder_iface
);
4202 struct foldermanager
4204 IKnownFolderManager IKnownFolderManager_iface
;
4210 static inline struct foldermanager
*impl_from_IKnownFolderManager( IKnownFolderManager
*iface
)
4212 return CONTAINING_RECORD( iface
, struct foldermanager
, IKnownFolderManager_iface
);
4215 static ULONG WINAPI
foldermanager_AddRef(
4216 IKnownFolderManager
*iface
)
4218 struct foldermanager
*foldermanager
= impl_from_IKnownFolderManager( iface
);
4219 return InterlockedIncrement( &foldermanager
->refs
);
4222 static ULONG WINAPI
foldermanager_Release(
4223 IKnownFolderManager
*iface
)
4225 struct foldermanager
*foldermanager
= impl_from_IKnownFolderManager( iface
);
4226 LONG refs
= InterlockedDecrement( &foldermanager
->refs
);
4229 TRACE("destroying %p\n", foldermanager
);
4230 heap_free( foldermanager
->ids
);
4231 heap_free( foldermanager
);
4236 static HRESULT WINAPI
foldermanager_QueryInterface(
4237 IKnownFolderManager
*iface
,
4241 struct foldermanager
*This
= impl_from_IKnownFolderManager( iface
);
4243 TRACE("%p %s %p\n", This
, debugstr_guid( riid
), ppv
);
4246 if ( IsEqualGUID( riid
, &IID_IKnownFolderManager
) ||
4247 IsEqualGUID( riid
, &IID_IUnknown
) )
4251 else if ( IsEqualGUID( riid
, &IID_IMarshal
) )
4253 TRACE("IID_IMarshal returning NULL.\n");
4254 return E_NOINTERFACE
;
4258 FIXME("interface %s not implemented\n", debugstr_guid(riid
));
4259 return E_NOINTERFACE
;
4261 IKnownFolderManager_AddRef( iface
);
4265 static HRESULT WINAPI
foldermanager_FolderIdFromCsidl(
4266 IKnownFolderManager
*iface
,
4268 KNOWNFOLDERID
*pfid
)
4270 TRACE("%d, %p\n", nCsidl
, pfid
);
4272 if (nCsidl
>= ARRAY_SIZE(CSIDL_Data
))
4273 return E_INVALIDARG
;
4274 *pfid
= *CSIDL_Data
[nCsidl
].id
;
4278 static HRESULT WINAPI
foldermanager_FolderIdToCsidl(
4279 IKnownFolderManager
*iface
,
4280 REFKNOWNFOLDERID rfid
,
4285 TRACE("%s, %p\n", debugstr_guid(rfid
), pnCsidl
);
4287 csidl
= csidl_from_id( rfid
);
4288 if (csidl
== -1) return E_INVALIDARG
;
4293 static HRESULT WINAPI
foldermanager_GetFolderIds(
4294 IKnownFolderManager
*iface
,
4295 KNOWNFOLDERID
**ppKFId
,
4298 struct foldermanager
*fm
= impl_from_IKnownFolderManager( iface
);
4300 TRACE("%p, %p\n", ppKFId
, pCount
);
4302 *ppKFId
= CoTaskMemAlloc(fm
->num_ids
* sizeof(KNOWNFOLDERID
));
4303 memcpy(*ppKFId
, fm
->ids
, fm
->num_ids
* sizeof(KNOWNFOLDERID
));
4304 *pCount
= fm
->num_ids
;
4308 static BOOL
is_knownfolder( struct foldermanager
*fm
, const KNOWNFOLDERID
*id
)
4312 LPWSTR registryPath
= NULL
;
4315 /* TODO: move all entries from "CSIDL_Data" static array to registry known folder descriptions */
4316 for (i
= 0; i
< fm
->num_ids
; i
++)
4317 if (IsEqualGUID( &fm
->ids
[i
], id
)) return TRUE
;
4319 hr
= get_known_folder_registry_path(id
, NULL
, ®istryPath
);
4322 hr
= HRESULT_FROM_WIN32(RegOpenKeyExW(HKEY_LOCAL_MACHINE
, registryPath
, 0, 0, &hKey
));
4323 heap_free(registryPath
);
4335 static HRESULT WINAPI
foldermanager_GetFolder(
4336 IKnownFolderManager
*iface
,
4337 REFKNOWNFOLDERID rfid
,
4338 IKnownFolder
**ppkf
)
4340 struct foldermanager
*fm
= impl_from_IKnownFolderManager( iface
);
4341 struct knownfolder
*kf
;
4344 TRACE("%s, %p\n", debugstr_guid(rfid
), ppkf
);
4346 if (!is_knownfolder( fm
, rfid
))
4348 WARN("unknown folder\n");
4349 return E_INVALIDARG
;
4351 hr
= knownfolder_create( &kf
);
4352 if (SUCCEEDED( hr
))
4354 hr
= knownfolder_set_id( kf
, rfid
);
4355 *ppkf
= &kf
->IKnownFolder_iface
;
4363 static HRESULT WINAPI
foldermanager_GetFolderByName(
4364 IKnownFolderManager
*iface
,
4365 LPCWSTR pszCanonicalName
,
4366 IKnownFolder
**ppkf
)
4368 struct foldermanager
*fm
= impl_from_IKnownFolderManager( iface
);
4369 struct knownfolder
*kf
;
4374 TRACE( "%s, %p\n", debugstr_w(pszCanonicalName
), ppkf
);
4376 for (i
= 0; i
< fm
->num_ids
; i
++)
4379 hr
= get_known_folder_registry_path( &fm
->ids
[i
], NULL
, &path
);
4380 if (FAILED( hr
)) return hr
;
4382 hr
= get_known_folder_wstr( path
, L
"Name", &name
);
4384 if (FAILED( hr
)) return hr
;
4386 found
= !wcsicmp( pszCanonicalName
, name
);
4387 CoTaskMemFree( name
);
4393 hr
= knownfolder_create( &kf
);
4394 if (FAILED( hr
)) return hr
;
4396 hr
= knownfolder_set_id( kf
, &fm
->ids
[i
] );
4399 IKnownFolder_Release( &kf
->IKnownFolder_iface
);
4402 *ppkf
= &kf
->IKnownFolder_iface
;
4406 hr
= HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND
);
4413 static HRESULT
register_folder(const KNOWNFOLDERID
*rfid
, const KNOWNFOLDER_DEFINITION
*pKFD
)
4418 LPWSTR registryPath
= NULL
;
4420 hr
= get_known_folder_registry_path(rfid
, NULL
, ®istryPath
);
4421 TRACE("registry path: %s\n", debugstr_w(registryPath
));
4424 hr
= HRESULT_FROM_WIN32(RegCreateKeyExW(HKEY_LOCAL_MACHINE
, registryPath
, 0, NULL
, 0, KEY_WRITE
, 0, &hKey
, &dwDisp
));
4428 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, L
"Category", 0, REG_DWORD
, (LPBYTE
)&pKFD
->category
, sizeof(pKFD
->category
)));
4430 if(SUCCEEDED(hr
) && pKFD
->dwAttributes
!= 0)
4431 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, L
"Attributes", 0, REG_DWORD
, (LPBYTE
)&pKFD
->dwAttributes
, sizeof(pKFD
->dwAttributes
)));
4434 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, L
"Name", 0, REG_SZ
, (LPBYTE
)pKFD
->pszName
, (lstrlenW(pKFD
->pszName
)+1)*sizeof(WCHAR
) ));
4436 if(SUCCEEDED(hr
) && pKFD
->pszParsingName
)
4437 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, L
"ParsingName", 0, REG_SZ
, (LPBYTE
)pKFD
->pszParsingName
, (lstrlenW(pKFD
->pszParsingName
)+1)*sizeof(WCHAR
) ));
4439 if(SUCCEEDED(hr
) && !IsEqualGUID(&pKFD
->fidParent
, &GUID_NULL
))
4441 WCHAR sParentGuid
[39];
4442 StringFromGUID2(&pKFD
->fidParent
, sParentGuid
, ARRAY_SIZE(sParentGuid
));
4444 /* this known folder has parent folder */
4445 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, L
"ParentFolder", 0, REG_SZ
, (LPBYTE
)sParentGuid
, sizeof(sParentGuid
)));
4448 if(SUCCEEDED(hr
) && pKFD
->category
!= KF_CATEGORY_VIRTUAL
&& pKFD
->pszRelativePath
)
4449 hr
= HRESULT_FROM_WIN32(RegSetValueExW(hKey
, L
"RelativePath", 0, REG_SZ
, (LPBYTE
)pKFD
->pszRelativePath
, (lstrlenW(pKFD
->pszRelativePath
)+1)*sizeof(WCHAR
) ));
4454 SHDeleteKeyW(HKEY_LOCAL_MACHINE
, registryPath
);
4457 heap_free(registryPath
);
4461 static HRESULT WINAPI
foldermanager_RegisterFolder(
4462 IKnownFolderManager
*iface
,
4463 REFKNOWNFOLDERID rfid
,
4464 KNOWNFOLDER_DEFINITION
const *pKFD
)
4466 TRACE("(%p, %s, %p)\n", iface
, debugstr_guid(rfid
), pKFD
);
4467 return register_folder(rfid
, pKFD
);
4470 static HRESULT WINAPI
foldermanager_UnregisterFolder(
4471 IKnownFolderManager
*iface
,
4472 REFKNOWNFOLDERID rfid
)
4475 LPWSTR registryPath
= NULL
;
4476 TRACE("(%p, %s)\n", iface
, debugstr_guid(rfid
));
4478 hr
= get_known_folder_registry_path(rfid
, NULL
, ®istryPath
);
4481 hr
= HRESULT_FROM_WIN32(SHDeleteKeyW(HKEY_LOCAL_MACHINE
, registryPath
));
4483 heap_free(registryPath
);
4487 static HRESULT WINAPI
foldermanager_FindFolderFromPath(
4488 IKnownFolderManager
*iface
,
4491 IKnownFolder
**ppkf
)
4493 FIXME("%s, 0x%08x, %p\n", debugstr_w(pszPath
), mode
, ppkf
);
4497 static HRESULT WINAPI
foldermanager_FindFolderFromIDList(
4498 IKnownFolderManager
*iface
,
4499 PCIDLIST_ABSOLUTE pidl
,
4500 IKnownFolder
**ppkf
)
4502 FIXME("%p, %p\n", pidl
, ppkf
);
4506 static HRESULT WINAPI
foldermanager_Redirect(
4507 IKnownFolderManager
*iface
,
4508 REFKNOWNFOLDERID rfid
,
4510 KF_REDIRECT_FLAGS flags
,
4511 LPCWSTR pszTargetPath
,
4513 KNOWNFOLDERID
const *pExclusion
,
4516 return redirect_known_folder(rfid
, hwnd
, flags
, pszTargetPath
, cFolders
, pExclusion
, ppszError
);
4519 static const struct IKnownFolderManagerVtbl foldermanager_vtbl
=
4521 foldermanager_QueryInterface
,
4522 foldermanager_AddRef
,
4523 foldermanager_Release
,
4524 foldermanager_FolderIdFromCsidl
,
4525 foldermanager_FolderIdToCsidl
,
4526 foldermanager_GetFolderIds
,
4527 foldermanager_GetFolder
,
4528 foldermanager_GetFolderByName
,
4529 foldermanager_RegisterFolder
,
4530 foldermanager_UnregisterFolder
,
4531 foldermanager_FindFolderFromPath
,
4532 foldermanager_FindFolderFromIDList
,
4533 foldermanager_Redirect
4536 static HRESULT
foldermanager_create( void **ppv
)
4539 struct foldermanager
*fm
;
4541 fm
= heap_alloc( sizeof(*fm
) );
4542 if (!fm
) return E_OUTOFMEMORY
;
4544 fm
->IKnownFolderManager_iface
.lpVtbl
= &foldermanager_vtbl
;
4548 for (i
= 0; i
< ARRAY_SIZE(CSIDL_Data
); i
++)
4550 if (!IsEqualGUID( CSIDL_Data
[i
].id
, &GUID_NULL
)) fm
->num_ids
++;
4552 fm
->ids
= heap_alloc( fm
->num_ids
* sizeof(KNOWNFOLDERID
) );
4556 return E_OUTOFMEMORY
;
4558 for (i
= j
= 0; i
< ARRAY_SIZE(CSIDL_Data
); i
++)
4560 if (!IsEqualGUID( CSIDL_Data
[i
].id
, &GUID_NULL
))
4562 fm
->ids
[j
] = *CSIDL_Data
[i
].id
;
4566 TRACE("found %u known folders\n", fm
->num_ids
);
4567 *ppv
= &fm
->IKnownFolderManager_iface
;
4569 TRACE("returning iface %p\n", *ppv
);
4573 HRESULT WINAPI
KnownFolderManager_Constructor( IUnknown
*punk
, REFIID riid
, void **ppv
)
4575 TRACE("%p, %s, %p\n", punk
, debugstr_guid(riid
), ppv
);
4580 return CLASS_E_NOAGGREGATION
;
4582 return foldermanager_create( ppv
);
4585 HRESULT WINAPI
SHGetKnownFolderIDList(REFKNOWNFOLDERID rfid
, DWORD flags
, HANDLE token
, PIDLIST_ABSOLUTE
*pidl
)
4587 TRACE("%s, 0x%08lx, %p, %p\n", debugstr_guid(rfid
), flags
, token
, pidl
);
4590 return E_INVALIDARG
;
4593 FIXME("unsupported flags: 0x%08lx\n", flags
);
4596 FIXME("user token is not used.\n");
4599 if (IsEqualIID(rfid
, &FOLDERID_Desktop
))
4600 *pidl
= _ILCreateDesktop();
4601 else if (IsEqualIID(rfid
, &FOLDERID_RecycleBinFolder
))
4602 *pidl
= _ILCreateBitBucket();
4603 else if (IsEqualIID(rfid
, &FOLDERID_ComputerFolder
))
4604 *pidl
= _ILCreateMyComputer();
4605 else if (IsEqualIID(rfid
, &FOLDERID_PrintersFolder
))
4606 *pidl
= _ILCreatePrinters();
4607 else if (IsEqualIID(rfid
, &FOLDERID_ControlPanelFolder
))
4608 *pidl
= _ILCreateControlPanel();
4609 else if (IsEqualIID(rfid
, &FOLDERID_NetworkFolder
))
4610 *pidl
= _ILCreateNetwork();
4611 else if (IsEqualIID(rfid
, &FOLDERID_Documents
))
4612 *pidl
= _ILCreateMyDocuments();
4615 DWORD attributes
= 0;
4619 hr
= SHGetKnownFolderPath(rfid
, flags
, token
, &pathW
);
4623 hr
= SHILCreateFromPathW(pathW
, pidl
, &attributes
);
4624 CoTaskMemFree(pathW
);
4628 return *pidl
? S_OK
: E_FAIL
;
4631 HRESULT WINAPI
SHGetKnownFolderItem(REFKNOWNFOLDERID rfid
, KNOWN_FOLDER_FLAG flags
, HANDLE hToken
,
4632 REFIID riid
, void **ppv
)
4634 PIDLIST_ABSOLUTE pidl
;
4637 TRACE("%s, 0x%08x, %p, %s, %p\n", debugstr_guid(rfid
), flags
, hToken
, debugstr_guid(riid
), ppv
);
4639 hr
= SHGetKnownFolderIDList(rfid
, flags
, hToken
, &pidl
);
4646 hr
= SHCreateItemFromIDList(pidl
, riid
, ppv
);
4647 CoTaskMemFree(pidl
);
4651 static void register_system_knownfolders(void)
4655 for (i
= 0; i
< ARRAY_SIZE(CSIDL_Data
); ++i
)
4657 const CSIDL_DATA
*folder
= &CSIDL_Data
[i
];
4659 KNOWNFOLDER_DEFINITION kfd
;
4661 /* register_folder won't modify kfd, so cast away const instead of
4663 kfd
.category
= folder
->category
;
4664 kfd
.pszName
= (WCHAR
*)folder
->name
;
4665 kfd
.pszDescription
= NULL
;
4666 kfd
.fidParent
= folder
->parent
? *folder
->parent
: GUID_NULL
;
4667 kfd
.pszRelativePath
= (WCHAR
*)folder
->path
;
4668 kfd
.pszParsingName
= (WCHAR
*)folder
->parsing
;
4669 kfd
.pszTooltip
= NULL
;
4670 kfd
.pszLocalizedName
= NULL
;
4672 kfd
.pszSecurity
= NULL
;
4673 kfd
.dwAttributes
= folder
->attributes
;
4674 kfd
.kfdFlags
= folder
->flags
;
4675 kfd
.ftidType
= folder
->typeid ? *folder
->typeid : GUID_NULL
;
4676 register_folder(folder
->id
, &kfd
);
4681 HRESULT
SHELL_RegisterShellFolders(void)
4685 hr
= _SHRegisterUserShellFolders(TRUE
);
4687 hr
= _SHRegisterUserShellFolders(FALSE
);
4689 hr
= _SHRegisterCommonShellFolders();
4691 hr
= create_extra_folders();
4693 hr
= set_folder_attributes();
4695 register_system_knownfolders();