nsresult nsSeamonkeyProfileMigrator::TransformPreferences(const nsAString& aSourcePrefFileName, const nsAString& aTargetPrefFileName) { PrefTransform* transform; PrefTransform* end = gTransforms + sizeof(gTransforms)/sizeof(PrefTransform); // Load the source pref file nsCOMPtr<nsIPrefService> psvc(do_GetService(NS_PREFSERVICE_CONTRACTID)); psvc->ResetPrefs(); nsCOMPtr<nsIFile> sourcePrefsFile; mSourceProfile->Clone(getter_AddRefs(sourcePrefsFile)); sourcePrefsFile->Append(aSourcePrefFileName); psvc->ReadUserPrefs(sourcePrefsFile); nsCOMPtr<nsIPrefBranch> branch(do_QueryInterface(psvc)); for (transform = gTransforms; transform < end; ++transform) transform->prefGetterFunc(transform, branch); nsTArray<FontPref> fontPrefs; ReadFontsBranch(psvc, &fontPrefs); // Now that we have all the pref data in memory, load the target pref file, // and write it back out psvc->ResetPrefs(); for (transform = gTransforms; transform < end; ++transform) transform->prefSetterFunc(transform, branch); WriteFontsBranch(psvc, &fontPrefs); nsCOMPtr<nsIFile> targetPrefsFile; mTargetProfile->Clone(getter_AddRefs(targetPrefsFile)); targetPrefsFile->Append(aTargetPrefFileName); psvc->SavePrefFile(targetPrefsFile); psvc->ResetPrefs(); psvc->ReadUserPrefs(nsnull); return NS_OK; }
NS_IMETHODIMP nsSeamonkeyProfileMigrator::GetSourceHomePageURL(nsACString& aResult) { // Load the source pref file nsCOMPtr<nsIPrefService> psvc(do_GetService(NS_PREFSERVICE_CONTRACTID)); psvc->ResetPrefs(); nsCOMPtr<nsIFile> sourcePrefsFile; mSourceProfile->Clone(getter_AddRefs(sourcePrefsFile)); sourcePrefsFile->Append(FILE_NAME_PREFS); psvc->ReadUserPrefs(sourcePrefsFile); nsCOMPtr<nsIPrefBranch> branch(do_QueryInterface(psvc)); PRBool hasUserValue; nsCOMPtr<nsIPrefLocalizedString> prefValue; nsresult rv = branch->PrefHasUserValue("browser.startup.homepage", &hasUserValue); if (NS_SUCCEEDED(rv) && hasUserValue) { rv = branch->GetComplexValue("browser.startup.homepage", NS_GET_IID(nsIPrefLocalizedString), getter_AddRefs(prefValue)); if (NS_SUCCEEDED(rv) && prefValue) { nsString data; prefValue->ToString(getter_Copies(data)); nsCAutoString val; val = ToNewCString(NS_ConvertUTF16toUTF8(data)); aResult.Assign(val); } } psvc->ResetPrefs(); psvc->ReadUserPrefs(nsnull); return NS_OK; }
nsresult nsNetscapeProfileMigratorBase::GetSignonFileName(bool aReplace, char** aFileName) { 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; }
bool nsNetscapeProfileMigratorBase::GetSourceHasHomePageURL() { // Load the source pref file nsCOMPtr<nsIPrefService> psvc(do_GetService(NS_PREFSERVICE_CONTRACTID)); psvc->ResetPrefs(); nsCOMPtr<nsIFile> sourcePrefsFile; mSourceProfile->Clone(getter_AddRefs(sourcePrefsFile)); sourcePrefsFile->AppendNative(NS_LITERAL_CSTRING(FILE_NAME_PREFS)); psvc->ReadUserPrefs(sourcePrefsFile); nsCOMPtr<nsIPrefBranch> branch(do_QueryInterface(psvc)); bool hasUserValue; nsresult rv = branch->PrefHasUserValue("browser.startup.homepage", &hasUserValue); return NS_SUCCEEDED(rv) && hasUserValue; }
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 nsThunderbirdProfileMigrator::TransformPreferences( const char* aSourcePrefFileName, const char* aTargetPrefFileName) { PrefTransform* transform; PrefTransform* end = gTransforms + sizeof(gTransforms)/sizeof(PrefTransform); // Load the source pref file nsCOMPtr<nsIPrefService> psvc(do_GetService(NS_PREFSERVICE_CONTRACTID)); psvc->ResetPrefs(); nsCOMPtr<nsIFile> sourcePrefsFile; mSourceProfile->Clone(getter_AddRefs(sourcePrefsFile)); sourcePrefsFile->AppendNative(nsDependentCString(aSourcePrefFileName)); psvc->ReadUserPrefs(sourcePrefsFile); nsCOMPtr<nsIPrefBranch> branch(do_QueryInterface(psvc)); for (transform = gTransforms; transform < end; ++transform) transform->prefGetterFunc(transform, branch); // read in the various pref branch trees for accounts, identities, servers, // etc. static const char* branchNames[] = { // Keep the three below first, or change the indexes below "mail.identity.", "mail.server.", "ldap_2.", "accessibility.", "applications.", "bidi.", "dom.", "editor.", "font.", "helpers.", "mail.account.", "mail.addr_book.", "mail.imap.", "mail.mdn.", "mail.smtpserver.", "mail.spam.", "mail.toolbars.", "mailnews.labels.", "mailnews.reply_", "mailnews.tags.", "middlemouse.", "mousewheel.", "network.http.", "print.", "privacy.", "security.OSCP.", "security.crl.", "ui.key.", "wallet." }; PBStructArray branches[MOZ_ARRAY_LENGTH(branchNames)]; uint32_t i; for (i = 0; i < MOZ_ARRAY_LENGTH(branchNames); ++i) ReadBranch(branchNames[i], psvc, branches[i]); // the signature file prefs may be paths to files in the thunderbird profile // path so we need to copy them over and fix these paths up before we write // them out to the new prefs.js CopySignatureFiles(branches[0], psvc); // certain mail prefs may actually be absolute paths instead of profile // relative paths we need to fix these paths up before we write them out to // the new prefs.js CopyMailFolderPrefs(branches[1], psvc); CopyAddressBookDirectories(branches[2], psvc); // Now that we have all the pref data in memory, load the target pref file, // and write it back out psvc->ResetPrefs(); nsCOMPtr<nsIFile> targetPrefsFile; mTargetProfile->Clone(getter_AddRefs(targetPrefsFile)); targetPrefsFile->AppendNative(nsDependentCString(aTargetPrefFileName)); // Don't use nullptr here as we're too early in the cycle for the prefs // service to get its default file (because the NS_GetDirectoryService items // aren't fully set up yet). psvc->ReadUserPrefs(targetPrefsFile); for (transform = gTransforms; transform < end; ++transform) transform->prefSetterFunc(transform, branch); for (i = 0; i < MOZ_ARRAY_LENGTH(branchNames); ++i) WriteBranch(branchNames[i], psvc, branches[i]); psvc->SavePrefFile(targetPrefsFile); return NS_OK; }