ProfileStruct* aProfile = new ProfileStruct(); NS_ENSURE_TRUE(aProfile, NS_ERROR_OUT_OF_MEMORY);
NS_IMETHODIMP nsProfile::SetProfileDir(const char *profileName, nsFileSpec& profileDir){    nsresult rv = NS_OK;    PRBool openalready = PR_FALSE;     #if defined(DEBUG_profile)    printf("ProfileManager : SetProfileDir\n");    printf("profileName : %s ", profileName);    nsXPIDLCString profileDirStr;    rv = GetStringFromSpec(profileDir, getter_Copies(profileDirStr));    if (NS_SUCCEEDED(rv) && profileDirStr) {        printf("profileDir  : %s\n", (const char *)profileDirStr);    }#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;			rv = m_reg->GetSubtree(nsIRegistry::Common, "Profiles", &key);			if (NS_SUCCEEDED(rv))			{				nsIRegistry::Key newKey;				rv = m_reg->AddSubtree(key, profileName, &newKey);						if (NS_SUCCEEDED(rv))				{					// Create a tmp Filespec and create a directory if required					nsFileSpec tmpDir(profileDir);					if (!profileDir.Exists())					{						// nsPersistentFileDescriptor requires an existing						// object. Make it first.						tmpDir.CreateDirectory();					}										nsXPIDLCString profileDirString;                    										nsCOMPtr<nsIFileSpec>spec;					rv = NS_NewFileSpecWithSpec(profileDir, getter_AddRefs(spec));					if (NS_SUCCEEDED(rv)) {						rv = spec->GetPersistentDescriptorString(getter_Copies(profileDirString));					}    					// Set the entry "directory" for this profile					if (NS_SUCCEEDED(rv) && profileDirString)					{						rv = m_reg->SetString(newKey, "directory", profileDirString);						CreateUserDirectories(tmpDir);						if (NS_FAILED(rv))						{#if defined(DEBUG_profile)								printf("Couldn't set directory property.\n" );#endif						}												// A 5.0 profile needs no migration.						// Hence setting migrated flag to "yes"						// Need to change this logic to "migrate" = true/false.						rv = m_reg->SetString( newKey, "migrated", "yes");					}					else					{#if defined(DEBUG_profile)							printf("NULL value received for directory name.\n" );#endif					}				}				else				{#if defined(DEBUG_profile)                    printf("Profiles : Could not add profile name subtree.\n" );#endif				}			}			else			{#if defined(DEBUG_profile)					printf("Registry : Couldn't get Profiles subtree.\n");#endif			}			rv = m_reg->SetString(key, "CurrentProfile", profileName);			if (NS_FAILED(rv))			{#if defined(DEBUG_profile)					printf("Couldn't set CurrentProfile name.\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;}