printf("ProfileName : %s\n", currProfileNameCStr.GetBuffer()); printf("ProfileDir  : %s\n", currProfileDirSpec.GetNativePathCString());
PRINTF("ProfileName : %s\n", currProfileNameCStr.GetBuffer()); PRINTF("ProfileDir  : %s\n", currProfileDirSpec.GetNativePathCString());
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);        PRBool available = PR_FALSE;        profileService->IsCurrentProfileAvailable(&available);        if (!available)            return PR_FALSE;        int numProfiles = 0;        profileService->GetProfileCount(&numProfiles);        if (numProfiles == 0)            return PR_FALSE;        PRUnichar* currProfileName;        nsCOMPtr<nsIFile> currProfileDir;        if (numProfiles == 1)        {            // one profile exists: use that profile            profileService->GetFirstProfile(&currProfileName);            if (currProfileName && (nsCRT::strlen(currProfileName) > 0)) {                profileService->GetProfileDir(currProfileName, getter_AddRefs(currProfileDir));            }            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 && (nsCRT::strlen(currProfileName) > 0)) {                profileService->GetProfileDir(currProfileName, getter_AddRefs(currProfileDir));            }            else            {                profileService->GetFirstProfile(&currProfileName);                if (currProfileName && currProfileName[0]) {                    profileService->GetProfileDir(currProfileName, getter_AddRefs(currProfileDir));                }            }        }        if (!currProfileName || (nsCRT::strlen(currProfileName) == 0)) {            // we don't have it, return false.            PR_FREEIF(currProfileName);            return PR_FALSE;        }                    nsFileSpec currProfileDirSpec;        nsXPIDLCString pathBuf;        rv = currProfileDir->GetPath(getter_Copies(pathBuf));        if (NS_FAILED(rv)) return PR_FALSE;        currProfileDirSpec = (const char *)pathBuf;    #if defined(NS_DEBUG)    if (currProfileName) {        nsCAutoString currProfileNameCStr; currProfileNameCStr.AssignWithConversion(currProfileName);        printf("ProfileName : %s\n", currProfileNameCStr.GetBuffer());        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(getter_AddRefs(currProfileDir))))        {            delete gProfileDir; // All that for nothing.  sigh.            gProfileDir = nsnull;            return PR_FALSE;        }        nsXPIDLCString pathBuf2;        rv = currProfileDir->GetPath(getter_Copies(pathBuf2));        if (NS_FAILED(rv)) return PR_FALSE;        *gProfileDir = (const char *)pathBuf2;        NS_ASSERTION(*gProfileDir == currProfileDirSpec, "Profile spec does not match!");        if (!gProfileDir->Exists())            gProfileDir->CreateDir();    }    if (!gProfileDir)        return PR_FALSE;    outSpec = *gProfileDir;    return PR_TRUE;} // GetProfileDirectory