Back to index

lightning-sunbird  0.9+nobinonly
Enumerations | Functions
SpecialSystemDirectory.h File Reference
#include "nscore.h"
#include "nsILocalFile.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  SystemDirectories {
  OS_DriveDirectory = 1, OS_TemporaryDirectory = 2, OS_CurrentProcessDirectory = 3, OS_CurrentWorkingDirectory = 4,
  XPCOM_CurrentProcessComponentDirectory = 5, XPCOM_CurrentProcessComponentRegistry = 6, Moz_BinDirectory = 100, Mac_SystemDirectory = 101,
  Mac_DesktopDirectory = 102, Mac_TrashDirectory = 103, Mac_StartupDirectory = 104, Mac_ShutdownDirectory = 105,
  Mac_AppleMenuDirectory = 106, Mac_ControlPanelDirectory = 107, Mac_ExtensionDirectory = 108, Mac_FontsDirectory = 109,
  Mac_ClassicPreferencesDirectory = 110, Mac_DocumentsDirectory = 111, Mac_InternetSearchDirectory = 112, Mac_DefaultDownloadDirectory = 113,
  Mac_UserLibDirectory = 114, Mac_PreferencesDirectory = 115, Win_SystemDirectory = 201, Win_WindowsDirectory = 202,
  Win_HomeDirectory = 203, Win_Desktop = 204, Win_Programs = 205, Win_Controls = 206,
  Win_Printers = 207, Win_Personal = 208, Win_Favorites = 209, Win_Startup = 210,
  Win_Recent = 211, Win_Sendto = 212, Win_Bitbucket = 213, Win_Startmenu = 214,
  Win_Desktopdirectory = 215, Win_Drives = 216, Win_Network = 217, Win_Nethood = 218,
  Win_Fonts = 219, Win_Templates = 220, Win_Common_Startmenu = 221, Win_Common_Programs = 222,
  Win_Common_Startup = 223, Win_Common_Desktopdirectory = 224, Win_Appdata = 225, Win_Printhood = 226,
  Win_Cookies = 227, Win_LocalAppdata = 228, Win_ProgramFiles = 229, Unix_LocalDirectory = 301,
  Unix_LibDirectory = 302, Unix_HomeDirectory = 303, Unix_DesktopDirectory = 304, BeOS_SettingsDirectory = 401,
  BeOS_HomeDirectory = 402, BeOS_DesktopDirectory = 403, BeOS_SystemDirectory = 404, OS2_SystemDirectory = 501,
  OS2_OS2Directory = 502, OS2_DesktopDirectory = 503, OS2_HomeDirectory = 504
}

Functions

NS_COM void StartupSpecialSystemDirectory ()
NS_COM void ShutdownSpecialSystemDirectory ()
nsresult GetSpecialSystemDirectory (SystemDirectories aSystemSystemDirectory, nsILocalFile **aFile)

Enumeration Type Documentation

Enumerator:
OS_DriveDirectory 
OS_TemporaryDirectory 
OS_CurrentProcessDirectory 
OS_CurrentWorkingDirectory 
XPCOM_CurrentProcessComponentDirectory 
XPCOM_CurrentProcessComponentRegistry 
Moz_BinDirectory 
Mac_SystemDirectory 
Mac_DesktopDirectory 
Mac_TrashDirectory 
Mac_StartupDirectory 
Mac_ShutdownDirectory 
Mac_AppleMenuDirectory 
Mac_ControlPanelDirectory 
Mac_ExtensionDirectory 
Mac_FontsDirectory 
Mac_ClassicPreferencesDirectory 
Mac_DocumentsDirectory 
Mac_InternetSearchDirectory 
Mac_DefaultDownloadDirectory 
Mac_UserLibDirectory 
Mac_PreferencesDirectory 
Win_SystemDirectory 
Win_WindowsDirectory 
Win_HomeDirectory 
Win_Desktop 
Win_Programs 
Win_Controls 
Win_Printers 
Win_Personal 
Win_Favorites 
Win_Startup 
Win_Recent 
Win_Sendto 
Win_Bitbucket 
Win_Startmenu 
Win_Desktopdirectory 
Win_Drives 
Win_Network 
Win_Nethood 
Win_Fonts 
Win_Templates 
Win_Common_Startmenu 
Win_Common_Programs 
Win_Common_Startup 
Win_Common_Desktopdirectory 
Win_Appdata 
Win_Printhood 
Win_Cookies 
Win_LocalAppdata 
Win_ProgramFiles 
Unix_LocalDirectory 
Unix_LibDirectory 
Unix_HomeDirectory 
Unix_DesktopDirectory 
BeOS_SettingsDirectory 
BeOS_HomeDirectory 
BeOS_DesktopDirectory 
BeOS_SystemDirectory 
OS2_SystemDirectory 
OS2_OS2Directory 
OS2_DesktopDirectory 
OS2_HomeDirectory 

Definition at line 58 of file SpecialSystemDirectory.h.

                       {
  OS_DriveDirectory         =   1,   
  OS_TemporaryDirectory     =   2,   
  OS_CurrentProcessDirectory=   3,   
  OS_CurrentWorkingDirectory=   4,
  XPCOM_CurrentProcessComponentDirectory=   5,   
  XPCOM_CurrentProcessComponentRegistry=   6,   
  
  Moz_BinDirectory          =   100 ,
  Mac_SystemDirectory       =   101,   
  Mac_DesktopDirectory      =   102,   
  Mac_TrashDirectory        =   103,   
  Mac_StartupDirectory      =   104,   
  Mac_ShutdownDirectory     =   105,   
  Mac_AppleMenuDirectory    =   106,   
  Mac_ControlPanelDirectory =   107,   
  Mac_ExtensionDirectory    =   108,   
  Mac_FontsDirectory        =   109,   
  Mac_ClassicPreferencesDirectory =   110,   
  Mac_DocumentsDirectory          =   111,   
  Mac_InternetSearchDirectory     =   112,   
  Mac_DefaultDownloadDirectory    =   113,   
  Mac_UserLibDirectory      =   114,   
  Mac_PreferencesDirectory  =   115,
   
  Win_SystemDirectory       =   201,   
  Win_WindowsDirectory      =   202,
  Win_HomeDirectory         =   203,   
  Win_Desktop               =   204,   
  Win_Programs              =   205,   
  Win_Controls              =   206,   
  Win_Printers              =   207,   
  Win_Personal              =   208,   
  Win_Favorites             =   209,   
  Win_Startup               =   210,   
  Win_Recent                =   211,   
  Win_Sendto                =   212,   
  Win_Bitbucket             =   213,   
  Win_Startmenu             =   214,   
  Win_Desktopdirectory      =   215,   
  Win_Drives                =   216,   
  Win_Network               =   217,   
  Win_Nethood               =   218,   
  Win_Fonts                 =   219,   
  Win_Templates             =   220,   
  Win_Common_Startmenu      =   221,   
  Win_Common_Programs       =   222,   
  Win_Common_Startup        =   223,   
  Win_Common_Desktopdirectory = 224,   
  Win_Appdata               =   225,   
  Win_Printhood             =   226,   
  Win_Cookies               =   227, 
  Win_LocalAppdata          =   228,
  Win_ProgramFiles          =   229,
  
  Unix_LocalDirectory       =   301,   
  Unix_LibDirectory         =   302,   
  Unix_HomeDirectory        =   303,
  Unix_DesktopDirectory     =   304,
  
  BeOS_SettingsDirectory    =   401,   
  BeOS_HomeDirectory        =   402,   
  BeOS_DesktopDirectory     =   403,   
  BeOS_SystemDirectory      =   404,
  
  OS2_SystemDirectory       =   501,   
  OS2_OS2Directory          =   502,   
  OS2_DesktopDirectory      =   503,   
  OS2_HomeDirectory         =   504
};

Function Documentation

nsresult GetSpecialSystemDirectory ( SystemDirectories  aSystemSystemDirectory,
nsILocalFile **  aFile 
)

Definition at line 317 of file SpecialSystemDirectory.cpp.

{
#if defined(XP_WIN)
    WCHAR path[MAX_PATH];
#else
    char path[MAXPATHLEN];
#endif

    switch (aSystemSystemDirectory)
    {
        case OS_CurrentWorkingDirectory:
#if defined(XP_WIN)
            if (!nsWinAPIs::mGetCwd(path, MAX_PATH))
                return NS_ERROR_FAILURE;
            return NS_NewLocalFile(nsDependentString(path), 
                                   PR_TRUE, 
                                   aFile);
#elif defined(XP_OS2)
            if (DosQueryPathInfo( ".", FIL_QUERYFULLNAME, path, MAXPATHLEN))
                return NS_ERROR_FAILURE;
#else
            if(!getcwd(path, MAXPATHLEN))
                return NS_ERROR_FAILURE;
#endif

#if !defined(XP_WIN)
            return NS_NewNativeLocalFile(nsDependentCString(path), 
                                         PR_TRUE, 
                                         aFile);
#endif

        case OS_DriveDirectory:
#if defined (XP_WIN)
        {
            PRInt32 len = nsWinAPIs::mGetWindowsDirectory(path, MAX_PATH);
            if (len == 0)
                break;
            if (path[1] == PRUnichar(':') && path[2] == PRUnichar('\\'))
                path[3] = 0;

            return NS_NewLocalFile(nsDependentString(path),
                                   PR_TRUE, 
                                   aFile);
        }
#elif defined(XP_OS2)
        {
            ULONG ulBootDrive = 0;
            char  buffer[] = " :\\OS2\\";
            DosQuerySysInfo( QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
                             &ulBootDrive, sizeof ulBootDrive);
            buffer[0] = 'A' - 1 + ulBootDrive; // duh, 1-based index...

            return NS_NewNativeLocalFile(nsDependentCString(buffer),
                                         PR_TRUE, 
                                         aFile);
        }
#else
        return NS_NewNativeLocalFile(nsDependentCString("/"), 
                                     PR_TRUE, 
                                     aFile);

#endif
            
        case OS_TemporaryDirectory:
#if defined (XP_WIN) && !defined (WINCE)
        {
            DWORD len = nsWinAPIs::mGetTempPath(MAX_PATH, path);
            if (len == 0)
                break;
            return NS_NewLocalFile(nsDependentString(path, len), 
                                   PR_TRUE, 
                                   aFile);
        }
#elif defined (WINCE)
        {
            return NS_NewNativeLocalFile(NS_LITERAL_CSTRING("\\Temp"), 
                                         PR_TRUE, 
                                         aFile);
        }
#elif defined(XP_OS2)
        {
            char buffer[CCHMAXPATH] = "";
            char *c = getenv( "TMP");
            if( c) strcpy( buffer, c);
            else
            {
                c = getenv( "TEMP");
                if( c) strcpy( buffer, c);
            }

            nsCString tString = nsDependentCString(buffer);
            if (tString.Find("/", PR_FALSE, 0, -1)) {
                tString.ReplaceChar('/','\\');
            }
            return NS_NewNativeLocalFile(tString, PR_TRUE, aFile);
        } 
#elif defined(XP_MACOSX)
        {
            return GetOSXFolderType(kUserDomain, kTemporaryFolderType, aFile);
        }

#elif defined(XP_UNIX) || defined(XP_BEOS)
        {
            static const char *tPath = nsnull;
            if (!tPath) {
                tPath = PR_GetEnv("TMPDIR");
                if (!tPath || !*tPath) {
                    tPath = PR_GetEnv("TMP");
                    if (!tPath || !*tPath) {
                        tPath = PR_GetEnv("TEMP");
                        if (!tPath || !*tPath) {
                            tPath = "/tmp/";
                        }
                    }
                }
            }
            return NS_NewNativeLocalFile(nsDependentCString(tPath), 
                                         PR_TRUE, 
                                         aFile);
        }
#else
        break;
#endif            
#if defined (XP_WIN)
        case Win_SystemDirectory:
        {    
            PRInt32 len = nsWinAPIs::mGetSystemDirectory(path, MAX_PATH);
        
            // Need enough space to add the trailing backslash
            if (!len || len > MAX_PATH - 2)
                break;
            path[len]   = L'\\';
            path[++len] = L'\0';

            return NS_NewLocalFile(nsDependentString(path, len), 
                                   PR_TRUE, 
                                   aFile);
        }

        case Win_WindowsDirectory:
        {    
            PRInt32 len = nsWinAPIs::mGetWindowsDirectory(path, MAX_PATH);
            
            // Need enough space to add the trailing backslash
            if (!len || len > MAX_PATH - 2)
                break;
            
            path[len]   = L'\\';
            path[++len] = L'\0';

            return NS_NewLocalFile(nsDependentString(path, len), 
                                   PR_TRUE, 
                                   aFile);
        }

        case Win_ProgramFiles:
        {
            return GetWindowsFolder(CSIDL_PROGRAM_FILES, aFile);
        }

        case Win_HomeDirectory:
        {    
            PRInt32 len;
            if ((len = 
                 nsWinAPIs::mGetEnvironmentVariable(L"HOME", path, 
                                                    MAX_PATH)) > 0)
            {
                // Need enough space to add the trailing backslash
                if (len > MAX_PATH - 2)
                    break;
               
                path[len]   = L'\\';
                path[++len] = L'\0';

                return NS_NewLocalFile(nsDependentString(path, len), 
                                       PR_TRUE, 
                                       aFile);
            }

            len = nsWinAPIs::mGetEnvironmentVariable(L"HOMEDRIVE", 
                                                     path, MAX_PATH);
            if (0 < len && len < MAX_PATH)
            {
                WCHAR temp[MAX_PATH];
                DWORD len2 = nsWinAPIs::mGetEnvironmentVariable(L"HOMEPATH", 
                                                                temp,
                                                                MAX_PATH);
                if (0 < len2 && len + len2 < MAX_PATH)
                    wcsncat(path, temp, len2);
        
                len = wcslen(path);

                // Need enough space to add the trailing backslash
                if (len > MAX_PATH - 2)
                    break;
            
                path[len]   = L'\\';
                path[++len] = L'\0';
                
                return NS_NewLocalFile(nsDependentString(path, len), 
                                       PR_TRUE, 
                                       aFile);
            }
        }
        case Win_Desktop:
        {
            return GetWindowsFolder(CSIDL_DESKTOP, aFile);
        }
        case Win_Programs:
        {
            return GetWindowsFolder(CSIDL_PROGRAMS, aFile);
        }
        case Win_Controls:
        {
            return GetWindowsFolder(CSIDL_CONTROLS, aFile);
        }
        case Win_Printers:
        {
            return GetWindowsFolder(CSIDL_PRINTERS, aFile);
        }
        case Win_Personal:
        {
            return GetWindowsFolder(CSIDL_PERSONAL, aFile);
        }
        case Win_Favorites:
        {
            return GetWindowsFolder(CSIDL_FAVORITES, aFile);
        }
        case Win_Startup:
        {
            return GetWindowsFolder(CSIDL_STARTUP, aFile);
        }
        case Win_Recent:
        {
            return GetWindowsFolder(CSIDL_RECENT, aFile);
        }
        case Win_Sendto:
        {
            return GetWindowsFolder(CSIDL_SENDTO, aFile);
        }
        case Win_Bitbucket:
        {
            return GetWindowsFolder(CSIDL_BITBUCKET, aFile);
        }
        case Win_Startmenu:
        {
            return GetWindowsFolder(CSIDL_STARTMENU, aFile);
        }
        case Win_Desktopdirectory:
        {
            return GetWindowsFolder(CSIDL_DESKTOPDIRECTORY, aFile);
        }
        case Win_Drives:
        {
            return GetWindowsFolder(CSIDL_DRIVES, aFile);
        }
        case Win_Network:
        {
            return GetWindowsFolder(CSIDL_NETWORK, aFile);
        }
        case Win_Nethood:
        {
            return GetWindowsFolder(CSIDL_NETHOOD, aFile);
        }
        case Win_Fonts:
        {
            return GetWindowsFolder(CSIDL_FONTS, aFile);
        }
        case Win_Templates:
        {
            return GetWindowsFolder(CSIDL_TEMPLATES, aFile);
        }
#ifndef WINCE
        case Win_Common_Startmenu:
        {
            return GetWindowsFolder(CSIDL_COMMON_STARTMENU, aFile);
        }
        case Win_Common_Programs:
        {
            return GetWindowsFolder(CSIDL_COMMON_PROGRAMS, aFile);
        }
        case Win_Common_Startup:
        {
            return GetWindowsFolder(CSIDL_COMMON_STARTUP, aFile);
        }
        case Win_Common_Desktopdirectory:
        {
            return GetWindowsFolder(CSIDL_COMMON_DESKTOPDIRECTORY, aFile);
        }
        case Win_Printhood:
        {
            return GetWindowsFolder(CSIDL_PRINTHOOD, aFile);
        }
        case Win_Cookies:
        {
            return GetWindowsFolder(CSIDL_COOKIES, aFile);
        }
#endif
        case Win_Appdata:
        {
            return GetWindowsFolder(CSIDL_APPDATA, aFile);
        }

        case Win_LocalAppdata:
        {
            return GetWindowsFolder(CSIDL_LOCAL_APPDATA, aFile);
        }
#endif  // XP_WIN

#if defined(XP_UNIX)
        case Unix_LocalDirectory:
            return NS_NewNativeLocalFile(nsDependentCString("/usr/local/netscape/"), 
                                         PR_TRUE, 
                                         aFile);
        case Unix_LibDirectory:
            return NS_NewNativeLocalFile(nsDependentCString("/usr/local/lib/netscape/"), 
                                         PR_TRUE, 
                                         aFile);

        case Unix_HomeDirectory:
            return GetUnixHomeDir(aFile);

        case Unix_DesktopDirectory:
        {
            nsCOMPtr<nsILocalFile> home;
            nsresult rv = GetUnixHomeDir(getter_AddRefs(home));
            if (NS_FAILED(rv))
                return rv;
            rv = home->AppendNative(NS_LITERAL_CSTRING("Desktop"));
            if (NS_FAILED(rv))
                return rv;
            PRBool exists;
            rv = home->Exists(&exists);
            if (NS_FAILED(rv))
                return rv;
            if (!exists)
                return GetUnixHomeDir(aFile);
              
            NS_ADDREF(*aFile = home);
            return NS_OK;
        }
#endif

#ifdef XP_BEOS
        case BeOS_SettingsDirectory:
        {
            return GetBeOSFolder(B_USER_SETTINGS_DIRECTORY,0, aFile);
        }

        case BeOS_HomeDirectory:
        {
            return GetBeOSFolder(B_USER_DIRECTORY,0, aFile);
        }

        case BeOS_DesktopDirectory:
        {
            /* Get the user's desktop folder, which in the future may differ from the boot desktop */
            char path[MAXPATHLEN];
            if (find_directory(B_USER_DIRECTORY, 0, false, path, MAXPATHLEN) != B_OK )
                break;
            return GetBeOSFolder(B_DESKTOP_DIRECTORY, dev_for_path(path), aFile);
        }

        case BeOS_SystemDirectory:
        {
            return GetBeOSFolder(B_BEOS_DIRECTORY,0, aFile);
        }
#endif        
#ifdef XP_OS2
        case OS2_SystemDirectory:
        {
            ULONG ulBootDrive = 0;
            char  buffer[] = " :\\OS2\\System\\";
            DosQuerySysInfo( QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
                             &ulBootDrive, sizeof ulBootDrive);
            buffer[0] = 'A' - 1 + ulBootDrive; // duh, 1-based index...

            return NS_NewNativeLocalFile(nsDependentCString(buffer), 
                                         PR_TRUE, 
                                         aFile);
        }

     case OS2_OS2Directory:
        {
            ULONG ulBootDrive = 0;
            char  buffer[] = " :\\OS2\\";
            DosQuerySysInfo( QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
                             &ulBootDrive, sizeof ulBootDrive);
            buffer[0] = 'A' - 1 + ulBootDrive; // duh, 1-based index...

            return NS_NewNativeLocalFile(nsDependentCString(buffer), 
                                         PR_TRUE, 
                                         aFile);
        }

     case OS2_HomeDirectory:
        {
            nsresult rv;
            char *tPath = PR_GetEnv("MOZILLA_HOME");
            char buffer[CCHMAXPATH];
            /* If MOZILLA_HOME is not set, use GetCurrentProcessDirectory */
            /* To ensure we get a long filename system */
            if (!tPath || !*tPath) {
                PPIB ppib;
                PTIB ptib;
                DosGetInfoBlocks( &ptib, &ppib);
                DosQueryModuleName( ppib->pib_hmte, CCHMAXPATH, buffer);
                *strrchr( buffer, '\\') = '\0'; // XXX DBCS misery
                tPath = buffer;
            }
            rv = NS_NewNativeLocalFile(nsDependentCString(tPath),
                                       PR_TRUE, 
                                       aFile);

            PrfWriteProfileString(HINI_USERPROFILE, "Mozilla", "Home", tPath);
            return rv;
        }

        case OS2_DesktopDirectory:
        {
            char szPath[CCHMAXPATH + 1];        
            BOOL fSuccess;
            fSuccess = WinQueryActiveDesktopPathname (szPath, sizeof(szPath));
            if (!fSuccess) {
                // this could happen if we are running without the WPS, return
                // the Home directory instead
                return GetSpecialSystemDirectory(OS2_HomeDirectory, aFile);
            }
            int len = strlen (szPath);   
            if (len > CCHMAXPATH -1)
                break;
            szPath[len] = '\\';     
            szPath[len + 1] = '\0';

            return NS_NewNativeLocalFile(nsDependentCString(szPath),
                                         PR_TRUE, 
                                         aFile);
        }
#endif
        default:
            break;
    }
    return NS_ERROR_NOT_AVAILABLE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 166 of file SpecialSystemDirectory.cpp.

{
#if defined (XP_WIN)
    if (gShell32DLLInst)
    {
        FreeLibrary(gShell32DLLInst);
        gShell32DLLInst = NULL;
        gGetSpecialFolderPath = NULL;
    }
#endif
}

Here is the caller graph for this function:

Definition at line 136 of file SpecialSystemDirectory.cpp.

{
#if defined (XP_WIN) && !defined (WINCE)
    /* On windows, the old method to get file locations is incredibly slow.
       As of this writing, 3 calls to GetWindowsFolder accounts for 3% of mozilla
       startup. Replacing these older calls with a single call to SHGetSpecialFolderPath
       effectively removes these calls from the performace radar.  We need to 
       support the older way of file location lookup on systems that do not have
       IE4. 
    */ 
    gShell32DLLInst = LoadLibrary("Shell32.dll");
    if(gShell32DLLInst)
    {
        if (NS_UseUnicode())
        {
            gGetSpecialFolderPath = (nsGetSpecialFolderPathW) 
                GetProcAddress(gShell32DLLInst, "SHGetSpecialFolderPathW");
        }
        else 
        {
            gGetSpecialFolderPathA = (nsGetSpecialFolderPathA)
                GetProcAddress(gShell32DLLInst, "SHGetSpecialFolderPathA");
            // need to check because it's not available on Win95 without IE.
            if (gGetSpecialFolderPathA)
                gGetSpecialFolderPath = NS_GetSpecialFolderPath;
        }
    }
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function: