Fixes for 15037, 24681, 24247, 17527, 21716, 19620, 15755. Adapted nsVoidArray solution for profiles data structure. Fixed couple of activation related bugs. Fixed CreateProfile option bug. Added to code to create a default profile silently, when needed. r= sspitzer

This commit is contained in:
racham%netscape.com 2000-01-26 22:19:02 +00:00
Родитель ccbec76759
Коммит b6530da963
4 изменённых файлов: 299 добавлений и 147 удалений

Просмотреть файл

@ -72,9 +72,17 @@
#define PREG_USERNAME "PREG_USER_NAME"
#define PREG_DENIAL "PREG_USER_DENIAL"
// JavaScript and Cookies prefs in the all.js
#define JAVASCRIPT_PREF "javascript.enabled"
#define COOKIES_PREF "network.accept_cookies"
#define NEVER_ACCEPT_COOKIES 2
// hack for copying panels.rdf into migrated profile dir
#define PANELS_RDF_FILE "panels.rdf"
// A default profile name, in case automigration 4x profile fails
#define DEFAULT_PROFILE_NAME "default"
// kill me now.
#define REGISTRY_YES_STRING "yes"
#define REGISTRY_NO_STRING "no"
@ -232,6 +240,7 @@ nsProfile::LoadDefaultProfileDir(nsCString & profileURLStr)
nsresult rv;
nsCOMPtr<nsIURI> profileURL;
PRInt32 numProfiles=0;
PRBool pregURLLoaded = PR_FALSE;
NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &rv);
if (NS_FAILED(rv)) return rv;
@ -256,6 +265,20 @@ nsProfile::LoadDefaultProfileDir(nsCString & profileURLStr)
nsXPIDLCString pregURL;
rv = prefs->CopyCharPref(PREG_URL_PREF, getter_Copies(pregURL));
// Check if the javascript is enabled....
PRBool javascriptEnabled = PR_TRUE;
rv = prefs->GetBoolPref(JAVASCRIPT_PREF, &javascriptEnabled);
// Check if cookies are accepted....
PRInt32 acceptCookies = 0;
rv = prefs->GetIntPref(COOKIES_PREF, &acceptCookies);
// Set the boolean based on javascript and cookies prefs
PRBool requiredPrefsEnabled = PR_TRUE;
if ((!(javascriptEnabled)) || (acceptCookies == NEVER_ACCEPT_COOKIES))
requiredPrefsEnabled = PR_FALSE;
if (profileURLStr.Length() == 0)
{
// This means that there was no command-line argument to force
@ -263,8 +286,14 @@ nsProfile::LoadDefaultProfileDir(nsCString & profileURLStr)
// are no profiles yet, or if there is more than one.
if (numProfiles == 0)
{
if (pregPref)
profileURLStr = pregURL;
if (pregPref && requiredPrefsEnabled)
{
rv = CreateDefaultProfile();
if (NS_FAILED(rv)) return rv;
GetProfileCount(&numProfiles);
profileURLStr = pregURL;
}
else
profileURLStr = PROFILE_WIZARD_URL;
}
@ -272,13 +301,18 @@ nsProfile::LoadDefaultProfileDir(nsCString & profileURLStr)
profileURLStr = PROFILE_SELECTION_URL;
}
// Provide Preg information
if (pregPref && (PL_strcmp(isPregInfoSet, REGISTRY_YES_STRING) != 0))
profileURLStr = pregURL;
if (pregPref && (PL_strcmp(isPregInfoSet, REGISTRY_YES_STRING) != 0) && requiredPrefsEnabled)
{
if (profileURLStr.Length() == 0)
profileURLStr = pregURL;
}
if (profileURLStr.Length() != 0)
{
if (PL_strcmp((const char *)profileURLStr, pregURL) == 0)
pregURLLoaded = PR_TRUE;
rv = NS_NewURI(getter_AddRefs(profileURL), (const char *)profileURLStr);
if (NS_FAILED(rv)) {
@ -335,7 +369,39 @@ nsProfile::LoadDefaultProfileDir(nsCString & profileURLStr)
}
PR_FREEIF(currentProfileStr);
if (pregPref && PL_strcmp(isPregInfoSet, REGISTRY_YES_STRING) != 0)
// in multiple profiles case, we still need to take them to registration screens
if (pregPref && (PL_strcmp(isPregInfoSet, REGISTRY_YES_STRING) != 0) && requiredPrefsEnabled)
{
profileURLStr = pregURL;
// Load PReg shell
if (!pregURLLoaded)
{
nsCOMPtr<nsIURI> registrationURL;
rv = NS_NewURI(getter_AddRefs(registrationURL), (const char *)profileURLStr);
if (NS_FAILED(rv)) {
return rv;
}
nsCOMPtr<nsIWebShellWindow> profWindow;
rv = profAppShell->CreateTopLevelWindow(nsnull, registrationURL,
PR_TRUE, PR_TRUE, NS_CHROME_ALL_CHROME,
nsnull,
NS_SIZETOCONTENT, // width
NS_SIZETOCONTENT, // height
getter_AddRefs(profWindow));
if (NS_FAILED(rv)) return rv;
/*
* Start up the main event loop...
*/
rv = profAppShell->Run();
}
}
if (pregPref && (PL_strcmp(isPregInfoSet, REGISTRY_YES_STRING) != 0) && requiredPrefsEnabled)
ProcessPRegCookie();
CRTFREEIF(isPregInfoSet);
@ -348,11 +414,20 @@ nsProfile::LoadDefaultProfileDir(nsCString & profileURLStr)
nsresult
nsProfile::AutoMigrate()
{
nsresult rv = NS_OK;
// automatically migrate the one 4.x profile
MigrateAllProfiles();
rv = MigrateAllProfiles();
if (NS_FAILED(rv))
{
printf("AutoMigration failed. Let's create a default 5.0 profile.\n");
rv = CreateDefaultProfile();
if (NS_FAILED(rv)) return rv;
}
gProfileDataAccess->UpdateRegistry();
return NS_OK;
return rv;
}
nsresult
@ -436,6 +511,7 @@ nsProfile::ProcessArgs(nsICmdLineService *cmdLineArgs,
// Need to load new profile prefs.
rv = LoadNewProfilePrefs();
gProfileDataAccess->UpdateRegistry();
}
}
}
@ -483,9 +559,13 @@ nsProfile::ProcessArgs(nsICmdLineService *cmdLineArgs,
PRInt32 numProfiles = 0;
GetProfileCount(&numProfiles);
if (num4xProfiles == 0 && numProfiles == 0) {
// show the create profile wizard
profileURLStr = PROFILE_WIZARD_URL;
// Let us create a default 5.0 profile
CreateDefaultProfile();
if (NS_FAILED(rv)) return rv;
}
else if (num4xProfiles == 0 && numProfiles == 1) {
profileURLStr = "";
}
else if (num4xProfiles == 1 && numProfiles == 0) {
PRBool confirmAutomigration = PR_FALSE;
NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &rv)
@ -1101,7 +1181,7 @@ NS_IMETHODIMP nsProfile::MigrateProfile(const char* profileName, PRBool showProg
if (NS_FAILED(rv)) return rv;
if (!oldProfDir.Exists()) {
oldProfDir.CreateDirectory();
return NS_ERROR_FAILURE;
}
rv = GetStringFromSpec(oldProfDir, getter_Copies(oldProfDirStr));
if (NS_FAILED(rv)) return rv;
@ -1246,15 +1326,15 @@ NS_IMETHODIMP nsProfile::ProcessPREGInfo(const char* data)
if (userProfileName.mLength > 0)
{
rv = RenameProfile(curProfile, userProfileName.ToNewCString());
CloneProfile(userProfileName.ToNewCString());
DeleteProfile(curProfile, PR_TRUE);
ProfileStruct* aProfile;
gProfileDataAccess->GetValue(userProfileName.ToNewCString(), &aProfile);
PRInt32 length = PL_strlen(userProfileName.ToNewCString());
aProfile->NCProfileName = (char *) PR_Realloc(aProfile->NCProfileName, length+1);
PL_strcpy(aProfile->NCProfileName, userProfileName.ToNewCString());
aProfile->NCProfileName = nsCRT::strdup(userProfileName.ToNewCString());
gProfileDataAccess->SetValue(aProfile);
gProfileDataAccess->SetCurrentProfile(userProfileName.ToNewCString());
@ -1267,8 +1347,7 @@ NS_IMETHODIMP nsProfile::ProcessPREGInfo(const char* data)
gProfileDataAccess->GetValue(curProfile, &aProfile);
PRInt32 length = PL_strlen(userServiceDenial.ToNewCString());
aProfile->NCDeniedService = (char *) PR_Realloc(aProfile->NCDeniedService, length+1);
PL_strcpy(aProfile->NCDeniedService, userServiceDenial.ToNewCString());
aProfile->NCDeniedService = nsCRT::strdup(userServiceDenial.ToNewCString());
gProfileDataAccess->SetValue(aProfile);
FreeProfileStruct(aProfile);
@ -1312,7 +1391,8 @@ NS_IMETHODIMP nsProfile::MigrateAllProfiles()
nsresult rv = NS_OK;
for (PRInt32 i=0; i < gProfileDataAccess->mNumOldProfiles; i++)
{
rv = MigrateProfile(gProfileDataAccess->m4xProfiles[i]->profileName, PR_FALSE /* don't show progress as modal window */);
ProfileStruct* profileItem = (ProfileStruct *) (gProfileDataAccess->m4xProfiles->ElementAt(i));
rv = MigrateProfile(profileItem->profileName, PR_FALSE /* don't show progress as modal window */);
if (NS_FAILED(rv)) return rv;
}
@ -1395,6 +1475,8 @@ NS_IMETHODIMP nsProfile::CloneProfile(const char* newProfile)
#endif
gProfileDataAccess->mProfileDataChanged = PR_TRUE;
gProfileDataAccess->UpdateRegistry();
return rv;
}
@ -1412,3 +1494,29 @@ nsProfile::FreeProfileStruct(ProfileStruct* aProfile)
PR_FREEIF(aProfile);
}
}
nsresult
nsProfile::CreateDefaultProfile(void)
{
nsresult rv = NS_OK;
nsFileSpec profileDirSpec;
// Get the default user profiles folder
NS_WITH_SERVICE(nsIFileLocator, locator, kFileLocatorCID, &rv);
if (NS_FAILED(rv) || !locator)
return NS_ERROR_FAILURE;
nsCOMPtr <nsIFileSpec> spec;
rv = locator->GetFileLocation(nsSpecialFileSpec::App_DefaultUserProfileRoot50, getter_AddRefs(spec));
if (NS_FAILED(rv) || !spec)
return NS_ERROR_FAILURE;
spec->GetFileSpec(&profileDirSpec);
rv = locator->ForgetProfileDir();
rv = CreateNewProfile(DEFAULT_PROFILE_NAME, profileDirSpec);
return rv;
}

Просмотреть файл

@ -62,5 +62,7 @@ public:
void FreeProfileStruct(ProfileStruct* aProfile);
nsresult AutoMigrate();
nsresult CreateDefaultProfile(void);
};

Просмотреть файл

@ -85,6 +85,8 @@ nsProfileAccess::nsProfileAccess()
mFixRegEntries = PR_FALSE;
mProfileDataChanged = PR_FALSE;
mForgetProfileCalled = PR_FALSE;
mProfiles = new nsVoidArray();
m4xProfiles = new nsVoidArray();
FillProfileInfo();
}
@ -111,21 +113,17 @@ nsProfileAccess::~nsProfileAccess()
// Free up the member profile structs
void
nsProfileAccess::FreeProfileMembers(ProfileStruct *profiles[], PRInt32 numElems)
nsProfileAccess::FreeProfileMembers(nsVoidArray *profiles, PRInt32 numElems)
{
PRInt32 index = 0;
for (index=0; index < numElems; index++)
ProfileStruct* aProfile;
for (index = 0; index < numElems; index++)
{
CRTFREEIF(profiles[index]->profileName);
CRTFREEIF(profiles[index]->profileLocation);
CRTFREEIF(profiles[index]->isMigrated);
CRTFREEIF(profiles[index]->NCProfileName);
CRTFREEIF(profiles[index]->NCDeniedService);
PR_FREEIF(profiles[index]);
aProfile = (ProfileStruct *) profiles->ElementAt(index);
delete aProfile;
}
}
// Close the registry.
@ -183,20 +181,22 @@ nsProfileAccess::GetValue(const char* profileName, ProfileStruct** aProfile)
if (!*aProfile)
return NS_ERROR_OUT_OF_MEMORY;
ProfileStruct* profileItem = (ProfileStruct *) (mProfiles->ElementAt(index));
(*aProfile)->profileName = nsnull;
(*aProfile)->profileLocation = nsnull;
(*aProfile)->isMigrated = nsnull;
(*aProfile)->NCProfileName = nsnull;
(*aProfile)->NCDeniedService = nsnull;
(*aProfile)->profileName = nsCRT::strdup(mProfiles[index]->profileName);
(*aProfile)->profileLocation = nsCRT::strdup(mProfiles[index]->profileLocation);
(*aProfile)->isMigrated = nsCRT::strdup(mProfiles[index]->isMigrated);
(*aProfile)->profileName = nsCRT::strdup(profileItem->profileName);
(*aProfile)->profileLocation = nsCRT::strdup(profileItem->profileLocation);
(*aProfile)->isMigrated = nsCRT::strdup(profileItem->isMigrated);
if (mProfiles[index]->NCProfileName)
(*aProfile)->NCProfileName = nsCRT::strdup(mProfiles[index]->NCProfileName);
if (mProfiles[index]->NCDeniedService)
(*aProfile)->NCProfileName = nsCRT::strdup(mProfiles[index]->NCDeniedService);
if (profileItem->NCProfileName)
(*aProfile)->NCProfileName = nsCRT::strdup(profileItem->NCProfileName);
if (profileItem->NCDeniedService)
(*aProfile)->NCProfileName = nsCRT::strdup(profileItem->NCDeniedService);
}
else
*aProfile = nsnull;
@ -217,51 +217,56 @@ nsProfileAccess::SetValue(ProfileStruct* aProfile)
if (index >= 0)
{
ProfileStruct* profileItem = (ProfileStruct *) (mProfiles->ElementAt(index));
PRInt32 length = PL_strlen(aProfile->profileLocation);
mProfiles[index]->profileLocation = (char *) PR_Realloc(mProfiles[index]->profileLocation, length+1);
PL_strcpy(mProfiles[index]->profileLocation, aProfile->profileLocation);
profileItem->profileLocation = (char *) PR_Realloc(profileItem->profileLocation, length+1);
PL_strcpy(profileItem->profileLocation, aProfile->profileLocation);
length = PL_strlen(aProfile->isMigrated);
mProfiles[index]->isMigrated = (char *) PR_Realloc(mProfiles[index]->isMigrated, length+1);
PL_strcpy(mProfiles[index]->isMigrated, aProfile->isMigrated);
profileItem->isMigrated = (char *) PR_Realloc(profileItem->isMigrated, length+1);
PL_strcpy(profileItem->isMigrated, aProfile->isMigrated);
mProfiles[index]->updateProfileEntry = PR_TRUE;
profileItem->updateProfileEntry = PR_TRUE;
if (aProfile->NCProfileName)
{
length = PL_strlen(aProfile->NCProfileName);
mProfiles[index]->NCProfileName = (char *) PR_Realloc(mProfiles[index]->NCProfileName, length+1);
PL_strcpy(mProfiles[index]->NCProfileName, aProfile->NCProfileName);
profileItem->NCProfileName = (char *) PR_Realloc(profileItem->NCProfileName, length+1);
PL_strcpy(profileItem->NCProfileName, aProfile->NCProfileName);
}
if (aProfile->NCDeniedService)
{
length = PL_strlen(aProfile->NCDeniedService);
mProfiles[index]->NCDeniedService = (char *) PR_Realloc(mProfiles[index]->NCDeniedService, length+1);
PL_strcpy(mProfiles[mCount]->NCDeniedService, aProfile->NCDeniedService);
profileItem->NCDeniedService = (char *) PR_Realloc(profileItem->NCDeniedService, length+1);
PL_strcpy(profileItem->NCDeniedService, aProfile->NCDeniedService);
}
}
else
{
mProfiles[mCount] = (ProfileStruct *) PR_Malloc(sizeof(ProfileStruct));
if (!mProfiles[mCount])
ProfileStruct* profileItem = new ProfileStruct();
if (!profileItem)
return NS_ERROR_OUT_OF_MEMORY;
mProfiles[mCount]->profileName = nsnull;
mProfiles[mCount]->profileLocation = nsnull;
mProfiles[mCount]->isMigrated = nsnull;
mProfiles[mCount]->NCProfileName = nsnull;
mProfiles[mCount]->NCDeniedService = nsnull;
profileItem->profileName = nsnull;
profileItem->profileLocation = nsnull;
profileItem->isMigrated = nsnull;
profileItem->NCProfileName = nsnull;
profileItem->NCDeniedService = nsnull;
mProfiles[mCount]->profileName = nsCRT::strdup(aProfile->profileName);
mProfiles[mCount]->profileLocation = nsCRT::strdup(aProfile->profileLocation);
mProfiles[mCount]->isMigrated = nsCRT::strdup(aProfile->isMigrated);
mProfiles[mCount]->updateProfileEntry = PR_TRUE;
profileItem->profileName = nsCRT::strdup(aProfile->profileName);
profileItem->profileLocation = nsCRT::strdup(aProfile->profileLocation);
profileItem->isMigrated = nsCRT::strdup(aProfile->isMigrated);
profileItem->updateProfileEntry = PR_TRUE;
if (aProfile->NCProfileName)
mProfiles[index]->NCProfileName = nsCRT::strdup(aProfile->NCProfileName);
profileItem->NCProfileName = nsCRT::strdup(aProfile->NCProfileName);
if (aProfile->NCDeniedService)
mProfiles[mCount]->NCProfileName = nsCRT::strdup(aProfile->NCDeniedService);
profileItem->NCProfileName = nsCRT::strdup(aProfile->NCDeniedService);
if (!mProfiles)
mProfiles = new nsVoidArray();
mProfiles->AppendElement((void*)profileItem);
mCount++;
}
return NS_OK;
@ -277,12 +282,12 @@ nsProfileAccess::SetValue(ProfileStruct* aProfile)
nsresult
nsProfileAccess::FillProfileInfo()
{
nsresult rv = NS_OK;
nsresult rv = NS_OK;
// Make the fail: thing work
mProfiles[0] = nsnull;
// Make the fail: thing work
mProfiles = nsnull;
rv = OpenRegistry();
rv = OpenRegistry();
if (NS_FAILED(rv)) return rv;
// Enumerate all subkeys (immediately) under the given node.
@ -371,37 +376,40 @@ nsProfileAccess::FillProfileInfo()
rv = m_registry->GetString(profKey, REGISTRY_NC_PROFILE_NAME_STRING, getter_Copies(NCProfileName));
rv = m_registry->GetString(profKey, REGISTRY_NC_SERVICE_DENIAL_STRING, getter_Copies(NCDeniedService));
mProfiles[mCount] = (ProfileStruct *) PR_Malloc(sizeof(ProfileStruct));
if (!mProfiles[mCount])
return NS_ERROR_OUT_OF_MEMORY;
ProfileStruct* profileItem = new ProfileStruct();
if (!profileItem)
return NS_ERROR_OUT_OF_MEMORY;
mProfiles[mCount]->profileName = nsnull;
mProfiles[mCount]->profileLocation = nsnull;
mProfiles[mCount]->isMigrated = nsnull;
mProfiles[mCount]->NCProfileName = nsnull;
mProfiles[mCount]->NCDeniedService = nsnull;
mProfiles[mCount]->updateProfileEntry = PR_TRUE;
profileItem->profileName = nsnull;
profileItem->profileLocation = nsnull;
profileItem->isMigrated = nsnull;
profileItem->NCProfileName = nsnull;
profileItem->NCDeniedService = nsnull;
profileItem->updateProfileEntry = PR_TRUE;
mProfiles[mCount]->profileName = nsCRT::strdup(profile);
mProfiles[mCount]->profileLocation = nsCRT::strdup(directory);
mProfiles[mCount]->isMigrated = nsCRT::strdup(isMigrated);
profileItem->profileName = nsCRT::strdup(profile);
profileItem->profileLocation = nsCRT::strdup(directory);
profileItem->isMigrated = nsCRT::strdup(isMigrated);
if (NCProfileName)
mProfiles[mCount]->NCProfileName = nsCRT::strdup(NCProfileName);
if (NCDeniedService)
mProfiles[mCount]->NCDeniedService = nsCRT::strdup(NCDeniedService);
if (NCProfileName)
profileItem->NCProfileName = nsCRT::strdup(NCProfileName);
if (NCDeniedService)
profileItem->NCDeniedService = nsCRT::strdup(NCDeniedService);
if (PL_strcmp(isMigrated, REGISTRY_YES_STRING) == 0)
mNumProfiles++;
else if (PL_strcmp(isMigrated, REGISTRY_NO_STRING) == 0)
mNumOldProfiles++;
if (PL_strcmp(isMigrated, REGISTRY_YES_STRING) == 0)
mNumProfiles++;
else if (PL_strcmp(isMigrated, REGISTRY_NO_STRING) == 0)
mNumOldProfiles++;
if (!mProfiles)
mProfiles = new nsVoidArray();
mProfiles->AppendElement((void*)profileItem);
mCount++;
CRTFREEIF(directory);
}
rv = enumKeys->Next();
mCount++;
CRTFREEIF(directory);
}
rv = enumKeys->Next();
}
mFixRegEntries = PR_FALSE;
rv = CloseRegistry();
@ -439,9 +447,11 @@ nsProfileAccess::GetFirstProfile(char **firstProfile)
for(index = 0; index < mCount; index++)
{
if (PL_strcmp(mProfiles[index]->isMigrated, REGISTRY_YES_STRING) == 0)
ProfileStruct* profileItem = (ProfileStruct *) (mProfiles->ElementAt(index));
if (PL_strcmp(profileItem->isMigrated, REGISTRY_YES_STRING) == 0)
{
*firstProfile = nsCRT::strdup(mProfiles[index]->profileName);
*firstProfile = nsCRT::strdup(profileItem->profileName);
break;
}
}
@ -468,7 +478,7 @@ nsProfileAccess::GetCurrentProfile(char **profileName)
{
*profileName = nsnull;
if (mCurrentProfile)
{
if ((PL_strcmp(mCurrentProfile,"") != 0) || mForgetProfileCalled)
@ -494,19 +504,18 @@ nsProfileAccess::RemoveSubTree(const char* profileName)
// by moving the pointers with something like memmove
// decrement mCount if it works.
PRInt32 index = 0;
PRInt32 i = 0;
PRBool isOldProfile = PR_FALSE;
index = FindProfileIndex(profileName);
if (index >= 0)
{
if (PL_strcmp(mProfiles[index]->isMigrated, REGISTRY_NO_STRING) == 0)
ProfileStruct* profileItem = (ProfileStruct *) (mProfiles->ElementAt(index));
if (PL_strcmp(profileItem->isMigrated, REGISTRY_NO_STRING) == 0)
isOldProfile = PR_TRUE;
PRInt32 movePositions = mCount - index;
for (i=0; i < movePositions; i++,index++)
nsCRT::memmove(&mProfiles[index], &mProfiles[index+1], sizeof(ProfileStruct *));
mProfiles->RemoveElementAt(index);
mCount--;
if (isOldProfile)
@ -583,7 +592,9 @@ nsProfileAccess::FindProfileIndex(const char* profileName)
for (index=0; index < mCount; index++)
{
if (PL_strcmp(profileName, mProfiles[index]->profileName) == 0)
ProfileStruct* profileItem = (ProfileStruct *) (mProfiles->ElementAt(index));
if (PL_strcmp(profileName, profileItem->profileName) == 0)
{
retval = index;
break;
@ -668,19 +679,21 @@ nsProfileAccess::UpdateRegistry()
{
nsRegistryKey profKey;
ProfileStruct* profileItem = (ProfileStruct *) (mProfiles->ElementAt(index));
rv = m_registry->GetSubtree(profilesTreeKey, profile, &profKey);
if (NS_FAILED(rv)) return rv;
rv = m_registry->SetString(profKey, REGISTRY_DIRECTORY_STRING, mProfiles[index]->profileLocation);
rv = m_registry->SetString(profKey, REGISTRY_DIRECTORY_STRING, profileItem->profileLocation);
if (NS_FAILED(rv)) return rv;
rv = m_registry->SetString(profKey, REGISTRY_MIGRATED_STRING, mProfiles[index]->isMigrated);
rv = m_registry->SetString(profKey, REGISTRY_MIGRATED_STRING, profileItem->isMigrated);
if (NS_FAILED(rv)) return rv;
rv = m_registry->SetString(profKey, REGISTRY_NC_PROFILE_NAME_STRING, mProfiles[index]->NCProfileName);
rv = m_registry->SetString(profKey, REGISTRY_NC_SERVICE_DENIAL_STRING, mProfiles[index]->NCDeniedService);
rv = m_registry->SetString(profKey, REGISTRY_NC_PROFILE_NAME_STRING, profileItem->NCProfileName);
rv = m_registry->SetString(profKey, REGISTRY_NC_SERVICE_DENIAL_STRING, profileItem->NCDeniedService);
mProfiles[index]->updateProfileEntry = PR_FALSE;
profileItem->updateProfileEntry = PR_FALSE;
}
rv = enumKeys->Next();
}
@ -688,20 +701,22 @@ nsProfileAccess::UpdateRegistry()
// Take care of new nodes
for (int i = 0; i < mCount; i++)
{
if (mProfiles[i]->updateProfileEntry)
ProfileStruct* profileItem = (ProfileStruct *) (mProfiles->ElementAt(i));
if (profileItem->updateProfileEntry)
{
nsRegistryKey profKey;
rv = m_registry->AddSubtree(profilesTreeKey, mProfiles[i]->profileName, &profKey);
rv = m_registry->AddSubtree(profilesTreeKey, profileItem->profileName, &profKey);
if (NS_FAILED(rv)) return rv;
rv = m_registry->SetString(profKey, REGISTRY_DIRECTORY_STRING, mProfiles[i]->profileLocation);
rv = m_registry->SetString(profKey, REGISTRY_DIRECTORY_STRING, profileItem->profileLocation);
if (NS_FAILED(rv)) return rv;
rv = m_registry->SetString(profKey, REGISTRY_MIGRATED_STRING, mProfiles[i]->isMigrated);
rv = m_registry->SetString(profKey, REGISTRY_MIGRATED_STRING, profileItem->isMigrated);
if (NS_FAILED(rv)) return rv;
mProfiles[i]->updateProfileEntry = PR_FALSE;
profileItem->updateProfileEntry = PR_FALSE;
}
}
@ -721,13 +736,15 @@ nsProfileAccess::GetProfileList(char **profileListStr)
for (PRInt32 index=0; index < mCount; index++)
{
ProfileStruct* profileItem = (ProfileStruct *) (mProfiles->ElementAt(index));
if (index != 0)
{
profileList += ",";
}
profileList += mProfiles[index]->profileName;
profileList += profileItem->profileName;
if (PL_strcmp(mProfiles[index]->isMigrated, REGISTRY_NO_STRING) == 0)
if (PL_strcmp(profileItem->isMigrated, REGISTRY_NO_STRING) == 0)
profileList += " - migrate";
}
@ -742,7 +759,8 @@ nsProfileAccess::ProfileExists(const char *profileName)
for (PRInt32 index=0; index < mCount; index++)
{
if (PL_strcmp(mProfiles[index]->profileName, profileName) == 0)
ProfileStruct* profileItem = (ProfileStruct *) (mProfiles->ElementAt(index));
if (PL_strcmp(profileItem->profileName, profileName) == 0)
{
exists = PR_TRUE;
break;
@ -798,7 +816,17 @@ nsProfileAccess::Get4xProfileInfo(const char *registryName)
char *profile = nsnull;
rv = node->GetName(&profile);
if (NS_FAILED(rv)) return rv;
PRBool exists = PR_FALSE;;
exists = ProfileExists(profile);
if (exists)
{
rv = enumKeys->Next();
if (NS_FAILED(rv)) return rv;
continue;
}
nsRegistryKey key;
rv = oldReg->GetSubtree(nsIRegistry::Users, profile, &key);
@ -813,27 +841,31 @@ nsProfileAccess::Get4xProfileInfo(const char *registryName)
printf("oldProflie Location = %s\n", profLoc);
#endif
m4xProfiles[mNumOldProfiles] = (ProfileStruct *) PR_Malloc(sizeof(ProfileStruct));
if (!m4xProfiles[mNumOldProfiles])
return NS_ERROR_OUT_OF_MEMORY;
ProfileStruct* profileItem = new ProfileStruct();
if (!profileItem)
return NS_ERROR_OUT_OF_MEMORY;
m4xProfiles[mNumOldProfiles]->profileName = nsnull;
m4xProfiles[mNumOldProfiles]->profileLocation = nsnull;
m4xProfiles[mNumOldProfiles]->isMigrated = nsnull;
m4xProfiles[mNumOldProfiles]->NCProfileName = nsnull;
m4xProfiles[mNumOldProfiles]->NCDeniedService = nsnull;
m4xProfiles[mNumOldProfiles]->updateProfileEntry = PR_TRUE;
profileItem->profileName = nsnull;
profileItem->profileLocation = nsnull;
profileItem->isMigrated = nsnull;
profileItem->NCProfileName = nsnull;
profileItem->NCDeniedService = nsnull;
profileItem->updateProfileEntry = PR_TRUE;
m4xProfiles[mNumOldProfiles]->profileName = nsCRT::strdup(nsUnescape(profile));
m4xProfiles[mNumOldProfiles]->profileLocation = nsCRT::strdup(profLoc);
m4xProfiles[mNumOldProfiles]->isMigrated = nsCRT::strdup(REGISTRY_NO_STRING);
profileItem->profileName = nsCRT::strdup(nsUnescape(profile));
profileItem->profileLocation = nsCRT::strdup(profLoc);
profileItem->isMigrated = nsCRT::strdup(REGISTRY_NO_STRING);
if (!m4xProfiles)
m4xProfiles = new nsVoidArray();
m4xProfiles->AppendElement((void*)profileItem);
mNumOldProfiles++;
rv = enumKeys->Next();
rv = enumKeys->Next();
if (NS_FAILED(rv)) return rv;
}
oldReg->Close();
}
oldReg->Close();
#elif defined (XP_BEOS)
#else
@ -846,28 +878,39 @@ nsProfileAccess::Get4xProfileInfo(const char *registryName)
unixProfileDirectory = PR_GetEnv(HOME_ENVIRONMENT_VARIABLE);
}
PRBool exists = PR_FALSE;;
exists = ProfileExists(unixProfileName);
if (exists)
{
return NS_OK;
}
if (unixProfileName && unixProfileDirectory) {
m4xProfiles[mNumOldProfiles] = (ProfileStruct *) PR_Malloc(sizeof(ProfileStruct));
if (!m4xProfiles[mNumOldProfiles])
ProfileStruct* profileItem = new ProfileStruct();
if (!profileItem)
return NS_ERROR_OUT_OF_MEMORY;
m4xProfiles[mNumOldProfiles]->profileName = nsnull;
m4xProfiles[mNumOldProfiles]->profileLocation = nsnull;
m4xProfiles[mNumOldProfiles]->isMigrated = nsnull;
m4xProfiles[mNumOldProfiles]->NCProfileName = nsnull;
m4xProfiles[mNumOldProfiles]->NCDeniedService = nsnull;
m4xProfiles[mNumOldProfiles]->updateProfileEntry = PR_TRUE;
profileItem->profileName = nsnull;
profileItem->profileLocation = nsnull;
profileItem->isMigrated = nsnull;
profileItem->NCProfileName = nsnull;
profileItem->NCDeniedService = nsnull;
profileItem->updateProfileEntry = PR_TRUE;
m4xProfiles[mNumOldProfiles]->profileName = nsCRT::strdup(nsUnescape(unixProfileName));
m4xProfiles[mNumOldProfiles]->profileLocation = nsCRT::strdup(unixProfileDirectory);
profileItem->profileName = nsCRT::strdup(nsUnescape(unixProfileName));
profileItem->profileLocation = nsCRT::strdup(unixProfileDirectory);
PRInt32 length = PL_strlen(unixProfileDirectory) + PL_strlen("/.netscape");
m4xProfiles[mNumOldProfiles]->profileLocation = (char *) PR_Realloc(m4xProfiles[mNumOldProfiles]->profileLocation, length+1);
PL_strcpy(m4xProfiles[mNumOldProfiles]->profileLocation, unixProfileDirectory);
PL_strcat(m4xProfiles[mNumOldProfiles]->profileLocation, "/.netscape");
profileItem->profileLocation = (char *) PR_Realloc(profileItem->profileLocation, length+1);
PL_strcpy(profileItem->profileLocation, unixProfileDirectory);
PL_strcat(profileItem->profileLocation, "/.netscape");
m4xProfiles[mNumOldProfiles]->isMigrated = nsCRT::strdup(REGISTRY_NO_STRING);
profileItem->isMigrated = nsCRT::strdup(REGISTRY_NO_STRING);
if (!m4xProfiles)
m4xProfiles = new nsVoidArray();
m4xProfiles->AppendElement((void*)profileItem);
mNumOldProfiles++;
}
@ -892,10 +935,11 @@ nsProfileAccess::UpdateProfileArray()
for (PRInt32 idx = 0; idx < m4xCount; idx++)
{
nsFileSpec profileDir(m4xProfiles[idx]->profileLocation);
ProfileStruct* profileItem = (ProfileStruct *) (m4xProfiles->ElementAt(idx));
nsFileSpec profileDir(profileItem->profileLocation);
PRBool exists;
exists = ProfileExists(m4xProfiles[idx]->profileName);
exists = ProfileExists(profileItem->profileName);
if (NS_FAILED(rv)) return rv;
// That profile already exists...
@ -915,11 +959,11 @@ nsProfileAccess::UpdateProfileArray()
{
PRInt32 length = PL_strlen(profileDirString);
m4xProfiles[idx]->profileLocation = (char *) PR_Realloc(m4xProfiles[idx]->profileLocation, length+1);
profileItem->profileLocation = (char *) PR_Realloc(profileItem->profileLocation, length+1);
PL_strcpy(m4xProfiles[idx]->profileLocation, profileDirString);
PL_strcpy(profileItem->profileLocation, profileDirString);
SetValue(m4xProfiles[idx]);
SetValue(profileItem);
}
}

Просмотреть файл

@ -24,9 +24,7 @@
#include "nsString.h"
#include "nsIRegistry.h"
#include "nsXPIDLString.h"
#define _MAX_NUM_PROFILES 100
#define _MAX_4X_PROFILES 50
#include "nsVoidArray.h"
//typedef struct _profile_struct ProfileStruct;
typedef struct _profile_struct {
@ -44,7 +42,7 @@ class nsProfileAccess
private:
nsCOMPtr <nsIRegistry> m_registry;
ProfileStruct *mProfiles[_MAX_NUM_PROFILES];
nsVoidArray *mProfiles;
PRInt32 mCount;
char* mCurrentProfile;
char* mVersion;
@ -60,7 +58,7 @@ public:
PRBool mForgetProfileCalled;
PRInt32 mNumProfiles;
PRInt32 mNumOldProfiles;
ProfileStruct *m4xProfiles[_MAX_4X_PROFILES];
nsVoidArray *m4xProfiles;
nsProfileAccess();
virtual ~nsProfileAccess();
@ -89,7 +87,7 @@ public:
nsresult UpdateProfileArray();
void SetPREGInfo(const char* pregInfo);
void GetPREGInfo(char** pregInfo);
void FreeProfileMembers(ProfileStruct *aProfile[], PRInt32 numElems);
void FreeProfileMembers(nsVoidArray *aProfile, PRInt32 numElems);
};
#endif // __nsProfileAccess_h___