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 Communicator client code, released
|
---|
16 | * March 31, 1998.
|
---|
17 | *
|
---|
18 | * The Initial Developer of the Original Code is
|
---|
19 | * Netscape Communications Corporation.
|
---|
20 | * Portions created by the Initial Developer are Copyright (C) 1998
|
---|
21 | * the Initial Developer. All Rights Reserved.
|
---|
22 | *
|
---|
23 | * Contributor(s):
|
---|
24 | * Doug Turner <[email protected]>
|
---|
25 | * IBM Corp.
|
---|
26 | *
|
---|
27 | * Alternatively, the contents of this file may be used under the terms of
|
---|
28 | * either of the GNU General Public License Version 2 or later (the "GPL"),
|
---|
29 | * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
---|
30 | * in which case the provisions of the GPL or the LGPL are applicable instead
|
---|
31 | * of those above. If you wish to allow use of your version of this file only
|
---|
32 | * under the terms of either the GPL or the LGPL, and not to allow others to
|
---|
33 | * use your version of this file under the terms of the MPL, indicate your
|
---|
34 | * decision by deleting the provisions above and replace them with the notice
|
---|
35 | * and other provisions required by the GPL or the LGPL. If you do not delete
|
---|
36 | * the provisions above, a recipient may use your version of this file under
|
---|
37 | * the terms of any one of the MPL, the GPL or the LGPL.
|
---|
38 | *
|
---|
39 | * ***** END LICENSE BLOCK ***** */
|
---|
40 |
|
---|
41 | #include "SpecialSystemDirectory.h"
|
---|
42 | #include "nsString.h"
|
---|
43 | #include "nsDependentString.h"
|
---|
44 |
|
---|
45 |
|
---|
46 | #ifdef XP_MAC
|
---|
47 |
|
---|
48 | #include <Folders.h>
|
---|
49 | #include <Files.h>
|
---|
50 | #include <Memory.h>
|
---|
51 | #include <Processes.h>
|
---|
52 | #include <Gestalt.h>
|
---|
53 | #include "nsIInternetConfigService.h"
|
---|
54 |
|
---|
55 |
|
---|
56 | #if UNIVERSAL_INTERFACES_VERSION < 0x0340
|
---|
57 | enum {
|
---|
58 | kSystemDomain = -32766, /* Read-only system hierarchy.*/
|
---|
59 | kLocalDomain = -32765, /* All users of a single machine have access to these resources.*/
|
---|
60 | kNetworkDomain = -32764, /* All users configured to use a common network server has access to these resources.*/
|
---|
61 | kUserDomain = -32763, /* Read/write. Resources that are private to the user.*/
|
---|
62 | kClassicDomain = -32762, /* Domain referring to the currently configured Classic System Folder*/
|
---|
63 |
|
---|
64 | kDomainLibraryFolderType = FOUR_CHAR_CODE('dlib')
|
---|
65 | };
|
---|
66 | #endif
|
---|
67 |
|
---|
68 | #elif defined(XP_WIN)
|
---|
69 |
|
---|
70 | #include <windows.h>
|
---|
71 | #include <shlobj.h>
|
---|
72 | #include <stdlib.h>
|
---|
73 | #include <stdio.h>
|
---|
74 | #include <string.h>
|
---|
75 |
|
---|
76 | #elif defined(XP_OS2)
|
---|
77 |
|
---|
78 | #define MAX_PATH _MAX_PATH
|
---|
79 | #define INCL_WINWORKPLACE
|
---|
80 | #define INCL_DOSMISC
|
---|
81 | #define INCL_DOSMODULEMGR
|
---|
82 | #define INCL_DOSPROCESS
|
---|
83 | #define INCL_WINSHELLDATA
|
---|
84 | #include <os2.h>
|
---|
85 | #include <stdlib.h>
|
---|
86 | #include <stdio.h>
|
---|
87 | #include "prenv.h"
|
---|
88 |
|
---|
89 | #elif defined(XP_UNIX)
|
---|
90 |
|
---|
91 | #include <unistd.h>
|
---|
92 | #include <stdlib.h>
|
---|
93 | #include <sys/param.h>
|
---|
94 | #include "prenv.h"
|
---|
95 | # if defined(XP_MACOSX) && defined(VBOX_WITH_NEWER_OSX_SDK)
|
---|
96 | # include <Folders.h>
|
---|
97 | # endif
|
---|
98 |
|
---|
99 | #elif defined(XP_BEOS)
|
---|
100 |
|
---|
101 | #include <FindDirectory.h>
|
---|
102 | #include <Path.h>
|
---|
103 | #include <unistd.h>
|
---|
104 | #include <stdlib.h>
|
---|
105 | #include <sys/param.h>
|
---|
106 | #include <OS.h>
|
---|
107 | #include <image.h>
|
---|
108 | #include "prenv.h"
|
---|
109 |
|
---|
110 | #endif
|
---|
111 |
|
---|
112 | #if defined(VMS)
|
---|
113 | #include <unixlib.h>
|
---|
114 | #endif
|
---|
115 |
|
---|
116 |
|
---|
117 |
|
---|
118 | #if defined (XP_WIN)
|
---|
119 | typedef BOOL (WINAPI * GetSpecialPathProc) (HWND hwndOwner, LPSTR lpszPath, int nFolder, BOOL fCreate);
|
---|
120 | GetSpecialPathProc gGetSpecialPathProc = NULL;
|
---|
121 | static HINSTANCE gShell32DLLInst = NULL;
|
---|
122 | #endif
|
---|
123 | NS_COM void StartupSpecialSystemDirectory()
|
---|
124 | {
|
---|
125 | #if defined (XP_WIN)
|
---|
126 | /* On windows, the old method to get file locations is incredibly slow.
|
---|
127 | As of this writing, 3 calls to GetWindowsFolder accounts for 3% of mozilla
|
---|
128 | startup. Replacing these older calls with a single call to SHGetSpecialFolderPath
|
---|
129 | effectively removes these calls from the performace radar. We need to
|
---|
130 | support the older way of file location lookup on systems that do not have
|
---|
131 | IE4. (Note: gets the ansi version: SHGetSpecialFolderPathA).
|
---|
132 | */
|
---|
133 | gShell32DLLInst = LoadLibrary("Shell32.dll");
|
---|
134 | if(gShell32DLLInst)
|
---|
135 | {
|
---|
136 | gGetSpecialPathProc = (GetSpecialPathProc) GetProcAddress(gShell32DLLInst,
|
---|
137 | "SHGetSpecialFolderPathA");
|
---|
138 | }
|
---|
139 | #endif
|
---|
140 | }
|
---|
141 |
|
---|
142 | NS_COM void ShutdownSpecialSystemDirectory()
|
---|
143 | {
|
---|
144 | #if defined (XP_WIN)
|
---|
145 | if (gShell32DLLInst)
|
---|
146 | {
|
---|
147 | FreeLibrary(gShell32DLLInst);
|
---|
148 | gShell32DLLInst = NULL;
|
---|
149 | gGetSpecialPathProc = NULL;
|
---|
150 | }
|
---|
151 | #endif
|
---|
152 | }
|
---|
153 |
|
---|
154 | #if defined (XP_WIN)
|
---|
155 |
|
---|
156 | //----------------------------------------------------------------------------------------
|
---|
157 | static nsresult GetWindowsFolder(int folder, nsILocalFile** aFile)
|
---|
158 | //----------------------------------------------------------------------------------------
|
---|
159 | {
|
---|
160 | if (gGetSpecialPathProc) {
|
---|
161 | TCHAR path[MAX_PATH];
|
---|
162 | HRESULT result = gGetSpecialPathProc(NULL, path, folder, true);
|
---|
163 |
|
---|
164 | if (!SUCCEEDED(result))
|
---|
165 | return NS_ERROR_FAILURE;
|
---|
166 |
|
---|
167 | // Append the trailing slash
|
---|
168 | int len = strlen(path);
|
---|
169 | if (len>1 && path[len-1] != '\\')
|
---|
170 | {
|
---|
171 | path[len] = '\\';
|
---|
172 | path[len + 1] = '\0';
|
---|
173 | }
|
---|
174 |
|
---|
175 | return NS_NewNativeLocalFile(nsDependentCString(path),
|
---|
176 | PR_TRUE,
|
---|
177 | aFile);
|
---|
178 | }
|
---|
179 |
|
---|
180 | nsresult rv = NS_ERROR_FAILURE;
|
---|
181 | LPMALLOC pMalloc = NULL;
|
---|
182 | LPSTR pBuffer = NULL;
|
---|
183 | LPITEMIDLIST pItemIDList = NULL;
|
---|
184 | int len;
|
---|
185 |
|
---|
186 | // Get the shell's allocator.
|
---|
187 | if (!SUCCEEDED(SHGetMalloc(&pMalloc)))
|
---|
188 | return NS_ERROR_FAILURE;
|
---|
189 |
|
---|
190 | // Allocate a buffer
|
---|
191 | if ((pBuffer = (LPSTR) pMalloc->Alloc(MAX_PATH + 2)) == NULL)
|
---|
192 | return NS_ERROR_FAILURE;
|
---|
193 |
|
---|
194 | // Get the PIDL for the folder.
|
---|
195 | if (!SUCCEEDED(SHGetSpecialFolderLocation(
|
---|
196 | NULL, folder, &pItemIDList)))
|
---|
197 | goto Clean;
|
---|
198 |
|
---|
199 | if (!SUCCEEDED(SHGetPathFromIDList(pItemIDList, pBuffer)))
|
---|
200 | goto Clean;
|
---|
201 |
|
---|
202 | // Append the trailing slash
|
---|
203 | len = strlen(pBuffer);
|
---|
204 | pBuffer[len] = '\\';
|
---|
205 | pBuffer[len + 1] = '\0';
|
---|
206 |
|
---|
207 | // Assign the directory
|
---|
208 | rv = NS_NewNativeLocalFile(nsDependentCString(pBuffer),
|
---|
209 | PR_TRUE,
|
---|
210 | aFile);
|
---|
211 |
|
---|
212 | Clean:
|
---|
213 | // Clean up.
|
---|
214 | if (pItemIDList)
|
---|
215 | pMalloc->Free(pItemIDList);
|
---|
216 | if (pBuffer)
|
---|
217 | pMalloc->Free(pBuffer);
|
---|
218 |
|
---|
219 | pMalloc->Release();
|
---|
220 |
|
---|
221 | return rv;
|
---|
222 | }
|
---|
223 |
|
---|
224 | #endif // XP_WIN
|
---|
225 |
|
---|
226 |
|
---|
227 |
|
---|
228 |
|
---|
229 | nsresult
|
---|
230 | GetSpecialSystemDirectory(SystemDirectories aSystemSystemDirectory,
|
---|
231 | nsILocalFile** aFile)
|
---|
232 | {
|
---|
233 | #ifdef XP_MAC
|
---|
234 | OSErr err;
|
---|
235 | short vRefNum;
|
---|
236 | long dirID;
|
---|
237 | #endif
|
---|
238 |
|
---|
239 | switch (aSystemSystemDirectory)
|
---|
240 | {
|
---|
241 | case OS_DriveDirectory:
|
---|
242 | #if defined (XP_WIN)
|
---|
243 | {
|
---|
244 | char path[_MAX_PATH];
|
---|
245 | PRInt32 len = GetWindowsDirectory( path, _MAX_PATH );
|
---|
246 | if (len)
|
---|
247 | {
|
---|
248 | if ( path[1] == ':' && path[2] == '\\' )
|
---|
249 | path[3] = 0;
|
---|
250 | }
|
---|
251 |
|
---|
252 | return NS_NewNativeLocalFile(nsDependentCString(path),
|
---|
253 | PR_TRUE,
|
---|
254 | aFile);
|
---|
255 | }
|
---|
256 | #elif defined(XP_OS2)
|
---|
257 | {
|
---|
258 | ULONG ulBootDrive = 0;
|
---|
259 | char buffer[] = " :\\OS2\\";
|
---|
260 | DosQuerySysInfo( QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
|
---|
261 | &ulBootDrive, sizeof ulBootDrive);
|
---|
262 | buffer[0] = 'A' - 1 + ulBootDrive; // duh, 1-based index...
|
---|
263 |
|
---|
264 | return NS_NewNativeLocalFile(nsDependentCString(buffer),
|
---|
265 | PR_TRUE,
|
---|
266 | aFile);
|
---|
267 | }
|
---|
268 | #elif defined(XP_MAC)
|
---|
269 | {
|
---|
270 | return nsIFileFromOSType(kVolumeRootFolderType, aFile);
|
---|
271 | }
|
---|
272 | #else
|
---|
273 | return NS_NewNativeLocalFile(nsDependentCString("/"),
|
---|
274 | PR_TRUE,
|
---|
275 | aFile);
|
---|
276 |
|
---|
277 | #endif
|
---|
278 |
|
---|
279 | case OS_TemporaryDirectory:
|
---|
280 | #if defined (XP_WIN)
|
---|
281 | {
|
---|
282 | char path[_MAX_PATH];
|
---|
283 | DWORD len = GetTempPath(_MAX_PATH, path);
|
---|
284 | return NS_NewNativeLocalFile(nsDependentCString(path),
|
---|
285 | PR_TRUE,
|
---|
286 | aFile);
|
---|
287 | }
|
---|
288 | #elif defined(XP_OS2)
|
---|
289 | {
|
---|
290 | char buffer[CCHMAXPATH] = "";
|
---|
291 | char *c = getenv( "TMP");
|
---|
292 | if( c) strcpy( buffer, c);
|
---|
293 | else
|
---|
294 | {
|
---|
295 | c = getenv( "TEMP");
|
---|
296 | if( c) strcpy( buffer, c);
|
---|
297 | }
|
---|
298 |
|
---|
299 | return NS_NewNativeLocalFile(nsDependentCString(buffer),
|
---|
300 | PR_TRUE,
|
---|
301 | aFile);
|
---|
302 | }
|
---|
303 | #elif defined(XP_MAC)
|
---|
304 | return nsIFileFromOSType(kTemporaryFolderType, aFile);
|
---|
305 |
|
---|
306 | #elif defined(XP_MACOSX)
|
---|
307 | {
|
---|
308 | return GetOSXFolderType(kUserDomain, kTemporaryFolderType, aFile);
|
---|
309 | }
|
---|
310 |
|
---|
311 | #elif defined(XP_UNIX) || defined(XP_BEOS)
|
---|
312 | {
|
---|
313 | static const char *tPath = nsnull;
|
---|
314 | if (!tPath) {
|
---|
315 | tPath = PR_GetEnv("TMPDIR");
|
---|
316 | if (!tPath || !*tPath) {
|
---|
317 | tPath = PR_GetEnv("TMP");
|
---|
318 | if (!tPath || !*tPath) {
|
---|
319 | tPath = PR_GetEnv("TEMP");
|
---|
320 | if (!tPath || !*tPath) {
|
---|
321 | tPath = "/tmp/";
|
---|
322 | }
|
---|
323 | }
|
---|
324 | }
|
---|
325 | }
|
---|
326 | return NS_NewNativeLocalFile(nsDependentCString(tPath),
|
---|
327 | PR_TRUE,
|
---|
328 | aFile);
|
---|
329 | }
|
---|
330 | #else
|
---|
331 | break;
|
---|
332 | #endif
|
---|
333 |
|
---|
334 | #if defined(XP_MAC)
|
---|
335 | case Mac_SystemDirectory:
|
---|
336 | return nsIFileFromOSType(kSystemFolderType, aFile);
|
---|
337 |
|
---|
338 | case Mac_DesktopDirectory:
|
---|
339 | return nsIFileFromOSType(kDesktopFolderType, aFile);
|
---|
340 |
|
---|
341 | case Mac_TrashDirectory:
|
---|
342 | return nsIFileFromOSType(kTrashFolderType, aFile);
|
---|
343 |
|
---|
344 | case Mac_StartupDirectory:
|
---|
345 | return nsIFileFromOSType(kStartupFolderType, aFile);
|
---|
346 |
|
---|
347 | case Mac_ShutdownDirectory:
|
---|
348 | return nsIFileFromOSType(kShutdownFolderType, aFile);
|
---|
349 |
|
---|
350 | case Mac_AppleMenuDirectory:
|
---|
351 | return nsIFileFromOSType(kAppleMenuFolderType, aFile);
|
---|
352 |
|
---|
353 | case Mac_ControlPanelDirectory:
|
---|
354 | return nsIFileFromOSType(kControlPanelFolderType, aFile);
|
---|
355 |
|
---|
356 | case Mac_ExtensionDirectory:
|
---|
357 | return nsIFileFromOSType(kExtensionFolderType, aFile);
|
---|
358 |
|
---|
359 | case Mac_FontsDirectory:
|
---|
360 | return nsIFileFromOSType(kFontsFolderType, aFile);
|
---|
361 |
|
---|
362 | case Mac_ClassicPreferencesDirectory:
|
---|
363 | {
|
---|
364 | // whether Mac OS X or pre-Mac OS X, return Classic's Prefs folder
|
---|
365 | short domain;
|
---|
366 | long response;
|
---|
367 | err = ::Gestalt(gestaltSystemVersion, &response);
|
---|
368 | domain = (!err && response >= 0x00001000) ? kClassicDomain : kOnSystemDisk;
|
---|
369 | err = ::FindFolder(domain, kPreferencesFolderType, true, &vRefNum, &dirID);
|
---|
370 | if (!err) {
|
---|
371 | err = ::FSMakeFSSpec(vRefNum, dirID, "\p", &mSpec);
|
---|
372 | }
|
---|
373 | return NS_FILE_RESULT(err);
|
---|
374 | }
|
---|
375 |
|
---|
376 | case Mac_PreferencesDirectory:
|
---|
377 | {
|
---|
378 | // if Mac OS X, return Mac OS X's Prefs folder
|
---|
379 | // if pre-Mac OS X, return Mac OS's Prefs folder
|
---|
380 | err = ::FindFolder(kOnSystemDisk, kPreferencesFolderType, true, &vRefNum, &dirID);
|
---|
381 | if (!err) {
|
---|
382 | err = ::FSMakeFSSpec(vRefNum, dirID, "\p", &mSpec);
|
---|
383 | }
|
---|
384 | return NS_FILE_RESULT(err);
|
---|
385 | }
|
---|
386 |
|
---|
387 | case Mac_DocumentsDirectory:
|
---|
388 | return nsIFileFromOSType(kDocumentsFolderType, aFile);
|
---|
389 |
|
---|
390 | case Mac_InternetSearchDirectory:
|
---|
391 | return nsIFileFromOSType(kInternetSearchSitesFolderType, aFile);
|
---|
392 |
|
---|
393 | case Mac_DefaultDownloadDirectory:
|
---|
394 | return nsIFileFromOSType(kDefaultDownloadFolderType, aFile);
|
---|
395 |
|
---|
396 | case Mac_UserLibDirectory:
|
---|
397 | {
|
---|
398 | FSSpec spec;
|
---|
399 | err = ::FindFolder(kUserDomain, kDomainLibraryFolderType, true, &vRefNum, &dirID);
|
---|
400 | if (!err) {
|
---|
401 | err = ::FSMakeFSSpec(vRefNum, dirID, "\p", &spec);
|
---|
402 | }
|
---|
403 |
|
---|
404 | return NS_NewLocalFileWithFSSpec(&spec, PR_FALUE, aFile);
|
---|
405 | }
|
---|
406 | #endif
|
---|
407 |
|
---|
408 | #if defined (XP_WIN)
|
---|
409 | case Win_SystemDirectory:
|
---|
410 | {
|
---|
411 | char path[_MAX_PATH];
|
---|
412 | PRInt32 len = GetSystemDirectory( path, _MAX_PATH );
|
---|
413 |
|
---|
414 | // Need enough space to add the trailing backslash
|
---|
415 | if (len > _MAX_PATH-2)
|
---|
416 | break;
|
---|
417 | path[len] = '\\';
|
---|
418 | path[len+1] = '\0';
|
---|
419 |
|
---|
420 | return NS_NewNativeLocalFile(nsDependentCString(path),
|
---|
421 | PR_TRUE,
|
---|
422 | aFile);
|
---|
423 | }
|
---|
424 |
|
---|
425 | case Win_WindowsDirectory:
|
---|
426 | {
|
---|
427 | char path[_MAX_PATH];
|
---|
428 | PRInt32 len = GetWindowsDirectory( path, _MAX_PATH );
|
---|
429 |
|
---|
430 | // Need enough space to add the trailing backslash
|
---|
431 | if (len > _MAX_PATH-2)
|
---|
432 | break;
|
---|
433 |
|
---|
434 | path[len] = '\\';
|
---|
435 | path[len+1] = '\0';
|
---|
436 |
|
---|
437 | return NS_NewNativeLocalFile(nsDependentCString(path),
|
---|
438 | PR_TRUE,
|
---|
439 | aFile);
|
---|
440 | }
|
---|
441 |
|
---|
442 | case Win_HomeDirectory:
|
---|
443 | {
|
---|
444 | char path[_MAX_PATH];
|
---|
445 | if (GetEnvironmentVariable(TEXT("HOME"), path, _MAX_PATH) > 0)
|
---|
446 | {
|
---|
447 | PRInt32 len = strlen(path);
|
---|
448 | // Need enough space to add the trailing backslash
|
---|
449 | if (len > _MAX_PATH - 2)
|
---|
450 | break;
|
---|
451 |
|
---|
452 | path[len] = '\\';
|
---|
453 | path[len+1] = '\0';
|
---|
454 |
|
---|
455 | return NS_NewNativeLocalFile(nsDependentCString(path),
|
---|
456 | PR_TRUE,
|
---|
457 | aFile);
|
---|
458 | }
|
---|
459 |
|
---|
460 | if (GetEnvironmentVariable(TEXT("HOMEDRIVE"), path, _MAX_PATH) > 0)
|
---|
461 | {
|
---|
462 | char temp[_MAX_PATH];
|
---|
463 | if (GetEnvironmentVariable(TEXT("HOMEPATH"), temp, _MAX_PATH) > 0)
|
---|
464 | strncat(path, temp, _MAX_PATH);
|
---|
465 |
|
---|
466 | PRInt32 len = strlen(path);
|
---|
467 |
|
---|
468 | // Need enough space to add the trailing backslash
|
---|
469 | if (len > _MAX_PATH - 2)
|
---|
470 | break;
|
---|
471 |
|
---|
472 | path[len] = '\\';
|
---|
473 | path[len+1] = '\0';
|
---|
474 |
|
---|
475 | return NS_NewNativeLocalFile(nsDependentCString(path),
|
---|
476 | PR_TRUE,
|
---|
477 | aFile);
|
---|
478 | }
|
---|
479 | }
|
---|
480 | case Win_Desktop:
|
---|
481 | {
|
---|
482 | return GetWindowsFolder(CSIDL_DESKTOP, aFile);
|
---|
483 | }
|
---|
484 | case Win_Programs:
|
---|
485 | {
|
---|
486 | return GetWindowsFolder(CSIDL_PROGRAMS, aFile);
|
---|
487 | }
|
---|
488 | case Win_Controls:
|
---|
489 | {
|
---|
490 | return GetWindowsFolder(CSIDL_CONTROLS, aFile);
|
---|
491 | }
|
---|
492 | case Win_Printers:
|
---|
493 | {
|
---|
494 | return GetWindowsFolder(CSIDL_PRINTERS, aFile);
|
---|
495 | }
|
---|
496 | case Win_Personal:
|
---|
497 | {
|
---|
498 | return GetWindowsFolder(CSIDL_PERSONAL, aFile);
|
---|
499 | }
|
---|
500 | case Win_Favorites:
|
---|
501 | {
|
---|
502 | return GetWindowsFolder(CSIDL_FAVORITES, aFile);
|
---|
503 | }
|
---|
504 | case Win_Startup:
|
---|
505 | {
|
---|
506 | return GetWindowsFolder(CSIDL_STARTUP, aFile);
|
---|
507 | }
|
---|
508 | case Win_Recent:
|
---|
509 | {
|
---|
510 | return GetWindowsFolder(CSIDL_RECENT, aFile);
|
---|
511 | }
|
---|
512 | case Win_Sendto:
|
---|
513 | {
|
---|
514 | return GetWindowsFolder(CSIDL_SENDTO, aFile);
|
---|
515 | }
|
---|
516 | case Win_Bitbucket:
|
---|
517 | {
|
---|
518 | return GetWindowsFolder(CSIDL_BITBUCKET, aFile);
|
---|
519 | }
|
---|
520 | case Win_Startmenu:
|
---|
521 | {
|
---|
522 | return GetWindowsFolder(CSIDL_STARTMENU, aFile);
|
---|
523 | }
|
---|
524 | case Win_Desktopdirectory:
|
---|
525 | {
|
---|
526 | return GetWindowsFolder(CSIDL_DESKTOPDIRECTORY, aFile);
|
---|
527 | }
|
---|
528 | case Win_Drives:
|
---|
529 | {
|
---|
530 | return GetWindowsFolder(CSIDL_DRIVES, aFile);
|
---|
531 | }
|
---|
532 | case Win_Network:
|
---|
533 | {
|
---|
534 | return GetWindowsFolder(CSIDL_NETWORK, aFile);
|
---|
535 | }
|
---|
536 | case Win_Nethood:
|
---|
537 | {
|
---|
538 | return GetWindowsFolder(CSIDL_NETHOOD, aFile);
|
---|
539 | }
|
---|
540 | case Win_Fonts:
|
---|
541 | {
|
---|
542 | return GetWindowsFolder(CSIDL_FONTS, aFile);
|
---|
543 | }
|
---|
544 | case Win_Templates:
|
---|
545 | {
|
---|
546 | return GetWindowsFolder(CSIDL_TEMPLATES, aFile);
|
---|
547 | }
|
---|
548 | case Win_Common_Startmenu:
|
---|
549 | {
|
---|
550 | return GetWindowsFolder(CSIDL_COMMON_STARTMENU, aFile);
|
---|
551 | }
|
---|
552 | case Win_Common_Programs:
|
---|
553 | {
|
---|
554 | return GetWindowsFolder(CSIDL_COMMON_PROGRAMS, aFile);
|
---|
555 | }
|
---|
556 | case Win_Common_Startup:
|
---|
557 | {
|
---|
558 | return GetWindowsFolder(CSIDL_COMMON_STARTUP, aFile);
|
---|
559 | }
|
---|
560 | case Win_Common_Desktopdirectory:
|
---|
561 | {
|
---|
562 | return GetWindowsFolder(CSIDL_COMMON_DESKTOPDIRECTORY, aFile);
|
---|
563 | }
|
---|
564 | case Win_Appdata:
|
---|
565 | {
|
---|
566 | return GetWindowsFolder(CSIDL_APPDATA, aFile);
|
---|
567 | }
|
---|
568 | case Win_Printhood:
|
---|
569 | {
|
---|
570 | return GetWindowsFolder(CSIDL_PRINTHOOD, aFile);
|
---|
571 | }
|
---|
572 | case Win_Cookies:
|
---|
573 | {
|
---|
574 | return GetWindowsFolder(CSIDL_COOKIES, aFile);
|
---|
575 | }
|
---|
576 | #endif // XP_WIN
|
---|
577 |
|
---|
578 | #if defined(XP_UNIX)
|
---|
579 | case Unix_LocalDirectory:
|
---|
580 | return NS_NewNativeLocalFile(nsDependentCString("/usr/local/netscape/"),
|
---|
581 | PR_TRUE,
|
---|
582 | aFile);
|
---|
583 | case Unix_LibDirectory:
|
---|
584 | return NS_NewNativeLocalFile(nsDependentCString("/usr/local/lib/netscape/"),
|
---|
585 | PR_TRUE,
|
---|
586 | aFile);
|
---|
587 |
|
---|
588 | case Unix_HomeDirectory:
|
---|
589 | #ifdef VMS
|
---|
590 | {
|
---|
591 | char *pHome;
|
---|
592 | pHome = getenv("HOME");
|
---|
593 | if (*pHome == '/') {
|
---|
594 | return NS_NewNativeLocalFile(nsDependentCString(pHome),
|
---|
595 | PR_TRUE,
|
---|
596 | aFile);
|
---|
597 |
|
---|
598 | }
|
---|
599 | else
|
---|
600 | {
|
---|
601 | return NS_NewNativeLocalFile(nsDependentCString(decc$translate_vms(pHome)),
|
---|
602 | PR_TRUE,
|
---|
603 | aFile);
|
---|
604 | }
|
---|
605 | }
|
---|
606 | #else
|
---|
607 | return NS_NewNativeLocalFile(nsDependentCString(PR_GetEnv("HOME")),
|
---|
608 | PR_TRUE,
|
---|
609 | aFile);
|
---|
610 |
|
---|
611 | #endif
|
---|
612 |
|
---|
613 | #endif
|
---|
614 |
|
---|
615 | #ifdef XP_BEOS
|
---|
616 | case BeOS_SettingsDirectory:
|
---|
617 | {
|
---|
618 | char path[MAXPATHLEN];
|
---|
619 | find_directory(B_USER_SETTINGS_DIRECTORY, 0, 0, path, MAXPATHLEN);
|
---|
620 | // Need enough space to add the trailing backslash
|
---|
621 | int len = strlen(path);
|
---|
622 | if (len > MAXPATHLEN-2)
|
---|
623 | break;
|
---|
624 | path[len] = '/';
|
---|
625 | path[len+1] = '\0';
|
---|
626 | return NS_NewNativeLocalFile(nsDependentCString(path),
|
---|
627 | PR_TRUE,
|
---|
628 | aFile);
|
---|
629 | }
|
---|
630 |
|
---|
631 | case BeOS_HomeDirectory:
|
---|
632 | {
|
---|
633 | char path[MAXPATHLEN];
|
---|
634 | find_directory(B_USER_DIRECTORY, 0, 0, path, MAXPATHLEN);
|
---|
635 | // Need enough space to add the trailing backslash
|
---|
636 | int len = strlen(path);
|
---|
637 | if (len > MAXPATHLEN-2)
|
---|
638 | break;
|
---|
639 | path[len] = '/';
|
---|
640 | path[len+1] = '\0';
|
---|
641 |
|
---|
642 | return NS_NewNativeLocalFile(nsDependentCString(path),
|
---|
643 | PR_TRUE,
|
---|
644 | aFile);
|
---|
645 | }
|
---|
646 |
|
---|
647 | case BeOS_DesktopDirectory:
|
---|
648 | {
|
---|
649 | char path[MAXPATHLEN];
|
---|
650 | find_directory(B_DESKTOP_DIRECTORY, 0, 0, path, MAXPATHLEN);
|
---|
651 | // Need enough space to add the trailing backslash
|
---|
652 | int len = strlen(path);
|
---|
653 | if (len > MAXPATHLEN-2)
|
---|
654 | break;
|
---|
655 | path[len] = '/';
|
---|
656 | path[len+1] = '\0';
|
---|
657 |
|
---|
658 | return NS_NewNativeLocalFile(nsDependentCString(path),
|
---|
659 | PR_TRUE,
|
---|
660 | aFile);
|
---|
661 | }
|
---|
662 |
|
---|
663 | case BeOS_SystemDirectory:
|
---|
664 | {
|
---|
665 | char path[MAXPATHLEN];
|
---|
666 | find_directory(B_BEOS_DIRECTORY, 0, 0, path, MAXPATHLEN);
|
---|
667 | // Need enough space to add the trailing backslash
|
---|
668 | int len = strlen(path);
|
---|
669 | if (len > MAXPATHLEN-2)
|
---|
670 | break;
|
---|
671 | path[len] = '/';
|
---|
672 | path[len+1] = '\0';
|
---|
673 |
|
---|
674 | return NS_NewNativeLocalFile(nsDependentCString(path),
|
---|
675 | PR_TRUE,
|
---|
676 | aFile);
|
---|
677 | }
|
---|
678 | #endif
|
---|
679 | #ifdef XP_OS2
|
---|
680 | case OS2_SystemDirectory:
|
---|
681 | {
|
---|
682 | ULONG ulBootDrive = 0;
|
---|
683 | char buffer[] = " :\\OS2\\System\\";
|
---|
684 | DosQuerySysInfo( QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
|
---|
685 | &ulBootDrive, sizeof ulBootDrive);
|
---|
686 | buffer[0] = 'A' - 1 + ulBootDrive; // duh, 1-based index...
|
---|
687 |
|
---|
688 | return NS_NewNativeLocalFile(nsDependentCString(buffer),
|
---|
689 | PR_TRUE,
|
---|
690 | aFile);
|
---|
691 | }
|
---|
692 |
|
---|
693 | case OS2_OS2Directory:
|
---|
694 | {
|
---|
695 | ULONG ulBootDrive = 0;
|
---|
696 | char buffer[] = " :\\OS2\\";
|
---|
697 | DosQuerySysInfo( QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
|
---|
698 | &ulBootDrive, sizeof ulBootDrive);
|
---|
699 | buffer[0] = 'A' - 1 + ulBootDrive; // duh, 1-based index...
|
---|
700 |
|
---|
701 | return NS_NewNativeLocalFile(nsDependentCString(buffer),
|
---|
702 | PR_TRUE,
|
---|
703 | aFile);
|
---|
704 | }
|
---|
705 |
|
---|
706 | case OS2_HomeDirectory:
|
---|
707 | {
|
---|
708 | nsresult rv;
|
---|
709 | char *tPath = PR_GetEnv("MOZILLA_HOME");
|
---|
710 | char buffer[CCHMAXPATH];
|
---|
711 | /* If MOZILLA_HOME is not set, use GetCurrentProcessDirectory */
|
---|
712 | /* To ensure we get a long filename system */
|
---|
713 | if (!tPath || !*tPath) {
|
---|
714 | PPIB ppib;
|
---|
715 | PTIB ptib;
|
---|
716 | DosGetInfoBlocks( &ptib, &ppib);
|
---|
717 | DosQueryModuleName( ppib->pib_hmte, CCHMAXPATH, buffer);
|
---|
718 | *strrchr( buffer, '\\') = '\0'; // XXX DBCS misery
|
---|
719 | tPath = buffer;
|
---|
720 | }
|
---|
721 | rv = NS_NewNativeLocalFile(nsDependentCString(tPath),
|
---|
722 | PR_TRUE,
|
---|
723 | aFile);
|
---|
724 |
|
---|
725 | PrfWriteProfileString(HINI_USERPROFILE, "Mozilla", "Home", tPath);
|
---|
726 | return rv;
|
---|
727 | }
|
---|
728 |
|
---|
729 | case OS2_DesktopDirectory:
|
---|
730 | {
|
---|
731 | char szPath[CCHMAXPATH + 1];
|
---|
732 | BOOL fSuccess;
|
---|
733 | fSuccess = WinQueryActiveDesktopPathname (szPath, sizeof(szPath));
|
---|
734 | int len = strlen (szPath);
|
---|
735 | if (len > CCHMAXPATH -1)
|
---|
736 | break;
|
---|
737 | szPath[len] = '\\';
|
---|
738 | szPath[len + 1] = '\0';
|
---|
739 |
|
---|
740 | return NS_NewNativeLocalFile(nsDependentCString(szPath),
|
---|
741 | PR_TRUE,
|
---|
742 | aFile);
|
---|
743 | }
|
---|
744 | #endif
|
---|
745 | default:
|
---|
746 | break;
|
---|
747 | }
|
---|
748 | return NS_ERROR_NOT_AVAILABLE;
|
---|
749 | }
|
---|
750 |
|
---|
751 | #if defined (XP_MACOSX)
|
---|
752 | nsresult
|
---|
753 | GetOSXFolderType(short aDomain, OSType aFolderType, nsILocalFile **localFile)
|
---|
754 | {
|
---|
755 | OSErr err;
|
---|
756 | FSRef fsRef;
|
---|
757 | nsresult rv = NS_ERROR_FAILURE;
|
---|
758 |
|
---|
759 | err = ::FSFindFolder(aDomain, aFolderType, kCreateFolder, &fsRef);
|
---|
760 | if (err == noErr)
|
---|
761 | {
|
---|
762 | NS_NewLocalFile(EmptyString(), PR_TRUE, localFile);
|
---|
763 | nsCOMPtr<nsILocalFileMac> localMacFile(do_QueryInterface(*localFile));
|
---|
764 | if (localMacFile)
|
---|
765 | rv = localMacFile->InitWithFSRef(&fsRef);
|
---|
766 | }
|
---|
767 | return rv;
|
---|
768 | }
|
---|
769 | #endif
|
---|
770 |
|
---|