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 * PathCombine [SHELL32.37]
50 LPVOID WINAPI
PathCombineAW(
55 if (SHELL_OsIsUnicode())
56 return PathCombineW( szDest
, lpszDir
, lpszFile
);
57 return PathCombineA( szDest
, lpszDir
, lpszFile
);
60 /*************************************************************************
61 * PathAddBackslash [SHELL32.32]
63 LPVOID WINAPI
PathAddBackslashAW(LPVOID lpszPath
)
65 if(SHELL_OsIsUnicode())
66 return PathAddBackslashW(lpszPath
);
67 return PathAddBackslashA(lpszPath
);
70 /*************************************************************************
71 * PathBuildRoot [SHELL32.30]
73 LPVOID WINAPI
PathBuildRootAW(LPVOID lpszPath
, int drive
)
75 if(SHELL_OsIsUnicode())
76 return PathBuildRootW(lpszPath
, drive
);
77 return PathBuildRootA(lpszPath
, drive
);
81 Extracting Component Parts
84 /*************************************************************************
85 * PathFindFileName [SHELL32.34]
87 LPVOID WINAPI
PathFindFileNameAW(LPCVOID lpszPath
)
89 if(SHELL_OsIsUnicode())
90 return PathFindFileNameW(lpszPath
);
91 return PathFindFileNameA(lpszPath
);
94 /*************************************************************************
95 * PathFindExtension [SHELL32.31]
97 LPVOID WINAPI
PathFindExtensionAW(LPCVOID lpszPath
)
99 if (SHELL_OsIsUnicode())
100 return PathFindExtensionW(lpszPath
);
101 return PathFindExtensionA(lpszPath
);
105 /*************************************************************************
106 * PathGetExtensionA [internal]
109 * exported by ordinal
110 * return value points to the first char after the dot
112 static LPSTR
PathGetExtensionA(LPCSTR lpszPath
)
114 TRACE("(%s)\n",lpszPath
);
116 lpszPath
= PathFindExtensionA(lpszPath
);
117 return (LPSTR
)(*lpszPath
?(lpszPath
+1):lpszPath
);
120 /*************************************************************************
121 * PathGetExtensionW [internal]
123 static LPWSTR
PathGetExtensionW(LPCWSTR lpszPath
)
125 TRACE("(%s)\n",debugstr_w(lpszPath
));
127 lpszPath
= PathFindExtensionW(lpszPath
);
128 return (LPWSTR
)(*lpszPath
?(lpszPath
+1):lpszPath
);
131 /*************************************************************************
132 * PathGetExtension [SHELL32.158]
134 LPVOID WINAPI
PathGetExtensionAW(LPCVOID lpszPath
,DWORD void1
, DWORD void2
)
136 if (SHELL_OsIsUnicode())
137 return PathGetExtensionW(lpszPath
);
138 return PathGetExtensionA(lpszPath
);
141 /*************************************************************************
142 * PathGetArgs [SHELL32.52]
144 LPVOID WINAPI
PathGetArgsAW(LPVOID lpszPath
)
146 if (SHELL_OsIsUnicode())
147 return PathGetArgsW(lpszPath
);
148 return PathGetArgsA(lpszPath
);
151 /*************************************************************************
152 * PathGetDriveNumber [SHELL32.57]
154 int WINAPI
PathGetDriveNumberAW(LPVOID lpszPath
)
156 if (SHELL_OsIsUnicode())
157 return PathGetDriveNumberW(lpszPath
);
158 return PathGetDriveNumberA(lpszPath
);
161 /*************************************************************************
162 * PathRemoveFileSpec [SHELL32.35]
164 BOOL WINAPI
PathRemoveFileSpecAW(LPVOID lpszPath
)
166 if (SHELL_OsIsUnicode())
167 return PathRemoveFileSpecW(lpszPath
);
168 return PathRemoveFileSpecA(lpszPath
);
171 /*************************************************************************
172 * PathStripPath [SHELL32.38]
174 void WINAPI
PathStripPathAW(LPVOID lpszPath
)
176 if (SHELL_OsIsUnicode())
177 PathStripPathW(lpszPath
);
179 PathStripPathA(lpszPath
);
182 /*************************************************************************
183 * PathStripToRoot [SHELL32.50]
185 BOOL WINAPI
PathStripToRootAW(LPVOID lpszPath
)
187 if (SHELL_OsIsUnicode())
188 return PathStripToRootW(lpszPath
);
189 return PathStripToRootA(lpszPath
);
192 /*************************************************************************
193 * PathRemoveArgs [SHELL32.251]
195 void WINAPI
PathRemoveArgsAW(LPVOID lpszPath
)
197 if (SHELL_OsIsUnicode())
198 PathRemoveArgsW(lpszPath
);
200 PathRemoveArgsA(lpszPath
);
203 /*************************************************************************
204 * PathRemoveExtension [SHELL32.250]
206 void WINAPI
PathRemoveExtensionAW(LPVOID lpszPath
)
208 if (SHELL_OsIsUnicode())
209 PathRemoveExtensionW(lpszPath
);
211 PathRemoveExtensionA(lpszPath
);
219 /*************************************************************************
220 * PathGetShortPathA [internal]
222 static void PathGetShortPathA(LPSTR pszPath
)
226 TRACE("%s\n", pszPath
);
228 if (GetShortPathNameA(pszPath
, path
, MAX_PATH
))
230 lstrcpyA(pszPath
, path
);
234 /*************************************************************************
235 * PathGetShortPathW [internal]
237 static void PathGetShortPathW(LPWSTR pszPath
)
239 WCHAR path
[MAX_PATH
];
241 TRACE("%s\n", debugstr_w(pszPath
));
243 if (GetShortPathNameW(pszPath
, path
, MAX_PATH
))
245 wcscpy(pszPath
, path
);
249 /*************************************************************************
250 * PathGetShortPath [SHELL32.92]
252 VOID WINAPI
PathGetShortPathAW(LPVOID pszPath
)
254 if(SHELL_OsIsUnicode())
255 PathGetShortPathW(pszPath
);
256 PathGetShortPathA(pszPath
);
259 /*************************************************************************
260 * PathRemoveBlanks [SHELL32.33]
262 void WINAPI
PathRemoveBlanksAW(LPVOID str
)
264 if(SHELL_OsIsUnicode())
265 PathRemoveBlanksW(str
);
267 PathRemoveBlanksA(str
);
270 /*************************************************************************
271 * PathQuoteSpaces [SHELL32.55]
273 VOID WINAPI
PathQuoteSpacesAW (LPVOID lpszPath
)
275 if(SHELL_OsIsUnicode())
276 PathQuoteSpacesW(lpszPath
);
278 PathQuoteSpacesA(lpszPath
);
281 /*************************************************************************
282 * PathUnquoteSpaces [SHELL32.56]
284 VOID WINAPI
PathUnquoteSpacesAW(LPVOID str
)
286 if(SHELL_OsIsUnicode())
287 PathUnquoteSpacesW(str
);
289 PathUnquoteSpacesA(str
);
292 /*************************************************************************
293 * PathParseIconLocation [SHELL32.249]
295 int WINAPI
PathParseIconLocationAW (LPVOID lpszPath
)
297 if(SHELL_OsIsUnicode())
298 return PathParseIconLocationW(lpszPath
);
299 return PathParseIconLocationA(lpszPath
);
303 ########## Path Testing ##########
305 /*************************************************************************
306 * PathIsUNC [SHELL32.39]
308 BOOL WINAPI
PathIsUNCAW (LPCVOID lpszPath
)
310 if (SHELL_OsIsUnicode())
311 return PathIsUNCW( lpszPath
);
312 return PathIsUNCA( lpszPath
);
315 /*************************************************************************
316 * PathIsRelative [SHELL32.40]
318 BOOL WINAPI
PathIsRelativeAW (LPCVOID lpszPath
)
320 if (SHELL_OsIsUnicode())
321 return PathIsRelativeW( lpszPath
);
322 return PathIsRelativeA( lpszPath
);
325 /*************************************************************************
326 * PathIsRoot [SHELL32.29]
328 BOOL WINAPI
PathIsRootAW(LPCVOID lpszPath
)
330 if (SHELL_OsIsUnicode())
331 return PathIsRootW(lpszPath
);
332 return PathIsRootA(lpszPath
);
335 /*************************************************************************
336 * PathIsExeA [internal]
338 static BOOL
PathIsExeA (LPCSTR lpszPath
)
340 LPCSTR lpszExtension
= PathGetExtensionA(lpszPath
);
342 static const char * const lpszExtensions
[] =
343 {"exe", "com", "pif", "cmd", "bat", "scf", "scr", NULL
};
345 TRACE("path=%s\n",lpszPath
);
347 for(i
=0; lpszExtensions
[i
]; i
++)
348 if (!lstrcmpiA(lpszExtension
,lpszExtensions
[i
])) return TRUE
;
353 /*************************************************************************
354 * PathIsExeW [internal]
356 static BOOL
PathIsExeW (LPCWSTR lpszPath
)
358 LPCWSTR lpszExtension
= PathGetExtensionW(lpszPath
);
360 static const WCHAR lpszExtensions
[][4] =
361 {{'e','x','e','\0'}, {'c','o','m','\0'}, {'p','i','f','\0'},
362 {'c','m','d','\0'}, {'b','a','t','\0'}, {'s','c','f','\0'},
363 {'s','c','r','\0'}, {'\0'} };
365 TRACE("path=%s\n",debugstr_w(lpszPath
));
367 for(i
=0; lpszExtensions
[i
][0]; i
++)
368 if (!strcmpiW(lpszExtension
,lpszExtensions
[i
])) return TRUE
;
373 /*************************************************************************
374 * PathIsExe [SHELL32.43]
376 BOOL WINAPI
PathIsExeAW (LPCVOID path
)
378 if (SHELL_OsIsUnicode())
379 return PathIsExeW (path
);
380 return PathIsExeA(path
);
383 /*************************************************************************
384 * PathIsDirectory [SHELL32.159]
386 BOOL WINAPI
PathIsDirectoryAW (LPCVOID lpszPath
)
388 if (SHELL_OsIsUnicode())
389 return PathIsDirectoryW (lpszPath
);
390 return PathIsDirectoryA (lpszPath
);
393 /*************************************************************************
394 * PathFileExists [SHELL32.45]
396 BOOL WINAPI
PathFileExistsAW (LPCVOID lpszPath
)
398 if (SHELL_OsIsUnicode())
399 return PathFileExistsW (lpszPath
);
400 return PathFileExistsA (lpszPath
);
403 /*************************************************************************
404 * PathMatchSpec [SHELL32.46]
406 BOOL WINAPI
PathMatchSpecAW(LPVOID name
, LPVOID mask
)
408 if (SHELL_OsIsUnicode())
409 return PathMatchSpecW( name
, mask
);
410 return PathMatchSpecA( name
, mask
);
413 /*************************************************************************
414 * PathIsSameRoot [SHELL32.650]
416 BOOL WINAPI
PathIsSameRootAW(LPCVOID lpszPath1
, LPCVOID lpszPath2
)
418 if (SHELL_OsIsUnicode())
419 return PathIsSameRootW(lpszPath1
, lpszPath2
);
420 return PathIsSameRootA(lpszPath1
, lpszPath2
);
423 /*************************************************************************
424 * IsLFNDriveA [SHELL32.41]
426 BOOL WINAPI
IsLFNDriveA(LPCSTR lpszPath
)
430 if (!GetVolumeInformationA(lpszPath
, NULL
, 0, NULL
, &fnlen
, NULL
, NULL
, 0))
435 /*************************************************************************
436 * IsLFNDriveW [SHELL32.42]
438 BOOL WINAPI
IsLFNDriveW(LPCWSTR lpszPath
)
442 if (!GetVolumeInformationW(lpszPath
, NULL
, 0, NULL
, &fnlen
, NULL
, NULL
, 0))
447 /*************************************************************************
448 * IsLFNDrive [SHELL32.119]
450 BOOL WINAPI
IsLFNDriveAW(LPCVOID lpszPath
)
452 if (SHELL_OsIsUnicode())
453 return IsLFNDriveW(lpszPath
);
454 return IsLFNDriveA(lpszPath
);
458 ########## Creating Something Unique ##########
460 /*************************************************************************
461 * PathMakeUniqueNameA [internal]
463 BOOL WINAPI
PathMakeUniqueNameA(
466 LPCSTR lpszShortName
,
470 FIXME("%p %u %s %s %s stub\n",
471 lpszBuffer
, dwBuffSize
, debugstr_a(lpszShortName
),
472 debugstr_a(lpszLongName
), debugstr_a(lpszPathName
));
476 /*************************************************************************
477 * PathMakeUniqueNameW [internal]
479 BOOL WINAPI
PathMakeUniqueNameW(
482 LPCWSTR lpszShortName
,
483 LPCWSTR lpszLongName
,
484 LPCWSTR lpszPathName
)
486 FIXME("%p %u %s %s %s stub\n",
487 lpszBuffer
, dwBuffSize
, debugstr_w(lpszShortName
),
488 debugstr_w(lpszLongName
), debugstr_w(lpszPathName
));
492 /*************************************************************************
493 * PathMakeUniqueName [SHELL32.47]
495 BOOL WINAPI
PathMakeUniqueNameAW(
498 LPCVOID lpszShortName
,
499 LPCVOID lpszLongName
,
500 LPCVOID lpszPathName
)
502 if (SHELL_OsIsUnicode())
503 return PathMakeUniqueNameW(lpszBuffer
,dwBuffSize
, lpszShortName
,lpszLongName
,lpszPathName
);
504 return PathMakeUniqueNameA(lpszBuffer
,dwBuffSize
, lpszShortName
,lpszLongName
,lpszPathName
);
507 /*************************************************************************
508 * PathYetAnotherMakeUniqueName [SHELL32.75]
511 * exported by ordinal
513 BOOL WINAPI
PathYetAnotherMakeUniqueName(
515 LPCWSTR lpszPathName
,
516 LPCWSTR lpszShortName
,
517 LPCWSTR lpszLongName
)
519 FIXME("(%p, %s, %s ,%s):stub.\n",
520 lpszBuffer
, debugstr_w(lpszPathName
), debugstr_w(lpszShortName
), debugstr_w(lpszLongName
));
526 ########## cleaning and resolving paths ##########
529 /*************************************************************************
530 * PathFindOnPath [SHELL32.145]
532 BOOL WINAPI
PathFindOnPathAW(LPVOID sFile
, LPCVOID
*sOtherDirs
)
534 if (SHELL_OsIsUnicode())
535 return PathFindOnPathW(sFile
, (LPCWSTR
*)sOtherDirs
);
536 return PathFindOnPathA(sFile
, (LPCSTR
*)sOtherDirs
);
539 /*************************************************************************
540 * PathCleanupSpec [SHELL32.171]
542 * lpszFile is changed in place.
544 int WINAPI
PathCleanupSpec( LPCWSTR lpszPathW
, LPWSTR lpszFileW
)
550 if (SHELL_OsIsUnicode())
552 LPWSTR p
= lpszFileW
;
554 TRACE("Cleanup %s\n",debugstr_w(lpszFileW
));
557 length
= wcslen(lpszPathW
);
561 int gct
= PathGetCharTypeW(*p
);
562 if (gct
== GCT_INVALID
|| gct
== GCT_WILD
|| gct
== GCT_SEPARATOR
)
565 rc
|= PCS_REPLACEDCHAR
;
571 if (length
+ i
== MAX_PATH
)
573 rc
|= PCS_FATAL
| PCS_PATHTOOLONG
;
581 LPSTR lpszFileA
= (LPSTR
)lpszFileW
;
582 LPCSTR lpszPathA
= (LPCSTR
)lpszPathW
;
585 TRACE("Cleanup %s\n",debugstr_a(lpszFileA
));
588 length
= strlen(lpszPathA
);
592 int gct
= PathGetCharTypeA(*p
);
593 if (gct
== GCT_INVALID
|| gct
== GCT_WILD
|| gct
== GCT_SEPARATOR
)
596 rc
|= PCS_REPLACEDCHAR
;
602 if (length
+ i
== MAX_PATH
)
604 rc
|= PCS_FATAL
| PCS_PATHTOOLONG
;
613 /*************************************************************************
614 * PathQualifyA [SHELL32]
616 BOOL WINAPI
PathQualifyA(LPCSTR pszPath
)
618 FIXME("%s\n",pszPath
);
622 /*************************************************************************
623 * PathQualifyW [SHELL32]
625 BOOL WINAPI
PathQualifyW(LPCWSTR pszPath
)
627 FIXME("%s\n",debugstr_w(pszPath
));
631 /*************************************************************************
632 * PathQualify [SHELL32.49]
634 BOOL WINAPI
PathQualifyAW(LPCVOID pszPath
)
636 if (SHELL_OsIsUnicode())
637 return PathQualifyW(pszPath
);
638 return PathQualifyA(pszPath
);
641 /*************************************************************************
642 * PathResolveA [SHELL32.51]
644 BOOL WINAPI
PathResolveA(
649 FIXME("(%s,%p,0x%08x),stub!\n",
650 lpszPath
, *alpszPaths
, dwFlags
);
654 /*************************************************************************
655 * PathResolveW [SHELL32]
657 BOOL WINAPI
PathResolveW(
662 FIXME("(%s,%p,0x%08x),stub!\n",
663 debugstr_w(lpszPath
), debugstr_w(*alpszPaths
), dwFlags
);
667 /*************************************************************************
668 * PathResolve [SHELL32.51]
670 BOOL WINAPI
PathResolveAW(
675 if (SHELL_OsIsUnicode())
676 return PathResolveW(lpszPath
, (LPCWSTR
*)alpszPaths
, dwFlags
);
677 return PathResolveA(lpszPath
, (LPCSTR
*)alpszPaths
, dwFlags
);
680 /*************************************************************************
681 * PathProcessCommandA [SHELL32.653]
683 LONG WINAPI
PathProcessCommandA (
689 FIXME("%s %p 0x%04x 0x%04x stub\n",
690 lpszPath
, lpszBuff
, dwBuffSize
, dwFlags
);
691 if(!lpszPath
) return -1;
692 if(lpszBuff
) strcpy(lpszBuff
, lpszPath
);
693 return strlen(lpszPath
);
696 /*************************************************************************
697 * PathProcessCommandW
699 LONG WINAPI
PathProcessCommandW (
705 FIXME("(%s, %p, 0x%04x, 0x%04x) stub\n",
706 debugstr_w(lpszPath
), lpszBuff
, dwBuffSize
, dwFlags
);
707 if(!lpszPath
) return -1;
708 if(lpszBuff
) wcscpy(lpszBuff
, lpszPath
);
709 return wcslen(lpszPath
);
712 /*************************************************************************
713 * PathProcessCommand (SHELL32.653)
715 LONG WINAPI
PathProcessCommandAW (
721 if (SHELL_OsIsUnicode())
722 return PathProcessCommandW(lpszPath
, lpszBuff
, dwBuffSize
, dwFlags
);
723 return PathProcessCommandA(lpszPath
, lpszBuff
, dwBuffSize
, dwFlags
);
727 ########## special ##########
730 /*************************************************************************
731 * PathSetDlgItemPath (SHELL32.48)
733 VOID WINAPI
PathSetDlgItemPathAW(HWND hDlg
, int id
, LPCVOID pszPath
)
735 if (SHELL_OsIsUnicode())
736 PathSetDlgItemPathW(hDlg
, id
, pszPath
);
738 PathSetDlgItemPathA(hDlg
, id
, pszPath
);
741 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'};
742 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'};
743 static const WCHAR AppDataW
[] = {'A','p','p','D','a','t','a','\0'};
744 static const WCHAR CacheW
[] = {'C','a','c','h','e','\0'};
745 static const WCHAR CD_BurningW
[] = {'C','D',' ','B','u','r','n','i','n','g','\0'};
746 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'};
747 static const WCHAR Common_AppDataW
[] = {'C','o','m','m','o','n',' ','A','p','p','D','a','t','a','\0'};
748 static const WCHAR Common_DesktopW
[] = {'C','o','m','m','o','n',' ','D','e','s','k','t','o','p','\0'};
749 static const WCHAR Common_DocumentsW
[] = {'C','o','m','m','o','n',' ','D','o','c','u','m','e','n','t','s','\0'};
750 static const WCHAR CommonFilesDirW
[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r','\0'};
751 static const WCHAR CommonMusicW
[] = {'C','o','m','m','o','n','M','u','s','i','c','\0'};
752 static const WCHAR CommonPicturesW
[] = {'C','o','m','m','o','n','P','i','c','t','u','r','e','s','\0'};
753 static const WCHAR Common_ProgramsW
[] = {'C','o','m','m','o','n',' ','P','r','o','g','r','a','m','s','\0'};
754 static const WCHAR Common_StartUpW
[] = {'C','o','m','m','o','n',' ','S','t','a','r','t','U','p','\0'};
755 static const WCHAR Common_Start_MenuW
[] = {'C','o','m','m','o','n',' ','S','t','a','r','t',' ','M','e','n','u','\0'};
756 static const WCHAR Common_TemplatesW
[] = {'C','o','m','m','o','n',' ','T','e','m','p','l','a','t','e','s','\0'};
757 static const WCHAR CommonVideoW
[] = {'C','o','m','m','o','n','V','i','d','e','o','\0'};
758 static const WCHAR CookiesW
[] = {'C','o','o','k','i','e','s','\0'};
759 static const WCHAR DesktopW
[] = {'D','e','s','k','t','o','p','\0'};
760 static const WCHAR FavoritesW
[] = {'F','a','v','o','r','i','t','e','s','\0'};
761 static const WCHAR FontsW
[] = {'F','o','n','t','s','\0'};
762 static const WCHAR HistoryW
[] = {'H','i','s','t','o','r','y','\0'};
763 static const WCHAR Local_AppDataW
[] = {'L','o','c','a','l',' ','A','p','p','D','a','t','a','\0'};
764 static const WCHAR My_MusicW
[] = {'M','y',' ','M','u','s','i','c','\0'};
765 static const WCHAR My_PicturesW
[] = {'M','y',' ','P','i','c','t','u','r','e','s','\0'};
766 static const WCHAR My_VideoW
[] = {'M','y',' ','V','i','d','e','o','\0'};
767 static const WCHAR NetHoodW
[] = {'N','e','t','H','o','o','d','\0'};
768 static const WCHAR PersonalW
[] = {'P','e','r','s','o','n','a','l','\0'};
769 static const WCHAR PrintHoodW
[] = {'P','r','i','n','t','H','o','o','d','\0'};
770 static const WCHAR ProgramFilesDirW
[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r','\0'};
771 static const WCHAR ProgramsW
[] = {'P','r','o','g','r','a','m','s','\0'};
772 static const WCHAR RecentW
[] = {'R','e','c','e','n','t','\0'};
773 static const WCHAR ResourcesW
[] = {'R','e','s','o','u','r','c','e','s','\0'};
774 static const WCHAR SendToW
[] = {'S','e','n','d','T','o','\0'};
775 static const WCHAR StartUpW
[] = {'S','t','a','r','t','U','p','\0'};
776 static const WCHAR Start_MenuW
[] = {'S','t','a','r','t',' ','M','e','n','u','\0'};
777 static const WCHAR TemplatesW
[] = {'T','e','m','p','l','a','t','e','s','\0'};
778 static const WCHAR DefaultW
[] = {'.','D','e','f','a','u','l','t','\0'};
779 static const WCHAR AllUsersProfileW
[] = {'%','A','L','L','U','S','E','R','S','P','R','O','F','I','L','E','%','\0'};
780 static const WCHAR UserProfileW
[] = {'%','U','S','E','R','P','R','O','F','I','L','E','%','\0'};
781 static const WCHAR SystemDriveW
[] = {'%','S','y','s','t','e','m','D','r','i','v','e','%','\0'};
782 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};
783 static const WCHAR ProfilesDirectoryW
[] = {'P','r','o','f','i','l','e','s','D','i','r','e','c','t','o','r','y',0};
784 static const WCHAR AllUsersProfileValueW
[] = {'A','l','l','U','s','e','r','s','P','r','o','f','i','l','e','\0'};
785 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'};
786 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'};
787 /* This defaults to L"Documents and Settings" on Windows 2000/XP, but we're
788 * acting more Windows 9x-like for now.
790 static const WCHAR szDefaultProfileDirW
[] = {'p','r','o','f','i','l','e','s','\0'};
791 static const WCHAR AllUsersW
[] = {'A','l','l',' ','U','s','e','r','s','\0'};
793 typedef enum _CSIDL_Type
{
797 CSIDL_Type_Disallowed
,
798 CSIDL_Type_NonExistent
,
799 CSIDL_Type_WindowsPath
,
800 CSIDL_Type_SystemPath
,
807 LPCWSTR szDefaultPath
; /* fallback string or resource ID */
810 static const CSIDL_DATA CSIDL_Data
[] =
812 { /* 0x00 - CSIDL_DESKTOP */
815 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY
)
817 { /* 0x01 - CSIDL_INTERNET */
818 CSIDL_Type_Disallowed
,
822 { /* 0x02 - CSIDL_PROGRAMS */
825 MAKEINTRESOURCEW(IDS_PROGRAMS
)
827 { /* 0x03 - CSIDL_CONTROLS (.CPL files) */
828 CSIDL_Type_SystemPath
,
832 { /* 0x04 - CSIDL_PRINTERS */
833 CSIDL_Type_SystemPath
,
837 { /* 0x05 - CSIDL_PERSONAL */
840 MAKEINTRESOURCEW(IDS_PERSONAL
)
842 { /* 0x06 - CSIDL_FAVORITES */
845 MAKEINTRESOURCEW(IDS_FAVORITES
)
847 { /* 0x07 - CSIDL_STARTUP */
850 MAKEINTRESOURCEW(IDS_STARTUP
)
852 { /* 0x08 - CSIDL_RECENT */
855 MAKEINTRESOURCEW(IDS_RECENT
)
857 { /* 0x09 - CSIDL_SENDTO */
860 MAKEINTRESOURCEW(IDS_SENDTO
)
862 { /* 0x0a - CSIDL_BITBUCKET - Recycle Bin */
863 CSIDL_Type_Disallowed
,
867 { /* 0x0b - CSIDL_STARTMENU */
870 MAKEINTRESOURCEW(IDS_STARTMENU
)
872 { /* 0x0c - CSIDL_MYDOCUMENTS */
873 CSIDL_Type_Disallowed
, /* matches WinXP--can't get its path */
877 { /* 0x0d - CSIDL_MYMUSIC */
880 MAKEINTRESOURCEW(IDS_MYMUSIC
)
882 { /* 0x0e - CSIDL_MYVIDEO */
885 MAKEINTRESOURCEW(IDS_MYVIDEO
)
887 { /* 0x0f - unassigned */
888 CSIDL_Type_Disallowed
,
892 { /* 0x10 - CSIDL_DESKTOPDIRECTORY */
895 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY
)
897 { /* 0x11 - CSIDL_DRIVES */
898 CSIDL_Type_Disallowed
,
902 { /* 0x12 - CSIDL_NETWORK */
903 CSIDL_Type_Disallowed
,
907 { /* 0x13 - CSIDL_NETHOOD */
910 MAKEINTRESOURCEW(IDS_NETHOOD
)
912 { /* 0x14 - CSIDL_FONTS */
913 CSIDL_Type_WindowsPath
,
917 { /* 0x15 - CSIDL_TEMPLATES */
920 MAKEINTRESOURCEW(IDS_TEMPLATES
)
922 { /* 0x16 - CSIDL_COMMON_STARTMENU */
925 MAKEINTRESOURCEW(IDS_STARTMENU
)
927 { /* 0x17 - CSIDL_COMMON_PROGRAMS */
930 MAKEINTRESOURCEW(IDS_PROGRAMS
)
932 { /* 0x18 - CSIDL_COMMON_STARTUP */
935 MAKEINTRESOURCEW(IDS_STARTUP
)
937 { /* 0x19 - CSIDL_COMMON_DESKTOPDIRECTORY */
940 MAKEINTRESOURCEW(IDS_DESKTOP
)
942 { /* 0x1a - CSIDL_APPDATA */
945 MAKEINTRESOURCEW(IDS_APPDATA
)
947 { /* 0x1b - CSIDL_PRINTHOOD */
950 MAKEINTRESOURCEW(IDS_PRINTHOOD
)
952 { /* 0x1c - CSIDL_LOCAL_APPDATA */
955 MAKEINTRESOURCEW(IDS_LOCAL_APPDATA
)
957 { /* 0x1d - CSIDL_ALTSTARTUP */
958 CSIDL_Type_NonExistent
,
962 { /* 0x1e - CSIDL_COMMON_ALTSTARTUP */
963 CSIDL_Type_NonExistent
,
967 { /* 0x1f - CSIDL_COMMON_FAVORITES */
970 MAKEINTRESOURCEW(IDS_FAVORITES
)
972 { /* 0x20 - CSIDL_INTERNET_CACHE */
975 MAKEINTRESOURCEW(IDS_INTERNET_CACHE
)
977 { /* 0x21 - CSIDL_COOKIES */
980 MAKEINTRESOURCEW(IDS_COOKIES
)
982 { /* 0x22 - CSIDL_HISTORY */
985 MAKEINTRESOURCEW(IDS_HISTORY
)
987 { /* 0x23 - CSIDL_COMMON_APPDATA */
990 MAKEINTRESOURCEW(IDS_APPDATA
)
992 { /* 0x24 - CSIDL_WINDOWS */
993 CSIDL_Type_WindowsPath
,
997 { /* 0x25 - CSIDL_SYSTEM */
998 CSIDL_Type_SystemPath
,
1002 { /* 0x26 - CSIDL_PROGRAM_FILES */
1005 MAKEINTRESOURCEW(IDS_PROGRAM_FILES
)
1007 { /* 0x27 - CSIDL_MYPICTURES */
1010 MAKEINTRESOURCEW(IDS_MYPICTURES
)
1012 { /* 0x28 - CSIDL_PROFILE */
1017 { /* 0x29 - CSIDL_SYSTEMX86 */
1018 CSIDL_Type_NonExistent
,
1022 { /* 0x2a - CSIDL_PROGRAM_FILESX86 */
1023 CSIDL_Type_NonExistent
,
1027 { /* 0x2b - CSIDL_PROGRAM_FILES_COMMON */
1030 MAKEINTRESOURCEW(IDS_PROGRAM_FILES_COMMON
)
1032 { /* 0x2c - CSIDL_PROGRAM_FILES_COMMONX86 */
1033 CSIDL_Type_NonExistent
,
1037 { /* 0x2d - CSIDL_COMMON_TEMPLATES */
1038 CSIDL_Type_AllUsers
,
1040 MAKEINTRESOURCEW(IDS_TEMPLATES
)
1042 { /* 0x2e - CSIDL_COMMON_DOCUMENTS */
1043 CSIDL_Type_AllUsers
,
1045 MAKEINTRESOURCEW(IDS_COMMON_DOCUMENTS
)
1047 { /* 0x2f - CSIDL_COMMON_ADMINTOOLS */
1048 CSIDL_Type_AllUsers
,
1049 Common_Administrative_ToolsW
,
1050 MAKEINTRESOURCEW(IDS_ADMINTOOLS
)
1052 { /* 0x30 - CSIDL_ADMINTOOLS */
1054 Administrative_ToolsW
,
1055 MAKEINTRESOURCEW(IDS_ADMINTOOLS
)
1057 { /* 0x31 - CSIDL_CONNECTIONS */
1058 CSIDL_Type_Disallowed
,
1062 { /* 0x32 - unassigned */
1063 CSIDL_Type_Disallowed
,
1067 { /* 0x33 - unassigned */
1068 CSIDL_Type_Disallowed
,
1072 { /* 0x34 - unassigned */
1073 CSIDL_Type_Disallowed
,
1077 { /* 0x35 - CSIDL_COMMON_MUSIC */
1078 CSIDL_Type_AllUsers
,
1080 MAKEINTRESOURCEW(IDS_COMMON_MUSIC
)
1082 { /* 0x36 - CSIDL_COMMON_PICTURES */
1083 CSIDL_Type_AllUsers
,
1085 MAKEINTRESOURCEW(IDS_COMMON_PICTURES
)
1087 { /* 0x37 - CSIDL_COMMON_VIDEO */
1088 CSIDL_Type_AllUsers
,
1090 MAKEINTRESOURCEW(IDS_COMMON_VIDEO
)
1092 { /* 0x38 - CSIDL_RESOURCES */
1093 CSIDL_Type_WindowsPath
,
1097 { /* 0x39 - CSIDL_RESOURCES_LOCALIZED */
1098 CSIDL_Type_NonExistent
,
1102 { /* 0x3a - CSIDL_COMMON_OEM_LINKS */
1103 CSIDL_Type_NonExistent
,
1107 { /* 0x3b - CSIDL_CDBURN_AREA */
1110 MAKEINTRESOURCEW(IDS_CDBURN_AREA
)
1112 { /* 0x3c unassigned */
1113 CSIDL_Type_Disallowed
,
1117 { /* 0x3d - CSIDL_COMPUTERSNEARME */
1118 CSIDL_Type_Disallowed
, /* FIXME */
1122 { /* 0x3e - CSIDL_PROFILES */
1123 CSIDL_Type_Disallowed
, /* oddly, this matches WinXP */
1129 static HRESULT
_SHExpandEnvironmentStrings(LPCWSTR szSrc
, LPWSTR szDest
);
1131 /* Gets the value named value from the registry key
1132 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
1133 * (or from rootKey\userPrefix\... if userPrefix is not NULL) into path, which
1134 * is assumed to be MAX_PATH WCHARs in length.
1135 * If it exists, expands the value and writes the expanded value to
1136 * rootKey\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
1137 * Returns successful error code if the value was retrieved from the registry,
1138 * and a failure otherwise.
1140 static HRESULT
_SHGetUserShellFolderPath(HKEY rootKey
, LPCWSTR userPrefix
,
1141 LPCWSTR value
, LPWSTR path
)
1144 WCHAR shellFolderPath
[MAX_PATH
], userShellFolderPath
[MAX_PATH
];
1145 LPCWSTR pShellFolderPath
, pUserShellFolderPath
;
1146 DWORD dwDisp
, dwType
, dwPathLen
= MAX_PATH
;
1147 HKEY userShellFolderKey
, shellFolderKey
;
1149 TRACE("%p,%s,%s,%p\n",rootKey
, debugstr_w(userPrefix
), debugstr_w(value
),
1154 wcscpy(shellFolderPath
, userPrefix
);
1155 PathAddBackslashW(shellFolderPath
);
1156 wcscat(shellFolderPath
, szSHFolders
);
1157 pShellFolderPath
= shellFolderPath
;
1158 wcscpy(userShellFolderPath
, userPrefix
);
1159 PathAddBackslashW(userShellFolderPath
);
1160 wcscat(userShellFolderPath
, szSHUserFolders
);
1161 pUserShellFolderPath
= userShellFolderPath
;
1165 pUserShellFolderPath
= szSHUserFolders
;
1166 pShellFolderPath
= szSHFolders
;
1169 if (RegCreateKeyExW(rootKey
, pShellFolderPath
, 0, NULL
, 0, KEY_ALL_ACCESS
,
1170 NULL
, &shellFolderKey
, &dwDisp
))
1172 TRACE("Failed to create %s\n", debugstr_w(pShellFolderPath
));
1175 if (RegCreateKeyExW(rootKey
, pUserShellFolderPath
, 0, NULL
, 0,
1176 KEY_ALL_ACCESS
, NULL
, &userShellFolderKey
, &dwDisp
))
1178 TRACE("Failed to create %s\n",
1179 debugstr_w(pUserShellFolderPath
));
1180 RegCloseKey(shellFolderKey
);
1184 if (!RegQueryValueExW(userShellFolderKey
, value
, NULL
, &dwType
,
1185 (LPBYTE
)path
, &dwPathLen
) && (dwType
== REG_EXPAND_SZ
|| dwType
== REG_SZ
))
1189 path
[dwPathLen
/ sizeof(WCHAR
)] = '\0';
1190 if (dwType
== REG_EXPAND_SZ
&& path
[0] == '%')
1192 WCHAR szTemp
[MAX_PATH
];
1194 _SHExpandEnvironmentStrings(path
, szTemp
);
1195 lstrcpynW(path
, szTemp
, MAX_PATH
);
1197 ret
= RegSetValueExW(shellFolderKey
, value
, 0, REG_SZ
, (LPBYTE
)path
,
1198 (wcslen(path
) + 1) * sizeof(WCHAR
));
1199 if (ret
!= ERROR_SUCCESS
)
1200 hr
= HRESULT_FROM_WIN32(ret
);
1206 RegCloseKey(shellFolderKey
);
1207 RegCloseKey(userShellFolderKey
);
1208 TRACE("returning 0x%08x\n", hr
);
1212 /* Gets a 'semi-expanded' default value of the CSIDL with index folder into
1213 * pszPath, based on the entries in CSIDL_Data. By semi-expanded, I mean:
1214 * - The entry's szDefaultPath may be either a string value or an integer
1215 * resource identifier. In the latter case, the string value of the resource
1217 * - Depending on the entry's type, the path may begin with an (unexpanded)
1218 * environment variable name. The caller is responsible for expanding
1219 * environment strings if so desired.
1220 * The types that are prepended with environment variables are:
1221 * CSIDL_Type_User: %USERPROFILE%
1222 * CSIDL_Type_AllUsers: %ALLUSERSPROFILE%
1223 * CSIDL_Type_CurrVer: %SystemDrive%
1224 * (Others might make sense too, but as yet are unneeded.)
1226 static HRESULT
_SHGetDefaultValue(BYTE folder
, LPWSTR pszPath
)
1229 WCHAR resourcePath
[MAX_PATH
];
1230 LPCWSTR pDefaultPath
= NULL
;
1232 TRACE("0x%02x,%p\n", folder
, pszPath
);
1234 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1235 return E_INVALIDARG
;
1237 return E_INVALIDARG
;
1239 if (CSIDL_Data
[folder
].szDefaultPath
&&
1240 IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
))
1242 if (LoadStringW(shell32_hInstance
,
1243 LOWORD(CSIDL_Data
[folder
].szDefaultPath
), resourcePath
, MAX_PATH
))
1246 pDefaultPath
= resourcePath
;
1250 FIXME("(%d,%s), LoadString failed, missing translation?\n", folder
,
1251 debugstr_w(pszPath
));
1258 pDefaultPath
= CSIDL_Data
[folder
].szDefaultPath
;
1262 switch (CSIDL_Data
[folder
].type
)
1264 case CSIDL_Type_User
:
1265 wcscpy(pszPath
, UserProfileW
);
1267 case CSIDL_Type_AllUsers
:
1268 wcscpy(pszPath
, AllUsersProfileW
);
1270 case CSIDL_Type_CurrVer
:
1271 wcscpy(pszPath
, SystemDriveW
);
1274 ; /* no corresponding env. var, do nothing */
1278 PathAddBackslashW(pszPath
);
1279 wcscat(pszPath
, pDefaultPath
);
1282 TRACE("returning 0x%08x\n", hr
);
1286 /* Gets the (unexpanded) value of the folder with index folder into pszPath.
1287 * The folder's type is assumed to be CSIDL_Type_CurrVer. Its default value
1288 * can be overridden in the HKLM\\szCurrentVersion key.
1289 * If dwFlags has SHGFP_TYPE_DEFAULT set or if the value isn't overridden in
1290 * the registry, uses _SHGetDefaultValue to get the value.
1292 static HRESULT
_SHGetCurrentVersionPath(DWORD dwFlags
, BYTE folder
,
1297 TRACE("0x%08x,0x%02x,%p\n", dwFlags
, folder
, pszPath
);
1299 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1300 return E_INVALIDARG
;
1301 if (CSIDL_Data
[folder
].type
!= CSIDL_Type_CurrVer
)
1302 return E_INVALIDARG
;
1304 return E_INVALIDARG
;
1306 if (dwFlags
& SHGFP_TYPE_DEFAULT
)
1307 hr
= _SHGetDefaultValue(folder
, pszPath
);
1313 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE
, szCurrentVersion
, 0,
1314 NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hKey
, &dwDisp
))
1318 DWORD dwType
, dwPathLen
= MAX_PATH
* sizeof(WCHAR
);
1320 if (RegQueryValueExW(hKey
, CSIDL_Data
[folder
].szValueName
, NULL
,
1321 &dwType
, (LPBYTE
)pszPath
, &dwPathLen
) ||
1322 (dwType
!= REG_SZ
&& dwType
!= REG_EXPAND_SZ
))
1324 hr
= _SHGetDefaultValue(folder
, pszPath
);
1325 dwType
= REG_EXPAND_SZ
;
1326 RegSetValueExW(hKey
, CSIDL_Data
[folder
].szValueName
, 0, dwType
,
1327 (LPBYTE
)pszPath
, (wcslen(pszPath
)+1)*sizeof(WCHAR
));
1331 pszPath
[dwPathLen
/ sizeof(WCHAR
)] = '\0';
1337 TRACE("returning 0x%08x (output path is %s)\n", hr
, debugstr_w(pszPath
));
1341 /* Gets the user's path (unexpanded) for the CSIDL with index folder:
1342 * If SHGFP_TYPE_DEFAULT is set, calls _SHGetDefaultValue for it. Otherwise
1343 * calls _SHGetUserShellFolderPath for it. Where it looks depends on hToken:
1344 * - if hToken is -1, looks in HKEY_USERS\.Default
1345 * - otherwise looks first in HKEY_CURRENT_USER, followed by HKEY_LOCAL_MACHINE
1346 * if HKEY_CURRENT_USER doesn't contain any entries. If both fail, finally
1347 * calls _SHGetDefaultValue for it.
1349 static HRESULT
_SHGetUserProfilePath(HANDLE hToken
, DWORD dwFlags
, BYTE folder
,
1354 TRACE("%p,0x%08x,0x%02x,%p\n", hToken
, dwFlags
, folder
, pszPath
);
1356 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1357 return E_INVALIDARG
;
1358 if (CSIDL_Data
[folder
].type
!= CSIDL_Type_User
)
1359 return E_INVALIDARG
;
1361 return E_INVALIDARG
;
1363 /* Only the current user and the default user are supported right now
1365 * FIXME: should be able to call GetTokenInformation on the token,
1366 * then call ConvertSidToStringSidW on it to get the user prefix.
1367 * But Wine's registry doesn't store user info by sid, it stores it
1368 * by user name (and I don't know how to convert from a token to a
1371 if (hToken
!= NULL
&& hToken
!= (HANDLE
)-1)
1373 FIXME("unsupported for user other than current or default\n");
1377 if (dwFlags
& SHGFP_TYPE_DEFAULT
)
1378 hr
= _SHGetDefaultValue(folder
, pszPath
);
1381 LPCWSTR userPrefix
= NULL
;
1384 if (hToken
== (HANDLE
)-1)
1386 hRootKey
= HKEY_USERS
;
1387 userPrefix
= DefaultW
;
1389 else /* hToken == NULL, other values disallowed above */
1390 hRootKey
= HKEY_CURRENT_USER
;
1391 hr
= _SHGetUserShellFolderPath(hRootKey
, userPrefix
,
1392 CSIDL_Data
[folder
].szValueName
, pszPath
);
1393 if (FAILED(hr
) && hRootKey
!= HKEY_LOCAL_MACHINE
)
1394 hr
= _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE
, NULL
,
1395 CSIDL_Data
[folder
].szValueName
, pszPath
);
1397 hr
= _SHGetDefaultValue(folder
, pszPath
);
1399 TRACE("returning 0x%08x (output path is %s)\n", hr
, debugstr_w(pszPath
));
1403 /* Gets the (unexpanded) path for the CSIDL with index folder. If dwFlags has
1404 * SHGFP_TYPE_DEFAULT set, calls _SHGetDefaultValue. Otherwise calls
1405 * _SHGetUserShellFolderPath for it, looking only in HKEY_LOCAL_MACHINE.
1406 * If this fails, falls back to _SHGetDefaultValue.
1408 static HRESULT
_SHGetAllUsersProfilePath(DWORD dwFlags
, BYTE folder
,
1413 TRACE("0x%08x,0x%02x,%p\n", dwFlags
, folder
, pszPath
);
1415 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1416 return E_INVALIDARG
;
1417 if (CSIDL_Data
[folder
].type
!= CSIDL_Type_AllUsers
)
1418 return E_INVALIDARG
;
1420 return E_INVALIDARG
;
1422 if (dwFlags
& SHGFP_TYPE_DEFAULT
)
1423 hr
= _SHGetDefaultValue(folder
, pszPath
);
1426 hr
= _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE
, NULL
,
1427 CSIDL_Data
[folder
].szValueName
, pszPath
);
1429 hr
= _SHGetDefaultValue(folder
, pszPath
);
1431 TRACE("returning 0x%08x (output path is %s)\n", hr
, debugstr_w(pszPath
));
1435 static HRESULT
_SHOpenProfilesKey(PHKEY pKey
)
1440 lRet
= RegCreateKeyExW(HKEY_LOCAL_MACHINE
, ProfileListW
, 0, NULL
, 0,
1441 KEY_ALL_ACCESS
, NULL
, pKey
, &disp
);
1442 return HRESULT_FROM_WIN32(lRet
);
1445 /* Reads the value named szValueName from the key profilesKey (assumed to be
1446 * opened by _SHOpenProfilesKey) into szValue, which is assumed to be MAX_PATH
1447 * WCHARs in length. If it doesn't exist, returns szDefault (and saves
1448 * szDefault to the registry).
1450 static HRESULT
_SHGetProfilesValue(HKEY profilesKey
, LPCWSTR szValueName
,
1451 LPWSTR szValue
, LPCWSTR szDefault
)
1454 DWORD type
, dwPathLen
= MAX_PATH
* sizeof(WCHAR
);
1457 TRACE("%p,%s,%p,%s\n", profilesKey
, debugstr_w(szValueName
), szValue
,
1458 debugstr_w(szDefault
));
1459 lRet
= RegQueryValueExW(profilesKey
, szValueName
, NULL
, &type
,
1460 (LPBYTE
)szValue
, &dwPathLen
);
1461 if (!lRet
&& (type
== REG_SZ
|| type
== REG_EXPAND_SZ
) && dwPathLen
1464 dwPathLen
/= sizeof(WCHAR
);
1465 szValue
[dwPathLen
] = '\0';
1470 /* Missing or invalid value, set a default */
1471 lstrcpynW(szValue
, szDefault
, MAX_PATH
);
1472 TRACE("Setting missing value %s to %s\n", debugstr_w(szValueName
),
1473 debugstr_w(szValue
));
1474 lRet
= RegSetValueExW(profilesKey
, szValueName
, 0, REG_EXPAND_SZ
,
1476 (wcslen(szValue
) + 1) * sizeof(WCHAR
));
1478 hr
= HRESULT_FROM_WIN32(lRet
);
1482 TRACE("returning 0x%08x (output value is %s)\n", hr
, debugstr_w(szValue
));
1486 /* Attempts to expand environment variables from szSrc into szDest, which is
1487 * assumed to be MAX_PATH characters in length. Before referring to the
1488 * environment, handles a few variables directly, because the environment
1489 * variables may not be set when this is called (as during Wine's installation
1490 * when default values are being written to the registry).
1491 * The directly handled environment variables, and their source, are:
1492 * - ALLUSERSPROFILE, USERPROFILE: reads from the registry
1493 * - SystemDrive: uses GetSystemDirectoryW and uses the drive portion of its
1495 * If one of the directly handled environment variables is expanded, only
1496 * expands a single variable, and only in the beginning of szSrc.
1498 static HRESULT
_SHExpandEnvironmentStrings(LPCWSTR szSrc
, LPWSTR szDest
)
1501 WCHAR szTemp
[MAX_PATH
], szProfilesPrefix
[MAX_PATH
] = { 0 };
1504 TRACE("%s, %p\n", debugstr_w(szSrc
), szDest
);
1506 if (!szSrc
|| !szDest
) return E_INVALIDARG
;
1508 /* short-circuit if there's nothing to expand */
1509 if (szSrc
[0] != '%')
1511 wcscpy(szDest
, szSrc
);
1515 /* Get the profile prefix, we'll probably be needing it */
1516 hr
= _SHOpenProfilesKey(&key
);
1519 WCHAR szDefaultProfilesPrefix
[MAX_PATH
];
1521 GetWindowsDirectoryW(szDefaultProfilesPrefix
, MAX_PATH
);
1522 PathAddBackslashW(szDefaultProfilesPrefix
);
1523 PathAppendW(szDefaultProfilesPrefix
, szDefaultProfileDirW
);
1524 hr
= _SHGetProfilesValue(key
, ProfilesDirectoryW
, szProfilesPrefix
,
1525 szDefaultProfilesPrefix
);
1529 wcscpy(szTemp
, szSrc
);
1530 while (SUCCEEDED(hr
) && szTemp
[0] == '%')
1532 if (!strncmpiW(szTemp
, AllUsersProfileW
, wcslen(AllUsersProfileW
)))
1534 WCHAR szAllUsers
[MAX_PATH
];
1536 wcscpy(szDest
, szProfilesPrefix
);
1537 hr
= _SHGetProfilesValue(key
, AllUsersProfileValueW
,
1538 szAllUsers
, AllUsersW
);
1539 PathAppendW(szDest
, szAllUsers
);
1540 PathAppendW(szDest
, szTemp
+ wcslen(AllUsersProfileW
));
1542 else if (!strncmpiW(szTemp
, UserProfileW
, wcslen(UserProfileW
)))
1544 WCHAR userName
[MAX_PATH
];
1545 DWORD userLen
= MAX_PATH
;
1547 wcscpy(szDest
, szProfilesPrefix
);
1548 GetUserNameW(userName
, &userLen
);
1549 PathAppendW(szDest
, userName
);
1550 PathAppendW(szDest
, szTemp
+ wcslen(UserProfileW
));
1552 else if (!strncmpiW(szTemp
, SystemDriveW
, wcslen(SystemDriveW
)))
1554 GetSystemDirectoryW(szDest
, MAX_PATH
);
1555 if (szDest
[1] != ':')
1557 FIXME("non-drive system paths unsupported\n");
1562 wcscpy(szDest
+ 3, szTemp
+ wcslen(SystemDriveW
) + 1);
1568 DWORD ret
= ExpandEnvironmentStringsW(szSrc
, szDest
, MAX_PATH
);
1571 hr
= HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER
);
1573 hr
= HRESULT_FROM_WIN32(GetLastError());
1577 if (SUCCEEDED(hr
) && szDest
[0] == '%')
1578 wcscpy(szTemp
, szDest
);
1581 /* terminate loop */
1588 TRACE("returning 0x%08x (input was %s, output is %s)\n", hr
,
1589 debugstr_w(szSrc
), debugstr_w(szDest
));
1593 /*************************************************************************
1594 * SHGetFolderPathW [SHELL32.@]
1596 * Convert nFolder to path.
1600 * Failure: standard HRESULT error codes.
1603 * Most values can be overridden in either
1604 * HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
1605 * or in the same location in HKLM.
1606 * The "Shell Folders" registry key was used in NT4 and earlier systems.
1607 * Beginning with Windows 2000, the "User Shell Folders" key is used, so
1608 * changes made to it are made to the former key too. This synchronization is
1609 * done on-demand: not until someone requests the value of one of these paths
1610 * (by calling one of the SHGet functions) is the value synchronized.
1611 * Furthermore, the HKCU paths take precedence over the HKLM paths.
1613 HRESULT WINAPI
SHGetFolderPathW(
1614 HWND hwndOwner
, /* [I] owner window */
1615 int nFolder
, /* [I] CSIDL identifying the folder */
1616 HANDLE hToken
, /* [I] access token */
1617 DWORD dwFlags
, /* [I] which path to return */
1618 LPWSTR pszPath
) /* [O] converted path */
1620 HRESULT hr
= SHGetFolderPathAndSubDirW(hwndOwner
, nFolder
, hToken
, dwFlags
, NULL
, pszPath
);
1621 if(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
) == hr
)
1622 hr
= HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
);
1626 HRESULT WINAPI
SHGetFolderPathAndSubDirA(
1627 HWND hwndOwner
, /* [I] owner window */
1628 int nFolder
, /* [I] CSIDL identifying the folder */
1629 HANDLE hToken
, /* [I] access token */
1630 DWORD dwFlags
, /* [I] which path to return */
1631 LPCSTR pszSubPath
, /* [I] sub directory of the specified folder */
1632 LPSTR pszPath
) /* [O] converted path */
1636 LPWSTR pszSubPathW
= NULL
;
1637 LPWSTR pszPathW
= NULL
;
1638 TRACE("%08x,%08x,%s\n",nFolder
, dwFlags
, debugstr_w(pszSubPathW
));
1641 pszPathW
= HeapAlloc(GetProcessHeap(), 0, MAX_PATH
* sizeof(WCHAR
));
1643 hr
= HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY
);
1647 TRACE("%08x,%08x,%s\n",nFolder
, dwFlags
, debugstr_w(pszSubPathW
));
1649 /* SHGetFolderPathAndSubDirW does not distinguish if pszSubPath isn't
1650 * set (null), or an empty string.therefore call it without the parameter set
1651 * if pszSubPath is an empty string
1653 if (pszSubPath
&& pszSubPath
[0]) {
1654 length
= MultiByteToWideChar(CP_ACP
, 0, pszSubPath
, -1, NULL
, 0);
1655 pszSubPathW
= HeapAlloc(GetProcessHeap(), 0, length
* sizeof(WCHAR
));
1657 hr
= HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY
);
1660 MultiByteToWideChar(CP_ACP
, 0, pszSubPath
, -1, pszSubPathW
, length
);
1663 hr
= SHGetFolderPathAndSubDirW(hwndOwner
, nFolder
, hToken
, dwFlags
, pszSubPathW
, pszPathW
);
1665 if (SUCCEEDED(hr
) && pszPath
)
1666 WideCharToMultiByte(CP_ACP
, 0, pszPathW
, -1, pszPath
, MAX_PATH
, NULL
, NULL
);
1669 HeapFree(GetProcessHeap(), 0, pszPathW
);
1670 HeapFree(GetProcessHeap(), 0, pszSubPathW
);
1674 HRESULT WINAPI
SHGetFolderPathAndSubDirW(
1675 HWND hwndOwner
, /* [I] owner window */
1676 int nFolder
, /* [I] CSIDL identifying the folder */
1677 HANDLE hToken
, /* [I] access token */
1678 DWORD dwFlags
, /* [I] which path to return */
1679 LPCWSTR pszSubPath
,/* [I] sub directory of the specified folder */
1680 LPWSTR pszPath
) /* [O] converted path */
1683 WCHAR szBuildPath
[MAX_PATH
], szTemp
[MAX_PATH
];
1684 DWORD folder
= nFolder
& CSIDL_FOLDER_MASK
; //FIXME
1688 TRACE("%p,%p,nFolder=0x%04x,%s\n", hwndOwner
,pszPath
,nFolder
,debugstr_w(pszSubPath
));
1690 /* Windows always NULL-terminates the resulting path regardless of success
1691 * or failure, so do so first
1696 if (folder
>= sizeof(CSIDL_Data
) / sizeof(CSIDL_Data
[0]))
1697 return E_INVALIDARG
;
1698 if ((SHGFP_TYPE_CURRENT
!= dwFlags
) && (SHGFP_TYPE_DEFAULT
!= dwFlags
))
1699 return E_INVALIDARG
;
1701 type
= CSIDL_Data
[folder
].type
;
1704 case CSIDL_Type_Disallowed
:
1707 case CSIDL_Type_NonExistent
:
1710 case CSIDL_Type_WindowsPath
:
1711 GetWindowsDirectoryW(szTemp
, MAX_PATH
);
1712 if (CSIDL_Data
[folder
].szDefaultPath
&&
1713 !IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
) &&
1714 *CSIDL_Data
[folder
].szDefaultPath
)
1716 PathAddBackslashW(szTemp
);
1717 wcscat(szTemp
, CSIDL_Data
[folder
].szDefaultPath
);
1721 case CSIDL_Type_SystemPath
:
1722 GetSystemDirectoryW(szTemp
, MAX_PATH
);
1723 if (CSIDL_Data
[folder
].szDefaultPath
&&
1724 !IS_INTRESOURCE(CSIDL_Data
[folder
].szDefaultPath
) &&
1725 *CSIDL_Data
[folder
].szDefaultPath
)
1727 PathAddBackslashW(szTemp
);
1728 wcscat(szTemp
, CSIDL_Data
[folder
].szDefaultPath
);
1732 case CSIDL_Type_CurrVer
:
1733 hr
= _SHGetCurrentVersionPath(dwFlags
, folder
, szTemp
);
1735 case CSIDL_Type_User
:
1736 hr
= _SHGetUserProfilePath(hToken
, dwFlags
, folder
, szTemp
);
1738 case CSIDL_Type_AllUsers
:
1739 hr
= _SHGetAllUsersProfilePath(dwFlags
, folder
, szTemp
);
1742 FIXME("bogus type %d, please fix\n", type
);
1747 /* Expand environment strings if necessary */
1749 hr
= _SHExpandEnvironmentStrings(szTemp
, szBuildPath
);
1751 wcscpy(szBuildPath
, szTemp
);
1753 if (FAILED(hr
)) goto end
;
1756 /* make sure the new path does not exceed th bufferlength
1757 * rememebr to backslash and the termination */
1758 if(MAX_PATH
< (wcslen(szBuildPath
) + wcslen(pszSubPath
) + 2)) {
1759 hr
= HRESULT_FROM_WIN32(ERROR_FILENAME_EXCED_RANGE
);
1762 PathAppendW(szBuildPath
, pszSubPath
);
1763 PathRemoveBackslashW(szBuildPath
);
1765 /* Copy the path if it's available before we might return */
1766 if (SUCCEEDED(hr
) && pszPath
)
1767 wcscpy(pszPath
, szBuildPath
);
1769 /* if we don't care about existing directories we are ready */
1770 if(nFolder
& CSIDL_FLAG_DONT_VERIFY
) goto end
;
1772 if (PathFileExistsW(szBuildPath
)) goto end
;
1774 /* not existing but we are not allowed to create it. The return value
1775 * is verified against shell32 version 6.0.
1777 if (!(nFolder
& CSIDL_FLAG_CREATE
))
1779 hr
= HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
);
1783 /* create directory/directories */
1784 ret
= SHCreateDirectoryExW(hwndOwner
, szBuildPath
, NULL
);
1785 if (ret
&& ret
!= ERROR_ALREADY_EXISTS
)
1787 ERR("Failed to create directory %s.\n", debugstr_w(szBuildPath
));
1792 TRACE("Created missing system directory %s\n", debugstr_w(szBuildPath
));
1794 TRACE("returning 0x%08x (final path is %s)\n", hr
, debugstr_w(szBuildPath
));
1798 /*************************************************************************
1799 * SHGetFolderPathA [SHELL32.@]
1801 * See SHGetFolderPathW.
1803 HRESULT WINAPI
SHGetFolderPathA(
1810 WCHAR szTemp
[MAX_PATH
];
1813 TRACE("%p,%p,nFolder=0x%04x\n",hwndOwner
,pszPath
,nFolder
);
1817 hr
= SHGetFolderPathW(hwndOwner
, nFolder
, hToken
, dwFlags
, szTemp
);
1818 if (SUCCEEDED(hr
) && pszPath
)
1819 WideCharToMultiByte(CP_ACP
, 0, szTemp
, -1, pszPath
, MAX_PATH
, NULL
,
1825 /* For each folder in folders, if its value has not been set in the registry,
1826 * calls _SHGetUserProfilePath or _SHGetAllUsersProfilePath (depending on the
1827 * folder's type) to get the unexpanded value first.
1828 * Writes the unexpanded value to User Shell Folders, and queries it with
1829 * SHGetFolderPathW to force the creation of the directory if it doesn't
1830 * already exist. SHGetFolderPathW also returns the expanded value, which
1831 * this then writes to Shell Folders.
1833 static HRESULT
_SHRegisterFolders(HKEY hRootKey
, HANDLE hToken
,
1834 LPCWSTR szUserShellFolderPath
, LPCWSTR szShellFolderPath
, const UINT folders
[],
1838 WCHAR path
[MAX_PATH
];
1840 HKEY hUserKey
= NULL
, hKey
= NULL
;
1841 DWORD dwDisp
, dwType
, dwPathLen
;
1844 TRACE("%p,%p,%s,%p,%u\n", hRootKey
, hToken
,
1845 debugstr_w(szUserShellFolderPath
), folders
, foldersLen
);
1847 ret
= RegCreateKeyExW(hRootKey
, szUserShellFolderPath
, 0, NULL
, 0,
1848 KEY_ALL_ACCESS
, NULL
, &hUserKey
, &dwDisp
);
1850 hr
= HRESULT_FROM_WIN32(ret
);
1853 ret
= RegCreateKeyExW(hRootKey
, szShellFolderPath
, 0, NULL
, 0,
1854 KEY_ALL_ACCESS
, NULL
, &hKey
, &dwDisp
);
1856 hr
= HRESULT_FROM_WIN32(ret
);
1858 for (i
= 0; SUCCEEDED(hr
) && i
< foldersLen
; i
++)
1860 dwPathLen
= MAX_PATH
* sizeof(WCHAR
);
1861 if (RegQueryValueExW(hUserKey
, CSIDL_Data
[folders
[i
]].szValueName
, NULL
,
1862 &dwType
, (LPBYTE
)path
, &dwPathLen
) || (dwType
!= REG_SZ
&&
1863 dwType
!= REG_EXPAND_SZ
))
1866 if (CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_User
)
1867 _SHGetUserProfilePath(hToken
, SHGFP_TYPE_DEFAULT
, folders
[i
],
1869 else if (CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_AllUsers
)
1870 _SHGetAllUsersProfilePath(SHGFP_TYPE_DEFAULT
, folders
[i
], path
);
1871 else if (CSIDL_Data
[folders
[i
]].type
== CSIDL_Type_WindowsPath
)
1872 GetWindowsDirectoryW(path
, MAX_PATH
);
1877 ret
= RegSetValueExW(hUserKey
,
1878 CSIDL_Data
[folders
[i
]].szValueName
, 0, REG_EXPAND_SZ
,
1879 (LPBYTE
)path
, (wcslen(path
) + 1) * sizeof(WCHAR
));
1881 hr
= HRESULT_FROM_WIN32(ret
);
1884 hr
= SHGetFolderPathW(NULL
, folders
[i
] | CSIDL_FLAG_CREATE
,
1885 hToken
, SHGFP_TYPE_DEFAULT
, path
);
1886 ret
= RegSetValueExW(hKey
,
1887 CSIDL_Data
[folders
[i
]].szValueName
, 0, REG_SZ
,
1888 (LPBYTE
)path
, (wcslen(path
) + 1) * sizeof(WCHAR
));
1890 hr
= HRESULT_FROM_WIN32(ret
);
1896 RegCloseKey(hUserKey
);
1900 TRACE("returning 0x%08x\n", hr
);
1904 static HRESULT
_SHRegisterUserShellFolders(BOOL bDefault
)
1906 static const UINT folders
[] = {
1917 CSIDL_DESKTOPDIRECTORY
,
1921 CSIDL_LOCAL_APPDATA
,
1922 CSIDL_INTERNET_CACHE
,
1928 WCHAR userShellFolderPath
[MAX_PATH
], shellFolderPath
[MAX_PATH
];
1929 LPCWSTR pUserShellFolderPath
, pShellFolderPath
;
1934 TRACE("%s\n", bDefault
? "TRUE" : "FALSE");
1937 hToken
= (HANDLE
)-1;
1938 hRootKey
= HKEY_USERS
;
1939 wcscpy(userShellFolderPath
, DefaultW
);
1940 PathAddBackslashW(userShellFolderPath
);
1941 wcscat(userShellFolderPath
, szSHUserFolders
);
1942 pUserShellFolderPath
= userShellFolderPath
;
1943 wcscpy(shellFolderPath
, DefaultW
);
1944 PathAddBackslashW(shellFolderPath
);
1945 wcscat(shellFolderPath
, szSHFolders
);
1946 pShellFolderPath
= shellFolderPath
;
1951 hRootKey
= HKEY_CURRENT_USER
;
1952 pUserShellFolderPath
= szSHUserFolders
;
1953 pShellFolderPath
= szSHFolders
;
1956 hr
= _SHRegisterFolders(hRootKey
, hToken
, pUserShellFolderPath
,
1957 pShellFolderPath
, folders
, sizeof(folders
) / sizeof(folders
[0]));
1958 TRACE("returning 0x%08x\n", hr
);
1962 static HRESULT
_SHRegisterCommonShellFolders(void)
1964 static const UINT folders
[] = {
1965 CSIDL_COMMON_STARTMENU
,
1966 CSIDL_COMMON_PROGRAMS
,
1967 CSIDL_COMMON_STARTUP
,
1968 CSIDL_COMMON_DESKTOPDIRECTORY
,
1969 CSIDL_COMMON_FAVORITES
,
1970 CSIDL_COMMON_APPDATA
,
1971 CSIDL_COMMON_TEMPLATES
,
1972 CSIDL_COMMON_DOCUMENTS
,
1977 hr
= _SHRegisterFolders(HKEY_LOCAL_MACHINE
, NULL
, szSHUserFolders
,
1978 szSHFolders
, folders
, sizeof(folders
) / sizeof(folders
[0]));
1979 TRACE("returning 0x%08x\n", hr
);
1983 /******************************************************************************
1984 * _SHAppendToUnixPath [Internal]
1986 * Helper function for _SHCreateSymbolicLinks. Appends pwszSubPath (or the
1987 * corresponding resource, if IS_INTRESOURCE) to the unix base path 'szBasePath'
1988 * and replaces backslashes with slashes.
1991 * szBasePath [IO] The unix base path, which will be appended to (CP_UNXICP).
1992 * pwszSubPath [I] Sub-path or resource id (use MAKEINTRESOURCEW).
1998 static BOOL __inline
_SHAppendToUnixPath(char *szBasePath
, LPCWSTR pwszSubPath
) {
1999 WCHAR wszSubPath
[MAX_PATH
];
2000 int cLen
= strlen(szBasePath
);
2003 if (IS_INTRESOURCE(pwszSubPath
)) {
2004 if (!LoadStringW(shell32_hInstance
, LOWORD(pwszSubPath
), wszSubPath
, MAX_PATH
)) {
2005 /* Fall back to hard coded defaults. */
2006 switch (LOWORD(pwszSubPath
)) {
2008 wcscpy(wszSubPath
, PersonalW
);
2011 wcscpy(wszSubPath
, My_MusicW
);
2013 case IDS_MYPICTURES
:
2014 wcscpy(wszSubPath
, My_PicturesW
);
2017 wcscpy(wszSubPath
, My_VideoW
);
2020 ERR("LoadString(%d) failed!\n", LOWORD(pwszSubPath
));
2025 wcscpy(wszSubPath
, pwszSubPath
);
2028 if (szBasePath
[cLen
-1] != '/') szBasePath
[cLen
++] = '/';
2030 if (!WideCharToMultiByte(CP_ACP
, 0, wszSubPath
, -1, szBasePath
+ cLen
,
2031 FILENAME_MAX
- cLen
, NULL
, NULL
))
2036 pBackslash
= szBasePath
+ cLen
;
2037 while ((pBackslash
= strchr(pBackslash
, '\\'))) *pBackslash
= '/';
2042 /******************************************************************************
2043 * _SHCreateSymbolicLinks [Internal]
2045 * Sets up symbol links for various shell folders to point into the users home
2046 * directory. We do an educated guess about what the user would probably want:
2047 * - If there is a 'My Documents' directory in $HOME, the user probably wants
2048 * wine's 'My Documents' to point there. Furthermore, we imply that the user
2049 * is a Windows lover and has no problem with wine creating 'My Pictures',
2050 * 'My Music' and 'My Video' subfolders under '$HOME/My Documents', if those
2051 * do not already exits. We put appropriate symbolic links in place for those,
2053 * - If there is no 'My Documents' directory in $HOME, we let 'My Documents'
2054 * point directly to $HOME. We assume the user to be a unix hacker who does not
2055 * want wine to create anything anywhere besides the .wine directory. So, if
2056 * there already is a 'My Music' directory in $HOME, we symlink the 'My Music'
2057 * shell folder to it. But if not, we symlink it to $HOME directly. The same
2058 * holds fo 'My Pictures' and 'My Video'.
2059 * - The Desktop shell folder is symlinked to '$HOME/Desktop', if that does
2060 * exists and left alone if not.
2061 * ('My Music',... above in fact means LoadString(IDS_MYMUSIC))
2063 static void _SHCreateSymbolicLinks(void)
2065 UINT aidsMyStuff
[] = { IDS_MYPICTURES
, IDS_MYVIDEO
, IDS_MYMUSIC
}, i
;
2066 int acsidlMyStuff
[] = { CSIDL_MYPICTURES
, CSIDL_MYVIDEO
, CSIDL_MYMUSIC
};
2067 WCHAR wszTempPath
[MAX_PATH
];
2068 char szPersonalTarget
[FILENAME_MAX
], *pszPersonal
;
2069 char szMyStuffTarget
[FILENAME_MAX
], *pszMyStuff
;
2070 char szDesktopTarget
[FILENAME_MAX
], *pszDesktop
;
2071 struct stat statFolder
;
2072 const char *pszHome
;
2075 /* Create all necessary profile sub-dirs up to 'My Documents' and get the unix path. */
2076 hr
= SHGetFolderPathW(NULL
, CSIDL_PERSONAL
|CSIDL_FLAG_CREATE
, NULL
,
2077 SHGFP_TYPE_DEFAULT
, wszTempPath
);
2078 if (FAILED(hr
)) return;
2079 pszPersonal
= wine_get_unix_file_name(wszTempPath
);
2080 if (!pszPersonal
) return;
2082 pszHome
= getenv("HOME");
2083 if (pszHome
&& !stat(pszHome
, &statFolder
) && S_ISDIR(statFolder
.st_mode
)) {
2084 strcpy(szPersonalTarget
, pszHome
);
2085 if (_SHAppendToUnixPath(szPersonalTarget
, MAKEINTRESOURCEW(IDS_PERSONAL
)) &&
2086 !stat(szPersonalTarget
, &statFolder
) && S_ISDIR(statFolder
.st_mode
))
2088 /* '$HOME/My Documents' exists. Create 'My Pictures', 'My Videos' and
2089 * 'My Music' subfolders or fail silently if they already exist. */
2090 for (i
= 0; i
< sizeof(aidsMyStuff
)/sizeof(aidsMyStuff
[0]); i
++) {
2091 strcpy(szMyStuffTarget
, szPersonalTarget
);
2092 if (_SHAppendToUnixPath(szMyStuffTarget
, MAKEINTRESOURCEW(aidsMyStuff
[i
])))
2093 mkdir(szMyStuffTarget
);
2098 /* '$HOME/My Documents' doesn't exists, but '$HOME' does. */
2099 strcpy(szPersonalTarget
, pszHome
);
2102 /* Replace 'My Documents' directory with a symlink of fail silently if not empty. */
2104 symlink(szPersonalTarget
, pszPersonal
);
2108 /* '$HOME' doesn't exist. Create 'My Pictures', 'My Videos' and 'My Music' subdirs
2109 * in '%USERPROFILE%\\My Documents' or fail silently if they already exist. */
2110 strcpy(szPersonalTarget
, pszPersonal
);
2111 for (i
= 0; i
< sizeof(aidsMyStuff
)/sizeof(aidsMyStuff
[0]); i
++) {
2112 strcpy(szMyStuffTarget
, szPersonalTarget
);
2113 if (_SHAppendToUnixPath(szMyStuffTarget
, MAKEINTRESOURCEW(aidsMyStuff
[i
])))
2114 mkdir(szMyStuffTarget
);
2118 /* Create symbolic links for 'My Pictures', 'My Video' and 'My Music'. */
2119 for (i
=0; i
< sizeof(aidsMyStuff
)/sizeof(aidsMyStuff
[0]); i
++) {
2120 /* Create the current 'My Whatever' folder and get it's unix path. */
2121 hr
= SHGetFolderPathW(NULL
, acsidlMyStuff
[i
]|CSIDL_FLAG_CREATE
, NULL
,
2122 SHGFP_TYPE_DEFAULT
, wszTempPath
);
2123 if (FAILED(hr
)) continue;
2124 pszMyStuff
= wine_get_unix_file_name(wszTempPath
);
2125 if (!pszMyStuff
) continue;
2127 strcpy(szMyStuffTarget
, szPersonalTarget
);
2128 if (_SHAppendToUnixPath(szMyStuffTarget
, MAKEINTRESOURCEW(aidsMyStuff
[i
])) &&
2129 !stat(szMyStuffTarget
, &statFolder
) && S_ISDIR(statFolder
.st_mode
))
2131 /* If there's a 'My Whatever' directory where 'My Documents' links to, link to it. */
2133 symlink(szMyStuffTarget
, pszMyStuff
);
2137 /* Else link to where 'My Documents' itself links to. */
2139 symlink(szPersonalTarget
, pszMyStuff
);
2141 HeapFree(GetProcessHeap(), 0, pszMyStuff
);
2144 /* Last but not least, the Desktop folder */
2146 strcpy(szDesktopTarget
, pszHome
);
2148 strcpy(szDesktopTarget
, pszPersonal
);
2149 HeapFree(GetProcessHeap(), 0, pszPersonal
);
2151 if (_SHAppendToUnixPath(szDesktopTarget
, DesktopW
) &&
2152 !stat(szDesktopTarget
, &statFolder
) && S_ISDIR(statFolder
.st_mode
))
2154 hr
= SHGetFolderPathW(NULL
, CSIDL_DESKTOPDIRECTORY
|CSIDL_FLAG_CREATE
, NULL
,
2155 SHGFP_TYPE_DEFAULT
, wszTempPath
);
2156 if (SUCCEEDED(hr
) && (pszDesktop
= wine_get_unix_file_name(wszTempPath
)))
2159 symlink(szDesktopTarget
, pszDesktop
);
2160 HeapFree(GetProcessHeap(), 0, pszDesktop
);
2166 /* Register the default values in the registry, as some apps seem to depend
2167 * on their presence. The set registered was taken from Windows XP.
2169 HRESULT
SHELL_RegisterShellFolders(void)
2173 /* Set up '$HOME' targeted symlinks for 'My Documents', 'My Pictures',
2174 * 'My Video', 'My Music' and 'Desktop' in advance, so that the
2175 * _SHRegister*ShellFolders() functions will find everything nice and clean
2176 * and thus will not attempt to create them in the profile directory. */
2178 _SHCreateSymbolicLinks();
2181 hr
= _SHRegisterUserShellFolders(TRUE
);
2183 hr
= _SHRegisterUserShellFolders(FALSE
);
2185 hr
= _SHRegisterCommonShellFolders();
2189 /*************************************************************************
2190 * SHGetSpecialFolderPathA [SHELL32.@]
2192 BOOL WINAPI
SHGetSpecialFolderPathA (
2198 return (SHGetFolderPathA(
2200 nFolder
+ (bCreate
? CSIDL_FLAG_CREATE
: 0),
2203 szPath
)) == S_OK
? TRUE
: FALSE
;
2206 /*************************************************************************
2207 * SHGetSpecialFolderPathW
2209 BOOL WINAPI
SHGetSpecialFolderPathW (
2215 return (SHGetFolderPathW(
2217 nFolder
+ (bCreate
? CSIDL_FLAG_CREATE
: 0),
2220 szPath
)) == S_OK
? TRUE
: FALSE
;
2223 /*************************************************************************
2224 * SHGetSpecialFolderPath (SHELL32.175)
2226 BOOL WINAPI
SHGetSpecialFolderPathAW (
2233 if (SHELL_OsIsUnicode())
2234 return SHGetSpecialFolderPathW (hwndOwner
, szPath
, nFolder
, bCreate
);
2235 return SHGetSpecialFolderPathA (hwndOwner
, szPath
, nFolder
, bCreate
);
2238 /*************************************************************************
2239 * SHGetFolderLocation [SHELL32.@]
2241 * Gets the folder locations from the registry and creates a pidl.
2245 * nFolder [I] CSIDL_xxxxx
2246 * hToken [I] token representing user, or NULL for current user, or -1 for
2248 * dwReserved [I] must be zero
2249 * ppidl [O] PIDL of a special folder
2253 * Failure: Standard OLE-defined error result, S_FALSE or E_INVALIDARG
2256 * Creates missing reg keys and directories.
2257 * Mostly forwards to SHGetFolderPathW, but a few values of nFolder return
2258 * virtual folders that are handled here.
2260 HRESULT WINAPI
SHGetFolderLocation(
2265 LPITEMIDLIST
*ppidl
)
2267 HRESULT hr
= E_INVALIDARG
;
2269 TRACE("%p 0x%08x %p 0x%08x %p\n",
2270 hwndOwner
, nFolder
, hToken
, dwReserved
, ppidl
);
2273 return E_INVALIDARG
;
2275 return E_INVALIDARG
;
2277 /* The virtual folders' locations are not user-dependent */
2282 *ppidl
= _ILCreateDesktop();
2285 case CSIDL_PERSONAL
:
2286 *ppidl
= _ILCreateMyDocuments();
2289 case CSIDL_INTERNET
:
2290 *ppidl
= _ILCreateIExplore();
2293 case CSIDL_CONTROLS
:
2294 *ppidl
= _ILCreateControlPanel();
2297 case CSIDL_PRINTERS
:
2298 *ppidl
= _ILCreatePrinters();
2301 case CSIDL_BITBUCKET
:
2302 *ppidl
= _ILCreateBitBucket();
2306 *ppidl
= _ILCreateMyComputer();
2310 *ppidl
= _ILCreateNetwork();
2315 WCHAR szPath
[MAX_PATH
];
2317 hr
= SHGetFolderPathW(hwndOwner
, nFolder
, hToken
,
2318 SHGFP_TYPE_CURRENT
, szPath
);
2323 TRACE("Value=%s\n", debugstr_w(szPath
));
2324 hr
= SHILCreateFromPathW(szPath
, ppidl
, &attributes
);
2326 else if (hr
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
))
2328 /* unlike SHGetFolderPath, SHGetFolderLocation in shell32
2329 * version 6.0 returns E_FAIL for nonexistent paths
2338 TRACE("-- (new pidl %p)\n",*ppidl
);
2342 /*************************************************************************
2343 * SHGetSpecialFolderLocation [SHELL32.@]
2346 * In NT5, SHGetSpecialFolderLocation needs the <winntdir>/Recent
2349 HRESULT WINAPI
SHGetSpecialFolderLocation(
2352 LPITEMIDLIST
* ppidl
)
2354 HRESULT hr
= E_INVALIDARG
;
2356 TRACE("(%p,0x%x,%p)\n", hwndOwner
,nFolder
,ppidl
);
2359 return E_INVALIDARG
;
2361 hr
= SHGetFolderLocation(hwndOwner
, nFolder
, NULL
, 0, ppidl
);