VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/xpcom/io/nsDirectoryService.cpp@ 62376

Last change on this file since 62376 was 62376, checked in by vboxsync, 8 years ago

xpcom: "if" requires condition in parentheses. Luckily, macros
usually provide parentheses around their bodies, but let's not abuse
that.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 44.8 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.org code.
16 *
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.
21 *
22 * Contributor(s):
23 * IBM Corp.
24 *
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
36 *
37 * ***** END LICENSE BLOCK ***** */
38
39#include "nsCOMPtr.h"
40#include "nsDirectoryService.h"
41#include "nsDirectoryServiceDefs.h"
42#include "nsLocalFile.h"
43#include "nsDebug.h"
44#include "nsStaticAtom.h"
45
46#if defined(XP_MAC)
47#include <Folders.h>
48#include <Files.h>
49#include <Memory.h>
50#include <Processes.h>
51#include <Gestalt.h>
52#elif defined(XP_WIN)
53#include <windows.h>
54#include <shlobj.h>
55#include <stdlib.h>
56#include <stdio.h>
57#elif defined(XP_UNIX) || defined(XP_MACOSX)
58#include <unistd.h>
59#include <stdlib.h>
60#include <sys/param.h>
61#include <dlfcn.h>
62#include "prenv.h"
63#ifdef XP_MACOSX
64#include <CoreServices/CoreServices.h>
65#include <Folders.h>
66#include <Files.h>
67# ifndef VBOX_WITH_NEWER_OSX_SDK
68# include <Memory.h>
69# endif
70#include <Processes.h>
71#include <Gestalt.h>
72#include <CFURL.h>
73#include <InternetConfig.h>
74#endif
75#elif defined(XP_OS2)
76#define MAX_PATH _MAX_PATH
77#elif defined(XP_BEOS)
78#include <FindDirectory.h>
79#include <Path.h>
80#include <unistd.h>
81#include <stdlib.h>
82#include <sys/param.h>
83#include <OS.h>
84#include <image.h>
85#include "prenv.h"
86#endif
87
88#include "SpecialSystemDirectory.h"
89#include "nsAppFileLocationProvider.h"
90
91#if defined(XP_MAC)
92#define COMPONENT_REGISTRY_NAME NS_LITERAL_CSTRING("Component Registry")
93#define COMPONENT_DIRECTORY NS_LITERAL_CSTRING("Components")
94#else
95#define COMPONENT_REGISTRY_NAME NS_LITERAL_CSTRING("compreg.dat")
96#define COMPONENT_DIRECTORY NS_LITERAL_CSTRING("components")
97#endif
98
99#define XPTI_REGISTRY_NAME NS_LITERAL_CSTRING("xpti.dat")
100
101// define home directory
102// For Windows platform, We are choosing Appdata folder as HOME
103#if defined (XP_WIN)
104#define HOME_DIR NS_WIN_APPDATA_DIR
105#elif defined (XP_MAC) || defined (XP_MACOSX)
106#define HOME_DIR NS_OSX_HOME_DIR
107#elif defined (XP_UNIX)
108#define HOME_DIR NS_UNIX_HOME_DIR
109#elif defined (XP_OS2)
110#define HOME_DIR NS_OS2_HOME_DIR
111#elif defined (XP_BEOS)
112#define HOME_DIR NS_BEOS_HOME_DIR
113#endif
114
115//----------------------------------------------------------------------------------------
116nsresult
117nsDirectoryService::GetCurrentProcessDirectory(nsILocalFile** aFile)
118//----------------------------------------------------------------------------------------
119{
120 NS_ENSURE_ARG_POINTER(aFile);
121 *aFile = nsnull;
122
123 // Set the component registry location:
124 if (!mService)
125 return NS_ERROR_FAILURE;
126
127 nsresult rv;
128
129 nsCOMPtr<nsIProperties> dirService;
130 rv = nsDirectoryService::Create(nsnull,
131 NS_GET_IID(nsIProperties),
132 getter_AddRefs(dirService)); // needs to be around for life of product
133
134 if (dirService)
135 {
136 nsCOMPtr <nsILocalFile> aLocalFile;
137 dirService->Get(NS_XPCOM_INIT_CURRENT_PROCESS_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(aLocalFile));
138 if (aLocalFile)
139 {
140 *aFile = aLocalFile;
141 NS_ADDREF(*aFile);
142 return NS_OK;
143 }
144 }
145
146 nsLocalFile* localFile = new nsLocalFile;
147
148 if (localFile == nsnull)
149 return NS_ERROR_OUT_OF_MEMORY;
150 NS_ADDREF(localFile);
151
152
153
154#ifdef XP_WIN
155 char buf[MAX_PATH];
156 if ( ::GetModuleFileName(0, buf, sizeof(buf)) ) {
157 // chop of the executable name by finding the rightmost backslash
158 char* lastSlash = PL_strrchr(buf, '\\');
159 if (lastSlash)
160 *(lastSlash + 1) = '\0';
161
162 localFile->InitWithNativePath(nsDependentCString(buf));
163 *aFile = localFile;
164 return NS_OK;
165 }
166
167#elif defined(XP_MAC)
168 // get info for the the current process to determine the directory
169 // its located in
170 OSErr err;
171 ProcessSerialNumber psn = {kNoProcess, kCurrentProcess};
172 ProcessInfoRec pInfo;
173 FSSpec tempSpec;
174
175 // initialize ProcessInfoRec before calling
176 // GetProcessInformation() or die horribly.
177 pInfo.processName = nil;
178 pInfo.processAppSpec = &tempSpec;
179 pInfo.processInfoLength = sizeof(ProcessInfoRec);
180
181 err = GetProcessInformation(&psn, &pInfo);
182 if (!err)
183 {
184 // create an FSSpec from the volume and dirid of the app.
185 FSSpec appFSSpec;
186 ::FSMakeFSSpec(pInfo.processAppSpec->vRefNum, pInfo.processAppSpec->parID, 0, &appFSSpec);
187
188 nsCOMPtr<nsILocalFileMac> localFileMac = do_QueryInterface((nsIFile*)localFile);
189 if (localFileMac)
190 {
191 localFileMac->InitWithFSSpec(&appFSSpec);
192 *aFile = localFile;
193 return NS_OK;
194 }
195 }
196#elif defined(XP_MACOSX)
197# ifdef MOZ_DEFAULT_VBOX_XPCOM_HOME
198 rv = localFile->InitWithNativePath(nsDependentCString(MOZ_DEFAULT_VBOX_XPCOM_HOME));
199 if (NS_SUCCEEDED(rv))
200 *aFile = localFile;
201# else
202 // Works even if we're not bundled.
203 CFBundleRef appBundle = CFBundleGetMainBundle();
204 if (appBundle != nsnull)
205 {
206 CFURLRef bundleURL = CFBundleCopyExecutableURL(appBundle);
207 if (bundleURL != nsnull)
208 {
209 CFURLRef parentURL = CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault, bundleURL);
210 if (parentURL)
211 {
212 // Pass PR_TRUE for the "resolveAgainstBase" arg to CFURLGetFileSystemRepresentation.
213 // This will resolve the relative portion of the CFURL against it base, giving a full
214 // path, which CFURLCopyFileSystemPath doesn't do.
215 char buffer[PATH_MAX];
216 if (CFURLGetFileSystemRepresentation(parentURL, PR_TRUE, (UInt8 *)buffer, sizeof(buffer)))
217 {
218#ifdef DEBUG_conrad
219 printf("nsDirectoryService - CurrentProcessDir is: %s\n", buffer);
220#endif
221 rv = localFile->InitWithNativePath(nsDependentCString(buffer));
222 if (NS_SUCCEEDED(rv))
223 *aFile = localFile;
224 }
225 CFRelease(parentURL);
226 }
227 CFRelease(bundleURL);
228 }
229 }
230#endif
231
232 NS_ASSERTION(*aFile, "nsDirectoryService - Could not determine CurrentProcessDir.\n");
233 if (*aFile)
234 return NS_OK;
235
236#elif defined(XP_UNIX)
237
238 // In the absence of a good way to get the executable directory let
239 // us try this for unix:
240 // - if VBOX_XPCOM_HOME is defined, that is it
241 // - else give the current directory
242 char buf[MAXPATHLEN];
243
244#if 0 /* we need .so location. */
245 // Actually we have a way on linux.
246 static volatile bool fPathSet = false;
247 static char szPath[MAXPATHLEN];
248 if (!fPathSet)
249 {
250 char buf2[MAXPATHLEN + 3];
251 buf2[0] = '\0';
252
253 /*
254 * Env.var. VBOX_XPCOM_HOME first.
255 */
256 char *psz = PR_GetEnv("VBOX_XPCOM_HOME");
257 if (psz)
258 {
259 if (strlen(psz) < MAXPATHLEN)
260 {
261 if (!realpath(psz, buf2))
262 strcpy(buf2, psz);
263 strcat(buf2, "/x"); /* for the filename stripping */
264 }
265 }
266
267 /*
268 * The dynamic loader.
269 */
270 if (!buf2[0])
271 {
272 Dl_info DlInfo = {0};
273 if ( !dladdr((void *)nsDirectoryService::mService, &DlInfo)
274 && DlInfo.dli_fname)
275 {
276 if (!realpath(DlInfo.dli_fname, buf2))
277 buf2[0] = '\0';
278 }
279 }
280
281 /*
282 * Executable location.
283 */
284 if (!buf2[0])
285 {
286 char buf[MAXPATHLEN];
287 int cchLink = readlink("/proc/self/exe", buf, sizeof(buf) - 1);
288 if (cchLink > 0 || cchLink != sizeof(buf) - 1)
289 {
290 buf[cchLink] = '\0';
291 if (!realpath(buf, buf2))
292 buf2[0] = '\0';
293 }
294 }
295
296 /*
297 * Copy to static buffer on success.
298 */
299 if (buf2[0])
300 {
301 char *p = strrchr(buf2, '/');
302 if (p)
303 {
304 p[p == buf2] = '\0';
305 #ifdef DEBUG
306 printf("debug: (1) VBOX_XPCOM_HOME=%s\n", buf2);
307 #endif
308 strcpy(szPath, buf2);
309 fPathSet = true;
310 }
311 }
312 }
313 if (fPathSet)
314 {
315 localFile->InitWithNativePath(nsDependentCString(szPath));
316 *aFile = localFile;
317 return NS_OK;
318 }
319
320#endif
321
322
323 // The MOZ_DEFAULT_VBOX_XPCOM_HOME variable can be set at configure time with
324 // a --with-default-mozilla-five-home=foo autoconf flag.
325 //
326 // The idea here is to allow for builds that have a default VBOX_XPCOM_HOME
327 // regardless of the environment. This makes it easier to write apps that
328 // embed mozilla without having to worry about setting up the environment
329 //
330 // We do this py putenv()ing the default value into the environment. Note that
331 // we only do this if it is not already set.
332#ifdef MOZ_DEFAULT_VBOX_XPCOM_HOME
333 if (PR_GetEnv("VBOX_XPCOM_HOME") == nsnull)
334 {
335 putenv("VBOX_XPCOM_HOME=" MOZ_DEFAULT_VBOX_XPCOM_HOME);
336 }
337#endif
338
339 char *moz5 = PR_GetEnv("VBOX_XPCOM_HOME");
340
341 if (moz5)
342 {
343 if (realpath(moz5, buf)) {
344 localFile->InitWithNativePath(nsDependentCString(buf));
345 *aFile = localFile;
346 return NS_OK;
347 }
348 }
349#if defined(DEBUG)
350 static PRBool firstWarning = PR_TRUE;
351
352 if(!moz5 && firstWarning) {
353 // Warn that VBOX_XPCOM_HOME not set, once.
354 printf("Warning: VBOX_XPCOM_HOME not set.\n");
355 firstWarning = PR_FALSE;
356 }
357#endif /* DEBUG */
358
359 // Fall back to current directory.
360 if (getcwd(buf, sizeof(buf)))
361 {
362 localFile->InitWithNativePath(nsDependentCString(buf));
363 *aFile = localFile;
364 return NS_OK;
365 }
366
367#elif defined(XP_OS2)
368 PPIB ppib;
369 PTIB ptib;
370 char buffer[CCHMAXPATH];
371 DosGetInfoBlocks( &ptib, &ppib);
372 DosQueryModuleName( ppib->pib_hmte, CCHMAXPATH, buffer);
373 *strrchr( buffer, '\\') = '\0'; // XXX DBCS misery
374 localFile->InitWithNativePath(nsDependentCString(buffer));
375 *aFile = localFile;
376 return NS_OK;
377
378#elif defined(XP_BEOS)
379
380 char *moz5 = getenv("VBOX_XPCOM_HOME");
381 if (moz5)
382 {
383 localFile->InitWithNativePath(nsDependentCString(moz5));
384 localFile->Normalize();
385 *aFile = localFile;
386 return NS_OK;
387 }
388 else
389 {
390 static char buf[MAXPATHLEN];
391 int32 cookie = 0;
392 image_info info;
393 char *p;
394 *buf = 0;
395 if(get_next_image_info(0, &cookie, &info) == B_OK)
396 {
397 strcpy(buf, info.name);
398 if((p = strrchr(buf, '/')) != 0)
399 {
400 *p = 0;
401 localFile->InitWithNativePath(nsDependentCString(buf));
402 *aFile = localFile;
403 return NS_OK;
404 }
405 }
406 }
407
408#endif
409
410 NS_RELEASE(localFile);
411
412 NS_ERROR("unable to get current process directory");
413 return NS_ERROR_FAILURE;
414} // GetCurrentProcessDirectory()
415
416
417nsIAtom* nsDirectoryService::sCurrentProcess = nsnull;
418nsIAtom* nsDirectoryService::sComponentRegistry = nsnull;
419nsIAtom* nsDirectoryService::sXPTIRegistry = nsnull;
420nsIAtom* nsDirectoryService::sComponentDirectory = nsnull;
421nsIAtom* nsDirectoryService::sGRE_Directory = nsnull;
422nsIAtom* nsDirectoryService::sGRE_ComponentDirectory = nsnull;
423nsIAtom* nsDirectoryService::sOS_DriveDirectory = nsnull;
424nsIAtom* nsDirectoryService::sOS_TemporaryDirectory = nsnull;
425nsIAtom* nsDirectoryService::sOS_CurrentProcessDirectory = nsnull;
426nsIAtom* nsDirectoryService::sOS_CurrentWorkingDirectory = nsnull;
427#if defined (XP_MACOSX)
428nsIAtom* nsDirectoryService::sDirectory = nsnull;
429nsIAtom* nsDirectoryService::sDesktopDirectory = nsnull;
430nsIAtom* nsDirectoryService::sTrashDirectory = nsnull;
431nsIAtom* nsDirectoryService::sStartupDirectory = nsnull;
432nsIAtom* nsDirectoryService::sShutdownDirectory = nsnull;
433nsIAtom* nsDirectoryService::sAppleMenuDirectory = nsnull;
434nsIAtom* nsDirectoryService::sControlPanelDirectory = nsnull;
435nsIAtom* nsDirectoryService::sExtensionDirectory = nsnull;
436nsIAtom* nsDirectoryService::sFontsDirectory = nsnull;
437nsIAtom* nsDirectoryService::sPreferencesDirectory = nsnull;
438nsIAtom* nsDirectoryService::sDocumentsDirectory = nsnull;
439nsIAtom* nsDirectoryService::sInternetSearchDirectory = nsnull;
440nsIAtom* nsDirectoryService::sUserLibDirectory = nsnull;
441nsIAtom* nsDirectoryService::sHomeDirectory = nsnull;
442nsIAtom* nsDirectoryService::sDefaultDownloadDirectory = nsnull;
443nsIAtom* nsDirectoryService::sUserDesktopDirectory = nsnull;
444nsIAtom* nsDirectoryService::sLocalDesktopDirectory = nsnull;
445nsIAtom* nsDirectoryService::sUserApplicationsDirectory = nsnull;
446nsIAtom* nsDirectoryService::sLocalApplicationsDirectory = nsnull;
447nsIAtom* nsDirectoryService::sUserDocumentsDirectory = nsnull;
448nsIAtom* nsDirectoryService::sLocalDocumentsDirectory = nsnull;
449nsIAtom* nsDirectoryService::sUserInternetPlugInDirectory = nsnull;
450nsIAtom* nsDirectoryService::sLocalInternetPlugInDirectory = nsnull;
451nsIAtom* nsDirectoryService::sUserFrameworksDirectory = nsnull;
452nsIAtom* nsDirectoryService::sLocalFrameworksDirectory = nsnull;
453nsIAtom* nsDirectoryService::sUserPreferencesDirectory = nsnull;
454nsIAtom* nsDirectoryService::sLocalPreferencesDirectory = nsnull;
455nsIAtom* nsDirectoryService::sPictureDocumentsDirectory = nsnull;
456nsIAtom* nsDirectoryService::sMovieDocumentsDirectory = nsnull;
457nsIAtom* nsDirectoryService::sMusicDocumentsDirectory = nsnull;
458nsIAtom* nsDirectoryService::sInternetSitesDirectory = nsnull;
459#elif defined (XP_WIN)
460nsIAtom* nsDirectoryService::sSystemDirectory = nsnull;
461nsIAtom* nsDirectoryService::sWindowsDirectory = nsnull;
462nsIAtom* nsDirectoryService::sHomeDirectory = nsnull;
463nsIAtom* nsDirectoryService::sDesktop = nsnull;
464nsIAtom* nsDirectoryService::sPrograms = nsnull;
465nsIAtom* nsDirectoryService::sControls = nsnull;
466nsIAtom* nsDirectoryService::sPrinters = nsnull;
467nsIAtom* nsDirectoryService::sPersonal = nsnull;
468nsIAtom* nsDirectoryService::sFavorites = nsnull;
469nsIAtom* nsDirectoryService::sStartup = nsnull;
470nsIAtom* nsDirectoryService::sRecent = nsnull;
471nsIAtom* nsDirectoryService::sSendto = nsnull;
472nsIAtom* nsDirectoryService::sBitbucket = nsnull;
473nsIAtom* nsDirectoryService::sStartmenu = nsnull;
474nsIAtom* nsDirectoryService::sDesktopdirectory = nsnull;
475nsIAtom* nsDirectoryService::sDrives = nsnull;
476nsIAtom* nsDirectoryService::sNetwork = nsnull;
477nsIAtom* nsDirectoryService::sNethood = nsnull;
478nsIAtom* nsDirectoryService::sFonts = nsnull;
479nsIAtom* nsDirectoryService::sTemplates = nsnull;
480nsIAtom* nsDirectoryService::sCommon_Startmenu = nsnull;
481nsIAtom* nsDirectoryService::sCommon_Programs = nsnull;
482nsIAtom* nsDirectoryService::sCommon_Startup = nsnull;
483nsIAtom* nsDirectoryService::sCommon_Desktopdirectory = nsnull;
484nsIAtom* nsDirectoryService::sAppdata = nsnull;
485nsIAtom* nsDirectoryService::sPrinthood = nsnull;
486nsIAtom* nsDirectoryService::sWinCookiesDirectory = nsnull;
487#elif defined (XP_UNIX)
488nsIAtom* nsDirectoryService::sLocalDirectory = nsnull;
489nsIAtom* nsDirectoryService::sLibDirectory = nsnull;
490nsIAtom* nsDirectoryService::sHomeDirectory = nsnull;
491#elif defined (XP_OS2)
492nsIAtom* nsDirectoryService::sSystemDirectory = nsnull;
493nsIAtom* nsDirectoryService::sOS2Directory = nsnull;
494nsIAtom* nsDirectoryService::sHomeDirectory = nsnull;
495nsIAtom* nsDirectoryService::sDesktopDirectory = nsnull;
496#elif defined (XP_BEOS)
497nsIAtom* nsDirectoryService::sSettingsDirectory = nsnull;
498nsIAtom* nsDirectoryService::sHomeDirectory = nsnull;
499nsIAtom* nsDirectoryService::sDesktopDirectory = nsnull;
500nsIAtom* nsDirectoryService::sSystemDirectory = nsnull;
501#endif
502
503
504nsDirectoryService* nsDirectoryService::mService = nsnull;
505
506nsDirectoryService::nsDirectoryService() :
507 mHashtable(256, PR_TRUE)
508{
509}
510
511NS_METHOD
512nsDirectoryService::Create(nsISupports *outer, REFNSIID aIID, void **aResult)
513{
514 NS_ENSURE_ARG_POINTER(aResult);
515 if (!mService)
516 {
517 mService = new nsDirectoryService();
518 if (!mService)
519 return NS_ERROR_OUT_OF_MEMORY;
520 }
521 return mService->QueryInterface(aIID, aResult);
522}
523
524static const nsStaticAtom directory_atoms[] = {
525 { NS_XPCOM_CURRENT_PROCESS_DIR, &nsDirectoryService::sCurrentProcess },
526 { NS_XPCOM_COMPONENT_REGISTRY_FILE, &nsDirectoryService::sComponentRegistry },
527 { NS_XPCOM_COMPONENT_DIR, &nsDirectoryService::sComponentDirectory },
528 { NS_XPCOM_XPTI_REGISTRY_FILE, &nsDirectoryService::sXPTIRegistry },
529 { NS_GRE_DIR, &nsDirectoryService::sGRE_Directory },
530 { NS_GRE_COMPONENT_DIR, &nsDirectoryService::sGRE_ComponentDirectory },
531 { NS_OS_DRIVE_DIR, &nsDirectoryService::sOS_DriveDirectory },
532 { NS_OS_TEMP_DIR, &nsDirectoryService::sOS_TemporaryDirectory },
533 { NS_OS_CURRENT_PROCESS_DIR, &nsDirectoryService::sOS_CurrentProcessDirectory },
534 { NS_OS_CURRENT_WORKING_DIR, &nsDirectoryService::sOS_CurrentWorkingDirectory },
535 { NS_XPCOM_INIT_CURRENT_PROCESS_DIR, nsnull },
536#if defined (XP_MACOSX)
537 { NS_OS_SYSTEM_DIR, &nsDirectoryService::sDirectory },
538 { NS_MAC_DESKTOP_DIR, &nsDirectoryService::sDesktopDirectory },
539 { NS_MAC_TRASH_DIR, &nsDirectoryService::sTrashDirectory },
540 { NS_MAC_STARTUP_DIR, &nsDirectoryService::sStartupDirectory },
541 { NS_MAC_SHUTDOWN_DIR, &nsDirectoryService::sShutdownDirectory },
542 { NS_MAC_APPLE_MENU_DIR, &nsDirectoryService::sAppleMenuDirectory },
543 { NS_MAC_CONTROL_PANELS_DIR, &nsDirectoryService::sControlPanelDirectory },
544 { NS_MAC_EXTENSIONS_DIR, &nsDirectoryService::sExtensionDirectory },
545 { NS_MAC_FONTS_DIR, &nsDirectoryService::sFontsDirectory },
546 { NS_MAC_PREFS_DIR, &nsDirectoryService::sPreferencesDirectory },
547 { NS_MAC_DOCUMENTS_DIR, &nsDirectoryService::sDocumentsDirectory },
548 { NS_MAC_INTERNET_SEARCH_DIR, &nsDirectoryService::sInternetSearchDirectory },
549 { NS_MAC_USER_LIB_DIR, &nsDirectoryService::sUserLibDirectory },
550 { NS_OSX_HOME_DIR, &nsDirectoryService::sHomeDirectory },
551 { NS_OSX_DEFAULT_DOWNLOAD_DIR, &nsDirectoryService::sDefaultDownloadDirectory },
552 { NS_OSX_USER_DESKTOP_DIR, &nsDirectoryService::sUserDesktopDirectory },
553 { NS_OSX_LOCAL_DESKTOP_DIR, &nsDirectoryService::sLocalDesktopDirectory },
554 { NS_OSX_USER_APPLICATIONS_DIR, &nsDirectoryService::sUserApplicationsDirectory },
555 { NS_OSX_LOCAL_APPLICATIONS_DIR, &nsDirectoryService::sLocalApplicationsDirectory },
556 { NS_OSX_USER_DOCUMENTS_DIR, &nsDirectoryService::sUserDocumentsDirectory },
557 { NS_OSX_LOCAL_DOCUMENTS_DIR, &nsDirectoryService::sLocalDocumentsDirectory },
558 { NS_OSX_USER_INTERNET_PLUGIN_DIR, &nsDirectoryService::sUserInternetPlugInDirectory },
559 { NS_OSX_LOCAL_INTERNET_PLUGIN_DIR, &nsDirectoryService::sLocalInternetPlugInDirectory },
560 { NS_OSX_USER_FRAMEWORKS_DIR, &nsDirectoryService::sUserFrameworksDirectory },
561 { NS_OSX_LOCAL_FRAMEWORKS_DIR, &nsDirectoryService::sLocalFrameworksDirectory },
562 { NS_OSX_USER_PREFERENCES_DIR, &nsDirectoryService::sUserPreferencesDirectory },
563 { NS_OSX_LOCAL_PREFERENCES_DIR, &nsDirectoryService::sLocalPreferencesDirectory },
564 { NS_OSX_PICTURE_DOCUMENTS_DIR, &nsDirectoryService::sPictureDocumentsDirectory },
565 { NS_OSX_MOVIE_DOCUMENTS_DIR, &nsDirectoryService::sMovieDocumentsDirectory },
566 { NS_OSX_MUSIC_DOCUMENTS_DIR, &nsDirectoryService::sMusicDocumentsDirectory },
567 { NS_OSX_INTERNET_SITES_DIR, &nsDirectoryService::sInternetSitesDirectory },
568#elif defined (XP_WIN)
569 { NS_OS_SYSTEM_DIR, &nsDirectoryService::sSystemDirectory },
570 { NS_WIN_WINDOWS_DIR, &nsDirectoryService::sWindowsDirectory },
571 { NS_WIN_HOME_DIR, &nsDirectoryService::sHomeDirectory },
572 { NS_WIN_DESKTOP_DIR, &nsDirectoryService::sDesktop },
573 { NS_WIN_PROGRAMS_DIR, &nsDirectoryService::sPrograms },
574 { NS_WIN_CONTROLS_DIR, &nsDirectoryService::sControls },
575 { NS_WIN_PRINTERS_DIR, &nsDirectoryService::sPrinters },
576 { NS_WIN_PERSONAL_DIR, &nsDirectoryService::sPersonal },
577 { NS_WIN_FAVORITES_DIR, &nsDirectoryService::sFavorites },
578 { NS_WIN_STARTUP_DIR, &nsDirectoryService::sStartup },
579 { NS_WIN_RECENT_DIR, &nsDirectoryService::sRecent },
580 { NS_WIN_SEND_TO_DIR, &nsDirectoryService::sSendto },
581 { NS_WIN_BITBUCKET_DIR, &nsDirectoryService::sBitbucket },
582 { NS_WIN_STARTMENU_DIR, &nsDirectoryService::sStartmenu },
583 { NS_WIN_DESKTOP_DIRECTORY, &nsDirectoryService::sDesktopdirectory },
584 { NS_WIN_DRIVES_DIR, &nsDirectoryService::sDrives },
585 { NS_WIN_NETWORK_DIR, &nsDirectoryService::sNetwork },
586 { NS_WIN_NETHOOD_DIR, &nsDirectoryService::sNethood },
587 { NS_WIN_FONTS_DIR, &nsDirectoryService::sFonts },
588 { NS_WIN_TEMPLATES_DIR, &nsDirectoryService::sTemplates },
589 { NS_WIN_COMMON_STARTMENU_DIR, &nsDirectoryService::sCommon_Startmenu },
590 { NS_WIN_COMMON_PROGRAMS_DIR, &nsDirectoryService::sCommon_Programs },
591 { NS_WIN_COMMON_STARTUP_DIR, &nsDirectoryService::sCommon_Startup },
592 { NS_WIN_COMMON_DESKTOP_DIRECTORY, &nsDirectoryService::sCommon_Desktopdirectory },
593 { NS_WIN_APPDATA_DIR, &nsDirectoryService::sAppdata },
594 { NS_WIN_PRINTHOOD, &nsDirectoryService::sPrinthood },
595 { NS_WIN_COOKIES_DIR, &nsDirectoryService::sWinCookiesDirectory },
596#elif defined (XP_UNIX)
597 { NS_UNIX_LOCAL_DIR, &nsDirectoryService::sLocalDirectory },
598 { NS_UNIX_LIB_DIR, &nsDirectoryService::sLibDirectory },
599 { NS_UNIX_HOME_DIR, &nsDirectoryService::sHomeDirectory },
600#elif defined (XP_OS2)
601 { NS_OS_SYSTEM_DIR, &nsDirectoryService::sSystemDirectory },
602 { NS_OS2_DIR, &nsDirectoryService::sOS2Directory },
603 { NS_OS2_HOME_DIR, &nsDirectoryService::sHomeDirectory },
604 { NS_OS2_DESKTOP_DIR, &nsDirectoryService::sDesktopDirectory },
605#elif defined (XP_BEOS)
606 { NS_OS_SYSTEM_DIR, &nsDirectoryService::sSystemDirectory },
607 { NS_BEOS_SETTINGS_DIR, &nsDirectoryService::sSettingsDirectory },
608 { NS_BEOS_HOME_DIR, &nsDirectoryService::sHomeDirectory },
609 { NS_BEOS_DESKTOP_DIR, &nsDirectoryService::sDesktopDirectory },
610#endif
611};
612
613nsresult
614nsDirectoryService::Init()
615{
616 nsresult rv;
617
618 rv = NS_NewISupportsArray(getter_AddRefs(mProviders));
619 if (NS_FAILED(rv)) return rv;
620
621 NS_RegisterStaticAtoms(directory_atoms, NS_ARRAY_LENGTH(directory_atoms));
622
623 // Let the list hold the only reference to the provider.
624 nsAppFileLocationProvider *defaultProvider = new nsAppFileLocationProvider;
625 if (!defaultProvider)
626 return NS_ERROR_OUT_OF_MEMORY;
627 // AppendElement returns PR_TRUE for success.
628 rv = mProviders->AppendElement(defaultProvider) ? NS_OK : NS_ERROR_FAILURE;
629
630 return rv;
631}
632
633PRBool
634nsDirectoryService::ReleaseValues(nsHashKey* key, void* data, void* closure)
635{
636 nsISupports* value = (nsISupports*)data;
637 NS_IF_RELEASE(value);
638 return PR_TRUE;
639}
640
641nsDirectoryService::~nsDirectoryService()
642{
643 // clear the global
644 mService = nsnull;
645
646}
647
648NS_IMPL_THREADSAFE_ISUPPORTS4(nsDirectoryService, nsIProperties, nsIDirectoryService, nsIDirectoryServiceProvider, nsIDirectoryServiceProvider2)
649
650
651NS_IMETHODIMP
652nsDirectoryService::Undefine(const char* prop)
653{
654 nsCStringKey key(prop);
655 if (!mHashtable.Exists(&key))
656 return NS_ERROR_FAILURE;
657
658 mHashtable.Remove (&key);
659 return NS_OK;
660 }
661
662NS_IMETHODIMP
663nsDirectoryService::GetKeys(PRUint32 *count, char ***keys)
664{
665 return NS_ERROR_NOT_IMPLEMENTED;
666}
667
668struct FileData
669{
670 FileData(const char* aProperty,
671 const nsIID& aUUID) :
672 property(aProperty),
673 data(nsnull),
674 persistent(PR_TRUE),
675 uuid(aUUID) {}
676
677 const char* property;
678 nsISupports* data;
679 PRBool persistent;
680 const nsIID& uuid;
681};
682
683static PRBool FindProviderFile(nsISupports* aElement, void *aData)
684{
685 nsresult rv;
686 FileData* fileData = (FileData*)aData;
687 if (fileData->uuid.Equals(NS_GET_IID(nsISimpleEnumerator)))
688 {
689 // Not all providers implement this iface
690 nsCOMPtr<nsIDirectoryServiceProvider2> prov2 = do_QueryInterface(aElement);
691 if (prov2)
692 {
693 rv = prov2->GetFiles(fileData->property, (nsISimpleEnumerator **)&fileData->data);
694 if (NS_SUCCEEDED(rv) && fileData->data) {
695 fileData->persistent = PR_FALSE; // Enumerators can never be peristent
696 return PR_FALSE;
697 }
698 }
699 }
700 else
701 {
702 nsCOMPtr<nsIDirectoryServiceProvider> prov = do_QueryInterface(aElement);
703 if (!prov)
704 return PR_FALSE;
705 rv = prov->GetFile(fileData->property, &fileData->persistent, (nsIFile **)&fileData->data);
706 if (NS_SUCCEEDED(rv) && fileData->data)
707 return PR_FALSE;
708 }
709
710 return PR_TRUE;
711}
712
713NS_IMETHODIMP
714nsDirectoryService::Get(const char* prop, const nsIID & uuid, void* *result)
715{
716 nsCStringKey key(prop);
717
718 nsCOMPtr<nsISupports> value = dont_AddRef(mHashtable.Get(&key));
719
720 if (value)
721 {
722 nsCOMPtr<nsIFile> cloneFile;
723 nsCOMPtr<nsIFile> cachedFile = do_QueryInterface(value);
724 NS_ASSERTION(cachedFile, "nsIFile expected");
725
726 cachedFile->Clone(getter_AddRefs(cloneFile));
727 return cloneFile->QueryInterface(uuid, result);
728 }
729
730 // it is not one of our defaults, lets check any providers
731 FileData fileData(prop, uuid);
732
733 mProviders->EnumerateBackwards(FindProviderFile, &fileData);
734 if (fileData.data)
735 {
736 if (fileData.persistent)
737 {
738 Set(prop, NS_STATIC_CAST(nsIFile*, fileData.data));
739 }
740 nsresult rv = (fileData.data)->QueryInterface(uuid, result);
741 NS_RELEASE(fileData.data); // addref occurs in FindProviderFile()
742 return rv;
743 }
744
745 FindProviderFile(NS_STATIC_CAST(nsIDirectoryServiceProvider*, this), &fileData);
746 if (fileData.data)
747 {
748 if (fileData.persistent)
749 {
750 Set(prop, NS_STATIC_CAST(nsIFile*, fileData.data));
751 }
752 nsresult rv = (fileData.data)->QueryInterface(uuid, result);
753 NS_RELEASE(fileData.data); // addref occurs in FindProviderFile()
754 return rv;
755 }
756
757 return NS_ERROR_FAILURE;
758}
759
760NS_IMETHODIMP
761nsDirectoryService::Set(const char* prop, nsISupports* value)
762{
763 nsCStringKey key(prop);
764 if (mHashtable.Exists(&key) || value == nsnull)
765 return NS_ERROR_FAILURE;
766
767 nsCOMPtr<nsIFile> ourFile;
768 value->QueryInterface(NS_GET_IID(nsIFile), getter_AddRefs(ourFile));
769 if (ourFile)
770 {
771 nsCOMPtr<nsIFile> cloneFile;
772 ourFile->Clone (getter_AddRefs (cloneFile));
773 mHashtable.Put(&key, cloneFile);
774
775 return NS_OK;
776 }
777
778 return NS_ERROR_FAILURE;
779}
780
781NS_IMETHODIMP
782nsDirectoryService::Has(const char *prop, PRBool *_retval)
783{
784 *_retval = PR_FALSE;
785 nsCOMPtr<nsIFile> value;
786 nsresult rv = Get(prop, NS_GET_IID(nsIFile), getter_AddRefs(value));
787 if (NS_FAILED(rv))
788 return rv;
789
790 if (value)
791 {
792 *_retval = PR_TRUE;
793 }
794
795 return rv;
796}
797
798NS_IMETHODIMP
799nsDirectoryService::RegisterProvider(nsIDirectoryServiceProvider *prov)
800{
801 nsresult rv;
802 if (!prov)
803 return NS_ERROR_FAILURE;
804 if (!mProviders)
805 return NS_ERROR_NOT_INITIALIZED;
806
807 nsCOMPtr<nsISupports> supports = do_QueryInterface(prov, &rv);
808 if (NS_FAILED(rv)) return rv;
809
810 // AppendElement returns PR_TRUE for success.
811 return mProviders->AppendElement(supports) ? NS_OK : NS_ERROR_FAILURE;
812}
813
814NS_IMETHODIMP
815nsDirectoryService::UnregisterProvider(nsIDirectoryServiceProvider *prov)
816{
817 nsresult rv;
818 if (!prov)
819 return NS_ERROR_FAILURE;
820 if (!mProviders)
821 return NS_ERROR_NOT_INITIALIZED;
822
823 nsCOMPtr<nsISupports> supports = do_QueryInterface(prov, &rv);
824 if (NS_FAILED(rv)) return rv;
825
826 // RemoveElement returns PR_TRUE for success.
827 return mProviders->RemoveElement(supports) ? NS_OK : NS_ERROR_FAILURE;
828}
829
830// DO NOT ADD ANY LOCATIONS TO THIS FUNCTION UNTIL YOU TALK TO: dougt@netscape.com.
831// This is meant to be a place of xpcom or system specific file locations, not
832// application specific locations. If you need the later, register a callback for
833// your application.
834
835NS_IMETHODIMP
836nsDirectoryService::GetFile(const char *prop, PRBool *persistent, nsIFile **_retval)
837{
838 nsCOMPtr<nsILocalFile> localFile;
839 nsresult rv = NS_ERROR_FAILURE;
840
841 *_retval = nsnull;
842 *persistent = PR_TRUE;
843
844 nsIAtom* inAtom = NS_NewAtom(prop);
845
846 // check to see if it is one of our defaults
847
848 if (inAtom == nsDirectoryService::sCurrentProcess ||
849 inAtom == nsDirectoryService::sOS_CurrentProcessDirectory )
850 {
851 rv = GetCurrentProcessDirectory(getter_AddRefs(localFile));
852 }
853 else if (inAtom == nsDirectoryService::sComponentRegistry)
854 {
855 rv = GetCurrentProcessDirectory(getter_AddRefs(localFile));
856 if (!localFile)
857 return NS_ERROR_FAILURE;
858
859 localFile->AppendNative(COMPONENT_DIRECTORY);
860 localFile->AppendNative(COMPONENT_REGISTRY_NAME);
861 }
862 else if (inAtom == nsDirectoryService::sXPTIRegistry)
863 {
864 rv = GetCurrentProcessDirectory(getter_AddRefs(localFile));
865 if (!localFile)
866 return NS_ERROR_FAILURE;
867
868 localFile->AppendNative(COMPONENT_DIRECTORY);
869 localFile->AppendNative(XPTI_REGISTRY_NAME);
870 }
871
872 // Unless otherwise set, the core pieces of the GRE exist
873 // in the current process directory.
874 else if (inAtom == nsDirectoryService::sGRE_Directory)
875 {
876 rv = GetCurrentProcessDirectory(getter_AddRefs(localFile));
877 }
878 // the GRE components directory is relative to the GRE directory
879 // by default; applications may override this behavior in special
880 // cases
881 else if (inAtom == nsDirectoryService::sGRE_ComponentDirectory)
882 {
883 rv = Get(NS_GRE_DIR, nsILocalFile::GetIID(), getter_AddRefs(localFile));
884 if (localFile)
885 localFile->AppendNative(COMPONENT_DIRECTORY);
886 }
887 else if (inAtom == nsDirectoryService::sComponentDirectory)
888 {
889 rv = GetCurrentProcessDirectory(getter_AddRefs(localFile));
890 if (localFile)
891 localFile->AppendNative(COMPONENT_DIRECTORY);
892 }
893 else if (inAtom == nsDirectoryService::sOS_DriveDirectory)
894 {
895 rv = GetSpecialSystemDirectory(OS_DriveDirectory, getter_AddRefs(localFile));
896 }
897 else if (inAtom == nsDirectoryService::sOS_TemporaryDirectory)
898 {
899 rv = GetSpecialSystemDirectory(OS_TemporaryDirectory, getter_AddRefs(localFile));
900 }
901 else if (inAtom == nsDirectoryService::sOS_CurrentProcessDirectory)
902 {
903 rv = GetSpecialSystemDirectory(OS_CurrentProcessDirectory, getter_AddRefs(localFile));
904 }
905 else if (inAtom == nsDirectoryService::sOS_CurrentWorkingDirectory)
906 {
907 rv = GetSpecialSystemDirectory(OS_CurrentWorkingDirectory, getter_AddRefs(localFile));
908 }
909
910#if defined(XP_MACOSX)
911 else if (inAtom == nsDirectoryService::sDirectory)
912 {
913 rv = GetOSXFolderType(kClassicDomain, kSystemFolderType, getter_AddRefs(localFile));
914 }
915 else if (inAtom == nsDirectoryService::sDesktopDirectory)
916 {
917 rv = GetOSXFolderType(kClassicDomain, kDesktopFolderType, getter_AddRefs(localFile));
918 }
919 else if (inAtom == nsDirectoryService::sTrashDirectory)
920 {
921 rv = GetOSXFolderType(kClassicDomain, kTrashFolderType, getter_AddRefs(localFile));
922 }
923 else if (inAtom == nsDirectoryService::sStartupDirectory)
924 {
925 rv = GetOSXFolderType(kClassicDomain, kStartupFolderType, getter_AddRefs(localFile));
926 }
927 else if (inAtom == nsDirectoryService::sShutdownDirectory)
928 {
929 rv = GetOSXFolderType(kClassicDomain, kShutdownFolderType, getter_AddRefs(localFile));
930 }
931 else if (inAtom == nsDirectoryService::sAppleMenuDirectory)
932 {
933 rv = GetOSXFolderType(kClassicDomain, kAppleMenuFolderType, getter_AddRefs(localFile));
934 }
935 else if (inAtom == nsDirectoryService::sControlPanelDirectory)
936 {
937 rv = GetOSXFolderType(kClassicDomain, kControlPanelFolderType, getter_AddRefs(localFile));
938 }
939 else if (inAtom == nsDirectoryService::sExtensionDirectory)
940 {
941 rv = GetOSXFolderType(kClassicDomain, kExtensionFolderType, getter_AddRefs(localFile));
942 }
943 else if (inAtom == nsDirectoryService::sFontsDirectory)
944 {
945 rv = GetOSXFolderType(kClassicDomain, kFontsFolderType, getter_AddRefs(localFile));
946 }
947 else if (inAtom == nsDirectoryService::sPreferencesDirectory)
948 {
949 rv = GetOSXFolderType(kClassicDomain, kPreferencesFolderType, getter_AddRefs(localFile));
950 }
951 else if (inAtom == nsDirectoryService::sDocumentsDirectory)
952 {
953 rv = GetOSXFolderType(kClassicDomain, kDocumentsFolderType, getter_AddRefs(localFile));
954 }
955 else if (inAtom == nsDirectoryService::sInternetSearchDirectory)
956 {
957 rv = GetOSXFolderType(kClassicDomain, kInternetSearchSitesFolderType, getter_AddRefs(localFile));
958 }
959 else if (inAtom == nsDirectoryService::sUserLibDirectory)
960 {
961 rv = GetOSXFolderType(kUserDomain, kDomainLibraryFolderType, getter_AddRefs(localFile));
962 }
963 else if (inAtom == nsDirectoryService::sHomeDirectory)
964 {
965 rv = GetOSXFolderType(kUserDomain, kDomainTopLevelFolderType, getter_AddRefs(localFile));
966 }
967 else if (inAtom == nsDirectoryService::sDefaultDownloadDirectory)
968 {
969 NS_NewLocalFile(EmptyString(), PR_TRUE, getter_AddRefs(localFile));
970 nsCOMPtr<nsILocalFileMac> localMacFile(do_QueryInterface(localFile));
971
972 if (localMacFile)
973 {
974 OSErr err;
975 ICInstance icInstance;
976
977 err = ::ICStart(&icInstance, 'XPCM');
978 if (err == noErr)
979 {
980 ICAttr attrs;
981 ICFileSpec icFileSpec;
982 long size = kICFileSpecHeaderSize;
983 err = ::ICGetPref(icInstance, kICDownloadFolder, &attrs, &icFileSpec, &size);
984 if (err == noErr || (err == icTruncatedErr && size >= kICFileSpecHeaderSize))
985 {
986 rv = localMacFile->InitWithFSSpec(&icFileSpec.fss);
987 }
988 ::ICStop(icInstance);
989 }
990
991 if (NS_FAILED(rv))
992 {
993 // We got an error getting the DL folder from IC so try finding the user's Desktop folder
994 rv = GetOSXFolderType(kUserDomain, kDesktopFolderType, getter_AddRefs(localFile));
995 }
996 }
997
998 // Don't cache the DL directory as the user may change it while we're running.
999 // Negligible perf hit as this directory is only requested for downloads
1000 *persistent = PR_FALSE;
1001 }
1002 else if (inAtom == nsDirectoryService::sUserDesktopDirectory)
1003 {
1004 rv = GetOSXFolderType(kUserDomain, kDesktopFolderType, getter_AddRefs(localFile));
1005 }
1006 else if (inAtom == nsDirectoryService::sLocalDesktopDirectory)
1007 {
1008 rv = GetOSXFolderType(kLocalDomain, kDesktopFolderType, getter_AddRefs(localFile));
1009 }
1010 else if (inAtom == nsDirectoryService::sUserApplicationsDirectory)
1011 {
1012 rv = GetOSXFolderType(kUserDomain, kApplicationsFolderType, getter_AddRefs(localFile));
1013 }
1014 else if (inAtom == nsDirectoryService::sLocalApplicationsDirectory)
1015 {
1016 rv = GetOSXFolderType(kLocalDomain, kApplicationsFolderType, getter_AddRefs(localFile));
1017 }
1018 else if (inAtom == nsDirectoryService::sUserDocumentsDirectory)
1019 {
1020 rv = GetOSXFolderType(kUserDomain, kDocumentsFolderType, getter_AddRefs(localFile));
1021 }
1022 else if (inAtom == nsDirectoryService::sLocalDocumentsDirectory)
1023 {
1024 rv = GetOSXFolderType(kLocalDomain, kDocumentsFolderType, getter_AddRefs(localFile));
1025 }
1026 else if (inAtom == nsDirectoryService::sUserInternetPlugInDirectory)
1027 {
1028 rv = GetOSXFolderType(kUserDomain, kInternetPlugInFolderType, getter_AddRefs(localFile));
1029 }
1030 else if (inAtom == nsDirectoryService::sLocalInternetPlugInDirectory)
1031 {
1032 rv = GetOSXFolderType(kLocalDomain, kInternetPlugInFolderType, getter_AddRefs(localFile));
1033 }
1034 else if (inAtom == nsDirectoryService::sUserFrameworksDirectory)
1035 {
1036 rv = GetOSXFolderType(kUserDomain, kFrameworksFolderType, getter_AddRefs(localFile));
1037 }
1038 else if (inAtom == nsDirectoryService::sLocalFrameworksDirectory)
1039 {
1040 rv = GetOSXFolderType(kLocalDomain, kFrameworksFolderType, getter_AddRefs(localFile));
1041 }
1042 else if (inAtom == nsDirectoryService::sUserPreferencesDirectory)
1043 {
1044 rv = GetOSXFolderType(kUserDomain, kPreferencesFolderType, getter_AddRefs(localFile));
1045 }
1046 else if (inAtom == nsDirectoryService::sLocalPreferencesDirectory)
1047 {
1048 rv = GetOSXFolderType(kLocalDomain, kPreferencesFolderType, getter_AddRefs(localFile));
1049 }
1050 else if (inAtom == nsDirectoryService::sPictureDocumentsDirectory)
1051 {
1052 rv = GetOSXFolderType(kUserDomain, kPictureDocumentsFolderType, getter_AddRefs(localFile));
1053 }
1054 else if (inAtom == nsDirectoryService::sMovieDocumentsDirectory)
1055 {
1056 rv = GetOSXFolderType(kUserDomain, kMovieDocumentsFolderType, getter_AddRefs(localFile));
1057 }
1058 else if (inAtom == nsDirectoryService::sMusicDocumentsDirectory)
1059 {
1060 rv = GetOSXFolderType(kUserDomain, kMusicDocumentsFolderType, getter_AddRefs(localFile));
1061 }
1062 else if (inAtom == nsDirectoryService::sInternetSitesDirectory)
1063 {
1064 rv = GetOSXFolderType(kUserDomain, kInternetSitesFolderType, getter_AddRefs(localFile));
1065 }
1066#elif defined (XP_WIN)
1067 else if (inAtom == nsDirectoryService::sSystemDirectory)
1068 {
1069 rv = GetSpecialSystemDirectory(Win_SystemDirectory, getter_AddRefs(localFile));
1070 }
1071 else if (inAtom == nsDirectoryService::sWindowsDirectory)
1072 {
1073 rv = GetSpecialSystemDirectory(Win_WindowsDirectory, getter_AddRefs(localFile));
1074 }
1075 else if (inAtom == nsDirectoryService::sHomeDirectory)
1076 {
1077 rv = GetSpecialSystemDirectory(Win_HomeDirectory, getter_AddRefs(localFile));
1078 }
1079 else if (inAtom == nsDirectoryService::sDesktop)
1080 {
1081 rv = GetSpecialSystemDirectory(Win_Desktop, getter_AddRefs(localFile));
1082 }
1083 else if (inAtom == nsDirectoryService::sPrograms)
1084 {
1085 rv = GetSpecialSystemDirectory(Win_Programs, getter_AddRefs(localFile));
1086 }
1087 else if (inAtom == nsDirectoryService::sControls)
1088 {
1089 rv = GetSpecialSystemDirectory(Win_Controls, getter_AddRefs(localFile));
1090 }
1091 else if (inAtom == nsDirectoryService::sPrinters)
1092 {
1093 rv = GetSpecialSystemDirectory(Win_Printers, getter_AddRefs(localFile));
1094 }
1095 else if (inAtom == nsDirectoryService::sPersonal)
1096 {
1097 rv = GetSpecialSystemDirectory(Win_Personal, getter_AddRefs(localFile));
1098 }
1099 else if (inAtom == nsDirectoryService::sFavorites)
1100 {
1101 rv = GetSpecialSystemDirectory(Win_Favorites, getter_AddRefs(localFile));
1102 }
1103 else if (inAtom == nsDirectoryService::sStartup)
1104 {
1105 rv = GetSpecialSystemDirectory(Win_Startup, getter_AddRefs(localFile));
1106 }
1107 else if (inAtom == nsDirectoryService::sRecent)
1108 {
1109 rv = GetSpecialSystemDirectory(Win_Recent, getter_AddRefs(localFile));
1110 }
1111 else if (inAtom == nsDirectoryService::sSendto)
1112 {
1113 rv = GetSpecialSystemDirectory(Win_Sendto, getter_AddRefs(localFile));
1114 }
1115 else if (inAtom == nsDirectoryService::sBitbucket)
1116 {
1117 rv = GetSpecialSystemDirectory(Win_Bitbucket, getter_AddRefs(localFile));
1118 }
1119 else if (inAtom == nsDirectoryService::sStartmenu)
1120 {
1121 rv = GetSpecialSystemDirectory(Win_Startmenu, getter_AddRefs(localFile));
1122 }
1123 else if (inAtom == nsDirectoryService::sDesktopdirectory)
1124 {
1125 rv = GetSpecialSystemDirectory(Win_Desktopdirectory, getter_AddRefs(localFile));
1126 }
1127 else if (inAtom == nsDirectoryService::sDrives)
1128 {
1129 rv = GetSpecialSystemDirectory(Win_Drives, getter_AddRefs(localFile));
1130 }
1131 else if (inAtom == nsDirectoryService::sNetwork)
1132 {
1133 rv = GetSpecialSystemDirectory(Win_Network, getter_AddRefs(localFile));
1134 }
1135 else if (inAtom == nsDirectoryService::sNethood)
1136 {
1137 rv = GetSpecialSystemDirectory(Win_Nethood, getter_AddRefs(localFile));
1138 }
1139 else if (inAtom == nsDirectoryService::sFonts)
1140 {
1141 rv = GetSpecialSystemDirectory(Win_Fonts, getter_AddRefs(localFile));
1142 }
1143 else if (inAtom == nsDirectoryService::sTemplates)
1144 {
1145 rv = GetSpecialSystemDirectory(Win_Templates, getter_AddRefs(localFile));
1146 }
1147 else if (inAtom == nsDirectoryService::sCommon_Startmenu)
1148 {
1149 rv = GetSpecialSystemDirectory(Win_Common_Startmenu, getter_AddRefs(localFile));
1150 }
1151 else if (inAtom == nsDirectoryService::sCommon_Programs)
1152 {
1153 rv = GetSpecialSystemDirectory(Win_Common_Programs, getter_AddRefs(localFile));
1154 }
1155 else if (inAtom == nsDirectoryService::sCommon_Startup)
1156 {
1157 rv = GetSpecialSystemDirectory(Win_Common_Startup, getter_AddRefs(localFile));
1158 }
1159 else if (inAtom == nsDirectoryService::sCommon_Desktopdirectory)
1160 {
1161 rv = GetSpecialSystemDirectory(Win_Common_Desktopdirectory, getter_AddRefs(localFile));
1162 }
1163 else if (inAtom == nsDirectoryService::sAppdata)
1164 {
1165 rv = GetSpecialSystemDirectory(Win_Appdata, getter_AddRefs(localFile));
1166 }
1167 else if (inAtom == nsDirectoryService::sPrinthood)
1168 {
1169 rv = GetSpecialSystemDirectory(Win_Printhood, getter_AddRefs(localFile));
1170 }
1171 else if (inAtom == nsDirectoryService::sWinCookiesDirectory)
1172 {
1173 rv = GetSpecialSystemDirectory(Win_Cookies, getter_AddRefs(localFile));
1174 }
1175#elif defined (XP_UNIX)
1176
1177 else if (inAtom == nsDirectoryService::sLocalDirectory)
1178 {
1179 rv = GetSpecialSystemDirectory(Unix_LocalDirectory, getter_AddRefs(localFile));
1180 }
1181 else if (inAtom == nsDirectoryService::sLibDirectory)
1182 {
1183 rv = GetSpecialSystemDirectory(Unix_LibDirectory, getter_AddRefs(localFile));
1184 }
1185 else if (inAtom == nsDirectoryService::sHomeDirectory)
1186 {
1187 rv = GetSpecialSystemDirectory(Unix_HomeDirectory, getter_AddRefs(localFile));
1188 }
1189#elif defined (XP_OS2)
1190 else if (inAtom == nsDirectoryService::sSystemDirectory)
1191 {
1192 rv = GetSpecialSystemDirectory(OS2_SystemDirectory, getter_AddRefs(localFile));
1193 }
1194 else if (inAtom == nsDirectoryService::sOS2Directory)
1195 {
1196 rv = GetSpecialSystemDirectory(OS2_OS2Directory, getter_AddRefs(localFile));
1197 }
1198 else if (inAtom == nsDirectoryService::sHomeDirectory)
1199 {
1200 rv = GetSpecialSystemDirectory(OS2_HomeDirectory, getter_AddRefs(localFile));
1201 }
1202 else if (inAtom == nsDirectoryService::sDesktopDirectory)
1203 {
1204 rv = GetSpecialSystemDirectory(OS2_DesktopDirectory, getter_AddRefs(localFile));
1205 }
1206#elif defined (XP_BEOS)
1207 else if (inAtom == nsDirectoryService::sSettingsDirectory)
1208 {
1209 rv = GetSpecialSystemDirectory(BeOS_SettingsDirectory, getter_AddRefs(localFile));
1210 }
1211 else if (inAtom == nsDirectoryService::sHomeDirectory)
1212 {
1213 rv = GetSpecialSystemDirectory(BeOS_HomeDirectory, getter_AddRefs(localFile));
1214 }
1215 else if (inAtom == nsDirectoryService::sDesktopDirectory)
1216 {
1217 rv = GetSpecialSystemDirectory(BeOS_DesktopDirectory, getter_AddRefs(localFile));
1218 }
1219 else if (inAtom == nsDirectoryService::sSystemDirectory)
1220 {
1221 rv = GetSpecialSystemDirectory(BeOS_SystemDirectory, getter_AddRefs(localFile));
1222 }
1223#endif
1224
1225
1226 NS_RELEASE(inAtom);
1227
1228 if (localFile && NS_SUCCEEDED(rv))
1229 return localFile->QueryInterface(NS_GET_IID(nsIFile), (void**)_retval);
1230#ifdef DEBUG_dougt
1231 printf("Failed to find directory for key: %s\n", prop);
1232#endif
1233 return rv;
1234}
1235
1236NS_IMETHODIMP
1237nsDirectoryService::GetFiles(const char *prop, nsISimpleEnumerator **_retval)
1238{
1239 NS_ENSURE_ARG_POINTER(_retval);
1240 *_retval = nsnull;
1241
1242 return NS_ERROR_FAILURE;
1243}
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