CreateDefaultProfileDirectorySpec(currProfileDirSpec);
static void 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.//----------------------------------------------------------------------------------------{    static nsFileSpec* gProfileDir = nsnull;        // pointer so that we can detect whether it has been initialized    if (!gProfileDir)    {        // First time, initialize gProfileDir        nsIProfile *profileService = nsnull;        gProfileDir = new nsFileSpec;        if (!gProfileDir)            return;        nsresult rv = nsServiceManager::GetService(            kProfileCID,             nsIProfile::GetIID(),             (nsISupports **)&profileService);        if (NS_SUCCEEDED(rv))        {            char* currProfileName = nsnull;            nsFileSpec currProfileDirSpec;                        profileService->Startup(nsnull);            int numProfiles = 0;            profileService->GetProfileCount(&numProfiles);            if (numProfiles == 0)            {    		        // no profiles exist: create "default" profile		        CreateDefaultProfileDirectorySpec(currProfileDirSpec);	            profileService->SetProfileDir("default", currProfileDirSpec);	            currProfileName = PL_strdup("default");	        }	        else if (numProfiles == 1)	        {	            // one profile exists: use that profile	            profileService->GetSingleProfile(&currProfileName);	            profileService->GetProfileDir(currProfileName, &currProfileDirSpec);	        }		    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)		        {		            profileService->GetProfileDir(currProfileName, &currProfileDirSpec);		        }		        else		        {		            profileService->GetFirstProfile(&currProfileName);		            profileService->GetProfileDir(currProfileName, &currProfileDirSpec);		        }		    }		    if (currProfileName)		    {#if defined(XP_PC) && defined(NS_DEBUG)		        // Don't print in release version. Don't use stderr in XP code.		        fprintf(stderr, "ProfileName : %s\n", currProfileName);		        fprintf(stderr, "ProfileDir  : %s\n", currProfileDirSpec.GetCString());#endif		        PR_FREEIF(currProfileName);            }            if (!currProfileDirSpec.Exists())                currProfileDirSpec.CreateDir();            if (NS_FAILED(profileService->GetCurrentProfileDir(gProfileDir)))            {                delete gProfileDir; // All that for nothing.  sigh.                gProfileDir = nsnull;            }                            nsServiceManager::ReleaseService(kProfileCID, profileService);        }        if (!gProfileDir)        {            gProfileDir = new nsFileSpec;            if (gProfileDir)                CreateDefaultProfileDirectorySpec(*gProfileDir);        }        if (gProfileDir && !gProfileDir->Exists())            gProfileDir->CreateDir();    }    if (gProfileDir)    {        outSpec = *gProfileDir;    }} // GetProfileDirectory