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.

This commit is contained in:
cavin%netscape.com 2003-03-16 02:22:09 +00:00
Родитель 1e4f46228e
Коммит f9c8130ef3
3 изменённых файлов: 57 добавлений и 13 удалений

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

@ -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<nsIPref> pPref(do_GetService(NS_PREF_CONTRACTID, &rv));
if (NS_FAILED(rv) || !pPref)
return nsnull;
nsXPIDLString dirName;
// Get Pretty name from prefs.
nsCOMPtr<nsIPref> 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();

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

@ -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)
{

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

@ -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);