1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/ArrayUtils.h"
10 #include "nsAutoPtr.h"
11 #include "nsDirectoryService.h"
12 #include "nsDirectoryServiceDefs.h"
13 #include "nsLocalFile.h"
15 #include "nsStaticAtom.h"
16 #include "nsEnumeratorUtils.h"
18 #include "nsICategoryManager.h"
19 #include "nsISimpleEnumerator.h"
20 #include "nsIStringEnumerator.h"
27 #elif defined(XP_UNIX)
30 #include <sys/param.h>
32 #ifdef MOZ_WIDGET_COCOA
33 #include <CoreServices/CoreServices.h>
34 #include <Carbon/Carbon.h>
38 #include "SpecialSystemDirectory.h"
39 #include "nsAppFileLocationProvider.h"
41 using namespace mozilla
;
43 // define home directory
44 // For Windows platform, We are choosing Appdata folder as HOME
46 #define HOME_DIR NS_WIN_APPDATA_DIR
47 #elif defined (MOZ_WIDGET_COCOA)
48 #define HOME_DIR NS_OSX_HOME_DIR
49 #elif defined (XP_UNIX)
50 #define HOME_DIR NS_UNIX_HOME_DIR
53 //----------------------------------------------------------------------------------------
55 nsDirectoryService::GetCurrentProcessDirectory(nsIFile
** aFile
)
56 //----------------------------------------------------------------------------------------
58 if (NS_WARN_IF(!aFile
)) {
59 return NS_ERROR_INVALID_ARG
;
63 // Set the component registry location:
65 return NS_ERROR_FAILURE
;
70 nsCOMPtr
<nsIProperties
> dirService
;
71 rv
= nsDirectoryService::Create(nullptr,
72 NS_GET_IID(nsIProperties
),
73 getter_AddRefs(dirService
)); // needs to be around for life of product
79 nsCOMPtr
<nsIFile
> aLocalFile
;
80 dirService
->Get(NS_XPCOM_INIT_CURRENT_PROCESS_DIR
, NS_GET_IID(nsIFile
),
81 getter_AddRefs(aLocalFile
));
89 nsLocalFile
* localFile
= new nsLocalFile
;
91 return NS_ERROR_OUT_OF_MEMORY
;
96 wchar_t buf
[MAX_PATH
+ 1];
97 SetLastError(ERROR_SUCCESS
);
98 if (GetModuleFileNameW(0, buf
, mozilla::ArrayLength(buf
)) &&
99 GetLastError() != ERROR_INSUFFICIENT_BUFFER
) {
100 // chop off the executable name by finding the rightmost backslash
101 wchar_t* lastSlash
= wcsrchr(buf
, L
'\\');
103 *(lastSlash
+ 1) = L
'\0';
106 localFile
->InitWithPath(nsDependentString(buf
));
111 #elif defined(MOZ_WIDGET_COCOA)
112 // Works even if we're not bundled.
113 CFBundleRef appBundle
= CFBundleGetMainBundle();
115 CFURLRef bundleURL
= CFBundleCopyExecutableURL(appBundle
);
117 CFURLRef parentURL
= CFURLCreateCopyDeletingLastPathComponent(
118 kCFAllocatorDefault
, bundleURL
);
120 // Pass true for the "resolveAgainstBase" arg to CFURLGetFileSystemRepresentation.
121 // This will resolve the relative portion of the CFURL against it base, giving a full
122 // path, which CFURLCopyFileSystemPath doesn't do.
123 char buffer
[PATH_MAX
];
124 if (CFURLGetFileSystemRepresentation(parentURL
, true,
125 (UInt8
*)buffer
, sizeof(buffer
))) {
127 printf("nsDirectoryService - CurrentProcessDir is: %s\n", buffer
);
129 rv
= localFile
->InitWithNativePath(nsDependentCString(buffer
));
130 if (NS_SUCCEEDED(rv
)) {
134 CFRelease(parentURL
);
136 CFRelease(bundleURL
);
140 NS_ASSERTION(*aFile
, "nsDirectoryService - Could not determine CurrentProcessDir.\n");
145 #elif defined(XP_UNIX)
147 // In the absence of a good way to get the executable directory let
148 // us try this for unix:
149 // - if MOZILLA_FIVE_HOME is defined, that is it
150 // - else give the current directory
151 char buf
[MAXPATHLEN
];
153 // The MOZ_DEFAULT_MOZILLA_FIVE_HOME variable can be set at configure time with
154 // a --with-default-mozilla-five-home=foo autoconf flag.
156 // The idea here is to allow for builds that have a default MOZILLA_FIVE_HOME
157 // regardless of the environment. This makes it easier to write apps that
158 // embed mozilla without having to worry about setting up the environment
160 // We do this by putenv()ing the default value into the environment. Note that
161 // we only do this if it is not already set.
162 #ifdef MOZ_DEFAULT_MOZILLA_FIVE_HOME
163 const char* home
= PR_GetEnv("MOZILLA_FIVE_HOME");
164 if (!home
|| !*home
) {
165 putenv("MOZILLA_FIVE_HOME=" MOZ_DEFAULT_MOZILLA_FIVE_HOME
);
169 char* moz5
= PR_GetEnv("MOZILLA_FIVE_HOME");
171 if (realpath(moz5
, buf
)) {
172 localFile
->InitWithNativePath(nsDependentCString(buf
));
178 static bool firstWarning
= true;
180 if ((!moz5
|| !*moz5
) && firstWarning
) {
181 // Warn that MOZILLA_FIVE_HOME not set, once.
182 printf("Warning: MOZILLA_FIVE_HOME not set.\n");
183 firstWarning
= false;
187 // Fall back to current directory.
188 if (getcwd(buf
, sizeof(buf
))) {
189 localFile
->InitWithNativePath(nsDependentCString(buf
));
196 NS_RELEASE(localFile
);
198 NS_ERROR("unable to get current process directory");
199 return NS_ERROR_FAILURE
;
200 } // GetCurrentProcessDirectory()
202 nsDirectoryService
* nsDirectoryService::gService
= nullptr;
204 nsDirectoryService::nsDirectoryService()
210 nsDirectoryService::Create(nsISupports
* aOuter
, REFNSIID aIID
, void** aResult
)
212 if (NS_WARN_IF(!aResult
)) {
213 return NS_ERROR_INVALID_ARG
;
215 if (NS_WARN_IF(aOuter
)) {
216 return NS_ERROR_NO_AGGREGATION
;
220 return NS_ERROR_NOT_INITIALIZED
;
223 return gService
->QueryInterface(aIID
, aResult
);
226 #define DIR_ATOM(name_, value_) nsIAtom* nsDirectoryService::name_ = nullptr;
227 #include "nsDirectoryServiceAtomList.h"
230 #define DIR_ATOM(name_, value_) NS_STATIC_ATOM_BUFFER(name_##_buffer, value_)
231 #include "nsDirectoryServiceAtomList.h"
234 static const nsStaticAtom directory_atoms
[] = {
235 #define DIR_ATOM(name_, value_) NS_STATIC_ATOM(name_##_buffer, &nsDirectoryService::name_),
236 #include "nsDirectoryServiceAtomList.h"
241 nsDirectoryService::Init()
243 NS_NOTREACHED("nsDirectoryService::Init() for internal use only!");
248 nsDirectoryService::RealInit()
250 NS_ASSERTION(!gService
,
251 "nsDirectoryService::RealInit Mustn't initialize twice!");
253 nsRefPtr
<nsDirectoryService
> self
= new nsDirectoryService();
255 NS_RegisterStaticAtoms(directory_atoms
);
257 // Let the list hold the only reference to the provider.
258 nsAppFileLocationProvider
* defaultProvider
= new nsAppFileLocationProvider
;
259 self
->mProviders
.AppendElement(defaultProvider
);
264 nsDirectoryService::~nsDirectoryService()
268 NS_IMPL_ISUPPORTS(nsDirectoryService
,
271 nsIDirectoryServiceProvider
,
272 nsIDirectoryServiceProvider2
)
276 nsDirectoryService::Undefine(const char* aProp
)
278 if (NS_WARN_IF(!aProp
)) {
279 return NS_ERROR_INVALID_ARG
;
282 nsDependentCString
key(aProp
);
283 if (!mHashtable
.Get(key
, nullptr)) {
284 return NS_ERROR_FAILURE
;
287 mHashtable
.Remove(key
);
292 nsDirectoryService::GetKeys(uint32_t* aCount
, char*** aKeys
)
294 return NS_ERROR_NOT_IMPLEMENTED
;
299 FileData(const char* aProperty
, const nsIID
& aUUID
)
300 : property(aProperty
)
307 const char* property
;
314 FindProviderFile(nsIDirectoryServiceProvider
* aElement
, FileData
* aData
)
317 if (aData
->uuid
.Equals(NS_GET_IID(nsISimpleEnumerator
))) {
318 // Not all providers implement this iface
319 nsCOMPtr
<nsIDirectoryServiceProvider2
> prov2
= do_QueryInterface(aElement
);
321 nsCOMPtr
<nsISimpleEnumerator
> newFiles
;
322 rv
= prov2
->GetFiles(aData
->property
, getter_AddRefs(newFiles
));
323 if (NS_SUCCEEDED(rv
) && newFiles
) {
325 nsCOMPtr
<nsISimpleEnumerator
> unionFiles
;
327 NS_NewUnionEnumerator(getter_AddRefs(unionFiles
),
328 (nsISimpleEnumerator
*)aData
->data
, newFiles
);
331 unionFiles
.swap(*(nsISimpleEnumerator
**)&aData
->data
);
334 NS_ADDREF(aData
->data
= newFiles
);
337 aData
->persistent
= false; // Enumerators can never be persistent
338 return rv
== NS_SUCCESS_AGGREGATE_RESULT
;
342 rv
= aElement
->GetFile(aData
->property
, &aData
->persistent
,
343 (nsIFile
**)&aData
->data
);
344 if (NS_SUCCEEDED(rv
) && aData
->data
) {
353 nsDirectoryService::Get(const char* aProp
, const nsIID
& aUuid
, void** aResult
)
355 if (NS_WARN_IF(!aProp
)) {
356 return NS_ERROR_INVALID_ARG
;
359 nsDependentCString
key(aProp
);
361 nsCOMPtr
<nsIFile
> cachedFile
= mHashtable
.Get(key
);
364 nsCOMPtr
<nsIFile
> cloneFile
;
365 cachedFile
->Clone(getter_AddRefs(cloneFile
));
366 return cloneFile
->QueryInterface(aUuid
, aResult
);
369 // it is not one of our defaults, lets check any providers
370 FileData
fileData(aProp
, aUuid
);
372 for (int32_t i
= mProviders
.Length() - 1; i
>= 0; i
--) {
373 if (!FindProviderFile(mProviders
[i
], &fileData
)) {
378 if (fileData
.persistent
) {
379 Set(aProp
, static_cast<nsIFile
*>(fileData
.data
));
381 nsresult rv
= (fileData
.data
)->QueryInterface(aUuid
, aResult
);
382 NS_RELEASE(fileData
.data
); // addref occurs in FindProviderFile()
386 FindProviderFile(static_cast<nsIDirectoryServiceProvider
*>(this), &fileData
);
388 if (fileData
.persistent
) {
389 Set(aProp
, static_cast<nsIFile
*>(fileData
.data
));
391 nsresult rv
= (fileData
.data
)->QueryInterface(aUuid
, aResult
);
392 NS_RELEASE(fileData
.data
); // addref occurs in FindProviderFile()
396 return NS_ERROR_FAILURE
;
400 nsDirectoryService::Set(const char* aProp
, nsISupports
* aValue
)
402 if (NS_WARN_IF(!aProp
)) {
403 return NS_ERROR_INVALID_ARG
;
406 nsDependentCString
key(aProp
);
407 if (mHashtable
.Get(key
, nullptr) || !aValue
) {
408 return NS_ERROR_FAILURE
;
411 nsCOMPtr
<nsIFile
> ourFile
= do_QueryInterface(aValue
);
413 nsCOMPtr
<nsIFile
> cloneFile
;
414 ourFile
->Clone(getter_AddRefs(cloneFile
));
415 mHashtable
.Put(key
, cloneFile
);
420 return NS_ERROR_FAILURE
;
424 nsDirectoryService::Has(const char* aProp
, bool* aResult
)
426 if (NS_WARN_IF(!aProp
)) {
427 return NS_ERROR_INVALID_ARG
;
431 nsCOMPtr
<nsIFile
> value
;
432 nsresult rv
= Get(aProp
, NS_GET_IID(nsIFile
), getter_AddRefs(value
));
445 nsDirectoryService::RegisterProvider(nsIDirectoryServiceProvider
* aProv
)
448 return NS_ERROR_FAILURE
;
451 mProviders
.AppendElement(aProv
);
456 nsDirectoryService::RegisterCategoryProviders()
458 nsCOMPtr
<nsICategoryManager
> catman
459 (do_GetService(NS_CATEGORYMANAGER_CONTRACTID
));
464 nsCOMPtr
<nsISimpleEnumerator
> entries
;
465 catman
->EnumerateCategory(XPCOM_DIRECTORY_PROVIDER_CATEGORY
,
466 getter_AddRefs(entries
));
468 nsCOMPtr
<nsIUTF8StringEnumerator
> strings(do_QueryInterface(entries
));
474 while (NS_SUCCEEDED(strings
->HasMore(&more
)) && more
) {
476 strings
->GetNext(entry
);
478 nsXPIDLCString contractID
;
479 catman
->GetCategoryEntry(XPCOM_DIRECTORY_PROVIDER_CATEGORY
, entry
.get(),
480 getter_Copies(contractID
));
483 nsCOMPtr
<nsIDirectoryServiceProvider
> provider
= do_GetService(contractID
.get());
485 RegisterProvider(provider
);
492 nsDirectoryService::UnregisterProvider(nsIDirectoryServiceProvider
* aProv
)
495 return NS_ERROR_FAILURE
;
498 mProviders
.RemoveElement(aProv
);
502 // DO NOT ADD ANY LOCATIONS TO THIS FUNCTION UNTIL YOU TALK TO: dougt@netscape.com.
503 // This is meant to be a place of xpcom or system specific file locations, not
504 // application specific locations. If you need the later, register a callback for
508 nsDirectoryService::GetFile(const char* aProp
, bool* aPersistent
,
511 nsCOMPtr
<nsIFile
> localFile
;
512 nsresult rv
= NS_ERROR_FAILURE
;
517 nsCOMPtr
<nsIAtom
> inAtom
= do_GetAtom(aProp
);
519 // check to see if it is one of our defaults
521 if (inAtom
== nsDirectoryService::sCurrentProcess
||
522 inAtom
== nsDirectoryService::sOS_CurrentProcessDirectory
) {
523 rv
= GetCurrentProcessDirectory(getter_AddRefs(localFile
));
526 // Unless otherwise set, the core pieces of the GRE exist
527 // in the current process directory.
528 else if (inAtom
== nsDirectoryService::sGRE_Directory
||
529 inAtom
== nsDirectoryService::sGRE_BinDirectory
) {
530 rv
= GetCurrentProcessDirectory(getter_AddRefs(localFile
));
531 } else if (inAtom
== nsDirectoryService::sOS_DriveDirectory
) {
532 rv
= GetSpecialSystemDirectory(OS_DriveDirectory
, getter_AddRefs(localFile
));
533 } else if (inAtom
== nsDirectoryService::sOS_TemporaryDirectory
) {
534 rv
= GetSpecialSystemDirectory(OS_TemporaryDirectory
, getter_AddRefs(localFile
));
535 } else if (inAtom
== nsDirectoryService::sOS_CurrentProcessDirectory
) {
536 rv
= GetSpecialSystemDirectory(OS_CurrentProcessDirectory
, getter_AddRefs(localFile
));
537 } else if (inAtom
== nsDirectoryService::sOS_CurrentWorkingDirectory
) {
538 rv
= GetSpecialSystemDirectory(OS_CurrentWorkingDirectory
, getter_AddRefs(localFile
));
541 #if defined(MOZ_WIDGET_COCOA)
542 else if (inAtom
== nsDirectoryService::sDirectory
) {
543 rv
= GetOSXFolderType(kClassicDomain
, kSystemFolderType
, getter_AddRefs(localFile
));
544 } else if (inAtom
== nsDirectoryService::sTrashDirectory
) {
545 rv
= GetOSXFolderType(kClassicDomain
, kTrashFolderType
, getter_AddRefs(localFile
));
546 } else if (inAtom
== nsDirectoryService::sStartupDirectory
) {
547 rv
= GetOSXFolderType(kClassicDomain
, kStartupFolderType
, getter_AddRefs(localFile
));
548 } else if (inAtom
== nsDirectoryService::sShutdownDirectory
) {
549 rv
= GetOSXFolderType(kClassicDomain
, kShutdownFolderType
, getter_AddRefs(localFile
));
550 } else if (inAtom
== nsDirectoryService::sAppleMenuDirectory
) {
551 rv
= GetOSXFolderType(kClassicDomain
, kAppleMenuFolderType
, getter_AddRefs(localFile
));
552 } else if (inAtom
== nsDirectoryService::sControlPanelDirectory
) {
553 rv
= GetOSXFolderType(kClassicDomain
, kControlPanelFolderType
, getter_AddRefs(localFile
));
554 } else if (inAtom
== nsDirectoryService::sExtensionDirectory
) {
555 rv
= GetOSXFolderType(kClassicDomain
, kExtensionFolderType
, getter_AddRefs(localFile
));
556 } else if (inAtom
== nsDirectoryService::sFontsDirectory
) {
557 rv
= GetOSXFolderType(kClassicDomain
, kFontsFolderType
, getter_AddRefs(localFile
));
558 } else if (inAtom
== nsDirectoryService::sPreferencesDirectory
) {
559 rv
= GetOSXFolderType(kClassicDomain
, kPreferencesFolderType
, getter_AddRefs(localFile
));
560 } else if (inAtom
== nsDirectoryService::sDocumentsDirectory
) {
561 rv
= GetOSXFolderType(kClassicDomain
, kDocumentsFolderType
, getter_AddRefs(localFile
));
562 } else if (inAtom
== nsDirectoryService::sInternetSearchDirectory
) {
563 rv
= GetOSXFolderType(kClassicDomain
, kInternetSearchSitesFolderType
, getter_AddRefs(localFile
));
564 } else if (inAtom
== nsDirectoryService::sUserLibDirectory
) {
565 rv
= GetOSXFolderType(kUserDomain
, kDomainLibraryFolderType
, getter_AddRefs(localFile
));
566 } else if (inAtom
== nsDirectoryService::sOS_HomeDirectory
) {
567 rv
= GetOSXFolderType(kUserDomain
, kDomainTopLevelFolderType
, getter_AddRefs(localFile
));
568 } else if (inAtom
== nsDirectoryService::sDefaultDownloadDirectory
) {
569 // 10.5 and later, we can use kDownloadsFolderType which is defined in
570 // Folders.h as "down". However, in order to support 10.4 still, we
571 // cannot use the named constant. We'll use it's value, and if it
572 // fails, fall back to the desktop.
573 #ifndef kDownloadsFolderType
574 #define kDownloadsFolderType 'down'
577 rv
= GetOSXFolderType(kUserDomain
, kDownloadsFolderType
,
578 getter_AddRefs(localFile
));
580 rv
= GetOSXFolderType(kUserDomain
, kDesktopFolderType
,
581 getter_AddRefs(localFile
));
583 } else if (inAtom
== nsDirectoryService::sUserDesktopDirectory
||
584 inAtom
== nsDirectoryService::sOS_DesktopDirectory
) {
585 rv
= GetOSXFolderType(kUserDomain
, kDesktopFolderType
, getter_AddRefs(localFile
));
586 } else if (inAtom
== nsDirectoryService::sLocalDesktopDirectory
) {
587 rv
= GetOSXFolderType(kLocalDomain
, kDesktopFolderType
, getter_AddRefs(localFile
));
588 } else if (inAtom
== nsDirectoryService::sUserApplicationsDirectory
) {
589 rv
= GetOSXFolderType(kUserDomain
, kApplicationsFolderType
, getter_AddRefs(localFile
));
590 } else if (inAtom
== nsDirectoryService::sLocalApplicationsDirectory
) {
591 rv
= GetOSXFolderType(kLocalDomain
, kApplicationsFolderType
, getter_AddRefs(localFile
));
592 } else if (inAtom
== nsDirectoryService::sUserDocumentsDirectory
) {
593 rv
= GetOSXFolderType(kUserDomain
, kDocumentsFolderType
, getter_AddRefs(localFile
));
594 } else if (inAtom
== nsDirectoryService::sLocalDocumentsDirectory
) {
595 rv
= GetOSXFolderType(kLocalDomain
, kDocumentsFolderType
, getter_AddRefs(localFile
));
596 } else if (inAtom
== nsDirectoryService::sUserInternetPlugInDirectory
) {
597 rv
= GetOSXFolderType(kUserDomain
, kInternetPlugInFolderType
, getter_AddRefs(localFile
));
598 } else if (inAtom
== nsDirectoryService::sLocalInternetPlugInDirectory
) {
599 rv
= GetOSXFolderType(kLocalDomain
, kInternetPlugInFolderType
, getter_AddRefs(localFile
));
600 } else if (inAtom
== nsDirectoryService::sUserFrameworksDirectory
) {
601 rv
= GetOSXFolderType(kUserDomain
, kFrameworksFolderType
, getter_AddRefs(localFile
));
602 } else if (inAtom
== nsDirectoryService::sLocalFrameworksDirectory
) {
603 rv
= GetOSXFolderType(kLocalDomain
, kFrameworksFolderType
, getter_AddRefs(localFile
));
604 } else if (inAtom
== nsDirectoryService::sUserPreferencesDirectory
) {
605 rv
= GetOSXFolderType(kUserDomain
, kPreferencesFolderType
, getter_AddRefs(localFile
));
606 } else if (inAtom
== nsDirectoryService::sLocalPreferencesDirectory
) {
607 rv
= GetOSXFolderType(kLocalDomain
, kPreferencesFolderType
, getter_AddRefs(localFile
));
608 } else if (inAtom
== nsDirectoryService::sPictureDocumentsDirectory
) {
609 rv
= GetOSXFolderType(kUserDomain
, kPictureDocumentsFolderType
, getter_AddRefs(localFile
));
610 } else if (inAtom
== nsDirectoryService::sMovieDocumentsDirectory
) {
611 rv
= GetOSXFolderType(kUserDomain
, kMovieDocumentsFolderType
, getter_AddRefs(localFile
));
612 } else if (inAtom
== nsDirectoryService::sMusicDocumentsDirectory
) {
613 rv
= GetOSXFolderType(kUserDomain
, kMusicDocumentsFolderType
, getter_AddRefs(localFile
));
614 } else if (inAtom
== nsDirectoryService::sInternetSitesDirectory
) {
615 rv
= GetOSXFolderType(kUserDomain
, kInternetSitesFolderType
, getter_AddRefs(localFile
));
617 #elif defined (XP_WIN)
618 else if (inAtom
== nsDirectoryService::sSystemDirectory
) {
619 rv
= GetSpecialSystemDirectory(Win_SystemDirectory
, getter_AddRefs(localFile
));
620 } else if (inAtom
== nsDirectoryService::sWindowsDirectory
) {
621 rv
= GetSpecialSystemDirectory(Win_WindowsDirectory
, getter_AddRefs(localFile
));
622 } else if (inAtom
== nsDirectoryService::sWindowsProgramFiles
) {
623 rv
= GetSpecialSystemDirectory(Win_ProgramFiles
, getter_AddRefs(localFile
));
624 } else if (inAtom
== nsDirectoryService::sOS_HomeDirectory
) {
625 rv
= GetSpecialSystemDirectory(Win_HomeDirectory
, getter_AddRefs(localFile
));
626 } else if (inAtom
== nsDirectoryService::sDesktop
) {
627 rv
= GetSpecialSystemDirectory(Win_Desktop
, getter_AddRefs(localFile
));
628 } else if (inAtom
== nsDirectoryService::sPrograms
) {
629 rv
= GetSpecialSystemDirectory(Win_Programs
, getter_AddRefs(localFile
));
630 } else if (inAtom
== nsDirectoryService::sControls
) {
631 rv
= GetSpecialSystemDirectory(Win_Controls
, getter_AddRefs(localFile
));
632 } else if (inAtom
== nsDirectoryService::sPrinters
) {
633 rv
= GetSpecialSystemDirectory(Win_Printers
, getter_AddRefs(localFile
));
634 } else if (inAtom
== nsDirectoryService::sPersonal
) {
635 rv
= GetSpecialSystemDirectory(Win_Personal
, getter_AddRefs(localFile
));
636 } else if (inAtom
== nsDirectoryService::sFavorites
) {
637 rv
= GetSpecialSystemDirectory(Win_Favorites
, getter_AddRefs(localFile
));
638 } else if (inAtom
== nsDirectoryService::sStartup
) {
639 rv
= GetSpecialSystemDirectory(Win_Startup
, getter_AddRefs(localFile
));
640 } else if (inAtom
== nsDirectoryService::sRecent
) {
641 rv
= GetSpecialSystemDirectory(Win_Recent
, getter_AddRefs(localFile
));
642 } else if (inAtom
== nsDirectoryService::sSendto
) {
643 rv
= GetSpecialSystemDirectory(Win_Sendto
, getter_AddRefs(localFile
));
644 } else if (inAtom
== nsDirectoryService::sBitbucket
) {
645 rv
= GetSpecialSystemDirectory(Win_Bitbucket
, getter_AddRefs(localFile
));
646 } else if (inAtom
== nsDirectoryService::sStartmenu
) {
647 rv
= GetSpecialSystemDirectory(Win_Startmenu
, getter_AddRefs(localFile
));
648 } else if (inAtom
== nsDirectoryService::sDesktopdirectory
||
649 inAtom
== nsDirectoryService::sOS_DesktopDirectory
) {
650 rv
= GetSpecialSystemDirectory(Win_Desktopdirectory
, getter_AddRefs(localFile
));
651 } else if (inAtom
== nsDirectoryService::sDrives
) {
652 rv
= GetSpecialSystemDirectory(Win_Drives
, getter_AddRefs(localFile
));
653 } else if (inAtom
== nsDirectoryService::sNetwork
) {
654 rv
= GetSpecialSystemDirectory(Win_Network
, getter_AddRefs(localFile
));
655 } else if (inAtom
== nsDirectoryService::sNethood
) {
656 rv
= GetSpecialSystemDirectory(Win_Nethood
, getter_AddRefs(localFile
));
657 } else if (inAtom
== nsDirectoryService::sFonts
) {
658 rv
= GetSpecialSystemDirectory(Win_Fonts
, getter_AddRefs(localFile
));
659 } else if (inAtom
== nsDirectoryService::sTemplates
) {
660 rv
= GetSpecialSystemDirectory(Win_Templates
, getter_AddRefs(localFile
));
661 } else if (inAtom
== nsDirectoryService::sCommon_Startmenu
) {
662 rv
= GetSpecialSystemDirectory(Win_Common_Startmenu
, getter_AddRefs(localFile
));
663 } else if (inAtom
== nsDirectoryService::sCommon_Programs
) {
664 rv
= GetSpecialSystemDirectory(Win_Common_Programs
, getter_AddRefs(localFile
));
665 } else if (inAtom
== nsDirectoryService::sCommon_Startup
) {
666 rv
= GetSpecialSystemDirectory(Win_Common_Startup
, getter_AddRefs(localFile
));
667 } else if (inAtom
== nsDirectoryService::sCommon_Desktopdirectory
) {
668 rv
= GetSpecialSystemDirectory(Win_Common_Desktopdirectory
, getter_AddRefs(localFile
));
669 } else if (inAtom
== nsDirectoryService::sCommon_AppData
) {
670 rv
= GetSpecialSystemDirectory(Win_Common_AppData
, getter_AddRefs(localFile
));
671 } else if (inAtom
== nsDirectoryService::sAppdata
) {
672 rv
= GetSpecialSystemDirectory(Win_Appdata
, getter_AddRefs(localFile
));
673 } else if (inAtom
== nsDirectoryService::sLocalAppdata
) {
674 rv
= GetSpecialSystemDirectory(Win_LocalAppdata
, getter_AddRefs(localFile
));
675 } else if (inAtom
== nsDirectoryService::sPrinthood
) {
676 rv
= GetSpecialSystemDirectory(Win_Printhood
, getter_AddRefs(localFile
));
677 } else if (inAtom
== nsDirectoryService::sWinCookiesDirectory
) {
678 rv
= GetSpecialSystemDirectory(Win_Cookies
, getter_AddRefs(localFile
));
679 } else if (inAtom
== nsDirectoryService::sDefaultDownloadDirectory
) {
680 rv
= GetSpecialSystemDirectory(Win_Downloads
, getter_AddRefs(localFile
));
681 } else if (inAtom
== nsDirectoryService::sDocs
) {
682 rv
= GetSpecialSystemDirectory(Win_Documents
, getter_AddRefs(localFile
));
683 } else if (inAtom
== nsDirectoryService::sPictures
) {
684 rv
= GetSpecialSystemDirectory(Win_Pictures
, getter_AddRefs(localFile
));
685 } else if (inAtom
== nsDirectoryService::sMusic
) {
686 rv
= GetSpecialSystemDirectory(Win_Music
, getter_AddRefs(localFile
));
687 } else if (inAtom
== nsDirectoryService::sVideos
) {
688 rv
= GetSpecialSystemDirectory(Win_Videos
, getter_AddRefs(localFile
));
690 #elif defined (XP_UNIX)
692 else if (inAtom
== nsDirectoryService::sLocalDirectory
) {
693 rv
= GetSpecialSystemDirectory(Unix_LocalDirectory
, getter_AddRefs(localFile
));
694 } else if (inAtom
== nsDirectoryService::sLibDirectory
) {
695 rv
= GetSpecialSystemDirectory(Unix_LibDirectory
, getter_AddRefs(localFile
));
696 } else if (inAtom
== nsDirectoryService::sOS_HomeDirectory
) {
697 rv
= GetSpecialSystemDirectory(Unix_HomeDirectory
, getter_AddRefs(localFile
));
698 } else if (inAtom
== nsDirectoryService::sXDGDesktop
||
699 inAtom
== nsDirectoryService::sOS_DesktopDirectory
) {
700 rv
= GetSpecialSystemDirectory(Unix_XDG_Desktop
, getter_AddRefs(localFile
));
701 *aPersistent
= false;
702 } else if (inAtom
== nsDirectoryService::sXDGDocuments
) {
703 rv
= GetSpecialSystemDirectory(Unix_XDG_Documents
, getter_AddRefs(localFile
));
704 *aPersistent
= false;
705 } else if (inAtom
== nsDirectoryService::sXDGDownload
||
706 inAtom
== nsDirectoryService::sDefaultDownloadDirectory
) {
707 rv
= GetSpecialSystemDirectory(Unix_XDG_Download
, getter_AddRefs(localFile
));
708 *aPersistent
= false;
709 } else if (inAtom
== nsDirectoryService::sXDGMusic
) {
710 rv
= GetSpecialSystemDirectory(Unix_XDG_Music
, getter_AddRefs(localFile
));
711 *aPersistent
= false;
712 } else if (inAtom
== nsDirectoryService::sXDGPictures
) {
713 rv
= GetSpecialSystemDirectory(Unix_XDG_Pictures
, getter_AddRefs(localFile
));
714 *aPersistent
= false;
715 } else if (inAtom
== nsDirectoryService::sXDGPublicShare
) {
716 rv
= GetSpecialSystemDirectory(Unix_XDG_PublicShare
, getter_AddRefs(localFile
));
717 *aPersistent
= false;
718 } else if (inAtom
== nsDirectoryService::sXDGTemplates
) {
719 rv
= GetSpecialSystemDirectory(Unix_XDG_Templates
, getter_AddRefs(localFile
));
720 *aPersistent
= false;
721 } else if (inAtom
== nsDirectoryService::sXDGVideos
) {
722 rv
= GetSpecialSystemDirectory(Unix_XDG_Videos
, getter_AddRefs(localFile
));
723 *aPersistent
= false;
732 return NS_ERROR_FAILURE
;
735 localFile
.forget(aResult
);
740 nsDirectoryService::GetFiles(const char* aProp
, nsISimpleEnumerator
** aResult
)
742 if (NS_WARN_IF(!aResult
)) {
743 return NS_ERROR_INVALID_ARG
;
747 return NS_ERROR_FAILURE
;