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
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/
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
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
24 * Fredrik Holmqvist <thesuckiestemail@yahoo.se>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either of the GNU General Public License Version 2 or later (the "GPL"),
28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
41 #include "nsAutoPtr.h"
42 #include "nsDirectoryService.h"
43 #include "nsDirectoryServiceDefs.h"
44 #include "nsLocalFile.h"
46 #include "nsStaticAtom.h"
47 #include "nsEnumeratorUtils.h"
49 #include "nsICategoryManager.h"
50 #include "nsISimpleEnumerator.h"
51 #include "nsIStringEnumerator.h"
58 #elif defined(XP_UNIX)
61 #include <sys/param.h>
64 #include <CoreServices/CoreServices.h>
68 #include <Processes.h>
71 #include <InternetConfig.h>
74 #define MAX_PATH _MAX_PATH
75 #elif defined(XP_BEOS)
76 #include <FindDirectory.h>
80 #include <sys/param.h>
86 #include "SpecialSystemDirectory.h"
87 #include "nsAppFileLocationProvider.h"
89 #define COMPONENT_REGISTRY_NAME NS_LITERAL_CSTRING("compreg.dat")
90 #define COMPONENT_DIRECTORY NS_LITERAL_CSTRING("components")
92 #define XPTI_REGISTRY_NAME NS_LITERAL_CSTRING("xpti.dat")
94 // define home directory
95 // For Windows platform, We are choosing Appdata folder as HOME
97 #define HOME_DIR NS_WIN_APPDATA_DIR
98 #elif defined (XP_MACOSX)
99 #define HOME_DIR NS_OSX_HOME_DIR
100 #elif defined (XP_UNIX)
101 #define HOME_DIR NS_UNIX_HOME_DIR
102 #elif defined (XP_OS2)
103 #define HOME_DIR NS_OS2_HOME_DIR
104 #elif defined (XP_BEOS)
105 #define HOME_DIR NS_BEOS_HOME_DIR
108 //----------------------------------------------------------------------------------------
110 nsDirectoryService::GetCurrentProcessDirectory(nsILocalFile
** aFile
)
111 //----------------------------------------------------------------------------------------
113 NS_ENSURE_ARG_POINTER(aFile
);
116 // Set the component registry location:
118 return NS_ERROR_FAILURE
;
122 nsCOMPtr
<nsIProperties
> dirService
;
123 rv
= nsDirectoryService::Create(nsnull
,
124 NS_GET_IID(nsIProperties
),
125 getter_AddRefs(dirService
)); // needs to be around for life of product
129 nsCOMPtr
<nsILocalFile
> aLocalFile
;
130 dirService
->Get(NS_XPCOM_INIT_CURRENT_PROCESS_DIR
, NS_GET_IID(nsILocalFile
), getter_AddRefs(aLocalFile
));
139 nsLocalFile
* localFile
= new nsLocalFile
;
141 if (localFile
== nsnull
)
142 return NS_ERROR_OUT_OF_MEMORY
;
143 NS_ADDREF(localFile
);
148 PRUnichar buf
[MAX_PATH
];
149 if ( ::GetModuleFileNameW(0, buf
, sizeof(buf
)) )
151 // chop off the executable name by finding the rightmost backslash
152 PRUnichar
* lastSlash
= wcsrchr(buf
, L
'\\');
154 *(lastSlash
+ 1) = L
'\0';
156 localFile
->InitWithPath(nsDependentString(buf
));
161 #elif defined(XP_MACOSX)
162 // Works even if we're not bundled.
163 CFBundleRef appBundle
= CFBundleGetMainBundle();
164 if (appBundle
!= nsnull
)
166 CFURLRef bundleURL
= CFBundleCopyExecutableURL(appBundle
);
167 if (bundleURL
!= nsnull
)
169 CFURLRef parentURL
= CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault
, bundleURL
);
172 // Pass PR_TRUE for the "resolveAgainstBase" arg to CFURLGetFileSystemRepresentation.
173 // This will resolve the relative portion of the CFURL against it base, giving a full
174 // path, which CFURLCopyFileSystemPath doesn't do.
175 char buffer
[PATH_MAX
];
176 if (CFURLGetFileSystemRepresentation(parentURL
, PR_TRUE
, (UInt8
*)buffer
, sizeof(buffer
)))
179 printf("nsDirectoryService - CurrentProcessDir is: %s\n", buffer
);
181 rv
= localFile
->InitWithNativePath(nsDependentCString(buffer
));
182 if (NS_SUCCEEDED(rv
))
185 CFRelease(parentURL
);
187 CFRelease(bundleURL
);
191 NS_ASSERTION(*aFile
, "nsDirectoryService - Could not determine CurrentProcessDir.\n");
195 #elif defined(XP_UNIX)
197 // In the absence of a good way to get the executable directory let
198 // us try this for unix:
199 // - if MOZILLA_FIVE_HOME is defined, that is it
200 // - else give the current directory
201 char buf
[MAXPATHLEN
];
203 // The MOZ_DEFAULT_MOZILLA_FIVE_HOME variable can be set at configure time with
204 // a --with-default-mozilla-five-home=foo autoconf flag.
206 // The idea here is to allow for builds that have a default MOZILLA_FIVE_HOME
207 // regardless of the environment. This makes it easier to write apps that
208 // embed mozilla without having to worry about setting up the environment
210 // We do this by putenv()ing the default value into the environment. Note that
211 // we only do this if it is not already set.
212 #ifdef MOZ_DEFAULT_MOZILLA_FIVE_HOME
213 const char *home
= PR_GetEnv("MOZILLA_FIVE_HOME");
216 putenv("MOZILLA_FIVE_HOME=" MOZ_DEFAULT_MOZILLA_FIVE_HOME
);
220 char *moz5
= PR_GetEnv("MOZILLA_FIVE_HOME");
223 if (realpath(moz5
, buf
)) {
224 localFile
->InitWithNativePath(nsDependentCString(buf
));
230 static PRBool firstWarning
= PR_TRUE
;
232 if((!moz5
|| !*moz5
) && firstWarning
) {
233 // Warn that MOZILLA_FIVE_HOME not set, once.
234 printf("Warning: MOZILLA_FIVE_HOME not set.\n");
235 firstWarning
= PR_FALSE
;
239 // Fall back to current directory.
240 if (getcwd(buf
, sizeof(buf
)))
242 localFile
->InitWithNativePath(nsDependentCString(buf
));
247 #elif defined(XP_OS2)
250 char buffer
[CCHMAXPATH
];
251 DosGetInfoBlocks( &ptib
, &ppib
);
252 DosQueryModuleName( ppib
->pib_hmte
, CCHMAXPATH
, buffer
);
253 *strrchr( buffer
, '\\') = '\0'; // XXX DBCS misery
254 localFile
->InitWithNativePath(nsDependentCString(buffer
));
258 #elif defined(XP_BEOS)
259 char buf
[MAXPATHLEN
];
264 if(get_next_image_info(0, &cookie
, &info
) == B_OK
)
266 strcpy(buf
, info
.name
);
267 if((p
= strrchr(buf
, '/')) != 0)
269 if( (p
-2 >= buf
) && *(p
-2)=='/' && *(p
-1)=='.')
272 localFile
->InitWithNativePath(nsDependentCString(buf
));
279 NS_RELEASE(localFile
);
281 NS_ERROR("unable to get current process directory");
282 return NS_ERROR_FAILURE
;
283 } // GetCurrentProcessDirectory()
286 nsIAtom
* nsDirectoryService::sCurrentProcess
= nsnull
;
287 nsIAtom
* nsDirectoryService::sComponentRegistry
= nsnull
;
288 nsIAtom
* nsDirectoryService::sXPTIRegistry
= nsnull
;
289 nsIAtom
* nsDirectoryService::sComponentDirectory
= nsnull
;
290 nsIAtom
* nsDirectoryService::sGRE_Directory
= nsnull
;
291 nsIAtom
* nsDirectoryService::sGRE_ComponentDirectory
= nsnull
;
292 nsIAtom
* nsDirectoryService::sOS_DriveDirectory
= nsnull
;
293 nsIAtom
* nsDirectoryService::sOS_TemporaryDirectory
= nsnull
;
294 nsIAtom
* nsDirectoryService::sOS_CurrentProcessDirectory
= nsnull
;
295 nsIAtom
* nsDirectoryService::sOS_CurrentWorkingDirectory
= nsnull
;
296 nsIAtom
* nsDirectoryService::sOS_DesktopDirectory
= nsnull
;
297 nsIAtom
* nsDirectoryService::sOS_HomeDirectory
= nsnull
;
298 #if defined (XP_MACOSX)
299 nsIAtom
* nsDirectoryService::sDirectory
= nsnull
;
300 nsIAtom
* nsDirectoryService::sTrashDirectory
= nsnull
;
301 nsIAtom
* nsDirectoryService::sStartupDirectory
= nsnull
;
302 nsIAtom
* nsDirectoryService::sShutdownDirectory
= nsnull
;
303 nsIAtom
* nsDirectoryService::sAppleMenuDirectory
= nsnull
;
304 nsIAtom
* nsDirectoryService::sControlPanelDirectory
= nsnull
;
305 nsIAtom
* nsDirectoryService::sExtensionDirectory
= nsnull
;
306 nsIAtom
* nsDirectoryService::sFontsDirectory
= nsnull
;
307 nsIAtom
* nsDirectoryService::sPreferencesDirectory
= nsnull
;
308 nsIAtom
* nsDirectoryService::sDocumentsDirectory
= nsnull
;
309 nsIAtom
* nsDirectoryService::sInternetSearchDirectory
= nsnull
;
310 nsIAtom
* nsDirectoryService::sUserLibDirectory
= nsnull
;
311 nsIAtom
* nsDirectoryService::sDefaultDownloadDirectory
= nsnull
;
312 nsIAtom
* nsDirectoryService::sUserDesktopDirectory
= nsnull
;
313 nsIAtom
* nsDirectoryService::sLocalDesktopDirectory
= nsnull
;
314 nsIAtom
* nsDirectoryService::sUserApplicationsDirectory
= nsnull
;
315 nsIAtom
* nsDirectoryService::sLocalApplicationsDirectory
= nsnull
;
316 nsIAtom
* nsDirectoryService::sUserDocumentsDirectory
= nsnull
;
317 nsIAtom
* nsDirectoryService::sLocalDocumentsDirectory
= nsnull
;
318 nsIAtom
* nsDirectoryService::sUserInternetPlugInDirectory
= nsnull
;
319 nsIAtom
* nsDirectoryService::sLocalInternetPlugInDirectory
= nsnull
;
320 nsIAtom
* nsDirectoryService::sUserFrameworksDirectory
= nsnull
;
321 nsIAtom
* nsDirectoryService::sLocalFrameworksDirectory
= nsnull
;
322 nsIAtom
* nsDirectoryService::sUserPreferencesDirectory
= nsnull
;
323 nsIAtom
* nsDirectoryService::sLocalPreferencesDirectory
= nsnull
;
324 nsIAtom
* nsDirectoryService::sPictureDocumentsDirectory
= nsnull
;
325 nsIAtom
* nsDirectoryService::sMovieDocumentsDirectory
= nsnull
;
326 nsIAtom
* nsDirectoryService::sMusicDocumentsDirectory
= nsnull
;
327 nsIAtom
* nsDirectoryService::sInternetSitesDirectory
= nsnull
;
328 #elif defined (XP_WIN)
329 nsIAtom
* nsDirectoryService::sSystemDirectory
= nsnull
;
330 nsIAtom
* nsDirectoryService::sWindowsDirectory
= nsnull
;
331 nsIAtom
* nsDirectoryService::sWindowsProgramFiles
= nsnull
;
332 nsIAtom
* nsDirectoryService::sDesktop
= nsnull
;
333 nsIAtom
* nsDirectoryService::sPrograms
= nsnull
;
334 nsIAtom
* nsDirectoryService::sControls
= nsnull
;
335 nsIAtom
* nsDirectoryService::sPrinters
= nsnull
;
336 nsIAtom
* nsDirectoryService::sPersonal
= nsnull
;
337 nsIAtom
* nsDirectoryService::sFavorites
= nsnull
;
338 nsIAtom
* nsDirectoryService::sStartup
= nsnull
;
339 nsIAtom
* nsDirectoryService::sRecent
= nsnull
;
340 nsIAtom
* nsDirectoryService::sSendto
= nsnull
;
341 nsIAtom
* nsDirectoryService::sBitbucket
= nsnull
;
342 nsIAtom
* nsDirectoryService::sStartmenu
= nsnull
;
343 nsIAtom
* nsDirectoryService::sDesktopdirectory
= nsnull
;
344 nsIAtom
* nsDirectoryService::sDrives
= nsnull
;
345 nsIAtom
* nsDirectoryService::sNetwork
= nsnull
;
346 nsIAtom
* nsDirectoryService::sNethood
= nsnull
;
347 nsIAtom
* nsDirectoryService::sFonts
= nsnull
;
348 nsIAtom
* nsDirectoryService::sTemplates
= nsnull
;
349 nsIAtom
* nsDirectoryService::sCommon_Startmenu
= nsnull
;
350 nsIAtom
* nsDirectoryService::sCommon_Programs
= nsnull
;
351 nsIAtom
* nsDirectoryService::sCommon_Startup
= nsnull
;
352 nsIAtom
* nsDirectoryService::sCommon_Desktopdirectory
= nsnull
;
353 nsIAtom
* nsDirectoryService::sAppdata
= nsnull
;
354 nsIAtom
* nsDirectoryService::sLocalAppdata
= nsnull
;
355 nsIAtom
* nsDirectoryService::sPrinthood
= nsnull
;
356 nsIAtom
* nsDirectoryService::sWinCookiesDirectory
= nsnull
;
357 nsIAtom
* nsDirectoryService::sDefaultDownloadDirectory
= nsnull
;
358 #elif defined (XP_UNIX)
359 nsIAtom
* nsDirectoryService::sLocalDirectory
= nsnull
;
360 nsIAtom
* nsDirectoryService::sLibDirectory
= nsnull
;
361 nsIAtom
* nsDirectoryService::sDefaultDownloadDirectory
= nsnull
;
362 nsIAtom
* nsDirectoryService::sXDGDesktop
= nsnull
;
363 nsIAtom
* nsDirectoryService::sXDGDocuments
= nsnull
;
364 nsIAtom
* nsDirectoryService::sXDGDownload
= nsnull
;
365 nsIAtom
* nsDirectoryService::sXDGMusic
= nsnull
;
366 nsIAtom
* nsDirectoryService::sXDGPictures
= nsnull
;
367 nsIAtom
* nsDirectoryService::sXDGPublicShare
= nsnull
;
368 nsIAtom
* nsDirectoryService::sXDGTemplates
= nsnull
;
369 nsIAtom
* nsDirectoryService::sXDGVideos
= nsnull
;
370 #elif defined (XP_OS2)
371 nsIAtom
* nsDirectoryService::sSystemDirectory
= nsnull
;
372 nsIAtom
* nsDirectoryService::sOS2Directory
= nsnull
;
373 #elif defined (XP_BEOS)
374 nsIAtom
* nsDirectoryService::sSettingsDirectory
= nsnull
;
375 nsIAtom
* nsDirectoryService::sSystemDirectory
= nsnull
;
379 nsDirectoryService
* nsDirectoryService::gService
= nsnull
;
381 nsDirectoryService::nsDirectoryService() :
382 mHashtable(256, PR_TRUE
)
387 nsDirectoryService::Create(nsISupports
*outer
, REFNSIID aIID
, void **aResult
)
389 NS_ENSURE_ARG_POINTER(aResult
);
390 NS_ENSURE_NO_AGGREGATION(outer
);
394 return NS_ERROR_NOT_INITIALIZED
;
397 return gService
->QueryInterface(aIID
, aResult
);
400 static const nsStaticAtom directory_atoms
[] = {
401 { NS_XPCOM_CURRENT_PROCESS_DIR
, &nsDirectoryService::sCurrentProcess
},
402 { NS_XPCOM_COMPONENT_REGISTRY_FILE
, &nsDirectoryService::sComponentRegistry
},
403 { NS_XPCOM_COMPONENT_DIR
, &nsDirectoryService::sComponentDirectory
},
404 { NS_XPCOM_XPTI_REGISTRY_FILE
, &nsDirectoryService::sXPTIRegistry
},
405 { NS_GRE_DIR
, &nsDirectoryService::sGRE_Directory
},
406 { NS_GRE_COMPONENT_DIR
, &nsDirectoryService::sGRE_ComponentDirectory
},
407 { NS_OS_DRIVE_DIR
, &nsDirectoryService::sOS_DriveDirectory
},
408 { NS_OS_TEMP_DIR
, &nsDirectoryService::sOS_TemporaryDirectory
},
409 { NS_OS_CURRENT_PROCESS_DIR
, &nsDirectoryService::sOS_CurrentProcessDirectory
},
410 { NS_OS_CURRENT_WORKING_DIR
, &nsDirectoryService::sOS_CurrentWorkingDirectory
},
411 { NS_OS_HOME_DIR
, &nsDirectoryService::sOS_HomeDirectory
},
412 { NS_OS_DESKTOP_DIR
, &nsDirectoryService::sOS_DesktopDirectory
},
413 { NS_XPCOM_INIT_CURRENT_PROCESS_DIR
, nsnull
},
414 #if defined (XP_MACOSX)
415 { NS_OS_SYSTEM_DIR
, &nsDirectoryService::sDirectory
},
416 { NS_MAC_TRASH_DIR
, &nsDirectoryService::sTrashDirectory
},
417 { NS_MAC_STARTUP_DIR
, &nsDirectoryService::sStartupDirectory
},
418 { NS_MAC_SHUTDOWN_DIR
, &nsDirectoryService::sShutdownDirectory
},
419 { NS_MAC_APPLE_MENU_DIR
, &nsDirectoryService::sAppleMenuDirectory
},
420 { NS_MAC_CONTROL_PANELS_DIR
, &nsDirectoryService::sControlPanelDirectory
},
421 { NS_MAC_EXTENSIONS_DIR
, &nsDirectoryService::sExtensionDirectory
},
422 { NS_MAC_FONTS_DIR
, &nsDirectoryService::sFontsDirectory
},
423 { NS_MAC_PREFS_DIR
, &nsDirectoryService::sPreferencesDirectory
},
424 { NS_MAC_DOCUMENTS_DIR
, &nsDirectoryService::sDocumentsDirectory
},
425 { NS_MAC_INTERNET_SEARCH_DIR
, &nsDirectoryService::sInternetSearchDirectory
},
426 { NS_MAC_USER_LIB_DIR
, &nsDirectoryService::sUserLibDirectory
},
427 { NS_OSX_DEFAULT_DOWNLOAD_DIR
, &nsDirectoryService::sDefaultDownloadDirectory
},
428 { NS_OSX_USER_DESKTOP_DIR
, &nsDirectoryService::sUserDesktopDirectory
},
429 { NS_OSX_LOCAL_DESKTOP_DIR
, &nsDirectoryService::sLocalDesktopDirectory
},
430 { NS_OSX_USER_APPLICATIONS_DIR
, &nsDirectoryService::sUserApplicationsDirectory
},
431 { NS_OSX_LOCAL_APPLICATIONS_DIR
, &nsDirectoryService::sLocalApplicationsDirectory
},
432 { NS_OSX_USER_DOCUMENTS_DIR
, &nsDirectoryService::sUserDocumentsDirectory
},
433 { NS_OSX_LOCAL_DOCUMENTS_DIR
, &nsDirectoryService::sLocalDocumentsDirectory
},
434 { NS_OSX_USER_INTERNET_PLUGIN_DIR
, &nsDirectoryService::sUserInternetPlugInDirectory
},
435 { NS_OSX_LOCAL_INTERNET_PLUGIN_DIR
, &nsDirectoryService::sLocalInternetPlugInDirectory
},
436 { NS_OSX_USER_FRAMEWORKS_DIR
, &nsDirectoryService::sUserFrameworksDirectory
},
437 { NS_OSX_LOCAL_FRAMEWORKS_DIR
, &nsDirectoryService::sLocalFrameworksDirectory
},
438 { NS_OSX_USER_PREFERENCES_DIR
, &nsDirectoryService::sUserPreferencesDirectory
},
439 { NS_OSX_LOCAL_PREFERENCES_DIR
, &nsDirectoryService::sLocalPreferencesDirectory
},
440 { NS_OSX_PICTURE_DOCUMENTS_DIR
, &nsDirectoryService::sPictureDocumentsDirectory
},
441 { NS_OSX_MOVIE_DOCUMENTS_DIR
, &nsDirectoryService::sMovieDocumentsDirectory
},
442 { NS_OSX_MUSIC_DOCUMENTS_DIR
, &nsDirectoryService::sMusicDocumentsDirectory
},
443 { NS_OSX_INTERNET_SITES_DIR
, &nsDirectoryService::sInternetSitesDirectory
},
444 #elif defined (XP_WIN)
445 { NS_OS_SYSTEM_DIR
, &nsDirectoryService::sSystemDirectory
},
446 { NS_WIN_WINDOWS_DIR
, &nsDirectoryService::sWindowsDirectory
},
447 { NS_WIN_PROGRAM_FILES_DIR
, &nsDirectoryService::sWindowsProgramFiles
},
448 { NS_WIN_DESKTOP_DIR
, &nsDirectoryService::sDesktop
},
449 { NS_WIN_PROGRAMS_DIR
, &nsDirectoryService::sPrograms
},
450 { NS_WIN_CONTROLS_DIR
, &nsDirectoryService::sControls
},
451 { NS_WIN_PRINTERS_DIR
, &nsDirectoryService::sPrinters
},
452 { NS_WIN_PERSONAL_DIR
, &nsDirectoryService::sPersonal
},
453 { NS_WIN_FAVORITES_DIR
, &nsDirectoryService::sFavorites
},
454 { NS_WIN_STARTUP_DIR
, &nsDirectoryService::sStartup
},
455 { NS_WIN_RECENT_DIR
, &nsDirectoryService::sRecent
},
456 { NS_WIN_SEND_TO_DIR
, &nsDirectoryService::sSendto
},
457 { NS_WIN_BITBUCKET_DIR
, &nsDirectoryService::sBitbucket
},
458 { NS_WIN_STARTMENU_DIR
, &nsDirectoryService::sStartmenu
},
459 { NS_WIN_DESKTOP_DIRECTORY
, &nsDirectoryService::sDesktopdirectory
},
460 { NS_WIN_DRIVES_DIR
, &nsDirectoryService::sDrives
},
461 { NS_WIN_NETWORK_DIR
, &nsDirectoryService::sNetwork
},
462 { NS_WIN_NETHOOD_DIR
, &nsDirectoryService::sNethood
},
463 { NS_WIN_FONTS_DIR
, &nsDirectoryService::sFonts
},
464 { NS_WIN_TEMPLATES_DIR
, &nsDirectoryService::sTemplates
},
465 { NS_WIN_COMMON_STARTMENU_DIR
, &nsDirectoryService::sCommon_Startmenu
},
466 { NS_WIN_COMMON_PROGRAMS_DIR
, &nsDirectoryService::sCommon_Programs
},
467 { NS_WIN_COMMON_STARTUP_DIR
, &nsDirectoryService::sCommon_Startup
},
468 { NS_WIN_COMMON_DESKTOP_DIRECTORY
, &nsDirectoryService::sCommon_Desktopdirectory
},
469 { NS_WIN_APPDATA_DIR
, &nsDirectoryService::sAppdata
},
470 { NS_WIN_LOCAL_APPDATA_DIR
, &nsDirectoryService::sLocalAppdata
},
471 { NS_WIN_PRINTHOOD
, &nsDirectoryService::sPrinthood
},
472 { NS_WIN_COOKIES_DIR
, &nsDirectoryService::sWinCookiesDirectory
},
473 { NS_WIN_DEFAULT_DOWNLOAD_DIR
, &nsDirectoryService::sDefaultDownloadDirectory
},
474 #elif defined (XP_UNIX)
475 { NS_UNIX_LOCAL_DIR
, &nsDirectoryService::sLocalDirectory
},
476 { NS_UNIX_LIB_DIR
, &nsDirectoryService::sLibDirectory
},
477 { NS_UNIX_DEFAULT_DOWNLOAD_DIR
, &nsDirectoryService::sDefaultDownloadDirectory
},
478 { NS_UNIX_XDG_DESKTOP_DIR
, &nsDirectoryService::sXDGDesktop
},
479 { NS_UNIX_XDG_DOCUMENTS_DIR
, &nsDirectoryService::sXDGDocuments
},
480 { NS_UNIX_XDG_DOWNLOAD_DIR
, &nsDirectoryService::sXDGDownload
},
481 { NS_UNIX_XDG_MUSIC_DIR
, &nsDirectoryService::sXDGMusic
},
482 { NS_UNIX_XDG_PICTURES_DIR
, &nsDirectoryService::sXDGPictures
},
483 { NS_UNIX_XDG_PUBLIC_SHARE_DIR
, &nsDirectoryService::sXDGPublicShare
},
484 { NS_UNIX_XDG_TEMPLATES_DIR
, &nsDirectoryService::sXDGTemplates
},
485 { NS_UNIX_XDG_VIDEOS_DIR
, &nsDirectoryService::sXDGVideos
},
486 #elif defined (XP_OS2)
487 { NS_OS_SYSTEM_DIR
, &nsDirectoryService::sSystemDirectory
},
488 { NS_OS2_DIR
, &nsDirectoryService::sOS2Directory
},
489 #elif defined (XP_BEOS)
490 { NS_OS_SYSTEM_DIR
, &nsDirectoryService::sSystemDirectory
},
491 { NS_BEOS_SETTINGS_DIR
, &nsDirectoryService::sSettingsDirectory
},
496 nsDirectoryService::Init()
498 NS_NOTREACHED("nsDirectoryService::Init() for internal use only!");
503 nsDirectoryService::RealInit()
505 NS_ASSERTION(!gService
,
506 "nsDirectoryService::RealInit Mustn't initialize twice!");
510 nsRefPtr
<nsDirectoryService
> self
= new nsDirectoryService();
512 return NS_ERROR_OUT_OF_MEMORY
;
514 rv
= NS_NewISupportsArray(getter_AddRefs(((nsDirectoryService
*) self
)->mProviders
));
518 NS_RegisterStaticAtoms(directory_atoms
, NS_ARRAY_LENGTH(directory_atoms
));
520 // Let the list hold the only reference to the provider.
521 nsAppFileLocationProvider
*defaultProvider
= new nsAppFileLocationProvider
;
522 if (!defaultProvider
)
523 return NS_ERROR_OUT_OF_MEMORY
;
524 // AppendElement returns PR_TRUE for success.
525 rv
= ((nsDirectoryService
*) self
)->mProviders
->AppendElement(defaultProvider
) ? NS_OK
: NS_ERROR_FAILURE
;
534 nsDirectoryService::ReleaseValues(nsHashKey
* key
, void* data
, void* closure
)
536 nsISupports
* value
= (nsISupports
*)data
;
537 NS_IF_RELEASE(value
);
541 nsDirectoryService::~nsDirectoryService()
545 NS_IMPL_THREADSAFE_ISUPPORTS4(nsDirectoryService
, nsIProperties
, nsIDirectoryService
, nsIDirectoryServiceProvider
, nsIDirectoryServiceProvider2
)
549 nsDirectoryService::Undefine(const char* prop
)
553 nsCStringKey
key(prop
);
554 if (!mHashtable
.Exists(&key
))
555 return NS_ERROR_FAILURE
;
557 mHashtable
.Remove (&key
);
562 nsDirectoryService::GetKeys(PRUint32
*count
, char ***keys
)
564 return NS_ERROR_NOT_IMPLEMENTED
;
569 FileData(const char* aProperty
,
570 const nsIID
& aUUID
) :
576 const char* property
;
582 static PRBool
FindProviderFile(nsISupports
* aElement
, void *aData
)
585 FileData
* fileData
= (FileData
*)aData
;
586 if (fileData
->uuid
.Equals(NS_GET_IID(nsISimpleEnumerator
)))
588 // Not all providers implement this iface
589 nsCOMPtr
<nsIDirectoryServiceProvider2
> prov2
= do_QueryInterface(aElement
);
592 nsCOMPtr
<nsISimpleEnumerator
> newFiles
;
593 rv
= prov2
->GetFiles(fileData
->property
, getter_AddRefs(newFiles
));
594 if (NS_SUCCEEDED(rv
) && newFiles
) {
595 if (fileData
->data
) {
596 nsCOMPtr
<nsISimpleEnumerator
> unionFiles
;
598 NS_NewUnionEnumerator(getter_AddRefs(unionFiles
),
599 (nsISimpleEnumerator
*) fileData
->data
, newFiles
);
602 unionFiles
.swap(* (nsISimpleEnumerator
**) &fileData
->data
);
606 NS_ADDREF(fileData
->data
= newFiles
);
609 fileData
->persistent
= PR_FALSE
; // Enumerators can never be persistent
610 return rv
== NS_SUCCESS_AGGREGATE_RESULT
;
616 nsCOMPtr
<nsIDirectoryServiceProvider
> prov
= do_QueryInterface(aElement
);
619 rv
= prov
->GetFile(fileData
->property
, &fileData
->persistent
, (nsIFile
**)&fileData
->data
);
620 if (NS_SUCCEEDED(rv
) && fileData
->data
)
629 nsDirectoryService::Get(const char* prop
, const nsIID
& uuid
, void* *result
)
633 nsCStringKey
key(prop
);
635 nsCOMPtr
<nsISupports
> value
= dont_AddRef(mHashtable
.Get(&key
));
639 nsCOMPtr
<nsIFile
> cloneFile
;
640 nsCOMPtr
<nsIFile
> cachedFile
= do_QueryInterface(value
);
641 NS_ASSERTION(cachedFile
,
642 "nsDirectoryService::Get nsIFile expected");
644 cachedFile
->Clone(getter_AddRefs(cloneFile
));
645 return cloneFile
->QueryInterface(uuid
, result
);
648 // it is not one of our defaults, lets check any providers
649 FileData
fileData(prop
, uuid
);
651 mProviders
->EnumerateBackwards(FindProviderFile
, &fileData
);
654 if (fileData
.persistent
)
656 Set(prop
, static_cast<nsIFile
*>(fileData
.data
));
658 nsresult rv
= (fileData
.data
)->QueryInterface(uuid
, result
);
659 NS_RELEASE(fileData
.data
); // addref occurs in FindProviderFile()
663 FindProviderFile(static_cast<nsIDirectoryServiceProvider
*>(this), &fileData
);
666 if (fileData
.persistent
)
668 Set(prop
, static_cast<nsIFile
*>(fileData
.data
));
670 nsresult rv
= (fileData
.data
)->QueryInterface(uuid
, result
);
671 NS_RELEASE(fileData
.data
); // addref occurs in FindProviderFile()
675 return NS_ERROR_FAILURE
;
679 nsDirectoryService::Set(const char* prop
, nsISupports
* value
)
683 nsCStringKey
key(prop
);
684 if (mHashtable
.Exists(&key
) || value
== nsnull
)
685 return NS_ERROR_FAILURE
;
687 nsCOMPtr
<nsIFile
> ourFile
;
688 value
->QueryInterface(NS_GET_IID(nsIFile
), getter_AddRefs(ourFile
));
691 nsCOMPtr
<nsIFile
> cloneFile
;
692 ourFile
->Clone (getter_AddRefs (cloneFile
));
693 mHashtable
.Put(&key
, cloneFile
);
698 return NS_ERROR_FAILURE
;
702 nsDirectoryService::Has(const char *prop
, PRBool
*_retval
)
707 nsCOMPtr
<nsIFile
> value
;
708 nsresult rv
= Get(prop
, NS_GET_IID(nsIFile
), getter_AddRefs(value
));
721 nsDirectoryService::RegisterProvider(nsIDirectoryServiceProvider
*prov
)
725 return NS_ERROR_FAILURE
;
727 return NS_ERROR_NOT_INITIALIZED
;
729 nsCOMPtr
<nsISupports
> supports
= do_QueryInterface(prov
, &rv
);
730 if (NS_FAILED(rv
)) return rv
;
732 // AppendElement returns PR_TRUE for success.
733 return mProviders
->AppendElement(supports
) ? NS_OK
: NS_ERROR_FAILURE
;
737 nsDirectoryService::RegisterCategoryProviders()
739 nsCOMPtr
<nsICategoryManager
> catman
740 (do_GetService(NS_CATEGORYMANAGER_CONTRACTID
));
744 nsCOMPtr
<nsISimpleEnumerator
> entries
;
745 catman
->EnumerateCategory(XPCOM_DIRECTORY_PROVIDER_CATEGORY
,
746 getter_AddRefs(entries
));
748 nsCOMPtr
<nsIUTF8StringEnumerator
> strings(do_QueryInterface(entries
));
753 while (NS_SUCCEEDED(strings
->HasMore(&more
)) && more
) {
755 strings
->GetNext(entry
);
757 nsXPIDLCString contractID
;
758 catman
->GetCategoryEntry(XPCOM_DIRECTORY_PROVIDER_CATEGORY
, entry
.get(), getter_Copies(contractID
));
761 nsCOMPtr
<nsIDirectoryServiceProvider
> provider
= do_GetService(contractID
.get());
763 RegisterProvider(provider
);
769 nsDirectoryService::UnregisterProvider(nsIDirectoryServiceProvider
*prov
)
773 return NS_ERROR_FAILURE
;
775 return NS_ERROR_NOT_INITIALIZED
;
777 nsCOMPtr
<nsISupports
> supports
= do_QueryInterface(prov
, &rv
);
778 if (NS_FAILED(rv
)) return rv
;
780 // RemoveElement returns PR_TRUE for success.
781 return mProviders
->RemoveElement(supports
) ? NS_OK
: NS_ERROR_FAILURE
;
784 // DO NOT ADD ANY LOCATIONS TO THIS FUNCTION UNTIL YOU TALK TO: dougt@netscape.com.
785 // This is meant to be a place of xpcom or system specific file locations, not
786 // application specific locations. If you need the later, register a callback for
790 nsDirectoryService::GetFile(const char *prop
, PRBool
*persistent
, nsIFile
**_retval
)
792 nsCOMPtr
<nsILocalFile
> localFile
;
793 nsresult rv
= NS_ERROR_FAILURE
;
796 *persistent
= PR_TRUE
;
798 nsIAtom
* inAtom
= NS_NewAtom(prop
);
800 // check to see if it is one of our defaults
802 if (inAtom
== nsDirectoryService::sCurrentProcess
||
803 inAtom
== nsDirectoryService::sOS_CurrentProcessDirectory
)
805 rv
= GetCurrentProcessDirectory(getter_AddRefs(localFile
));
807 else if (inAtom
== nsDirectoryService::sComponentRegistry
)
809 rv
= GetCurrentProcessDirectory(getter_AddRefs(localFile
));
811 return NS_ERROR_FAILURE
;
813 localFile
->AppendNative(COMPONENT_DIRECTORY
);
814 localFile
->AppendNative(COMPONENT_REGISTRY_NAME
);
816 else if (inAtom
== nsDirectoryService::sXPTIRegistry
)
818 rv
= GetCurrentProcessDirectory(getter_AddRefs(localFile
));
820 return NS_ERROR_FAILURE
;
822 localFile
->AppendNative(COMPONENT_DIRECTORY
);
823 localFile
->AppendNative(XPTI_REGISTRY_NAME
);
826 // Unless otherwise set, the core pieces of the GRE exist
827 // in the current process directory.
828 else if (inAtom
== nsDirectoryService::sGRE_Directory
)
830 rv
= GetCurrentProcessDirectory(getter_AddRefs(localFile
));
832 // the GRE components directory is relative to the GRE directory
833 // by default; applications may override this behavior in special
835 else if (inAtom
== nsDirectoryService::sGRE_ComponentDirectory
)
837 rv
= Get(NS_GRE_DIR
, NS_GET_IID(nsILocalFile
), getter_AddRefs(localFile
));
839 localFile
->AppendNative(COMPONENT_DIRECTORY
);
841 else if (inAtom
== nsDirectoryService::sComponentDirectory
)
843 rv
= GetCurrentProcessDirectory(getter_AddRefs(localFile
));
845 localFile
->AppendNative(COMPONENT_DIRECTORY
);
847 else if (inAtom
== nsDirectoryService::sOS_DriveDirectory
)
849 rv
= GetSpecialSystemDirectory(OS_DriveDirectory
, getter_AddRefs(localFile
));
851 else if (inAtom
== nsDirectoryService::sOS_TemporaryDirectory
)
853 rv
= GetSpecialSystemDirectory(OS_TemporaryDirectory
, getter_AddRefs(localFile
));
855 else if (inAtom
== nsDirectoryService::sOS_CurrentProcessDirectory
)
857 rv
= GetSpecialSystemDirectory(OS_CurrentProcessDirectory
, getter_AddRefs(localFile
));
859 else if (inAtom
== nsDirectoryService::sOS_CurrentWorkingDirectory
)
861 rv
= GetSpecialSystemDirectory(OS_CurrentWorkingDirectory
, getter_AddRefs(localFile
));
864 #if defined(XP_MACOSX)
865 else if (inAtom
== nsDirectoryService::sDirectory
)
867 rv
= GetOSXFolderType(kClassicDomain
, kSystemFolderType
, getter_AddRefs(localFile
));
869 else if (inAtom
== nsDirectoryService::sTrashDirectory
)
871 rv
= GetOSXFolderType(kClassicDomain
, kTrashFolderType
, getter_AddRefs(localFile
));
873 else if (inAtom
== nsDirectoryService::sStartupDirectory
)
875 rv
= GetOSXFolderType(kClassicDomain
, kStartupFolderType
, getter_AddRefs(localFile
));
877 else if (inAtom
== nsDirectoryService::sShutdownDirectory
)
879 rv
= GetOSXFolderType(kClassicDomain
, kShutdownFolderType
, getter_AddRefs(localFile
));
881 else if (inAtom
== nsDirectoryService::sAppleMenuDirectory
)
883 rv
= GetOSXFolderType(kClassicDomain
, kAppleMenuFolderType
, getter_AddRefs(localFile
));
885 else if (inAtom
== nsDirectoryService::sControlPanelDirectory
)
887 rv
= GetOSXFolderType(kClassicDomain
, kControlPanelFolderType
, getter_AddRefs(localFile
));
889 else if (inAtom
== nsDirectoryService::sExtensionDirectory
)
891 rv
= GetOSXFolderType(kClassicDomain
, kExtensionFolderType
, getter_AddRefs(localFile
));
893 else if (inAtom
== nsDirectoryService::sFontsDirectory
)
895 rv
= GetOSXFolderType(kClassicDomain
, kFontsFolderType
, getter_AddRefs(localFile
));
897 else if (inAtom
== nsDirectoryService::sPreferencesDirectory
)
899 rv
= GetOSXFolderType(kClassicDomain
, kPreferencesFolderType
, getter_AddRefs(localFile
));
901 else if (inAtom
== nsDirectoryService::sDocumentsDirectory
)
903 rv
= GetOSXFolderType(kClassicDomain
, kDocumentsFolderType
, getter_AddRefs(localFile
));
905 else if (inAtom
== nsDirectoryService::sInternetSearchDirectory
)
907 rv
= GetOSXFolderType(kClassicDomain
, kInternetSearchSitesFolderType
, getter_AddRefs(localFile
));
909 else if (inAtom
== nsDirectoryService::sUserLibDirectory
)
911 rv
= GetOSXFolderType(kUserDomain
, kDomainLibraryFolderType
, getter_AddRefs(localFile
));
913 else if (inAtom
== nsDirectoryService::sOS_HomeDirectory
)
915 rv
= GetOSXFolderType(kUserDomain
, kDomainTopLevelFolderType
, getter_AddRefs(localFile
));
917 else if (inAtom
== nsDirectoryService::sDefaultDownloadDirectory
)
919 NS_NewLocalFile(EmptyString(), PR_TRUE
, getter_AddRefs(localFile
));
920 nsCOMPtr
<nsILocalFileMac
> localMacFile(do_QueryInterface(localFile
));
925 ICInstance icInstance
;
927 err
= ::ICStart(&icInstance
, 'XPCM');
930 // ICGetPref() crashes when getting the download directory if the download
931 // directory has never been specified (e.g. a new user account), bug 265903.
932 // To work around this we enumerate through the IC prefs to see if the
933 // download directory has been specified before trying to obtain it.
935 err
= ::ICCountPref(icInstance
, &numPrefs
);
938 for ( long i
= 0; i
< numPrefs
; ++i
)
941 err
= ::ICGetIndPref(icInstance
, i
, key
);
942 if ( err
== noErr
&& ( PLstrcmp( key
, kICDownloadFolder
) == 0 ) )
945 ICFileSpec icFileSpec
;
946 long size
= kICFileSpecHeaderSize
;
947 err
= ::ICGetPref(icInstance
, kICDownloadFolder
, &attrs
, &icFileSpec
, &size
);
948 if (err
== noErr
|| (err
== icTruncatedErr
&& size
>= kICFileSpecHeaderSize
))
950 rv
= localMacFile
->InitWithFSSpec(&icFileSpec
.fss
);
956 ::ICStop(icInstance
);
961 // We got an error getting the DL folder from IC so try finding the user's Desktop folder
962 rv
= GetOSXFolderType(kUserDomain
, kDesktopFolderType
, getter_AddRefs(localFile
));
966 // Don't cache the DL directory as the user may change it while we're running.
967 // Negligible perf hit as this directory is only requested for downloads
968 *persistent
= PR_FALSE
;
970 else if (inAtom
== nsDirectoryService::sUserDesktopDirectory
||
971 inAtom
== nsDirectoryService::sOS_DesktopDirectory
)
973 rv
= GetOSXFolderType(kUserDomain
, kDesktopFolderType
, getter_AddRefs(localFile
));
975 else if (inAtom
== nsDirectoryService::sLocalDesktopDirectory
)
977 rv
= GetOSXFolderType(kLocalDomain
, kDesktopFolderType
, getter_AddRefs(localFile
));
979 else if (inAtom
== nsDirectoryService::sUserApplicationsDirectory
)
981 rv
= GetOSXFolderType(kUserDomain
, kApplicationsFolderType
, getter_AddRefs(localFile
));
983 else if (inAtom
== nsDirectoryService::sLocalApplicationsDirectory
)
985 rv
= GetOSXFolderType(kLocalDomain
, kApplicationsFolderType
, getter_AddRefs(localFile
));
987 else if (inAtom
== nsDirectoryService::sUserDocumentsDirectory
)
989 rv
= GetOSXFolderType(kUserDomain
, kDocumentsFolderType
, getter_AddRefs(localFile
));
991 else if (inAtom
== nsDirectoryService::sLocalDocumentsDirectory
)
993 rv
= GetOSXFolderType(kLocalDomain
, kDocumentsFolderType
, getter_AddRefs(localFile
));
995 else if (inAtom
== nsDirectoryService::sUserInternetPlugInDirectory
)
997 rv
= GetOSXFolderType(kUserDomain
, kInternetPlugInFolderType
, getter_AddRefs(localFile
));
999 else if (inAtom
== nsDirectoryService::sLocalInternetPlugInDirectory
)
1001 rv
= GetOSXFolderType(kLocalDomain
, kInternetPlugInFolderType
, getter_AddRefs(localFile
));
1003 else if (inAtom
== nsDirectoryService::sUserFrameworksDirectory
)
1005 rv
= GetOSXFolderType(kUserDomain
, kFrameworksFolderType
, getter_AddRefs(localFile
));
1007 else if (inAtom
== nsDirectoryService::sLocalFrameworksDirectory
)
1009 rv
= GetOSXFolderType(kLocalDomain
, kFrameworksFolderType
, getter_AddRefs(localFile
));
1011 else if (inAtom
== nsDirectoryService::sUserPreferencesDirectory
)
1013 rv
= GetOSXFolderType(kUserDomain
, kPreferencesFolderType
, getter_AddRefs(localFile
));
1015 else if (inAtom
== nsDirectoryService::sLocalPreferencesDirectory
)
1017 rv
= GetOSXFolderType(kLocalDomain
, kPreferencesFolderType
, getter_AddRefs(localFile
));
1019 else if (inAtom
== nsDirectoryService::sPictureDocumentsDirectory
)
1021 rv
= GetOSXFolderType(kUserDomain
, kPictureDocumentsFolderType
, getter_AddRefs(localFile
));
1023 else if (inAtom
== nsDirectoryService::sMovieDocumentsDirectory
)
1025 rv
= GetOSXFolderType(kUserDomain
, kMovieDocumentsFolderType
, getter_AddRefs(localFile
));
1027 else if (inAtom
== nsDirectoryService::sMusicDocumentsDirectory
)
1029 rv
= GetOSXFolderType(kUserDomain
, kMusicDocumentsFolderType
, getter_AddRefs(localFile
));
1031 else if (inAtom
== nsDirectoryService::sInternetSitesDirectory
)
1033 rv
= GetOSXFolderType(kUserDomain
, kInternetSitesFolderType
, getter_AddRefs(localFile
));
1035 #elif defined (XP_WIN)
1036 else if (inAtom
== nsDirectoryService::sSystemDirectory
)
1038 rv
= GetSpecialSystemDirectory(Win_SystemDirectory
, getter_AddRefs(localFile
));
1040 else if (inAtom
== nsDirectoryService::sWindowsDirectory
)
1042 rv
= GetSpecialSystemDirectory(Win_WindowsDirectory
, getter_AddRefs(localFile
));
1044 else if (inAtom
== nsDirectoryService::sWindowsProgramFiles
)
1046 rv
= GetSpecialSystemDirectory(Win_ProgramFiles
, getter_AddRefs(localFile
));
1048 else if (inAtom
== nsDirectoryService::sOS_HomeDirectory
)
1050 rv
= GetSpecialSystemDirectory(Win_HomeDirectory
, getter_AddRefs(localFile
));
1052 else if (inAtom
== nsDirectoryService::sDesktop
)
1054 rv
= GetSpecialSystemDirectory(Win_Desktop
, getter_AddRefs(localFile
));
1056 else if (inAtom
== nsDirectoryService::sPrograms
)
1058 rv
= GetSpecialSystemDirectory(Win_Programs
, getter_AddRefs(localFile
));
1060 else if (inAtom
== nsDirectoryService::sControls
)
1062 rv
= GetSpecialSystemDirectory(Win_Controls
, getter_AddRefs(localFile
));
1064 else if (inAtom
== nsDirectoryService::sPrinters
)
1066 rv
= GetSpecialSystemDirectory(Win_Printers
, getter_AddRefs(localFile
));
1068 else if (inAtom
== nsDirectoryService::sPersonal
)
1070 rv
= GetSpecialSystemDirectory(Win_Personal
, getter_AddRefs(localFile
));
1072 else if (inAtom
== nsDirectoryService::sFavorites
)
1074 rv
= GetSpecialSystemDirectory(Win_Favorites
, getter_AddRefs(localFile
));
1076 else if (inAtom
== nsDirectoryService::sStartup
)
1078 rv
= GetSpecialSystemDirectory(Win_Startup
, getter_AddRefs(localFile
));
1080 else if (inAtom
== nsDirectoryService::sRecent
)
1082 rv
= GetSpecialSystemDirectory(Win_Recent
, getter_AddRefs(localFile
));
1084 else if (inAtom
== nsDirectoryService::sSendto
)
1086 rv
= GetSpecialSystemDirectory(Win_Sendto
, getter_AddRefs(localFile
));
1088 else if (inAtom
== nsDirectoryService::sBitbucket
)
1090 rv
= GetSpecialSystemDirectory(Win_Bitbucket
, getter_AddRefs(localFile
));
1092 else if (inAtom
== nsDirectoryService::sStartmenu
)
1094 rv
= GetSpecialSystemDirectory(Win_Startmenu
, getter_AddRefs(localFile
));
1096 else if (inAtom
== nsDirectoryService::sDesktopdirectory
||
1097 inAtom
== nsDirectoryService::sOS_DesktopDirectory
)
1099 rv
= GetSpecialSystemDirectory(Win_Desktopdirectory
, getter_AddRefs(localFile
));
1101 else if (inAtom
== nsDirectoryService::sDrives
)
1103 rv
= GetSpecialSystemDirectory(Win_Drives
, getter_AddRefs(localFile
));
1105 else if (inAtom
== nsDirectoryService::sNetwork
)
1107 rv
= GetSpecialSystemDirectory(Win_Network
, getter_AddRefs(localFile
));
1109 else if (inAtom
== nsDirectoryService::sNethood
)
1111 rv
= GetSpecialSystemDirectory(Win_Nethood
, getter_AddRefs(localFile
));
1113 else if (inAtom
== nsDirectoryService::sFonts
)
1115 rv
= GetSpecialSystemDirectory(Win_Fonts
, getter_AddRefs(localFile
));
1117 else if (inAtom
== nsDirectoryService::sTemplates
)
1119 rv
= GetSpecialSystemDirectory(Win_Templates
, getter_AddRefs(localFile
));
1121 else if (inAtom
== nsDirectoryService::sCommon_Startmenu
)
1123 rv
= GetSpecialSystemDirectory(Win_Common_Startmenu
, getter_AddRefs(localFile
));
1125 else if (inAtom
== nsDirectoryService::sCommon_Programs
)
1127 rv
= GetSpecialSystemDirectory(Win_Common_Programs
, getter_AddRefs(localFile
));
1129 else if (inAtom
== nsDirectoryService::sCommon_Startup
)
1131 rv
= GetSpecialSystemDirectory(Win_Common_Startup
, getter_AddRefs(localFile
));
1133 else if (inAtom
== nsDirectoryService::sCommon_Desktopdirectory
)
1135 rv
= GetSpecialSystemDirectory(Win_Common_Desktopdirectory
, getter_AddRefs(localFile
));
1137 else if (inAtom
== nsDirectoryService::sAppdata
)
1139 rv
= GetSpecialSystemDirectory(Win_Appdata
, getter_AddRefs(localFile
));
1141 else if (inAtom
== nsDirectoryService::sLocalAppdata
)
1143 rv
= GetSpecialSystemDirectory(Win_LocalAppdata
, getter_AddRefs(localFile
));
1145 else if (inAtom
== nsDirectoryService::sPrinthood
)
1147 rv
= GetSpecialSystemDirectory(Win_Printhood
, getter_AddRefs(localFile
));
1149 else if (inAtom
== nsDirectoryService::sWinCookiesDirectory
)
1151 rv
= GetSpecialSystemDirectory(Win_Cookies
, getter_AddRefs(localFile
));
1153 else if (inAtom
== nsDirectoryService::sDefaultDownloadDirectory
)
1155 rv
= GetSpecialSystemDirectory(Win_Downloads
, getter_AddRefs(localFile
));
1157 #elif defined (XP_UNIX)
1159 else if (inAtom
== nsDirectoryService::sLocalDirectory
)
1161 rv
= GetSpecialSystemDirectory(Unix_LocalDirectory
, getter_AddRefs(localFile
));
1163 else if (inAtom
== nsDirectoryService::sLibDirectory
)
1165 rv
= GetSpecialSystemDirectory(Unix_LibDirectory
, getter_AddRefs(localFile
));
1167 else if (inAtom
== nsDirectoryService::sOS_HomeDirectory
)
1169 rv
= GetSpecialSystemDirectory(Unix_HomeDirectory
, getter_AddRefs(localFile
));
1171 else if (inAtom
== nsDirectoryService::sXDGDesktop
||
1172 inAtom
== nsDirectoryService::sOS_DesktopDirectory
)
1174 rv
= GetSpecialSystemDirectory(Unix_XDG_Desktop
, getter_AddRefs(localFile
));
1175 *persistent
= PR_FALSE
;
1177 else if (inAtom
== nsDirectoryService::sXDGDocuments
)
1179 rv
= GetSpecialSystemDirectory(Unix_XDG_Documents
, getter_AddRefs(localFile
));
1180 *persistent
= PR_FALSE
;
1182 else if (inAtom
== nsDirectoryService::sXDGDownload
||
1183 inAtom
== nsDirectoryService::sDefaultDownloadDirectory
)
1185 rv
= GetSpecialSystemDirectory(Unix_XDG_Download
, getter_AddRefs(localFile
));
1186 *persistent
= PR_FALSE
;
1188 else if (inAtom
== nsDirectoryService::sXDGMusic
)
1190 rv
= GetSpecialSystemDirectory(Unix_XDG_Music
, getter_AddRefs(localFile
));
1191 *persistent
= PR_FALSE
;
1193 else if (inAtom
== nsDirectoryService::sXDGPictures
)
1195 rv
= GetSpecialSystemDirectory(Unix_XDG_Pictures
, getter_AddRefs(localFile
));
1196 *persistent
= PR_FALSE
;
1198 else if (inAtom
== nsDirectoryService::sXDGPublicShare
)
1200 rv
= GetSpecialSystemDirectory(Unix_XDG_PublicShare
, getter_AddRefs(localFile
));
1201 *persistent
= PR_FALSE
;
1203 else if (inAtom
== nsDirectoryService::sXDGTemplates
)
1205 rv
= GetSpecialSystemDirectory(Unix_XDG_Templates
, getter_AddRefs(localFile
));
1206 *persistent
= PR_FALSE
;
1208 else if (inAtom
== nsDirectoryService::sXDGVideos
)
1210 rv
= GetSpecialSystemDirectory(Unix_XDG_Videos
, getter_AddRefs(localFile
));
1211 *persistent
= PR_FALSE
;
1213 #elif defined (XP_OS2)
1214 else if (inAtom
== nsDirectoryService::sSystemDirectory
)
1216 rv
= GetSpecialSystemDirectory(OS2_SystemDirectory
, getter_AddRefs(localFile
));
1218 else if (inAtom
== nsDirectoryService::sOS2Directory
)
1220 rv
= GetSpecialSystemDirectory(OS2_OS2Directory
, getter_AddRefs(localFile
));
1222 else if (inAtom
== nsDirectoryService::sOS_HomeDirectory
)
1224 rv
= GetSpecialSystemDirectory(OS2_HomeDirectory
, getter_AddRefs(localFile
));
1226 else if (inAtom
== nsDirectoryService::sOS_DesktopDirectory
)
1228 rv
= GetSpecialSystemDirectory(OS2_DesktopDirectory
, getter_AddRefs(localFile
));
1230 #elif defined (XP_BEOS)
1231 else if (inAtom
== nsDirectoryService::sSettingsDirectory
)
1233 rv
= GetSpecialSystemDirectory(BeOS_SettingsDirectory
, getter_AddRefs(localFile
));
1235 else if (inAtom
== nsDirectoryService::sOS_HomeDirectory
)
1237 rv
= GetSpecialSystemDirectory(BeOS_HomeDirectory
, getter_AddRefs(localFile
));
1239 else if (inAtom
== nsDirectoryService::sOS_DesktopDirectory
)
1241 rv
= GetSpecialSystemDirectory(BeOS_DesktopDirectory
, getter_AddRefs(localFile
));
1243 else if (inAtom
== nsDirectoryService::sSystemDirectory
)
1245 rv
= GetSpecialSystemDirectory(BeOS_SystemDirectory
, getter_AddRefs(localFile
));
1252 if (localFile
&& NS_SUCCEEDED(rv
))
1253 return localFile
->QueryInterface(NS_GET_IID(nsIFile
), (void**)_retval
);
1255 printf("Failed to find directory for key: %s\n", prop
);
1261 nsDirectoryService::GetFiles(const char *prop
, nsISimpleEnumerator
**_retval
)
1263 NS_ENSURE_ARG_POINTER(_retval
);
1266 return NS_ERROR_FAILURE
;