VirtualBox

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

最後變更 在這個檔案從31232是 1,由 vboxsync 提交於 55 年 前

import

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

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