39 #include "nsDirectoryServiceDefs.h"
40 #include "nsIObserverService.h"
41 #include "nsILoginInfo.h"
42 #include "nsILoginManager.h"
43 #include "nsILoginManagerStorage.h"
44 #include "nsIPrefLocalizedString.h"
45 #include "nsIPrefService.h"
46 #include "nsIServiceManager.h"
47 #include "nsISupportsArray.h"
48 #include "nsISupportsPrimitives.h"
50 #include "nsNetUtil.h"
52 #include "nsIProfileMigrator.h"
57 #define FILE_NAME_BOOKMARKS NS_LITERAL_STRING("bookmarks.html")
58 #define FILE_NAME_COOKIES NS_LITERAL_STRING("cookies.txt")
59 #define FILE_NAME_SITEPERM_OLD NS_LITERAL_STRING("cookperm.txt")
60 #define FILE_NAME_SITEPERM_NEW NS_LITERAL_STRING("hostperm.1")
61 #define FILE_NAME_CERT8DB NS_LITERAL_STRING("cert8.db")
62 #define FILE_NAME_KEY3DB NS_LITERAL_STRING("key3.db")
63 #define FILE_NAME_SECMODDB NS_LITERAL_STRING("secmod.db")
64 #define FILE_NAME_HISTORY NS_LITERAL_STRING("history.dat")
65 #define FILE_NAME_MIMETYPES NS_LITERAL_STRING("mimeTypes.rdf")
66 #define FILE_NAME_DOWNLOADS NS_LITERAL_STRING("downloads.rdf")
67 #define FILE_NAME_PREFS NS_LITERAL_STRING("prefs.js")
68 #define FILE_NAME_USER_PREFS NS_LITERAL_STRING("user.js")
69 #define FILE_NAME_USERCONTENT NS_LITERAL_STRING("userContent.css")
70 #define DIR_NAME_CHROME NS_LITERAL_STRING("chrome")
76 mObserverService = do_GetService(
"@mozilla.org/observer-service;1");
87 nsSeamonkeyProfileMigrator::Migrate(PRUint16 aItems, nsIProfileStartup* aStartup,
const PRUnichar* aProfile)
90 PRBool aReplace = aStartup ? PR_TRUE : PR_FALSE;
111 rv = aStartup->DoStartup();
112 NS_ENSURE_SUCCESS(rv, rv);
133 nsSeamonkeyProfileMigrator::GetMigrateData(
const PRUnichar* aProfile,
142 return NS_ERROR_FILE_NOT_FOUND;
172 nsCString signonsFileName;
175 if (!signonsFileName.IsEmpty()) {
176 NS_ConvertASCIItoUTF16 fileName(signonsFileName);
177 nsCOMPtr<nsIFile> sourcePasswordsFile;
179 sourcePasswordsFile->Append(fileName);
182 sourcePasswordsFile->Exists(&exists);
191 nsSeamonkeyProfileMigrator::GetSourceExists(PRBool* aResult)
193 nsCOMPtr<nsISupportsArray> profiles;
194 GetSourceProfiles(getter_AddRefs(profiles));
198 profiles->Count(&count);
199 *aResult = count > 0;
208 nsSeamonkeyProfileMigrator::GetSourceHasMultipleProfiles(PRBool* aResult)
210 nsCOMPtr<nsISupportsArray> profiles;
211 GetSourceProfiles(getter_AddRefs(profiles));
215 profiles->Count(&count);
216 *aResult = count > 1;
225 nsSeamonkeyProfileMigrator::GetSourceProfiles(nsISupportsArray** aResult)
227 if (!mProfileNames && !mProfileLocations) {
228 mProfileNames = do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID);
229 mProfileLocations = do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID);
230 NS_ENSURE_TRUE(mProfileNames && mProfileLocations, NS_ERROR_UNEXPECTED);
236 NS_IF_ADDREF(*aResult = mProfileNames);
241 nsSeamonkeyProfileMigrator::GetSourceHomePageURL(nsACString& aResult)
247 nsCOMPtr<nsIFile> sourcePrefsFile;
252 psvc->ReadUserPrefs(sourcePrefsFile);
254 nsCOMPtr<nsIPrefBranch> branch(do_QueryInterface(psvc));
257 nsCOMPtr<nsIPrefLocalizedString> prefValue;
258 nsresult rv = branch->PrefHasUserValue(
"browser.startup.homepage", &hasUserValue);
259 if (NS_SUCCEEDED(rv) && hasUserValue) {
260 rv = branch->GetComplexValue(
"browser.startup.homepage",
262 getter_AddRefs(prefValue));
263 if (NS_SUCCEEDED(rv) && prefValue) {
265 prefValue->ToString(getter_Copies(data));
268 val = ToNewCString(NS_ConvertUTF16toUTF8(data));
275 psvc->ReadUserPrefs(nsnull);
287 mProfileNames->Count(&count);
288 for (PRUint32
i = 0;
i <
count; ++
i) {
289 nsCOMPtr<nsISupportsString>
str;
291 getter_AddRefs(str));
292 nsString profileName;
293 str->GetData(profileName);
294 if (profileName.Equals(aProfile)) {
295 mProfileLocations->QueryElementAt(
i, NS_GET_IID(nsILocalFile),
308 nsCOMPtr<nsIProperties> fileLocator(do_GetService(
"@mozilla.org/file/directory_service;1"));
309 nsCOMPtr<nsILocalFile> seamonkeyRegistry;
311 fileLocator->Get(NS_WIN_APPDATA_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(seamonkeyRegistry));
313 seamonkeyRegistry->Append(NS_LITERAL_STRING(
"Mozilla"));
314 seamonkeyRegistry->Append(NS_LITERAL_STRING(
"registry.dat"));
315 #elif defined(XP_MACOSX)
316 fileLocator->Get(NS_MAC_USER_LIB_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(seamonkeyRegistry));
318 seamonkeyRegistry->Append(NS_LITERAL_STRING(
"Mozilla"));
319 seamonkeyRegistry->Append(NS_LITERAL_STRING(
"Application Registry"));
320 #elif defined(XP_UNIX)
321 fileLocator->Get(NS_UNIX_HOME_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(seamonkeyRegistry));
323 seamonkeyRegistry->Append(NS_LITERAL_STRING(
".mozilla"));
324 seamonkeyRegistry->Append(NS_LITERAL_STRING(
"appreg"));
325 #elif defined(XP_BEOS)
326 fileLocator->Get(NS_BEOS_SETTINGS_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(seamonkeyRegistry));
328 seamonkeyRegistry->Append(NS_LITERAL_STRING(
"Mozilla"));
329 seamonkeyRegistry->Append(NS_LITERAL_STRING(
"appreg"));
330 #elif defined(XP_OS2)
331 fileLocator->Get(NS_OS2_HOME_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(seamonkeyRegistry));
333 seamonkeyRegistry->Append(NS_LITERAL_STRING(
"Mozilla"));
334 seamonkeyRegistry->Append(NS_LITERAL_STRING(
"registry.dat"));
340 #define F(a) nsSeamonkeyProfileMigrator::a
342 #define MAKEPREFTRANSFORM(pref, newpref, getmethod, setmethod) \
343 { pref, newpref, F(Get##getmethod), F(Set##setmethod), PR_FALSE, { -1 } }
345 #define MAKESAMETYPEPREFTRANSFORM(pref, method) \
346 { pref, 0, F(Get##method), F(Set##method), PR_FALSE, { -1 } }
420 rv = aBranch->SetIntPref(
"network.image.imageBehavior", xform->
intValue == 1 ? 0 : xform->
intValue);
432 rv = aBranch->SetIntPref(
"network.cookie.cookieBehavior", xform->
intValue == 3 ? 0 : xform->
intValue);
454 rv |= aBranch->SetBoolPref(
"browser.download.manager.showWhenStarting", xform->
intValue != 2);
455 rv |= aBranch->SetBoolPref(
"browser.download.manager.closeWhenDone", xform->
intValue == 1);
462 const nsAString& aTargetPrefFileName)
471 nsCOMPtr<nsIFile> sourcePrefsFile;
473 sourcePrefsFile->Append(aSourcePrefFileName);
474 psvc->ReadUserPrefs(sourcePrefsFile);
476 nsCOMPtr<nsIPrefBranch> branch(do_QueryInterface(psvc));
477 for (transform = gTransforms; transform < end; ++transform)
480 nsTArray<FontPref> fontPrefs;
486 for (transform = gTransforms; transform < end; ++transform)
491 nsCOMPtr<nsIFile> targetPrefsFile;
493 targetPrefsFile->Append(aTargetPrefFileName);
494 psvc->SavePrefFile(targetPrefsFile);
497 psvc->ReadUserPrefs(nsnull);
504 nsTArray<FontPref>* aPrefs)
507 nsCOMPtr<nsIPrefBranch> branch;
508 aPrefService->GetBranch(
"font.", getter_AddRefs(branch));
511 char**
prefs = nsnull;
512 nsresult rv = branch->GetChildList(
"", &count, &prefs);
513 if (NS_FAILED(rv))
return;
515 for (PRUint32
i = 0;
i <
count; ++
i) {
517 char* currPref = prefs[
i];
519 branch->GetPrefType(currPref, &type);
524 case nsIPrefBranch::PREF_STRING:
525 rv = branch->GetCharPref(currPref, &pref->
stringValue);
527 case nsIPrefBranch::PREF_BOOL:
528 rv = branch->GetBoolPref(currPref, &pref->
boolValue);
530 case nsIPrefBranch::PREF_INT:
531 rv = branch->GetIntPref(currPref, &pref->
intValue);
533 case nsIPrefBranch::PREF_INVALID:
535 nsCOMPtr<nsIPrefLocalizedString>
str;
536 rv = branch->GetComplexValue(currPref,
538 getter_AddRefs(str));
539 if (NS_SUCCEEDED(rv) && str)
546 aPrefs->RemoveElementAt(aPrefs->Length()-1);
552 nsTArray<FontPref>* aPrefs)
557 nsCOMPtr<nsIPrefBranch> branch;
558 aPrefService->GetBranch(
"font.", getter_AddRefs(branch));
560 PRUint32
count = aPrefs->Length();
561 for (PRUint32
i = 0;
i <
count; ++
i) {
564 case nsIPrefBranch::PREF_STRING:
569 case nsIPrefBranch::PREF_BOOL:
572 case nsIPrefBranch::PREF_INT:
575 case nsIPrefBranch::PREF_INVALID:
576 nsCOMPtr<nsIPrefLocalizedString> pls(do_CreateInstance(
"@mozilla.org/pref-localizedstring;1"));
578 rv = branch->SetComplexValue(pref.
prefName,
615 nsCOMPtr<nsIFile> sourceUserContent;
620 PRBool exists = PR_FALSE;
621 sourceUserContent->Exists(&exists);
625 nsCOMPtr<nsIFile> targetUserContent;
628 nsCOMPtr<nsIFile> targetChromeDir;
629 targetUserContent->Clone(getter_AddRefs(targetChromeDir));
632 targetUserContent->Exists(&exists);
634 targetUserContent->Remove(PR_FALSE);
646 nsCOMPtr<nsIFile> seamonkeyCookiesFile;
666 nsCString signonsFileName;
669 if (signonsFileName.IsEmpty())
670 return NS_ERROR_FILE_NOT_FOUND;
672 NS_ConvertASCIItoUTF16 fileName(signonsFileName);
680 nsCOMPtr<nsILoginManager> pwmgr(
681 do_GetService(
"@mozilla.org/login-manager;1"));
682 nsCOMPtr<nsILoginManagerStorage>
importer(
683 do_CreateInstance(
"@mozilla.org/login-manager/storage/legacy;1"));
685 nsCOMPtr<nsIFile> signonsFile;
687 signonsFile->Append(fileName);
689 importer->InitWithFile(signonsFile, nsnull);
692 nsILoginInfo **logins;
694 rv = importer->GetAllLogins(&count, &logins);
695 NS_ENSURE_SUCCESS(rv, rv);
696 for (PRUint32
i = 0;
i <
count;
i++) {
697 pwmgr->AddLogin(logins[
i]);
699 NS_FREE_XPCOM_ISUPPORTS_POINTER_ARRAY(count, logins);
701 PRUnichar **hostnames;
702 rv = importer->GetAllDisabledHosts(&count, &hostnames);
703 NS_ENSURE_SUCCESS(rv, rv);
704 for (PRUint32
i = 0;
i <
count;
i++) {
705 pwmgr->SetLoginSavingEnabled(nsDependentString(hostnames[
i]),
708 NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(count, hostnames);
720 NS_ENSURE_SUCCESS(rv, rv);
723 nsCOMPtr<nsIFile> sourceFile;
727 NS_ENSURE_SUCCESS(rv, rv);
731 NS_LITERAL_STRING(
"sourceNameSeamonkey").
get());
732 NS_ENSURE_SUCCESS(rv, rv);
nsresult CopyFile(const nsAString &aSourceFileName, const nsAString &aTargetFileName)
nsresult ImportNetscapeBookmarks(const nsAString &aBookmarksFileName, const PRUnichar *aImportSourceNameKey)
void ReadFontsBranch(nsIPrefService *aPrefService, nsTArray< FontPref > *aPrefs)
nsresult InitializeBookmarks(nsIFile *aTargetProfile)
void WriteFontsBranch(nsIPrefService *aPrefService, nsTArray< FontPref > *aPrefs)
nsresult CopyOtherData(PRBool aReplace)
#define FILE_NAME_SITEPERM_NEW
const unsigned short HISTORY
NS_IMPL_ISUPPORTS1(sbDeviceCapabilitiesUtils, sbIDeviceCapabilitiesUtils) sbDeviceCapabilitiesUtils
const NS_PREFSERVICE_CONTRACTID
const nsIPrefLocalizedString
#define FILE_NAME_SECMODDB
nsresult ImportBookmarksHTML(nsIFile *aBookmarksFile, PRBool aImportIntoRoot, PRBool aOverwriteDefaults, const PRUnichar *aImportSourceNameKey)
nsresult CopyPasswords(PRBool aReplace)
nsresult CopyPreferences(PRBool aReplace)
const unsigned short SETTINGS
#define FILE_NAME_HISTORY
#define FILE_NAME_USER_PREFS
static nsresult SetImage(void *aTransform, nsIPrefBranch *aBranch)
#define NOTIFY_OBSERVERS(message, item)
nsCOMPtr< nsIFile > mTargetProfile
#define FILE_NAME_BOOKMARKS
nsresult CopyHistory(PRBool aReplace)
nsresult CopyBookmarks(PRBool aReplace)
#define MIGRATION_STARTED
nsresult GetProfileDataFromRegistry(nsILocalFile *aRegistryFile, nsISupportsArray *aProfileNames, nsISupportsArray *aProfileLocations)
virtual ~nsSeamonkeyProfileMigrator()
#define FILE_NAME_DOWNLOADS
#define COPY_DATA(func, replace, itemIndex)
nsresult CopyCookies(PRBool aReplace)
this _dialogInput val(dateText)
nsresult FillProfileDataFromSeamonkeyRegistry()
#define FILE_NAME_USERCONTENT
static nsSeamonkeyProfileMigrator::PrefTransform gTransforms[]
#define FILE_NAME_SITEPERM_OLD
nsresult CopyUserContentSheet()
nsresult GetSourceProfile(const PRUnichar *aProfile)
const unsigned short COOKIES
#define MAKESAMETYPEPREFTRANSFORM(pref, method)
#define FILE_NAME_CERT8DB
const unsigned short BOOKMARKS
static nsresult SetCookie(void *aTransform, nsIPrefBranch *aBranch)
void GetProfilePath(nsIProfileStartup *aStartup, nsCOMPtr< nsIFile > &aProfileDir)
nsresult TransformPreferences(const nsAString &aSourcePrefFileName, const nsAString &aTargetPrefFileName)
#define MAKEPREFTRANSFORM(pref, newpref, getmethod, setmethod)
static nsresult SetDownloadManager(void *aTransform, nsIPrefBranch *aBranch)
const unsigned short PASSWORDS
const unsigned short OTHERDATA
_getSelectedPageStyle s i
#define FILE_NAME_COOKIES
nsresult ImportNetscapeCookies(nsIFile *aCookiesFile)
nsCOMPtr< nsILocalFile > mSourceProfile
void GetMigrateDataFromArray(MigrationData *aDataArray, PRInt32 aDataArrayLength, PRBool aReplace, nsIFile *aSourceProfile, PRUint16 *aResult)
#define FILE_NAME_MIMETYPES
nsresult GetSignonFileName(PRBool aReplace, char **aFileName)