зеркало из https://github.com/mozilla/pjs.git
Backout changeset 81a7f5489ebc (bug 679352), since burning comm-central; a=callek
This commit is contained in:
Родитель
5405dc2590
Коммит
104c371d02
|
@ -56,6 +56,7 @@
|
|||
#include "nsDirectoryServiceDefs.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
|
||||
#include "NSReg.h"
|
||||
#include "nsStringAPI.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
#ifdef XP_WIN
|
||||
|
@ -68,6 +69,18 @@
|
|||
|
||||
#include "nsAutoPtr.h"
|
||||
|
||||
#ifndef MAXPATHLEN
|
||||
#ifdef PATH_MAX
|
||||
#define MAXPATHLEN PATH_MAX
|
||||
#elif defined(_MAX_PATH)
|
||||
#define MAXPATHLEN _MAX_PATH
|
||||
#elif defined(CCHMAXPATH)
|
||||
#define MAXPATHLEN CCHMAXPATH
|
||||
#else
|
||||
#define MAXPATHLEN 1024
|
||||
#endif
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// nsIProfileMigrator
|
||||
|
||||
|
@ -131,6 +144,15 @@ nsProfileMigrator::Migrate(nsIProfileStartup* aStartup)
|
|||
getter_AddRefs(migrateWizard));
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsProfileMigrator::Import()
|
||||
{
|
||||
if (ImportRegistryProfiles(NS_LITERAL_CSTRING("Firefox")))
|
||||
return NS_OK;
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// nsProfileMigrator
|
||||
|
||||
|
@ -245,3 +267,110 @@ nsProfileMigrator::GetDefaultBrowserMigratorKey(nsACString& aKey,
|
|||
#endif
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsProfileMigrator::ImportRegistryProfiles(const nsACString& aAppName)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIToolkitProfileService> profileSvc
|
||||
(do_GetService(NS_PROFILESERVICE_CONTRACTID));
|
||||
NS_ENSURE_TRUE(profileSvc, PR_FALSE);
|
||||
|
||||
nsCOMPtr<nsIProperties> dirService
|
||||
(do_GetService("@mozilla.org/file/directory_service;1"));
|
||||
NS_ENSURE_TRUE(dirService, PR_FALSE);
|
||||
|
||||
nsCOMPtr<nsILocalFile> regFile;
|
||||
#ifdef XP_WIN
|
||||
rv = dirService->Get(NS_WIN_APPDATA_DIR, NS_GET_IID(nsILocalFile),
|
||||
getter_AddRefs(regFile));
|
||||
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
||||
regFile->AppendNative(aAppName);
|
||||
regFile->AppendNative(NS_LITERAL_CSTRING("registry.dat"));
|
||||
#elif defined(XP_MACOSX)
|
||||
rv = dirService->Get(NS_MAC_USER_LIB_DIR, NS_GET_IID(nsILocalFile),
|
||||
getter_AddRefs(regFile));
|
||||
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
||||
regFile->AppendNative(aAppName);
|
||||
regFile->AppendNative(NS_LITERAL_CSTRING("Application Registry"));
|
||||
#elif defined(XP_OS2)
|
||||
rv = dirService->Get(NS_OS2_HOME_DIR, NS_GET_IID(nsILocalFile),
|
||||
getter_AddRefs(regFile));
|
||||
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
||||
regFile->AppendNative(aAppName);
|
||||
regFile->AppendNative(NS_LITERAL_CSTRING("registry.dat"));
|
||||
#else
|
||||
rv = dirService->Get(NS_UNIX_HOME_DIR, NS_GET_IID(nsILocalFile),
|
||||
getter_AddRefs(regFile));
|
||||
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
||||
nsCAutoString dotAppName;
|
||||
ToLowerCase(aAppName, dotAppName);
|
||||
dotAppName.Insert('.', 0);
|
||||
|
||||
regFile->AppendNative(dotAppName);
|
||||
regFile->AppendNative(NS_LITERAL_CSTRING("appreg"));
|
||||
#endif
|
||||
|
||||
nsCAutoString path;
|
||||
rv = regFile->GetNativePath(path);
|
||||
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
||||
|
||||
if (NR_StartupRegistry())
|
||||
return PR_FALSE;
|
||||
|
||||
PRBool migrated = PR_FALSE;
|
||||
HREG reg = nsnull;
|
||||
RKEY profiles = 0;
|
||||
REGENUM enumstate = 0;
|
||||
char profileName[MAXREGNAMELEN];
|
||||
|
||||
if (NR_RegOpen(path.get(), ®))
|
||||
goto cleanup;
|
||||
|
||||
if (NR_RegGetKey(reg, ROOTKEY_COMMON, "Profiles", &profiles))
|
||||
goto cleanup;
|
||||
|
||||
while (!NR_RegEnumSubkeys(reg, profiles, &enumstate,
|
||||
profileName, MAXREGNAMELEN, REGENUM_CHILDREN)) {
|
||||
#ifdef DEBUG_bsmedberg
|
||||
printf("Found profile %s.\n", profileName);
|
||||
#endif
|
||||
|
||||
RKEY profile = 0;
|
||||
if (NR_RegGetKey(reg, profiles, profileName, &profile)) {
|
||||
NS_ERROR("Could not get the key that was enumerated.");
|
||||
continue;
|
||||
}
|
||||
|
||||
char profilePath[MAXPATHLEN];
|
||||
if (NR_RegGetEntryString(reg, profile, "directory",
|
||||
profilePath, MAXPATHLEN))
|
||||
continue;
|
||||
|
||||
nsCOMPtr<nsILocalFile> profileFile
|
||||
(do_CreateInstance("@mozilla.org/file/local;1"));
|
||||
if (!profileFile)
|
||||
continue;
|
||||
|
||||
#if defined (XP_MACOSX)
|
||||
rv = profileFile->SetPersistentDescriptor(nsDependentCString(profilePath));
|
||||
#else
|
||||
NS_ConvertUTF8toUTF16 widePath(profilePath);
|
||||
rv = profileFile->InitWithPath(widePath);
|
||||
#endif
|
||||
if (NS_FAILED(rv)) continue;
|
||||
|
||||
nsCOMPtr<nsIToolkitProfile> tprofile;
|
||||
profileSvc->CreateProfile(profileFile, nsnull,
|
||||
nsDependentCString(profileName),
|
||||
getter_AddRefs(tprofile));
|
||||
migrated = PR_TRUE;
|
||||
}
|
||||
|
||||
cleanup:
|
||||
if (reg)
|
||||
NR_RegClose(reg);
|
||||
NR_ShutdownRegistry();
|
||||
return migrated;
|
||||
}
|
||||
|
|
|
@ -58,6 +58,12 @@ protected:
|
|||
|
||||
nsresult GetDefaultBrowserMigratorKey(nsACString& key,
|
||||
nsCOMPtr<nsIBrowserProfileMigrator>& bpm);
|
||||
|
||||
/**
|
||||
* Import profiles from ~/.firefox/
|
||||
* @return PR_TRUE if any profiles imported.
|
||||
*/
|
||||
PRBool ImportRegistryProfiles(const nsACString& aAppName);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -72,6 +72,19 @@ interface nsIProfileStartup : nsISupports
|
|||
[scriptable, uuid(24ce8b9d-b7ff-4279-aef4-26e158f03e34)]
|
||||
interface nsIProfileMigrator : nsISupports
|
||||
{
|
||||
/**
|
||||
* Import existing profile paths. When the app is started the first
|
||||
* time, if there are no INI-style profiles, appstartup will call
|
||||
* this method to import any registry- style profiles that may
|
||||
* exist. When this method is called, there is no event queue
|
||||
* service and this method should not attempt to use the network or
|
||||
* show any GUI.
|
||||
*
|
||||
* @note You don't actually have to move the profile data. Just call
|
||||
* nsIToolkitProfileService.create on the existing profile path(s).
|
||||
*/
|
||||
void import();
|
||||
|
||||
/**
|
||||
* Do profile migration.
|
||||
*
|
||||
|
|
|
@ -1861,6 +1861,35 @@ ShowProfileManager(nsIToolkitProfileService* aProfileSvc,
|
|||
return LaunchChild(aNative);
|
||||
}
|
||||
|
||||
static nsresult
|
||||
ImportProfiles(nsIToolkitProfileService* aPService,
|
||||
nsINativeAppSupport* aNative)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
SaveToEnv("XRE_IMPORT_PROFILES=1");
|
||||
|
||||
// try to import old-style profiles
|
||||
{ // scope XPCOM
|
||||
ScopedXPCOMStartup xpcom;
|
||||
rv = xpcom.Initialize();
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
#ifdef XP_MACOSX
|
||||
CommandLineServiceMac::SetupMacCommandLine(gRestartArgc, gRestartArgv, PR_TRUE);
|
||||
#endif
|
||||
|
||||
nsCOMPtr<nsIProfileMigrator> migrator
|
||||
(do_GetService(NS_PROFILEMIGRATOR_CONTRACTID));
|
||||
if (migrator) {
|
||||
migrator->Import();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
aPService->Flush();
|
||||
return LaunchChild(aNative);
|
||||
}
|
||||
|
||||
// Pick a profile. We need to end up with a profile lock.
|
||||
//
|
||||
// 1) check for -profile <path>
|
||||
|
@ -2012,6 +2041,12 @@ SelectProfile(nsIProfileLock* *aResult, nsINativeAppSupport* aNative,
|
|||
rv = profileSvc->GetProfileCount(&count);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (gAppData->flags & NS_XRE_ENABLE_PROFILE_MIGRATOR) {
|
||||
if (!count && !EnvHasValue("XRE_IMPORT_PROFILES")) {
|
||||
return ImportProfiles(profileSvc, aNative);
|
||||
}
|
||||
}
|
||||
|
||||
ar = CheckArg("p", PR_FALSE, &arg);
|
||||
if (ar == ARG_BAD) {
|
||||
ar = CheckArg("osint");
|
||||
|
@ -3433,6 +3468,7 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData)
|
|||
SaveToEnv("XRE_PROFILE_LOCAL_PATH=");
|
||||
SaveToEnv("XRE_PROFILE_NAME=");
|
||||
SaveToEnv("XRE_START_OFFLINE=");
|
||||
SaveToEnv("XRE_IMPORT_PROFILES=");
|
||||
SaveToEnv("NO_EM_RESTART=");
|
||||
SaveToEnv("XUL_APP_FILE=");
|
||||
SaveToEnv("XRE_BINARY_PATH=");
|
||||
|
|
Загрузка…
Ссылка в новой задаче