if (canDeleteFiles) { nsFileSpec profileDirSpec;  nsCOMPtr<nsIFile> profileDir; rv = GetProfileDir(profileName, getter_AddRefs(profileDir)); if (NS_FAILED(rv)) return rv;  nsCOMPtr<nsILocalFile> localProfileDir(do_QueryInterface(profileDir)); if (!localProfileDir) return NS_ERROR_FAILURE; rv = DeleteUserDirectories(localProfileDir); if (NS_FAILED(rv)) return rv;
nsFileSpec profileDirSpec; GetProfileDir(profileName, &profileDirSpec);     if ( m_reg != nsnull ) {  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; }   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 }       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();
NS_IMETHODIMP nsProfile::DeleteProfile(const PRUnichar* profileName, PRBool canDeleteFiles){    NS_ENSURE_ARG_POINTER(profileName);       nsresult rv = NS_OK;     rv = ForgetCurrentProfile();    if (NS_FAILED(rv)) return rv;        // If user asks for it, delete profile directory    if (canDeleteFiles) {        nsFileSpec profileDirSpec;                nsCOMPtr<nsIFile> profileDir;        rv = GetProfileDir(profileName, getter_AddRefs(profileDir));        if (NS_FAILED(rv)) return rv;                nsCOMPtr<nsILocalFile> localProfileDir(do_QueryInterface(profileDir));        if (!localProfileDir) return NS_ERROR_FAILURE;        rv = DeleteUserDirectories(localProfileDir);        if (NS_FAILED(rv)) return rv;    }    // Remove the subtree from the registry.    gProfileDataAccess->RemoveSubTree(profileName);    if (NS_FAILED(rv)) return rv;    gProfileDataAccess->mProfileDataChanged = PR_TRUE;    gProfileDataAccess->UpdateRegistry(nsnull);    return rv;}