From b0422b32d247286310b88778fb53526bee8e9daf Mon Sep 17 00:00:00 2001 From: "cavin%netscape.com" Date: Sun, 16 Mar 2003 02:22:09 +0000 Subject: [PATCH] Fix for 70396. Use the directory description in prefs if it exists for the addrbook names. Copy 4.x .na2 files to 7.x directory during migration. r=ccarlen, sr=sspitzer. git-svn-id: svn://10.0.0.236/trunk@139551 18797224-902f-48f8-a5cc-f745e15eee43 --- .../mailnews/addrbook/src/nsAddressBook.cpp | 31 +++++++++------- .../pref-migrator/src/nsPrefMigration.cpp | 35 +++++++++++++++++++ .../pref-migrator/src/nsPrefMigration.h | 4 +++ 3 files changed, 57 insertions(+), 13 deletions(-) diff --git a/mozilla/mailnews/addrbook/src/nsAddressBook.cpp b/mozilla/mailnews/addrbook/src/nsAddressBook.cpp index efd0421f904..1acd39f5f82 100644 --- a/mozilla/mailnews/addrbook/src/nsAddressBook.cpp +++ b/mozilla/mailnews/addrbook/src/nsAddressBook.cpp @@ -414,12 +414,11 @@ nsresult AddressBookParser::ParseFile() return ParseLDIFFile(); } + // We are migrating 4.x profile /* Get database file name */ char *leafName = nsnull; - nsAutoString fileString; if (mFileSpec) { mFileSpec->GetLeafName(&leafName); - fileString.AssignWithConversion(leafName); PRInt32 i = 0; while (leafName[i] != '\0') @@ -469,19 +468,25 @@ nsresult AddressBookParser::ParseFile() if (!parentDir) return NS_ERROR_NULL_POINTER; - if (PL_strcmp(fileName, kPersonalAddressbook) == 0) - { - // This is the personal address book, get name from prefs - nsCOMPtr pPref(do_GetService(NS_PREF_CONTRACTID, &rv)); - if (NS_FAILED(rv) || !pPref) - return nsnull; - - nsXPIDLString dirName; + // Get Pretty name from prefs. + nsCOMPtr pPref(do_GetService(NS_PREF_CONTRACTID, &rv)); + if (NS_FAILED(rv) || !pPref) + return nsnull; + + nsXPIDLString dirName; + if (strcmp(fileName, kPersonalAddressbook) == 0) rv = pPref->GetLocalizedUnicharPref("ldap_2.servers.pab.description", getter_Copies(dirName)); - parentDir->CreateDirectoryByURI(dirName, mDbUri, mMigrating); - } else - parentDir->CreateDirectoryByURI(fileString.get(), mDbUri, mMigrating); + { + nsCAutoString prefName; + prefName = NS_LITERAL_CSTRING("ldap_2.servers.") + nsDependentCString(leafName) + NS_LITERAL_CSTRING(".description"); + rv = pPref->GetLocalizedUnicharPref(prefName.get(), getter_Copies(dirName)); + } + + // If a name is found then use it, otherwise use the filename as last resort. + if (NS_FAILED(rv) || dirName.IsEmpty()) + dirName = NS_ConvertASCIItoUCS2(leafName); + parentDir->CreateDirectoryByURI(dirName, mDbUri, mMigrating); rv = ParseLDIFFile(); diff --git a/mozilla/profile/pref-migrator/src/nsPrefMigration.cpp b/mozilla/profile/pref-migrator/src/nsPrefMigration.cpp index 6055195e117..ed22c3dd67e 100644 --- a/mozilla/profile/pref-migrator/src/nsPrefMigration.cpp +++ b/mozilla/profile/pref-migrator/src/nsPrefMigration.cpp @@ -150,6 +150,7 @@ #endif /* XP_UNIX */ #define PREMIGRATION_PREFIX "premigration." +#define ADDRBOOK_FILE_EXTENSION_IN_4X ".na2" // this is for the hidden preference setting in mozilla/modules/libpref/src/init/mailnews.js // pref("mail.migration.copyMailFiles", true); @@ -1140,6 +1141,10 @@ nsPrefMigration::ProcessPrefsCallback(const char* oldProfilePathStr, const char if (NS_FAILED(rv)) return rv; #endif /* XP_MAC */ + // Copy the addrbook files. + rv = CopyFilesByExtension(oldProfilePath, newProfilePath, ADDRBOOK_FILE_EXTENSION_IN_4X); + NS_ENSURE_SUCCESS(rv,rv); + rv = DoTheCopy(oldNewsPath, newNewsPath, PR_TRUE); if (NS_FAILED(rv)) return rv; @@ -1696,6 +1701,36 @@ nsPrefMigration::DoTheCopyAndRename(nsIFileSpec * aPathSpec, PRBool aReadSubdirs return NS_OK; } +nsresult +nsPrefMigration::CopyFilesByExtension(nsIFileSpec * oldPathSpec, nsIFileSpec * newPathSpec, const char *fileExtension) +{ + nsFileSpec oldPath; + nsFileSpec newPath; + + nsresult rv = oldPathSpec->GetFileSpec(&oldPath); + NS_ENSURE_SUCCESS(rv,rv); + rv = newPathSpec->GetFileSpec(&newPath); + NS_ENSURE_SUCCESS(rv,rv); + + for (nsDirectoryIterator dir(oldPath, PR_FALSE); dir.Exists(); dir++) + { + nsFileSpec fileOrDirName = dir.Spec(); //set first file or dir to a nsFileSpec + + if (fileOrDirName.IsDirectory()) + continue; + + nsCAutoString fileOrDirNameStr(fileOrDirName.GetLeafName()); + if (!nsCStringEndsWith(fileOrDirNameStr, fileExtension)) + continue; + + // copy the file + rv = fileOrDirName.CopyToDir(newPath); + NS_ENSURE_SUCCESS(rv,rv); + } + + return NS_OK; +} + nsresult nsPrefMigration::DoTheCopy(nsIFileSpec * oldPath, nsIFileSpec * newPath, PRBool readSubdirs) { diff --git a/mozilla/profile/pref-migrator/src/nsPrefMigration.h b/mozilla/profile/pref-migrator/src/nsPrefMigration.h index 122b0061baf..625b2fcf7ea 100644 --- a/mozilla/profile/pref-migrator/src/nsPrefMigration.h +++ b/mozilla/profile/pref-migrator/src/nsPrefMigration.h @@ -149,6 +149,10 @@ class nsPrefMigration: public nsIPrefMigration PRBool aReadSubdirs, const char *aOldName, const char *aNewName); + nsresult CopyFilesByExtension(nsIFileSpec * oldPathSpec, + nsIFileSpec * newPathSpec, + const char *fileExtension); + #ifdef NEED_TO_COPY_AND_RENAME_NEWSRC_FILES nsresult CopyAndRenameNewsrcFiles(nsIFileSpec *newPath);