PRBool available = PR_FALSE; profileService->IsCurrentProfileAvailable(&available); if (!available) return PR_FALSE;
static PRBool GetProfileDirectory(nsFileSpec& outSpec)// The app profile directory comes from the profile manager.// Once the profile manager knows which profile needs to be// accessed it tells us about the directory. // And if the profile manager doesn't return anything, we use the routine above,// CreateDefaultProfileDirectorySpec() above.//----------------------------------------------------------------------------------------{        // pointer so that we can detect whether it has been initialized    if (!gProfileDir)    {        // First time, initialize gProfileDir        nsresult rv;        NS_WITH_SERVICE(nsIProfile, profileService, kProfileCID, &rv);        if (NS_FAILED(rv))            return PR_FALSE;                profileService->Startup(nsnull);        int numProfiles = 0;        profileService->GetProfileCount(&numProfiles);        if (numProfiles == 0)            return PR_FALSE;        char* currProfileName = nsnull;        nsFileSpec currProfileDirSpec;        if (numProfiles == 1)        {            // one profile exists: use that profile            profileService->GetFirstProfile(&currProfileName);	    if (currProfileName && (PL_strlen(currProfileName) > 0)) {            	profileService->GetProfileDir(currProfileName, &currProfileDirSpec);	    }	    else {		// this should never happen		PR_FREEIF(currProfileName);		return PR_FALSE;	    }        }	    else	    {		    // multiple profiles exist: we'll use the same profile as last time 		    // (see following rules) 		    // (if we can't figure out what the last profile used was for some reason, 		    // we'll pick the first one as returned from the registry query) 	        profileService->GetCurrentProfile(&currProfileName);	        if (currProfileName && (PL_strlen(currProfileName) > 0)) {	            profileService->GetProfileDir(currProfileName, &currProfileDirSpec);		}	        else	        {	            profileService->GetFirstProfile(&currProfileName);	            if (currProfileName && (PL_strlen(currProfileName) > 0)) {			    profileService->GetProfileDir(currProfileName, &currProfileDirSpec);		    }	        }	    }	if (!currProfileName || (PL_strlen(currProfileName) == 0)) {		// we don't have it, return false.		PR_FREEIF(currProfileName);		return PR_FALSE;	}    #if defined(NS_DEBUG)	if (currProfileName) {		printf("ProfileName : %s\n", currProfileName);		printf("ProfileDir  : %s\n", currProfileDirSpec.GetNativePathCString());	}#endif /* NS_DEBUG */        PR_FREEIF(currProfileName);        if (!currProfileDirSpec.Exists())            currProfileDirSpec.CreateDir();        // Copy into our cached pointer so we'll only do this once (unless told to 'forget').        // We also do this by querying the profile manager, instead of just using        // our local copy (currProfileDirSpec), though they should be the same.        gProfileDir = new nsFileSpec("Default");        if (!gProfileDir)            return PR_FALSE;        if (NS_FAILED(profileService->GetCurrentProfileDir(gProfileDir)))        {            delete gProfileDir; // All that for nothing.  sigh.            gProfileDir = nsnull;        }        NS_ASSERTION(*gProfileDir == currProfileDirSpec, "Profile spec does not match!");    }    if (!gProfileDir)        return PR_FALSE;    if (!gProfileDir->Exists())        gProfileDir->CreateDir();    outSpec = *gProfileDir;    return PR_TRUE;} // GetProfileDirectory