Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Protected Member Functions
nsProfileMigrator Class Reference

#include <nsProfileMigrator.h>

Inheritance diagram for nsProfileMigrator:
Inheritance graph
[legend]
Collaboration diagram for nsProfileMigrator:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_NSIPROFILEMIGRATOR
NS_DECL_ISUPPORTS 
nsProfileMigrator ()
void migrate (in nsIProfileStartup aStartup)
 Do profile migration.

Public Attributes

 void
 Import existing profile paths.

Protected Member Functions

 ~nsProfileMigrator ()
nsresult GetDefaultMailMigratorKey (nsACString &key, nsCOMPtr< nsIMailProfileMigrator > &mailMigrator)
PRBool ImportRegistryProfiles (const nsACString &aAppName)
 Import profiles from ~/.thunderbird/.

Detailed Description

Definition at line 56 of file nsProfileMigrator.h.


Constructor & Destructor Documentation

NS_DECL_NSIPROFILEMIGRATOR NS_DECL_ISUPPORTS nsProfileMigrator::nsProfileMigrator ( ) [inline]

Definition at line 62 of file nsProfileMigrator.h.

{ };
nsProfileMigrator::~nsProfileMigrator ( ) [inline, protected]

Definition at line 65 of file nsProfileMigrator.h.

{ };

Member Function Documentation

nsresult nsProfileMigrator::GetDefaultMailMigratorKey ( nsACString &  key,
nsCOMPtr< nsIMailProfileMigrator > &  mailMigrator 
) [protected]

Definition at line 121 of file nsProfileMigrator.cpp.

{
  // look up the value of profile.force.migration in case we are supposed to force migration using a particular
  // migrator....
  nsresult rv = NS_OK;
  nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
  NS_ENSURE_SUCCESS(rv, rv);

  nsXPIDLCString forceMigrationType;
  prefs->GetCharPref("profile.force.migration", getter_Copies(forceMigrationType));

  // if we are being forced to migrate to a particular migration type, then create an instance of that migrator
  // and return it.
  if (forceMigrationType.get())
  {
    PRBool exists = PR_FALSE;
    nsCAutoString migratorID (NS_MAILPROFILEMIGRATOR_CONTRACTID_PREFIX);
    migratorID.Append(forceMigrationType);
    mailMigrator = do_CreateInstance(migratorID.get());
  
    if (mailMigrator)
    {
      mailMigrator->GetSourceExists(&exists);
      if (exists) 
        aKey = forceMigrationType;
      else
        rv = NS_ERROR_FAILURE; // trying to force migration on a source which does not have any profiles
    }
  }
 
  return rv;
}

Here is the call graph for this function:

PRBool nsProfileMigrator::ImportRegistryProfiles ( const nsACString &  aAppName) [protected]

Import profiles from ~/.thunderbird/.

Returns:
PR_TRUE if any profiles imported.

Definition at line 164 of file nsProfileMigrator.cpp.

{
  nsresult rv;

  nsCOMPtr<nsIToolkitProfileService> profileSvc
    (do_GetService(NS_PROFILESERVICE_CONTRACTID));
  NS_ENSURE_TRUE(profileSvc, NS_ERROR_FAILURE);

  nsCOMPtr<nsIProperties> dirService
    (do_GetService("@mozilla.org/file/directory_service;1"));
  NS_ENSURE_TRUE(dirService, NS_ERROR_FAILURE);

  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"));
#elif defined(XP_BEOS)
  rv = dirService->Get(NS_BEOS_SETTINGS_DIR, NS_GET_IID(nsILocalFile),
                       getter_AddRefs(regFile));
  NS_ENSURE_SUCCESS(rv, PR_FALSE);
  regFile->AppendNative(aAppName);
  regFile->AppendNative(NS_LITERAL_CSTRING("appreg"));
#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;
}

Here is the call graph for this function:

Do profile migration.

When this method is called, a default profile has been created; XPCOM has been initialized such that compreg.dat is in the profile; the directory service does not return a key for NS_APP_USER_PROFILE_50_DIR or any of the keys depending on an active profile. To figure out the directory of the "current" profile, use aStartup.directory.

If your migrator needs to access services that use the profile (to set profile prefs or bookmarks, for example), use aStartup.doStartup.

The startup code ignores COM exceptions thrown from this method.


Member Data Documentation

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).

Definition at line 86 of file nsIProfileMigrator.idl.


The documentation for this class was generated from the following files: