nsresult nsDogbertProfileMigrator::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); // 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); nsCOMPtr<nsIFile> targetPrefsFile; mTargetProfile->Clone(getter_AddRefs(targetPrefsFile)); targetPrefsFile->Append(aTargetPrefFileName); psvc->SavePrefFile(targetPrefsFile); return NS_OK; }
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); nsVoidArray* fontPrefs = new nsVoidArray(); if (!fontPrefs) return NS_ERROR_OUT_OF_MEMORY; 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); delete fontPrefs; fontPrefs = nsnull; nsCOMPtr<nsIFile> targetPrefsFile; mTargetProfile->Clone(getter_AddRefs(targetPrefsFile)); targetPrefsFile->Append(aTargetPrefFileName); psvc->SavePrefFile(targetPrefsFile); psvc->ResetPrefs(); psvc->ReadUserPrefs(nsnull); return NS_OK; }
nsresult nsOperaProfileMigrator::CopyPreferences(PRBool aReplace) { nsresult rv; nsCOMPtr<nsIFile> operaPrefs; mOperaProfile->Clone(getter_AddRefs(operaPrefs)); operaPrefs->Append(OPERA_PREFERENCES_FILE_NAME); nsCOMPtr<nsILocalFile> lf(do_QueryInterface(operaPrefs)); NS_ENSURE_TRUE(lf, NS_ERROR_UNEXPECTED); nsINIParser parser; rv = parser.Init(lf); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIPrefBranch> branch(do_GetService(NS_PREFSERVICE_CONTRACTID)); // Traverse the standard transforms PrefTransform* transform; PrefTransform* end = gTransforms + sizeof(gTransforms)/sizeof(PrefTransform); const char* lastSectionName = nsnull; for (transform = gTransforms; transform < end; ++transform) { if (transform->sectionName) lastSectionName = transform->sectionName; if (transform->type == _OPM(COLOR)) { char* colorString = nsnull; nsresult rv = ParseColor(parser, lastSectionName, &colorString); if (NS_SUCCEEDED(rv)) { transform->stringValue = colorString; transform->prefHasValue = PR_TRUE; transform->prefSetterFunc(transform, branch); } if (colorString) free(colorString); } else { nsCAutoString val; rv = parser.GetString(lastSectionName, transform->keyName, val); if (NS_SUCCEEDED(rv)) { nsresult strerr; switch (transform->type) { case _OPM(STRING): transform->stringValue = ToNewCString(val); break; case _OPM(INT): { transform->intValue = val.ToInteger(&strerr); } break; case _OPM(BOOL): { transform->boolValue = val.ToInteger(&strerr) != 0; } break; default: break; } transform->prefHasValue = PR_TRUE; transform->prefSetterFunc(transform, branch); if (transform->type == _OPM(STRING) && transform->stringValue) { NS_Free(transform->stringValue); transform->stringValue = nsnull; } } } } // Copy Proxy Settings CopyProxySettings(parser, branch); // Copy User Content Sheet if (aReplace) CopyUserContentSheet(parser); return NS_OK; }
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; }
nsresult nsSafariProfileMigrator::CopyPreferences(bool aReplace) { nsCOMPtr<nsIPrefBranch> branch(do_GetService(NS_PREFSERVICE_CONTRACTID)); CFDictionaryRef safariPrefs = CopySafariPrefs(); if (!safariPrefs) return NS_ERROR_FAILURE; // Traverse the standard transforms PrefTransform* transform; PrefTransform* end = gTransforms + sizeof(gTransforms) / sizeof(PrefTransform); for (transform = gTransforms; transform < end; ++transform) { Boolean hasValue = ::CFDictionaryContainsKey(safariPrefs, transform->keyName); if (!hasValue) continue; transform->prefHasValue = false; switch (transform->type) { case _SPM(STRING): { CFStringRef stringValue = (CFStringRef) ::CFDictionaryGetValue(safariPrefs, transform->keyName); char* value = GetNullTerminatedString(stringValue); if (value) { transform->stringValue = value; transform->prefHasValue = true; } } break; case _SPM(INT): { CFNumberRef intValue = (CFNumberRef) ::CFDictionaryGetValue(safariPrefs, transform->keyName); PRInt32 value = 0; if (::CFNumberGetValue(intValue, kCFNumberSInt32Type, &value)) { transform->intValue = value; transform->prefHasValue = true; } } break; case _SPM(BOOL): { CFBooleanRef boolValue = (CFBooleanRef) ::CFDictionaryGetValue(safariPrefs, transform->keyName); transform->boolValue = boolValue == kCFBooleanTrue; transform->prefHasValue = true; } break; default: break; } if (transform->prefHasValue) transform->prefSetterFunc(transform, branch); if (transform->type == _SPM(STRING)) FreeNullTerminatedString(transform->stringValue); } ::CFRelease(safariPrefs); // Safari stores the Cookie "Accept/Don't Accept/Don't Accept Foreign" cookie // setting in a separate WebFoundation preferences PList. nsCOMPtr<nsIProperties> fileLocator(do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID)); nsCOMPtr<nsILocalFile> safariWebFoundationPrefsFile; fileLocator->Get(NS_OSX_USER_PREFERENCES_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(safariWebFoundationPrefsFile)); safariWebFoundationPrefsFile->Append(SAFARI_COOKIE_BEHAVIOR_FILE_NAME); CFDictionaryRef safariWebFoundationPrefs = static_cast<CFDictionaryRef>(CopyPListFromFile(safariWebFoundationPrefsFile)); if (safariWebFoundationPrefs) { // Mapping of Safari preference values to Firefox preference values: // // Setting Safari Firefox // Always Accept always 0 // Accept from Originating current page 1 // Never Accept never 2 nsAutoString acceptCookies; if (GetDictionaryStringValue(safariWebFoundationPrefs, CFSTR("NSHTTPAcceptCookies"), acceptCookies)) { PRInt32 cookieValue = 0; if (acceptCookies.EqualsLiteral("never")) cookieValue = 2; else if (acceptCookies.EqualsLiteral("current page")) cookieValue = 1; branch->SetIntPref("network.cookie.cookieBehavior", cookieValue); } ::CFRelease(safariWebFoundationPrefs); } return NS_OK; }