VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/xpcom/io/SpecialSystemDirectory.cpp@ 53433

Last change on this file since 53433 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 23.9 KB
Line 
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is Mozilla Communicator client code, released
16 * March 31, 1998.
17 *
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
22 *
23 * Contributor(s):
24 * Doug Turner <[email protected]>
25 * IBM Corp.
26 *
27 * Alternatively, the contents of this file may be used under the terms of
28 * either of the GNU General Public License Version 2 or later (the "GPL"),
29 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
38 *
39 * ***** END LICENSE BLOCK ***** */
40
41#include "SpecialSystemDirectory.h"
42#include "nsString.h"
43#include "nsDependentString.h"
44
45
46#ifdef XP_MAC
47
48#include <Folders.h>
49#include <Files.h>
50#include <Memory.h>
51#include <Processes.h>
52#include <Gestalt.h>
53#include "nsIInternetConfigService.h"
54
55
56#if UNIVERSAL_INTERFACES_VERSION < 0x0340
57 enum {
58 kSystemDomain = -32766, /* Read-only system hierarchy.*/
59 kLocalDomain = -32765, /* All users of a single machine have access to these resources.*/
60 kNetworkDomain = -32764, /* All users configured to use a common network server has access to these resources.*/
61 kUserDomain = -32763, /* Read/write. Resources that are private to the user.*/
62 kClassicDomain = -32762, /* Domain referring to the currently configured Classic System Folder*/
63
64 kDomainLibraryFolderType = FOUR_CHAR_CODE('dlib')
65 };
66#endif
67
68#elif defined(XP_WIN)
69
70#include <windows.h>
71#include <shlobj.h>
72#include <stdlib.h>
73#include <stdio.h>
74#include <string.h>
75
76#elif defined(XP_OS2)
77
78#define MAX_PATH _MAX_PATH
79#define INCL_WINWORKPLACE
80#define INCL_DOSMISC
81#define INCL_DOSMODULEMGR
82#define INCL_DOSPROCESS
83#define INCL_WINSHELLDATA
84#include <os2.h>
85#include <stdlib.h>
86#include <stdio.h>
87#include "prenv.h"
88
89#elif defined(XP_UNIX)
90
91#include <unistd.h>
92#include <stdlib.h>
93#include <sys/param.h>
94#include "prenv.h"
95
96#elif defined(XP_BEOS)
97
98#include <FindDirectory.h>
99#include <Path.h>
100#include <unistd.h>
101#include <stdlib.h>
102#include <sys/param.h>
103#include <OS.h>
104#include <image.h>
105#include "prenv.h"
106
107#endif
108
109#if defined(VMS)
110#include <unixlib.h>
111#endif
112
113
114
115#if defined (XP_WIN)
116typedef BOOL (WINAPI * GetSpecialPathProc) (HWND hwndOwner, LPSTR lpszPath, int nFolder, BOOL fCreate);
117GetSpecialPathProc gGetSpecialPathProc = NULL;
118static HINSTANCE gShell32DLLInst = NULL;
119#endif
120NS_COM void StartupSpecialSystemDirectory()
121{
122#if defined (XP_WIN)
123 /* On windows, the old method to get file locations is incredibly slow.
124 As of this writing, 3 calls to GetWindowsFolder accounts for 3% of mozilla
125 startup. Replacing these older calls with a single call to SHGetSpecialFolderPath
126 effectively removes these calls from the performace radar. We need to
127 support the older way of file location lookup on systems that do not have
128 IE4. (Note: gets the ansi version: SHGetSpecialFolderPathA).
129 */
130 gShell32DLLInst = LoadLibrary("Shell32.dll");
131 if(gShell32DLLInst)
132 {
133 gGetSpecialPathProc = (GetSpecialPathProc) GetProcAddress(gShell32DLLInst,
134 "SHGetSpecialFolderPathA");
135 }
136#endif
137}
138
139NS_COM void ShutdownSpecialSystemDirectory()
140{
141#if defined (XP_WIN)
142 if (gShell32DLLInst)
143 {
144 FreeLibrary(gShell32DLLInst);
145 gShell32DLLInst = NULL;
146 gGetSpecialPathProc = NULL;
147 }
148#endif
149}
150
151#if defined (XP_WIN)
152
153//----------------------------------------------------------------------------------------
154static nsresult GetWindowsFolder(int folder, nsILocalFile** aFile)
155//----------------------------------------------------------------------------------------
156{
157 if (gGetSpecialPathProc) {
158 TCHAR path[MAX_PATH];
159 HRESULT result = gGetSpecialPathProc(NULL, path, folder, true);
160
161 if (!SUCCEEDED(result))
162 return NS_ERROR_FAILURE;
163
164 // Append the trailing slash
165 int len = strlen(path);
166 if (len>1 && path[len-1] != '\\')
167 {
168 path[len] = '\\';
169 path[len + 1] = '\0';
170 }
171
172 return NS_NewNativeLocalFile(nsDependentCString(path),
173 PR_TRUE,
174 aFile);
175 }
176
177 nsresult rv = NS_ERROR_FAILURE;
178 LPMALLOC pMalloc = NULL;
179 LPSTR pBuffer = NULL;
180 LPITEMIDLIST pItemIDList = NULL;
181 int len;
182
183 // Get the shell's allocator.
184 if (!SUCCEEDED(SHGetMalloc(&pMalloc)))
185 return NS_ERROR_FAILURE;
186
187 // Allocate a buffer
188 if ((pBuffer = (LPSTR) pMalloc->Alloc(MAX_PATH + 2)) == NULL)
189 return NS_ERROR_FAILURE;
190
191 // Get the PIDL for the folder.
192 if (!SUCCEEDED(SHGetSpecialFolderLocation(
193 NULL, folder, &pItemIDList)))
194 goto Clean;
195
196 if (!SUCCEEDED(SHGetPathFromIDList(pItemIDList, pBuffer)))
197 goto Clean;
198
199 // Append the trailing slash
200 len = strlen(pBuffer);
201 pBuffer[len] = '\\';
202 pBuffer[len + 1] = '\0';
203
204 // Assign the directory
205 rv = NS_NewNativeLocalFile(nsDependentCString(pBuffer),
206 PR_TRUE,
207 aFile);
208
209Clean:
210 // Clean up.
211 if (pItemIDList)
212 pMalloc->Free(pItemIDList);
213 if (pBuffer)
214 pMalloc->Free(pBuffer);
215
216 pMalloc->Release();
217
218 return rv;
219}
220
221#endif // XP_WIN
222
223
224
225
226nsresult
227GetSpecialSystemDirectory(SystemDirectories aSystemSystemDirectory,
228 nsILocalFile** aFile)
229{
230#ifdef XP_MAC
231 OSErr err;
232 short vRefNum;
233 long dirID;
234#endif
235
236 switch (aSystemSystemDirectory)
237 {
238 case OS_DriveDirectory:
239#if defined (XP_WIN)
240 {
241 char path[_MAX_PATH];
242 PRInt32 len = GetWindowsDirectory( path, _MAX_PATH );
243 if (len)
244 {
245 if ( path[1] == ':' && path[2] == '\\' )
246 path[3] = 0;
247 }
248
249 return NS_NewNativeLocalFile(nsDependentCString(path),
250 PR_TRUE,
251 aFile);
252 }
253#elif defined(XP_OS2)
254 {
255 ULONG ulBootDrive = 0;
256 char buffer[] = " :\\OS2\\";
257 DosQuerySysInfo( QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
258 &ulBootDrive, sizeof ulBootDrive);
259 buffer[0] = 'A' - 1 + ulBootDrive; // duh, 1-based index...
260
261 return NS_NewNativeLocalFile(nsDependentCString(buffer),
262 PR_TRUE,
263 aFile);
264 }
265#elif defined(XP_MAC)
266 {
267 return nsIFileFromOSType(kVolumeRootFolderType, aFile);
268 }
269#else
270 return NS_NewNativeLocalFile(nsDependentCString("/"),
271 PR_TRUE,
272 aFile);
273
274#endif
275
276 case OS_TemporaryDirectory:
277#if defined (XP_WIN)
278 {
279 char path[_MAX_PATH];
280 DWORD len = GetTempPath(_MAX_PATH, path);
281 return NS_NewNativeLocalFile(nsDependentCString(path),
282 PR_TRUE,
283 aFile);
284 }
285#elif defined(XP_OS2)
286 {
287 char buffer[CCHMAXPATH] = "";
288 char *c = getenv( "TMP");
289 if( c) strcpy( buffer, c);
290 else
291 {
292 c = getenv( "TEMP");
293 if( c) strcpy( buffer, c);
294 }
295
296 return NS_NewNativeLocalFile(nsDependentCString(buffer),
297 PR_TRUE,
298 aFile);
299 }
300#elif defined(XP_MAC)
301 return nsIFileFromOSType(kTemporaryFolderType, aFile);
302
303#elif defined(XP_MACOSX)
304 {
305 return GetOSXFolderType(kUserDomain, kTemporaryFolderType, aFile);
306 }
307
308#elif defined(XP_UNIX) || defined(XP_BEOS)
309 {
310 static const char *tPath = nsnull;
311 if (!tPath) {
312 tPath = PR_GetEnv("TMPDIR");
313 if (!tPath || !*tPath) {
314 tPath = PR_GetEnv("TMP");
315 if (!tPath || !*tPath) {
316 tPath = PR_GetEnv("TEMP");
317 if (!tPath || !*tPath) {
318 tPath = "/tmp/";
319 }
320 }
321 }
322 }
323 return NS_NewNativeLocalFile(nsDependentCString(tPath),
324 PR_TRUE,
325 aFile);
326 }
327#else
328 break;
329#endif
330
331#if defined(XP_MAC)
332 case Mac_SystemDirectory:
333 return nsIFileFromOSType(kSystemFolderType, aFile);
334
335 case Mac_DesktopDirectory:
336 return nsIFileFromOSType(kDesktopFolderType, aFile);
337
338 case Mac_TrashDirectory:
339 return nsIFileFromOSType(kTrashFolderType, aFile);
340
341 case Mac_StartupDirectory:
342 return nsIFileFromOSType(kStartupFolderType, aFile);
343
344 case Mac_ShutdownDirectory:
345 return nsIFileFromOSType(kShutdownFolderType, aFile);
346
347 case Mac_AppleMenuDirectory:
348 return nsIFileFromOSType(kAppleMenuFolderType, aFile);
349
350 case Mac_ControlPanelDirectory:
351 return nsIFileFromOSType(kControlPanelFolderType, aFile);
352
353 case Mac_ExtensionDirectory:
354 return nsIFileFromOSType(kExtensionFolderType, aFile);
355
356 case Mac_FontsDirectory:
357 return nsIFileFromOSType(kFontsFolderType, aFile);
358
359 case Mac_ClassicPreferencesDirectory:
360 {
361 // whether Mac OS X or pre-Mac OS X, return Classic's Prefs folder
362 short domain;
363 long response;
364 err = ::Gestalt(gestaltSystemVersion, &response);
365 domain = (!err && response >= 0x00001000) ? kClassicDomain : kOnSystemDisk;
366 err = ::FindFolder(domain, kPreferencesFolderType, true, &vRefNum, &dirID);
367 if (!err) {
368 err = ::FSMakeFSSpec(vRefNum, dirID, "\p", &mSpec);
369 }
370 return NS_FILE_RESULT(err);
371 }
372
373 case Mac_PreferencesDirectory:
374 {
375 // if Mac OS X, return Mac OS X's Prefs folder
376 // if pre-Mac OS X, return Mac OS's Prefs folder
377 err = ::FindFolder(kOnSystemDisk, kPreferencesFolderType, true, &vRefNum, &dirID);
378 if (!err) {
379 err = ::FSMakeFSSpec(vRefNum, dirID, "\p", &mSpec);
380 }
381 return NS_FILE_RESULT(err);
382 }
383
384 case Mac_DocumentsDirectory:
385 return nsIFileFromOSType(kDocumentsFolderType, aFile);
386
387 case Mac_InternetSearchDirectory:
388 return nsIFileFromOSType(kInternetSearchSitesFolderType, aFile);
389
390 case Mac_DefaultDownloadDirectory:
391 return nsIFileFromOSType(kDefaultDownloadFolderType, aFile);
392
393 case Mac_UserLibDirectory:
394 {
395 FSSpec spec;
396 err = ::FindFolder(kUserDomain, kDomainLibraryFolderType, true, &vRefNum, &dirID);
397 if (!err) {
398 err = ::FSMakeFSSpec(vRefNum, dirID, "\p", &spec);
399 }
400
401 return NS_NewLocalFileWithFSSpec(&spec, PR_FALUE, aFile);
402 }
403#endif
404
405#if defined (XP_WIN)
406 case Win_SystemDirectory:
407 {
408 char path[_MAX_PATH];
409 PRInt32 len = GetSystemDirectory( path, _MAX_PATH );
410
411 // Need enough space to add the trailing backslash
412 if (len > _MAX_PATH-2)
413 break;
414 path[len] = '\\';
415 path[len+1] = '\0';
416
417 return NS_NewNativeLocalFile(nsDependentCString(path),
418 PR_TRUE,
419 aFile);
420 }
421
422 case Win_WindowsDirectory:
423 {
424 char path[_MAX_PATH];
425 PRInt32 len = GetWindowsDirectory( path, _MAX_PATH );
426
427 // Need enough space to add the trailing backslash
428 if (len > _MAX_PATH-2)
429 break;
430
431 path[len] = '\\';
432 path[len+1] = '\0';
433
434 return NS_NewNativeLocalFile(nsDependentCString(path),
435 PR_TRUE,
436 aFile);
437 }
438
439 case Win_HomeDirectory:
440 {
441 char path[_MAX_PATH];
442 if (GetEnvironmentVariable(TEXT("HOME"), path, _MAX_PATH) > 0)
443 {
444 PRInt32 len = strlen(path);
445 // Need enough space to add the trailing backslash
446 if (len > _MAX_PATH - 2)
447 break;
448
449 path[len] = '\\';
450 path[len+1] = '\0';
451
452 return NS_NewNativeLocalFile(nsDependentCString(path),
453 PR_TRUE,
454 aFile);
455 }
456
457 if (GetEnvironmentVariable(TEXT("HOMEDRIVE"), path, _MAX_PATH) > 0)
458 {
459 char temp[_MAX_PATH];
460 if (GetEnvironmentVariable(TEXT("HOMEPATH"), temp, _MAX_PATH) > 0)
461 strncat(path, temp, _MAX_PATH);
462
463 PRInt32 len = strlen(path);
464
465 // Need enough space to add the trailing backslash
466 if (len > _MAX_PATH - 2)
467 break;
468
469 path[len] = '\\';
470 path[len+1] = '\0';
471
472 return NS_NewNativeLocalFile(nsDependentCString(path),
473 PR_TRUE,
474 aFile);
475 }
476 }
477 case Win_Desktop:
478 {
479 return GetWindowsFolder(CSIDL_DESKTOP, aFile);
480 }
481 case Win_Programs:
482 {
483 return GetWindowsFolder(CSIDL_PROGRAMS, aFile);
484 }
485 case Win_Controls:
486 {
487 return GetWindowsFolder(CSIDL_CONTROLS, aFile);
488 }
489 case Win_Printers:
490 {
491 return GetWindowsFolder(CSIDL_PRINTERS, aFile);
492 }
493 case Win_Personal:
494 {
495 return GetWindowsFolder(CSIDL_PERSONAL, aFile);
496 }
497 case Win_Favorites:
498 {
499 return GetWindowsFolder(CSIDL_FAVORITES, aFile);
500 }
501 case Win_Startup:
502 {
503 return GetWindowsFolder(CSIDL_STARTUP, aFile);
504 }
505 case Win_Recent:
506 {
507 return GetWindowsFolder(CSIDL_RECENT, aFile);
508 }
509 case Win_Sendto:
510 {
511 return GetWindowsFolder(CSIDL_SENDTO, aFile);
512 }
513 case Win_Bitbucket:
514 {
515 return GetWindowsFolder(CSIDL_BITBUCKET, aFile);
516 }
517 case Win_Startmenu:
518 {
519 return GetWindowsFolder(CSIDL_STARTMENU, aFile);
520 }
521 case Win_Desktopdirectory:
522 {
523 return GetWindowsFolder(CSIDL_DESKTOPDIRECTORY, aFile);
524 }
525 case Win_Drives:
526 {
527 return GetWindowsFolder(CSIDL_DRIVES, aFile);
528 }
529 case Win_Network:
530 {
531 return GetWindowsFolder(CSIDL_NETWORK, aFile);
532 }
533 case Win_Nethood:
534 {
535 return GetWindowsFolder(CSIDL_NETHOOD, aFile);
536 }
537 case Win_Fonts:
538 {
539 return GetWindowsFolder(CSIDL_FONTS, aFile);
540 }
541 case Win_Templates:
542 {
543 return GetWindowsFolder(CSIDL_TEMPLATES, aFile);
544 }
545 case Win_Common_Startmenu:
546 {
547 return GetWindowsFolder(CSIDL_COMMON_STARTMENU, aFile);
548 }
549 case Win_Common_Programs:
550 {
551 return GetWindowsFolder(CSIDL_COMMON_PROGRAMS, aFile);
552 }
553 case Win_Common_Startup:
554 {
555 return GetWindowsFolder(CSIDL_COMMON_STARTUP, aFile);
556 }
557 case Win_Common_Desktopdirectory:
558 {
559 return GetWindowsFolder(CSIDL_COMMON_DESKTOPDIRECTORY, aFile);
560 }
561 case Win_Appdata:
562 {
563 return GetWindowsFolder(CSIDL_APPDATA, aFile);
564 }
565 case Win_Printhood:
566 {
567 return GetWindowsFolder(CSIDL_PRINTHOOD, aFile);
568 }
569 case Win_Cookies:
570 {
571 return GetWindowsFolder(CSIDL_COOKIES, aFile);
572 }
573#endif // XP_WIN
574
575#if defined(XP_UNIX)
576 case Unix_LocalDirectory:
577 return NS_NewNativeLocalFile(nsDependentCString("/usr/local/netscape/"),
578 PR_TRUE,
579 aFile);
580 case Unix_LibDirectory:
581 return NS_NewNativeLocalFile(nsDependentCString("/usr/local/lib/netscape/"),
582 PR_TRUE,
583 aFile);
584
585 case Unix_HomeDirectory:
586#ifdef VMS
587 {
588 char *pHome;
589 pHome = getenv("HOME");
590 if (*pHome == '/') {
591 return NS_NewNativeLocalFile(nsDependentCString(pHome),
592 PR_TRUE,
593 aFile);
594
595 }
596 else
597 {
598 return NS_NewNativeLocalFile(nsDependentCString(decc$translate_vms(pHome)),
599 PR_TRUE,
600 aFile);
601 }
602 }
603#else
604 return NS_NewNativeLocalFile(nsDependentCString(PR_GetEnv("HOME")),
605 PR_TRUE,
606 aFile);
607
608#endif
609
610#endif
611
612#ifdef XP_BEOS
613 case BeOS_SettingsDirectory:
614 {
615 char path[MAXPATHLEN];
616 find_directory(B_USER_SETTINGS_DIRECTORY, 0, 0, path, MAXPATHLEN);
617 // Need enough space to add the trailing backslash
618 int len = strlen(path);
619 if (len > MAXPATHLEN-2)
620 break;
621 path[len] = '/';
622 path[len+1] = '\0';
623 return NS_NewNativeLocalFile(nsDependentCString(path),
624 PR_TRUE,
625 aFile);
626 }
627
628 case BeOS_HomeDirectory:
629 {
630 char path[MAXPATHLEN];
631 find_directory(B_USER_DIRECTORY, 0, 0, path, MAXPATHLEN);
632 // Need enough space to add the trailing backslash
633 int len = strlen(path);
634 if (len > MAXPATHLEN-2)
635 break;
636 path[len] = '/';
637 path[len+1] = '\0';
638
639 return NS_NewNativeLocalFile(nsDependentCString(path),
640 PR_TRUE,
641 aFile);
642 }
643
644 case BeOS_DesktopDirectory:
645 {
646 char path[MAXPATHLEN];
647 find_directory(B_DESKTOP_DIRECTORY, 0, 0, path, MAXPATHLEN);
648 // Need enough space to add the trailing backslash
649 int len = strlen(path);
650 if (len > MAXPATHLEN-2)
651 break;
652 path[len] = '/';
653 path[len+1] = '\0';
654
655 return NS_NewNativeLocalFile(nsDependentCString(path),
656 PR_TRUE,
657 aFile);
658 }
659
660 case BeOS_SystemDirectory:
661 {
662 char path[MAXPATHLEN];
663 find_directory(B_BEOS_DIRECTORY, 0, 0, path, MAXPATHLEN);
664 // Need enough space to add the trailing backslash
665 int len = strlen(path);
666 if (len > MAXPATHLEN-2)
667 break;
668 path[len] = '/';
669 path[len+1] = '\0';
670
671 return NS_NewNativeLocalFile(nsDependentCString(path),
672 PR_TRUE,
673 aFile);
674 }
675#endif
676#ifdef XP_OS2
677 case OS2_SystemDirectory:
678 {
679 ULONG ulBootDrive = 0;
680 char buffer[] = " :\\OS2\\System\\";
681 DosQuerySysInfo( QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
682 &ulBootDrive, sizeof ulBootDrive);
683 buffer[0] = 'A' - 1 + ulBootDrive; // duh, 1-based index...
684
685 return NS_NewNativeLocalFile(nsDependentCString(buffer),
686 PR_TRUE,
687 aFile);
688 }
689
690 case OS2_OS2Directory:
691 {
692 ULONG ulBootDrive = 0;
693 char buffer[] = " :\\OS2\\";
694 DosQuerySysInfo( QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
695 &ulBootDrive, sizeof ulBootDrive);
696 buffer[0] = 'A' - 1 + ulBootDrive; // duh, 1-based index...
697
698 return NS_NewNativeLocalFile(nsDependentCString(buffer),
699 PR_TRUE,
700 aFile);
701 }
702
703 case OS2_HomeDirectory:
704 {
705 nsresult rv;
706 char *tPath = PR_GetEnv("MOZILLA_HOME");
707 char buffer[CCHMAXPATH];
708 /* If MOZILLA_HOME is not set, use GetCurrentProcessDirectory */
709 /* To ensure we get a long filename system */
710 if (!tPath || !*tPath) {
711 PPIB ppib;
712 PTIB ptib;
713 DosGetInfoBlocks( &ptib, &ppib);
714 DosQueryModuleName( ppib->pib_hmte, CCHMAXPATH, buffer);
715 *strrchr( buffer, '\\') = '\0'; // XXX DBCS misery
716 tPath = buffer;
717 }
718 rv = NS_NewNativeLocalFile(nsDependentCString(tPath),
719 PR_TRUE,
720 aFile);
721
722 PrfWriteProfileString(HINI_USERPROFILE, "Mozilla", "Home", tPath);
723 return rv;
724 }
725
726 case OS2_DesktopDirectory:
727 {
728 char szPath[CCHMAXPATH + 1];
729 BOOL fSuccess;
730 fSuccess = WinQueryActiveDesktopPathname (szPath, sizeof(szPath));
731 int len = strlen (szPath);
732 if (len > CCHMAXPATH -1)
733 break;
734 szPath[len] = '\\';
735 szPath[len + 1] = '\0';
736
737 return NS_NewNativeLocalFile(nsDependentCString(szPath),
738 PR_TRUE,
739 aFile);
740 }
741#endif
742 default:
743 break;
744 }
745 return NS_ERROR_NOT_AVAILABLE;
746}
747
748#if defined (XP_MACOSX)
749nsresult
750GetOSXFolderType(short aDomain, OSType aFolderType, nsILocalFile **localFile)
751{
752 OSErr err;
753 FSRef fsRef;
754 nsresult rv = NS_ERROR_FAILURE;
755
756 err = ::FSFindFolder(aDomain, aFolderType, kCreateFolder, &fsRef);
757 if (err == noErr)
758 {
759 NS_NewLocalFile(EmptyString(), PR_TRUE, localFile);
760 nsCOMPtr<nsILocalFileMac> localMacFile(do_QueryInterface(*localFile));
761 if (localMacFile)
762 rv = localMacFile->InitWithFSRef(&fsRef);
763 }
764 return rv;
765}
766#endif
767
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette