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
29 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
32 ########## Combining and Constructing paths ##########
35 /*************************************************************************
36 * PathAppend [SHELL32.36]
38 BOOL WINAPI
PathAppendAW(
42 if (SHELL_OsIsUnicode())
43 return PathAppendW(lpszPath1
, lpszPath2
);
44 return PathAppendA(lpszPath1
, lpszPath2
);
47 /*************************************************************************
48 * PathBuildRoot [SHELL32.30]
50 LPVOID WINAPI
PathBuildRootAW(LPVOID lpszPath
, int drive
)
52 if(SHELL_OsIsUnicode())
53 return PathBuildRootW(lpszPath
, drive
);
54 return PathBuildRootA(lpszPath
, drive
);
57 /*************************************************************************
58 * PathGetExtensionA [internal]
62 * return value points to the first char after the dot
64 static LPSTR
PathGetExtensionA(LPCSTR lpszPath
)
66 TRACE("(%s)\n",lpszPath
);
68 lpszPath
= PathFindExtensionA(lpszPath
);
69 return (LPSTR
)(*lpszPath
?(lpszPath
+1):lpszPath
);
72 /*************************************************************************
73 * PathGetExtensionW [internal]
75 LPWSTR
PathGetExtensionW(LPCWSTR lpszPath
)
77 TRACE("(%s)\n",debugstr_w(lpszPath
));
79 lpszPath
= PathFindExtensionW(lpszPath
);
80 return (LPWSTR
)(*lpszPath
?(lpszPath
+1):lpszPath
);
83 /*************************************************************************
84 * SHPathGetExtension [SHELL32.158]
86 LPVOID WINAPI
SHPathGetExtensionW(LPCWSTR lpszPath
, DWORD void1
, DWORD void2
)
88 return PathGetExtensionW(lpszPath
);
91 /*************************************************************************
92 * PathRemoveFileSpec [SHELL32.35]
94 BOOL WINAPI
PathRemoveFileSpecAW(LPVOID lpszPath
)
96 if (SHELL_OsIsUnicode())
97 return PathRemoveFileSpecW(lpszPath
);
98 return PathRemoveFileSpecA(lpszPath
);
105 /*************************************************************************
106 * PathGetShortPathA [internal]
108 static void PathGetShortPathA(LPSTR pszPath
)
112 TRACE("%s\n", pszPath
);
114 if (GetShortPathNameA(pszPath
, path
, MAX_PATH
))
116 lstrcpyA(pszPath
, path
);
120 /*************************************************************************
121 * PathGetShortPathW [internal]
123 static void PathGetShortPathW(LPWSTR pszPath
)
125 WCHAR path
[MAX_PATH
];
127 TRACE("%s\n", debugstr_w(pszPath
));
129 if (GetShortPathNameW(pszPath
, path
, MAX_PATH
))
131 wcscpy(pszPath
, path
);
135 /*************************************************************************
136 * PathGetShortPath [SHELL32.92]
138 VOID WINAPI
PathGetShortPathAW(LPVOID pszPath
)
140 if(SHELL_OsIsUnicode())
141 PathGetShortPathW(pszPath
);
142 PathGetShortPathA(pszPath
);
146 ########## Path Testing ##########
149 /*************************************************************************
150 * PathIsRoot [SHELL32.29]
152 BOOL WINAPI
PathIsRootAW(LPCVOID lpszPath
)
154 if (SHELL_OsIsUnicode())
155 return PathIsRootW(lpszPath
);
156 return PathIsRootA(lpszPath
);
159 /*************************************************************************
160 * PathIsExeA [internal]
162 static BOOL
PathIsExeA (LPCSTR lpszPath
)
164 LPCSTR lpszExtension
= PathGetExtensionA(lpszPath
);
166 static const char * const lpszExtensions
[] =
167 {"exe", "com", "pif", "cmd", "bat", "scf", "scr", NULL
};
169 TRACE("path=%s\n",lpszPath
);
171 for(i
=0; lpszExtensions
[i
]; i
++)
172 if (!lstrcmpiA(lpszExtension
,lpszExtensions
[i
])) return TRUE
;
177 /*************************************************************************
178 * PathIsExeW [internal]
180 static BOOL
PathIsExeW (LPCWSTR lpszPath
)
182 LPCWSTR lpszExtension
= PathGetExtensionW(lpszPath
);
184 static const WCHAR lpszExtensions
[][4] =
185 {{'e','x','e','\0'}, {'c','o','m','\0'}, {'p','i','f','\0'},
186 {'c','m','d','\0'}, {'b','a','t','\0'}, {'s','c','f','\0'},
187 {'s','c','r','\0'}, {'\0'} };
189 TRACE("path=%s\n",debugstr_w(lpszPath
));
191 for(i
=0; lpszExtensions
[i
][0]; i
++)
192 if (!strcmpiW(lpszExtension
,lpszExtensions
[i
])) return TRUE
;
197 /*************************************************************************
198 * PathIsExe [SHELL32.43]
200 BOOL WINAPI
PathIsExeAW (LPCVOID path
)
202 if (SHELL_OsIsUnicode())
203 return PathIsExeW (path
);
204 return PathIsExeA(path
);
207 /*************************************************************************
208 * PathFileExists [SHELL32.45]
210 BOOL WINAPI
PathFileExistsAW (LPCVOID lpszPath
)
212 if (SHELL_OsIsUnicode())
213 return PathFileExistsW (lpszPath
);
214 return PathFileExistsA (lpszPath
);
217 /*************************************************************************
218 * PathIsSameRoot [SHELL32.650]
220 BOOL WINAPI
PathIsSameRootAW(LPCVOID lpszPath1
, LPCVOID lpszPath2
)
222 if (SHELL_OsIsUnicode())
223 return PathIsSameRootW(lpszPath1
, lpszPath2
);
224 return PathIsSameRootA(lpszPath1
, lpszPath2
);
227 /*************************************************************************
228 * IsLFNDriveA [SHELL32.41]
230 BOOL WINAPI
IsLFNDriveA(LPCSTR lpszPath
)
234 if (!GetVolumeInformationA(lpszPath
, NULL
, 0, NULL
, &fnlen
, NULL
, NULL
, 0))
239 /*************************************************************************
240 * IsLFNDriveW [SHELL32.42]
242 BOOL WINAPI
IsLFNDriveW(LPCWSTR lpszPath
)
246 if (!GetVolumeInformationW(lpszPath
, NULL
, 0, NULL
, &fnlen
, NULL
, NULL
, 0))
251 /*************************************************************************
252 * IsLFNDrive [SHELL32.119]
254 BOOL WINAPI
IsLFNDriveAW(LPCVOID lpszPath
)
256 if (SHELL_OsIsUnicode())
257 return IsLFNDriveW(lpszPath
);
258 return IsLFNDriveA(lpszPath
);
262 ########## Creating Something Unique ##########
264 /*************************************************************************
265 * PathMakeUniqueNameA [internal]
267 BOOL WINAPI
PathMakeUniqueNameA(
270 LPCSTR lpszShortName
,
274 FIXME("%p %u %s %s %s stub\n",
275 lpszBuffer
, dwBuffSize
, debugstr_a(lpszShortName
),
276 debugstr_a(lpszLongName
), debugstr_a(lpszPathName
));
280 /*************************************************************************
281 * PathMakeUniqueNameW [internal]
283 BOOL WINAPI
PathMakeUniqueNameW(
286 LPCWSTR lpszShortName
,
287 LPCWSTR lpszLongName
,
288 LPCWSTR lpszPathName
)
290 FIXME("%p %u %s %s %s stub\n",
291 lpszBuffer
, dwBuffSize
, debugstr_w(lpszShortName
),
292 debugstr_w(lpszLongName
), debugstr_w(lpszPathName
));
296 /*************************************************************************
297 * PathMakeUniqueName [SHELL32.47]
299 BOOL WINAPI
PathMakeUniqueNameAW(
302 LPCVOID lpszShortName
,
303 LPCVOID lpszLongName
,
304 LPCVOID lpszPathName
)
306 if (SHELL_OsIsUnicode())
307 return PathMakeUniqueNameW(lpszBuffer
,dwBuffSize
, lpszShortName
,lpszLongName
,lpszPathName
);
308 return PathMakeUniqueNameA(lpszBuffer
,dwBuffSize
, lpszShortName
,lpszLongName
,lpszPathName
);
311 /*************************************************************************
312 * PathYetAnotherMakeUniqueName [SHELL32.75]
315 * exported by ordinal
317 BOOL WINAPI
PathYetAnotherMakeUniqueName(
319 LPCWSTR lpszPathName
,
320 LPCWSTR lpszShortName
,
321 LPCWSTR lpszLongName
)
323 FIXME("(%p, %s, %s ,%s):stub.\n",
324 lpszBuffer
, debugstr_w(lpszPathName
), debugstr_w(lpszShortName
), debugstr_w(lpszLongName
));
330 ########## cleaning and resolving paths ##########
333 /*************************************************************************
334 * PathCleanupSpec [SHELL32.171]
336 * lpszFile is changed in place.
338 int WINAPI
PathCleanupSpec( LPCWSTR lpszPathW
, LPWSTR lpszFileW
)
344 if (SHELL_OsIsUnicode())
346 LPWSTR p
= lpszFileW
;
348 TRACE("Cleanup %s\n",debugstr_w(lpszFileW
));
351 length
= wcslen(lpszPathW
);
355 int gct
= PathGetCharTypeW(*p
);
356 if (gct
== GCT_INVALID
|| gct
== GCT_WILD
|| gct
== GCT_SEPARATOR
)
359 rc
|= PCS_REPLACEDCHAR
;
365 if (length
+ i
== MAX_PATH
)
367 rc
|= PCS_FATAL
| PCS_PATHTOOLONG
;
375 LPSTR lpszFileA
= (LPSTR
)lpszFileW
;
376 LPCSTR lpszPathA
= (LPCSTR
)lpszPathW
;
379 TRACE("Cleanup %s\n",debugstr_a(lpszFileA
));
382 length
= strlen(lpszPathA
);
386 int gct
= PathGetCharTypeA(*p
);
387 if (gct
== GCT_INVALID
|| gct
== GCT_WILD
|| gct
== GCT_SEPARATOR
)
390 rc
|= PCS_REPLACEDCHAR
;
396 if (length
+ i
== MAX_PATH
)
398 rc
|= PCS_FATAL
| PCS_PATHTOOLONG
;
407 /*************************************************************************
408 * PathQualifyA [SHELL32]
410 BOOL WINAPI
PathQualifyA(LPCSTR pszPath
)
412 FIXME("%s\n",pszPath
);
416 /*************************************************************************
417 * PathQualifyW [SHELL32]
419 BOOL WINAPI
PathQualifyW(LPCWSTR pszPath
)
421 FIXME("%s\n",debugstr_w(pszPath
));
425 /*************************************************************************
426 * PathQualify [SHELL32.49]
428 BOOL WINAPI
PathQualifyAW(LPCVOID pszPath
)
430 if (SHELL_OsIsUnicode())
431 return PathQualifyW(pszPath
);
432 return PathQualifyA(pszPath
);
435 /*************************************************************************
436 * PathResolveA [SHELL32.51]
438 BOOL WINAPI
PathResolveA(
443 FIXME("(%s,%p,0x%08x),stub!\n",
444 lpszPath
, *alpszPaths
, dwFlags
);
448 /*************************************************************************
449 * PathResolveW [SHELL32]
451 BOOL WINAPI
PathResolveW(
456 FIXME("(%s,%p,0x%08x),stub!\n",
457 debugstr_w(lpszPath
), debugstr_w(*alpszPaths
), dwFlags
);
461 /*************************************************************************
462 * PathResolve [SHELL32.51]
464 BOOL WINAPI
PathResolveAW(
469 if (SHELL_OsIsUnicode())
470 return PathResolveW(lpszPath
, (LPCWSTR
*)alpszPaths
, dwFlags
);
471 return PathResolveA(lpszPath
, (LPCSTR
*)alpszPaths
, dwFlags
);
474 /*************************************************************************
475 * PathProcessCommandA [SHELL32.653]
477 LONG WINAPI
PathProcessCommandA (
483 FIXME("%s %p 0x%04x 0x%04x stub\n",
484 lpszPath
, lpszBuff
, dwBuffSize
, dwFlags
);
485 if(!lpszPath
) return -1;
486 if(lpszBuff
) strcpy(lpszBuff
, lpszPath
);
487 return strlen(lpszPath
);
490 /*************************************************************************
491 * PathProcessCommandW
493 LONG WINAPI
PathProcessCommandW (
499 FIXME("(%s, %p, 0x%04x, 0x%04x) stub\n",
500 debugstr_w(lpszPath
), lpszBuff
, dwBuffSize
, dwFlags
);
501 if(!lpszPath
) return -1;
502 if(lpszBuff
) wcscpy(lpszBuff
, lpszPath
);
503 return wcslen(lpszPath
);
506 /*************************************************************************
507 * PathProcessCommand (SHELL32.653)
509 LONG WINAPI
PathProcessCommandAW (
515 if (SHELL_OsIsUnicode())
516 return PathProcessCommandW(lpszPath
, lpszBuff
, dwBuffSize
, dwFlags
);
517 return PathProcessCommandA(lpszPath
, lpszBuff
, dwBuffSize
, dwFlags
);
521 ########## special ##########
524 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'};
525 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'};
526 static const WCHAR AppDataW
[] = {'A','p','p','D','a','t','a','\0'};
527 static const WCHAR CacheW
[] = {'C','a','c','h','e','\0'};
528 static const WCHAR CD_BurningW
[] = {'C','D',' ','B','u','r','n','i','n','g','\0'};
529 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'};
530 static const WCHAR Common_AppDataW
[] = {'C','o','m','m','o','n',' ','A','p','p','D','a','t','a','\0'};
531 static const WCHAR Common_DesktopW
[] = {'C','o','m','m','o','n',' ','D','e','s','k','t','o','p','\0'};
532 static const WCHAR Common_DocumentsW
[] = {'C','o','m','m','o','n',' ','D','o','c','u','m','e','n','t','s','\0'};
533 static const WCHAR CommonFilesDirW
[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r','\0'};
534 static const WCHAR CommonMusicW
[] = {'C','o','m','m','o','n','M','u','s','i','c','\0'};
535 static const WCHAR CommonPicturesW
[] = {'C','o','m','m','o','n','P','i','c','t','u','r','e','s','\0'};
536 static const WCHAR Common_ProgramsW
[] = {'C','o','m','m','o','n',' ','P','r','o','g','r','a','m','s','\0'};
537 static const WCHAR Common_StartUpW
[] = {'C','o','m','m','o','n',' ','S','t','a','r','t','U','p','\0'};
538 static const WCHAR Common_Start_MenuW
[] = {'C','o','m','m','o','n',' ','S','t','a','r','t',' ','M','e','n','u','\0'};
539 static const WCHAR Common_TemplatesW
[] = {'C','o','m','m','o','n',' ','T','e','m','p','l','a','t','e','s','\0'};
540 static const WCHAR CommonVideoW
[] = {'C','o','m','m','o','n','V','i','d','e','o','\0'};
541 static const WCHAR CookiesW
[] = {'C','o','o','k','i','e','s','\0'};
542 static const WCHAR DesktopW
[] = {'D','e','s','k','t','o','p','\0'};
543 static const WCHAR FavoritesW
[] = {'F','a','v','o','r','i','t','e','s','\0'};
544 static const WCHAR FontsW
[] = {'F','o','n','t','s','\0'};
545 static const WCHAR HistoryW
[] = {'H','i','s','t','o','r','y','\0'};
546 static const WCHAR Local_AppDataW
[] = {'L','o','c','a','l',' ','A','p','p','D','a','t','a','\0'};
547 static const WCHAR My_MusicW
[] = {'M','y',' ','M','u','s','i','c','\0'};
548 static const WCHAR My_PicturesW
[] = {'M','y',' ','P','i','c','t','u','r','e','s','\0'};
549 static const WCHAR My_VideoW
[] = {'M','y',' ','V','i','d','e','o','\0'};
550 static const WCHAR NetHoodW
[] = {'N','e','t','H','o','o','d','\0'};
551 static const WCHAR PersonalW
[] = {'P','e','r','s','o','n','a','l','\0'};
552 static const WCHAR PrintHoodW
[] = {'P','r','i','n','t','H','o','o','d','\0'};
553 static const WCHAR ProgramFilesDirW
[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r','\0'};
554 static const WCHAR ProgramsW
[] = {'P','r','o','g','r','a','m','s','\0'};
555 static const WCHAR RecentW
[] = {'R','e','c','e','n','t','\0'};
556 static const WCHAR ResourcesW
[] = {'R','e','s','o','u','r','c','e','s','\0'};
557 static const WCHAR SendToW
[] = {'S','e','n','d','T','o','\0'};
558 static const WCHAR StartUpW
[] = {'S','t','a','r','t','U','p','\0'};
559 static const WCHAR Start_MenuW
[] = {'S','t','a','r','t',' ','M','e','n','u','\0'};
560 static const WCHAR TemplatesW
[] = {'T','e','m','p','l','a','t','e','s','\0'};
561 static const WCHAR DefaultW
[] = {'.','D','e','f','a','u','l','t','\0'};
562 static const WCHAR AllUsersProfileW
[] = {'%','A','L','L','U','S','E','R','S','P','R','O','F','I','L','E','%','\0'};
563 static const WCHAR UserProfileW
[] = {'%','U','S','E','R','P','R','O','F','I','L','E','%','\0'};
564 static const WCHAR SystemDriveW
[] = {'%','S','y','s','t','e','m','D','r','i','v','e','%','\0'};
565 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};
566 static const WCHAR ProfilesDirectoryW
[] = {'P','r','o','f','i','l','e','s','D','i','r','e','c','t','o','r','y',0};
567 static const WCHAR AllUsersProfileValueW
[] = {'A','l','l','U','s','e','r','s','P','r','o','f','i','l','e','\0'};
568 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'};
569 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'};
570 /* This defaults to L"Documents and Settings" on Windows 2000/XP, but we're
571 * acting more Windows 9x-like for now.
573 static const WCHAR szDefaultProfileDirW
[] = {'p','r','o','f','i','l','e','s','\0'};
574 static const WCHAR AllUsersW
[] = {'A','l','l',' ','U','s','e','r','s','\0'};
576 typedef enum _CSIDL_Type
{
580 CSIDL_Type_Disallowed
,
581 CSIDL_Type_NonExistent
,
582 CSIDL_Type_WindowsPath
,
583 CSIDL_Type_SystemPath
,
590 LPCWSTR szDefaultPath
; /* fallback string or resource ID */
593 static const CSIDL_DATA CSIDL_Data
[] =
595 { /* 0x00 - CSIDL_DESKTOP */
598 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY
)
600 { /* 0x01 - CSIDL_INTERNET */
601 CSIDL_Type_Disallowed
,
605 { /* 0x02 - CSIDL_PROGRAMS */
608 MAKEINTRESOURCEW(IDS_PROGRAMS
)
610 { /* 0x03 - CSIDL_CONTROLS (.CPL files) */
611 CSIDL_Type_SystemPath
,
615 { /* 0x04 - CSIDL_PRINTERS */
616 CSIDL_Type_SystemPath
,
620 { /* 0x05 - CSIDL_PERSONAL */
623 MAKEINTRESOURCEW(IDS_PERSONAL
)
625 { /* 0x06 - CSIDL_FAVORITES */
628 MAKEINTRESOURCEW(IDS_FAVORITES
)
630 { /* 0x07 - CSIDL_STARTUP */
633 MAKEINTRESOURCEW(IDS_STARTUP
)
635 { /* 0x08 - CSIDL_RECENT */
638 MAKEINTRESOURCEW(IDS_RECENT
)
640 { /* 0x09 - CSIDL_SENDTO */
643 MAKEINTRESOURCEW(IDS_SENDTO
)
645 { /* 0x0a - CSIDL_BITBUCKET - Recycle Bin */
646 CSIDL_Type_Disallowed
,
650 { /* 0x0b - CSIDL_STARTMENU */
653 MAKEINTRESOURCEW(IDS_STARTMENU
)
655 { /* 0x0c - CSIDL_MYDOCUMENTS */
656 CSIDL_Type_Disallowed
, /* matches WinXP--can't get its path */
660 { /* 0x0d - CSIDL_MYMUSIC */
663 MAKEINTRESOURCEW(IDS_MYMUSIC
)
665 { /* 0x0e - CSIDL_MYVIDEO */
668 MAKEINTRESOURCEW(IDS_MYVIDEO
)
670 { /* 0x0f - unassigned */
671 CSIDL_Type_Disallowed
,
675 { /* 0x10 - CSIDL_DESKTOPDIRECTORY */
678 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY
)
680 { /* 0x11 - CSIDL_DRIVES */
681 CSIDL_Type_Disallowed
,
685 { /* 0x12 - CSIDL_NETWORK */
686 CSIDL_Type_Disallowed
,
690 { /* 0x13 - CSIDL_NETHOOD */
693 MAKEINTRESOURCEW(IDS_NETHOOD
)
695 { /* 0x14 - CSIDL_FONTS */
696 CSIDL_Type_WindowsPath
,
700 { /* 0x15 - CSIDL_TEMPLATES */
703 MAKEINTRESOURCEW(IDS_TEMPLATES
)
705 { /* 0x16 - CSIDL_COMMON_STARTMENU */
708 MAKEINTRESOURCEW(IDS_STARTMENU
)
710 { /* 0x17 - CSIDL_COMMON_PROGRAMS */
713 MAKEINTRESOURCEW(IDS_PROGRAMS
)
715 { /* 0x18 - CSIDL_COMMON_STARTUP */
718 MAKEINTRESOURCEW(IDS_STARTUP
)
720 { /* 0x19 - CSIDL_COMMON_DESKTOPDIRECTORY */
723 MAKEINTRESOURCEW(IDS_DESKTOP
)
725 { /* 0x1a - CSIDL_APPDATA */
728 MAKEINTRESOURCEW(IDS_APPDATA
)
730 { /* 0x1b - CSIDL_PRINTHOOD */
733 MAKEINTRESOURCEW(IDS_PRINTHOOD
)
735 { /* 0x1c - CSIDL_LOCAL_APPDATA */
738 MAKEINTRESOURCEW(IDS_LOCAL_APPDATA
)
740 { /* 0x1d - CSIDL_ALTSTARTUP */
741 CSIDL_Type_NonExistent
,
745 { /* 0x1e - CSIDL_COMMON_ALTSTARTUP */
746 CSIDL_Type_NonExistent
,
750 { /* 0x1f - CSIDL_COMMON_FAVORITES */
753 MAKEINTRESOURCEW(IDS_FAVORITES
)
755 { /* 0x20 - CSIDL_INTERNET_CACHE */
758 MAKEINTRESOURCEW(IDS_INTERNET_CACHE
)
760 { /* 0x21 - CSIDL_COOKIES */
763 MAKEINTRESOURCEW(IDS_COOKIES
)
765 { /* 0x22 - CSIDL_HISTORY */
768 MAKEINTRESOURCEW(IDS_HISTORY
)
770 { /* 0x23 - CSIDL_COMMON_APPDATA */
773 MAKEINTRESOURCEW(IDS_APPDATA
)
775 { /* 0x24 - CSIDL_WINDOWS */
776 CSIDL_Type_WindowsPath
,
780 { /* 0x25 - CSIDL_SYSTEM */
781 CSIDL_Type_SystemPath
,
785 { /* 0x26 - CSIDL_PROGRAM_FILES */
788 MAKEINTRESOURCEW(IDS_PROGRAM_FILES
)
790 { /* 0x27 - CSIDL_MYPICTURES */
793 MAKEINTRESOURCEW(IDS_MYPICTURES
)
795 { /* 0x28 - CSIDL_PROFILE */
800 { /* 0x29 - CSIDL_SYSTEMX86 */
801 CSIDL_Type_NonExistent
,
805 { /* 0x2a - CSIDL_PROGRAM_FILESX86 */
806 CSIDL_Type_NonExistent
,
810 { /* 0x2b - CSIDL_PROGRAM_FILES_COMMON */
813 MAKEINTRESOURCEW(IDS_PROGRAM_FILES_COMMON
)
815 { /* 0x2c - CSIDL_PROGRAM_FILES_COMMONX86 */
816 CSIDL_Type_NonExistent
,
820 { /* 0x2d - CSIDL_COMMON_TEMPLATES */
823 MAKEINTRESOURCEW(IDS_TEMPLATES
)
825 { /* 0x2e - CSIDL_COMMON_DOCUMENTS */
828 MAKEINTRESOURCEW(IDS_COMMON_DOCUMENTS
)
830 { /* 0x2f - CSIDL_COMMON_ADMINTOOLS */
832 Common_Administrative_ToolsW
,
833 MAKEINTRESOURCEW(IDS_ADMINTOOLS
)
835 { /* 0x30 - CSIDL_ADMINTOOLS */
837 Administrative_ToolsW
,
838 MAKEINTRESOURCEW(IDS_ADMINTOOLS
)
840 { /* 0x31 - CSIDL_CONNECTIONS */
841 CSIDL_Type_Disallowed
,
845 { /* 0x32 - unassigned */
846 CSIDL_Type_Disallowed
,
850 { /* 0x33 - unassigned */
851 CSIDL_Type_Disallowed
,
855 { /* 0x34 - unassigned */
856 CSIDL_Type_Disallowed
,
860 { /* 0x35 - CSIDL_COMMON_MUSIC */
863 MAKEINTRESOURCEW(IDS_COMMON_MUSIC
)
865 { /* 0x36 - CSIDL_COMMON_PICTURES */
868 MAKEINTRESOURCEW(IDS_COMMON_PICTURES
)
870 { /* 0x37 - CSIDL_COMMON_VIDEO */
873 MAKEINTRESOURCEW(IDS_COMMON_VIDEO
)
875 { /* 0x38 - CSIDL_RESOURCES */
876 CSIDL_Type_WindowsPath
,
880 { /* 0x39 - CSIDL_RESOURCES_LOCALIZED */
881 CSIDL_Type_NonExistent
,
885 { /* 0x3a - CSIDL_COMMON_OEM_LINKS */
886 CSIDL_Type_NonExistent
,
890 { /* 0x3b - CSIDL_CDBURN_AREA */
893 MAKEINTRESOURCEW(IDS_CDBURN_AREA
)
895 { /* 0x3c unassigned */
896 CSIDL_Type_Disallowed
,
900 { /* 0x3d - CSIDL_COMPUTERSNEARME */
901 CSIDL_Type_Disallowed
, /* FIXME */
905 { /* 0x3e - CSIDL_PROFILES */
906 CSIDL_Type_Disallowed
, /* oddly, this matches WinXP */
912 /* Gets the value named value from the registry key
913 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
914 * (or from rootKey\userPrefix\... if userPrefix is not NULL) into path, which
915 * is assumed to be MAX_PATH WCHARs in length.
916 * If it exists, expands the value and writes the expanded value to
917 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
918 * Returns successful error code if the value was retrieved from the registry,
919 * and a failure otherwise.
921 static HRESULT
_SHGetUserShellFolderPath(HKEY rootKey
, LPCWSTR userPrefix
,
922 LPCWSTR value
, LPWSTR path
)
925 WCHAR shellFolderPath
[MAX_PATH
], userShellFolderPath
[MAX_PATH
];
926 LPCWSTR pShellFolderPath
, pUserShellFolderPath
;
927 DWORD dwDisp
, dwType
, dwPathLen
;
928 HKEY userShellFolderKey
, shellFolderKey
;
930 TRACE("%p,%s,%s,%p\n",rootKey
, debugstr_w(userPrefix
), debugstr_w(value
),
935 wcscpy(shellFolderPath
, userPrefix
);
936 PathAddBackslashW(shellFolderPath
);
937 wcscat(shellFolderPath
, szSHFolders
);
938 pShellFolderPath
= shellFolderPath
;
939 wcscpy(userShellFolderPath
, userPrefix
);
940 PathAddBackslashW(userShellFolderPath
);
941 wcscat(userShellFolderPath
, szSHUserFolders
);
942 pUserShellFolderPath
= userShellFolderPath
;
946 pUserShellFolderPath
= szSHUserFolders
;
947 pShellFolderPath
= szSHFolders
;
950 if (RegCreateKeyExW(rootKey
, pShellFolderPath
, 0, NULL
, 0, KEY_SET_VALUE
,
951 NULL
, &shellFolderKey
, &dwDisp
))
953 TRACE("Failed to create %s\n", debugstr_w(pShellFolderPath
));
956 if (RegCreateKeyExW(rootKey
, pUserShellFolderPath
, 0, NULL
, 0,
957 KEY_QUERY_VALUE
, NULL
, &userShellFolderKey
, &dwDisp
))
959 TRACE("Failed to create %s\n",
960 debugstr_w(pUserShellFolderPath
));
961 RegCloseKey(shellFolderKey
);
965 dwPathLen
= MAX_PATH
* sizeof(WCHAR
);
967 if (!RegQueryValueExW(userShellFolderKey
, value
, NULL
, &dwType
,
968 (LPBYTE
)path
, &dwPathLen
) && (dwType
== REG_EXPAND_SZ
|| dwType
== REG_SZ
))
972 dwPathLen
/= sizeof(WCHAR
);
974 path
[dwPathLen
] = '\0';
975 if (dwType
== REG_EXPAND_SZ
&& path
[0] == '%')
977 WCHAR szTemp
[MAX_PATH
];
979 dwPathLen
= ExpandEnvironmentStringsW(path
, szTemp
, MAX_PATH
);
980 lstrcpynW(path
, szTemp
, dwPathLen
);
983 ret
= RegSetValueExW(shellFolderKey
, value
, 0, REG_SZ
, (LPBYTE
)path
, dwPathLen
* sizeof(WCHAR
));
984 if (ret
!= ERROR_SUCCESS
)
985 hr
= HRESULT_FROM_WIN32(ret
);
992 RegCloseKey(shellFolderKey
);
993 RegCloseKey(userShellFolderKey
);
994 TRACE("returning 0x%08x\n", hr
);
998 /* Gets a 'semi-expanded' default value of the CSIDL with index folder into
999 * pszPath, based on the entries in CSIDL_Data. By semi-expanded, I mean:
1000 * - The entry's szDefaultPath may be either a string value or an integer
1001 * resource identifier. In the latter case, the string value of the resource
1003 * - Depending on the entry's type, the path may begin with an (unexpanded)
1004 * environment variable name. The caller is responsible for expanding
1005 * environment strings if so desired.
1006 * The types that are prepended with environment variables are:
1007 * CSIDL_Type_User: %USERPROFILE%
1008 * CSIDL_Type_AllUsers: %ALLUSERSPROFILE%
1009 * CSIDL_Type_CurrVer: %SystemDrive%
1010 * (Others might make sense too, but as yet are unneeded.)
1012 static HRESULT
_SHGetDefaultValue(BYTE folder
, LPWSTR pszPath
)
1017 WCHAR resourcePath
[MAX_PATH
];
1018 LPCWSTR pDefaultPath
= NULL
;
1020 TRACE("0x%02x,%p\n", folder
, pszPath
);
1022 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1023 return E_INVALIDARG
;
1025 return E_INVALIDARG
;
1027 if (RegOpenKeyExW(HKEY_CURRENT_USER
, L
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
)
1029 /* FIXME assume MAX_PATH size */
1030 dwSize
= MAX_PATH
* sizeof(WCHAR
);
1031 if (RegQueryValueExW(hKey
, CSIDL_Data
[folder
].szValueName
, NULL
, NULL
, (LPBYTE
)pszPath
, &dwSize
) == ERROR_SUCCESS
)
1039 if (CSIDL_Data
[folder
].szDefaultPath
&&
1040 IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
))
1042 if (LoadStringW(shell32_hInstance
,
1043 LOWORD(CSIDL_Data
[folder
].szDefaultPath
), resourcePath
, MAX_PATH
))
1046 pDefaultPath
= resourcePath
;
1050 FIXME("(%d,%s), LoadString failed, missing translation?\n", folder
,
1051 debugstr_w(pszPath
));
1058 pDefaultPath
= CSIDL_Data
[folder
].szDefaultPath
;
1062 switch (CSIDL_Data
[folder
].type
)
1064 case CSIDL_Type_User
:
1065 wcscpy(pszPath
, UserProfileW
);
1067 case CSIDL_Type_AllUsers
:
1068 wcscpy(pszPath
, AllUsersProfileW
);
1070 case CSIDL_Type_CurrVer
:
1071 wcscpy(pszPath
, SystemDriveW
);
1074 ; /* no corresponding env. var, do nothing */
1078 PathAddBackslashW(pszPath
);
1079 wcscat(pszPath
, pDefaultPath
);
1082 TRACE("returning 0x%08x\n", hr
);
1086 /* Gets the (unexpanded) value of the folder with index folder into pszPath.
1087 * The folder's type is assumed to be CSIDL_Type_CurrVer. Its default value
1088 * can be overridden in the HKLM\\szCurrentVersion key.
1089 * If dwFlags has SHGFP_TYPE_DEFAULT set or if the value isn't overridden in
1090 * the registry, uses _SHGetDefaultValue to get the value.
1092 static HRESULT
_SHGetCurrentVersionPath(DWORD dwFlags
, BYTE folder
,
1097 TRACE("0x%08x,0x%02x,%p\n", dwFlags
, folder
, pszPath
);
1099 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1100 return E_INVALIDARG
;
1101 if (CSIDL_Data
[folder
].type
!= CSIDL_Type_CurrVer
)
1102 return E_INVALIDARG
;
1104 return E_INVALIDARG
;
1106 if (dwFlags
& SHGFP_TYPE_DEFAULT
)
1107 hr
= _SHGetDefaultValue(folder
, pszPath
);
1113 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE
, szCurrentVersion
, 0,
1114 NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hKey
, &dwDisp
))
1118 DWORD dwType
, dwPathLen
= MAX_PATH
* sizeof(WCHAR
);
1120 if (RegQueryValueExW(hKey
, CSIDL_Data
[folder
].szValueName
, NULL
,
1121 &dwType
, (LPBYTE
)pszPath
, &dwPathLen
) ||
1122 (dwType
!= REG_SZ
&& dwType
!= REG_EXPAND_SZ
))
1124 hr
= _SHGetDefaultValue(folder
, pszPath
);
1125 dwType
= REG_EXPAND_SZ
;
1126 RegSetValueExW(hKey
, CSIDL_Data
[folder
].szValueName
, 0, dwType
,
1127 (LPBYTE
)pszPath
, (wcslen(pszPath
)+1)*sizeof(WCHAR
));
1131 pszPath
[dwPathLen
/ sizeof(WCHAR
)] = '\0';
1137 TRACE("returning 0x%08x (output path is %s)\n", hr
, debugstr_w(pszPath
));
1141 /* Gets the user's path (unexpanded) for the CSIDL with index folder:
1142 * If SHGFP_TYPE_DEFAULT is set, calls _SHGetDefaultValue for it. Otherwise
1143 * calls _SHGetUserShellFolderPath for it. Where it looks depends on hToken:
1144 * - if hToken is -1, looks in HKEY_USERS\.Default
1145 * - otherwise looks first in HKEY_CURRENT_USER, followed by HKEY_LOCAL_MACHINE
1146 * if HKEY_CURRENT_USER doesn't contain any entries. If both fail, finally
1147 * calls _SHGetDefaultValue for it.
1149 static HRESULT
_SHGetUserProfilePath(HANDLE hToken
, DWORD dwFlags
, BYTE folder
,
1154 TRACE("%p,0x%08x,0x%02x,%p\n", hToken
, dwFlags
, folder
, pszPath
);
1156 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1157 return E_INVALIDARG
;
1159 if (CSIDL_Data
[folder
].type
!= CSIDL_Type_User
)
1160 return E_INVALIDARG
;
1163 return E_INVALIDARG
;
1165 if (dwFlags
& SHGFP_TYPE_DEFAULT
)
1167 hr
= _SHGetDefaultValue(folder
, pszPath
);
1174 if (hToken
== (HANDLE
)-1)
1176 /* Get the folder of the default user */
1177 hRootKey
= HKEY_USERS
;
1178 userPrefix
= (LPWSTR
)DefaultW
;
1182 /* Get the folder of the current user */
1183 hRootKey
= HKEY_CURRENT_USER
;
1188 /* Get the folder of the specified user */
1190 PTOKEN_USER UserInfo
;
1192 hRootKey
= HKEY_USERS
;
1194 GetTokenInformation(hToken
, TokenUser
, NULL
, 0, &InfoLength
);
1195 UserInfo
= (PTOKEN_USER
)HeapAlloc(GetProcessHeap(), 0, InfoLength
);
1197 if(!GetTokenInformation(hToken
, TokenUser
, UserInfo
, InfoLength
, &InfoLength
))
1199 WARN("GetTokenInformation failed for %x!\n", hToken
);
1200 HeapFree(GetProcessHeap(), 0, UserInfo
);
1204 if(!ConvertSidToStringSidW(UserInfo
->User
.Sid
, &userPrefix
))
1206 WARN("ConvertSidToStringSidW failed for %x!\n", hToken
);
1207 HeapFree(GetProcessHeap(), 0, UserInfo
);
1211 HeapFree(GetProcessHeap(), 0, UserInfo
);
1214 hr
= _SHGetUserShellFolderPath(hRootKey
, userPrefix
, CSIDL_Data
[folder
].szValueName
, pszPath
);
1216 /* Free the memory allocated by ConvertSidToStringSidW */
1217 if(hToken
&& hToken
!= (HANDLE
)-1)
1218 LocalFree(userPrefix
);
1220 if (FAILED(hr
) && hRootKey
!= HKEY_LOCAL_MACHINE
)
1221 hr
= _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE
, NULL
, CSIDL_Data
[folder
].szValueName
, pszPath
);
1224 hr
= _SHGetDefaultValue(folder
, pszPath
);
1227 TRACE("returning 0x%08x (output path is %s)\n", hr
, debugstr_w(pszPath
));
1231 /* Gets the (unexpanded) path for the CSIDL with index folder. If dwFlags has
1232 * SHGFP_TYPE_DEFAULT set, calls _SHGetDefaultValue. Otherwise calls
1233 * _SHGetUserShellFolderPath for it, looking only in HKEY_LOCAL_MACHINE.
1234 * If this fails, falls back to _SHGetDefaultValue.
1236 static HRESULT
_SHGetAllUsersProfilePath(DWORD dwFlags
, BYTE folder
,
1241 TRACE("0x%08x,0x%02x,%p\n", dwFlags
, folder
, pszPath
);
1243 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1244 return E_INVALIDARG
;
1245 if (CSIDL_Data
[folder
].type
!= CSIDL_Type_AllUsers
)
1246 return E_INVALIDARG
;
1248 return E_INVALIDARG
;
1250 if (dwFlags
& SHGFP_TYPE_DEFAULT
)
1251 hr
= _SHGetDefaultValue(folder
, pszPath
);
1254 hr
= _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE
, NULL
,
1255 CSIDL_Data
[folder
].szValueName
, pszPath
);
1257 hr
= _SHGetDefaultValue(folder
, pszPath
);
1259 TRACE("returning 0x%08x (output path is %s)\n", hr
, debugstr_w(pszPath
));
1263 /*************************************************************************
1264 * SHGetFolderPathW [SHELL32.@]
1266 * Convert nFolder to path.
1270 * Failure: standard HRESULT error codes.
1273 * Most values can be overridden in either
1274 * HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
1275 * or in the same location in HKLM.
1276 * The "Shell Folders" registry key was used in NT4 and earlier systems.
1277 * Beginning with Windows 2000, the "User Shell Folders" key is used, so
1278 * changes made to it are made to the former key too. This synchronization is
1279 * done on-demand: not until someone requests the value of one of these paths
1280 * (by calling one of the SHGet functions) is the value synchronized.
1281 * Furthermore, the HKCU paths take precedence over the HKLM paths.
1283 HRESULT WINAPI
SHGetFolderPathW(
1284 HWND hwndOwner
, /* [I] owner window */
1285 int nFolder
, /* [I] CSIDL identifying the folder */
1286 HANDLE hToken
, /* [I] access token */
1287 DWORD dwFlags
, /* [I] which path to return */
1288 LPWSTR pszPath
) /* [O] converted path */
1290 HRESULT hr
= SHGetFolderPathAndSubDirW(hwndOwner
, nFolder
, hToken
, dwFlags
, NULL
, pszPath
);
1291 if(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
) == hr
)
1292 hr
= HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
1296 HRESULT WINAPI
SHGetFolderPathAndSubDirA(
1297 HWND hwndOwner
, /* [I] owner window */
1298 int nFolder
, /* [I] CSIDL identifying the folder */
1299 HANDLE hToken
, /* [I] access token */
1300 DWORD dwFlags
, /* [I] which path to return */
1301 LPCSTR pszSubPath
, /* [I] sub directory of the specified folder */
1302 LPSTR pszPath
) /* [O] converted path */
1306 LPWSTR pszSubPathW
= NULL
;
1307 LPWSTR pszPathW
= NULL
;
1308 TRACE("%08x,%08x,%s\n",nFolder
, dwFlags
, debugstr_w(pszSubPathW
));
1311 pszPathW
= HeapAlloc(GetProcessHeap(), 0, MAX_PATH
* sizeof(WCHAR
));
1313 hr
= HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY
);
1317 TRACE("%08x,%08x,%s\n",nFolder
, dwFlags
, debugstr_w(pszSubPathW
));
1319 /* SHGetFolderPathAndSubDirW does not distinguish if pszSubPath isn't
1320 * set (null), or an empty string.therefore call it without the parameter set
1321 * if pszSubPath is an empty string
1323 if (pszSubPath
&& pszSubPath
[0]) {
1324 length
= MultiByteToWideChar(CP_ACP
, 0, pszSubPath
, -1, NULL
, 0);
1325 pszSubPathW
= HeapAlloc(GetProcessHeap(), 0, length
* sizeof(WCHAR
));
1327 hr
= HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY
);
1330 MultiByteToWideChar(CP_ACP
, 0, pszSubPath
, -1, pszSubPathW
, length
);
1333 hr
= SHGetFolderPathAndSubDirW(hwndOwner
, nFolder
, hToken
, dwFlags
, pszSubPathW
, pszPathW
);
1335 if (SUCCEEDED(hr
) && pszPath
)
1336 WideCharToMultiByte(CP_ACP
, 0, pszPathW
, -1, pszPath
, MAX_PATH
, NULL
, NULL
);
1339 HeapFree(GetProcessHeap(), 0, pszPathW
);
1340 HeapFree(GetProcessHeap(), 0, pszSubPathW
);
1344 HRESULT WINAPI
SHGetFolderPathAndSubDirW(
1345 HWND hwndOwner
, /* [I] owner window */
1346 int nFolder
, /* [I] CSIDL identifying the folder */
1347 HANDLE hToken
, /* [I] access token */
1348 DWORD dwFlags
, /* [I] which path to return */
1349 LPCWSTR pszSubPath
,/* [I] sub directory of the specified folder */
1350 LPWSTR pszPath
) /* [O] converted path */
1353 WCHAR szBuildPath
[MAX_PATH
], szTemp
[MAX_PATH
];
1354 DWORD folder
= nFolder
& CSIDL_FOLDER_MASK
; //FIXME
1358 TRACE("%p,%p,nFolder=0x%04x,%s\n", hwndOwner
,pszPath
,nFolder
,debugstr_w(pszSubPath
));
1360 /* Windows always NULL-terminates the resulting path regardless of success
1361 * or failure, so do so first
1366 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1367 return E_INVALIDARG
;
1368 if ((SHGFP_TYPE_CURRENT
!= dwFlags
) && (SHGFP_TYPE_DEFAULT
!= dwFlags
))
1369 return E_INVALIDARG
;
1371 type
= CSIDL_Data
[folder
].type
;
1374 case CSIDL_Type_Disallowed
:
1377 case CSIDL_Type_NonExistent
:
1380 case CSIDL_Type_WindowsPath
:
1381 GetWindowsDirectoryW(szTemp
, MAX_PATH
);
1382 if (CSIDL_Data
[folder
].szDefaultPath
&&
1383 !IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
) &&
1384 *CSIDL_Data
[folder
].szDefaultPath
)
1386 PathAddBackslashW(szTemp
);
1387 wcscat(szTemp
, CSIDL_Data
[folder
].szDefaultPath
);
1391 case CSIDL_Type_SystemPath
:
1392 GetSystemDirectoryW(szTemp
, MAX_PATH
);
1393 if (CSIDL_Data
[folder
].szDefaultPath
&&
1394 !IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
) &&
1395 *CSIDL_Data
[folder
].szDefaultPath
)
1397 PathAddBackslashW(szTemp
);
1398 wcscat(szTemp
, CSIDL_Data
[folder
].szDefaultPath
);
1402 case CSIDL_Type_CurrVer
:
1403 hr
= _SHGetCurrentVersionPath(dwFlags
, folder
, szTemp
);
1405 case CSIDL_Type_User
:
1406 hr
= _SHGetUserProfilePath(hToken
, dwFlags
, folder
, szTemp
);
1408 case CSIDL_Type_AllUsers
:
1409 hr
= _SHGetAllUsersProfilePath(dwFlags
, folder
, szTemp
);
1412 FIXME("bogus type %d, please fix\n", type
);
1417 /* Expand environment strings if necessary */
1420 DWORD ExpandRet
= ExpandEnvironmentStringsW(szTemp
, szBuildPath
, MAX_PATH
);
1422 if (ExpandRet
> MAX_PATH
)
1423 hr
= HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
1424 else if (ExpandRet
== 0)
1425 hr
= HRESULT_FROM_WIN32(GetLastError());
1431 wcscpy(szBuildPath
, szTemp
);
1434 if (FAILED(hr
)) goto end
;
1437 /* make sure the new path does not exceed th bufferlength
1438 * rememebr to backslash and the termination */
1439 if(MAX_PATH
< (wcslen(szBuildPath
) + wcslen(pszSubPath
) + 2)) {
1440 hr
= HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE
);
1443 PathAppendW(szBuildPath
, pszSubPath
);
1444 PathRemoveBackslashW(szBuildPath
);
1446 /* Copy the path if it's available before we might return */
1447 if (SUCCEEDED(hr
) && pszPath
)
1448 wcscpy(pszPath
, szBuildPath
);
1450 /* if we don't care about existing directories we are ready */
1451 if(nFolder
& CSIDL_FLAG_DONT_VERIFY
) goto end
;
1453 if (PathFileExistsW(szBuildPath
)) goto end
;
1455 /* not existing but we are not allowed to create it. The return value
1456 * is verified against shell32 version 6.0.
1458 if (!(nFolder
& CSIDL_FLAG_CREATE
))
1460 hr
= HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
);
1464 /* create directory/directories */
1465 ret
= SHCreateDirectoryExW(hwndOwner
, szBuildPath
, NULL
);
1466 if (ret
&& ret
!= ERROR_ALREADY_EXISTS
)
1468 ERR("Failed to create directory %s.\n", debugstr_w(szBuildPath
));
1473 TRACE("Created missing system directory %s\n", debugstr_w(szBuildPath
));
1475 TRACE("returning 0x%08x (final path is %s)\n", hr
, debugstr_w(szBuildPath
));
1479 /*************************************************************************
1480 * SHGetFolderPathA [SHELL32.@]
1482 * See SHGetFolderPathW.
1484 HRESULT WINAPI
SHGetFolderPathA(
1491 WCHAR szTemp
[MAX_PATH
];
1494 TRACE("%p,%p,nFolder=0x%04x\n",hwndOwner
,pszPath
,nFolder
);
1498 hr
= SHGetFolderPathW(hwndOwner
, nFolder
, hToken
, dwFlags
, szTemp
);
1499 if (SUCCEEDED(hr
) && pszPath
)
1500 WideCharToMultiByte(CP_ACP
, 0, szTemp
, -1, pszPath
, MAX_PATH
, NULL
,
1506 /* For each folder in folders, if its value has not been set in the registry,
1507 * calls _SHGetUserProfilePath or _SHGetAllUsersProfilePath (depending on the
1508 * folder's type) to get the unexpanded value first.
1509 * Writes the unexpanded value to User Shell Folders, and queries it with
1510 * SHGetFolderPathW to force the creation of the directory if it doesn't
1511 * already exist. SHGetFolderPathW also returns the expanded value, which
1512 * this then writes to Shell Folders.
1514 static HRESULT
_SHRegisterFolders(HKEY hRootKey
, HANDLE hToken
,
1515 LPCWSTR szUserShellFolderPath
, LPCWSTR szShellFolderPath
, const UINT folders
[],
1519 WCHAR path
[MAX_PATH
];
1521 HKEY hUserKey
= NULL
, hKey
= NULL
;
1522 DWORD dwDisp
, dwType
, dwPathLen
;
1525 TRACE("%p,%p,%s,%p,%u\n", hRootKey
, hToken
,
1526 debugstr_w(szUserShellFolderPath
), folders
, foldersLen
);
1528 ret
= RegCreateKeyExW(hRootKey
, szUserShellFolderPath
, 0, NULL
, 0,
1529 KEY_ALL_ACCESS
, NULL
, &hUserKey
, &dwDisp
);
1531 hr
= HRESULT_FROM_WIN32(ret
);
1534 ret
= RegCreateKeyExW(hRootKey
, szShellFolderPath
, 0, NULL
, 0,
1535 KEY_ALL_ACCESS
, NULL
, &hKey
, &dwDisp
);
1537 hr
= HRESULT_FROM_WIN32(ret
);
1539 for (i
= 0; SUCCEEDED(hr
) && i
< foldersLen
; i
++)
1541 dwPathLen
= MAX_PATH
* sizeof(WCHAR
);
1542 if (RegQueryValueExW(hUserKey
, CSIDL_Data
[folders
[i
]].szValueName
, NULL
,
1543 &dwType
, (LPBYTE
)path
, &dwPathLen
) || (dwType
!= REG_SZ
&&
1544 dwType
!= REG_EXPAND_SZ
))
1547 if (CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_User
)
1548 _SHGetUserProfilePath(hToken
, SHGFP_TYPE_DEFAULT
, folders
[i
],
1550 else if (CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_AllUsers
)
1551 _SHGetAllUsersProfilePath(SHGFP_TYPE_DEFAULT
, folders
[i
], path
);
1552 else if (CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_WindowsPath
)
1553 GetWindowsDirectoryW(path
, MAX_PATH
);
1558 ret
= RegSetValueExW(hUserKey
,
1559 CSIDL_Data
[folders
[i
]].szValueName
, 0, REG_EXPAND_SZ
,
1560 (LPBYTE
)path
, (wcslen(path
) + 1) * sizeof(WCHAR
));
1562 hr
= HRESULT_FROM_WIN32(ret
);
1565 hr
= SHGetFolderPathW(NULL
, folders
[i
] | CSIDL_FLAG_CREATE
,
1566 hToken
, SHGFP_TYPE_DEFAULT
, path
);
1567 ret
= RegSetValueExW(hKey
,
1568 CSIDL_Data
[folders
[i
]].szValueName
, 0, REG_SZ
,
1569 (LPBYTE
)path
, (wcslen(path
) + 1) * sizeof(WCHAR
));
1571 hr
= HRESULT_FROM_WIN32(ret
);
1577 RegCloseKey(hUserKey
);
1581 TRACE("returning 0x%08x\n", hr
);
1585 static HRESULT
_SHRegisterUserShellFolders(BOOL bDefault
)
1587 static const UINT folders
[] = {
1598 CSIDL_DESKTOPDIRECTORY
,
1602 CSIDL_LOCAL_APPDATA
,
1603 CSIDL_INTERNET_CACHE
,
1609 WCHAR userShellFolderPath
[MAX_PATH
], shellFolderPath
[MAX_PATH
];
1610 LPCWSTR pUserShellFolderPath
, pShellFolderPath
;
1615 TRACE("%s\n", bDefault
? "TRUE" : "FALSE");
1618 hToken
= (HANDLE
)-1;
1619 hRootKey
= HKEY_USERS
;
1620 wcscpy(userShellFolderPath
, DefaultW
);
1621 PathAddBackslashW(userShellFolderPath
);
1622 wcscat(userShellFolderPath
, szSHUserFolders
);
1623 pUserShellFolderPath
= userShellFolderPath
;
1624 wcscpy(shellFolderPath
, DefaultW
);
1625 PathAddBackslashW(shellFolderPath
);
1626 wcscat(shellFolderPath
, szSHFolders
);
1627 pShellFolderPath
= shellFolderPath
;
1632 hRootKey
= HKEY_CURRENT_USER
;
1633 pUserShellFolderPath
= szSHUserFolders
;
1634 pShellFolderPath
= szSHFolders
;
1637 hr
= _SHRegisterFolders(hRootKey
, hToken
, pUserShellFolderPath
,
1638 pShellFolderPath
, folders
, sizeof(folders
) / sizeof(folders
[0]));
1639 TRACE("returning 0x%08x\n", hr
);
1643 static HRESULT
_SHRegisterCommonShellFolders(void)
1645 static const UINT folders
[] = {
1646 CSIDL_COMMON_STARTMENU
,
1647 CSIDL_COMMON_PROGRAMS
,
1648 CSIDL_COMMON_STARTUP
,
1649 CSIDL_COMMON_DESKTOPDIRECTORY
,
1650 CSIDL_COMMON_FAVORITES
,
1651 CSIDL_COMMON_APPDATA
,
1652 CSIDL_COMMON_TEMPLATES
,
1653 CSIDL_COMMON_DOCUMENTS
,
1658 hr
= _SHRegisterFolders(HKEY_LOCAL_MACHINE
, NULL
, szSHUserFolders
,
1659 szSHFolders
, folders
, sizeof(folders
) / sizeof(folders
[0]));
1660 TRACE("returning 0x%08x\n", hr
);
1664 /******************************************************************************
1665 * _SHAppendToUnixPath [Internal]
1667 * Helper function for _SHCreateSymbolicLinks. Appends pwszSubPath (or the
1668 * corresponding resource, if IS_INTRESOURCE) to the unix base path 'szBasePath'
1669 * and replaces backslashes with slashes.
1672 * szBasePath [IO] The unix base path, which will be appended to (CP_UNXICP).
1673 * pwszSubPath [I] Sub-path or resource id (use MAKEINTRESOURCEW).
1679 static BOOL __inline
_SHAppendToUnixPath(char *szBasePath
, LPCWSTR pwszSubPath
) {
1680 WCHAR wszSubPath
[MAX_PATH
];
1681 int cLen
= strlen(szBasePath
);
1684 if (IS_INTRESOURCE(pwszSubPath
)) {
1685 if (!LoadStringW(shell32_hInstance
, LOWORD(pwszSubPath
), wszSubPath
, MAX_PATH
)) {
1686 /* Fall back to hard coded defaults. */
1687 switch (LOWORD(pwszSubPath
)) {
1689 wcscpy(wszSubPath
, PersonalW
);
1692 wcscpy(wszSubPath
, My_MusicW
);
1694 case IDS_MYPICTURES
:
1695 wcscpy(wszSubPath
, My_PicturesW
);
1698 wcscpy(wszSubPath
, My_VideoW
);
1701 ERR("LoadString(%d) failed!\n", LOWORD(pwszSubPath
));
1706 wcscpy(wszSubPath
, pwszSubPath
);
1709 if (szBasePath
[cLen
-1] != '/') szBasePath
[cLen
++] = '/';
1711 if (!WideCharToMultiByte(CP_ACP
, 0, wszSubPath
, -1, szBasePath
+ cLen
,
1712 FILENAME_MAX
- cLen
, NULL
, NULL
))
1717 pBackslash
= szBasePath
+ cLen
;
1718 while ((pBackslash
= strchr(pBackslash
, '\\'))) *pBackslash
= '/';
1723 /******************************************************************************
1724 * _SHCreateSymbolicLinks [Internal]
1726 * Sets up symbol links for various shell folders to point into the users home
1727 * directory. We do an educated guess about what the user would probably want:
1728 * - If there is a 'My Documents' directory in $HOME, the user probably wants
1729 * wine's 'My Documents' to point there. Furthermore, we imply that the user
1730 * is a Windows lover and has no problem with wine creating 'My Pictures',
1731 * 'My Music' and 'My Video' subfolders under '$HOME/My Documents', if those
1732 * do not already exits. We put appropriate symbolic links in place for those,
1734 * - If there is no 'My Documents' directory in $HOME, we let 'My Documents'
1735 * point directly to $HOME. We assume the user to be a unix hacker who does not
1736 * want wine to create anything anywhere besides the .wine directory. So, if
1737 * there already is a 'My Music' directory in $HOME, we symlink the 'My Music'
1738 * shell folder to it. But if not, we symlink it to $HOME directly. The same
1739 * holds fo 'My Pictures' and 'My Video'.
1740 * - The Desktop shell folder is symlinked to '$HOME/Desktop', if that does
1741 * exists and left alone if not.
1742 * ('My Music',... above in fact means LoadString(IDS_MYMUSIC))
1744 static void _SHCreateSymbolicLinks(void)
1746 UINT aidsMyStuff
[] = { IDS_MYPICTURES
, IDS_MYVIDEO
, IDS_MYMUSIC
}, i
;
1747 int acsidlMyStuff
[] = { CSIDL_MYPICTURES
, CSIDL_MYVIDEO
, CSIDL_MYMUSIC
};
1748 WCHAR wszTempPath
[MAX_PATH
];
1749 char szPersonalTarget
[FILENAME_MAX
], *pszPersonal
;
1750 char szMyStuffTarget
[FILENAME_MAX
], *pszMyStuff
;
1751 char szDesktopTarget
[FILENAME_MAX
], *pszDesktop
;
1752 struct stat statFolder
;
1753 const char *pszHome
;
1756 /* Create all necessary profile sub-dirs up to 'My Documents' and get the unix path. */
1757 hr
= SHGetFolderPathW(NULL
, CSIDL_PERSONAL
|CSIDL_FLAG_CREATE
, NULL
,
1758 SHGFP_TYPE_DEFAULT
, wszTempPath
);
1759 if (FAILED(hr
)) return;
1760 pszPersonal
= wine_get_unix_file_name(wszTempPath
);
1761 if (!pszPersonal
) return;
1763 pszHome
= getenv("HOME");
1764 if (pszHome
&& !stat(pszHome
, &statFolder
) && S_ISDIR(statFolder
.st_mode
)) {
1765 strcpy(szPersonalTarget
, pszHome
);
1766 if (_SHAppendToUnixPath(szPersonalTarget
, MAKEINTRESOURCEW(IDS_PERSONAL
)) &&
1767 !stat(szPersonalTarget
, &statFolder
) && S_ISDIR(statFolder
.st_mode
))
1769 /* '$HOME/My Documents' exists. Create 'My Pictures', 'My Videos' and
1770 * 'My Music' subfolders or fail silently if they already exist. */
1771 for (i
= 0; i
< sizeof(aidsMyStuff
)/sizeof(aidsMyStuff
[0]); i
++) {
1772 strcpy(szMyStuffTarget
, szPersonalTarget
);
1773 if (_SHAppendToUnixPath(szMyStuffTarget
, MAKEINTRESOURCEW(aidsMyStuff
[i
])))
1774 mkdir(szMyStuffTarget
);
1779 /* '$HOME/My Documents' doesn't exists, but '$HOME' does. */
1780 strcpy(szPersonalTarget
, pszHome
);
1783 /* Replace 'My Documents' directory with a symlink of fail silently if not empty. */
1785 symlink(szPersonalTarget
, pszPersonal
);
1789 /* '$HOME' doesn't exist. Create 'My Pictures', 'My Videos' and 'My Music' subdirs
1790 * in '%USERPROFILE%\\My Documents' or fail silently if they already exist. */
1791 strcpy(szPersonalTarget
, pszPersonal
);
1792 for (i
= 0; i
< sizeof(aidsMyStuff
)/sizeof(aidsMyStuff
[0]); i
++) {
1793 strcpy(szMyStuffTarget
, szPersonalTarget
);
1794 if (_SHAppendToUnixPath(szMyStuffTarget
, MAKEINTRESOURCEW(aidsMyStuff
[i
])))
1795 mkdir(szMyStuffTarget
);
1799 /* Create symbolic links for 'My Pictures', 'My Video' and 'My Music'. */
1800 for (i
=0; i
< sizeof(aidsMyStuff
)/sizeof(aidsMyStuff
[0]); i
++) {
1801 /* Create the current 'My Whatever' folder and get it's unix path. */
1802 hr
= SHGetFolderPathW(NULL
, acsidlMyStuff
[i
]|CSIDL_FLAG_CREATE
, NULL
,
1803 SHGFP_TYPE_DEFAULT
, wszTempPath
);
1804 if (FAILED(hr
)) continue;
1805 pszMyStuff
= wine_get_unix_file_name(wszTempPath
);
1806 if (!pszMyStuff
) continue;
1808 strcpy(szMyStuffTarget
, szPersonalTarget
);
1809 if (_SHAppendToUnixPath(szMyStuffTarget
, MAKEINTRESOURCEW(aidsMyStuff
[i
])) &&
1810 !stat(szMyStuffTarget
, &statFolder
) && S_ISDIR(statFolder
.st_mode
))
1812 /* If there's a 'My Whatever' directory where 'My Documents' links to, link to it. */
1814 symlink(szMyStuffTarget
, pszMyStuff
);
1818 /* Else link to where 'My Documents' itself links to. */
1820 symlink(szPersonalTarget
, pszMyStuff
);
1822 HeapFree(GetProcessHeap(), 0, pszMyStuff
);
1825 /* Last but not least, the Desktop folder */
1827 strcpy(szDesktopTarget
, pszHome
);
1829 strcpy(szDesktopTarget
, pszPersonal
);
1830 HeapFree(GetProcessHeap(), 0, pszPersonal
);
1832 if (_SHAppendToUnixPath(szDesktopTarget
, DesktopW
) &&
1833 !stat(szDesktopTarget
, &statFolder
) && S_ISDIR(statFolder
.st_mode
))
1835 hr
= SHGetFolderPathW(NULL
, CSIDL_DESKTOPDIRECTORY
|CSIDL_FLAG_CREATE
, NULL
,
1836 SHGFP_TYPE_DEFAULT
, wszTempPath
);
1837 if (SUCCEEDED(hr
) && (pszDesktop
= wine_get_unix_file_name(wszTempPath
)))
1840 symlink(szDesktopTarget
, pszDesktop
);
1841 HeapFree(GetProcessHeap(), 0, pszDesktop
);
1847 /* Register the default values in the registry, as some apps seem to depend
1848 * on their presence. The set registered was taken from Windows XP.
1850 HRESULT
SHELL_RegisterShellFolders(void)
1854 /* Set up '$HOME' targeted symlinks for 'My Documents', 'My Pictures',
1855 * 'My Video', 'My Music' and 'Desktop' in advance, so that the
1856 * _SHRegister*ShellFolders() functions will find everything nice and clean
1857 * and thus will not attempt to create them in the profile directory. */
1859 _SHCreateSymbolicLinks();
1862 hr
= _SHRegisterUserShellFolders(TRUE
);
1864 hr
= _SHRegisterUserShellFolders(FALSE
);
1866 hr
= _SHRegisterCommonShellFolders();
1870 /*************************************************************************
1871 * SHGetSpecialFolderPathA [SHELL32.@]
1873 BOOL WINAPI
SHGetSpecialFolderPathA (
1879 return (SHGetFolderPathA(
1881 nFolder
+ (bCreate
? CSIDL_FLAG_CREATE
: 0),
1884 szPath
)) == S_OK
? TRUE
: FALSE
;
1887 /*************************************************************************
1888 * SHGetSpecialFolderPathW
1890 BOOL WINAPI
SHGetSpecialFolderPathW (
1896 return (SHGetFolderPathW(
1898 nFolder
+ (bCreate
? CSIDL_FLAG_CREATE
: 0),
1901 szPath
)) == S_OK
? TRUE
: FALSE
;
1904 /*************************************************************************
1905 * SHGetFolderLocation [SHELL32.@]
1907 * Gets the folder locations from the registry and creates a pidl.
1911 * nFolder [I] CSIDL_xxxxx
1912 * hToken [I] token representing user, or NULL for current user, or -1 for
1914 * dwReserved [I] must be zero
1915 * ppidl [O] PIDL of a special folder
1919 * Failure: Standard OLE-defined error result, S_FALSE or E_INVALIDARG
1922 * Creates missing reg keys and directories.
1923 * Mostly forwards to SHGetFolderPathW, but a few values of nFolder return
1924 * virtual folders that are handled here.
1926 HRESULT WINAPI
SHGetFolderLocation(
1931 LPITEMIDLIST
*ppidl
)
1933 HRESULT hr
= E_INVALIDARG
;
1935 TRACE("%p 0x%08x %p 0x%08x %p\n",
1936 hwndOwner
, nFolder
, hToken
, dwReserved
, ppidl
);
1939 return E_INVALIDARG
;
1941 return E_INVALIDARG
;
1943 /* The virtual folders' locations are not user-dependent */
1948 *ppidl
= _ILCreateDesktop();
1951 case CSIDL_PERSONAL
:
1952 *ppidl
= _ILCreateMyDocuments();
1955 case CSIDL_INTERNET
:
1956 *ppidl
= _ILCreateIExplore();
1959 case CSIDL_CONTROLS
:
1960 *ppidl
= _ILCreateControlPanel();
1963 case CSIDL_PRINTERS
:
1964 *ppidl
= _ILCreatePrinters();
1967 case CSIDL_BITBUCKET
:
1968 *ppidl
= _ILCreateBitBucket();
1972 *ppidl
= _ILCreateMyComputer();
1976 *ppidl
= _ILCreateNetwork();
1981 WCHAR szPath
[MAX_PATH
];
1983 hr
= SHGetFolderPathW(hwndOwner
, nFolder
, hToken
,
1984 SHGFP_TYPE_CURRENT
, szPath
);
1989 TRACE("Value=%s\n", debugstr_w(szPath
));
1990 hr
= SHILCreateFromPathW(szPath
, ppidl
, &attributes
);
1992 else if (hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
))
1994 /* unlike SHGetFolderPath, SHGetFolderLocation in shell32
1995 * version 6.0 returns E_FAIL for nonexistent paths
2004 TRACE("-- (new pidl %p)\n",*ppidl
);
2008 /*************************************************************************
2009 * SHGetSpecialFolderLocation [SHELL32.@]
2012 * In NT5, SHGetSpecialFolderLocation needs the <winntdir>/Recent
2015 HRESULT WINAPI
SHGetSpecialFolderLocation(
2018 LPITEMIDLIST
* ppidl
)
2020 HRESULT hr
= E_INVALIDARG
;
2022 TRACE("(%p,0x%x,%p)\n", hwndOwner
,nFolder
,ppidl
);
2025 return E_INVALIDARG
;
2027 hr
= SHGetFolderLocation(hwndOwner
, nFolder
, NULL
, 0, ppidl
);