Back to index

lightning-sunbird  0.9+nobinonly
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
nsNetscapeProfileMigratorBase Class Reference

#include <nsNetscapeProfileMigratorBase.h>

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

List of all members.

Classes

struct  PrefTransform
union  PrefTransform.__unnamed__

Public Types

typedef nsresult(* prefConverter )(void *, nsIPrefBranch *)

Public Member Functions

 nsNetscapeProfileMigratorBase ()
virtual ~nsNetscapeProfileMigratorBase ()
nsresult RecursiveCopy (nsIFile *srcDir, nsIFile *destDir)

Static Public Member Functions

static nsresult GetString (void *aTransform, nsIPrefBranch *aBranch)
static nsresult SetString (void *aTransform, nsIPrefBranch *aBranch)
static nsresult GetWString (void *aTransform, nsIPrefBranch *aBranch)
static nsresult SetWString (void *aTransform, nsIPrefBranch *aBranch)
static nsresult SetWStringFromASCII (void *aTransform, nsIPrefBranch *aBranch)
static nsresult GetBool (void *aTransform, nsIPrefBranch *aBranch)
static nsresult SetBool (void *aTransform, nsIPrefBranch *aBranch)
static nsresult GetInt (void *aTransform, nsIPrefBranch *aBranch)
static nsresult SetInt (void *aTransform, nsIPrefBranch *aBranch)

Protected Member Functions

nsresult GetProfileDataFromRegistry (nsILocalFile *aRegistryFile, nsISupportsArray *aProfileNames, nsISupportsArray *aProfileLocations)
nsresult CopyFile (const nsAString &aSourceFileName, const nsAString &aTargetFileName)
nsresult GetSignonFileName (PRBool aReplace, char **aFileName)
nsresult LocateSignonsFile (char **aResult)

Protected Attributes

nsCOMPtr< nsILocalFilemSourceProfile
nsCOMPtr< nsIFilemTargetProfile
nsCOMPtr< nsIStringBundlemBundle
nsVoidArraymFileCopyTransactions
PRUint32 mFileCopyTransactionIndex

Detailed Description

Definition at line 57 of file nsNetscapeProfileMigratorBase.h.


Class Documentation

struct nsNetscapeProfileMigratorBase::PrefTransform

Definition at line 66 of file nsNetscapeProfileMigratorBase.h.

Collaboration diagram for nsNetscapeProfileMigratorBase::PrefTransform:
Class Members
union PrefTransform __unnamed__
prefConverter prefGetterFunc
PRBool prefHasValue
prefConverter prefSetterFunc
char * sourcePrefName
char * targetPrefName
union nsNetscapeProfileMigratorBase::PrefTransform.__unnamed__

Definition at line 72 of file nsNetscapeProfileMigratorBase.h.

Class Members
PRBool boolValue
PRInt32 intValue
char * stringValue

Member Typedef Documentation

Definition at line 64 of file nsNetscapeProfileMigratorBase.h.


Constructor & Destructor Documentation

Definition at line 70 of file nsNetscapeProfileMigratorBase.cpp.

{
  nsCOMPtr<nsIStringBundleService> bundleService(do_GetService(kStringBundleServiceCID));
  bundleService->CreateBundle(MIGRATION_BUNDLE, getter_AddRefs(mBundle));

  // create the array we'll be using to keep track of the asynchronous file copy routines
  mFileCopyTransactions = new nsVoidArray();
  mFileCopyTransactionIndex = 0;
}

Here is the call graph for this function:

Definition at line 61 of file nsNetscapeProfileMigratorBase.h.

{ };

Member Function Documentation

nsresult nsNetscapeProfileMigratorBase::CopyFile ( const nsAString &  aSourceFileName,
const nsAString &  aTargetFileName 
) [protected]

Definition at line 253 of file nsNetscapeProfileMigratorBase.cpp.

{
  nsCOMPtr<nsIFile> sourceFile;
  mSourceProfile->Clone(getter_AddRefs(sourceFile));

  sourceFile->Append(aSourceFileName);
  PRBool exists = PR_FALSE;
  sourceFile->Exists(&exists);
  if (!exists)
    return NS_OK;

  nsCOMPtr<nsIFile> targetFile;
  mTargetProfile->Clone(getter_AddRefs(targetFile));
  
  targetFile->Append(aTargetFileName);
  targetFile->Exists(&exists);
  if (exists)
    targetFile->Remove(PR_FALSE);

  return sourceFile->CopyTo(mTargetProfile, aTargetFileName);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsNetscapeProfileMigratorBase::GetBool ( void aTransform,
nsIPrefBranch aBranch 
) [static]

Definition at line 225 of file nsNetscapeProfileMigratorBase.cpp.

{
  PrefTransform* xform = (PrefTransform*)aTransform;
  GETPREF(xform, GetBoolPref, &xform->boolValue);
}
nsresult nsNetscapeProfileMigratorBase::GetInt ( void aTransform,
nsIPrefBranch aBranch 
) [static]

Definition at line 239 of file nsNetscapeProfileMigratorBase.cpp.

{
  PrefTransform* xform = (PrefTransform*)aTransform;
  GETPREF(xform, GetIntPref, &xform->intValue);
}
nsresult nsNetscapeProfileMigratorBase::GetProfileDataFromRegistry ( nsILocalFile aRegistryFile,
nsISupportsArray aProfileNames,
nsISupportsArray aProfileLocations 
) [protected]

Definition at line 81 of file nsNetscapeProfileMigratorBase.cpp.

{
  nsresult rv = NS_OK;

  // Open It
  nsCOMPtr<nsIRegistry> reg(do_CreateInstance("@mozilla.org/registry;1"));
  reg->Open(aRegistryFile);

  nsRegistryKey profilesTree;
  rv = reg->GetKey(nsIRegistry::Common, NS_LITERAL_STRING("Profiles").get(), &profilesTree);
  if (NS_FAILED(rv)) return rv;

  nsCOMPtr<nsIEnumerator> keys;
  reg->EnumerateSubtrees(profilesTree, getter_AddRefs(keys));

  keys->First();
  while (keys->IsDone() != NS_OK) {
    nsCOMPtr<nsISupports> key;
    keys->CurrentItem(getter_AddRefs(key));

    nsCOMPtr<nsIRegistryNode> node(do_QueryInterface(key));

    nsRegistryKey profile;
    node->GetKey(&profile);

    // "migrated" is "yes" for all valid Seamonkey profiles. It is only "no"
    // for 4.x profiles. 
    nsXPIDLString isMigrated;
    reg->GetString(profile, NS_LITERAL_STRING("migrated").get(), getter_Copies(isMigrated));

    if (isMigrated.Equals(NS_LITERAL_STRING("no"))) {
      keys->Next();
      continue;
    }

    // Get the profile name and add it to the names array
    nsXPIDLString profileName;
    node->GetName(getter_Copies(profileName));

    // Get the profile location and add it to the locations array
    nsXPIDLString directory;
    reg->GetString(profile, NS_LITERAL_STRING("directory").get(), getter_Copies(directory));

    nsCOMPtr<nsILocalFile> dir;
#ifdef XP_MACOSX
    rv = NS_NewNativeLocalFile(EmptyCString(), PR_TRUE, getter_AddRefs(dir));
    if (NS_FAILED(rv)) return rv;
    dir->SetPersistentDescriptor(NS_LossyConvertUCS2toASCII(directory));
#else
    rv = NS_NewLocalFile(directory, PR_TRUE, getter_AddRefs(dir));
    if (NS_FAILED(rv)) return rv;
#endif

    PRBool exists;
    dir->Exists(&exists);

    if (exists) {
      nsCOMPtr<nsISupportsString> profileNameString(do_CreateInstance("@mozilla.org/supports-string;1"));
      profileNameString->SetData(profileName);
      aProfileNames->AppendElement(profileNameString);

      aProfileLocations->AppendElement(dir);
    }

    keys->Next();
  }
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsNetscapeProfileMigratorBase::GetSignonFileName ( PRBool  aReplace,
char **  aFileName 
) [protected]

Definition at line 276 of file nsNetscapeProfileMigratorBase.cpp.

{
  nsresult rv;
  if (aReplace) {
    // Find out what the signons file was called, this is stored in a pref
    // in Seamonkey.
    nsCOMPtr<nsIPrefService> psvc(do_GetService(NS_PREFSERVICE_CONTRACTID));
    psvc->ResetPrefs();

    nsCOMPtr<nsIFile> sourcePrefsName;
    mSourceProfile->Clone(getter_AddRefs(sourcePrefsName));
    sourcePrefsName->Append(FILE_NAME_PREFS_5X);
    psvc->ReadUserPrefs(sourcePrefsName);

    nsCOMPtr<nsIPrefBranch> branch(do_QueryInterface(psvc));
    rv = branch->GetCharPref("signon.SignonFileName", aFileName);
  }
  else 
    rv = LocateSignonsFile(aFileName);
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsNetscapeProfileMigratorBase::GetString ( void aTransform,
nsIPrefBranch aBranch 
) [static]

Definition at line 165 of file nsNetscapeProfileMigratorBase.cpp.

{
  PrefTransform* xform = (PrefTransform*)aTransform;
  GETPREF(xform, GetCharPref, &xform->stringValue);
}
nsresult nsNetscapeProfileMigratorBase::GetWString ( void aTransform,
nsIPrefBranch aBranch 
) [static]

Definition at line 179 of file nsNetscapeProfileMigratorBase.cpp.

{
  PrefTransform* xform = (PrefTransform*)aTransform;
  nsCOMPtr<nsIPrefLocalizedString> prefValue;
  nsresult rv = aBranch->GetComplexValue(xform->sourcePrefName, 
                                         NS_GET_IID(nsIPrefLocalizedString),
                                         getter_AddRefs(prefValue));

  if (NS_SUCCEEDED(rv) && prefValue) {
    nsXPIDLString data;
    prefValue->ToString(getter_Copies(data));

    xform->stringValue = ToNewCString(NS_ConvertUCS2toUTF8(data));
    xform->prefHasValue = PR_TRUE;
  }
  return rv;
}

Here is the call graph for this function:

Definition at line 299 of file nsNetscapeProfileMigratorBase.cpp.

{
  nsCOMPtr<nsISimpleEnumerator> entries;
  nsresult rv = mSourceProfile->GetDirectoryEntries(getter_AddRefs(entries));
  if (NS_FAILED(rv)) return rv;

  nsCAutoString fileName;
  do {
    PRBool hasMore = PR_FALSE;
    rv = entries->HasMoreElements(&hasMore);
    if (NS_FAILED(rv) || !hasMore) break;

    nsCOMPtr<nsISupports> supp;
    rv = entries->GetNext(getter_AddRefs(supp));
    if (NS_FAILED(rv)) break;

    nsCOMPtr<nsIFile> currFile(do_QueryInterface(supp));

    nsCOMPtr<nsIURI> uri;
    rv = NS_NewFileURI(getter_AddRefs(uri), currFile);
    if (NS_FAILED(rv)) break;
    nsCOMPtr<nsIURL> url(do_QueryInterface(uri));

    nsCAutoString extn;
    url->GetFileExtension(extn);

    if (extn.EqualsIgnoreCase("s")) {
      url->GetFileName(fileName);
      break;
    }
  }
  while (1);

  *aResult = ToNewCString(fileName);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 340 of file nsNetscapeProfileMigratorBase.cpp.

{
  nsresult rv;
  PRBool isDir;
  
  rv = srcDir->IsDirectory(&isDir);
  if (NS_FAILED(rv)) return rv;
  if (!isDir) return NS_ERROR_INVALID_ARG;
  
  PRBool exists;
  rv = destDir->Exists(&exists);
  if (NS_SUCCEEDED(rv) && !exists)
    rv = destDir->Create(nsIFile::DIRECTORY_TYPE, 0775);
  if (NS_FAILED(rv)) return rv;
  
  PRBool hasMore = PR_FALSE;
  nsCOMPtr<nsISimpleEnumerator> dirIterator;
  rv = srcDir->GetDirectoryEntries(getter_AddRefs(dirIterator));
  if (NS_FAILED(rv)) return rv;
  
  rv = dirIterator->HasMoreElements(&hasMore);
  if (NS_FAILED(rv)) return rv;
  
  nsCOMPtr<nsIFile> dirEntry;
  
  while (hasMore)
  {
    rv = dirIterator->GetNext((nsISupports**)getter_AddRefs(dirEntry));
    if (NS_SUCCEEDED(rv))
    {
      rv = dirEntry->IsDirectory(&isDir);
      if (NS_SUCCEEDED(rv))
      {
        if (isDir)
        {
          nsCOMPtr<nsIFile> destClone;
          rv = destDir->Clone(getter_AddRefs(destClone));
          if (NS_SUCCEEDED(rv))
          {
            nsCOMPtr<nsILocalFile> newChild(do_QueryInterface(destClone));
            nsAutoString leafName;
            dirEntry->GetLeafName(leafName);
            newChild->AppendRelativePath(leafName);
            rv = newChild->Exists(&exists);
            if (NS_SUCCEEDED(rv) && !exists)
              rv = newChild->Create(nsIFile::DIRECTORY_TYPE, 0775);
            rv = RecursiveCopy(dirEntry, newChild);
          }
        }
        else
        {
          // we aren't going to do any actual file copying here. Instead, add this to our
          // file transaction list so we can copy files asynchronously...
          fileTransactionEntry* fileEntry = new fileTransactionEntry;
          fileEntry->srcFile = dirEntry;
          fileEntry->destFile = destDir;

          mFileCopyTransactions->AppendElement((void*) fileEntry);
        }
      }      
    }
    rv = dirIterator->HasMoreElements(&hasMore);
    if (NS_FAILED(rv)) return rv;
  }
  
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsNetscapeProfileMigratorBase::SetBool ( void aTransform,
nsIPrefBranch aBranch 
) [static]

Definition at line 232 of file nsNetscapeProfileMigratorBase.cpp.

{
  PrefTransform* xform = (PrefTransform*)aTransform;
  SETPREF(xform, SetBoolPref, xform->boolValue);
}
nsresult nsNetscapeProfileMigratorBase::SetInt ( void aTransform,
nsIPrefBranch aBranch 
) [static]

Definition at line 246 of file nsNetscapeProfileMigratorBase.cpp.

{
  PrefTransform* xform = (PrefTransform*)aTransform;
  SETPREF(xform, SetIntPref, xform->intValue);
}
nsresult nsNetscapeProfileMigratorBase::SetString ( void aTransform,
nsIPrefBranch aBranch 
) [static]

Definition at line 172 of file nsNetscapeProfileMigratorBase.cpp.

{
  PrefTransform* xform = (PrefTransform*)aTransform;
  SETPREF(xform, SetCharPref, xform->stringValue);
}
nsresult nsNetscapeProfileMigratorBase::SetWString ( void aTransform,
nsIPrefBranch aBranch 
) [static]

Definition at line 211 of file nsNetscapeProfileMigratorBase.cpp.

{
  PrefTransform* xform = (PrefTransform*)aTransform;
  if (xform->prefHasValue) {
    nsCOMPtr<nsIPrefLocalizedString> pls(do_CreateInstance("@mozilla.org/pref-localizedstring;1"));
    nsAutoString data = NS_ConvertUTF8toUCS2(xform->stringValue);
    pls->SetData(data.get());
    return aBranch->SetComplexValue(xform->targetPrefName ? xform->targetPrefName : xform->sourcePrefName, NS_GET_IID(nsIPrefLocalizedString), pls);
  }
  return NS_OK;
}

Here is the call graph for this function:

Definition at line 198 of file nsNetscapeProfileMigratorBase.cpp.

{
  PrefTransform* xform = (PrefTransform*)aTransform;
  if (xform->prefHasValue) {
    nsCOMPtr<nsIPrefLocalizedString> pls(do_CreateInstance("@mozilla.org/pref-localizedstring;1"));
    nsAutoString data; data.AssignWithConversion(xform->stringValue);
    pls->SetData(data.get());
    return aBranch->SetComplexValue(xform->targetPrefName ? xform->targetPrefName : xform->sourcePrefName, NS_GET_IID(nsIPrefLocalizedString), pls);
  }
  return NS_OK;
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 104 of file nsNetscapeProfileMigratorBase.h.

Definition at line 107 of file nsNetscapeProfileMigratorBase.h.

Definition at line 106 of file nsNetscapeProfileMigratorBase.h.

Definition at line 102 of file nsNetscapeProfileMigratorBase.h.

Definition at line 103 of file nsNetscapeProfileMigratorBase.h.


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