From f2a284c8dc17da9c19aea3c80070192e4ec5f01b Mon Sep 17 00:00:00 2001 From: "bugzilla%standard8.demon.co.uk" Date: Thu, 21 Jun 2007 19:43:40 +0000 Subject: [PATCH] Final part of Bug 329744 - tidy up some of the string defines/usage. r=Neil. --- .../src/nsNetscapeProfileMigratorBase.cpp | 68 ++++++++----------- .../src/nsNetscapeProfileMigratorBase.h | 24 +++---- .../src/nsSeamonkeyProfileMigrator.cpp | 28 ++++---- .../src/nsSeamonkeyProfileMigrator.h | 4 +- .../src/nsSuiteProfileMigratorUtils.cpp | 2 +- .../src/nsSuiteProfileMigratorUtils.h | 2 +- .../src/nsThunderbirdProfileMigrator.cpp | 29 ++++---- .../src/nsThunderbirdProfileMigrator.h | 4 +- 8 files changed, 75 insertions(+), 86 deletions(-) diff --git a/suite/profile/migration/src/nsNetscapeProfileMigratorBase.cpp b/suite/profile/migration/src/nsNetscapeProfileMigratorBase.cpp index 2123fb9bd2a..ba6dbe0d335 100644 --- a/suite/profile/migration/src/nsNetscapeProfileMigratorBase.cpp +++ b/suite/profile/migration/src/nsNetscapeProfileMigratorBase.cpp @@ -241,7 +241,7 @@ nsNetscapeProfileMigratorBase::GetSourceHomePageURL(nsACString& aResult) nsCOMPtr sourcePrefsFile; mSourceProfile->Clone(getter_AddRefs(sourcePrefsFile)); - sourcePrefsFile->Append(FILE_NAME_PREFS); + sourcePrefsFile->AppendNative(NS_LITERAL_CSTRING(FILE_NAME_PREFS)); psvc->ReadUserPrefs(sourcePrefsFile); @@ -589,13 +589,13 @@ nsNetscapeProfileMigratorBase::GetProfileDataFromRegistry(nsILocalFile* aRegistr } nsresult -nsNetscapeProfileMigratorBase::CopyFile(const nsAString& aSourceFileName, - const nsAString& aTargetFileName) +nsNetscapeProfileMigratorBase::CopyFile(const char* aSourceFileName, + const char* aTargetFileName) { nsCOMPtr sourceFile; mSourceProfile->Clone(getter_AddRefs(sourceFile)); - sourceFile->Append(aSourceFileName); + sourceFile->AppendNative(nsDependentCString(aSourceFileName)); PRBool exists = PR_FALSE; sourceFile->Exists(&exists); if (!exists) @@ -604,12 +604,13 @@ nsNetscapeProfileMigratorBase::CopyFile(const nsAString& aSourceFileName, nsCOMPtr targetFile; mTargetProfile->Clone(getter_AddRefs(targetFile)); - targetFile->Append(aTargetFileName); + targetFile->AppendNative(nsDependentCString(aTargetFileName)); targetFile->Exists(&exists); if (exists) targetFile->Remove(PR_FALSE); - return sourceFile->CopyTo(mTargetProfile, aTargetFileName); + return sourceFile->CopyToNative(mTargetProfile, + nsDependentCString(aTargetFileName)); } // helper function, copies the contents of srcDir into destDir. @@ -789,7 +790,7 @@ nsNetscapeProfileMigratorBase::CopyCookies(PRBool aReplace) nsCOMPtr seamonkeyCookiesFile; mSourceProfile->Clone(getter_AddRefs(seamonkeyCookiesFile)); - seamonkeyCookiesFile->Append(FILE_NAME_COOKIES); + seamonkeyCookiesFile->AppendNative(NS_LITERAL_CSTRING(FILE_NAME_COOKIES)); return ImportNetscapeCookies(seamonkeyCookiesFile); } @@ -803,15 +804,8 @@ nsNetscapeProfileMigratorBase::CopyFormData(PRBool aReplace) if (svFileName.IsEmpty()) return NS_ERROR_FILE_NOT_FOUND; - nsAutoString fileName; - fileName.Append(NS_ConvertUTF8toUTF16(svFileName)); - if (aReplace) - return CopyFile(fileName, fileName); - - nsCOMPtr seamonkeyFormDataFile; - mSourceProfile->Clone(getter_AddRefs(seamonkeyFormDataFile)); - seamonkeyFormDataFile->Append(fileName); + return CopyFile(svFileName.get(), svFileName.get()); // We don't need to do anything else here - there's no import function // for form data, so instead we just let the pref functions copy the @@ -829,15 +823,12 @@ nsNetscapeProfileMigratorBase::CopyPasswords(PRBool aReplace) if (signonsFileName.IsEmpty()) return NS_ERROR_FILE_NOT_FOUND; - nsAutoString fileName; - fileName.Assign(NS_ConvertUTF8toUTF16(signonsFileName)); - if (aReplace) - return CopyFile(fileName, fileName); + return CopyFile(signonsFileName.get(), signonsFileName.get()); nsCOMPtr seamonkeyPasswordsFile; mSourceProfile->Clone(getter_AddRefs(seamonkeyPasswordsFile)); - seamonkeyPasswordsFile->Append(fileName); + seamonkeyPasswordsFile->AppendNative(signonsFileName); nsCOMPtr pmi( do_GetService("@mozilla.org/passwordmanager;1")); @@ -850,7 +841,7 @@ nsNetscapeProfileMigratorBase::CopyUserContentSheet() nsCOMPtr sourceUserContent; mSourceProfile->Clone(getter_AddRefs(sourceUserContent)); sourceUserContent->Append(DIR_NAME_CHROME); - sourceUserContent->Append(FILE_NAME_USERCONTENT); + sourceUserContent->AppendNative(NS_LITERAL_CSTRING(FILE_NAME_USERCONTENT)); PRBool exists = PR_FALSE; sourceUserContent->Exists(&exists); @@ -862,13 +853,14 @@ nsNetscapeProfileMigratorBase::CopyUserContentSheet() targetUserContent->Append(DIR_NAME_CHROME); nsCOMPtr targetChromeDir; targetUserContent->Clone(getter_AddRefs(targetChromeDir)); - targetUserContent->Append(FILE_NAME_USERCONTENT); + targetUserContent->AppendNative(NS_LITERAL_CSTRING(FILE_NAME_USERCONTENT)); targetUserContent->Exists(&exists); if (exists) targetUserContent->Remove(PR_FALSE); - return sourceUserContent->CopyTo(targetChromeDir, FILE_NAME_USERCONTENT); + return sourceUserContent->CopyTo(targetChromeDir, + NS_LITERAL_STRING(FILE_NAME_USERCONTENT)); } nsresult @@ -1053,8 +1045,7 @@ nsNetscapeProfileMigratorBase::CopyBookmarks(PRBool aReplace) if (aReplace) return CopyFile(FILE_NAME_BOOKMARKS, FILE_NAME_BOOKMARKS); - return ImportNetscapeBookmarks(FILE_NAME_BOOKMARKS, - NS_LITERAL_STRING("sourceNameSeamonkey").get()); + return ImportNetscapeBookmarks(FILE_NAME_BOOKMARKS, "sourceNameSeamonkey"); } nsresult @@ -1069,14 +1060,15 @@ nsNetscapeProfileMigratorBase::CopyOtherData(PRBool aReplace) } nsresult -nsNetscapeProfileMigratorBase::ImportNetscapeBookmarks(const nsAString& aBookmarksFileName, - const PRUnichar* aImportSourceNameKey) +nsNetscapeProfileMigratorBase::ImportNetscapeBookmarks(const char* aBookmarksFileName, + const char* aImportSourceNameKey) { nsCOMPtr bookmarksFile; mSourceProfile->Clone(getter_AddRefs(bookmarksFile)); - bookmarksFile->Append(aBookmarksFileName); - - return ImportBookmarksHTML(bookmarksFile, aImportSourceNameKey); + bookmarksFile->AppendNative(nsDependentCString(aBookmarksFileName)); + + return ImportBookmarksHTML(bookmarksFile, + NS_ConvertUTF8toUTF16(aImportSourceNameKey).get()); } /////////////////////////////////////////////////////////////////////////////// @@ -1097,10 +1089,8 @@ nsNetscapeProfileMigratorBase::CopyAddressBookDirectories(PBStructArray &aLdapSe PrefBranchStruct* pref = aLdapServers.ElementAt(i); nsDependentCString prefName(pref->prefName); - if (StringEndsWith(prefName, nsDependentCString(".filename"))) { - // should we be assuming utf-8 or ascii here? - CopyFile(NS_ConvertUTF8toUTF16(pref->stringValue), - NS_ConvertUTF8toUTF16(pref->stringValue)); + if (StringEndsWith(prefName, NS_LITERAL_CSTRING(".filename"))) { + CopyFile(pref->stringValue, pref->stringValue); } // we don't need to do anything to the fileName pref itself @@ -1128,7 +1118,7 @@ nsNetscapeProfileMigratorBase::CopySignatureFiles(PBStructArray &aIdentities, // old profile root, we'll copy it over to the new profile root and // then set the pref to the new value. Note, this doesn't work for // multiple signatures that live below the seamonkey profile root - if (StringEndsWith(prefName, nsDependentCString(".sig_file"))) + if (StringEndsWith(prefName, NS_LITERAL_CSTRING(".sig_file"))) { // turn the pref into a nsILocalFile nsCOMPtr srcSigFile = @@ -1165,8 +1155,8 @@ nsNetscapeProfileMigratorBase::CopySignatureFiles(PBStructArray &aIdentities, nsresult nsNetscapeProfileMigratorBase::CopyJunkTraining(PRBool aReplace) { - return aReplace ? CopyFile(FILE_NAME_JUNKTRAINING, FILE_NAME_JUNKTRAINING) : - NS_OK; + return aReplace ? CopyFile(FILE_NAME_JUNKTRAINING, + FILE_NAME_JUNKTRAINING) : NS_OK; } nsresult @@ -1199,7 +1189,7 @@ nsNetscapeProfileMigratorBase::CopyMailFolderPrefs(PBStructArray &aMailServers, --i; --count; } - else if (StringEndsWith(prefName, nsDependentCString(".directory"))) { + else if (StringEndsWith(prefName, NS_LITERAL_CSTRING(".directory"))) { // let's try to get a branch for this particular server to simplify things prefName.Cut(prefName.Length() - strlen("directory"), strlen("directory")); @@ -1260,7 +1250,7 @@ nsNetscapeProfileMigratorBase::CopyMailFolderPrefs(PBStructArray &aMailServers, pref->stringValue = ToNewCString(descriptorString); } } - else if (StringEndsWith(prefName, nsDependentCString(".newsrc.file"))) { + else if (StringEndsWith(prefName, NS_LITERAL_CSTRING(".newsrc.file"))) { // copy the news RC file into \News. this won't work if the user has // different newsrc files for each account I don't know what to do in // that situation. diff --git a/suite/profile/migration/src/nsNetscapeProfileMigratorBase.h b/suite/profile/migration/src/nsNetscapeProfileMigratorBase.h index 75e8e16f02d..8750f321bd4 100644 --- a/suite/profile/migration/src/nsNetscapeProfileMigratorBase.h +++ b/suite/profile/migration/src/nsNetscapeProfileMigratorBase.h @@ -56,14 +56,14 @@ struct fileTransactionEntry { // getting copied }; -#define FILE_NAME_BOOKMARKS NS_LITERAL_STRING("bookmarks.html") -#define FILE_NAME_COOKIES NS_LITERAL_STRING("cookies.txt") -#define FILE_NAME_PREFS NS_LITERAL_STRING("prefs.js") -#define FILE_NAME_JUNKTRAINING NS_LITERAL_STRING("training.dat") -#define FILE_NAME_VIRTUALFOLDERS NS_LITERAL_STRING("virtualFolders.dat") -#define FILE_NAME_USERCONTENT NS_LITERAL_STRING("userContent.css") -#define FILE_NAME_SEARCH NS_LITERAL_STRING("search.rdf") -#define FILE_NAME_DOWNLOADS NS_LITERAL_STRING("downloads.rdf") +#define FILE_NAME_BOOKMARKS "bookmarks.html" +#define FILE_NAME_COOKIES "cookies.txt" +#define FILE_NAME_PREFS "prefs.js" +#define FILE_NAME_JUNKTRAINING "training.dat" +#define FILE_NAME_VIRTUALFOLDERS "virtualFolders.dat" +#define FILE_NAME_USERCONTENT "userContent.css" +#define FILE_NAME_SEARCH "search.rdf" +#define FILE_NAME_DOWNLOADS "downloads.rdf" #define F(a) nsNetscapeProfileMigratorBase::a @@ -146,8 +146,8 @@ protected: nsresult GetProfileDataFromRegistry(nsILocalFile* aRegistryFile, nsISupportsArray* aProfileNames, nsISupportsArray* aProfileLocations); - nsresult CopyFile(const nsAString& aSourceFileName, - const nsAString& aTargetFileName); + nsresult CopyFile(const char* aSourceFileName, + const char* aTargetFileName); nsresult RecursiveCopy(nsIFile* srcDir, nsIFile* destDir); void ReadBranch(const char * branchName, nsIPrefService* aPrefService, PBStructArray &aPrefs); @@ -167,8 +167,8 @@ protected: // Browser Import Functions nsresult CopyBookmarks(PRBool aReplace); nsresult CopyOtherData(PRBool aReplace); - nsresult ImportNetscapeBookmarks(const nsAString& aBookmarksFileName, - const PRUnichar* aImportSourceNameKey); + nsresult ImportNetscapeBookmarks(const char* aBookmarksFileName, + const char* aImportSourceNameKey); // Mail Import Functions nsresult CopyAddressBookDirectories(PBStructArray &aLdapServers, diff --git a/suite/profile/migration/src/nsSeamonkeyProfileMigrator.cpp b/suite/profile/migration/src/nsSeamonkeyProfileMigrator.cpp index a84d0153c01..ba489444eba 100644 --- a/suite/profile/migration/src/nsSeamonkeyProfileMigrator.cpp +++ b/suite/profile/migration/src/nsSeamonkeyProfileMigrator.cpp @@ -52,16 +52,16 @@ /////////////////////////////////////////////////////////////////////////////// // nsSeamonkeyProfileMigrator -#define FILE_NAME_SITEPERM_OLD NS_LITERAL_STRING("cookperm.txt") -#define FILE_NAME_SITEPERM_NEW NS_LITERAL_STRING("hostperm.1") -#define FILE_NAME_CERT8DB NS_LITERAL_STRING("cert8.db") -#define FILE_NAME_KEY3DB NS_LITERAL_STRING("key3.db") -#define FILE_NAME_SECMODDB NS_LITERAL_STRING("secmod.db") -#define FILE_NAME_HISTORY NS_LITERAL_STRING("history.dat") -#define FILE_NAME_MIMETYPES NS_LITERAL_STRING("mimeTypes.rdf") -#define FILE_NAME_USER_PREFS NS_LITERAL_STRING("user.js") -#define FILE_NAME_PERSONALDICTIONARY NS_LITERAL_STRING("persdict.dat") -#define FILE_NAME_MAILVIEWS NS_LITERAL_STRING("mailViews.dat") +#define FILE_NAME_SITEPERM_OLD "cookperm.txt" +#define FILE_NAME_SITEPERM_NEW "hostperm.1" +#define FILE_NAME_CERT8DB "cert8.db" +#define FILE_NAME_KEY3DB "key3.db" +#define FILE_NAME_SECMODDB "secmod.db" +#define FILE_NAME_HISTORY "history.dat" +#define FILE_NAME_MIMETYPES "mimeTypes.rdf" +#define FILE_NAME_USER_PREFS "user.js" +#define FILE_NAME_PERSONALDICTIONARY "persdict.dat" +#define FILE_NAME_MAILVIEWS "mailViews.dat" NS_IMPL_ISUPPORTS2(nsSeamonkeyProfileMigrator, nsISuiteProfileMigrator, nsITimerCallback) @@ -585,8 +585,8 @@ nsSeamonkeyProfileMigrator::PrefTransform gTransforms[] = { }; nsresult -nsSeamonkeyProfileMigrator::TransformPreferences(const nsAString& aSourcePrefFileName, - const nsAString& aTargetPrefFileName) +nsSeamonkeyProfileMigrator::TransformPreferences(const char* aSourcePrefFileName, + const char* aTargetPrefFileName) { PrefTransform* transform; PrefTransform* end = gTransforms + sizeof(gTransforms)/sizeof(PrefTransform); @@ -597,7 +597,7 @@ nsSeamonkeyProfileMigrator::TransformPreferences(const nsAString& aSourcePrefFil nsCOMPtr sourcePrefsFile; mSourceProfile->Clone(getter_AddRefs(sourcePrefsFile)); - sourcePrefsFile->Append(aSourcePrefFileName); + sourcePrefsFile->AppendNative(nsDependentCString(aSourcePrefFileName)); psvc->ReadUserPrefs(sourcePrefsFile); nsCOMPtr branch(do_QueryInterface(psvc)); @@ -680,7 +680,7 @@ nsSeamonkeyProfileMigrator::TransformPreferences(const nsAString& aSourcePrefFil nsCOMPtr targetPrefsFile; mTargetProfile->Clone(getter_AddRefs(targetPrefsFile)); - targetPrefsFile->Append(aTargetPrefFileName); + targetPrefsFile->AppendNative(nsDependentCString(aTargetPrefFileName)); psvc->SavePrefFile(targetPrefsFile); psvc->ResetPrefs(); diff --git a/suite/profile/migration/src/nsSeamonkeyProfileMigrator.h b/suite/profile/migration/src/nsSeamonkeyProfileMigrator.h index b864c8b5639..8b98146db53 100644 --- a/suite/profile/migration/src/nsSeamonkeyProfileMigrator.h +++ b/suite/profile/migration/src/nsSeamonkeyProfileMigrator.h @@ -69,8 +69,8 @@ public: protected: nsresult FillProfileDataFromRegistry(); nsresult CopyPreferences(PRBool aReplace); - nsresult TransformPreferences(const nsAString& aSourcePrefFileName, - const nsAString& aTargetPrefFileName); + nsresult TransformPreferences(const char* aSourcePrefFileName, + const char* aTargetPrefFileName); nsresult CopyHistory(PRBool aReplace); nsresult LocateSignonsFile(char** aResult); diff --git a/suite/profile/migration/src/nsSuiteProfileMigratorUtils.cpp b/suite/profile/migration/src/nsSuiteProfileMigratorUtils.cpp index ec2d420f8bd..a26a6b9f7d7 100644 --- a/suite/profile/migration/src/nsSuiteProfileMigratorUtils.cpp +++ b/suite/profile/migration/src/nsSuiteProfileMigratorUtils.cpp @@ -137,7 +137,7 @@ void GetMigrateDataFromArray(MigrationData* aDataArray, // replacement can be imported. if (aReplace || !cursor->replaceOnly) { aSourceProfile->Clone(getter_AddRefs(sourceFile)); - sourceFile->Append(cursor->fileName); + sourceFile->AppendNative(nsDependentCString(cursor->fileName)); sourceFile->Exists(&exists); if (exists) *aResult |= cursor->sourceFlag; diff --git a/suite/profile/migration/src/nsSuiteProfileMigratorUtils.h b/suite/profile/migration/src/nsSuiteProfileMigratorUtils.h index 08018145837..82672797ad9 100644 --- a/suite/profile/migration/src/nsSuiteProfileMigratorUtils.h +++ b/suite/profile/migration/src/nsSuiteProfileMigratorUtils.h @@ -77,7 +77,7 @@ void SetProxyPref(const nsAString& aHostPort, const char* aPref, const char* aPortPref, nsIPrefBranch* aPrefs); struct MigrationData { - nsString fileName; + char* fileName; PRUint32 sourceFlag; PRBool replaceOnly; }; diff --git a/suite/profile/migration/src/nsThunderbirdProfileMigrator.cpp b/suite/profile/migration/src/nsThunderbirdProfileMigrator.cpp index 0ee76075058..4c791cec48c 100644 --- a/suite/profile/migration/src/nsThunderbirdProfileMigrator.cpp +++ b/suite/profile/migration/src/nsThunderbirdProfileMigrator.cpp @@ -53,17 +53,16 @@ /////////////////////////////////////////////////////////////////////////////// // nsThunderbirdProfileMigrator -#define FILE_NAME_SITEPERM_OLD NS_LITERAL_STRING("cookperm.txt") -#define FILE_NAME_SITEPERM_NEW NS_LITERAL_STRING("hostperm.1") -#define FILE_NAME_CERT8DB NS_LITERAL_STRING("cert8.db") -#define FILE_NAME_KEY3DB NS_LITERAL_STRING("key3.db") -#define FILE_NAME_SECMODDB NS_LITERAL_STRING("secmod.db") -#define FILE_NAME_HISTORY NS_LITERAL_STRING("history.dat") -#define FILE_NAME_MIMETYPES NS_LITERAL_STRING("mimeTypes.rdf") -#define FILE_NAME_USER_PREFS NS_LITERAL_STRING("user.js") -#define FILE_NAME_PERSONALDICTIONARY NS_LITERAL_STRING("persdict.dat") -#define FILE_NAME_MAILVIEWS NS_LITERAL_STRING("mailViews.dat") -#define FILE_NAME_VIRTUALFOLDERS NS_LITERAL_STRING("virtualFolders.dat") +#define FILE_NAME_SITEPERM_OLD "cookperm.txt" +#define FILE_NAME_SITEPERM_NEW "hostperm.1" +#define FILE_NAME_CERT8DB "cert8.db" +#define FILE_NAME_KEY3DB "key3.db" +#define FILE_NAME_SECMODDB "secmod.db" +#define FILE_NAME_HISTORY "history.dat" +#define FILE_NAME_MIMETYPES "mimeTypes.rdf" +#define FILE_NAME_USER_PREFS "user.js" +#define FILE_NAME_PERSONALDICTIONARY "persdict.dat" +#define FILE_NAME_MAILVIEWS "mailViews.dat" NS_IMPL_ISUPPORTS2(nsThunderbirdProfileMigrator, nsISuiteProfileMigrator, nsITimerCallback) @@ -558,8 +557,8 @@ nsThunderbirdProfileMigrator::PrefTransform gTransforms[] = { nsresult nsThunderbirdProfileMigrator::TransformPreferences( - const nsAString& aSourcePrefFileName, - const nsAString& aTargetPrefFileName) + const char* aSourcePrefFileName, + const char* aTargetPrefFileName) { PrefTransform* transform; PrefTransform* end = gTransforms + sizeof(gTransforms)/sizeof(PrefTransform); @@ -570,7 +569,7 @@ nsThunderbirdProfileMigrator::TransformPreferences( nsCOMPtr sourcePrefsFile; mSourceProfile->Clone(getter_AddRefs(sourcePrefsFile)); - sourcePrefsFile->Append(aSourcePrefFileName); + sourcePrefsFile->AppendNative(nsDependentCString(aSourcePrefFileName)); psvc->ReadUserPrefs(sourcePrefsFile); nsCOMPtr branch(do_QueryInterface(psvc)); @@ -639,7 +638,7 @@ nsThunderbirdProfileMigrator::TransformPreferences( nsCOMPtr targetPrefsFile; mTargetProfile->Clone(getter_AddRefs(targetPrefsFile)); - targetPrefsFile->Append(aTargetPrefFileName); + targetPrefsFile->AppendNative(nsDependentCString(aTargetPrefFileName)); psvc->SavePrefFile(targetPrefsFile); psvc->ResetPrefs(); diff --git a/suite/profile/migration/src/nsThunderbirdProfileMigrator.h b/suite/profile/migration/src/nsThunderbirdProfileMigrator.h index 44642f01096..f137712da53 100644 --- a/suite/profile/migration/src/nsThunderbirdProfileMigrator.h +++ b/suite/profile/migration/src/nsThunderbirdProfileMigrator.h @@ -71,8 +71,8 @@ public: protected: nsresult FillProfileDataFromRegistry(); nsresult CopyPreferences(PRBool aReplace); - nsresult TransformPreferences(const nsAString& aSourcePrefFileName, - const nsAString& aTargetPrefFileName); + nsresult TransformPreferences(const char* aSourcePrefFileName, + const char* aTargetPrefFileName); nsresult CopyHistory(PRBool aReplace); nsresult LocateSignonsFile(char** aResult); };