rv = NS_GetSpecialDirectory(NS_OS_CURRENT_PROCESS_DIR, getter_AddRefs(parentDir)); if (NS_FAILED(rv)) return rv;
PRBool exists = PR_FALSE; #ifdef XP_PC rv = NS_GetSpecialDirectory(NS_WIN_APPDATA_DIR, getter_AddRefs(parentDir)); if (NS_SUCCEEDED(rv)) rv = parentDir->Exists(&exists); if (NS_FAILED(rv) || !exists) { parentDir = nsnull; rv = NS_GetSpecialDirectory(NS_WIN_WINDOWS_DIR, getter_AddRefs(parentDir)); }  if (NS_FAILED(rv)) return rv; #else rv = NS_GetSpecialDirectory(NS_OS_HOME_DIR, getter_AddRefs(parentDir));  if (NS_SUCCEEDED(rv)) rv = parentDir->Exists(&exists); if (NS_FAILED(rv) || !exists) return rv; #endif
static nsresult InitializeProfileService(nsICmdLineService *cmdLineArgs){    nsresult rv;    PRBool standaloneApp = PR_FALSE;     NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &rv);     if (NS_FAILED(rv)) return rv;     rv = prefs->GetBoolPref(STANDALONE_APP_PREF, &standaloneApp);     if (NS_SUCCEEDED(rv) && standaloneApp)     {         nsMPFileLocProvider *fileLocProvider = new nsMPFileLocProvider;         NS_ENSURE_TRUE(fileLocProvider, NS_ERROR_OUT_OF_MEMORY);         // Specify the dir that standalone app will use for its "profile" dir         nsCOMPtr<nsIFile> parentDir;         rv = NS_GetSpecialDirectory(NS_OS_CURRENT_PROCESS_DIR, getter_AddRefs(parentDir));         if (NS_FAILED(rv)) return rv;         // Get standalone app dir name from prefs and initialize mpfilelocprovider        nsXPIDLCString appDir;        rv = prefs->CopyCharPref(STANDALONE_APP_DIR_PREF, getter_Copies(appDir));        if (NS_FAILED(rv) || (nsCRT::strlen(appDir) == 0))             return NS_ERROR_FAILURE;         rv = fileLocProvider->Initialize(parentDir, appDir);         if (NS_FAILED(rv)) return rv;         rv = prefs->ResetPrefs();         if (NS_FAILED(rv)) return rv;         rv = prefs->ReadUserPrefs();         if (NS_FAILED(rv)) return rv;     }     else     {         nsCOMPtr<nsIProfile> profileMgr = do_GetService(kProfileCID, &rv);        NS_ASSERTION(NS_SUCCEEDED(rv), "failed to get profile manager");        if (NS_FAILED(rv)) return rv;        rv = profileMgr->StartupWithArgs(cmdLineArgs);        if (NS_FAILED(rv)) return rv;        // if we get here, and we don't have a current profile, return a failure so we will exit        // this can happen, if the user hits Cancel or Exit in the profile manager dialogs        nsXPIDLString currentProfileStr;        rv = profileMgr->GetCurrentProfile(getter_Copies(currentProfileStr));        if (NS_FAILED(rv) || !((const PRUnichar *)currentProfileStr) ||                            (nsCRT::strlen((const PRUnichar *)currentProfileStr) == 0)) {  	    return NS_ERROR_FAILURE;        }    }    return rv;}