?? nsdogbertprofilemigrator.cpp
字號:
if (NS_FAILED(rv)) return rv;#endif /* XP_MAC */ // Copy the addrbook files. rv = CopyFilesByPattern(oldProfilePath, newProfilePath, ADDRBOOK_FILE_EXTENSION_IN_4X); NS_ENSURE_SUCCESS(rv,rv);#if defined(XP_MAX) || defined(XP_MACOSX) // Copy the Mac filter rule files which sits at the top level dir of a 4.x profile. if(serverType == IMAP_4X_MAIL_TYPE) { rv = CopyFilesByPattern(oldProfilePath, newProfilePath, MAC_RULES_FILE_ENDING_STRING_IN_4X); NS_ENSURE_SUCCESS(rv,rv); }#endif rv = DoTheCopy(oldNewsPath, newNewsPath, PR_TRUE); if (NS_FAILED(rv)) return rv;#ifdef NEED_TO_COPY_AND_RENAME_NEWSRC_FILES /* in 4.x, the newsrc files were in $HOME. Now that we can have multiple * profiles in 5.x, with the same user, this won't fly. * when they migrate, we need to copy from $HOME/.newsrc-<host> to * ~/.mozilla/<profile>/News/newsrc-<host> */ rv = CopyAndRenameNewsrcFiles(newNewsPath); if (NS_FAILED(rv)) return rv;#endif /* NEED_TO_COPY_AND_RENAME_NEWSRC_FILES */ if (serverType == IMAP_4X_MAIL_TYPE) { if( copyMailFileInMigration ) // copy mail files in migration { rv = DoTheCopyAndRename(oldIMAPMailPath, newIMAPMailPath, PR_TRUE, needToRenameFilterFiles, IMAP_MAIL_FILTER_FILE_NAME_IN_4x, IMAP_MAIL_FILTER_FILE_NAME_IN_5x); if (NS_FAILED(rv)) return rv; rv = DoTheCopyAndRename(oldIMAPLocalMailPath, newIMAPLocalMailPath, PR_TRUE, needToRenameFilterFiles,IMAP_MAIL_FILTER_FILE_NAME_IN_4x,IMAP_MAIL_FILTER_FILE_NAME_IN_5x); if (NS_FAILED(rv)) return rv; } else // Copy & Rename filter files { // IMAP path // don't care if this fails (void)DoTheCopyAndRename(oldIMAPMailPath, PR_TRUE, IMAP_MAIL_FILTER_FILE_NAME_IN_4x, IMAP_MAIL_FILTER_FILE_NAME_IN_5x); // Local Folders path // don't care if this fails (void)DoTheCopyAndRename(oldIMAPLocalMailPath, PR_TRUE, IMAP_MAIL_FILTER_FILE_NAME_IN_4x, IMAP_MAIL_FILTER_FILE_NAME_IN_5x); } } else if (serverType == POP_4X_MAIL_TYPE) { // fix for bug #202010 // copy over the pop filter and popstate files now // and later, in DoSpecialUpdates() // we'll move and rename them#ifdef POP_MAIL_FILTER_FILE_NAME_IN_4x rv = DoTheCopy(oldProfilePath, newProfilePath, POP_MAIL_FILTER_FILE_NAME_IN_4x); if (NS_FAILED(rv)) return rv;#endif #ifdef POPSTATE_FILE_IN_4x rv = DoTheCopy(oldProfilePath, newProfilePath, POPSTATE_FILE_IN_4x); if (NS_FAILED(rv)) return rv;#endif rv = DoTheCopy(oldPOPMailPath, newPOPMailPath, PR_TRUE); if (NS_FAILED(rv)) return rv; }#ifdef HAVE_MOVEMAIL else if (serverType == MOVEMAIL_4X_MAIL_TYPE) { // in 4.x, the movemail filter name was the same as the pop filter name // copy over the filter file now // and later, in DoSpecialUpdates() // we'll move and rename them rv = DoTheCopy(oldProfilePath, newProfilePath, POP_MAIL_FILTER_FILE_NAME_IN_4x); if (NS_FAILED(rv)) return rv; rv = DoTheCopy(oldMOVEMAILMailPath, newMOVEMAILMailPath, PR_TRUE); }#endif /* HAVE_MOVEMAIL */ else { NS_ASSERTION(0, "unknown mail server type!"); return NS_ERROR_FAILURE; } // Don't inherit the 4.x cache file location for mozilla! // The cache pref later gets set with a default in nsAppRunner::InitCachePrefs(). mPrefs->ClearUserPref(PREF_BROWSER_CACHE_DIRECTORY); rv = DoSpecialUpdates(newProfilePath); if (NS_FAILED(rv)) return rv; PR_FREEIF(popServerName); nsXPIDLCString path; newProfilePath->GetNativePath(getter_Copies(path)); NS_NewNativeLocalFile(path, PR_TRUE, getter_AddRefs(newPrefsFile)); rv = newPrefsFile->AppendNative(NS_LITERAL_CSTRING(PREF_FILE_NAME_IN_5x)); if (NS_FAILED(rv)) return rv; rv=mPrefs->SavePrefFile(newPrefsFile); if (NS_FAILED(rv)) return rv; rv=mPrefs->ResetPrefs(); if (NS_FAILED(rv)) return rv; PRBool flagExists = PR_FALSE; m_prefsFile->Exists(&flagExists); //Delete the prefs.js file in the temp directory. if (flagExists) m_prefsFile->Remove(PR_FALSE); systemTempDir->Exists(&flagExists); //Delete the unique dir in the system temp dir. if (flagExists) systemTempDir->Remove(PR_FALSE); return rv;}nsresult nsDogbertProfileMigrator::CreateNewUser5Tree(nsIFileSpec * oldProfilePath, nsIFileSpec * newProfilePath){ nsresult rv; PRBool exists; NS_ASSERTION(*PREF_FILE_NAME_IN_4x, "don't know how to migrate your platform"); if (!*PREF_FILE_NAME_IN_4x) { return NS_ERROR_UNEXPECTED; } /* Copy the old prefs file to the new profile directory for modification and reading. after copying it, rename it to pref.js, the 5.x pref file name on all platforms */ nsCOMPtr<nsIFileSpec> oldPrefsFile; rv = NS_NewFileSpec(getter_AddRefs(oldPrefsFile)); if (NS_FAILED(rv)) return rv; rv = oldPrefsFile->FromFileSpec(oldProfilePath); if (NS_FAILED(rv)) return rv; rv = oldPrefsFile->AppendRelativeUnixPath(PREF_FILE_NAME_IN_4x); if (NS_FAILED(rv)) return rv; /* the new prefs file */ nsCOMPtr<nsIFileSpec> newPrefsFile; rv = NS_NewFileSpec(getter_AddRefs(newPrefsFile)); if (NS_FAILED(rv)) return rv; rv = newPrefsFile->FromFileSpec(newProfilePath); if (NS_FAILED(rv)) return rv; rv = newPrefsFile->Exists(&exists); if (!exists) { rv = newPrefsFile->CreateDir(); } rv = oldPrefsFile->CopyToDir(newPrefsFile); NS_ASSERTION(NS_SUCCEEDED(rv),"failed to copy prefs file"); rv = newPrefsFile->AppendRelativeUnixPath(PREF_FILE_NAME_IN_4x); rv = newPrefsFile->Rename(PREF_FILE_NAME_IN_5x); return NS_OK;}#ifdef NEED_TO_COPY_AND_RENAME_NEWSRC_FILESnsresult nsDogbertProfileMigrator::CopyAndRenameNewsrcFiles(nsIFileSpec * newPathSpec){ nsresult rv; nsCOMPtr <nsIFileSpec>oldPathSpec; nsFileSpec oldPath; nsFileSpec newPath; char* folderName = nsnull; nsCAutoString fileOrDirNameStr; rv = GetPremigratedFilePref(PREF_NEWS_DIRECTORY, getter_AddRefs(oldPathSpec)); if (NS_FAILED(rv)) return rv; rv = oldPathSpec->GetFileSpec(&oldPath); if (NS_FAILED(rv)) return rv; rv = newPathSpec->GetFileSpec(&newPath); if (NS_FAILED(rv)) return rv; for (nsDirectoryIterator dir(oldPath, PR_FALSE); dir.Exists(); dir++) { nsFileSpec fileOrDirName = dir.Spec(); //set first file or dir to a nsFileSpec folderName = fileOrDirName.GetLeafName(); //get the filename without the full path fileOrDirNameStr.Assign(folderName); if (nsCStringStartsWith(fileOrDirNameStr, NEWSRC_PREFIX_IN_4x) || nsCStringStartsWith(fileOrDirNameStr, SNEWSRC_PREFIX_IN_4x)) {#ifdef DEBUG_seth printf("newsrc file == %s\n",folderName);#endif /* DEBUG_seth */ rv = fileOrDirName.CopyToDir(newPath); NS_ASSERTION(NS_SUCCEEDED(rv),"failed to copy news file"); nsFileSpec newFile = newPath; newFile += fileOrDirNameStr.get(); newFile.Rename(folderName + 1); /* rename .newsrc-news to newsrc-news, no need to keep it hidden anymore */ } } return NS_OK;}#endif /* NEED_TO_COPY_AND_RENAME_NEWSRC_FILES *//*------------------------------------------------------------------------- * DoTheCopyAndRename copies the files listed in oldPath to newPath * and renames files, if necessary * * INPUT: oldPath - The old profile path plus the specific data type * (e.g. mail or news) * newPath - The new profile path plus the specific data type * * readSubdirs * * needToRenameFiles - do we need to search for files named oldFile * and rename them to newFile * * oldFile - old file name (used for renaming) * * newFile - new file name (used for renaming) * * RETURNS: NS_OK if successful * NS_ERROR_FAILURE if failed * *--------------------------------------------------------------------------*/nsresult nsDogbertProfileMigrator::DoTheCopyAndRename(nsIFileSpec * oldPathSpec, nsIFileSpec *newPathSpec, PRBool readSubdirs, PRBool needToRenameFiles, const char *oldName, const char *newName){ nsresult rv; char* folderName = nsnull; nsCAutoString fileOrDirNameStr; nsFileSpec oldPath; nsFileSpec newPath; rv = oldPathSpec->GetFileSpec(&oldPath); if (NS_FAILED(rv)) return rv; rv = newPathSpec->GetFileSpec(&newPath); if (NS_FAILED(rv)) return rv; for (nsDirectoryIterator dir(oldPath, PR_FALSE); dir.Exists(); dir++) { nsFileSpec fileOrDirName = dir.Spec(); //set first file or dir to a nsFileSpec folderName = fileOrDirName.GetLeafName(); //get the filename without the full path fileOrDirNameStr.Assign(folderName); if (nsCStringEndsWith(fileOrDirNameStr, MAIL_SUMMARY_SUFFIX_IN_4x) || nsCStringEndsWith(fileOrDirNameStr, NEWS_SUMMARY_SUFFIX_IN_4x) || nsCStringEndsWith(fileOrDirNameStr, SUMMARY_SUFFIX_IN_5x)) /* Don't copy the summary files */ continue; else { if (fileOrDirName.IsDirectory()) { if(readSubdirs) { nsCOMPtr<nsIFileSpec> newPathExtended; rv = NS_NewFileSpecWithSpec(newPath, getter_AddRefs(newPathExtended)); rv = newPathExtended->AppendRelativeUnixPath(folderName); rv = newPathExtended->CreateDir(); nsCOMPtr<nsIFileSpec>fileOrDirNameSpec; rv = NS_NewFileSpecWithSpec(fileOrDirName, getter_AddRefs(fileOrDirNameSpec)); DoTheCopyAndRename(fileOrDirNameSpec, newPathExtended, PR_TRUE, needToRenameFiles, oldName, newName); /* re-enter the DoTheCopyAndRename function */ } else continue; } else { // copy the file if (fileOrDirNameStr.Equals(oldName)) AddFileCopyToList(&fileOrDirName, &newPath, newName); else AddFileCopyToList(&fileOrDirName, &newPath, ""); } } } return NS_OK;}/*------------------------------------------------------------------------- * DoTheCopyAndRename copies and renames files * * INPUT: aPath - the path * * aReadSubdirs - if sub directories should be handled * * aOldFile - old file name (used for renaming) * * aNewFile - new file name (used for renaming) * * RETURNS: NS_OK if successful * NS_ERROR_FAILURE if failed * *--------------------------------------------------------------------------*/nsresult nsDogbertProfileMigrator::DoTheCopyAndRename(nsIFileSpec * aPathSpec, PRBool aReadSubdirs, const char *aOldName, const char *aNewName){ if( !aOldName || !aNewName || !strcmp(aOldName, aNewName) ) return NS_ERROR_FAILURE; nsresult rv; nsFileSpec path, file; rv = aPathSpec->GetFileSpec(&path); if (NS_FAILED(rv)) return rv; rv = aPathSpec->GetFileSpec(&file); if (NS_FAILED(rv)) return rv; file += aOldName; // Handle sub folders for (nsDirectoryIterator dir(path, PR_FALSE); dir.Exists(); dir++) { nsFileSpec fileOrDirName = dir.Spec(); //set first file or dir to a nsFileSpec if (fileOrDirName.IsDirectory()) { if( aReadSubdirs ) { nsCOMPtr<nsIFileSpec>fileOrDirNameSpec; rv = NS_NewFileSpecWithSpec(fileOrDirName, getter_AddRefs(fileOrDirNameSpec)); DoTheCopyAndRename(fileOrDirNameSpec, aReadSubdirs, aOldName, aNewName); /* re-enter the DoTheCopyAndRename function */ } else continue; } } nsCOMPtr<nsILocalFile> localFileOld, localFileDirectory; rv = NS_FileSpecToIFile(&file, getter_AddRefs(localFileOld)); if (NS_FAILED(rv)) return rv; rv = NS_FileSpecToIFile(&path, getter_AddRefs(localFileDirectory)); if (NS_FAILED(rv)) return rv; nsAutoString newName = NS_ConvertUTF8toUCS2(aNewName); localFileOld->CopyTo(localFileDirectory, newName); return NS_OK;}nsresult nsDogbertProfileMigrator::CopyFilesByPattern(nsIFileSpec * oldPathSpec, nsIFileSpec * newPathSpec, const char *pattern){ 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, pattern)) continue; AddFileCopyToList(&fileOrDirName, &newPath, ""); } return NS_OK;}nsresult nsDogbertProfileMigrator::AddFileCopyToList(nsFileSpec * aOldPath, nsFileSpec * aNewPath, const char * newName){ // convert to nsIFile nsCOMPtr<nsILocalFile> oldPathFile; nsCOMPtr<nsILocalFile> newPathFile; NS_FileSpecToIFile(aOldPath, getter_AddRefs(oldPathFile)); NS_FileSpecToIFile(aNewPath, getter_AddRefs(newPathFile)); fileTransactionEntry* fileEntry = new fileTransactionEntry; fileEntry->srcFile = do_QueryInterface(oldPathFile); fileEntry->destFile = do_QueryInterface(newPathFile); fileEntry->newName = NS_ConvertUTF8toUCS2(newName); mFileCopyTransactions->AppendElement((void*) fileEntry); return NS_OK;}nsresult nsDogbertProfileMigrator::DoTheCopy(nsIFileSpec * oldPath, nsIFileSpec * newPath, PRBool readSubdirs){ return DoTheCopyAndRename(oldPath, newPath, readSubdirs, PR_FALSE, "", "");}nsresult nsDogbertProfileMigrator::DoTheCopy(nsIFileSpec * oldPath, nsIFileSpec * newPath, const char *fileOrDirName, PRBool isDirectory){ nsresult rv; if (isDirectory) {
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -