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 | //----------------------------------------------------------------------------------------
|
---|
116 | nsresult
|
---|
117 | nsDirectoryService::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 | PR_SetEnv("VBOX_XPCOM_HOME=" MOZ_DEFAULT_VBOX_XPCOM_HOME);
|
---|
335 | #endif
|
---|
336 |
|
---|
337 | char *moz5 = PR_GetEnv("VBOX_XPCOM_HOME");
|
---|
338 |
|
---|
339 | if (moz5)
|
---|
340 | {
|
---|
341 | if (realpath(moz5, buf)) {
|
---|
342 | localFile->InitWithNativePath(nsDependentCString(buf));
|
---|
343 | *aFile = localFile;
|
---|
344 | return NS_OK;
|
---|
345 | }
|
---|
346 | }
|
---|
347 | #if defined(DEBUG)
|
---|
348 | static PRBool firstWarning = PR_TRUE;
|
---|
349 |
|
---|
350 | if(!moz5 && firstWarning) {
|
---|
351 | // Warn that VBOX_XPCOM_HOME not set, once.
|
---|
352 | printf("Warning: VBOX_XPCOM_HOME not set.\n");
|
---|
353 | firstWarning = PR_FALSE;
|
---|
354 | }
|
---|
355 | #endif /* DEBUG */
|
---|
356 |
|
---|
357 | // Fall back to current directory.
|
---|
358 | if (getcwd(buf, sizeof(buf)))
|
---|
359 | {
|
---|
360 | localFile->InitWithNativePath(nsDependentCString(buf));
|
---|
361 | *aFile = localFile;
|
---|
362 | return NS_OK;
|
---|
363 | }
|
---|
364 |
|
---|
365 | #elif defined(XP_OS2)
|
---|
366 | PPIB ppib;
|
---|
367 | PTIB ptib;
|
---|
368 | char buffer[CCHMAXPATH];
|
---|
369 | DosGetInfoBlocks( &ptib, &ppib);
|
---|
370 | DosQueryModuleName( ppib->pib_hmte, CCHMAXPATH, buffer);
|
---|
371 | *strrchr( buffer, '\\') = '\0'; // XXX DBCS misery
|
---|
372 | localFile->InitWithNativePath(nsDependentCString(buffer));
|
---|
373 | *aFile = localFile;
|
---|
374 | return NS_OK;
|
---|
375 |
|
---|
376 | #elif defined(XP_BEOS)
|
---|
377 |
|
---|
378 | char *moz5 = getenv("VBOX_XPCOM_HOME");
|
---|
379 | if (moz5)
|
---|
380 | {
|
---|
381 | localFile->InitWithNativePath(nsDependentCString(moz5));
|
---|
382 | localFile->Normalize();
|
---|
383 | *aFile = localFile;
|
---|
384 | return NS_OK;
|
---|
385 | }
|
---|
386 | else
|
---|
387 | {
|
---|
388 | static char buf[MAXPATHLEN];
|
---|
389 | int32 cookie = 0;
|
---|
390 | image_info info;
|
---|
391 | char *p;
|
---|
392 | *buf = 0;
|
---|
393 | if(get_next_image_info(0, &cookie, &info) == B_OK)
|
---|
394 | {
|
---|
395 | strcpy(buf, info.name);
|
---|
396 | if((p = strrchr(buf, '/')) != 0)
|
---|
397 | {
|
---|
398 | *p = 0;
|
---|
399 | localFile->InitWithNativePath(nsDependentCString(buf));
|
---|
400 | *aFile = localFile;
|
---|
401 | return NS_OK;
|
---|
402 | }
|
---|
403 | }
|
---|
404 | }
|
---|
405 |
|
---|
406 | #endif
|
---|
407 |
|
---|
408 | NS_RELEASE(localFile);
|
---|
409 |
|
---|
410 | NS_ERROR("unable to get current process directory");
|
---|
411 | return NS_ERROR_FAILURE;
|
---|
412 | } // GetCurrentProcessDirectory()
|
---|
413 |
|
---|
414 |
|
---|
415 | nsIAtom* nsDirectoryService::sCurrentProcess = nsnull;
|
---|
416 | nsIAtom* nsDirectoryService::sComponentRegistry = nsnull;
|
---|
417 | nsIAtom* nsDirectoryService::sXPTIRegistry = nsnull;
|
---|
418 | nsIAtom* nsDirectoryService::sComponentDirectory = nsnull;
|
---|
419 | nsIAtom* nsDirectoryService::sGRE_Directory = nsnull;
|
---|
420 | nsIAtom* nsDirectoryService::sGRE_ComponentDirectory = nsnull;
|
---|
421 | nsIAtom* nsDirectoryService::sOS_DriveDirectory = nsnull;
|
---|
422 | nsIAtom* nsDirectoryService::sOS_TemporaryDirectory = nsnull;
|
---|
423 | nsIAtom* nsDirectoryService::sOS_CurrentProcessDirectory = nsnull;
|
---|
424 | nsIAtom* nsDirectoryService::sOS_CurrentWorkingDirectory = nsnull;
|
---|
425 | #if defined (XP_MACOSX)
|
---|
426 | nsIAtom* nsDirectoryService::sDirectory = nsnull;
|
---|
427 | nsIAtom* nsDirectoryService::sDesktopDirectory = nsnull;
|
---|
428 | nsIAtom* nsDirectoryService::sTrashDirectory = nsnull;
|
---|
429 | nsIAtom* nsDirectoryService::sStartupDirectory = nsnull;
|
---|
430 | nsIAtom* nsDirectoryService::sShutdownDirectory = nsnull;
|
---|
431 | nsIAtom* nsDirectoryService::sAppleMenuDirectory = nsnull;
|
---|
432 | nsIAtom* nsDirectoryService::sControlPanelDirectory = nsnull;
|
---|
433 | nsIAtom* nsDirectoryService::sExtensionDirectory = nsnull;
|
---|
434 | nsIAtom* nsDirectoryService::sFontsDirectory = nsnull;
|
---|
435 | nsIAtom* nsDirectoryService::sPreferencesDirectory = nsnull;
|
---|
436 | nsIAtom* nsDirectoryService::sDocumentsDirectory = nsnull;
|
---|
437 | nsIAtom* nsDirectoryService::sInternetSearchDirectory = nsnull;
|
---|
438 | nsIAtom* nsDirectoryService::sUserLibDirectory = nsnull;
|
---|
439 | nsIAtom* nsDirectoryService::sHomeDirectory = nsnull;
|
---|
440 | nsIAtom* nsDirectoryService::sDefaultDownloadDirectory = nsnull;
|
---|
441 | nsIAtom* nsDirectoryService::sUserDesktopDirectory = nsnull;
|
---|
442 | nsIAtom* nsDirectoryService::sLocalDesktopDirectory = nsnull;
|
---|
443 | nsIAtom* nsDirectoryService::sUserApplicationsDirectory = nsnull;
|
---|
444 | nsIAtom* nsDirectoryService::sLocalApplicationsDirectory = nsnull;
|
---|
445 | nsIAtom* nsDirectoryService::sUserDocumentsDirectory = nsnull;
|
---|
446 | nsIAtom* nsDirectoryService::sLocalDocumentsDirectory = nsnull;
|
---|
447 | nsIAtom* nsDirectoryService::sUserInternetPlugInDirectory = nsnull;
|
---|
448 | nsIAtom* nsDirectoryService::sLocalInternetPlugInDirectory = nsnull;
|
---|
449 | nsIAtom* nsDirectoryService::sUserFrameworksDirectory = nsnull;
|
---|
450 | nsIAtom* nsDirectoryService::sLocalFrameworksDirectory = nsnull;
|
---|
451 | nsIAtom* nsDirectoryService::sUserPreferencesDirectory = nsnull;
|
---|
452 | nsIAtom* nsDirectoryService::sLocalPreferencesDirectory = nsnull;
|
---|
453 | nsIAtom* nsDirectoryService::sPictureDocumentsDirectory = nsnull;
|
---|
454 | nsIAtom* nsDirectoryService::sMovieDocumentsDirectory = nsnull;
|
---|
455 | nsIAtom* nsDirectoryService::sMusicDocumentsDirectory = nsnull;
|
---|
456 | nsIAtom* nsDirectoryService::sInternetSitesDirectory = nsnull;
|
---|
457 | #elif defined (XP_WIN)
|
---|
458 | nsIAtom* nsDirectoryService::sSystemDirectory = nsnull;
|
---|
459 | nsIAtom* nsDirectoryService::sWindowsDirectory = nsnull;
|
---|
460 | nsIAtom* nsDirectoryService::sHomeDirectory = nsnull;
|
---|
461 | nsIAtom* nsDirectoryService::sDesktop = nsnull;
|
---|
462 | nsIAtom* nsDirectoryService::sPrograms = nsnull;
|
---|
463 | nsIAtom* nsDirectoryService::sControls = nsnull;
|
---|
464 | nsIAtom* nsDirectoryService::sPrinters = nsnull;
|
---|
465 | nsIAtom* nsDirectoryService::sPersonal = nsnull;
|
---|
466 | nsIAtom* nsDirectoryService::sFavorites = nsnull;
|
---|
467 | nsIAtom* nsDirectoryService::sStartup = nsnull;
|
---|
468 | nsIAtom* nsDirectoryService::sRecent = nsnull;
|
---|
469 | nsIAtom* nsDirectoryService::sSendto = nsnull;
|
---|
470 | nsIAtom* nsDirectoryService::sBitbucket = nsnull;
|
---|
471 | nsIAtom* nsDirectoryService::sStartmenu = nsnull;
|
---|
472 | nsIAtom* nsDirectoryService::sDesktopdirectory = nsnull;
|
---|
473 | nsIAtom* nsDirectoryService::sDrives = nsnull;
|
---|
474 | nsIAtom* nsDirectoryService::sNetwork = nsnull;
|
---|
475 | nsIAtom* nsDirectoryService::sNethood = nsnull;
|
---|
476 | nsIAtom* nsDirectoryService::sFonts = nsnull;
|
---|
477 | nsIAtom* nsDirectoryService::sTemplates = nsnull;
|
---|
478 | nsIAtom* nsDirectoryService::sCommon_Startmenu = nsnull;
|
---|
479 | nsIAtom* nsDirectoryService::sCommon_Programs = nsnull;
|
---|
480 | nsIAtom* nsDirectoryService::sCommon_Startup = nsnull;
|
---|
481 | nsIAtom* nsDirectoryService::sCommon_Desktopdirectory = nsnull;
|
---|
482 | nsIAtom* nsDirectoryService::sAppdata = nsnull;
|
---|
483 | nsIAtom* nsDirectoryService::sPrinthood = nsnull;
|
---|
484 | nsIAtom* nsDirectoryService::sWinCookiesDirectory = nsnull;
|
---|
485 | #elif defined (XP_UNIX)
|
---|
486 | nsIAtom* nsDirectoryService::sLocalDirectory = nsnull;
|
---|
487 | nsIAtom* nsDirectoryService::sLibDirectory = nsnull;
|
---|
488 | nsIAtom* nsDirectoryService::sHomeDirectory = nsnull;
|
---|
489 | #elif defined (XP_OS2)
|
---|
490 | nsIAtom* nsDirectoryService::sSystemDirectory = nsnull;
|
---|
491 | nsIAtom* nsDirectoryService::sOS2Directory = nsnull;
|
---|
492 | nsIAtom* nsDirectoryService::sHomeDirectory = nsnull;
|
---|
493 | nsIAtom* nsDirectoryService::sDesktopDirectory = nsnull;
|
---|
494 | #elif defined (XP_BEOS)
|
---|
495 | nsIAtom* nsDirectoryService::sSettingsDirectory = nsnull;
|
---|
496 | nsIAtom* nsDirectoryService::sHomeDirectory = nsnull;
|
---|
497 | nsIAtom* nsDirectoryService::sDesktopDirectory = nsnull;
|
---|
498 | nsIAtom* nsDirectoryService::sSystemDirectory = nsnull;
|
---|
499 | #endif
|
---|
500 |
|
---|
501 |
|
---|
502 | nsDirectoryService* nsDirectoryService::mService = nsnull;
|
---|
503 |
|
---|
504 | nsDirectoryService::nsDirectoryService() :
|
---|
505 | mHashtable(256, PR_TRUE)
|
---|
506 | {
|
---|
507 | }
|
---|
508 |
|
---|
509 | NS_METHOD
|
---|
510 | nsDirectoryService::Create(nsISupports *outer, REFNSIID aIID, void **aResult)
|
---|
511 | {
|
---|
512 | NS_ENSURE_ARG_POINTER(aResult);
|
---|
513 | if (!mService)
|
---|
514 | {
|
---|
515 | mService = new nsDirectoryService();
|
---|
516 | if (!mService)
|
---|
517 | return NS_ERROR_OUT_OF_MEMORY;
|
---|
518 | }
|
---|
519 | return mService->QueryInterface(aIID, aResult);
|
---|
520 | }
|
---|
521 |
|
---|
522 | static const nsStaticAtom directory_atoms[] = {
|
---|
523 | { NS_XPCOM_CURRENT_PROCESS_DIR, &nsDirectoryService::sCurrentProcess },
|
---|
524 | { NS_XPCOM_COMPONENT_REGISTRY_FILE, &nsDirectoryService::sComponentRegistry },
|
---|
525 | { NS_XPCOM_COMPONENT_DIR, &nsDirectoryService::sComponentDirectory },
|
---|
526 | { NS_XPCOM_XPTI_REGISTRY_FILE, &nsDirectoryService::sXPTIRegistry },
|
---|
527 | { NS_GRE_DIR, &nsDirectoryService::sGRE_Directory },
|
---|
528 | { NS_GRE_COMPONENT_DIR, &nsDirectoryService::sGRE_ComponentDirectory },
|
---|
529 | { NS_OS_DRIVE_DIR, &nsDirectoryService::sOS_DriveDirectory },
|
---|
530 | { NS_OS_TEMP_DIR, &nsDirectoryService::sOS_TemporaryDirectory },
|
---|
531 | { NS_OS_CURRENT_PROCESS_DIR, &nsDirectoryService::sOS_CurrentProcessDirectory },
|
---|
532 | { NS_OS_CURRENT_WORKING_DIR, &nsDirectoryService::sOS_CurrentWorkingDirectory },
|
---|
533 | { NS_XPCOM_INIT_CURRENT_PROCESS_DIR, nsnull },
|
---|
534 | #if defined (XP_MACOSX)
|
---|
535 | { NS_OS_SYSTEM_DIR, &nsDirectoryService::sDirectory },
|
---|
536 | { NS_MAC_DESKTOP_DIR, &nsDirectoryService::sDesktopDirectory },
|
---|
537 | { NS_MAC_TRASH_DIR, &nsDirectoryService::sTrashDirectory },
|
---|
538 | { NS_MAC_STARTUP_DIR, &nsDirectoryService::sStartupDirectory },
|
---|
539 | { NS_MAC_SHUTDOWN_DIR, &nsDirectoryService::sShutdownDirectory },
|
---|
540 | { NS_MAC_APPLE_MENU_DIR, &nsDirectoryService::sAppleMenuDirectory },
|
---|
541 | { NS_MAC_CONTROL_PANELS_DIR, &nsDirectoryService::sControlPanelDirectory },
|
---|
542 | { NS_MAC_EXTENSIONS_DIR, &nsDirectoryService::sExtensionDirectory },
|
---|
543 | { NS_MAC_FONTS_DIR, &nsDirectoryService::sFontsDirectory },
|
---|
544 | { NS_MAC_PREFS_DIR, &nsDirectoryService::sPreferencesDirectory },
|
---|
545 | { NS_MAC_DOCUMENTS_DIR, &nsDirectoryService::sDocumentsDirectory },
|
---|
546 | { NS_MAC_INTERNET_SEARCH_DIR, &nsDirectoryService::sInternetSearchDirectory },
|
---|
547 | { NS_MAC_USER_LIB_DIR, &nsDirectoryService::sUserLibDirectory },
|
---|
548 | { NS_OSX_HOME_DIR, &nsDirectoryService::sHomeDirectory },
|
---|
549 | { NS_OSX_DEFAULT_DOWNLOAD_DIR, &nsDirectoryService::sDefaultDownloadDirectory },
|
---|
550 | { NS_OSX_USER_DESKTOP_DIR, &nsDirectoryService::sUserDesktopDirectory },
|
---|
551 | { NS_OSX_LOCAL_DESKTOP_DIR, &nsDirectoryService::sLocalDesktopDirectory },
|
---|
552 | { NS_OSX_USER_APPLICATIONS_DIR, &nsDirectoryService::sUserApplicationsDirectory },
|
---|
553 | { NS_OSX_LOCAL_APPLICATIONS_DIR, &nsDirectoryService::sLocalApplicationsDirectory },
|
---|
554 | { NS_OSX_USER_DOCUMENTS_DIR, &nsDirectoryService::sUserDocumentsDirectory },
|
---|
555 | { NS_OSX_LOCAL_DOCUMENTS_DIR, &nsDirectoryService::sLocalDocumentsDirectory },
|
---|
556 | { NS_OSX_USER_INTERNET_PLUGIN_DIR, &nsDirectoryService::sUserInternetPlugInDirectory },
|
---|
557 | { NS_OSX_LOCAL_INTERNET_PLUGIN_DIR, &nsDirectoryService::sLocalInternetPlugInDirectory },
|
---|
558 | { NS_OSX_USER_FRAMEWORKS_DIR, &nsDirectoryService::sUserFrameworksDirectory },
|
---|
559 | { NS_OSX_LOCAL_FRAMEWORKS_DIR, &nsDirectoryService::sLocalFrameworksDirectory },
|
---|
560 | { NS_OSX_USER_PREFERENCES_DIR, &nsDirectoryService::sUserPreferencesDirectory },
|
---|
561 | { NS_OSX_LOCAL_PREFERENCES_DIR, &nsDirectoryService::sLocalPreferencesDirectory },
|
---|
562 | { NS_OSX_PICTURE_DOCUMENTS_DIR, &nsDirectoryService::sPictureDocumentsDirectory },
|
---|
563 | { NS_OSX_MOVIE_DOCUMENTS_DIR, &nsDirectoryService::sMovieDocumentsDirectory },
|
---|
564 | { NS_OSX_MUSIC_DOCUMENTS_DIR, &nsDirectoryService::sMusicDocumentsDirectory },
|
---|
565 | { NS_OSX_INTERNET_SITES_DIR, &nsDirectoryService::sInternetSitesDirectory },
|
---|
566 | #elif defined (XP_WIN)
|
---|
567 | { NS_OS_SYSTEM_DIR, &nsDirectoryService::sSystemDirectory },
|
---|
568 | { NS_WIN_WINDOWS_DIR, &nsDirectoryService::sWindowsDirectory },
|
---|
569 | { NS_WIN_HOME_DIR, &nsDirectoryService::sHomeDirectory },
|
---|
570 | { NS_WIN_DESKTOP_DIR, &nsDirectoryService::sDesktop },
|
---|
571 | { NS_WIN_PROGRAMS_DIR, &nsDirectoryService::sPrograms },
|
---|
572 | { NS_WIN_CONTROLS_DIR, &nsDirectoryService::sControls },
|
---|
573 | { NS_WIN_PRINTERS_DIR, &nsDirectoryService::sPrinters },
|
---|
574 | { NS_WIN_PERSONAL_DIR, &nsDirectoryService::sPersonal },
|
---|
575 | { NS_WIN_FAVORITES_DIR, &nsDirectoryService::sFavorites },
|
---|
576 | { NS_WIN_STARTUP_DIR, &nsDirectoryService::sStartup },
|
---|
577 | { NS_WIN_RECENT_DIR, &nsDirectoryService::sRecent },
|
---|
578 | { NS_WIN_SEND_TO_DIR, &nsDirectoryService::sSendto },
|
---|
579 | { NS_WIN_BITBUCKET_DIR, &nsDirectoryService::sBitbucket },
|
---|
580 | { NS_WIN_STARTMENU_DIR, &nsDirectoryService::sStartmenu },
|
---|
581 | { NS_WIN_DESKTOP_DIRECTORY, &nsDirectoryService::sDesktopdirectory },
|
---|
582 | { NS_WIN_DRIVES_DIR, &nsDirectoryService::sDrives },
|
---|
583 | { NS_WIN_NETWORK_DIR, &nsDirectoryService::sNetwork },
|
---|
584 | { NS_WIN_NETHOOD_DIR, &nsDirectoryService::sNethood },
|
---|
585 | { NS_WIN_FONTS_DIR, &nsDirectoryService::sFonts },
|
---|
586 | { NS_WIN_TEMPLATES_DIR, &nsDirectoryService::sTemplates },
|
---|
587 | { NS_WIN_COMMON_STARTMENU_DIR, &nsDirectoryService::sCommon_Startmenu },
|
---|
588 | { NS_WIN_COMMON_PROGRAMS_DIR, &nsDirectoryService::sCommon_Programs },
|
---|
589 | { NS_WIN_COMMON_STARTUP_DIR, &nsDirectoryService::sCommon_Startup },
|
---|
590 | { NS_WIN_COMMON_DESKTOP_DIRECTORY, &nsDirectoryService::sCommon_Desktopdirectory },
|
---|
591 | { NS_WIN_APPDATA_DIR, &nsDirectoryService::sAppdata },
|
---|
592 | { NS_WIN_PRINTHOOD, &nsDirectoryService::sPrinthood },
|
---|
593 | { NS_WIN_COOKIES_DIR, &nsDirectoryService::sWinCookiesDirectory },
|
---|
594 | #elif defined (XP_UNIX)
|
---|
595 | { NS_UNIX_LOCAL_DIR, &nsDirectoryService::sLocalDirectory },
|
---|
596 | { NS_UNIX_LIB_DIR, &nsDirectoryService::sLibDirectory },
|
---|
597 | { NS_UNIX_HOME_DIR, &nsDirectoryService::sHomeDirectory },
|
---|
598 | #elif defined (XP_OS2)
|
---|
599 | { NS_OS_SYSTEM_DIR, &nsDirectoryService::sSystemDirectory },
|
---|
600 | { NS_OS2_DIR, &nsDirectoryService::sOS2Directory },
|
---|
601 | { NS_OS2_HOME_DIR, &nsDirectoryService::sHomeDirectory },
|
---|
602 | { NS_OS2_DESKTOP_DIR, &nsDirectoryService::sDesktopDirectory },
|
---|
603 | #elif defined (XP_BEOS)
|
---|
604 | { NS_OS_SYSTEM_DIR, &nsDirectoryService::sSystemDirectory },
|
---|
605 | { NS_BEOS_SETTINGS_DIR, &nsDirectoryService::sSettingsDirectory },
|
---|
606 | { NS_BEOS_HOME_DIR, &nsDirectoryService::sHomeDirectory },
|
---|
607 | { NS_BEOS_DESKTOP_DIR, &nsDirectoryService::sDesktopDirectory },
|
---|
608 | #endif
|
---|
609 | };
|
---|
610 |
|
---|
611 | nsresult
|
---|
612 | nsDirectoryService::Init()
|
---|
613 | {
|
---|
614 | nsresult rv;
|
---|
615 |
|
---|
616 | rv = NS_NewISupportsArray(getter_AddRefs(mProviders));
|
---|
617 | if (NS_FAILED(rv)) return rv;
|
---|
618 |
|
---|
619 | NS_RegisterStaticAtoms(directory_atoms, NS_ARRAY_LENGTH(directory_atoms));
|
---|
620 |
|
---|
621 | // Let the list hold the only reference to the provider.
|
---|
622 | nsAppFileLocationProvider *defaultProvider = new nsAppFileLocationProvider;
|
---|
623 | if (!defaultProvider)
|
---|
624 | return NS_ERROR_OUT_OF_MEMORY;
|
---|
625 | // AppendElement returns PR_TRUE for success.
|
---|
626 | rv = mProviders->AppendElement(defaultProvider) ? NS_OK : NS_ERROR_FAILURE;
|
---|
627 |
|
---|
628 | return rv;
|
---|
629 | }
|
---|
630 |
|
---|
631 | PRBool
|
---|
632 | nsDirectoryService::ReleaseValues(nsHashKey* key, void* data, void* closure)
|
---|
633 | {
|
---|
634 | nsISupports* value = (nsISupports*)data;
|
---|
635 | NS_IF_RELEASE(value);
|
---|
636 | return PR_TRUE;
|
---|
637 | }
|
---|
638 |
|
---|
639 | nsDirectoryService::~nsDirectoryService()
|
---|
640 | {
|
---|
641 | // clear the global
|
---|
642 | mService = nsnull;
|
---|
643 |
|
---|
644 | }
|
---|
645 |
|
---|
646 | NS_IMPL_THREADSAFE_ISUPPORTS4(nsDirectoryService, nsIProperties, nsIDirectoryService, nsIDirectoryServiceProvider, nsIDirectoryServiceProvider2)
|
---|
647 |
|
---|
648 |
|
---|
649 | NS_IMETHODIMP
|
---|
650 | nsDirectoryService::Undefine(const char* prop)
|
---|
651 | {
|
---|
652 | nsCStringKey key(prop);
|
---|
653 | if (!mHashtable.Exists(&key))
|
---|
654 | return NS_ERROR_FAILURE;
|
---|
655 |
|
---|
656 | mHashtable.Remove (&key);
|
---|
657 | return NS_OK;
|
---|
658 | }
|
---|
659 |
|
---|
660 | NS_IMETHODIMP
|
---|
661 | nsDirectoryService::GetKeys(PRUint32 *count, char ***keys)
|
---|
662 | {
|
---|
663 | return NS_ERROR_NOT_IMPLEMENTED;
|
---|
664 | }
|
---|
665 |
|
---|
666 | struct FileData
|
---|
667 | {
|
---|
668 | FileData(const char* aProperty,
|
---|
669 | const nsIID& aUUID) :
|
---|
670 | property(aProperty),
|
---|
671 | data(nsnull),
|
---|
672 | persistent(PR_TRUE),
|
---|
673 | uuid(aUUID) {}
|
---|
674 |
|
---|
675 | const char* property;
|
---|
676 | nsISupports* data;
|
---|
677 | PRBool persistent;
|
---|
678 | const nsIID& uuid;
|
---|
679 | };
|
---|
680 |
|
---|
681 | static PRBool FindProviderFile(nsISupports* aElement, void *aData)
|
---|
682 | {
|
---|
683 | nsresult rv;
|
---|
684 | FileData* fileData = (FileData*)aData;
|
---|
685 | if (fileData->uuid.Equals(NS_GET_IID(nsISimpleEnumerator)))
|
---|
686 | {
|
---|
687 | // Not all providers implement this iface
|
---|
688 | nsCOMPtr<nsIDirectoryServiceProvider2> prov2 = do_QueryInterface(aElement);
|
---|
689 | if (prov2)
|
---|
690 | {
|
---|
691 | rv = prov2->GetFiles(fileData->property, (nsISimpleEnumerator **)&fileData->data);
|
---|
692 | if (NS_SUCCEEDED(rv) && fileData->data) {
|
---|
693 | fileData->persistent = PR_FALSE; // Enumerators can never be peristent
|
---|
694 | return PR_FALSE;
|
---|
695 | }
|
---|
696 | }
|
---|
697 | }
|
---|
698 | else
|
---|
699 | {
|
---|
700 | nsCOMPtr<nsIDirectoryServiceProvider> prov = do_QueryInterface(aElement);
|
---|
701 | if (!prov)
|
---|
702 | return PR_FALSE;
|
---|
703 | rv = prov->GetFile(fileData->property, &fileData->persistent, (nsIFile **)&fileData->data);
|
---|
704 | if (NS_SUCCEEDED(rv) && fileData->data)
|
---|
705 | return PR_FALSE;
|
---|
706 | }
|
---|
707 |
|
---|
708 | return PR_TRUE;
|
---|
709 | }
|
---|
710 |
|
---|
711 | NS_IMETHODIMP
|
---|
712 | nsDirectoryService::Get(const char* prop, const nsIID & uuid, void* *result)
|
---|
713 | {
|
---|
714 | nsCStringKey key(prop);
|
---|
715 |
|
---|
716 | nsCOMPtr<nsISupports> value = dont_AddRef(mHashtable.Get(&key));
|
---|
717 |
|
---|
718 | if (value)
|
---|
719 | {
|
---|
720 | nsCOMPtr<nsIFile> cloneFile;
|
---|
721 | nsCOMPtr<nsIFile> cachedFile = do_QueryInterface(value);
|
---|
722 | NS_ASSERTION(cachedFile, "nsIFile expected");
|
---|
723 |
|
---|
724 | cachedFile->Clone(getter_AddRefs(cloneFile));
|
---|
725 | return cloneFile->QueryInterface(uuid, result);
|
---|
726 | }
|
---|
727 |
|
---|
728 | // it is not one of our defaults, lets check any providers
|
---|
729 | FileData fileData(prop, uuid);
|
---|
730 |
|
---|
731 | mProviders->EnumerateBackwards(FindProviderFile, &fileData);
|
---|
732 | if (fileData.data)
|
---|
733 | {
|
---|
734 | if (fileData.persistent)
|
---|
735 | {
|
---|
736 | Set(prop, NS_STATIC_CAST(nsIFile*, fileData.data));
|
---|
737 | }
|
---|
738 | nsresult rv = (fileData.data)->QueryInterface(uuid, result);
|
---|
739 | NS_RELEASE(fileData.data); // addref occurs in FindProviderFile()
|
---|
740 | return rv;
|
---|
741 | }
|
---|
742 |
|
---|
743 | FindProviderFile(NS_STATIC_CAST(nsIDirectoryServiceProvider*, this), &fileData);
|
---|
744 | if (fileData.data)
|
---|
745 | {
|
---|
746 | if (fileData.persistent)
|
---|
747 | {
|
---|
748 | Set(prop, NS_STATIC_CAST(nsIFile*, fileData.data));
|
---|
749 | }
|
---|
750 | nsresult rv = (fileData.data)->QueryInterface(uuid, result);
|
---|
751 | NS_RELEASE(fileData.data); // addref occurs in FindProviderFile()
|
---|
752 | return rv;
|
---|
753 | }
|
---|
754 |
|
---|
755 | return NS_ERROR_FAILURE;
|
---|
756 | }
|
---|
757 |
|
---|
758 | NS_IMETHODIMP
|
---|
759 | nsDirectoryService::Set(const char* prop, nsISupports* value)
|
---|
760 | {
|
---|
761 | nsCStringKey key(prop);
|
---|
762 | if (mHashtable.Exists(&key) || value == nsnull)
|
---|
763 | return NS_ERROR_FAILURE;
|
---|
764 |
|
---|
765 | nsCOMPtr<nsIFile> ourFile;
|
---|
766 | value->QueryInterface(NS_GET_IID(nsIFile), getter_AddRefs(ourFile));
|
---|
767 | if (ourFile)
|
---|
768 | {
|
---|
769 | nsCOMPtr<nsIFile> cloneFile;
|
---|
770 | ourFile->Clone (getter_AddRefs (cloneFile));
|
---|
771 | mHashtable.Put(&key, cloneFile);
|
---|
772 |
|
---|
773 | return NS_OK;
|
---|
774 | }
|
---|
775 |
|
---|
776 | return NS_ERROR_FAILURE;
|
---|
777 | }
|
---|
778 |
|
---|
779 | NS_IMETHODIMP
|
---|
780 | nsDirectoryService::Has(const char *prop, PRBool *_retval)
|
---|
781 | {
|
---|
782 | *_retval = PR_FALSE;
|
---|
783 | nsCOMPtr<nsIFile> value;
|
---|
784 | nsresult rv = Get(prop, NS_GET_IID(nsIFile), getter_AddRefs(value));
|
---|
785 | if (NS_FAILED(rv))
|
---|
786 | return rv;
|
---|
787 |
|
---|
788 | if (value)
|
---|
789 | {
|
---|
790 | *_retval = PR_TRUE;
|
---|
791 | }
|
---|
792 |
|
---|
793 | return rv;
|
---|
794 | }
|
---|
795 |
|
---|
796 | NS_IMETHODIMP
|
---|
797 | nsDirectoryService::RegisterProvider(nsIDirectoryServiceProvider *prov)
|
---|
798 | {
|
---|
799 | nsresult rv;
|
---|
800 | if (!prov)
|
---|
801 | return NS_ERROR_FAILURE;
|
---|
802 | if (!mProviders)
|
---|
803 | return NS_ERROR_NOT_INITIALIZED;
|
---|
804 |
|
---|
805 | nsCOMPtr<nsISupports> supports = do_QueryInterface(prov, &rv);
|
---|
806 | if (NS_FAILED(rv)) return rv;
|
---|
807 |
|
---|
808 | // AppendElement returns PR_TRUE for success.
|
---|
809 | return mProviders->AppendElement(supports) ? NS_OK : NS_ERROR_FAILURE;
|
---|
810 | }
|
---|
811 |
|
---|
812 | NS_IMETHODIMP
|
---|
813 | nsDirectoryService::UnregisterProvider(nsIDirectoryServiceProvider *prov)
|
---|
814 | {
|
---|
815 | nsresult rv;
|
---|
816 | if (!prov)
|
---|
817 | return NS_ERROR_FAILURE;
|
---|
818 | if (!mProviders)
|
---|
819 | return NS_ERROR_NOT_INITIALIZED;
|
---|
820 |
|
---|
821 | nsCOMPtr<nsISupports> supports = do_QueryInterface(prov, &rv);
|
---|
822 | if (NS_FAILED(rv)) return rv;
|
---|
823 |
|
---|
824 | // RemoveElement returns PR_TRUE for success.
|
---|
825 | return mProviders->RemoveElement(supports) ? NS_OK : NS_ERROR_FAILURE;
|
---|
826 | }
|
---|
827 |
|
---|
828 | // DO NOT ADD ANY LOCATIONS TO THIS FUNCTION UNTIL YOU TALK TO: [email protected].
|
---|
829 | // This is meant to be a place of xpcom or system specific file locations, not
|
---|
830 | // application specific locations. If you need the later, register a callback for
|
---|
831 | // your application.
|
---|
832 |
|
---|
833 | NS_IMETHODIMP
|
---|
834 | nsDirectoryService::GetFile(const char *prop, PRBool *persistent, nsIFile **_retval)
|
---|
835 | {
|
---|
836 | nsCOMPtr<nsILocalFile> localFile;
|
---|
837 | nsresult rv = NS_ERROR_FAILURE;
|
---|
838 |
|
---|
839 | *_retval = nsnull;
|
---|
840 | *persistent = PR_TRUE;
|
---|
841 |
|
---|
842 | nsIAtom* inAtom = NS_NewAtom(prop);
|
---|
843 |
|
---|
844 | // check to see if it is one of our defaults
|
---|
845 |
|
---|
846 | if (inAtom == nsDirectoryService::sCurrentProcess ||
|
---|
847 | inAtom == nsDirectoryService::sOS_CurrentProcessDirectory )
|
---|
848 | {
|
---|
849 | rv = GetCurrentProcessDirectory(getter_AddRefs(localFile));
|
---|
850 | }
|
---|
851 | else if (inAtom == nsDirectoryService::sComponentRegistry)
|
---|
852 | {
|
---|
853 | rv = GetCurrentProcessDirectory(getter_AddRefs(localFile));
|
---|
854 | if (!localFile)
|
---|
855 | return NS_ERROR_FAILURE;
|
---|
856 |
|
---|
857 | localFile->AppendNative(COMPONENT_DIRECTORY);
|
---|
858 | localFile->AppendNative(COMPONENT_REGISTRY_NAME);
|
---|
859 | }
|
---|
860 | else if (inAtom == nsDirectoryService::sXPTIRegistry)
|
---|
861 | {
|
---|
862 | rv = GetCurrentProcessDirectory(getter_AddRefs(localFile));
|
---|
863 | if (!localFile)
|
---|
864 | return NS_ERROR_FAILURE;
|
---|
865 |
|
---|
866 | localFile->AppendNative(COMPONENT_DIRECTORY);
|
---|
867 | localFile->AppendNative(XPTI_REGISTRY_NAME);
|
---|
868 | }
|
---|
869 |
|
---|
870 | // Unless otherwise set, the core pieces of the GRE exist
|
---|
871 | // in the current process directory.
|
---|
872 | else if (inAtom == nsDirectoryService::sGRE_Directory)
|
---|
873 | {
|
---|
874 | rv = GetCurrentProcessDirectory(getter_AddRefs(localFile));
|
---|
875 | }
|
---|
876 | // the GRE components directory is relative to the GRE directory
|
---|
877 | // by default; applications may override this behavior in special
|
---|
878 | // cases
|
---|
879 | else if (inAtom == nsDirectoryService::sGRE_ComponentDirectory)
|
---|
880 | {
|
---|
881 | rv = Get(NS_GRE_DIR, nsILocalFile::GetIID(), getter_AddRefs(localFile));
|
---|
882 | if (localFile)
|
---|
883 | localFile->AppendNative(COMPONENT_DIRECTORY);
|
---|
884 | }
|
---|
885 | else if (inAtom == nsDirectoryService::sComponentDirectory)
|
---|
886 | {
|
---|
887 | rv = GetCurrentProcessDirectory(getter_AddRefs(localFile));
|
---|
888 | if (localFile)
|
---|
889 | localFile->AppendNative(COMPONENT_DIRECTORY);
|
---|
890 | }
|
---|
891 | else if (inAtom == nsDirectoryService::sOS_DriveDirectory)
|
---|
892 | {
|
---|
893 | rv = GetSpecialSystemDirectory(OS_DriveDirectory, getter_AddRefs(localFile));
|
---|
894 | }
|
---|
895 | else if (inAtom == nsDirectoryService::sOS_TemporaryDirectory)
|
---|
896 | {
|
---|
897 | rv = GetSpecialSystemDirectory(OS_TemporaryDirectory, getter_AddRefs(localFile));
|
---|
898 | }
|
---|
899 | else if (inAtom == nsDirectoryService::sOS_CurrentProcessDirectory)
|
---|
900 | {
|
---|
901 | rv = GetSpecialSystemDirectory(OS_CurrentProcessDirectory, getter_AddRefs(localFile));
|
---|
902 | }
|
---|
903 | else if (inAtom == nsDirectoryService::sOS_CurrentWorkingDirectory)
|
---|
904 | {
|
---|
905 | rv = GetSpecialSystemDirectory(OS_CurrentWorkingDirectory, getter_AddRefs(localFile));
|
---|
906 | }
|
---|
907 |
|
---|
908 | #if defined(XP_MACOSX)
|
---|
909 | else if (inAtom == nsDirectoryService::sDirectory)
|
---|
910 | {
|
---|
911 | rv = GetOSXFolderType(kClassicDomain, kSystemFolderType, getter_AddRefs(localFile));
|
---|
912 | }
|
---|
913 | else if (inAtom == nsDirectoryService::sDesktopDirectory)
|
---|
914 | {
|
---|
915 | rv = GetOSXFolderType(kClassicDomain, kDesktopFolderType, getter_AddRefs(localFile));
|
---|
916 | }
|
---|
917 | else if (inAtom == nsDirectoryService::sTrashDirectory)
|
---|
918 | {
|
---|
919 | rv = GetOSXFolderType(kClassicDomain, kTrashFolderType, getter_AddRefs(localFile));
|
---|
920 | }
|
---|
921 | else if (inAtom == nsDirectoryService::sStartupDirectory)
|
---|
922 | {
|
---|
923 | rv = GetOSXFolderType(kClassicDomain, kStartupFolderType, getter_AddRefs(localFile));
|
---|
924 | }
|
---|
925 | else if (inAtom == nsDirectoryService::sShutdownDirectory)
|
---|
926 | {
|
---|
927 | rv = GetOSXFolderType(kClassicDomain, kShutdownFolderType, getter_AddRefs(localFile));
|
---|
928 | }
|
---|
929 | else if (inAtom == nsDirectoryService::sAppleMenuDirectory)
|
---|
930 | {
|
---|
931 | rv = GetOSXFolderType(kClassicDomain, kAppleMenuFolderType, getter_AddRefs(localFile));
|
---|
932 | }
|
---|
933 | else if (inAtom == nsDirectoryService::sControlPanelDirectory)
|
---|
934 | {
|
---|
935 | rv = GetOSXFolderType(kClassicDomain, kControlPanelFolderType, getter_AddRefs(localFile));
|
---|
936 | }
|
---|
937 | else if (inAtom == nsDirectoryService::sExtensionDirectory)
|
---|
938 | {
|
---|
939 | rv = GetOSXFolderType(kClassicDomain, kExtensionFolderType, getter_AddRefs(localFile));
|
---|
940 | }
|
---|
941 | else if (inAtom == nsDirectoryService::sFontsDirectory)
|
---|
942 | {
|
---|
943 | rv = GetOSXFolderType(kClassicDomain, kFontsFolderType, getter_AddRefs(localFile));
|
---|
944 | }
|
---|
945 | else if (inAtom == nsDirectoryService::sPreferencesDirectory)
|
---|
946 | {
|
---|
947 | rv = GetOSXFolderType(kClassicDomain, kPreferencesFolderType, getter_AddRefs(localFile));
|
---|
948 | }
|
---|
949 | else if (inAtom == nsDirectoryService::sDocumentsDirectory)
|
---|
950 | {
|
---|
951 | rv = GetOSXFolderType(kClassicDomain, kDocumentsFolderType, getter_AddRefs(localFile));
|
---|
952 | }
|
---|
953 | else if (inAtom == nsDirectoryService::sInternetSearchDirectory)
|
---|
954 | {
|
---|
955 | rv = GetOSXFolderType(kClassicDomain, kInternetSearchSitesFolderType, getter_AddRefs(localFile));
|
---|
956 | }
|
---|
957 | else if (inAtom == nsDirectoryService::sUserLibDirectory)
|
---|
958 | {
|
---|
959 | rv = GetOSXFolderType(kUserDomain, kDomainLibraryFolderType, getter_AddRefs(localFile));
|
---|
960 | }
|
---|
961 | else if (inAtom == nsDirectoryService::sHomeDirectory)
|
---|
962 | {
|
---|
963 | rv = GetOSXFolderType(kUserDomain, kDomainTopLevelFolderType, getter_AddRefs(localFile));
|
---|
964 | }
|
---|
965 | else if (inAtom == nsDirectoryService::sDefaultDownloadDirectory)
|
---|
966 | {
|
---|
967 | NS_NewLocalFile(EmptyString(), PR_TRUE, getter_AddRefs(localFile));
|
---|
968 | nsCOMPtr<nsILocalFileMac> localMacFile(do_QueryInterface(localFile));
|
---|
969 |
|
---|
970 | if (localMacFile)
|
---|
971 | {
|
---|
972 | OSErr err;
|
---|
973 | ICInstance icInstance;
|
---|
974 |
|
---|
975 | err = ::ICStart(&icInstance, 'XPCM');
|
---|
976 | if (err == noErr)
|
---|
977 | {
|
---|
978 | ICAttr attrs;
|
---|
979 | ICFileSpec icFileSpec;
|
---|
980 | long size = kICFileSpecHeaderSize;
|
---|
981 | err = ::ICGetPref(icInstance, kICDownloadFolder, &attrs, &icFileSpec, &size);
|
---|
982 | if (err == noErr || (err == icTruncatedErr && size >= kICFileSpecHeaderSize))
|
---|
983 | {
|
---|
984 | rv = localMacFile->InitWithFSSpec(&icFileSpec.fss);
|
---|
985 | }
|
---|
986 | ::ICStop(icInstance);
|
---|
987 | }
|
---|
988 |
|
---|
989 | if (NS_FAILED(rv))
|
---|
990 | {
|
---|
991 | // We got an error getting the DL folder from IC so try finding the user's Desktop folder
|
---|
992 | rv = GetOSXFolderType(kUserDomain, kDesktopFolderType, getter_AddRefs(localFile));
|
---|
993 | }
|
---|
994 | }
|
---|
995 |
|
---|
996 | // Don't cache the DL directory as the user may change it while we're running.
|
---|
997 | // Negligible perf hit as this directory is only requested for downloads
|
---|
998 | *persistent = PR_FALSE;
|
---|
999 | }
|
---|
1000 | else if (inAtom == nsDirectoryService::sUserDesktopDirectory)
|
---|
1001 | {
|
---|
1002 | rv = GetOSXFolderType(kUserDomain, kDesktopFolderType, getter_AddRefs(localFile));
|
---|
1003 | }
|
---|
1004 | else if (inAtom == nsDirectoryService::sLocalDesktopDirectory)
|
---|
1005 | {
|
---|
1006 | rv = GetOSXFolderType(kLocalDomain, kDesktopFolderType, getter_AddRefs(localFile));
|
---|
1007 | }
|
---|
1008 | else if (inAtom == nsDirectoryService::sUserApplicationsDirectory)
|
---|
1009 | {
|
---|
1010 | rv = GetOSXFolderType(kUserDomain, kApplicationsFolderType, getter_AddRefs(localFile));
|
---|
1011 | }
|
---|
1012 | else if (inAtom == nsDirectoryService::sLocalApplicationsDirectory)
|
---|
1013 | {
|
---|
1014 | rv = GetOSXFolderType(kLocalDomain, kApplicationsFolderType, getter_AddRefs(localFile));
|
---|
1015 | }
|
---|
1016 | else if (inAtom == nsDirectoryService::sUserDocumentsDirectory)
|
---|
1017 | {
|
---|
1018 | rv = GetOSXFolderType(kUserDomain, kDocumentsFolderType, getter_AddRefs(localFile));
|
---|
1019 | }
|
---|
1020 | else if (inAtom == nsDirectoryService::sLocalDocumentsDirectory)
|
---|
1021 | {
|
---|
1022 | rv = GetOSXFolderType(kLocalDomain, kDocumentsFolderType, getter_AddRefs(localFile));
|
---|
1023 | }
|
---|
1024 | else if (inAtom == nsDirectoryService::sUserInternetPlugInDirectory)
|
---|
1025 | {
|
---|
1026 | rv = GetOSXFolderType(kUserDomain, kInternetPlugInFolderType, getter_AddRefs(localFile));
|
---|
1027 | }
|
---|
1028 | else if (inAtom == nsDirectoryService::sLocalInternetPlugInDirectory)
|
---|
1029 | {
|
---|
1030 | rv = GetOSXFolderType(kLocalDomain, kInternetPlugInFolderType, getter_AddRefs(localFile));
|
---|
1031 | }
|
---|
1032 | else if (inAtom == nsDirectoryService::sUserFrameworksDirectory)
|
---|
1033 | {
|
---|
1034 | rv = GetOSXFolderType(kUserDomain, kFrameworksFolderType, getter_AddRefs(localFile));
|
---|
1035 | }
|
---|
1036 | else if (inAtom == nsDirectoryService::sLocalFrameworksDirectory)
|
---|
1037 | {
|
---|
1038 | rv = GetOSXFolderType(kLocalDomain, kFrameworksFolderType, getter_AddRefs(localFile));
|
---|
1039 | }
|
---|
1040 | else if (inAtom == nsDirectoryService::sUserPreferencesDirectory)
|
---|
1041 | {
|
---|
1042 | rv = GetOSXFolderType(kUserDomain, kPreferencesFolderType, getter_AddRefs(localFile));
|
---|
1043 | }
|
---|
1044 | else if (inAtom == nsDirectoryService::sLocalPreferencesDirectory)
|
---|
1045 | {
|
---|
1046 | rv = GetOSXFolderType(kLocalDomain, kPreferencesFolderType, getter_AddRefs(localFile));
|
---|
1047 | }
|
---|
1048 | else if (inAtom == nsDirectoryService::sPictureDocumentsDirectory)
|
---|
1049 | {
|
---|
1050 | rv = GetOSXFolderType(kUserDomain, kPictureDocumentsFolderType, getter_AddRefs(localFile));
|
---|
1051 | }
|
---|
1052 | else if (inAtom == nsDirectoryService::sMovieDocumentsDirectory)
|
---|
1053 | {
|
---|
1054 | rv = GetOSXFolderType(kUserDomain, kMovieDocumentsFolderType, getter_AddRefs(localFile));
|
---|
1055 | }
|
---|
1056 | else if (inAtom == nsDirectoryService::sMusicDocumentsDirectory)
|
---|
1057 | {
|
---|
1058 | rv = GetOSXFolderType(kUserDomain, kMusicDocumentsFolderType, getter_AddRefs(localFile));
|
---|
1059 | }
|
---|
1060 | else if (inAtom == nsDirectoryService::sInternetSitesDirectory)
|
---|
1061 | {
|
---|
1062 | rv = GetOSXFolderType(kUserDomain, kInternetSitesFolderType, getter_AddRefs(localFile));
|
---|
1063 | }
|
---|
1064 | #elif defined (XP_WIN)
|
---|
1065 | else if (inAtom == nsDirectoryService::sSystemDirectory)
|
---|
1066 | {
|
---|
1067 | rv = GetSpecialSystemDirectory(Win_SystemDirectory, getter_AddRefs(localFile));
|
---|
1068 | }
|
---|
1069 | else if (inAtom == nsDirectoryService::sWindowsDirectory)
|
---|
1070 | {
|
---|
1071 | rv = GetSpecialSystemDirectory(Win_WindowsDirectory, getter_AddRefs(localFile));
|
---|
1072 | }
|
---|
1073 | else if (inAtom == nsDirectoryService::sHomeDirectory)
|
---|
1074 | {
|
---|
1075 | rv = GetSpecialSystemDirectory(Win_HomeDirectory, getter_AddRefs(localFile));
|
---|
1076 | }
|
---|
1077 | else if (inAtom == nsDirectoryService::sDesktop)
|
---|
1078 | {
|
---|
1079 | rv = GetSpecialSystemDirectory(Win_Desktop, getter_AddRefs(localFile));
|
---|
1080 | }
|
---|
1081 | else if (inAtom == nsDirectoryService::sPrograms)
|
---|
1082 | {
|
---|
1083 | rv = GetSpecialSystemDirectory(Win_Programs, getter_AddRefs(localFile));
|
---|
1084 | }
|
---|
1085 | else if (inAtom == nsDirectoryService::sControls)
|
---|
1086 | {
|
---|
1087 | rv = GetSpecialSystemDirectory(Win_Controls, getter_AddRefs(localFile));
|
---|
1088 | }
|
---|
1089 | else if (inAtom == nsDirectoryService::sPrinters)
|
---|
1090 | {
|
---|
1091 | rv = GetSpecialSystemDirectory(Win_Printers, getter_AddRefs(localFile));
|
---|
1092 | }
|
---|
1093 | else if (inAtom == nsDirectoryService::sPersonal)
|
---|
1094 | {
|
---|
1095 | rv = GetSpecialSystemDirectory(Win_Personal, getter_AddRefs(localFile));
|
---|
1096 | }
|
---|
1097 | else if (inAtom == nsDirectoryService::sFavorites)
|
---|
1098 | {
|
---|
1099 | rv = GetSpecialSystemDirectory(Win_Favorites, getter_AddRefs(localFile));
|
---|
1100 | }
|
---|
1101 | else if (inAtom == nsDirectoryService::sStartup)
|
---|
1102 | {
|
---|
1103 | rv = GetSpecialSystemDirectory(Win_Startup, getter_AddRefs(localFile));
|
---|
1104 | }
|
---|
1105 | else if (inAtom == nsDirectoryService::sRecent)
|
---|
1106 | {
|
---|
1107 | rv = GetSpecialSystemDirectory(Win_Recent, getter_AddRefs(localFile));
|
---|
1108 | }
|
---|
1109 | else if (inAtom == nsDirectoryService::sSendto)
|
---|
1110 | {
|
---|
1111 | rv = GetSpecialSystemDirectory(Win_Sendto, getter_AddRefs(localFile));
|
---|
1112 | }
|
---|
1113 | else if (inAtom == nsDirectoryService::sBitbucket)
|
---|
1114 | {
|
---|
1115 | rv = GetSpecialSystemDirectory(Win_Bitbucket, getter_AddRefs(localFile));
|
---|
1116 | }
|
---|
1117 | else if (inAtom == nsDirectoryService::sStartmenu)
|
---|
1118 | {
|
---|
1119 | rv = GetSpecialSystemDirectory(Win_Startmenu, getter_AddRefs(localFile));
|
---|
1120 | }
|
---|
1121 | else if (inAtom == nsDirectoryService::sDesktopdirectory)
|
---|
1122 | {
|
---|
1123 | rv = GetSpecialSystemDirectory(Win_Desktopdirectory, getter_AddRefs(localFile));
|
---|
1124 | }
|
---|
1125 | else if (inAtom == nsDirectoryService::sDrives)
|
---|
1126 | {
|
---|
1127 | rv = GetSpecialSystemDirectory(Win_Drives, getter_AddRefs(localFile));
|
---|
1128 | }
|
---|
1129 | else if (inAtom == nsDirectoryService::sNetwork)
|
---|
1130 | {
|
---|
1131 | rv = GetSpecialSystemDirectory(Win_Network, getter_AddRefs(localFile));
|
---|
1132 | }
|
---|
1133 | else if (inAtom == nsDirectoryService::sNethood)
|
---|
1134 | {
|
---|
1135 | rv = GetSpecialSystemDirectory(Win_Nethood, getter_AddRefs(localFile));
|
---|
1136 | }
|
---|
1137 | else if (inAtom == nsDirectoryService::sFonts)
|
---|
1138 | {
|
---|
1139 | rv = GetSpecialSystemDirectory(Win_Fonts, getter_AddRefs(localFile));
|
---|
1140 | }
|
---|
1141 | else if (inAtom == nsDirectoryService::sTemplates)
|
---|
1142 | {
|
---|
1143 | rv = GetSpecialSystemDirectory(Win_Templates, getter_AddRefs(localFile));
|
---|
1144 | }
|
---|
1145 | else if (inAtom == nsDirectoryService::sCommon_Startmenu)
|
---|
1146 | {
|
---|
1147 | rv = GetSpecialSystemDirectory(Win_Common_Startmenu, getter_AddRefs(localFile));
|
---|
1148 | }
|
---|
1149 | else if (inAtom == nsDirectoryService::sCommon_Programs)
|
---|
1150 | {
|
---|
1151 | rv = GetSpecialSystemDirectory(Win_Common_Programs, getter_AddRefs(localFile));
|
---|
1152 | }
|
---|
1153 | else if (inAtom == nsDirectoryService::sCommon_Startup)
|
---|
1154 | {
|
---|
1155 | rv = GetSpecialSystemDirectory(Win_Common_Startup, getter_AddRefs(localFile));
|
---|
1156 | }
|
---|
1157 | else if (inAtom == nsDirectoryService::sCommon_Desktopdirectory)
|
---|
1158 | {
|
---|
1159 | rv = GetSpecialSystemDirectory(Win_Common_Desktopdirectory, getter_AddRefs(localFile));
|
---|
1160 | }
|
---|
1161 | else if (inAtom == nsDirectoryService::sAppdata)
|
---|
1162 | {
|
---|
1163 | rv = GetSpecialSystemDirectory(Win_Appdata, getter_AddRefs(localFile));
|
---|
1164 | }
|
---|
1165 | else if (inAtom == nsDirectoryService::sPrinthood)
|
---|
1166 | {
|
---|
1167 | rv = GetSpecialSystemDirectory(Win_Printhood, getter_AddRefs(localFile));
|
---|
1168 | }
|
---|
1169 | else if (inAtom == nsDirectoryService::sWinCookiesDirectory)
|
---|
1170 | {
|
---|
1171 | rv = GetSpecialSystemDirectory(Win_Cookies, getter_AddRefs(localFile));
|
---|
1172 | }
|
---|
1173 | #elif defined (XP_UNIX)
|
---|
1174 |
|
---|
1175 | else if (inAtom == nsDirectoryService::sLocalDirectory)
|
---|
1176 | {
|
---|
1177 | rv = GetSpecialSystemDirectory(Unix_LocalDirectory, getter_AddRefs(localFile));
|
---|
1178 | }
|
---|
1179 | else if (inAtom == nsDirectoryService::sLibDirectory)
|
---|
1180 | {
|
---|
1181 | rv = GetSpecialSystemDirectory(Unix_LibDirectory, getter_AddRefs(localFile));
|
---|
1182 | }
|
---|
1183 | else if (inAtom == nsDirectoryService::sHomeDirectory)
|
---|
1184 | {
|
---|
1185 | rv = GetSpecialSystemDirectory(Unix_HomeDirectory, getter_AddRefs(localFile));
|
---|
1186 | }
|
---|
1187 | #elif defined (XP_OS2)
|
---|
1188 | else if (inAtom == nsDirectoryService::sSystemDirectory)
|
---|
1189 | {
|
---|
1190 | rv = GetSpecialSystemDirectory(OS2_SystemDirectory, getter_AddRefs(localFile));
|
---|
1191 | }
|
---|
1192 | else if (inAtom == nsDirectoryService::sOS2Directory)
|
---|
1193 | {
|
---|
1194 | rv = GetSpecialSystemDirectory(OS2_OS2Directory, getter_AddRefs(localFile));
|
---|
1195 | }
|
---|
1196 | else if (inAtom == nsDirectoryService::sHomeDirectory)
|
---|
1197 | {
|
---|
1198 | rv = GetSpecialSystemDirectory(OS2_HomeDirectory, getter_AddRefs(localFile));
|
---|
1199 | }
|
---|
1200 | else if (inAtom == nsDirectoryService::sDesktopDirectory)
|
---|
1201 | {
|
---|
1202 | rv = GetSpecialSystemDirectory(OS2_DesktopDirectory, getter_AddRefs(localFile));
|
---|
1203 | }
|
---|
1204 | #elif defined (XP_BEOS)
|
---|
1205 | else if (inAtom == nsDirectoryService::sSettingsDirectory)
|
---|
1206 | {
|
---|
1207 | rv = GetSpecialSystemDirectory(BeOS_SettingsDirectory, getter_AddRefs(localFile));
|
---|
1208 | }
|
---|
1209 | else if (inAtom == nsDirectoryService::sHomeDirectory)
|
---|
1210 | {
|
---|
1211 | rv = GetSpecialSystemDirectory(BeOS_HomeDirectory, getter_AddRefs(localFile));
|
---|
1212 | }
|
---|
1213 | else if (inAtom == nsDirectoryService::sDesktopDirectory)
|
---|
1214 | {
|
---|
1215 | rv = GetSpecialSystemDirectory(BeOS_DesktopDirectory, getter_AddRefs(localFile));
|
---|
1216 | }
|
---|
1217 | else if (inAtom == nsDirectoryService::sSystemDirectory)
|
---|
1218 | {
|
---|
1219 | rv = GetSpecialSystemDirectory(BeOS_SystemDirectory, getter_AddRefs(localFile));
|
---|
1220 | }
|
---|
1221 | #endif
|
---|
1222 |
|
---|
1223 |
|
---|
1224 | NS_RELEASE(inAtom);
|
---|
1225 |
|
---|
1226 | if (localFile && NS_SUCCEEDED(rv))
|
---|
1227 | return localFile->QueryInterface(NS_GET_IID(nsIFile), (void**)_retval);
|
---|
1228 | #ifdef DEBUG_dougt
|
---|
1229 | printf("Failed to find directory for key: %s\n", prop);
|
---|
1230 | #endif
|
---|
1231 | return rv;
|
---|
1232 | }
|
---|
1233 |
|
---|
1234 | NS_IMETHODIMP
|
---|
1235 | nsDirectoryService::GetFiles(const char *prop, nsISimpleEnumerator **_retval)
|
---|
1236 | {
|
---|
1237 | NS_ENSURE_ARG_POINTER(_retval);
|
---|
1238 | *_retval = nsnull;
|
---|
1239 |
|
---|
1240 | return NS_ERROR_FAILURE;
|
---|
1241 | }
|
---|