if (NS_SUCCEEDED(rv)) { nsIRegistry::Key key;
if (aProfile == nsnull) return NS_ERROR_FAILURE;
NS_IMETHODIMP nsProfile::GetProfileDir(const char *profileName, nsFileSpec* profileDir){    nsresult rv = NS_OK;#if defined(DEBUG_profile)    printf("ProfileManager : GetProfileDir\n");#endif    // Check result.    if ( m_reg != nsnull ) 	{        // Latch onto the registry object.        NS_ADDREF(m_reg);        // Open the registry        rv = m_reg->Open();		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))				{					char* encodedProfileDir = nsnull;					// Get the value of entry "directory"			        rv = m_reg->GetString( newKey, "directory", &encodedProfileDir );					if (NS_SUCCEEDED(rv))					{						char* isMigrated = nsnull;												// Use persistent classes to make the directory names XPlatform						nsInputStringStream stream(encodedProfileDir);						nsPersistentFileDescriptor descriptor;						stream >> descriptor;						*profileDir = descriptor;						PR_FREEIF(encodedProfileDir);						// Get the value of entry "migrated" to check the nature of the profile						m_reg->GetString( newKey, "migrated", &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					        }						}					}					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			}			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;}