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
27 #define WIN32_NO_STATUS
31 #include <wine/config.h>
36 #include <undocshell.h>
39 #include <wine/debug.h>
40 #include <wine/unicode.h>
45 #include "shell32_main.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
50 static const BOOL is_win64
= sizeof(void *) > sizeof(int);
52 typedef BOOL(WINAPI
*LPFN_ISWOW64PROCESS
) (HANDLE
, PBOOL
);
54 static LPFN_ISWOW64PROCESS fnIsWow64Process
= NULL
;
58 BOOL bIsWow64
= FALSE
;
60 if (!fnIsWow64Process
)
62 fnIsWow64Process
= (LPFN_ISWOW64PROCESS
) GetProcAddress(
63 GetModuleHandle(TEXT("kernel32")), "IsWow64Process");
66 if (!fnIsWow64Process
)
69 if (!fnIsWow64Process(GetCurrentProcess(), &bIsWow64
))
77 ########## Combining and Constructing paths ##########
80 /*************************************************************************
81 * PathAppend [SHELL32.36]
83 BOOL WINAPI
PathAppendAW(
87 if (SHELL_OsIsUnicode())
88 return PathAppendW(lpszPath1
, lpszPath2
);
89 return PathAppendA(lpszPath1
, lpszPath2
);
92 /*************************************************************************
93 * PathBuildRoot [SHELL32.30]
95 LPVOID WINAPI
PathBuildRootAW(LPVOID lpszPath
, int drive
)
97 if(SHELL_OsIsUnicode())
98 return PathBuildRootW(lpszPath
, drive
);
99 return PathBuildRootA(lpszPath
, drive
);
102 /*************************************************************************
103 * PathGetExtensionA [internal]
106 * exported by ordinal
107 * return value points to the first char after the dot
109 static LPSTR
PathGetExtensionA(LPCSTR lpszPath
)
111 TRACE("(%s)\n",lpszPath
);
113 lpszPath
= PathFindExtensionA(lpszPath
);
114 return (LPSTR
)(*lpszPath
?(lpszPath
+1):lpszPath
);
117 /*************************************************************************
118 * PathGetExtensionW [internal]
120 static LPWSTR
PathGetExtensionW(LPCWSTR lpszPath
)
122 TRACE("(%s)\n",debugstr_w(lpszPath
));
124 lpszPath
= PathFindExtensionW(lpszPath
);
125 return (LPWSTR
)(*lpszPath
?(lpszPath
+1):lpszPath
);
128 /*************************************************************************
129 * SHPathGetExtension [SHELL32.158]
131 EXTERN_C LPVOID WINAPI
SHPathGetExtensionW(LPCWSTR lpszPath
, DWORD void1
, DWORD void2
)
133 return PathGetExtensionW(lpszPath
);
136 /*************************************************************************
137 * PathRemoveFileSpec [SHELL32.35]
139 BOOL WINAPI
PathRemoveFileSpecAW(LPVOID lpszPath
)
141 if (SHELL_OsIsUnicode())
142 return PathRemoveFileSpecW(lpszPath
);
143 return PathRemoveFileSpecA(lpszPath
);
150 /*************************************************************************
151 * PathGetShortPathA [internal]
153 static void PathGetShortPathA(LPSTR pszPath
)
157 TRACE("%s\n", pszPath
);
159 if (GetShortPathNameA(pszPath
, path
, MAX_PATH
))
161 lstrcpyA(pszPath
, path
);
165 /*************************************************************************
166 * PathGetShortPathW [internal]
168 static void PathGetShortPathW(LPWSTR pszPath
)
170 WCHAR path
[MAX_PATH
];
172 TRACE("%s\n", debugstr_w(pszPath
));
174 if (GetShortPathNameW(pszPath
, path
, MAX_PATH
))
176 lstrcpyW(pszPath
, path
);
180 /*************************************************************************
181 * PathGetShortPath [SHELL32.92]
183 VOID WINAPI
PathGetShortPathAW(LPVOID pszPath
)
185 if(SHELL_OsIsUnicode())
186 PathGetShortPathW(pszPath
);
187 PathGetShortPathA(pszPath
);
191 ########## Path Testing ##########
194 /*************************************************************************
195 * PathIsRoot [SHELL32.29]
197 BOOL WINAPI
PathIsRootAW(LPCVOID lpszPath
)
199 if (SHELL_OsIsUnicode())
200 return PathIsRootW(lpszPath
);
201 return PathIsRootA(lpszPath
);
204 /*************************************************************************
205 * PathIsExeA [internal]
207 static BOOL
PathIsExeA (LPCSTR lpszPath
)
209 LPCSTR lpszExtension
= PathGetExtensionA(lpszPath
);
211 static const char * const lpszExtensions
[] =
212 {"exe", "com", "pif", "cmd", "bat", "scf", "scr", NULL
};
214 TRACE("path=%s\n",lpszPath
);
216 for(i
=0; lpszExtensions
[i
]; i
++)
217 if (!lstrcmpiA(lpszExtension
,lpszExtensions
[i
])) return TRUE
;
222 /*************************************************************************
223 * PathIsExeW [internal]
225 BOOL
PathIsExeW (LPCWSTR lpszPath
)
227 LPCWSTR lpszExtension
= PathGetExtensionW(lpszPath
);
229 static const WCHAR lpszExtensions
[][4] =
230 {{'e','x','e','\0'}, {'c','o','m','\0'}, {'p','i','f','\0'},
231 {'c','m','d','\0'}, {'b','a','t','\0'}, {'s','c','f','\0'},
232 {'s','c','r','\0'}, {'\0'} };
234 TRACE("path=%s\n",debugstr_w(lpszPath
));
236 for(i
=0; lpszExtensions
[i
][0]; i
++)
237 if (!strcmpiW(lpszExtension
,lpszExtensions
[i
])) return TRUE
;
242 /*************************************************************************
243 * PathIsExe [SHELL32.43]
245 BOOL WINAPI
PathIsExeAW (LPCVOID path
)
247 if (SHELL_OsIsUnicode())
248 return PathIsExeW (path
);
249 return PathIsExeA(path
);
252 /*************************************************************************
253 * PathFileExists [SHELL32.45]
255 BOOL WINAPI
PathFileExistsAW (LPCVOID lpszPath
)
257 if (SHELL_OsIsUnicode())
258 return PathFileExistsW (lpszPath
);
259 return PathFileExistsA (lpszPath
);
262 /*************************************************************************
263 * PathIsSameRoot [SHELL32.650]
265 BOOL WINAPI
PathIsSameRootAW(LPCVOID lpszPath1
, LPCVOID lpszPath2
)
267 if (SHELL_OsIsUnicode())
268 return PathIsSameRootW(lpszPath1
, lpszPath2
);
269 return PathIsSameRootA(lpszPath1
, lpszPath2
);
272 /*************************************************************************
273 * IsLFNDriveA [SHELL32.41]
275 BOOL WINAPI
IsLFNDriveA(LPCSTR lpszPath
)
279 if (!GetVolumeInformationA(lpszPath
, NULL
, 0, NULL
, &fnlen
, NULL
, NULL
, 0))
284 /*************************************************************************
285 * IsLFNDriveW [SHELL32.42]
287 BOOL WINAPI
IsLFNDriveW(LPCWSTR lpszPath
)
291 if (!GetVolumeInformationW(lpszPath
, NULL
, 0, NULL
, &fnlen
, NULL
, NULL
, 0))
296 /*************************************************************************
297 * IsLFNDrive [SHELL32.119]
299 BOOL WINAPI
IsLFNDriveAW(LPCVOID lpszPath
)
301 if (SHELL_OsIsUnicode())
302 return IsLFNDriveW(lpszPath
);
303 return IsLFNDriveA(lpszPath
);
307 ########## Creating Something Unique ##########
309 /*************************************************************************
310 * PathMakeUniqueNameA [internal]
312 static BOOL
PathMakeUniqueNameA(
315 LPCSTR lpszShortName
,
319 FIXME("%p %u %s %s %s stub\n",
320 lpszBuffer
, dwBuffSize
, debugstr_a(lpszShortName
),
321 debugstr_a(lpszLongName
), debugstr_a(lpszPathName
));
325 /*************************************************************************
326 * PathMakeUniqueNameW [internal]
328 static BOOL
PathMakeUniqueNameW(
331 LPCWSTR lpszShortName
,
332 LPCWSTR lpszLongName
,
333 LPCWSTR lpszPathName
)
335 FIXME("%p %u %s %s %s stub\n",
336 lpszBuffer
, dwBuffSize
, debugstr_w(lpszShortName
),
337 debugstr_w(lpszLongName
), debugstr_w(lpszPathName
));
341 /*************************************************************************
342 * PathMakeUniqueName [SHELL32.47]
344 BOOL WINAPI
PathMakeUniqueNameAW(
347 LPCVOID lpszShortName
,
348 LPCVOID lpszLongName
,
349 LPCVOID lpszPathName
)
351 if (SHELL_OsIsUnicode())
352 return PathMakeUniqueNameW(lpszBuffer
,dwBuffSize
, lpszShortName
,lpszLongName
,lpszPathName
);
353 return PathMakeUniqueNameA(lpszBuffer
,dwBuffSize
, lpszShortName
,lpszLongName
,lpszPathName
);
356 /*************************************************************************
357 * PathYetAnotherMakeUniqueName [SHELL32.75]
359 BOOL WINAPI
PathYetAnotherMakeUniqueName(LPWSTR buffer
, LPCWSTR path
, LPCWSTR shortname
, LPCWSTR longname
)
361 WCHAR pathW
[MAX_PATH
], retW
[MAX_PATH
];
362 const WCHAR
*file
, *ext
;
365 TRACE("(%p, %s, %s, %s)\n", buffer
, debugstr_w(path
), debugstr_w(shortname
), debugstr_w(longname
));
367 file
= longname
? longname
: shortname
;
368 PathCombineW(pathW
, path
, file
);
369 strcpyW(retW
, pathW
);
370 PathRemoveExtensionW(pathW
);
372 ext
= PathFindExtensionW(file
);
374 /* now try to make it unique */
375 while (PathFileExistsW(retW
))
377 static const WCHAR fmtW
[] = {'%','s',' ','(','%','d',')','%','s',0};
379 sprintfW(retW
, fmtW
, pathW
, i
, ext
);
383 strcpyW(buffer
, retW
);
384 TRACE("ret - %s\n", debugstr_w(buffer
));
390 ########## cleaning and resolving paths ##########
393 /*************************************************************************
394 * PathCleanupSpec [SHELL32.171]
396 * lpszFile is changed in place.
398 int WINAPI
PathCleanupSpec( LPCWSTR lpszPathW
, LPWSTR lpszFileW
)
404 if (SHELL_OsIsUnicode())
406 LPWSTR p
= lpszFileW
;
408 TRACE("Cleanup %s\n",debugstr_w(lpszFileW
));
411 length
= strlenW(lpszPathW
);
415 int gct
= PathGetCharTypeW(*p
);
416 if (gct
== GCT_INVALID
|| gct
== GCT_WILD
|| gct
== GCT_SEPARATOR
)
419 rc
|= PCS_REPLACEDCHAR
;
425 if (length
+ i
== MAX_PATH
)
427 rc
|= PCS_FATAL
| PCS_PATHTOOLONG
;
435 LPSTR lpszFileA
= (LPSTR
)lpszFileW
;
436 LPCSTR lpszPathA
= (LPCSTR
)lpszPathW
;
439 TRACE("Cleanup %s\n",debugstr_a(lpszFileA
));
442 length
= strlen(lpszPathA
);
446 int gct
= PathGetCharTypeA(*p
);
447 if (gct
== GCT_INVALID
|| gct
== GCT_WILD
|| gct
== GCT_SEPARATOR
)
450 rc
|= PCS_REPLACEDCHAR
;
456 if (length
+ i
== MAX_PATH
)
458 rc
|= PCS_FATAL
| PCS_PATHTOOLONG
;
467 /*************************************************************************
468 * PathQualifyA [SHELL32]
470 static BOOL
PathQualifyA(LPCSTR pszPath
)
472 FIXME("%s\n",pszPath
);
476 /*************************************************************************
477 * PathQualifyW [SHELL32]
479 static BOOL
PathQualifyW(LPCWSTR pszPath
)
481 FIXME("%s\n",debugstr_w(pszPath
));
485 /*************************************************************************
486 * PathQualify [SHELL32.49]
488 BOOL WINAPI
PathQualifyAW(LPCVOID pszPath
)
490 if (SHELL_OsIsUnicode())
491 return PathQualifyW(pszPath
);
492 return PathQualifyA(pszPath
);
495 static BOOL
PathResolveA(LPSTR path
, LPCSTR
*paths
, DWORD flags
)
497 FIXME("(%s,%p,0x%08x),stub!\n", debugstr_a(path
), paths
, flags
);
501 static BOOL
PathResolveW(LPWSTR path
, LPCWSTR
*paths
, DWORD flags
)
503 FIXME("(%s,%p,0x%08x),stub!\n", debugstr_w(path
), paths
, flags
);
507 /*************************************************************************
508 * PathResolve [SHELL32.51]
510 BOOL WINAPI
PathResolveAW(LPVOID path
, LPCVOID
*paths
, DWORD flags
)
512 if (SHELL_OsIsUnicode())
513 return PathResolveW(path
, (LPCWSTR
*)paths
, flags
);
515 return PathResolveA(path
, (LPCSTR
*)paths
, flags
);
518 /*************************************************************************
519 * PathProcessCommandA
521 static LONG
PathProcessCommandA (
527 FIXME("%s %p 0x%04x 0x%04x stub\n",
528 lpszPath
, lpszBuff
, dwBuffSize
, dwFlags
);
529 if(!lpszPath
) return -1;
530 if(lpszBuff
) strcpy(lpszBuff
, lpszPath
);
531 return strlen(lpszPath
);
534 /*************************************************************************
535 * PathProcessCommandW
537 static LONG
PathProcessCommandW (
543 FIXME("(%s, %p, 0x%04x, 0x%04x) stub\n",
544 debugstr_w(lpszPath
), lpszBuff
, dwBuffSize
, dwFlags
);
545 if(!lpszPath
) return -1;
546 if(lpszBuff
) strcpyW(lpszBuff
, lpszPath
);
547 return strlenW(lpszPath
);
550 /*************************************************************************
551 * PathProcessCommand (SHELL32.653)
553 LONG WINAPI
PathProcessCommandAW (
559 if (SHELL_OsIsUnicode())
560 return PathProcessCommandW(lpszPath
, lpszBuff
, dwBuffSize
, dwFlags
);
561 return PathProcessCommandA(lpszPath
, lpszBuff
, dwBuffSize
, dwFlags
);
565 ########## special ##########
568 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'};
569 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'};
570 static const WCHAR AppDataW
[] = {'A','p','p','D','a','t','a','\0'};
571 static const WCHAR AppData_LocalLowW
[] = {'A','p','p','D','a','t','a','\\','L','o','c','a','l','L','o','w','\0'};
572 static const WCHAR Application_DataW
[] = {'A','p','p','l','i','c','a','t','i','o','n',' ','D','a','t','a','\0'};
573 static const WCHAR CacheW
[] = {'C','a','c','h','e','\0'};
574 static const WCHAR CD_BurningW
[] = {'C','D',' ','B','u','r','n','i','n','g','\0'};
575 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'};
576 static const WCHAR Common_AppDataW
[] = {'C','o','m','m','o','n',' ','A','p','p','D','a','t','a','\0'};
577 static const WCHAR Common_DesktopW
[] = {'C','o','m','m','o','n',' ','D','e','s','k','t','o','p','\0'};
578 static const WCHAR Common_DocumentsW
[] = {'C','o','m','m','o','n',' ','D','o','c','u','m','e','n','t','s','\0'};
579 static const WCHAR Common_FavoritesW
[] = {'C','o','m','m','o','n',' ','F','a','v','o','r','i','t','e','s','\0'};
580 static const WCHAR CommonFilesDirW
[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r','\0'};
581 static const WCHAR CommonFilesDirX86W
[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r',' ','(','x','8','6',')','\0'};
582 static const WCHAR CommonMusicW
[] = {'C','o','m','m','o','n','M','u','s','i','c','\0'};
583 static const WCHAR CommonPicturesW
[] = {'C','o','m','m','o','n','P','i','c','t','u','r','e','s','\0'};
584 static const WCHAR Common_ProgramsW
[] = {'C','o','m','m','o','n',' ','P','r','o','g','r','a','m','s','\0'};
585 static const WCHAR Common_StartUpW
[] = {'C','o','m','m','o','n',' ','S','t','a','r','t','U','p','\0'};
586 static const WCHAR Common_Start_MenuW
[] = {'C','o','m','m','o','n',' ','S','t','a','r','t',' ','M','e','n','u','\0'};
587 static const WCHAR Common_TemplatesW
[] = {'C','o','m','m','o','n',' ','T','e','m','p','l','a','t','e','s','\0'};
588 static const WCHAR CommonVideoW
[] = {'C','o','m','m','o','n','V','i','d','e','o','\0'};
589 static const WCHAR ContactsW
[] = {'C','o','n','t','a','c','t','s','\0'};
590 static const WCHAR CookiesW
[] = {'C','o','o','k','i','e','s','\0'};
591 static const WCHAR DesktopW
[] = {'D','e','s','k','t','o','p','\0'};
592 static const WCHAR DocumentsW
[] = {'D','o','c','u','m','e','n','t','s','\0'};
593 static const WCHAR DownloadsW
[] = {'D','o','w','n','l','o','a','d','s','\0'};
594 static const WCHAR FavoritesW
[] = {'F','a','v','o','r','i','t','e','s','\0'};
595 static const WCHAR FontsW
[] = {'F','o','n','t','s','\0'};
596 static const WCHAR HistoryW
[] = {'H','i','s','t','o','r','y','\0'};
597 static const WCHAR LinksW
[] = {'L','i','n','k','s','\0'};
598 static const WCHAR Local_AppDataW
[] = {'L','o','c','a','l',' ','A','p','p','D','a','t','a','\0'};
599 static const WCHAR Local_Settings_Application_DataW
[] = {'L','o','c','a','l',' ','S','e','t','t','i','n','g','s','\\','A','p','p','l','i','c','a','t','i','o','n',' ','D','a','t','a','\0'};
600 static const WCHAR Local_Settings_CD_BurningW
[] = {'L','o','c','a','l',' ','S','e','t','t','i','n','g','s','\\','A','p','p','l','i','c','a','t','i','o','n',' ','D','a','t','a','\\','M','i','c','r','o','s','o','f','t','\\','C','D',' ','B','u','r','n','i','n','g','\0'};
601 static const WCHAR Local_Settings_HistoryW
[] = {'L','o','c','a','l',' ','S','e','t','t','i','n','g','s','\\','H','i','s','t','o','r','y','\0'};
602 static const WCHAR Local_Settings_Temporary_Internet_FilesW
[] = {'L','o','c','a','l',' ','S','e','t','t','i','n','g','s','\\','T','e','m','p','o','r','a','r','y',' ','I','n','t','e','r','n','e','t',' ','F','i','l','e','s','\0'};
603 static const WCHAR Microsoft_Windows_GameExplorerW
[] = {'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','G','a','m','e','E','x','p','l','o','r','e','r','\0'};
604 static const WCHAR Microsoft_Windows_LibrariesW
[] = {'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','L','i','b','r','a','r','i','e','s','\0'};
605 static const WCHAR Microsoft_Windows_RingtonesW
[] = {'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','R','i','n','g','t','o','n','e','s','\0'};
606 static const WCHAR MusicW
[] = {'M','u','s','i','c','\0'};
607 static const WCHAR Music_PlaylistsW
[] = {'M','u','s','i','c','\\','P','l','a','y','l','i','s','t','s','\0'};
608 static const WCHAR Music_Sample_MusicW
[] = {'M','u','s','i','c','\\','S','a','m','p','l','e',' ','M','u','s','i','c','\0'};
609 static const WCHAR Music_Sample_PlaylistsW
[] = {'M','u','s','i','c','\\','S','a','m','p','l','e',' ','P','l','a','y','l','i','s','t','s','\0'};
610 static const WCHAR My_DocumentsW
[] = {'M','y',' ','D','o','c','u','m','e','n','t','s','\0'};
611 static const WCHAR My_MusicW
[] = {'M','y',' ','M','u','s','i','c','\0'};
612 static const WCHAR My_PicturesW
[] = {'M','y',' ','P','i','c','t','u','r','e','s','\0'};
613 static const WCHAR My_VideoW
[] = {'M','y',' ','V','i','d','e','o','\0'};
614 static const WCHAR NetHoodW
[] = {'N','e','t','H','o','o','d','\0'};
615 static const WCHAR OEM_LinksW
[] = {'O','E','M',' ','L','i','n','k','s','\0'};
616 static const WCHAR PersonalW
[] = {'P','e','r','s','o','n','a','l','\0'};
617 static const WCHAR PicturesW
[] = {'P','i','c','t','u','r','e','s','\0'};
618 static const WCHAR Pictures_Sample_PicturesW
[] = {'P','i','c','t','u','r','e','s','\\','S','a','m','p','l','e',' ','P','i','c','t','u','r','e','s','\0'};
619 static const WCHAR Pictures_Slide_ShowsW
[] = {'P','i','c','t','u','r','e','s','\\','S','l','i','d','e',' ','S','h','o','w','s','\0'};
620 static const WCHAR PrintHoodW
[] = {'P','r','i','n','t','H','o','o','d','\0'};
621 static const WCHAR Program_FilesW
[] = {'P','r','o','g','r','a','m',' ','F','i','l','e','s','\0'};
622 static const WCHAR Program_Files_Common_FilesW
[] = {'P','r','o','g','r','a','m',' ','F','i','l','e','s','\\','C','o','m','m','o','n',' ','F','i','l','e','s','\0'};
623 static const WCHAR Program_Files_x86W
[] = {'P','r','o','g','r','a','m',' ','F','i','l','e','s',' ','(','x','8','6',')','\0'};
624 static const WCHAR Program_Files_x86_Common_FilesW
[] = {'P','r','o','g','r','a','m',' ','F','i','l','e','s',' ','(','x','8','6',')','\\','C','o','m','m','o','n',' ','F','i','l','e','s','\0'};
625 static const WCHAR ProgramFilesDirW
[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r','\0'};
626 static const WCHAR ProgramFilesDirX86W
[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r',' ','(','x','8','6',')','\0'};
627 static const WCHAR ProgramsW
[] = {'P','r','o','g','r','a','m','s','\0'};
628 static const WCHAR RecentW
[] = {'R','e','c','e','n','t','\0'};
629 static const WCHAR ResourcesW
[] = {'R','e','s','o','u','r','c','e','s','\0'};
630 static const WCHAR Saved_GamesW
[] = {'S','a','v','e','d',' ','G','a','m','e','s','\0'};
631 static const WCHAR SearchesW
[] = {'S','e','a','r','c','h','e','s','\0'};
632 static const WCHAR SendToW
[] = {'S','e','n','d','T','o','\0'};
633 static const WCHAR StartUpW
[] = {'S','t','a','r','t','U','p','\0'};
634 static const WCHAR Start_MenuW
[] = {'S','t','a','r','t',' ','M','e','n','u','\0'};
635 static const WCHAR Start_Menu_ProgramsW
[] = {'S','t','a','r','t',' ','M','e','n','u','\\','P','r','o','g','r','a','m','s','\0'};
636 static const WCHAR Start_Menu_Admin_ToolsW
[] = {'S','t','a','r','t',' ','M','e','n','u','\\','P','r','o','g','r','a','m','s','\\','A','d','m','i','n','i','s','t','r','a','t','i','v','e',' ','T','o','o','l','s','\0'};
637 static const WCHAR Start_Menu_StartupW
[] = {'S','t','a','r','t',' ','M','e','n','u','\\','P','r','o','g','r','a','m','s','\\','S','t','a','r','t','U','p','\0'};
638 static const WCHAR TemplatesW
[] = {'T','e','m','p','l','a','t','e','s','\0'};
639 static const WCHAR UsersW
[] = {'U','s','e','r','s','\0'};
640 static const WCHAR UsersPublicW
[] = {'U','s','e','r','s','\\','P','u','b','l','i','c','\0'};
641 static const WCHAR VideosW
[] = {'V','i','d','e','o','s','\0'};
642 static const WCHAR Videos_Sample_VideosW
[] = {'V','i','d','e','o','s','\\','S','a','m','p','l','e',' ','V','i','d','e','o','s','\0'};
643 static const WCHAR DefaultW
[] = {'.','D','e','f','a','u','l','t','\0'};
644 static const WCHAR AllUsersProfileW
[] = {'%','A','L','L','U','S','E','R','S','P','R','O','F','I','L','E','%','\0'};
645 static const WCHAR UserProfileW
[] = {'%','U','S','E','R','P','R','O','F','I','L','E','%','\0'};
646 static const WCHAR SystemDriveW
[] = {'%','S','y','s','t','e','m','D','r','i','v','e','%','\0'};
647 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};
648 static const WCHAR ProfilesDirectoryW
[] = {'P','r','o','f','i','l','e','s','D','i','r','e','c','t','o','r','y',0};
649 static const WCHAR AllUsersProfileValueW
[] = {'A','l','l','U','s','e','r','s','P','r','o','f','i','l','e','\0'};
650 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'};
651 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'};
652 static const WCHAR szDefaultProfileDirW
[] = {'u','s','e','r','s',0};
653 static const WCHAR szKnownFolderDescriptions
[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l','o','r','e','r','\\','F','o','l','d','e','r','D','e','s','c','r','i','p','t','i','o','n','s','\0'};
654 static const WCHAR szKnownFolderRedirections
[] = {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\','C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\','E','x','p','l','o','r','e','r','\\','U','s','e','r',' ','S','h','e','l','l',' ','F','o','l','d','e','r','s',0};
655 static const WCHAR AllUsersW
[] = {'P','u','b','l','i','c',0};
657 typedef enum _CSIDL_Type
{
661 CSIDL_Type_Disallowed
,
662 CSIDL_Type_NonExistent
,
663 CSIDL_Type_WindowsPath
,
664 CSIDL_Type_SystemPath
,
665 CSIDL_Type_SystemX86Path
,
668 #if WIN32_WINNT >= 0x0600
669 #define CSIDL_CONTACTS 0x0043
670 #define CSIDL_DOWNLOADS 0x0047
671 #define CSIDL_LINKS 0x004d
672 #define CSIDL_APPDATA_LOCALLOW 0x004e
673 #define CSIDL_SAVED_GAMES 0x0062
674 #define CSIDL_SEARCHES 0x0063
679 const KNOWNFOLDERID
*id
;
682 LPCWSTR szDefaultPath
; /* fallback string or resource ID */
685 static const CSIDL_DATA CSIDL_Data
[] =
687 { /* 0x00 - CSIDL_DESKTOP */
691 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY
)
693 { /* 0x01 - CSIDL_INTERNET */
694 &FOLDERID_InternetFolder
,
695 CSIDL_Type_Disallowed
,
699 { /* 0x02 - CSIDL_PROGRAMS */
703 MAKEINTRESOURCEW(IDS_PROGRAMS
)
705 { /* 0x03 - CSIDL_CONTROLS (.CPL files) */
706 &FOLDERID_ControlPanelFolder
,
707 CSIDL_Type_SystemPath
,
711 { /* 0x04 - CSIDL_PRINTERS */
712 &FOLDERID_PrintersFolder
,
713 CSIDL_Type_SystemPath
,
717 { /* 0x05 - CSIDL_PERSONAL */
721 MAKEINTRESOURCEW(IDS_PERSONAL
)
723 { /* 0x06 - CSIDL_FAVORITES */
727 MAKEINTRESOURCEW(IDS_FAVORITES
)
729 { /* 0x07 - CSIDL_STARTUP */
733 MAKEINTRESOURCEW(IDS_STARTUP
)
735 { /* 0x08 - CSIDL_RECENT */
739 MAKEINTRESOURCEW(IDS_RECENT
)
741 { /* 0x09 - CSIDL_SENDTO */
745 MAKEINTRESOURCEW(IDS_SENDTO
)
747 { /* 0x0a - CSIDL_BITBUCKET - Recycle Bin */
748 &FOLDERID_RecycleBinFolder
,
749 CSIDL_Type_Disallowed
,
753 { /* 0x0b - CSIDL_STARTMENU */
757 MAKEINTRESOURCEW(IDS_STARTMENU
)
759 { /* 0x0c - CSIDL_MYDOCUMENTS */
761 CSIDL_Type_Disallowed
, /* matches WinXP--can't get its path */
765 { /* 0x0d - CSIDL_MYMUSIC */
769 MAKEINTRESOURCEW(IDS_MYMUSIC
)
771 { /* 0x0e - CSIDL_MYVIDEO */
775 MAKEINTRESOURCEW(IDS_MYVIDEO
)
777 { /* 0x0f - unassigned */
779 CSIDL_Type_Disallowed
,
783 { /* 0x10 - CSIDL_DESKTOPDIRECTORY */
787 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY
)
789 { /* 0x11 - CSIDL_DRIVES */
790 &FOLDERID_ComputerFolder
,
791 CSIDL_Type_Disallowed
,
795 { /* 0x12 - CSIDL_NETWORK */
796 &FOLDERID_NetworkFolder
,
797 CSIDL_Type_Disallowed
,
801 { /* 0x13 - CSIDL_NETHOOD */
805 MAKEINTRESOURCEW(IDS_NETHOOD
)
807 { /* 0x14 - CSIDL_FONTS */
809 CSIDL_Type_WindowsPath
,
811 MAKEINTRESOURCEW(IDS_FONTS
)
813 { /* 0x15 - CSIDL_TEMPLATES */
817 MAKEINTRESOURCEW(IDS_TEMPLATES
)
819 { /* 0x16 - CSIDL_COMMON_STARTMENU */
820 &FOLDERID_CommonStartMenu
,
823 MAKEINTRESOURCEW(IDS_STARTMENU
)
825 { /* 0x17 - CSIDL_COMMON_PROGRAMS */
826 &FOLDERID_CommonPrograms
,
829 MAKEINTRESOURCEW(IDS_PROGRAMS
)
831 { /* 0x18 - CSIDL_COMMON_STARTUP */
832 &FOLDERID_CommonStartup
,
835 MAKEINTRESOURCEW(IDS_STARTUP
)
837 { /* 0x19 - CSIDL_COMMON_DESKTOPDIRECTORY */
838 &FOLDERID_PublicDesktop
,
841 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY
)
843 { /* 0x1a - CSIDL_APPDATA */
844 &FOLDERID_RoamingAppData
,
847 MAKEINTRESOURCEW(IDS_APPDATA
)
849 { /* 0x1b - CSIDL_PRINTHOOD */
853 MAKEINTRESOURCEW(IDS_PRINTHOOD
)
855 { /* 0x1c - CSIDL_LOCAL_APPDATA */
856 &FOLDERID_LocalAppData
,
859 MAKEINTRESOURCEW(IDS_LOCAL_APPDATA
)
861 { /* 0x1d - CSIDL_ALTSTARTUP */
863 CSIDL_Type_NonExistent
,
867 { /* 0x1e - CSIDL_COMMON_ALTSTARTUP */
869 CSIDL_Type_NonExistent
,
873 { /* 0x1f - CSIDL_COMMON_FAVORITES */
877 MAKEINTRESOURCEW(IDS_FAVORITES
)
879 { /* 0x20 - CSIDL_INTERNET_CACHE */
880 &FOLDERID_InternetCache
,
883 MAKEINTRESOURCEW(IDS_INTERNET_CACHE
)
885 { /* 0x21 - CSIDL_COOKIES */
889 MAKEINTRESOURCEW(IDS_COOKIES
)
891 { /* 0x22 - CSIDL_HISTORY */
895 MAKEINTRESOURCEW(IDS_HISTORY
)
897 { /* 0x23 - CSIDL_COMMON_APPDATA */
898 &FOLDERID_ProgramData
,
901 MAKEINTRESOURCEW(IDS_APPDATA
)
903 { /* 0x24 - CSIDL_WINDOWS */
905 CSIDL_Type_WindowsPath
,
909 { /* 0x25 - CSIDL_SYSTEM */
911 CSIDL_Type_SystemPath
,
915 { /* 0x26 - CSIDL_PROGRAM_FILES */
916 &FOLDERID_ProgramFiles
,
919 MAKEINTRESOURCEW(IDS_PROGRAM_FILES
)
921 { /* 0x27 - CSIDL_MYPICTURES */
925 MAKEINTRESOURCEW(IDS_MYPICTURES
)
927 { /* 0x28 - CSIDL_PROFILE */
933 { /* 0x29 - CSIDL_SYSTEMX86 */
935 CSIDL_Type_SystemX86Path
,
939 { /* 0x2a - CSIDL_PROGRAM_FILESX86 */
940 &FOLDERID_ProgramFilesX86
,
945 { /* 0x2b - CSIDL_PROGRAM_FILES_COMMON */
946 &FOLDERID_ProgramFilesCommon
,
949 MAKEINTRESOURCEW(IDS_PROGRAM_FILES_COMMON
)
951 { /* 0x2c - CSIDL_PROGRAM_FILES_COMMONX86 */
952 &FOLDERID_ProgramFilesCommonX86
,
955 Program_Files_x86_Common_FilesW
957 { /* 0x2d - CSIDL_COMMON_TEMPLATES */
958 &FOLDERID_CommonTemplates
,
961 MAKEINTRESOURCEW(IDS_TEMPLATES
)
963 { /* 0x2e - CSIDL_COMMON_DOCUMENTS */
964 &FOLDERID_PublicDocuments
,
967 MAKEINTRESOURCEW(IDS_PERSONAL
)
969 { /* 0x2f - CSIDL_COMMON_ADMINTOOLS */
970 &FOLDERID_CommonAdminTools
,
972 Common_Administrative_ToolsW
,
973 MAKEINTRESOURCEW(IDS_ADMINTOOLS
)
975 { /* 0x30 - CSIDL_ADMINTOOLS */
976 &FOLDERID_AdminTools
,
978 Administrative_ToolsW
,
979 MAKEINTRESOURCEW(IDS_ADMINTOOLS
)
981 { /* 0x31 - CSIDL_CONNECTIONS */
982 &FOLDERID_ConnectionsFolder
,
983 CSIDL_Type_Disallowed
,
987 { /* 0x32 - unassigned */
989 CSIDL_Type_Disallowed
,
993 { /* 0x33 - unassigned */
995 CSIDL_Type_Disallowed
,
999 { /* 0x34 - unassigned */
1001 CSIDL_Type_Disallowed
,
1005 { /* 0x35 - CSIDL_COMMON_MUSIC */
1006 &FOLDERID_PublicMusic
,
1007 CSIDL_Type_AllUsers
,
1009 MAKEINTRESOURCEW(IDS_COMMON_MUSIC
)
1011 { /* 0x36 - CSIDL_COMMON_PICTURES */
1012 &FOLDERID_PublicPictures
,
1013 CSIDL_Type_AllUsers
,
1015 MAKEINTRESOURCEW(IDS_COMMON_PICTURES
)
1017 { /* 0x37 - CSIDL_COMMON_VIDEO */
1018 &FOLDERID_PublicVideos
,
1019 CSIDL_Type_AllUsers
,
1021 MAKEINTRESOURCEW(IDS_COMMON_VIDEO
)
1023 { /* 0x38 - CSIDL_RESOURCES */
1024 &FOLDERID_ResourceDir
,
1025 CSIDL_Type_WindowsPath
,
1029 { /* 0x39 - CSIDL_RESOURCES_LOCALIZED */
1030 &FOLDERID_LocalizedResourcesDir
,
1031 CSIDL_Type_NonExistent
,
1035 { /* 0x3a - CSIDL_COMMON_OEM_LINKS */
1036 &FOLDERID_CommonOEMLinks
,
1037 CSIDL_Type_AllUsers
,
1041 { /* 0x3b - CSIDL_CDBURN_AREA */
1042 &FOLDERID_CDBurning
,
1045 Local_Settings_CD_BurningW
1047 { /* 0x3c unassigned */
1049 CSIDL_Type_Disallowed
,
1053 { /* 0x3d - CSIDL_COMPUTERSNEARME */
1055 CSIDL_Type_Disallowed
, /* FIXME */
1059 { /* 0x3e - CSIDL_PROFILES */
1061 CSIDL_Type_Disallowed
, /* oddly, this matches WinXP */
1065 #if WIN32_WINNT >= 0x0600
1067 &FOLDERID_AddNewPrograms
,
1068 CSIDL_Type_Disallowed
,
1073 &FOLDERID_AppUpdates
,
1074 CSIDL_Type_Disallowed
,
1079 &FOLDERID_ChangeRemovePrograms
,
1080 CSIDL_Type_Disallowed
,
1085 &FOLDERID_ConflictFolder
,
1086 CSIDL_Type_Disallowed
,
1090 { /* 0x43 - CSIDL_CONTACTS */
1097 &FOLDERID_DeviceMetadataStore
,
1098 CSIDL_Type_Disallowed
, /* FIXME */
1109 &FOLDERID_DocumentsLibrary
,
1110 CSIDL_Type_Disallowed
, /* FIXME */
1114 { /* 0x47 - CSIDL_DOWNLOADS */
1115 &FOLDERID_Downloads
,
1122 CSIDL_Type_Disallowed
,
1127 &FOLDERID_GameTasks
,
1128 CSIDL_Type_Disallowed
, /* FIXME */
1133 &FOLDERID_HomeGroup
,
1134 CSIDL_Type_Disallowed
,
1139 &FOLDERID_ImplicitAppShortcuts
,
1140 CSIDL_Type_Disallowed
, /* FIXME */
1145 &FOLDERID_Libraries
,
1146 CSIDL_Type_Disallowed
, /* FIXME */
1150 { /* 0x4d - CSIDL_LINKS */
1156 { /* 0x4e - CSIDL_APPDATA_LOCALLOW */
1157 &FOLDERID_LocalAppDataLow
,
1163 &FOLDERID_MusicLibrary
,
1164 CSIDL_Type_Disallowed
, /* FIXME */
1169 &FOLDERID_OriginalImages
,
1170 CSIDL_Type_Disallowed
, /* FIXME */
1175 &FOLDERID_PhotoAlbums
,
1178 Pictures_Slide_ShowsW
1181 &FOLDERID_PicturesLibrary
,
1182 CSIDL_Type_Disallowed
, /* FIXME */
1187 &FOLDERID_Playlists
,
1193 &FOLDERID_ProgramFilesX64
,
1194 CSIDL_Type_NonExistent
,
1199 &FOLDERID_ProgramFilesCommonX64
,
1200 CSIDL_Type_NonExistent
,
1206 CSIDL_Type_CurrVer
, /* FIXME */
1211 &FOLDERID_PublicDownloads
,
1212 CSIDL_Type_AllUsers
,
1217 &FOLDERID_PublicGameTasks
,
1218 CSIDL_Type_AllUsers
,
1220 Microsoft_Windows_GameExplorerW
1223 &FOLDERID_PublicLibraries
,
1224 CSIDL_Type_AllUsers
,
1226 Microsoft_Windows_LibrariesW
1229 &FOLDERID_PublicRingtones
,
1230 CSIDL_Type_AllUsers
,
1232 Microsoft_Windows_RingtonesW
1235 &FOLDERID_QuickLaunch
,
1236 CSIDL_Type_Disallowed
, /* FIXME */
1241 &FOLDERID_RecordedTVLibrary
,
1242 CSIDL_Type_Disallowed
, /* FIXME */
1247 &FOLDERID_Ringtones
,
1248 CSIDL_Type_Disallowed
, /* FIXME */
1253 &FOLDERID_SampleMusic
,
1254 CSIDL_Type_AllUsers
,
1259 &FOLDERID_SamplePictures
,
1260 CSIDL_Type_AllUsers
,
1262 Pictures_Sample_PicturesW
1265 &FOLDERID_SamplePlaylists
,
1266 CSIDL_Type_AllUsers
,
1268 Music_Sample_PlaylistsW
1271 &FOLDERID_SampleVideos
,
1272 CSIDL_Type_AllUsers
,
1274 Videos_Sample_VideosW
1276 { /* 0x62 - CSIDL_SAVED_GAMES */
1277 &FOLDERID_SavedGames
,
1282 { /* 0x63 - CSIDL_SEARCHES */
1283 &FOLDERID_SavedSearches
,
1289 &FOLDERID_SEARCH_CSC
,
1290 CSIDL_Type_Disallowed
,
1295 &FOLDERID_SEARCH_MAPI
,
1296 CSIDL_Type_Disallowed
,
1301 &FOLDERID_SearchHome
,
1302 CSIDL_Type_Disallowed
,
1307 &FOLDERID_SidebarDefaultParts
,
1308 CSIDL_Type_Disallowed
, /* FIXME */
1313 &FOLDERID_SidebarParts
,
1314 CSIDL_Type_Disallowed
, /* FIXME */
1319 &FOLDERID_SyncManagerFolder
,
1320 CSIDL_Type_Disallowed
,
1325 &FOLDERID_SyncResultsFolder
,
1326 CSIDL_Type_Disallowed
,
1331 &FOLDERID_SyncSetupFolder
,
1332 CSIDL_Type_Disallowed
,
1337 &FOLDERID_UserPinned
,
1338 CSIDL_Type_Disallowed
, /* FIXME */
1343 &FOLDERID_UserProfiles
,
1349 &FOLDERID_UserProgramFiles
,
1350 CSIDL_Type_Disallowed
, /* FIXME */
1355 &FOLDERID_UserProgramFilesCommon
,
1356 CSIDL_Type_Disallowed
, /* FIXME */
1361 &FOLDERID_UsersFiles
,
1362 CSIDL_Type_Disallowed
,
1367 &FOLDERID_UsersLibraries
,
1368 CSIDL_Type_Disallowed
,
1373 &FOLDERID_VideosLibrary
,
1374 CSIDL_Type_Disallowed
, /* FIXME */
1381 static HRESULT
_SHExpandEnvironmentStrings(LPCWSTR szSrc
, LPWSTR szDest
);
1383 /* Gets the value named value from the registry key
1384 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
1385 * (or from rootKey\userPrefix\... if userPrefix is not NULL) into path, which
1386 * is assumed to be MAX_PATH WCHARs in length.
1387 * If it exists, expands the value and writes the expanded value to
1388 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
1389 * Returns successful error code if the value was retrieved from the registry,
1390 * and a failure otherwise.
1392 static HRESULT
_SHGetUserShellFolderPath(HKEY rootKey
, LPCWSTR userPrefix
,
1393 LPCWSTR value
, LPWSTR path
)
1396 WCHAR shellFolderPath
[MAX_PATH
], userShellFolderPath
[MAX_PATH
];
1397 LPCWSTR pShellFolderPath
, pUserShellFolderPath
;
1398 DWORD dwType
, dwPathLen
= MAX_PATH
;
1399 HKEY userShellFolderKey
, shellFolderKey
;
1401 TRACE("%p,%s,%s,%p\n",rootKey
, debugstr_w(userPrefix
), debugstr_w(value
),
1406 strcpyW(shellFolderPath
, userPrefix
);
1407 PathAddBackslashW(shellFolderPath
);
1408 strcatW(shellFolderPath
, szSHFolders
);
1409 pShellFolderPath
= shellFolderPath
;
1410 strcpyW(userShellFolderPath
, userPrefix
);
1411 PathAddBackslashW(userShellFolderPath
);
1412 strcatW(userShellFolderPath
, szSHUserFolders
);
1413 pUserShellFolderPath
= userShellFolderPath
;
1417 pUserShellFolderPath
= szSHUserFolders
;
1418 pShellFolderPath
= szSHFolders
;
1421 if (RegCreateKeyW(rootKey
, pShellFolderPath
, &shellFolderKey
))
1423 TRACE("Failed to create %s\n", debugstr_w(pShellFolderPath
));
1426 if (RegCreateKeyW(rootKey
, pUserShellFolderPath
, &userShellFolderKey
))
1428 TRACE("Failed to create %s\n",
1429 debugstr_w(pUserShellFolderPath
));
1430 RegCloseKey(shellFolderKey
);
1434 if (!RegQueryValueExW(userShellFolderKey
, value
, NULL
, &dwType
,
1435 (LPBYTE
)path
, &dwPathLen
) && (dwType
== REG_EXPAND_SZ
|| dwType
== REG_SZ
))
1439 path
[dwPathLen
/ sizeof(WCHAR
)] = '\0';
1440 if (dwType
== REG_EXPAND_SZ
&& path
[0] == '%')
1442 WCHAR szTemp
[MAX_PATH
];
1444 _SHExpandEnvironmentStrings(path
, szTemp
);
1445 lstrcpynW(path
, szTemp
, MAX_PATH
);
1447 ret
= RegSetValueExW(shellFolderKey
, value
, 0, REG_SZ
, (LPBYTE
)path
,
1448 (strlenW(path
) + 1) * sizeof(WCHAR
));
1449 if (ret
!= ERROR_SUCCESS
)
1450 hr
= HRESULT_FROM_WIN32(ret
);
1456 RegCloseKey(shellFolderKey
);
1457 RegCloseKey(userShellFolderKey
);
1458 TRACE("returning 0x%08x\n", hr
);
1462 BOOL
_SHGetUserProfileDirectoryW(HANDLE hToken
, LPWSTR szPath
, LPDWORD lpcchPath
)
1467 OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY
, &hToken
);
1468 result
= GetUserProfileDirectoryW(hToken
, szPath
, lpcchPath
);
1469 CloseHandle(hToken
);
1471 else if ((INT
) hToken
== -1)
1473 result
= GetDefaultUserProfileDirectoryW(szPath
, lpcchPath
);
1477 result
= GetUserProfileDirectoryW(hToken
, szPath
, lpcchPath
);
1479 DbgPrint("_SHGetUserProfileDirectoryW returning %S\n", szPath
);
1483 /* Gets a 'semi-expanded' default value of the CSIDL with index folder into
1484 * pszPath, based on the entries in CSIDL_Data. By semi-expanded, I mean:
1485 * - The entry's szDefaultPath may be either a string value or an integer
1486 * resource identifier. In the latter case, the string value of the resource
1488 * - Depending on the entry's type, the path may begin with an (unexpanded)
1489 * environment variable name. The caller is responsible for expanding
1490 * environment strings if so desired.
1491 * The types that are prepended with environment variables are:
1492 * CSIDL_Type_User: %USERPROFILE%
1493 * CSIDL_Type_AllUsers: %ALLUSERSPROFILE%
1494 * CSIDL_Type_CurrVer: %SystemDrive%
1495 * (Others might make sense too, but as yet are unneeded.)
1497 static HRESULT
_SHGetDefaultValue(HANDLE hToken
, BYTE folder
, LPWSTR pszPath
)
1501 WCHAR resourcePath
[MAX_PATH
];
1503 TRACE("0x%02x,%p\n", folder
, pszPath
);
1505 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1506 return E_INVALIDARG
;
1508 return E_INVALIDARG
;
1512 case CSIDL_PROGRAM_FILES
:
1514 folder
= CSIDL_PROGRAM_FILESX86
;
1516 case CSIDL_PROGRAM_FILES_COMMON
:
1518 folder
= CSIDL_PROGRAM_FILESX86
;
1522 switch (CSIDL_Data
[folder
].type
)
1524 case CSIDL_Type_User
:
1526 if (!_SHGetUserProfileDirectoryW(hToken
, pszPath
, &cchSize
))
1527 return HRESULT_FROM_WIN32(GetLastError());
1529 case CSIDL_Type_AllUsers
:
1531 if (!GetAllUsersProfileDirectoryW(pszPath
, &cchSize
))
1532 return HRESULT_FROM_WIN32(GetLastError());
1534 case CSIDL_Type_CurrVer
:
1535 strcpyW(pszPath
, SystemDriveW
);
1538 ; /* no corresponding env. var, do nothing */
1541 if (CSIDL_Data
[folder
].szDefaultPath
)
1543 if (IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
))
1545 if (LoadStringW(shell32_hInstance
,
1546 LOWORD(CSIDL_Data
[folder
].szDefaultPath
), resourcePath
, MAX_PATH
))
1549 PathAppendW(pszPath
, resourcePath
);
1553 ERR("(%d,%s), LoadString failed, missing translation?\n", folder
,
1554 debugstr_w(pszPath
));
1561 PathAppendW(pszPath
, CSIDL_Data
[folder
].szDefaultPath
);
1564 TRACE("returning 0x%08x\n", hr
);
1568 /* Gets the (unexpanded) value of the folder with index folder into pszPath.
1569 * The folder's type is assumed to be CSIDL_Type_CurrVer. Its default value
1570 * can be overridden in the HKLM\\szCurrentVersion key.
1571 * If dwFlags has SHGFP_TYPE_DEFAULT set or if the value isn't overridden in
1572 * the registry, uses _SHGetDefaultValue to get the value.
1574 static HRESULT
_SHGetCurrentVersionPath(DWORD dwFlags
, BYTE folder
,
1579 TRACE("0x%08x,0x%02x,%p\n", dwFlags
, folder
, pszPath
);
1581 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1582 return E_INVALIDARG
;
1583 if (CSIDL_Data
[folder
].type
!= CSIDL_Type_CurrVer
)
1584 return E_INVALIDARG
;
1586 return E_INVALIDARG
;
1588 if (dwFlags
& SHGFP_TYPE_DEFAULT
)
1589 hr
= _SHGetDefaultValue(NULL
, folder
, pszPath
);
1594 if (RegCreateKeyW(HKEY_LOCAL_MACHINE
, szCurrentVersion
, &hKey
))
1598 DWORD dwType
, dwPathLen
= MAX_PATH
* sizeof(WCHAR
);
1600 if (RegQueryValueExW(hKey
, CSIDL_Data
[folder
].szValueName
, NULL
,
1601 &dwType
, (LPBYTE
)pszPath
, &dwPathLen
) ||
1602 (dwType
!= REG_SZ
&& dwType
!= REG_EXPAND_SZ
))
1604 hr
= _SHGetDefaultValue(NULL
, folder
, pszPath
);
1605 dwType
= REG_EXPAND_SZ
;
1608 case CSIDL_PROGRAM_FILESX86
:
1609 case CSIDL_PROGRAM_FILES_COMMONX86
:
1610 /* these two should never be set on 32-bit setups */
1614 IsWow64Process( GetCurrentProcess(), &is_wow64
);
1615 if (!is_wow64
) break;
1619 RegSetValueExW(hKey
, CSIDL_Data
[folder
].szValueName
, 0, dwType
,
1620 (LPBYTE
)pszPath
, (strlenW(pszPath
)+1)*sizeof(WCHAR
));
1625 pszPath
[dwPathLen
/ sizeof(WCHAR
)] = '\0';
1631 TRACE("returning 0x%08x (output path is %s)\n", hr
, debugstr_w(pszPath
));
1635 static LPWSTR
_GetUserSidStringFromToken(HANDLE Token
)
1637 char InfoBuffer
[64];
1638 PTOKEN_USER UserInfo
;
1642 UserInfo
= (PTOKEN_USER
) InfoBuffer
;
1643 if (! GetTokenInformation(Token
, TokenUser
, InfoBuffer
, sizeof(InfoBuffer
),
1646 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
1648 UserInfo
= HeapAlloc(GetProcessHeap(), 0, InfoSize
);
1649 if (UserInfo
== NULL
)
1651 if (! GetTokenInformation(Token
, TokenUser
, UserInfo
, InfoSize
,
1654 HeapFree(GetProcessHeap(), 0, UserInfo
);
1659 if (! ConvertSidToStringSidW(UserInfo
->User
.Sid
, &SidStr
))
1662 if (UserInfo
!= (PTOKEN_USER
) InfoBuffer
)
1663 HeapFree(GetProcessHeap(), 0, UserInfo
);
1668 /* Gets the user's path (unexpanded) for the CSIDL with index folder:
1669 * If SHGFP_TYPE_DEFAULT is set, calls _SHGetDefaultValue for it. Otherwise
1670 * calls _SHGetUserShellFolderPath for it. Where it looks depends on hToken:
1671 * - if hToken is -1, looks in HKEY_USERS\.Default
1672 * - otherwise looks first in HKEY_CURRENT_USER, followed by HKEY_LOCAL_MACHINE
1673 * if HKEY_CURRENT_USER doesn't contain any entries. If both fail, finally
1674 * calls _SHGetDefaultValue for it.
1676 static HRESULT
_SHGetUserProfilePath(HANDLE hToken
, DWORD dwFlags
, BYTE folder
,
1679 const WCHAR
*szValueName
;
1683 TRACE("%p,0x%08x,0x%02x,%p\n", hToken
, dwFlags
, folder
, pszPath
);
1685 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1686 return E_INVALIDARG
;
1687 if (CSIDL_Data
[folder
].type
!= CSIDL_Type_User
)
1688 return E_INVALIDARG
;
1690 return E_INVALIDARG
;
1692 if (dwFlags
& SHGFP_TYPE_DEFAULT
)
1694 hr
= _SHGetDefaultValue(hToken
, folder
, pszPath
);
1698 LPCWSTR userPrefix
= NULL
;
1701 if (hToken
== (HANDLE
)-1)
1703 hRootKey
= HKEY_USERS
;
1704 userPrefix
= DefaultW
;
1706 else if (hToken
== NULL
)
1707 hRootKey
= HKEY_CURRENT_USER
;
1710 hRootKey
= HKEY_USERS
;
1711 userPrefix
= _GetUserSidStringFromToken(hToken
);
1712 if (userPrefix
== NULL
)
1719 /* For CSIDL_Type_User we also use the GUID if no szValueName is provided */
1720 szValueName
= CSIDL_Data
[folder
].szValueName
;
1723 StringFromGUID2( CSIDL_Data
[folder
].id
, buffer
, 39 );
1724 szValueName
= &buffer
[0];
1727 hr
= _SHGetUserShellFolderPath(hRootKey
, userPrefix
, szValueName
, pszPath
);
1728 if (FAILED(hr
) && hRootKey
!= HKEY_LOCAL_MACHINE
)
1729 hr
= _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE
, NULL
, szValueName
, pszPath
);
1731 hr
= _SHGetDefaultValue(hToken
, folder
, pszPath
);
1732 if (userPrefix
!= NULL
&& userPrefix
!= DefaultW
)
1733 LocalFree((HLOCAL
) userPrefix
);
1736 TRACE("returning 0x%08x (output path is %s)\n", hr
, debugstr_w(pszPath
));
1740 /* Gets the (unexpanded) path for the CSIDL with index folder. If dwFlags has
1741 * SHGFP_TYPE_DEFAULT set, calls _SHGetDefaultValue. Otherwise calls
1742 * _SHGetUserShellFolderPath for it, looking only in HKEY_LOCAL_MACHINE.
1743 * If this fails, falls back to _SHGetDefaultValue.
1745 static HRESULT
_SHGetAllUsersProfilePath(DWORD dwFlags
, BYTE folder
,
1750 TRACE("0x%08x,0x%02x,%p\n", dwFlags
, folder
, pszPath
);
1752 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1753 return E_INVALIDARG
;
1754 if (CSIDL_Data
[folder
].type
!= CSIDL_Type_AllUsers
)
1755 return E_INVALIDARG
;
1757 return E_INVALIDARG
;
1759 if (dwFlags
& SHGFP_TYPE_DEFAULT
)
1760 hr
= _SHGetDefaultValue(NULL
, folder
, pszPath
);
1763 hr
= _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE
, NULL
,
1764 CSIDL_Data
[folder
].szValueName
, pszPath
);
1766 hr
= _SHGetDefaultValue(NULL
, folder
, pszPath
);
1768 TRACE("returning 0x%08x (output path is %s)\n", hr
, debugstr_w(pszPath
));
1772 static HRESULT
_SHOpenProfilesKey(PHKEY pKey
)
1777 lRet
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, ProfileListW
, 0, NULL
, 0,
1778 KEY_ALL_ACCESS
, NULL
, pKey
, &disp
);
1779 return HRESULT_FROM_WIN32(lRet
);
1782 /* Reads the value named szValueName from the key profilesKey (assumed to be
1783 * opened by _SHOpenProfilesKey) into szValue, which is assumed to be MAX_PATH
1784 * WCHARs in length. If it doesn't exist, returns szDefault (and saves
1785 * szDefault to the registry).
1787 static HRESULT
_SHGetProfilesValue(HKEY profilesKey
, LPCWSTR szValueName
,
1788 LPWSTR szValue
, LPCWSTR szDefault
)
1791 DWORD type
, dwPathLen
= MAX_PATH
* sizeof(WCHAR
);
1794 TRACE("%p,%s,%p,%s\n", profilesKey
, debugstr_w(szValueName
), szValue
,
1795 debugstr_w(szDefault
));
1796 lRet
= RegQueryValueExW(profilesKey
, szValueName
, NULL
, &type
,
1797 (LPBYTE
)szValue
, &dwPathLen
);
1798 if (!lRet
&& (type
== REG_SZ
|| type
== REG_EXPAND_SZ
) && dwPathLen
1801 dwPathLen
/= sizeof(WCHAR
);
1802 szValue
[dwPathLen
] = '\0';
1807 /* Missing or invalid value, set a default */
1808 lstrcpynW(szValue
, szDefault
, MAX_PATH
);
1809 TRACE("Setting missing value %s to %s\n", debugstr_w(szValueName
),
1810 debugstr_w(szValue
));
1811 lRet
= RegSetValueExW(profilesKey
, szValueName
, 0, REG_EXPAND_SZ
,
1813 (strlenW(szValue
) + 1) * sizeof(WCHAR
));
1815 hr
= HRESULT_FROM_WIN32(lRet
);
1819 TRACE("returning 0x%08x (output value is %s)\n", hr
, debugstr_w(szValue
));
1823 /* Attempts to expand environment variables from szSrc into szDest, which is
1824 * assumed to be MAX_PATH characters in length. Before referring to the
1825 * environment, handles a few variables directly, because the environment
1826 * variables may not be set when this is called (as during Wine's installation
1827 * when default values are being written to the registry).
1828 * The directly handled environment variables, and their source, are:
1829 * - ALLUSERSPROFILE, USERPROFILE: reads from the registry
1830 * - SystemDrive: uses GetSystemDirectoryW and uses the drive portion of its
1832 * If one of the directly handled environment variables is expanded, only
1833 * expands a single variable, and only in the beginning of szSrc.
1835 static HRESULT
_SHExpandEnvironmentStrings(LPCWSTR szSrc
, LPWSTR szDest
)
1838 WCHAR szTemp
[MAX_PATH
], szProfilesPrefix
[MAX_PATH
] = { 0 };
1841 TRACE("%s, %p\n", debugstr_w(szSrc
), szDest
);
1843 if (!szSrc
|| !szDest
) return E_INVALIDARG
;
1845 /* short-circuit if there's nothing to expand */
1846 if (szSrc
[0] != '%')
1848 strcpyW(szDest
, szSrc
);
1852 /* Get the profile prefix, we'll probably be needing it */
1853 hr
= _SHOpenProfilesKey(&key
);
1856 WCHAR def_val
[MAX_PATH
];
1858 /* get the system drive */
1859 GetSystemDirectoryW(def_val
, MAX_PATH
);
1860 if (def_val
[1] == ':') strcpyW( def_val
+ 3, szDefaultProfileDirW
);
1861 else FIXME("non-drive system paths unsupported\n");
1863 hr
= _SHGetProfilesValue(key
, ProfilesDirectoryW
, szProfilesPrefix
, def_val
);
1867 strcpyW(szTemp
, szSrc
);
1868 while (SUCCEEDED(hr
) && szTemp
[0] == '%')
1870 if (!strncmpiW(szTemp
, AllUsersProfileW
, strlenW(AllUsersProfileW
)))
1872 WCHAR szAllUsers
[MAX_PATH
];
1874 strcpyW(szDest
, szProfilesPrefix
);
1875 hr
= _SHGetProfilesValue(key
, AllUsersProfileValueW
,
1876 szAllUsers
, AllUsersW
);
1877 PathAppendW(szDest
, szAllUsers
);
1878 PathAppendW(szDest
, szTemp
+ strlenW(AllUsersProfileW
));
1880 else if (!strncmpiW(szTemp
, UserProfileW
, strlenW(UserProfileW
)))
1882 WCHAR userName
[MAX_PATH
];
1883 DWORD userLen
= MAX_PATH
;
1885 strcpyW(szDest
, szProfilesPrefix
);
1886 GetUserNameW(userName
, &userLen
);
1887 PathAppendW(szDest
, userName
);
1888 PathAppendW(szDest
, szTemp
+ strlenW(UserProfileW
));
1890 else if (!strncmpiW(szTemp
, SystemDriveW
, strlenW(SystemDriveW
)))
1892 GetSystemDirectoryW(szDest
, MAX_PATH
);
1893 if (szDest
[1] != ':')
1895 FIXME("non-drive system paths unsupported\n");
1900 strcpyW(szDest
+ 3, szTemp
+ strlenW(SystemDriveW
) + 1);
1906 DWORD ret
= ExpandEnvironmentStringsW(szSrc
, szDest
, MAX_PATH
);
1909 hr
= HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
1911 hr
= HRESULT_FROM_WIN32(GetLastError());
1915 if (SUCCEEDED(hr
) && szDest
[0] == '%')
1916 strcpyW(szTemp
, szDest
);
1919 /* terminate loop */
1926 TRACE("returning 0x%08x (input was %s, output is %s)\n", hr
,
1927 debugstr_w(szSrc
), debugstr_w(szDest
));
1931 /*************************************************************************
1932 * SHGetFolderPathW [SHELL32.@]
1934 * Convert nFolder to path.
1938 * Failure: standard HRESULT error codes.
1941 * Most values can be overridden in either
1942 * HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
1943 * or in the same location in HKLM.
1944 * The "Shell Folders" registry key was used in NT4 and earlier systems.
1945 * Beginning with Windows 2000, the "User Shell Folders" key is used, so
1946 * changes made to it are made to the former key too. This synchronization is
1947 * done on-demand: not until someone requests the value of one of these paths
1948 * (by calling one of the SHGet functions) is the value synchronized.
1949 * Furthermore, the HKCU paths take precedence over the HKLM paths.
1951 HRESULT WINAPI
SHGetFolderPathW(
1952 HWND hwndOwner
, /* [I] owner window */
1953 int nFolder
, /* [I] CSIDL identifying the folder */
1954 HANDLE hToken
, /* [I] access token */
1955 DWORD dwFlags
, /* [I] which path to return */
1956 LPWSTR pszPath
) /* [O] converted path */
1958 HRESULT hr
= SHGetFolderPathAndSubDirW(hwndOwner
, nFolder
, hToken
, dwFlags
, NULL
, pszPath
);
1959 if(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
) == hr
)
1960 hr
= HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
1964 HRESULT WINAPI
SHGetFolderPathAndSubDirA(
1965 HWND hwndOwner
, /* [I] owner window */
1966 int nFolder
, /* [I] CSIDL identifying the folder */
1967 HANDLE hToken
, /* [I] access token */
1968 DWORD dwFlags
, /* [I] which path to return */
1969 LPCSTR pszSubPath
, /* [I] sub directory of the specified folder */
1970 LPSTR pszPath
) /* [O] converted path */
1974 LPWSTR pszSubPathW
= NULL
;
1975 LPWSTR pszPathW
= NULL
;
1976 TRACE("%08x,%08x,%s\n",nFolder
, dwFlags
, debugstr_w(pszSubPathW
));
1979 pszPathW
= HeapAlloc(GetProcessHeap(), 0, MAX_PATH
* sizeof(WCHAR
));
1981 hr
= HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY
);
1985 TRACE("%08x,%08x,%s\n",nFolder
, dwFlags
, debugstr_w(pszSubPathW
));
1987 /* SHGetFolderPathAndSubDirW does not distinguish if pszSubPath isn't
1988 * set (null), or an empty string.therefore call it without the parameter set
1989 * if pszSubPath is an empty string
1991 if (pszSubPath
&& pszSubPath
[0]) {
1992 length
= MultiByteToWideChar(CP_ACP
, 0, pszSubPath
, -1, NULL
, 0);
1993 pszSubPathW
= HeapAlloc(GetProcessHeap(), 0, length
* sizeof(WCHAR
));
1995 hr
= HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY
);
1998 MultiByteToWideChar(CP_ACP
, 0, pszSubPath
, -1, pszSubPathW
, length
);
2001 hr
= SHGetFolderPathAndSubDirW(hwndOwner
, nFolder
, hToken
, dwFlags
, pszSubPathW
, pszPathW
);
2003 if (SUCCEEDED(hr
) && pszPath
)
2004 WideCharToMultiByte(CP_ACP
, 0, pszPathW
, -1, pszPath
, MAX_PATH
, NULL
, NULL
);
2007 HeapFree(GetProcessHeap(), 0, pszPathW
);
2008 HeapFree(GetProcessHeap(), 0, pszSubPathW
);
2012 /*************************************************************************
2013 * SHGetFolderPathAndSubDirW [SHELL32.@]
2015 HRESULT WINAPI
SHGetFolderPathAndSubDirW(
2016 HWND hwndOwner
, /* [I] owner window */
2017 int nFolder
, /* [I] CSIDL identifying the folder */
2018 HANDLE hToken
, /* [I] access token */
2019 DWORD dwFlags
, /* [I] which path to return */
2020 LPCWSTR pszSubPath
,/* [I] sub directory of the specified folder */
2021 LPWSTR pszPath
) /* [O] converted path */
2024 WCHAR szBuildPath
[MAX_PATH
], szTemp
[MAX_PATH
];
2025 DWORD folder
= nFolder
& CSIDL_FOLDER_MASK
;
2029 TRACE("%p,%p,nFolder=0x%04x,%s\n", hwndOwner
,pszPath
,nFolder
,debugstr_w(pszSubPath
));
2031 /* Windows always NULL-terminates the resulting path regardless of success
2032 * or failure, so do so first
2037 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
2038 return E_INVALIDARG
;
2039 if ((SHGFP_TYPE_CURRENT
!= dwFlags
) && (SHGFP_TYPE_DEFAULT
!= dwFlags
))
2040 return E_INVALIDARG
;
2042 type
= CSIDL_Data
[folder
].type
;
2045 case CSIDL_Type_Disallowed
:
2048 case CSIDL_Type_NonExistent
:
2051 case CSIDL_Type_WindowsPath
:
2052 GetWindowsDirectoryW(szTemp
, MAX_PATH
);
2053 if (CSIDL_Data
[folder
].szDefaultPath
&&
2054 !IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
) &&
2055 *CSIDL_Data
[folder
].szDefaultPath
)
2057 PathAddBackslashW(szTemp
);
2058 strcatW(szTemp
, CSIDL_Data
[folder
].szDefaultPath
);
2062 case CSIDL_Type_SystemPath
:
2063 GetSystemDirectoryW(szTemp
, MAX_PATH
);
2064 if (CSIDL_Data
[folder
].szDefaultPath
&&
2065 !IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
) &&
2066 *CSIDL_Data
[folder
].szDefaultPath
)
2068 PathAddBackslashW(szTemp
);
2069 strcatW(szTemp
, CSIDL_Data
[folder
].szDefaultPath
);
2073 case CSIDL_Type_SystemX86Path
:
2074 if (!GetSystemWow64DirectoryW(szTemp
, MAX_PATH
)) GetSystemDirectoryW(szTemp
, MAX_PATH
);
2075 if (CSIDL_Data
[folder
].szDefaultPath
&&
2076 !IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
) &&
2077 *CSIDL_Data
[folder
].szDefaultPath
)
2079 PathAddBackslashW(szTemp
);
2080 strcatW(szTemp
, CSIDL_Data
[folder
].szDefaultPath
);
2084 case CSIDL_Type_CurrVer
:
2085 hr
= _SHGetCurrentVersionPath(dwFlags
, folder
, szTemp
);
2087 case CSIDL_Type_User
:
2088 hr
= _SHGetUserProfilePath(hToken
, dwFlags
, folder
, szTemp
);
2090 case CSIDL_Type_AllUsers
:
2091 hr
= _SHGetAllUsersProfilePath(dwFlags
, folder
, szTemp
);
2094 FIXME("bogus type %d, please fix\n", type
);
2099 /* Expand environment strings if necessary */
2101 hr
= _SHExpandEnvironmentStrings(szTemp
, szBuildPath
);
2103 strcpyW(szBuildPath
, szTemp
);
2105 if (FAILED(hr
)) goto end
;
2108 /* make sure the new path does not exceed the buffer length
2109 * and remember to backslash and terminate it */
2110 if(MAX_PATH
< (lstrlenW(szBuildPath
) + lstrlenW(pszSubPath
) + 2)) {
2111 hr
= HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE
);
2114 PathAppendW(szBuildPath
, pszSubPath
);
2115 PathRemoveBackslashW(szBuildPath
);
2117 /* Copy the path if it's available before we might return */
2118 if (SUCCEEDED(hr
) && pszPath
)
2119 strcpyW(pszPath
, szBuildPath
);
2121 /* if we don't care about existing directories we are ready */
2122 if(nFolder
& CSIDL_FLAG_DONT_VERIFY
) goto end
;
2124 if (PathFileExistsW(szBuildPath
)) goto end
;
2126 /* not existing but we are not allowed to create it. The return value
2127 * is verified against shell32 version 6.0.
2129 if (!(nFolder
& CSIDL_FLAG_CREATE
))
2131 hr
= HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
);
2135 /* create directory/directories */
2136 ret
= SHCreateDirectoryExW(hwndOwner
, szBuildPath
, NULL
);
2137 if (ret
&& ret
!= ERROR_ALREADY_EXISTS
)
2139 ERR("Failed to create directory %s.\n", debugstr_w(szBuildPath
));
2144 TRACE("Created missing system directory %s\n", debugstr_w(szBuildPath
));
2146 TRACE("returning 0x%08x (final path is %s)\n", hr
, debugstr_w(szBuildPath
));
2150 /*************************************************************************
2151 * SHGetFolderPathA [SHELL32.@]
2153 * See SHGetFolderPathW.
2155 HRESULT WINAPI
SHGetFolderPathA(
2162 WCHAR szTemp
[MAX_PATH
];
2165 TRACE("%p,%p,nFolder=0x%04x\n",hwndOwner
,pszPath
,nFolder
);
2169 hr
= SHGetFolderPathW(hwndOwner
, nFolder
, hToken
, dwFlags
, szTemp
);
2170 if (SUCCEEDED(hr
) && pszPath
)
2171 WideCharToMultiByte(CP_ACP
, 0, szTemp
, -1, pszPath
, MAX_PATH
, NULL
,
2177 /* For each folder in folders, if its value has not been set in the registry,
2178 * calls _SHGetUserProfilePath or _SHGetAllUsersProfilePath (depending on the
2179 * folder's type) to get the unexpanded value first.
2180 * Writes the unexpanded value to User Shell Folders, and queries it with
2181 * SHGetFolderPathW to force the creation of the directory if it doesn't
2182 * already exist. SHGetFolderPathW also returns the expanded value, which
2183 * this then writes to Shell Folders.
2185 static HRESULT
_SHRegisterFolders(HKEY hRootKey
, HANDLE hToken
,
2186 LPCWSTR szUserShellFolderPath
, LPCWSTR szShellFolderPath
, const UINT folders
[],
2189 const WCHAR
*szValueName
;
2192 WCHAR path
[MAX_PATH
];
2194 HKEY hUserKey
= NULL
, hKey
= NULL
;
2195 DWORD dwType
, dwPathLen
;
2198 TRACE("%p,%p,%s,%p,%u\n", hRootKey
, hToken
,
2199 debugstr_w(szUserShellFolderPath
), folders
, foldersLen
);
2201 ret
= RegCreateKeyW(hRootKey
, szUserShellFolderPath
, &hUserKey
);
2203 hr
= HRESULT_FROM_WIN32(ret
);
2206 ret
= RegCreateKeyW(hRootKey
, szShellFolderPath
, &hKey
);
2208 hr
= HRESULT_FROM_WIN32(ret
);
2210 for (i
= 0; SUCCEEDED(hr
) && i
< foldersLen
; i
++)
2212 dwPathLen
= MAX_PATH
* sizeof(WCHAR
);
2214 /* For CSIDL_Type_User we also use the GUID if no szValueName is provided */
2215 szValueName
= CSIDL_Data
[folders
[i
]].szValueName
;
2216 if (!szValueName
&& CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_User
)
2218 StringFromGUID2( CSIDL_Data
[folders
[i
]].id
, buffer
, 39 );
2219 szValueName
= &buffer
[0];
2222 if (RegQueryValueExW(hUserKey
, szValueName
, NULL
,
2223 &dwType
, (LPBYTE
)path
, &dwPathLen
) || (dwType
!= REG_SZ
&&
2224 dwType
!= REG_EXPAND_SZ
))
2227 if (CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_User
)
2228 _SHGetUserProfilePath(hToken
, SHGFP_TYPE_DEFAULT
, folders
[i
],
2230 else if (CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_AllUsers
)
2231 _SHGetAllUsersProfilePath(SHGFP_TYPE_DEFAULT
, folders
[i
], path
);
2232 else if (CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_WindowsPath
)
2234 GetWindowsDirectoryW(path
, MAX_PATH
);
2235 if (CSIDL_Data
[folders
[i
]].szDefaultPath
&&
2236 !IS_INTRESOURCE(CSIDL_Data
[folders
[i
]].szDefaultPath
))
2238 PathAddBackslashW(path
);
2239 strcatW(path
, CSIDL_Data
[folders
[i
]].szDefaultPath
);
2246 ret
= RegSetValueExW(hUserKey
, szValueName
, 0, REG_EXPAND_SZ
,
2247 (LPBYTE
)path
, (strlenW(path
) + 1) * sizeof(WCHAR
));
2249 hr
= HRESULT_FROM_WIN32(ret
);
2252 hr
= SHGetFolderPathW(NULL
, folders
[i
] | CSIDL_FLAG_CREATE
,
2253 hToken
, SHGFP_TYPE_DEFAULT
, path
);
2254 ret
= RegSetValueExW(hKey
, szValueName
, 0, REG_SZ
,
2255 (LPBYTE
)path
, (strlenW(path
) + 1) * sizeof(WCHAR
));
2257 hr
= HRESULT_FROM_WIN32(ret
);
2263 RegCloseKey(hUserKey
);
2267 TRACE("returning 0x%08x\n", hr
);
2271 static HRESULT
_SHRegisterUserShellFolders(BOOL bDefault
)
2273 static const UINT folders
[] = {
2284 CSIDL_DESKTOPDIRECTORY
,
2288 CSIDL_LOCAL_APPDATA
,
2289 CSIDL_INTERNET_CACHE
,
2295 #if WIN32_WINNT >= 0x0600
2299 CSIDL_APPDATA_LOCALLOW
,
2304 WCHAR userShellFolderPath
[MAX_PATH
], shellFolderPath
[MAX_PATH
];
2305 LPCWSTR pUserShellFolderPath
, pShellFolderPath
;
2310 TRACE("%s\n", bDefault
? "TRUE" : "FALSE");
2313 hToken
= (HANDLE
)-1;
2314 hRootKey
= HKEY_USERS
;
2315 strcpyW(userShellFolderPath
, DefaultW
);
2316 PathAddBackslashW(userShellFolderPath
);
2317 strcatW(userShellFolderPath
, szSHUserFolders
);
2318 pUserShellFolderPath
= userShellFolderPath
;
2319 strcpyW(shellFolderPath
, DefaultW
);
2320 PathAddBackslashW(shellFolderPath
);
2321 strcatW(shellFolderPath
, szSHFolders
);
2322 pShellFolderPath
= shellFolderPath
;
2327 hRootKey
= HKEY_CURRENT_USER
;
2328 pUserShellFolderPath
= szSHUserFolders
;
2329 pShellFolderPath
= szSHFolders
;
2332 hr
= _SHRegisterFolders(hRootKey
, hToken
, pUserShellFolderPath
,
2333 pShellFolderPath
, folders
, sizeof(folders
) / sizeof(folders
[0]));
2334 TRACE("returning 0x%08x\n", hr
);
2338 static HRESULT
_SHRegisterCommonShellFolders(void)
2340 static const UINT folders
[] = {
2341 CSIDL_COMMON_STARTMENU
,
2342 CSIDL_COMMON_PROGRAMS
,
2343 CSIDL_COMMON_STARTUP
,
2344 CSIDL_COMMON_DESKTOPDIRECTORY
,
2345 CSIDL_COMMON_FAVORITES
,
2346 CSIDL_COMMON_APPDATA
,
2347 CSIDL_COMMON_TEMPLATES
,
2348 CSIDL_COMMON_DOCUMENTS
,
2349 CSIDL_COMMON_ADMINTOOLS
,
2351 CSIDL_COMMON_PICTURES
,
2357 hr
= _SHRegisterFolders(HKEY_LOCAL_MACHINE
, NULL
, szSHUserFolders
,
2358 szSHFolders
, folders
, sizeof(folders
) / sizeof(folders
[0]));
2359 TRACE("returning 0x%08x\n", hr
);
2363 /* Register the default values in the registry, as some apps seem to depend
2364 * on their presence. The set registered was taken from Windows XP.
2366 HRESULT
SHELL_RegisterShellFolders(void)
2370 hr
= _SHRegisterUserShellFolders(TRUE
);
2372 hr
= _SHRegisterUserShellFolders(FALSE
);
2374 hr
= _SHRegisterCommonShellFolders();
2378 /*************************************************************************
2379 * SHGetSpecialFolderPathA [SHELL32.@]
2381 BOOL WINAPI
SHGetSpecialFolderPathA (
2387 return SHGetFolderPathA(hwndOwner
, nFolder
+ (bCreate
? CSIDL_FLAG_CREATE
: 0), NULL
, 0,
2391 /*************************************************************************
2392 * SHGetSpecialFolderPathW
2394 BOOL WINAPI
SHGetSpecialFolderPathW (
2400 return SHGetFolderPathW(hwndOwner
, nFolder
+ (bCreate
? CSIDL_FLAG_CREATE
: 0), NULL
, 0,
2404 /*************************************************************************
2405 * SHGetFolderLocation [SHELL32.@]
2407 * Gets the folder locations from the registry and creates a pidl.
2411 * nFolder [I] CSIDL_xxxxx
2412 * hToken [I] token representing user, or NULL for current user, or -1 for
2414 * dwReserved [I] must be zero
2415 * ppidl [O] PIDL of a special folder
2419 * Failure: Standard OLE-defined error result, S_FALSE or E_INVALIDARG
2422 * Creates missing reg keys and directories.
2423 * Mostly forwards to SHGetFolderPathW, but a few values of nFolder return
2424 * virtual folders that are handled here.
2426 HRESULT WINAPI
SHGetFolderLocation(
2431 LPITEMIDLIST
*ppidl
)
2433 HRESULT hr
= E_INVALIDARG
;
2435 TRACE("%p 0x%08x %p 0x%08x %p\n",
2436 hwndOwner
, nFolder
, hToken
, dwReserved
, ppidl
);
2439 return E_INVALIDARG
;
2441 return E_INVALIDARG
;
2443 /* The virtual folders' locations are not user-dependent */
2445 switch (nFolder
& CSIDL_FOLDER_MASK
)
2448 *ppidl
= _ILCreateDesktop();
2451 case CSIDL_PERSONAL
:
2452 *ppidl
= _ILCreateMyDocuments();
2455 case CSIDL_INTERNET
:
2456 *ppidl
= _ILCreateIExplore();
2459 case CSIDL_CONTROLS
:
2460 *ppidl
= _ILCreateControlPanel();
2463 case CSIDL_PRINTERS
:
2464 *ppidl
= _ILCreatePrinters();
2467 case CSIDL_BITBUCKET
:
2468 *ppidl
= _ILCreateBitBucket();
2472 *ppidl
= _ILCreateMyComputer();
2476 *ppidl
= _ILCreateNetwork();
2481 WCHAR szPath
[MAX_PATH
];
2483 hr
= SHGetFolderPathW(hwndOwner
, nFolder
, hToken
,
2484 SHGFP_TYPE_CURRENT
, szPath
);
2489 TRACE("Value=%s\n", debugstr_w(szPath
));
2490 hr
= SHILCreateFromPathW(szPath
, ppidl
, &attributes
);
2492 else if (hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
))
2494 /* unlike SHGetFolderPath, SHGetFolderLocation in shell32
2495 * version 6.0 returns E_FAIL for nonexistent paths
2504 TRACE("-- (new pidl %p)\n",*ppidl
);
2508 /*************************************************************************
2509 * SHGetSpecialFolderLocation [SHELL32.@]
2512 * In NT5, SHGetSpecialFolderLocation needs the <winntdir>/Recent
2515 HRESULT WINAPI
SHGetSpecialFolderLocation(
2518 LPITEMIDLIST
* ppidl
)
2520 HRESULT hr
= E_INVALIDARG
;
2522 TRACE("(%p,0x%x,%p)\n", hwndOwner
,nFolder
,ppidl
);
2525 return E_INVALIDARG
;
2527 hr
= SHGetFolderLocation(hwndOwner
, nFolder
, NULL
, 0, ppidl
);