nsCOMPtr<nsIEnumerator> enumKeys; nsRegistryKey key;  rv = m_reg->GetSubtree(nsIRegistry::Common, REGISTRY_PROFILE_SUBTREE_STRING, &key);  if (NS_SUCCEEDED(rv)) { rv = m_reg->EnumerateSubtrees( key, getter_AddRefs(enumKeys));  if (NS_SUCCEEDED(rv)) {  rv = enumKeys->First();  while(NS_SUCCEEDED(rv)&& (NS_OK != enumKeys->IsDone()) ) { nsCOMPtr<nsISupports> base; rv = enumKeys->CurrentItem(getter_AddRefs(base));  if (NS_SUCCEEDED(rv)) {  nsCOMPtr <nsIRegistryNode> node; nsIID nodeIID = NS_IREGISTRYNODE_IID; rv = base->QueryInterface( nodeIID, getter_AddRefs(node));  if (NS_SUCCEEDED(rv)) { nsXPIDLCString isMigrated; nsRegistryKey profKey;   rv = node->GetName(profileName );    if (NS_SUCCEEDED(rv)) { rv = m_reg->GetSubtree(key, *profileName, &profKey);  m_reg->GetString(profKey, REGISTRY_MIGRATED_STRING, getter_Copies(isMigrated));  if (PL_strcmp(isMigrated, REGISTRY_NO_STRING) == 0) { rv = enumKeys->Next(); continue; } else { if (NS_SUCCEEDED(rv)) { rv = m_reg->SetString(key, REGISTRY_CURRENT_PROFILE_STRING, *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(); } } 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 }
rv = GetSingleProfile(profileName);  if (NS_FAILED(rv)) { #if defined(DEBUG_profile) printf("Couldn't get the first profile.\n" ); #endif }
NS_IMETHODIMP nsProfile::GetFirstProfile(char **profileName){	nsresult rv = NS_OK;#if defined(DEBUG_profile)    printf("ProfileManager : GetFirstProfile\n");#endif    // Enumerate all subkeys (immediately) under the given node.    nsCOMPtr<nsIEnumerator> enumKeys;    nsRegistryKey key;        rv = m_reg->GetSubtree(nsIRegistry::Common, REGISTRY_PROFILE_SUBTREE_STRING, &key);        if (NS_SUCCEEDED(rv))        {            rv = m_reg->EnumerateSubtrees( key, getter_AddRefs(enumKeys));                        if (NS_SUCCEEDED(rv))				{					// Go to beginning.					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.                                    nsCOMPtr <nsIRegistryNode> node;                                    nsIID nodeIID = NS_IREGISTRYNODE_IID;                                    rv = base->QueryInterface( nodeIID, getter_AddRefs(node));                                                                        if (NS_SUCCEEDED(rv))                                        {                                            nsXPIDLCString isMigrated;                                            nsRegistryKey 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, REGISTRY_MIGRATED_STRING, getter_Copies(isMigrated));                                                                                                        if (PL_strcmp(isMigrated, REGISTRY_NO_STRING) == 0)                                                        {                                                            rv = enumKeys->Next();                                                            continue;                                                        }                                                    else                                                        {                                                            if (NS_SUCCEEDED(rv))                                                                {                                                                    rv = m_reg->SetString(key, REGISTRY_CURRENT_PROFILE_STRING, *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				}            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        }    return rv;}