nsresult nsDogbertProfileMigrator::MigrateDogbertBookmarks() { nsresult rv; // Find out what the personal toolbar folder was called, this is stored in a pref // in 4.x nsCOMPtr<nsIPrefService> psvc(do_GetService(NS_PREFSERVICE_CONTRACTID)); psvc->ResetPrefs(); nsCOMPtr<nsIFile> dogbertPrefsFile; mSourceProfile->Clone(getter_AddRefs(dogbertPrefsFile)); dogbertPrefsFile->Append(PREF_FILE_NAME_IN_4x); psvc->ReadUserPrefs(dogbertPrefsFile); nsCString toolbarName; nsCOMPtr<nsIPrefBranch> branch(do_QueryInterface(psvc)); rv = branch->GetCharPref("custtoolbar.personal_toolbar_folder", getter_Copies(toolbarName)); // If the pref wasn't set in the user's 4.x preferences, there's no way we can "Fix" the // file when importing it to set the personal toolbar folder correctly, so don't bother // with the more involved file correction procedure and just copy the file over. if (NS_FAILED(rv)) return CopyFile(BOOKMARKS_FILE_NAME_IN_4x, BOOKMARKS_FILE_NAME_IN_5x); // Now read the 4.x bookmarks file, correcting the Personal Toolbar Folder line // and writing to the new location. nsCOMPtr<nsIFile> sourceBookmarksFile; mSourceProfile->Clone(getter_AddRefs(sourceBookmarksFile)); sourceBookmarksFile->Append(BOOKMARKS_FILE_NAME_IN_4x); nsCOMPtr<nsIFile> targetBookmarksFile; mTargetProfile->Clone(getter_AddRefs(targetBookmarksFile)); targetBookmarksFile->Append(BOOKMARKS_FILE_NAME_IN_5x); return AnnotatePersonalToolbarFolder(sourceBookmarksFile, targetBookmarksFile, toolbarName.get()); }
nsresult nsMacIEProfileMigrator::CopyBookmarks(PRBool aReplace) { nsresult rv; nsCOMPtr<nsIFile> sourceFile; mSourceProfile->Clone(getter_AddRefs(sourceFile)); sourceFile->Append(MACIE_BOOKMARKS_FILE_NAME); PRBool exists = PR_FALSE; sourceFile->Exists(&exists); if (!exists) return NS_OK; // it's an import if (!aReplace) return ImportBookmarksHTML(sourceFile, PR_FALSE, PR_FALSE, NS_LITERAL_STRING("sourceNameIE").get()); // Initialize the default bookmarks rv = InitializeBookmarks(mTargetProfile); NS_ENSURE_SUCCESS(rv, rv); // If we're blowing away existing content, annotate the Personal Toolbar and // then import the file. nsCOMPtr<nsIFile> tempFile; mTargetProfile->Clone(getter_AddRefs(tempFile)); tempFile->Append(TEMP_BOOKMARKS_FILE_NAME); // Look for the localized name of the IE Favorites Bar nsCOMPtr<nsIStringBundleService> bundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIStringBundle> bundle; rv = bundleService->CreateBundle(MIGRATION_BUNDLE, getter_AddRefs(bundle)); NS_ENSURE_SUCCESS(rv, rv); nsString toolbarFolderNameMacIE; bundle->GetStringFromName(NS_LITERAL_STRING("toolbarFolderNameMacIE").get(), getter_Copies(toolbarFolderNameMacIE)); nsCAutoString ctoolbarFolderNameMacIE; CopyUTF16toUTF8(toolbarFolderNameMacIE, ctoolbarFolderNameMacIE); // Now read the 4.x bookmarks file, correcting the Personal Toolbar Folder // line and writing to the temporary file. rv = AnnotatePersonalToolbarFolder(sourceFile, tempFile, ctoolbarFolderNameMacIE.get()); NS_ENSURE_SUCCESS(rv, rv); // import the temp file rv = ImportBookmarksHTML(tempFile, PR_TRUE, PR_FALSE, EmptyString().get()); NS_ENSURE_SUCCESS(rv, rv); // remove the temp file return tempFile->Remove(PR_FALSE); }