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
GetSpecialSystemDirectory(SystemDirectories aSystemSystemDirectory,                         nsILocalFile** aFile){    char path[MAXPATHLEN];#ifdef XP_MAC    OSErr err;    short vRefNum;    long dirID;#endif    switch (aSystemSystemDirectory)    {        case OS_CurrentWorkingDirectory:#if defined(XP_WIN)            if (!_getcwd(path, MAXPATHLEN))                return NS_ERROR_FAILURE;#elif defined(XP_OS2)            if (DosQueryPathInfo( ".", FIL_QUERYFULLNAME, path, MAXPATHLEN))                return NS_ERROR_FAILURE;#else            if(!getcwd(path, MAXPATHLEN))                return NS_ERROR_FAILURE;#endif            return NS_NewNativeLocalFile(nsDependentCString(path),                                          PR_TRUE,                                          aFile);        case OS_DriveDirectory:#if defined (XP_WIN)        {            PRInt32 len = GetWindowsDirectory( path, _MAX_PATH );            if (len)            {                if ( path[1] == ':' && path[2] == '\\' )                    path[3] = 0;            }            return NS_NewNativeLocalFile(nsDependentCString(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);        }#elif defined(XP_MAC)        {            return nsIFileFromOSType(kVolumeRootFolderType, aFile);        }#else        return NS_NewNativeLocalFile(nsDependentCString("/"),                                      PR_TRUE,                                      aFile);#endif                    case OS_TemporaryDirectory:#if defined (XP_WIN) && !defined (WINCE)        {            DWORD len = GetTempPath(_MAX_PATH, path);            return NS_NewNativeLocalFile(nsDependentCString(path),                                          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);            }            return NS_NewNativeLocalFile(nsDependentCString(buffer),                                          PR_TRUE,                                          aFile);        } #elif defined(XP_MAC)        return nsIFileFromOSType(kTemporaryFolderType, 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_MAC)        case Mac_SystemDirectory:            return nsIFileFromOSType(kSystemFolderType, aFile);        case Mac_DesktopDirectory:            return nsIFileFromOSType(kDesktopFolderType, aFile);        case Mac_TrashDirectory:            return nsIFileFromOSType(kTrashFolderType, aFile);        case Mac_StartupDirectory:            return nsIFileFromOSType(kStartupFolderType, aFile);        case Mac_ShutdownDirectory:            return nsIFileFromOSType(kShutdownFolderType, aFile);        case Mac_AppleMenuDirectory:            return nsIFileFromOSType(kAppleMenuFolderType, aFile);        case Mac_ControlPanelDirectory:            return nsIFileFromOSType(kControlPanelFolderType, aFile);        case Mac_ExtensionDirectory:            return nsIFileFromOSType(kExtensionFolderType, aFile);        case Mac_FontsDirectory:            return nsIFileFromOSType(kFontsFolderType, aFile);        case Mac_ClassicPreferencesDirectory:        {            // whether Mac OS X or pre-Mac OS X, return Classic's Prefs folder            short domain;            long response;            err = ::Gestalt(gestaltSystemVersion, &response);            domain = (!err && response >= 0x00001000) ? kClassicDomain : kOnSystemDisk;            err = ::FindFolder(domain, kPreferencesFolderType, true, &vRefNum, &dirID);            if (!err) {                err = ::FSMakeFSSpec(vRefNum, dirID, "\p", &mSpec);            }            return NS_FILE_RESULT(err);        }        case Mac_PreferencesDirectory:        {            // if Mac OS X, return Mac OS X's Prefs folder            // if pre-Mac OS X, return Mac OS's Prefs folder            err = ::FindFolder(kOnSystemDisk, kPreferencesFolderType, true, &vRefNum, &dirID);            if (!err) {                err = ::FSMakeFSSpec(vRefNum, dirID, "\p", &mSpec);            }            return NS_FILE_RESULT(err);        }        case Mac_DocumentsDirectory:            return nsIFileFromOSType(kDocumentsFolderType, aFile);        case Mac_InternetSearchDirectory:            return nsIFileFromOSType(kInternetSearchSitesFolderType, aFile);        case Mac_DefaultDownloadDirectory:            return nsIFileFromOSType(kDefaultDownloadFolderType, aFile);                    case Mac_UserLibDirectory:        {            FSSpec spec;            err = ::FindFolder(kUserDomain, kDomainLibraryFolderType, true, &vRefNum, &dirID);            if (!err) {                err = ::FSMakeFSSpec(vRefNum, dirID, "\p", &spec);            }            return NS_NewLocalFileWithFSSpec(&spec, PR_FALUE, aFile);        }#endif            #if defined (XP_WIN)        case Win_SystemDirectory:        {                PRInt32 len = GetSystemDirectory( path, _MAX_PATH );                    // Need enough space to add the trailing backslash            if (len > _MAX_PATH-2)                break;            path[len]   = '\\';            path[len+1] = '\0';            return NS_NewNativeLocalFile(nsDependentCString(path),                                          PR_TRUE,                                          aFile);        }        case Win_WindowsDirectory:        {                PRInt32 len = GetWindowsDirectory( path, _MAX_PATH );                        // Need enough space to add the trailing backslash            if (len > _MAX_PATH-2)                break;                        path[len]   = '\\';            path[len+1] = '\0';            return NS_NewNativeLocalFile(nsDependentCString(path),                                          PR_TRUE,                                          aFile);        }        case Win_HomeDirectory:        {                if (GetEnvironmentVariable(TEXT("HOME"), path, _MAX_PATH) > 0)            {                PRInt32 len = strlen(path);                // Need enough space to add the trailing backslash                if (len > _MAX_PATH - 2)                    break;                               path[len]   = '\\';                path[len+1] = '\0';                return NS_NewNativeLocalFile(nsDependentCString(path),                                              PR_TRUE,                                              aFile);            }            if (GetEnvironmentVariable(TEXT("HOMEDRIVE"), path, _MAX_PATH) > 0)            {                char temp[_MAX_PATH];                if (GetEnvironmentVariable(TEXT("HOMEPATH"), temp, _MAX_PATH) > 0)                   strncat(path, temp, _MAX_PATH);                        PRInt32 len = strlen(path);                // Need enough space to add the trailing backslash                if (len > _MAX_PATH - 2)                    break;                            path[len]   = '\\';                path[len+1] = '\0';                                return NS_NewNativeLocalFile(nsDependentCString(path),                                              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);        }#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:#ifdef VMS        {            char *pHome;            pHome = getenv("HOME");            if (*pHome == '/') {                return NS_NewNativeLocalFile(nsDependentCString(pHome),                                              PR_TRUE,                                              aFile);            }            else            {                return NS_NewNativeLocalFile(nsDependentCString(decc$translate_vms(pHome)),                                              PR_TRUE,                                              aFile);            }         }#else            return NS_NewNativeLocalFile(nsDependentCString(PR_GetEnv("HOME")),                                              PR_TRUE,                                              aFile);#endif#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));            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;}