source: trunk/src/shell32/shellpath.c@ 4121

Last change on this file since 4121 was 4121, checked in by sandervl, 25 years ago

complete merge with shell32 from wine 20000801

File size: 23.2 KB
Line 
1/* $Id: shellpath.c,v 1.2 2000-08-30 13:51:02 sandervl Exp $ */
2/*
3 * Path Functions
4 *
5 * Many of this functions are in SHLWAPI.DLL also
6 *
7 */
8#ifdef __WIN32OS2__
9#define ICOM_CINTERFACE 1
10#include <odin.h>
11#endif
12#include <string.h>
13#include <ctype.h>
14#include "debugtools.h"
15#include "winnls.h"
16#include "winreg.h"
17
18#include "shlobj.h"
19#include "shell32_main.h"
20#include "windef.h"
21#include "options.h"
22#include "wine/undocshell.h"
23#include "wine/unicode.h"
24#include "shlwapi.h"
25
26DEFAULT_DEBUG_CHANNEL(shell);
27
28#define isSlash(x) ((x)=='\\' || (x)=='/')
29/*
30 ########## Combining and Constructing paths ##########
31*/
32
33/*************************************************************************
34 * PathAppendAW [SHELL32.36]
35 */
36BOOL WINAPI PathAppendAW(
37 LPVOID lpszPath1,
38 LPCVOID lpszPath2)
39{
40 if (SHELL_OsIsUnicode())
41 return PathAppendW(lpszPath1, lpszPath2);
42 return PathAppendA(lpszPath1, lpszPath2);
43}
44
45/*************************************************************************
46 * PathCombineAW [SHELL32.37]
47 */
48LPVOID WINAPI PathCombineAW(
49 LPVOID szDest,
50 LPCVOID lpszDir,
51 LPCVOID lpszFile)
52{
53 if (SHELL_OsIsUnicode())
54 return PathCombineW( szDest, lpszDir, lpszFile );
55 return PathCombineA( szDest, lpszDir, lpszFile );
56}
57
58/*************************************************************************
59 * PathAddBackslashAW [SHELL32.32]
60 */
61LPVOID WINAPI PathAddBackslashAW(LPVOID lpszPath)
62{
63 if(SHELL_OsIsUnicode())
64 return PathAddBackslashW(lpszPath);
65 return PathAddBackslashA(lpszPath);
66}
67
68/*************************************************************************
69 * PathBuildRootAW [SHELL32.30]
70 */
71LPVOID WINAPI PathBuildRootAW(LPVOID lpszPath, int drive)
72{
73 if(SHELL_OsIsUnicode())
74 return PathBuildRootW(lpszPath, drive);
75 return PathBuildRootA(lpszPath, drive);
76}
77
78/*
79 Extracting Component Parts
80*/
81
82/*************************************************************************
83 * PathFindFileNameAW [SHELL32.34]
84 */
85LPVOID WINAPI PathFindFileNameAW(LPCVOID lpszPath)
86{
87 if(SHELL_OsIsUnicode())
88 return PathFindFileNameW(lpszPath);
89 return PathFindFileNameA(lpszPath);
90}
91
92/*************************************************************************
93 * PathFindExtensionAW [SHELL32.31]
94 */
95LPVOID WINAPI PathFindExtensionAW(LPCVOID lpszPath)
96{
97 if (SHELL_OsIsUnicode())
98 return PathFindExtensionW(lpszPath);
99 return PathFindExtensionA(lpszPath);
100
101}
102
103/*************************************************************************
104 * PathGetExtensionA [internal]
105 *
106 * NOTES
107 * exported by ordinal
108 * return value points to the first char after the dot
109 */
110static LPSTR PathGetExtensionA(LPCSTR lpszPath)
111{
112 TRACE("(%s)\n",lpszPath);
113
114 lpszPath = PathFindExtensionA(lpszPath);
115 return (LPSTR)(*lpszPath?(lpszPath+1):lpszPath);
116}
117
118/*************************************************************************
119 * PathGetExtensionW [internal]
120 */
121static LPWSTR PathGetExtensionW(LPCWSTR lpszPath)
122{
123 TRACE("(%s)\n",debugstr_w(lpszPath));
124
125 lpszPath = PathFindExtensionW(lpszPath);
126 return (LPWSTR)(*lpszPath?(lpszPath+1):lpszPath);
127}
128
129/*************************************************************************
130 * PathGetExtensionAW [SHELL32.158]
131 */
132LPVOID WINAPI PathGetExtensionAW(LPCVOID lpszPath)
133{
134 if (SHELL_OsIsUnicode())
135 return PathGetExtensionW(lpszPath);
136 return PathGetExtensionA(lpszPath);
137}
138
139/*************************************************************************
140 * PathGetArgsAW [SHELL32.52]
141 */
142LPVOID WINAPI PathGetArgsAW(LPVOID lpszPath)
143{
144 if (SHELL_OsIsUnicode())
145 return PathGetArgsW(lpszPath);
146 return PathGetArgsA(lpszPath);
147}
148
149/*************************************************************************
150 * PathGetDriveNumber [SHELL32.57]
151 */
152int WINAPI PathGetDriveNumberAW(LPVOID lpszPath)
153{
154 if (SHELL_OsIsUnicode())
155 return PathGetDriveNumberW(lpszPath);
156 return PathGetDriveNumberA(lpszPath);
157}
158
159/*************************************************************************
160 * PathRemoveFileSpec [SHELL32.35]
161 */
162BOOL WINAPI PathRemoveFileSpecAW(LPVOID lpszPath)
163{
164 if (SHELL_OsIsUnicode())
165 return PathRemoveFileSpecW(lpszPath);
166 return PathRemoveFileSpecA(lpszPath);
167}
168
169/*************************************************************************
170 * PathStripPathAW [SHELL32.38]
171 */
172void WINAPI PathStripPathAW(LPVOID lpszPath)
173{
174 if (SHELL_OsIsUnicode())
175 return PathStripPathW(lpszPath);
176 return PathStripPathA(lpszPath);
177}
178
179/*************************************************************************
180 * PathStripToRootAW [SHELL32.50]
181 */
182BOOL WINAPI PathStripToRootAW(LPVOID lpszPath)
183{
184 if (SHELL_OsIsUnicode())
185 return PathStripToRootW(lpszPath);
186 return PathStripToRootA(lpszPath);
187}
188
189/*************************************************************************
190 * PathRemoveArgsAW [SHELL32.251]
191 */
192void WINAPI PathRemoveArgsAW(LPVOID lpszPath)
193{
194 if (SHELL_OsIsUnicode())
195 PathRemoveArgsW(lpszPath);
196 PathRemoveArgsA(lpszPath);
197}
198
199/*************************************************************************
200 * PathRemoveExtensionAW [SHELL32.250]
201 */
202void WINAPI PathRemoveExtensionAW(LPVOID lpszPath)
203{
204 if (SHELL_OsIsUnicode())
205 return PathRemoveExtensionW(lpszPath);
206 return PathRemoveExtensionA(lpszPath);
207}
208
209
210/*
211 Path Manipulations
212*/
213
214/*************************************************************************
215 * PathGetShortPathA [internal]
216 */
217LPSTR WINAPI PathGetShortPathA(LPSTR lpszPath)
218{
219 FIXME("%s stub\n", lpszPath);
220 return NULL;
221}
222
223/*************************************************************************
224 * PathGetShortPathW [internal]
225 */
226LPWSTR WINAPI PathGetShortPathW(LPWSTR lpszPath)
227{
228 FIXME("%s stub\n", debugstr_w(lpszPath));
229 return NULL;
230}
231
232/*************************************************************************
233 * PathGetShortPathAW [SHELL32.92]
234 */
235LPVOID WINAPI PathGetShortPathAW(LPVOID lpszPath)
236{
237 if(SHELL_OsIsUnicode())
238 return PathGetShortPathW(lpszPath);
239 return PathGetShortPathA(lpszPath);
240}
241
242/*************************************************************************
243 * PathRemoveBlanksAW [SHELL32.33]
244 */
245void WINAPI PathRemoveBlanksAW(LPVOID str)
246{
247 if(SHELL_OsIsUnicode())
248 PathRemoveBlanksW(str);
249 PathRemoveBlanksA(str);
250}
251
252/*************************************************************************
253 * PathQuoteSpacesAW [SHELL32.55]
254 */
255LPVOID WINAPI PathQuoteSpacesAW (LPVOID lpszPath)
256{
257 if(SHELL_OsIsUnicode())
258 return PathQuoteSpacesW(lpszPath);
259 return PathQuoteSpacesA(lpszPath);
260}
261
262/*************************************************************************
263 * PathUnquoteSpacesAW [SHELL32.56]
264 */
265VOID WINAPI PathUnquoteSpacesAW(LPVOID str)
266{
267 if(SHELL_OsIsUnicode())
268 PathUnquoteSpacesW(str);
269 else
270 PathUnquoteSpacesA(str);
271}
272
273/*************************************************************************
274 * PathParseIconLocationAW [SHELL32.249]
275 */
276int WINAPI PathParseIconLocationAW (LPVOID lpszPath)
277{
278 if(SHELL_OsIsUnicode())
279 return PathParseIconLocationW(lpszPath);
280 return PathParseIconLocationA(lpszPath);
281}
282
283/*
284 ########## Path Testing ##########
285*/
286/*************************************************************************
287 * PathIsUNCAW [SHELL32.39]
288 */
289BOOL WINAPI PathIsUNCAW (LPCVOID lpszPath)
290{
291 if (SHELL_OsIsUnicode())
292 return PathIsUNCW( lpszPath );
293 return PathIsUNCA( lpszPath );
294}
295
296/*************************************************************************
297 * PathIsRelativeAW [SHELL32.40]
298 */
299BOOL WINAPI PathIsRelativeAW (LPCVOID lpszPath)
300{
301 if (SHELL_OsIsUnicode())
302 return PathIsRelativeW( lpszPath );
303 return PathIsRelativeA( lpszPath );
304}
305
306/*************************************************************************
307 * PathIsRootAW [SHELL32.29]
308 */
309BOOL WINAPI PathIsRootAW(LPCVOID lpszPath)
310{
311 if (SHELL_OsIsUnicode())
312 return PathIsRootW(lpszPath);
313 return PathIsRootA(lpszPath);
314}
315
316/*************************************************************************
317 * PathIsExeA [internal]
318 */
319static BOOL PathIsExeA (LPCSTR lpszPath)
320{
321 LPCSTR lpszExtension = PathGetExtensionA(lpszPath);
322 int i = 0;
323 static char * lpszExtensions[6] = {"exe", "com", "pid", "cmd", "bat", NULL };
324
325 TRACE("path=%s\n",lpszPath);
326
327 for(i=0; lpszExtensions[i]; i++)
328 if (!strcasecmp(lpszExtension,lpszExtensions[i])) return TRUE;
329
330 return FALSE;
331}
332
333/*************************************************************************
334 * PathIsExeW [internal]
335 */
336static BOOL PathIsExeW (LPCWSTR lpszPath)
337{
338 LPCWSTR lpszExtension = PathGetExtensionW(lpszPath);
339 int i = 0;
340 static WCHAR lpszExtensions[6][4] =
341 {{'e','x','e','\0'}, {'c','o','m','\0'}, {'p','i','d','\0'},
342 {'c','m','d','\0'}, {'b','a','t','\0'}, {'\0'} };
343
344 TRACE("path=%s\n",debugstr_w(lpszPath));
345
346 for(i=0; lpszExtensions[i]; i++)
347 if (!strcmpiW(lpszExtension,lpszExtensions[i])) return TRUE;
348
349 return FALSE;
350}
351
352/*************************************************************************
353 * PathIsExeAW [SHELL32.43]
354 */
355BOOL WINAPI PathIsExeAW (LPCVOID path)
356{
357 if (SHELL_OsIsUnicode())
358 return PathIsExeW (path);
359 return PathIsExeA(path);
360}
361
362/*************************************************************************
363 * PathIsDirectoryAW [SHELL32.159]
364 */
365BOOL WINAPI PathIsDirectoryAW (LPCVOID lpszPath)
366{
367 if (SHELL_OsIsUnicode())
368 return PathIsDirectoryW (lpszPath);
369 return PathIsDirectoryA (lpszPath);
370}
371
372/*************************************************************************
373 * PathFileExistsAW [SHELL32.45]
374 */
375BOOL WINAPI PathFileExistsAW (LPCVOID lpszPath)
376{
377 if (SHELL_OsIsUnicode())
378 return PathFileExistsW (lpszPath);
379 return PathFileExistsA (lpszPath);
380}
381
382/*************************************************************************
383 * PathMatchSpecAW [SHELL32.46]
384 */
385BOOL WINAPI PathMatchSpecAW(LPVOID name, LPVOID mask)
386{
387 if (SHELL_OsIsUnicode())
388 return PathMatchSpecW( name, mask );
389 return PathMatchSpecA( name, mask );
390}
391
392/*************************************************************************
393 * PathIsSameRootAW [SHELL32.650]
394 */
395BOOL WINAPI PathIsSameRootAW(LPCVOID lpszPath1, LPCVOID lpszPath2)
396{
397 if (SHELL_OsIsUnicode())
398 return PathIsSameRootW(lpszPath1, lpszPath2);
399 return PathIsSameRootA(lpszPath1, lpszPath2);
400}
401
402/*************************************************************************
403 * IsLFNDriveA [SHELL32.119]
404 *
405 * NOTES
406 * exported by ordinal Name
407 */
408BOOL WINAPI IsLFNDriveA(LPCSTR lpszPath)
409{
410 DWORD fnlen;
411
412 if (!GetVolumeInformationA(lpszPath,NULL,0,NULL,&fnlen,NULL,NULL,0))
413 return FALSE;
414 return fnlen>12;
415}
416
417/*
418 ########## Creating Something Unique ##########
419*/
420/*************************************************************************
421 * PathMakeUniqueNameA [internal]
422 */
423BOOL WINAPI PathMakeUniqueNameA(
424 LPSTR lpszBuffer,
425 DWORD dwBuffSize,
426 LPCSTR lpszShortName,
427 LPCSTR lpszLongName,
428 LPCSTR lpszPathName)
429{
430 FIXME("%p %lu %s %s %s stub\n",
431 lpszBuffer, dwBuffSize, debugstr_a(lpszShortName),
432 debugstr_a(lpszLongName), debugstr_a(lpszPathName));
433 return TRUE;
434}
435
436/*************************************************************************
437 * PathMakeUniqueNameW [internal]
438 */
439BOOL WINAPI PathMakeUniqueNameW(
440 LPWSTR lpszBuffer,
441 DWORD dwBuffSize,
442 LPCWSTR lpszShortName,
443 LPCWSTR lpszLongName,
444 LPCWSTR lpszPathName)
445{
446 FIXME("%p %lu %s %s %s stub\n",
447 lpszBuffer, dwBuffSize, debugstr_w(lpszShortName),
448 debugstr_w(lpszLongName), debugstr_w(lpszPathName));
449 return TRUE;
450}
451
452/*************************************************************************
453 * PathMakeUniqueNameAW [SHELL32.47]
454 */
455BOOL WINAPI PathMakeUniqueNameAW(
456 LPVOID lpszBuffer,
457 DWORD dwBuffSize,
458 LPCVOID lpszShortName,
459 LPCVOID lpszLongName,
460 LPCVOID lpszPathName)
461{
462 if (SHELL_OsIsUnicode())
463 return PathMakeUniqueNameW(lpszBuffer,dwBuffSize, lpszShortName,lpszLongName,lpszPathName);
464 return PathMakeUniqueNameA(lpszBuffer,dwBuffSize, lpszShortName,lpszLongName,lpszPathName);
465}
466
467/*************************************************************************
468 * PathYetAnotherMakeUniqueNameA [SHELL32.75]
469 *
470 * NOTES
471 * exported by ordinal
472 */
473BOOL WINAPI PathYetAnotherMakeUniqueNameA(
474 LPSTR lpszBuffer,
475 LPCSTR lpszPathName,
476 LPCSTR lpszShortName,
477 LPCSTR lpszLongName)
478{
479 FIXME("(%p,%p, %p ,%p):stub.\n",
480 lpszBuffer, lpszPathName, lpszShortName, lpszLongName);
481 return TRUE;
482}
483#ifdef __WIN32OS2__
484/*************************************************************************
485 * PathYetAnotherMakeUniqueNameA [SHELL32.75]
486 *
487 * NOTES
488 * exported by ordinal
489 */
490BOOL WINAPI PathYetAnotherMakeUniqueNameW(
491 LPWSTR lpszBuffer,
492 LPCWSTR lpszPathName,
493 LPCWSTR lpszShortName,
494 LPCWSTR lpszLongName)
495{
496 FIXME("(%p,%p, %p ,%p):stub.\n",
497 lpszBuffer, lpszPathName, lpszShortName, lpszLongName);
498 return TRUE;
499}
500
501BOOL WINAPI PathYetAnotherMakeUniqueNameAW(
502 LPSTR lpszBuffer,
503 LPCSTR lpszPathName,
504 LPCSTR lpszShortName,
505 LPCSTR lpszLongName)
506{
507 if (SHELL_OsIsUnicode())
508 return PathYetAnotherMakeUniqueNameW((LPWSTR)lpszBuffer,(LPCWSTR)lpszPathName, (LPCWSTR)lpszShortName,(LPCWSTR)lpszLongName);
509 return PathYetAnotherMakeUniqueNameA(lpszBuffer, lpszPathName, lpszShortName,lpszLongName);
510}
511#endif
512
513/*
514 ########## cleaning and resolving paths ##########
515 */
516
517/*************************************************************************
518 * PathFindOnPathAW [SHELL32]
519 */
520BOOL WINAPI PathFindOnPathAW(LPVOID sFile, LPCVOID sOtherDirs)
521{
522 if (SHELL_OsIsUnicode())
523 return PathFindOnPathW(sFile, sOtherDirs);
524 return PathFindOnPathA(sFile, sOtherDirs);
525}
526
527/*************************************************************************
528 * PathCleanupSpecAW [SHELL32]
529 */
530DWORD WINAPI PathCleanupSpecAW (LPVOID x, LPVOID y)
531{
532 FIXME("(%p, %p) stub\n",x,y);
533 return TRUE;
534}
535
536/*************************************************************************
537 * PathQualifyA [SHELL32]
538 */
539BOOL WINAPI PathQualifyA(LPCSTR pszPath)
540{
541 FIXME("%s\n",pszPath);
542 return 0;
543}
544
545/*************************************************************************
546 * PathQualifyW [SHELL32]
547 */
548BOOL WINAPI PathQualifyW(LPCWSTR pszPath)
549{
550 FIXME("%s\n",debugstr_w(pszPath));
551 return 0;
552}
553
554/*************************************************************************
555 * PathQualifyAW [SHELL32]
556 */
557BOOL WINAPI PathQualifyAW(LPCVOID pszPath)
558{
559 if (SHELL_OsIsUnicode())
560 return PathQualifyW(pszPath);
561 return PathQualifyA(pszPath);
562}
563
564/*************************************************************************
565 * PathResolveA [SHELL32.51]
566 */
567BOOL WINAPI PathResolveA(
568 LPSTR lpszPath,
569 LPCSTR *alpszPaths,
570 DWORD dwFlags)
571{
572 FIXME("(%s,%p,0x%08lx),stub!\n",
573 lpszPath, *alpszPaths, dwFlags);
574 return 0;
575}
576
577/*************************************************************************
578 * PathResolveW [SHELL32]
579 */
580BOOL WINAPI PathResolveW(
581 LPWSTR lpszPath,
582 LPCWSTR *alpszPaths,
583 DWORD dwFlags)
584{
585 FIXME("(%s,%p,0x%08lx),stub!\n",
586 debugstr_w(lpszPath), debugstr_w(*alpszPaths), dwFlags);
587 return 0;
588}
589
590/*************************************************************************
591 * PathResolveAW [SHELL32]
592 */
593BOOL WINAPI PathResolveAW(
594 LPVOID lpszPath,
595 LPCVOID *alpszPaths,
596 DWORD dwFlags)
597{
598 if (SHELL_OsIsUnicode())
599 return PathResolveW(lpszPath, (LPCWSTR*)alpszPaths, dwFlags);
600 return PathResolveA(lpszPath, (LPCSTR*)alpszPaths, dwFlags);
601}
602
603/*************************************************************************
604* PathProcessCommandA [SHELL32.653]
605*/
606HRESULT WINAPI PathProcessCommandA (
607 LPCSTR lpszPath,
608 LPSTR lpszBuff,
609 DWORD dwBuffSize,
610 DWORD dwFlags)
611{
612 FIXME("%s %p 0x%04lx 0x%04lx stub\n",
613 lpszPath, lpszBuff, dwBuffSize, dwFlags);
614 strcpy(lpszBuff, lpszPath);
615 return 0;
616}
617
618/*************************************************************************
619* PathProcessCommandW
620*/
621HRESULT WINAPI PathProcessCommandW (
622 LPCWSTR lpszPath,
623 LPWSTR lpszBuff,
624 DWORD dwBuffSize,
625 DWORD dwFlags)
626{
627 FIXME("(%s, %p, 0x%04lx, 0x%04lx) stub\n",
628 debugstr_w(lpszPath), lpszBuff, dwBuffSize, dwFlags);
629 strcpyW(lpszBuff, lpszPath);
630 return 0;
631}
632
633/*************************************************************************
634* PathProcessCommandAW
635*/
636HRESULT WINAPI PathProcessCommandAW (
637 LPCVOID lpszPath,
638 LPVOID lpszBuff,
639 DWORD dwBuffSize,
640 DWORD dwFlags)
641{
642 if (SHELL_OsIsUnicode())
643 return PathProcessCommandW(lpszPath, lpszBuff, dwBuffSize, dwFlags);
644 return PathProcessCommandA(lpszPath, lpszBuff, dwBuffSize, dwFlags);
645}
646
647/*
648 ########## special ##########
649*/
650
651/*************************************************************************
652 * PathSetDlgItemPathAW
653 */
654BOOL WINAPI PathSetDlgItemPathAW(HWND hDlg, int id, LPCVOID pszPath)
655{ if (SHELL_OsIsUnicode())
656 return PathSetDlgItemPathW(hDlg, id, pszPath);
657 return PathSetDlgItemPathA(hDlg, id, pszPath);
658}
659
660
661/*************************************************************************
662 * SHGetSpecialFolderPathA [SHELL32.175]
663 *
664 * converts csidl to path
665 */
666
667static char * szSHFolders = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
668static char * szSHUserFolders = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders";
669#if 0
670static char * szEnvUserProfile = "%USERPROFILE%";
671static char * szEnvSystemRoot = "%SYSTEMROOT%";
672#endif
673
674BOOL WINAPI SHGetSpecialFolderPathA (
675 HWND hwndOwner,
676 LPSTR szPath,
677 DWORD csidl,
678 BOOL bCreate)
679{
680 CHAR szValueName[MAX_PATH], szDefaultPath[MAX_PATH];
681 HKEY hRootKey, hKey;
682 BOOL bRelative = TRUE;
683 DWORD dwType, dwDisp, dwPathLen = MAX_PATH;
684
685 TRACE("0x%04x,%p,csidl=%lu,0x%04x\n", hwndOwner,szPath,csidl,bCreate);
686
687 /* build default values */
688 switch(csidl)
689 {
690 case CSIDL_APPDATA:
691 hRootKey = HKEY_CURRENT_USER;
692 strcpy (szValueName, "AppData");
693 strcpy (szDefaultPath, "AppData");
694 break;
695
696 case CSIDL_COOKIES:
697 hRootKey = HKEY_CURRENT_USER;
698 strcpy (szValueName, "Cookies");
699 strcpy(szDefaultPath, "Cookies");
700 break;
701
702 case CSIDL_DESKTOPDIRECTORY:
703 hRootKey = HKEY_CURRENT_USER;
704 strcpy(szValueName, "Desktop");
705 strcpy(szDefaultPath, "Desktop");
706 break;
707
708 case CSIDL_COMMON_DESKTOPDIRECTORY:
709 hRootKey = HKEY_LOCAL_MACHINE;
710 strcpy(szValueName, "Common Desktop");
711 strcpy(szDefaultPath, "Desktop");
712 break;
713
714 case CSIDL_FAVORITES:
715 hRootKey = HKEY_CURRENT_USER;
716 strcpy(szValueName, "Favorites");
717 strcpy(szDefaultPath, "Favorites");
718 break;
719
720 case CSIDL_FONTS:
721 hRootKey = HKEY_CURRENT_USER;
722 strcpy(szValueName, "Fonts");
723 strcpy(szDefaultPath, "Fonts");
724 break;
725
726 case CSIDL_HISTORY:
727 hRootKey = HKEY_CURRENT_USER;
728 strcpy(szValueName, "History");
729 strcpy(szDefaultPath, "History");
730 break;
731
732 case CSIDL_NETHOOD:
733 hRootKey = HKEY_CURRENT_USER;
734 strcpy(szValueName, "NetHood");
735 strcpy(szDefaultPath, "NetHood");
736 break;
737
738 case CSIDL_INTERNET_CACHE:
739 hRootKey = HKEY_CURRENT_USER;
740 strcpy(szValueName, "Cache");
741 strcpy(szDefaultPath, "Temporary Internet Files");
742 break;
743
744 case CSIDL_PERSONAL:
745 hRootKey = HKEY_CURRENT_USER;
746 strcpy(szValueName, "Personal");
747 strcpy(szDefaultPath, "My Own Files");
748 bRelative = FALSE;
749 break;
750
751 case CSIDL_PRINTHOOD:
752 hRootKey = HKEY_CURRENT_USER;
753 strcpy(szValueName, "PrintHood");
754 strcpy(szDefaultPath, "PrintHood");
755 break;
756
757 case CSIDL_PROGRAMS:
758 hRootKey = HKEY_CURRENT_USER;
759 strcpy(szValueName, "Programs");
760 strcpy(szDefaultPath, "StartMenu\\Programs");
761 break;
762
763 case CSIDL_COMMON_PROGRAMS:
764 hRootKey = HKEY_LOCAL_MACHINE;
765 strcpy(szValueName, "Common Programs");
766 strcpy(szDefaultPath, "");
767 break;
768
769 case CSIDL_RECENT:
770 hRootKey = HKEY_CURRENT_USER;
771 strcpy(szValueName, "Recent");
772 strcpy(szDefaultPath, "Recent");
773 break;
774
775 case CSIDL_SENDTO:
776 hRootKey = HKEY_CURRENT_USER;
777 strcpy(szValueName, "SendTo");
778 strcpy(szDefaultPath, "SendTo");
779 break;
780
781 case CSIDL_STARTMENU:
782 hRootKey = HKEY_CURRENT_USER;
783 strcpy(szValueName, "StartMenu");
784 strcpy(szDefaultPath, "StartMenu");
785 break;
786
787 case CSIDL_COMMON_STARTMENU:
788 hRootKey = HKEY_LOCAL_MACHINE;
789 strcpy(szValueName, "Common StartMenu");
790 strcpy(szDefaultPath, "StartMenu");
791 break;
792
793 case CSIDL_STARTUP:
794 hRootKey = HKEY_CURRENT_USER;
795 strcpy(szValueName, "Startup");
796 strcpy(szDefaultPath, "StartMenu\\Programs\\Startup");
797 break;
798
799 case CSIDL_COMMON_STARTUP:
800 hRootKey = HKEY_LOCAL_MACHINE;
801 strcpy(szValueName, "Common Startup");
802 strcpy(szDefaultPath, "StartMenu\\Programs\\Startup");
803 break;
804
805 case CSIDL_TEMPLATES:
806 hRootKey = HKEY_CURRENT_USER;
807 strcpy(szValueName, "Templates");
808 strcpy(szDefaultPath, "ShellNew");
809 break;
810
811 default:
812 ERR("folder unknown or not allowed\n");
813 return FALSE;
814 }
815
816 /* user shell folders */
817 if (RegCreateKeyExA(hRootKey,szSHUserFolders,0,NULL,0,KEY_ALL_ACCESS,NULL,&hKey,&dwDisp)) return FALSE;
818
819 if (RegQueryValueExA(hKey,szValueName,NULL,&dwType,(LPBYTE)szPath,&dwPathLen))
820 {
821 RegCloseKey(hKey);
822
823 /* shell folders */
824 if (RegCreateKeyExA(hRootKey,szSHFolders,0,NULL,0,KEY_ALL_ACCESS,NULL,&hKey,&dwDisp)) return FALSE;
825
826 if (RegQueryValueExA(hKey,szValueName,NULL,&dwType,(LPBYTE)szPath,&dwPathLen))
827 {
828
829 /* value not existing */
830 if (bRelative)
831 {
832 GetWindowsDirectoryA(szPath, MAX_PATH);
833 PathAddBackslashA(szPath);
834 strcat(szPath, szDefaultPath);
835 }
836 else
837 {
838 strcpy(szPath, "C:\\"); /* fixme ??? */
839 strcat(szPath, szDefaultPath);
840 }
841 RegSetValueExA(hKey,szValueName,0,REG_SZ,(LPBYTE)szPath,strlen(szPath)+1);
842 }
843 }
844 RegCloseKey(hKey);
845
846 /* expand paths like %USERPROFILE% */
847 if (dwType == REG_EXPAND_SZ)
848 {
849 ExpandEnvironmentStringsA(szPath, szDefaultPath, MAX_PATH);
850 strcpy(szPath, szDefaultPath);
851 }
852
853 /* if we don't care about existing directorys we are ready */
854 if(csidl & CSIDL_FLAG_DONT_VERIFY) return TRUE;
855
856 if (PathFileExistsA(szPath)) return TRUE;
857
858 /* not existing but we not allowed to create it */
859 if (!bCreate) return FALSE;
860
861 if (!CreateDirectoryA(szPath,NULL))
862 {
863 ERR("Failed to create directory '%s'.\n", szPath);
864 return FALSE;
865 }
866
867 MESSAGE("Created not existing system directory '%s'\n", szPath);
868 return TRUE;
869}
870
871/*************************************************************************
872 * SHGetSpecialFolderPathW
873 */
874BOOL WINAPI SHGetSpecialFolderPathW (
875 HWND hwndOwner,
876 LPWSTR szPath,
877 DWORD csidl,
878 BOOL bCreate)
879{
880 char szTemp[MAX_PATH];
881
882 if (SHGetSpecialFolderPathA(hwndOwner, szTemp, csidl, bCreate))
883 {
884 lstrcpynAtoW(szPath, szTemp, MAX_PATH);
885 }
886
887 TRACE("0x%04x,%p,csidl=%lu,0x%04x\n", hwndOwner,szPath,csidl,bCreate);
888
889 return TRUE;
890}
891
892/*************************************************************************
893 * SHGetSpecialFolderPathAW
894 */
895BOOL WINAPI SHGetSpecialFolderPathAW (
896 HWND hwndOwner,
897 LPVOID szPath,
898 DWORD csidl,
899 BOOL bCreate)
900
901{
902 if (SHELL_OsIsUnicode())
903 return SHGetSpecialFolderPathW (hwndOwner, szPath, csidl, bCreate);
904 return SHGetSpecialFolderPathA (hwndOwner, szPath, csidl, bCreate);
905}
906
907/*************************************************************************
908 * SHGetFolderPathA [SHFOLDER.@]
909 */
910HRESULT WINAPI SHGetFolderPathA(
911 HWND hwndOwner,
912 int nFolder,
913 HANDLE hToken, /* FIXME: get paths for specific user */
914 DWORD dwFlags, /* FIXME: SHGFP_TYPE_CURRENT|SHGFP_TYPE_DEFAULT */
915 LPSTR pszPath)
916{
917 return (SHGetSpecialFolderPathA(
918 hwndOwner,
919 pszPath,
920 CSIDL_FOLDER_MASK & nFolder,
921 CSIDL_FLAG_CREATE & nFolder )) ? S_OK : E_FAIL;
922}
923
924/*************************************************************************
925 * SHGetFolderPathW [SHFOLDER.@]
926 */
927HRESULT WINAPI SHGetFolderPathW(
928 HWND hwndOwner,
929 int nFolder,
930 HANDLE hToken,
931 DWORD dwFlags,
932 LPWSTR pszPath)
933{
934 return (SHGetSpecialFolderPathW(
935 hwndOwner,
936 pszPath,
937 CSIDL_FOLDER_MASK & nFolder,
938 CSIDL_FLAG_CREATE & nFolder )) ? S_OK : E_FAIL;
939}
Note: See TracBrowser for help on using the repository browser.