PRBool openalready = PR_FALSE;
NS_IMETHODIMP nsProfile::Get4xProfileCount(int *numProfiles){    nsresult rv = NS_OK;    PRBool openalready = PR_FALSE;     #if defined(DEBUG_profile)    printf("ProfileManager : Get4xProfileCount\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))		{			// Enumerate all subkeys (immediately) under the given node.			nsCOMPtr<nsIEnumerator> enumKeys;			nsIRegistry::Key key;			rv = m_reg->GetSubtree(nsIRegistry::Common, "Profiles", &key);			if (NS_SUCCEEDED(rv))			{		        rv = m_reg->EnumerateSubtrees( key, getter_AddRefs(enumKeys));				if (NS_SUCCEEDED(rv))				{			        int numKeys=0;					rv = enumKeys->First();			        while( NS_SUCCEEDED( rv ) && (NS_OK != enumKeys->IsDone()) ) 					{						nsCOMPtr<nsISupports> base;						rv = enumKeys->CurrentItem(getter_AddRefs(base));						if (NS_SUCCEEDED(rv)) 						{	                        // Get specific interface.		                    nsIRegistryNode *node;			                nsIID nodeIID = NS_IREGISTRYNODE_IID;							rv = base->QueryInterface( nodeIID, (void**)&node );					        						    // Test that result.							if (NS_SUCCEEDED(rv)) 							{								// Get node name.		                        nsXPIDLCString profile;                                nsXPIDLCString isMigrated;                                			                    rv = node->GetName(getter_Copies(profile));								if (NS_SUCCEEDED(rv) && (profile))								{									nsIRegistry::Key profKey;																	rv = m_reg->GetSubtree(key, profile, &profKey);																	if (NS_SUCCEEDED(rv)) 									{										rv = m_reg->GetString(profKey, "migrated", getter_Copies(isMigrated));										if (NS_SUCCEEDED(rv) && (isMigrated))										{											if (PL_strcmp(isMigrated, "no") == 0)											{												numKeys++;											}										}									}								}								NS_RELEASE(node);					        }						}							rv = enumKeys->Next();					}					*numProfiles = numKeys;				}				else				{#if defined(DEBUG_profile)						printf("Profiles : Can't enumerate subtrees.\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;}