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 <dougt@netscape.com>
|
---|
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 "nsSpecialSystemDirectory.h"
|
---|
42 | #include "nsDebug.h"
|
---|
43 |
|
---|
44 | #ifdef XP_MAC
|
---|
45 | #include <Folders.h>
|
---|
46 | #include <Files.h>
|
---|
47 | #include <Memory.h>
|
---|
48 | #include <Processes.h>
|
---|
49 | #include <Gestalt.h>
|
---|
50 | #include "nsIInternetConfigService.h"
|
---|
51 | #ifdef DEBUG
|
---|
52 | #include "prenv.h" // For PR_Getenv
|
---|
53 | #endif
|
---|
54 | #elif defined(XP_WIN)
|
---|
55 | #include <windows.h>
|
---|
56 | #include <shlobj.h>
|
---|
57 | #include <stdlib.h>
|
---|
58 | #include <stdio.h>
|
---|
59 | #elif defined(XP_OS2)
|
---|
60 | #define MAX_PATH _MAX_PATH
|
---|
61 | #define INCL_WINWORKPLACE
|
---|
62 | #include <os2.h>
|
---|
63 | #include <stdlib.h>
|
---|
64 | #include <stdio.h>
|
---|
65 | #include "prenv.h"
|
---|
66 | #elif defined(XP_UNIX)
|
---|
67 | #include <unistd.h>
|
---|
68 | #include <stdlib.h>
|
---|
69 | #include <sys/param.h>
|
---|
70 | #include "prenv.h"
|
---|
71 | #elif defined(XP_BEOS)
|
---|
72 | #include <FindDirectory.h>
|
---|
73 | #include <Path.h>
|
---|
74 | #include <unistd.h>
|
---|
75 | #include <stdlib.h>
|
---|
76 | #include <sys/param.h>
|
---|
77 | #include <OS.h>
|
---|
78 | #include <image.h>
|
---|
79 | #include "prenv.h"
|
---|
80 | #endif
|
---|
81 |
|
---|
82 | #if defined(VMS)
|
---|
83 | #include <unixlib.h>
|
---|
84 | #endif
|
---|
85 |
|
---|
86 | #include "plstr.h"
|
---|
87 |
|
---|
88 | #include "nsHashtable.h"
|
---|
89 | #include "prlog.h"
|
---|
90 |
|
---|
91 | #if defined (XP_MAC) && UNIVERSAL_INTERFACES_VERSION < 0x0340
|
---|
92 | enum {
|
---|
93 | kSystemDomain = -32766, /* Read-only system hierarchy.*/
|
---|
94 | kLocalDomain = -32765, /* All users of a single machine have access to these resources.*/
|
---|
95 | kNetworkDomain = -32764, /* All users configured to use a common network server has access to these resources.*/
|
---|
96 | kUserDomain = -32763, /* Read/write. Resources that are private to the user.*/
|
---|
97 | kClassicDomain = -32762, /* Domain referring to the currently configured Classic System Folder*/
|
---|
98 |
|
---|
99 | kDomainLibraryFolderType = FOUR_CHAR_CODE('dlib')
|
---|
100 | };
|
---|
101 | #endif
|
---|
102 |
|
---|
103 |
|
---|
104 | class SystemDirectoriesKey : public nsHashKey {
|
---|
105 | public:
|
---|
106 |
|
---|
107 | SystemDirectoriesKey(nsSpecialSystemDirectory::SystemDirectories newKey) : sdKey(newKey) {}
|
---|
108 |
|
---|
109 | virtual PRUint32 HashCode(void) const
|
---|
110 | {
|
---|
111 | return PRUint32(sdKey);
|
---|
112 | }
|
---|
113 |
|
---|
114 | virtual PRBool Equals(const nsHashKey *aKey) const
|
---|
115 | {
|
---|
116 | nsSpecialSystemDirectory::SystemDirectories other =
|
---|
117 | ((SystemDirectoriesKey*)aKey)->sdKey;
|
---|
118 | return other == sdKey;
|
---|
119 | }
|
---|
120 |
|
---|
121 | virtual nsHashKey *Clone(void) const
|
---|
122 | {
|
---|
123 | return new SystemDirectoriesKey(sdKey);
|
---|
124 | }
|
---|
125 |
|
---|
126 | private:
|
---|
127 | nsSpecialSystemDirectory::SystemDirectories sdKey; // sd for SystemDirectories
|
---|
128 | };
|
---|
129 |
|
---|
130 | PR_STATIC_CALLBACK(PRBool) DeleteSystemDirKeys(nsHashKey *aKey, void *aData, void* closure)
|
---|
131 | {
|
---|
132 | delete ((nsFileSpec *)aData);
|
---|
133 | return PR_TRUE;
|
---|
134 | }
|
---|
135 |
|
---|
136 | #define NS_SYSTEMDIR_HASH_NUM (10)
|
---|
137 | static nsHashtable *systemDirectoriesLocations = NULL;
|
---|
138 | #if defined (XP_WIN)
|
---|
139 | typedef BOOL (WINAPI * GetSpecialPathProc) (HWND hwndOwner, LPSTR lpszPath, int nFolder, BOOL fCreate);
|
---|
140 | GetSpecialPathProc gGetSpecialPathProc = NULL;
|
---|
141 | static HINSTANCE gShell32DLLInst = NULL;
|
---|
142 | #endif
|
---|
143 | NS_COM_OBSOLETE void StartupSpecialSystemDirectory()
|
---|
144 | {
|
---|
145 | #if defined (XP_WIN)
|
---|
146 | /* On windows, the old method to get file locations is incredibly slow.
|
---|
147 | As of this writing, 3 calls to GetWindowsFolder accounts for 3% of mozilla
|
---|
148 | startup. Replacing these older calls with a single call to SHGetSpecialFolderPath
|
---|
149 | effectively removes these calls from the performace radar. We need to
|
---|
150 | support the older way of file location lookup on systems that do not have
|
---|
151 | IE4. (Note: gets the ansi version: SHGetSpecialFolderPathA).
|
---|
152 | */
|
---|
153 | gShell32DLLInst = LoadLibrary("Shell32.dll");
|
---|
154 | if(gShell32DLLInst)
|
---|
155 | {
|
---|
156 | gGetSpecialPathProc = (GetSpecialPathProc) GetProcAddress(gShell32DLLInst,
|
---|
157 | "SHGetSpecialFolderPathA");
|
---|
158 | }
|
---|
159 | #endif
|
---|
160 | }
|
---|
161 |
|
---|
162 | NS_COM_OBSOLETE void ShutdownSpecialSystemDirectory()
|
---|
163 | {
|
---|
164 | if (systemDirectoriesLocations)
|
---|
165 | {
|
---|
166 | systemDirectoriesLocations->Reset(DeleteSystemDirKeys);
|
---|
167 | delete systemDirectoriesLocations;
|
---|
168 | }
|
---|
169 | #if defined (XP_WIN)
|
---|
170 | if (gShell32DLLInst)
|
---|
171 | {
|
---|
172 | FreeLibrary(gShell32DLLInst);
|
---|
173 | gShell32DLLInst = NULL;
|
---|
174 | gGetSpecialPathProc = NULL;
|
---|
175 | }
|
---|
176 | #endif
|
---|
177 | }
|
---|
178 |
|
---|
179 | #if defined (XP_WIN)
|
---|
180 |
|
---|
181 | static PRBool gGlobalOSInitialized = PR_FALSE;
|
---|
182 | static PRBool gGlobalDBCSEnabledOS = PR_FALSE;
|
---|
183 |
|
---|
184 | //----------------------------------------------------------------------------------------
|
---|
185 | static char* MakeUpperCase(char* aPath)
|
---|
186 | //----------------------------------------------------------------------------------------
|
---|
187 | {
|
---|
188 | // check if the Windows is DBCSEnabled once.
|
---|
189 | if (PR_FALSE == gGlobalOSInitialized) {
|
---|
190 | if (GetSystemMetrics(SM_DBCSENABLED))
|
---|
191 | gGlobalDBCSEnabledOS = PR_TRUE;
|
---|
192 | gGlobalOSInitialized = PR_TRUE;
|
---|
193 | }
|
---|
194 |
|
---|
195 | // windows does not care about case. pu sh to uppercase:
|
---|
196 | int length = strlen(aPath);
|
---|
197 | int i = 0; /* C++ portability guide #20 */
|
---|
198 | if (!gGlobalDBCSEnabledOS) {
|
---|
199 | // for non-DBCS windows
|
---|
200 | for (i = 0; i < length; i++)
|
---|
201 | if (islower(aPath[i]))
|
---|
202 | aPath[i] = _toupper(aPath[i]);
|
---|
203 | }
|
---|
204 | else {
|
---|
205 | // for DBCS windows
|
---|
206 | for (i = 0; i < length; i++) {
|
---|
207 | if (IsDBCSLeadByte(aPath[i])) {
|
---|
208 | // begining of the double bye char
|
---|
209 | i++;
|
---|
210 | }
|
---|
211 | else {
|
---|
212 | if ( islower(aPath[i]))
|
---|
213 | aPath[i] = _toupper(aPath[i]);
|
---|
214 | }
|
---|
215 | } //end of for loop
|
---|
216 | }
|
---|
217 | return aPath;
|
---|
218 | }
|
---|
219 |
|
---|
220 | //----------------------------------------------------------------------------------------
|
---|
221 | static void GetWindowsFolder(int folder, nsFileSpec& outDirectory)
|
---|
222 | //----------------------------------------------------------------------------------------
|
---|
223 | {
|
---|
224 |
|
---|
225 | if (gGetSpecialPathProc) {
|
---|
226 | TCHAR path[MAX_PATH];
|
---|
227 | HRESULT result = gGetSpecialPathProc(NULL, path, folder, true);
|
---|
228 |
|
---|
229 | if (!SUCCEEDED(result))
|
---|
230 | return;
|
---|
231 |
|
---|
232 | // Append the trailing slash
|
---|
233 | int len = PL_strlen(path);
|
---|
234 | if (len>1 && path[len-1] != '\\')
|
---|
235 | {
|
---|
236 | path[len] = '\\';
|
---|
237 | path[len + 1] = '\0';
|
---|
238 | }
|
---|
239 | outDirectory = path;
|
---|
240 | return;
|
---|
241 | }
|
---|
242 |
|
---|
243 | LPMALLOC pMalloc = NULL;
|
---|
244 | LPSTR pBuffer = NULL;
|
---|
245 | LPITEMIDLIST pItemIDList = NULL;
|
---|
246 | int len;
|
---|
247 |
|
---|
248 | // Get the shell's allocator.
|
---|
249 | if (!SUCCEEDED(SHGetMalloc(&pMalloc)))
|
---|
250 | return;
|
---|
251 |
|
---|
252 | // Allocate a buffer
|
---|
253 | if ((pBuffer = (LPSTR) pMalloc->Alloc(MAX_PATH + 2)) == NULL)
|
---|
254 | return;
|
---|
255 |
|
---|
256 | // Get the PIDL for the folder.
|
---|
257 | if (!SUCCEEDED(SHGetSpecialFolderLocation(
|
---|
258 | NULL, folder, &pItemIDList)))
|
---|
259 | goto Clean;
|
---|
260 |
|
---|
261 | if (!SUCCEEDED(SHGetPathFromIDList(pItemIDList, pBuffer)))
|
---|
262 | goto Clean;
|
---|
263 |
|
---|
264 | // Append the trailing slash
|
---|
265 | len = PL_strlen(pBuffer);
|
---|
266 | pBuffer[len] = '\\';
|
---|
267 | pBuffer[len + 1] = '\0';
|
---|
268 |
|
---|
269 | // Assign the directory
|
---|
270 | outDirectory = pBuffer;
|
---|
271 |
|
---|
272 | Clean:
|
---|
273 | // Clean up.
|
---|
274 | if (pItemIDList)
|
---|
275 | pMalloc->Free(pItemIDList);
|
---|
276 | if (pBuffer)
|
---|
277 | pMalloc->Free(pBuffer);
|
---|
278 |
|
---|
279 | pMalloc->Release();
|
---|
280 | } // GetWindowsFolder
|
---|
281 | #endif // XP_WIN
|
---|
282 |
|
---|
283 | //----------------------------------------------------------------------------------------
|
---|
284 | static void GetCurrentWorkingDirectory(nsFileSpec& aFileSpec)
|
---|
285 | //----------------------------------------------------------------------------------------
|
---|
286 | {
|
---|
287 | aFileSpec = ".";
|
---|
288 | return;
|
---|
289 | } // GetCurrentWorkingDirectory
|
---|
290 |
|
---|
291 | //----------------------------------------------------------------------------------------
|
---|
292 | static void GetCurrentProcessDirectory(nsFileSpec& aFileSpec)
|
---|
293 | //----------------------------------------------------------------------------------------
|
---|
294 | {
|
---|
295 | #if defined (XP_WIN)
|
---|
296 | char buf[MAX_PATH];
|
---|
297 | if ( ::GetModuleFileName(0, buf, sizeof(buf)) ) {
|
---|
298 | // chop of the executable name by finding the rightmost backslash
|
---|
299 | char* lastSlash = PL_strrchr(buf, '\\');
|
---|
300 | if (lastSlash)
|
---|
301 | *(lastSlash + 1) = '\0';
|
---|
302 |
|
---|
303 | aFileSpec = buf;
|
---|
304 | return;
|
---|
305 | }
|
---|
306 |
|
---|
307 | #elif defined(XP_OS2)
|
---|
308 | PPIB ppib;
|
---|
309 | PTIB ptib;
|
---|
310 | char buffer[CCHMAXPATH];
|
---|
311 | DosGetInfoBlocks( &ptib, &ppib);
|
---|
312 | DosQueryModuleName( ppib->pib_hmte, CCHMAXPATH, buffer);
|
---|
313 | *strrchr( buffer, '\\') = '\0'; // XXX DBCS misery
|
---|
314 | aFileSpec = buffer;
|
---|
315 | return;
|
---|
316 |
|
---|
317 |
|
---|
318 | #elif defined(XP_MAC)
|
---|
319 | // get info for the the current process to determine the directory
|
---|
320 | // its located in
|
---|
321 | OSErr err;
|
---|
322 | ProcessSerialNumber psn = {kNoProcess, kCurrentProcess};
|
---|
323 | ProcessInfoRec pInfo;
|
---|
324 | FSSpec tempSpec;
|
---|
325 |
|
---|
326 | // initialize ProcessInfoRec before calling
|
---|
327 | // GetProcessInformation() or die horribly.
|
---|
328 | pInfo.processName = nil;
|
---|
329 | pInfo.processAppSpec = &tempSpec;
|
---|
330 | pInfo.processInfoLength = sizeof(ProcessInfoRec);
|
---|
331 |
|
---|
332 | if (!(err = GetProcessInformation(&psn, &pInfo)))
|
---|
333 | {
|
---|
334 | FSSpec appFSSpec = *(pInfo.processAppSpec);
|
---|
335 | long theDirID = appFSSpec.parID;
|
---|
336 |
|
---|
337 | Str255 name;
|
---|
338 | CInfoPBRec catInfo;
|
---|
339 | catInfo.dirInfo.ioCompletion = NULL;
|
---|
340 | catInfo.dirInfo.ioNamePtr = (StringPtr)&name;
|
---|
341 | catInfo.dirInfo.ioVRefNum = appFSSpec.vRefNum;
|
---|
342 | catInfo.dirInfo.ioDrDirID = theDirID;
|
---|
343 | catInfo.dirInfo.ioFDirIndex = -1; // -1 = query dir in ioDrDirID
|
---|
344 |
|
---|
345 | if (!(err = PBGetCatInfoSync(&catInfo)))
|
---|
346 | {
|
---|
347 | aFileSpec = nsFileSpec(appFSSpec.vRefNum,
|
---|
348 | catInfo.dirInfo.ioDrParID,
|
---|
349 | name,
|
---|
350 | PR_TRUE);
|
---|
351 | return;
|
---|
352 | }
|
---|
353 | }
|
---|
354 | #if defined(DEBUG)
|
---|
355 | else
|
---|
356 | {
|
---|
357 | // In the absence of a good way to get the executable directory let
|
---|
358 | // us try this for unix:
|
---|
359 | // - if VBOX_XPCOM_HOME is defined, that is it
|
---|
360 | char *moz5 = PR_GetEnv("VBOX_XPCOM_HOME");
|
---|
361 | if (moz5)
|
---|
362 | {
|
---|
363 | printf( "nsSpecialSystemDirectory::VBOX_XPCOM_HOME is set to %s\n", moz5 );
|
---|
364 | aFileSpec = moz5;
|
---|
365 | return;
|
---|
366 | }
|
---|
367 | else
|
---|
368 | {
|
---|
369 | static PRBool firstWarning = PR_TRUE;
|
---|
370 |
|
---|
371 | if(firstWarning) {
|
---|
372 | // Warn that VBOX_XPCOM_HOME not set, once.
|
---|
373 | printf("***Warning: VBOX_XPCOM_HOME not set.\n");
|
---|
374 | firstWarning = PR_FALSE;
|
---|
375 | }
|
---|
376 | }
|
---|
377 | }
|
---|
378 | #endif /* DEBUG */
|
---|
379 |
|
---|
380 | #elif defined(XP_UNIX)
|
---|
381 |
|
---|
382 | // In the absence of a good way to get the executable directory let
|
---|
383 | // us try this for unix:
|
---|
384 | // - if VBOX_XPCOM_HOME is defined, that is it
|
---|
385 | // - else give the current directory
|
---|
386 | char buf[MAXPATHLEN];
|
---|
387 | char *moz5 = PR_GetEnv("VBOX_XPCOM_HOME");
|
---|
388 | if (moz5)
|
---|
389 | {
|
---|
390 | aFileSpec = moz5;
|
---|
391 | return;
|
---|
392 | }
|
---|
393 | else
|
---|
394 | {
|
---|
395 | #if defined(DEBUG)
|
---|
396 | static PRBool firstWarning = PR_TRUE;
|
---|
397 |
|
---|
398 | if(firstWarning) {
|
---|
399 | // Warn that VBOX_XPCOM_HOME not set, once.
|
---|
400 | printf("Warning: VBOX_XPCOM_HOME not set.\n");
|
---|
401 | firstWarning = PR_FALSE;
|
---|
402 | }
|
---|
403 | #endif /* DEBUG */
|
---|
404 |
|
---|
405 | // Fall back to current directory.
|
---|
406 | if (getcwd(buf, sizeof(buf)))
|
---|
407 | {
|
---|
408 | aFileSpec = buf;
|
---|
409 | return;
|
---|
410 | }
|
---|
411 | }
|
---|
412 |
|
---|
413 | #elif defined(XP_BEOS)
|
---|
414 |
|
---|
415 | char *moz5 = getenv("VBOX_XPCOM_HOME");
|
---|
416 | if (moz5)
|
---|
417 | {
|
---|
418 | aFileSpec = moz5;
|
---|
419 | return;
|
---|
420 | }
|
---|
421 | else
|
---|
422 | {
|
---|
423 | static char buf[MAXPATHLEN];
|
---|
424 | int32 cookie = 0;
|
---|
425 | image_info info;
|
---|
426 | char *p;
|
---|
427 | *buf = 0;
|
---|
428 | if(get_next_image_info(0, &cookie, &info) == B_OK)
|
---|
429 | {
|
---|
430 | strcpy(buf, info.name);
|
---|
431 | if((p = strrchr(buf, '/')) != 0)
|
---|
432 | {
|
---|
433 | *p = 0;
|
---|
434 | aFileSpec = buf;
|
---|
435 | return;
|
---|
436 | }
|
---|
437 | }
|
---|
438 | }
|
---|
439 |
|
---|
440 | #endif
|
---|
441 |
|
---|
442 | NS_ERROR("unable to get current process directory");
|
---|
443 | } // GetCurrentProcessDirectory()
|
---|
444 |
|
---|
445 | //nsSpecialSystemDirectory::nsSpecialSystemDirectory()
|
---|
446 | //: nsFileSpec(nsnull)
|
---|
447 | //{
|
---|
448 | //}
|
---|
449 |
|
---|
450 | //----------------------------------------------------------------------------------------
|
---|
451 | nsSpecialSystemDirectory::nsSpecialSystemDirectory(SystemDirectories aSystemSystemDirectory)
|
---|
452 | //----------------------------------------------------------------------------------------
|
---|
453 | : nsFileSpec(nsnull)
|
---|
454 | {
|
---|
455 | *this = aSystemSystemDirectory;
|
---|
456 | }
|
---|
457 |
|
---|
458 | //----------------------------------------------------------------------------------------
|
---|
459 | nsSpecialSystemDirectory::~nsSpecialSystemDirectory()
|
---|
460 | //----------------------------------------------------------------------------------------
|
---|
461 | {
|
---|
462 | }
|
---|
463 |
|
---|
464 | //----------------------------------------------------------------------------------------
|
---|
465 | void nsSpecialSystemDirectory::operator = (SystemDirectories aSystemSystemDirectory)
|
---|
466 | //----------------------------------------------------------------------------------------
|
---|
467 | {
|
---|
468 | SystemDirectoriesKey dirKey(aSystemSystemDirectory);
|
---|
469 | SystemDirectoriesKey mozBinDirKey(Moz_BinDirectory);
|
---|
470 |
|
---|
471 | // This flag is used to tell whether or not we need to append something
|
---|
472 | // onto the *this. Search for needToAppend to how it's used.
|
---|
473 | // IT's VERY IMPORTANT that needToAppend is initialized to PR_TRUE.
|
---|
474 | PRBool needToAppend = PR_TRUE;
|
---|
475 |
|
---|
476 | #ifdef XP_MAC
|
---|
477 | OSErr err;
|
---|
478 | short vRefNum;
|
---|
479 | long dirID;
|
---|
480 | #endif
|
---|
481 |
|
---|
482 | *this = (const char*)nsnull;
|
---|
483 | switch (aSystemSystemDirectory)
|
---|
484 | {
|
---|
485 |
|
---|
486 | case OS_DriveDirectory:
|
---|
487 | #if defined (XP_WIN)
|
---|
488 | {
|
---|
489 | char path[_MAX_PATH];
|
---|
490 | PRInt32 len = GetWindowsDirectory( path, _MAX_PATH );
|
---|
491 | if (len)
|
---|
492 | {
|
---|
493 | if ( path[1] == ':' && path[2] == '\\' )
|
---|
494 | path[3] = 0;
|
---|
495 | }
|
---|
496 | *this = MakeUpperCase(path);
|
---|
497 | }
|
---|
498 | #elif defined(XP_OS2)
|
---|
499 | {
|
---|
500 | // printf( "*** Warning warning OS_DriveDirectory called for");
|
---|
501 |
|
---|
502 | ULONG ulBootDrive = 0;
|
---|
503 | char buffer[] = " :\\OS2\\";
|
---|
504 | DosQuerySysInfo( QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
|
---|
505 | &ulBootDrive, sizeof ulBootDrive);
|
---|
506 | buffer[0] = 'A' - 1 + ulBootDrive; // duh, 1-based index...
|
---|
507 | *this = buffer;
|
---|
508 | #ifdef DEBUG
|
---|
509 | printf( "Got OS_DriveDirectory: %s\n", buffer);
|
---|
510 | #endif
|
---|
511 | }
|
---|
512 | #elif defined(XP_MAC)
|
---|
513 | {
|
---|
514 | *this = kVolumeRootFolderType;
|
---|
515 | }
|
---|
516 | #else
|
---|
517 | *this = "/";
|
---|
518 | #endif
|
---|
519 | break;
|
---|
520 |
|
---|
521 |
|
---|
522 | case OS_TemporaryDirectory:
|
---|
523 | #if defined (XP_WIN)
|
---|
524 | {
|
---|
525 | char path[_MAX_PATH];
|
---|
526 | DWORD len = GetTempPath(_MAX_PATH, path);
|
---|
527 | *this = MakeUpperCase(path);
|
---|
528 | }
|
---|
529 | #elif defined(XP_OS2)
|
---|
530 | {
|
---|
531 | char buffer[CCHMAXPATH] = "";
|
---|
532 | char *c = getenv( "TMP");
|
---|
533 | if( c) strcpy( buffer, c);
|
---|
534 | else
|
---|
535 | {
|
---|
536 | c = getenv( "TEMP");
|
---|
537 | if( c) strcpy( buffer, c);
|
---|
538 | }
|
---|
539 | if( c) *this = buffer;
|
---|
540 | // use exe's directory if not set
|
---|
541 | else GetCurrentProcessDirectory(*this);
|
---|
542 | }
|
---|
543 | #elif defined(XP_MAC)
|
---|
544 | *this = kTemporaryFolderType;
|
---|
545 |
|
---|
546 | #elif defined(XP_UNIX) || defined(XP_BEOS)
|
---|
547 | {
|
---|
548 | static const char *tPath = nsnull;
|
---|
549 | if (!tPath) {
|
---|
550 | tPath = PR_GetEnv("TMPDIR");
|
---|
551 | if (!tPath || !*tPath) {
|
---|
552 | tPath = PR_GetEnv("TMP");
|
---|
553 | if (!tPath || !*tPath) {
|
---|
554 | tPath = PR_GetEnv("TEMP");
|
---|
555 | if (!tPath || !*tPath) {
|
---|
556 | tPath = "/tmp/";
|
---|
557 | }
|
---|
558 | }
|
---|
559 | }
|
---|
560 | }
|
---|
561 |
|
---|
562 | *this = tPath;
|
---|
563 | }
|
---|
564 | #endif
|
---|
565 | break;
|
---|
566 |
|
---|
567 | case OS_CurrentProcessDirectory:
|
---|
568 | GetCurrentProcessDirectory(*this);
|
---|
569 | break;
|
---|
570 |
|
---|
571 | case OS_CurrentWorkingDirectory:
|
---|
572 | GetCurrentWorkingDirectory(*this);
|
---|
573 | break;
|
---|
574 |
|
---|
575 | case XPCOM_CurrentProcessComponentRegistry:
|
---|
576 | {
|
---|
577 | nsFileSpec *dirSpec = NULL;
|
---|
578 |
|
---|
579 | // if someone has called nsSpecialSystemDirectory::Set()
|
---|
580 | if (systemDirectoriesLocations) {
|
---|
581 | // look for the value for the argument key
|
---|
582 | if (!(dirSpec = (nsFileSpec *)systemDirectoriesLocations->Get(&dirKey))) {
|
---|
583 | // if not found, try Moz_BinDirectory
|
---|
584 | dirSpec = (nsFileSpec *)
|
---|
585 | systemDirectoriesLocations->Get(&mozBinDirKey);
|
---|
586 | }
|
---|
587 | else {
|
---|
588 | // if the value is found for the argument key,
|
---|
589 | // we don't need to append.
|
---|
590 | needToAppend = PR_FALSE;
|
---|
591 | }
|
---|
592 | }
|
---|
593 |
|
---|
594 | if (dirSpec)
|
---|
595 | {
|
---|
596 | *this = *dirSpec;
|
---|
597 | }
|
---|
598 | else
|
---|
599 | {
|
---|
600 | GetCurrentProcessDirectory(*this);
|
---|
601 | }
|
---|
602 |
|
---|
603 | if (needToAppend) {
|
---|
604 | // XXX We need to unify these names across all platforms
|
---|
605 | #if defined(XP_MAC)
|
---|
606 | *this += "Component Registry";
|
---|
607 | #else
|
---|
608 | *this += "component.reg";
|
---|
609 | #endif /* XP_MAC */
|
---|
610 | }
|
---|
611 | }
|
---|
612 | break;
|
---|
613 |
|
---|
614 | case XPCOM_CurrentProcessComponentDirectory:
|
---|
615 | {
|
---|
616 | nsFileSpec *dirSpec = NULL;
|
---|
617 | // if someone has called nsSpecialSystemDirectory::Set()
|
---|
618 | if (systemDirectoriesLocations) {
|
---|
619 | // look for the value for the argument key
|
---|
620 | if (!(dirSpec = (nsFileSpec *)systemDirectoriesLocations->Get(&dirKey))) {
|
---|
621 | // if not found, try Moz_BinDirectory
|
---|
622 | dirSpec = (nsFileSpec *)
|
---|
623 | systemDirectoriesLocations->Get(&mozBinDirKey);
|
---|
624 | }
|
---|
625 | else {
|
---|
626 | // if the value is found for the argument key,
|
---|
627 | // we don't need to append.
|
---|
628 | needToAppend = PR_FALSE;
|
---|
629 | }
|
---|
630 | }
|
---|
631 | if (dirSpec)
|
---|
632 | {
|
---|
633 | *this = *dirSpec;
|
---|
634 | }
|
---|
635 | else
|
---|
636 | {
|
---|
637 | // <exedir>/Components
|
---|
638 | GetCurrentProcessDirectory(*this);
|
---|
639 | }
|
---|
640 |
|
---|
641 | if (needToAppend) {
|
---|
642 | // XXX We need to unify these names across all platforms
|
---|
643 | #if defined(XP_MAC)
|
---|
644 | *this += "Components";
|
---|
645 | #else
|
---|
646 | *this += "components";
|
---|
647 | #endif /* XP_MAC */
|
---|
648 | }
|
---|
649 | }
|
---|
650 | break;
|
---|
651 |
|
---|
652 | case Moz_BinDirectory:
|
---|
653 | {
|
---|
654 | nsFileSpec *dirSpec = NULL;
|
---|
655 | // if someone has called nsSpecialSystemDirectory::Set()
|
---|
656 | if (systemDirectoriesLocations) {
|
---|
657 | // look for the value for the argument key
|
---|
658 | dirSpec = (nsFileSpec *)
|
---|
659 | systemDirectoriesLocations->Get(&dirKey);
|
---|
660 | }
|
---|
661 | if (dirSpec) {
|
---|
662 | *this = *dirSpec;
|
---|
663 | }
|
---|
664 | else {
|
---|
665 | GetCurrentProcessDirectory(*this);
|
---|
666 | }
|
---|
667 | }
|
---|
668 | break;
|
---|
669 |
|
---|
670 | #if defined(XP_MAC)
|
---|
671 | case Mac_SystemDirectory:
|
---|
672 | *this = kSystemFolderType;
|
---|
673 | break;
|
---|
674 |
|
---|
675 | case Mac_DesktopDirectory:
|
---|
676 | *this = kDesktopFolderType;
|
---|
677 | break;
|
---|
678 |
|
---|
679 | case Mac_TrashDirectory:
|
---|
680 | *this = kTrashFolderType;
|
---|
681 | break;
|
---|
682 |
|
---|
683 | case Mac_StartupDirectory:
|
---|
684 | *this = kStartupFolderType;
|
---|
685 | break;
|
---|
686 |
|
---|
687 | case Mac_ShutdownDirectory:
|
---|
688 | *this = kShutdownFolderType;
|
---|
689 | break;
|
---|
690 |
|
---|
691 | case Mac_AppleMenuDirectory:
|
---|
692 | *this = kAppleMenuFolderType;
|
---|
693 | break;
|
---|
694 |
|
---|
695 | case Mac_ControlPanelDirectory:
|
---|
696 | *this = kControlPanelFolderType;
|
---|
697 | break;
|
---|
698 |
|
---|
699 | case Mac_ExtensionDirectory:
|
---|
700 | *this = kExtensionFolderType;
|
---|
701 | break;
|
---|
702 |
|
---|
703 | case Mac_FontsDirectory:
|
---|
704 | *this = kFontsFolderType;
|
---|
705 | break;
|
---|
706 |
|
---|
707 | case Mac_ClassicPreferencesDirectory:
|
---|
708 | {
|
---|
709 | // whether Mac OS X or pre-Mac OS X, return Classic's Prefs folder
|
---|
710 | short domain;
|
---|
711 | long response;
|
---|
712 | err = ::Gestalt(gestaltSystemVersion, &response);
|
---|
713 | domain = (!err && response >= 0x00001000) ? kClassicDomain : kOnSystemDisk;
|
---|
714 | err = ::FindFolder(domain, kPreferencesFolderType, true, &vRefNum, &dirID);
|
---|
715 | if (!err) {
|
---|
716 | err = ::FSMakeFSSpec(vRefNum, dirID, "\p", &mSpec);
|
---|
717 | }
|
---|
718 | mError = NS_FILE_RESULT(err);
|
---|
719 | break;
|
---|
720 | }
|
---|
721 |
|
---|
722 | case Mac_PreferencesDirectory:
|
---|
723 | {
|
---|
724 | // if Mac OS X, return Mac OS X's Prefs folder
|
---|
725 | // if pre-Mac OS X, return Mac OS's Prefs folder
|
---|
726 | err = ::FindFolder(kOnSystemDisk, kPreferencesFolderType, true, &vRefNum, &dirID);
|
---|
727 | if (!err) {
|
---|
728 | err = ::FSMakeFSSpec(vRefNum, dirID, "\p", &mSpec);
|
---|
729 | }
|
---|
730 | mError = NS_FILE_RESULT(err);
|
---|
731 | break;
|
---|
732 | }
|
---|
733 |
|
---|
734 | case Mac_DocumentsDirectory:
|
---|
735 | *this = kDocumentsFolderType;
|
---|
736 | break;
|
---|
737 |
|
---|
738 | case Mac_InternetSearchDirectory:
|
---|
739 | *this = kInternetSearchSitesFolderType;
|
---|
740 | break;
|
---|
741 |
|
---|
742 | case Mac_DefaultDownloadDirectory:
|
---|
743 | *this = kDefaultDownloadFolderType;
|
---|
744 | break;
|
---|
745 |
|
---|
746 | case Mac_UserLibDirectory:
|
---|
747 | {
|
---|
748 | err = ::FindFolder(kUserDomain, kDomainLibraryFolderType, true, &vRefNum, &dirID);
|
---|
749 | if (!err) {
|
---|
750 | err = ::FSMakeFSSpec(vRefNum, dirID, "\p", &mSpec);
|
---|
751 | }
|
---|
752 | mError = NS_FILE_RESULT(err);
|
---|
753 | break;
|
---|
754 | }
|
---|
755 | #endif
|
---|
756 |
|
---|
757 | #if defined (XP_WIN)
|
---|
758 | case Win_SystemDirectory:
|
---|
759 | {
|
---|
760 | char path[_MAX_PATH];
|
---|
761 | PRInt32 len = GetSystemDirectory( path, _MAX_PATH );
|
---|
762 |
|
---|
763 | // Need enough space to add the trailing backslash
|
---|
764 | if (len > _MAX_PATH-2)
|
---|
765 | break;
|
---|
766 | path[len] = '\\';
|
---|
767 | path[len+1] = '\0';
|
---|
768 |
|
---|
769 | *this = MakeUpperCase(path);
|
---|
770 |
|
---|
771 | break;
|
---|
772 | }
|
---|
773 |
|
---|
774 | case Win_WindowsDirectory:
|
---|
775 | {
|
---|
776 | char path[_MAX_PATH];
|
---|
777 | PRInt32 len = GetWindowsDirectory( path, _MAX_PATH );
|
---|
778 |
|
---|
779 | // Need enough space to add the trailing backslash
|
---|
780 | if (len > _MAX_PATH-2)
|
---|
781 | break;
|
---|
782 |
|
---|
783 | path[len] = '\\';
|
---|
784 | path[len+1] = '\0';
|
---|
785 |
|
---|
786 | *this = MakeUpperCase(path);
|
---|
787 | break;
|
---|
788 | }
|
---|
789 |
|
---|
790 | case Win_HomeDirectory:
|
---|
791 | {
|
---|
792 | char path[_MAX_PATH];
|
---|
793 | if (GetEnvironmentVariable(TEXT("HOME"), path, _MAX_PATH) > 0)
|
---|
794 | {
|
---|
795 | PRInt32 len = PL_strlen(path);
|
---|
796 | // Need enough space to add the trailing backslash
|
---|
797 | if (len > _MAX_PATH - 2)
|
---|
798 | break;
|
---|
799 |
|
---|
800 | path[len] = '\\';
|
---|
801 | path[len+1] = '\0';
|
---|
802 |
|
---|
803 | *this = MakeUpperCase(path);
|
---|
804 | break;
|
---|
805 | }
|
---|
806 |
|
---|
807 | if (GetEnvironmentVariable(TEXT("HOMEDRIVE"), path, _MAX_PATH) > 0)
|
---|
808 | {
|
---|
809 | char temp[_MAX_PATH];
|
---|
810 | if (GetEnvironmentVariable(TEXT("HOMEPATH"), temp, _MAX_PATH) > 0)
|
---|
811 | PL_strcatn(path, _MAX_PATH, temp);
|
---|
812 |
|
---|
813 | PRInt32 len = PL_strlen(path);
|
---|
814 |
|
---|
815 | // Need enough space to add the trailing backslash
|
---|
816 | if (len > _MAX_PATH - 2)
|
---|
817 | break;
|
---|
818 |
|
---|
819 | path[len] = '\\';
|
---|
820 | path[len+1] = '\0';
|
---|
821 |
|
---|
822 | *this = MakeUpperCase(path);
|
---|
823 | break;
|
---|
824 | }
|
---|
825 | }
|
---|
826 | case Win_Desktop:
|
---|
827 | {
|
---|
828 | GetWindowsFolder(CSIDL_DESKTOP, *this);
|
---|
829 | break;
|
---|
830 | }
|
---|
831 | case Win_Programs:
|
---|
832 | {
|
---|
833 | GetWindowsFolder(CSIDL_PROGRAMS, *this);
|
---|
834 | break;
|
---|
835 | }
|
---|
836 | case Win_Controls:
|
---|
837 | {
|
---|
838 | GetWindowsFolder(CSIDL_CONTROLS, *this);
|
---|
839 | break;
|
---|
840 | }
|
---|
841 | case Win_Printers:
|
---|
842 | {
|
---|
843 | GetWindowsFolder(CSIDL_PRINTERS, *this);
|
---|
844 | break;
|
---|
845 | }
|
---|
846 | case Win_Personal:
|
---|
847 | {
|
---|
848 | GetWindowsFolder(CSIDL_PERSONAL, *this);
|
---|
849 | break;
|
---|
850 | }
|
---|
851 | case Win_Favorites:
|
---|
852 | {
|
---|
853 | GetWindowsFolder(CSIDL_FAVORITES, *this);
|
---|
854 | break;
|
---|
855 | }
|
---|
856 | case Win_Startup:
|
---|
857 | {
|
---|
858 | GetWindowsFolder(CSIDL_STARTUP, *this);
|
---|
859 | break;
|
---|
860 | }
|
---|
861 | case Win_Recent:
|
---|
862 | {
|
---|
863 | GetWindowsFolder(CSIDL_RECENT, *this);
|
---|
864 | break;
|
---|
865 | }
|
---|
866 | case Win_Sendto:
|
---|
867 | {
|
---|
868 | GetWindowsFolder(CSIDL_SENDTO, *this);
|
---|
869 | break;
|
---|
870 | }
|
---|
871 | case Win_Bitbucket:
|
---|
872 | {
|
---|
873 | GetWindowsFolder(CSIDL_BITBUCKET, *this);
|
---|
874 | break;
|
---|
875 | }
|
---|
876 | case Win_Startmenu:
|
---|
877 | {
|
---|
878 | GetWindowsFolder(CSIDL_STARTMENU, *this);
|
---|
879 | break;
|
---|
880 | }
|
---|
881 | case Win_Desktopdirectory:
|
---|
882 | {
|
---|
883 | GetWindowsFolder(CSIDL_DESKTOPDIRECTORY, *this);
|
---|
884 | break;
|
---|
885 | }
|
---|
886 | case Win_Drives:
|
---|
887 | {
|
---|
888 | GetWindowsFolder(CSIDL_DRIVES, *this);
|
---|
889 | break;
|
---|
890 | }
|
---|
891 | case Win_Network:
|
---|
892 | {
|
---|
893 | GetWindowsFolder(CSIDL_NETWORK, *this);
|
---|
894 | break;
|
---|
895 | }
|
---|
896 | case Win_Nethood:
|
---|
897 | {
|
---|
898 | GetWindowsFolder(CSIDL_NETHOOD, *this);
|
---|
899 | break;
|
---|
900 | }
|
---|
901 | case Win_Fonts:
|
---|
902 | {
|
---|
903 | GetWindowsFolder(CSIDL_FONTS, *this);
|
---|
904 | break;
|
---|
905 | }
|
---|
906 | case Win_Templates:
|
---|
907 | {
|
---|
908 | GetWindowsFolder(CSIDL_TEMPLATES, *this);
|
---|
909 | break;
|
---|
910 | }
|
---|
911 | case Win_Common_Startmenu:
|
---|
912 | {
|
---|
913 | GetWindowsFolder(CSIDL_COMMON_STARTMENU, *this);
|
---|
914 | break;
|
---|
915 | }
|
---|
916 | case Win_Common_Programs:
|
---|
917 | {
|
---|
918 | GetWindowsFolder(CSIDL_COMMON_PROGRAMS, *this);
|
---|
919 | break;
|
---|
920 | }
|
---|
921 | case Win_Common_Startup:
|
---|
922 | {
|
---|
923 | GetWindowsFolder(CSIDL_COMMON_STARTUP, *this);
|
---|
924 | break;
|
---|
925 | }
|
---|
926 | case Win_Common_Desktopdirectory:
|
---|
927 | {
|
---|
928 | GetWindowsFolder(CSIDL_COMMON_DESKTOPDIRECTORY, *this);
|
---|
929 | break;
|
---|
930 | }
|
---|
931 | case Win_Appdata:
|
---|
932 | {
|
---|
933 | GetWindowsFolder(CSIDL_APPDATA, *this);
|
---|
934 | break;
|
---|
935 | }
|
---|
936 | case Win_Printhood:
|
---|
937 | {
|
---|
938 | GetWindowsFolder(CSIDL_PRINTHOOD, *this);
|
---|
939 | break;
|
---|
940 | }
|
---|
941 | case Win_Cookies:
|
---|
942 | {
|
---|
943 | GetWindowsFolder(CSIDL_COOKIES, *this);
|
---|
944 | break;
|
---|
945 | }
|
---|
946 | #endif // XP_WIN
|
---|
947 |
|
---|
948 | #if defined(XP_UNIX)
|
---|
949 | case Unix_LocalDirectory:
|
---|
950 | *this = "/usr/local/netscape/";
|
---|
951 | break;
|
---|
952 |
|
---|
953 | case Unix_LibDirectory:
|
---|
954 | *this = "/usr/local/lib/netscape/";
|
---|
955 | break;
|
---|
956 |
|
---|
957 | case Unix_HomeDirectory:
|
---|
958 | #ifdef VMS
|
---|
959 | {
|
---|
960 | char *pHome;
|
---|
961 | pHome = getenv("HOME");
|
---|
962 | if (*pHome == '/')
|
---|
963 | *this = pHome;
|
---|
964 | else
|
---|
965 | *this = decc$translate_vms(pHome);
|
---|
966 | }
|
---|
967 | #else
|
---|
968 | *this = PR_GetEnv("HOME");
|
---|
969 | #endif
|
---|
970 | break;
|
---|
971 |
|
---|
972 | #endif
|
---|
973 |
|
---|
974 | #ifdef XP_BEOS
|
---|
975 | case BeOS_SettingsDirectory:
|
---|
976 | {
|
---|
977 | char path[MAXPATHLEN];
|
---|
978 | find_directory(B_USER_SETTINGS_DIRECTORY, 0, 0, path, MAXPATHLEN);
|
---|
979 | // Need enough space to add the trailing backslash
|
---|
980 | int len = strlen(path);
|
---|
981 | if (len > MAXPATHLEN-2)
|
---|
982 | break;
|
---|
983 | path[len] = '/';
|
---|
984 | path[len+1] = '\0';
|
---|
985 | *this = path;
|
---|
986 | break;
|
---|
987 | }
|
---|
988 |
|
---|
989 | case BeOS_HomeDirectory:
|
---|
990 | {
|
---|
991 | char path[MAXPATHLEN];
|
---|
992 | find_directory(B_USER_DIRECTORY, 0, 0, path, MAXPATHLEN);
|
---|
993 | // Need enough space to add the trailing backslash
|
---|
994 | int len = strlen(path);
|
---|
995 | if (len > MAXPATHLEN-2)
|
---|
996 | break;
|
---|
997 | path[len] = '/';
|
---|
998 | path[len+1] = '\0';
|
---|
999 | *this = path;
|
---|
1000 | break;
|
---|
1001 | }
|
---|
1002 |
|
---|
1003 | case BeOS_DesktopDirectory:
|
---|
1004 | {
|
---|
1005 | char path[MAXPATHLEN];
|
---|
1006 | find_directory(B_DESKTOP_DIRECTORY, 0, 0, path, MAXPATHLEN);
|
---|
1007 | // Need enough space to add the trailing backslash
|
---|
1008 | int len = strlen(path);
|
---|
1009 | if (len > MAXPATHLEN-2)
|
---|
1010 | break;
|
---|
1011 | path[len] = '/';
|
---|
1012 | path[len+1] = '\0';
|
---|
1013 | *this = path;
|
---|
1014 | break;
|
---|
1015 | }
|
---|
1016 |
|
---|
1017 | case BeOS_SystemDirectory:
|
---|
1018 | {
|
---|
1019 | char path[MAXPATHLEN];
|
---|
1020 | find_directory(B_BEOS_DIRECTORY, 0, 0, path, MAXPATHLEN);
|
---|
1021 | // Need enough space to add the trailing backslash
|
---|
1022 | int len = strlen(path);
|
---|
1023 | if (len > MAXPATHLEN-2)
|
---|
1024 | break;
|
---|
1025 | path[len] = '/';
|
---|
1026 | path[len+1] = '\0';
|
---|
1027 | *this = path;
|
---|
1028 | break;
|
---|
1029 | }
|
---|
1030 | #endif
|
---|
1031 | #ifdef XP_OS2
|
---|
1032 | case OS2_SystemDirectory:
|
---|
1033 | {
|
---|
1034 | ULONG ulBootDrive = 0;
|
---|
1035 | char buffer[] = " :\\OS2\\System\\";
|
---|
1036 | DosQuerySysInfo( QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
|
---|
1037 | &ulBootDrive, sizeof ulBootDrive);
|
---|
1038 | buffer[0] = 'A' - 1 + ulBootDrive; // duh, 1-based index...
|
---|
1039 | *this = buffer;
|
---|
1040 | #ifdef DEBUG
|
---|
1041 | printf( "Got OS2_SystemDirectory: %s\n", buffer);
|
---|
1042 | #endif
|
---|
1043 | break;
|
---|
1044 | }
|
---|
1045 |
|
---|
1046 | case OS2_OS2Directory:
|
---|
1047 | {
|
---|
1048 | ULONG ulBootDrive = 0;
|
---|
1049 | char buffer[] = " :\\OS2\\";
|
---|
1050 | DosQuerySysInfo( QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
|
---|
1051 | &ulBootDrive, sizeof ulBootDrive);
|
---|
1052 | buffer[0] = 'A' - 1 + ulBootDrive; // duh, 1-based index...
|
---|
1053 | *this = buffer;
|
---|
1054 | #ifdef DEBUG
|
---|
1055 | printf( "Got OS2_OS2Directory: %s\n", buffer);
|
---|
1056 | #endif
|
---|
1057 | break;
|
---|
1058 | }
|
---|
1059 |
|
---|
1060 | case OS2_HomeDirectory:
|
---|
1061 | {
|
---|
1062 | char *tPath = PR_GetEnv("MOZILLA_HOME");
|
---|
1063 | /* If MOZILLA_HOME is not set, use GetCurrentProcessDirectory */
|
---|
1064 | /* To ensure we get a long filename system */
|
---|
1065 | if (!tPath || !*tPath)
|
---|
1066 | GetCurrentProcessDirectory(*this);
|
---|
1067 | else
|
---|
1068 | *this = tPath;
|
---|
1069 | PrfWriteProfileString(HINI_USERPROFILE, "Mozilla", "Home", *this);
|
---|
1070 | break;
|
---|
1071 | }
|
---|
1072 |
|
---|
1073 | case OS2_DesktopDirectory:
|
---|
1074 | {
|
---|
1075 | char szPath[CCHMAXPATH + 1];
|
---|
1076 | BOOL fSuccess;
|
---|
1077 | fSuccess = WinQueryActiveDesktopPathname (szPath, sizeof(szPath));
|
---|
1078 | int len = strlen (szPath);
|
---|
1079 | if (len > CCHMAXPATH -1)
|
---|
1080 | break;
|
---|
1081 | szPath[len] = '\\';
|
---|
1082 | szPath[len + 1] = '\0';
|
---|
1083 | #ifdef DEBUG
|
---|
1084 | if (fSuccess) {
|
---|
1085 | printf ("Got OS2_DesktopDirectory: %s\n", szPath);
|
---|
1086 | } else {
|
---|
1087 | printf ("Failed getting OS2_DesktopDirectory: %s\n", szPath);
|
---|
1088 | }
|
---|
1089 | #endif
|
---|
1090 | break;
|
---|
1091 | }
|
---|
1092 |
|
---|
1093 | #endif
|
---|
1094 | default:
|
---|
1095 | break;
|
---|
1096 | }
|
---|
1097 | }
|
---|
1098 |
|
---|
1099 | void
|
---|
1100 | nsSpecialSystemDirectory::Set(SystemDirectories dirToSet, nsFileSpec *dirSpec)
|
---|
1101 | {
|
---|
1102 | SystemDirectoriesKey dirKey(dirToSet);
|
---|
1103 |
|
---|
1104 | PR_ASSERT(NULL != dirSpec);
|
---|
1105 |
|
---|
1106 | if (NULL == systemDirectoriesLocations) {
|
---|
1107 | systemDirectoriesLocations = new nsHashtable(NS_SYSTEMDIR_HASH_NUM);
|
---|
1108 | }
|
---|
1109 | PR_ASSERT(NULL != systemDirectoriesLocations);
|
---|
1110 |
|
---|
1111 | nsFileSpec *newSpec = new nsFileSpec(*dirSpec);
|
---|
1112 | if (NULL != newSpec) {
|
---|
1113 | systemDirectoriesLocations->Put(&dirKey, newSpec);
|
---|
1114 | }
|
---|
1115 |
|
---|
1116 | return;
|
---|
1117 | }
|
---|
1118 |
|
---|
1119 | #if defined(XP_MAC)
|
---|
1120 | //----------------------------------------------------------------------------------------
|
---|
1121 | nsSpecialSystemDirectory::nsSpecialSystemDirectory(OSType folderType)
|
---|
1122 | //----------------------------------------------------------------------------------------
|
---|
1123 | {
|
---|
1124 | *this = folderType;
|
---|
1125 | }
|
---|
1126 |
|
---|
1127 | //----------------------------------------------------------------------------------------
|
---|
1128 | void nsSpecialSystemDirectory::operator = (OSType folderType)
|
---|
1129 | //----------------------------------------------------------------------------------------
|
---|
1130 | {
|
---|
1131 | CInfoPBRec cinfo;
|
---|
1132 | DirInfo *dipb=(DirInfo *)&cinfo;
|
---|
1133 |
|
---|
1134 | // hack: first check for kDefaultDownloadFolderType
|
---|
1135 | // if it is, get Internet Config Download folder, if that's
|
---|
1136 | // not availble use desktop folder
|
---|
1137 | if (folderType == kDefaultDownloadFolderType)
|
---|
1138 | {
|
---|
1139 | nsCOMPtr<nsIInternetConfigService> icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID));
|
---|
1140 | if (icService)
|
---|
1141 | {
|
---|
1142 | if (NS_SUCCEEDED(icService->GetDownloadFolder(&mSpec)))
|
---|
1143 | return;
|
---|
1144 | else
|
---|
1145 | folderType = kDesktopFolderType;
|
---|
1146 | }
|
---|
1147 | else
|
---|
1148 | {
|
---|
1149 | folderType = kDesktopFolderType;
|
---|
1150 | }
|
---|
1151 | }
|
---|
1152 | // Call FindFolder to fill in the vrefnum and dirid
|
---|
1153 | for (int attempts = 0; attempts < 2; attempts++)
|
---|
1154 | {
|
---|
1155 | mError = NS_FILE_RESULT(
|
---|
1156 | FindFolder(
|
---|
1157 | kOnSystemDisk,
|
---|
1158 | folderType,
|
---|
1159 | true,
|
---|
1160 | &dipb->ioVRefNum,
|
---|
1161 | &dipb->ioDrDirID));
|
---|
1162 | if (NS_SUCCEEDED(mError))
|
---|
1163 | break;
|
---|
1164 | if (attempts > 0)
|
---|
1165 | return;
|
---|
1166 | switch (folderType)
|
---|
1167 | {
|
---|
1168 | case kDocumentsFolderType:
|
---|
1169 | // Find folder will find this, as long as it exists.
|
---|
1170 | // The "create" parameter, however, is sadly ignored.
|
---|
1171 | // How do we internationalize this?
|
---|
1172 | *this = kVolumeRootFolderType;
|
---|
1173 | *this += "Documents";
|
---|
1174 | CreateDirectory();
|
---|
1175 | break;
|
---|
1176 | } // switch
|
---|
1177 | } // for
|
---|
1178 | StrFileName filename;
|
---|
1179 | filename[0] = '\0';
|
---|
1180 | dipb->ioNamePtr = (StringPtr)&filename;
|
---|
1181 | dipb->ioFDirIndex = -1;
|
---|
1182 |
|
---|
1183 | mError = NS_FILE_RESULT(PBGetCatInfoSync(&cinfo));
|
---|
1184 | if (NS_SUCCEEDED(mError))
|
---|
1185 | {
|
---|
1186 | mError = NS_FILE_RESULT(FSMakeFSSpec(dipb->ioVRefNum, dipb->ioDrParID, filename, &mSpec));
|
---|
1187 | }
|
---|
1188 | }
|
---|
1189 | #endif // XP_MAC
|
---|