nsCOMPtr<nsIFileSpec>spec; rv = NS_NewFileSpec(getter_AddRefs(spec)); if (NS_FAILED(rv)) return rv; rv = spec->SetPersistentDescriptorString(encodedProfileDir); if (NS_FAILED(rv)) return rv; rv = spec->GetFileSpec(profileDir); if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIFile> profDefaultsDir; rv = NS_GetSpecialDirectory(NS_APP_PROFILE_DEFAULTS_50_DIR, getter_AddRefs(profDefaultsDir)); if (NS_FAILED(rv)) return rv; rv = profDefaultsDir->Exists(&exists); if (NS_SUCCEEDED(rv) && exists) rv = RecursiveCopy(profDefaultsDir, aProfileDir); } }
NS_IMETHODIMP nsProfile::GetProfileDir(const char *profileName, nsFileSpec* profileDir){    nsresult rv = NS_OK;    PRBool openalready = PR_FALSE;#if defined(DEBUG_profile)    printf("ProfileManager : GetProfileDir\n");#endif    // Check result.    if ( m_reg != nsnull ) 	{        // Open the registry		rv = m_reg->IsOpen( &openalready );				if ( !openalready )			rv = m_reg->OpenDefault();		if (NS_SUCCEEDED(rv))		{			nsIRegistry::Key key;			// Get handle to subtree "Profiles"			rv = m_reg->GetSubtree(nsIRegistry::Common, "Profiles", &key);			if (NS_SUCCEEDED(rv))			{		        nsIRegistry::Key newKey;				// Get handle to <profileName> passed				rv = m_reg->GetSubtree(key, profileName, &newKey);				if (NS_SUCCEEDED(rv))				{					nsXPIDLCString encodedProfileDir;					// Get the value of entry "directory"			        rv = m_reg->GetString( newKey, "directory", getter_Copies(encodedProfileDir));					if (NS_SUCCEEDED(rv))					{						nsXPIDLCString isMigrated;						nsCOMPtr<nsIFileSpec>spec;						rv = NS_NewFileSpec(getter_AddRefs(spec));						if (NS_FAILED(rv)) return rv;						rv = spec->SetPersistentDescriptorString(encodedProfileDir);						if (NS_FAILED(rv)) return rv;						rv = spec->GetFileSpec(profileDir);						if (NS_FAILED(rv)) return rv;						// Get the value of entry "migrated" to check the nature of the profile						m_reg->GetString( newKey, "migrated",                                          getter_Copies(isMigrated));										// Set this to be a current profile only if it is a 5.0 profile						if (PL_strcmp(isMigrated, "yes") == 0)						{							rv = m_reg->SetString(key, "CurrentProfile", profileName);																				if (NS_FAILED(rv))							{#if defined(DEBUG_profile)									printf("Profiles : Couldn't set CurrentProfile Name.\n");#endif					        }							nsFileSpec tmpFileSpec(*profileDir);							if (!tmpFileSpec.Exists()) {							    								// Get profile defaults folder..                              					NS_WITH_SERVICE(nsIFileLocator, locator, kFileLocatorCID, &rv);								if (NS_FAILED(rv) || !locator)									return NS_ERROR_FAILURE;								nsCOMPtr <nsIFileSpec> profDefaultsDir;								rv = locator->GetFileLocation(nsSpecialFileSpec::App_ProfileDefaultsFolder50, getter_AddRefs(profDefaultsDir));        								if (NS_FAILED(rv) || !profDefaultsDir)									return NS_ERROR_FAILURE;								nsFileSpec defaultsDirSpec;											profDefaultsDir->GetFileSpec(&defaultsDirSpec);								// Copy contents from defaults folder.								if (defaultsDirSpec.Exists())								{									defaultsDirSpec.RecursiveCopy(tmpFileSpec);								}							}						}					}					else					{#if defined(DEBUG_profile)							printf("Profiles : Couldn't get Profile directory name.\n");#endif					}				}				else				{#if defined(DEBUG_profile)						printf("Profiles : Couldn't get profileName subtree.\n");#endif				}			}			else			{#if defined(DEBUG_profile)					printf("Registry : Couldn't get Profiles subtree.\n");#endif			}			if (!openalready)				m_reg->Close();		}		else		{#if defined(DEBUG_profile)				printf("Couldn't open registry.\n");#endif		}		    }	else	{#if defined(DEBUG_profile)        printf("Registry Object is NULL.\n");#endif		return NS_ERROR_FAILURE;	}    return rv;}