Bug 679352 - Remove libreg (Part 1: Clean nsProfileMigrator). r=bsmedberg

This commit is contained in:
Marco Castelluccio 2011-09-24 16:25:20 +02:00
Родитель 72d3a7d2e0
Коммит df8ae70db2
4 изменённых файлов: 0 добавлений и 184 удалений

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

@ -56,7 +56,6 @@
#include "nsDirectoryServiceDefs.h"
#include "nsServiceManagerUtils.h"
#include "NSReg.h"
#include "nsStringAPI.h"
#include "nsUnicharUtils.h"
#ifdef XP_WIN
@ -69,18 +68,6 @@
#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
@ -144,15 +131,6 @@ 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
@ -267,110 +245,3 @@ 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(), &reg))
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,12 +58,6 @@ 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,19 +72,6 @@ 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,35 +1861,6 @@ 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>
@ -2041,12 +2012,6 @@ 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");
@ -3468,7 +3433,6 @@ 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=");