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
31 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
34 ########## Combining and Constructing paths ##########
37 /*************************************************************************
38 * PathAppend [SHELL32.36]
40 BOOL WINAPI
PathAppendAW(
44 if (SHELL_OsIsUnicode())
45 return PathAppendW((LPWSTR
)lpszPath1
, (LPCWSTR
)lpszPath2
);
46 return PathAppendA((LPSTR
)lpszPath1
, (LPCSTR
)lpszPath2
);
49 /*************************************************************************
50 * PathBuildRoot [SHELL32.30]
52 LPVOID WINAPI
PathBuildRootAW(LPVOID lpszPath
, int drive
)
54 if(SHELL_OsIsUnicode())
55 return PathBuildRootW((LPWSTR
)lpszPath
, drive
);
56 return PathBuildRootA((LPSTR
)lpszPath
, drive
);
59 /*************************************************************************
60 * PathGetExtensionA [internal]
64 * return value points to the first char after the dot
66 static LPSTR
PathGetExtensionA(LPCSTR lpszPath
)
68 TRACE("(%s)\n",lpszPath
);
70 lpszPath
= PathFindExtensionA(lpszPath
);
71 return (LPSTR
)(*lpszPath
?(lpszPath
+1):lpszPath
);
74 /*************************************************************************
75 * PathGetExtensionW [internal]
77 static LPWSTR
PathGetExtensionW(LPCWSTR lpszPath
)
79 TRACE("(%s)\n",debugstr_w(lpszPath
));
81 lpszPath
= PathFindExtensionW(lpszPath
);
82 return (LPWSTR
)(*lpszPath
?(lpszPath
+1):lpszPath
);
85 /*************************************************************************
86 * SHPathGetExtension [SHELL32.158]
88 EXTERN_C LPVOID WINAPI
SHPathGetExtensionW(LPCWSTR lpszPath
, DWORD void1
, DWORD void2
)
90 return PathGetExtensionW(lpszPath
);
93 /*************************************************************************
94 * PathRemoveFileSpec [SHELL32.35]
96 BOOL WINAPI
PathRemoveFileSpecAW(LPVOID lpszPath
)
98 if (SHELL_OsIsUnicode())
99 return PathRemoveFileSpecW((LPWSTR
)lpszPath
);
100 return PathRemoveFileSpecA((LPSTR
)lpszPath
);
107 /*************************************************************************
108 * PathGetShortPathA [internal]
110 static void PathGetShortPathA(LPSTR pszPath
)
114 TRACE("%s\n", pszPath
);
116 if (GetShortPathNameA(pszPath
, path
, MAX_PATH
))
118 lstrcpyA(pszPath
, path
);
122 /*************************************************************************
123 * PathGetShortPathW [internal]
125 static void PathGetShortPathW(LPWSTR pszPath
)
127 WCHAR path
[MAX_PATH
];
129 TRACE("%s\n", debugstr_w(pszPath
));
131 if (GetShortPathNameW(pszPath
, path
, MAX_PATH
))
133 wcscpy(pszPath
, path
);
137 /*************************************************************************
138 * PathGetShortPath [SHELL32.92]
140 EXTERN_C VOID WINAPI
PathGetShortPathAW(LPVOID pszPath
)
142 if(SHELL_OsIsUnicode())
143 PathGetShortPathW((LPWSTR
)pszPath
);
144 PathGetShortPathA((LPSTR
)pszPath
);
148 ########## Path Testing ##########
151 /*************************************************************************
152 * PathIsRoot [SHELL32.29]
154 BOOL WINAPI
PathIsRootAW(LPCVOID lpszPath
)
156 if (SHELL_OsIsUnicode())
157 return PathIsRootW((LPWSTR
)lpszPath
);
158 return PathIsRootA((LPSTR
)lpszPath
);
161 /*************************************************************************
162 * PathIsExeA [internal]
164 static BOOL
PathIsExeA (LPCSTR lpszPath
)
166 LPCSTR lpszExtension
= PathGetExtensionA(lpszPath
);
168 static const char * const lpszExtensions
[] =
169 {"exe", "com", "pif", "cmd", "bat", "scf", "scr", NULL
};
171 TRACE("path=%s\n",lpszPath
);
173 for(i
=0; lpszExtensions
[i
]; i
++)
174 if (!lstrcmpiA(lpszExtension
,lpszExtensions
[i
])) return TRUE
;
179 /*************************************************************************
180 * PathIsExeW [internal]
182 BOOL
PathIsExeW (LPCWSTR lpszPath
)
184 LPCWSTR lpszExtension
= PathGetExtensionW(lpszPath
);
186 static const WCHAR lpszExtensions
[][4] =
187 {{'e','x','e','\0'}, {'c','o','m','\0'}, {'p','i','f','\0'},
188 {'c','m','d','\0'}, {'b','a','t','\0'}, {'s','c','f','\0'},
189 {'s','c','r','\0'}, {'\0'} };
191 TRACE("path=%s\n",debugstr_w(lpszPath
));
193 for(i
=0; lpszExtensions
[i
][0]; i
++)
194 if (!strcmpiW(lpszExtension
,lpszExtensions
[i
])) return TRUE
;
199 /*************************************************************************
200 * PathIsExe [SHELL32.43]
202 BOOL WINAPI
PathIsExeAW (LPCVOID path
)
204 if (SHELL_OsIsUnicode())
205 return PathIsExeW ((LPWSTR
)path
);
206 return PathIsExeA((LPSTR
)path
);
209 /*************************************************************************
210 * PathFileExists [SHELL32.45]
212 BOOL WINAPI
PathFileExistsAW (LPCVOID lpszPath
)
214 if (SHELL_OsIsUnicode())
215 return PathFileExistsW ((LPWSTR
)lpszPath
);
216 return PathFileExistsA ((LPSTR
)lpszPath
);
219 /*************************************************************************
220 * PathIsSameRoot [SHELL32.650]
222 BOOL WINAPI
PathIsSameRootAW(LPCVOID lpszPath1
, LPCVOID lpszPath2
)
224 if (SHELL_OsIsUnicode())
225 return PathIsSameRootW((LPCWSTR
)lpszPath1
, (LPCWSTR
)lpszPath2
);
226 return PathIsSameRootA((LPCSTR
)lpszPath1
, (LPCSTR
)lpszPath2
);
229 /*************************************************************************
230 * IsLFNDriveA [SHELL32.41]
232 EXTERN_C BOOL WINAPI
IsLFNDriveA(LPCSTR lpszPath
)
236 if (!GetVolumeInformationA(lpszPath
, NULL
, 0, NULL
, &fnlen
, NULL
, NULL
, 0))
241 /*************************************************************************
242 * IsLFNDriveW [SHELL32.42]
244 EXTERN_C BOOL WINAPI
IsLFNDriveW(LPCWSTR lpszPath
)
248 if (!GetVolumeInformationW(lpszPath
, NULL
, 0, NULL
, &fnlen
, NULL
, NULL
, 0))
253 /*************************************************************************
254 * IsLFNDrive [SHELL32.119]
256 EXTERN_C BOOL WINAPI
IsLFNDriveAW(LPCVOID lpszPath
)
258 if (SHELL_OsIsUnicode())
259 return IsLFNDriveW((LPCWSTR
)lpszPath
);
260 return IsLFNDriveA((LPCSTR
)lpszPath
);
264 ########## Creating Something Unique ##########
266 /*************************************************************************
267 * PathMakeUniqueNameA [internal]
269 static BOOL
PathMakeUniqueNameA(
272 LPCSTR lpszShortName
,
276 FIXME("%p %u %s %s %s stub\n",
277 lpszBuffer
, dwBuffSize
, debugstr_a(lpszShortName
),
278 debugstr_a(lpszLongName
), debugstr_a(lpszPathName
));
282 /*************************************************************************
283 * PathMakeUniqueNameW [internal]
285 static BOOL
PathMakeUniqueNameW(
288 LPCWSTR lpszShortName
,
289 LPCWSTR lpszLongName
,
290 LPCWSTR lpszPathName
)
292 FIXME("%p %u %s %s %s stub\n",
293 lpszBuffer
, dwBuffSize
, debugstr_w(lpszShortName
),
294 debugstr_w(lpszLongName
), debugstr_w(lpszPathName
));
298 /*************************************************************************
299 * PathMakeUniqueName [SHELL32.47]
301 BOOL WINAPI
PathMakeUniqueNameAW(
304 LPCVOID lpszShortName
,
305 LPCVOID lpszLongName
,
306 LPCVOID lpszPathName
)
308 if (SHELL_OsIsUnicode())
309 return PathMakeUniqueNameW((LPWSTR
)lpszBuffer
, dwBuffSize
, (LPCWSTR
)lpszShortName
, (LPCWSTR
)lpszLongName
, (LPCWSTR
)lpszPathName
);
310 return PathMakeUniqueNameA((LPSTR
)lpszBuffer
, dwBuffSize
, (LPCSTR
)lpszShortName
, (LPCSTR
)lpszLongName
, (LPCSTR
)lpszPathName
);
313 /*************************************************************************
314 * PathYetAnotherMakeUniqueName [SHELL32.75]
317 * exported by ordinal
319 BOOL WINAPI
PathYetAnotherMakeUniqueName(
321 LPCWSTR lpszPathName
,
322 LPCWSTR lpszShortName
,
323 LPCWSTR lpszLongName
)
325 FIXME("(%p, %s, %s ,%s):stub.\n",
326 lpszBuffer
, debugstr_w(lpszPathName
), debugstr_w(lpszShortName
), debugstr_w(lpszLongName
));
332 ########## cleaning and resolving paths ##########
335 /*************************************************************************
336 * PathCleanupSpec [SHELL32.171]
338 * lpszFile is changed in place.
340 int WINAPI
PathCleanupSpec( LPCWSTR lpszPathW
, LPWSTR lpszFileW
)
346 if (SHELL_OsIsUnicode())
348 LPWSTR p
= lpszFileW
;
350 TRACE("Cleanup %s\n",debugstr_w(lpszFileW
));
353 length
= wcslen(lpszPathW
);
357 int gct
= PathGetCharTypeW(*p
);
358 if (gct
== GCT_INVALID
|| gct
== GCT_WILD
|| gct
== GCT_SEPARATOR
)
361 rc
|= PCS_REPLACEDCHAR
;
367 if (length
+ i
== MAX_PATH
)
369 rc
|= PCS_FATAL
| PCS_PATHTOOLONG
;
377 LPSTR lpszFileA
= (LPSTR
)lpszFileW
;
378 LPCSTR lpszPathA
= (LPCSTR
)lpszPathW
;
381 TRACE("Cleanup %s\n",debugstr_a(lpszFileA
));
384 length
= strlen(lpszPathA
);
388 int gct
= PathGetCharTypeA(*p
);
389 if (gct
== GCT_INVALID
|| gct
== GCT_WILD
|| gct
== GCT_SEPARATOR
)
392 rc
|= PCS_REPLACEDCHAR
;
398 if (length
+ i
== MAX_PATH
)
400 rc
|= PCS_FATAL
| PCS_PATHTOOLONG
;
409 /*************************************************************************
410 * PathQualifyA [SHELL32]
412 static BOOL
PathQualifyA(LPCSTR pszPath
)
414 FIXME("%s\n",pszPath
);
418 /*************************************************************************
419 * PathQualifyW [SHELL32]
421 static BOOL
PathQualifyW(LPCWSTR pszPath
)
423 FIXME("%s\n",debugstr_w(pszPath
));
427 /*************************************************************************
428 * PathQualify [SHELL32.49]
430 BOOL WINAPI
PathQualifyAW(LPCVOID pszPath
)
432 if (SHELL_OsIsUnicode())
433 return PathQualifyW((LPCWSTR
)pszPath
);
434 return PathQualifyA((LPCSTR
)pszPath
);
437 /*************************************************************************
438 * PathResolveA [SHELL32.51]
440 static BOOL
PathResolveA(
445 FIXME("(%s,%p,0x%08x),stub!\n",
446 lpszPath
, *alpszPaths
, dwFlags
);
450 /*************************************************************************
451 * PathResolveW [SHELL32]
453 static BOOL
PathResolveW(
458 FIXME("(%s,%p,0x%08x),stub!\n",
459 debugstr_w(lpszPath
), debugstr_w(*alpszPaths
), dwFlags
);
463 /*************************************************************************
464 * PathResolve [SHELL32.51]
466 BOOL WINAPI
PathResolveAW(
471 if (SHELL_OsIsUnicode())
472 return PathResolveW((LPWSTR
)lpszPath
, (LPCWSTR
*)alpszPaths
, dwFlags
);
473 return PathResolveA((LPSTR
)lpszPath
, (LPCSTR
*)alpszPaths
, dwFlags
);
476 /*************************************************************************
477 * PathProcessCommandA [SHELL32.653]
479 static LONG
PathProcessCommandA (
485 FIXME("%s %p 0x%04x 0x%04x stub\n",
486 lpszPath
, lpszBuff
, dwBuffSize
, dwFlags
);
487 if(!lpszPath
) return -1;
488 if(lpszBuff
) strcpy(lpszBuff
, lpszPath
);
489 return strlen(lpszPath
);
492 /*************************************************************************
493 * PathProcessCommandW
495 static LONG
PathProcessCommandW (
501 FIXME("(%s, %p, 0x%04x, 0x%04x) stub\n",
502 debugstr_w(lpszPath
), lpszBuff
, dwBuffSize
, dwFlags
);
503 if(!lpszPath
) return -1;
504 if(lpszBuff
) wcscpy(lpszBuff
, lpszPath
);
505 return wcslen(lpszPath
);
508 /*************************************************************************
509 * PathProcessCommand (SHELL32.653)
511 LONG WINAPI
PathProcessCommandAW (
517 if (SHELL_OsIsUnicode())
518 return PathProcessCommandW((LPCWSTR
)lpszPath
, (LPWSTR
)lpszBuff
, dwBuffSize
, dwFlags
);
519 return PathProcessCommandA((LPCSTR
)lpszPath
, (LPSTR
)lpszBuff
, dwBuffSize
, dwFlags
);
523 ########## special ##########
526 static const WCHAR szCurrentVersion
[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\0'};
527 static const WCHAR Administrative_ToolsW
[] = {'A','d','m','i','n','i','s','t','r','a','t','i','v','e',' ','T','o','o','l','s','\0'};
528 static const WCHAR AppDataW
[] = {'A','p','p','D','a','t','a','\0'};
529 static const WCHAR CacheW
[] = {'C','a','c','h','e','\0'};
530 static const WCHAR CD_BurningW
[] = {'C','D',' ','B','u','r','n','i','n','g','\0'};
531 static const WCHAR Common_Administrative_ToolsW
[] = {'C','o','m','m','o','n',' ','A','d','m','i','n','i','s','t','r','a','t','i','v','e',' ','T','o','o','l','s','\0'};
532 static const WCHAR Common_AppDataW
[] = {'C','o','m','m','o','n',' ','A','p','p','D','a','t','a','\0'};
533 static const WCHAR Common_DesktopW
[] = {'C','o','m','m','o','n',' ','D','e','s','k','t','o','p','\0'};
534 static const WCHAR Common_DocumentsW
[] = {'C','o','m','m','o','n',' ','D','o','c','u','m','e','n','t','s','\0'};
535 static const WCHAR CommonFilesDirW
[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r','\0'};
536 static const WCHAR CommonMusicW
[] = {'C','o','m','m','o','n','M','u','s','i','c','\0'};
537 static const WCHAR CommonPicturesW
[] = {'C','o','m','m','o','n','P','i','c','t','u','r','e','s','\0'};
538 static const WCHAR Common_ProgramsW
[] = {'C','o','m','m','o','n',' ','P','r','o','g','r','a','m','s','\0'};
539 static const WCHAR Common_StartUpW
[] = {'C','o','m','m','o','n',' ','S','t','a','r','t','U','p','\0'};
540 static const WCHAR Common_Start_MenuW
[] = {'C','o','m','m','o','n',' ','S','t','a','r','t',' ','M','e','n','u','\0'};
541 static const WCHAR Common_TemplatesW
[] = {'C','o','m','m','o','n',' ','T','e','m','p','l','a','t','e','s','\0'};
542 static const WCHAR CommonVideoW
[] = {'C','o','m','m','o','n','V','i','d','e','o','\0'};
543 static const WCHAR CookiesW
[] = {'C','o','o','k','i','e','s','\0'};
544 static const WCHAR DesktopW
[] = {'D','e','s','k','t','o','p','\0'};
545 static const WCHAR FavoritesW
[] = {'F','a','v','o','r','i','t','e','s','\0'};
546 static const WCHAR FontsW
[] = {'F','o','n','t','s','\0'};
547 static const WCHAR HistoryW
[] = {'H','i','s','t','o','r','y','\0'};
548 static const WCHAR Local_AppDataW
[] = {'L','o','c','a','l',' ','A','p','p','D','a','t','a','\0'};
549 static const WCHAR My_MusicW
[] = {'M','y',' ','M','u','s','i','c','\0'};
550 static const WCHAR My_PicturesW
[] = {'M','y',' ','P','i','c','t','u','r','e','s','\0'};
551 static const WCHAR My_VideoW
[] = {'M','y',' ','V','i','d','e','o','\0'};
552 static const WCHAR NetHoodW
[] = {'N','e','t','H','o','o','d','\0'};
553 static const WCHAR PersonalW
[] = {'P','e','r','s','o','n','a','l','\0'};
554 static const WCHAR PrintHoodW
[] = {'P','r','i','n','t','H','o','o','d','\0'};
555 static const WCHAR ProgramFilesDirW
[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r','\0'};
556 static const WCHAR ProgramsW
[] = {'P','r','o','g','r','a','m','s','\0'};
557 static const WCHAR RecentW
[] = {'R','e','c','e','n','t','\0'};
558 static const WCHAR ResourcesW
[] = {'R','e','s','o','u','r','c','e','s','\0'};
559 static const WCHAR SendToW
[] = {'S','e','n','d','T','o','\0'};
560 static const WCHAR StartUpW
[] = {'S','t','a','r','t','U','p','\0'};
561 static const WCHAR Start_MenuW
[] = {'S','t','a','r','t',' ','M','e','n','u','\0'};
562 static const WCHAR TemplatesW
[] = {'T','e','m','p','l','a','t','e','s','\0'};
563 static const WCHAR DefaultW
[] = {'.','D','e','f','a','u','l','t','\0'};
564 static const WCHAR AllUsersProfileW
[] = {'%','A','L','L','U','S','E','R','S','P','R','O','F','I','L','E','%','\0'};
565 static const WCHAR UserProfileW
[] = {'%','U','S','E','R','P','R','O','F','I','L','E','%','\0'};
566 static const WCHAR SystemDriveW
[] = {'%','S','y','s','t','e','m','D','r','i','v','e','%','\0'};
567 static const WCHAR szSHFolders
[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l','o','r','e','r','\\','S','h','e','l','l',' ','F','o','l','d','e','r','s','\0'};
568 static const WCHAR szSHUserFolders
[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l','o','r','e','r','\\','U','s','e','r',' ','S','h','e','l','l',' ','F','o','l','d','e','r','s','\0'};
571 static const WCHAR ProfileListW
[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','P','r','o','f','i','l','e','L','i','s','t',0};
572 static const WCHAR ProfilesDirectoryW
[] = {'P','r','o','f','i','l','e','s','D','i','r','e','c','t','o','r','y',0};
573 static const WCHAR AllUsersProfileValueW
[] = {'A','l','l','U','s','e','r','s','P','r','o','f','i','l','e','\0'};
574 static const WCHAR szDefaultProfileDirW
[] = {'p','r','o','f','i','l','e','s','\0'};
575 static const WCHAR AllUsersW
[] = {'A','l','l',' ','U','s','e','r','s','\0'};
578 /* This defaults to L"Documents and Settings" on Windows 2000/XP, but we're
579 * acting more Windows 9x-like for now.
582 typedef enum _CSIDL_Type
{
586 CSIDL_Type_Disallowed
,
587 CSIDL_Type_NonExistent
,
588 CSIDL_Type_WindowsPath
,
589 CSIDL_Type_SystemPath
,
596 LPCWSTR szDefaultPath
; /* fallback string or resource ID */
599 static const CSIDL_DATA CSIDL_Data
[] =
601 { /* 0x00 - CSIDL_DESKTOP */
604 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY
)
606 { /* 0x01 - CSIDL_INTERNET */
607 CSIDL_Type_Disallowed
,
611 { /* 0x02 - CSIDL_PROGRAMS */
614 MAKEINTRESOURCEW(IDS_PROGRAMS
)
616 { /* 0x03 - CSIDL_CONTROLS (.CPL files) */
617 CSIDL_Type_SystemPath
,
621 { /* 0x04 - CSIDL_PRINTERS */
622 CSIDL_Type_SystemPath
,
626 { /* 0x05 - CSIDL_PERSONAL */
629 MAKEINTRESOURCEW(IDS_PERSONAL
)
631 { /* 0x06 - CSIDL_FAVORITES */
634 MAKEINTRESOURCEW(IDS_FAVORITES
)
636 { /* 0x07 - CSIDL_STARTUP */
639 MAKEINTRESOURCEW(IDS_STARTUP
)
641 { /* 0x08 - CSIDL_RECENT */
644 MAKEINTRESOURCEW(IDS_RECENT
)
646 { /* 0x09 - CSIDL_SENDTO */
649 MAKEINTRESOURCEW(IDS_SENDTO
)
651 { /* 0x0a - CSIDL_BITBUCKET - Recycle Bin */
652 CSIDL_Type_Disallowed
,
656 { /* 0x0b - CSIDL_STARTMENU */
659 MAKEINTRESOURCEW(IDS_STARTMENU
)
661 { /* 0x0c - CSIDL_MYDOCUMENTS */
662 CSIDL_Type_Disallowed
, /* matches WinXP--can't get its path */
666 { /* 0x0d - CSIDL_MYMUSIC */
669 MAKEINTRESOURCEW(IDS_MYMUSIC
)
671 { /* 0x0e - CSIDL_MYVIDEO */
674 MAKEINTRESOURCEW(IDS_MYVIDEO
)
676 { /* 0x0f - unassigned */
677 CSIDL_Type_Disallowed
,
681 { /* 0x10 - CSIDL_DESKTOPDIRECTORY */
684 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY
)
686 { /* 0x11 - CSIDL_DRIVES */
687 CSIDL_Type_Disallowed
,
691 { /* 0x12 - CSIDL_NETWORK */
692 CSIDL_Type_Disallowed
,
696 { /* 0x13 - CSIDL_NETHOOD */
699 MAKEINTRESOURCEW(IDS_NETHOOD
)
701 { /* 0x14 - CSIDL_FONTS */
702 CSIDL_Type_WindowsPath
,
706 { /* 0x15 - CSIDL_TEMPLATES */
709 MAKEINTRESOURCEW(IDS_TEMPLATES
)
711 { /* 0x16 - CSIDL_COMMON_STARTMENU */
714 MAKEINTRESOURCEW(IDS_STARTMENU
)
716 { /* 0x17 - CSIDL_COMMON_PROGRAMS */
719 MAKEINTRESOURCEW(IDS_PROGRAMS
)
721 { /* 0x18 - CSIDL_COMMON_STARTUP */
724 MAKEINTRESOURCEW(IDS_STARTUP
)
726 { /* 0x19 - CSIDL_COMMON_DESKTOPDIRECTORY */
729 MAKEINTRESOURCEW(IDS_DESKTOP
)
731 { /* 0x1a - CSIDL_APPDATA */
734 MAKEINTRESOURCEW(IDS_APPDATA
)
736 { /* 0x1b - CSIDL_PRINTHOOD */
739 MAKEINTRESOURCEW(IDS_PRINTHOOD
)
741 { /* 0x1c - CSIDL_LOCAL_APPDATA */
744 MAKEINTRESOURCEW(IDS_LOCAL_APPDATA
)
746 { /* 0x1d - CSIDL_ALTSTARTUP */
747 CSIDL_Type_NonExistent
,
751 { /* 0x1e - CSIDL_COMMON_ALTSTARTUP */
752 CSIDL_Type_NonExistent
,
756 { /* 0x1f - CSIDL_COMMON_FAVORITES */
759 MAKEINTRESOURCEW(IDS_FAVORITES
)
761 { /* 0x20 - CSIDL_INTERNET_CACHE */
764 MAKEINTRESOURCEW(IDS_INTERNET_CACHE
)
766 { /* 0x21 - CSIDL_COOKIES */
769 MAKEINTRESOURCEW(IDS_COOKIES
)
771 { /* 0x22 - CSIDL_HISTORY */
774 MAKEINTRESOURCEW(IDS_HISTORY
)
776 { /* 0x23 - CSIDL_COMMON_APPDATA */
779 MAKEINTRESOURCEW(IDS_APPDATA
)
781 { /* 0x24 - CSIDL_WINDOWS */
782 CSIDL_Type_WindowsPath
,
786 { /* 0x25 - CSIDL_SYSTEM */
787 CSIDL_Type_SystemPath
,
791 { /* 0x26 - CSIDL_PROGRAM_FILES */
794 MAKEINTRESOURCEW(IDS_PROGRAM_FILES
)
796 { /* 0x27 - CSIDL_MYPICTURES */
799 MAKEINTRESOURCEW(IDS_MYPICTURES
)
801 { /* 0x28 - CSIDL_PROFILE */
806 { /* 0x29 - CSIDL_SYSTEMX86 */
807 CSIDL_Type_NonExistent
,
811 { /* 0x2a - CSIDL_PROGRAM_FILESX86 */
812 CSIDL_Type_NonExistent
,
816 { /* 0x2b - CSIDL_PROGRAM_FILES_COMMON */
819 MAKEINTRESOURCEW(IDS_PROGRAM_FILES_COMMON
)
821 { /* 0x2c - CSIDL_PROGRAM_FILES_COMMONX86 */
822 CSIDL_Type_NonExistent
,
826 { /* 0x2d - CSIDL_COMMON_TEMPLATES */
829 MAKEINTRESOURCEW(IDS_TEMPLATES
)
831 { /* 0x2e - CSIDL_COMMON_DOCUMENTS */
834 MAKEINTRESOURCEW(IDS_COMMON_DOCUMENTS
)
836 { /* 0x2f - CSIDL_COMMON_ADMINTOOLS */
838 Common_Administrative_ToolsW
,
839 MAKEINTRESOURCEW(IDS_ADMINTOOLS
)
841 { /* 0x30 - CSIDL_ADMINTOOLS */
843 Administrative_ToolsW
,
844 MAKEINTRESOURCEW(IDS_ADMINTOOLS
)
846 { /* 0x31 - CSIDL_CONNECTIONS */
847 CSIDL_Type_Disallowed
,
851 { /* 0x32 - unassigned */
852 CSIDL_Type_Disallowed
,
856 { /* 0x33 - unassigned */
857 CSIDL_Type_Disallowed
,
861 { /* 0x34 - unassigned */
862 CSIDL_Type_Disallowed
,
866 { /* 0x35 - CSIDL_COMMON_MUSIC */
869 MAKEINTRESOURCEW(IDS_COMMON_MUSIC
)
871 { /* 0x36 - CSIDL_COMMON_PICTURES */
874 MAKEINTRESOURCEW(IDS_COMMON_PICTURES
)
876 { /* 0x37 - CSIDL_COMMON_VIDEO */
879 MAKEINTRESOURCEW(IDS_COMMON_VIDEO
)
881 { /* 0x38 - CSIDL_RESOURCES */
882 CSIDL_Type_WindowsPath
,
886 { /* 0x39 - CSIDL_RESOURCES_LOCALIZED */
887 CSIDL_Type_NonExistent
,
891 { /* 0x3a - CSIDL_COMMON_OEM_LINKS */
892 CSIDL_Type_NonExistent
,
896 { /* 0x3b - CSIDL_CDBURN_AREA */
899 MAKEINTRESOURCEW(IDS_CDBURN_AREA
)
901 { /* 0x3c unassigned */
902 CSIDL_Type_Disallowed
,
906 { /* 0x3d - CSIDL_COMPUTERSNEARME */
907 CSIDL_Type_Disallowed
, /* FIXME */
911 { /* 0x3e - CSIDL_PROFILES */
912 CSIDL_Type_Disallowed
, /* oddly, this matches WinXP */
918 /* Gets the value named value from the registry key
919 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
920 * (or from rootKey\userPrefix\... if userPrefix is not NULL) into path, which
921 * is assumed to be MAX_PATH WCHARs in length.
922 * If it exists, expands the value and writes the expanded value to
923 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
924 * Returns successful error code if the value was retrieved from the registry,
925 * and a failure otherwise.
927 static HRESULT
_SHGetUserShellFolderPath(HKEY rootKey
, LPCWSTR userPrefix
,
928 LPCWSTR value
, LPWSTR path
)
931 WCHAR shellFolderPath
[MAX_PATH
], userShellFolderPath
[MAX_PATH
];
932 LPCWSTR pShellFolderPath
, pUserShellFolderPath
;
933 DWORD dwDisp
, dwType
, dwPathLen
;
934 HKEY userShellFolderKey
, shellFolderKey
;
936 TRACE("%p,%s,%s,%p\n",rootKey
, debugstr_w(userPrefix
), debugstr_w(value
),
941 wcscpy(shellFolderPath
, userPrefix
);
942 PathAddBackslashW(shellFolderPath
);
943 wcscat(shellFolderPath
, szSHFolders
);
944 pShellFolderPath
= shellFolderPath
;
945 wcscpy(userShellFolderPath
, userPrefix
);
946 PathAddBackslashW(userShellFolderPath
);
947 wcscat(userShellFolderPath
, szSHUserFolders
);
948 pUserShellFolderPath
= userShellFolderPath
;
952 pUserShellFolderPath
= szSHUserFolders
;
953 pShellFolderPath
= szSHFolders
;
956 if (RegCreateKeyExW(rootKey
, pShellFolderPath
, 0, NULL
, 0, KEY_SET_VALUE
,
957 NULL
, &shellFolderKey
, &dwDisp
))
959 TRACE("Failed to create %s\n", debugstr_w(pShellFolderPath
));
962 if (RegCreateKeyExW(rootKey
, pUserShellFolderPath
, 0, NULL
, 0,
963 KEY_QUERY_VALUE
, NULL
, &userShellFolderKey
, &dwDisp
))
965 TRACE("Failed to create %s\n",
966 debugstr_w(pUserShellFolderPath
));
967 RegCloseKey(shellFolderKey
);
971 dwPathLen
= MAX_PATH
* sizeof(WCHAR
);
973 if (!RegQueryValueExW(userShellFolderKey
, value
, NULL
, &dwType
,
974 (LPBYTE
)path
, &dwPathLen
) && (dwType
== REG_EXPAND_SZ
|| dwType
== REG_SZ
))
978 dwPathLen
/= sizeof(WCHAR
);
980 path
[dwPathLen
] = '\0';
981 if (dwType
== REG_EXPAND_SZ
&& path
[0] == '%')
983 WCHAR szTemp
[MAX_PATH
];
985 dwPathLen
= ExpandEnvironmentStringsW(path
, szTemp
, MAX_PATH
);
986 lstrcpynW(path
, szTemp
, dwPathLen
);
989 ret
= RegSetValueExW(shellFolderKey
, value
, 0, REG_SZ
, (LPBYTE
)path
, dwPathLen
* sizeof(WCHAR
));
990 if (ret
!= ERROR_SUCCESS
)
991 hr
= HRESULT_FROM_WIN32(ret
);
998 RegCloseKey(shellFolderKey
);
999 RegCloseKey(userShellFolderKey
);
1000 TRACE("returning 0x%08x\n", hr
);
1004 /* Gets a 'semi-expanded' default value of the CSIDL with index folder into
1005 * pszPath, based on the entries in CSIDL_Data. By semi-expanded, I mean:
1006 * - The entry's szDefaultPath may be either a string value or an integer
1007 * resource identifier. In the latter case, the string value of the resource
1009 * - Depending on the entry's type, the path may begin with an (unexpanded)
1010 * environment variable name. The caller is responsible for expanding
1011 * environment strings if so desired.
1012 * The types that are prepended with environment variables are:
1013 * CSIDL_Type_User: %USERPROFILE%
1014 * CSIDL_Type_AllUsers: %ALLUSERSPROFILE%
1015 * CSIDL_Type_CurrVer: %SystemDrive%
1016 * (Others might make sense too, but as yet are unneeded.)
1018 static HRESULT
_SHGetDefaultValue(BYTE folder
, LPWSTR pszPath
)
1023 WCHAR resourcePath
[MAX_PATH
];
1024 LPCWSTR pDefaultPath
= NULL
;
1026 TRACE("0x%02x,%p\n", folder
, pszPath
);
1028 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1029 return E_INVALIDARG
;
1031 return E_INVALIDARG
;
1034 if (RegOpenKeyExW(HKEY_CURRENT_USER
, L
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
)
1036 /* FIXME assume MAX_PATH size */
1037 dwSize
= MAX_PATH
* sizeof(WCHAR
);
1038 if (RegQueryValueExW(hKey
, CSIDL_Data
[folder
].szValueName
, NULL
, NULL
, (LPBYTE
)pszPath
, &dwSize
) == ERROR_SUCCESS
)
1046 if (CSIDL_Data
[folder
].szDefaultPath
&&
1047 IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
))
1049 if (LoadStringW(shell32_hInstance
,
1050 LOWORD(CSIDL_Data
[folder
].szDefaultPath
), resourcePath
, MAX_PATH
))
1053 pDefaultPath
= resourcePath
;
1057 FIXME("(%d,%s), LoadString failed, missing translation?\n", folder
,
1058 debugstr_w(pszPath
));
1065 pDefaultPath
= CSIDL_Data
[folder
].szDefaultPath
;
1069 switch (CSIDL_Data
[folder
].type
)
1071 case CSIDL_Type_User
:
1072 wcscpy(pszPath
, UserProfileW
);
1074 case CSIDL_Type_AllUsers
:
1075 wcscpy(pszPath
, AllUsersProfileW
);
1077 case CSIDL_Type_CurrVer
:
1078 wcscpy(pszPath
, SystemDriveW
);
1081 ; /* no corresponding env. var, do nothing */
1085 PathAddBackslashW(pszPath
);
1086 wcscat(pszPath
, pDefaultPath
);
1089 TRACE("returning 0x%08x\n", hr
);
1093 /* Gets the (unexpanded) value of the folder with index folder into pszPath.
1094 * The folder's type is assumed to be CSIDL_Type_CurrVer. Its default value
1095 * can be overridden in the HKLM\\szCurrentVersion key.
1096 * If dwFlags has SHGFP_TYPE_DEFAULT set or if the value isn't overridden in
1097 * the registry, uses _SHGetDefaultValue to get the value.
1099 static HRESULT
_SHGetCurrentVersionPath(DWORD dwFlags
, BYTE folder
,
1104 TRACE("0x%08x,0x%02x,%p\n", dwFlags
, folder
, pszPath
);
1106 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1107 return E_INVALIDARG
;
1108 if (CSIDL_Data
[folder
].type
!= CSIDL_Type_CurrVer
)
1109 return E_INVALIDARG
;
1111 return E_INVALIDARG
;
1113 if (dwFlags
& SHGFP_TYPE_DEFAULT
)
1114 hr
= _SHGetDefaultValue(folder
, pszPath
);
1120 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE
, szCurrentVersion
, 0,
1121 NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hKey
, &dwDisp
))
1125 DWORD dwType
, dwPathLen
= MAX_PATH
* sizeof(WCHAR
);
1127 if (RegQueryValueExW(hKey
, CSIDL_Data
[folder
].szValueName
, NULL
,
1128 &dwType
, (LPBYTE
)pszPath
, &dwPathLen
) ||
1129 (dwType
!= REG_SZ
&& dwType
!= REG_EXPAND_SZ
))
1131 hr
= _SHGetDefaultValue(folder
, pszPath
);
1132 dwType
= REG_EXPAND_SZ
;
1133 RegSetValueExW(hKey
, CSIDL_Data
[folder
].szValueName
, 0, dwType
,
1134 (LPBYTE
)pszPath
, (wcslen(pszPath
)+1)*sizeof(WCHAR
));
1138 pszPath
[dwPathLen
/ sizeof(WCHAR
)] = '\0';
1144 TRACE("returning 0x%08x (output path is %s)\n", hr
, debugstr_w(pszPath
));
1148 /* Gets the user's path (unexpanded) for the CSIDL with index folder:
1149 * If SHGFP_TYPE_DEFAULT is set, calls _SHGetDefaultValue for it. Otherwise
1150 * calls _SHGetUserShellFolderPath for it. Where it looks depends on hToken:
1151 * - if hToken is -1, looks in HKEY_USERS\.Default
1152 * - otherwise looks first in HKEY_CURRENT_USER, followed by HKEY_LOCAL_MACHINE
1153 * if HKEY_CURRENT_USER doesn't contain any entries. If both fail, finally
1154 * calls _SHGetDefaultValue for it.
1156 static HRESULT
_SHGetUserProfilePath(HANDLE hToken
, DWORD dwFlags
, BYTE folder
,
1161 TRACE("%p,0x%08x,0x%02x,%p\n", hToken
, dwFlags
, folder
, pszPath
);
1163 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1164 return E_INVALIDARG
;
1166 if (CSIDL_Data
[folder
].type
!= CSIDL_Type_User
)
1167 return E_INVALIDARG
;
1170 return E_INVALIDARG
;
1172 if (dwFlags
& SHGFP_TYPE_DEFAULT
)
1174 if (hToken
!= NULL
&& hToken
!= (HANDLE
)-1)
1176 FIXME("unsupported for user other than current or default\n");
1179 hr
= _SHGetDefaultValue(folder
, pszPath
);
1186 if (hToken
== (HANDLE
)-1)
1188 /* Get the folder of the default user */
1189 hRootKey
= HKEY_USERS
;
1190 userPrefix
= (LPWSTR
)DefaultW
;
1194 /* Get the folder of the current user */
1195 hRootKey
= HKEY_CURRENT_USER
;
1200 /* Get the folder of the specified user */
1202 PTOKEN_USER UserInfo
;
1204 hRootKey
= HKEY_USERS
;
1206 GetTokenInformation(hToken
, TokenUser
, NULL
, 0, &InfoLength
);
1207 UserInfo
= (PTOKEN_USER
)HeapAlloc(GetProcessHeap(), 0, InfoLength
);
1209 if(!GetTokenInformation(hToken
, TokenUser
, UserInfo
, InfoLength
, &InfoLength
))
1211 WARN("GetTokenInformation failed for %x!\n", hToken
);
1212 HeapFree(GetProcessHeap(), 0, UserInfo
);
1216 if(!ConvertSidToStringSidW(UserInfo
->User
.Sid
, &userPrefix
))
1218 WARN("ConvertSidToStringSidW failed for %x!\n", hToken
);
1219 HeapFree(GetProcessHeap(), 0, UserInfo
);
1223 HeapFree(GetProcessHeap(), 0, UserInfo
);
1226 hr
= _SHGetUserShellFolderPath(hRootKey
, userPrefix
, CSIDL_Data
[folder
].szValueName
, pszPath
);
1228 /* Free the memory allocated by ConvertSidToStringSidW */
1229 if(hToken
&& hToken
!= (HANDLE
)-1)
1230 LocalFree(userPrefix
);
1232 if (FAILED(hr
) && hRootKey
!= HKEY_LOCAL_MACHINE
)
1233 hr
= _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE
, NULL
, CSIDL_Data
[folder
].szValueName
, pszPath
);
1236 hr
= _SHGetDefaultValue(folder
, pszPath
);
1239 TRACE("returning 0x%08x (output path is %s)\n", hr
, debugstr_w(pszPath
));
1243 /* Gets the (unexpanded) path for the CSIDL with index folder. If dwFlags has
1244 * SHGFP_TYPE_DEFAULT set, calls _SHGetDefaultValue. Otherwise calls
1245 * _SHGetUserShellFolderPath for it, looking only in HKEY_LOCAL_MACHINE.
1246 * If this fails, falls back to _SHGetDefaultValue.
1248 static HRESULT
_SHGetAllUsersProfilePath(DWORD dwFlags
, BYTE folder
,
1253 TRACE("0x%08x,0x%02x,%p\n", dwFlags
, folder
, pszPath
);
1255 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1256 return E_INVALIDARG
;
1257 if (CSIDL_Data
[folder
].type
!= CSIDL_Type_AllUsers
)
1258 return E_INVALIDARG
;
1260 return E_INVALIDARG
;
1262 if (dwFlags
& SHGFP_TYPE_DEFAULT
)
1263 hr
= _SHGetDefaultValue(folder
, pszPath
);
1266 hr
= _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE
, NULL
,
1267 CSIDL_Data
[folder
].szValueName
, pszPath
);
1269 hr
= _SHGetDefaultValue(folder
, pszPath
);
1271 TRACE("returning 0x%08x (output path is %s)\n", hr
, debugstr_w(pszPath
));
1275 /*************************************************************************
1276 * SHGetFolderPathW [SHELL32.@]
1278 * Convert nFolder to path.
1282 * Failure: standard HRESULT error codes.
1285 * Most values can be overridden in either
1286 * HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
1287 * or in the same location in HKLM.
1288 * The "Shell Folders" registry key was used in NT4 and earlier systems.
1289 * Beginning with Windows 2000, the "User Shell Folders" key is used, so
1290 * changes made to it are made to the former key too. This synchronization is
1291 * done on-demand: not until someone requests the value of one of these paths
1292 * (by calling one of the SHGet functions) is the value synchronized.
1293 * Furthermore, the HKCU paths take precedence over the HKLM paths.
1295 HRESULT WINAPI
SHGetFolderPathW(
1296 HWND hwndOwner
, /* [I] owner window */
1297 int nFolder
, /* [I] CSIDL identifying the folder */
1298 HANDLE hToken
, /* [I] access token */
1299 DWORD dwFlags
, /* [I] which path to return */
1300 LPWSTR pszPath
) /* [O] converted path */
1302 HRESULT hr
= SHGetFolderPathAndSubDirW(hwndOwner
, nFolder
, hToken
, dwFlags
, NULL
, pszPath
);
1303 if(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
) == hr
)
1304 hr
= HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
1308 HRESULT WINAPI
SHGetFolderPathAndSubDirA(
1309 HWND hwndOwner
, /* [I] owner window */
1310 int nFolder
, /* [I] CSIDL identifying the folder */
1311 HANDLE hToken
, /* [I] access token */
1312 DWORD dwFlags
, /* [I] which path to return */
1313 LPCSTR pszSubPath
, /* [I] sub directory of the specified folder */
1314 LPSTR pszPath
) /* [O] converted path */
1318 LPWSTR pszSubPathW
= NULL
;
1319 LPWSTR pszPathW
= NULL
;
1320 TRACE("%08x,%08x,%s\n",nFolder
, dwFlags
, debugstr_w(pszSubPathW
));
1323 pszPathW
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, MAX_PATH
* sizeof(WCHAR
));
1325 hr
= HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY
);
1329 TRACE("%08x,%08x,%s\n",nFolder
, dwFlags
, debugstr_w(pszSubPathW
));
1331 /* SHGetFolderPathAndSubDirW does not distinguish if pszSubPath isn't
1332 * set (null), or an empty string.therefore call it without the parameter set
1333 * if pszSubPath is an empty string
1335 if (pszSubPath
&& pszSubPath
[0]) {
1336 length
= MultiByteToWideChar(CP_ACP
, 0, pszSubPath
, -1, NULL
, 0);
1337 pszSubPathW
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, length
* sizeof(WCHAR
));
1339 hr
= HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY
);
1342 MultiByteToWideChar(CP_ACP
, 0, pszSubPath
, -1, pszSubPathW
, length
);
1345 hr
= SHGetFolderPathAndSubDirW(hwndOwner
, nFolder
, hToken
, dwFlags
, pszSubPathW
, pszPathW
);
1347 if (SUCCEEDED(hr
) && pszPath
)
1348 WideCharToMultiByte(CP_ACP
, 0, pszPathW
, -1, pszPath
, MAX_PATH
, NULL
, NULL
);
1351 HeapFree(GetProcessHeap(), 0, pszPathW
);
1352 HeapFree(GetProcessHeap(), 0, pszSubPathW
);
1356 HRESULT WINAPI
SHGetFolderPathAndSubDirW(
1357 HWND hwndOwner
, /* [I] owner window */
1358 int nFolder
, /* [I] CSIDL identifying the folder */
1359 HANDLE hToken
, /* [I] access token */
1360 DWORD dwFlags
, /* [I] which path to return */
1361 LPCWSTR pszSubPath
,/* [I] sub directory of the specified folder */
1362 LPWSTR pszPath
) /* [O] converted path */
1365 WCHAR szBuildPath
[MAX_PATH
], szTemp
[MAX_PATH
];
1366 DWORD folder
= nFolder
& CSIDL_FOLDER_MASK
; //FIXME
1370 TRACE("%p,%p,nFolder=0x%04x,%s\n", hwndOwner
,pszPath
,nFolder
,debugstr_w(pszSubPath
));
1372 /* Windows always NULL-terminates the resulting path regardless of success
1373 * or failure, so do so first
1378 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1379 return E_INVALIDARG
;
1380 if ((SHGFP_TYPE_CURRENT
!= dwFlags
) && (SHGFP_TYPE_DEFAULT
!= dwFlags
))
1381 return E_INVALIDARG
;
1383 type
= CSIDL_Data
[folder
].type
;
1386 case CSIDL_Type_Disallowed
:
1389 case CSIDL_Type_NonExistent
:
1392 case CSIDL_Type_WindowsPath
:
1393 GetWindowsDirectoryW(szTemp
, MAX_PATH
);
1394 if (CSIDL_Data
[folder
].szDefaultPath
&&
1395 !IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
) &&
1396 *CSIDL_Data
[folder
].szDefaultPath
)
1398 PathAddBackslashW(szTemp
);
1399 wcscat(szTemp
, CSIDL_Data
[folder
].szDefaultPath
);
1403 case CSIDL_Type_SystemPath
:
1404 GetSystemDirectoryW(szTemp
, MAX_PATH
);
1405 if (CSIDL_Data
[folder
].szDefaultPath
&&
1406 !IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
) &&
1407 *CSIDL_Data
[folder
].szDefaultPath
)
1409 PathAddBackslashW(szTemp
);
1410 wcscat(szTemp
, CSIDL_Data
[folder
].szDefaultPath
);
1414 case CSIDL_Type_CurrVer
:
1415 hr
= _SHGetCurrentVersionPath(dwFlags
, folder
, szTemp
);
1417 case CSIDL_Type_User
:
1418 hr
= _SHGetUserProfilePath(hToken
, dwFlags
, folder
, szTemp
);
1420 case CSIDL_Type_AllUsers
:
1421 hr
= _SHGetAllUsersProfilePath(dwFlags
, folder
, szTemp
);
1424 FIXME("bogus type %d, please fix\n", type
);
1429 /* Expand environment strings if necessary */
1432 DWORD ExpandRet
= ExpandEnvironmentStringsW(szTemp
, szBuildPath
, MAX_PATH
);
1434 if (ExpandRet
> MAX_PATH
)
1435 hr
= HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
1436 else if (ExpandRet
== 0)
1437 hr
= HRESULT_FROM_WIN32(GetLastError());
1443 wcscpy(szBuildPath
, szTemp
);
1446 if (FAILED(hr
)) goto end
;
1449 /* make sure the new path does not exceed th bufferlength
1450 * rememebr to backslash and the termination */
1451 if(MAX_PATH
< (wcslen(szBuildPath
) + wcslen(pszSubPath
) + 2)) {
1452 hr
= HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE
);
1455 PathAppendW(szBuildPath
, pszSubPath
);
1456 PathRemoveBackslashW(szBuildPath
);
1458 /* Copy the path if it's available before we might return */
1459 if (SUCCEEDED(hr
) && pszPath
)
1460 wcscpy(pszPath
, szBuildPath
);
1462 /* if we don't care about existing directories we are ready */
1463 if(nFolder
& CSIDL_FLAG_DONT_VERIFY
) goto end
;
1465 if (PathFileExistsW(szBuildPath
)) goto end
;
1467 /* not existing but we are not allowed to create it. The return value
1468 * is verified against shell32 version 6.0.
1470 if (!(nFolder
& CSIDL_FLAG_CREATE
))
1472 hr
= HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
);
1476 /* create directory/directories */
1477 ret
= SHCreateDirectoryExW(hwndOwner
, szBuildPath
, NULL
);
1478 if (ret
&& ret
!= ERROR_ALREADY_EXISTS
)
1480 WARN("Failed to create directory %s.\n", debugstr_w(szBuildPath
));
1485 TRACE("Created missing system directory %s\n", debugstr_w(szBuildPath
));
1487 TRACE("returning 0x%08x (final path is %s)\n", hr
, debugstr_w(szBuildPath
));
1491 /*************************************************************************
1492 * SHGetFolderPathA [SHELL32.@]
1494 * See SHGetFolderPathW.
1496 HRESULT WINAPI
SHGetFolderPathA(
1503 WCHAR szTemp
[MAX_PATH
];
1506 TRACE("%p,%p,nFolder=0x%04x\n",hwndOwner
,pszPath
,nFolder
);
1510 hr
= SHGetFolderPathW(hwndOwner
, nFolder
, hToken
, dwFlags
, szTemp
);
1511 if (SUCCEEDED(hr
) && pszPath
)
1512 WideCharToMultiByte(CP_ACP
, 0, szTemp
, -1, pszPath
, MAX_PATH
, NULL
,
1518 /* For each folder in folders, if its value has not been set in the registry,
1519 * calls _SHGetUserProfilePath or _SHGetAllUsersProfilePath (depending on the
1520 * folder's type) to get the unexpanded value first.
1521 * Writes the unexpanded value to User Shell Folders, and queries it with
1522 * SHGetFolderPathW to force the creation of the directory if it doesn't
1523 * already exist. SHGetFolderPathW also returns the expanded value, which
1524 * this then writes to Shell Folders.
1526 static HRESULT
_SHRegisterFolders(HKEY hRootKey
, HANDLE hToken
,
1527 LPCWSTR szUserShellFolderPath
, LPCWSTR szShellFolderPath
, const UINT folders
[],
1531 WCHAR path
[MAX_PATH
];
1533 HKEY hUserKey
= NULL
, hKey
= NULL
;
1534 DWORD dwDisp
, dwType
, dwPathLen
;
1537 TRACE("%p,%p,%s,%p,%u\n", hRootKey
, hToken
,
1538 debugstr_w(szUserShellFolderPath
), folders
, foldersLen
);
1540 ret
= RegCreateKeyExW(hRootKey
, szUserShellFolderPath
, 0, NULL
, 0,
1541 KEY_ALL_ACCESS
, NULL
, &hUserKey
, &dwDisp
);
1543 hr
= HRESULT_FROM_WIN32(ret
);
1546 ret
= RegCreateKeyExW(hRootKey
, szShellFolderPath
, 0, NULL
, 0,
1547 KEY_ALL_ACCESS
, NULL
, &hKey
, &dwDisp
);
1549 hr
= HRESULT_FROM_WIN32(ret
);
1551 for (i
= 0; SUCCEEDED(hr
) && i
< foldersLen
; i
++)
1553 dwPathLen
= MAX_PATH
* sizeof(WCHAR
);
1554 if (RegQueryValueExW(hUserKey
, CSIDL_Data
[folders
[i
]].szValueName
, NULL
,
1555 &dwType
, (LPBYTE
)path
, &dwPathLen
) || (dwType
!= REG_SZ
&&
1556 dwType
!= REG_EXPAND_SZ
))
1559 if (CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_User
)
1560 _SHGetUserProfilePath(hToken
, SHGFP_TYPE_DEFAULT
, folders
[i
],
1562 else if (CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_AllUsers
)
1563 _SHGetAllUsersProfilePath(SHGFP_TYPE_DEFAULT
, folders
[i
], path
);
1564 else if (CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_WindowsPath
)
1565 GetWindowsDirectoryW(path
, MAX_PATH
);
1570 ret
= RegSetValueExW(hUserKey
,
1571 CSIDL_Data
[folders
[i
]].szValueName
, 0, REG_EXPAND_SZ
,
1572 (LPBYTE
)path
, (wcslen(path
) + 1) * sizeof(WCHAR
));
1574 hr
= HRESULT_FROM_WIN32(ret
);
1577 // Don't fail if folder can't be created
1578 if (SUCCEEDED(SHGetFolderPathW(NULL
, folders
[i
] | CSIDL_FLAG_CREATE
,
1579 hToken
, SHGFP_TYPE_DEFAULT
, path
)))
1581 ret
= RegSetValueExW(hKey
, CSIDL_Data
[folders
[i
]].szValueName
, 0, REG_SZ
,
1582 (LPBYTE
)path
, (wcslen(path
) + 1) * sizeof(WCHAR
));
1584 hr
= HRESULT_FROM_WIN32(ret
);
1591 RegCloseKey(hUserKey
);
1595 TRACE("returning 0x%08x\n", hr
);
1599 static HRESULT
_SHRegisterUserShellFolders(BOOL bDefault
)
1601 static const UINT folders
[] = {
1612 CSIDL_DESKTOPDIRECTORY
,
1616 CSIDL_LOCAL_APPDATA
,
1617 CSIDL_INTERNET_CACHE
,
1623 WCHAR userShellFolderPath
[MAX_PATH
], shellFolderPath
[MAX_PATH
];
1624 LPCWSTR pUserShellFolderPath
, pShellFolderPath
;
1629 TRACE("%s\n", bDefault
? "TRUE" : "FALSE");
1632 hToken
= (HANDLE
)-1;
1633 hRootKey
= HKEY_USERS
;
1634 wcscpy(userShellFolderPath
, DefaultW
);
1635 PathAddBackslashW(userShellFolderPath
);
1636 wcscat(userShellFolderPath
, szSHUserFolders
);
1637 pUserShellFolderPath
= userShellFolderPath
;
1638 wcscpy(shellFolderPath
, DefaultW
);
1639 PathAddBackslashW(shellFolderPath
);
1640 wcscat(shellFolderPath
, szSHFolders
);
1641 pShellFolderPath
= shellFolderPath
;
1646 hRootKey
= HKEY_CURRENT_USER
;
1647 pUserShellFolderPath
= szSHUserFolders
;
1648 pShellFolderPath
= szSHFolders
;
1651 hr
= _SHRegisterFolders(hRootKey
, hToken
, pUserShellFolderPath
,
1652 pShellFolderPath
, folders
, sizeof(folders
) / sizeof(folders
[0]));
1653 TRACE("returning 0x%08x\n", hr
);
1657 static HRESULT
_SHRegisterCommonShellFolders(void)
1659 static const UINT folders
[] = {
1660 CSIDL_COMMON_STARTMENU
,
1661 CSIDL_COMMON_PROGRAMS
,
1662 CSIDL_COMMON_STARTUP
,
1663 CSIDL_COMMON_DESKTOPDIRECTORY
,
1664 CSIDL_COMMON_FAVORITES
,
1665 CSIDL_COMMON_APPDATA
,
1666 CSIDL_COMMON_TEMPLATES
,
1667 CSIDL_COMMON_DOCUMENTS
,
1672 hr
= _SHRegisterFolders(HKEY_LOCAL_MACHINE
, NULL
, szSHUserFolders
,
1673 szSHFolders
, folders
, sizeof(folders
) / sizeof(folders
[0]));
1674 TRACE("returning 0x%08x\n", hr
);
1678 /* Register the default values in the registry, as some apps seem to depend
1679 * on their presence. The set registered was taken from Windows XP.
1681 EXTERN_C HRESULT
SHELL_RegisterShellFolders(void)
1685 hr
= _SHRegisterUserShellFolders(TRUE
);
1687 hr
= _SHRegisterUserShellFolders(FALSE
);
1689 hr
= _SHRegisterCommonShellFolders();
1693 /*************************************************************************
1694 * SHGetSpecialFolderPathA [SHELL32.@]
1696 BOOL WINAPI
SHGetSpecialFolderPathA (
1702 return (SHGetFolderPathA(
1704 nFolder
+ (bCreate
? CSIDL_FLAG_CREATE
: 0),
1707 szPath
)) == S_OK
? TRUE
: FALSE
;
1710 /*************************************************************************
1711 * SHGetSpecialFolderPathW
1713 BOOL WINAPI
SHGetSpecialFolderPathW (
1719 return (SHGetFolderPathW(
1721 nFolder
+ (bCreate
? CSIDL_FLAG_CREATE
: 0),
1724 szPath
)) == S_OK
? TRUE
: FALSE
;
1727 /*************************************************************************
1728 * SHGetFolderLocation [SHELL32.@]
1730 * Gets the folder locations from the registry and creates a pidl.
1734 * nFolder [I] CSIDL_xxxxx
1735 * hToken [I] token representing user, or NULL for current user, or -1 for
1737 * dwReserved [I] must be zero
1738 * ppidl [O] PIDL of a special folder
1742 * Failure: Standard OLE-defined error result, S_FALSE or E_INVALIDARG
1745 * Creates missing reg keys and directories.
1746 * Mostly forwards to SHGetFolderPathW, but a few values of nFolder return
1747 * virtual folders that are handled here.
1749 HRESULT WINAPI
SHGetFolderLocation(
1754 LPITEMIDLIST
*ppidl
)
1756 HRESULT hr
= E_INVALIDARG
;
1758 TRACE("%p 0x%08x %p 0x%08x %p\n",
1759 hwndOwner
, nFolder
, hToken
, dwReserved
, ppidl
);
1762 return E_INVALIDARG
;
1764 return E_INVALIDARG
;
1766 /* The virtual folders' locations are not user-dependent */
1771 *ppidl
= _ILCreateDesktop();
1774 case CSIDL_PERSONAL
:
1775 *ppidl
= _ILCreateMyDocuments();
1778 case CSIDL_INTERNET
:
1779 *ppidl
= _ILCreateIExplore();
1782 case CSIDL_CONTROLS
:
1783 *ppidl
= _ILCreateControlPanel();
1786 case CSIDL_PRINTERS
:
1787 *ppidl
= _ILCreatePrinters();
1790 case CSIDL_BITBUCKET
:
1791 *ppidl
= _ILCreateBitBucket();
1795 *ppidl
= _ILCreateMyComputer();
1799 *ppidl
= _ILCreateNetwork();
1804 WCHAR szPath
[MAX_PATH
];
1806 hr
= SHGetFolderPathW(hwndOwner
, nFolder
, hToken
,
1807 SHGFP_TYPE_CURRENT
, szPath
);
1812 TRACE("Value=%s\n", debugstr_w(szPath
));
1813 hr
= SHILCreateFromPathW(szPath
, ppidl
, &attributes
);
1815 else if (hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
))
1817 /* unlike SHGetFolderPath, SHGetFolderLocation in shell32
1818 * version 6.0 returns E_FAIL for nonexistent paths
1827 TRACE("-- (new pidl %p)\n",*ppidl
);
1831 /*************************************************************************
1832 * SHGetSpecialFolderLocation [SHELL32.@]
1835 * In NT5, SHGetSpecialFolderLocation needs the <winntdir>/Recent
1838 HRESULT WINAPI
SHGetSpecialFolderLocation(
1841 LPITEMIDLIST
* ppidl
)
1843 HRESULT hr
= E_INVALIDARG
;
1845 TRACE("(%p,0x%x,%p)\n", hwndOwner
,nFolder
,ppidl
);
1848 return E_INVALIDARG
;
1850 hr
= SHGetFolderLocation(hwndOwner
, nFolder
, NULL
, 0, ppidl
);