Changeset 101866 in vbox for trunk/src/libs/xpcom18a4
- Timestamp:
- Nov 6, 2023 12:51:35 PM (15 months ago)
- Location:
- trunk/src/libs/xpcom18a4/xpcom/io
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/xpcom18a4/xpcom/io/SpecialSystemDirectory.cpp
r60949 r101866 44 44 45 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) 46 #if defined(XP_UNIX) 90 47 91 48 #include <unistd.h> … … 97 54 # endif 98 55 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 56 #endif 111 57 112 #if defined(VMS)113 #include <unixlib.h>114 #endif115 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 #endif123 58 NS_COM void StartupSpecialSystemDirectory() 124 59 { 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 mozilla128 startup. Replacing these older calls with a single call to SHGetSpecialFolderPath129 effectively removes these calls from the performace radar. We need to130 support the older way of file location lookup on systems that do not have131 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 #endif140 60 } 141 61 142 62 NS_COM void ShutdownSpecialSystemDirectory() 143 63 { 144 #if defined (XP_WIN)145 if (gShell32DLLInst)146 {147 FreeLibrary(gShell32DLLInst);148 gShell32DLLInst = NULL;149 gGetSpecialPathProc = NULL;150 }151 #endif152 64 } 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 slash168 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 buffer191 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 slash203 len = strlen(pBuffer);204 pBuffer[len] = '\\';205 pBuffer[len + 1] = '\0';206 207 // Assign the directory208 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_WIN225 226 227 65 228 66 … … 231 69 nsILocalFile** aFile) 232 70 { 233 #ifdef XP_MAC234 OSErr err;235 short vRefNum;236 long dirID;237 #endif238 239 71 switch (aSystemSystemDirectory) 240 72 { 241 73 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), 74 return NS_NewNativeLocalFile(nsDependentCString("/"), 253 75 PR_TRUE, 254 76 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 #else273 return NS_NewNativeLocalFile(nsDependentCString("/"),274 PR_TRUE,275 aFile);276 277 #endif278 279 77 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) 78 #if defined(XP_MACOSX) 307 79 { 308 80 return GetOSXFolderType(kUserDomain, kTemporaryFolderType, aFile); 309 81 } 310 82 311 #elif defined(XP_UNIX) || defined(XP_BEOS)83 #elif defined(XP_UNIX) 312 84 { 313 85 static const char *tPath = nsnull; … … 332 104 #endif 333 105 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 folder365 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 folder379 // if pre-Mac OS X, return Mac OS's Prefs folder380 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 #endif407 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 backslash415 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 backslash431 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 backslash449 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 backslash469 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_WIN577 578 106 #if defined(XP_UNIX) 579 107 case Unix_LocalDirectory: … … 587 115 588 116 case Unix_HomeDirectory: 589 #ifdef VMS590 {591 char *pHome;592 pHome = getenv("HOME");593 if (*pHome == '/') {594 return NS_NewNativeLocalFile(nsDependentCString(pHome),595 PR_TRUE,596 aFile);597 598 }599 else600 {601 return NS_NewNativeLocalFile(nsDependentCString(decc$translate_vms(pHome)),602 PR_TRUE,603 aFile);604 }605 }606 #else607 117 return NS_NewNativeLocalFile(nsDependentCString(PR_GetEnv("HOME")), 608 118 PR_TRUE, 609 119 aFile); 610 611 #endif612 613 #endif614 615 #ifdef XP_BEOS616 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 backslash621 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 backslash636 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 backslash652 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 backslash668 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 #endif679 #ifdef XP_OS2680 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 misery719 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 120 #endif 745 121 default: -
trunk/src/libs/xpcom18a4/xpcom/io/SpecialSystemDirectory.h
r60949 r101866 65 65 XPCOM_CurrentProcessComponentDirectory= 5, 66 66 XPCOM_CurrentProcessComponentRegistry= 6, 67 67 68 68 Moz_BinDirectory = 100 , 69 Mac_SystemDirectory = 101, 70 Mac_DesktopDirectory = 102, 71 Mac_TrashDirectory = 103, 72 Mac_StartupDirectory = 104, 73 Mac_ShutdownDirectory = 105, 74 Mac_AppleMenuDirectory = 106, 75 Mac_ControlPanelDirectory = 107, 76 Mac_ExtensionDirectory = 108, 77 Mac_FontsDirectory = 109, 78 Mac_ClassicPreferencesDirectory = 110, 79 Mac_DocumentsDirectory = 111, 80 Mac_InternetSearchDirectory = 112, 81 Mac_DefaultDownloadDirectory = 113, 82 Mac_UserLibDirectory = 114, 83 Mac_PreferencesDirectory = 115, 84 85 Win_SystemDirectory = 201, 86 Win_WindowsDirectory = 202, 87 Win_HomeDirectory = 203, 88 Win_Desktop = 204, 89 Win_Programs = 205, 90 Win_Controls = 206, 91 Win_Printers = 207, 92 Win_Personal = 208, 93 Win_Favorites = 209, 94 Win_Startup = 210, 95 Win_Recent = 211, 96 Win_Sendto = 212, 97 Win_Bitbucket = 213, 98 Win_Startmenu = 214, 99 Win_Desktopdirectory = 215, 100 Win_Drives = 216, 101 Win_Network = 217, 102 Win_Nethood = 218, 103 Win_Fonts = 219, 104 Win_Templates = 220, 105 Win_Common_Startmenu = 221, 106 Win_Common_Programs = 222, 107 Win_Common_Startup = 223, 108 Win_Common_Desktopdirectory = 224, 109 Win_Appdata = 225, 110 Win_Printhood = 226, 111 Win_Cookies = 227, 112 69 113 70 Unix_LocalDirectory = 301, 114 71 Unix_LibDirectory = 302, 115 72 Unix_HomeDirectory = 303, 116 117 BeOS_SettingsDirectory = 401,118 BeOS_HomeDirectory = 402,119 BeOS_DesktopDirectory = 403,120 BeOS_SystemDirectory = 404,121 122 OS2_SystemDirectory = 501,123 OS2_OS2Directory = 502,124 OS2_DesktopDirectory = 503,125 OS2_HomeDirectory = 504126 73 }; 127 74 -
trunk/src/libs/xpcom18a4/xpcom/io/nsDirectoryService.cpp
r63541 r101866 44 44 #include "nsStaticAtom.h" 45 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) 46 #if defined(XP_UNIX) || defined(XP_MACOSX) 58 47 #include <unistd.h> 59 48 #include <stdlib.h> … … 73 62 #include <InternetConfig.h> 74 63 #endif 75 #elif defined(XP_OS2)76 #define MAX_PATH _MAX_PATH77 #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 64 #endif 87 65 … … 89 67 #include "nsAppFileLocationProvider.h" 90 68 91 #if defined(XP_MAC)92 #define COMPONENT_REGISTRY_NAME NS_LITERAL_CSTRING("Component Registry")93 #define COMPONENT_DIRECTORY NS_LITERAL_CSTRING("Components")94 #else95 69 #define COMPONENT_REGISTRY_NAME NS_LITERAL_CSTRING("compreg.dat") 96 70 #define COMPONENT_DIRECTORY NS_LITERAL_CSTRING("components") 97 #endif98 71 99 72 #define XPTI_REGISTRY_NAME NS_LITERAL_CSTRING("xpti.dat") 100 73 101 74 // 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) 75 #if defined (XP_MACOSX) 106 76 #define HOME_DIR NS_OSX_HOME_DIR 107 77 #elif defined (XP_UNIX) 108 78 #define HOME_DIR NS_UNIX_HOME_DIR 109 #elif defined (XP_OS2)110 #define HOME_DIR NS_OS2_HOME_DIR111 #elif defined (XP_BEOS)112 #define HOME_DIR NS_BEOS_HOME_DIR113 79 #endif 114 80 … … 152 118 153 119 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) 120 #if defined(XP_MACOSX) 197 121 # ifdef MOZ_DEFAULT_VBOX_XPCOM_HOME 198 122 rv = localFile->InitWithNativePath(nsDependentCString(MOZ_DEFAULT_VBOX_XPCOM_HOME)); … … 216 140 if (CFURLGetFileSystemRepresentation(parentURL, PR_TRUE, (UInt8 *)buffer, sizeof(buffer))) 217 141 { 218 #ifdef DEBUG_conrad219 printf("nsDirectoryService - CurrentProcessDir is: %s\n", buffer);220 #endif221 142 rv = localFile->InitWithNativePath(nsDependentCString(buffer)); 222 143 if (NS_SUCCEEDED(rv)) … … 241 162 // - else give the current directory 242 163 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 DEBUG306 printf("debug: (1) VBOX_XPCOM_HOME=%s\n", buf2);307 #endif308 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 #endif321 322 164 323 165 // The MOZ_DEFAULT_VBOX_XPCOM_HOME variable can be set at configure time with … … 361 203 *aFile = localFile; 362 204 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 misery372 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 else387 {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 205 } 405 206 … … 455 256 nsIAtom* nsDirectoryService::sMusicDocumentsDirectory = nsnull; 456 257 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 258 #elif defined (XP_UNIX) 486 259 nsIAtom* nsDirectoryService::sLocalDirectory = nsnull; 487 260 nsIAtom* nsDirectoryService::sLibDirectory = nsnull; 488 261 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 262 #endif 500 263 … … 564 327 { NS_OSX_MUSIC_DOCUMENTS_DIR, &nsDirectoryService::sMusicDocumentsDirectory }, 565 328 { 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 329 #elif defined (XP_UNIX) 595 330 { NS_UNIX_LOCAL_DIR, &nsDirectoryService::sLocalDirectory }, 596 331 { NS_UNIX_LIB_DIR, &nsDirectoryService::sLibDirectory }, 597 332 { 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 333 #endif 609 334 }; … … 1062 787 rv = GetOSXFolderType(kUserDomain, kInternetSitesFolderType, getter_AddRefs(localFile)); 1063 788 } 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)); 789 #elif defined (XP_UNIX) 790 791 else if (inAtom == nsDirectoryService::sLocalDirectory) 792 { 793 rv = GetSpecialSystemDirectory(Unix_LocalDirectory, getter_AddRefs(localFile)); 794 } 795 else if (inAtom == nsDirectoryService::sLibDirectory) 796 { 797 rv = GetSpecialSystemDirectory(Unix_LibDirectory, getter_AddRefs(localFile)); 1072 798 } 1073 799 else if (inAtom == nsDirectoryService::sHomeDirectory) 1074 800 { 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 801 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 802 } 1221 803 #endif … … 1226 808 if (localFile && NS_SUCCEEDED(rv)) 1227 809 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 810 1231 811 return rv; 1232 812 }
Note:
See TracChangeset
for help on using the changeset viewer.