From efb54792ef4623ef88f69ab455b9bea27aff851a Mon Sep 17 00:00:00 2001 From: "gayatrib%netscape.com" Date: Wed, 19 May 1999 04:38:44 +0000 Subject: [PATCH] Added code to support the new profile manager services git-svn-id: svn://10.0.0.236/trunk@32277 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/profile/src/nsProfile.cpp | 933 ++++++++++++++++++++++-------- 1 file changed, 702 insertions(+), 231 deletions(-) diff --git a/mozilla/profile/src/nsProfile.cpp b/mozilla/profile/src/nsProfile.cpp index bd3dae11c5b..467669d0529 100644 --- a/mozilla/profile/src/nsProfile.cpp +++ b/mozilla/profile/src/nsProfile.cpp @@ -54,6 +54,10 @@ static char gNewProfileData[20][_MAX_LENGTH] = {'\0', '\0'}; static int g_Count = 0; +static char gProfiles[50][256] = {'\0'}; +static int g_numProfiles = 0; + + extern "C" NS_EXPORT nsresult NS_RegistryGetFactory(const nsCID &cid, nsISupports* servMgr, nsIFactory** aFactory ); @@ -80,9 +84,12 @@ public: virtual ~nsProfile(); static nsProfile *GetInstance(); - void CreateUserDirectories(const nsFileSpec& profileDir); - void SetDataArray(nsString data); - char* GetValue(char *name); + void CreateUserDirectories(const nsFileSpec& profileDir); + void SetDataArray(nsString data); + char* GetValue(char *name); + nsresult CopyRegKey(const char *oldProfile, const char *newProfile); + void GetAllProfiles(); + // Initialize/shutdown NS_IMETHOD Startup(char *registry); NS_IMETHOD Shutdown(); @@ -97,8 +104,12 @@ public: // Setters NS_IMETHOD SetProfileDir(const char *profileName, const nsFileSpec& profileDir); - // Creators + + // Profile Core supporters NS_IMETHOD CreateNewProfile(char* data); + NS_IMETHOD RenameProfile(const char* aOldName, const char* aNewName); + NS_IMETHOD DeleteProfile(const char* aProfileName); + NS_IMETHOD GetProfileList(nsString& profileList); }; nsProfile* nsProfile::mInstance = nsnull; @@ -106,16 +117,6 @@ nsProfile* nsProfile::mInstance = nsnull; static PRInt32 g_InstanceCount = 0; static PRInt32 g_LockCount = 0; -#ifndef XP_UNIX -/* sspitzer: what is this for? */ -static nsresult _convertRes(int res) -{ - nsresult nsres = NS_OK; - - return nsres; -} -#endif - /* * Constructor/Destructor */ @@ -178,75 +179,91 @@ NS_IMETHODIMP nsProfile::Shutdown() // Gets the profiles directory for a given profile NS_IMETHODIMP nsProfile::GetProfileDir(const char *profileName, nsFileSpec* profileDir) { - nsresult rv; + nsresult rv = NS_OK; #if defined(DEBUG_profile) printf("ProfileManager : GetProfileDir\n"); #endif // Check result. - if ( m_reg != nsnull ) { + if ( m_reg != nsnull ) + { // Latch onto the registry object. NS_ADDREF(m_reg); // Open it against the input file name. rv = m_reg->Open(); - if (NS_FAILED(rv)) - { -#if defined(NS_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("Registry Error OK.\n" ); -#endif - return rv; - } + if (NS_SUCCEEDED(rv)) + { + nsIRegistry::Key key; + rv = m_reg->GetSubtree(nsIRegistry::Common, "Profiles", &key); -#if defined(DEBUG_profile) - printf("Registry:Profiles opened OK.\n" ); -#endif - nsIRegistry::Key newKey; - rv = m_reg->GetSubtree(key, profileName, &newKey); + if (NS_SUCCEEDED(rv)) + { + nsIRegistry::Key newKey; + rv = m_reg->GetSubtree(key, profileName, &newKey); - if (NS_FAILED(rv)) - return rv; + if (NS_SUCCEEDED(rv)) + { + char* encodedProfileDir = nsnull; + rv = m_reg->GetString( newKey, "directory", &encodedProfileDir ); - char* encodedProfileDir = nsnull; - rv = m_reg->GetString( newKey, "directory", &encodedProfileDir ); + if (NS_SUCCEEDED(rv)) + { + + nsInputStringStream stream(encodedProfileDir); + nsPersistentFileDescriptor descriptor; + stream >> descriptor; + *profileDir = descriptor; - if (NS_FAILED(rv)) - { -#ifdef DEBUG_profile - printf( "Error"); -#endif - return rv; - } - - rv = m_reg->SetString(key, "CurrentProfile", profileName); - if (NS_FAILED(rv)) - { -#ifdef DEBUG_profile - printf( "Error"); -#endif - return rv; - } - nsInputStringStream stream(encodedProfileDir); - nsPersistentFileDescriptor descriptor; - stream >> descriptor; - *profileDir = descriptor; - - PR_FREEIF(encodedProfileDir); - m_reg->Close(); + PR_FREEIF(encodedProfileDir); + + rv = m_reg->SetString(key, "CurrentProfile", profileName); + + if (NS_FAILED(rv)) + { + #ifdef DEBUG_profile + printf("Profiles : Couldn't set CurrentProfile Name.\n"); + #endif + } + } + else + { + #ifdef DEBUG_profile + printf("Profiles : Couldn't get Profile directory name.\n"); + #endif + } + } + else + { + #ifdef DEBUG_profile + printf("Profiles : Couldn't get profileName subtree.\n"); + #endif + } + } + else + { + #ifdef DEBUG_profile + printf("Registry : Couldn't get Profiles subtree.\n"); + #endif + } + m_reg->Close(); + } + else + { + #ifdef DEBUG_profile + printf("Couldn't open registry.\n"); + #endif + } } - return NS_OK; + else + { + #ifdef DEBUG_profile + printf("Registry Object is NULL.\n"); + #endif + + return NS_ERROR_FAILURE; + } + return rv; } @@ -254,46 +271,76 @@ NS_IMETHODIMP nsProfile::GetProfileDir(const char *profileName, nsFileSpec* prof // Location: Common/Profiles NS_IMETHODIMP nsProfile::GetProfileCount(int *numProfiles) { - nsresult rv; + nsresult rv = NS_OK; #if defined(DEBUG_profile) printf("ProfileManager : GetProfileCount\n"); #endif // Check result. - if ( m_reg != nsnull ) { + if ( m_reg != nsnull ) + { // Latch onto the registry object. NS_ADDREF(m_reg); // Open it against the input file name. rv = m_reg->Open(); - if (NS_SUCCEEDED(rv)) { -#if defined(DEBUG_profile) - printf("Registry opened OK.\n" ); -#endif - // 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)) { - int numKeys=0; - rv = enumKeys->First(); - // Enumerate subkeys till done. - while( NS_SUCCEEDED( rv ) && !enumKeys->IsDone() ) - { - rv = enumKeys->Next(); - numKeys++; - } - *numProfiles = numKeys; - NS_RELEASE(enumKeys); - } - } - m_reg->Close(); - } + 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)) + { + int numKeys=0; + rv = enumKeys->First(); + + while( NS_SUCCEEDED( rv ) && !enumKeys->IsDone() ) + { + rv = enumKeys->Next(); + numKeys++; + } + *numProfiles = numKeys; + NS_RELEASE(enumKeys); + } + else + { + #ifdef DEBUG_profile + printf("Profiles : Can't enumerate subtrees.\n" ); + #endif + } + } + else + { + #ifdef DEBUG_profile + printf("Registry : Couldn't get Profiles subtree.\n"); + #endif + } + m_reg->Close(); + } + else + { + #ifdef DEBUG_profile + printf("Couldn't open registry.\n"); + #endif + } } + else + { + #ifdef DEBUG_profile + printf("Registry Object is NULL.\n"); + #endif - return NS_OK; + return NS_ERROR_FAILURE; + + } + + return rv; } @@ -301,135 +348,251 @@ NS_IMETHODIMP nsProfile::GetProfileCount(int *numProfiles) // and returns the name of the single profile NS_IMETHODIMP nsProfile::GetSingleProfile(char **profileName) { - nsresult rv; + nsresult rv = NS_OK; #if defined(DEBUG_profile) printf("ProfileManager : GetSingleProfile\n"); #endif // Check result. - if ( m_reg != nsnull ) { + if ( m_reg != nsnull ) + { // Latch onto the registry object. NS_ADDREF(m_reg); // Open it against the input file name. rv = m_reg->Open(); - if (NS_SUCCEEDED(rv)) { -#if defined(DEBUG_profile) - printf("Registry opened OK.\n" ); -#endif - // 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 ); - // Go to beginning. - rv = enumKeys->First(); - if(NS_SUCCEEDED(rv)&& !enumKeys->IsDone() ) { - nsISupports *base; - rv = enumKeys->CurrentItem( &base ); - - // Test result. - 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. - *profileName = (char*) PR_Malloc(sizeof(char)*_MAX_LENGTH); - rv = node->GetName( profileName ); + 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); - // Test result. - if (NS_SUCCEEDED(rv)) { - rv = m_reg->SetString(key, "CurrentProfile", *profileName); - // Print name: -#ifdef DEBUG_profile - printf( "\t\tProfile name: %s", *profileName); -#endif - } - } - } - } - } - + if (NS_SUCCEEDED(rv)) + { + rv = m_reg->EnumerateSubtrees( key, &enumKeys ); + + if (NS_SUCCEEDED(rv)) + { + // Go to beginning. + rv = enumKeys->First(); + + if(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)) + { + // Get node name. + *profileName = (char*) PR_Malloc(sizeof(char)*_MAX_LENGTH); + + rv = node->GetName( profileName ); + + if (NS_SUCCEEDED(rv)) + { + rv = m_reg->SetString(key, "CurrentProfile", *profileName); + + if (NS_FAILED(rv)) + { + #ifdef DEBUG_profile + printf("RegistryNode : Can't set Current Profile name.\n" ); + #endif + } + } + else + { + #ifdef DEBUG_profile + printf("RegistryNode : Couldn't get the node name.\n"); + #endif + } + } + else + { + #ifdef DEBUG_profile + printf("RegistryNode : Couldn't get the interface.\n"); + #endif + } + } + else + { + #ifdef DEBUG_profile + printf("Profiles : Couldn't get current enumerated item.\n"); + #endif + } + } + else + { + #ifdef DEBUG_profile + printf("Profiles : Couldn't get first enumerated key.\n"); + #endif + } + } + else + { + #ifdef DEBUG_profile + printf("Profiles : Couldn't enumerate subtrees.\n"); + #endif + } + } + else + { + #ifdef DEBUG_profile + printf("Registry : Couldn't get Profiles subtree.\n"); + #endif + } m_reg->Close(); - } - } + } + else + { + #ifdef DEBUG_profile + printf("Couldn't open registry.\n"); + #endif + } + } + else + { + #ifdef DEBUG_profile + printf("Registry Object is NULL.\n"); + #endif - return NS_OK; + return NS_ERROR_FAILURE; + } + return rv; } +/***** Need to modify from here for NS_SUCCEDED *****/ // Returns the name of the current profile i.e., the last used profile NS_IMETHODIMP nsProfile::GetCurrentProfile(char **profileName) { - nsresult rv; + nsresult rv = NS_OK; #if defined(DEBUG_profile) - printf("ProfileManager : GetCurrentProfile\n"); + printf("ProfileManager : GetCurrentProfile\n"); #endif - // Check result. - if ( m_reg != nsnull ) { - // Latch onto the registry object. - NS_ADDREF(m_reg); + + // Check result. + if ( m_reg != nsnull ) + { + + // Latch onto the registry object. + NS_ADDREF(m_reg); - // Open it against the input file name. - rv = m_reg->Open(); - if (NS_SUCCEEDED(rv)) - { -#if defined(DEBUG_profile) - printf("Registry opened OK.\n" ); -#endif - nsIRegistry::Key key; - rv = m_reg->GetSubtree(nsIRegistry::Common, "Profiles", &key); - if (NS_SUCCEEDED(rv)) - { - *profileName = (char*) PR_Malloc(sizeof(char)*_MAX_LENGTH); + // Open it against the input file name. + rv = m_reg->Open(); - rv = m_reg->GetString( key, "CurrentProfile", profileName ); - if (NS_SUCCEEDED(rv)) { - - } - else { - profileName = '\0'; - } - } - m_reg->Close(); - } + if (NS_SUCCEEDED(rv)) + { + nsIRegistry::Key key; + rv = m_reg->GetSubtree(nsIRegistry::Common, "Profiles", &key); + + if (NS_SUCCEEDED(rv)) + { + *profileName = (char*) PR_Malloc(sizeof(char)*_MAX_LENGTH); + + rv = m_reg->GetString( key, "CurrentProfile", profileName ); + + if (NS_FAILED(rv)) + { + profileName = '\0'; + + #ifdef DEBUG_profile + printf("Profiles:Can't get Current Profile value.\n" ); + #endif + } + } + else + { + #ifdef DEBUG_profile + printf("Registry : Couldn't get Profiles subtree.\n"); + #endif + } + } + else + { + #ifdef DEBUG_profile + printf("Couldn't open registry.\n"); + #endif + } + m_reg->Close(); } - return NS_OK; + else + { + #ifdef DEBUG_profile + printf("Registry Object is NULL.\n"); + #endif + + return NS_ERROR_FAILURE; + } + return rv; } // Returns the name of the first profile in the Registry NS_IMETHODIMP nsProfile::GetFirstProfile(char **profileName) { + nsresult rv = NS_OK; #if defined(DEBUG_profile) printf("ProfileManager : GetFirstProfile\n"); #endif - GetSingleProfile(profileName); - return NS_OK; + + rv = GetSingleProfile(profileName); + + if (NS_FAILED(rv)) + { + #ifdef DEBUG_profile + printf("Couldn't get the first profile.\n" ); + #endif + } + + return rv; } // Returns the name of the current profile directory NS_IMETHODIMP nsProfile::GetCurrentProfileDir(nsFileSpec* profileDir) { + nsresult rv = NS_OK; #if defined(DEBUG_profile) printf("ProfileManager : GetCurrentProfileDir\n"); #endif char *profileName; - GetCurrentProfile(&profileName); - nsresult rv = GetProfileDir(profileName, profileDir); - PR_DELETE(profileName); + rv = GetCurrentProfile(&profileName); + + if (NS_SUCCEEDED(rv)) + { + rv = GetProfileDir(profileName, profileDir); + + if (NS_FAILED(rv)) + { + #ifdef DEBUG_profile + printf("Couldn't get the profile dir.\n" ); + #endif + } + + } + else + { + #ifdef DEBUG_profile + printf("Couldn't get the current profile.\n" ); + #endif + } + + + PR_DELETE(profileName); return rv; - } + /* * Setters */ @@ -437,72 +600,108 @@ NS_IMETHODIMP nsProfile::GetCurrentProfileDir(nsFileSpec* profileDir) // Sets the current profile directory NS_IMETHODIMP nsProfile::SetProfileDir(const char *profileName, const nsFileSpec& profileDir) { - nsresult rv; + nsresult rv = NS_OK; #if defined(DEBUG_profile) printf("ProfileManager : SetProfileDir\n"); printf("profileName : %s ", profileName); printf("profileDir : %s\n", profileDir.GetCString()); #endif + // Check result. - if (m_reg == nsnull) - return NS_ERROR_NULL_POINTER; + if (m_reg != nsnull) + { + // Latch onto the registry object. + NS_ADDREF(m_reg); - // Latch onto the registry object. - NS_ADDREF(m_reg); + // Open it against the input file name. + rv = m_reg->Open(); + + if (NS_SUCCEEDED(rv)) + { + nsIRegistry::Key key; + rv = m_reg->AddSubtree(nsIRegistry::Common, "Profiles", &key); - // Open it against the input file name. - rv = m_reg->Open(); - if (NS_FAILED(rv)) - { -#if defined(DEBUG_profile) - printf("Registry NOT opened OK.\n" ); -#endif - return rv; - } + if (NS_SUCCEEDED(rv)) + { + nsIRegistry::Key newKey; + rv = m_reg->AddSubtree(key, profileName, &newKey); + + if (NS_SUCCEEDED(rv)) + { -#if defined(DEBUG_profile) - printf("Registry opened OK.\n" ); -#endif - nsIRegistry::Key key; - rv = m_reg->AddSubtree(nsIRegistry::Common, "Profiles", &key); - if (NS_FAILED(rv)) - { -#if defined(DEBUG_profile) - printf("Registry Subtree not added.\n" ); -#endif - return rv; - } + if (!profileDir.Exists()) + { + // nsPersistentFileDescriptor requires an existing + // object. Make it first. + nsFileSpec tmp(profileDir); + tmp.CreateDirectory(); + } + + nsPersistentFileDescriptor descriptor(profileDir); + char* profileDirString = nsnull; + nsOutputStringStream stream(profileDirString); + stream << descriptor; + + if (profileDirString && *profileDirString) + { + rv = m_reg->SetString(newKey, "directory", profileDirString); -#if defined(DEBUG_profile) - printf("Registry:Profiles opened OK.\n" ); -#endif - nsIRegistry::Key newKey; - rv = m_reg->AddSubtree(key, profileName, &newKey); - if (NS_FAILED(rv)) - return rv; + if (NS_FAILED(rv)) + { + #if defined(DEBUG_profile) + printf("Couldn't set directory property.\n" ); + #endif + } - rv = m_reg->SetString(key, "CurrentProfile", profileName); - if (NS_FAILED(rv)) - return rv; + } + else + { + #if defined(DEBUG_profile) + printf("NULL value received for directory name.\n" ); + #endif + } + delete [] profileDirString; + } + else + { + #if defined(DEBUG_profile) + printf("Profiles : Could not add profile name subtree.\n" ); + #endif + } + } + else + { + #ifdef DEBUG_profile + printf("Registry : Couldn't get Profiles subtree.\n"); + #endif + } - if (!profileDir.Exists()) - { - // nsPersistentFileDescriptor requires an existing - // object. Make it first. - nsFileSpec tmp(profileDir); - tmp.CreateDirectory(); - } - nsPersistentFileDescriptor descriptor(profileDir); - char* profileDirString = nsnull; - nsOutputStringStream stream(profileDirString); - stream << descriptor; - if (profileDirString && *profileDirString) - rv = m_reg->SetString(newKey, "directory", profileDirString); - delete [] profileDirString; + rv = m_reg->SetString(key, "CurrentProfile", profileName); - m_reg->Close(); + if (NS_FAILED(rv)) + { + #if defined(DEBUG_profile) + printf("Couldn't set CurrentProfile name.\n" ); + #endif + } + m_reg->Close(); + } + else + { + #ifdef DEBUG_profile + printf("Couldn't open registry.\n"); + #endif + } + } + else + { + #ifdef DEBUG_profile + printf("Registry Object is NULL.\n"); + #endif - return NS_OK; + return NS_ERROR_FAILURE; + } + return rv; } @@ -591,6 +790,7 @@ void nsProfile::SetDataArray(nsString data) printf("ProfileManager : Setting new profile data\n"); printf("SetDataArray data : %s\n", data.ToNewCString()); #endif + int index = 0; char *newStr=nsnull; char *tokstr = data.ToNewCString(); char *token = nsCRT::strtok(tokstr, "%", &newStr); @@ -602,8 +802,9 @@ void nsProfile::SetDataArray(nsString data) #ifdef DEBUG_profile printf("subTok : %s\n", token); #endif - PL_strcpy(gNewProfileData[g_Count], token); - g_Count++; + PL_strcpy(gNewProfileData[index], token); + index++; + g_Count = index; token = nsCRT::strtok(newStr, "%", &newStr); } @@ -637,6 +838,276 @@ char* nsProfile::GetValue(char *name) return nsnull; } + +// Creates a new profile +NS_IMETHODIMP nsProfile::RenameProfile(const char* oldName, const char* newName) +{ +#if defined(NS_DEBUG) + printf("ProfileManager : Renaming profile %s to %s \n", oldName, newName); +#endif + + char *currProfile = nsnull; + + nsresult rv = NS_OK; + + GetCurrentProfile(&currProfile); + + CopyRegKey(oldName, newName); + + DeleteProfile(oldName); + + if (currProfile) + { + if (PL_strcmp(oldName, currProfile) == 0) + { + rv = m_reg->Open(); + + if (NS_SUCCEEDED(rv)) + { + nsIRegistry::Key profileRootKey; + rv = m_reg->GetSubtree(nsIRegistry::Common, "Profiles", &profileRootKey); + + if (NS_SUCCEEDED(rv)) + { + rv = m_reg->SetString(profileRootKey, "CurrentProfile", newName); + } + + m_reg->Close(); + } + } + } + return rv; +} + +nsresult nsProfile::CopyRegKey(const char *oldProfile, const char *newProfile) +{ + nsIEnumerator *enumKeys; + nsIRegistry::Key sourceKey, destKey, profileRootKey; + + nsresult rv = m_reg->Open(); + + if (NS_SUCCEEDED(rv)) + { + rv = m_reg->GetSubtree(nsIRegistry::Common, "Profiles", &profileRootKey); + + if (NS_SUCCEEDED(rv)) + { + + rv = m_reg->GetSubtree(profileRootKey, (char *) oldProfile, &sourceKey); + + if (NS_SUCCEEDED(rv)) + { + rv = m_reg->AddSubtree(profileRootKey, (char *) newProfile, &destKey); + + if (NS_SUCCEEDED(rv)) + { + + rv = m_reg->EnumerateValues(sourceKey, &enumKeys ); + + if (NS_SUCCEEDED(rv)) { + rv = enumKeys->First(); + + // Enumerate subkeys till done. + while( NS_SUCCEEDED( rv ) && !enumKeys->IsDone() ) + { + nsISupports *base; + rv = enumKeys->CurrentItem( &base ); + + // Test result. + if (NS_SUCCEEDED(rv)) { + // Get specific interface. + nsIRegistryNode *value; + nsIID valueIID = NS_IREGISTRYVALUE_IID; + rv = base->QueryInterface( valueIID, (void**)&value ); + + // Test that result. + if (NS_SUCCEEDED(rv)) { + // Get node name. + char *entryName; + char *entryValue; + + entryName = (char*) PR_Malloc(sizeof(char)*_MAX_LENGTH); + entryValue = (char*) PR_Malloc(sizeof(char)*_MAX_LENGTH); + + rv = value->GetName( &entryName ); + + if (NS_SUCCEEDED(rv)) { + + rv = m_reg->GetString( sourceKey, entryName, &entryValue); + + if (NS_SUCCEEDED(rv)) { + printf("######### %s = %s\n", entryName, entryValue); + rv = m_reg->SetString(destKey, entryName, entryValue); + } + } + + PR_DELETE(entryName); + PR_DELETE(entryValue); + } + } + rv = enumKeys->Next(); + } + NS_RELEASE(enumKeys); + } + } + } + } + m_reg->Close(); + } + return rv; +} + +// Creates a new profile +NS_IMETHODIMP nsProfile::DeleteProfile(const char* profileName) +{ + nsresult rv = NS_OK; + +#if defined(NS_DEBUG) + printf("ProfileManager : DeleteProfile\n"); +#endif + + // Check result. + if ( m_reg != nsnull ) { + // Latch onto the registry object. + NS_ADDREF(m_reg); + + // Open it against the input file name. + rv = m_reg->Open(); + if (NS_FAILED(rv)) + { + #if defined(NS_DEBUG) + printf("Error opening Registry.\n" ); + #endif + return rv; + } + + #if defined(NS_DEBUG) + printf("Registry opened OK.\n" ); + #endif + nsIRegistry::Key key; + rv = m_reg->GetSubtree(nsIRegistry::Common, "Profiles", &key); + + if (NS_FAILED(rv)) + { + #if defined(NS_DEBUG) + printf("Registry Error OK.\n" ); + #endif + + return rv; + } + + #if defined(NS_DEBUG) + printf("Registry:Profiles opened OK.\n" ); + #endif + rv = m_reg->RemoveSubtree(key, profileName); + + if (NS_FAILED(rv)) + return rv; + else + { + #if defined(NS_DEBUG) + printf("DeleteProfile : deleted profile -> %s <-\n", profileName); + #endif + } + + rv = m_reg->SetString(key, "CurrentProfile", "\0"); + if (NS_FAILED(rv)) { + #if defined(NS_DEBUG) + printf("Did not take nsnull successfully\n"); + #endif + } + + m_reg->Close(); + } + + return rv; +} + +// Creates a new profile +void nsProfile::GetAllProfiles() +{ +#if defined(NS_DEBUG) + printf("ProfileManager : GetAllProfiles\n"); +#endif + int index = 0; + + // Check result. + if ( m_reg != nsnull ) { + // Latch onto the registry object. + NS_ADDREF(m_reg); + + // Open it against the input file name. + nsresult rv = m_reg->Open(); + if (NS_SUCCEEDED(rv)) { +#if defined(NS_DEBUG) + printf("Registry opened OK.\n" ); +#endif + // 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)) { + int numKeys=0; + rv = enumKeys->First(); + // Enumerate subkeys till done. + 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 ); + + // Test that result. + if (NS_SUCCEEDED(rv)) { + // Get node name. + char *profile = (char*) PR_Malloc(sizeof(char)*_MAX_LENGTH); + rv = node->GetName( &profile ); + PL_strcpy(gProfiles[index], profile); + printf("proflie%d = %s\n", index, gProfiles[index]); + PR_DELETE(profile); + } + rv = enumKeys->Next(); + index++; + } + } + g_numProfiles = index; + NS_RELEASE(enumKeys); + } + } + } + m_reg->Close(); + } +} + +// Creates a new profile +NS_IMETHODIMP nsProfile::GetProfileList(nsString& profileList) +{ + printf("Inside GetProfileList routine.\n" ); + + GetAllProfiles(); + + for (int i=0; i < g_numProfiles; i++) + { + if (i != 0) + { + profileList += ","; + } + profileList += gProfiles[i]; + } + + return NS_OK; +} + +/***************************************************************************************/ +/*********** PROFILE FACTORY ************/ +/***************************************************************************************/ // Factory class nsProfileFactory: public nsIFactory { NS_DECL_ISUPPORTS