Fixing bug 46320. Reducing the number of global files by moving profile regitry to the product sub-directory under HOME. r=dougt
git-svn-id: svn://10.0.0.236/trunk@76451 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -28,6 +28,7 @@ interface nsIFileSpec;
|
||||
%{C++
|
||||
#include "nsFileSpec.h"
|
||||
#include "nsICmdLineService.h"
|
||||
#include "nsIFile.h"
|
||||
|
||||
#define NS_PROFILE_CID \
|
||||
{ /* {02b0625b-e7f3-11d2-9f5a-006008a6efe9} */ \
|
||||
@@ -46,6 +47,7 @@ interface nsIFileSpec;
|
||||
|
||||
[ptr] native nsFileSpec(nsFileSpec);
|
||||
[ref] native nsFileSpecRef(nsFileSpec);
|
||||
[ptr] native nsIFile(nsIFile);
|
||||
[scriptable, uuid(02b0625a-e7f3-11d2-9f5a-006008a6efe9)]
|
||||
interface nsIProfile : nsISupports {
|
||||
[noscript] void startupWithArgs(in nsICmdLineService cmdLine);
|
||||
@@ -94,7 +96,7 @@ interface nsIProfile : nsISupports {
|
||||
|
||||
readonly attribute nsIFileSpec defaultProfileParentDir;
|
||||
|
||||
void updateRegistry();
|
||||
[noscript] void updateRegistry(in nsIFile regName);
|
||||
void setRegStrings(in wstring profileName,
|
||||
in wstring regString,
|
||||
in wstring regName,
|
||||
|
||||
@@ -40,10 +40,18 @@ function StartUp()
|
||||
if(window.location && window.location.search && window.location.search == "?manage=true" )
|
||||
SwitchProfileManagerMode();
|
||||
|
||||
var dirServ = Components.classes['component://netscape/file/directory_service'].createInstance();
|
||||
dirServ = dirServ.QueryInterface(Components.interfaces.nsIProperties);
|
||||
|
||||
// "AggRegF" stands for Application Registry File.
|
||||
// Forgive the weird name directory service has adapted for
|
||||
// application registry file....
|
||||
var regFile = dirServ.get("AppRegF", Components.interfaces.nsIFile);
|
||||
|
||||
Registry = Components.classes['component://netscape/registry'].createInstance();
|
||||
Registry = Registry.QueryInterface(Components.interfaces.nsIRegistry);
|
||||
Registry.openWellKnownRegistry(Registry.ApplicationRegistry);
|
||||
|
||||
Registry.open(regFile.path);
|
||||
|
||||
loadElements();
|
||||
highlightCurrentProfile();
|
||||
|
||||
|
||||
@@ -239,7 +239,7 @@ nsProfile::~nsProfile()
|
||||
#endif
|
||||
|
||||
gProfileDataAccess->mProfileDataChanged = PR_TRUE;
|
||||
gProfileDataAccess->UpdateRegistry();
|
||||
gProfileDataAccess->UpdateRegistry(nsnull);
|
||||
|
||||
if (--gInstanceCount == 0) {
|
||||
|
||||
@@ -496,7 +496,7 @@ nsProfile::AutoMigrate()
|
||||
}
|
||||
|
||||
gProfileDataAccess->mProfileDataChanged = PR_TRUE;
|
||||
gProfileDataAccess->UpdateRegistry();
|
||||
gProfileDataAccess->UpdateRegistry(nsnull);
|
||||
|
||||
return rv;
|
||||
}
|
||||
@@ -619,7 +619,7 @@ nsProfile::ProcessArgs(nsICmdLineService *cmdLineArgs,
|
||||
// Need to load new profile prefs.
|
||||
rv = LoadNewProfilePrefs();
|
||||
gProfileDataAccess->mProfileDataChanged = PR_TRUE;
|
||||
gProfileDataAccess->UpdateRegistry();
|
||||
gProfileDataAccess->UpdateRegistry(nsnull);
|
||||
}
|
||||
rv = ForgetCurrentProfile();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
@@ -1100,7 +1100,7 @@ nsProfile::CreateNewProfile(const PRUnichar* profileName,
|
||||
|
||||
gProfileDataAccess->mNumProfiles++;
|
||||
gProfileDataAccess->mProfileDataChanged = PR_TRUE;
|
||||
gProfileDataAccess->UpdateRegistry();
|
||||
gProfileDataAccess->UpdateRegistry(nsnull);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -1209,7 +1209,7 @@ nsProfile::RenameProfile(const PRUnichar* oldName, const PRUnichar* newName)
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
gProfileDataAccess->mProfileDataChanged = PR_TRUE;
|
||||
gProfileDataAccess->UpdateRegistry();
|
||||
gProfileDataAccess->UpdateRegistry(nsnull);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -1288,7 +1288,7 @@ NS_IMETHODIMP nsProfile::DeleteProfile(const PRUnichar* profileName, PRBool canD
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
gProfileDataAccess->mProfileDataChanged = PR_TRUE;
|
||||
gProfileDataAccess->UpdateRegistry();
|
||||
gProfileDataAccess->UpdateRegistry(nsnull);
|
||||
|
||||
return rv;
|
||||
}
|
||||
@@ -1402,7 +1402,7 @@ NS_IMETHODIMP nsProfile::MigrateProfileInfo()
|
||||
#endif /* XP_PC || XP_MAC */
|
||||
|
||||
gProfileDataAccess->mProfileDataChanged = PR_TRUE;
|
||||
gProfileDataAccess->UpdateRegistry();
|
||||
gProfileDataAccess->UpdateRegistry(nsnull);
|
||||
|
||||
return rv;
|
||||
}
|
||||
@@ -1578,7 +1578,7 @@ nsProfile::MigrateProfile(const PRUnichar* profileName, PRBool showProgressAsMod
|
||||
gProfileDataAccess->mNumOldProfiles--;
|
||||
|
||||
gProfileDataAccess->mProfileDataChanged = PR_TRUE;
|
||||
gProfileDataAccess->UpdateRegistry();
|
||||
gProfileDataAccess->UpdateRegistry(nsnull);
|
||||
|
||||
return rv;
|
||||
}
|
||||
@@ -1882,12 +1882,12 @@ nsProfile::CreateDefaultProfile(void)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsProfile::UpdateRegistry(void)
|
||||
nsProfile::UpdateRegistry(nsIFile* regName)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
gProfileDataAccess->mProfileDataChanged = PR_TRUE;
|
||||
rv= gProfileDataAccess->UpdateRegistry();
|
||||
rv= gProfileDataAccess->UpdateRegistry(regName);
|
||||
|
||||
return rv;
|
||||
}
|
||||
@@ -2094,3 +2094,4 @@ nsresult nsProfile::CloneProfileDirectorySpec(nsILocalFile **aLocalFile)
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@
|
||||
#define REGISTRY_MIGRATED_STRING "migrated"
|
||||
#define REGISTRY_DIRECTORY_STRING "directory"
|
||||
#define REGISTRY_NEED_MIGRATION_STRING "NeedMigration"
|
||||
#define REGISTRY_MOZREG_DATA_MOVED_STRING "OldRegDataMoved"
|
||||
|
||||
#define REGISTRY_VERSION_STRING "Version"
|
||||
#define REGISTRY_VERSION_1_0 "1.0"
|
||||
|
||||
@@ -32,9 +32,9 @@
|
||||
#include "nsSpecialSystemDirectory.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIFileSpec.h"
|
||||
#include "nsFileStream.h"
|
||||
#include "nsEscape.h"
|
||||
#include "nsDirectoryServiceDefs.h"
|
||||
|
||||
#define NS_IMPL_IDS
|
||||
#include "nsICharsetConverterManager.h"
|
||||
@@ -53,6 +53,15 @@
|
||||
#elif defined (XP_BEOS)
|
||||
#endif
|
||||
|
||||
#if defined(XP_PC)
|
||||
#define WIN_MOZ_REG "mozregistry.dat"
|
||||
#elif defined(XP_MAC)
|
||||
#define MAC_MOZ_REG "Mozilla Registry"
|
||||
#elif defined(XP_UNIX)
|
||||
#define UNIX_MOZ_REG_FOLDER ".mozilla"
|
||||
#define UNIX_MOZ_REG_FILE "registry"
|
||||
#endif
|
||||
|
||||
// IID and CIDs of all the services needed
|
||||
static NS_DEFINE_CID(kRegistryCID, NS_REGISTRY_CID);
|
||||
static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
|
||||
@@ -74,7 +83,68 @@ nsProfileAccess::nsProfileAccess()
|
||||
mProfiles = new nsVoidArray();
|
||||
m4xProfiles = new nsVoidArray();
|
||||
|
||||
FillProfileInfo();
|
||||
// Get the profile registry path
|
||||
NS_GetSpecialDirectory(NS_XPCOM_APPLICATION_REGISTRY_FILE, getter_AddRefs(mNewRegFile));
|
||||
|
||||
PRBool regDataMoved = PR_FALSE;
|
||||
PRBool oldMozRegFileExists = PR_FALSE;
|
||||
|
||||
// Get the old moz registry
|
||||
nsCOMPtr<nsIFile> mozRegFile;
|
||||
|
||||
#if defined(XP_PC)
|
||||
NS_GetSpecialDirectory(NS_WIN_WINDOWS_DIR, getter_AddRefs(mozRegFile));
|
||||
if (mozRegFile)
|
||||
mozRegFile->Append(WIN_MOZ_REG);
|
||||
#elif defined(XP_MAC)
|
||||
NS_GetSpecialDirectory(NS_MAC_PREFS_DIR, getter_AddRefs(mozRegFile));
|
||||
if (mozRegFile)
|
||||
mozRegFile->Append(MAC_MOZ_REG);
|
||||
#elif defined(XP_UNIX)
|
||||
NS_GetSpecialDirectory(NS_UNIX_HOME_DIR, getter_AddRefs(mozRegFile));
|
||||
if (mozRegFile)
|
||||
{
|
||||
mozRegFile->Append(UNIX_MOZ_REG_FOLDER);
|
||||
mozRegFile->Append(UNIX_MOZ_REG_FILE);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Check if the old profile registry exists, before we decide
|
||||
// on transfering the data.
|
||||
if (mozRegFile)
|
||||
mozRegFile->Exists(&oldMozRegFileExists);
|
||||
|
||||
if (oldMozRegFileExists) {
|
||||
// Check to see if there is a requirement to move the registry data..
|
||||
GetMozRegDataMovedFlag(®DataMoved);
|
||||
|
||||
// If we have not transfered the data from old registry,
|
||||
// do it now....
|
||||
if (!regDataMoved)
|
||||
{
|
||||
// Get the data from old moz registry
|
||||
FillProfileInfo(mozRegFile);
|
||||
// Flush the registry to be on safe side.
|
||||
CloseRegistry();
|
||||
|
||||
// Internal data structure now has all the data from old
|
||||
// registry. Update the Flush the new registry with this info.
|
||||
mProfileDataChanged = PR_TRUE;
|
||||
UpdateRegistry(mNewRegFile);
|
||||
CloseRegistry();
|
||||
|
||||
// Set the flag in the new registry to indicate that we have
|
||||
// transfered the data from the old registry
|
||||
SetMozRegDataMovedFlag(mNewRegFile);
|
||||
|
||||
// Time to clean the internal data structure and make it
|
||||
// ready for reading values from the new registry.
|
||||
ResetProfileMembers();
|
||||
}
|
||||
}
|
||||
// Now the new registry is the one with all profile information
|
||||
// Read the data into internal data structure....
|
||||
FillProfileInfo(mNewRegFile);
|
||||
}
|
||||
|
||||
// On the way out, close the registry if it is
|
||||
@@ -82,7 +152,7 @@ nsProfileAccess::nsProfileAccess()
|
||||
nsProfileAccess::~nsProfileAccess()
|
||||
{
|
||||
// Release all resources.
|
||||
|
||||
mNewRegFile = nsnull;
|
||||
FreeProfileMembers(mProfiles, mCount);
|
||||
FreeProfileMembers(m4xProfiles, m4xCount);
|
||||
}
|
||||
@@ -177,11 +247,14 @@ nsProfileAccess::CloseRegistry()
|
||||
// Open the registry.
|
||||
// If already opened, just use it.
|
||||
nsresult
|
||||
nsProfileAccess::OpenRegistry()
|
||||
nsProfileAccess::OpenRegistry(const char* regName)
|
||||
{
|
||||
nsresult rv;
|
||||
PRBool openalready = PR_FALSE;
|
||||
|
||||
if (!regName)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if (!m_registry) {
|
||||
rv = nsComponentManager::CreateInstance(kRegistryCID,
|
||||
nsnull,
|
||||
@@ -196,7 +269,7 @@ nsProfileAccess::OpenRegistry()
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (!openalready)
|
||||
rv = m_registry->OpenWellKnownRegistry(nsIRegistry::ApplicationRegistry);
|
||||
rv = m_registry->Open(regName);
|
||||
|
||||
return rv;
|
||||
}
|
||||
@@ -309,11 +382,15 @@ nsProfileAccess::SetValue(ProfileStruct* aProfile)
|
||||
// data structure to reflect the latest status.
|
||||
// Data will be flushed at the end.
|
||||
nsresult
|
||||
nsProfileAccess::FillProfileInfo()
|
||||
nsProfileAccess::FillProfileInfo(nsIFile* regName)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsXPIDLCString regFile;
|
||||
|
||||
rv = OpenRegistry();
|
||||
if (regName)
|
||||
regName->GetPath(getter_Copies(regFile));
|
||||
|
||||
rv = OpenRegistry(regFile);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Enumerate all subkeys (immediately) under the given node.
|
||||
@@ -784,16 +861,27 @@ nsProfileAccess::FindProfileIndex(const PRUnichar* profileName)
|
||||
|
||||
// Flush profile information from the data structure to the registry.
|
||||
nsresult
|
||||
nsProfileAccess::UpdateRegistry()
|
||||
nsProfileAccess::UpdateRegistry(nsIFile* regName)
|
||||
{
|
||||
nsresult rv;
|
||||
nsXPIDLCString regFile;
|
||||
|
||||
if (!mProfileDataChanged)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
rv = OpenRegistry();
|
||||
if (!regName)
|
||||
{
|
||||
if (mNewRegFile)
|
||||
mNewRegFile->GetPath(getter_Copies(regFile));
|
||||
}
|
||||
else
|
||||
{
|
||||
regName->GetPath(getter_Copies(regFile));
|
||||
}
|
||||
|
||||
rv = OpenRegistry(regFile);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Enumerate all subkeys (immediately) under the given node.
|
||||
@@ -1331,3 +1419,98 @@ nsProfileAccess::CheckRegString(const PRUnichar *profileName, char **info)
|
||||
}
|
||||
}
|
||||
|
||||
// Get the flag that from the new reigstry which indicates that it
|
||||
// got the transfered data from old mozilla registry
|
||||
nsresult
|
||||
nsProfileAccess::GetMozRegDataMovedFlag(PRBool *isDataMoved)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsXPIDLCString regFile;
|
||||
|
||||
nsRegistryKey profilesTreeKey;
|
||||
nsXPIDLString tmpRegDataMoved;
|
||||
|
||||
nsAutoString mozRegDataMovedString;
|
||||
mozRegDataMovedString.AssignWithConversion(REGISTRY_MOZREG_DATA_MOVED_STRING);
|
||||
nsAutoString registryProfileSubtreeString;
|
||||
registryProfileSubtreeString.AssignWithConversion(REGISTRY_PROFILE_SUBTREE_STRING);
|
||||
|
||||
if (mNewRegFile)
|
||||
mNewRegFile->GetPath(getter_Copies(regFile));
|
||||
|
||||
rv = OpenRegistry(regFile);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = m_registry->GetKey(nsIRegistry::Common,
|
||||
registryProfileSubtreeString.GetUnicode(),
|
||||
&profilesTreeKey);
|
||||
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
rv = m_registry->GetString(profilesTreeKey,
|
||||
mozRegDataMovedString.GetUnicode(),
|
||||
getter_Copies(tmpRegDataMoved));
|
||||
|
||||
nsAutoString isDataMovedString(tmpRegDataMoved);
|
||||
if (isDataMovedString.EqualsWithConversion(REGISTRY_YES_STRING))
|
||||
*isDataMoved = PR_TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = m_registry->AddKey(nsIRegistry::Common,
|
||||
registryProfileSubtreeString.GetUnicode(),
|
||||
&profilesTreeKey);
|
||||
}
|
||||
CloseRegistry();
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Set the flag in the new reigstry which indicates that it
|
||||
// got the transfered data from old mozilla registry
|
||||
nsresult
|
||||
nsProfileAccess::SetMozRegDataMovedFlag(nsIFile* regName)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsXPIDLCString regFile;
|
||||
|
||||
if (regName)
|
||||
regName->GetPath(getter_Copies(regFile));
|
||||
|
||||
nsRegistryKey profilesTreeKey;
|
||||
nsXPIDLString tmpRegDataMoved;
|
||||
|
||||
nsAutoString mozRegDataMovedString;
|
||||
mozRegDataMovedString.AssignWithConversion(REGISTRY_MOZREG_DATA_MOVED_STRING);
|
||||
nsAutoString registryProfileSubtreeString;
|
||||
registryProfileSubtreeString.AssignWithConversion(REGISTRY_PROFILE_SUBTREE_STRING);
|
||||
nsAutoString regYesString;
|
||||
regYesString.AssignWithConversion(REGISTRY_YES_STRING);
|
||||
|
||||
rv = OpenRegistry(regFile);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = m_registry->GetKey(nsIRegistry::Common,
|
||||
registryProfileSubtreeString.GetUnicode(),
|
||||
&profilesTreeKey);
|
||||
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
rv = m_registry->SetString(profilesTreeKey,
|
||||
mozRegDataMovedString.GetUnicode(),
|
||||
regYesString.GetUnicode());
|
||||
}
|
||||
CloseRegistry();
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Clear the profile member data structure
|
||||
// We need to fill in the data from the new registry
|
||||
nsresult
|
||||
nsProfileAccess::ResetProfileMembers()
|
||||
{
|
||||
FreeProfileMembers(mProfiles, mCount);
|
||||
mProfiles = new nsVoidArray();
|
||||
mCount = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
#include "nsIRegistry.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsIFileSpec.h"
|
||||
#include "nsIFile.h"
|
||||
|
||||
class ProfileStruct
|
||||
{
|
||||
@@ -49,6 +51,7 @@ class nsProfileAccess
|
||||
|
||||
private:
|
||||
nsCOMPtr <nsIRegistry> m_registry;
|
||||
nsCOMPtr <nsIFile> mNewRegFile;
|
||||
|
||||
// This is an array that holds all the profile information--migrated/unmigrated
|
||||
// unmigrated: if the profileinfo is migrated--i.e. -installer option is used
|
||||
@@ -69,7 +72,7 @@ private:
|
||||
PRInt32 m4xCount;
|
||||
|
||||
|
||||
nsresult OpenRegistry();
|
||||
nsresult OpenRegistry(const char* regName);
|
||||
nsresult CloseRegistry();
|
||||
|
||||
// It looks like mCount and m4xCount are not required.
|
||||
@@ -92,7 +95,7 @@ public:
|
||||
virtual ~nsProfileAccess();
|
||||
|
||||
nsresult SetValue(ProfileStruct* aProfile);
|
||||
nsresult FillProfileInfo();
|
||||
nsresult FillProfileInfo(nsIFile* regName);
|
||||
|
||||
void GetNumProfiles(PRInt32 *numProfiles);
|
||||
void GetNum4xProfiles(PRInt32 *numProfiles);
|
||||
@@ -108,7 +111,7 @@ public:
|
||||
nsresult GetValue(const PRUnichar* profileName, ProfileStruct** aProfile);
|
||||
PRInt32 FindProfileIndex(const PRUnichar* profileName);
|
||||
|
||||
nsresult UpdateRegistry();
|
||||
nsresult UpdateRegistry(nsIFile* regName);
|
||||
void GetProfileList(PRUnichar **profileListStr);
|
||||
PRBool ProfileExists(const PRUnichar *profileName);
|
||||
nsresult Get4xProfileInfo(const char *registryName);
|
||||
@@ -116,6 +119,9 @@ public:
|
||||
void SetPREGInfo(const char* pregInfo);
|
||||
void CheckRegString(const PRUnichar *profileName, char** regString);
|
||||
void FreeProfileMembers(nsVoidArray *aProfile, PRInt32 numElems);
|
||||
nsresult GetMozRegDataMovedFlag(PRBool *regDataMoved);
|
||||
nsresult SetMozRegDataMovedFlag(nsIFile* regName);
|
||||
nsresult ResetProfileMembers();
|
||||
};
|
||||
|
||||
#endif // __nsProfileAccess_h___
|
||||
|
||||
Reference in New Issue
Block a user