PRBool openalready = PR_FALSE;
NS_IMETHODIMP nsProfile::DeleteProfile(const char* profileName, const char* canDeleteFiles){    nsresult rv = NS_OK;    PRBool openalready = PR_FALSE;     #if defined(DEBUG_profile)    printf("ProfileManager : DeleteProfile\n");#endif    	nsFileSpec profileDirSpec;	GetProfileDir(profileName, &profileDirSpec);	// To be more uniform need to change the arragement	// of the following with NS_SUCCEEDED()	// Check result.    if ( m_reg != nsnull ) 	{        // Open the registry.		rv = m_reg->IsOpen( &openalready );				if ( !openalready )			rv = m_reg->OpenDefault();        if (NS_FAILED(rv))        {#if defined(DEBUG_profile)				printf("Error opening Registry.\n" );#endif            return rv;        }		#if defined(DEBUG_profile)			printf("Registry opened OK.\n" );#endif        nsIRegistry::Key key;        rv = m_reg->GetSubtree(nsIRegistry::Common, "Profiles", &key);        if (NS_FAILED(rv))        {#if defined(DEBUG_profile)				printf("Can't obtain subtree Profiles.\n" );#endif            return rv;        }		// Remove the subtree from the registry.        rv = m_reg->RemoveSubtree(key, profileName);        if (NS_FAILED(rv))           return rv;		else		{#if defined(DEBUG_profile) 				printf("DeleteProfile : deleted profile -> %s <-\n", profileName);#endif		}		// May need to delete directories, but not so directly.		// DeleteUserDirectories(profileDirSpec);		// Take care of the current profile, if the profile 		// just deleted was a current profile.		if (!renameCurrProfile)		{			char *oldCurrProfile = nsnull;			char *newCurrProfile = nsnull;			GetCurrentProfile(&oldCurrProfile);			if (PL_strcmp(profileName, oldCurrProfile) == 0)			{				GetFirstProfile(&newCurrProfile);#if defined(DEBUG_profile) 					printf("DeleteProfile : Old Current profile -> %s <-\n", oldCurrProfile);					printf("DeleteProfile : New Current profile -> %s <-\n", newCurrProfile);#endif				rv = m_reg->SetString(key, "CurrentProfile", newCurrProfile);			    if (NS_FAILED(rv)) 				{#if defined(DEBUG_profile) 					   printf("Did not take nsnull successfully\n");#endif				}			}		}		if (!openalready)			m_reg->Close();    }	// If user asks for it, delete profile directory	if (PL_strcmp(canDeleteFiles, "true") == 0)	{		DeleteUserDirectories(profileDirSpec);	}    return rv;}