Merging r37048, r37051, r37052, r37055 from the-real-msvc branch
[reactos.git] / reactos / dll / win32 / shell32 / shellpath.c
1 /*
2 * Path Functions
3 *
4 * Copyright 1998, 1999, 2000 Juergen Schmied
5 * Copyright 2004 Juan Lang
6 *
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.
11 *
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.
16 *
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
20 *
21 * NOTES:
22 *
23 * Many of these functions are in SHLWAPI.DLL also
24 *
25 */
26
27 #include <precomp.h>
28
29 WINE_DEFAULT_DEBUG_CHANNEL(shell);
30
31 /*
32 ########## Combining and Constructing paths ##########
33 */
34
35 /*************************************************************************
36 * PathAppend [SHELL32.36]
37 */
38 BOOL WINAPI PathAppendAW(
39 LPVOID lpszPath1,
40 LPCVOID lpszPath2)
41 {
42 if (SHELL_OsIsUnicode())
43 return PathAppendW(lpszPath1, lpszPath2);
44 return PathAppendA(lpszPath1, lpszPath2);
45 }
46
47 /*************************************************************************
48 * PathCombine [SHELL32.37]
49 */
50 LPVOID WINAPI PathCombineAW(
51 LPVOID szDest,
52 LPCVOID lpszDir,
53 LPCVOID lpszFile)
54 {
55 if (SHELL_OsIsUnicode())
56 return PathCombineW( szDest, lpszDir, lpszFile );
57 return PathCombineA( szDest, lpszDir, lpszFile );
58 }
59
60 /*************************************************************************
61 * PathAddBackslash [SHELL32.32]
62 */
63 LPVOID WINAPI PathAddBackslashAW(LPVOID lpszPath)
64 {
65 if(SHELL_OsIsUnicode())
66 return PathAddBackslashW(lpszPath);
67 return PathAddBackslashA(lpszPath);
68 }
69
70 /*************************************************************************
71 * PathBuildRoot [SHELL32.30]
72 */
73 LPVOID WINAPI PathBuildRootAW(LPVOID lpszPath, int drive)
74 {
75 if(SHELL_OsIsUnicode())
76 return PathBuildRootW(lpszPath, drive);
77 return PathBuildRootA(lpszPath, drive);
78 }
79
80 /*
81 Extracting Component Parts
82 */
83
84 /*************************************************************************
85 * PathFindFileName [SHELL32.34]
86 */
87 LPVOID WINAPI PathFindFileNameAW(LPCVOID lpszPath)
88 {
89 if(SHELL_OsIsUnicode())
90 return PathFindFileNameW(lpszPath);
91 return PathFindFileNameA(lpszPath);
92 }
93
94 /*************************************************************************
95 * PathFindExtension [SHELL32.31]
96 */
97 LPVOID WINAPI PathFindExtensionAW(LPCVOID lpszPath)
98 {
99 if (SHELL_OsIsUnicode())
100 return PathFindExtensionW(lpszPath);
101 return PathFindExtensionA(lpszPath);
102
103 }
104
105 /*************************************************************************
106 * PathGetExtensionA [internal]
107 *
108 * NOTES
109 * exported by ordinal
110 * return value points to the first char after the dot
111 */
112 static LPSTR PathGetExtensionA(LPCSTR lpszPath)
113 {
114 TRACE("(%s)\n",lpszPath);
115
116 lpszPath = PathFindExtensionA(lpszPath);
117 return (LPSTR)(*lpszPath?(lpszPath+1):lpszPath);
118 }
119
120 /*************************************************************************
121 * PathGetExtensionW [internal]
122 */
123 static LPWSTR PathGetExtensionW(LPCWSTR lpszPath)
124 {
125 TRACE("(%s)\n",debugstr_w(lpszPath));
126
127 lpszPath = PathFindExtensionW(lpszPath);
128 return (LPWSTR)(*lpszPath?(lpszPath+1):lpszPath);
129 }
130
131 /*************************************************************************
132 * PathGetExtension [SHELL32.158]
133 */
134 LPVOID WINAPI PathGetExtensionAW(LPCVOID lpszPath,DWORD void1, DWORD void2)
135 {
136 if (SHELL_OsIsUnicode())
137 return PathGetExtensionW(lpszPath);
138 return PathGetExtensionA(lpszPath);
139 }
140
141 /*************************************************************************
142 * PathGetArgs [SHELL32.52]
143 */
144 LPVOID WINAPI PathGetArgsAW(LPVOID lpszPath)
145 {
146 if (SHELL_OsIsUnicode())
147 return PathGetArgsW(lpszPath);
148 return PathGetArgsA(lpszPath);
149 }
150
151 /*************************************************************************
152 * PathGetDriveNumber [SHELL32.57]
153 */
154 int WINAPI PathGetDriveNumberAW(LPVOID lpszPath)
155 {
156 if (SHELL_OsIsUnicode())
157 return PathGetDriveNumberW(lpszPath);
158 return PathGetDriveNumberA(lpszPath);
159 }
160
161 /*************************************************************************
162 * PathRemoveFileSpec [SHELL32.35]
163 */
164 BOOL WINAPI PathRemoveFileSpecAW(LPVOID lpszPath)
165 {
166 if (SHELL_OsIsUnicode())
167 return PathRemoveFileSpecW(lpszPath);
168 return PathRemoveFileSpecA(lpszPath);
169 }
170
171 /*************************************************************************
172 * PathStripPath [SHELL32.38]
173 */
174 void WINAPI PathStripPathAW(LPVOID lpszPath)
175 {
176 if (SHELL_OsIsUnicode())
177 PathStripPathW(lpszPath);
178 else
179 PathStripPathA(lpszPath);
180 }
181
182 /*************************************************************************
183 * PathStripToRoot [SHELL32.50]
184 */
185 BOOL WINAPI PathStripToRootAW(LPVOID lpszPath)
186 {
187 if (SHELL_OsIsUnicode())
188 return PathStripToRootW(lpszPath);
189 return PathStripToRootA(lpszPath);
190 }
191
192 /*************************************************************************
193 * PathRemoveArgs [SHELL32.251]
194 */
195 void WINAPI PathRemoveArgsAW(LPVOID lpszPath)
196 {
197 if (SHELL_OsIsUnicode())
198 PathRemoveArgsW(lpszPath);
199 else
200 PathRemoveArgsA(lpszPath);
201 }
202
203 /*************************************************************************
204 * PathRemoveExtension [SHELL32.250]
205 */
206 void WINAPI PathRemoveExtensionAW(LPVOID lpszPath)
207 {
208 if (SHELL_OsIsUnicode())
209 PathRemoveExtensionW(lpszPath);
210 else
211 PathRemoveExtensionA(lpszPath);
212 }
213
214
215 /*
216 Path Manipulations
217 */
218
219 /*************************************************************************
220 * PathGetShortPathA [internal]
221 */
222 static void PathGetShortPathA(LPSTR pszPath)
223 {
224 CHAR path[MAX_PATH];
225
226 TRACE("%s\n", pszPath);
227
228 if (GetShortPathNameA(pszPath, path, MAX_PATH))
229 {
230 lstrcpyA(pszPath, path);
231 }
232 }
233
234 /*************************************************************************
235 * PathGetShortPathW [internal]
236 */
237 static void PathGetShortPathW(LPWSTR pszPath)
238 {
239 WCHAR path[MAX_PATH];
240
241 TRACE("%s\n", debugstr_w(pszPath));
242
243 if (GetShortPathNameW(pszPath, path, MAX_PATH))
244 {
245 wcscpy(pszPath, path);
246 }
247 }
248
249 /*************************************************************************
250 * PathGetShortPath [SHELL32.92]
251 */
252 VOID WINAPI PathGetShortPathAW(LPVOID pszPath)
253 {
254 if(SHELL_OsIsUnicode())
255 PathGetShortPathW(pszPath);
256 PathGetShortPathA(pszPath);
257 }
258
259 /*************************************************************************
260 * PathRemoveBlanks [SHELL32.33]
261 */
262 void WINAPI PathRemoveBlanksAW(LPVOID str)
263 {
264 if(SHELL_OsIsUnicode())
265 PathRemoveBlanksW(str);
266 else
267 PathRemoveBlanksA(str);
268 }
269
270 /*************************************************************************
271 * PathQuoteSpaces [SHELL32.55]
272 */
273 VOID WINAPI PathQuoteSpacesAW (LPVOID lpszPath)
274 {
275 if(SHELL_OsIsUnicode())
276 PathQuoteSpacesW(lpszPath);
277 else
278 PathQuoteSpacesA(lpszPath);
279 }
280
281 /*************************************************************************
282 * PathUnquoteSpaces [SHELL32.56]
283 */
284 VOID WINAPI PathUnquoteSpacesAW(LPVOID str)
285 {
286 if(SHELL_OsIsUnicode())
287 PathUnquoteSpacesW(str);
288 else
289 PathUnquoteSpacesA(str);
290 }
291
292 /*************************************************************************
293 * PathParseIconLocation [SHELL32.249]
294 */
295 int WINAPI PathParseIconLocationAW (LPVOID lpszPath)
296 {
297 if(SHELL_OsIsUnicode())
298 return PathParseIconLocationW(lpszPath);
299 return PathParseIconLocationA(lpszPath);
300 }
301
302 /*
303 ########## Path Testing ##########
304 */
305 /*************************************************************************
306 * PathIsUNC [SHELL32.39]
307 */
308 BOOL WINAPI PathIsUNCAW (LPCVOID lpszPath)
309 {
310 if (SHELL_OsIsUnicode())
311 return PathIsUNCW( lpszPath );
312 return PathIsUNCA( lpszPath );
313 }
314
315 /*************************************************************************
316 * PathIsRelative [SHELL32.40]
317 */
318 BOOL WINAPI PathIsRelativeAW (LPCVOID lpszPath)
319 {
320 if (SHELL_OsIsUnicode())
321 return PathIsRelativeW( lpszPath );
322 return PathIsRelativeA( lpszPath );
323 }
324
325 /*************************************************************************
326 * PathIsRoot [SHELL32.29]
327 */
328 BOOL WINAPI PathIsRootAW(LPCVOID lpszPath)
329 {
330 if (SHELL_OsIsUnicode())
331 return PathIsRootW(lpszPath);
332 return PathIsRootA(lpszPath);
333 }
334
335 /*************************************************************************
336 * PathIsExeA [internal]
337 */
338 static BOOL PathIsExeA (LPCSTR lpszPath)
339 {
340 LPCSTR lpszExtension = PathGetExtensionA(lpszPath);
341 int i;
342 static const char * const lpszExtensions[] =
343 {"exe", "com", "pif", "cmd", "bat", "scf", "scr", NULL };
344
345 TRACE("path=%s\n",lpszPath);
346
347 for(i=0; lpszExtensions[i]; i++)
348 if (!lstrcmpiA(lpszExtension,lpszExtensions[i])) return TRUE;
349
350 return FALSE;
351 }
352
353 /*************************************************************************
354 * PathIsExeW [internal]
355 */
356 static BOOL PathIsExeW (LPCWSTR lpszPath)
357 {
358 LPCWSTR lpszExtension = PathGetExtensionW(lpszPath);
359 int i;
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'} };
364
365 TRACE("path=%s\n",debugstr_w(lpszPath));
366
367 for(i=0; lpszExtensions[i][0]; i++)
368 if (!strcmpiW(lpszExtension,lpszExtensions[i])) return TRUE;
369
370 return FALSE;
371 }
372
373 /*************************************************************************
374 * PathIsExe [SHELL32.43]
375 */
376 BOOL WINAPI PathIsExeAW (LPCVOID path)
377 {
378 if (SHELL_OsIsUnicode())
379 return PathIsExeW (path);
380 return PathIsExeA(path);
381 }
382
383 /*************************************************************************
384 * PathIsDirectory [SHELL32.159]
385 */
386 BOOL WINAPI PathIsDirectoryAW (LPCVOID lpszPath)
387 {
388 if (SHELL_OsIsUnicode())
389 return PathIsDirectoryW (lpszPath);
390 return PathIsDirectoryA (lpszPath);
391 }
392
393 /*************************************************************************
394 * PathFileExists [SHELL32.45]
395 */
396 BOOL WINAPI PathFileExistsAW (LPCVOID lpszPath)
397 {
398 if (SHELL_OsIsUnicode())
399 return PathFileExistsW (lpszPath);
400 return PathFileExistsA (lpszPath);
401 }
402
403 /*************************************************************************
404 * PathMatchSpec [SHELL32.46]
405 */
406 BOOL WINAPI PathMatchSpecAW(LPVOID name, LPVOID mask)
407 {
408 if (SHELL_OsIsUnicode())
409 return PathMatchSpecW( name, mask );
410 return PathMatchSpecA( name, mask );
411 }
412
413 /*************************************************************************
414 * PathIsSameRoot [SHELL32.650]
415 */
416 BOOL WINAPI PathIsSameRootAW(LPCVOID lpszPath1, LPCVOID lpszPath2)
417 {
418 if (SHELL_OsIsUnicode())
419 return PathIsSameRootW(lpszPath1, lpszPath2);
420 return PathIsSameRootA(lpszPath1, lpszPath2);
421 }
422
423 /*************************************************************************
424 * IsLFNDriveA [SHELL32.41]
425 */
426 BOOL WINAPI IsLFNDriveA(LPCSTR lpszPath)
427 {
428 DWORD fnlen;
429
430 if (!GetVolumeInformationA(lpszPath, NULL, 0, NULL, &fnlen, NULL, NULL, 0))
431 return FALSE;
432 return fnlen > 12;
433 }
434
435 /*************************************************************************
436 * IsLFNDriveW [SHELL32.42]
437 */
438 BOOL WINAPI IsLFNDriveW(LPCWSTR lpszPath)
439 {
440 DWORD fnlen;
441
442 if (!GetVolumeInformationW(lpszPath, NULL, 0, NULL, &fnlen, NULL, NULL, 0))
443 return FALSE;
444 return fnlen > 12;
445 }
446
447 /*************************************************************************
448 * IsLFNDrive [SHELL32.119]
449 */
450 BOOL WINAPI IsLFNDriveAW(LPCVOID lpszPath)
451 {
452 if (SHELL_OsIsUnicode())
453 return IsLFNDriveW(lpszPath);
454 return IsLFNDriveA(lpszPath);
455 }
456
457 /*
458 ########## Creating Something Unique ##########
459 */
460 /*************************************************************************
461 * PathMakeUniqueNameA [internal]
462 */
463 BOOL WINAPI PathMakeUniqueNameA(
464 LPSTR lpszBuffer,
465 DWORD dwBuffSize,
466 LPCSTR lpszShortName,
467 LPCSTR lpszLongName,
468 LPCSTR lpszPathName)
469 {
470 FIXME("%p %u %s %s %s stub\n",
471 lpszBuffer, dwBuffSize, debugstr_a(lpszShortName),
472 debugstr_a(lpszLongName), debugstr_a(lpszPathName));
473 return TRUE;
474 }
475
476 /*************************************************************************
477 * PathMakeUniqueNameW [internal]
478 */
479 BOOL WINAPI PathMakeUniqueNameW(
480 LPWSTR lpszBuffer,
481 DWORD dwBuffSize,
482 LPCWSTR lpszShortName,
483 LPCWSTR lpszLongName,
484 LPCWSTR lpszPathName)
485 {
486 FIXME("%p %u %s %s %s stub\n",
487 lpszBuffer, dwBuffSize, debugstr_w(lpszShortName),
488 debugstr_w(lpszLongName), debugstr_w(lpszPathName));
489 return TRUE;
490 }
491
492 /*************************************************************************
493 * PathMakeUniqueName [SHELL32.47]
494 */
495 BOOL WINAPI PathMakeUniqueNameAW(
496 LPVOID lpszBuffer,
497 DWORD dwBuffSize,
498 LPCVOID lpszShortName,
499 LPCVOID lpszLongName,
500 LPCVOID lpszPathName)
501 {
502 if (SHELL_OsIsUnicode())
503 return PathMakeUniqueNameW(lpszBuffer,dwBuffSize, lpszShortName,lpszLongName,lpszPathName);
504 return PathMakeUniqueNameA(lpszBuffer,dwBuffSize, lpszShortName,lpszLongName,lpszPathName);
505 }
506
507 /*************************************************************************
508 * PathYetAnotherMakeUniqueName [SHELL32.75]
509 *
510 * NOTES
511 * exported by ordinal
512 */
513 BOOL WINAPI PathYetAnotherMakeUniqueName(
514 LPWSTR lpszBuffer,
515 LPCWSTR lpszPathName,
516 LPCWSTR lpszShortName,
517 LPCWSTR lpszLongName)
518 {
519 FIXME("(%p, %s, %s ,%s):stub.\n",
520 lpszBuffer, debugstr_w(lpszPathName), debugstr_w(lpszShortName), debugstr_w(lpszLongName));
521 return TRUE;
522 }
523
524
525 /*
526 ########## cleaning and resolving paths ##########
527 */
528
529 /*************************************************************************
530 * PathFindOnPath [SHELL32.145]
531 */
532 BOOL WINAPI PathFindOnPathAW(LPVOID sFile, LPCVOID *sOtherDirs)
533 {
534 if (SHELL_OsIsUnicode())
535 return PathFindOnPathW(sFile, (LPCWSTR *)sOtherDirs);
536 return PathFindOnPathA(sFile, (LPCSTR *)sOtherDirs);
537 }
538
539 /*************************************************************************
540 * PathCleanupSpec [SHELL32.171]
541 *
542 * lpszFile is changed in place.
543 */
544 int WINAPI PathCleanupSpec( LPCWSTR lpszPathW, LPWSTR lpszFileW )
545 {
546 int i = 0;
547 DWORD rc = 0;
548 int length = 0;
549
550 if (SHELL_OsIsUnicode())
551 {
552 LPWSTR p = lpszFileW;
553
554 TRACE("Cleanup %s\n",debugstr_w(lpszFileW));
555
556 if (lpszPathW)
557 length = wcslen(lpszPathW);
558
559 while (*p)
560 {
561 int gct = PathGetCharTypeW(*p);
562 if (gct == GCT_INVALID || gct == GCT_WILD || gct == GCT_SEPARATOR)
563 {
564 lpszFileW[i]='-';
565 rc |= PCS_REPLACEDCHAR;
566 }
567 else
568 lpszFileW[i]=*p;
569 i++;
570 p++;
571 if (length + i == MAX_PATH)
572 {
573 rc |= PCS_FATAL | PCS_PATHTOOLONG;
574 break;
575 }
576 }
577 lpszFileW[i]=0;
578 }
579 else
580 {
581 LPSTR lpszFileA = (LPSTR)lpszFileW;
582 LPCSTR lpszPathA = (LPCSTR)lpszPathW;
583 LPSTR p = lpszFileA;
584
585 TRACE("Cleanup %s\n",debugstr_a(lpszFileA));
586
587 if (lpszPathA)
588 length = strlen(lpszPathA);
589
590 while (*p)
591 {
592 int gct = PathGetCharTypeA(*p);
593 if (gct == GCT_INVALID || gct == GCT_WILD || gct == GCT_SEPARATOR)
594 {
595 lpszFileA[i]='-';
596 rc |= PCS_REPLACEDCHAR;
597 }
598 else
599 lpszFileA[i]=*p;
600 i++;
601 p++;
602 if (length + i == MAX_PATH)
603 {
604 rc |= PCS_FATAL | PCS_PATHTOOLONG;
605 break;
606 }
607 }
608 lpszFileA[i]=0;
609 }
610 return rc;
611 }
612
613 /*************************************************************************
614 * PathQualifyA [SHELL32]
615 */
616 BOOL WINAPI PathQualifyA(LPCSTR pszPath)
617 {
618 FIXME("%s\n",pszPath);
619 return 0;
620 }
621
622 /*************************************************************************
623 * PathQualifyW [SHELL32]
624 */
625 BOOL WINAPI PathQualifyW(LPCWSTR pszPath)
626 {
627 FIXME("%s\n",debugstr_w(pszPath));
628 return 0;
629 }
630
631 /*************************************************************************
632 * PathQualify [SHELL32.49]
633 */
634 BOOL WINAPI PathQualifyAW(LPCVOID pszPath)
635 {
636 if (SHELL_OsIsUnicode())
637 return PathQualifyW(pszPath);
638 return PathQualifyA(pszPath);
639 }
640
641 /*************************************************************************
642 * PathResolveA [SHELL32.51]
643 */
644 BOOL WINAPI PathResolveA(
645 LPSTR lpszPath,
646 LPCSTR *alpszPaths,
647 DWORD dwFlags)
648 {
649 FIXME("(%s,%p,0x%08x),stub!\n",
650 lpszPath, *alpszPaths, dwFlags);
651 return 0;
652 }
653
654 /*************************************************************************
655 * PathResolveW [SHELL32]
656 */
657 BOOL WINAPI PathResolveW(
658 LPWSTR lpszPath,
659 LPCWSTR *alpszPaths,
660 DWORD dwFlags)
661 {
662 FIXME("(%s,%p,0x%08x),stub!\n",
663 debugstr_w(lpszPath), debugstr_w(*alpszPaths), dwFlags);
664 return 0;
665 }
666
667 /*************************************************************************
668 * PathResolve [SHELL32.51]
669 */
670 BOOL WINAPI PathResolveAW(
671 LPVOID lpszPath,
672 LPCVOID *alpszPaths,
673 DWORD dwFlags)
674 {
675 if (SHELL_OsIsUnicode())
676 return PathResolveW(lpszPath, (LPCWSTR*)alpszPaths, dwFlags);
677 return PathResolveA(lpszPath, (LPCSTR*)alpszPaths, dwFlags);
678 }
679
680 /*************************************************************************
681 * PathProcessCommandA [SHELL32.653]
682 */
683 LONG WINAPI PathProcessCommandA (
684 LPCSTR lpszPath,
685 LPSTR lpszBuff,
686 DWORD dwBuffSize,
687 DWORD dwFlags)
688 {
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);
694 }
695
696 /*************************************************************************
697 * PathProcessCommandW
698 */
699 LONG WINAPI PathProcessCommandW (
700 LPCWSTR lpszPath,
701 LPWSTR lpszBuff,
702 DWORD dwBuffSize,
703 DWORD dwFlags)
704 {
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);
710 }
711
712 /*************************************************************************
713 * PathProcessCommand (SHELL32.653)
714 */
715 LONG WINAPI PathProcessCommandAW (
716 LPCVOID lpszPath,
717 LPVOID lpszBuff,
718 DWORD dwBuffSize,
719 DWORD dwFlags)
720 {
721 if (SHELL_OsIsUnicode())
722 return PathProcessCommandW(lpszPath, lpszBuff, dwBuffSize, dwFlags);
723 return PathProcessCommandA(lpszPath, lpszBuff, dwBuffSize, dwFlags);
724 }
725
726 /*
727 ########## special ##########
728 */
729
730 /*************************************************************************
731 * PathSetDlgItemPath (SHELL32.48)
732 */
733 VOID WINAPI PathSetDlgItemPathAW(HWND hDlg, int id, LPCVOID pszPath)
734 {
735 if (SHELL_OsIsUnicode())
736 PathSetDlgItemPathW(hDlg, id, pszPath);
737 else
738 PathSetDlgItemPathA(hDlg, id, pszPath);
739 }
740
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.
789 */
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'};
792
793 typedef enum _CSIDL_Type {
794 CSIDL_Type_User,
795 CSIDL_Type_AllUsers,
796 CSIDL_Type_CurrVer,
797 CSIDL_Type_Disallowed,
798 CSIDL_Type_NonExistent,
799 CSIDL_Type_WindowsPath,
800 CSIDL_Type_SystemPath,
801 } CSIDL_Type;
802
803 typedef struct
804 {
805 CSIDL_Type type;
806 LPCWSTR szValueName;
807 LPCWSTR szDefaultPath; /* fallback string or resource ID */
808 } CSIDL_DATA;
809
810 static const CSIDL_DATA CSIDL_Data[] =
811 {
812 { /* 0x00 - CSIDL_DESKTOP */
813 CSIDL_Type_User,
814 DesktopW,
815 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY)
816 },
817 { /* 0x01 - CSIDL_INTERNET */
818 CSIDL_Type_Disallowed,
819 NULL,
820 NULL
821 },
822 { /* 0x02 - CSIDL_PROGRAMS */
823 CSIDL_Type_User,
824 ProgramsW,
825 MAKEINTRESOURCEW(IDS_PROGRAMS)
826 },
827 { /* 0x03 - CSIDL_CONTROLS (.CPL files) */
828 CSIDL_Type_SystemPath,
829 NULL,
830 NULL
831 },
832 { /* 0x04 - CSIDL_PRINTERS */
833 CSIDL_Type_SystemPath,
834 NULL,
835 NULL
836 },
837 { /* 0x05 - CSIDL_PERSONAL */
838 CSIDL_Type_User,
839 PersonalW,
840 MAKEINTRESOURCEW(IDS_PERSONAL)
841 },
842 { /* 0x06 - CSIDL_FAVORITES */
843 CSIDL_Type_User,
844 FavoritesW,
845 MAKEINTRESOURCEW(IDS_FAVORITES)
846 },
847 { /* 0x07 - CSIDL_STARTUP */
848 CSIDL_Type_User,
849 StartUpW,
850 MAKEINTRESOURCEW(IDS_STARTUP)
851 },
852 { /* 0x08 - CSIDL_RECENT */
853 CSIDL_Type_User,
854 RecentW,
855 MAKEINTRESOURCEW(IDS_RECENT)
856 },
857 { /* 0x09 - CSIDL_SENDTO */
858 CSIDL_Type_User,
859 SendToW,
860 MAKEINTRESOURCEW(IDS_SENDTO)
861 },
862 { /* 0x0a - CSIDL_BITBUCKET - Recycle Bin */
863 CSIDL_Type_Disallowed,
864 NULL,
865 NULL,
866 },
867 { /* 0x0b - CSIDL_STARTMENU */
868 CSIDL_Type_User,
869 Start_MenuW,
870 MAKEINTRESOURCEW(IDS_STARTMENU)
871 },
872 { /* 0x0c - CSIDL_MYDOCUMENTS */
873 CSIDL_Type_Disallowed, /* matches WinXP--can't get its path */
874 NULL,
875 NULL
876 },
877 { /* 0x0d - CSIDL_MYMUSIC */
878 CSIDL_Type_User,
879 My_MusicW,
880 MAKEINTRESOURCEW(IDS_MYMUSIC)
881 },
882 { /* 0x0e - CSIDL_MYVIDEO */
883 CSIDL_Type_User,
884 My_VideoW,
885 MAKEINTRESOURCEW(IDS_MYVIDEO)
886 },
887 { /* 0x0f - unassigned */
888 CSIDL_Type_Disallowed,
889 NULL,
890 NULL,
891 },
892 { /* 0x10 - CSIDL_DESKTOPDIRECTORY */
893 CSIDL_Type_User,
894 DesktopW,
895 MAKEINTRESOURCEW(IDS_DESKTOPDIRECTORY)
896 },
897 { /* 0x11 - CSIDL_DRIVES */
898 CSIDL_Type_Disallowed,
899 NULL,
900 NULL,
901 },
902 { /* 0x12 - CSIDL_NETWORK */
903 CSIDL_Type_Disallowed,
904 NULL,
905 NULL,
906 },
907 { /* 0x13 - CSIDL_NETHOOD */
908 CSIDL_Type_User,
909 NetHoodW,
910 MAKEINTRESOURCEW(IDS_NETHOOD)
911 },
912 { /* 0x14 - CSIDL_FONTS */
913 CSIDL_Type_WindowsPath,
914 FontsW,
915 FontsW
916 },
917 { /* 0x15 - CSIDL_TEMPLATES */
918 CSIDL_Type_User,
919 TemplatesW,
920 MAKEINTRESOURCEW(IDS_TEMPLATES)
921 },
922 { /* 0x16 - CSIDL_COMMON_STARTMENU */
923 CSIDL_Type_AllUsers,
924 Common_Start_MenuW,
925 MAKEINTRESOURCEW(IDS_STARTMENU)
926 },
927 { /* 0x17 - CSIDL_COMMON_PROGRAMS */
928 CSIDL_Type_AllUsers,
929 Common_ProgramsW,
930 MAKEINTRESOURCEW(IDS_PROGRAMS)
931 },
932 { /* 0x18 - CSIDL_COMMON_STARTUP */
933 CSIDL_Type_AllUsers,
934 Common_StartUpW,
935 MAKEINTRESOURCEW(IDS_STARTUP)
936 },
937 { /* 0x19 - CSIDL_COMMON_DESKTOPDIRECTORY */
938 CSIDL_Type_AllUsers,
939 Common_DesktopW,
940 MAKEINTRESOURCEW(IDS_DESKTOP)
941 },
942 { /* 0x1a - CSIDL_APPDATA */
943 CSIDL_Type_User,
944 AppDataW,
945 MAKEINTRESOURCEW(IDS_APPDATA)
946 },
947 { /* 0x1b - CSIDL_PRINTHOOD */
948 CSIDL_Type_User,
949 PrintHoodW,
950 MAKEINTRESOURCEW(IDS_PRINTHOOD)
951 },
952 { /* 0x1c - CSIDL_LOCAL_APPDATA */
953 CSIDL_Type_User,
954 Local_AppDataW,
955 MAKEINTRESOURCEW(IDS_LOCAL_APPDATA)
956 },
957 { /* 0x1d - CSIDL_ALTSTARTUP */
958 CSIDL_Type_NonExistent,
959 NULL,
960 NULL
961 },
962 { /* 0x1e - CSIDL_COMMON_ALTSTARTUP */
963 CSIDL_Type_NonExistent,
964 NULL,
965 NULL
966 },
967 { /* 0x1f - CSIDL_COMMON_FAVORITES */
968 CSIDL_Type_AllUsers,
969 FavoritesW,
970 MAKEINTRESOURCEW(IDS_FAVORITES)
971 },
972 { /* 0x20 - CSIDL_INTERNET_CACHE */
973 CSIDL_Type_User,
974 CacheW,
975 MAKEINTRESOURCEW(IDS_INTERNET_CACHE)
976 },
977 { /* 0x21 - CSIDL_COOKIES */
978 CSIDL_Type_User,
979 CookiesW,
980 MAKEINTRESOURCEW(IDS_COOKIES)
981 },
982 { /* 0x22 - CSIDL_HISTORY */
983 CSIDL_Type_User,
984 HistoryW,
985 MAKEINTRESOURCEW(IDS_HISTORY)
986 },
987 { /* 0x23 - CSIDL_COMMON_APPDATA */
988 CSIDL_Type_AllUsers,
989 Common_AppDataW,
990 MAKEINTRESOURCEW(IDS_APPDATA)
991 },
992 { /* 0x24 - CSIDL_WINDOWS */
993 CSIDL_Type_WindowsPath,
994 NULL,
995 NULL
996 },
997 { /* 0x25 - CSIDL_SYSTEM */
998 CSIDL_Type_SystemPath,
999 NULL,
1000 NULL
1001 },
1002 { /* 0x26 - CSIDL_PROGRAM_FILES */
1003 CSIDL_Type_CurrVer,
1004 ProgramFilesDirW,
1005 MAKEINTRESOURCEW(IDS_PROGRAM_FILES)
1006 },
1007 { /* 0x27 - CSIDL_MYPICTURES */
1008 CSIDL_Type_User,
1009 My_PicturesW,
1010 MAKEINTRESOURCEW(IDS_MYPICTURES)
1011 },
1012 { /* 0x28 - CSIDL_PROFILE */
1013 CSIDL_Type_User,
1014 NULL,
1015 NULL
1016 },
1017 { /* 0x29 - CSIDL_SYSTEMX86 */
1018 CSIDL_Type_NonExistent,
1019 NULL,
1020 NULL
1021 },
1022 { /* 0x2a - CSIDL_PROGRAM_FILESX86 */
1023 CSIDL_Type_NonExistent,
1024 NULL,
1025 NULL
1026 },
1027 { /* 0x2b - CSIDL_PROGRAM_FILES_COMMON */
1028 CSIDL_Type_CurrVer,
1029 CommonFilesDirW,
1030 MAKEINTRESOURCEW(IDS_PROGRAM_FILES_COMMON)
1031 },
1032 { /* 0x2c - CSIDL_PROGRAM_FILES_COMMONX86 */
1033 CSIDL_Type_NonExistent,
1034 NULL,
1035 NULL
1036 },
1037 { /* 0x2d - CSIDL_COMMON_TEMPLATES */
1038 CSIDL_Type_AllUsers,
1039 Common_TemplatesW,
1040 MAKEINTRESOURCEW(IDS_TEMPLATES)
1041 },
1042 { /* 0x2e - CSIDL_COMMON_DOCUMENTS */
1043 CSIDL_Type_AllUsers,
1044 Common_DocumentsW,
1045 MAKEINTRESOURCEW(IDS_COMMON_DOCUMENTS)
1046 },
1047 { /* 0x2f - CSIDL_COMMON_ADMINTOOLS */
1048 CSIDL_Type_AllUsers,
1049 Common_Administrative_ToolsW,
1050 MAKEINTRESOURCEW(IDS_ADMINTOOLS)
1051 },
1052 { /* 0x30 - CSIDL_ADMINTOOLS */
1053 CSIDL_Type_User,
1054 Administrative_ToolsW,
1055 MAKEINTRESOURCEW(IDS_ADMINTOOLS)
1056 },
1057 { /* 0x31 - CSIDL_CONNECTIONS */
1058 CSIDL_Type_Disallowed,
1059 NULL,
1060 NULL
1061 },
1062 { /* 0x32 - unassigned */
1063 CSIDL_Type_Disallowed,
1064 NULL,
1065 NULL
1066 },
1067 { /* 0x33 - unassigned */
1068 CSIDL_Type_Disallowed,
1069 NULL,
1070 NULL
1071 },
1072 { /* 0x34 - unassigned */
1073 CSIDL_Type_Disallowed,
1074 NULL,
1075 NULL
1076 },
1077 { /* 0x35 - CSIDL_COMMON_MUSIC */
1078 CSIDL_Type_AllUsers,
1079 CommonMusicW,
1080 MAKEINTRESOURCEW(IDS_COMMON_MUSIC)
1081 },
1082 { /* 0x36 - CSIDL_COMMON_PICTURES */
1083 CSIDL_Type_AllUsers,
1084 CommonPicturesW,
1085 MAKEINTRESOURCEW(IDS_COMMON_PICTURES)
1086 },
1087 { /* 0x37 - CSIDL_COMMON_VIDEO */
1088 CSIDL_Type_AllUsers,
1089 CommonVideoW,
1090 MAKEINTRESOURCEW(IDS_COMMON_VIDEO)
1091 },
1092 { /* 0x38 - CSIDL_RESOURCES */
1093 CSIDL_Type_WindowsPath,
1094 NULL,
1095 ResourcesW
1096 },
1097 { /* 0x39 - CSIDL_RESOURCES_LOCALIZED */
1098 CSIDL_Type_NonExistent,
1099 NULL,
1100 NULL
1101 },
1102 { /* 0x3a - CSIDL_COMMON_OEM_LINKS */
1103 CSIDL_Type_NonExistent,
1104 NULL,
1105 NULL
1106 },
1107 { /* 0x3b - CSIDL_CDBURN_AREA */
1108 CSIDL_Type_User,
1109 CD_BurningW,
1110 MAKEINTRESOURCEW(IDS_CDBURN_AREA)
1111 },
1112 { /* 0x3c unassigned */
1113 CSIDL_Type_Disallowed,
1114 NULL,
1115 NULL
1116 },
1117 { /* 0x3d - CSIDL_COMPUTERSNEARME */
1118 CSIDL_Type_Disallowed, /* FIXME */
1119 NULL,
1120 NULL
1121 },
1122 { /* 0x3e - CSIDL_PROFILES */
1123 CSIDL_Type_Disallowed, /* oddly, this matches WinXP */
1124 NULL,
1125 NULL
1126 }
1127 };
1128
1129 static HRESULT _SHExpandEnvironmentStrings(LPCWSTR szSrc, LPWSTR szDest);
1130
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.
1139 */
1140 static HRESULT _SHGetUserShellFolderPath(HKEY rootKey, LPCWSTR userPrefix,
1141 LPCWSTR value, LPWSTR path)
1142 {
1143 HRESULT hr;
1144 WCHAR shellFolderPath[MAX_PATH], userShellFolderPath[MAX_PATH];
1145 LPCWSTR pShellFolderPath, pUserShellFolderPath;
1146 DWORD dwDisp, dwType, dwPathLen = MAX_PATH;
1147 HKEY userShellFolderKey, shellFolderKey;
1148
1149 TRACE("%p,%s,%s,%p\n",rootKey, debugstr_w(userPrefix), debugstr_w(value),
1150 path);
1151
1152 if (userPrefix)
1153 {
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;
1162 }
1163 else
1164 {
1165 pUserShellFolderPath = szSHUserFolders;
1166 pShellFolderPath = szSHFolders;
1167 }
1168
1169 if (RegCreateKeyExW(rootKey, pShellFolderPath, 0, NULL, 0, KEY_ALL_ACCESS,
1170 NULL, &shellFolderKey, &dwDisp))
1171 {
1172 TRACE("Failed to create %s\n", debugstr_w(pShellFolderPath));
1173 return E_FAIL;
1174 }
1175 if (RegCreateKeyExW(rootKey, pUserShellFolderPath, 0, NULL, 0,
1176 KEY_ALL_ACCESS, NULL, &userShellFolderKey, &dwDisp))
1177 {
1178 TRACE("Failed to create %s\n",
1179 debugstr_w(pUserShellFolderPath));
1180 RegCloseKey(shellFolderKey);
1181 return E_FAIL;
1182 }
1183
1184 if (!RegQueryValueExW(userShellFolderKey, value, NULL, &dwType,
1185 (LPBYTE)path, &dwPathLen) && (dwType == REG_EXPAND_SZ || dwType == REG_SZ))
1186 {
1187 LONG ret;
1188
1189 path[dwPathLen / sizeof(WCHAR)] = '\0';
1190 if (dwType == REG_EXPAND_SZ && path[0] == '%')
1191 {
1192 WCHAR szTemp[MAX_PATH];
1193
1194 _SHExpandEnvironmentStrings(path, szTemp);
1195 lstrcpynW(path, szTemp, MAX_PATH);
1196 }
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);
1201 else
1202 hr = S_OK;
1203 }
1204 else
1205 hr = E_FAIL;
1206 RegCloseKey(shellFolderKey);
1207 RegCloseKey(userShellFolderKey);
1208 TRACE("returning 0x%08x\n", hr);
1209 return hr;
1210 }
1211
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
1216 * is written.
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.)
1225 */
1226 static HRESULT _SHGetDefaultValue(BYTE folder, LPWSTR pszPath)
1227 {
1228 HRESULT hr;
1229 WCHAR resourcePath[MAX_PATH];
1230 LPCWSTR pDefaultPath = NULL;
1231
1232 TRACE("0x%02x,%p\n", folder, pszPath);
1233
1234 if (folder >= sizeof(CSIDL_Data) / sizeof(CSIDL_Data[0]))
1235 return E_INVALIDARG;
1236 if (!pszPath)
1237 return E_INVALIDARG;
1238
1239 if (CSIDL_Data[folder].szDefaultPath &&
1240 IS_INTRESOURCE(CSIDL_Data[folder].szDefaultPath))
1241 {
1242 if (LoadStringW(shell32_hInstance,
1243 LOWORD(CSIDL_Data[folder].szDefaultPath), resourcePath, MAX_PATH))
1244 {
1245 hr = S_OK;
1246 pDefaultPath = resourcePath;
1247 }
1248 else
1249 {
1250 FIXME("(%d,%s), LoadString failed, missing translation?\n", folder,
1251 debugstr_w(pszPath));
1252 hr = E_FAIL;
1253 }
1254 }
1255 else
1256 {
1257 hr = S_OK;
1258 pDefaultPath = CSIDL_Data[folder].szDefaultPath;
1259 }
1260 if (SUCCEEDED(hr))
1261 {
1262 switch (CSIDL_Data[folder].type)
1263 {
1264 case CSIDL_Type_User:
1265 wcscpy(pszPath, UserProfileW);
1266 break;
1267 case CSIDL_Type_AllUsers:
1268 wcscpy(pszPath, AllUsersProfileW);
1269 break;
1270 case CSIDL_Type_CurrVer:
1271 wcscpy(pszPath, SystemDriveW);
1272 break;
1273 default:
1274 ; /* no corresponding env. var, do nothing */
1275 }
1276 if (pDefaultPath)
1277 {
1278 PathAddBackslashW(pszPath);
1279 wcscat(pszPath, pDefaultPath);
1280 }
1281 }
1282 TRACE("returning 0x%08x\n", hr);
1283 return hr;
1284 }
1285
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.
1291 */
1292 static HRESULT _SHGetCurrentVersionPath(DWORD dwFlags, BYTE folder,
1293 LPWSTR pszPath)
1294 {
1295 HRESULT hr;
1296
1297 TRACE("0x%08x,0x%02x,%p\n", dwFlags, folder, pszPath);
1298
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;
1303 if (!pszPath)
1304 return E_INVALIDARG;
1305
1306 if (dwFlags & SHGFP_TYPE_DEFAULT)
1307 hr = _SHGetDefaultValue(folder, pszPath);
1308 else
1309 {
1310 HKEY hKey;
1311 DWORD dwDisp;
1312
1313 if (RegCreateKeyExW(HKEY_LOCAL_MACHINE, szCurrentVersion, 0,
1314 NULL, 0, KEY_ALL_ACCESS, NULL, &hKey, &dwDisp))
1315 hr = E_FAIL;
1316 else
1317 {
1318 DWORD dwType, dwPathLen = MAX_PATH * sizeof(WCHAR);
1319
1320 if (RegQueryValueExW(hKey, CSIDL_Data[folder].szValueName, NULL,
1321 &dwType, (LPBYTE)pszPath, &dwPathLen) ||
1322 (dwType != REG_SZ && dwType != REG_EXPAND_SZ))
1323 {
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));
1328 }
1329 else
1330 {
1331 pszPath[dwPathLen / sizeof(WCHAR)] = '\0';
1332 hr = S_OK;
1333 }
1334 RegCloseKey(hKey);
1335 }
1336 }
1337 TRACE("returning 0x%08x (output path is %s)\n", hr, debugstr_w(pszPath));
1338 return hr;
1339 }
1340
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.
1348 */
1349 static HRESULT _SHGetUserProfilePath(HANDLE hToken, DWORD dwFlags, BYTE folder,
1350 LPWSTR pszPath)
1351 {
1352 HRESULT hr;
1353
1354 TRACE("%p,0x%08x,0x%02x,%p\n", hToken, dwFlags, folder, pszPath);
1355
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;
1360 if (!pszPath)
1361 return E_INVALIDARG;
1362
1363 /* Only the current user and the default user are supported right now
1364 * I'm afraid.
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
1369 * user name).
1370 */
1371 if (hToken != NULL && hToken != (HANDLE)-1)
1372 {
1373 FIXME("unsupported for user other than current or default\n");
1374 return E_FAIL;
1375 }
1376
1377 if (dwFlags & SHGFP_TYPE_DEFAULT)
1378 hr = _SHGetDefaultValue(folder, pszPath);
1379 else
1380 {
1381 LPCWSTR userPrefix = NULL;
1382 HKEY hRootKey;
1383
1384 if (hToken == (HANDLE)-1)
1385 {
1386 hRootKey = HKEY_USERS;
1387 userPrefix = DefaultW;
1388 }
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);
1396 if (FAILED(hr))
1397 hr = _SHGetDefaultValue(folder, pszPath);
1398 }
1399 TRACE("returning 0x%08x (output path is %s)\n", hr, debugstr_w(pszPath));
1400 return hr;
1401 }
1402
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.
1407 */
1408 static HRESULT _SHGetAllUsersProfilePath(DWORD dwFlags, BYTE folder,
1409 LPWSTR pszPath)
1410 {
1411 HRESULT hr;
1412
1413 TRACE("0x%08x,0x%02x,%p\n", dwFlags, folder, pszPath);
1414
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;
1419 if (!pszPath)
1420 return E_INVALIDARG;
1421
1422 if (dwFlags & SHGFP_TYPE_DEFAULT)
1423 hr = _SHGetDefaultValue(folder, pszPath);
1424 else
1425 {
1426 hr = _SHGetUserShellFolderPath(HKEY_LOCAL_MACHINE, NULL,
1427 CSIDL_Data[folder].szValueName, pszPath);
1428 if (FAILED(hr))
1429 hr = _SHGetDefaultValue(folder, pszPath);
1430 }
1431 TRACE("returning 0x%08x (output path is %s)\n", hr, debugstr_w(pszPath));
1432 return hr;
1433 }
1434
1435 static HRESULT _SHOpenProfilesKey(PHKEY pKey)
1436 {
1437 LONG lRet;
1438 DWORD disp;
1439
1440 lRet = RegCreateKeyExW(HKEY_LOCAL_MACHINE, ProfileListW, 0, NULL, 0,
1441 KEY_ALL_ACCESS, NULL, pKey, &disp);
1442 return HRESULT_FROM_WIN32(lRet);
1443 }
1444
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).
1449 */
1450 static HRESULT _SHGetProfilesValue(HKEY profilesKey, LPCWSTR szValueName,
1451 LPWSTR szValue, LPCWSTR szDefault)
1452 {
1453 HRESULT hr;
1454 DWORD type, dwPathLen = MAX_PATH * sizeof(WCHAR);
1455 LONG lRet;
1456
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
1462 && *szValue)
1463 {
1464 dwPathLen /= sizeof(WCHAR);
1465 szValue[dwPathLen] = '\0';
1466 hr = S_OK;
1467 }
1468 else
1469 {
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,
1475 (LPBYTE)szValue,
1476 (wcslen(szValue) + 1) * sizeof(WCHAR));
1477 if (lRet)
1478 hr = HRESULT_FROM_WIN32(lRet);
1479 else
1480 hr = S_OK;
1481 }
1482 TRACE("returning 0x%08x (output value is %s)\n", hr, debugstr_w(szValue));
1483 return hr;
1484 }
1485
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
1494 * path
1495 * If one of the directly handled environment variables is expanded, only
1496 * expands a single variable, and only in the beginning of szSrc.
1497 */
1498 static HRESULT _SHExpandEnvironmentStrings(LPCWSTR szSrc, LPWSTR szDest)
1499 {
1500 HRESULT hr;
1501 WCHAR szTemp[MAX_PATH], szProfilesPrefix[MAX_PATH] = { 0 };
1502 HKEY key = NULL;
1503
1504 TRACE("%s, %p\n", debugstr_w(szSrc), szDest);
1505
1506 if (!szSrc || !szDest) return E_INVALIDARG;
1507
1508 /* short-circuit if there's nothing to expand */
1509 if (szSrc[0] != '%')
1510 {
1511 wcscpy(szDest, szSrc);
1512 hr = S_OK;
1513 goto end;
1514 }
1515 /* Get the profile prefix, we'll probably be needing it */
1516 hr = _SHOpenProfilesKey(&key);
1517 if (SUCCEEDED(hr))
1518 {
1519 WCHAR szDefaultProfilesPrefix[MAX_PATH];
1520
1521 GetWindowsDirectoryW(szDefaultProfilesPrefix, MAX_PATH);
1522 PathAddBackslashW(szDefaultProfilesPrefix);
1523 PathAppendW(szDefaultProfilesPrefix, szDefaultProfileDirW);
1524 hr = _SHGetProfilesValue(key, ProfilesDirectoryW, szProfilesPrefix,
1525 szDefaultProfilesPrefix);
1526 }
1527
1528 *szDest = 0;
1529 wcscpy(szTemp, szSrc);
1530 while (SUCCEEDED(hr) && szTemp[0] == '%')
1531 {
1532 if (!strncmpiW(szTemp, AllUsersProfileW, wcslen(AllUsersProfileW)))
1533 {
1534 WCHAR szAllUsers[MAX_PATH];
1535
1536 wcscpy(szDest, szProfilesPrefix);
1537 hr = _SHGetProfilesValue(key, AllUsersProfileValueW,
1538 szAllUsers, AllUsersW);
1539 PathAppendW(szDest, szAllUsers);
1540 PathAppendW(szDest, szTemp + wcslen(AllUsersProfileW));
1541 }
1542 else if (!strncmpiW(szTemp, UserProfileW, wcslen(UserProfileW)))
1543 {
1544 WCHAR userName[MAX_PATH];
1545 DWORD userLen = MAX_PATH;
1546
1547 wcscpy(szDest, szProfilesPrefix);
1548 GetUserNameW(userName, &userLen);
1549 PathAppendW(szDest, userName);
1550 PathAppendW(szDest, szTemp + wcslen(UserProfileW));
1551 }
1552 else if (!strncmpiW(szTemp, SystemDriveW, wcslen(SystemDriveW)))
1553 {
1554 GetSystemDirectoryW(szDest, MAX_PATH);
1555 if (szDest[1] != ':')
1556 {
1557 FIXME("non-drive system paths unsupported\n");
1558 hr = E_FAIL;
1559 }
1560 else
1561 {
1562 wcscpy(szDest + 3, szTemp + wcslen(SystemDriveW) + 1);
1563 hr = S_OK;
1564 }
1565 }
1566 else
1567 {
1568 DWORD ret = ExpandEnvironmentStringsW(szSrc, szDest, MAX_PATH);
1569
1570 if (ret > MAX_PATH)
1571 hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
1572 else if (ret == 0)
1573 hr = HRESULT_FROM_WIN32(GetLastError());
1574 else
1575 hr = S_OK;
1576 }
1577 if (SUCCEEDED(hr) && szDest[0] == '%')
1578 wcscpy(szTemp, szDest);
1579 else
1580 {
1581 /* terminate loop */
1582 szTemp[0] = '\0';
1583 }
1584 }
1585 end:
1586 if (key)
1587 RegCloseKey(key);
1588 TRACE("returning 0x%08x (input was %s, output is %s)\n", hr,
1589 debugstr_w(szSrc), debugstr_w(szDest));
1590 return hr;
1591 }
1592
1593 /*************************************************************************
1594 * SHGetFolderPathW [SHELL32.@]
1595 *
1596 * Convert nFolder to path.
1597 *
1598 * RETURNS
1599 * Success: S_OK
1600 * Failure: standard HRESULT error codes.
1601 *
1602 * NOTES
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.
1612 */
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 */
1619 {
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);
1623 return hr;
1624 }
1625
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 */
1633 {
1634 int length;
1635 HRESULT hr = S_OK;
1636 LPWSTR pszSubPathW = NULL;
1637 LPWSTR pszPathW = NULL;
1638 TRACE("%08x,%08x,%s\n",nFolder, dwFlags, debugstr_w(pszSubPathW));
1639
1640 if(pszPath) {
1641 pszPathW = HeapAlloc(GetProcessHeap(), 0, MAX_PATH * sizeof(WCHAR));
1642 if(!pszPathW) {
1643 hr = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
1644 goto cleanup;
1645 }
1646 }
1647 TRACE("%08x,%08x,%s\n",nFolder, dwFlags, debugstr_w(pszSubPathW));
1648
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
1652 */
1653 if (pszSubPath && pszSubPath[0]) {
1654 length = MultiByteToWideChar(CP_ACP, 0, pszSubPath, -1, NULL, 0);
1655 pszSubPathW = HeapAlloc(GetProcessHeap(), 0, length * sizeof(WCHAR));
1656 if(!pszSubPathW) {
1657 hr = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
1658 goto cleanup;
1659 }
1660 MultiByteToWideChar(CP_ACP, 0, pszSubPath, -1, pszSubPathW, length);
1661 }
1662
1663 hr = SHGetFolderPathAndSubDirW(hwndOwner, nFolder, hToken, dwFlags, pszSubPathW, pszPathW);
1664
1665 if (SUCCEEDED(hr) && pszPath)
1666 WideCharToMultiByte(CP_ACP, 0, pszPathW, -1, pszPath, MAX_PATH, NULL, NULL);
1667
1668 cleanup:
1669 HeapFree(GetProcessHeap(), 0, pszPathW);
1670 HeapFree(GetProcessHeap(), 0, pszSubPathW);
1671 return hr;
1672 }
1673
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 */
1681 {
1682 HRESULT hr;
1683 WCHAR szBuildPath[MAX_PATH], szTemp[MAX_PATH];
1684 DWORD folder = nFolder & CSIDL_FOLDER_MASK; //FIXME
1685 CSIDL_Type type;
1686 int ret;
1687
1688 TRACE("%p,%p,nFolder=0x%04x,%s\n", hwndOwner,pszPath,nFolder,debugstr_w(pszSubPath));
1689
1690 /* Windows always NULL-terminates the resulting path regardless of success
1691 * or failure, so do so first
1692 */
1693 if (pszPath)
1694 *pszPath = '\0';
1695
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;
1700 szTemp[0] = 0;
1701 type = CSIDL_Data[folder].type;
1702 switch (type)
1703 {
1704 case CSIDL_Type_Disallowed:
1705 hr = E_INVALIDARG;
1706 break;
1707 case CSIDL_Type_NonExistent:
1708 hr = S_FALSE;
1709 break;
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)
1715 {
1716 PathAddBackslashW(szTemp);
1717 wcscat(szTemp, CSIDL_Data[folder].szDefaultPath);
1718 }
1719 hr = S_OK;
1720 break;
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)
1726 {
1727 PathAddBackslashW(szTemp);
1728 wcscat(szTemp, CSIDL_Data[folder].szDefaultPath);
1729 }
1730 hr = S_OK;
1731 break;
1732 case CSIDL_Type_CurrVer:
1733 hr = _SHGetCurrentVersionPath(dwFlags, folder, szTemp);
1734 break;
1735 case CSIDL_Type_User:
1736 hr = _SHGetUserProfilePath(hToken, dwFlags, folder, szTemp);
1737 break;
1738 case CSIDL_Type_AllUsers:
1739 hr = _SHGetAllUsersProfilePath(dwFlags, folder, szTemp);
1740 break;
1741 default:
1742 FIXME("bogus type %d, please fix\n", type);
1743 hr = E_INVALIDARG;
1744 break;
1745 }
1746
1747 /* Expand environment strings if necessary */
1748 if (*szTemp == '%')
1749 hr = _SHExpandEnvironmentStrings(szTemp, szBuildPath);
1750 else
1751 wcscpy(szBuildPath, szTemp);
1752
1753 if (FAILED(hr)) goto end;
1754
1755 if(pszSubPath) {
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);
1760 goto end;
1761 }
1762 PathAppendW(szBuildPath, pszSubPath);
1763 PathRemoveBackslashW(szBuildPath);
1764 }
1765 /* Copy the path if it's available before we might return */
1766 if (SUCCEEDED(hr) && pszPath)
1767 wcscpy(pszPath, szBuildPath);
1768
1769 /* if we don't care about existing directories we are ready */
1770 if(nFolder & CSIDL_FLAG_DONT_VERIFY) goto end;
1771
1772 if (PathFileExistsW(szBuildPath)) goto end;
1773
1774 /* not existing but we are not allowed to create it. The return value
1775 * is verified against shell32 version 6.0.
1776 */
1777 if (!(nFolder & CSIDL_FLAG_CREATE))
1778 {
1779 hr = HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND);
1780 goto end;
1781 }
1782
1783 /* create directory/directories */
1784 ret = SHCreateDirectoryExW(hwndOwner, szBuildPath, NULL);
1785 if (ret && ret != ERROR_ALREADY_EXISTS)
1786 {
1787 ERR("Failed to create directory %s.\n", debugstr_w(szBuildPath));
1788 hr = E_FAIL;
1789 goto end;
1790 }
1791
1792 TRACE("Created missing system directory %s\n", debugstr_w(szBuildPath));
1793 end:
1794 TRACE("returning 0x%08x (final path is %s)\n", hr, debugstr_w(szBuildPath));
1795 return hr;
1796 }
1797
1798 /*************************************************************************
1799 * SHGetFolderPathA [SHELL32.@]
1800 *
1801 * See SHGetFolderPathW.
1802 */
1803 HRESULT WINAPI SHGetFolderPathA(
1804 HWND hwndOwner,
1805 int nFolder,
1806 HANDLE hToken,
1807 DWORD dwFlags,
1808 LPSTR pszPath)
1809 {
1810 WCHAR szTemp[MAX_PATH];
1811 HRESULT hr;
1812
1813 TRACE("%p,%p,nFolder=0x%04x\n",hwndOwner,pszPath,nFolder);
1814
1815 if (pszPath)
1816 *pszPath = '\0';
1817 hr = SHGetFolderPathW(hwndOwner, nFolder, hToken, dwFlags, szTemp);
1818 if (SUCCEEDED(hr) && pszPath)
1819 WideCharToMultiByte(CP_ACP, 0, szTemp, -1, pszPath, MAX_PATH, NULL,
1820 NULL);
1821
1822 return hr;
1823 }
1824
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.
1832 */
1833 static HRESULT _SHRegisterFolders(HKEY hRootKey, HANDLE hToken,
1834 LPCWSTR szUserShellFolderPath, LPCWSTR szShellFolderPath, const UINT folders[],
1835 UINT foldersLen)
1836 {
1837 UINT i;
1838 WCHAR path[MAX_PATH];
1839 HRESULT hr = S_OK;
1840 HKEY hUserKey = NULL, hKey = NULL;
1841 DWORD dwDisp, dwType, dwPathLen;
1842 LONG ret;
1843
1844 TRACE("%p,%p,%s,%p,%u\n", hRootKey, hToken,
1845 debugstr_w(szUserShellFolderPath), folders, foldersLen);
1846
1847 ret = RegCreateKeyExW(hRootKey, szUserShellFolderPath, 0, NULL, 0,
1848 KEY_ALL_ACCESS, NULL, &hUserKey, &dwDisp);
1849 if (ret)
1850 hr = HRESULT_FROM_WIN32(ret);
1851 else
1852 {
1853 ret = RegCreateKeyExW(hRootKey, szShellFolderPath, 0, NULL, 0,
1854 KEY_ALL_ACCESS, NULL, &hKey, &dwDisp);
1855 if (ret)
1856 hr = HRESULT_FROM_WIN32(ret);
1857 }
1858 for (i = 0; SUCCEEDED(hr) && i < foldersLen; i++)
1859 {
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))
1864 {
1865 *path = '\0';
1866 if (CSIDL_Data[folders[i]].type == CSIDL_Type_User)
1867 _SHGetUserProfilePath(hToken, SHGFP_TYPE_DEFAULT, folders[i],
1868 path);
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);
1873 else
1874 hr = E_FAIL;
1875 if (*path)
1876 {
1877 ret = RegSetValueExW(hUserKey,
1878 CSIDL_Data[folders[i]].szValueName, 0, REG_EXPAND_SZ,
1879 (LPBYTE)path, (wcslen(path) + 1) * sizeof(WCHAR));
1880 if (ret)
1881 hr = HRESULT_FROM_WIN32(ret);
1882 else
1883 {
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));
1889 if (ret)
1890 hr = HRESULT_FROM_WIN32(ret);
1891 }
1892 }
1893 }
1894 }
1895 if (hUserKey)
1896 RegCloseKey(hUserKey);
1897 if (hKey)
1898 RegCloseKey(hKey);
1899
1900 TRACE("returning 0x%08x\n", hr);
1901 return hr;
1902 }
1903
1904 static HRESULT _SHRegisterUserShellFolders(BOOL bDefault)
1905 {
1906 static const UINT folders[] = {
1907 CSIDL_PROGRAMS,
1908 CSIDL_PERSONAL,
1909 CSIDL_FAVORITES,
1910 CSIDL_APPDATA,
1911 CSIDL_STARTUP,
1912 CSIDL_RECENT,
1913 CSIDL_SENDTO,
1914 CSIDL_STARTMENU,
1915 CSIDL_MYMUSIC,
1916 CSIDL_MYVIDEO,
1917 CSIDL_DESKTOPDIRECTORY,
1918 CSIDL_NETHOOD,
1919 CSIDL_TEMPLATES,
1920 CSIDL_PRINTHOOD,
1921 CSIDL_LOCAL_APPDATA,
1922 CSIDL_INTERNET_CACHE,
1923 CSIDL_COOKIES,
1924 CSIDL_HISTORY,
1925 CSIDL_MYPICTURES,
1926 CSIDL_FONTS
1927 };
1928 WCHAR userShellFolderPath[MAX_PATH], shellFolderPath[MAX_PATH];
1929 LPCWSTR pUserShellFolderPath, pShellFolderPath;
1930 HRESULT hr = S_OK;
1931 HKEY hRootKey;
1932 HANDLE hToken;
1933
1934 TRACE("%s\n", bDefault ? "TRUE" : "FALSE");
1935 if (bDefault)
1936 {
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;
1947 }
1948 else
1949 {
1950 hToken = NULL;
1951 hRootKey = HKEY_CURRENT_USER;
1952 pUserShellFolderPath = szSHUserFolders;
1953 pShellFolderPath = szSHFolders;
1954 }
1955
1956 hr = _SHRegisterFolders(hRootKey, hToken, pUserShellFolderPath,
1957 pShellFolderPath, folders, sizeof(folders) / sizeof(folders[0]));
1958 TRACE("returning 0x%08x\n", hr);
1959 return hr;
1960 }
1961
1962 static HRESULT _SHRegisterCommonShellFolders(void)
1963 {
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,
1973 };
1974 HRESULT hr;
1975
1976 TRACE("\n");
1977 hr = _SHRegisterFolders(HKEY_LOCAL_MACHINE, NULL, szSHUserFolders,
1978 szSHFolders, folders, sizeof(folders) / sizeof(folders[0]));
1979 TRACE("returning 0x%08x\n", hr);
1980 return hr;
1981 }
1982
1983 /******************************************************************************
1984 * _SHAppendToUnixPath [Internal]
1985 *
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.
1989 *
1990 * PARAMS
1991 * szBasePath [IO] The unix base path, which will be appended to (CP_UNXICP).
1992 * pwszSubPath [I] Sub-path or resource id (use MAKEINTRESOURCEW).
1993 *
1994 * RETURNS
1995 * Success: TRUE,
1996 * Failure: FALSE
1997 */
1998 static BOOL __inline _SHAppendToUnixPath(char *szBasePath, LPCWSTR pwszSubPath) {
1999 WCHAR wszSubPath[MAX_PATH];
2000 int cLen = strlen(szBasePath);
2001 char *pBackslash;
2002
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)) {
2007 case IDS_PERSONAL:
2008 wcscpy(wszSubPath, PersonalW);
2009 break;
2010 case IDS_MYMUSIC:
2011 wcscpy(wszSubPath, My_MusicW);
2012 break;
2013 case IDS_MYPICTURES:
2014 wcscpy(wszSubPath, My_PicturesW);
2015 break;
2016 case IDS_MYVIDEO:
2017 wcscpy(wszSubPath, My_VideoW);
2018 break;
2019 default:
2020 ERR("LoadString(%d) failed!\n", LOWORD(pwszSubPath));
2021 return FALSE;
2022 }
2023 }
2024 } else {
2025 wcscpy(wszSubPath, pwszSubPath);
2026 }
2027
2028 if (szBasePath[cLen-1] != '/') szBasePath[cLen++] = '/';
2029
2030 if (!WideCharToMultiByte(CP_ACP, 0, wszSubPath, -1, szBasePath + cLen,
2031 FILENAME_MAX - cLen, NULL, NULL))
2032 {
2033 return FALSE;
2034 }
2035
2036 pBackslash = szBasePath + cLen;
2037 while ((pBackslash = strchr(pBackslash, '\\'))) *pBackslash = '/';
2038
2039 return TRUE;
2040 }
2041 #if 0
2042 /******************************************************************************
2043 * _SHCreateSymbolicLinks [Internal]
2044 *
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,
2052 * too.
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))
2062 */
2063 static void _SHCreateSymbolicLinks(void)
2064 {
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;
2073 HRESULT hr;
2074
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;
2081
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))
2087 {
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);
2094 }
2095 }
2096 else
2097 {
2098 /* '$HOME/My Documents' doesn't exists, but '$HOME' does. */
2099 strcpy(szPersonalTarget, pszHome);
2100 }
2101
2102 /* Replace 'My Documents' directory with a symlink of fail silently if not empty. */
2103 rmdir(pszPersonal);
2104 symlink(szPersonalTarget, pszPersonal);
2105 }
2106 else
2107 {
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);
2115 }
2116 }
2117
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;
2126
2127 strcpy(szMyStuffTarget, szPersonalTarget);
2128 if (_SHAppendToUnixPath(szMyStuffTarget, MAKEINTRESOURCEW(aidsMyStuff[i])) &&
2129 !stat(szMyStuffTarget, &statFolder) && S_ISDIR(statFolder.st_mode))
2130 {
2131 /* If there's a 'My Whatever' directory where 'My Documents' links to, link to it. */
2132 rmdir(pszMyStuff);
2133 symlink(szMyStuffTarget, pszMyStuff);
2134 }
2135 else
2136 {
2137 /* Else link to where 'My Documents' itself links to. */
2138 rmdir(pszMyStuff);
2139 symlink(szPersonalTarget, pszMyStuff);
2140 }
2141 HeapFree(GetProcessHeap(), 0, pszMyStuff);
2142 }
2143
2144 /* Last but not least, the Desktop folder */
2145 if (pszHome)
2146 strcpy(szDesktopTarget, pszHome);
2147 else
2148 strcpy(szDesktopTarget, pszPersonal);
2149 HeapFree(GetProcessHeap(), 0, pszPersonal);
2150
2151 if (_SHAppendToUnixPath(szDesktopTarget, DesktopW) &&
2152 !stat(szDesktopTarget, &statFolder) && S_ISDIR(statFolder.st_mode))
2153 {
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)))
2157 {
2158 rmdir(pszDesktop);
2159 symlink(szDesktopTarget, pszDesktop);
2160 HeapFree(GetProcessHeap(), 0, pszDesktop);
2161 }
2162 }
2163 }
2164 #endif
2165
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.
2168 */
2169 HRESULT SHELL_RegisterShellFolders(void)
2170 {
2171 HRESULT hr;
2172
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. */
2177 #if 0
2178 _SHCreateSymbolicLinks();
2179 #endif
2180
2181 hr = _SHRegisterUserShellFolders(TRUE);
2182 if (SUCCEEDED(hr))
2183 hr = _SHRegisterUserShellFolders(FALSE);
2184 if (SUCCEEDED(hr))
2185 hr = _SHRegisterCommonShellFolders();
2186 return hr;
2187 }
2188
2189 /*************************************************************************
2190 * SHGetSpecialFolderPathA [SHELL32.@]
2191 */
2192 BOOL WINAPI SHGetSpecialFolderPathA (
2193 HWND hwndOwner,
2194 LPSTR szPath,
2195 int nFolder,
2196 BOOL bCreate)
2197 {
2198 return (SHGetFolderPathA(
2199 hwndOwner,
2200 nFolder + (bCreate ? CSIDL_FLAG_CREATE : 0),
2201 NULL,
2202 0,
2203 szPath)) == S_OK ? TRUE : FALSE;
2204 }
2205
2206 /*************************************************************************
2207 * SHGetSpecialFolderPathW
2208 */
2209 BOOL WINAPI SHGetSpecialFolderPathW (
2210 HWND hwndOwner,
2211 LPWSTR szPath,
2212 int nFolder,
2213 BOOL bCreate)
2214 {
2215 return (SHGetFolderPathW(
2216 hwndOwner,
2217 nFolder + (bCreate ? CSIDL_FLAG_CREATE : 0),
2218 NULL,
2219 0,
2220 szPath)) == S_OK ? TRUE : FALSE;
2221 }
2222
2223 /*************************************************************************
2224 * SHGetSpecialFolderPath (SHELL32.175)
2225 */
2226 BOOL WINAPI SHGetSpecialFolderPathAW (
2227 HWND hwndOwner,
2228 LPVOID szPath,
2229 int nFolder,
2230 BOOL bCreate)
2231
2232 {
2233 if (SHELL_OsIsUnicode())
2234 return SHGetSpecialFolderPathW (hwndOwner, szPath, nFolder, bCreate);
2235 return SHGetSpecialFolderPathA (hwndOwner, szPath, nFolder, bCreate);
2236 }
2237
2238 /*************************************************************************
2239 * SHGetFolderLocation [SHELL32.@]
2240 *
2241 * Gets the folder locations from the registry and creates a pidl.
2242 *
2243 * PARAMS
2244 * hwndOwner [I]
2245 * nFolder [I] CSIDL_xxxxx
2246 * hToken [I] token representing user, or NULL for current user, or -1 for
2247 * default user
2248 * dwReserved [I] must be zero
2249 * ppidl [O] PIDL of a special folder
2250 *
2251 * RETURNS
2252 * Success: S_OK
2253 * Failure: Standard OLE-defined error result, S_FALSE or E_INVALIDARG
2254 *
2255 * NOTES
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.
2259 */
2260 HRESULT WINAPI SHGetFolderLocation(
2261 HWND hwndOwner,
2262 int nFolder,
2263 HANDLE hToken,
2264 DWORD dwReserved,
2265 LPITEMIDLIST *ppidl)
2266 {
2267 HRESULT hr = E_INVALIDARG;
2268
2269 TRACE("%p 0x%08x %p 0x%08x %p\n",
2270 hwndOwner, nFolder, hToken, dwReserved, ppidl);
2271
2272 if (!ppidl)
2273 return E_INVALIDARG;
2274 if (dwReserved)
2275 return E_INVALIDARG;
2276
2277 /* The virtual folders' locations are not user-dependent */
2278 *ppidl = NULL;
2279 switch (nFolder)
2280 {
2281 case CSIDL_DESKTOP:
2282 *ppidl = _ILCreateDesktop();
2283 break;
2284
2285 case CSIDL_PERSONAL:
2286 *ppidl = _ILCreateMyDocuments();
2287 break;
2288
2289 case CSIDL_INTERNET:
2290 *ppidl = _ILCreateIExplore();
2291 break;
2292
2293 case CSIDL_CONTROLS:
2294 *ppidl = _ILCreateControlPanel();
2295 break;
2296
2297 case CSIDL_PRINTERS:
2298 *ppidl = _ILCreatePrinters();
2299 break;
2300
2301 case CSIDL_BITBUCKET:
2302 *ppidl = _ILCreateBitBucket();
2303 break;
2304
2305 case CSIDL_DRIVES:
2306 *ppidl = _ILCreateMyComputer();
2307 break;
2308
2309 case CSIDL_NETWORK:
2310 *ppidl = _ILCreateNetwork();
2311 break;
2312
2313 default:
2314 {
2315 WCHAR szPath[MAX_PATH];
2316
2317 hr = SHGetFolderPathW(hwndOwner, nFolder, hToken,
2318 SHGFP_TYPE_CURRENT, szPath);
2319 if (SUCCEEDED(hr))
2320 {
2321 DWORD attributes=0;
2322
2323 TRACE("Value=%s\n", debugstr_w(szPath));
2324 hr = SHILCreateFromPathW(szPath, ppidl, &attributes);
2325 }
2326 else if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
2327 {
2328 /* unlike SHGetFolderPath, SHGetFolderLocation in shell32
2329 * version 6.0 returns E_FAIL for nonexistent paths
2330 */
2331 hr = E_FAIL;
2332 }
2333 }
2334 }
2335 if(*ppidl)
2336 hr = NOERROR;
2337
2338 TRACE("-- (new pidl %p)\n",*ppidl);
2339 return hr;
2340 }
2341
2342 /*************************************************************************
2343 * SHGetSpecialFolderLocation [SHELL32.@]
2344 *
2345 * NOTES
2346 * In NT5, SHGetSpecialFolderLocation needs the <winntdir>/Recent
2347 * directory.
2348 */
2349 HRESULT WINAPI SHGetSpecialFolderLocation(
2350 HWND hwndOwner,
2351 INT nFolder,
2352 LPITEMIDLIST * ppidl)
2353 {
2354 HRESULT hr = E_INVALIDARG;
2355
2356 TRACE("(%p,0x%x,%p)\n", hwndOwner,nFolder,ppidl);
2357
2358 if (!ppidl)
2359 return E_INVALIDARG;
2360
2361 hr = SHGetFolderLocation(hwndOwner, nFolder, NULL, 0, ppidl);
2362 return hr;
2363 }