NS_ADDREF(m_reg);
NS_IMETHODIMP nsProfile::GetSingleProfile(char **profileName){	nsresult rv = NS_OK;#if defined(DEBUG_profile)    printf("ProfileManager : GetSingleProfile\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))		{	        // Enumerate all subkeys (immediately) under the given node.		    nsIEnumerator *enumKeys;			nsIRegistry::Key key;	        rv = m_reg->GetSubtree(nsIRegistry::Common, "Profiles", &key);			if (NS_SUCCEEDED(rv))			{		        rv = m_reg->EnumerateSubtrees( key, &enumKeys );				if (NS_SUCCEEDED(rv))				{					// Go to beginning.					rv = enumKeys->First();			        while(NS_SUCCEEDED(rv)&& !enumKeys->IsDone() ) 					{						nsISupports *base;						rv = enumKeys->CurrentItem( &base );								if (NS_SUCCEEDED(rv))						{							// Get specific interface.							nsIRegistryNode *node;							nsIID nodeIID = NS_IREGISTRYNODE_IID;							rv = base->QueryInterface( nodeIID, (void**)&node );		                        							if (NS_SUCCEEDED(rv))							{								char *isMigrated = nsnull;								nsIRegistry::Key profKey;													            // Get node name.					            rv = node->GetName( profileName );									// Profiles need to be migrated are not considered as valid profiles								// On finding the valid profile, breaks out of the while loop.								if (NS_SUCCEEDED(rv))								{									rv = m_reg->GetSubtree(key, *profileName, &profKey);									m_reg->GetString(profKey, "migrated", &isMigrated);									if (PL_strcmp(isMigrated, "no") == 0)									{										rv = enumKeys->Next();										continue;									}									else									{										if (NS_SUCCEEDED(rv))										{										    rv = m_reg->SetString(key, "CurrentProfile", *profileName);														if (NS_SUCCEEDED(rv))											{												break;											}											else											{												#if defined(DEBUG_profile)													printf("RegistryNode : Can't set Current Profile name.\n" );												#endif																						}										}									}								}								else								{									#if defined(DEBUG_profile)										printf("RegistryNode : Couldn't get the node name.\n");									#endif								}							}							else							{								#if defined(DEBUG_profile)									printf("RegistryNode : Couldn't get the interface.\n");								#endif							}						}						else						{							#if defined(DEBUG_profile)								printf("Profiles : Couldn't get current enumerated item.\n");							#endif						}						rv = enumKeys->Next();					} //end while loop					NS_RELEASE(enumKeys);				}				else				{					#if defined(DEBUG_profile)						printf("Profiles : Couldn't enumerate subtrees.\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;}