From 824def02af9283df7dbba758d0ec026013e39881 Mon Sep 17 00:00:00 2001 From: "darin%netscape.com" Date: Sat, 27 Apr 2002 05:33:09 +0000 Subject: [PATCH] fixes bug 129279 "nsIFile unicode/utf8/ascii task" r=dougt sr=alecf git-svn-id: svn://10.0.0.236/trunk@120092 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/caps/src/nsScriptSecurityManager.cpp | 4 +- mozilla/chrome/src/nsChromeRegistry.cpp | 41 +- mozilla/configure.in | 28 +- .../html/content/src/nsHTMLInputElement.cpp | 11 +- .../xul/document/src/nsXULDocument.cpp | 12 +- mozilla/docshell/base/nsDefaultURIFixup.cpp | 41 +- mozilla/docshell/base/nsDefaultURIFixup.h | 1 - .../activex/src/control/MozillaBrowser.cpp | 6 +- .../browser/gtk/src/EmbedPrivate.cpp | 4 +- .../source/CAppFileLocationProvider.cpp | 14 +- .../powerplant/source/CProfileManager.cpp | 5 +- .../ui/helperAppDlg/nsHelperAppDlg.js | 10 +- .../ui/progressDlg/nsProgressDialog.js | 4 +- .../ui/progressDlg/nsProgressDlg.js | 4 +- .../src/nsWebBrowserPersist.cpp | 22 +- .../embedding/tests/mfcembed/BrowserView.cpp | 8 +- .../tests/mfcembed/MostRecentUrls.cpp | 2 +- .../mfcembed/components/HelperAppDlg.cpp | 4 +- .../mfcembed/winEmbedFileLocProvider.cpp | 20 +- mozilla/embedding/tests/winEmbed/winEmbed.cpp | 4 +- mozilla/extensions/cookie/nsCookies.cpp | 2 +- mozilla/extensions/cookie/nsPermissions.cpp | 2 +- mozilla/extensions/cookie/nsUtils.cpp | 7 +- .../inspector/base/src/inFileSearch.cpp | 21 +- .../content/viewers/boxModel/boxModel.js | 2 +- .../pref/autoconfig/src/nsAutoConfig.cpp | 4 +- .../pref/autoconfig/src/nsReadConfig.cpp | 10 +- .../venkman/resources/content/file-utils.js | 4 +- .../resources/content/venkman-utils.js | 2 +- mozilla/extensions/wallet/src/wallet.cpp | 23 +- .../xmlterm/base/mozXMLTermSession.cpp | 2 +- mozilla/gfx/public/nsNameValuePairDB.h | 4 +- mozilla/gfx/src/freetype/nsFT2FontCatalog.cpp | 79 ++- mozilla/gfx/src/freetype/nsFT2FontCatalog.h | 10 +- mozilla/gfx/src/mac/nsDeviceContextSpecX.cpp | 5 +- mozilla/gfx/src/nsNameValuePairDB.cpp | 31 +- .../gfx/src/x11shared/nsFT2FontCatalog.cpp | 79 ++- mozilla/gfx/src/x11shared/nsFT2FontCatalog.h | 10 +- .../gfx/src/x11shared/nsNameValuePairDB.cpp | 31 +- .../xpconnect/loader/mozJSComponentLoader.cpp | 34 +- mozilla/layout/forms/nsFileControlFrame.cpp | 20 +- .../html/forms/src/nsFileControlFrame.cpp | 20 +- mozilla/mailnews/absync/src/nsAbSync.cpp | 16 +- .../absync/src/nsAbSyncPostEngine.cpp | 2 +- .../addrbook/src/nsAbLDAPReplicationData.cpp | 29 +- .../addrbook/src/nsAbLDAPReplicationData.h | 3 +- .../addrbook/src/nsAddrBookSession.cpp | 8 +- .../mailnews/addrbook/src/nsAddressBook.cpp | 4 +- .../prefs/resources/content/AccountManager.js | 4 +- .../prefs/resources/content/AccountWizard.js | 2 +- .../base/prefs/resources/content/am-main.js | 2 +- .../base/search/src/nsMsgFilterService.cpp | 4 +- mozilla/mailnews/base/src/nsMessenger.cpp | 49 +- .../mailnews/base/src/nsMessengerMigrator.cpp | 74 +-- .../base/src/nsMessengerWinIntegration.cpp | 10 +- .../mailnews/base/src/nsMsgAccountManager.cpp | 8 +- .../mailnews/base/src/nsMsgMailSession.cpp | 6 +- .../base/util/nsMsgIncomingServer.cpp | 8 +- mozilla/mailnews/compose/src/nsMsgCompose.cpp | 16 +- .../mailnews/imap/src/nsImapMailFolder.cpp | 13 +- mozilla/mailnews/imap/src/nsImapService.cpp | 6 +- .../import/comm4x/src/nsComm4xProfile.cpp | 16 +- .../mailnews/local/src/nsMovemailService.cpp | 6 +- .../mailnews/local/src/nsNoIncomingServer.cpp | 6 +- mozilla/mailnews/local/src/nsNoneService.cpp | 6 +- mozilla/mailnews/local/src/nsParseMailbox.cpp | 14 +- mozilla/mailnews/local/src/nsPop3Service.cpp | 6 +- .../mapi/mapihook/src/msgMapiHook.cpp | 62 +- .../mapi/mapihook/src/nsMapiRegistryUtils.cpp | 28 +- .../news/src/nsNntpIncomingServer.cpp | 6 +- mozilla/mailnews/news/src/nsNntpService.cpp | 6 +- mozilla/modules/libjar/nsJAR.cpp | 21 +- .../decoders/icon/mac/nsIconChannel.cpp | 14 +- .../libpr0n/decoders/icon/mac/nsIconChannel.h | 2 +- .../libpr0n/decoders/icon/nsIIconURI.idl | 4 +- .../libpr0n/decoders/icon/nsIconURI.cpp | 16 +- .../decoders/icon/win/nsIconChannel.cpp | 15 +- .../libpr0n/decoders/icon/win/nsIconChannel.h | 2 +- mozilla/modules/libpref/src/nsPrefBranch.cpp | 8 +- mozilla/modules/libpref/src/nsPrefService.cpp | 39 +- .../modules/libpref/src/nsSafeSaveFile.cpp | 38 +- mozilla/modules/libpref/src/nsSafeSaveFile.h | 3 +- mozilla/modules/libreg/xpcom/nsIRegistry.idl | 4 +- mozilla/modules/libreg/xpcom/nsRegistry.cpp | 44 +- mozilla/modules/libreg/xpcom/nsRegistry.h | 4 +- .../public/nsMPFileLocProvider.h | 2 +- .../src/nsMPFileLocProvider.cpp | 34 +- .../modules/plugin/base/src/nsIPluginHost.h | 2 +- .../base/src/nsPluginDirServiceProvider.cpp | 5 +- .../plugin/base/src/nsPluginHostImpl.cpp | 179 +++-- mozilla/netwerk/base/public/nsNetUtil.h | 4 +- .../base/src/nsDirectoryIndexStream.cpp | 22 +- mozilla/netwerk/base/src/nsFileStreams.cpp | 24 +- mozilla/netwerk/base/src/nsFileStreams.h | 2 +- mozilla/netwerk/base/src/nsIOServiceMac.cpp | 16 +- mozilla/netwerk/base/src/nsIOServiceOS2.cpp | 16 +- mozilla/netwerk/base/src/nsIOServiceUnix.cpp | 16 +- mozilla/netwerk/base/src/nsIOServiceWin.cpp | 16 +- mozilla/netwerk/base/src/nsStandardURL.cpp | 4 +- .../netwerk/cache/src/nsDiskCacheDevice.cpp | 16 +- mozilla/netwerk/cache/src/nsDiskCacheMap.cpp | 6 +- mozilla/netwerk/mime/src/nsMIMEService.cpp | 11 +- .../protocol/about/src/nsAboutBloat.cpp | 8 +- mozilla/netwerk/test/TestFileInput.cpp | 12 +- mozilla/netwerk/test/TestFileInput2.cpp | 21 +- mozilla/netwerk/test/TestFileTransport.cpp | 21 +- mozilla/netwerk/test/TestUpload.cpp | 2 +- .../pref-migrator/src/nsPrefMigration.cpp | 55 +- .../resources/content/createProfileWizard.js | 6 +- .../resources/content/newProfile1_2.js | 12 +- .../resources/content/profileSelection.js | 2 +- mozilla/profile/src/nsProfile.cpp | 163 ++--- mozilla/profile/src/nsProfile.h | 2 +- mozilla/profile/src/nsProfileAccess.cpp | 61 +- mozilla/rdf/chrome/src/nsChromeRegistry.cpp | 41 +- .../datasource/src/nsFileSystemDataSource.cpp | 39 +- .../manager/ssl/src/nsNSSComponent.cpp | 39 +- .../security/manager/ssl/src/nsPKCS12Blob.cpp | 33 +- .../exthandler/mac/nsOSHelperAppService.cpp | 2 +- .../exthandler/nsExternalHelperAppService.cpp | 98 +-- .../exthandler/nsExternalHelperAppService.h | 6 +- .../exthandler/unix/nsOSHelperAppService.cpp | 21 +- .../exthandler/win/nsOSHelperAppService.cpp | 10 +- mozilla/widget/src/windows/nsClipboard.cpp | 6 +- mozilla/widget/src/windows/nsFilePicker.cpp | 39 +- mozilla/widget/src/windows/nsWindow.cpp | 20 +- mozilla/xpcom/build/dlldeps.cpp | 3 +- mozilla/xpcom/build/nsXPComInit.cpp | 7 +- .../xpcom/components/nsComponentManager.cpp | 33 +- mozilla/xpcom/components/nsIRegistry.idl | 4 +- .../components/nsNativeComponentLoader.cpp | 15 +- mozilla/xpcom/components/nsRegistry.cpp | 44 +- mozilla/xpcom/components/nsRegistry.h | 4 +- mozilla/xpcom/components/xcDll.cpp | 39 +- mozilla/xpcom/components/xcDll.h | 9 +- mozilla/xpcom/io/Makefile.in | 6 +- .../xpcom/io/nsAppFileLocationProvider.cpp | 48 +- mozilla/xpcom/io/nsDirectoryService.cpp | 27 +- mozilla/xpcom/io/nsFastLoadFile.cpp | 17 +- mozilla/xpcom/io/nsFastLoadService.cpp | 10 +- mozilla/xpcom/io/nsFileSpec.cpp | 3 +- mozilla/xpcom/io/nsFileSpecImpl.cpp | 19 + mozilla/xpcom/io/nsFileSpecMac.cpp | 4 +- mozilla/xpcom/io/nsIFile.idl | 30 +- mozilla/xpcom/io/nsIFileSpec.idl | 13 + mozilla/xpcom/io/nsILocalFile.idl | 18 +- mozilla/xpcom/io/nsLocalFile.h | 14 +- mozilla/xpcom/io/nsLocalFileCommon.cpp | 218 ++++-- mozilla/xpcom/io/nsLocalFileMac.cpp | 197 +++--- mozilla/xpcom/io/nsLocalFileMac.h | 16 +- mozilla/xpcom/io/nsLocalFileOS2.cpp | 380 +++++------ mozilla/xpcom/io/nsLocalFileOS2.h | 21 +- mozilla/xpcom/io/nsLocalFileUnicode.cpp | 57 +- mozilla/xpcom/io/nsLocalFileUnicode.h | 3 + mozilla/xpcom/io/nsLocalFileUnix.cpp | 619 +++++++++++------- mozilla/xpcom/io/nsLocalFileUnix.h | 53 +- mozilla/xpcom/io/nsLocalFileWin.cpp | 489 +++++++------- mozilla/xpcom/io/nsLocalFileWin.h | 24 +- .../xptinfo/src/xptiInterfaceInfoManager.cpp | 67 +- .../reflect/xptinfo/src/xptiManifest.cpp | 29 +- .../reflect/xptinfo/src/xptiWorkingSet.cpp | 5 +- .../xpcom/reflect/xptinfo/src/xptiprivate.h | 23 +- mozilla/xpcom/tests/nsIFileEnumerator.cpp | 14 +- mozilla/xpcom/tests/nsIFileTest.cpp | 39 +- mozilla/xpcom/threads/nsIProcess.idl | 3 + mozilla/xpcom/threads/nsProcess.h | 5 +- mozilla/xpcom/threads/nsProcessCommon.cpp | 10 +- mozilla/xpcom/tools/registry/regExport.cpp | 11 +- mozilla/xpcom/tools/registry/regxpcom.cpp | 19 +- .../appshell/src/nsCommandLineService.cpp | 3 +- mozilla/xpfe/bootstrap/nsAppRunner.cpp | 4 +- .../resources/content/contentAreaUtils.js | 2 +- .../bookmarks/resources/addBookmark.js | 2 +- .../bookmarks/src/nsBookmarksService.cpp | 24 +- .../bookmarks/src/nsBookmarksService.h | 1 + .../directory/nsDirectoryViewer.cpp | 8 +- .../src/nsDownloadManager.cpp | 50 +- .../download-manager/src/nsDownloadProxy.h | 6 +- .../filepicker/res/content/filepicker.js | 46 +- .../components/filepicker/src/nsFilePicker.js | 2 +- .../filepicker/src/nsFilePicker.js.in | 2 +- .../components/filepicker/src/nsFileView.cpp | 25 +- .../history/src/nsGlobalHistory.cpp | 12 +- .../content/pref-applications-new.js | 4 +- .../resources/content/pref-cache.js | 4 +- .../regviewer/nsIRegistryDataSource.idl | 4 +- .../regviewer/nsRegistryDataSource.cpp | 9 +- .../search/src/nsInternetSearchService.cpp | 108 ++- .../startup/src/nsCommandLineService.cpp | 3 +- .../ucth/resources/helperAppDldProgress.js | 4 +- .../ucth/resources/helperAppLauncher.js | 4 +- .../xfer/resources/downloadProgress.js | 2 +- .../components/xfer/src/nsStreamTransfer.cpp | 17 +- .../xpinstall/cleanup/InstallCleanupDefines.h | 23 +- mozilla/xpinstall/src/ScheduledTasks.cpp | 123 ++-- mozilla/xpinstall/src/nsInstall.cpp | 37 +- mozilla/xpinstall/src/nsInstallExecute.cpp | 6 +- mozilla/xpinstall/src/nsInstallFile.cpp | 23 +- mozilla/xpinstall/src/nsInstallFileOpItem.cpp | 181 +++-- mozilla/xpinstall/src/nsInstallFolder.cpp | 22 +- mozilla/xpinstall/src/nsInstallFolder.h | 12 +- mozilla/xpinstall/src/nsInstallPatch.cpp | 88 ++- mozilla/xpinstall/src/nsInstallUninstall.cpp | 3 +- mozilla/xpinstall/src/nsJSFile.cpp | 12 +- .../src/nsLoggingProgressNotifier.cpp | 20 +- mozilla/xpinstall/src/nsRegisterItem.cpp | 12 +- mozilla/xpinstall/src/nsSoftwareUpdate.cpp | 16 +- mozilla/xpinstall/src/nsSoftwareUpdateRun.cpp | 2 +- mozilla/xpinstall/src/nsXPInstallManager.cpp | 6 +- mozilla/xpinstall/stub/xpistub.cpp | 8 +- 210 files changed, 3081 insertions(+), 2903 deletions(-) diff --git a/mozilla/caps/src/nsScriptSecurityManager.cpp b/mozilla/caps/src/nsScriptSecurityManager.cpp index 06ebae53cc1..57b0f49ad2b 100644 --- a/mozilla/caps/src/nsScriptSecurityManager.cpp +++ b/mozilla/caps/src/nsScriptSecurityManager.cpp @@ -1869,10 +1869,10 @@ nsScriptSecurityManager::SetCanEnableCapability(const char* certificateID, if (NS_FAILED(rv)) return NS_ERROR_FAILURE; #ifdef XP_MAC // On Mac, this file will be located in the Essential Files folder - systemCertFile->Append("Essential Files"); + systemCertFile->Append(NS_LITERAL_CSTRING("Essential Files")); if (NS_FAILED(rv)) return NS_ERROR_FAILURE; #endif - systemCertFile->Append("systemSignature.jar"); + systemCertFile->Append(NS_LITERAL_CSTRING("systemSignature.jar")); if (NS_FAILED(rv)) return NS_ERROR_FAILURE; nsCOMPtr systemCertZip; rv = nsComponentManager::CreateInstance(kZipReaderCID, nsnull, diff --git a/mozilla/chrome/src/nsChromeRegistry.cpp b/mozilla/chrome/src/nsChromeRegistry.cpp index 156fecc6875..b04b801d84e 100644 --- a/mozilla/chrome/src/nsChromeRegistry.cpp +++ b/mozilla/chrome/src/nsChromeRegistry.cpp @@ -99,6 +99,7 @@ #include "prio.h" #include "nsInt64.h" #include "nsIDirectoryService.h" +#include "nsILocalFile.h" #include "nsAppDirectoryServiceDefs.h" #include "nsIPref.h" #include "nsIObserverService.h" @@ -109,10 +110,11 @@ #include "imgICache.h" static char kChromePrefix[] = "chrome://"; -static char kChromeFileName[] = "chrome.rdf"; -static char kInstalledChromeFileName[] = "installed-chrome.txt"; static char kUseXBLFormsPref[] = "nglayout.debug.enable_xbl_forms"; +#define kChromeFileName NS_LITERAL_CSTRING("chrome.rdf") +#define kInstalledChromeFileName NS_LITERAL_CSTRING("installed-chrome.txt") + static NS_DEFINE_CID(kWindowMediatorCID, NS_WINDOWMEDIATOR_CID); static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID); @@ -1800,9 +1802,8 @@ nsChromeRegistry::SetProviderForPackage(const nsACString& aProvider, // Figure out which file we're needing to modify, e.g., is it the install // dir or the profile dir, and get the right datasource. - nsDependentCString dataSourceStr(kChromeFileName); nsCOMPtr dataSource; - rv = LoadDataSource(dataSourceStr, getter_AddRefs(dataSource), aUseProfile, aProfilePath); + rv = LoadDataSource(kChromeFileName, getter_AddRefs(dataSource), aUseProfile, aProfilePath); if (NS_FAILED(rv)) return rv; rv = nsChromeRegistry::UpdateArc(dataSource, aPackageResource, aSelectionArc, aProviderPackageResource, !aIsAdding); @@ -2077,10 +2078,9 @@ nsChromeRegistry::IsProviderSetForPackage(const nsACString& aProvider, nsresult rv; // Figure out which file we're needing to modify, e.g., is it the install // dir or the profile dir, and get the right datasource. - nsDependentCString dataSourceStr(kChromeFileName); nsCOMPtr dataSource; - rv = LoadDataSource(dataSourceStr, getter_AddRefs(dataSource), aUseProfile, nsnull); + rv = LoadDataSource(kChromeFileName, getter_AddRefs(dataSource), aUseProfile, nsnull); if (NS_FAILED(rv)) return rv; nsCOMPtr retVal; @@ -2166,8 +2166,7 @@ NS_IMETHODIMP nsChromeRegistry::InstallProvider(const nsACString& aProviderType, // Load the install data source that we wish to manipulate. nsCOMPtr installSource; - nsDependentCString installStr(kChromeFileName); - rv = LoadDataSource(installStr, getter_AddRefs(installSource), aUseProfile, nsnull); + rv = LoadDataSource(kChromeFileName, getter_AddRefs(installSource), aUseProfile, nsnull); if (NS_FAILED(rv)) return rv; NS_ASSERTION(installSource, "failed to get installSource"); @@ -2533,8 +2532,7 @@ nsChromeRegistry::UninstallProvider(const nsACString& aProviderType, // Instantiate the data source we wish to modify. nsCOMPtr installSource; - nsDependentCString installStr(kChromeFileName); - rv = LoadDataSource(installStr, getter_AddRefs(installSource), aUseProfile, nsnull); + rv = LoadDataSource(kChromeFileName, getter_AddRefs(installSource), aUseProfile, nsnull); if (NS_FAILED(rv)) return rv; NS_ASSERTION(installSource, "failed to get installSource"); @@ -2605,15 +2603,15 @@ nsChromeRegistry::GetProfileRoot(nsCString& aFileURL) getter_AddRefs(defaultUserChromeFile)); if (NS_FAILED(rv)) return(rv); - defaultUserContentFile->Append("chrome"); - defaultUserContentFile->Append("userContent.css"); - defaultUserChromeFile->Append("chrome"); - defaultUserChromeFile->Append("userChrome.css"); + defaultUserContentFile->Append(NS_LITERAL_CSTRING("chrome")); + defaultUserContentFile->Append(NS_LITERAL_CSTRING("userContent.css")); + defaultUserChromeFile->Append(NS_LITERAL_CSTRING("chrome")); + defaultUserChromeFile->Append(NS_LITERAL_CSTRING("userChrome.css")); // copy along // It aint an error if these files dont exist - (void) defaultUserContentFile->CopyTo(userChromeDir, nsnull); - (void) defaultUserChromeFile->CopyTo(userChromeDir, nsnull); + (void) defaultUserContentFile->CopyTo(userChromeDir, nsCString()); + (void) defaultUserChromeFile->CopyTo(userChromeDir, nsCString()); } } if (NS_FAILED(rv)) @@ -2745,17 +2743,16 @@ nsChromeRegistry::AddToCompositeDataSource(PRBool aUseProfile) if (NS_FAILED(rv)) return rv; } - nsDependentCString name(kChromeFileName); if (aUseProfile) { // Profiles take precedence. Load them first. nsCOMPtr dataSource; - LoadDataSource(name, getter_AddRefs(dataSource), PR_TRUE, nsnull); + LoadDataSource(kChromeFileName, getter_AddRefs(dataSource), PR_TRUE, nsnull); mChromeDataSource->AddDataSource(dataSource); } // Always load the install dir datasources nsCOMPtr dataSource; - LoadDataSource(name, getter_AddRefs(dataSource), PR_FALSE, nsnull); + LoadDataSource(kChromeFileName, getter_AddRefs(dataSource), PR_FALSE, nsnull); mChromeDataSource->AddDataSource(dataSource); return NS_OK; @@ -3155,7 +3152,8 @@ nsChromeRegistry::ProcessNewChromeBuffer(char *aBuffer, PRInt32 aLength) nsCOMPtr chromeFile(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv)); if (NS_FAILED(rv)) return rv; - rv = chromeFile->InitWithPath(chromeLocation); + // assuming chromeLocation is given in the charset of the current locale + rv = chromeFile->InitWithNativePath(nsDependentCString(chromeLocation)); if (NS_FAILED(rv)) return rv; @@ -3218,9 +3216,8 @@ nsChromeRegistry::ProcessNewChromeBuffer(char *aBuffer, PRInt32 aLength) } mBatchInstallFlushes = PR_FALSE; - nsDependentCString dataSourceStr(kChromeFileName); nsCOMPtr dataSource; - LoadDataSource(dataSourceStr, getter_AddRefs(dataSource), PR_FALSE, nsnull); + LoadDataSource(kChromeFileName, getter_AddRefs(dataSource), PR_FALSE, nsnull); nsCOMPtr remote(do_QueryInterface(dataSource)); remote->Flush(); return NS_OK; diff --git a/mozilla/configure.in b/mozilla/configure.in index 7b687c39030..55dc10df6fe 100644 --- a/mozilla/configure.in +++ b/mozilla/configure.in @@ -1507,7 +1507,7 @@ dnl ======================================================== AC_CACHE_CHECK(for usable wchar_t (2 bytes, unsigned), ac_cv_have_usable_wchar, - [AC_TRY_RUN([#include + [AC_TRY_RUN([#include int main () { return (sizeof(wchar_t) != 2) || (wchar_t)-1 < (wchar_t) 0 ; } ], @@ -1531,7 +1531,7 @@ dnl Note that we assume that mac & win32 have short wchar (see nscore.h) AC_CACHE_CHECK(for compiler -fshort-wchar option, ac_cv_have_usable_wchar_option, - [AC_TRY_RUN([#include + [AC_TRY_RUN([#include int main () { return (sizeof(wchar_t) != 2) || (wchar_t)-1 < (wchar_t) 0 ; } ], @@ -1548,6 +1548,30 @@ dnl Note that we assume that mac & win32 have short wchar (see nscore.h) AC_LANG_RESTORE fi +dnl check for wcrtomb/mbrtowc +dnl ======================================================================= + +AC_LANG_CPLUSPLUS +AC_CACHE_CHECK(for wcrtomb, + ac_cv_have_wcrtomb, + [AC_TRY_LINK([#include ], + [mbstate_t ps={0};wcrtomb(0,'f',&ps);], + ac_cv_have_wcrtomb="yes", + ac_cv_have_wcrtomb="no")]) +if test "$ac_cv_have_wcrtomb" = "yes"; then + AC_DEFINE(HAVE_WCRTOMB) +fi +AC_CACHE_CHECK(for mbrtowc, + ac_cv_have_mbrtowc, + [AC_TRY_LINK([#include ], + [mbstate_t ps={0};mbrtowc(0,0,0,&ps);], + ac_cv_have_mbrtowc="yes", + ac_cv_have_mbrtowc="no")]) +if test "$ac_cv_have_mbrtowc" = "yes"; then + AC_DEFINE(HAVE_MBRTOWC) +fi +AC_LANG_C + dnl Checks for header files. dnl ======================================================== AC_HEADER_DIRENT diff --git a/mozilla/content/html/content/src/nsHTMLInputElement.cpp b/mozilla/content/html/content/src/nsHTMLInputElement.cpp index eec7fc80f62..09a0fa79247 100644 --- a/mozilla/content/html/content/src/nsHTMLInputElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLInputElement.cpp @@ -2182,19 +2182,18 @@ nsHTMLInputElement::SubmitNamesValues(nsIFormSubmission* aFormSubmission, &rv)); NS_ENSURE_SUCCESS(rv, rv); - rv = file->InitWithUnicodePath(value.get()); + rv = file->InitWithPath(NS_ConvertUCS2toUTF8(value)); if (NS_SUCCEEDED(rv)) { // // Get the leaf path name (to be submitted as the value) // - PRUnichar* leafNameChars = nsnull; - rv = file->GetUnicodeLeafName(&leafNameChars); + nsCAutoString leafNameChars; + rv = file->GetLeafName(leafNameChars); NS_ENSURE_SUCCESS(rv, rv); - if (leafNameChars) { - nsAutoString filename; - filename.Adopt(leafNameChars); + if (!leafNameChars.IsEmpty()) { + NS_ConvertUTF8toUCS2 filename(leafNameChars); PRBool acceptsFiles = PR_FALSE; aFormSubmission->AcceptsFiles(&acceptsFiles); diff --git a/mozilla/content/xul/document/src/nsXULDocument.cpp b/mozilla/content/xul/document/src/nsXULDocument.cpp index ba3aa871198..31afa66e41f 100644 --- a/mozilla/content/xul/document/src/nsXULDocument.cpp +++ b/mozilla/content/xul/document/src/nsXULDocument.cpp @@ -5069,8 +5069,8 @@ nsXULDocument::StartFastLoad() rv = NS_GetSpecialDirectory(NS_APP_CHROME_DIR, getter_AddRefs(chromeDir)); if (NS_FAILED(rv)) return rv; - nsXPIDLCString chromePath; - rv = chromeDir->GetPath(getter_Copies(chromePath)); + nsCAutoString chromePath; + rv = chromeDir->GetPath(chromePath); if (NS_FAILED(rv)) return rv; @@ -5145,7 +5145,7 @@ nsXULDocument::StartFastLoad() rv = objectInput->ReadStringZ( getter_Copies(fileChromePath)); if (NS_SUCCEEDED(rv) && - nsCRT::strcmp(fileChromePath, chromePath) != 0) { + !fileChromePath.Equals(chromePath)) { rv = NS_ERROR_UNEXPECTED; } } @@ -5165,7 +5165,7 @@ nsXULDocument::StartFastLoad() xio->mInputStream = nsnull; #ifdef DEBUG - file->MoveTo(nsnull, "Invalid.mfasl"); + file->MoveTo(nsnull, NS_LITERAL_CSTRING("Invalid.mfasl")); #else file->Remove(PR_FALSE); #endif @@ -5185,7 +5185,7 @@ nsXULDocument::StartFastLoad() if (NS_SUCCEEDED(rv)) { rv = objectOutput->Write32(XUL_FASTLOAD_FILE_VERSION); if (NS_SUCCEEDED(rv)) - rv = objectOutput->WriteStringZ(chromePath); + rv = objectOutput->WriteStringZ(chromePath.get()); } // Remove here even though some errors above will lead to a FastLoad @@ -5308,7 +5308,7 @@ nsXULDocument::AbortFastLoads() // Now rename or remove the file. if (file) { #ifdef DEBUG - file->MoveTo(nsnull, "Aborted.mfasl"); + file->MoveTo(nsnull, NS_LITERAL_CSTRING("Aborted.mfasl")); #else file->Remove(PR_FALSE); #endif diff --git a/mozilla/docshell/base/nsDefaultURIFixup.cpp b/mozilla/docshell/base/nsDefaultURIFixup.cpp index b5c9e26529c..dbea6c8e88f 100644 --- a/mozilla/docshell/base/nsDefaultURIFixup.cpp +++ b/mozilla/docshell/base/nsDefaultURIFixup.cpp @@ -25,7 +25,6 @@ #include "nsNetUtil.h" #include "nsEscape.h" -#include "nsICharsetConverterManager.h" #include "nsIPlatformCharset.h" #include "nsILocalFile.h" @@ -357,7 +356,7 @@ nsresult nsDefaultURIFixup::ConvertFileToStringURI(nsString& aIn, // platform. nsCOMPtr filePath; - nsCAutoString file; + nsresult rv; // this is not the real fix but a temporary fix // in order to really fix the problem, we need to change the @@ -380,14 +379,13 @@ nsresult nsDefaultURIFixup::ConvertFileToStringURI(nsString& aIn, // all the Unicode data come in is correctly converted. if (PossiblyByteExpandedFileName(aIn)) { // removes high byte - file.AssignWithConversion(aIn); + rv = NS_NewNativeLocalFile(NS_LossyConvertUCS2toASCII(aIn), PR_FALSE, getter_AddRefs(filePath)); } else { - // converts from Unicode to FS Charset - ConvertStringURIToFileCharset(aIn, file); + // input is unicode + rv = NS_NewLocalFile(NS_ConvertUCS2toUTF8(aIn), PR_FALSE, getter_AddRefs(filePath)); } - nsresult rv = NS_NewLocalFile(file.get(), PR_FALSE, getter_AddRefs(filePath)); if (NS_SUCCEEDED(rv)) { NS_GetURLSpecFromFile(filePath, aOut); @@ -449,37 +447,6 @@ const char * nsDefaultURIFixup::GetCharsetForUrlBar() return charset; } -nsresult nsDefaultURIFixup::ConvertStringURIToFileCharset(nsString& aIn, - nsCString& aOut) -{ - aOut = ""; - // We probably should cache ccm here. - // get a charset converter from the manager - nsCOMPtr ccm(do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID)); - NS_ENSURE_TRUE(ccm, NS_ERROR_FAILURE); - - // for file url, we need to convert the nsString to the file system - // charset before we pass to NS_NewURI - NS_ConvertASCIItoUCS2 fsCharset(GetFileSystemCharset()); - nsCOMPtr fsEncoder; - NS_ENSURE_SUCCESS(ccm->GetUnicodeEncoder(&fsCharset, - getter_AddRefs(fsEncoder)), NS_ERROR_FAILURE); - - PRInt32 bufLen = 0; - NS_ENSURE_SUCCESS(fsEncoder->GetMaxLength(aIn.get(), aIn.Length(), - &bufLen), NS_ERROR_FAILURE); - aOut.SetCapacity(bufLen+1); - PRInt32 srclen = aIn.Length(); - NS_ENSURE_SUCCESS(fsEncoder->Convert(aIn.get(), &srclen, - (char*)aOut.get(), &bufLen), NS_ERROR_FAILURE); - - ((char*)aOut.get())[bufLen]='\0'; - aOut.SetLength(bufLen); - - return NS_OK; -} - - nsresult nsDefaultURIFixup::KeywordURIFixup(const PRUnichar* aStringURI, nsIURI** aURI) { diff --git a/mozilla/docshell/base/nsDefaultURIFixup.h b/mozilla/docshell/base/nsDefaultURIFixup.h index c18097f2602..6d4cf6a9d36 100644 --- a/mozilla/docshell/base/nsDefaultURIFixup.h +++ b/mozilla/docshell/base/nsDefaultURIFixup.h @@ -46,7 +46,6 @@ private: /* additional members */ nsresult FileURIFixup(const PRUnichar* aStringURI, nsIURI** aURI); nsresult ConvertFileToStringURI(nsString& aIn, nsCString& aOut); - nsresult ConvertStringURIToFileCharset(nsString& aIn, nsCString& aOut); nsresult KeywordURIFixup(const PRUnichar* aStringURI, nsIURI** aURI); PRBool PossiblyByteExpandedFileName(nsString& aIn); PRBool MakeAlternateURI(nsIURI *aURI); diff --git a/mozilla/embedding/browser/activex/src/control/MozillaBrowser.cpp b/mozilla/embedding/browser/activex/src/control/MozillaBrowser.cpp index 97a56561add..58117342a34 100644 --- a/mozilla/embedding/browser/activex/src/control/MozillaBrowser.cpp +++ b/mozilla/embedding/browser/activex/src/control/MozillaBrowser.cpp @@ -667,10 +667,10 @@ LRESULT CMozillaBrowser::OnSaveAs(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL _makepath(szDataPath, drive, dir, szDataFile, ""); nsCOMPtr file; - NS_NewLocalFile(T2A(szFile), TRUE, getter_AddRefs(file)); + NS_NewNativeLocalFile(nsDependentCString(T2A(szFile)), TRUE, getter_AddRefs(file)); nsCOMPtr dataPath; - NS_NewLocalFile(szDataPath, TRUE, getter_AddRefs(dataPath)); + NS_NewNativeLocalFile(nsDependentCString(szDataPath), TRUE, getter_AddRefs(dataPath)); persist->SaveDocument(nsnull, file, dataPath, nsnull, 0, 0); } @@ -987,7 +987,7 @@ HRESULT CMozillaBrowser::Initialize() // Create an object to represent the path nsCOMPtr binDir; USES_CONVERSION; - NS_NewLocalFile(T2A(szBinDirPath), TRUE, getter_AddRefs(binDir)); + NS_NewNativeLocalFile(nsDependentCString(T2A(szBinDirPath)), TRUE, getter_AddRefs(binDir)); rv = NS_InitEmbedding(binDir, provider); // Load preferences service diff --git a/mozilla/embedding/browser/gtk/src/EmbedPrivate.cpp b/mozilla/embedding/browser/gtk/src/EmbedPrivate.cpp index 66b2b5f563a..081590d6377 100644 --- a/mozilla/embedding/browser/gtk/src/EmbedPrivate.cpp +++ b/mozilla/embedding/browser/gtk/src/EmbedPrivate.cpp @@ -353,7 +353,7 @@ EmbedPrivate::PushStartup(void) nsCOMPtr binDir; if (sCompPath) { - rv = NS_NewLocalFile(sCompPath, 1, getter_AddRefs(binDir)); + rv = NS_NewNativeLocalFile(nsDependentCString(sCompPath), 1, getter_AddRefs(binDir)); if (NS_FAILED(rv)) return; } @@ -788,7 +788,7 @@ EmbedPrivate::StartupProfile(void) PRBool exists = PR_FALSE; PRBool isDir = PR_FALSE; profileDir = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID); - rv = profileDir->InitWithPath(sProfileDir); + rv = profileDir->InitWithNativePath(nsDependentCString(sProfileDir)); if (NS_FAILED(rv)) return NS_ERROR_FAILURE; profileDir->Exists(&exists); diff --git a/mozilla/embedding/browser/powerplant/source/CAppFileLocationProvider.cpp b/mozilla/embedding/browser/powerplant/source/CAppFileLocationProvider.cpp index 76c9b6dd072..29d496658d8 100755 --- a/mozilla/embedding/browser/powerplant/source/CAppFileLocationProvider.cpp +++ b/mozilla/embedding/browser/powerplant/source/CAppFileLocationProvider.cpp @@ -37,7 +37,7 @@ #include "ApplIDs.h" -static char* GetResCString(PRInt32 stringIndex, Str255& buf); +static const nsACString &GetResCString(PRInt32 stringIndex, Str255& buf); //***************************************************************************** @@ -84,13 +84,13 @@ CAppFileLocationProvider::GetFile(const char *prop, PRBool *persistant, nsIFile { rv = GetProductDirectory(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->Append(GetResCString(str_AppRegistryName, strBuf)); + rv = localFile->AppendNative(GetResCString(str_AppRegistryName, strBuf)); } else if (nsCRT::strcmp(prop, NS_APP_DEFAULTS_50_DIR) == 0) { rv = CloneMozBinDirectory(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->AppendRelativePath(GetResCString(str_DefaultsDirName, strBuf)); + rv = localFile->AppendRelativeNativePath(GetResCString(str_DefaultsDirName, strBuf)); } else if (nsCRT::strcmp(prop, NS_APP_PREF_DEFAULTS_50_DIR) == 0) { @@ -211,7 +211,7 @@ NS_METHOD CAppFileLocationProvider::GetProductDirectory(nsILocalFile **aLocalFil rv = directoryService->Get(prop, NS_GET_IID(nsILocalFile), getter_AddRefs(localDir)); if (NS_FAILED(rv)) return rv; - rv = localDir->AppendRelativePath(mProductDirName); + rv = localDir->AppendRelativeNativePath(nsDependentCString(mProductDirName)); if (NS_FAILED(rv)) return rv; rv = localDir->Exists(&exists); if (NS_SUCCEEDED(rv) && !exists) @@ -259,12 +259,12 @@ NS_METHOD CAppFileLocationProvider::GetDefaultUserProfileRoot(nsILocalFile **aLo // Static Routines //**************************************************************************************** -static char* GetResCString(PRInt32 stringIndex, Str255& buf) +static const nsACString &GetResCString(PRInt32 stringIndex, Str255& buf) { GetIndString(buf, STRx_FileLocProviderStrings, stringIndex); if (!buf[0]) { NS_ASSERTION(PR_FALSE, "Directory name resource is missing."); - return nsnull; + return nsCString(); } // Because of different availability of Pascal to C conversion routines @@ -273,5 +273,5 @@ static char* GetResCString(PRInt32 stringIndex, Str255& buf) memmove(buf, buf + 1, len); buf[len] = '\0'; - return (char *)buf; + return nsDependentCString((char *)buf); } diff --git a/mozilla/embedding/browser/powerplant/source/CProfileManager.cpp b/mozilla/embedding/browser/powerplant/source/CProfileManager.cpp index 7038b640b2a..0c24466d892 100755 --- a/mozilla/embedding/browser/powerplant/source/CProfileManager.cpp +++ b/mozilla/embedding/browser/powerplant/source/CProfileManager.cpp @@ -415,16 +415,13 @@ nsresult CProfileManager::OpenAppRegistry(nsIRegistry **aRegistry) nsresult rv; nsCOMPtr regFile; - nsXPIDLCString regFilePath; rv = NS_GetSpecialDirectory(NS_APP_APPLICATION_REGISTRY_FILE, getter_AddRefs(regFile)); if (NS_FAILED(rv)) return rv; - rv = regFile->GetPath(getter_Copies(regFilePath)); - if (NS_FAILED(rv)) return rv; nsCOMPtr registry(do_CreateInstance(NS_REGISTRY_CONTRACTID, &rv)); if (NS_FAILED(rv)) return rv; - rv = registry->Open(regFilePath); + rv = registry->Open(regFile); if (NS_FAILED(rv)) return rv; *aRegistry = registry; diff --git a/mozilla/embedding/components/ui/helperAppDlg/nsHelperAppDlg.js b/mozilla/embedding/components/ui/helperAppDlg/nsHelperAppDlg.js index 44635dc2c16..8703812160e 100644 --- a/mozilla/embedding/components/ui/helperAppDlg/nsHelperAppDlg.js +++ b/mozilla/embedding/components/ui/helperAppDlg/nsHelperAppDlg.js @@ -302,7 +302,7 @@ nsHelperAppDialog.prototype = { var parentObject = fileObject.parent; if (parentObject) { - pathString = parentObject.unicodePath; + pathString = parentObject.path; } } } @@ -329,10 +329,10 @@ nsHelperAppDialog.prototype = { this.updateApplicationName(applicationDescription); this.givenDefaultApp = true; } - else if (this.chosenApp && this.chosenApp.unicodePath) + else if (this.chosenApp && this.chosenApp.path) { // If a user-chosen application, show its path. - this.updateApplicationName(this.chosenApp.unicodePath); + this.updateApplicationName(this.chosenApp.path); this.choseApp = true; } else @@ -401,7 +401,7 @@ nsHelperAppDialog.prototype = { { // only enable the OK button if we have a default app to use or if // the user chose an app.... - if ((this.choseApp && this.chosenApp.unicodePath) || this.givenDefaultApp) + if ((this.choseApp && this.chosenApp.path) || this.givenDefaultApp) ok = true; } @@ -475,7 +475,7 @@ nsHelperAppDialog.prototype = { this.chosenApp = fp.file; // Update dialog. - this.updateApplicationName(this.chosenApp.unicodePath); + this.updateApplicationName(this.chosenApp.path); } }, diff --git a/mozilla/embedding/components/ui/progressDlg/nsProgressDialog.js b/mozilla/embedding/components/ui/progressDlg/nsProgressDialog.js index 10c1c816762..65613ea8fe6 100644 --- a/mozilla/embedding/components/ui/progressDlg/nsProgressDialog.js +++ b/mozilla/embedding/components/ui/progressDlg/nsProgressDialog.js @@ -375,7 +375,7 @@ nsProgressDialog.prototype = { } } else { // Target is the destination file. - this.setValue( "target", this.target.unicodePath ); + this.setValue( "target", this.target.path ); } // Set source field. @@ -476,7 +476,7 @@ nsProgressDialog.prototype = { // Get filename from target file. fileName: function() { - return this.target ? this.target.unicodeLeafName : ""; + return this.target ? this.target.leafName : ""; }, // Set the dialog title. diff --git a/mozilla/embedding/components/ui/progressDlg/nsProgressDlg.js b/mozilla/embedding/components/ui/progressDlg/nsProgressDlg.js index d0261fe8d2e..e319b53b185 100644 --- a/mozilla/embedding/components/ui/progressDlg/nsProgressDlg.js +++ b/mozilla/embedding/components/ui/progressDlg/nsProgressDlg.js @@ -320,7 +320,7 @@ function loadDialog() dialog.timeLeft.setAttribute("value", formatSeconds( 0 )); dialog.location.setAttribute("value", sourceUrl.spec ); - dialog.fileName.setAttribute( "value", targetFile.unicodePath ); + dialog.fileName.setAttribute( "value", targetFile.path ); var prefs = Components.classes[prefContractID].getService(Components.interfaces.nsIPrefBranch); if (prefs) @@ -403,7 +403,7 @@ function onLoad() { const lfContractID = "@mozilla.org/file/local;1"; const lfIID = Components.interfaces.nsILocalFile; filesFolder = Components .classes[lfContractID].createInstance(lfIID); - filesFolder.initWithUnicodePath(persistArgs.target.unicodePath); + filesFolder.initWithPath(persistArgs.target.path); var nameWithoutExtension = filesFolder.leafName; nameWithoutExtension = nameWithoutExtension.substring(0, nameWithoutExtension.lastIndexOf(".")); diff --git a/mozilla/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp b/mozilla/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp index 3ac055c69b9..7f054f2a8c8 100644 --- a/mozilla/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp +++ b/mozilla/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp @@ -839,15 +839,15 @@ nsresult nsWebBrowserPersist::SendErrorStatusChange( nsAutoString path; if (file) { - nsXPIDLString filePath; - file->GetUnicodePath(getter_Copies(filePath)); - path = filePath; + nsCAutoString filePath; + file->GetPath(filePath); + path = NS_ConvertUTF8toUCS2(filePath); } else { nsCAutoString fileurl; aURI->GetSpec(fileurl); - path.Assign(NS_ConvertUTF8toUCS2(fileurl)); + path = NS_ConvertUTF8toUCS2(fileurl); } nsAutoString msgId; @@ -1263,13 +1263,13 @@ nsresult nsWebBrowserPersist::SaveDocumentInternal( break; } - nsXPIDLCString dirName; - dataDirParent->GetLeafName(getter_Copies(dirName)); + nsCAutoString dirName; + dataDirParent->GetNativeLeafName(dirName); nsCAutoString newRelativePathToData; - newRelativePathToData = dirName.get(); - newRelativePathToData.Append("/"); - newRelativePathToData.Append(relativePathToData); + newRelativePathToData = dirName + + NS_LITERAL_CSTRING("/") + + relativePathToData; relativePathToData = newRelativePathToData; nsCOMPtr newDataDirParent; @@ -1283,7 +1283,7 @@ nsresult nsWebBrowserPersist::SaveDocumentInternal( nsCOMPtr pathToBaseURL(do_QueryInterface(aFile)); if (pathToBaseURL) { - nsXPIDLCString relativePath; // nsACString + nsCAutoString relativePath; // nsACString if (NS_SUCCEEDED(pathToBaseURL->GetRelativeSpec(aDataPath, relativePath))) { mCurrentDataPathIsRelative = PR_TRUE; @@ -1532,7 +1532,7 @@ nsWebBrowserPersist::CalculateAndAppendFileExt(nsIURI *aURI, nsIChannel *aChanne if (localFile) { - localFile->SetLeafName(newFileName.get()); + localFile->SetNativeLeafName(newFileName); // Resync the URI with the file after the extension has been appended nsCOMPtr fileURL = do_QueryInterface(aURI, &rv); diff --git a/mozilla/embedding/tests/mfcembed/BrowserView.cpp b/mozilla/embedding/tests/mfcembed/BrowserView.cpp index f8899970d44..564c655a816 100644 --- a/mozilla/embedding/tests/mfcembed/BrowserView.cpp +++ b/mozilla/embedding/tests/mfcembed/BrowserView.cpp @@ -693,12 +693,12 @@ void CBrowserView::OnFileSaveAs() if(persist) { nsCOMPtr file; - NS_NewLocalFile(T2A(pStrFullPath), TRUE, getter_AddRefs(file)); + NS_NewNativeLocalFile(nsDependentCString(T2A(pStrFullPath)), TRUE, getter_AddRefs(file)); nsCOMPtr dataPath; if (pStrDataPath) { - NS_NewLocalFile(pStrDataPath, TRUE, getter_AddRefs(dataPath)); + NS_NewNativeLocalFile(nsDependentCString(pStrDataPath), TRUE, getter_AddRefs(dataPath)); } if(bSaveAll) @@ -839,7 +839,7 @@ void CBrowserView::OnSaveLinkAs() if(persist) { nsCOMPtr file; - NS_NewLocalFile(strFullPath.GetBuffer(0), TRUE, getter_AddRefs(file)); + NS_NewNativeLocalFile(nsDependentCString(strFullPath.GetBuffer(0)), TRUE, getter_AddRefs(file)); persist->SaveURI(linkURI, nsnull, file); } } @@ -885,7 +885,7 @@ void CBrowserView::OnSaveImageAs() if(persist) { nsCOMPtr file; - NS_NewLocalFile(strFullPath.GetBuffer(0), TRUE, getter_AddRefs(file)); + NS_NewNativeLocalFile(nsDependentCString(strFullPath.GetBuffer(0)), TRUE, getter_AddRefs(file)); persist->SaveURI(linkURI, nsnull, file); } } diff --git a/mozilla/embedding/tests/mfcembed/MostRecentUrls.cpp b/mozilla/embedding/tests/mfcembed/MostRecentUrls.cpp index 580f8424923..5652ea9b17b 100644 --- a/mozilla/embedding/tests/mfcembed/MostRecentUrls.cpp +++ b/mozilla/embedding/tests/mfcembed/MostRecentUrls.cpp @@ -83,7 +83,7 @@ FILE * CMostRecentUrls::GetFD(const char * aMode) nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(file)); if (NS_SUCCEEDED(rv)) { nsCOMPtr local_file(do_QueryInterface(file)); - local_file->Append("urls.txt"); + local_file->Append(NS_LITERAL_CSTRING("urls.txt")); local_file->OpenANSIFileDesc(aMode, &fd); } diff --git a/mozilla/embedding/tests/mfcembed/components/HelperAppDlg.cpp b/mozilla/embedding/tests/mfcembed/components/HelperAppDlg.cpp index 74b0a0badba..32d7f1be953 100644 --- a/mozilla/embedding/tests/mfcembed/components/HelperAppDlg.cpp +++ b/mozilla/embedding/tests/mfcembed/components/HelperAppDlg.cpp @@ -250,7 +250,7 @@ NS_IMETHODIMP CHelperAppLauncherDialog::Show(nsIHelperAppLauncher *aLauncher, m_FileName = dlg.m_OpenWithAppName; nsCOMPtr openWith; - nsresult rv = NS_NewLocalFile(m_FileName, PR_FALSE, getter_AddRefs(openWith)); + nsresult rv = NS_NewNativeLocalFile(nsDependentCString(m_FileName), PR_FALSE, getter_AddRefs(openWith)); if (NS_FAILED(rv)) return aLauncher->LaunchWithApplication(nsnull, PR_FALSE); else @@ -279,7 +279,7 @@ NS_IMETHODIMP CHelperAppLauncherDialog::PromptForSaveToFile(nsISupports *aWindow { m_FileName = cf.GetPathName(); // Will be like: c:\tmp\junk.exe - return NS_NewLocalFile(m_FileName, PR_FALSE, _retval); + return NS_NewNativeLocalFile(nsDependentCString(m_FileName), PR_FALSE, _retval); } else return NS_ERROR_FAILURE; diff --git a/mozilla/embedding/tests/mfcembed/winEmbedFileLocProvider.cpp b/mozilla/embedding/tests/mfcembed/winEmbedFileLocProvider.cpp index 96c4d472829..62651deb427 100644 --- a/mozilla/embedding/tests/mfcembed/winEmbedFileLocProvider.cpp +++ b/mozilla/embedding/tests/mfcembed/winEmbedFileLocProvider.cpp @@ -36,16 +36,16 @@ // WARNING: These hard coded names need to go away. They need to // come from localizable resources -#define APP_REGISTRY_NAME "registry.dat" +#define APP_REGISTRY_NAME NS_LITERAL_CSTRING("registry.dat") -#define PROFILE_ROOT_DIR_NAME "Profiles" -#define DEFAULTS_DIR_NAME "defaults" -#define DEFAULTS_PREF_DIR_NAME "pref" -#define DEFAULTS_PROFILE_DIR_NAME "profile" -#define RES_DIR_NAME "res" -#define CHROME_DIR_NAME "chrome" -#define PLUGINS_DIR_NAME "plugins" -#define SEARCH_DIR_NAME "searchplugins" +#define PROFILE_ROOT_DIR_NAME NS_LITERAL_CSTRING("Profiles") +#define DEFAULTS_DIR_NAME NS_LITERAL_CSTRING("defaults") +#define DEFAULTS_PREF_DIR_NAME NS_LITERAL_CSTRING("pref") +#define DEFAULTS_PROFILE_DIR_NAME NS_LITERAL_CSTRING("profile") +#define RES_DIR_NAME NS_LITERAL_CSTRING("res") +#define CHROME_DIR_NAME NS_LITERAL_CSTRING("chrome") +#define PLUGINS_DIR_NAME NS_LITERAL_CSTRING("plugins") +#define SEARCH_DIR_NAME NS_LITERAL_CSTRING("searchplugins") //***************************************************************************** @@ -221,7 +221,7 @@ NS_METHOD winEmbedFileLocProvider::GetProductDirectory(nsILocalFile **aLocalFile } if (NS_FAILED(rv)) return rv; - rv = localDir->AppendRelativePath(mProductDirName); + rv = localDir->AppendRelativeNativePath(nsDependentCString(mProductDirName)); if (NS_FAILED(rv)) return rv; rv = localDir->Exists(&exists); if (NS_SUCCEEDED(rv) && !exists) diff --git a/mozilla/embedding/tests/winEmbed/winEmbed.cpp b/mozilla/embedding/tests/winEmbed/winEmbed.cpp index 8a807fddb11..1d79727bebe 100644 --- a/mozilla/embedding/tests/winEmbed/winEmbed.cpp +++ b/mozilla/embedding/tests/winEmbed/winEmbed.cpp @@ -427,12 +427,12 @@ void SaveWebPage(nsIWebBrowser *aWebBrowser) nsCOMPtr persist(do_QueryInterface(aWebBrowser)); nsCOMPtr file; - NS_NewLocalFile(szFile, TRUE, getter_AddRefs(file)); + NS_NewNativeLocalFile(nsDependentCString(szFile), TRUE, getter_AddRefs(file)); nsCOMPtr dataPath; if (pszDataPath) { - NS_NewLocalFile(pszDataPath, TRUE, getter_AddRefs(dataPath)); + NS_NewNativeLocalFile(nsDependentCString(pszDataPath), TRUE, getter_AddRefs(dataPath)); } persist->SaveDocument(nsnull, file, dataPath, nsnull, 0, 0); diff --git a/mozilla/extensions/cookie/nsCookies.cpp b/mozilla/extensions/cookie/nsCookies.cpp index ff116408266..358bcc3ac17 100644 --- a/mozilla/extensions/cookie/nsCookies.cpp +++ b/mozilla/extensions/cookie/nsCookies.cpp @@ -212,7 +212,7 @@ COOKIE_DeletePersistentUserData(void) nsCOMPtr cookiesFile; res = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(cookiesFile)); if (NS_SUCCEEDED(res)) { - res = cookiesFile->Append(kCookiesFileName); + res = cookiesFile->AppendNative(nsDependentCString(kCookiesFileName)); if (NS_SUCCEEDED(res)) (void) cookiesFile->Remove(PR_FALSE); } diff --git a/mozilla/extensions/cookie/nsPermissions.cpp b/mozilla/extensions/cookie/nsPermissions.cpp index 66e3c7a2529..e315323c4c6 100644 --- a/mozilla/extensions/cookie/nsPermissions.cpp +++ b/mozilla/extensions/cookie/nsPermissions.cpp @@ -684,7 +684,7 @@ PERMISSION_DeletePersistentUserData(void) nsCOMPtr cookiesPermFile; res = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(cookiesPermFile)); if (NS_SUCCEEDED(res)) { - res = cookiesPermFile->Append(kCookiesPermFileName); + res = cookiesPermFile->AppendNative(nsDependentCString(kCookiesPermFileName)); if (NS_SUCCEEDED(res)) (void) cookiesPermFile->Remove(PR_FALSE); } diff --git a/mozilla/extensions/cookie/nsUtils.cpp b/mozilla/extensions/cookie/nsUtils.cpp index 68a3b5c5e90..3dbeb28e3d0 100644 --- a/mozilla/extensions/cookie/nsUtils.cpp +++ b/mozilla/extensions/cookie/nsUtils.cpp @@ -41,6 +41,7 @@ #include "nsIStringBundle.h" #include "nsIPref.h" #include "nsIFileSpec.h" +#include "nsILocalFile.h" #include "nsAppDirectoryServiceDefs.h" #include "prmem.h" @@ -128,11 +129,7 @@ CKutil_ProfileDirectory(nsFileSpec& dirSpec) { // TODO: When the calling code can take an nsIFile, // this conversion to nsFileSpec can be avoided. - nsXPIDLCString pathBuf; - aFile->GetPath(getter_Copies(pathBuf)); - res = NS_NewFileSpec(getter_AddRefs(tempSpec)); - if (NS_FAILED(res)) return res; - res = tempSpec->SetNativePath(pathBuf); + res = NS_NewFileSpecFromIFile(aFile, getter_AddRefs(tempSpec)); if (NS_FAILED(res)) return res; res = tempSpec->GetFileSpec(&dirSpec); diff --git a/mozilla/extensions/inspector/base/src/inFileSearch.cpp b/mozilla/extensions/inspector/base/src/inFileSearch.cpp index d723058ed60..df911785420 100644 --- a/mozilla/extensions/inspector/base/src/inFileSearch.cpp +++ b/mozilla/extensions/inspector/base/src/inFileSearch.cpp @@ -171,9 +171,9 @@ inFileSearch::GetStringResultAt(PRInt32 aIndex, nsAString& _retval) } if (file) { - nsXPIDLCString temp; - mLastResult->GetPath(getter_Copies(temp)); - _retval = NS_ConvertASCIItoUCS2(temp); + nsCAutoString temp; + mLastResult->GetPath(temp); + _retval = NS_ConvertUTF8toUCS2(temp); if (mReturnRelativePaths) MakePathRelative(_retval); } else { @@ -543,11 +543,10 @@ inFileSearch::GetNextDirectory(nsISimpleEnumerator* aEnum) PRBool inFileSearch::MatchFile(nsIFile* aFile) { - char* fileName; - aFile->GetLeafName(&fileName); + nsCAutoString fileName; + aFile->GetLeafName(fileName); - nsAutoString temp; - temp.AssignWithConversion(fileName); + NS_ConvertUTF8toUCS2 temp(fileName); PRUnichar* fileNameUnicode = ToNewUnicode(temp); @@ -558,6 +557,7 @@ inFileSearch::MatchFile(nsIFile* aFile) if (match) return PR_TRUE; } + // XXX are we leaking fileNameUnicode? return PR_FALSE; } @@ -610,10 +610,9 @@ inFileSearch::MakePathRelative(nsAString& aPath) { // get an nsAutoString version of the search path - char* temp; - mSearchPath->GetPath(&temp); - nsAutoString searchPath; - searchPath.AssignWithConversion(temp); + nsCAutoString temp; + mSearchPath->GetPath(temp); + NS_ConvertUTF8toUCS2 searchPath(temp); nsAutoString result; PRUint32 len = searchPath.Length(); diff --git a/mozilla/extensions/inspector/resources/content/viewers/boxModel/boxModel.js b/mozilla/extensions/inspector/resources/content/viewers/boxModel/boxModel.js index 6b33b030789..ec5f055ba66 100644 --- a/mozilla/extensions/inspector/resources/content/viewers/boxModel/boxModel.js +++ b/mozilla/extensions/inspector/resources/content/viewers/boxModel/boxModel.js @@ -512,7 +512,7 @@ BoxModelViewer.prototype = var encoder = XPCU.createInstance("@mozilla.org/inspector/png-encoder;1", "inIPNGEncoder"); var path = FilePickerUtils.pickFile("Save Image as PNG", "", ["filterAll"], "Save"); if (path) - encoder.writePNG(this.mBitmap, path.unicodePath, 24); + encoder.writePNG(this.mBitmap, path.path, 24); }, //////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/extensions/pref/autoconfig/src/nsAutoConfig.cpp b/mozilla/extensions/pref/autoconfig/src/nsAutoConfig.cpp index 830c52cfb6a..6b500ec35b0 100644 --- a/mozilla/extensions/pref/autoconfig/src/nsAutoConfig.cpp +++ b/mozilla/extensions/pref/autoconfig/src/nsAutoConfig.cpp @@ -445,7 +445,7 @@ nsresult nsAutoConfig::readOfflineFile() if (NS_FAILED(rv)) return rv; - failoverFile->Append("failover.jsc"); + failoverFile->Append(NS_LITERAL_CSTRING("failover.jsc")); rv = evaluateLocalFile(failoverFile); if (NS_FAILED(rv)) NS_WARNING("Couldn't open failover.jsc, going back to default prefs"); @@ -491,7 +491,7 @@ nsresult nsAutoConfig::writeFailoverFile() if (NS_FAILED(rv)) return rv; - failoverFile->Append("failover.jsc"); + failoverFile->Append(NS_LITERAL_CSTRING("failover.jsc")); rv = NS_NewLocalFileOutputStream(getter_AddRefs(outStr), failoverFile); if (NS_FAILED(rv)) diff --git a/mozilla/extensions/pref/autoconfig/src/nsReadConfig.cpp b/mozilla/extensions/pref/autoconfig/src/nsReadConfig.cpp index 82d2c915cbc..0d5ce16bd68 100644 --- a/mozilla/extensions/pref/autoconfig/src/nsReadConfig.cpp +++ b/mozilla/extensions/pref/autoconfig/src/nsReadConfig.cpp @@ -221,18 +221,18 @@ nsresult nsReadConfig::openAndEvaluateJSFile(const char *aFileName, return rv; #ifdef XP_MAC - jsFile->Append("Essential Files"); + jsFile->Append(NS_LITERAL_CSTRING("Essential Files")); #endif } else { rv = NS_GetSpecialDirectory(NS_APP_DEFAULTS_50_DIR, getter_AddRefs(jsFile)); if (NS_FAILED(rv)) return rv; - rv = jsFile->Append("autoconfig"); + rv = jsFile->Append(NS_LITERAL_CSTRING("autoconfig")); if (NS_FAILED(rv)) return rv; } - rv = jsFile->Append(aFileName); + rv = jsFile->Append(nsDependentCString(aFileName)); if (NS_FAILED(rv)) return rv; @@ -259,9 +259,9 @@ nsresult nsReadConfig::openAndEvaluateJSFile(const char *aFileName, for (PRUint32 i = 0; i < amt; i++) buf[i] -= obscure_value; } - nsXPIDLCString path; + nsCAutoString path; - jsFile->GetPath(getter_Copies(path)); + jsFile->GetNativePath(path); nsCAutoString fileURL; fileURL = NS_LITERAL_CSTRING("file:///") + path; rv = EvaluateAdminConfigScript(buf, amt, fileURL.get(), diff --git a/mozilla/extensions/venkman/resources/content/file-utils.js b/mozilla/extensions/venkman/resources/content/file-utils.js index fd5ebfdd9a2..3c03c43c328 100644 --- a/mozilla/extensions/venkman/resources/content/file-utils.js +++ b/mozilla/extensions/venkman/resources/content/file-utils.js @@ -105,7 +105,7 @@ function futils_nosepicker(initialPath, typeList, attribs) { localFile = classes[LOCALFILE_CTRID].createInstance(nsILocalFile); - localFile.initWithUnicodePath(initialPath); + localFile.initWithPath(initialPath); } else { @@ -224,7 +224,7 @@ function LocalFile(file, mode, perms, tmp) if (typeof file == "string") { this.localFile = classes[LOCALFILE_CTRID].createInstance(nsILocalFile); - this.localFile.initWithUnicodePath(file); + this.localFile.initWithPath(file); } else if (file instanceof nsILocalFile) { diff --git a/mozilla/extensions/venkman/resources/content/venkman-utils.js b/mozilla/extensions/venkman/resources/content/venkman-utils.js index 06d4d3900a9..efc1f1a999b 100644 --- a/mozilla/extensions/venkman/resources/content/venkman-utils.js +++ b/mozilla/extensions/venkman/resources/content/venkman-utils.js @@ -345,7 +345,7 @@ function getURLSpecFromFile (file) { var fileObj = Components.classes[LOCALFILE_CTRID].createInstance(nsILocalFile); - fileObj.initWithUnicodePath(file); + fileObj.initWithPath(file); file = fileObj; } diff --git a/mozilla/extensions/wallet/src/wallet.cpp b/mozilla/extensions/wallet/src/wallet.cpp index 9f0cdd5c654..7bd24dab8b5 100644 --- a/mozilla/extensions/wallet/src/wallet.cpp +++ b/mozilla/extensions/wallet/src/wallet.cpp @@ -49,6 +49,7 @@ #include "nsNetUtil.h" #include "nsReadableUtils.h" #include "nsUnicharUtils.h" +#include "nsILocalFile.h" #include "nsIServiceManager.h" #include "nsIDocument.h" @@ -1280,20 +1281,18 @@ PUBLIC nsresult Wallet_ProfileDirectory(nsFileSpec& dirSpec) { nsresult res; nsCOMPtr aFile; - nsXPIDLCString pathBuf; + nsCAutoString pathBuf; nsCOMPtr tempSpec; res = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(aFile)); if (NS_FAILED(res)) return res; - res = aFile->GetPath(getter_Copies(pathBuf)); + + res = NS_NewFileSpecFromIFile(aFile, getter_AddRefs(tempSpec)); if (NS_FAILED(res)) return res; // TODO: Change the function to return an nsIFile // and not do this conversion - res = NS_NewFileSpec(getter_AddRefs(tempSpec)); - if (NS_FAILED(res)) return res; - res = tempSpec->SetNativePath(pathBuf); - if (NS_FAILED(res)) return res; + res = tempSpec->GetFileSpec(&dirSpec); return res; @@ -1303,22 +1302,20 @@ PUBLIC nsresult Wallet_DefaultsDirectory(nsFileSpec& dirSpec) { nsresult res; nsCOMPtr aFile; - nsXPIDLCString pathBuf; + nsCAutoString pathBuf; nsCOMPtr tempSpec; res = NS_GetSpecialDirectory(NS_APP_DEFAULTS_50_DIR, getter_AddRefs(aFile)); if (NS_FAILED(res)) return res; - res = aFile->Append("wallet"); + res = aFile->Append(NS_LITERAL_CSTRING("wallet")); if (NS_FAILED(res)) return res; - res = aFile->GetPath(getter_Copies(pathBuf)); + + res = NS_NewFileSpecFromIFile(aFile, getter_AddRefs(tempSpec)); if (NS_FAILED(res)) return res; // TODO: Change the function to return an nsIFile // and not do this conversion - res = NS_NewFileSpec(getter_AddRefs(tempSpec)); - if (NS_FAILED(res)) return res; - res = tempSpec->SetNativePath(pathBuf); - if (NS_FAILED(res)) return res; + res = tempSpec->GetFileSpec(&dirSpec); return res; diff --git a/mozilla/extensions/xmlterm/base/mozXMLTermSession.cpp b/mozilla/extensions/xmlterm/base/mozXMLTermSession.cpp index be919b57af4..c7e49b5b932 100644 --- a/mozilla/extensions/xmlterm/base/mozXMLTermSession.cpp +++ b/mozilla/extensions/xmlterm/base/mozXMLTermSession.cpp @@ -1208,7 +1208,7 @@ NS_IMETHODIMP mozXMLTermSession::ExportHTML(const PRUnichar* aFilename, XMLT_LOG(mozXMLTermSession::ExportHTML,0, ("Exporting %d\n", mCountExportHTML)); - result = localFile->InitWithUnicodePath(filename.get()); + result = localFile->InitWithPath(NS_ConvertUCS2toUTF8(filename)); if (NS_FAILED(result)) return NS_ERROR_FAILURE; diff --git a/mozilla/gfx/public/nsNameValuePairDB.h b/mozilla/gfx/public/nsNameValuePairDB.h index d159b18f8eb..e01e10c0edd 100644 --- a/mozilla/gfx/public/nsNameValuePairDB.h +++ b/mozilla/gfx/public/nsNameValuePairDB.h @@ -70,8 +70,8 @@ public: PRInt32 GetNextElement(const char** aName, const char** aValue); PRInt32 GetNextElement(const char** aName, const char** aValue, char *aBuffer, PRUint32 aBufferLen); - PRBool OpenForRead(const nsACString& aCatalogName); - PRBool OpenTmpForWrite(const nsACString& aCatalogName); + PRBool OpenForRead(const nsACString& aCatalogName); // native charset + PRBool OpenTmpForWrite(const nsACString& aCatalogName); // native charset PRBool PutElement(const char* aName, const char* aValue); PRBool PutEndGroup(const char* aType); PRBool PutStartGroup(const char* aType); diff --git a/mozilla/gfx/src/freetype/nsFT2FontCatalog.cpp b/mozilla/gfx/src/freetype/nsFT2FontCatalog.cpp index 4f8ac2ef8d5..23bff51dc8b 100644 --- a/mozilla/gfx/src/freetype/nsFT2FontCatalog.cpp +++ b/mozilla/gfx/src/freetype/nsFT2FontCatalog.cpp @@ -677,6 +677,7 @@ nsFT2FontCatalog::doGetDirsPrefEnumCallback(const char* aName, void* aClosure) dce = (nsDirCatalogEntry *)calloc(1, sizeof(nsDirCatalogEntry)); if (!dce) return; + // native charset?! mPref->CopyCharPref(aName, (char **)&dce->mDirName); if (!dce->mDirName) return; @@ -713,21 +714,20 @@ nsFT2FontCatalog::GetFontCatalog(FT_Library lib, nsFontCatalog *aFontCatalog, { int i; nsresult rv; - nsXPIDLCString font_summaries_dir_path; - nsXPIDLCString font_download_dir_path; + nsCAutoString font_summaries_dir_path; + nsCAutoString font_download_dir_path; PRBool exists; - nsCOMPtr font_download_dir; + nsCOMPtr font_summaries_dir, font_download_dir; if (lib) { // // Get the dir for downloaded fonts // - rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILES_ROOT_DIR, - getter_AddRefs(font_download_dir)); + rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILES_ROOT_DIR, getter_AddRefs(font_download_dir)); if (NS_FAILED(rv)) goto cleanup_and_return; - rv = font_download_dir->Append(FONT_DOWNLOAD_SUBDIR); + rv = font_download_dir->AppendNative(FONT_DOWNLOAD_SUBDIR); if (NS_FAILED(rv)) goto cleanup_and_return; exists = PR_FALSE; @@ -740,23 +740,21 @@ nsFT2FontCatalog::GetFontCatalog(FT_Library lib, nsFontCatalog *aFontCatalog, if (NS_FAILED(rv)) goto cleanup_and_return; } - rv = font_download_dir->GetPath(getter_Copies(font_download_dir_path)); + rv = font_download_dir->GetNativePath(font_download_dir_path); if (NS_FAILED(rv)) goto cleanup_and_return; // // Get the user dir for font catalogs // - nsCOMPtr font_summaries_dir; - rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILES_ROOT_DIR, - getter_AddRefs(font_summaries_dir)); + rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILES_ROOT_DIR, getter_AddRefs(font_summaries_dir)); if (NS_FAILED(rv)) goto cleanup_and_return; - rv = font_summaries_dir->Append(FONT_DOWNLOAD_SUBDIR); + rv = font_summaries_dir->AppendNative(FONT_DOWNLOAD_SUBDIR); if (NS_FAILED(rv)) goto cleanup_and_return; - rv = font_summaries_dir->Append(FONT_SUMMARIES_SUBDIR); + rv = font_summaries_dir->AppendNative(FONT_SUMMARIES_SUBDIR); if (NS_FAILED(rv)) goto cleanup_and_return; exists = PR_FALSE; @@ -769,24 +767,22 @@ nsFT2FontCatalog::GetFontCatalog(FT_Library lib, nsFontCatalog *aFontCatalog, if (NS_FAILED(rv)) goto cleanup_and_return; } - rv = font_summaries_dir->GetPath(getter_Copies(font_summaries_dir_path)); + rv = font_summaries_dir->GetNativePath(font_summaries_dir_path); if (NS_FAILED(rv)) goto cleanup_and_return; // // Get the font summaries for the public font dirs // - nsCAutoString fs_dir(font_summaries_dir_path); for (i=0; inumDirs; i++) { - nsCAutoString dir_name(aOldDirCatalog->dirs[i]->mDirName); - HandleFontDir(lib, aFontCatalog, fs_dir, dir_name); + HandleFontDir(lib, aFontCatalog, font_summaries_dir_path, + nsDependentCString(aOldDirCatalog->dirs[i]->mDirName)); } // // Get the font summaries for the downloaded/private font dir // - nsCAutoString fdown_dir(font_download_dir_path); - HandleFontDir(lib, aFontCatalog, fs_dir, fdown_dir); + HandleFontDir(lib, aFontCatalog, font_summaries_dir_path, font_download_dir_path); } return 0; @@ -887,8 +883,8 @@ cleanup_and_return: } PRBool -nsFT2FontCatalog::GetFontSummaryName(const nsACString &aFontDirName, - const nsACString &aFontSummariesDir, +nsFT2FontCatalog::GetFontSummaryName(const nsACString &aFontDirName, // native charset + const nsACString &aFontSummariesDir, // native charset nsACString &aFontSummaryFileName, nsACString &aFallbackFontSummaryFileName) @@ -906,16 +902,16 @@ nsFT2FontCatalog::GetFontSummaryName(const nsACString &aFontDirName, // or the "private" one in our $HOME/.mozilla/fontsummaries dir // font_dir = new nsLocalFile(); - font_dir->InitWithPath(PromiseFlatCString(aFontDirName).get()); + font_dir->InitWithNativePath(aFontDirName); rv = font_dir->IsWritable(&public_dir_writable); if (NS_SUCCEEDED(rv) && public_dir_writable) { FONT_CATALOG_PRINTF(("can write \"%s\"", PromiseFlatCString(aFontDirName).get())); nsCOMPtr summary_file = new nsLocalFile(); - summary_file->InitWithPath(PromiseFlatCString(aFontDirName).get()); - summary_file->Append(PUBLIC_FONT_SUMMARY_NAME); - char *font_summary_path; - summary_file->GetPath(&font_summary_path); - FONT_CATALOG_PRINTF(("font_summary_path = \"%s\"", font_summary_path)); + summary_file->InitWithNativePath(aFontDirName); + summary_file->AppendNative(PUBLIC_FONT_SUMMARY_NAME); + nsCAutoString font_summary_path; + summary_file->GetNativePath(font_summary_path); + FONT_CATALOG_PRINTF(("font_summary_path = \"%s\"", font_summary_path.get())); rv = summary_file->Exists(&exists); if (NS_SUCCEEDED(rv)) { if (!exists) { @@ -923,11 +919,11 @@ nsFT2FontCatalog::GetFontSummaryName(const nsACString &aFontDirName, aFontSummaryFileName = font_summary_path; } else { - FONT_CATALOG_PRINTF(("font summary \"%s\" exists", font_summary_path)); + FONT_CATALOG_PRINTF(("font summary \"%s\" exists", font_summary_path.get())); rv = summary_file->IsWritable(&public_summary_writable); if (NS_SUCCEEDED(rv) && public_summary_writable) { FONT_CATALOG_PRINTF(("font summary \"%s\" is writable", - font_summary_path)); + font_summary_path.get())); public_summary_writable = PR_TRUE; aFontSummaryFileName = font_summary_path; } @@ -1054,12 +1050,12 @@ nsFT2FontCatalog::GetRange2CharSetName(unsigned long aBit) PRBool nsFT2FontCatalog::HandleFontDir(FT_Library aFreeTypeLibrary, nsFontCatalog *aFontCatalog, - const nsACString &aFontSummariesDir, - const nsACString &aFontDirName) + const nsACString &aFontSummariesDir, // native charset + const nsACString &aFontDirName) // native charset { int i, status = -1; PRBool rslt, current; - char *fileName; + nsCAutoString fileName; nsHashtable* fontFileNamesHash = nsnull; nsHashtable* fallbackFceHash = nsnull; nsresult rv; @@ -1068,7 +1064,7 @@ nsFT2FontCatalog::HandleFontDir(FT_Library aFreeTypeLibrary, PRBool moreFilesInDir = PR_FALSE; nsCOMPtr dir; nsCOMPtr dirLocal; - nsCOMPtr dirEntry; + nsCOMPtr dirEntry; nsCOMPtr dirIterator; PRBool summary_needs_update = PR_FALSE; nsFontCatalogEntry *fce; @@ -1115,7 +1111,7 @@ nsFT2FontCatalog::HandleFontDir(FT_Library aFreeTypeLibrary, // dir = new nsLocalFile(); dirLocal = do_QueryInterface(dir); - dirLocal->InitWithPath(PromiseFlatCString(aFontDirName).get()); + dirLocal->InitWithNativePath(aFontDirName); rv = dir->GetDirectoryEntries(getter_AddRefs(dirIterator)); if (NS_FAILED(rv)) { FONT_CATALOG_PRINTF(("failed to open dir (get iterator) for %s", @@ -1141,20 +1137,19 @@ nsFT2FontCatalog::HandleFontDir(FT_Library aFreeTypeLibrary, goto cleanup_and_return; } //char *path; - dirEntry->GetPath(&fileName); - FONT_CATALOG_PRINTF(("dirEntry = \"%s\"", fileName)); + dirEntry->GetNativePath(fileName); + FONT_CATALOG_PRINTF(("dirEntry = \"%s\"", fileName.get())); rv = dirEntry->IsFile(&isFile); if (NS_SUCCEEDED(rv) && isFile) { PRInt64 modtime; dirEntry->GetLastModifiedTime(&modtime); - current = AddFceIfCurrent(fileName, fontFileNamesHash, + current = AddFceIfCurrent(fileName.get(), fontFileNamesHash, modtime, dirFontCatalog); if (!current) { // Ignore the font summary itself - nsDependentCString name(fileName); - if (name.Equals(fontSummaryFilename) || - name.Equals(fallbackFontSummaryFilename)) { - FONT_CATALOG_PRINTF(("font summary %s is not a font", fileName)); + if (fileName.Equals(fontSummaryFilename) || + fileName.Equals(fallbackFontSummaryFilename)) { + FONT_CATALOG_PRINTF(("font summary %s is not a font", fileName.get())); current = PR_TRUE; } // If not in font summary, try the fallback summary @@ -1168,7 +1163,7 @@ nsFT2FontCatalog::HandleFontDir(FT_Library aFreeTypeLibrary, } if (fallbackFceHash) { summary_needs_update = PR_TRUE; - current = AddFceIfCurrent(fileName, fallbackFceHash, + current = AddFceIfCurrent(fileName.get(), fallbackFceHash, modtime, dirFontCatalog); } } @@ -1180,7 +1175,7 @@ nsFT2FontCatalog::HandleFontDir(FT_Library aFreeTypeLibrary, if (!current) { summary_needs_update = PR_TRUE; HandleFontFile(aFreeTypeLibrary, dirFontCatalog, - fileName); + fileName.get()); } } } diff --git a/mozilla/gfx/src/freetype/nsFT2FontCatalog.h b/mozilla/gfx/src/freetype/nsFT2FontCatalog.h index fcbaeda29b9..a952c618791 100644 --- a/mozilla/gfx/src/freetype/nsFT2FontCatalog.h +++ b/mozilla/gfx/src/freetype/nsFT2FontCatalog.h @@ -64,10 +64,10 @@ typedef unsigned short FT_UShort; class nsFontNodeArray; -#define PUBLIC_FONT_SUMMARY_NAME ".mozilla_font_summary.ndb" -#define FONT_SUMMARIES_SUBDIR "catalog" -#define FONT_DOWNLOAD_SUBDIR "fonts" -#define FONT_SUMMARIES_EXTENSION ".ndb" +#define PUBLIC_FONT_SUMMARY_NAME NS_LITERAL_CSTRING(".mozilla_font_summary.ndb") +#define FONT_SUMMARIES_SUBDIR NS_LITERAL_CSTRING("catalog") +#define FONT_DOWNLOAD_SUBDIR NS_LITERAL_CSTRING("fonts") +#define FONT_SUMMARIES_EXTENSION NS_LITERAL_CSTRING(".ndb") #define FONT_SUMMARY_VERSION_TAG "FontSummaryVersion" #define FONT_SUMMARY_VERSION_MAJOR 1 #define FONT_SUMMARY_VERSION_MINOR 0 @@ -97,7 +97,7 @@ typedef struct nsTTFontFamilyEncoderInfo { } nsTTFontFamilyEncoderInfo; typedef struct { - const char *mDirName; + const char *mDirName; // encoded in the native charset } nsDirCatalogEntry; diff --git a/mozilla/gfx/src/mac/nsDeviceContextSpecX.cpp b/mozilla/gfx/src/mac/nsDeviceContextSpecX.cpp index fda1b2973cc..8ed4b04f1b1 100644 --- a/mozilla/gfx/src/mac/nsDeviceContextSpecX.cpp +++ b/mozilla/gfx/src/mac/nsDeviceContextSpecX.cpp @@ -324,9 +324,8 @@ FSSpec spec; return false; } - char *fullModuleName = nsnull; - mozFile->Append("Essential Files"); - mozFile->Append("PrintDialogPDE.plugin"); + mozFile->Append(NS_LITERAL_CSTRING("Essential Files")); + mozFile->Append(NS_LITERAL_CSTRING("PrintDialogPDE.plugin")); nsCOMPtr mozMacFile(do_QueryInterface(mozFile)); mozMacFile->GetFSSpec(&spec); diff --git a/mozilla/gfx/src/nsNameValuePairDB.cpp b/mozilla/gfx/src/nsNameValuePairDB.cpp index f523569b669..0e4af63bec6 100644 --- a/mozilla/gfx/src/nsNameValuePairDB.cpp +++ b/mozilla/gfx/src/nsNameValuePairDB.cpp @@ -325,7 +325,7 @@ nsNameValuePairDB::~nsNameValuePairDB() } PRBool -nsNameValuePairDB::OpenForRead(const nsACString & aCatalogName) +nsNameValuePairDB::OpenForRead(const nsACString & aCatalogName) // native charset { nsresult result; @@ -334,7 +334,7 @@ nsNameValuePairDB::OpenForRead(const nsACString & aCatalogName) if (NS_FAILED(result)) goto error_return; - local_file->InitWithPath(PromiseFlatCString(aCatalogName).get()); + local_file->InitWithNativePath(aCatalogName); local_file->OpenANSIFileDesc("r", &mFile); if (mFile && CheckHeader()) return PR_TRUE; @@ -346,17 +346,14 @@ error_return: } PRBool -nsNameValuePairDB::OpenTmpForWrite(const nsACString& aCatalogName) +nsNameValuePairDB::OpenTmpForWrite(const nsACString& aCatalogName) // native charset { - nsCAutoString name(aCatalogName); - name.Append(".tmp"); - nsresult result; nsCOMPtr local_file = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &result); if (NS_FAILED(result)) return PR_FALSE; - local_file->InitWithPath(name.get()); + local_file->InitWithNativePath(aCatalogName + NS_LITERAL_CSTRING(".tmp")); local_file->OpenANSIFileDesc("w+", &mFile); if (mFile == nsnull) return PR_FALSE; @@ -455,8 +452,8 @@ nsNameValuePairDB::RenameTmp(const char* aCatalogName) nsCOMPtr current_file; nsCOMPtr tmp_file; nsCAutoString parent_dir; - nsXPIDLCString parent_path; - nsXPIDLCString cur_path; + nsCAutoString parent_path; + nsCAutoString cur_path; // // Split the parent dir and file name @@ -475,8 +472,8 @@ nsNameValuePairDB::RenameTmp(const char* aCatalogName) dir = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv); if (NS_FAILED(rv)) goto Rename_Error; - dir->InitWithPath(parent_dir.get()); - dir->GetPath(getter_Copies(parent_path)); + dir->InitWithNativePath(parent_dir); + dir->GetNativePath(parent_path); if (!mAtEndOfGroup || mError) goto Rename_Error; @@ -488,7 +485,7 @@ nsNameValuePairDB::RenameTmp(const char* aCatalogName) tmp_file = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv); if (NS_FAILED(rv)) goto Rename_Error; - tmp_file->InitWithPath(tmp_name.get()); + tmp_file->InitWithNativePath(tmp_name); tmp_file->Exists(&exists); if (!exists) goto Rename_Error; @@ -500,7 +497,7 @@ nsNameValuePairDB::RenameTmp(const char* aCatalogName) old_file = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv); if (NS_FAILED(rv)) goto Rename_Error; - old_file->InitWithPath(old_name.get()); + old_file->InitWithNativePath(old_name); // // Check we have a current copy @@ -508,15 +505,15 @@ nsNameValuePairDB::RenameTmp(const char* aCatalogName) current_file = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv); if (NS_FAILED(rv)) goto Rename_Error; - current_file->InitWithPath(current_name.get()); + current_file->InitWithNativePath(current_name); current_file->Exists(&exists); if (exists) { // // Rename the current copy to old // - current_file->GetPath(getter_Copies(cur_path)); + current_file->GetNativePath(cur_path); old_name.Right(old_name_tail, old_name.Length() - last_slash - 1); - rv = current_file->MoveTo(dir, old_name_tail.get()); + rv = current_file->MoveToNative(dir, old_name_tail); if (NS_FAILED(rv)) goto Rename_Error; } @@ -525,7 +522,7 @@ nsNameValuePairDB::RenameTmp(const char* aCatalogName) // Rename the tmp to current // current_name.Right(current_name_tail, current_name.Length() - last_slash - 1); - rv = tmp_file->MoveTo(dir, current_name_tail.get()); + rv = tmp_file->MoveToNative(dir, current_name_tail); if (NS_FAILED(rv)) goto Rename_Error; diff --git a/mozilla/gfx/src/x11shared/nsFT2FontCatalog.cpp b/mozilla/gfx/src/x11shared/nsFT2FontCatalog.cpp index 4f8ac2ef8d5..23bff51dc8b 100644 --- a/mozilla/gfx/src/x11shared/nsFT2FontCatalog.cpp +++ b/mozilla/gfx/src/x11shared/nsFT2FontCatalog.cpp @@ -677,6 +677,7 @@ nsFT2FontCatalog::doGetDirsPrefEnumCallback(const char* aName, void* aClosure) dce = (nsDirCatalogEntry *)calloc(1, sizeof(nsDirCatalogEntry)); if (!dce) return; + // native charset?! mPref->CopyCharPref(aName, (char **)&dce->mDirName); if (!dce->mDirName) return; @@ -713,21 +714,20 @@ nsFT2FontCatalog::GetFontCatalog(FT_Library lib, nsFontCatalog *aFontCatalog, { int i; nsresult rv; - nsXPIDLCString font_summaries_dir_path; - nsXPIDLCString font_download_dir_path; + nsCAutoString font_summaries_dir_path; + nsCAutoString font_download_dir_path; PRBool exists; - nsCOMPtr font_download_dir; + nsCOMPtr font_summaries_dir, font_download_dir; if (lib) { // // Get the dir for downloaded fonts // - rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILES_ROOT_DIR, - getter_AddRefs(font_download_dir)); + rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILES_ROOT_DIR, getter_AddRefs(font_download_dir)); if (NS_FAILED(rv)) goto cleanup_and_return; - rv = font_download_dir->Append(FONT_DOWNLOAD_SUBDIR); + rv = font_download_dir->AppendNative(FONT_DOWNLOAD_SUBDIR); if (NS_FAILED(rv)) goto cleanup_and_return; exists = PR_FALSE; @@ -740,23 +740,21 @@ nsFT2FontCatalog::GetFontCatalog(FT_Library lib, nsFontCatalog *aFontCatalog, if (NS_FAILED(rv)) goto cleanup_and_return; } - rv = font_download_dir->GetPath(getter_Copies(font_download_dir_path)); + rv = font_download_dir->GetNativePath(font_download_dir_path); if (NS_FAILED(rv)) goto cleanup_and_return; // // Get the user dir for font catalogs // - nsCOMPtr font_summaries_dir; - rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILES_ROOT_DIR, - getter_AddRefs(font_summaries_dir)); + rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILES_ROOT_DIR, getter_AddRefs(font_summaries_dir)); if (NS_FAILED(rv)) goto cleanup_and_return; - rv = font_summaries_dir->Append(FONT_DOWNLOAD_SUBDIR); + rv = font_summaries_dir->AppendNative(FONT_DOWNLOAD_SUBDIR); if (NS_FAILED(rv)) goto cleanup_and_return; - rv = font_summaries_dir->Append(FONT_SUMMARIES_SUBDIR); + rv = font_summaries_dir->AppendNative(FONT_SUMMARIES_SUBDIR); if (NS_FAILED(rv)) goto cleanup_and_return; exists = PR_FALSE; @@ -769,24 +767,22 @@ nsFT2FontCatalog::GetFontCatalog(FT_Library lib, nsFontCatalog *aFontCatalog, if (NS_FAILED(rv)) goto cleanup_and_return; } - rv = font_summaries_dir->GetPath(getter_Copies(font_summaries_dir_path)); + rv = font_summaries_dir->GetNativePath(font_summaries_dir_path); if (NS_FAILED(rv)) goto cleanup_and_return; // // Get the font summaries for the public font dirs // - nsCAutoString fs_dir(font_summaries_dir_path); for (i=0; inumDirs; i++) { - nsCAutoString dir_name(aOldDirCatalog->dirs[i]->mDirName); - HandleFontDir(lib, aFontCatalog, fs_dir, dir_name); + HandleFontDir(lib, aFontCatalog, font_summaries_dir_path, + nsDependentCString(aOldDirCatalog->dirs[i]->mDirName)); } // // Get the font summaries for the downloaded/private font dir // - nsCAutoString fdown_dir(font_download_dir_path); - HandleFontDir(lib, aFontCatalog, fs_dir, fdown_dir); + HandleFontDir(lib, aFontCatalog, font_summaries_dir_path, font_download_dir_path); } return 0; @@ -887,8 +883,8 @@ cleanup_and_return: } PRBool -nsFT2FontCatalog::GetFontSummaryName(const nsACString &aFontDirName, - const nsACString &aFontSummariesDir, +nsFT2FontCatalog::GetFontSummaryName(const nsACString &aFontDirName, // native charset + const nsACString &aFontSummariesDir, // native charset nsACString &aFontSummaryFileName, nsACString &aFallbackFontSummaryFileName) @@ -906,16 +902,16 @@ nsFT2FontCatalog::GetFontSummaryName(const nsACString &aFontDirName, // or the "private" one in our $HOME/.mozilla/fontsummaries dir // font_dir = new nsLocalFile(); - font_dir->InitWithPath(PromiseFlatCString(aFontDirName).get()); + font_dir->InitWithNativePath(aFontDirName); rv = font_dir->IsWritable(&public_dir_writable); if (NS_SUCCEEDED(rv) && public_dir_writable) { FONT_CATALOG_PRINTF(("can write \"%s\"", PromiseFlatCString(aFontDirName).get())); nsCOMPtr summary_file = new nsLocalFile(); - summary_file->InitWithPath(PromiseFlatCString(aFontDirName).get()); - summary_file->Append(PUBLIC_FONT_SUMMARY_NAME); - char *font_summary_path; - summary_file->GetPath(&font_summary_path); - FONT_CATALOG_PRINTF(("font_summary_path = \"%s\"", font_summary_path)); + summary_file->InitWithNativePath(aFontDirName); + summary_file->AppendNative(PUBLIC_FONT_SUMMARY_NAME); + nsCAutoString font_summary_path; + summary_file->GetNativePath(font_summary_path); + FONT_CATALOG_PRINTF(("font_summary_path = \"%s\"", font_summary_path.get())); rv = summary_file->Exists(&exists); if (NS_SUCCEEDED(rv)) { if (!exists) { @@ -923,11 +919,11 @@ nsFT2FontCatalog::GetFontSummaryName(const nsACString &aFontDirName, aFontSummaryFileName = font_summary_path; } else { - FONT_CATALOG_PRINTF(("font summary \"%s\" exists", font_summary_path)); + FONT_CATALOG_PRINTF(("font summary \"%s\" exists", font_summary_path.get())); rv = summary_file->IsWritable(&public_summary_writable); if (NS_SUCCEEDED(rv) && public_summary_writable) { FONT_CATALOG_PRINTF(("font summary \"%s\" is writable", - font_summary_path)); + font_summary_path.get())); public_summary_writable = PR_TRUE; aFontSummaryFileName = font_summary_path; } @@ -1054,12 +1050,12 @@ nsFT2FontCatalog::GetRange2CharSetName(unsigned long aBit) PRBool nsFT2FontCatalog::HandleFontDir(FT_Library aFreeTypeLibrary, nsFontCatalog *aFontCatalog, - const nsACString &aFontSummariesDir, - const nsACString &aFontDirName) + const nsACString &aFontSummariesDir, // native charset + const nsACString &aFontDirName) // native charset { int i, status = -1; PRBool rslt, current; - char *fileName; + nsCAutoString fileName; nsHashtable* fontFileNamesHash = nsnull; nsHashtable* fallbackFceHash = nsnull; nsresult rv; @@ -1068,7 +1064,7 @@ nsFT2FontCatalog::HandleFontDir(FT_Library aFreeTypeLibrary, PRBool moreFilesInDir = PR_FALSE; nsCOMPtr dir; nsCOMPtr dirLocal; - nsCOMPtr dirEntry; + nsCOMPtr dirEntry; nsCOMPtr dirIterator; PRBool summary_needs_update = PR_FALSE; nsFontCatalogEntry *fce; @@ -1115,7 +1111,7 @@ nsFT2FontCatalog::HandleFontDir(FT_Library aFreeTypeLibrary, // dir = new nsLocalFile(); dirLocal = do_QueryInterface(dir); - dirLocal->InitWithPath(PromiseFlatCString(aFontDirName).get()); + dirLocal->InitWithNativePath(aFontDirName); rv = dir->GetDirectoryEntries(getter_AddRefs(dirIterator)); if (NS_FAILED(rv)) { FONT_CATALOG_PRINTF(("failed to open dir (get iterator) for %s", @@ -1141,20 +1137,19 @@ nsFT2FontCatalog::HandleFontDir(FT_Library aFreeTypeLibrary, goto cleanup_and_return; } //char *path; - dirEntry->GetPath(&fileName); - FONT_CATALOG_PRINTF(("dirEntry = \"%s\"", fileName)); + dirEntry->GetNativePath(fileName); + FONT_CATALOG_PRINTF(("dirEntry = \"%s\"", fileName.get())); rv = dirEntry->IsFile(&isFile); if (NS_SUCCEEDED(rv) && isFile) { PRInt64 modtime; dirEntry->GetLastModifiedTime(&modtime); - current = AddFceIfCurrent(fileName, fontFileNamesHash, + current = AddFceIfCurrent(fileName.get(), fontFileNamesHash, modtime, dirFontCatalog); if (!current) { // Ignore the font summary itself - nsDependentCString name(fileName); - if (name.Equals(fontSummaryFilename) || - name.Equals(fallbackFontSummaryFilename)) { - FONT_CATALOG_PRINTF(("font summary %s is not a font", fileName)); + if (fileName.Equals(fontSummaryFilename) || + fileName.Equals(fallbackFontSummaryFilename)) { + FONT_CATALOG_PRINTF(("font summary %s is not a font", fileName.get())); current = PR_TRUE; } // If not in font summary, try the fallback summary @@ -1168,7 +1163,7 @@ nsFT2FontCatalog::HandleFontDir(FT_Library aFreeTypeLibrary, } if (fallbackFceHash) { summary_needs_update = PR_TRUE; - current = AddFceIfCurrent(fileName, fallbackFceHash, + current = AddFceIfCurrent(fileName.get(), fallbackFceHash, modtime, dirFontCatalog); } } @@ -1180,7 +1175,7 @@ nsFT2FontCatalog::HandleFontDir(FT_Library aFreeTypeLibrary, if (!current) { summary_needs_update = PR_TRUE; HandleFontFile(aFreeTypeLibrary, dirFontCatalog, - fileName); + fileName.get()); } } } diff --git a/mozilla/gfx/src/x11shared/nsFT2FontCatalog.h b/mozilla/gfx/src/x11shared/nsFT2FontCatalog.h index fcbaeda29b9..a952c618791 100644 --- a/mozilla/gfx/src/x11shared/nsFT2FontCatalog.h +++ b/mozilla/gfx/src/x11shared/nsFT2FontCatalog.h @@ -64,10 +64,10 @@ typedef unsigned short FT_UShort; class nsFontNodeArray; -#define PUBLIC_FONT_SUMMARY_NAME ".mozilla_font_summary.ndb" -#define FONT_SUMMARIES_SUBDIR "catalog" -#define FONT_DOWNLOAD_SUBDIR "fonts" -#define FONT_SUMMARIES_EXTENSION ".ndb" +#define PUBLIC_FONT_SUMMARY_NAME NS_LITERAL_CSTRING(".mozilla_font_summary.ndb") +#define FONT_SUMMARIES_SUBDIR NS_LITERAL_CSTRING("catalog") +#define FONT_DOWNLOAD_SUBDIR NS_LITERAL_CSTRING("fonts") +#define FONT_SUMMARIES_EXTENSION NS_LITERAL_CSTRING(".ndb") #define FONT_SUMMARY_VERSION_TAG "FontSummaryVersion" #define FONT_SUMMARY_VERSION_MAJOR 1 #define FONT_SUMMARY_VERSION_MINOR 0 @@ -97,7 +97,7 @@ typedef struct nsTTFontFamilyEncoderInfo { } nsTTFontFamilyEncoderInfo; typedef struct { - const char *mDirName; + const char *mDirName; // encoded in the native charset } nsDirCatalogEntry; diff --git a/mozilla/gfx/src/x11shared/nsNameValuePairDB.cpp b/mozilla/gfx/src/x11shared/nsNameValuePairDB.cpp index f523569b669..0e4af63bec6 100644 --- a/mozilla/gfx/src/x11shared/nsNameValuePairDB.cpp +++ b/mozilla/gfx/src/x11shared/nsNameValuePairDB.cpp @@ -325,7 +325,7 @@ nsNameValuePairDB::~nsNameValuePairDB() } PRBool -nsNameValuePairDB::OpenForRead(const nsACString & aCatalogName) +nsNameValuePairDB::OpenForRead(const nsACString & aCatalogName) // native charset { nsresult result; @@ -334,7 +334,7 @@ nsNameValuePairDB::OpenForRead(const nsACString & aCatalogName) if (NS_FAILED(result)) goto error_return; - local_file->InitWithPath(PromiseFlatCString(aCatalogName).get()); + local_file->InitWithNativePath(aCatalogName); local_file->OpenANSIFileDesc("r", &mFile); if (mFile && CheckHeader()) return PR_TRUE; @@ -346,17 +346,14 @@ error_return: } PRBool -nsNameValuePairDB::OpenTmpForWrite(const nsACString& aCatalogName) +nsNameValuePairDB::OpenTmpForWrite(const nsACString& aCatalogName) // native charset { - nsCAutoString name(aCatalogName); - name.Append(".tmp"); - nsresult result; nsCOMPtr local_file = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &result); if (NS_FAILED(result)) return PR_FALSE; - local_file->InitWithPath(name.get()); + local_file->InitWithNativePath(aCatalogName + NS_LITERAL_CSTRING(".tmp")); local_file->OpenANSIFileDesc("w+", &mFile); if (mFile == nsnull) return PR_FALSE; @@ -455,8 +452,8 @@ nsNameValuePairDB::RenameTmp(const char* aCatalogName) nsCOMPtr current_file; nsCOMPtr tmp_file; nsCAutoString parent_dir; - nsXPIDLCString parent_path; - nsXPIDLCString cur_path; + nsCAutoString parent_path; + nsCAutoString cur_path; // // Split the parent dir and file name @@ -475,8 +472,8 @@ nsNameValuePairDB::RenameTmp(const char* aCatalogName) dir = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv); if (NS_FAILED(rv)) goto Rename_Error; - dir->InitWithPath(parent_dir.get()); - dir->GetPath(getter_Copies(parent_path)); + dir->InitWithNativePath(parent_dir); + dir->GetNativePath(parent_path); if (!mAtEndOfGroup || mError) goto Rename_Error; @@ -488,7 +485,7 @@ nsNameValuePairDB::RenameTmp(const char* aCatalogName) tmp_file = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv); if (NS_FAILED(rv)) goto Rename_Error; - tmp_file->InitWithPath(tmp_name.get()); + tmp_file->InitWithNativePath(tmp_name); tmp_file->Exists(&exists); if (!exists) goto Rename_Error; @@ -500,7 +497,7 @@ nsNameValuePairDB::RenameTmp(const char* aCatalogName) old_file = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv); if (NS_FAILED(rv)) goto Rename_Error; - old_file->InitWithPath(old_name.get()); + old_file->InitWithNativePath(old_name); // // Check we have a current copy @@ -508,15 +505,15 @@ nsNameValuePairDB::RenameTmp(const char* aCatalogName) current_file = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv); if (NS_FAILED(rv)) goto Rename_Error; - current_file->InitWithPath(current_name.get()); + current_file->InitWithNativePath(current_name); current_file->Exists(&exists); if (exists) { // // Rename the current copy to old // - current_file->GetPath(getter_Copies(cur_path)); + current_file->GetNativePath(cur_path); old_name.Right(old_name_tail, old_name.Length() - last_slash - 1); - rv = current_file->MoveTo(dir, old_name_tail.get()); + rv = current_file->MoveToNative(dir, old_name_tail); if (NS_FAILED(rv)) goto Rename_Error; } @@ -525,7 +522,7 @@ nsNameValuePairDB::RenameTmp(const char* aCatalogName) // Rename the tmp to current // current_name.Right(current_name_tail, current_name.Length() - last_slash - 1); - rv = tmp_file->MoveTo(dir, current_name_tail.get()); + rv = tmp_file->MoveToNative(dir, current_name_tail); if (NS_FAILED(rv)) goto Rename_Error; diff --git a/mozilla/js/src/xpconnect/loader/mozJSComponentLoader.cpp b/mozilla/js/src/xpconnect/loader/mozJSComponentLoader.cpp index 2b2574387ef..a0061cbb9c0 100644 --- a/mozilla/js/src/xpconnect/loader/mozJSComponentLoader.cpp +++ b/mozilla/js/src/xpconnect/loader/mozJSComponentLoader.cpp @@ -734,7 +734,7 @@ mozJSComponentLoader::AutoRegisterComponent(PRInt32 when, const char jsExtension[] = ".js"; int jsExtensionLen = 3; - nsXPIDLCString leafName; + nsCAutoString leafName; *registered = PR_FALSE; @@ -743,28 +743,28 @@ mozJSComponentLoader::AutoRegisterComponent(PRInt32 when, if (NS_FAILED(rv = component->IsFile(&isFile)) || !isFile) return rv; - if (NS_FAILED(rv = component->GetLeafName(getter_Copies(leafName)))) + if (NS_FAILED(rv = component->GetNativeLeafName(leafName))) return rv; - int len = PL_strlen(leafName); + int len = leafName.Length(); /* if it's not *.js, return now */ if (len < jsExtensionLen || // too short - PL_strcasecmp(leafName + len - jsExtensionLen, jsExtension)) + PL_strcasecmp(leafName.get() + len - jsExtensionLen, jsExtension)) return NS_OK; #ifdef DEBUG_shaver_off fprintf(stderr, "mJCL: registering JS component %s\n", - (const char *)leafName); + leafName.get()); #endif rv = AttemptRegistration(component, PR_FALSE); #ifdef DEBUG_shaver_off if (NS_SUCCEEDED(rv)) - fprintf(stderr, "registered module %s\n", (const char *)leafName); + fprintf(stderr, "registered module %s\n", leafName.get()); else if (rv == NS_ERROR_FACTORY_REGISTER_AGAIN) - fprintf(stderr, "deferred module %s\n", (const char *)leafName); + fprintf(stderr, "deferred module %s\n", leafName.get()); else - fprintf(stderr, "failed to register %s\n", (const char *)leafName); + fprintf(stderr, "failed to register %s\n", leafName.get()); #endif *registered = (PRBool) NS_SUCCEEDED(rv); return NS_OK; @@ -781,7 +781,7 @@ mozJSComponentLoader::AutoUnregisterComponent(PRInt32 when, const char jsExtension[] = ".js"; int jsExtensionLen = 3; - nsXPIDLCString leafName; + nsCAutoString leafName; *unregistered = PR_FALSE; @@ -790,21 +790,21 @@ mozJSComponentLoader::AutoUnregisterComponent(PRInt32 when, if (NS_FAILED(rv = component->IsFile(&isFile)) || !isFile) return rv; - if (NS_FAILED(rv = component->GetLeafName(getter_Copies(leafName)))) + if (NS_FAILED(rv = component->GetNativeLeafName(leafName))) return rv; - int len = PL_strlen(leafName); + int len = leafName.Length(); /* if it's not *.js, return now */ if (len < jsExtensionLen || // too short - PL_strcasecmp(leafName + len - jsExtensionLen, jsExtension)) + PL_strcasecmp(leafName.get() + len - jsExtensionLen, jsExtension)) return NS_OK; rv = UnregisterComponent(component); #ifdef DEBUG_dp if (NS_SUCCEEDED(rv)) - fprintf(stderr, "unregistered module %s\n", (const char *)leafName); + fprintf(stderr, "unregistered module %s\n", leafName.get()); else - fprintf(stderr, "failed to unregister %s\n", (const char *)leafName); + fprintf(stderr, "failed to unregister %s\n", leafName.get()); #endif *unregistered = (PRBool) NS_SUCCEEDED(rv); return NS_OK; @@ -852,9 +852,9 @@ mozJSComponentLoader::AttemptRegistration(nsIFile *component, // get the file name if (component) { - nsXPIDLCString leafName; - component->GetLeafName(getter_Copies(leafName)); - fileName.AssignWithConversion(leafName); + nsCAutoString leafName; + component->GetLeafName(leafName); + fileName.Assign(NS_ConvertUTF8toUCS2(leafName)); } // this string can't come from a string bundle, because we diff --git a/mozilla/layout/forms/nsFileControlFrame.cpp b/mozilla/layout/forms/nsFileControlFrame.cpp index 87911fd302d..096626a24de 100644 --- a/mozilla/layout/forms/nsFileControlFrame.cpp +++ b/mozilla/layout/forms/nsFileControlFrame.cpp @@ -304,13 +304,12 @@ nsFileControlFrame::MouseClick(nsIDOMEvent* aMouseEvent) nsCOMPtr currentFile = do_CreateInstance("@mozilla.org/file/local;1"); if (currentFile && !defaultName.IsEmpty()) { - result = currentFile->InitWithUnicodePath(defaultName.get()); + result = currentFile->InitWithPath(NS_ConvertUCS2toUTF8(defaultName)); if (NS_SUCCEEDED(result)) { - PRUnichar *leafName = nsnull; - currentFile->GetUnicodeLeafName(&leafName); - if (leafName) { - filePicker->SetDefaultString(leafName); - nsMemory::Free(leafName); + nsCAutoString leafName; + currentFile->GetLeafName(leafName); + if (!leafName.IsEmpty()) { + filePicker->SetDefaultString(NS_ConvertUTF8toUCS2(leafName).get()); } // set directory @@ -336,12 +335,11 @@ nsFileControlFrame::MouseClick(nsIDOMEvent* aMouseEvent) nsCOMPtr localFile; result = filePicker->GetFile(getter_AddRefs(localFile)); if (localFile) { - PRUnichar *nativePath = nsnull; - result = localFile->GetUnicodePath(&nativePath); - if (nativePath) { - nsAutoString pathName(nativePath); + nsCAutoString unicodePath; + result = localFile->GetPath(unicodePath); + if (!unicodePath.IsEmpty()) { + NS_ConvertUTF8toUCS2 pathName(unicodePath); mTextFrame->SetProperty(mPresContext, nsHTMLAtoms::value, pathName); - nsMemory::Free(nativePath); return NS_OK; } } diff --git a/mozilla/layout/html/forms/src/nsFileControlFrame.cpp b/mozilla/layout/html/forms/src/nsFileControlFrame.cpp index 87911fd302d..096626a24de 100644 --- a/mozilla/layout/html/forms/src/nsFileControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsFileControlFrame.cpp @@ -304,13 +304,12 @@ nsFileControlFrame::MouseClick(nsIDOMEvent* aMouseEvent) nsCOMPtr currentFile = do_CreateInstance("@mozilla.org/file/local;1"); if (currentFile && !defaultName.IsEmpty()) { - result = currentFile->InitWithUnicodePath(defaultName.get()); + result = currentFile->InitWithPath(NS_ConvertUCS2toUTF8(defaultName)); if (NS_SUCCEEDED(result)) { - PRUnichar *leafName = nsnull; - currentFile->GetUnicodeLeafName(&leafName); - if (leafName) { - filePicker->SetDefaultString(leafName); - nsMemory::Free(leafName); + nsCAutoString leafName; + currentFile->GetLeafName(leafName); + if (!leafName.IsEmpty()) { + filePicker->SetDefaultString(NS_ConvertUTF8toUCS2(leafName).get()); } // set directory @@ -336,12 +335,11 @@ nsFileControlFrame::MouseClick(nsIDOMEvent* aMouseEvent) nsCOMPtr localFile; result = filePicker->GetFile(getter_AddRefs(localFile)); if (localFile) { - PRUnichar *nativePath = nsnull; - result = localFile->GetUnicodePath(&nativePath); - if (nativePath) { - nsAutoString pathName(nativePath); + nsCAutoString unicodePath; + result = localFile->GetPath(unicodePath); + if (!unicodePath.IsEmpty()) { + NS_ConvertUTF8toUCS2 pathName(unicodePath); mTextFrame->SetProperty(mPresContext, nsHTMLAtoms::value, pathName); - nsMemory::Free(nativePath); return NS_OK; } } diff --git a/mozilla/mailnews/absync/src/nsAbSync.cpp b/mozilla/mailnews/absync/src/nsAbSync.cpp index c8ad837f66a..1fe6400a1c7 100644 --- a/mozilla/mailnews/absync/src/nsAbSync.cpp +++ b/mozilla/mailnews/absync/src/nsAbSync.cpp @@ -1175,19 +1175,15 @@ nsAbSync::AnalyzeAllRecords(nsIAddrDatabase *aDatabase, nsIAbDirectory *director rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(historyFile)); NS_ENSURE_SUCCESS(rv, rv); - rv = historyFile->Append("absync.dat"); + rv = historyFile->Append(NS_LITERAL_CSTRING("absync.dat")); NS_ENSURE_SUCCESS(rv, rv); // TODO: Convert the rest of the code to use // nsIFile and avoid this conversion hack. do { - nsXPIDLCString pathBuf; - rv = historyFile->GetPath(getter_Copies(pathBuf)); + rv = NS_NewFileSpecFromIFile(historyFile, getter_AddRefs(mHistoryFile)); if (NS_FAILED(rv)) break; - rv = NS_NewFileSpec(getter_AddRefs(mHistoryFile)); - if (NS_FAILED(rv)) break; - rv = mHistoryFile->SetNativePath(pathBuf); } while (0); @@ -1227,7 +1223,7 @@ nsAbSync::AnalyzeAllRecords(nsIAddrDatabase *aDatabase, nsIAbDirectory *director rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(lockFile)); if (NS_SUCCEEDED(rv)) { - rv = lockFile->Append((const char *)"absync.lck"); + rv = lockFile->Append(NS_LITERAL_CSTRING("absync.lck")); if (NS_SUCCEEDED(rv)) { @@ -1235,12 +1231,8 @@ nsAbSync::AnalyzeAllRecords(nsIAddrDatabase *aDatabase, nsIAbDirectory *director // nsIFile and avoid this conversion hack. do { - nsXPIDLCString pathBuf; - rv = lockFile->GetPath(getter_Copies(pathBuf)); + rv = NS_NewFileSpecFromIFile(lockFile, getter_AddRefs(mLockFile)); if (NS_FAILED(rv)) break; - rv = NS_NewFileSpec(getter_AddRefs(mLockFile)); - if (NS_FAILED(rv)) break; - rv = mLockFile->SetNativePath(pathBuf); } while (0); diff --git a/mozilla/mailnews/absync/src/nsAbSyncPostEngine.cpp b/mozilla/mailnews/absync/src/nsAbSyncPostEngine.cpp index d65361cbc0c..fe49d029e10 100644 --- a/mozilla/mailnews/absync/src/nsAbSyncPostEngine.cpp +++ b/mozilla/mailnews/absync/src/nsAbSyncPostEngine.cpp @@ -698,7 +698,7 @@ nsAbSyncPostEngine::FireURLRequest(nsIURI *aURL, const char *postData) if (!httpChannel) return NS_ERROR_FAILURE; - if (NS_SUCCEEDED(rv = NS_NewPostDataStream(getter_AddRefs(postStream), PR_FALSE, postData, 0))){ + if (NS_SUCCEEDED(rv = NS_NewPostDataStream(getter_AddRefs(postStream), PR_FALSE, nsDependentCString(postData), 0))){ nsCOMPtr uploadChannel(do_QueryInterface(httpChannel)); NS_ASSERTION(uploadChannel, "http must support nsIUploadChannel"); uploadChannel->SetUploadStream(postStream, nsnull, -1); diff --git a/mozilla/mailnews/addrbook/src/nsAbLDAPReplicationData.cpp b/mozilla/mailnews/addrbook/src/nsAbLDAPReplicationData.cpp index d5f238b73c6..bf497ecd3b5 100644 --- a/mozilla/mailnews/addrbook/src/nsAbLDAPReplicationData.cpp +++ b/mozilla/mailnews/addrbook/src/nsAbLDAPReplicationData.cpp @@ -236,7 +236,7 @@ NS_IMETHODIMP nsAbLDAPProcessReplicationData::Abort() if(NS_SUCCEEDED(rv)) { // now put back the backed up replicated file if aborted if(mBackupReplicationFile && mDirServerInfo->replInfo) - rv = mBackupReplicationFile->MoveTo(nsnull, mDirServerInfo->replInfo->fileName); + rv = mBackupReplicationFile->MoveToNative(nsnull, nsDependentCString(mDirServerInfo->replInfo->fileName)); } } } @@ -472,7 +472,7 @@ nsresult nsAbLDAPProcessReplicationData::OnLDAPSearchResult(nsILDAPMessage *aMes // now put back the backed up replicated file if(mBackupReplicationFile && mDirServerInfo->replInfo) { - rv = mBackupReplicationFile->MoveTo(nsnull, mDirServerInfo->replInfo->fileName); + rv = mBackupReplicationFile->MoveToNative(nsnull, nsDependentCString(mDirServerInfo->replInfo->fileName)); NS_ASSERTION(NS_SUCCEEDED(rv), "Replication Backup File Move back on Failure failed"); } } @@ -526,7 +526,14 @@ nsresult nsAbLDAPProcessReplicationData::OpenABForReplicatedDir(PRBool aCreate) // clone the existing one for a much better performance - for Download All. // And also important in case if replication fails we donot lose user's existing // replicated data for both Download all and Changelog. - rv = mReplicationFile->Clone(getter_AddRefs(mBackupReplicationFile)); + nsCOMPtr clone; + rv = mReplicationFile->Clone(getter_AddRefs(clone)); + if(NS_FAILED(rv)) { + delete dbPath; + Done(PR_FALSE); + return rv; + } + mBackupReplicationFile = do_QueryInterface(clone, &rv); if(NS_FAILED(rv)) { delete dbPath; Done(PR_FALSE); @@ -538,8 +545,8 @@ nsresult nsAbLDAPProcessReplicationData::OpenABForReplicatedDir(PRBool aCreate) Done(PR_FALSE); return rv; } - nsXPIDLCString backupFileLeafName; - rv = mBackupReplicationFile->GetLeafName(getter_Copies(backupFileLeafName)); + nsCAutoString backupFileLeafName; + rv = mBackupReplicationFile->GetLeafName(backupFileLeafName); if(NS_FAILED(rv)) { delete dbPath; Done(PR_FALSE); @@ -555,25 +562,25 @@ nsresult nsAbLDAPProcessReplicationData::OpenABForReplicatedDir(PRBool aCreate) if(aCreate) { // set backup file to existing replication file for move - mBackupReplicationFile->SetLeafName(mDirServerInfo->replInfo->fileName); - rv = mBackupReplicationFile->MoveTo(nsnull, backupFileLeafName.get()); + mBackupReplicationFile->SetNativeLeafName(nsDependentCString(mDirServerInfo->replInfo->fileName)); + rv = mBackupReplicationFile->MoveTo(nsnull, backupFileLeafName); // set the backup file leaf name now if (NS_SUCCEEDED(rv)) - mBackupReplicationFile->SetLeafName(backupFileLeafName.get()); + mBackupReplicationFile->SetLeafName(backupFileLeafName); } else { // set backup file to existing replication file for copy - mBackupReplicationFile->SetLeafName(mDirServerInfo->replInfo->fileName); + mBackupReplicationFile->SetLeafName(nsDependentCString(mDirServerInfo->replInfo->fileName)); // specify the parent here specifically, // passing nsnull to copy to the same dir actually renames existing file // instead of making another copy of the existing file. nsCOMPtr parent; rv = mBackupReplicationFile->GetParent(getter_AddRefs(parent)); if (NS_SUCCEEDED(rv)) - rv = mBackupReplicationFile->CopyTo(parent, backupFileLeafName.get()); + rv = mBackupReplicationFile->CopyTo(parent, backupFileLeafName); // set the backup file leaf name now if (NS_SUCCEEDED(rv)) - mBackupReplicationFile->SetLeafName(backupFileLeafName.get()); + mBackupReplicationFile->SetLeafName(backupFileLeafName); } if(NS_FAILED(rv)) { delete dbPath; diff --git a/mozilla/mailnews/addrbook/src/nsAbLDAPReplicationData.h b/mozilla/mailnews/addrbook/src/nsAbLDAPReplicationData.h index 50f44138518..de5ae6c3d67 100644 --- a/mozilla/mailnews/addrbook/src/nsAbLDAPReplicationData.h +++ b/mozilla/mailnews/addrbook/src/nsAbLDAPReplicationData.h @@ -43,6 +43,7 @@ #include "nsIWebProgressListener.h" #include "nsIAbLDAPReplicationQuery.h" #include "nsIAddrDatabase.h" +#include "nsILocalFile.h" #include "nsDirPrefs.h" class nsAbLDAPProcessReplicationData : public nsIAbLDAPProcessReplicationData @@ -63,7 +64,7 @@ protected : nsCOMPtr mReplicationDB; nsCOMPtr mReplicationFile; - nsCOMPtr mBackupReplicationFile; + nsCOMPtr mBackupReplicationFile; // state of processing, protocol used and count of results PRInt32 mState; diff --git a/mozilla/mailnews/addrbook/src/nsAddrBookSession.cpp b/mozilla/mailnews/addrbook/src/nsAddrBookSession.cpp index d505a2a2750..2a58c7c1bc5 100644 --- a/mozilla/mailnews/addrbook/src/nsAddrBookSession.cpp +++ b/mozilla/mailnews/addrbook/src/nsAddrBookSession.cpp @@ -40,6 +40,7 @@ #include "nsAddrBookSession.h" #include "nsIAddrBookSession.h" #include "nsIFileSpec.h" +#include "nsILocalFile.h" #include "nsIDirectoryService.h" #include "nsAppDirectoryServiceDefs.h" #include "nsXPIDLString.h" @@ -179,14 +180,15 @@ NS_IMETHODIMP nsAddrBookSession::GetUserProfileDirectory(nsFileSpec * *userDir) nsresult rv; nsCOMPtr profileDir; - nsXPIDLCString pathBuf; + nsCAutoString pathBuf; rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(profileDir)); NS_ENSURE_SUCCESS(rv, rv); - rv = profileDir->GetPath(getter_Copies(pathBuf)); + + rv = profileDir->GetNativePath(pathBuf); NS_ENSURE_SUCCESS(rv, rv); - *userDir = new nsFileSpec(pathBuf); + *userDir = new nsFileSpec(pathBuf.get()); NS_ENSURE_TRUE(*userDir, NS_ERROR_OUT_OF_MEMORY); return rv; diff --git a/mozilla/mailnews/addrbook/src/nsAddressBook.cpp b/mozilla/mailnews/addrbook/src/nsAddressBook.cpp index 6b86bc05304..0c4ec574929 100644 --- a/mozilla/mailnews/addrbook/src/nsAddressBook.cpp +++ b/mozilla/mailnews/addrbook/src/nsAddressBook.cpp @@ -1323,8 +1323,8 @@ NS_IMETHODIMP nsAddressBook::ExportAddressBook(nsIAbDirectory *aDirectory) } } - nsXPIDLCString leafName; - rv = localFile->GetLeafName(getter_Copies(leafName)); + nsCAutoString leafName; + rv = localFile->GetLeafName(leafName); NS_ENSURE_SUCCESS(rv,rv); // we're looking for .tab, .txt, .csv, .ldi or .ldif diff --git a/mozilla/mailnews/base/prefs/resources/content/AccountManager.js b/mozilla/mailnews/base/prefs/resources/content/AccountManager.js index 8ed9e7cfbf1..96f9e7f77b1 100644 --- a/mozilla/mailnews/base/prefs/resources/content/AccountManager.js +++ b/mozilla/mailnews/base/prefs/resources/content/AccountManager.js @@ -869,7 +869,7 @@ function getFormElementValue(formElement) { if (formElement.value) { var localfile = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); - localfile.initWithUnicodePath(formElement.value); + localfile.initWithPath(formElement.value); return localfile; } else { @@ -952,7 +952,7 @@ function setFormElementValue(formElement, value) { if (value) { var localfile = value.QueryInterface(Components.interfaces.nsILocalFile); try { - formElement.value = localfile.unicodePath; + formElement.value = localfile.path; } catch (ex) { dump("Still need to fix uninitialized nsIFile problem!\n"); } diff --git a/mozilla/mailnews/base/prefs/resources/content/AccountWizard.js b/mozilla/mailnews/base/prefs/resources/content/AccountWizard.js index e09337f30c6..f51afe4212b 100644 --- a/mozilla/mailnews/base/prefs/resources/content/AccountWizard.js +++ b/mozilla/mailnews/base/prefs/resources/content/AccountWizard.js @@ -431,7 +431,7 @@ function finishAccount(account, accountData) { var sigFileName = accountData.signatureFileName; var sigFile = gMailSession.getDataFilesDir("messenger"); - sigFile.appendUnicode(sigFileName); + sigFile.append(sigFileName); destIdentity.signature = sigFile; } diff --git a/mozilla/mailnews/base/prefs/resources/content/am-main.js b/mozilla/mailnews/base/prefs/resources/content/am-main.js index 6e43f2a469f..7eee0c657ea 100644 --- a/mozilla/mailnews/base/prefs/resources/content/am-main.js +++ b/mozilla/mailnews/base/prefs/resources/content/am-main.js @@ -78,7 +78,7 @@ function selectFile() var ret = fp.show(); if (ret == nsIFilePicker.returnOK) { var folderField = document.getElementById("identity.signature"); - folderField.value = fp.file.unicodePath; + folderField.value = fp.file.path; } } diff --git a/mozilla/mailnews/base/search/src/nsMsgFilterService.cpp b/mozilla/mailnews/base/search/src/nsMsgFilterService.cpp index 1ed9906b660..6bc41963870 100644 --- a/mozilla/mailnews/base/search/src/nsMsgFilterService.cpp +++ b/mozilla/mailnews/base/search/src/nsMsgFilterService.cpp @@ -199,13 +199,13 @@ nsresult nsMsgFilterService::BackUpFilterFile(nsIFileSpec *aFilterFile, nsIMsgWi nsCOMPtr backupFile; rv = NS_FileSpecToIFile(&parentDirSpec, getter_AddRefs(backupFile)); NS_ENSURE_SUCCESS(rv,rv); - backupFile->Append("rulesbackup.dat"); + backupFile->Append(NS_LITERAL_CSTRING("rulesbackup.dat")); PRBool exists; backupFile->Exists(&exists); if (exists) backupFile->Remove(PR_FALSE); - return localFilterFile->CopyTo(localParentDir, "rulesbackup.dat"); + return localFilterFile->CopyTo(localParentDir, NS_LITERAL_CSTRING("rulesbackup.dat")); } nsresult nsMsgFilterService::AlertBackingUpFilterFile(nsIMsgWindow *aMsgWindow) diff --git a/mozilla/mailnews/base/src/nsMessenger.cpp b/mozilla/mailnews/base/src/nsMessenger.cpp index 96f2398892d..9249bdfae6c 100644 --- a/mozilla/mailnews/base/src/nsMessenger.cpp +++ b/mozilla/mailnews/base/src/nsMessenger.cpp @@ -48,6 +48,7 @@ #include "nsXPIDLString.h" #include "nsReadableUtils.h" #include "nsIFileSpec.h" +#include "nsILocalFile.h" #ifdef XP_MAC #include "nsIAppleFileDecoder.h" #endif @@ -206,31 +207,27 @@ ConvertBufToPlainText(nsString &aConBuf) nsresult ConvertAndSanitizeFileName(const char * displayName, PRUnichar ** unicodeResult, char ** result) { - char * unescapedName = PL_strdup(displayName); - if (!unescapedName) - return NS_ERROR_OUT_OF_MEMORY; + nsCAutoString unescapedName(displayName); /* we need to convert the UTF-8 fileName to platform specific character set. The display name is in UTF-8 because it has been escaped from JS */ - nsUnescape(unescapedName); - nsAutoString ucs2Str = NS_ConvertUTF8toUCS2(unescapedName); - PR_FREEIF(unescapedName); + NS_UnescapeURL(unescapedName); nsresult rv = NS_OK; #if defined(XP_MAC) /* We need to truncate the name to 31 characters, this even on MacOS X until the file API - correctly support long file name. Using a nsILocalFIle will do the trick... + correctly support long file name. Using a nsILocalFile will do the trick... */ nsCOMPtr aLocalFile(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv)); - if (NS_SUCCEEDED(aLocalFile->SetUnicodeLeafName(ucs2Str.get()))) + if (NS_SUCCEEDED(aLocalFile->SetLeafName(unescapedName))) { - PRUnichar * tempStr; - aLocalFile->GetUnicodeLeafName(&tempStr); - ucs2Str.Adopt(tempStr); + aLocalFile->GetLeafName(unescapedName); } #endif + NS_ConvertUTF8toUCS2 ucs2Str(unescapedName); + // replace platform specific path separator and illegale characters to avoid any confusion ucs2Str.ReplaceChar(FILE_PATH_SEPARATOR FILE_ILLEGAL_CHARACTERS, '-'); @@ -525,7 +522,7 @@ nsMessenger::PromptIfFileExists(nsFileSpec &fileSpec) return NS_ERROR_FAILURE; nsCOMPtr localFile; - nsXPIDLCString filePath; + nsCAutoString filePath; rv = filePicker->GetFile(getter_AddRefs(localFile)); if (NS_FAILED(rv)) return rv; @@ -533,9 +530,10 @@ nsMessenger::PromptIfFileExists(nsFileSpec &fileSpec) rv = SetLastSaveDirectory(localFile); NS_ENSURE_SUCCESS(rv,rv); - rv = localFile->GetPath(getter_Copies(filePath)); + rv = localFile->GetNativePath(filePath); if (NS_FAILED(rv)) return rv; - fileSpec = (const char*) filePath; + + fileSpec = filePath.get(); return NS_OK; } } @@ -788,7 +786,7 @@ nsMessenger::SaveAttachment(const char * contentType, const char * url, PRInt16 dialogResult; nsCOMPtr localFile; - nsCOMPtr lastSaveDir; + nsCOMPtr lastSaveDir; nsCOMPtr fileSpec; nsXPIDLCString filePath; nsXPIDLString defaultDisplayString; @@ -826,12 +824,10 @@ nsMessenger::SaveAttachment(const char * contentType, const char * url, if (NS_FAILED(rv)) goto done; (void)SetLastSaveDirectory(localFile); - - rv = localFile->GetPath(getter_Copies(filePath)); - fileSpec = do_CreateInstance("@mozilla.org/filespec;1", &rv); + + rv = NS_NewFileSpecFromIFile(localFile, getter_AddRefs(fileSpec)); if (NS_FAILED(rv)) goto done; - fileSpec->SetNativePath(filePath); rv = SaveAttachment(fileSpec, unescapedUrl, messageUri, contentType, nsnull); done: @@ -880,8 +876,8 @@ nsMessenger::SaveAllAttachments(PRUint32 count, rv = SetLastSaveDirectory(localFile); if (NS_FAILED(rv)) goto done; - - rv = localFile->GetPath(getter_Copies(dirName)); + + rv = localFile->GetNativePath(dirName); if (NS_FAILED(rv)) goto done; rv = NS_NewFileSpec(getter_AddRefs(fileSpec)); if (NS_FAILED(rv)) goto done; @@ -978,10 +974,9 @@ nsMessenger::SaveAs(const char* url, PRBool asFile, nsIMsgIdentity* identity, ns if (NS_FAILED(rv)) goto done; - nsXPIDLCString tmpFileName; - rv = localFile->GetLeafName(getter_Copies(tmpFileName)); + nsCAutoString fileName; + rv = localFile->GetLeafName(fileName); if (NS_FAILED(rv)) goto done; - nsCAutoString fileName(tmpFileName); // First, check if they put ANY extension on the file, if not, // then we should look at the type of file they have chosen and @@ -1003,11 +998,9 @@ nsMessenger::SaveAs(const char* url, PRBool asFile, nsIMsgIdentity* identity, ns // XXX argh! converting from nsILocalFile to nsFileSpec ... oh baby, lets drop from unicode to ascii too // nsXPIDLString path; // localFile->GetUnicodePath(getter_Copies(path)); - nsXPIDLCString path; - localFile->GetPath(getter_Copies(path)); - nsCOMPtr fileSpec = do_CreateInstance("@mozilla.org/filespec;1", &rv); + nsCOMPtr fileSpec; + rv = NS_NewFileSpecFromIFile(localFile, getter_AddRefs(fileSpec)); if (NS_FAILED(rv)) goto done; - fileSpec->SetNativePath(path); aListener = new nsSaveMsgListener(fileSpec, this); if (!aListener) { diff --git a/mozilla/mailnews/base/src/nsMessengerMigrator.cpp b/mozilla/mailnews/base/src/nsMessengerMigrator.cpp index 291ead7a823..b0809ec483d 100644 --- a/mozilla/mailnews/base/src/nsMessengerMigrator.cpp +++ b/mozilla/mailnews/base/src/nsMessengerMigrator.cpp @@ -55,6 +55,7 @@ #include "nsDirectoryServiceDefs.h" #include "nsAppDirectoryServiceDefs.h" #include "nsIFileSpec.h" +#include "nsILocalFile.h" #include "nsIURL.h" #include "nsNetCID.h" #include "nsIStringBundle.h" @@ -559,14 +560,8 @@ nsMessengerMigrator::CreateLocalMailAccount(PRBool migrating) // Convert the nsILocalFile into an nsIFileSpec // TODO: convert users os nsIFileSpec to nsILocalFile // and avoid this step. - nsXPIDLCString mailDirPath; - rv = mailDir->GetPath(getter_Copies(mailDirPath)); + rv = NS_NewFileSpecFromIFile(mailDir, getter_AddRefs(mailDirSpec)); if (NS_FAILED(rv)) return rv; - rv = NS_NewFileSpec(getter_AddRefs(mailDirSpec)); - if (NS_FAILED(rv)) return rv; - rv = mailDirSpec->SetNativePath(mailDirPath); - if (NS_FAILED(rv)) return rv; - // set the default local path for "none" rv = server->SetDefaultLocalPath(mailDirSpec); @@ -1180,17 +1175,12 @@ nsMessengerMigrator::MigrateLocalMailAccount() rv = mailDir->Create(nsIFile::DIRECTORY_TYPE, 0775); if (NS_FAILED(rv)) return rv; - nsXPIDLCString mailDirPath; nsCOMPtr mailDirSpec; // Convert the nsILocalFile into an nsIFileSpec // TODO: convert users of nsIFileSpec to nsILocalFile // and avoid this step. - rv = mailDir->GetPath(getter_Copies(mailDirPath)); - if (NS_FAILED(rv)) return rv; - rv = NS_NewFileSpec(getter_AddRefs(mailDirSpec)); - if (NS_FAILED(rv)) return rv; - rv = mailDirSpec->SetNativePath(mailDirPath); + rv = NS_NewFileSpecFromIFile(mailDir, getter_AddRefs(mailDirSpec)); if (NS_FAILED(rv)) return rv; // set the default local path for "none" @@ -1294,15 +1284,11 @@ nsMessengerMigrator::MigrateMovemailAccount(nsIMsgIdentity *identity) if (NS_FAILED(rv)) { // we wan't /Mail nsCOMPtr aFile; - nsXPIDLCString pathBuf; rv = NS_GetSpecialDirectory(NS_APP_MAIL_50_DIR, getter_AddRefs(aFile)); if (NS_FAILED(rv)) return rv; - rv = aFile->GetPath(getter_Copies(pathBuf)); - if (NS_FAILED(rv)) return rv; - rv = NS_NewFileSpec(getter_AddRefs(mailDir)); - if (NS_FAILED(rv)) return rv; - rv = mailDir->SetNativePath((const char *)pathBuf); + + NS_NewFileSpecFromIFile(aFile, getter_AddRefs(mailDir)); if (NS_FAILED(rv)) return rv; } @@ -1447,17 +1433,12 @@ nsMessengerMigrator::MigratePopAccount(nsIMsgIdentity *identity) rv = mailDir->Create(nsIFile::DIRECTORY_TYPE, 0775); if (NS_FAILED(rv)) return rv; - nsXPIDLCString mailDirPath; nsCOMPtr mailDirSpec; // Convert the nsILocalFile into an nsIFileSpec // TODO: convert users os nsIFileSpec to nsILocalFile // and avoid this step. - rv = mailDir->GetPath(getter_Copies(mailDirPath)); - if (NS_FAILED(rv)) return rv; - rv = NS_NewFileSpec(getter_AddRefs(mailDirSpec)); - if (NS_FAILED(rv)) return rv; - rv = mailDirSpec->SetNativePath(mailDirPath); + rv = NS_NewFileSpecFromIFile(mailDir, getter_AddRefs(mailDirSpec)); if (NS_FAILED(rv)) return rv; // set the default local path for "pop3" @@ -1747,17 +1728,12 @@ nsMessengerMigrator::MigrateImapAccount(nsIMsgIdentity *identity, const char *ho rv = imapMailDir->Create(nsIFile::DIRECTORY_TYPE, 0775); if (NS_FAILED(rv)) return rv; - nsXPIDLCString pathBuf; nsCOMPtr imapMailDirSpec; // Convert the nsILocalFile into an nsIFileSpec // TODO: convert users os nsIFileSpec to nsILocalFile // and avoid this step. - rv = imapMailDir->GetPath(getter_Copies(pathBuf)); - if (NS_FAILED(rv)) return rv; - rv = NS_NewFileSpec(getter_AddRefs(imapMailDirSpec)); - if (NS_FAILED(rv)) return rv; - rv = imapMailDirSpec->SetNativePath(pathBuf); + rv = NS_NewFileSpecFromIFile(imapMailDir, getter_AddRefs(imapMailDirSpec)); if (NS_FAILED(rv)) return rv; // we only need to do this once @@ -1946,15 +1922,8 @@ nsMessengerMigrator::migrateAddressBookPrefEnum(const char *aPref, void *aClosur if (NS_FAILED(rv) || !ab4xFile) return; // TODO: Change users of nsIFileSpec to nsIFile and avoid this. - { - nsXPIDLCString pathBuf; - rv = ab4xFile->GetPath(getter_Copies(pathBuf)); - if (NS_FAILED(rv)) return; - rv = NS_NewFileSpec(getter_AddRefs(ab4xFileSpec)); - if (NS_FAILED(rv)) return; - rv = ab4xFileSpec->SetNativePath(pathBuf); - if (NS_FAILED(rv)) return; - } + rv = NS_NewFileSpecFromIFile(ab4xFile, getter_AddRefs(ab4xFileSpec)); + if (NS_FAILED(rv)) return; rv = ab4xFileSpec->AppendRelativeUnixPath((const char *)abFileName); NS_ASSERTION(NS_SUCCEEDED(rv),"ab migration failed: failed to append filename"); @@ -1966,22 +1935,15 @@ nsMessengerMigrator::migrateAddressBookPrefEnum(const char *aPref, void *aClosur // do the migration in a subdirectory of temp, to prevent // collision (between multiple users), deleting TMPDIR // and privacy issues (where the temp ldif files are readable) - rv = tmpLDIFFile->Append("addr-migrate"); + rv = tmpLDIFFile->Append(NS_LITERAL_CSTRING("addr-migrate")); if (NS_FAILED(rv) || !tmpLDIFFile) return; rv = tmpLDIFFile->CreateUnique(nsIFile::DIRECTORY_TYPE, 0700); if (NS_FAILED(rv) || !tmpLDIFFile) return; // TODO: Change users of nsIFileSpec to nsIFile and avoid this. - { - nsXPIDLCString pathBuf; - rv = tmpLDIFFile->GetPath(getter_Copies(pathBuf)); - if (NS_FAILED(rv)) return; - rv = NS_NewFileSpec(getter_AddRefs(tmpLDIFFileSpec)); - if (NS_FAILED(rv)) return; - rv = tmpLDIFFileSpec->SetNativePath(pathBuf); - if (NS_FAILED(rv)) return; - } + rv = NS_NewFileSpecFromIFile(tmpLDIFFile, getter_AddRefs(tmpLDIFFileSpec)); + if (NS_FAILED(rv)) return; // get the csid from the prefs nsCAutoString csidPrefName; @@ -2124,10 +2086,10 @@ nsMessengerMigrator::MigrateNewsAccounts(nsIMsgIdentity *identity) // TODO: convert users os nsIFileSpec to nsILocalFile // and avoid this step. - nsXPIDLCString pathBuf; - rv = newsDir->GetPath(getter_Copies(pathBuf)); + nsCAutoString pathBuf; + rv = newsDir->GetNativePath(pathBuf); if (NS_FAILED(rv)) return rv; - newsHostsDir = pathBuf; + newsHostsDir = pathBuf.get(); #ifdef USE_NEWSRC_MAP_FILE // if we are using the fat file, it lives in the newsHostsDir. @@ -2264,10 +2226,10 @@ nsMessengerMigrator::MigrateNewsAccounts(nsIMsgIdentity *identity) newsDir = prefLocal; { - nsXPIDLCString pathBuf; - newsDir->GetPath(getter_Copies(pathBuf)); + nsCAutoString pathBuf; + newsDir->GetNativePath(pathBuf); if (NS_FAILED(rv)) return rv; - newsrcDir = (const char *)pathBuf; + newsrcDir = pathBuf.get(); } for (nsDirectoryIterator i(newsrcDir, PR_FALSE); i.Exists(); i++) { diff --git a/mozilla/mailnews/base/src/nsMessengerWinIntegration.cpp b/mozilla/mailnews/base/src/nsMessengerWinIntegration.cpp index 028b7f576a5..37262a733a0 100644 --- a/mozilla/mailnews/base/src/nsMessengerWinIntegration.cpp +++ b/mozilla/mailnews/base/src/nsMessengerWinIntegration.cpp @@ -73,7 +73,7 @@ #define XP_SHEnumerateUnreadMailAccounts "SHEnumerateUnreadMailAccountsW" #define ShellNotifyWideVersion "Shell_NotifyIconW" #define UNREADMAILNODEKEY "Software\\Microsoft\\Windows\\CurrentVersion\\UnreadMail\\" -#define SHELL32_DLL "shell32.dll" +#define SHELL32_DLL NS_LITERAL_CSTRING("shell32.dll") #define DOUBLE_QUOTE "\"" #define PROFILE_COMMANDLINE_ARG " -p " #define MAIL_COMMANDLINE_ARG " -mail" @@ -399,13 +399,11 @@ nsMessengerWinIntegration::Init() NS_ENSURE_SUCCESS(rv,rv); // get path to shell dll. - nsXPIDLCString shellFile; - rv = systemDir->GetPath(getter_Copies(shellFile)); + nsCAutoString shellFile; + rv = systemDir->GetNativePath(shellFile); NS_ENSURE_SUCCESS(rv,rv); - mShellDllPath.Assign(shellFile); - mShellDllPath.Append("\\"); - mShellDllPath.Append(SHELL32_DLL); + mShellDllPath.Assign(shellFile + NS_LITERAL_CSTRING("\\") + SHELL32_DLL); // load shell dll. If no such dll found, return HMODULE hModule = ::LoadLibrary(mShellDllPath.get()); diff --git a/mozilla/mailnews/base/src/nsMsgAccountManager.cpp b/mozilla/mailnews/base/src/nsMsgAccountManager.cpp index 557d235e74f..994f7a15817 100644 --- a/mozilla/mailnews/base/src/nsMsgAccountManager.cpp +++ b/mozilla/mailnews/base/src/nsMsgAccountManager.cpp @@ -62,6 +62,7 @@ #include "nsFileStream.h" #include "nsMsgUtils.h" #include "nsIFileSpec.h" +#include "nsILocalFile.h" #include "nsIURL.h" #include "nsNetCID.h" #include "nsISmtpService.h" @@ -954,12 +955,7 @@ nsresult nsMsgAccountManager::GetFolderCache(nsIMsgFolderCache* *aFolderCache) // TODO: Make nsIMsgFolderCache::Init take an nsIFile and // avoid this conversion. - nsXPIDLCString pathBuf; - rv = cacheFile->GetPath(getter_Copies(pathBuf)); - if (NS_FAILED(rv)) return rv; - rv = NS_NewFileSpec(getter_AddRefs(cacheFileSpec)); - if (NS_FAILED(rv)) return rv; - rv = cacheFileSpec->SetNativePath(pathBuf); + rv = NS_NewFileSpecFromIFile(cacheFile, getter_AddRefs(cacheFileSpec)); if (NS_FAILED(rv)) return rv; m_msgFolderCache->Init(cacheFileSpec); diff --git a/mozilla/mailnews/base/src/nsMsgMailSession.cpp b/mozilla/mailnews/base/src/nsMsgMailSession.cpp index cbed0b224c3..ca2db00d89e 100644 --- a/mozilla/mailnews/base/src/nsMsgMailSession.cpp +++ b/mozilla/mailnews/base/src/nsMsgMailSession.cpp @@ -565,7 +565,7 @@ nsMsgMailSession::GetSelectedLocaleDataDir(nsIFile *defaultsDir) rv = defaultsDir->Clone(getter_AddRefs(localeDataDir)); NS_ENSURE_SUCCESS(rv,rv); - rv = localeDataDir->AppendUnicode(localeName); + rv = localeDataDir->Append(NS_ConvertUCS2toUTF8(localeName)); NS_ENSURE_SUCCESS(rv,rv); rv = localeDataDir->Exists(&localeDirExists); @@ -573,7 +573,7 @@ nsMsgMailSession::GetSelectedLocaleDataDir(nsIFile *defaultsDir) if (localeDirExists) { // use locale provider instead - rv = defaultsDir->AppendUnicode(localeName); + rv = defaultsDir->Append(NS_ConvertUCS2toUTF8(localeName)); NS_ENSURE_SUCCESS(rv,rv); } } @@ -603,7 +603,7 @@ nsMsgMailSession::GetDataFilesDir(const char* dirName, nsIFile **dataFilesDir) getter_AddRefs(defaultsDir)); NS_ENSURE_SUCCESS(rv,rv); - rv = defaultsDir->Append(dirName); + rv = defaultsDir->AppendNative(nsDependentCString(dirName)); if (NS_SUCCEEDED(rv)) rv = GetSelectedLocaleDataDir(defaultsDir); diff --git a/mozilla/mailnews/base/util/nsMsgIncomingServer.cpp b/mozilla/mailnews/base/util/nsMsgIncomingServer.cpp index 2c01d1dd18e..9f666fd090b 100644 --- a/mozilla/mailnews/base/util/nsMsgIncomingServer.cpp +++ b/mozilla/mailnews/base/util/nsMsgIncomingServer.cpp @@ -452,15 +452,11 @@ nsMsgIncomingServer::GetFileValue(const char* prefname, nsCOMPtr prefLocal; nsCOMPtr outSpec; - nsXPIDLCString pathBuf; nsresult rv = m_prefs->GetFileXPref(fullPrefName.get(), getter_AddRefs(prefLocal)); if (NS_FAILED(rv)) return rv; - rv = NS_NewFileSpec(getter_AddRefs(outSpec)); - if (NS_FAILED(rv)) return rv; - rv = prefLocal->GetPath(getter_Copies(pathBuf)); - if (NS_FAILED(rv)) return rv; - rv = outSpec->SetNativePath((const char *)pathBuf); + + rv = NS_NewFileSpecFromIFile(prefLocal, getter_AddRefs(outSpec)); if (NS_FAILED(rv)) return rv; *spec = outSpec; diff --git a/mozilla/mailnews/compose/src/nsMsgCompose.cpp b/mozilla/mailnews/compose/src/nsMsgCompose.cpp index 02646cecc62..ddadf69199c 100644 --- a/mozilla/mailnews/compose/src/nsMsgCompose.cpp +++ b/mozilla/mailnews/compose/src/nsMsgCompose.cpp @@ -110,6 +110,7 @@ #include "nsNetUtil.h" #include "nsMsgSimulateError.h" #include "nsIAddrDatabase.h" +#include "nsILocalFile.h" // Defines.... static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); @@ -3063,7 +3064,7 @@ nsMsgCompose::ProcessSignature(nsIMsgIdentity *identity, nsString *aMsgBody) // are doing plain text compose, we should insert some sort of message // saying "Image Signature Omitted" or something. // - nsXPIDLCString sigNativePath; + nsCAutoString sigNativePath; PRBool useSigFile = PR_FALSE; PRBool htmlSig = PR_FALSE; PRBool imageSig = PR_FALSE; @@ -3075,12 +3076,15 @@ nsMsgCompose::ProcessSignature(nsIMsgIdentity *identity, nsString *aMsgBody) rv = identity->GetAttachSignature(&useSigFile); if (NS_SUCCEEDED(rv) && useSigFile) { + useSigFile = PR_FALSE; // by default, assume no signature file! + nsCOMPtr sigFile; rv = identity->GetSignature(getter_AddRefs(sigFile)); - if (NS_SUCCEEDED(rv) && sigFile) - rv = sigFile->GetPath(getter_Copies(sigNativePath)); - else - useSigFile = PR_FALSE; //No signature file! therefore turn it off. + if (NS_SUCCEEDED(rv) && sigFile) { + rv = sigFile->GetNativePath(sigNativePath); + if (NS_SUCCEEDED(rv) && !sigNativePath.IsEmpty()) + useSigFile = PR_TRUE; // ok, there's a signature file + } } } @@ -3090,7 +3094,7 @@ nsMsgCompose::ProcessSignature(nsIMsgIdentity *identity, nsString *aMsgBody) if ((!useSigFile) || NS_FAILED(rv)) return NS_OK; - nsFileSpec testSpec(sigNativePath); + nsFileSpec testSpec(sigNativePath.get()); // If this file doesn't really exist, just bail! if (!testSpec.Exists()) diff --git a/mozilla/mailnews/imap/src/nsImapMailFolder.cpp b/mozilla/mailnews/imap/src/nsImapMailFolder.cpp index d5d30f557bd..591afa16af8 100644 --- a/mozilla/mailnews/imap/src/nsImapMailFolder.cpp +++ b/mozilla/mailnews/imap/src/nsImapMailFolder.cpp @@ -41,6 +41,7 @@ #include "nsMsgImapCID.h" #include "nsImapMailFolder.h" #include "nsIEnumerator.h" +#include "nsILocalFile.h" #include "nsIFolderListener.h" #include "nsCOMPtr.h" #include "nsIRDFService.h" @@ -164,8 +165,8 @@ nsresult RecursiveCopy(nsIFile* srcDir, nsIFile* destDir) if (NS_SUCCEEDED(rv)) { nsCOMPtr newChild(do_QueryInterface(destClone)); - nsXPIDLCString leafName; - dirEntry->GetLeafName(getter_Copies(leafName)); + nsCAutoString leafName; + dirEntry->GetLeafName(leafName); newChild->AppendRelativePath(leafName); rv = newChild->Exists(&exists); if (NS_SUCCEEDED(rv) && !exists) @@ -174,7 +175,7 @@ nsresult RecursiveCopy(nsIFile* srcDir, nsIFile* destDir) } } else - rv = dirEntry->CopyTo(destDir, nsnull); + rv = dirEntry->CopyTo(destDir, nsCString()); } } @@ -1431,11 +1432,9 @@ NS_IMETHODIMP nsImapMailFolder::RenameLocal(const char *newName, nsIMsgFolder *p nsCOMPtr destDir = (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv)); NS_ENSURE_SUCCESS(rv,rv); - nsCString oldPathStr (dirSpec.GetNativePathCString()); - srcDir->InitWithPath(oldPathStr.get()); + srcDir->InitWithNativePath(nsDependentCString(dirSpec.GetNativePathCString())); - nsCString newPathStr (parentPath.GetNativePathCString()); - destDir->InitWithPath(newPathStr.get()); + destDir->InitWithNativePath(nsDependentCString(parentPath.GetNativePathCString())); rv = RecursiveCopy(srcDir, destDir); diff --git a/mozilla/mailnews/imap/src/nsImapService.cpp b/mozilla/mailnews/imap/src/nsImapService.cpp index 1c093983250..7118c8cff01 100644 --- a/mozilla/mailnews/imap/src/nsImapService.cpp +++ b/mozilla/mailnews/imap/src/nsImapService.cpp @@ -3593,13 +3593,9 @@ nsImapService::GetDefaultLocalPath(nsIFileSpec ** aResult) // Make the resulting nsIFileSpec // TODO: Convert arg to nsILocalFile and avoid this - nsXPIDLCString pathBuf; - rv = localFile->GetPath(getter_Copies(pathBuf)); - if (NS_FAILED(rv)) return rv; nsCOMPtr outSpec; - rv = NS_NewFileSpec(getter_AddRefs(outSpec)); + rv = NS_NewFileSpecFromIFile(localFile, getter_AddRefs(outSpec)); if (NS_FAILED(rv)) return rv; - outSpec->SetNativePath(pathBuf); if (!havePref || !exists) rv = SetDefaultLocalPath(outSpec); diff --git a/mozilla/mailnews/import/comm4x/src/nsComm4xProfile.cpp b/mozilla/mailnews/import/comm4x/src/nsComm4xProfile.cpp index f81d923a8d3..08652d9e5e3 100644 --- a/mozilla/mailnews/import/comm4x/src/nsComm4xProfile.cpp +++ b/mozilla/mailnews/import/comm4x/src/nsComm4xProfile.cpp @@ -89,7 +89,7 @@ nsComm4xProfile::GetMailDir(const PRUnichar *profileName, char **_retval) if (NS_FAILED(rv)) return rv; nsCOMPtr profileLocation; profileLocation = do_QueryInterface(file); - rv = profileLocation->Append(PREF_FILE_NAME_IN_4x); + rv = profileLocation->Append(NS_LITERAL_CSTRING(PREF_FILE_NAME_IN_4x)); if (NS_FAILED(rv)) return rv; PRBool exists = PR_FALSE; rv = profileLocation->Exists(&exists); @@ -100,9 +100,12 @@ nsComm4xProfile::GetMailDir(const PRUnichar *profileName, char **_retval) if (NS_FAILED(rv)) return rv; if (prefValue) { #ifdef XP_MAC - rv = profileLocation->SetPersistentDescriptor(prefValue.get()); + rv = profileLocation->SetPersistentDescriptor(prefValue); if (NS_FAILED(rv)) return rv; - rv = profileLocation->GetPath(_retval); + nsCAutoString nativePath; + rv = profileLocation->GetNativePath(nativePath); + if (NS_FAILED(rv)) return rv; + *_retval = ToNewCString(nativePath); #else *_retval = ToNewCString(prefValue); #endif @@ -112,9 +115,12 @@ nsComm4xProfile::GetMailDir(const PRUnichar *profileName, char **_retval) nsCOMPtr mailLocation; rv = resolvedLocation->Clone(getter_AddRefs(mailLocation)); if (NS_FAILED(rv)) return rv; - rv = mailLocation->Append("Mail"); + rv = mailLocation->Append(NS_LITERAL_CSTRING("Mail")); if (NS_FAILED(rv)) return rv; - rv = mailLocation->GetPath(_retval); + nsCAutoString nativePath; + rv = mailLocation->GetNativePath(nativePath); + if (NS_FAILED(rv)) return rv; + *_retval = ToNewCString(nativePath); } #endif } diff --git a/mozilla/mailnews/local/src/nsMovemailService.cpp b/mozilla/mailnews/local/src/nsMovemailService.cpp index 7e885af079b..d262f03eab8 100644 --- a/mozilla/mailnews/local/src/nsMovemailService.cpp +++ b/mozilla/mailnews/local/src/nsMovemailService.cpp @@ -594,13 +594,9 @@ nsMovemailService::GetDefaultLocalPath(nsIFileSpec ** aResult) // Make the resulting nsIFileSpec // TODO: Convert arg to nsILocalFile and avoid this - nsXPIDLCString pathBuf; - rv = localFile->GetPath(getter_Copies(pathBuf)); - if (NS_FAILED(rv)) return rv; nsCOMPtr outSpec; - rv = NS_NewFileSpec(getter_AddRefs(outSpec)); + rv = NS_NewFileSpecFromIFile(localFile, getter_AddRefs(outSpec)); if (NS_FAILED(rv)) return rv; - outSpec->SetNativePath(pathBuf); if (!havePref || !exists) rv = SetDefaultLocalPath(outSpec); diff --git a/mozilla/mailnews/local/src/nsNoIncomingServer.cpp b/mozilla/mailnews/local/src/nsNoIncomingServer.cpp index 68ffca21052..956e448ae59 100644 --- a/mozilla/mailnews/local/src/nsNoIncomingServer.cpp +++ b/mozilla/mailnews/local/src/nsNoIncomingServer.cpp @@ -117,7 +117,7 @@ NS_IMETHODIMP nsNoIncomingServer::CopyDefaultMessages(const char *folderNameOnDi // check if bin/defaults/messenger/ // (or bin/defaults/messenger// if we had a locale provide) exists. // it doesn't have to exist. if it doesn't, return - rv = defaultMessagesFile->Append(folderNameOnDisk); + rv = defaultMessagesFile->AppendNative(nsDependentCString(folderNameOnDisk)); if (NS_FAILED(rv)) return rv; rv = defaultMessagesFile->Exists(&exists); if (NS_FAILED(rv)) return rv; @@ -137,7 +137,7 @@ NS_IMETHODIMP nsNoIncomingServer::CopyDefaultMessages(const char *folderNameOnDi nsCOMPtr testDir; rv = localParentDir->Clone(getter_AddRefs(testDir)); if (NS_FAILED(rv)) return rv; - rv = testDir->Append(folderNameOnDisk); + rv = testDir->AppendNative(nsDependentCString(folderNameOnDisk)); if (NS_FAILED(rv)) return rv; rv = testDir->Exists(&exists); if (NS_FAILED(rv)) return rv; @@ -156,7 +156,7 @@ NS_IMETHODIMP nsNoIncomingServer::CopyDefaultMessages(const char *folderNameOnDi #ifdef DEBUG_sspitzer printf("copy default %s\n",folderNameOnDisk); #endif - rv = defaultMessagesFile->CopyTo(localParentDir, nsnull); + rv = defaultMessagesFile->CopyTo(localParentDir, nsCString()); if (NS_FAILED(rv)) return rv; } return NS_OK; diff --git a/mozilla/mailnews/local/src/nsNoneService.cpp b/mozilla/mailnews/local/src/nsNoneService.cpp index 47c02cf39bd..26013b69b49 100644 --- a/mozilla/mailnews/local/src/nsNoneService.cpp +++ b/mozilla/mailnews/local/src/nsNoneService.cpp @@ -115,13 +115,9 @@ nsNoneService::GetDefaultLocalPath(nsIFileSpec ** aResult) // Make the resulting nsIFileSpec // TODO: Convert arg to nsILocalFile and avoid this - nsXPIDLCString pathBuf; - rv = localFile->GetPath(getter_Copies(pathBuf)); - if (NS_FAILED(rv)) return rv; nsCOMPtr outSpec; - rv = NS_NewFileSpec(getter_AddRefs(outSpec)); + rv = NS_NewFileSpecFromIFile(localFile, getter_AddRefs(outSpec)); if (NS_FAILED(rv)) return rv; - outSpec->SetNativePath(pathBuf); if (!havePref || !exists) rv = SetDefaultLocalPath(outSpec); diff --git a/mozilla/mailnews/local/src/nsParseMailbox.cpp b/mozilla/mailnews/local/src/nsParseMailbox.cpp index 84abc4ef74a..bb9dcf696b4 100644 --- a/mozilla/mailnews/local/src/nsParseMailbox.cpp +++ b/mozilla/mailnews/local/src/nsParseMailbox.cpp @@ -44,6 +44,7 @@ #include "nsMsgMessageFlags.h" #include "nsIDBFolderInfo.h" #include "nsIInputStream.h" +#include "nsILocalFile.h" #include "nsMsgLocalFolderHdrs.h" #include "nsMsgBaseCID.h" #include "nsMsgDBCID.h" @@ -1554,13 +1555,14 @@ nsOutputFileStream * nsParseNewMailState::GetLogFile () nsCOMPtr logDir; NS_GetSpecialDirectory(NS_APP_MAIL_50_DIR, getter_AddRefs(logDir)); - nsXPIDLCString pathBuf; - logDir->Append("filter.log"); - nsresult rv = logDir->GetPath(getter_Copies(pathBuf)); - if (NS_FAILED(rv)) return nsnull; - nsCOMPtr outSpec; + logDir->Append(NS_LITERAL_CSTRING("filter.log")); + + nsCAutoString pathBuf; + nsresult rv = logDir->GetNativePath(pathBuf); + if (NS_FAILED(rv)) return nsnull; + + nsFileSpec logFile(pathBuf.get()); - nsFileSpec logFile(pathBuf); m_logFile = new nsOutputFileStream(logFile, PR_WRONLY | PR_CREATE_FILE, 00600); } return m_logFile; diff --git a/mozilla/mailnews/local/src/nsPop3Service.cpp b/mozilla/mailnews/local/src/nsPop3Service.cpp index ac5c75f523f..29f46becb98 100644 --- a/mozilla/mailnews/local/src/nsPop3Service.cpp +++ b/mozilla/mailnews/local/src/nsPop3Service.cpp @@ -483,13 +483,9 @@ nsPop3Service::GetDefaultLocalPath(nsIFileSpec ** aResult) // Make the resulting nsIFileSpec // TODO: Convert arg to nsILocalFile and avoid this - nsXPIDLCString pathBuf; - rv = localFile->GetPath(getter_Copies(pathBuf)); - if (NS_FAILED(rv)) return rv; nsCOMPtr outSpec; - rv = NS_NewFileSpec(getter_AddRefs(outSpec)); + rv = NS_NewFileSpecFromIFile(localFile, getter_AddRefs(outSpec)); if (NS_FAILED(rv)) return rv; - outSpec->SetNativePath(pathBuf); if (!havePref || !exists) rv = SetDefaultLocalPath(outSpec); diff --git a/mozilla/mailnews/mapi/mapihook/src/msgMapiHook.cpp b/mozilla/mailnews/mapi/mapihook/src/msgMapiHook.cpp index 78e63ecd4da..b13566859f6 100644 --- a/mozilla/mailnews/mapi/mapihook/src/msgMapiHook.cpp +++ b/mozilla/mailnews/mapi/mapihook/src/msgMapiHook.cpp @@ -518,9 +518,9 @@ nsresult nsMapiHook::HandleAttachments (nsIMsgCompFields * aCompFields, PRInt32 { // check if attachment exists if (aIsUnicode) - pFile->InitWithUnicodePath (aFiles[i].lpszPathName) ; + pFile->InitWithPath (NS_ConvertUCS2toUTF8(aFiles[i].lpszPathName)) ; else - pFile->InitWithPath ((char *) aFiles[i].lpszPathName) ; + pFile->InitWithNativePath (nsDependentCString((const char*)aFiles[i].lpszPathName)) ; PRBool bExist ; rv = pFile->Exists(&bExist) ; if (NS_FAILED(rv) || (!bExist) ) return NS_ERROR_FILE_TARGET_DOES_NOT_EXIST ; @@ -540,33 +540,35 @@ nsresult nsMapiHook::HandleAttachments (nsIMsgCompFields * aCompFields, PRInt32 rv = NS_FileSpecToIFile(&tmpDir, getter_AddRefs(pTempPath)) ; if(NS_FAILED(rv) || !pTempPath) return rv ; // temp dir path - nsXPIDLString tempPath ; - rv = pTempPath->GetUnicodePath (getter_Copies(tempPath)) ; + nsCAutoString tempPath ; + rv = pTempPath->GetPath (tempPath) ; if(NS_FAILED(rv) || tempPath.IsEmpty()) return rv ; // filename of the file attachment - nsXPIDLString leafName ; - pFile->GetUnicodeLeafName (getter_Copies(leafName)) ; + nsCAutoString leafName ; + pFile->GetLeafName (leafName) ; if(NS_FAILED(rv) || leafName.IsEmpty()) return rv ; // full path of the file attachment - nsXPIDLString path ; - pFile->GetUnicodePath (getter_Copies(path)) ; + nsCAutoString path ; + pFile->GetPath (path) ; if(NS_FAILED(rv) || path.IsEmpty()) return rv ; // dir path of the file attachment - nsAutoString dirPath (path.get()) ; + nsCAutoString dirPath (path.get()) ; PRInt32 offset = dirPath.Find (leafName.get()) ; if (offset != kNotFound && offset > 1) dirPath.SetLength(offset-1) ; // see if the attachment dir path (only) is same as temp path - if (!Compare(tempPath, dirPath, nsCaseInsensitiveStringComparator())) + // XXX need nsCaseInsensitiveUTF8StringComparator() + if (!Compare(NS_ConvertUTF8toUCS2(tempPath), + NS_ConvertUTF8toUCS2(dirPath), + nsCaseInsensitiveStringComparator())) { // if not already existing, create another temp dir for mapi within Win temp dir - nsAutoString strTempDir ; - strTempDir += tempPath.get() ; + nsCAutoString strTempDir ; // this is windows only so we can do "\\" - strTempDir.AppendWithConversion("\\moz_mapi") ; - pTempDir->InitWithUnicodePath (strTempDir.get()) ; + strTempDir = tempPath + NS_LITERAL_CSTRING("\\moz_mapi"); + pTempDir->InitWithPath (strTempDir) ; pTempDir->Exists (&bExist) ; if (!bExist) { @@ -582,21 +584,25 @@ nsresult nsMapiHook::HandleAttachments (nsIMsgCompFields * aCompFields, PRInt32 // rename or copy the existing temp file with the real file name if (aIsUnicode) { + NS_ConvertUCS2toUTF8 fileNameUTF8(aFiles[i].lpszFileName); // check if the user is sending a temporary unsaved file, in this case // the leaf name of the PathName and the FileName (real filename) would be same // if so copy the file (this will create a copy file) and then send else move would do nothing // and the calling app would delete the file and then send will fail. - if (!Compare(nsDependentString(aFiles[i].lpszFileName), nsDependentString(leafName), nsCaseInsensitiveStringComparator())) + // XXX need nsCaseInsensitiveUTF8StringComparator() + if (!Compare(nsDependentString(aFiles[i].lpszFileName), + NS_ConvertUTF8toUCS2(leafName), + nsCaseInsensitiveStringComparator())) { - rv = pFile->CopyToUnicode(pTempDir, aFiles[i].lpszFileName) ; - pFile->InitWithUnicodePath(strTempDir.get()) ; - pFile->AppendUnicode (aFiles[i].lpszFileName) ; + rv = pFile->CopyTo(pTempDir, fileNameUTF8); + pFile->InitWithPath(strTempDir) ; + pFile->Append(fileNameUTF8); } else { // else if user is sending an already existing file open in the application // just move the file to one with real file name, better performance - rv = pFile->MoveToUnicode(nsnull, aFiles[i].lpszFileName) ; + rv = pFile->MoveTo(nsnull, fileNameUTF8); // now create an empty file with the temp filename so that // the calling apps donot crash if they dont find their temp file if (NS_SUCCEEDED(rv)) @@ -613,18 +619,22 @@ nsresult nsMapiHook::HandleAttachments (nsIMsgCompFields * aCompFields, PRInt32 // convert to Unicode using Platform charset rv = ConvertToUnicode(nsMsgI18NFileSystemCharset(), (char *) aFiles[i].lpszFileName, fileName); if (NS_FAILED(rv)) return rv ; + nsDependentCString fileNameNative((char *) aFiles[i].lpszFileName); // now compare the unicode filename string - if (!Compare(fileName, leafName, nsCaseInsensitiveStringComparator())) + // XXX need nsCaseInsensitiveUTF8StringComparator() + if (!Compare(fileName, + NS_ConvertUTF8toUCS2(leafName), + nsCaseInsensitiveStringComparator())) { - rv = pFile->CopyTo(pTempDir, (char *) aFiles[i].lpszFileName) ; - pFile->InitWithUnicodePath(strTempDir.get()) ; - pFile->Append ((char *) aFiles[i].lpszFileName) ; + rv = pFile->CopyToNative(pTempDir, fileNameNative); + pFile->InitWithPath(strTempDir) ; + pFile->AppendNative (fileNameNative); } else { // else if user is sending an already existing file open in the application // just move the file to one with real file name, better performance - rv = pFile->MoveTo(nsnull, (char *) aFiles[i].lpszFileName) ; + rv = pFile->MoveToNative(nsnull, fileNameNative); // now create an empty file with the temp filename so that // the calling apps donot crash if they dont find their temp file if (NS_SUCCEEDED(rv)) @@ -780,7 +790,7 @@ nsresult nsMapiHook::PopulateCompFieldsForSendDocs(nsIMsgCompFields * aCompField { nsCOMPtr pFile = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID, &rv) ; if (NS_FAILED(rv) || (!pFile) ) return rv ; - pFile->InitWithUnicodePath (strFilePaths.get()) ; + pFile->InitWithPath (NS_ConvertUCS2toUTF8(strFilePaths)) ; PRBool bExist ; rv = pFile->Exists(&bExist) ; @@ -816,7 +826,7 @@ nsresult nsMapiHook::PopulateCompFieldsForSendDocs(nsIMsgCompFields * aCompField newFilePaths += offset + strDelimChars.Length() ; } - pFile->InitWithUnicodePath (RemainingPaths.get()) ; + pFile->InitWithPath (NS_ConvertUCS2toUTF8(RemainingPaths)) ; #ifdef RAJIV_DEBUG printf ("File : %S \n", RemainingPaths.get()) ; diff --git a/mozilla/mailnews/mapi/mapihook/src/nsMapiRegistryUtils.cpp b/mozilla/mailnews/mapi/mapihook/src/nsMapiRegistryUtils.cpp index a7e0895ad60..85c32fb0245 100644 --- a/mozilla/mailnews/mapi/mapihook/src/nsMapiRegistryUtils.cpp +++ b/mozilla/mailnews/mapi/mapihook/src/nsMapiRegistryUtils.cpp @@ -366,7 +366,7 @@ nsresult nsMapiRegistryUtils::CopyMozMapiToWinSysDir() nsCOMPtr pCurrentMapiFile = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID, &rv); if (NS_FAILED(rv) || !pCurrentMapiFile) return rv; - pCurrentMapiFile->InitWithPath(filePath.get()); + pCurrentMapiFile->InitWithNativePath(filePath); nsCOMPtr pMozMapiFile; nsCOMPtr directoryService = @@ -377,7 +377,7 @@ nsresult nsMapiRegistryUtils::CopyMozMapiToWinSysDir() getter_AddRefs(pMozMapiFile)); if (NS_FAILED(rv)) return rv; - pMozMapiFile->Append("mozMapi32.dll"); + pMozMapiFile->Append(NS_LITERAL_CSTRING("mozMapi32.dll")); PRBool bExist; rv = pMozMapiFile->Exists(&bExist); @@ -390,15 +390,15 @@ nsresult nsMapiRegistryUtils::CopyMozMapiToWinSysDir() } if (NS_FAILED(rv)) return rv; filePath.Assign(buffer); - filePath.Append("\\Mapi32.dll"); - pCurrentMapiFile->InitWithPath(filePath.get()); + filePath.Append(NS_LITERAL_CSTRING("\\Mapi32.dll")); + pCurrentMapiFile->InitWithNativePath(filePath); rv = pCurrentMapiFile->Exists(&bExist); if (NS_SUCCEEDED(rv) && bExist) { - rv = pCurrentMapiFile->MoveTo(nsnull, "Mapi32_moz_bak.dll"); + rv = pCurrentMapiFile->MoveTo(nsnull, NS_LITERAL_CSTRING("Mapi32_moz_bak.dll")); if (NS_FAILED(rv)) return rv; nsCAutoString fullFilePath(buffer); - fullFilePath.Append("\\Mapi32_moz_bak.dll"); + fullFilePath.Append(NS_LITERAL_CSTRING("\\Mapi32_moz_bak.dll")); rv = SetRegistryKey(HKEY_LOCAL_MACHINE, "Software\\Mozilla\\Desktop", "Mapi_backup_dll", @@ -409,10 +409,10 @@ nsresult nsMapiRegistryUtils::CopyMozMapiToWinSysDir() } } - NS_NAMED_LITERAL_STRING(fileName, "Mapi32.dll"); + NS_NAMED_LITERAL_CSTRING(fileName, "Mapi32.dll"); filePath.Assign(buffer); - pCurrentMapiFile->InitWithPath(filePath.get()); - rv = pMozMapiFile->CopyToUnicode(pCurrentMapiFile, fileName.get()); + pCurrentMapiFile->InitWithNativePath(filePath); + rv = pMozMapiFile->CopyTo(pCurrentMapiFile, fileName); if (NS_FAILED(rv)) RestoreBackedUpMapiDll(); return rv; @@ -430,16 +430,16 @@ nsresult nsMapiRegistryUtils::RestoreBackedUpMapiDll() nsCAutoString filePath(buffer); nsCAutoString previousFileName(buffer); - filePath.Append("\\Mapi32.dll"); - previousFileName.Append("\\Mapi32_moz_bak.dll"); + filePath.Append(NS_LITERAL_CSTRING("\\Mapi32.dll")); + previousFileName.Append(NS_LITERAL_CSTRING("\\Mapi32_moz_bak.dll")); nsCOMPtr pCurrentMapiFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv); if (NS_FAILED(rv) || !pCurrentMapiFile) return NS_ERROR_FAILURE; - pCurrentMapiFile->InitWithPath(filePath.get()); + pCurrentMapiFile->InitWithNativePath(filePath); nsCOMPtr pPreviousMapiFile = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID, &rv); if (NS_FAILED(rv) || !pPreviousMapiFile) return NS_ERROR_FAILURE; - pPreviousMapiFile->InitWithPath(previousFileName.get()); + pPreviousMapiFile->InitWithNativePath(previousFileName); PRBool bExist; rv = pCurrentMapiFile->Exists(&bExist); @@ -450,7 +450,7 @@ nsresult nsMapiRegistryUtils::RestoreBackedUpMapiDll() rv = pPreviousMapiFile->Exists(&bExist); if (NS_SUCCEEDED(rv) && bExist) - rv = pPreviousMapiFile->MoveTo(nsnull, "Mapi32.dll"); + rv = pPreviousMapiFile->MoveTo(nsnull, NS_LITERAL_CSTRING("Mapi32.dll")); if (NS_SUCCEEDED(rv)) DeleteRegistryValue(HKEY_LOCAL_MACHINE, "Software\\Mozilla\\Desktop", diff --git a/mozilla/mailnews/news/src/nsNntpIncomingServer.cpp b/mozilla/mailnews/news/src/nsNntpIncomingServer.cpp index 05b31adf8a4..71117de1a08 100644 --- a/mozilla/mailnews/news/src/nsNntpIncomingServer.cpp +++ b/mozilla/mailnews/news/src/nsNntpIncomingServer.cpp @@ -271,13 +271,9 @@ nsNntpIncomingServer::GetNewsrcRootPath(nsIFileSpec **aNewsrcRootPath) // Make the resulting nsIFileSpec // TODO: Convert arg to nsILocalFile and avoid this - nsXPIDLCString pathBuf; - rv = localFile->GetPath(getter_Copies(pathBuf)); - if (NS_FAILED(rv)) return rv; nsCOMPtr outSpec; - rv = NS_NewFileSpec(getter_AddRefs(outSpec)); + rv = NS_NewFileSpecFromIFile(localFile, getter_AddRefs(outSpec)); if (NS_FAILED(rv)) return rv; - outSpec->SetNativePath(pathBuf); if (!havePref || !exists) rv = SetNewsrcRootPath(outSpec); diff --git a/mozilla/mailnews/news/src/nsNntpService.cpp b/mozilla/mailnews/news/src/nsNntpService.cpp index e7f5752b95d..e3c63ec7671 100644 --- a/mozilla/mailnews/news/src/nsNntpService.cpp +++ b/mozilla/mailnews/news/src/nsNntpService.cpp @@ -1369,13 +1369,9 @@ nsNntpService::GetDefaultLocalPath(nsIFileSpec ** aResult) // Make the resulting nsIFileSpec // TODO: Convert arg to nsILocalFile and avoid this - nsXPIDLCString pathBuf; - rv = localFile->GetPath(getter_Copies(pathBuf)); - if (NS_FAILED(rv)) return rv; nsCOMPtr outSpec; - rv = NS_NewFileSpec(getter_AddRefs(outSpec)); + rv = NS_NewFileSpecFromIFile(localFile, getter_AddRefs(outSpec)); if (NS_FAILED(rv)) return rv; - outSpec->SetNativePath(pathBuf); if (!havePref || !exists) rv = SetDefaultLocalPath(outSpec); diff --git a/mozilla/modules/libjar/nsJAR.cpp b/mozilla/modules/libjar/nsJAR.cpp index 9424a53485a..db71eec883d 100644 --- a/mozilla/modules/libjar/nsJAR.cpp +++ b/mozilla/modules/libjar/nsJAR.cpp @@ -25,9 +25,9 @@ * Pierre Phaneuf */ #include -#include "nsILocalFile.h" #include "nsJARInputStream.h" #include "nsJAR.h" +#include "nsILocalFile.h" #include "nsXPIDLString.h" #include "nsReadableUtils.h" #include "nsIServiceManager.h" @@ -275,16 +275,15 @@ nsJAR::Extract(const char *zipEntry, nsIFile* outFile) else { #if defined(XP_UNIX) - nsXPIDLCString path; - - rv = outFile->GetPath(getter_Copies(path)); + nsCAutoString path; + rv = outFile->GetNativePath(path); if (NS_SUCCEEDED(rv)) { if (item->flags & ZIFLAG_SYMLINK) { - err = mZip.ResolveSymlink(path,item); + err = mZip.ResolveSymlink(path.get(),item); } - chmod(path, item->mode); + chmod(path.get(), item->mode); } #endif @@ -1205,8 +1204,8 @@ nsZipReaderCache::GetZip(nsIFile* zipFile, nsIZipReader* *result) mZipCacheLookups++; #endif - nsXPIDLCString path; - rv = zipFile->GetPath(getter_Copies(path)); + nsCAutoString path; + rv = zipFile->GetNativePath(path); if (NS_FAILED(rv)) return rv; nsCStringKey key(path); @@ -1329,8 +1328,8 @@ nsZipReaderCache::ReleaseZip(nsJAR* zip) rv = oldest->GetFile(getter_AddRefs(zipFile)); if (NS_FAILED(rv)) return rv; - nsXPIDLCString path; - rv = zipFile->GetPath(getter_Copies(path)); + nsCAutoString path; + rv = zipFile->GetNativePath(path); if (NS_FAILED(rv)) return rv; nsCStringKey key(path); @@ -1338,7 +1337,7 @@ nsZipReaderCache::ReleaseZip(nsJAR* zip) NS_ASSERTION(removed, "botched"); #ifdef xDEBUG_jband - printf("dumped %s from the jar cache\n", (const char*) path); + printf("dumped %s from the jar cache\n", path.get()); #endif return NS_OK; diff --git a/mozilla/modules/libpr0n/decoders/icon/mac/nsIconChannel.cpp b/mozilla/modules/libpr0n/decoders/icon/mac/nsIconChannel.cpp index 770702d9355..409d4e63a6b 100644 --- a/mozilla/modules/libpr0n/decoders/icon/mac/nsIconChannel.cpp +++ b/mozilla/modules/libpr0n/decoders/icon/mac/nsIconChannel.cpp @@ -136,7 +136,7 @@ nsIconChannel::Open(nsIInputStream **_retval) return NS_ERROR_FAILURE; } -nsresult nsIconChannel::ExtractIconInfoFromUrl(nsIFile ** aLocalFile, PRUint32 * aDesiredImageSize, char ** aContentType, char ** aFileExtension) +nsresult nsIconChannel::ExtractIconInfoFromUrl(nsIFile ** aLocalFile, PRUint32 * aDesiredImageSize, nsACString &aContentType, nsACString &aFileExtension) { nsresult rv = NS_OK; nsCOMPtr iconURI (do_QueryInterface(mUrl, &rv)); @@ -251,11 +251,11 @@ nsIconChannel::GetLockedIcons(IconFamilyHandle icnFamily, PRUint32 desiredImageS NS_IMETHODIMP nsIconChannel::AsyncOpen(nsIStreamListener *aListener, nsISupports *ctxt) { nsCOMPtr localFile; // file we want an icon for - nsXPIDLCString contentType; - nsXPIDLCString fileExtension; + nsCAutoString contentType; + nsCAutoString fileExtension; PRUint32 desiredImageSize; nsresult rv = ExtractIconInfoFromUrl(getter_AddRefs(localFile), &desiredImageSize, - getter_Copies(contentType), getter_Copies(fileExtension)); + contentType, fileExtension); if (NS_FAILED(rv)) return(rv); // ensure that we DO NOT resolve aliases, very important for file views @@ -333,13 +333,13 @@ NS_IMETHODIMP nsIconChannel::AsyncOpen(nsIStreamListener *aListener, nsISupports nsCOMPtr mimeInfo; if (mimeService) { - if (*contentType.get()) + if (!contentType.IsEmpty()) { - mimeService->GetFromMIMEType(contentType, getter_AddRefs(mimeInfo)); + mimeService->GetFromMIMEType(contentType.get(), getter_AddRefs(mimeInfo)); } if (!mimeInfo) // try to grab an extension for the dummy file in the url. { - mimeService->GetFromExtension(fileExtension, getter_AddRefs(mimeInfo)); + mimeService->GetFromExtension(fileExtension.get(), getter_AddRefs(mimeInfo)); } } diff --git a/mozilla/modules/libpr0n/decoders/icon/mac/nsIconChannel.h b/mozilla/modules/libpr0n/decoders/icon/mac/nsIconChannel.h index 63d952aabea..74f6011075b 100644 --- a/mozilla/modules/libpr0n/decoders/icon/mac/nsIconChannel.h +++ b/mozilla/modules/libpr0n/decoders/icon/mac/nsIconChannel.h @@ -53,7 +53,7 @@ protected: nsresult mStatus; nsresult ExtractIconInfoFromUrl(nsIFile ** aLocalFile, PRUint32 * aDesiredImageSize, - char ** aContentType, char ** aFileExtension); + nsACString &aContentType, nsACString &aFileExtension); nsresult GetLockedIconData(IconFamilyHandle iconFamilyH, PRUint32 iconType, Handle iconDataH, PRUint32 *iconDataSize); diff --git a/mozilla/modules/libpr0n/decoders/icon/nsIIconURI.idl b/mozilla/modules/libpr0n/decoders/icon/nsIIconURI.idl index f3acea6ea52..c63754a7630 100644 --- a/mozilla/modules/libpr0n/decoders/icon/nsIIconURI.idl +++ b/mozilla/modules/libpr0n/decoders/icon/nsIIconURI.idl @@ -41,6 +41,6 @@ interface nsIMozIconURI : nsIURI attribute nsIURI IconFile; // maybe null if there isn't a real file we are trying to fetch attribute unsigned long imageSize; // measured by # of pixels in a row. defaults to 16. - attribute string contentType; // may be an empty string - readonly attribute string fileExtension; + attribute ACString contentType; // may be an empty string + readonly attribute ACString fileExtension; }; diff --git a/mozilla/modules/libpr0n/decoders/icon/nsIconURI.cpp b/mozilla/modules/libpr0n/decoders/icon/nsIconURI.cpp index 8fa14bba642..632edf89e11 100644 --- a/mozilla/modules/libpr0n/decoders/icon/nsIconURI.cpp +++ b/mozilla/modules/libpr0n/decoders/icon/nsIconURI.cpp @@ -385,21 +385,21 @@ nsMozIconURI::SetImageSize(PRUint32 aImageSize) // measured by # of pixels in a } NS_IMETHODIMP -nsMozIconURI::GetContentType(char ** aContentType) +nsMozIconURI::GetContentType(nsACString &aContentType) { - *aContentType = ToNewCString(mContentType); + aContentType = mContentType; return NS_OK; } NS_IMETHODIMP -nsMozIconURI::SetContentType(const char * aContentType) +nsMozIconURI::SetContentType(const nsACString &aContentType) { mContentType = aContentType; return NS_OK; } NS_IMETHODIMP -nsMozIconURI::GetFileExtension(char ** aFileExtension) +nsMozIconURI::GetFileExtension(nsACString &aFileExtension) { nsCAutoString fileExtension; nsresult rv = NS_OK; @@ -416,11 +416,7 @@ nsMozIconURI::GetFileExtension(char ** aFileExtension) { // unfortunately, this code doesn't give us the required '.' in front of the extension // so we have to do it ourselves.. - nsCAutoString tempFileExt; - tempFileExt = "."; - tempFileExt.Append(fileExt); - - *aFileExtension = ToNewCString(tempFileExt); + aFileExtension = NS_LITERAL_CSTRING(".") + fileExt; return NS_OK; } } @@ -438,7 +434,7 @@ nsMozIconURI::GetFileExtension(char ** aFileExtension) const char * fileExt = strrchr(chFileName, '.'); if (!fileExt) return NS_ERROR_FAILURE; // no file extension to work from. else - *aFileExtension = nsCRT::strdup(fileExt); + aFileExtension = nsDependentCString(fileExt); return NS_OK; } diff --git a/mozilla/modules/libpr0n/decoders/icon/win/nsIconChannel.cpp b/mozilla/modules/libpr0n/decoders/icon/win/nsIconChannel.cpp index 78a9e0ad1db..f7f531f6187 100644 --- a/mozilla/modules/libpr0n/decoders/icon/win/nsIconChannel.cpp +++ b/mozilla/modules/libpr0n/decoders/icon/win/nsIconChannel.cpp @@ -161,7 +161,7 @@ void InvertRows(unsigned char * aInitialBuffer, PRUint32 sizeOfBuffer, PRUint32 nsMemory::Free(temporaryRowHolder); } -nsresult nsIconChannel::ExtractIconInfoFromUrl(nsIFile ** aLocalFile, PRUint32 * aDesiredImageSize, char ** aContentType, char ** aFileExtension) +nsresult nsIconChannel::ExtractIconInfoFromUrl(nsIFile ** aLocalFile, PRUint32 * aDesiredImageSize, nsACString &aContentType, nsACString &aFileExtension) { nsresult rv = NS_OK; nsCOMPtr iconURI (do_QueryInterface(mUrl, &rv)); @@ -298,10 +298,10 @@ void ConvertMaskBitMap(unsigned char * aBitMaskBuffer, PBITMAPINFOHEADER pBitMap NS_IMETHODIMP nsIconChannel::AsyncOpen(nsIStreamListener *aListener, nsISupports *ctxt) { nsXPIDLCString contentType; - nsXPIDLCString filePath; + nsCAutoString filePath; nsCOMPtr localFile; // file we want an icon for PRUint32 desiredImageSize; - nsresult rv = ExtractIconInfoFromUrl(getter_AddRefs(localFile), &desiredImageSize, getter_Copies(contentType), getter_Copies(filePath)); + nsresult rv = ExtractIconInfoFromUrl(getter_AddRefs(localFile), &desiredImageSize, contentType, filePath); NS_ENSURE_SUCCESS(rv, rv); // if the file exists, we are going to use it's real attributes...otherwise we only want to use it for it's extension... @@ -312,7 +312,7 @@ NS_IMETHODIMP nsIconChannel::AsyncOpen(nsIStreamListener *aListener, nsISupports if (localFile) { - localFile->GetPath(getter_Copies(filePath)); + localFile->GetNativePath(filePath); localFile->Exists(&fileExists); } @@ -324,7 +324,7 @@ NS_IMETHODIMP nsIconChannel::AsyncOpen(nsIStreamListener *aListener, nsISupports else infoFlags |= SHGFI_SMALLICON; - if ( (!filePath.get()) && (contentType.get() && *contentType.get()) ) // if we have a content type without a file extension...then use it! + if ( (filePath.IsEmpty()) && (contentType.get() && *contentType.get()) ) // if we have a content type without a file extension...then use it! { nsCOMPtr mimeService (do_GetService(NS_MIMESERVICE_CONTRACTID, &rv)); nsCOMPtr mimeObject; @@ -336,10 +336,7 @@ NS_IMETHODIMP nsIconChannel::AsyncOpen(nsIStreamListener *aListener, nsISupports nsXPIDLCString fileExt; mimeObject->GetPrimaryExtension(getter_Copies(fileExt)); // we need to insert a '.' b4 the extension... - nsCAutoString formattedFileExt; - formattedFileExt = "."; - formattedFileExt.Append(fileExt.get()); - filePath.Assign(formattedFileExt); + filePath = NS_LITERAL_CSTRING(".") + fileExt; } } diff --git a/mozilla/modules/libpr0n/decoders/icon/win/nsIconChannel.h b/mozilla/modules/libpr0n/decoders/icon/win/nsIconChannel.h index 4c129bc9d7c..d617e5f85eb 100644 --- a/mozilla/modules/libpr0n/decoders/icon/win/nsIconChannel.h +++ b/mozilla/modules/libpr0n/decoders/icon/win/nsIconChannel.h @@ -55,7 +55,7 @@ protected: nsCOMPtr mOwner; nsresult mStatus; - nsresult ExtractIconInfoFromUrl(nsIFile ** aLocalFile, PRUint32 * aDesiredImageSize, char ** aContentType, char ** aFileExtension); + nsresult ExtractIconInfoFromUrl(nsIFile ** aLocalFile, PRUint32 * aDesiredImageSize, nsACString &aContentType, nsACString &aFileExtension); }; #endif /* nsIconChannel_h___ */ diff --git a/mozilla/modules/libpref/src/nsPrefBranch.cpp b/mozilla/modules/libpref/src/nsPrefBranch.cpp index 9badeef0b78..e452d4f7c86 100644 --- a/mozilla/modules/libpref/src/nsPrefBranch.cpp +++ b/mozilla/modules/libpref/src/nsPrefBranch.cpp @@ -357,7 +357,7 @@ NS_IMETHODIMP nsPrefBranch::GetComplexValue(const char *aPrefName, const nsIID & return rv; nsCOMPtr theFile; - rv = NS_NewLocalFile(nsnull, PR_TRUE, getter_AddRefs(theFile)); + rv = NS_NewLocalFile(nsCString(), PR_TRUE, getter_AddRefs(theFile)); if (NS_FAILED(rv)) return rv; rv = theFile->SetRelativeDescriptor(fromFile, Substring(++keyEnd, strEnd)); @@ -420,11 +420,11 @@ NS_IMETHODIMP nsPrefBranch::SetComplexValue(const char *aPrefName, const nsIID & if (aType.Equals(NS_GET_IID(nsILocalFile))) { nsCOMPtr file = do_QueryInterface(aValue); - nsXPIDLCString descriptorString; + nsCAutoString descriptorString; - rv = file->GetPersistentDescriptor(getter_Copies(descriptorString)); + rv = file->GetPersistentDescriptor(descriptorString); if (NS_SUCCEEDED(rv)) { - rv = SetCharPref(aPrefName, descriptorString); + rv = SetCharPref(aPrefName, descriptorString.get()); } return rv; } diff --git a/mozilla/modules/libpref/src/nsPrefService.cpp b/mozilla/modules/libpref/src/nsPrefService.cpp index 7ce1b3be587..3e8b930d961 100644 --- a/mozilla/modules/libpref/src/nsPrefService.cpp +++ b/mozilla/modules/libpref/src/nsPrefService.cpp @@ -43,6 +43,7 @@ #include "nsICategoryManager.h" #include "nsIFile.h" #include "nsIFileStreams.h" +#include "nsILocalFile.h" #include "nsIObserverService.h" #include "nsPrefBranch.h" #include "nsXPIDLString.h" @@ -313,7 +314,7 @@ nsresult nsPrefService::UseDefaultPrefFile() // knows about NS_APP_PREFS_50_FILE. Put the file in NS_XPCOM_CURRENT_PROCESS_DIR. rv = NS_GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR, getter_AddRefs(aFile)); if (NS_FAILED(rv)) return rv; - rv = aFile->Append("default_prefs.js"); + rv = aFile->Append(NS_LITERAL_CSTRING("default_prefs.js")); if (NS_FAILED(rv)) return rv; } @@ -333,11 +334,9 @@ nsresult nsPrefService::UseUserPrefFile() nsresult rv = NS_OK; nsCOMPtr aFile; - static const char* userFiles[] = {"user.js"}; - rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(aFile)); if (NS_SUCCEEDED(rv) && aFile) { - rv = aFile->Append(userFiles[0]); + rv = aFile->Append(NS_LITERAL_CSTRING("user.js")); if (NS_SUCCEEDED(rv)) { rv = openPrefFile(aFile, PR_FALSE, PR_FALSE, PR_FALSE); } @@ -409,8 +408,8 @@ static nsresult openPrefFile(nsIFile* aFile, PRBool aIsErrorFatal, #if MOZ_TIMELINE { - nsXPIDLCString str; - aFile->GetPath(getter_Copies(str)); + nsCAutoString str; + aFile->GetNativePath(str); NS_TIMELINE_MARK_FUNCTION1("load pref file", str.get()); } #endif @@ -459,28 +458,24 @@ static nsresult openPrefFile(nsIFile* aFile, PRBool aIsErrorFatal, static int PR_CALLBACK inplaceSortCallback(const void *data1, const void *data2, void *privateData) { - char *name1 = nsnull; - char *name2 = nsnull; + nsCAutoString name1; + nsCAutoString name2; nsIFile *file1= *(nsIFile **)data1; nsIFile *file2= *(nsIFile **)data2; nsresult rv; int sortResult = 0; - rv = file1->GetLeafName(&name1); + rv = file1->GetNativeLeafName(name1); NS_ASSERTION(NS_SUCCEEDED(rv),"failed to get the leaf name"); if (NS_SUCCEEDED(rv)) { - rv = file2->GetLeafName(&name2); + rv = file2->GetNativeLeafName(name2); NS_ASSERTION(NS_SUCCEEDED(rv),"failed to get the leaf name"); if (NS_SUCCEEDED(rv)) { - if (name1 && name2) { + if (!name1.IsEmpty() && !name2.IsEmpty()) { // we want it so foo.js will come before foo-.js // "foo." is before "foo-", so we have to reverse the order to accomplish - sortResult = PL_strcmp(name2,name1); + sortResult = Compare(name2, name1); // XXX i18n } - if (name1) - nsCRT::free((char*)name1); - if (name2) - nsCRT::free((char*)name2); } } return sortResult; @@ -544,20 +539,20 @@ JSBool pref_InitInitialObjects() while (hasMoreElements) { PRBool shouldParse = PR_TRUE; - char* leafName; + nsCAutoString leafName; dirIterator->GetNext(getter_AddRefs(aFile)); dirIterator->HasMoreElements(&hasMoreElements); - rv = aFile->GetLeafName(&leafName); + rv = aFile->GetNativeLeafName(leafName); if (NS_SUCCEEDED(rv)) { // Skip non-js files - if (PL_strstr(leafName, ".js") + PL_strlen(".js") != leafName + PL_strlen(leafName)) + if ((leafName.Length() < 3) || !Substring(leafName, leafName.Length() - 3, 3).Equals(NS_LITERAL_CSTRING(".js"))) shouldParse = PR_FALSE; // Skip files in the special list. if (shouldParse) { for (int j = 0; j < (int) (sizeof(specialFiles) / sizeof(char *)); j++) - if (!PL_strcmp(leafName, specialFiles[j])) + if (!strcmp(leafName.get(), specialFiles[j])) shouldParse = PR_FALSE; } if (shouldParse) { @@ -571,8 +566,6 @@ JSBool pref_InitInitialObjects() } } } - if (leafName) - nsCRT::free((char*)leafName); } }; @@ -592,7 +585,7 @@ JSBool pref_InitInitialObjects() // because SetLeafName will not work here. rv = defaultPrefDir->Clone(getter_AddRefs(aFile)); if (NS_SUCCEEDED(rv)) { - rv = aFile->Append((char*)specialFiles[k]); + rv = aFile->Append(nsDependentCString(specialFiles[k])); if (NS_SUCCEEDED(rv)) { rv = openPrefFile(aFile, PR_FALSE, PR_FALSE, PR_FALSE); NS_ASSERTION(NS_SUCCEEDED(rv), ".js was not parsed successfully"); diff --git a/mozilla/modules/libpref/src/nsSafeSaveFile.cpp b/mozilla/modules/libpref/src/nsSafeSaveFile.cpp index 2e8fa8f4bf1..b34a97f9987 100644 --- a/mozilla/modules/libpref/src/nsSafeSaveFile.cpp +++ b/mozilla/modules/libpref/src/nsSafeSaveFile.cpp @@ -40,7 +40,7 @@ #include "prmem.h" // Definitions -#define BACKUP_FILE_EXTENSION ".bak" +#define BACKUP_FILE_EXTENSION NS_LITERAL_CSTRING(".bak") nsSafeSaveFile::nsSafeSaveFile(nsIFile *aTargetFile, PRInt32 aNumBackupCopies) @@ -52,7 +52,7 @@ nsSafeSaveFile::nsSafeSaveFile(nsIFile *aTargetFile, PRInt32 aNumBackupCopies) nsresult rv; // determine the actual filename (less the extension) - rv = aTargetFile->GetLeafName(getter_Copies(mTargetFileName)); + rv = aTargetFile->GetLeafName(mTargetFileName); if (NS_FAILED(rv)) // yikes! out of memory return; @@ -60,14 +60,13 @@ nsSafeSaveFile::nsSafeSaveFile(nsIFile *aTargetFile, PRInt32 aNumBackupCopies) if (temp) mTargetNameLen = temp - mTargetFileName.get(); else - mTargetNameLen = strlen(mTargetFileName.get()); + mTargetNameLen = mTargetFileName.Length(); // create a new file object that points to the temp file - tempFileName.Assign(mTargetFileName.get(), mTargetNameLen); - tempFileName += ".tmp"; + tempFileName = Substring(mTargetFileName, 0, mTargetNameLen) + NS_LITERAL_CSTRING(".tmp"); rv = aTargetFile->Clone(getter_AddRefs(mTempFile)); if (NS_SUCCEEDED(rv)) - mTempFile->SetLeafName(tempFileName.get()); + mTempFile->SetLeafName(tempFileName); } void nsSafeSaveFile::CleanupFailedSave(void) @@ -80,7 +79,7 @@ void nsSafeSaveFile::CleanupFailedSave(void) nsresult nsSafeSaveFile::GetSaveFile(nsIFile **_retval) { - if (!mTargetFileName || !mTempFile) + if (mTargetFileName.IsEmpty() || !mTempFile) return(NS_ERROR_OUT_OF_MEMORY); *_retval = mTempFile; @@ -104,14 +103,13 @@ nsresult nsSafeSaveFile::PostProcessSave(void) if (mBackupCount > 0) { // kill the (oldest) backup copy, if necessary - fileName.Assign(mTargetFileName.get(), mTargetNameLen); - fileName += BACKUP_FILE_EXTENSION; + fileName = Substring(mTargetFileName, 0, mTargetNameLen) + BACKUP_FILE_EXTENSION; if (mBackupCount > 1) fileName.AppendInt(mBackupCount - 1); - backupFile->SetLeafName(fileName.get()); + backupFile->SetLeafName(fileName); } else { // no backups desired, delete the previous save - backupFile->SetLeafName(mTargetFileName.get()); + backupFile->SetLeafName(mTargetFileName); } // remove the file as determined by the logic above @@ -120,32 +118,31 @@ nsresult nsSafeSaveFile::PostProcessSave(void) // now manage the backup copies if (mBackupCount > 0) { PRInt32 backupCount = mBackupCount; - fileName.Assign(mTargetFileName.get(), mTargetNameLen); - fileName += BACKUP_FILE_EXTENSION; + fileName = Substring(mTargetFileName, 0, mTargetNameLen) + BACKUP_FILE_EXTENSION; while (--backupCount > 0) { // bump all of the redundant backups up one (i.e. bak -> bak1, bak1 -> bak2, etc.) if (backupCount > 1) fileName.AppendInt(backupCount - 1); - backupFile->SetLeafName(fileName.get()); + backupFile->SetLeafName(fileName); backupFile->Exists(&bExists); if (bExists) { fileName.Truncate(mTargetNameLen + (sizeof(BACKUP_FILE_EXTENSION) - 1)); fileName.AppendInt(backupCount); // fail silently because it's not important enough to bail on the save for - backupFile->MoveTo(0, fileName.get()); + backupFile->MoveTo(0, fileName); } fileName.Truncate(mTargetNameLen + (sizeof(BACKUP_FILE_EXTENSION) - 1)); }; // rename the previous save to .bak (i.e. to ) - backupFile->SetLeafName(mTargetFileName.get()); - rv = backupFile->MoveTo(0, fileName.get()); + backupFile->SetLeafName(mTargetFileName); + rv = backupFile->MoveTo(0, fileName); if (NS_FAILED(rv)) return rv; } // finally rename the temp file to the original name (i.e. to ) - rv = mTempFile->MoveTo(0, mTargetFileName.get()); + rv = mTempFile->MoveTo(0, mTargetFileName); return rv; } @@ -166,12 +163,11 @@ nsresult nsSafeSaveFile::PurgeOldestBackup(void) return NS_ERROR_FILE_NOT_FOUND; PRInt32 backupCount = mBackupCount; - fileName.Assign(mTargetFileName.get(), mTargetNameLen); - fileName += BACKUP_FILE_EXTENSION; + fileName = Substring(mTargetFileName, 0, mTargetNameLen) + BACKUP_FILE_EXTENSION; while (--backupCount >= 0) { if (backupCount) fileName.AppendInt(backupCount); - backupFile->SetLeafName(fileName.get()); + backupFile->SetLeafName(fileName); rv = backupFile->Remove(PR_FALSE); if (NS_SUCCEEDED(rv)) { return NS_OK; diff --git a/mozilla/modules/libpref/src/nsSafeSaveFile.h b/mozilla/modules/libpref/src/nsSafeSaveFile.h index 3cfb01633e4..156de76ecee 100644 --- a/mozilla/modules/libpref/src/nsSafeSaveFile.h +++ b/mozilla/modules/libpref/src/nsSafeSaveFile.h @@ -38,7 +38,6 @@ #include "nsIFile.h" #include "nsString.h" -#include "nsXPIDLString.h" class nsSafeSaveFile { public: @@ -55,7 +54,7 @@ class nsSafeSaveFile { private: nsCOMPtr mTempFile; - nsXPIDLCString mTargetFileName; + nsCString mTargetFileName; // UTF-8 PRInt32 mTargetNameLen; PRInt32 mBackupCount; }; diff --git a/mozilla/modules/libreg/xpcom/nsIRegistry.idl b/mozilla/modules/libreg/xpcom/nsIRegistry.idl index 78b3ba67f76..36d4c641a15 100644 --- a/mozilla/modules/libreg/xpcom/nsIRegistry.idl +++ b/mozilla/modules/libreg/xpcom/nsIRegistry.idl @@ -18,6 +18,8 @@ #include "nsISupports.idl" #include "nsIEnumerator.idl" +interface nsIFile; + typedef PRUint32 nsRegistryKey; typedef long nsWellKnownRegistry; @@ -35,7 +37,7 @@ interface nsIRegistry : nsISupports // Dont use this one. This for internal use only. const long ApplicationCustomRegistry = -1; - void open(in string regFile); + void open(in nsIFile regFile); void openWellKnownRegistry(in nsWellKnownRegistry regid); void flush(); diff --git a/mozilla/modules/libreg/xpcom/nsRegistry.cpp b/mozilla/modules/libreg/xpcom/nsRegistry.cpp index 6160338ec6e..3592cda4db4 100644 --- a/mozilla/modules/libreg/xpcom/nsRegistry.cpp +++ b/mozilla/modules/libreg/xpcom/nsRegistry.cpp @@ -367,7 +367,7 @@ NS_IMPL_ISUPPORTS1( nsRegistryValue, nsIRegistryValue ) | Vanilla nsRegistry constructor. | ------------------------------------------------------------------------------*/ nsRegistry::nsRegistry() - : mReg(0), mCurRegFile(nsnull), mCurRegID(0) { + : mReg(0), mCurRegID(0) { NS_INIT_REFCNT(); #ifdef EXTRA_THREADSAFE mregLock = PR_NewLock(); @@ -382,8 +382,6 @@ nsRegistry::~nsRegistry() { if( mReg ) { Close(); } - if (mCurRegFile) - nsCRT::free(mCurRegFile); #ifdef EXTRA_THREADSAFE if (mregLock) { PR_DestroyLock(mregLock); @@ -397,7 +395,7 @@ nsRegistry::~nsRegistry() { | file. We first check to see if a registry file is already open and close | | it if so. | ------------------------------------------------------------------------------*/ -NS_IMETHODIMP nsRegistry::Open( const char *regFile ) { +NS_IMETHODIMP nsRegistry::Open( nsIFile *regFile ) { REGERR err = REGERR_OK; // Check for default. @@ -405,8 +403,12 @@ NS_IMETHODIMP nsRegistry::Open( const char *regFile ) { return OpenWellKnownRegistry(nsIRegistry::ApplicationRegistry); } + nsCAutoString regPath; + nsresult rv = regFile->GetNativePath(regPath); + if (NS_FAILED(rv)) return rv; + #ifdef DEBUG_dp - printf("nsRegistry: Opening registry %s\n", regFile); + printf("nsRegistry: Opening registry %s\n", regPath.get()); #endif /* DEBUG_dp */ if (mCurRegID != nsIRegistry::None && mCurRegID != nsIRegistry::ApplicationCustomRegistry) @@ -418,7 +420,8 @@ NS_IMETHODIMP nsRegistry::Open( const char *regFile ) { // Do we have an open registry ? if (mCurRegID != nsIRegistry::None) { - if (mCurRegFile && !nsCRT::strcmp(regFile, mCurRegFile)) + PRBool equals; + if (mCurRegFile && NS_SUCCEEDED(mCurRegFile->Equals(regFile, &equals)) && equals) { // The right one is already open return NS_OK; @@ -433,12 +436,14 @@ NS_IMETHODIMP nsRegistry::Open( const char *regFile ) { // Open specified registry. PR_Lock(mregLock); - err = NR_RegOpen((char*)regFile, &mReg ); + err = NR_RegOpen(NS_CONST_CAST(char*,regPath.get()), &mReg); PR_Unlock(mregLock); mCurRegID = nsIRegistry::ApplicationCustomRegistry; + // No error checking for no mem. Trust me. - mCurRegFile = nsCRT::strdup(regFile); + if (NS_FAILED(regFile->Clone(getter_AddRefs(mCurRegFile)))) + mCurRegFile = nsnull; // not fatal // Convert the result. return regerr2nsresult( err ); @@ -521,7 +526,7 @@ NS_IMETHODIMP nsRegistry::OpenWellKnownRegistry( nsWellKnownRegistry regid ) nsCOMPtr registryLocation; PRBool foundReg = PR_FALSE; - char *regFile = nsnull; + nsCAutoString regFile; switch ( (nsWellKnownRegistry) regid ) { case ApplicationComponentRegistry: @@ -539,11 +544,11 @@ NS_IMETHODIMP nsRegistry::OpenWellKnownRegistry( nsWellKnownRegistry regid ) if (registryLocation) { foundReg = PR_TRUE; - registryLocation->GetPath(®File); // dougt fix... + rv = registryLocation->GetNativePath(regFile); // dougt fix... // dveditz needs to fix his registry so that I can pass an // nsIFile interface and not hack - if (!regFile) - return NS_ERROR_OUT_OF_MEMORY; + if (NS_FAILED(rv)) + return rv; } } @@ -563,11 +568,11 @@ NS_IMETHODIMP nsRegistry::OpenWellKnownRegistry( nsWellKnownRegistry regid ) if (registryLocation) { foundReg = PR_TRUE; - registryLocation->GetPath(®File); // dougt fix... + rv = registryLocation->GetNativePath(regFile); // dougt fix... // dveditz needs to fix his registry so that I can pass an // nsIFile interface and not hack - if (!regFile) - return NS_ERROR_OUT_OF_MEMORY; + if (NS_FAILED(rv)) + return rv; } } break; @@ -581,16 +586,13 @@ NS_IMETHODIMP nsRegistry::OpenWellKnownRegistry( nsWellKnownRegistry regid ) } #ifdef DEBUG_dp - printf("nsRegistry: Opening std registry %s\n", regFile); + printf("nsRegistry: Opening std registry %s\n", regFile.get()); #endif /* DEBUG_dp */ PR_Lock(mregLock); - err = NR_RegOpen((char*)regFile, &mReg ); + err = NR_RegOpen((char*)regFile.get(), &mReg ); PR_Unlock(mregLock); - if (regFile) - nsMemory::Free(regFile); - // Store the registry that was opened for optimizing future opens. mCurRegID = regid; @@ -618,8 +620,6 @@ NS_IMETHODIMP nsRegistry::Close() { err = NR_RegClose( mReg ); PR_Unlock(mregLock); mReg = 0; - if (mCurRegFile) - nsCRT::free(mCurRegFile); mCurRegFile = nsnull; mCurRegID = 0; } diff --git a/mozilla/modules/libreg/xpcom/nsRegistry.h b/mozilla/modules/libreg/xpcom/nsRegistry.h index b70cfb4ac0b..26164cccfe6 100644 --- a/mozilla/modules/libreg/xpcom/nsRegistry.h +++ b/mozilla/modules/libreg/xpcom/nsRegistry.h @@ -42,6 +42,8 @@ #include "nsIRegistry.h" #include "NSReg.h" +#include "nsIFile.h" +#include "nsCOMPtr.h" struct nsRegistry : public nsIRegistry, nsIRegistryGetter { // This class implements the nsISupports interface functions. @@ -64,7 +66,7 @@ protected: #ifdef EXTRA_THREADSAFE PRLock *mregLock; // libreg isn't threadsafe. Use locks to synchronize. #endif - char *mCurRegFile; // these are to prevent open from opening the registry again + nsCOMPtr mCurRegFile; // these are to prevent open from opening the registry again nsWellKnownRegistry mCurRegID; NS_IMETHOD Close(); diff --git a/mozilla/modules/mpfilelocprovider/public/nsMPFileLocProvider.h b/mozilla/modules/mpfilelocprovider/public/nsMPFileLocProvider.h index 8885297b056..cc0e8611720 100755 --- a/mozilla/modules/mpfilelocprovider/public/nsMPFileLocProvider.h +++ b/mozilla/modules/mpfilelocprovider/public/nsMPFileLocProvider.h @@ -63,7 +63,7 @@ class nsMPFileLocProvider: public nsIDirectoryServiceProvider Initialize: Must be called after constructor. profileParentDir -> The directory that is the parent dir of our profile folder. - profileDirName -> The leaf name of our profile folder. + profileDirName -> The leaf name of our profile folder (native charset). */ virtual nsresult Initialize(nsIFile* profileParentDir, const char *profileDirName); diff --git a/mozilla/modules/mpfilelocprovider/src/nsMPFileLocProvider.cpp b/mozilla/modules/mpfilelocprovider/src/nsMPFileLocProvider.cpp index 19b31edde61..f6379d471cc 100755 --- a/mozilla/modules/mpfilelocprovider/src/nsMPFileLocProvider.cpp +++ b/mozilla/modules/mpfilelocprovider/src/nsMPFileLocProvider.cpp @@ -157,19 +157,19 @@ NS_IMPL_THREADSAFE_ISUPPORTS1(nsMPFileLocProvider, nsIDirectoryServiceProvider) // File Name Defines - Copied straight from nsProfile -#define PREFS_FILE_50_NAME "prefs.js" -#define USER_CHROME_DIR_50_NAME "chrome" -#define LOCAL_STORE_FILE_50_NAME "localstore.rdf" -#define HISTORY_FILE_50_NAME "history.dat" -#define PANELS_FILE_50_NAME "panels.rdf" -#define MIME_TYPES_FILE_50_NAME "mimeTypes.rdf" -#define BOOKMARKS_FILE_50_NAME "bookmarks.html" -#define DOWNLOADS_FILE_50_NAME "downloads.rdf" -#define SEARCH_FILE_50_NAME "search.rdf" -#define MAIL_DIR_50_NAME "Mail" -#define IMAP_MAIL_DIR_50_NAME "ImapMail" -#define NEWS_DIR_50_NAME "News" -#define MSG_FOLDER_CACHE_DIR_50_NAME "panacea.dat" +#define PREFS_FILE_50_NAME NS_LITERAL_CSTRING("prefs.js") +#define USER_CHROME_DIR_50_NAME NS_LITERAL_CSTRING("chrome") +#define LOCAL_STORE_FILE_50_NAME NS_LITERAL_CSTRING("localstore.rdf") +#define HISTORY_FILE_50_NAME NS_LITERAL_CSTRING("history.dat") +#define PANELS_FILE_50_NAME NS_LITERAL_CSTRING("panels.rdf") +#define MIME_TYPES_FILE_50_NAME NS_LITERAL_CSTRING("mimeTypes.rdf") +#define BOOKMARKS_FILE_50_NAME NS_LITERAL_CSTRING("bookmarks.html") +#define DOWNLOADS_FILE_50_NAME NS_LITERAL_CSTRING("downloads.rdf") +#define SEARCH_FILE_50_NAME NS_LITERAL_CSTRING("search.rdf" ) +#define MAIL_DIR_50_NAME NS_LITERAL_CSTRING("Mail") +#define IMAP_MAIL_DIR_50_NAME NS_LITERAL_CSTRING("ImapMail") +#define NEWS_DIR_50_NAME NS_LITERAL_CSTRING("News") +#define MSG_FOLDER_CACHE_DIR_50_NAME NS_LITERAL_CSTRING("panacea.dat") NS_IMETHODIMP nsMPFileLocProvider::GetFile(const char *prop, PRBool *persistant, nsIFile **_retval) @@ -341,14 +341,14 @@ nsresult RecursiveCopy(nsIFile* srcDir, nsIFile* destDir) if (NS_SUCCEEDED(rv)) { nsCOMPtr newChild(do_QueryInterface(destClone)); - nsXPIDLCString leafName; - dirEntry->GetLeafName(getter_Copies(leafName)); + nsCAutoString leafName; + dirEntry->GetLeafName(leafName); newChild->AppendRelativePath(leafName); rv = RecursiveCopy(dirEntry, newChild); } } else - rv = dirEntry->CopyTo(destDir, nsnull); + rv = dirEntry->CopyTo(destDir, nsCString()); } } @@ -372,7 +372,7 @@ nsresult nsMPFileLocProvider::InitProfileDir(nsIFile *profileParentDir, rv = profileParentDir->Clone(getter_AddRefs(profileDir)); if (NS_FAILED(rv)) return rv; - rv = profileDir->Append(profileDirName); + rv = profileDir->AppendNative(nsDependentCString(profileDirName)); if (NS_FAILED(rv)) return rv; PRBool exists; diff --git a/mozilla/modules/plugin/base/src/nsIPluginHost.h b/mozilla/modules/plugin/base/src/nsIPluginHost.h index f44d54f8f1f..708f3d8c0ed 100644 --- a/mozilla/modules/plugin/base/src/nsIPluginHost.h +++ b/mozilla/modules/plugin/base/src/nsIPluginHost.h @@ -142,7 +142,7 @@ NS_NewPluginPostDataStream(nsIInputStream **result, } else { nsCOMPtr file; // tmp file will be deleted on release of stream nsCOMPtr fileStream; - if (NS_SUCCEEDED(rv = NS_NewLocalFile(data, PR_FALSE, getter_AddRefs(file))) && + if (NS_SUCCEEDED(rv = NS_NewNativeLocalFile(nsDependentCString(data), PR_FALSE, getter_AddRefs(file))) && NS_SUCCEEDED(rv = NS_NewLocalFileInputStream(getter_AddRefs(fileStream), file, PR_RDONLY, diff --git a/mozilla/modules/plugin/base/src/nsPluginDirServiceProvider.cpp b/mozilla/modules/plugin/base/src/nsPluginDirServiceProvider.cpp index 48fa66a1691..ab5ac63b321 100644 --- a/mozilla/modules/plugin/base/src/nsPluginDirServiceProvider.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginDirServiceProvider.cpp @@ -40,6 +40,7 @@ #include "nsCRT.h" #include "nsILocalFile.h" +#include "nsDependentString.h" #if defined (XP_WIN) #include @@ -109,7 +110,7 @@ nsPluginDirServiceProvider::GetFile(const char *prop, PRBool *persistant, nsIFil result = ::RegQueryValueEx(keyloc, "Plugins Directory", NULL, &type, (LPBYTE)&path, &pathlen); if (result == ERROR_SUCCESS) - rv = NS_NewLocalFile(path, PR_TRUE, getter_AddRefs(localFile)); + rv = NS_NewNativeLocalFile(nsDependentCString(path), PR_TRUE, getter_AddRefs(localFile)); ::RegCloseKey(keyloc); } } @@ -176,7 +177,7 @@ nsPluginDirServiceProvider::GetFile(const char *prop, PRBool *persistant, nsIFil if (newestPath[0] != 0) { PL_strcat(newestPath,"\\bin"); - rv = NS_NewLocalFile(newestPath, PR_TRUE, getter_AddRefs(localFile)); + rv = NS_NewNativeLocalFile(nsDependentCString(newestPath), PR_TRUE, getter_AddRefs(localFile)); } #endif } diff --git a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp index 39d3bcc2f7e..951800f8b0b 100644 --- a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp @@ -187,7 +187,7 @@ // this is the name of the directory which will be created // to cache temporary files. -static const char *kPluginTmpDirName = "plugtmp"; +#define kPluginTmpDirName NS_LITERAL_CSTRING("plugtmp") // Version of cached plugin info // 0.01 first implementation @@ -1175,10 +1175,10 @@ public: MakeByteRangeString(nsByteRange* aRangeList, nsACString &string, PRInt32 *numRequests); void - SetLocalCachedFile(const char* path); + SetLocalCachedFile(nsIFile *file); void - GetLocalCachedFile(char** path); + GetLocalCachedFile(nsIFile** file); void SetLocalCachedFileStream(nsIOutputStream *stream); @@ -1190,7 +1190,7 @@ private: char* mContentType; char* mURL; - char* mFilePath; + nsCOMPtr mCachedFile; PRBool mSeekable; PRUint32 mLength; PRUint32 mModified; @@ -1231,11 +1231,11 @@ public: nsresult InitializeFullPage(nsIPluginInstance *aInstance); - nsresult OnFileAvailable(const char* aFilename); + nsresult OnFileAvailable(nsIFile* aFile); nsILoadGroup* GetLoadGroup(); - nsresult SetLocalFile(const char* aFilename); + nsresult SetLocalFile(nsIFile* aFile); private: nsresult SetUpCache(nsIURI* aURL); // todo: see about removing this... @@ -1269,7 +1269,7 @@ private: nsIPluginHost *mHost; // local file which was used to post data and which should be deleted after that - char *mLocalFile; + nsCOMPtr mLocalFile; nsHashtable *mDataForwardToRequest; public: @@ -1289,7 +1289,6 @@ nsPluginStreamInfo::nsPluginStreamInfo() mContentType = nsnull; mURL = nsnull; - mFilePath = nsnull; mSeekable = PR_FALSE; mLength = 0; mModified = 0; @@ -1312,17 +1311,10 @@ nsPluginStreamInfo::~nsPluginStreamInfo() mFileCacheOutputStream->Close(); // ONLY delete our cached file if we created it - if(mLocallyCached && mFilePath) + if(mLocallyCached && mCachedFile) { - nsCOMPtr localFile; - nsresult res = NS_NewLocalFile(mFilePath, - PR_FALSE, - getter_AddRefs(localFile)); - if(NS_SUCCEEDED(res)) - localFile->Remove(PR_FALSE); + mCachedFile->Remove(PR_FALSE); } - if (mFilePath) - PL_strfree(mFilePath); NS_IF_RELEASE(mPluginInstance); } @@ -1569,23 +1561,18 @@ nsPluginStreamInfo::SetURL(const char* url) //////////////////////////////////////////////////////////////////////// void -nsPluginStreamInfo::SetLocalCachedFile(const char* path) +nsPluginStreamInfo::SetLocalCachedFile(nsIFile* file) { - if(mFilePath != nsnull) - PL_strfree(mFilePath); - - mFilePath = PL_strdup(path); + file->Clone(getter_AddRefs(mCachedFile)); } //////////////////////////////////////////////////////////////////////// void -nsPluginStreamInfo::GetLocalCachedFile(char** path) +nsPluginStreamInfo::GetLocalCachedFile(nsIFile** file) { - if (mFilePath) - *path = PL_strdup(mFilePath); - else - *path = nsnull; + *file = mCachedFile; + NS_IF_ADDREF(*file); } @@ -1718,7 +1705,6 @@ nsPluginStreamListenerPeer::nsPluginStreamListenerPeer() mHost = nsnull; mStreamType = nsPluginStreamType_Normal; mStartBinding = PR_FALSE; - mLocalFile = nsnull; mAbort = PR_FALSE; mRequestFailed = PR_FALSE; @@ -1735,8 +1721,11 @@ nsPluginStreamListenerPeer::~nsPluginStreamListenerPeer() nsCAutoString urlSpec; if(mURL != nsnull) (void)mURL->GetSpec(urlSpec); + nsCAutoString filePath; + if(mLocalFile != nsnull) (void)mLocalFile->GetNativePath(filePath); + PR_LOG(nsPluginLogging::gPluginLog, PLUGIN_LOG_NORMAL, - ("nsPluginStreamListenerPeer::dtor this=%p, url=%s, POST_file=%s\n",this, urlSpec.get(), mLocalFile)); + ("nsPluginStreamListenerPeer::dtor this=%p, url=%s, POST_file=%s\n",this, urlSpec.get(), filePath.get())); PR_LogFlush(); #endif @@ -1751,13 +1740,8 @@ nsPluginStreamListenerPeer::~nsPluginStreamListenerPeer() // if we have mLocalFile (temp file used to post data) it should be // safe to delete it now, and hopefully the owner doesn't hold it. if(mLocalFile) - { - nsCOMPtr localFile; - nsresult res = NS_NewLocalFile(mLocalFile, PR_FALSE, getter_AddRefs(localFile)); - if(NS_SUCCEEDED(res)) - localFile->Remove(PR_FALSE); - delete [] mLocalFile; - } + mLocalFile->Remove(PR_FALSE); + delete mDataForwardToRequest; } @@ -1931,18 +1915,15 @@ nsPluginStreamListenerPeer::SetupPluginCacheFile(nsIChannel* channel) if (NS_FAILED(rv)) return rv; // Create a file to save our stream into. Should we scramble the name? - rv = pluginTmp->Append(filename.get()); + rv = pluginTmp->AppendNative(filename); if (NS_FAILED(rv)) return rv; // Yes, make it unique. rv = pluginTmp->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0777); if (NS_FAILED(rv)) return rv; - // save the file path off. - nsXPIDLCString saveToFilename; - (void) pluginTmp->GetPath(getter_Copies(saveToFilename)); - - mPluginStreamInfo->SetLocalCachedFile(saveToFilename); + // save the file. + mPluginStreamInfo->SetLocalCachedFile(pluginTmp); // create a file output stream to write to... nsCOMPtr outstream; @@ -2102,7 +2083,7 @@ nsPluginStreamListenerPeer::OnStartRequest(nsIRequest *request, nsISupports* aCo // it's possible for the server to not send a Content-Length. We should // still work in this case. if (NS_FAILED(rv)) { - mPluginStreamInfo->SetLength(-1); + mPluginStreamInfo->SetLength(PRUint32(-1)); } else { mPluginStreamInfo->SetLength(length); @@ -2355,11 +2336,10 @@ NS_IMETHODIMP nsPluginStreamListenerPeer::OnStopRequest(nsIRequest *request, return NS_OK; } - nsXPIDLCString pathAndFilename; - mPluginStreamInfo->GetLocalCachedFile(getter_Copies(pathAndFilename)); + nsCOMPtr localFile; + mPluginStreamInfo->GetLocalCachedFile(getter_AddRefs(localFile)); - if (!pathAndFilename) { - nsCOMPtr localFile; + if (!localFile) { nsCOMPtr cacheChannel = do_QueryInterface(request); if (cacheChannel) { cacheChannel->GetCacheFile(getter_AddRefs(localFile)); @@ -2370,13 +2350,10 @@ NS_IMETHODIMP nsPluginStreamListenerPeer::OnStopRequest(nsIRequest *request, fileChannel->GetFile(getter_AddRefs(localFile)); } } - if (localFile) { - localFile->GetPath(getter_Copies(pathAndFilename)); - } } - if (pathAndFilename && *pathAndFilename) { - OnFileAvailable(pathAndFilename); + if (localFile) { + OnFileAvailable(localFile); } if (mStartBinding) @@ -2443,9 +2420,9 @@ nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIRequest *request, // set seekability (seekable if the stream has a known length and if the // http server accepts byte ranges). PRBool bSeekable = PR_FALSE; - PRUint32 length = -1; + PRUint32 length = PRUint32(-1); mPluginStreamInfo->GetLength(&length); - if ((length != -1) && httpChannel) + if ((length != PRUint32(-1)) && httpChannel) { nsCAutoString range; if(NS_SUCCEEDED(httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("accept-ranges"), range))) @@ -2507,13 +2484,22 @@ nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIRequest *request, //////////////////////////////////////////////////////////////////////// nsresult -nsPluginStreamListenerPeer::OnFileAvailable(const char* aFilename) +nsPluginStreamListenerPeer::OnFileAvailable(nsIFile* aFile) { nsresult rv; if (!mPStreamListener) return NS_ERROR_FAILURE; - rv = mPStreamListener->OnFileAvailable((nsIPluginStreamInfo*)mPluginStreamInfo, aFilename); + nsCAutoString path; + rv = aFile->GetNativePath(path); + if (NS_FAILED(rv)) return rv; + + if (path.IsEmpty()) { + NS_WARNING("empty path"); + return NS_OK; + } + + rv = mPStreamListener->OnFileAvailable((nsIPluginStreamInfo*)mPluginStreamInfo, path.get()); return rv; } @@ -2547,25 +2533,18 @@ nsPluginStreamListenerPeer::VisitHeader(const nsACString &header, const nsACStri //////////////////////////////////////////////////////////////////////// -nsresult nsPluginStreamListenerPeer::SetLocalFile(const char* aFilename) +nsresult nsPluginStreamListenerPeer::SetLocalFile(nsIFile* aFile) { - NS_ENSURE_ARG_POINTER(aFilename); - nsresult rv = NS_OK; + NS_ENSURE_ARG_POINTER(aFile); if(mLocalFile) { NS_ASSERTION(!mLocalFile, "nsPluginStreamListenerPeer::SetLocalFile -- path already set, cleaning..."); - delete [] mLocalFile; mLocalFile = nsnull; } - mLocalFile = new char[PL_strlen(aFilename) + 1]; - if(!mLocalFile) - return NS_ERROR_OUT_OF_MEMORY; - - PL_strcpy(mLocalFile, aFilename); - - return rv; + // clone file to prevent it from being changed out from under us + return aFile->Clone(getter_AddRefs(mLocalFile)); } ///////////////////////////////////////////////////////////////////////// @@ -3894,9 +3873,9 @@ NS_IMETHODIMP nsPluginHostImpl::SetUpPluginInstance(const char *aMimeType, if (NS_SUCCEEDED(result)) { - nsXPIDLCString path; - binDirectory->GetPath(getter_Copies(path)); - restoreOrigDir = ::SetCurrentDirectory(path); + nsCAutoString path; + binDirectory->GetNativePath(path); + restoreOrigDir = ::SetCurrentDirectory(path.get()); } } #endif @@ -4732,8 +4711,8 @@ nsresult nsPluginHostImpl::ScanPluginsDirectory(nsIFile * pluginsDir, *aPluginsChanged = PR_FALSE; #ifdef PLUGIN_LOGGING - nsXPIDLCString dirPath; - pluginsDir->GetPath(getter_Copies(dirPath)); + nsCAutoString dirPath; + pluginsDir->GetNativePath(dirPath); PLUGIN_LOG(PLUGIN_LOG_BASIC, ("nsPluginHostImpl::ScanPluginsDirectory dir=%s\n", dirPath.get())); #endif @@ -4751,15 +4730,15 @@ nsresult nsPluginHostImpl::ScanPluginsDirectory(nsIFile * pluginsDir, rv = iter->GetNext(getter_AddRefs(supports)); if (NS_FAILED(rv)) continue; - nsCOMPtr dirEntry(do_QueryInterface(supports, &rv)); + nsCOMPtr dirEntry(do_QueryInterface(supports, &rv)); if (NS_FAILED(rv)) continue; - nsXPIDLCString filePath; - rv = dirEntry->GetPath(getter_Copies(filePath)); + nsCAutoString filePath; + rv = dirEntry->GetNativePath(filePath); if (NS_FAILED(rv)) continue; - nsFileSpec file(filePath); + nsFileSpec file(filePath.get()); PRBool wasSymlink; file.ResolveSymlink(wasSymlink); @@ -5174,10 +5153,8 @@ void nsPluginHostImpl::ClearCachedPluginInfoList() static nsresult cidToDllname(nsIComponentManager* aComponentManager, nsIRegistry* aRegistry, - const char *aCID, char **dllName) + const nsACString &aCID, nsACString &dllName) { - NS_ENSURE_ARG_POINTER(dllName); - // To figure out the filename of the plugin, we'll need to get the // plugin's CID, and then navigate through the XPCOM registry to // pull out the DLL name to which the CID is registered. @@ -5452,13 +5429,13 @@ nsPluginHostImpl::LoadXPCOMPlugins(nsIComponentManager* aComponentManager, nsIFi nsRegistryKey key; node->GetKey(&key); - nsXPIDLCString filename; - rv = cidToDllname(aComponentManager, registry, cid, getter_Copies(filename)); + nsCAutoString filename; + rv = cidToDllname(aComponentManager, registry, cid, filename); if (NS_FAILED(rv)) continue; nsPluginTag* tag = nsnull; - rv = LoadXPCOMPlugin(registry, filename, key, &tag); + rv = LoadXPCOMPlugin(registry, filename.get(), key, &tag); if (NS_FAILED(rv)) continue; @@ -5984,14 +5961,14 @@ NS_IMETHODIMP nsPluginHostImpl::GetProgramPath(const char* *result) nsCOMPtr dirService(do_GetService(kDirectoryServiceContractID, &rv)); if (NS_FAILED(rv)) return rv; - nsCOMPtr programDir; - rv = dirService->Get(NS_XPCOM_CURRENT_PROCESS_DIR, NS_GET_IID(nsIFile), getter_AddRefs(programDir)); + nsCOMPtr programDir; + rv = dirService->Get(NS_XPCOM_CURRENT_PROCESS_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(programDir)); if (NS_FAILED(rv)) return rv; - char *temp; - rv = programDir->GetPath(&temp); - *result = temp; + nsCAutoString temp; + rv = programDir->GetNativePath(temp); + *result = ToNewCString(temp); return rv; } @@ -6006,14 +5983,14 @@ NS_IMETHODIMP nsPluginHostImpl::GetTempDirPath(const char* *result) nsCOMPtr dirService(do_GetService(kDirectoryServiceContractID, &rv)); if (NS_FAILED(rv)) return rv; - nsCOMPtr tempDir; - rv = dirService->Get(NS_OS_TEMP_DIR, NS_GET_IID(nsIFile), getter_AddRefs(tempDir)); + nsCOMPtr tempDir; + rv = dirService->Get(NS_OS_TEMP_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(tempDir)); if (NS_FAILED(rv)) return rv; - char *temp; - rv = tempDir->GetPath(&temp); - *result = temp; + nsCAutoString temp; + rv = tempDir->GetNativePath(temp); + *result = ToNewCString(temp); return rv; } @@ -6404,14 +6381,14 @@ nsPluginHostImpl::CreateTmpFileToPost(const char *postDataURL, char **pTmpFileNa *pTmpFileName = 0; nsresult rv; PRInt64 fileSize; - nsXPIDLCString filename; + nsCAutoString filename; // stat file == get size & convert file:///c:/ to c: if needed nsCOMPtr inFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv); if (NS_FAILED(rv) || (NS_FAILED(rv = NS_InitFileFromURLSpec(inFile, nsDependentCString(postDataURL))) && - NS_FAILED(rv = inFile->InitWithPath(postDataURL))) || + NS_FAILED(rv = inFile->InitWithNativePath(nsDependentCString(postDataURL)))) || NS_FAILED(rv = inFile->GetFileSize(&fileSize)) || - NS_FAILED(rv = inFile->GetPath(getter_Copies(filename))) + NS_FAILED(rv = inFile->GetNativePath(filename)) ) return rv; if (!LL_IS_ZERO(fileSize)) { @@ -6435,11 +6412,9 @@ nsPluginHostImpl::CreateTmpFileToPost(const char *postDataURL, char **pTmpFileNa if (!dirExists) (void) tempFile->Create(nsIFile::DIRECTORY_TYPE, 0600); - nsXPIDLCString inFileName; - inFile->GetLeafName(getter_Copies(inFileName)); - nsCAutoString tempFileName("post-"); - tempFileName += inFileName; - rv = tempFile->Append(tempFileName.get()); + nsCAutoString inFileName; + inFile->GetLeafName(inFileName); + rv = tempFile->Append(NS_LITERAL_CSTRING("post-") + inFileName); if (NS_FAILED(rv)) return rv; @@ -6497,7 +6472,9 @@ nsPluginHostImpl::CreateTmpFileToPost(const char *postDataURL, char **pTmpFileNa inStream->Close(); outStream->Close(); if (NS_SUCCEEDED(rv)) { - tempFile->GetPath(pTmpFileName); + nsCAutoString path; + if (NS_SUCCEEDED(tempFile->GetNativePath(path))) + *pTmpFileName = ToNewCString(path); } } return rv; diff --git a/mozilla/netwerk/base/public/nsNetUtil.h b/mozilla/netwerk/base/public/nsNetUtil.h index 096168ba928..343d9ca0c65 100644 --- a/mozilla/netwerk/base/public/nsNetUtil.h +++ b/mozilla/netwerk/base/public/nsNetUtil.h @@ -276,7 +276,7 @@ NS_MakeAbsoluteURI(nsAString &result, inline nsresult NS_NewPostDataStream(nsIInputStream **result, PRBool isFile, - const char *data, + const nsACString &data, PRUint32 encodeFlags, nsIIOService* ioService = nsnull) // pass in nsIIOService to optimize callers { @@ -297,7 +297,7 @@ NS_NewPostDataStream(nsIInputStream **result, } // otherwise, create a string stream for the data - return NS_NewCStringInputStream(result, nsDependentCString(data)); + return NS_NewCStringInputStream(result, data); } inline nsresult diff --git a/mozilla/netwerk/base/src/nsDirectoryIndexStream.cpp b/mozilla/netwerk/base/src/nsDirectoryIndexStream.cpp index ef9632f36a3..361d992a55f 100644 --- a/mozilla/netwerk/base/src/nsDirectoryIndexStream.cpp +++ b/mozilla/netwerk/base/src/nsDirectoryIndexStream.cpp @@ -129,9 +129,9 @@ static int PR_CALLBACK compare(const void* aElement1, coll->CompareString(kCollationStrengthDefault, str1, str2, &res); return res;*/ #else - nsXPIDLCString name1, name2; - a->GetLeafName(getter_Copies(name1)); - b->GetLeafName(getter_Copies(name2)); + nsCAutoString name1, name2; + a->GetNativeLeafName(name1); + b->GetNativeLeafName(name2); return Compare(name1, name2); #endif @@ -150,11 +150,11 @@ nsDirectoryIndexStream::Init(nsIFile* aDir) #ifdef PR_LOGGING if (PR_LOG_TEST(gLog, PR_LOG_DEBUG)) { - nsXPIDLCString path; - aDir->GetPath(getter_Copies(path)); + nsCAutoString path; + aDir->GetNativePath(path); PR_LOG(gLog, PR_LOG_DEBUG, ("nsDirectoryIndexStream[%p]: initialized on %s", - this, (const char*) path)); + this, path.get())); } #endif @@ -327,11 +327,11 @@ nsDirectoryIndexStream::Read(char* aBuf, PRUint32 aCount, PRUint32* aReadCount) #ifdef PR_LOGGING if (PR_LOG_TEST(gLog, PR_LOG_DEBUG)) { - nsXPIDLCString path; - current->GetPath(getter_Copies(path)); + nsCAutoString path; + current->GetNativePath(path); PR_LOG(gLog, PR_LOG_DEBUG, ("nsDirectoryIndexStream[%p]: iterated %s", - this, (const char*) path)); + this, path.get())); } #endif @@ -381,8 +381,8 @@ nsDirectoryIndexStream::Read(char* aBuf, PRUint32 aCount, PRUint32* aReadCount) mBuf.Append(' '); } #else - nsXPIDLCString leafname; - rv = current->GetLeafName(getter_Copies(leafname)); + nsCAutoString leafname; + rv = current->GetNativeLeafName(leafname); if (NS_FAILED(rv)) return rv; if (!leafname.IsEmpty()) { char* escaped = nsEscape(leafname.get(), url_Path); diff --git a/mozilla/netwerk/base/src/nsFileStreams.cpp b/mozilla/netwerk/base/src/nsFileStreams.cpp index 4ae1bfda52e..b5164038e9a 100644 --- a/mozilla/netwerk/base/src/nsFileStreams.cpp +++ b/mozilla/netwerk/base/src/nsFileStreams.cpp @@ -116,8 +116,6 @@ nsFileIO::nsFileIO() if (nsnull == gFileIOLog) { gFileIOLog = PR_NewLogModule("nsFileIO"); } - - mSpec = nsnull; #endif /* PR_LOGGING */ } @@ -128,9 +126,6 @@ nsFileIO::~nsFileIO() PR_Close(mFD); mFD = nsnull; } -#ifdef PR_LOGGING - if (mSpec) nsCRT::free(mSpec); -#endif } NS_METHOD @@ -158,7 +153,7 @@ nsFileIO::Init(nsIFile* file, PRInt32 ioFlags, PRInt32 perm) mIOFlags = ioFlags; mPerm = perm; #ifdef PR_LOGGING - nsresult rv = mFile->GetPath(&mSpec); + nsresult rv = mFile->GetNativePath(mSpec); NS_ASSERTION(NS_SUCCEEDED(rv), "GetSpec failed"); #endif return NS_OK; @@ -205,7 +200,7 @@ nsFileIO::Open() } PR_LOG(gFileIOLog, PR_LOG_DEBUG, - ("nsFileIO: logically opening %s", mSpec)); + ("nsFileIO: logically opening %s", mSpec.get())); return rv; } @@ -277,7 +272,7 @@ nsFileIO::Close(nsresult status) if (mFile) { PR_LOG(gFileIOLog, PR_LOG_DEBUG, ("nsFileIO: logically closing %s: status=%x", - mSpec, status)); + mSpec.get(), status)); mFile = nsnull; } mStatus = status; @@ -312,7 +307,7 @@ nsFileIO::GetInputStream(nsIInputStream * *aInputStream) rv = nsDirectoryIndexStream::Create(mFile, aInputStream); PR_LOG(gFileIOLog, PR_LOG_DEBUG, ("nsFileIO: opening local dir %s for input (%x)", - mSpec, rv)); + mSpec.get(), rv)); return rv; } @@ -335,7 +330,7 @@ nsFileIO::GetInputStream(nsIInputStream * *aInputStream) PR_LOG(gFileIOLog, PR_LOG_DEBUG, ("nsFileIO: opening local file %s for input (%x)", - mSpec, rv)); + mSpec.get(), rv)); return rv; } @@ -380,7 +375,7 @@ nsFileIO::GetOutputStream(nsIOutputStream * *aOutputStream) PR_LOG(gFileIOLog, PR_LOG_DEBUG, ("nsFileIO: opening local file %s for output (%x)", - mSpec, rv)); + mSpec.get(), rv)); return rv; } @@ -391,12 +386,7 @@ nsFileIO::GetName(nsACString &aName) if (mFile == nsnull) return NS_ERROR_NOT_INITIALIZED; - nsXPIDLCString path; - nsresult rv = mFile->GetPath(getter_Copies(path)); - if (NS_FAILED(rv)) return rv; - - aName = path; - return NS_OK; + return mFile->GetPath(aName); } //////////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/netwerk/base/src/nsFileStreams.h b/mozilla/netwerk/base/src/nsFileStreams.h index efe19ca8a7b..3d1a639e228 100644 --- a/mozilla/netwerk/base/src/nsFileStreams.h +++ b/mozilla/netwerk/base/src/nsFileStreams.h @@ -72,7 +72,7 @@ protected: nsresult mStatus; nsCString mContentType; #ifdef PR_LOGGING - char* mSpec; + nsCString mSpec; #endif }; diff --git a/mozilla/netwerk/base/src/nsIOServiceMac.cpp b/mozilla/netwerk/base/src/nsIOServiceMac.cpp index c6ed0cc107a..81b66756c9f 100644 --- a/mozilla/netwerk/base/src/nsIOServiceMac.cpp +++ b/mozilla/netwerk/base/src/nsIOServiceMac.cpp @@ -40,7 +40,6 @@ /* Mac-specific local file url parsing */ #include "nsIOService.h" #include "nsEscape.h" -#include "nsPrintfCString.h" #include "nsILocalFile.h" static void SwapSlashColon(char *s) @@ -72,9 +71,10 @@ nsIOService::GetURLSpecFromFile(nsIFile *aFile, nsACString &aURL) nsresult rv; NS_ENSURE_ARG(aFile); - nsXPIDLCString ePath; + nsCAutoString ePath; - rv = aFile->GetPath(getter_Copies(ePath)); + // construct URL spec from native file path + rv = aFile->GetNativePath(ePath); if (NS_FAILED(rv)) return rv; SwapSlashColon((char *) ePath.get()); @@ -97,9 +97,8 @@ nsIOService::GetURLSpecFromFile(nsIFile *aFile, nsACString &aURL) rv = aFile->IsDirectory(&dir); if (NS_FAILED(rv)) NS_WARNING(PromiseFlatCString( - NS_LITERAL_CSTRING("Cannot tell if ") + - escPath + NS_LITERAL_CSTRING(" is a directory or file") - ).get()); + NS_LITERAL_CSTRING("Cannot tell if ") + escPath + + NS_LITERAL_CSTRING(" is a directory or file")).get()); else if (dir) { // make sure we have a trailing slash escPath += "/"; @@ -146,11 +145,12 @@ nsIOService::InitFileFromURLSpec(nsIFile *aFile, const nsACString &aURL) NS_EscapeURL(fileExtension, esc_FileExtension|esc_AlwaysCopy, path); } - NS_UnescapeURL((char *) path.get()); + NS_UnescapeURL(path); // wack off leading :'s if (path.CharAt(0) == ':') path.Cut(0, 1); - return localFile->InitWithPath(path.get()); + // assuming path is encoded in the native charset + return localFile->InitWithNativePath(path); } diff --git a/mozilla/netwerk/base/src/nsIOServiceOS2.cpp b/mozilla/netwerk/base/src/nsIOServiceOS2.cpp index abb32b91d0f..c0b57e3b6bb 100644 --- a/mozilla/netwerk/base/src/nsIOServiceOS2.cpp +++ b/mozilla/netwerk/base/src/nsIOServiceOS2.cpp @@ -42,7 +42,6 @@ #define INCL_DOS #include "nsIOService.h" #include "nsEscape.h" -#include "nsPrintfCString.h" #include "nsILocalFile.h" static int isleadbyte(int c); @@ -51,9 +50,10 @@ NS_IMETHODIMP nsIOService::GetURLSpecFromFile(nsIFile *aFile, nsACString &result) { nsresult rv; - nsXPIDLCString ePath; + nsCAutoString ePath; - rv = aFile->GetPath(getter_Copies(ePath)); + // construct URL spec from native file path + rv = aFile->GetNativePath(ePath); if (NS_FAILED(rv)) return rv; // Replace \ with / to convert to an url @@ -83,9 +83,8 @@ nsIOService::GetURLSpecFromFile(nsIFile *aFile, nsACString &result) rv = aFile->IsDirectory(&dir); if (NS_FAILED(rv)) NS_WARNING(PromiseFlatCString( - NS_LITERAL_CSTRING("Cannot tell if ") + - escPath + NS_LITERAL_CSTRING(" is a directory or file") - ).get()); + NS_LITERAL_CSTRING("Cannot tell if ") + escPath + + NS_LITERAL_CSTRING(" is a directory or file")).get()); else if (dir) { // make sure we have a trailing slash escPath += "/"; @@ -127,13 +126,14 @@ nsIOService::InitFileFromURLSpec(nsIFile *aFile, const nsACString &aURL) NS_EscapeURL(fileExtension, esc_FileExtension|esc_AlwaysCopy, path); } - NS_UnescapeURL((char *) path.get()); + NS_UnescapeURL(path); // remove leading '\' if (path.CharAt(0) == '\\') path.Cut(0, 1); - return localFile->InitWithPath(path.get()); + // assuming path is encoded in the native charset + return localFile->InitWithNativePath(path); } static int isleadbyte(int c) diff --git a/mozilla/netwerk/base/src/nsIOServiceUnix.cpp b/mozilla/netwerk/base/src/nsIOServiceUnix.cpp index d3e493add8f..96d00a1b6eb 100644 --- a/mozilla/netwerk/base/src/nsIOServiceUnix.cpp +++ b/mozilla/netwerk/base/src/nsIOServiceUnix.cpp @@ -40,16 +40,16 @@ /* Unix-specific local file uri parsing */ #include "nsIOService.h" #include "nsEscape.h" -#include "nsPrintfCString.h" #include "nsILocalFile.h" NS_IMETHODIMP nsIOService::GetURLSpecFromFile(nsIFile *aFile, nsACString &result) { nsresult rv; - nsXPIDLCString ePath; + nsCAutoString ePath; - rv = aFile->GetPath(getter_Copies(ePath)); + // construct URL spec from native file path + rv = aFile->GetNativePath(ePath); if (NS_FAILED(rv)) return rv; nsCAutoString escPath; @@ -67,9 +67,8 @@ nsIOService::GetURLSpecFromFile(nsIFile *aFile, nsACString &result) rv = aFile->IsDirectory(&dir); if (NS_FAILED(rv)) NS_WARNING(PromiseFlatCString( - NS_LITERAL_CSTRING("Cannot tell if ") + - escPath + NS_LITERAL_CSTRING(" is a directory or file") - ).get()); + NS_LITERAL_CSTRING("Cannot tell if ") + escPath + + NS_LITERAL_CSTRING(" is a directory or file")).get()); else if (dir) { // make sure we have a trailing slash escPath += "/"; @@ -105,7 +104,8 @@ nsIOService::InitFileFromURLSpec(nsIFile* aFile, const nsACString &aURL) NS_EscapeURL(fileExtension, esc_FileExtension|esc_AlwaysCopy, path); } - NS_UnescapeURL((char *) path.get()); + NS_UnescapeURL(path); - return localFile->InitWithPath(path.get()); + // assuming path is encoded in the native charset + return localFile->InitWithNativePath(path); } diff --git a/mozilla/netwerk/base/src/nsIOServiceWin.cpp b/mozilla/netwerk/base/src/nsIOServiceWin.cpp index a9ab3b20cb9..7f1e3eda4e0 100644 --- a/mozilla/netwerk/base/src/nsIOServiceWin.cpp +++ b/mozilla/netwerk/base/src/nsIOServiceWin.cpp @@ -40,7 +40,6 @@ /* Windows-specific local file uri parsing */ #include "nsIOService.h" #include "nsEscape.h" -#include "nsPrintfCString.h" #include "nsILocalFile.h" #include @@ -48,9 +47,10 @@ NS_IMETHODIMP nsIOService::GetURLSpecFromFile(nsIFile *aFile, nsACString &result) { nsresult rv; - nsXPIDLCString ePath; + nsCAutoString ePath; - rv = aFile->GetPath(getter_Copies(ePath)); + // construct URL spec from native file path + rv = aFile->GetNativePath(ePath); if (NS_FAILED(rv)) return rv; // Replace \ with / to convert to an url @@ -80,9 +80,8 @@ nsIOService::GetURLSpecFromFile(nsIFile *aFile, nsACString &result) rv = aFile->IsDirectory(&dir); if (NS_FAILED(rv)) NS_WARNING(PromiseFlatCString( - NS_LITERAL_CSTRING("Cannot tell if ") + - escPath + NS_LITERAL_CSTRING(" is a directory or file") - ).get()); + NS_LITERAL_CSTRING("Cannot tell if ") + escPath + + NS_LITERAL_CSTRING(" is a directory or file")).get()); else if (dir) { // make sure we have a trailing slash escPath += "/"; @@ -124,11 +123,12 @@ nsIOService::InitFileFromURLSpec(nsIFile *aFile, const nsACString &aURL) NS_EscapeURL(fileExtension, esc_FileExtension|esc_AlwaysCopy, path); } - NS_UnescapeURL((char *) path.get()); + NS_UnescapeURL(path); // remove leading '\' if (path.CharAt(0) == '\\') path.Cut(0, 1); - return localFile->InitWithPath(path.get()); + // assuming path is encoded in the native charset + return localFile->InitWithNativePath(path); } diff --git a/mozilla/netwerk/base/src/nsStandardURL.cpp b/mozilla/netwerk/base/src/nsStandardURL.cpp index 8d2dd59a599..510977924e7 100644 --- a/mozilla/netwerk/base/src/nsStandardURL.cpp +++ b/mozilla/netwerk/base/src/nsStandardURL.cpp @@ -2157,8 +2157,8 @@ nsStandardURL::GetFile(nsIFile **result) #if defined(PR_LOGGING) if (LOG_ENABLED()) { - nsXPIDLCString path; - localFile->GetPath(getter_Copies(path)); + nsCAutoString path; + localFile->GetNativePath(path); LOG(("nsStandardURL::GetFile [this=%p spec=%s resulting_path=%s]\n", this, mSpec.get(), path.get())); } diff --git a/mozilla/netwerk/cache/src/nsDiskCacheDevice.cpp b/mozilla/netwerk/cache/src/nsDiskCacheDevice.cpp index 29324dacb1e..396e38ff8a5 100644 --- a/mozilla/netwerk/cache/src/nsDiskCacheDevice.cpp +++ b/mozilla/netwerk/cache/src/nsDiskCacheDevice.cpp @@ -178,9 +178,9 @@ NS_IMETHODIMP nsDiskCacheDeviceInfo::GetUsageReport(char ** usageReport) buffer.Append("Cache Directory: "); nsCOMPtr cacheDir; - char * path; + nsCAutoString path; mDevice->getCacheDirectory(getter_AddRefs(cacheDir)); - nsresult rv = cacheDir->GetPath(&path); + nsresult rv = cacheDir->GetPath(path); if (NS_SUCCEEDED(rv)) { buffer.Append(path); } else { @@ -758,7 +758,7 @@ nsDiskCacheDevice::InitializeCacheDirectory() } // create a directory with unique name to contain existing cache directory - rv = cacheTrashDir->Append("Cache"); + rv = cacheTrashDir->Append(NS_LITERAL_CSTRING("Cache")); if (NS_FAILED(rv)) return rv; rv = cacheTrashDir->CreateUnique(nsIFile::DIRECTORY_TYPE, 0777); if (NS_FAILED(rv)) return rv; @@ -767,7 +767,7 @@ nsDiskCacheDevice::InitializeCacheDirectory() nsCOMPtr existingCacheDir; rv = mCacheDirectory->Clone(getter_AddRefs(existingCacheDir)); if (NS_FAILED(rv)) return rv; - rv = existingCacheDir->MoveTo(cacheTrashDir, nsnull); + rv = existingCacheDir->MoveTo(cacheTrashDir, nsCString()); if (NS_FAILED(rv)) return rv; } @@ -786,7 +786,7 @@ nsDiskCacheDevice::GetCacheTrashDirectory(nsIFile ** result) nsCOMPtr cacheTrashDir; nsresult rv = mCacheDirectory->Clone(getter_AddRefs(cacheTrashDir)); if (NS_FAILED(rv)) return rv; - rv = cacheTrashDir->SetLeafName("Cache.Trash"); + rv = cacheTrashDir->SetLeafName(NS_LITERAL_CSTRING("Cache.Trash")); if (NS_FAILED(rv)) return rv; *result = cacheTrashDir.get(); @@ -844,7 +844,7 @@ nsDiskCacheDevice::SetCacheParentDirectory(nsILocalFile * parentDir) rv = parentDir->Clone(getter_AddRefs(directory)); if (NS_FAILED(rv)) return; - rv = directory->Append("Cache"); + rv = directory->Append(NS_LITERAL_CSTRING("Cache")); if (NS_FAILED(rv)) return; rv = directory->Exists(&exists); @@ -857,7 +857,7 @@ nsDiskCacheDevice::SetCacheParentDirectory(nsILocalFile * parentDir) // clean up Cache.Trash directories rv = parentDir->Clone(getter_AddRefs(directory)); if (NS_FAILED(rv)) return; - rv = directory->Append("Cache.Trash"); + rv = directory->Append(NS_LITERAL_CSTRING("Cache.Trash")); if (NS_FAILED(rv)) return; rv = directory->Exists(&exists); @@ -867,7 +867,7 @@ nsDiskCacheDevice::SetCacheParentDirectory(nsILocalFile * parentDir) // clean up obsolete NewCache directory rv = parentDir->Clone(getter_AddRefs(directory)); if (NS_FAILED(rv)) return; - rv = directory->Append("NewCache"); + rv = directory->Append(NS_LITERAL_CSTRING("NewCache")); if (NS_FAILED(rv)) return; rv = directory->Exists(&exists); diff --git a/mozilla/netwerk/cache/src/nsDiskCacheMap.cpp b/mozilla/netwerk/cache/src/nsDiskCacheMap.cpp index 749c5af3bee..5e7835f3f0d 100644 --- a/mozilla/netwerk/cache/src/nsDiskCacheMap.cpp +++ b/mozilla/netwerk/cache/src/nsDiskCacheMap.cpp @@ -149,7 +149,7 @@ nsDiskCacheMap::Open(nsILocalFile * cacheDirectory) rv = cacheDirectory->Clone(getter_AddRefs(file)); nsCOMPtr localFile(do_QueryInterface(file, &rv)); if (NS_FAILED(rv)) return rv; - rv = localFile->Append("_CACHE_MAP_"); + rv = localFile->Append(NS_LITERAL_CSTRING("_CACHE_MAP_")); if (NS_FAILED(rv)) return rv; // open the file @@ -799,7 +799,7 @@ nsDiskCacheMap::GetFileForDiskCacheRecord(nsDiskCacheRecord * record, PRInt16 generation = record->Generation(); char name[32]; ::sprintf(name, "%08X%c%02X", record->HashNumber(), (meta ? 'm' : 'd'), generation); - rv = file->Append(name); + rv = file->AppendNative(nsDependentCString(name)); if (NS_FAILED(rv)) return rv; NS_IF_ADDREF(*result = file); @@ -834,7 +834,7 @@ nsDiskCacheMap::GetBlockFileForIndex(PRUint32 index, nsILocalFile ** result) char name[32]; ::sprintf(name, "_CACHE_%03d_", index + 1); - rv = file->Append(name); + rv = file->AppendNative(nsDependentCString(name)); if (NS_FAILED(rv)) return rv; nsCOMPtr localFile = do_QueryInterface(file, &rv); diff --git a/mozilla/netwerk/mime/src/nsMIMEService.cpp b/mozilla/netwerk/mime/src/nsMIMEService.cpp index 96450a894a9..b6b798e1678 100644 --- a/mozilla/netwerk/mime/src/nsMIMEService.cpp +++ b/mozilla/netwerk/mime/src/nsMIMEService.cpp @@ -184,21 +184,20 @@ NS_IMETHODIMP nsMIMEService::GetTypeFromFile( nsIFile* aFile, char **aContentTyp nsCOMPtr info; // Get the Extension - char* fileName; + nsCAutoString fileName; const char* ext = nsnull; - rv = aFile->GetLeafName(&fileName); + rv = aFile->GetNativeLeafName(fileName); if (NS_FAILED(rv)) return rv; - if (fileName != nsnull) { - PRInt32 len = strlen(fileName); + if (!fileName.IsEmpty()) { + PRInt32 len = fileName.Length(); for (PRInt32 i = len; i >= 0; i--) { if (fileName[i] == '.') { - ext = &fileName[i + 1]; + ext = &fileName.get()[i + 1]; break; } } } nsCString fileExt( ext ); - nsCRT::free(fileName); // Handle the mac case #ifdef XP_MAC nsCOMPtr macFile; diff --git a/mozilla/netwerk/protocol/about/src/nsAboutBloat.cpp b/mozilla/netwerk/protocol/about/src/nsAboutBloat.cpp index ce756ea4867..21f08b216c5 100644 --- a/mozilla/netwerk/protocol/about/src/nsAboutBloat.cpp +++ b/mozilla/netwerk/protocol/about/src/nsAboutBloat.cpp @@ -107,7 +107,7 @@ nsAboutBloat::NewChannel(nsIURI *aURI, nsIChannel **result) getter_AddRefs(file)); if (NS_FAILED(rv)) return rv; - rv = file->Append("bloatlogs"); + rv = file->Append(NS_LITERAL_CSTRING("bloatlogs")); if (NS_FAILED(rv)) return rv; PRBool exists; @@ -132,11 +132,7 @@ nsAboutBloat::NewChannel(nsIURI *aURI, nsIChannel **result) char time[128]; PR_FormatTimeUSEnglish(time, 128, "%Y-%m-%d-%H%M%S.txt", &expTime); dumpFileName += time; - rv = file->Append(dumpFileName.get()); - if (NS_FAILED(rv)) return rv; - - char* nativePath; - rv = file->GetPath(&nativePath); + rv = file->Append(dumpFileName); if (NS_FAILED(rv)) return rv; FILE* out; diff --git a/mozilla/netwerk/test/TestFileInput.cpp b/mozilla/netwerk/test/TestFileInput.cpp index 12c940609b4..e5e15794b3c 100644 --- a/mozilla/netwerk/test/TestFileInput.cpp +++ b/mozilla/netwerk/test/TestFileInput.cpp @@ -223,7 +223,7 @@ Simulated_nsFileTransport_Run(nsReader* reader, const char* path) rv = reader->OnStartRequest(nsnull, nsnull); if (NS_FAILED(rv)) goto done; // XXX should this abort the transfer? - rv = NS_NewLocalFile(path, PR_FALSE, getter_AddRefs(file)); + rv = NS_NewNativeLocalFile(nsDependentCString(path), PR_FALSE, getter_AddRefs(file)); if (NS_FAILED(rv)) goto done; rv = NS_NewLocalFileInputStream(getter_AddRefs(fileStr), file); @@ -337,11 +337,11 @@ ParallelReadTest(char* dirName, nsIFileTransportService* fts) PRDirEntry* entry; while ((entry = PR_ReadDir(dir, PR_SKIP_BOTH)) != nsnull) { - nsCOMPtr file; - rv = NS_NewLocalFile(dirName, PR_FALSE, getter_AddRefs(file)); - NS_ASSERTION(NS_SUCCEEDED(rv), "NS_NewLocalFile failed"); + nsCOMPtr localFile; + rv = NS_NewNativeLocalFile(nsDependentCString(dirName), PR_FALSE, getter_AddRefs(localFile)); + NS_ASSERTION(NS_SUCCEEDED(rv), "NS_NewNativeLocalFile failed"); - rv = file->Append(entry->name); + rv = localFile->AppendNative(nsDependentCString(entry->name)); NS_ASSERTION(NS_SUCCEEDED(rv), "AppendPath failed"); nsReader* reader = new nsReader(); @@ -362,7 +362,7 @@ ParallelReadTest(char* dirName, nsIFileTransportService* fts) NS_ASSERTION(listener, "QI failed"); nsITransport* trans; - rv = fts->CreateTransport(file, PR_RDONLY, 0, PR_TRUE, &trans); + rv = fts->CreateTransport(localFile, PR_RDONLY, 0, PR_TRUE, &trans); NS_ASSERTION(NS_SUCCEEDED(rv), "create failed"); nsCOMPtr request; rv = trans->AsyncRead(nsnull, listener, 0, -1, 0, getter_AddRefs(request)); diff --git a/mozilla/netwerk/test/TestFileInput2.cpp b/mozilla/netwerk/test/TestFileInput2.cpp index 3fc48997dac..f83608dc2e9 100644 --- a/mozilla/netwerk/test/TestFileInput2.cpp +++ b/mozilla/netwerk/test/TestFileInput2.cpp @@ -354,14 +354,12 @@ Test(CreateFun create, PRUint32 count, nsresult rv; PRUint32 i; - char* inDir; - char* outDir; - (void)inDirSpec->GetPath(&inDir); - (void)outDirSpec->GetPath(&outDir); + nsCAutoString inDir; + nsCAutoString outDir; + (void)inDirSpec->GetPath(inDir); + (void)outDirSpec->GetPath(outDir); printf("###########\nTest: from %s to %s, bufSize = %d\n", - inDir, outDir, bufSize); - nsCRT::free(inDir); - nsCRT::free(outDir); + inDir.get(), outDir.get(), bufSize); gTimeSampler.Reset(); nsTimeSampler testTime; testTime.StartTime(); @@ -388,12 +386,11 @@ Test(CreateFun create, PRUint32 count, rv = outDirSpec->Clone(getter_AddRefs(outSpec)); // don't munge the original if (NS_FAILED(rv)) goto done; - char* leafName; - rv = inSpec->GetLeafName(&leafName); + nsCAutoString leafName; + rv = inSpec->GetLeafName(leafName); if (NS_FAILED(rv)) goto done; rv = outSpec->Append(leafName); - nsCRT::free(leafName); if (NS_FAILED(rv)) goto done; PRBool exists; @@ -464,11 +461,11 @@ main(int argc, char* argv[]) registrar->AutoRegister(nsnull); nsCOMPtr inDirFile; - rv = NS_NewLocalFile(inDir, PR_FALSE, getter_AddRefs(inDirFile)); + rv = NS_NewNativeLocalFile(nsDependentCString(inDir), PR_FALSE, getter_AddRefs(inDirFile)); if (NS_FAILED(rv)) return rv; nsCOMPtr outDirFile; - rv = NS_NewLocalFile(outDir, PR_FALSE, getter_AddRefs(outDirFile)); + rv = NS_NewNativeLocalFile(nsDependentCString(outDir), PR_FALSE, getter_AddRefs(outDirFile)); if (NS_FAILED(rv)) return rv; CreateFun create = FileChannelWorker::Create; diff --git a/mozilla/netwerk/test/TestFileTransport.cpp b/mozilla/netwerk/test/TestFileTransport.cpp index 4076c18e45c..2db26dd5864 100644 --- a/mozilla/netwerk/test/TestFileTransport.cpp +++ b/mozilla/netwerk/test/TestFileTransport.cpp @@ -51,6 +51,7 @@ #include "nsIStreamListener.h" #include "nsIEventQueueService.h" #include "nsIEventQueue.h" +#include "nsILocalFile.h" #include "nsNetUtil.h" #include "prlog.h" @@ -157,15 +158,13 @@ public: nsresult Init(const char* origFile) { nsresult rv; nsCOMPtr file; - rv = NS_NewLocalFile(origFile, PR_FALSE, getter_AddRefs(file)); + rv = NS_NewNativeLocalFile(nsDependentCString(origFile), PR_FALSE, getter_AddRefs(file)); if (NS_FAILED(rv)) return rv; - char* name; - rv = file->GetLeafName(&name); + nsCAutoString name; + rv = file->GetLeafName(name); if (NS_FAILED(rv)) return rv; - nsCAutoString str(name); - nsMemory::Free(name); - str.Append(".bak"); - rv = file->SetLeafName(str.get()); + name += NS_LITERAL_CSTRING(".bak"); + rv = file->SetLeafName(name); if (NS_FAILED(rv)) return rv; rv = NS_NewLocalFileOutputStream(getter_AddRefs(mOut), file, @@ -202,7 +201,7 @@ TestAsyncRead(const char* fileName, PRUint32 offset, PRInt32 length) nsITransport* fileTrans; nsCOMPtr file; - rv = NS_NewLocalFile(fileName, PR_FALSE, getter_AddRefs(file)); + rv = NS_NewNativeLocalFile(nsDependentCString(fileName), PR_FALSE, getter_AddRefs(file)); if (NS_FAILED(rv)) return rv; rv = fts->CreateTransport(file, PR_RDONLY, 0, PR_TRUE, &fileTrans); if (NS_FAILED(rv)) return rv; @@ -253,10 +252,10 @@ TestAsyncWrite(const char* fileName, PRUint32 offset, PRInt32 length) if (NS_FAILED(rv)) return rv; nsCAutoString outFile(fileName); - outFile.Append(".out"); + outFile += NS_LITERAL_CSTRING(".out"); nsITransport* fileTrans; nsCOMPtr file; - rv = NS_NewLocalFile(outFile.get(), PR_FALSE, getter_AddRefs(file)); + rv = NS_NewNativeLocalFile(outFile, PR_FALSE, getter_AddRefs(file)); if (NS_FAILED(rv)) return rv; rv = fts->CreateTransport(file, PR_CREATE_FILE | PR_WRONLY | PR_TRUNCATE, @@ -278,7 +277,7 @@ TestAsyncWrite(const char* fileName, PRUint32 offset, PRInt32 length) if (NS_FAILED(rv)) return rv; nsCOMPtr f; - rv = NS_NewLocalFile(fileName, PR_FALSE, getter_AddRefs(f)); + rv = NS_NewNativeLocalFile(nsDependentCString(fileName), PR_FALSE, getter_AddRefs(f)); if (NS_FAILED(rv)) return rv; nsCOMPtr inStr; rv = NS_NewLocalFileInputStream(getter_AddRefs(inStr), f); diff --git a/mozilla/netwerk/test/TestUpload.cpp b/mozilla/netwerk/test/TestUpload.cpp index e96a66bc750..fa868a2fd4f 100644 --- a/mozilla/netwerk/test/TestUpload.cpp +++ b/mozilla/netwerk/test/TestUpload.cpp @@ -155,7 +155,7 @@ main(int argc, char* argv[]) nsCOMPtr uploadStream; rv = NS_NewPostDataStream(getter_AddRefs(uploadStream), PR_TRUE, - fileName, + nsDependentCString(fileName), // XXX UTF-8 0, ioService); if (NS_FAILED(rv)) return rv; diff --git a/mozilla/profile/pref-migrator/src/nsPrefMigration.cpp b/mozilla/profile/pref-migrator/src/nsPrefMigration.cpp index 937cc79197f..5db843baa1d 100644 --- a/mozilla/profile/pref-migrator/src/nsPrefMigration.cpp +++ b/mozilla/profile/pref-migrator/src/nsPrefMigration.cpp @@ -45,7 +45,10 @@ #include "nsIServiceManager.h" #include "nsIScriptGlobalObject.h" #include "nsIScriptContext.h" -#include "nsSpecialSystemDirectory.h" +#include "nsILocalFile.h" +#include "nsDirectoryServiceUtils.h" +#include "nsDirectoryServiceDefs.h" +#include "nsDependentString.h" #include "nsFileStream.h" #include "nsIFileSpec.h" #include "nsCOMPtr.h" @@ -608,34 +611,28 @@ nsPrefMigration::ProcessPrefsCallback(const char* oldProfilePathStr, const char getter_AddRefs(PrefsFile4xAsIFile)); if (NS_FAILED(rv)) return rv; - nsSpecialSystemDirectory systemTempDir(nsSpecialSystemDirectory::OS_TemporaryDirectory); - nsFileSpec tempPrefsFile = systemTempDir; - - systemTempDir += "migrate"; - - //Convert the systemTempDir to an nsILocalFile - nsCOMPtr systemTempIFileDir; - rv = NS_NewLocalFile(systemTempDir, PR_TRUE, getter_AddRefs(systemTempIFileDir)); + nsCOMPtr systemTempDir; + rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(systemTempDir)); if (NS_FAILED(rv)) return rv; + systemTempDir->Append(NS_LITERAL_CSTRING("migrate")); + //Create a unique directory in the system temp dir based on the name of the 4.x prefs file - rv = systemTempIFileDir->CreateUnique(nsIFile::DIRECTORY_TYPE, 0700); + rv = systemTempDir->CreateUnique(nsIFile::DIRECTORY_TYPE, 0700); if (NS_FAILED(rv)) return rv; - rv = PrefsFile4xAsIFile->CopyTo(systemTempIFileDir, PREF_FILE_NAME_IN_4x); + rv = PrefsFile4xAsIFile->CopyTo(systemTempDir, NS_LITERAL_CSTRING(PREF_FILE_NAME_IN_4x)); if (NS_FAILED(rv)) return rv; - //Get the new unique directory name and append it to the system temp dir - nsXPIDLCString uniquePrefsDir; - systemTempIFileDir->GetLeafName(getter_Copies(uniquePrefsDir)); - tempPrefsFile += uniquePrefsDir; - tempPrefsFile += PREF_FILE_NAME_IN_4x; + nsCOMPtr cloneFile; + rv = systemTempDir->Clone(getter_AddRefs(cloneFile)); + if (NS_FAILED(rv)) return rv; - //Create the m_prefsFile fileSpec for use in ReadUserPrefsFrom -// rv = NS_NewFileSpecWithSpec(tempPrefsFile, getter_AddRefs(m_prefsFile)); -// if (NS_FAILED(rv)) return rv; + m_prefsFile = do_QueryInterface(cloneFile, &rv); + if (NS_FAILED(rv)) return rv; - NS_NewLocalFile((const char *)tempPrefsFile, PR_TRUE, getter_AddRefs(m_prefsFile)); + rv = m_prefsFile->Append(NS_LITERAL_CSTRING(PREF_FILE_NAME_IN_4x)); + if (NS_FAILED(rv)) return rv; //Clear the prefs in case a previous set was read in. m_prefs->ResetPrefs(); @@ -1114,9 +1111,9 @@ nsPrefMigration::ProcessPrefsCallback(const char* oldProfilePathStr, const char nsXPIDLCString path; newProfilePath->GetNativePath(getter_Copies(path)); - NS_NewLocalFile(path, PR_TRUE, getter_AddRefs(newPrefsFile)); + NS_NewNativeLocalFile(path, PR_TRUE, getter_AddRefs(newPrefsFile)); - rv = newPrefsFile->Append(PREF_FILE_NAME_IN_5x); + rv = newPrefsFile->Append(NS_LITERAL_CSTRING(PREF_FILE_NAME_IN_5x)); if (NS_FAILED(rv)) return rv; rv=m_prefs->SavePrefFile(newPrefsFile); @@ -1129,9 +1126,9 @@ nsPrefMigration::ProcessPrefsCallback(const char* oldProfilePathStr, const char if (flagExists) m_prefsFile->Remove(PR_FALSE); - systemTempIFileDir->Exists(&flagExists); //Delete the unique dir in the system temp dir. + systemTempDir->Exists(&flagExists); //Delete the unique dir in the system temp dir. if (flagExists) - systemTempIFileDir->Remove(PR_FALSE); + systemTempDir->Remove(PR_FALSE); return rv; } @@ -1244,7 +1241,7 @@ nsPrefMigration::GetDirFromPref(nsIFileSpec * oldProfilePath, nsIFileSpec * newP if (NS_FAILED(rv)) return rv; // convert nsILocalFile to nsIFileSpec - rv = oldPrefPathFile->GetPath(getter_Copies(oldPrefPathStr)); + rv = oldPrefPathFile->GetNativePath(oldPrefPathStr); if (NS_FAILED(rv)) return rv; rv = NS_NewFileSpec(getter_AddRefs(oldPrefPath)); @@ -2008,7 +2005,7 @@ nsPrefMigration::DetermineOldPath(nsIFileSpec *profilePath, const char *oldPathN rv = bundle->GetStringFromName(entityName.get(), getter_Copies(localizedDirName)); if (NS_FAILED(rv)) return rv; - rv = oldLocalFile->AppendRelativeUnicodePath((const PRUnichar *)localizedDirName); + rv = oldLocalFile->AppendRelativePath(NS_ConvertUCS2toUTF8(localizedDirName)); if (NS_FAILED(rv)) return rv; PRBool exists = PR_FALSE; @@ -2025,10 +2022,10 @@ nsPrefMigration::DetermineOldPath(nsIFileSpec *profilePath, const char *oldPathN } /* at this point, the folder with the localized name exists, so use it */ - nsXPIDLCString persistentDescriptor; - rv = oldLocalFile->GetPersistentDescriptor(getter_Copies(persistentDescriptor)); + nsCAutoString persistentDescriptor; + rv = oldLocalFile->GetPersistentDescriptor(persistentDescriptor); if (NS_FAILED(rv)) return rv; - rv = oldPath->SetPersistentDescriptorString((const char *)persistentDescriptor); + rv = oldPath->SetPersistentDescriptorString(persistentDescriptor.get()); if (NS_FAILED(rv)) return rv; return NS_OK; diff --git a/mozilla/profile/resources/content/createProfileWizard.js b/mozilla/profile/resources/content/createProfileWizard.js index 6898af758d3..939154b0a51 100644 --- a/mozilla/profile/resources/content/createProfileWizard.js +++ b/mozilla/profile/resources/content/createProfileWizard.js @@ -156,11 +156,11 @@ function processCreateProfileData( aProfName, aProfDir, langcode, regioncode) fileSpec = fileSpec.QueryInterface( Components.interfaces.nsILocalFile ); if (aProfDir == null) - fileSpec.initWithUnicodePath(profile.defaultProfileParentDir.unicodePath); + fileSpec.initWithPath(profile.defaultProfileParentDir.path); else - fileSpec.initWithUnicodePath(aProfDir); + fileSpec.initWithPath(aProfDir); - fileSpec.appendUnicode(aProfName); + fileSpec.append(aProfName); if (fileSpec != null && fileSpec.exists()) useExistingDir = true; diff --git a/mozilla/profile/resources/content/newProfile1_2.js b/mozilla/profile/resources/content/newProfile1_2.js index 9da305ffc86..140616b95e0 100644 --- a/mozilla/profile/resources/content/newProfile1_2.js +++ b/mozilla/profile/resources/content/newProfile1_2.js @@ -90,7 +90,7 @@ function chooseProfileFolder( aRootFolder ) fp.appendFilters(Components.interfaces.nsIFilePicker.filterAll); fp.show(); // later change to - aRootFolder = fp.file.unicodePath; + aRootFolder = fp.file.path; } catch(e) { aRootFolder = null; @@ -100,7 +100,7 @@ function chooseProfileFolder( aRootFolder ) var folderText = document.getElementById("ProfileDir"); dump("*** setting rootFolderAttribute to " + aRootFolder + "\n"); folderText.setAttribute( "rootFolder", aRootFolder ); - if ( aRootFolder != top.profile.defaultProfileParentDir.unicodePath ) + if ( aRootFolder != top.profile.defaultProfileParentDir.path ) document.getElementById( "useDefault" ).removeAttribute("disabled"); updateProfileName(); } @@ -128,14 +128,14 @@ function updateProfileName() var sfile = Components.classes[nsILocalFile_CONTRACTID].createInstance(nsILocalFile); if ( sfile ) { // later change to - sfile.initWithUnicodePath(rootFolder); + sfile.initWithPath(rootFolder); } // later change to - sfile.appendUnicode(profileName.value); + sfile.append(profileName.value); clearFolderDisplay(); // later change to - var value = document.createTextNode( sfile.unicodePath ); + var value = document.createTextNode( sfile.path ); folderDisplayElement.appendChild( value ); } catch(e) { @@ -153,7 +153,7 @@ function setDisplayToDefaultFolder() if ( fileSpec ) fileSpec = fileSpec.QueryInterface( Components.interfaces.nsIFile ); if ( fileSpec ) - profileDisplay.setAttribute("rootFolder", fileSpec.unicodePath ); + profileDisplay.setAttribute("rootFolder", fileSpec.path ); } diff --git a/mozilla/profile/resources/content/profileSelection.js b/mozilla/profile/resources/content/profileSelection.js index a4cd1901568..2cab68f72f9 100644 --- a/mozilla/profile/resources/content/profileSelection.js +++ b/mozilla/profile/resources/content/profileSelection.js @@ -52,7 +52,7 @@ function StartUp() Registry = Components.classes['@mozilla.org/registry;1'].createInstance(); Registry = Registry.QueryInterface(Components.interfaces.nsIRegistry); - Registry.open(regFile.path); + Registry.open(regFile); // get new profile registry & users location and dump it to console // to let users know about it. diff --git a/mozilla/profile/src/nsProfile.cpp b/mozilla/profile/src/nsProfile.cpp index 36ce6c35936..7b64fe6ced0 100644 --- a/mozilla/profile/src/nsProfile.cpp +++ b/mozilla/profile/src/nsProfile.cpp @@ -233,14 +233,14 @@ nsresult RecursiveCopy(nsIFile* srcDir, nsIFile* destDir) if (NS_SUCCEEDED(rv)) { nsCOMPtr newChild(do_QueryInterface(destClone)); - nsXPIDLCString leafName; - dirEntry->GetLeafName(getter_Copies(leafName)); + nsCAutoString leafName; + dirEntry->GetLeafName(leafName); newChild->AppendRelativePath(leafName); rv = RecursiveCopy(dirEntry, newChild); } } else - rv = dirEntry->CopyTo(destDir, nsnull); + rv = dirEntry->CopyTo(destDir, nsCString()); } } @@ -439,18 +439,18 @@ nsProfile::StartupWithArgs(nsICmdLineService *cmdLineArgs, PRBool canInteract) rv = GetCurrentProfileDir(getter_AddRefs(profileDir)); if (NS_FAILED(rv)) return rv; - nsXPIDLCString pathBuf; - rv = profileDir->GetPath(getter_Copies(pathBuf)); + nsCAutoString pathBuf; + rv = profileDir->GetNativePath(pathBuf); if (NS_FAILED(rv)) return rv; // -UILocale or -contentLocale has been specified, but // user has selected UILocale and contentLocale for this profile // on profileManager // We should not set here - nsCStringKey key((const char *)pathBuf); + nsCStringKey key(pathBuf); if (NS_PTR_TO_INT32(gLocaleProfiles->Get(&key)) == PR_TRUE) { #ifdef DEBUG_profile_verbose - printf(" already set UILocale and contentLocale: %s\n", NS_STATIC_CAST(const char*, pathBuf)); + printf(" already set UILocale and contentLocale: %s\n", pathBuf.get()); printf(" will not install locale\n"); #endif return NS_OK; @@ -461,9 +461,9 @@ nsProfile::StartupWithArgs(nsICmdLineService *cmdLineArgs, PRBool canInteract) if (NS_FAILED(rv)) return rv; // Install to the profile - nsFileSpec fileSpec((const char *)pathBuf); - nsFileURL fileURL(fileSpec); - const char* fileStr = fileURL.GetURLString(); + nsCAutoString fileStr; + rv = NS_GetURLSpecFromFile(profileDir, fileStr); + if (NS_FAILED(rv)) return rv; // NEED TO FIX: when current UILocale and contentLocale are same with specified locales, // we shouldn't install them again here. But packageRegistry->GetSelectedLocale() doesn't @@ -855,7 +855,7 @@ nsProfile::ProcessArgs(nsICmdLineService *cmdLineArgs, nsAutoString currProfileDirString; currProfileDirString.AssignWithConversion(strtok(NULL, " ")); if (!currProfileDirString.IsEmpty()) { - rv = NS_NewUnicodeLocalFile(currProfileDirString.get(), PR_TRUE, getter_AddRefs(currProfileDir)); + rv = NS_NewLocalFile(NS_ConvertUCS2toUTF8(currProfileDirString), PR_TRUE, getter_AddRefs(currProfileDir)); NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); } else { @@ -867,9 +867,9 @@ nsProfile::ProcessArgs(nsICmdLineService *cmdLineArgs, if (NS_FAILED(rv)) return rv; } - nsXPIDLString currProfilePath; - currProfileDir->GetUnicodePath(getter_Copies(currProfilePath)); - rv = CreateNewProfile(currProfileName.get(), currProfilePath, nsnull, PR_TRUE); + nsCAutoString currProfilePath; + currProfileDir->GetPath(currProfilePath); + rv = CreateNewProfile(currProfileName.get(), NS_ConvertUTF8toUCS2(currProfilePath).get(), nsnull, PR_TRUE); if (NS_SUCCEEDED(rv)) { *profileDirSet = PR_TRUE; mCurrentProfileAvailable = PR_TRUE; @@ -1043,7 +1043,12 @@ NS_IMETHODIMP nsProfile::GetProfilePath(const PRUnichar *profileName, PRUnichar if (NS_SUCCEEDED(rv)) prettyDir = parentDir; } - return prettyDir->GetUnicodePath(_retval); + nsCAutoString path; + rv = prettyDir->GetPath(path); + if (NS_FAILED(rv)) return rv; + + *_retval = ToNewUnicode(NS_ConvertUTF8toUCS2(path)); + return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } NS_IMETHODIMP nsProfile::GetOriginalProfileDir(const PRUnichar *profileName, nsILocalFile **originalDir) @@ -1083,7 +1088,7 @@ NS_IMETHODIMP nsProfile::GetProfileLastModTime(const PRUnichar *profileName, PRI rv = GetProfileDir(profileName, getter_AddRefs(profileDir)); if (NS_FAILED(rv)) return rv; - rv = profileDir->Append("prefs.js"); + rv = profileDir->Append(NS_LITERAL_CSTRING("prefs.js")); if (NS_FAILED(rv)) return rv; return profileDir->GetLastModifiedTime(_retval); @@ -1328,7 +1333,7 @@ nsProfile::AddLevelOfIndirection(nsIFile *aDir) rv = aDir->Clone(getter_AddRefs(prefFile)); NS_ENSURE_SUCCESS(rv,rv); - rv = prefFile->Append("prefs.js"); + rv = prefFile->Append(NS_LITERAL_CSTRING("prefs.js")); NS_ENSURE_SUCCESS(rv,rv); rv = prefFile->Exists(&exists); @@ -1356,16 +1361,16 @@ nsProfile::AddLevelOfIndirection(nsIFile *aDir) if (NS_SUCCEEDED(rv)) { rv = dirEntry->IsDirectory(&isDir); if (NS_SUCCEEDED(rv) && isDir) { - nsXPIDLCString leafName; - rv = dirEntry->GetLeafName(getter_Copies(leafName)); - if (NS_SUCCEEDED(rv) && (const char *)leafName) { - PRUint32 length = strlen((const char *)leafName); + nsCAutoString leafName; + rv = dirEntry->GetNativeLeafName(leafName); + if (NS_SUCCEEDED(rv) && !leafName.IsEmpty()) { + PRUint32 length = leafName.Length(); // check if the filename is the right length, len("xxxxxxxx.slt") if (length == (SALT_SIZE + kSaltExtensionCString.Length())) { // check that the filename ends with ".slt" - if (nsCRT::strncmp((const char *)leafName + SALT_SIZE, kSaltExtensionCString.get(), kSaltExtensionCString.Length()) == 0) { + if (nsCRT::strncmp(leafName.get() + SALT_SIZE, kSaltExtensionCString.get(), kSaltExtensionCString.Length()) == 0) { // found a salt directory, use it - rv = aDir->Append((const char *)leafName); + rv = aDir->AppendNative(leafName); return rv; } } @@ -1394,7 +1399,7 @@ nsProfile::AddLevelOfIndirection(nsIFile *aDir) printf("directory name: %s\n",saltStr.get()); #endif - rv = aDir->Append(saltStr.get()); + rv = aDir->AppendNative(saltStr); NS_ENSURE_SUCCESS(rv,rv); exists = PR_FALSE; @@ -1415,16 +1420,15 @@ nsresult nsProfile::IsProfileDirSalted(nsIFile *profileDir, PRBool *isSalted) *isSalted = PR_FALSE; // 1. The name of the profile dir has to end in ".slt" - nsXPIDLCString leafName; - rv = profileDir->GetLeafName(getter_Copies(leafName)); + nsCAutoString leafName; + rv = profileDir->GetNativeLeafName(leafName); if (NS_FAILED(rv)) return rv; PRBool endsWithSalt = PR_FALSE; - nsDependentCString leafNameString(leafName.get()); - if (leafNameString.Length() >= kSaltExtensionCString.Length()) + if (leafName.Length() >= kSaltExtensionCString.Length()) { nsReadingIterator stringEnd; - leafNameString.EndReading(stringEnd); + leafName.EndReading(stringEnd); nsReadingIterator stringStart = stringEnd; stringStart.advance( -(NS_STATIC_CAST(PRInt32, kSaltExtensionCString.Length())) ); @@ -1541,16 +1545,16 @@ nsProfile::CreateNewProfileWithLocales(const PRUnichar* profileName, profileDir->Create(nsIFile::DIRECTORY_TYPE, 0775); // append profile name - profileDir->AppendUnicode(profileName); + profileDir->Append(NS_ConvertUCS2toUTF8(profileName)); } else { - rv = NS_NewUnicodeLocalFile(nativeProfileDir, PR_TRUE, (nsILocalFile **)((nsIFile **)getter_AddRefs(profileDir))); + rv = NS_NewLocalFile(NS_ConvertUCS2toUTF8(nativeProfileDir), PR_TRUE, (nsILocalFile **)((nsIFile **)getter_AddRefs(profileDir))); // this prevents people from choosing there profile directory // or another directory, and remove it when they delete the profile. // append profile name - profileDir->AppendUnicode(profileName); + profileDir->Append(NS_ConvertUCS2toUTF8(profileName)); } @@ -1633,12 +1637,13 @@ nsProfile::CreateNewProfileWithLocales(const PRUnichar* profileName, printf(" contentLocale=%s\n", temp2.get()); #endif - nsXPIDLCString pathBuf; - rv = profileDir->GetPath(getter_Copies(pathBuf)); + nsCAutoString pathBuf; + rv = profileDir->GetNativePath(pathBuf); NS_ENSURE_SUCCESS(rv, rv); - nsFileSpec fileSpec((const char *)pathBuf); - nsFileURL fileURL(fileSpec); - const char* fileStr = fileURL.GetURLString(); + + nsCAutoString fileStr; + rv = NS_GetURLSpecFromFile(profileDir, fileStr); + if (NS_FAILED(rv)) return rv; if (uiLocale && uiLocale[0]) { rv = chromeRegistry->SelectLocaleForProfile(uiLocale, @@ -1646,7 +1651,7 @@ nsProfile::CreateNewProfileWithLocales(const PRUnichar* profileName, // Remember which profile has been created with the UILocale // didn't use gProfileDataAccess because just needed one time if (NS_SUCCEEDED(rv)) { - nsCStringKey key((const char *)pathBuf); + nsCStringKey key(pathBuf); gLocaleProfiles->Put(&key, (void*)PR_TRUE); } } @@ -1657,17 +1662,15 @@ nsProfile::CreateNewProfileWithLocales(const PRUnichar* profileName, rv = profDefaultsDir->Clone(getter_AddRefs(locProfDefaultsDir)); if (NS_FAILED(rv)) return rv; - locProfDefaultsDir->AppendUnicode(contentLocale); + locProfDefaultsDir->Append(NS_ConvertUCS2toUTF8(contentLocale)); rv = locProfDefaultsDir->Exists(&exists); if (NS_SUCCEEDED(rv) && exists) { profDefaultsDir = locProfDefaultsDir; // transfers ownership #if defined(DEBUG_profile_verbose) - nsXPIDLString profilePath; - rv = profDefaultsDir->GetUnicodePath(getter_Copies(profilePath)); - if (NS_SUCCEEDED(rv)) { - nsCAutoString temp5; temp5.AssignWithConversion(profilePath); - printf(" profDefaultsDir is set to: %s\n", temp5.get()); - } + nsCAutoString profilePath; + rv = profDefaultsDir->GetNativePath(profilePath); + if (NS_SUCCEEDED(rv)) + printf(" profDefaultsDir is set to: %s\n", profilePath.get()); #endif } @@ -1676,7 +1679,7 @@ nsProfile::CreateNewProfileWithLocales(const PRUnichar* profileName, // Remember which profile has been created with the UILocale // didn't use gProfileDataAccess because just needed one time if (NS_SUCCEEDED(rv)) { - nsCStringKey key((const char *)pathBuf); + nsCStringKey key(pathBuf); gLocaleProfiles->Put(&key, (void*)PR_TRUE); } } @@ -2031,7 +2034,7 @@ NS_IMETHODIMP nsProfile::MigrateProfileInfo() } nsresult -nsProfile::CopyDefaultFile(nsIFile *profDefaultsDir, nsIFile *newProfDir, const char *fileName) +nsProfile::CopyDefaultFile(nsIFile *profDefaultsDir, nsIFile *newProfDir, const nsACString &fileName) { nsresult rv; nsCOMPtr defaultFile; @@ -2040,11 +2043,11 @@ nsProfile::CopyDefaultFile(nsIFile *profDefaultsDir, nsIFile *newProfDir, const rv = profDefaultsDir->Clone(getter_AddRefs(defaultFile)); if (NS_FAILED(rv)) return rv; - defaultFile->Append(fileName); + defaultFile->AppendNative(fileName); rv = defaultFile->Exists(&exists); if (NS_FAILED(rv)) return rv; if (exists) - rv = defaultFile->CopyTo(newProfDir, fileName); + rv = defaultFile->CopyToNative(newProfDir, fileName); else rv = NS_ERROR_FILE_NOT_FOUND; @@ -2071,11 +2074,10 @@ nsProfile::EnsureProfileFileExists(nsIFile *aFile) rv = CloneProfileDirectorySpec(getter_AddRefs(profDir)); if (NS_FAILED(rv)) return rv; - char *leafName; - rv = aFile->GetLeafName(&leafName); + nsCAutoString leafName; + rv = aFile->GetNativeLeafName(leafName); if (NS_FAILED(rv)) return rv; rv = CopyDefaultFile(defaultsDir, profDir, leafName); - Recycle(leafName); return rv; } @@ -2100,7 +2102,7 @@ nsProfile::DefineLocaleDefaultsDir() nsXPIDLString localeName; rv = packageRegistry->GetSelectedLocale(NS_LITERAL_STRING("global-region").get(), getter_Copies(localeName)); if (NS_SUCCEEDED(rv)) - rv = localeDefaults->AppendUnicode(localeName); + rv = localeDefaults->Append(NS_ConvertUCS2toUTF8(localeName)); } (void) directoryService->Undefine(NS_APP_PROFILE_DEFAULTS_50_DIR); rv = directoryService->Define(NS_APP_PROFILE_DEFAULTS_50_DIR, localeDefaults); @@ -2166,16 +2168,16 @@ nsProfile::MigrateProfileInternal(const PRUnichar* profileName, nsCOMPtr newProfDirLocal(do_QueryInterface(newProfDir, &rv)); if (NS_FAILED(rv)) return rv; - nsXPIDLCString oldProfDirStr; - nsXPIDLCString newProfDirStr; + nsCAutoString oldProfDirStr; + nsCAutoString newProfDirStr; - rv = oldProfDirLocal->GetPersistentDescriptor(getter_Copies(oldProfDirStr)); + rv = oldProfDirLocal->GetPersistentDescriptor(oldProfDirStr); if (NS_FAILED(rv)) return rv; - rv = newProfDirLocal->GetPersistentDescriptor(getter_Copies(newProfDirStr)); + rv = newProfDirLocal->GetPersistentDescriptor(newProfDirStr); if (NS_FAILED(rv)) return rv; // you can do this a bunch of times. - rv = pPrefMigrator->AddProfilePaths(oldProfDirStr, newProfDirStr); + rv = pPrefMigrator->AddProfilePaths(oldProfDirStr.get(), newProfDirStr.get()); rv = pPrefMigrator->ProcessPrefs(PR_TRUE); // param is ignored if (NS_FAILED(rv)) return rv; @@ -2263,7 +2265,7 @@ nsProfile::MigrateProfile(const PRUnichar* profileName) if (NS_FAILED(rv)) return rv; - rv = newProfDir->AppendUnicode(profileName); + rv = newProfDir->Append(NS_ConvertUCS2toUTF8(profileName)); if (NS_FAILED(rv)) return rv; @@ -2299,14 +2301,13 @@ nsProfile::RemigrateProfile(const PRUnichar* profileName) NS_ENSURE_SUCCESS(rv,rv); // In case of error, we'll restore what we've renamed. - nsXPIDLCString origDirLeafName; - rv = profileDir->GetLeafName(getter_Copies(origDirLeafName)); + nsCAutoString origDirLeafName; + rv = profileDir->GetNativeLeafName(origDirLeafName); NS_ENSURE_SUCCESS(rv,rv); // Backup what we're remigrating by renaming it and leaving in place // XXX todo: what if .slt-old already exists? - nsCAutoString newDirLeafName(origDirLeafName + NS_LITERAL_CSTRING("-old")); - rv = profileDir->MoveTo(nsnull, newDirLeafName.get()); + rv = profileDir->MoveToNative(nsnull, origDirLeafName + NS_LITERAL_CSTRING("-old")); NS_ENSURE_SUCCESS(rv,rv); // Create a new directory for the remigrated profile @@ -2317,7 +2318,7 @@ nsProfile::RemigrateProfile(const PRUnichar* profileName) if (NS_FAILED(rv)) { newProfileDir->Remove(PR_TRUE); - profileDir->MoveTo(nsnull, origDirLeafName); + profileDir->MoveToNative(nsnull, origDirLeafName); } return rv; } @@ -2415,7 +2416,7 @@ NS_IMETHODIMP nsProfile::CloneProfile(const PRUnichar* newProfile) if (NS_FAILED(rv)) return rv; nsCOMPtr destDir(do_QueryInterface(aFile, &rv)); if (NS_FAILED(rv)) return rv; - destDir->AppendRelativeUnicodePath(newProfile); + destDir->AppendRelativePath(NS_ConvertUCS2toUTF8(newProfile)); // Find a unique name in the dest dir rv = destDir->CreateUnique(nsIFile::DIRECTORY_TYPE, 0775); @@ -2453,11 +2454,11 @@ nsProfile::CreateDefaultProfile(void) rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILES_ROOT_DIR, getter_AddRefs(profileRootDir)); if (NS_FAILED(rv)) return rv; - nsXPIDLString profilePath; - rv = profileRootDir->GetUnicodePath(getter_Copies(profilePath)); + nsCAutoString profilePath; + rv = profileRootDir->GetPath(profilePath); if (NS_FAILED(rv)) return rv; - rv = CreateNewProfile(DEFAULT_PROFILE_NAME, profilePath, nsnull, PR_TRUE); + rv = CreateNewProfile(DEFAULT_PROFILE_NAME, NS_ConvertUTF8toUCS2(profilePath).get(), nsnull, PR_TRUE); return rv; } @@ -2516,19 +2517,19 @@ nsProfile::IsRegStringSet(const PRUnichar *profileName, char **regString) // File Name Defines -#define PREFS_FILE_50_NAME "prefs.js" -#define USER_CHROME_DIR_50_NAME "chrome" -#define LOCAL_STORE_FILE_50_NAME "localstore.rdf" -#define HISTORY_FILE_50_NAME "history.dat" -#define PANELS_FILE_50_NAME "panels.rdf" -#define MIME_TYPES_FILE_50_NAME "mimeTypes.rdf" -#define BOOKMARKS_FILE_50_NAME "bookmarks.html" -#define DOWNLOADS_FILE_50_NAME "downloads.rdf" -#define SEARCH_FILE_50_NAME "search.rdf" -#define MAIL_DIR_50_NAME "Mail" -#define IMAP_MAIL_DIR_50_NAME "ImapMail" -#define NEWS_DIR_50_NAME "News" -#define MSG_FOLDER_CACHE_DIR_50_NAME "panacea.dat" +#define PREFS_FILE_50_NAME NS_LITERAL_CSTRING("prefs.js") +#define USER_CHROME_DIR_50_NAME NS_LITERAL_CSTRING("chrome") +#define LOCAL_STORE_FILE_50_NAME NS_LITERAL_CSTRING("localstore.rdf") +#define HISTORY_FILE_50_NAME NS_LITERAL_CSTRING("history.dat") +#define PANELS_FILE_50_NAME NS_LITERAL_CSTRING("panels.rdf") +#define MIME_TYPES_FILE_50_NAME NS_LITERAL_CSTRING("mimeTypes.rdf") +#define BOOKMARKS_FILE_50_NAME NS_LITERAL_CSTRING("bookmarks.html") +#define DOWNLOADS_FILE_50_NAME NS_LITERAL_CSTRING("downloads.rdf") +#define SEARCH_FILE_50_NAME NS_LITERAL_CSTRING("search.rdf") +#define MAIL_DIR_50_NAME NS_LITERAL_CSTRING("Mail") +#define IMAP_MAIL_DIR_50_NAME NS_LITERAL_CSTRING("ImapMail") +#define NEWS_DIR_50_NAME NS_LITERAL_CSTRING("News") +#define MSG_FOLDER_CACHE_DIR_50_NAME NS_LITERAL_CSTRING("panacea.dat") NS_IMETHODIMP nsProfile::GetFile(const char *prop, PRBool *persistant, nsIFile **_retval) diff --git a/mozilla/profile/src/nsProfile.h b/mozilla/profile/src/nsProfile.h index 4caa2b49146..2d3ec01ec31 100644 --- a/mozilla/profile/src/nsProfile.h +++ b/mozilla/profile/src/nsProfile.h @@ -75,7 +75,7 @@ private: nsresult ConfirmAutoMigration(PRBool canInteract, PRBool *confirmed); nsresult CopyDefaultFile(nsIFile *profDefaultsDir, nsIFile *newProfDir, - const char *fileName); + const nsACString &fileName); nsresult EnsureProfileFileExists(nsIFile *aFile); nsresult LoadNewProfilePrefs(); nsresult SetProfileDir(const PRUnichar *profileName, nsIFile *profileDir); diff --git a/mozilla/profile/src/nsProfileAccess.cpp b/mozilla/profile/src/nsProfileAccess.cpp index 8e2a56fee73..72fc7226622 100644 --- a/mozilla/profile/src/nsProfileAccess.cpp +++ b/mozilla/profile/src/nsProfileAccess.cpp @@ -264,15 +264,11 @@ nsresult nsProfileAccess::FillProfileInfo(nsIFile* regName) { nsresult rv = NS_OK; - nsXPIDLCString regFile; PRBool fixRegEntries = PR_FALSE; - if (regName) - regName->GetPath(getter_Copies(regFile)); - nsCOMPtr registry(do_CreateInstance(NS_REGISTRY_CONTRACTID, &rv)); if (NS_FAILED(rv)) return rv; - rv = registry->Open(regFile); + rv = registry->Open(regName); if (NS_FAILED(rv)) return rv; // Enumerate all subkeys (immediately) under the given node. @@ -588,8 +584,6 @@ nsProfileAccess::RemoveSubTree(const PRUnichar* profileName) if (index >= 0) { - ProfileStruct* profileItem = (ProfileStruct *) (mProfiles->ElementAt(index)); - mProfiles->RemoveElementAt(index); if (mCurrentProfile.Equals(profileName)) @@ -626,7 +620,6 @@ nsresult nsProfileAccess::UpdateRegistry(nsIFile* regName) { nsresult rv; - nsXPIDLCString regFile; if (!mProfileDataChanged) { @@ -635,17 +628,12 @@ nsProfileAccess::UpdateRegistry(nsIFile* regName) if (!regName) { - if (mNewRegFile) - mNewRegFile->GetPath(getter_Copies(regFile)); - } - else - { - regName->GetPath(getter_Copies(regFile)); + regName = mNewRegFile; } nsCOMPtr registry(do_CreateInstance(NS_REGISTRY_CONTRACTID, &rv)); if (NS_FAILED(rv)) return rv; - rv = registry->Open(regFile); + rv = registry->Open(regName); if (NS_FAILED(rv)) return rv; // Enumerate all subkeys (immediately) under the given node. @@ -1025,9 +1013,13 @@ nsProfileAccess::Get4xProfileInfo(const char *registryName, PRBool fromImport) #if defined(XP_PC) || defined(XP_MAC) NS_ASSERTION(registryName, "Invalid registryName"); + nsCOMPtr registryFile; + rv = NS_NewNativeLocalFile(nsDependentCString(registryName), PR_TRUE, getter_AddRefs(registryFile)); + if (NS_FAILED(rv)) return rv; + nsCOMPtr oldReg(do_CreateInstance(NS_REGISTRY_CONTRACTID, &rv)); if (NS_FAILED(rv)) return rv; - rv = oldReg->Open(registryName); + rv = oldReg->Open(registryFile); if (NS_FAILED(rv)) return rv; // Enumerate 4x tree and create an array of that information. @@ -1165,7 +1157,7 @@ nsProfileAccess::Get4xProfileInfo(const char *registryName, PRBool fromImport) profileItem->profileName = NS_ConvertASCIItoUCS2(unixProfileName).get(); nsCOMPtr localFile; - rv = NS_NewLocalFile(profileLocation.get(), PR_TRUE, getter_AddRefs(localFile)); + rv = NS_NewNativeLocalFile(profileLocation, PR_TRUE, getter_AddRefs(localFile)); if (NS_FAILED(rv)) return rv; profileItem->SetResolvedProfileDir(localFile); profileItem->isMigrated = PR_FALSE; @@ -1379,7 +1371,7 @@ nsresult ProfileStruct::InternalizeLocation(nsIRegistry *aRegistry, nsRegistryKe #endif // Now we have a unicode path - make it into a file - rv = NS_NewUnicodeLocalFile(convertedProfLoc.get(), PR_TRUE, getter_AddRefs(tempLocal)); + rv = NS_NewLocalFile(NS_ConvertUCS2toUTF8(convertedProfLoc), PR_TRUE, getter_AddRefs(tempLocal)); } else { @@ -1396,13 +1388,13 @@ nsresult ProfileStruct::InternalizeLocation(nsIRegistry *aRegistry, nsRegistryKe PRInt32 firstColon = regLocationData.FindChar(PRUnichar(':')); if (firstColon == -1) { - rv = NS_NewLocalFile(nsnull, PR_TRUE, getter_AddRefs(tempLocal)); - if (NS_SUCCEEDED(rv)) - rv = tempLocal->SetPersistentDescriptor(NS_ConvertUCS2toUTF8(regLocationData).get()); + rv = NS_NewLocalFile(nsCString(), PR_TRUE, getter_AddRefs(tempLocal)); + if (NS_SUCCEEDED(rv)) // XXX this only works on XP_MAC because regLocationData is ASCII + rv = tempLocal->SetPersistentDescriptor(NS_ConvertUCS2toUTF8(regLocationData)); } else #endif - rv = NS_NewUnicodeLocalFile(regLocationData.get(), PR_TRUE, getter_AddRefs(tempLocal)); + rv = NS_NewLocalFile(NS_ConvertUCS2toUTF8(regLocationData), PR_TRUE, getter_AddRefs(tempLocal)); } if (NS_SUCCEEDED(rv) && tempLocal) @@ -1425,21 +1417,21 @@ nsresult ProfileStruct::ExternalizeLocation(nsIRegistry *aRegistry, nsRegistryKe #if XP_MAC PRBool leafCreated; - nsXPIDLCString descBuf; + nsCAutoString descBuf; // It must exist before we try to use GetPersistentDescriptor rv = EnsureDirPathExists(resolvedLocation, &leafCreated); if (NS_FAILED(rv)) return rv; - rv = resolvedLocation->GetPersistentDescriptor(getter_Copies(descBuf)); + rv = resolvedLocation->GetPersistentDescriptor(descBuf); if (NS_FAILED(rv)) return rv; if (leafCreated) resolvedLocation->Remove(PR_FALSE); regData = NS_ConvertUTF8toUCS2(descBuf); #else - nsXPIDLString ucPath; - rv = resolvedLocation->GetUnicodePath(getter_Copies(ucPath)); + nsCAutoString utf8Path; + rv = resolvedLocation->GetPath(utf8Path); if (NS_FAILED(rv)) return rv; - regData = ucPath; + regData = NS_ConvertUTF8toUCS2(utf8Path); #endif rv = aRegistry->SetString(profKey, @@ -1475,16 +1467,16 @@ nsresult ProfileStruct::InternalizeMigratedFromLocation(nsIRegistry *aRegistry, if (NS_SUCCEEDED(rv)) { #ifdef XP_MAC - rv = NS_NewLocalFile(nsnull, PR_TRUE, getter_AddRefs(tempLocal)); + rv = NS_NewLocalFile(nsCString(), PR_TRUE, getter_AddRefs(tempLocal)); if (NS_SUCCEEDED(rv)) { // The persistent desc on Mac is base64 encoded so plain ASCII - rv = tempLocal->SetPersistentDescriptor(regData.get()); + rv = tempLocal->SetPersistentDescriptor(regData); if (NS_SUCCEEDED(rv)) migratedFrom = tempLocal; } #else - rv = NS_NewUnicodeLocalFile(NS_ConvertUTF8toUCS2(regData).get(), PR_TRUE, getter_AddRefs(tempLocal)); + rv = NS_NewLocalFile(regData, PR_TRUE, getter_AddRefs(tempLocal)); if (NS_SUCCEEDED(rv)) migratedFrom = tempLocal; #endif @@ -1495,17 +1487,14 @@ nsresult ProfileStruct::InternalizeMigratedFromLocation(nsIRegistry *aRegistry, nsresult ProfileStruct::ExternalizeMigratedFromLocation(nsIRegistry *aRegistry, nsRegistryKey profKey) { nsresult rv = NS_OK; - nsXPIDLCString regData; + nsCAutoString regData; if (migratedFrom) { #if XP_MAC - rv = migratedFrom->GetPersistentDescriptor(getter_Copies(regData)); + rv = migratedFrom->GetPersistentDescriptor(regData); #else - nsXPIDLString ucPath; - rv = resolvedLocation->GetUnicodePath(getter_Copies(ucPath)); - if (NS_SUCCEEDED(rv)) - regData = NS_ConvertUCS2toUTF8(ucPath); + rv = resolvedLocation->GetPath(regData); #endif if (NS_SUCCEEDED(rv)) diff --git a/mozilla/rdf/chrome/src/nsChromeRegistry.cpp b/mozilla/rdf/chrome/src/nsChromeRegistry.cpp index 156fecc6875..b04b801d84e 100644 --- a/mozilla/rdf/chrome/src/nsChromeRegistry.cpp +++ b/mozilla/rdf/chrome/src/nsChromeRegistry.cpp @@ -99,6 +99,7 @@ #include "prio.h" #include "nsInt64.h" #include "nsIDirectoryService.h" +#include "nsILocalFile.h" #include "nsAppDirectoryServiceDefs.h" #include "nsIPref.h" #include "nsIObserverService.h" @@ -109,10 +110,11 @@ #include "imgICache.h" static char kChromePrefix[] = "chrome://"; -static char kChromeFileName[] = "chrome.rdf"; -static char kInstalledChromeFileName[] = "installed-chrome.txt"; static char kUseXBLFormsPref[] = "nglayout.debug.enable_xbl_forms"; +#define kChromeFileName NS_LITERAL_CSTRING("chrome.rdf") +#define kInstalledChromeFileName NS_LITERAL_CSTRING("installed-chrome.txt") + static NS_DEFINE_CID(kWindowMediatorCID, NS_WINDOWMEDIATOR_CID); static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID); @@ -1800,9 +1802,8 @@ nsChromeRegistry::SetProviderForPackage(const nsACString& aProvider, // Figure out which file we're needing to modify, e.g., is it the install // dir or the profile dir, and get the right datasource. - nsDependentCString dataSourceStr(kChromeFileName); nsCOMPtr dataSource; - rv = LoadDataSource(dataSourceStr, getter_AddRefs(dataSource), aUseProfile, aProfilePath); + rv = LoadDataSource(kChromeFileName, getter_AddRefs(dataSource), aUseProfile, aProfilePath); if (NS_FAILED(rv)) return rv; rv = nsChromeRegistry::UpdateArc(dataSource, aPackageResource, aSelectionArc, aProviderPackageResource, !aIsAdding); @@ -2077,10 +2078,9 @@ nsChromeRegistry::IsProviderSetForPackage(const nsACString& aProvider, nsresult rv; // Figure out which file we're needing to modify, e.g., is it the install // dir or the profile dir, and get the right datasource. - nsDependentCString dataSourceStr(kChromeFileName); nsCOMPtr dataSource; - rv = LoadDataSource(dataSourceStr, getter_AddRefs(dataSource), aUseProfile, nsnull); + rv = LoadDataSource(kChromeFileName, getter_AddRefs(dataSource), aUseProfile, nsnull); if (NS_FAILED(rv)) return rv; nsCOMPtr retVal; @@ -2166,8 +2166,7 @@ NS_IMETHODIMP nsChromeRegistry::InstallProvider(const nsACString& aProviderType, // Load the install data source that we wish to manipulate. nsCOMPtr installSource; - nsDependentCString installStr(kChromeFileName); - rv = LoadDataSource(installStr, getter_AddRefs(installSource), aUseProfile, nsnull); + rv = LoadDataSource(kChromeFileName, getter_AddRefs(installSource), aUseProfile, nsnull); if (NS_FAILED(rv)) return rv; NS_ASSERTION(installSource, "failed to get installSource"); @@ -2533,8 +2532,7 @@ nsChromeRegistry::UninstallProvider(const nsACString& aProviderType, // Instantiate the data source we wish to modify. nsCOMPtr installSource; - nsDependentCString installStr(kChromeFileName); - rv = LoadDataSource(installStr, getter_AddRefs(installSource), aUseProfile, nsnull); + rv = LoadDataSource(kChromeFileName, getter_AddRefs(installSource), aUseProfile, nsnull); if (NS_FAILED(rv)) return rv; NS_ASSERTION(installSource, "failed to get installSource"); @@ -2605,15 +2603,15 @@ nsChromeRegistry::GetProfileRoot(nsCString& aFileURL) getter_AddRefs(defaultUserChromeFile)); if (NS_FAILED(rv)) return(rv); - defaultUserContentFile->Append("chrome"); - defaultUserContentFile->Append("userContent.css"); - defaultUserChromeFile->Append("chrome"); - defaultUserChromeFile->Append("userChrome.css"); + defaultUserContentFile->Append(NS_LITERAL_CSTRING("chrome")); + defaultUserContentFile->Append(NS_LITERAL_CSTRING("userContent.css")); + defaultUserChromeFile->Append(NS_LITERAL_CSTRING("chrome")); + defaultUserChromeFile->Append(NS_LITERAL_CSTRING("userChrome.css")); // copy along // It aint an error if these files dont exist - (void) defaultUserContentFile->CopyTo(userChromeDir, nsnull); - (void) defaultUserChromeFile->CopyTo(userChromeDir, nsnull); + (void) defaultUserContentFile->CopyTo(userChromeDir, nsCString()); + (void) defaultUserChromeFile->CopyTo(userChromeDir, nsCString()); } } if (NS_FAILED(rv)) @@ -2745,17 +2743,16 @@ nsChromeRegistry::AddToCompositeDataSource(PRBool aUseProfile) if (NS_FAILED(rv)) return rv; } - nsDependentCString name(kChromeFileName); if (aUseProfile) { // Profiles take precedence. Load them first. nsCOMPtr dataSource; - LoadDataSource(name, getter_AddRefs(dataSource), PR_TRUE, nsnull); + LoadDataSource(kChromeFileName, getter_AddRefs(dataSource), PR_TRUE, nsnull); mChromeDataSource->AddDataSource(dataSource); } // Always load the install dir datasources nsCOMPtr dataSource; - LoadDataSource(name, getter_AddRefs(dataSource), PR_FALSE, nsnull); + LoadDataSource(kChromeFileName, getter_AddRefs(dataSource), PR_FALSE, nsnull); mChromeDataSource->AddDataSource(dataSource); return NS_OK; @@ -3155,7 +3152,8 @@ nsChromeRegistry::ProcessNewChromeBuffer(char *aBuffer, PRInt32 aLength) nsCOMPtr chromeFile(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv)); if (NS_FAILED(rv)) return rv; - rv = chromeFile->InitWithPath(chromeLocation); + // assuming chromeLocation is given in the charset of the current locale + rv = chromeFile->InitWithNativePath(nsDependentCString(chromeLocation)); if (NS_FAILED(rv)) return rv; @@ -3218,9 +3216,8 @@ nsChromeRegistry::ProcessNewChromeBuffer(char *aBuffer, PRInt32 aLength) } mBatchInstallFlushes = PR_FALSE; - nsDependentCString dataSourceStr(kChromeFileName); nsCOMPtr dataSource; - LoadDataSource(dataSourceStr, getter_AddRefs(dataSource), PR_FALSE, nsnull); + LoadDataSource(kChromeFileName, getter_AddRefs(dataSource), PR_FALSE, nsnull); nsCOMPtr remote(do_QueryInterface(dataSource)); remote->Flush(); return NS_OK; diff --git a/mozilla/rdf/datasource/src/nsFileSystemDataSource.cpp b/mozilla/rdf/datasource/src/nsFileSystemDataSource.cpp index 64eb1fdf07f..0de9079a046 100644 --- a/mozilla/rdf/datasource/src/nsFileSystemDataSource.cpp +++ b/mozilla/rdf/datasource/src/nsFileSystemDataSource.cpp @@ -1322,12 +1322,12 @@ FileSystemDataSource::GetFolderList(nsIRDFResource *source, PRBool allowHidden, // XXX We should use nsIFile::GetUnicodeLeafName(). // But currently mozilla's xpcom/io is not unicode normalization. // And URI cannot use UTF-8 (On RFC2396, URI should use UTF-8) - // So, we uses nsIFile::GetLeafName() for performance... + // So, we uses nsIFile::GetNativeLeafName() for performance... - char *leafStr = nsnull; - if (NS_FAILED(rv = aFile->GetLeafName(&leafStr))) + nsCAutoString leafStr; + if (NS_FAILED(rv = aFile->GetNativeLeafName(leafStr))) break; - if (!leafStr) + if (leafStr.IsEmpty()) continue; nsCAutoString fullURI; @@ -1337,9 +1337,8 @@ FileSystemDataSource::GetFolderList(nsIRDFResource *source, PRBool allowHidden, fullURI.Append('/'); } - char *escLeafStr = nsEscape(leafStr, url_Path); - Recycle(leafStr); - leafStr = nsnull; + char *escLeafStr = nsEscape(leafStr.get(), url_Path); + leafStr.Truncate(); if (!escLeafStr) continue; @@ -1530,16 +1529,12 @@ FileSystemDataSource::GetName(nsIRDFResource *source, nsIRDFLiteral **aResult) if (aFileLocal) aFileLocal->SetFollowLinks(PR_FALSE); - PRUnichar *nameUni = nsnull; - if (NS_FAILED(rv = aFile->GetUnicodeLeafName(&nameUni))) + nsCAutoString name; + if (NS_FAILED(rv = aFile->GetLeafName(name))) return(rv); - if (!nameUni) + if (name.IsEmpty()) return(NS_ERROR_UNEXPECTED); - nsAutoString name(nameUni); - Recycle(nameUni); - nameUni = nsnull; - #ifdef XP_MAC nsCOMPtr aMacFile = do_QueryInterface(aFile); if (aMacFile) @@ -1561,11 +1556,10 @@ FileSystemDataSource::GetName(nsIRDFResource *source, nsIRDFLiteral **aResult) #ifdef XP_WIN // special hack for IE favorites under Windows; strip off the // trailing ".url" or ".lnk" at the end of IE favorites names - PRInt32 nameLen = name.Length(); - nsAutoString theURI; theURI.AssignWithConversion(uri); - if ((theURI.Find(ieFavoritesDir) == 0) && (nameLen > 4)) + PRInt32 nameLen = name.Length(); + if ((strncmp(uri, ieFavoritesDir, strlen(ieFavoritesDir)) == 0) && (nameLen > 4)) { - nsAutoString extension; + nsCAutoString extension; name.Right(extension, 4); if (extension.EqualsIgnoreCase(".url") || extension.EqualsIgnoreCase(".lnk")) @@ -1577,8 +1571,7 @@ FileSystemDataSource::GetName(nsIRDFResource *source, nsIRDFLiteral **aResult) #ifdef XP_BEOS // under BEOS, try and get the "META:title" attribute (if its a file) - nsAutoString theURI; theURI.AssignWithConversion(uri); - if (theURI.Find(netPositiveDir) == 0) + if (strncmp(uri, netPositiveDir, strlen(netPositiveDir)) == 0) { nsFileURL url(uri); nsFilePath path(url); @@ -1600,21 +1593,21 @@ FileSystemDataSource::GetName(nsIRDFResource *source, nsIRDFLiteral **aResult) 0, beNameAttr, sizeof(beNameAttr)-1)) > 0) { beNameAttr[len] = '\0'; - name = NS_ConvertUTF8toUCS2(beNameAttr); + name = beNameAttr; rv = NS_OK; } } } if (NS_OK != rv) { - name = NS_ConvertUTF8toUCS2(spec.GetLeafName()); + name = spec.GetLeafName(); rv = NS_OK; } } } #endif - gRDFService->GetLiteral(name.get(), aResult); + gRDFService->GetLiteral(NS_ConvertUTF8toUCS2(name).get(), aResult); return NS_OK; } diff --git a/mozilla/security/manager/ssl/src/nsNSSComponent.cpp b/mozilla/security/manager/ssl/src/nsNSSComponent.cpp index efd68071eec..768e58792a0 100644 --- a/mozilla/security/manager/ssl/src/nsNSSComponent.cpp +++ b/mozilla/security/manager/ssl/src/nsNSSComponent.cpp @@ -66,6 +66,7 @@ #include "nsIEntropyCollector.h" #include "nsIBufEntropyCollector.h" #include "nsIServiceManager.h" +#include "nsILocalFile.h" #include "nsCipherInfo.h" #include "nss.h" @@ -272,9 +273,9 @@ nsNSSComponent::~nsNSSComponent() #ifdef XP_MAC #ifdef DEBUG -#define LOADABLE_CERTS_MODULE "NSSckbiDebug.shlb" +#define LOADABLE_CERTS_MODULE NS_LITERAL_CSTRING("NSSckbiDebug.shlb") #else -#define LOADABLE_CERTS_MODULE "NSSckbi.shlb" +#define LOADABLE_CERTS_MODULE NS_LITERAL_CSTRING("NSSckbi.shlb") #endif /*DEBUG*/ #endif /*XP_MAC*/ @@ -361,7 +362,7 @@ nsNSSComponent::InstallLoadableRoots() } if (!hasRoot) { nsresult rv; - nsString modName; + nsAutoString modName; rv = GetPIPNSSBundleString(NS_LITERAL_STRING("RootCertModuleName").get(), modName); if (NS_FAILED(rv)) return; @@ -372,7 +373,7 @@ nsNSSComponent::InstallLoadableRoots() return; directoryService->Get( NS_XPCOM_CURRENT_PROCESS_DIR, - NS_GET_IID(nsIFile), + NS_GET_IID(nsILocalFile), getter_AddRefs(mozFile)); if (!mozFile) { @@ -380,23 +381,25 @@ nsNSSComponent::InstallLoadableRoots() } char *fullModuleName = nsnull; #ifdef XP_MAC - char *unixModulePath=nsnull; - mozFile->Append("Essential Files"); + nsCAutoString nativePath; + mozFile->Append(NS_LITERAL_CSTRING("Essential Files")); mozFile->Append(LOADABLE_CERTS_MODULE); - mozFile->GetPath(&fullModuleName); + mozFile->GetNativePath(nativePath); + fullModuleName = (char *) nativePath.get(); #else - char *processDir = nsnull; - mozFile->GetPath(&processDir); - fullModuleName = PR_GetLibraryName(processDir, "nssckbi"); - nsMemory::Free(processDir); + nsCAutoString processDir; + mozFile->GetNativePath(processDir); + fullModuleName = PR_GetLibraryName(processDir.get(), "nssckbi"); #endif /* If a module exists with the same name, delete it. */ char *modNameCString = ToNewCString(modName); int modType; SECMOD_DeleteModule(modNameCString, &modType); SECMOD_AddNewModule(modNameCString, fullModuleName, 0, 0); - nsMemory::Free(fullModuleName); nsMemory::Free(modNameCString); +#ifndef XP_MAC + PR_Free(fullModuleName); // allocated by NSPR +#endif } } @@ -835,7 +838,7 @@ nsNSSComponent::InitializeNSS() certHashtable_valueCompare, 0, 0 ); nsresult rv; - nsXPIDLCString profileStr; + nsCAutoString profileStr; nsCOMPtr profilePath; rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, @@ -848,12 +851,12 @@ nsNSSComponent::InitializeNSS() #ifdef XP_MAC // On the Mac we place all NSS DBs in the Security // Folder in the profile directory. - profilePath->Append("Security"); + profilePath->Append(NS_LITERAL_CSTRING("Security")); profilePath->Create(nsIFile::DIRECTORY_TYPE, 0); //This is for Mac, don't worry about //permissions. #endif - rv = profilePath->GetPath(getter_Copies(profileStr)); + rv = profilePath->GetNativePath(profileStr); if (NS_FAILED(rv)) return rv; @@ -876,7 +879,7 @@ nsNSSComponent::InitializeNSS() ConfigureInternalPKCS11Token(); - if (::NSS_InitReadWrite(profileStr) != SECSuccess) { + if (::NSS_InitReadWrite(profileStr.get()) != SECSuccess) { PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("can not init NSS r/w in %s\n", profileStr.get())); if (supress_warning_preference) { @@ -887,11 +890,11 @@ nsNSSComponent::InitializeNSS() } // try to init r/o - if (NSS_Init(profileStr) != SECSuccess) { + if (NSS_Init(profileStr.get()) != SECSuccess) { PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("can not init in r/o either\n")); which_nss_problem = problem_no_security_at_all; - NSS_NoDB_Init(profileStr); + NSS_NoDB_Init(profileStr.get()); } } diff --git a/mozilla/security/manager/ssl/src/nsPKCS12Blob.cpp b/mozilla/security/manager/ssl/src/nsPKCS12Blob.cpp index c7cdcea1d92..5db098675d5 100644 --- a/mozilla/security/manager/ssl/src/nsPKCS12Blob.cpp +++ b/mozilla/security/manager/ssl/src/nsPKCS12Blob.cpp @@ -31,7 +31,7 @@ * may use your version of this file under either the MPL or the * GPL. * - * $Id: nsPKCS12Blob.cpp,v 1.24 2002-02-28 05:14:10 cathleen%netscape.com Exp $ + * $Id: nsPKCS12Blob.cpp,v 1.25 2002-04-27 05:32:35 darin%netscape.com Exp $ */ #include "prmem.h" @@ -39,6 +39,7 @@ #include "nsISupportsArray.h" #include "nsIFileSpec.h" +#include "nsILocalFile.h" #include "nsINSSDialogs.h" #include "nsIDirectoryService.h" #include "nsIWindowWatcher.h" @@ -67,7 +68,7 @@ extern PRLogModuleInfo* gPIPNSSLog; static NS_DEFINE_CID(kNSSComponentCID, NS_NSSCOMPONENT_CID); -#define PIP_PKCS12_TMPFILENAME ".pip_p12tmp" +#define PIP_PKCS12_TMPFILENAME NS_LITERAL_CSTRING(".pip_p12tmp") #define PIP_PKCS12_BUFFER_SIZE 2048 #define PIP_PKCS12_RESTORE_OK 1 #define PIP_PKCS12_BACKUP_OK 2 @@ -257,8 +258,7 @@ nsPKCS12Blob::ExportToFile(nsILocalFile *file, SEC_PKCS12ExportContext *ecx = NULL; SEC_PKCS12SafeInfo *certSafe = NULL, *keySafe = NULL; SECItem unicodePw; - nsXPIDLCString xpidlFilePath; - nsAutoString filePath; + nsCAutoString filePath; int i; nsCOMPtr localFileRef; NS_ASSERTION(mToken, "Need to set the token before exporting"); @@ -352,8 +352,7 @@ nsPKCS12Blob::ExportToFile(nsILocalFile *file, // prepare the instance to write to an export file this->mTmpFile = NULL; - file->GetPath(getter_Copies(xpidlFilePath)); - filePath.AssignWithConversion(xpidlFilePath); + file->GetPath(filePath); // Use the nsCOMPtr var localFileRef so that // the reference to the nsILocalFile we create gets released as soon as // we're out of scope, ie when this function exits. @@ -361,10 +360,10 @@ nsPKCS12Blob::ExportToFile(nsILocalFile *file, // We're going to add the .p12 extension to the file name just like // Communicator used to. We create a new nsILocalFile and initialize // it with the new patch. - filePath.Append(NS_LITERAL_STRING(".p12")); + filePath.Append(NS_LITERAL_CSTRING(".p12")); localFileRef = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv); if (NS_FAILED(rv)) goto finish; - localFileRef->InitWithUnicodePath(filePath.get()); + localFileRef->InitWithPath(filePath); file = localFileRef; } rv = file->OpenNSPRFileDesc(PR_RDWR|PR_CREATE_FILE|PR_TRUNCATE, 0664, @@ -467,14 +466,8 @@ nsPKCS12Blob::inputToDecoder(SEC_PKCS12DecoderContext *dcx, nsILocalFile *file) unsigned char buf[PIP_PKCS12_BUFFER_SIZE]; // everybody else is doin' it nsCOMPtr tempSpec; - { - nsXPIDLCString pathBuf; - file->GetPath(getter_Copies(pathBuf)); - rv = NS_NewFileSpec(getter_AddRefs(tempSpec)); - if (NS_FAILED(rv)) return rv; - rv = tempSpec->SetNativePath(pathBuf); - if (NS_FAILED(rv)) return rv; - } + rv = NS_NewFileSpecFromIFile(file, getter_AddRefs(tempSpec)); + if (NS_FAILED(rv)) return rv; nsInputFileStream fileStream(tempSpec); while (PR_TRUE) { amount = fileStream.read(buf, PIP_PKCS12_BUFFER_SIZE); @@ -535,13 +528,13 @@ nsPKCS12Blob::digest_open(void *arg, PRBool reading) do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv); if (NS_FAILED(rv)) return SECFailure; directoryService->Get(NS_OS_TEMP_DIR, - NS_GET_IID(nsIFile), + NS_GET_IID(nsILocalFile), getter_AddRefs(tmpFile)); if (tmpFile) { tmpFile->Append(PIP_PKCS12_TMPFILENAME); - nsXPIDLCString pathBuf; - tmpFile->GetPath(getter_Copies(pathBuf)); - cx->mTmpFilePath = PL_strdup(pathBuf.get()); + nsCAutoString pathBuf; + tmpFile->GetNativePath(pathBuf); + cx->mTmpFilePath = ToNewCString(pathBuf); #ifdef XP_MAC char *unixPath = nsnull; ConvertMacPathToUnixPath(cx->mTmpFilePath, &unixPath); diff --git a/mozilla/uriloader/exthandler/mac/nsOSHelperAppService.cpp b/mozilla/uriloader/exthandler/mac/nsOSHelperAppService.cpp index e0e8fef4a2f..d4468ffc28f 100644 --- a/mozilla/uriloader/exthandler/mac/nsOSHelperAppService.cpp +++ b/mozilla/uriloader/exthandler/mac/nsOSHelperAppService.cpp @@ -144,7 +144,7 @@ nsresult nsOSHelperAppService::GetFileTokenForPath(const PRUnichar * platformApp if (localFile) { if (localFile) - localFile->InitWithUnicodePath(platformAppPath); + localFile->InitWithPath(NS_ConvertUCS2toUTF8(platformAppPath)); *aFile = localFile; NS_IF_ADDREF(*aFile); } diff --git a/mozilla/uriloader/exthandler/nsExternalHelperAppService.cpp b/mozilla/uriloader/exthandler/nsExternalHelperAppService.cpp index 0e5e9af172b..938841fef0e 100644 --- a/mozilla/uriloader/exthandler/nsExternalHelperAppService.cpp +++ b/mozilla/uriloader/exthandler/nsExternalHelperAppService.cpp @@ -892,7 +892,7 @@ void nsExternalAppHandler::ExtractSuggestedFileNameFromChannel(nsIChannel* aChan if (iter != start) { // not empty // ONLY if we got here, will we remember the suggested file name... // The filename must be ASCII, see RFC 2183, section 2.3 - CopyASCIItoUCS2(Substring(start, iter), mSuggestedFileName); + mSuggestedFileName = Substring(start, iter); // Make sure extension is still correct. EnsureSuggestedFileName(); @@ -969,17 +969,16 @@ void nsExternalAppHandler::EnsureSuggestedFileName() if (mTempFileExtension.Length() > 1) { // Get mSuggestedFileName's current extension. - nsAutoString fileExt; - PRInt32 pos = mSuggestedFileName.RFindChar(PRUnichar('.')); + nsCAutoString fileExt; + PRInt32 pos = mSuggestedFileName.RFindChar('.'); if (pos != kNotFound) mSuggestedFileName.Right(fileExt, mSuggestedFileName.Length() - pos); // Now, compare fileExt to mTempFileExtension. - NS_ConvertASCIItoUCS2 tempFileExt(mTempFileExtension); - if (!fileExt.Equals(tempFileExt, nsCaseInsensitiveStringComparator())) + if (!fileExt.Equals(mTempFileExtension, nsCaseInsensitiveCStringComparator())) { // Doesn't match, so force mSuggestedFileName to have the extension we want. - mSuggestedFileName.Append(tempFileExt); + mSuggestedFileName.Append(mTempFileExtension); } } } @@ -1030,8 +1029,8 @@ nsresult nsExternalAppHandler::SetUpTempFile(nsIChannel * aChannel) url->GetFileName(leafName); if (!leafName.IsEmpty()) { - NS_UnescapeURL((char *) leafName.get()); - mSuggestedFileName = NS_ConvertUTF8toUCS2(leafName); + NS_UnescapeURL(leafName); + mSuggestedFileName = leafName; // Make sure extension is still correct. EnsureSuggestedFileName(); @@ -1057,7 +1056,7 @@ nsresult nsExternalAppHandler::SetUpTempFile(nsIChannel * aChannel) // now append our extension. saltedTempLeafName.Append(mTempFileExtension); - mTempFile->Append(saltedTempLeafName.get()); // make this file unique!!! + mTempFile->Append(saltedTempLeafName); // make this file unique!!! mTempFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0600); NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID); @@ -1191,7 +1190,7 @@ NS_IMETHODIMP nsExternalAppHandler::OnStartRequest(nsIRequest *request, nsISuppo // to the web progress listener. typedef enum { kReadError, kWriteError, kLaunchError } ErrorType; static void SendStatusChange( - ErrorType type, nsresult rv, nsIRequest *aRequest, nsIWebProgressListener *aListener, const PRUnichar *path) + ErrorType type, nsresult rv, nsIRequest *aRequest, nsIWebProgressListener *aListener, const nsACString &path) { nsAutoString msgId; switch(rv) @@ -1236,7 +1235,8 @@ static void SendStatusChange( if (NS_SUCCEEDED(s->CreateBundle("chrome://global/locale/nsWebBrowserPersist.properties", getter_AddRefs(bundle)))) { nsXPIDLString msgText; - const PRUnichar *strings[] = { path }; + NS_ConvertUTF8toUCS2 uscPath(path); + const PRUnichar *strings[] = { uscPath.get() }; if(NS_SUCCEEDED(bundle->FormatStringFromName(msgId.get(), strings, 1, getter_Copies(msgText)))) { aListener->OnStatusChange(nsnull, (type == kReadError) ? aRequest : nsnull, rv, msgText); @@ -1317,10 +1317,10 @@ NS_IMETHODIMP nsExternalAppHandler::OnDataAvailable(nsIRequest *request, nsISupp // An error occurred, notify listener. if (mWebProgressListener) { - nsXPIDLString tempFilePath; + nsCAutoString tempFilePath; if (mTempFile) - mTempFile->GetUnicodePath(getter_Copies(tempFilePath)); - SendStatusChange(readError ? kReadError : kWriteError, rv, request, mWebProgressListener, tempFilePath.get()); + mTempFile->GetPath(tempFilePath); + SendStatusChange(readError ? kReadError : kWriteError, rv, request, mWebProgressListener, tempFilePath); } } } @@ -1424,7 +1424,7 @@ NS_IMETHODIMP nsExternalAppHandler::GetSource(nsIURI ** aSourceURI) NS_IMETHODIMP nsExternalAppHandler::GetSuggestedFileName(PRUnichar ** aSuggestedFileName) { - *aSuggestedFileName = ToNewUnicode(mSuggestedFileName); + *aSuggestedFileName = ToNewUnicode(NS_ConvertUTF8toUCS2(mSuggestedFileName)); return NS_OK; } @@ -1463,7 +1463,10 @@ nsresult nsExternalAppHandler::ShowProgressDialog() nsCOMPtr file = do_QueryInterface(appl); if (file) { - file->GetUnicodeLeafName(getter_Copies(openWith)); + nsCAutoString leafName; + file->GetLeafName(leafName); + if (!leafName.IsEmpty()) + openWith = NS_ConvertUTF8toUCS2(leafName); } } } @@ -1480,7 +1483,7 @@ nsresult nsExternalAppHandler::ShowProgressDialog() return rv; } -nsresult nsExternalAppHandler::PromptForSaveToFile(nsILocalFile ** aNewFile, const PRUnichar * aDefaultFile, const PRUnichar * aFileExtension) +nsresult nsExternalAppHandler::PromptForSaveToFile(nsILocalFile ** aNewFile, const nsACString &aDefaultFile, const nsACString &aFileExtension) { // invoke the dialog!!!!! use mWindowContext as the window context parameter for the dialog request // XXX Convert to use file picker? @@ -1495,8 +1498,10 @@ nsresult nsExternalAppHandler::PromptForSaveToFile(nsILocalFile ** aNewFile, con // we want to explicitly unescape aDefaultFile b4 passing into the dialog. we can't unescape // it because the dialog is implemented by a JS component which doesn't have a window so no unescape routine is defined... - rv = mDialog->PromptForSaveToFile(mWindowContext, aDefaultFile, aFileExtension, aNewFile); - + rv = mDialog->PromptForSaveToFile(mWindowContext, + NS_ConvertUTF8toUCS2(aDefaultFile).get(), + NS_ConvertUTF8toUCS2(aFileExtension).get(), + aNewFile); return rv; } @@ -1522,8 +1527,8 @@ nsresult nsExternalAppHandler::MoveFile(nsIFile * aNewFileLocation) fileToUse->Remove(PR_FALSE); // extract the new leaf name from the file location - nsXPIDLCString fileName; - fileToUse->GetLeafName(getter_Copies(fileName)); + nsCAutoString fileName; + fileToUse->GetLeafName(fileName); nsCOMPtr directoryLocation; fileToUse->GetParent(getter_AddRefs(directoryLocation)); if (directoryLocation) @@ -1533,9 +1538,9 @@ nsresult nsExternalAppHandler::MoveFile(nsIFile * aNewFileLocation) if (NS_FAILED(rv) && mWebProgressListener) { // Send error notification. - nsXPIDLString path; - fileToUse->GetUnicodePath(getter_Copies(path)); - SendStatusChange(kWriteError, rv, nsnull, mWebProgressListener, path.get()); + nsCAutoString path; + fileToUse->GetPath(path); + SendStatusChange(kWriteError, rv, nsnull, mWebProgressListener, path); } } @@ -1560,21 +1565,21 @@ NS_IMETHODIMP nsExternalAppHandler::SaveToDisk(nsIFile * aNewFileLocation, PRBoo if (!aNewFileLocation) { - nsXPIDLString leafName; + nsCAutoString leafName; nsCOMPtr fileToUse; - mTempFile->GetUnicodeLeafName(getter_Copies(leafName)); + mTempFile->GetLeafName(leafName); if (mSuggestedFileName.IsEmpty()) - rv = PromptForSaveToFile(getter_AddRefs(fileToUse), leafName, NS_ConvertASCIItoUCS2(mTempFileExtension).get()); + rv = PromptForSaveToFile(getter_AddRefs(fileToUse), leafName, mTempFileExtension); else { - nsAutoString fileExt; - PRInt32 pos = mSuggestedFileName.RFindChar(PRUnichar('.')); + nsCAutoString fileExt; + PRInt32 pos = mSuggestedFileName.RFindChar('.'); if (pos >= 0) mSuggestedFileName.Right(fileExt, mSuggestedFileName.Length() - pos); if (fileExt.IsEmpty()) - fileExt = NS_ConvertASCIItoUCS2(mTempFileExtension).get(); + fileExt = mTempFileExtension; - rv = PromptForSaveToFile(getter_AddRefs(fileToUse), mSuggestedFileName.get(), fileExt.get()); + rv = PromptForSaveToFile(getter_AddRefs(fileToUse), mSuggestedFileName, fileExt); } if (NS_FAILED(rv) || !fileToUse) @@ -1616,9 +1621,9 @@ nsresult nsExternalAppHandler::OpenWithApplication(nsIFile * aApplication) if (NS_FAILED(rv) && mWebProgressListener) { // Send error notification. - nsXPIDLString path; - mFinalFileDestination->GetUnicodePath(getter_Copies(path)); - SendStatusChange(kLaunchError, rv, nsnull, mWebProgressListener,path.get()); + nsCAutoString path; + mFinalFileDestination->GetPath(path); + SendStatusChange(kLaunchError, rv, nsnull, mWebProgressListener, path); } #ifndef XP_MAC @@ -1672,12 +1677,10 @@ NS_IMETHODIMP nsExternalAppHandler::LaunchWithApplication(nsIFile * aApplication if (mSuggestedFileName.IsEmpty()) { // Keep using the leafname of the temp file, since we're just starting a helper - PRUnichar* filename; - mTempFile->GetUnicodeLeafName(&filename); - mSuggestedFileName.Adopt(filename); + mTempFile->GetLeafName(mSuggestedFileName); } - fileToUse->AppendUnicode(mSuggestedFileName.get()); + fileToUse->Append(mSuggestedFileName); // We'll make sure this results in a unique name later mFinalFileDestination = do_QueryInterface(fileToUse); @@ -1951,30 +1954,29 @@ NS_IMETHODIMP nsExternalHelperAppService::GetTypeFromURI(nsIURI *aURI, char **aC NS_IMETHODIMP nsExternalHelperAppService::GetTypeFromFile( nsIFile* aFile, char **aContentType ) { - nsresult rv; - nsCOMPtr info; + nsresult rv; + nsCOMPtr info; - // Get the Extension - char* fileName; - const char* ext = nsnull; - rv = aFile->GetLeafName(&fileName); + // Get the Extension + nsCAutoString fileName; + const char* ext = nsnull; + rv = aFile->GetLeafName(fileName); if (NS_FAILED(rv)) return rv; - if (fileName != nsnull) + if (!fileName.IsEmpty()) { - PRInt32 len = strlen(fileName); + PRInt32 len = fileName.Length(); for (PRInt32 i = len; i >= 0; i--) { if (fileName[i] == '.') { - ext = &fileName[i + 1]; + ext = fileName.get() + i + 1; break; } } } nsCString fileExt( ext ); - nsCRT::free(fileName); // Handle the mac case #ifdef XP_MAC nsCOMPtr macFile; diff --git a/mozilla/uriloader/exthandler/nsExternalHelperAppService.h b/mozilla/uriloader/exthandler/nsExternalHelperAppService.h index 5e578caafa5..9aba82b832d 100644 --- a/mozilla/uriloader/exthandler/nsExternalHelperAppService.h +++ b/mozilla/uriloader/exthandler/nsExternalHelperAppService.h @@ -169,13 +169,13 @@ public: protected: nsCOMPtr mTempFile; nsCOMPtr mSourceUrl; - nsCString mTempFileExtension; + nsCString mTempFileExtension; // UTF-8 nsCOMPtr mMimeInfo; nsCOMPtr mOutStream; // output stream to the temp file... nsCOMPtr mWindowContext; // the following field is set if we were processing an http channel that had a content disposition header // which specified the SUGGESTED file name we should present to the user in the save to disk dialog. - nsString mSuggestedFileName; + nsCString mSuggestedFileName; // UTF-8 // the canceled flag is set if the user canceled the launching of this application before we finished // saving the data to a temp file... @@ -204,7 +204,7 @@ protected: // if the user tells us how they want to dispose of the content and we still haven't finished downloading while // they were deciding, then throw a progress dialog so they know what's going on... nsresult ShowProgressDialog(); - nsresult PromptForSaveToFile(nsILocalFile ** aNewFile, const PRUnichar * aDefaultFile, const PRUnichar * aDefaultFileExt); + nsresult PromptForSaveToFile(nsILocalFile ** aNewFile, const nsACString &aDefaultFile, const nsACString &aDefaultFileExt); // if the passed in channel is an nsIHTTPChannel, we'll attempt to extract a suggested file name // from the content disposition header... void ExtractSuggestedFileNameFromChannel(nsIChannel * aChannel); diff --git a/mozilla/uriloader/exthandler/unix/nsOSHelperAppService.cpp b/mozilla/uriloader/exthandler/unix/nsOSHelperAppService.cpp index 7cf6f53a51f..ca13a342a9b 100644 --- a/mozilla/uriloader/exthandler/unix/nsOSHelperAppService.cpp +++ b/mozilla/uriloader/exthandler/unix/nsOSHelperAppService.cpp @@ -140,8 +140,9 @@ NS_IMETHODIMP nsOSHelperAppService::LaunchAppWithTempFile(nsIMIMEInfo * aMIMEInf if (aMIMEInfo) { nsCOMPtr application; - nsXPIDLCString path; - aTempFile->GetPath(getter_Copies(path)); + + nsCAutoString path; + aTempFile->GetNativePath(path); aMIMEInfo->GetPreferredApplicationHandler(getter_AddRefs(application)); if (application) @@ -327,7 +328,7 @@ CreateInputStream(const nsAString& aFilename, nsCOMPtr file(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv)); if (NS_FAILED(rv)) return rv; - rv = file->InitWithUnicodePath(PromiseFlatString(aFilename).get()); + rv = file->InitWithPath(NS_ConvertUCS2toUTF8(aFilename)); if (NS_FAILED(rv)) return rv; @@ -895,7 +896,7 @@ GetHandlerAndDescriptionFromMailcapFile(const nsAString& aFilename, nsCOMPtr file(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv)); if (NS_FAILED(rv)) return rv; - rv = file->InitWithUnicodePath(PromiseFlatString(aFilename).get()); + rv = file->InitWithPath(NS_ConvertUCS2toUTF8(aFilename)); if (NS_FAILED(rv)) return rv; @@ -1093,14 +1094,14 @@ nsresult nsOSHelperAppService::GetFileTokenForPath(const PRUnichar * platformApp // first check if this is a full path PRBool exists = PR_FALSE; if (*platformAppPath == '/') { - localFile->InitWithUnicodePath(platformAppPath); + localFile->InitWithPath(NS_ConvertUCS2toUTF8(platformAppPath)); localFile->Exists(&exists); } else { + // ugly hack. Walk the PATH variable... char* unixpath = PR_GetEnv("PATH"); - nsAutoString path; - path.Assign(NS_ConvertUTF8toUCS2(unixpath)); - nsAString::const_iterator start_iter, end_iter, colon_iter; + nsCAutoString path(unixpath); + nsACString::const_iterator start_iter, end_iter, colon_iter; path.BeginReading(start_iter); colon_iter = start_iter; @@ -1110,8 +1111,8 @@ nsresult nsOSHelperAppService::GetFileTokenForPath(const PRUnichar * platformApp while (colon_iter != end_iter && *colon_iter != ':') { ++colon_iter; } - localFile->InitWithUnicodePath(PromiseFlatString(Substring(start_iter, colon_iter)).get()); - rv = localFile->AppendRelativeUnicodePath(platformAppPath); + localFile->InitWithNativePath(PromiseFlatCString(Substring(start_iter, colon_iter))); + rv = localFile->AppendRelativePath(NS_ConvertUCS2toUTF8(platformAppPath)); if (NS_SUCCEEDED(rv)) { localFile->Exists(&exists); if (!exists) { diff --git a/mozilla/uriloader/exthandler/win/nsOSHelperAppService.cpp b/mozilla/uriloader/exthandler/win/nsOSHelperAppService.cpp index 4e2f2661038..b7f1a1490ea 100644 --- a/mozilla/uriloader/exthandler/win/nsOSHelperAppService.cpp +++ b/mozilla/uriloader/exthandler/win/nsOSHelperAppService.cpp @@ -51,8 +51,8 @@ NS_IMETHODIMP nsOSHelperAppService::LaunchAppWithTempFile(nsIMIMEInfo * aMIMEInf if (aMIMEInfo) { nsCOMPtr application; - nsXPIDLCString path; - aTempFile->GetPath(getter_Copies(path)); + nsCAutoString path; + aTempFile->GetNativePath(path); nsMIMEInfoHandleAction action = nsIMIMEInfo::useSystemDefault; aMIMEInfo->GetPreferredAction(&action); @@ -62,7 +62,7 @@ NS_IMETHODIMP nsOSHelperAppService::LaunchAppWithTempFile(nsIMIMEInfo * aMIMEInf { // if we were given an application to use then use it....otherwise // make the registry call to launch the app - const char * strPath = (const char *) path; + const char * strPath = path.get(); nsCOMPtr process = do_CreateInstance(NS_PROCESS_CONTRACTID); nsresult rv; if (NS_FAILED(rv = process->Init(application))) @@ -218,7 +218,7 @@ NS_IMETHODIMP nsOSHelperAppService::LoadUrl(nsIURI * aURL) { // extract the url spec from the url nsCAutoString urlSpec; - aURL->GetSpec(urlSpec); + aURL->GetAsciiSpec(urlSpec); LONG r = (LONG) ::ShellExecute( NULL, "open", urlSpec.get(), NULL, NULL, SW_SHOWNORMAL); if (r < 32) @@ -236,7 +236,7 @@ nsresult nsOSHelperAppService::GetFileTokenForPath(const PRUnichar * platformApp if (localFile) { if (localFile) - localFile->InitWithUnicodePath(platformAppPath); + localFile->InitWithPath(NS_ConvertUCS2toUTF8(platformAppPath)); *aFile = localFile; NS_IF_ADDREF(*aFile); } diff --git a/mozilla/widget/src/windows/nsClipboard.cpp b/mozilla/widget/src/windows/nsClipboard.cpp index 4eb6eebdcaf..57cad294102 100644 --- a/mozilla/widget/src/windows/nsClipboard.cpp +++ b/mozilla/widget/src/windows/nsClipboard.cpp @@ -566,9 +566,9 @@ nsresult nsClipboard::GetDataFromDataObject(IDataObject * aDataObject, nsCOMPtr genericDataWrapper; if ( strcmp(flavorStr, kFileMime) == 0 ) { // we have a file path in |data|. Create an nsLocalFile object. - char* filepath = NS_REINTERPRET_CAST(char*, data); + nsDependentCString filepath(NS_REINTERPRET_CAST(char*, data)); nsCOMPtr file; - if ( NS_SUCCEEDED(NS_NewLocalFile(filepath, PR_FALSE, getter_AddRefs(file))) ) + if ( NS_SUCCEEDED(NS_NewNativeLocalFile(filepath, PR_FALSE, getter_AddRefs(file))) ) genericDataWrapper = do_QueryInterface(file); } else { @@ -669,7 +669,7 @@ nsClipboard :: FindURLFromLocalFile ( IDataObject* inDataObject, UINT inIndex, v else { // we have a normal file, use some Necko objects to get our file path nsCOMPtr file; - if ( NS_SUCCEEDED(NS_NewLocalFile(filepath, PR_FALSE, getter_AddRefs(file))) ) { + if ( NS_SUCCEEDED(NS_NewNativeLocalFile(nsDependentCString(filepath), PR_FALSE, getter_AddRefs(file))) ) { nsCAutoString urlSpec; NS_GetURLSpecFromFile(file, urlSpec); diff --git a/mozilla/widget/src/windows/nsFilePicker.cpp b/mozilla/widget/src/windows/nsFilePicker.cpp index 37de8f4aa58..6aa6e130685 100644 --- a/mozilla/widget/src/windows/nsFilePicker.cpp +++ b/mozilla/widget/src/windows/nsFilePicker.cpp @@ -98,16 +98,12 @@ NS_IMETHODIMP nsFilePicker::Show(PRInt16 *retval) char *title = ConvertToFileSystemCharset(mTitle.get()); if (nsnull == title) title = ToNewCString(mTitle); - char *initialDir; - mDisplayDirectory->GetPath(&initialDir); + nsCAutoString initialDir; + mDisplayDirectory->GetNativePath(initialDir); // If no display directory, re-use the last one. - if(!initialDir || !*initialDir) { - // Free empty string returned from GetPath. - if (initialDir) { - nsMemory::Free(initialDir); - } + if(initialDir.IsEmpty()) { // Allocate copy of last used dir. - initialDir = NS_STATIC_CAST( char*, nsMemory::Clone(mLastUsedDirectory, PL_strlen(mLastUsedDirectory)+1) ); + initialDir = mLastUsedDirectory; } mFile.SetLength(0); @@ -115,7 +111,7 @@ NS_IMETHODIMP nsFilePicker::Show(PRInt16 *retval) if (mMode == modeGetFolder) { char dirBuffer[MAX_PATH+1]; - PL_strncpy(dirBuffer, initialDir, MAX_PATH); + PL_strncpy(dirBuffer, initialDir.get(), MAX_PATH); BROWSEINFO browserInfo; browserInfo.hwndOwner = mWnd; browserInfo.pidlRoot = nsnull; @@ -162,8 +158,8 @@ NS_IMETHODIMP nsFilePicker::Show(PRInt16 *retval) filterBuffer[len] = NULL; filterBuffer[len+1] = NULL; - if (initialDir && *initialDir) { - ofn.lpstrInitialDir = initialDir; + if (!initialDir.IsEmpty()) { + ofn.lpstrInitialDir = initialDir.get(); } ofn.lpstrTitle = title; @@ -249,9 +245,6 @@ NS_IMETHODIMP nsFilePicker::Show(PRInt16 *retval) } - if (initialDir) - nsMemory::Free(initialDir); - if (title) nsMemory::Free( title ); @@ -262,20 +255,18 @@ NS_IMETHODIMP nsFilePicker::Show(PRInt16 *retval) nsCOMPtr file(do_CreateInstance("@mozilla.org/file/local;1")); NS_ENSURE_TRUE(file, NS_ERROR_FAILURE); - file->InitWithPath(mFile.get()); + file->InitWithNativePath(mFile); nsCOMPtr dir; if (NS_SUCCEEDED(file->GetParent(getter_AddRefs(dir)))) { nsCOMPtr localDir(do_QueryInterface(dir)); if (localDir) { - char *newDir; - localDir->GetPath(&newDir); - if(newDir) { - PL_strncpyz(mLastUsedDirectory, newDir, MAX_PATH+1); - nsMemory::Free(newDir); - } + nsCAutoString newDir; + localDir->GetNativePath(newDir); + if(!newDir.IsEmpty()) + PL_strncpyz(mLastUsedDirectory, newDir.get(), MAX_PATH+1); // Update mDisplayDirectory with this directory, also. // Some callers rely on this. - mDisplayDirectory->InitWithPath( mLastUsedDirectory ); + mDisplayDirectory->InitWithNativePath( nsDependentCString(mLastUsedDirectory) ); } } @@ -308,7 +299,7 @@ NS_IMETHODIMP nsFilePicker::GetFile(nsILocalFile **aFile) NS_ENSURE_TRUE(file, NS_ERROR_FAILURE); - file->InitWithPath(mFile.get()); + file->InitWithNativePath(mFile); NS_ADDREF(*aFile = file); @@ -320,7 +311,7 @@ NS_IMETHODIMP nsFilePicker::GetFileURL(nsIFileURL **aFileURL) { nsCOMPtr file(do_CreateInstance("@mozilla.org/file/local;1")); NS_ENSURE_TRUE(file, NS_ERROR_FAILURE); - file->InitWithPath(mFile.get()); + file->InitWithNativePath(mFile); nsCOMPtr uri; NS_NewFileURI(getter_AddRefs(uri), file); diff --git a/mozilla/widget/src/windows/nsWindow.cpp b/mozilla/widget/src/windows/nsWindow.cpp index 97c75da75d2..246d3c09617 100644 --- a/mozilla/widget/src/windows/nsWindow.cpp +++ b/mozilla/widget/src/windows/nsWindow.cpp @@ -5012,11 +5012,11 @@ NS_METHOD nsWindow::SetIcon(const nsAString& anIconSpec) return NS_ERROR_FAILURE; } // Get native file name of that directory. - nsXPIDLString rootPath; - chromeDir->GetUnicodePath( getter_Copies( rootPath ) ); + nsCAutoString rootPath; + chromeDir->GetPath( rootPath ); // Start there. - nsAutoString iconPath( rootPath ); + NS_ConvertUTF8toUCS2 iconPath( rootPath ); // Now take input path... nsAutoString iconSpec( anIconSpec ); @@ -5051,20 +5051,20 @@ NS_METHOD nsWindow::SetIcon(const nsAString& anIconSpec) // See if unicode API not implemented and if not, try ascii version if ( ::GetLastError() == ERROR_CALL_NOT_IMPLEMENTED ) { nsCOMPtr pathConverter; - if ( NS_SUCCEEDED( NS_NewUnicodeLocalFile( iconPath.get(), - PR_FALSE, - getter_AddRefs( pathConverter ) ) ) ) { + if ( NS_SUCCEEDED( NS_NewLocalFile( NS_ConvertUCS2toUTF8(iconPath), + PR_FALSE, + getter_AddRefs( pathConverter ) ) ) ) { // Now try the char* path. - nsXPIDLCString aPath; - pathConverter->GetPath( getter_Copies( aPath ) ); + nsCAutoString aPath; + pathConverter->GetNativePath( aPath ); bigIcon = (HICON)::LoadImage( NULL, - (const char*)aPath, + aPath.get(), IMAGE_ICON, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON), LR_LOADFROMFILE | LR_SHARED ); smallIcon = (HICON)::LoadImage( NULL, - (const char*)aPath, + aPath.get(), IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), diff --git a/mozilla/xpcom/build/dlldeps.cpp b/mozilla/xpcom/build/dlldeps.cpp index 50a0f670452..844d3343a3d 100644 --- a/mozilla/xpcom/build/dlldeps.cpp +++ b/mozilla/xpcom/build/dlldeps.cpp @@ -170,7 +170,8 @@ void XXXNeverCalled() nsPrintfCString bar(""); nsLinebreakConverter::ConvertStringLineBreaks(foo, nsLinebreakConverter::eLinebreakAny, nsLinebreakConverter::eLinebreakContent); - NS_NewLocalFile(NULL, PR_FALSE, NULL); + NS_NewLocalFile(nsCString(), PR_FALSE, NULL); + NS_NewNativeLocalFile(nsCString(), PR_FALSE, NULL); nsProcess(); NS_NewByteArrayInputStream (NULL, NULL, 0); nsStaticCaseInsensitiveNameTable(); diff --git a/mozilla/xpcom/build/nsXPComInit.cpp b/mozilla/xpcom/build/nsXPComInit.cpp index a767836b254..e1fa6fddb36 100644 --- a/mozilla/xpcom/build/nsXPComInit.cpp +++ b/mozilla/xpcom/build/nsXPComInit.cpp @@ -369,10 +369,9 @@ nsresult NS_COM NS_InitXPCOM2(nsIServiceManager* *result, gDirectoryService->Define(NS_XPCOM_INIT_CURRENT_PROCESS_DIR, binDirectory); //Since people are still using the nsSpecialSystemDirectory, we should init it. - char* path; - binDirectory->GetPath(&path); - nsFileSpec spec(path); - nsMemory::Free(path); + nsCAutoString path; + binDirectory->GetPath(path); + nsFileSpec spec(path.get()); nsSpecialSystemDirectory::Set(nsSpecialSystemDirectory::Moz_BinDirectory, &spec); diff --git a/mozilla/xpcom/components/nsComponentManager.cpp b/mozilla/xpcom/components/nsComponentManager.cpp index 8fdbde30abb..2cb3992edd0 100644 --- a/mozilla/xpcom/components/nsComponentManager.cpp +++ b/mozilla/xpcom/components/nsComponentManager.cpp @@ -921,14 +921,12 @@ nsComponentManagerImpl::PlatformInit(void) if (!mComponentsDir) return NS_ERROR_OUT_OF_MEMORY; - char* componentDescriptor; - mComponentsDir->GetPath(&componentDescriptor); - if (!componentDescriptor) - return NS_ERROR_NULL_POINTER; + nsCAutoString componentDescriptor; + rv = mComponentsDir->GetNativePath(componentDescriptor); + if (NS_FAILED(rv)) + return rv; - mComponentsOffset = strlen(componentDescriptor); - - nsMemory::Free(componentDescriptor); + mComponentsOffset = componentDescriptor.Length(); if (mNativeComponentLoader) { /* now that we have the registry, Init the native loader */ @@ -2300,38 +2298,35 @@ nsComponentManagerImpl::RegistryLocationForSpec(nsIFile *aSpec, PRBool containedIn; mComponentsDir->Contains(aSpec, PR_TRUE, &containedIn); - char *persistentDescriptor; + nsCAutoString persistentDescriptor; if (containedIn){ - - rv = aSpec->GetPath(&persistentDescriptor); + rv = aSpec->GetNativePath(persistentDescriptor); if (NS_FAILED(rv)) return rv; - char* relativeLocation = persistentDescriptor + mComponentsOffset + 1; + const char* relativeLocation = persistentDescriptor.get() + mComponentsOffset + 1; rv = MakeRegistryName(relativeLocation, XPCOM_RELCOMPONENT_PREFIX, aRegistryName); } else { /* absolute names include volume info on Mac, so persistent descriptor */ - rv = aSpec->GetPath(&persistentDescriptor); + rv = aSpec->GetNativePath(persistentDescriptor); if (NS_FAILED(rv)) return rv; - rv = MakeRegistryName(persistentDescriptor, XPCOM_ABSCOMPONENT_PREFIX, + rv = MakeRegistryName(persistentDescriptor.get(), XPCOM_ABSCOMPONENT_PREFIX, aRegistryName); } - if (persistentDescriptor) - nsMemory::Free(persistentDescriptor); - return rv; - } nsresult nsComponentManagerImpl::SpecForRegistryLocation(const char *aLocation, nsIFile **aSpec) { + // i18n: assuming aLocation is encoded for the current locale + nsresult rv; if (!aLocation || !aSpec) return NS_ERROR_NULL_POINTER; @@ -2342,7 +2337,7 @@ nsComponentManagerImpl::SpecForRegistryLocation(const char *aLocation, nsLocalFile* file = new nsLocalFile; if (!file) return NS_ERROR_FAILURE; - rv = file->InitWithPath(((char *)aLocation + 4)); + rv = file->InitWithNativePath(nsDependentCString((char *)aLocation + 4)); file->QueryInterface(NS_GET_IID(nsILocalFile), (void**)aSpec); return rv; } @@ -2357,7 +2352,7 @@ nsComponentManagerImpl::SpecForRegistryLocation(const char *aLocation, if (NS_FAILED(rv)) return rv; - rv = file->AppendRelativePath(aLocation + 4); + rv = file->AppendRelativeNativePath(nsDependentCString(aLocation + 4)); *aSpec = file; return rv; } diff --git a/mozilla/xpcom/components/nsIRegistry.idl b/mozilla/xpcom/components/nsIRegistry.idl index 78b3ba67f76..36d4c641a15 100644 --- a/mozilla/xpcom/components/nsIRegistry.idl +++ b/mozilla/xpcom/components/nsIRegistry.idl @@ -18,6 +18,8 @@ #include "nsISupports.idl" #include "nsIEnumerator.idl" +interface nsIFile; + typedef PRUint32 nsRegistryKey; typedef long nsWellKnownRegistry; @@ -35,7 +37,7 @@ interface nsIRegistry : nsISupports // Dont use this one. This for internal use only. const long ApplicationCustomRegistry = -1; - void open(in string regFile); + void open(in nsIFile regFile); void openWellKnownRegistry(in nsWellKnownRegistry regid); void flush(); diff --git a/mozilla/xpcom/components/nsNativeComponentLoader.cpp b/mozilla/xpcom/components/nsNativeComponentLoader.cpp index 79b1766d5ad..98e2e021ecd 100644 --- a/mozilla/xpcom/components/nsNativeComponentLoader.cpp +++ b/mozilla/xpcom/components/nsNativeComponentLoader.cpp @@ -774,24 +774,23 @@ nsNativeComponentLoader::AutoRegisterComponent(PRInt32 when, } #else - char *leafName = NULL; - rv = component->GetLeafName(&leafName); + nsCAutoString leafName; + rv = component->GetNativeLeafName(leafName); if (NS_FAILED(rv)) return rv; - int flen = PL_strlen(leafName); + int flen = leafName.Length(); for (int i=0; ValidDllExtensions[i] != NULL; i++) { int extlen = PL_strlen(ValidDllExtensions[i]); // Does fullname end with this extension if (flen >= extlen && - !PL_strcasecmp(&(leafName[flen - extlen]), ValidDllExtensions[i]) + !PL_strcasecmp(leafName.get() + (flen - extlen), ValidDllExtensions[i]) ) { validExtension = PR_TRUE; break; } } - if (leafName) nsMemory::Free(leafName); #endif if (validExtension == PR_FALSE) @@ -859,9 +858,9 @@ nsNativeComponentLoader::AutoRegisterComponent(PRInt32 when, nsCOMPtr dllSpec; if (NS_SUCCEEDED(dll->GetDllSpec(getter_AddRefs(dllSpec))) && dllSpec) { - nsXPIDLCString dllLeafName; - dllSpec->GetLeafName(getter_Copies(dllLeafName)); - fileName.AssignWithConversion(dllLeafName); + nsCAutoString dllLeafName; + dllSpec->GetLeafName(dllLeafName); // XXX + fileName.Assign(NS_ConvertUTF8toUCS2(dllLeafName)); } // this string can't come from a string bundle, because we diff --git a/mozilla/xpcom/components/nsRegistry.cpp b/mozilla/xpcom/components/nsRegistry.cpp index 6160338ec6e..3592cda4db4 100644 --- a/mozilla/xpcom/components/nsRegistry.cpp +++ b/mozilla/xpcom/components/nsRegistry.cpp @@ -367,7 +367,7 @@ NS_IMPL_ISUPPORTS1( nsRegistryValue, nsIRegistryValue ) | Vanilla nsRegistry constructor. | ------------------------------------------------------------------------------*/ nsRegistry::nsRegistry() - : mReg(0), mCurRegFile(nsnull), mCurRegID(0) { + : mReg(0), mCurRegID(0) { NS_INIT_REFCNT(); #ifdef EXTRA_THREADSAFE mregLock = PR_NewLock(); @@ -382,8 +382,6 @@ nsRegistry::~nsRegistry() { if( mReg ) { Close(); } - if (mCurRegFile) - nsCRT::free(mCurRegFile); #ifdef EXTRA_THREADSAFE if (mregLock) { PR_DestroyLock(mregLock); @@ -397,7 +395,7 @@ nsRegistry::~nsRegistry() { | file. We first check to see if a registry file is already open and close | | it if so. | ------------------------------------------------------------------------------*/ -NS_IMETHODIMP nsRegistry::Open( const char *regFile ) { +NS_IMETHODIMP nsRegistry::Open( nsIFile *regFile ) { REGERR err = REGERR_OK; // Check for default. @@ -405,8 +403,12 @@ NS_IMETHODIMP nsRegistry::Open( const char *regFile ) { return OpenWellKnownRegistry(nsIRegistry::ApplicationRegistry); } + nsCAutoString regPath; + nsresult rv = regFile->GetNativePath(regPath); + if (NS_FAILED(rv)) return rv; + #ifdef DEBUG_dp - printf("nsRegistry: Opening registry %s\n", regFile); + printf("nsRegistry: Opening registry %s\n", regPath.get()); #endif /* DEBUG_dp */ if (mCurRegID != nsIRegistry::None && mCurRegID != nsIRegistry::ApplicationCustomRegistry) @@ -418,7 +420,8 @@ NS_IMETHODIMP nsRegistry::Open( const char *regFile ) { // Do we have an open registry ? if (mCurRegID != nsIRegistry::None) { - if (mCurRegFile && !nsCRT::strcmp(regFile, mCurRegFile)) + PRBool equals; + if (mCurRegFile && NS_SUCCEEDED(mCurRegFile->Equals(regFile, &equals)) && equals) { // The right one is already open return NS_OK; @@ -433,12 +436,14 @@ NS_IMETHODIMP nsRegistry::Open( const char *regFile ) { // Open specified registry. PR_Lock(mregLock); - err = NR_RegOpen((char*)regFile, &mReg ); + err = NR_RegOpen(NS_CONST_CAST(char*,regPath.get()), &mReg); PR_Unlock(mregLock); mCurRegID = nsIRegistry::ApplicationCustomRegistry; + // No error checking for no mem. Trust me. - mCurRegFile = nsCRT::strdup(regFile); + if (NS_FAILED(regFile->Clone(getter_AddRefs(mCurRegFile)))) + mCurRegFile = nsnull; // not fatal // Convert the result. return regerr2nsresult( err ); @@ -521,7 +526,7 @@ NS_IMETHODIMP nsRegistry::OpenWellKnownRegistry( nsWellKnownRegistry regid ) nsCOMPtr registryLocation; PRBool foundReg = PR_FALSE; - char *regFile = nsnull; + nsCAutoString regFile; switch ( (nsWellKnownRegistry) regid ) { case ApplicationComponentRegistry: @@ -539,11 +544,11 @@ NS_IMETHODIMP nsRegistry::OpenWellKnownRegistry( nsWellKnownRegistry regid ) if (registryLocation) { foundReg = PR_TRUE; - registryLocation->GetPath(®File); // dougt fix... + rv = registryLocation->GetNativePath(regFile); // dougt fix... // dveditz needs to fix his registry so that I can pass an // nsIFile interface and not hack - if (!regFile) - return NS_ERROR_OUT_OF_MEMORY; + if (NS_FAILED(rv)) + return rv; } } @@ -563,11 +568,11 @@ NS_IMETHODIMP nsRegistry::OpenWellKnownRegistry( nsWellKnownRegistry regid ) if (registryLocation) { foundReg = PR_TRUE; - registryLocation->GetPath(®File); // dougt fix... + rv = registryLocation->GetNativePath(regFile); // dougt fix... // dveditz needs to fix his registry so that I can pass an // nsIFile interface and not hack - if (!regFile) - return NS_ERROR_OUT_OF_MEMORY; + if (NS_FAILED(rv)) + return rv; } } break; @@ -581,16 +586,13 @@ NS_IMETHODIMP nsRegistry::OpenWellKnownRegistry( nsWellKnownRegistry regid ) } #ifdef DEBUG_dp - printf("nsRegistry: Opening std registry %s\n", regFile); + printf("nsRegistry: Opening std registry %s\n", regFile.get()); #endif /* DEBUG_dp */ PR_Lock(mregLock); - err = NR_RegOpen((char*)regFile, &mReg ); + err = NR_RegOpen((char*)regFile.get(), &mReg ); PR_Unlock(mregLock); - if (regFile) - nsMemory::Free(regFile); - // Store the registry that was opened for optimizing future opens. mCurRegID = regid; @@ -618,8 +620,6 @@ NS_IMETHODIMP nsRegistry::Close() { err = NR_RegClose( mReg ); PR_Unlock(mregLock); mReg = 0; - if (mCurRegFile) - nsCRT::free(mCurRegFile); mCurRegFile = nsnull; mCurRegID = 0; } diff --git a/mozilla/xpcom/components/nsRegistry.h b/mozilla/xpcom/components/nsRegistry.h index b70cfb4ac0b..26164cccfe6 100644 --- a/mozilla/xpcom/components/nsRegistry.h +++ b/mozilla/xpcom/components/nsRegistry.h @@ -42,6 +42,8 @@ #include "nsIRegistry.h" #include "NSReg.h" +#include "nsIFile.h" +#include "nsCOMPtr.h" struct nsRegistry : public nsIRegistry, nsIRegistryGetter { // This class implements the nsISupports interface functions. @@ -64,7 +66,7 @@ protected: #ifdef EXTRA_THREADSAFE PRLock *mregLock; // libreg isn't threadsafe. Use locks to synchronize. #endif - char *mCurRegFile; // these are to prevent open from opening the registry again + nsCOMPtr mCurRegFile; // these are to prevent open from opening the registry again nsWellKnownRegistry mCurRegID; NS_IMETHOD Close(); diff --git a/mozilla/xpcom/components/xcDll.cpp b/mozilla/xpcom/components/xcDll.cpp index eb177d3119c..de903ab1d4b 100644 --- a/mozilla/xpcom/components/xcDll.cpp +++ b/mozilla/xpcom/components/xcDll.cpp @@ -94,7 +94,6 @@ nsDll::nsDll(nsIFile *dllSpec, const char *registryLocation) { m_modDate = LL_Zero(); m_size = LL_Zero(); - m_dllSpec = dllSpec; m_registryLocation = nsCRT::strdup(registryLocation); Init(dllSpec); @@ -113,7 +112,6 @@ nsDll::nsDll(nsIFile *dllSpec, const char *registryLocation, PRInt64* modDate, P { m_modDate = LL_Zero(); m_size = LL_Zero(); - m_dllSpec = dllSpec; m_registryLocation = nsCRT::strdup(registryLocation); Init(dllSpec); @@ -178,8 +176,7 @@ nsDll::Init(nsIFile *dllSpec) { // Load will fail anyway. So dont bother to stat the file - m_dllSpec = dllSpec; - + m_dllSpec = do_QueryInterface(dllSpec); m_status = DLL_OK; } @@ -210,7 +207,7 @@ nsDll::Init(const char *libPersistentDescriptor) return; } - rv = dllSpec->InitWithPath((char *)libPersistentDescriptor); + rv = dllSpec->InitWithNativePath(nsDependentCString(libPersistentDescriptor)); if (NS_FAILED(rv)) { m_status = DLL_INVALID_PARAM; @@ -233,10 +230,6 @@ nsDll::~nsDll(void) #endif if (m_dllName) nsCRT::free(m_dllName); - if (m_persistentDescriptor) - nsCRT::free(m_persistentDescriptor); - if (m_nativePath) - nsCRT::free(m_nativePath); if (m_registryLocation) nsCRT::free(m_registryLocation); @@ -261,10 +254,10 @@ nsDll::GetDisplayPath() { if (m_dllName) return m_dllName; - if (m_nativePath) - return m_nativePath; - m_dllSpec->GetPath(&m_nativePath); - return m_nativePath; + if (!m_nativePath.IsEmpty()) + return m_nativePath.get(); + m_dllSpec->GetNativePath(m_nativePath); + return m_nativePath.get(); } const char * @@ -272,10 +265,10 @@ nsDll::GetPersistentDescriptorString() { if (m_dllName) return m_dllName; - if (m_persistentDescriptor) - return m_persistentDescriptor; - m_dllSpec->GetPath(&m_persistentDescriptor); - return m_persistentDescriptor; + if (!m_persistentDescriptor.IsEmpty()) + return m_persistentDescriptor.get(); + m_dllSpec->GetNativePath(m_persistentDescriptor); + return m_persistentDescriptor.get(); } PRBool @@ -318,23 +311,19 @@ PRBool nsDll::Load(void) if (m_dllSpec) { - nsCOMPtr localFile = do_QueryInterface(m_dllSpec); - #ifdef NS_BUILD_REFCNT_LOGGING nsTraceRefcnt::SetActivityIsLegal(PR_FALSE); #endif - if (localFile) - localFile->Load(&m_instance); + m_dllSpec->Load(&m_instance); #ifdef NS_BUILD_REFCNT_LOGGING nsTraceRefcnt::SetActivityIsLegal(PR_TRUE); if (m_instance) { // Inform refcnt tracer of new library so that calls through the // new library can be traced. - char* displayPath; - m_dllSpec->GetPath(&displayPath); - nsTraceRefcnt::LoadLibrarySymbols(displayPath, m_instance); - nsMemory::Free(displayPath); + nsCAutoString displayPath; + m_dllSpec->GetNativePath(displayPath); + nsTraceRefcnt::LoadLibrarySymbols(displayPath.get(), m_instance); } #endif } diff --git a/mozilla/xpcom/components/xcDll.h b/mozilla/xpcom/components/xcDll.h index 72b5f1e1ccc..54b1552d2e9 100644 --- a/mozilla/xpcom/components/xcDll.h +++ b/mozilla/xpcom/components/xcDll.h @@ -49,8 +49,9 @@ #include "prio.h" #include "prlink.h" #include "nsISupports.h" -#include "nsIFile.h" +#include "nsILocalFile.h" #include "nsCOMPtr.h" +#include "nsString.h" class nsIModule; class nsIServiceManager; @@ -69,7 +70,7 @@ class nsDll private: char *m_dllName; // Stores the dllName to load. - nsCOMPtr m_dllSpec; // Filespec representing the component + nsCOMPtr m_dllSpec; // Filespec representing the component PRInt64 m_modDate; // last modified time at creation of this object PRInt64 m_size; // size of the dynamic library at creation of this object @@ -78,8 +79,8 @@ private: nsIModule *m_moduleObject; // Cache frequent queries - char *m_persistentDescriptor; - char *m_nativePath; + nsCString m_persistentDescriptor; + nsCString m_nativePath; PRBool m_markForUnload; char *m_registryLocation; diff --git a/mozilla/xpcom/io/Makefile.in b/mozilla/xpcom/io/Makefile.in index 4ee29f7e837..bcef84b336e 100644 --- a/mozilla/xpcom/io/Makefile.in +++ b/mozilla/xpcom/io/Makefile.in @@ -58,9 +58,9 @@ CPPSRCS = \ nsUnicharInputStream.cpp \ $(NULL) -ifneq ($(MOZ_WIDGET_TOOLKIT),os2) -CPPSRCS += nsLocalFileUnicode.cpp -endif +#ifneq ($(MOZ_WIDGET_TOOLKIT),os2) +#CPPSRCS += nsLocalFileUnicode.cpp +#endif ifeq ($(MOZ_WIDGET_TOOLKIT),os2) CPPSRCS += nsLocalFileOS2.cpp diff --git a/mozilla/xpcom/io/nsAppFileLocationProvider.cpp b/mozilla/xpcom/io/nsAppFileLocationProvider.cpp index 23982dee9af..523be86acc2 100755 --- a/mozilla/xpcom/io/nsAppFileLocationProvider.cpp +++ b/mozilla/xpcom/io/nsAppFileLocationProvider.cpp @@ -60,19 +60,19 @@ // come from localizable resources #if defined(XP_MAC) /* || defined(XP_MACOSX) REMIND HACKING FOR MACOS X!!! */ -#define APP_REGISTRY_NAME "Application Registry" -#define ESSENTIAL_FILES "Essential Files" +#define APP_REGISTRY_NAME NS_LITERAL_CSTRING("Application Registry") +#define ESSENTIAL_FILES NS_LITERAL_CSTRING("Essential Files") #elif defined(XP_WIN) || defined(XP_OS2) -#define APP_REGISTRY_NAME "registry.dat" +#define APP_REGISTRY_NAME NS_LITERAL_CSTRING("registry.dat") #else -#define APP_REGISTRY_NAME "appreg" +#define APP_REGISTRY_NAME NS_LITERAL_CSTRING("appreg") #endif // define default product directory #if defined(XP_WIN) || defined(XP_MAC) || defined(XP_OS2) || defined(XP_BEOS) -#define DEFAULT_PRODUCT_DIR "Mozilla" +#define DEFAULT_PRODUCT_DIR NS_LITERAL_CSTRING("Mozilla") #elif defined (XP_UNIX) -#define DEFAULT_PRODUCT_DIR ".mozilla" +#define DEFAULT_PRODUCT_DIR NS_LITERAL_CSTRING(".mozilla") #endif // Locally defined keys used by nsAppDirectoryEnumerator @@ -80,21 +80,21 @@ #define NS_USER_PLUGINS_DIR "UserPlugins" #if XP_MAC -#define DEFAULTS_DIR_NAME "Defaults" -#define DEFAULTS_PREF_DIR_NAME "Pref" -#define DEFAULTS_PROFILE_DIR_NAME "Profile" -#define RES_DIR_NAME "Res" -#define CHROME_DIR_NAME "Chrome" -#define PLUGINS_DIR_NAME "Plug-ins" -#define SEARCH_DIR_NAME "Search Plugins" +#define DEFAULTS_DIR_NAME NS_LITERAL_CSTRING("Defaults") +#define DEFAULTS_PREF_DIR_NAME NS_LITERAL_CSTRING("Pref") +#define DEFAULTS_PROFILE_DIR_NAME NS_LITERAL_CSTRING("Profile") +#define RES_DIR_NAME NS_LITERAL_CSTRING("Res") +#define CHROME_DIR_NAME NS_LITERAL_CSTRING("Chrome") +#define PLUGINS_DIR_NAME NS_LITERAL_CSTRING("Plug-ins") +#define SEARCH_DIR_NAME NS_LITERAL_CSTRING("Search Plugins") #else -#define DEFAULTS_DIR_NAME "defaults" -#define DEFAULTS_PREF_DIR_NAME "pref" -#define DEFAULTS_PROFILE_DIR_NAME "profile" -#define RES_DIR_NAME "res" -#define CHROME_DIR_NAME "chrome" -#define PLUGINS_DIR_NAME "plugins" -#define SEARCH_DIR_NAME "searchplugins" +#define DEFAULTS_DIR_NAME NS_LITERAL_CSTRING("defaults") +#define DEFAULTS_PREF_DIR_NAME NS_LITERAL_CSTRING("pref") +#define DEFAULTS_PROFILE_DIR_NAME NS_LITERAL_CSTRING("profile") +#define RES_DIR_NAME NS_LITERAL_CSTRING("res") +#define CHROME_DIR_NAME NS_LITERAL_CSTRING("chrome") +#define PLUGINS_DIR_NAME NS_LITERAL_CSTRING("plugins") +#define SEARCH_DIR_NAME NS_LITERAL_CSTRING("searchplugins") #endif //***************************************************************************** @@ -191,7 +191,7 @@ nsAppFileLocationProvider::GetFile(const char *prop, PRBool *persistant, nsIFile { const char *pathVar = PR_GetEnv("MOZ_PLUGIN_PATH"); if (pathVar) - rv = NS_NewLocalFile(pathVar, PR_TRUE, getter_AddRefs(localFile)); + rv = NS_NewNativeLocalFile(nsDependentCString(pathVar), PR_TRUE, getter_AddRefs(localFile)); } else if (nsCRT::strcmp(prop, NS_USER_PLUGINS_DIR) == 0) { @@ -308,7 +308,7 @@ NS_METHOD nsAppFileLocationProvider::GetProductDirectory(nsILocalFile **aLocalFi } if (NS_FAILED(rv)) return rv; #elif defined(XP_UNIX) - rv = NS_NewLocalFile(PR_GetEnv("HOME"), PR_TRUE, getter_AddRefs(localDir)); + rv = NS_NewNativeLocalFile(nsDependentCString(PR_GetEnv("HOME")), PR_TRUE, getter_AddRefs(localDir)); if (NS_FAILED(rv)) return rv; #elif defined(XP_BEOS) char path[MAXPATHLEN]; @@ -319,7 +319,7 @@ NS_METHOD nsAppFileLocationProvider::GetProductDirectory(nsILocalFile **aLocalFi return NS_ERROR_FAILURE; path[len] = '/'; path[len+1] = '\0'; - rv = NS_NewLocalFile(path, PR_TRUE, getter_AddRefs(localDir)); + rv = NS_NewNativeLocalFile(nsDependentCString(path), PR_TRUE, getter_AddRefs(localDir)); if (NS_FAILED(rv)) return rv; #else #error dont_know_how_to_get_product_dir_on_your_platform @@ -358,7 +358,7 @@ NS_METHOD nsAppFileLocationProvider::GetDefaultUserProfileRoot(nsILocalFile **aL #if defined(XP_MAC) || defined(XP_MACOSX) || defined(XP_OS2) || defined(XP_PC) // These 3 platforms share this part of the path - do them as one - rv = localDir->AppendRelativePath("Profiles"); + rv = localDir->AppendRelativePath(NS_LITERAL_CSTRING("Profiles")); if (NS_FAILED(rv)) return rv; PRBool exists; diff --git a/mozilla/xpcom/io/nsDirectoryService.cpp b/mozilla/xpcom/io/nsDirectoryService.cpp index 4a987a209e9..f905dbe14d1 100644 --- a/mozilla/xpcom/io/nsDirectoryService.cpp +++ b/mozilla/xpcom/io/nsDirectoryService.cpp @@ -39,7 +39,6 @@ #include "nsCOMPtr.h" #include "nsDirectoryService.h" #include "nsDirectoryServiceDefs.h" -#include "nsILocalFile.h" #include "nsLocalFile.h" #include "nsDebug.h" @@ -79,11 +78,11 @@ #include "nsAppFileLocationProvider.h" #if defined(XP_MAC) -#define COMPONENT_REGISTRY_NAME "Component Registry" -#define COMPONENT_DIRECTORY "Components" +#define COMPONENT_REGISTRY_NAME NS_LITERAL_CSTRING("Component Registry") +#define COMPONENT_DIRECTORY NS_LITERAL_CSTRING("Components") #else -#define COMPONENT_REGISTRY_NAME "component.reg" -#define COMPONENT_DIRECTORY "components" +#define COMPONENT_REGISTRY_NAME NS_LITERAL_CSTRING("component.reg") +#define COMPONENT_DIRECTORY NS_LITERAL_CSTRING("components") #endif #if defined(XP_MAC) @@ -159,7 +158,7 @@ nsDirectoryService::GetCurrentProcessDirectory(nsILocalFile** aFile) if (lastSlash) *(lastSlash + 1) = '\0'; - localFile->InitWithPath(buf); + localFile->InitWithNativePath(nsDependentCString(buf)); *aFile = localFile; return NS_OK; } @@ -261,7 +260,7 @@ nsDirectoryService::GetCurrentProcessDirectory(nsILocalFile** aFile) if (moz5) { - localFile->InitWithPath(moz5); + localFile->InitWithNativePath(nsDependentCString(moz5)); localFile->Normalize(); *aFile = localFile; return NS_OK; @@ -279,7 +278,7 @@ nsDirectoryService::GetCurrentProcessDirectory(nsILocalFile** aFile) // Fall back to current directory. if (getcwd(buf, sizeof(buf))) { - localFile->InitWithPath(buf); + localFile->InitWithNativePath(nsDependentCString(buf)); *aFile = localFile; return NS_OK; } @@ -292,7 +291,7 @@ nsDirectoryService::GetCurrentProcessDirectory(nsILocalFile** aFile) DosGetInfoBlocks( &ptib, &ppib); DosQueryModuleName( ppib->pib_hmte, CCHMAXPATH, buffer); *strrchr( buffer, '\\') = '\0'; // XXX DBCS misery - localFile->InitWithPath(buffer); + localFile->InitWithNativePath(nsDependentCString(buffer)); *aFile = localFile; return NS_OK; @@ -301,7 +300,7 @@ nsDirectoryService::GetCurrentProcessDirectory(nsILocalFile** aFile) char *moz5 = getenv("MOZILLA_FIVE_HOME"); if (moz5) { - localFile->InitWithPath(moz5); + localFile->InitWithNativePath(nsDependentCString(moz5)); localFile->Normalize(); *aFile = localFile; return NS_OK; @@ -319,7 +318,7 @@ nsDirectoryService::GetCurrentProcessDirectory(nsILocalFile** aFile) if((p = strrchr(buf, '/')) != 0) { *p = 0; - localFile->InitWithPath(buf); + localFile->InitWithNativePath(nsDependentCString(buf)); *aFile = localFile; return NS_OK; } @@ -693,7 +692,7 @@ nsDirectoryService::Get(const char* prop, const nsIID & uuid, void* *result) NS_RELEASE(fileData.data); // addref occurs in FindProviderFile() return rv; } - + FindProviderFile(NS_STATIC_CAST(nsIDirectoryServiceProvider*, this), &fileData); if (fileData.data) { @@ -715,7 +714,7 @@ nsDirectoryService::Set(const char* prop, nsISupports* value) nsCStringKey key(prop); if (mHashtable->Exists(&key) || value == nsnull) return NS_ERROR_FAILURE; - + nsCOMPtr ourFile; value->QueryInterface(NS_GET_IID(nsIFile), getter_AddRefs(ourFile)); if (ourFile) @@ -723,8 +722,10 @@ nsDirectoryService::Set(const char* prop, nsISupports* value) nsCOMPtr cloneFile; ourFile->Clone (getter_AddRefs (cloneFile)); mHashtable->Put(&key, cloneFile); + return NS_OK; } + return NS_ERROR_FAILURE; } diff --git a/mozilla/xpcom/io/nsFastLoadFile.cpp b/mozilla/xpcom/io/nsFastLoadFile.cpp index 208b1bf0287..eda33380375 100644 --- a/mozilla/xpcom/io/nsFastLoadFile.cpp +++ b/mozilla/xpcom/io/nsFastLoadFile.cpp @@ -43,6 +43,8 @@ #include "nsEnumeratorUtils.h" #include "nsMemory.h" #include "nsXPIDLString.h" +#include "nsString.h" +#include "nsReadableUtils.h" #include "nsIComponentManager.h" #include "nsIFile.h" @@ -748,10 +750,10 @@ nsFastLoadFileReader::ReadFooter(nsFastLoadFooter *aFooter) if (LL_NE(fastLoadMtime, currentMtime)) { #ifdef DEBUG - nsXPIDLCString path; - file->GetPath(getter_Copies(path)); + nsCAutoString path; + file->GetPath(path); printf("%s mtime changed, invalidating FastLoad file\n", - (const char *)path); + path.get()); #endif return NS_ERROR_FAILURE; } @@ -1488,8 +1490,8 @@ struct nsDependencyMapEntry : public nsStringMapEntry { NS_IMETHODIMP nsFastLoadFileWriter::AddDependency(nsIFile* aFile) { - nsXPIDLCString path; - nsresult rv = aFile->GetPath(getter_Copies(path)); + nsCAutoString path; + nsresult rv = aFile->GetPath(path); if (NS_FAILED(rv)) return rv; @@ -1501,11 +1503,10 @@ nsFastLoadFileWriter::AddDependency(nsIFile* aFile) return NS_ERROR_OUT_OF_MEMORY; if (!entry->mString) { - const char* str = path; - void *tmp = nsMemory::Clone(str, strlen(str) + 1); + const char *tmp = ToNewCString(path); if (!tmp) return NS_ERROR_OUT_OF_MEMORY; - entry->mString = NS_REINTERPRET_CAST(const char*, tmp); + entry->mString = tmp; rv = aFile->GetLastModifiedTime(&entry->mLastModified); } return rv; diff --git a/mozilla/xpcom/io/nsFastLoadService.cpp b/mozilla/xpcom/io/nsFastLoadService.cpp index 85f306a3909..79cccdda5a4 100644 --- a/mozilla/xpcom/io/nsFastLoadService.cpp +++ b/mozilla/xpcom/io/nsFastLoadService.cpp @@ -147,7 +147,7 @@ nsFastLoadService::NewFastLoadFile(const char* aBaseName, nsIFile* *aResult) nsCAutoString name(aBaseName); MASSAGE_BASENAME(name); name += PLATFORM_FASL_SUFFIX; - rv = file->Append(name.get()); + rv = file->Append(name); if (NS_FAILED(rv)) return rv; @@ -356,8 +356,8 @@ nsFastLoadService::ComputeChecksum(nsIFile* aFile, nsIFastLoadReadControl* aControl, PRUint32 *aChecksum) { - nsXPIDLCString path; - nsresult rv = aFile->GetPath(getter_Copies(path)); + nsCAutoString path; + nsresult rv = aFile->GetPath(path); if (NS_FAILED(rv)) return rv; @@ -389,8 +389,8 @@ nsFastLoadService::CacheChecksum(nsIFile* aFile, nsIObjectOutputStream *aStream) if (NS_FAILED(rv)) return rv; - nsXPIDLCString path; - rv = aFile->GetPath(getter_Copies(path)); + nsCAutoString path; + rv = aFile->GetPath(path); if (NS_FAILED(rv)) return rv; diff --git a/mozilla/xpcom/io/nsFileSpec.cpp b/mozilla/xpcom/io/nsFileSpec.cpp index fb34bf25660..87a23056e31 100644 --- a/mozilla/xpcom/io/nsFileSpec.cpp +++ b/mozilla/xpcom/io/nsFileSpec.cpp @@ -48,6 +48,7 @@ #include "nsCOMPtr.h" #include "nsIServiceManager.h" +#include "nsILocalFile.h" #include #include @@ -1300,7 +1301,7 @@ NS_FileSpecToIFile(nsFileSpec* fileSpec, nsILocalFile* *result) file = do_QueryInterface(psmAppMacFile, &rv); } #else - rv = file->InitWithPath(fileSpec->GetNativePathCString()); + rv = file->InitWithNativePath(nsDependentCString(fileSpec->GetNativePathCString())); #endif if (NS_FAILED(rv)) return rv; diff --git a/mozilla/xpcom/io/nsFileSpecImpl.cpp b/mozilla/xpcom/io/nsFileSpecImpl.cpp index c29720de71d..718a42cefad 100644 --- a/mozilla/xpcom/io/nsFileSpecImpl.cpp +++ b/mozilla/xpcom/io/nsFileSpecImpl.cpp @@ -41,6 +41,8 @@ #include "nsIFileStream.h" #include "nsFileStream.h" +#include "nsILocalFile.h" + #include "prmem.h" NS_IMPL_THREADSAFE_ISUPPORTS1(nsFileSpecImpl, nsIFileSpec) @@ -833,6 +835,23 @@ nsresult NS_NewFileSpec(nsIFileSpec** result) return nsFileSpecImpl::Create(nsnull, NS_GET_IID(nsIFileSpec), (void**)result); } +//---------------------------------------------------------------------------------------- +nsresult NS_NewFileSpecFromIFile(nsIFile *aFile, nsIFileSpec **result) +//---------------------------------------------------------------------------------------- +{ + nsresult rv = nsFileSpecImpl::Create(nsnull, NS_GET_IID(nsIFileSpec), (void**)result); + if (NS_FAILED(rv)) return rv; + + nsCAutoString path; + rv = aFile->GetNativePath(path); + if (NS_FAILED(rv)) return rv; + + rv = (*result)->SetNativePath(path.get()); + if (NS_FAILED(rv)) + NS_RELEASE(*result); + return rv; +} + //---------------------------------------------------------------------------------------- nsresult NS_NewDirectoryIterator(nsIDirectoryIterator** result) //---------------------------------------------------------------------------------------- diff --git a/mozilla/xpcom/io/nsFileSpecMac.cpp b/mozilla/xpcom/io/nsFileSpecMac.cpp index fbcb398985f..e25b1483ea9 100644 --- a/mozilla/xpcom/io/nsFileSpecMac.cpp +++ b/mozilla/xpcom/io/nsFileSpecMac.cpp @@ -536,14 +536,14 @@ char* MacFileHelpers::PathNameFromFSSpec( const FSSpec& inSpec ) nsresult rv; FSSpec nonConstSpec = inSpec; - nsXPIDLCString path; + nsCAutoString path; nsCOMPtr macFile; rv = NS_NewLocalFileWithFSSpec(&nonConstSpec, PR_TRUE, getter_AddRefs(macFile)); if (NS_FAILED(rv)) return nsnull; nsCOMPtr localFile(do_QueryInterface(macFile, &rv)); if (NS_FAILED(rv)) return nsnull; - rv = localFile->GetPath(getter_Copies(path)); + rv = localFile->GetNativePath(path); if (NS_FAILED(rv)) return nsnull; PRInt32 strLen = path.Length(); result = new char [strLen + 1]; diff --git a/mozilla/xpcom/io/nsIFile.idl b/mozilla/xpcom/io/nsIFile.idl index 65bca881a8a..8c6376c13c7 100644 --- a/mozilla/xpcom/io/nsIFile.idl +++ b/mozilla/xpcom/io/nsIFile.idl @@ -57,8 +57,8 @@ interface nsIFile : nsISupports * A string which is intented to be a child node of the * nsIFile. */ - void append([const] in string node); - void appendUnicode([const] in wstring node); + void append(in AUTF8String node); + [noscript] void appendNative(in ACString node); /** * Normalize the pathName (e.g. removing .. and . components on Unix). @@ -91,8 +91,8 @@ interface nsIFile : nsISupports /** * Accessor to the leaf name of the file itself. */ - attribute string leafName; - attribute wstring unicodeLeafName; + attribute AUTF8String leafName; + [noscript] attribute ACString nativeLeafName; /** * copyTo @@ -120,8 +120,8 @@ interface nsIFile : nsISupports * which case the current leaf name will be used. * */ - void copyTo(in nsIFile newParentDir, [const] in string newName); - void copyToUnicode(in nsIFile newParentDir, [const] in wstring newName); + void copyTo(in nsIFile newParentDir, in AUTF8String newName); + [noscrpit] void CopyToNative(in nsIFile newParentDir, in ACString newName); /** * copyToFollowingLinks @@ -131,8 +131,8 @@ interface nsIFile : nsISupports * such as Unix and Linux always follow symbolic links * when copying. */ - void copyToFollowingLinks(in nsIFile newParentDir, [const] in string newName); - void copyToFollowingLinksUnicode(in nsIFile newParentDir, [const] in wstring newName); + void copyToFollowingLinks(in nsIFile newParentDir, in AUTF8String newName); + [noscript] void copyToFollowingLinksNative(in nsIFile newParentDir, in ACString newName); /** * moveTo @@ -159,8 +159,8 @@ interface nsIFile : nsISupports * which case the current leaf name will be used. * */ - void moveTo(in nsIFile newParentDir, [const] in string newName); - void moveToUnicode(in nsIFile newParentDir, [const] in wstring newName); + void moveTo(in nsIFile newParentDir, in AUTF8String newName); + [noscript] void moveToNative(in nsIFile newParentDir, in ACString newName); /** * This will try to delete this file. The 'recursive' flag @@ -215,11 +215,10 @@ interface nsIFile : nsISupports * path: * Find out what the nsIFile points at. */ - - readonly attribute string target; - readonly attribute wstring unicodeTarget; - readonly attribute string path; - readonly attribute wstring unicodePath; + readonly attribute AUTF8String target; + [noscript] readonly attribute ACString nativeTarget; + readonly attribute AUTF8String path; + [noscript] readonly attribute ACString nativePath; boolean exists(); boolean isWritable(); @@ -260,7 +259,6 @@ interface nsIFile : nsISupports * permissions. */ void createUnique(in unsigned long type, in unsigned long permissions); - /** * clone() diff --git a/mozilla/xpcom/io/nsIFileSpec.idl b/mozilla/xpcom/io/nsIFileSpec.idl index 3c6b4d7b863..58efda9fc95 100644 --- a/mozilla/xpcom/io/nsIFileSpec.idl +++ b/mozilla/xpcom/io/nsIFileSpec.idl @@ -182,6 +182,19 @@ NS_COM nsresult NS_NewFileSpecWithSpec(const nsFileSpec& aSrcFileSpec, nsIFileSp NS_COM nsresult NS_NewFileSpec(nsIFileSpec** result); NS_COM nsresult NS_NewDirectoryIterator(nsIDirectoryIterator** result); +// Convert from nsIFile to nsIFileSpec +// +// XXX This function is here only to assist with the migration from nsIFileSpec +// to nsIFile. This function will dissappear in future mozilla releases. +// +// ...ripped from nsPrefService.cpp: +// +// "So discouraged is the use of nsIFileSpec, nobody wanted to have this routine be +// public - It might lead to continued use of nsIFileSpec. Right now, [mozilla] has +// such a need for it, here it is. Let's stop having to use it though." +// +NS_COM nsresult NS_NewFileSpecFromIFile(nsIFile *aFile, nsIFileSpec **result); + #define NS_BOOL_ACCESSOR(_method) { PRBool yes; return NS_SUCCEEDED(f->_method(&yes)) && yes; } inline PRBool Exists(nsIFileSpec* f) NS_BOOL_ACCESSOR(Exists) inline PRBool Exists(nsIDirectoryIterator* f) NS_BOOL_ACCESSOR(Exists) diff --git a/mozilla/xpcom/io/nsILocalFile.idl b/mozilla/xpcom/io/nsILocalFile.idl index b6fb4656e8f..df97e985c34 100644 --- a/mozilla/xpcom/io/nsILocalFile.idl +++ b/mozilla/xpcom/io/nsILocalFile.idl @@ -60,8 +60,8 @@ interface nsILocalFile : nsIFile * error (NS_ERROR_FILE_UNRECOGNIZED_PATH). This * path must in native. */ - void initWithPath([const] in string filePath); - void initWithUnicodePath([const] in wstring filePath); + void initWithPath(in AUTF8String filePath); + [noscript] void initWithNativePath(in ACString filePath); /** * initWithFile @@ -109,15 +109,16 @@ interface nsILocalFile : nsIFile * this cannot contain .. or cannot start with a directory separator * XXXbe Why not? Bogus! */ - void appendRelativePath([const] in string relativeFilePath); - void appendRelativeUnicodePath([const] in wstring relativeFilePath); - + void appendRelativePath(in AUTF8String relativeFilePath); + [noscript] void appendRelativeNativePath(in ACString relativeFilePath); /** * Accessor to a null terminated string which will specify * the file in a persistent manner for disk storage. + * + * XXX charset undefined */ - attribute string persistentDescriptor; + attribute ACString persistentDescriptor; /** * reveal --> Ask the operating system to open the folder which contains @@ -164,9 +165,8 @@ interface nsILocalFile : nsIFile #define NS_LOCAL_FILE_CLASSNAME "Local File Specification" extern "C" NS_EXPORT nsresult -NS_NewLocalFile(const char* path, PRBool followLinks, nsILocalFile* *result); - +NS_NewLocalFile(const nsACString &path, PRBool followLinks, nsILocalFile* *result); extern "C" NS_EXPORT nsresult -NS_NewUnicodeLocalFile(const PRUnichar* path, PRBool followLinks, nsILocalFile* *result); +NS_NewNativeLocalFile(const nsACString &path, PRBool followLinks, nsILocalFile* *result); %} diff --git a/mozilla/xpcom/io/nsLocalFile.h b/mozilla/xpcom/io/nsLocalFile.h index 03d79fa643e..88789dbcc17 100644 --- a/mozilla/xpcom/io/nsLocalFile.h +++ b/mozilla/xpcom/io/nsLocalFile.h @@ -34,10 +34,21 @@ #define NS_LOCAL_FILE_CID {0x2e23e220, 0x60be, 0x11d3, {0x8c, 0x4a, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74}} +#define NS_DECL_NSLOCALFILE_UNICODE_METHODS \ + nsresult AppendUnicode(const PRUnichar *aNode); \ + nsresult GetUnicodeLeafName(PRUnichar **aLeafName); \ + nsresult SetUnicodeLeafName(const PRUnichar *aLeafName); \ + nsresult CopyToUnicode(nsIFile *aNewParentDir, const PRUnichar *aNewLeafName); \ + nsresult CopyToFollowingLinksUnicode(nsIFile *aNewParentDir, const PRUnichar *aNewLeafName); \ + nsresult MoveToUnicode(nsIFile *aNewParentDir, const PRUnichar *aNewLeafName); \ + nsresult GetUnicodeTarget(PRUnichar **aTarget); \ + nsresult GetUnicodePath(PRUnichar **aPath); \ + nsresult InitWithUnicodePath(const PRUnichar *aPath); \ + nsresult AppendRelativeUnicodePath(const PRUnichar *aRelativePath); + // nsXPComInit needs to know about how we are implemented, // so here we will export it. Other users should not depend // on this. - #ifdef XP_WIN #include "nsLocalFileWin.h" #elif defined(XP_MAC) && !defined(XP_MACOSX) @@ -52,4 +63,5 @@ void NS_StartupLocalFile(); void NS_ShutdownLocalFile(); + #endif diff --git a/mozilla/xpcom/io/nsLocalFileCommon.cpp b/mozilla/xpcom/io/nsLocalFileCommon.cpp index e6fb663bb8b..93f4950e78d 100644 --- a/mozilla/xpcom/io/nsLocalFileCommon.cpp +++ b/mozilla/xpcom/io/nsLocalFileCommon.cpp @@ -41,33 +41,18 @@ #include "nsString.h" #include "nsCOMPtr.h" -#include "nsXPIDLString.h" #include "nsReadableUtils.h" +#include "nsPrintfCString.h" void NS_StartupLocalFile() { -#ifdef XP_WIN - nsresult rv = NS_CreateShortcutResolver(); - NS_ASSERTION(NS_SUCCEEDED(rv), "Shortcut resolver could not be created"); -#endif -#ifdef XP_OS2 - nsresult rv = NS_CreateUnicodeConverters(); -#endif + nsLocalFile::GlobalInit(); } void NS_ShutdownLocalFile() { -#ifndef XP_OS2 - NS_ShutdownLocalFileUnicode(); -#endif - -#ifdef XP_WIN - NS_DestroyShortcutResolver(); -#endif -#ifdef XP_OS2 - NS_DestroyUnicodeConverters(); -#endif + nsLocalFile::GlobalShutdown(); } #if !defined(XP_MAC) @@ -76,11 +61,11 @@ nsLocalFile::InitWithFile(nsILocalFile *aFile) { NS_ENSURE_ARG(aFile); - nsXPIDLCString path; - aFile->GetPath(getter_Copies(path)); - if (!path) + nsCAutoString path; + aFile->GetPath(path); + if (path.IsEmpty()) return NS_ERROR_FAILURE; - return InitWithPath(path.get()); + return InitWithPath(path); } #endif @@ -95,73 +80,71 @@ nsLocalFile::CreateUnique(PRUint32 type, PRUint32 attributes) if (NS_SUCCEEDED(rv)) return NS_OK; if (rv != NS_ERROR_FILE_ALREADY_EXISTS) return rv; - char* leafName; - rv = GetLeafName(&leafName); + nsCAutoString leafName; + rv = GetNativeLeafName(leafName); if (NS_FAILED(rv)) return rv; - char* lastDot = strrchr(leafName, '.'); + char* lastDot = strrchr(leafName.get(), '.'); char suffix[kMaxFilenameLength + 1] = ""; if (lastDot) { strncpy(suffix, lastDot, kMaxFilenameLength); // include '.' suffix[kMaxFilenameLength] = 0; // make sure it's null terminated - *lastDot = '\0'; // strip suffix and dot. + leafName.SetLength(lastDot - leafName.get()); // strip suffix and dot. } // 27 should work on Macintosh, Unix, and Win32. const int maxRootLength = 27 - strlen(suffix) - 1; - if ((int)strlen(leafName) > (int)maxRootLength) - leafName[maxRootLength] = '\0'; + if ((int)leafName.Length() > (int)maxRootLength) + leafName.SetLength(maxRootLength); for (short indx = 1; indx < 10000; indx++) { // start with "Picture-1.jpg" after "Picture.jpg" exists - char newName[kMaxFilenameLength + 1]; - sprintf(newName, "%s-%d%s", leafName, indx, suffix); - SetLeafName(newName); + SetNativeLeafName(leafName + + nsPrintfCString("-%d", indx) + + nsDependentCString(suffix)); rv = Create(type, attributes); if (NS_SUCCEEDED(rv) || rv != NS_ERROR_FILE_ALREADY_EXISTS) { - nsMemory::Free(leafName); return rv; } } - nsMemory::Free(leafName); // The disk is full, sort of return NS_ERROR_FILE_TOO_BIG; } #if defined(XP_MAC) -const PRUnichar kPathSeparatorChar = ':'; +static const char kPathSeparatorChar = ':'; #elif defined(XP_WIN) || defined(XP_OS2) -const PRUnichar kPathSeparatorChar = '\\'; +static const char kPathSeparatorChar = '\\'; #elif defined(XP_UNIX) || defined(XP_BEOS) -const PRUnichar kPathSeparatorChar = '/'; +static const char kPathSeparatorChar = '/'; #else #error Need to define file path separator for your platform #endif #if defined(XP_MAC) -const char* kSlashStr = "/"; -const char* kESCSlashStr = "%2F"; +static const char kSlashStr[] = "/"; +static const char kESCSlashStr[] = "%2F"; #endif -static PRInt32 SplitPath(PRUnichar *path, PRUnichar **nodeArray, PRInt32 arrayLen) +static PRInt32 SplitPath(char *path, char **nodeArray, PRInt32 arrayLen) { if (*path == 0) return 0; - PRUnichar **nodePtr = nodeArray; + char **nodePtr = nodeArray; if (*path == kPathSeparatorChar) path++; *nodePtr++ = path; - for (PRUnichar *cp = path; *cp != 0; cp++) { + for (char *cp = path; *cp != 0; cp++) { if (*cp == kPathSeparatorChar) { *cp++ = 0; if (*cp != 0) { @@ -183,48 +166,42 @@ nsLocalFile::GetRelativeDescriptor(nsILocalFile *fromFile, nsACString& _retval) nsresult rv; _retval.Truncate(0); - PRUnichar *thisPath = nsnull, *fromPath = nsnull; - PRUnichar *thisNodes[kMaxNodesInPath], *fromNodes[kMaxNodesInPath]; + nsCAutoString thisPath, fromPath; + char *thisNodes[kMaxNodesInPath], *fromNodes[kMaxNodesInPath]; PRInt32 thisNodeCnt, fromNodeCnt, nodeIndex; - rv = GetUnicodePath(&thisPath); + rv = GetPath(thisPath); if (NS_FAILED(rv)) return rv; - rv = fromFile->GetUnicodePath(&fromPath); - if (NS_FAILED(rv)) { - nsMemory::Free(thisPath); + rv = fromFile->GetPath(fromPath); + if (NS_FAILED(rv)) return rv; - } - thisNodeCnt = SplitPath(thisPath, thisNodes, kMaxNodesInPath); - fromNodeCnt = SplitPath(fromPath, fromNodes, kMaxNodesInPath); - if (thisNodeCnt < 0 || fromNodeCnt < 0) { - nsMemory::Free(thisPath); - nsMemory::Free(fromPath); + thisNodeCnt = SplitPath((char *)thisPath.get(), thisNodes, kMaxNodesInPath); + fromNodeCnt = SplitPath((char *)fromPath.get(), fromNodes, kMaxNodesInPath); + if (thisNodeCnt < 0 || fromNodeCnt < 0) return NS_ERROR_FAILURE; - } for (nodeIndex = 0; nodeIndex < thisNodeCnt && nodeIndex < fromNodeCnt; nodeIndex++) { - if (!(nsDependentString(thisNodes[nodeIndex])).Equals(nsDependentString(fromNodes[nodeIndex]))) + if (!strcmp(thisNodes[nodeIndex], fromNodes[nodeIndex])) break; } PRInt32 branchIndex = nodeIndex; for (nodeIndex = branchIndex; nodeIndex < fromNodeCnt; nodeIndex++) - _retval.Append("../"); + _retval.Append(NS_LITERAL_CSTRING("../")); for (nodeIndex = branchIndex; nodeIndex < thisNodeCnt; nodeIndex++) { - NS_ConvertUCS2toUTF8 nodeStr(thisNodes[nodeIndex]); #ifdef XP_MAC + nsCAutoString nodeStr(thisNodes[nodeIndex]); nodeStr.ReplaceSubstring(kSlashStr, kESCSlashStr); +#else + nsDependentCString nodeStr(thisNodes[nodeIndex]); #endif - _retval.Append(nodeStr.get()); + _retval.Append(nodeStr); if (nodeIndex + 1 < thisNodeCnt) _retval.Append('/'); } - nsMemory::Free(thisPath); - nsMemory::Free(fromPath); - return NS_OK; } @@ -260,11 +237,13 @@ nsLocalFile::SetRelativeDescriptor(nsILocalFile *fromFile, const nsACString& rel nodeBegin = nodeEnd = pos; while (nodeEnd != strEnd) { FindCharInReadable('/', nodeEnd, strEnd); - nsCAutoString nodeString(Substring(nodeBegin, nodeEnd)); #ifdef XP_MAC + nsCAutoString nodeString(Substring(nodeBegin, nodeEnd)); nodeString.ReplaceSubstring(kESCSlashStr, kSlashStr); + targetFile->Append(nodeString); +#else + targetFile->Append(Substring(nodeBegin, nodeEnd)); #endif - targetFile->AppendUnicode((NS_ConvertUTF8toUCS2(nodeString)).get()); if (nodeEnd != strEnd) // If there's more left in the string, inc over the '/' nodeEnd is on. ++nodeEnd; nodeBegin = nodeEnd; @@ -273,3 +252,116 @@ nsLocalFile::SetRelativeDescriptor(nsILocalFile *fromFile, const nsACString& rel nsCOMPtr targetLocalFile(do_QueryInterface(targetFile)); return InitWithFile(targetLocalFile); } + +#define GET_UTF8(func, result) \ + PR_BEGIN_MACRO \ + PRUnichar *buf = nsnull; \ + nsresult rv = (func)(&buf); \ + if (NS_FAILED(rv)) return rv; \ + result = NS_ConvertUCS2toUTF8(buf); \ + nsMemory::Free(buf); \ + PR_END_MACRO + +NS_IMETHODIMP +nsLocalFile::Append(const nsACString &aNode) +{ + if (aNode.IsEmpty() || FSCharsetIsUTF8() || IsASCII(aNode)) + return AppendNative(aNode); + + return AppendUnicode(NS_ConvertUTF8toUCS2(aNode).get()); +} + +NS_IMETHODIMP +nsLocalFile::GetLeafName(nsACString &aLeafName) +{ + if (FSCharsetIsUTF8() || LeafIsASCII()) + return GetNativeLeafName(aLeafName); + + GET_UTF8(GetUnicodeLeafName, aLeafName); + return NS_OK; +} + +NS_IMETHODIMP +nsLocalFile::SetLeafName(const nsACString &aLeafName) +{ + if (aLeafName.IsEmpty() || FSCharsetIsUTF8() || IsASCII(aLeafName)) + return SetNativeLeafName(aLeafName); + + return SetUnicodeLeafName(NS_ConvertUTF8toUCS2(aLeafName).get()); +} + +NS_IMETHODIMP +nsLocalFile::CopyTo(nsIFile *aNewParentDir, const nsACString &aNewName) +{ + if (aNewName.IsEmpty() || FSCharsetIsUTF8() || IsASCII(aNewName)) + return CopyToNative(aNewParentDir, aNewName); + + return CopyToUnicode(aNewParentDir, NS_ConvertUTF8toUCS2(aNewName).get()); +} + +NS_IMETHODIMP +nsLocalFile::CopyToFollowingLinks(nsIFile *aNewParentDir, const nsACString &aNewName) +{ + if (aNewName.IsEmpty() || FSCharsetIsUTF8() || IsASCII(aNewName)) + return CopyToFollowingLinksNative(aNewParentDir, aNewName); + + return CopyToFollowingLinksUnicode(aNewParentDir, NS_ConvertUTF8toUCS2(aNewName).get()); +} + +NS_IMETHODIMP +nsLocalFile::MoveTo(nsIFile *aNewParentDir, const nsACString &aNewName) +{ + if (aNewName.IsEmpty() || FSCharsetIsUTF8() || IsASCII(aNewName)) + return MoveToNative(aNewParentDir, aNewName); + + return MoveToUnicode(aNewParentDir, NS_ConvertUTF8toUCS2(aNewName).get()); +} + +NS_IMETHODIMP +nsLocalFile::GetTarget(nsACString &aTarget) +{ + if (FSCharsetIsUTF8()) + return GetNativeTarget(aTarget); + + // XXX unfortunately, there is no way to know if the target will contain + // non-ASCII characters until after we resolve it. + GET_UTF8(GetUnicodeTarget, aTarget); + return NS_OK; +} + +NS_IMETHODIMP +nsLocalFile::GetPath(nsACString &aPath) +{ + if (FSCharsetIsUTF8() || PathIsASCII()) + return GetNativePath(aPath); + + GET_UTF8(GetUnicodePath, aPath); + return NS_OK; +} + +NS_IMETHODIMP +nsLocalFile::InitWithPath(const nsACString &aPath) +{ + if (aPath.IsEmpty() || FSCharsetIsUTF8() || IsASCII(aPath)) + return InitWithNativePath(aPath); + + return InitWithUnicodePath(NS_ConvertUTF8toUCS2(aPath).get()); +} + +NS_IMETHODIMP +nsLocalFile::AppendRelativePath(const nsACString &aRelativePath) +{ + if (aRelativePath.IsEmpty() || FSCharsetIsUTF8() || IsASCII(aRelativePath)) + return AppendRelativeNativePath(aRelativePath); + + return AppendRelativeUnicodePath(NS_ConvertUTF8toUCS2(aRelativePath).get()); +} + +nsresult +NS_NewLocalFile(const nsACString &aPath, PRBool aFollowLinks, nsILocalFile **aResult) +{ + if (aPath.IsEmpty() || nsLocalFile::FSCharsetIsUTF8() || IsASCII(aPath)) + return NS_NewNativeLocalFile(aPath, aFollowLinks, aResult); + + return NS_NewUnicodeLocalFile(NS_ConvertUTF8toUCS2(aPath).get(), aFollowLinks, aResult); +} diff --git a/mozilla/xpcom/io/nsLocalFileMac.cpp b/mozilla/xpcom/io/nsLocalFileMac.cpp index c69aaa39c2c..3c499c9d54f 100644 --- a/mozilla/xpcom/io/nsLocalFileMac.cpp +++ b/mozilla/xpcom/io/nsLocalFileMac.cpp @@ -97,7 +97,7 @@ const OSType kDefaultCreator = 'MOSS'; class nsPathParser { public: - nsPathParser(const char* path); + nsPathParser(const nsACString &path); ~nsPathParser() { @@ -124,18 +124,30 @@ private: char *mBuffer, *mNewString; }; -nsPathParser::nsPathParser(const char* inPath) : +nsPathParser::nsPathParser(const nsACString &inPath) : mAllocatedBuffer(nsnull), mNewString(nsnull) { - PRUint32 inPathLen = strlen(inPath); + PRUint32 inPathLen = inPath.Length(); if (inPathLen >= sizeof(mAutoBuffer)) { - mAllocatedBuffer = (char *)nsMemory::Clone(inPath, inPathLen + 1); + mAllocatedBuffer = (char *)nsMemory::Alloc(inPathLen + 1); mBuffer = mAllocatedBuffer; } - else { - strcpy(mAutoBuffer, inPath); - mBuffer = mAutoBuffer; + else + mBuffer = mAutoBuffer; + + // copy inPath into mBuffer + nsACString::const_iterator start, end; + inPath.BeginReading(start); + inPath.EndReading(end); + + PRUint32 size, offset = 0; + for ( ; start != end; start.advance(size)) { + const char* buf = start.get(); + size = start.size_forward(); + memcpy(mBuffer + offset, buf, size); + offset += size; } + mBuffer[offset] = '\0'; } #pragma mark - @@ -1243,15 +1255,17 @@ nsLocalFile::Clone(nsIFile **file) } NS_IMETHODIMP -nsLocalFile::InitWithPath(const char *filePath) +nsLocalFile::InitWithNativePath(const nsACString &filePath) { // The incoming path must be a FULL path - NS_ENSURE_ARG(filePath); + if (filePath.IsEmpty()) + return NS_ERROR_INVALID_ARG; + MakeDirty(); // If it starts with a colon, it's invalid - if (*filePath == ':') + if (filePath.First() == ':') return NS_ERROR_FILE_UNRECOGNIZED_PATH; nsPathParser parser(filePath); @@ -1297,7 +1311,7 @@ nsLocalFile::InitWithUnicodePath(const PRUnichar *filePath) nsCAutoString fsStr; if (NS_SUCCEEDED(rv = nsFSStringConversionMac::UCSToFS(nsDependentString(filePath), fsStr))) - rv = InitWithPath(fsStr.get()); + rv = InitWithNativePath(fsStr); return rv; } @@ -1463,16 +1477,21 @@ nsLocalFile::Create(PRUint32 type, PRUint32 attributes) } NS_IMETHODIMP -nsLocalFile::Append(const char *aNode) +nsLocalFile::AppendNative(const nsACString &aNode) { - NS_ENSURE_ARG(aNode); - if (strchr(aNode, ':')) + if (aNode.IsEmpty()) + return NS_ERROR_INVALID_ARG; + + nsACString::const_iterator start, end; + aNode.BeginReading(start); + aNode.EndReading(end); + if (FindCharInReadable(':', start, end)) return NS_ERROR_FILE_UNRECOGNIZED_PATH; MakeDirty(); char truncBuffer[32]; - const char *node = TruncNodeName(aNode, truncBuffer); + const char *node = TruncNodeName(PromiseFlatCString(aNode).get(), truncBuffer); if (!mAppendedPath.Length()) { @@ -1520,15 +1539,16 @@ nsLocalFile::AppendUnicode(const PRUnichar *node) nsCAutoString fsStr; if (NS_SUCCEEDED(rv = nsFSStringConversionMac::UCSToFS(nsDependentString(node), fsStr))) - rv = Append(fsStr.get()); + rv = AppendNative(fsStr); return rv; } NS_IMETHODIMP -nsLocalFile::AppendRelativePath(const char *relPath) +nsLocalFile::AppendRelativeNativePath(const nsACString &relPath) { - NS_ENSURE_ARG(relPath); + if (relPath.IsEmpty()) + return NS_ERROR_INVALID_ARG; nsresult rv; nsPathParser parser(relPath); @@ -1536,7 +1556,7 @@ nsLocalFile::AppendRelativePath(const char *relPath) while (node) { - if (NS_FAILED(rv = Append(node))) + if (NS_FAILED(rv = AppendNative(nsDependentCString(node)))) return rv; node = parser.Next(); } @@ -1551,15 +1571,15 @@ nsLocalFile::AppendRelativeUnicodePath(const PRUnichar *relPath) nsCAutoString fsStr; if (NS_SUCCEEDED(rv = nsFSStringConversionMac::UCSToFS(nsDependentString(relPath), fsStr))) - rv = AppendRelativePath(fsStr.get()); + rv = AppendRelativeNativePath(fsStr); return rv; } NS_IMETHODIMP -nsLocalFile::GetLeafName(char * *aLeafName) +nsLocalFile::GetNativeLeafName(nsACString &aLeafName) { - NS_ENSURE_ARG_POINTER(aLeafName); + aLeafName.Truncate(); // See if we've had a path appended if (mAppendedPath.Length()) @@ -1576,20 +1596,19 @@ nsLocalFile::GetLeafName(char * *aLeafName) else leaf++; - *aLeafName = (char*) nsMemory::Clone(leaf, strlen(leaf)+1); - if (!*aLeafName) - return NS_ERROR_OUT_OF_MEMORY; + aLeafName = leaf; } else { // We don't have an appended path so grab the leaf name from the FSSpec // Convert the Pascal string to a C string PRInt32 len = mSpec.name[0]; - char* leafName = (char *)nsMemory::Alloc(len + 1); + char* leafName = (char *)malloc(len + 1); if (!leafName) return NS_ERROR_OUT_OF_MEMORY; ::BlockMoveData(&mSpec.name[1], leafName, len); leafName[len] = '\0'; - *aLeafName = leafName; + aLeafName = leafName; + free(leafName); } return NS_OK; @@ -1599,9 +1618,9 @@ NS_IMETHODIMP nsLocalFile::GetUnicodeLeafName(PRUnichar **aLeafName) { nsresult rv; - nsXPIDLCString fsStr; + nsCAutoString fsStr; - if (NS_SUCCEEDED(rv = GetLeafName(getter_Copies(fsStr)))) { + if (NS_SUCCEEDED(rv = GetNativeLeafName(fsStr))) { nsAutoString ucStr; if (NS_SUCCEEDED(rv = nsFSStringConversionMac::FSToUCS(fsStr, ucStr))) { if ((*aLeafName = ToNewUnicode(ucStr)) == nsnull) @@ -1612,14 +1631,15 @@ nsLocalFile::GetUnicodeLeafName(PRUnichar **aLeafName) } NS_IMETHODIMP -nsLocalFile::SetLeafName(const char * aLeafName) +nsLocalFile::SetNativeLeafName(const nsACString &aLeafName) { - NS_ENSURE_ARG(aLeafName); + if (aLeafName.IsEmpty()) + return NS_ERROR_INVALID_ARG; MakeDirty(); char truncBuffer[32]; - const char *leafName = TruncNodeName(aLeafName, truncBuffer); + const char *leafName = TruncNodeName(PromiseFlatCString(aLeafName).get(), truncBuffer); if (mAppendedPath.Length()) { // Lop off the end of the appended path and replace it with the new leaf name @@ -1646,15 +1666,15 @@ nsLocalFile::SetUnicodeLeafName(const PRUnichar * aLeafName) nsCAutoString fsStr; if (NS_SUCCEEDED(rv = nsFSStringConversionMac::UCSToFS(nsDependentString(aLeafName), fsStr))) - rv = SetLeafName(fsStr.get()); + rv = SetNativeLeafName(fsStr); return rv; } NS_IMETHODIMP -nsLocalFile::GetPath(char **_retval) +nsLocalFile::GetNativePath(nsACString &_retval) { - NS_ENSURE_ARG_POINTER(_retval); + _retval.Truncate(); nsCAutoString fsCharSetPathStr; @@ -1700,10 +1720,7 @@ nsLocalFile::GetPath(char **_retval) fsCharSetPathStr.Append(mAppendedPath); } - *_retval = ToNewCString(fsCharSetPathStr); - if (!*_retval) - return NS_ERROR_OUT_OF_MEMORY; - + _retval = fsCharSetPathStr; return NS_OK; } @@ -1747,9 +1764,9 @@ nsLocalFile::GetUnicodePath(PRUnichar **_retval) else #endif { - nsXPIDLCString fsStr; + nsCAutoString fsStr; - if (NS_SUCCEEDED(rv = GetPath(getter_Copies(fsStr)))) { + if (NS_SUCCEEDED(rv = GetNativePath(fsStr))) { nsAutoString ucStr; if (NS_SUCCEEDED(rv = nsFSStringConversionMac::FSToUCS(fsStr, ucStr))) { if ((*_retval = ToNewUnicode(ucStr)) == nsnull) @@ -1760,7 +1777,7 @@ nsLocalFile::GetUnicodePath(PRUnichar **_retval) return rv; } -nsresult nsLocalFile::MoveCopy( nsIFile* newParentDir, const char* newName, PRBool isCopy, PRBool followLinks ) +nsresult nsLocalFile::MoveCopy( nsIFile* newParentDir, const nsACString &newName, PRBool isCopy, PRBool followLinks ) { OSErr macErr; FSSpec srcSpec; @@ -1775,8 +1792,7 @@ nsresult nsLocalFile::MoveCopy( nsIFile* newParentDir, const char* newName, PRBo // If newParentDir == nsnull, it's a simple rename if ( !newParentDir ) { - NS_ENSURE_ARG( newName ); - myPLstrncpy( newPascalName, newName, 255 ); + myPLstrncpy( newPascalName, PromiseFlatCString(newName).get(), 255 ); macErr = ::FSpRename( &srcSpec, newPascalName ); return MacErrorMapper( macErr ); } @@ -1794,8 +1810,8 @@ nsresult nsLocalFile::MoveCopy( nsIFile* newParentDir, const char* newName, PRBo if ( macErr || !isDirectory ) return NS_ERROR_FILE_DESTINATION_NOT_DIR; - if ( newName ) - myPLstrncpy( newPascalName, newName, 255); + if ( !newName.IsEmpty() ) + myPLstrncpy( newPascalName, PromiseFlatCString(newName).get(), 255); else memcpy(newPascalName, srcSpec.name, srcSpec.name[0] + 1); if ( isCopy ) @@ -1832,7 +1848,7 @@ nsresult nsLocalFile::MoveCopy( nsIFile* newParentDir, const char* newName, PRBo if ( macErr == diffVolErr) { // On a different Volume so go for Copy and then delete - rv = CopyTo( newParentDir, newName ); + rv = CopyToNative( newParentDir, newName ); if ( NS_FAILED ( rv ) ) return rv; return Remove( PR_TRUE ); @@ -1842,7 +1858,7 @@ nsresult nsLocalFile::MoveCopy( nsIFile* newParentDir, const char* newName, PRBo } NS_IMETHODIMP -nsLocalFile::CopyTo(nsIFile *newParentDir, const char *newName) +nsLocalFile::CopyToNative(nsIFile *newParentDir, const nsACString &newName) { return MoveCopy( newParentDir, newName, PR_TRUE, PR_FALSE ); } @@ -1851,17 +1867,17 @@ NS_IMETHODIMP nsLocalFile::CopyToUnicode(nsIFile *newParentDir, const PRUnichar *newName) { if (!newName) - return CopyTo(newParentDir, nsnull); + return CopyToNative(newParentDir, nsCString()); nsresult rv; nsCAutoString fsStr; if (NS_SUCCEEDED(rv = nsFSStringConversionMac::UCSToFS(nsDependentString(newName), fsStr))) - rv = CopyTo(newParentDir, PromiseFlatCString(fsStr).get()); + rv = CopyToNative(newParentDir, fsStr); return rv; } NS_IMETHODIMP -nsLocalFile::CopyToFollowingLinks(nsIFile *newParentDir, const char *newName) +nsLocalFile::CopyToFollowingLinksNative(nsIFile *newParentDir, const nsACString &newName) { return MoveCopy( newParentDir, newName, PR_TRUE, PR_TRUE ); } @@ -1870,17 +1886,17 @@ NS_IMETHODIMP nsLocalFile::CopyToFollowingLinksUnicode(nsIFile *newParentDir, const PRUnichar *newName) { if (!newName) - return CopyToFollowingLinks(newParentDir, nsnull); + return CopyToFollowingLinksNative(newParentDir, nsCString()); nsresult rv; nsCAutoString fsStr; if (NS_SUCCEEDED(rv = nsFSStringConversionMac::UCSToFS(nsDependentString(newName), fsStr))) - rv = CopyToFollowingLinks(newParentDir, PromiseFlatCString(fsStr).get()); + rv = CopyToFollowingLinksNative(newParentDir, fsStr); return rv; } NS_IMETHODIMP -nsLocalFile::MoveTo(nsIFile *newParentDir, const char *newName) +nsLocalFile::MoveToNative(nsIFile *newParentDir, const nsACString &newName) { return MoveCopy( newParentDir, newName, PR_FALSE, PR_FALSE ); } @@ -1889,12 +1905,12 @@ NS_IMETHODIMP nsLocalFile::MoveToUnicode(nsIFile *newParentDir, const PRUnichar *newName) { if (!newName) - return MoveTo(newParentDir, nsnull); + return MoveToNative(newParentDir, nsCString()); nsresult rv; nsCAutoString fsStr; if (NS_SUCCEEDED(rv = nsFSStringConversionMac::UCSToFS(nsDependentString(newName), fsStr))) - rv = MoveTo(newParentDir, PromiseFlatCString(fsStr).get()); + rv = MoveToNative(newParentDir, fsStr); return rv; } @@ -2258,10 +2274,10 @@ nsLocalFile::IsPackage(PRBool *outIsPackage) { // Believe it or not, folders ending with ".app" are also considered // to be packages, even if the top-level folder doesn't have bundle set - nsXPIDLCString name; - if (NS_SUCCEEDED(rv = GetLeafName(getter_Copies(name)))) + nsCAutoString name; + if (NS_SUCCEEDED(rv = GetNativeLeafName(name))) { - const char *extPtr = strrchr(name, '.'); + const char *extPtr = strrchr(name.get(), '.'); if (extPtr) { if (!nsCRT::strcasecmp(extPtr, ".app")) @@ -2395,10 +2411,10 @@ nsLocalFile::IsHidden(PRBool *_retval) { // on Mac OS X, also follow Unix "convention" where files // beginning with a period are considered to be hidden - nsXPIDLCString name; - if (NS_SUCCEEDED(rv = GetLeafName(getter_Copies(name)))) + nsCAutoString name; + if (NS_SUCCEEDED(rv = GetNativeLeafName(name))) { - if (name.CharAt(0) == '.') + if (name.First() == '.') { *_retval = PR_TRUE; } @@ -2438,13 +2454,13 @@ nsLocalFile::Equals(nsIFile *inFile, PRBool *_retval) *_retval = IsEqualFSSpec(fileSpec, inFileSpec); else { - nsXPIDLCString filePath; - GetPath(getter_Copies(filePath)); + nsCAutoString filePath; + GetNativePath(filePath); nsXPIDLCString inFilePath; - inFile->GetPath(getter_Copies(inFilePath)); + inFile->GetNativePath(inFilePath); - if (nsCRT::strcasecmp(inFilePath, filePath) == 0) + if (nsCRT::strcasecmp(inFilePath.get(), filePath.get()) == 0) *_retval = PR_TRUE; } return NS_OK; @@ -2503,10 +2519,9 @@ nsLocalFile::Contains(nsIFile *inFile, PRBool recur, PRBool *outContains) NS_IMETHODIMP -nsLocalFile::GetTarget(char **_retval) +nsLocalFile::GetNativeTarget(nsACString &_retval) { - NS_ENSURE_ARG(_retval); - *_retval = nsnull; + _retval.Truncate(); PRBool symLink; @@ -2518,16 +2533,16 @@ nsLocalFile::GetTarget(char **_retval) return NS_ERROR_FILE_INVALID_PATH; StFollowLinksState followState(this, PR_TRUE); - return GetPath(_retval); + return GetNativePath(_retval); } NS_IMETHODIMP nsLocalFile::GetUnicodeTarget(PRUnichar **_retval) { nsresult rv; - nsXPIDLCString fsStr; + nsCAutoString fsStr; - if (NS_SUCCEEDED(rv = GetTarget(getter_Copies(fsStr)))) { + if (NS_SUCCEEDED(rv = GetNativeTarget(fsStr))) { nsAutoString ucStr; if (NS_SUCCEEDED(rv = nsFSStringConversionMac::FSToUCS(fsStr, ucStr))) { if ((*_retval = ToNewUnicode(ucStr)) == nsnull) @@ -2567,10 +2582,9 @@ nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator * *entries) } NS_IMETHODIMP -nsLocalFile::GetPersistentDescriptor(char * *aPersistentDescriptor) +nsLocalFile::GetPersistentDescriptor(nsACString &aPersistentDescriptor) { - NS_ENSURE_ARG_POINTER(aPersistentDescriptor); - *aPersistentDescriptor = nsnull; + aPersistentDescriptor.Truncate(); nsresult rv = ResolveAndStat(); if ( NS_FAILED( rv ) ) @@ -2587,20 +2601,22 @@ nsLocalFile::GetPersistentDescriptor(char * *aPersistentDescriptor) ::DisposeHandle((Handle) aliasH); NS_ENSURE_TRUE(buf, NS_ERROR_OUT_OF_MEMORY); - *aPersistentDescriptor = buf; + aPersistentDescriptor = buf; + PR_Free(buf); return NS_OK; } NS_IMETHODIMP -nsLocalFile::SetPersistentDescriptor(const char * aPersistentDescriptor) +nsLocalFile::SetPersistentDescriptor(const nsACString &aPersistentDescriptor) { - NS_ENSURE_ARG(aPersistentDescriptor); + if (aPersistentDescriptor.IsEmpty()) + return NS_ERROR_INVALID_ARG; nsresult rv = NS_OK; - PRUint32 dataSize = nsCRT::strlen(aPersistentDescriptor); - char* decodedData = PL_Base64Decode((const char*)aPersistentDescriptor, dataSize, nsnull); + PRUint32 dataSize = aPersistentDescriptor.Length(); + char* decodedData = PL_Base64Decode(PromiseFlatCString(aPersistentDescriptor).get(), dataSize, nsnull); // Cast to an alias record and resolve. AliasHandle aliasH = nsnull; if (::PtrToHand(decodedData, &(Handle)aliasH, (dataSize * 3) / 4) != noErr) @@ -3411,13 +3427,13 @@ nsresult nsLocalFile::SetOSTypeAndCreatorFromExtension(const char* extension) { nsresult rv; - nsXPIDLCString localExtBuf; + nsCAutoString localExtBuf; const char *extPtr; if (!extension) { - rv = GetLeafName(getter_Copies(localExtBuf)); - extPtr = strrchr(localExtBuf, '.'); + rv = GetNativeLeafName(localExtBuf); + extPtr = strrchr(localExtBuf.get(), '.'); if (!extPtr) return NS_ERROR_FAILURE; ++extPtr; @@ -3513,7 +3529,7 @@ void nsLocalFile::InitClassStatics() // Handy dandy utility create routine for something or the other nsresult -NS_NewLocalFile(const char* path, PRBool followLinks, nsILocalFile* *result) +NS_NewNativeLocalFile(const nsACString &path, PRBool followLinks, nsILocalFile* *result) { nsLocalFile* file = new nsLocalFile(); if (file == nsnull) @@ -3522,8 +3538,8 @@ NS_NewLocalFile(const char* path, PRBool followLinks, nsILocalFile* *result) file->SetFollowLinks(followLinks); - if (path) { - nsresult rv = file->InitWithPath(path); + if (!path.IsEmpty()) { + nsresult rv = file->InitWithNativePath(path); if (NS_FAILED(rv)) { NS_RELEASE(file); return rv; @@ -3540,7 +3556,7 @@ NS_NewUnicodeLocalFile(const PRUnichar* path, PRBool followLinks, nsILocalFile* nsresult rv = nsFSStringConversionMac::UCSToFS(nsDependentString(path), fsCharSetStr); if (NS_FAILED(rv)) return rv; - return NS_NewLocalFile(fsCharSetStr.get(), followLinks, result); + return NS_NewNativeLocalFile(fsCharSetStr, followLinks, result); } nsresult @@ -3563,7 +3579,12 @@ NS_NewLocalFileWithFSSpec(FSSpec* inSpec, PRBool followLinks, nsILocalFileMac* * } void -NS_ShutdownLocalFileUnicode() +nsLocalFile::GlobalInit() +{ +} + +void +nsLocalFile::GlobalShutdown() { nsFSStringConversionMac::CleanUp(); } diff --git a/mozilla/xpcom/io/nsLocalFileMac.h b/mozilla/xpcom/io/nsLocalFileMac.h index e2460b1264f..4baab07f7f4 100644 --- a/mozilla/xpcom/io/nsLocalFileMac.h +++ b/mozilla/xpcom/io/nsLocalFileMac.h @@ -59,6 +59,11 @@ public: // nsILocalFileMac interface NS_DECL_NSILOCALFILEMAC +public: + + static void GlobalInit(); + static void GlobalShutdown(); + protected: void MakeDirty(); @@ -74,13 +79,22 @@ protected: nsresult TestFinderFlag(PRUint16 flagMask, PRBool *outFlagSet, PRBool testTargetSpec = PR_TRUE); - nsresult MoveCopy( nsIFile* newParentDir, const char* newName, PRBool isCopy, PRBool followLinks ); + nsresult MoveCopy( nsIFile* newParentDir, const nsACString &newName, PRBool isCopy, PRBool followLinks ); // Passing nsnull for the extension uses leaf name nsresult SetOSTypeAndCreatorFromExtension(const char* extension = nsnull); nsresult ExtensionIsOnExceptionList(const char *extension, PRBool *onList); + // XXX needs impl + static PRBool FSCharsetIsUTF8() { return PR_FALSE; } + + // XXX we should compute and store these values + PRBool LeafIsASCII() { return PR_FALSE; } + PRBool PathIsASCII() { return PR_FALSE; } + + NS_DECL_NSLOCALFILE_UNICODE_METHODS + private: nsLocalFile(const nsLocalFile& srcFile); nsLocalFile(const FSSpec& aSpec, const nsACString& aAppendedPath); diff --git a/mozilla/xpcom/io/nsLocalFileOS2.cpp b/mozilla/xpcom/io/nsLocalFileOS2.cpp index 448e3ec4e22..1b809ebfd43 100644 --- a/mozilla/xpcom/io/nsLocalFileOS2.cpp +++ b/mozilla/xpcom/io/nsLocalFileOS2.cpp @@ -28,6 +28,7 @@ #include "nsMemory.h" #include "nsLocalFileOS2.h" +#include "nsLocalFileUnicode.h" #include @@ -157,24 +158,22 @@ class nsDirEnumerator : public nsISimpleEnumerator nsresult Init(nsILocalFile* parent) { - char* filepath; - parent->GetTarget(&filepath); + nsCAutoString filepath; + parent->GetNativeTarget(filepath); - if (filepath == nsnull) + if (filepath.IsEmpty()) { - parent->GetPath(&filepath); + parent->GetNativePath(filepath); } - if (filepath == nsnull) + if (filepath.IsEmpty()) { - return NS_ERROR_OUT_OF_MEMORY; + return NS_ERROR_UNEXPECTED; } - mDir = PR_OpenDir(filepath); + mDir = PR_OpenDir(filepath.get()); if (mDir == nsnull) // not a directory? return NS_ERROR_FAILURE; - - nsMemory::Free(filepath); mParent = parent; return NS_OK; @@ -204,13 +203,13 @@ class nsDirEnumerator : public nsISimpleEnumerator if (NS_FAILED(rv)) return rv; - rv = file->Append(entry->name); + rv = file->AppendNative(nsDependentCString(entry->name)); if (NS_FAILED(rv)) return rv; // make sure the thing exists. If it does, try the next one. PRBool exists; - rv = file->Exists(&exists); + rv = file->Exists(&exists); if (NS_FAILED(rv) || !exists) { return HasMoreElements(result); @@ -642,55 +641,47 @@ nsLocalFile::Clone(nsIFile **file) } NS_IMETHODIMP -nsLocalFile::InitWithPath(const char *filePath) +nsLocalFile::InitWithNativePath(const nsACString &filePath) { MakeDirty(); - NS_ENSURE_ARG(filePath); - - char* nativeFilePath = nsnull; + + nsACString::const_iterator begin, end; + filePath.BeginReading(begin); + filePath.EndReading(end); + + // input string must not be empty + if (begin == end) + return NS_ERROR_FAILURE; + + char firstChar = *begin; + char secondChar = *(++begin); // just do a sanity check. if it has any forward slashes, it is not a Native path // on windows. Also, it must have a colon at after the first char. - if (filePath[0] == 0) - return NS_ERROR_FAILURE; - if ( (filePath[2] == 0) && (filePath[1] == ':') ) - { - // C : // - nativeFilePath = (char*) nsMemory::Alloc( 4 ); - if (!nativeFilePath) - return NS_ERROR_OUT_OF_MEMORY; - nativeFilePath[0] = filePath[0]; - nativeFilePath[1] = ':'; - nativeFilePath[2] = '\\'; - nativeFilePath[3] = 0; - } - // XXX is this an 'else'? Otherwise 'nativeFilePath' could leak. - if ( ( (filePath[1] == ':') && (strchr(filePath, '/') == 0) ) || // normal windows path - ( (filePath[0] == '\\') && (filePath[1] == '\\') ) ) // netwerk path + char *path = nsnull; + PRInt32 pathLen = 0; + + if ( ( (secondChar == ':') && !FindCharInReadable('/', begin, end) ) || // normal path + ( (firstChar == '\\') && (secondChar == '\\') ) ) // network path { // This is a native path - if (nativeFilePath) nsCRT::free(nativeFilePath); - nativeFilePath = (char*) nsMemory::Clone( filePath, strlen(filePath)+1 ); + path = ToNewCString(filePath); + pathLen = filePath.Length(); } - - if (nativeFilePath == nsnull) + + if (path == nsnull) return NS_ERROR_FILE_UNRECOGNIZED_PATH; - // kill any trailing separator - char* temp = nativeFilePath; - int len = strlen(temp) - 1; - // Is '\' second charactor of DBCS? -#ifdef XP_OS2 - if(temp[len] == '\\' && !::isleadbyte(temp[len-1])) -#else - if(temp[len] == '\\' && !::IsDBCSLeadByte(temp[len-1])) -#endif - temp[len] = '\0'; + // kill any trailing '\' provided it isn't the second char of DBCS + PRInt32 len = pathLen - 1; + if (path[len] == '\\' && !::isleadbyte(path[len-1])) + { + path[len] = '\0'; + pathLen = len; + } - mWorkingPath.Assign(nativeFilePath); - nsMemory::Free( nativeFilePath ); - + mWorkingPath.Adopt(path, pathLen); return NS_OK; } @@ -794,27 +785,30 @@ nsLocalFile::Create(PRUint32 type, PRUint32 attributes) } NS_IMETHODIMP -nsLocalFile::Append(const char *node) +nsLocalFile::AppendNative(const nsACString &node) { // Append only one component. Check for subdirs. - if (!node || (_mbschr((const unsigned char*) node, '\\') != nsnull)) + // XXX can we avoid the PromiseFlatCString call? + if (node.IsEmpty() || (_mbschr((const unsigned char*) PromiseFlatCString(node).get(), '\\') != nsnull)) { return NS_ERROR_FILE_UNRECOGNIZED_PATH; } - return AppendRelativePath(node); + return AppendRelativeNativePath(node); } NS_IMETHODIMP -nsLocalFile::AppendRelativePath(const char *node) +nsLocalFile::AppendRelativeNativePath(const nsACString &node) { // Cannot start with a / or have .. or have / anywhere - if (!node || strchr(node, '/')) + nsACString::const_iterator begin, end; + node.BeginReading(begin); + node.EndReading(end); + if (node.IsEmpty() || FindCharInReadable('/', begin, end)) { return NS_ERROR_FILE_UNRECOGNIZED_PATH; } MakeDirty(); - mWorkingPath.Append("\\"); - mWorkingPath.Append(node); + mWorkingPath.Append(NS_LITERAL_CSTRING("\\") + node); return NS_OK; } @@ -825,9 +819,9 @@ nsLocalFile::Normalize() } NS_IMETHODIMP -nsLocalFile::GetLeafName(char * *aLeafName) +nsLocalFile::GetNativeLeafName(nsACString &aLeafName) { - NS_ENSURE_ARG_POINTER(aLeafName); + aLeafName.Truncate(); const char* temp = mWorkingPath.get(); if(temp == nsnull) @@ -841,12 +835,12 @@ nsLocalFile::GetLeafName(char * *aLeafName) else leaf++; - *aLeafName = (char*) nsMemory::Clone(leaf, strlen(leaf)+1); + aLeafName.Assign(leaf); return NS_OK; } NS_IMETHODIMP -nsLocalFile::SetLeafName(const char * aLeafName) +nsLocalFile::SetNativeLeafName(const nsACString &aLeafName) { MakeDirty(); @@ -867,36 +861,32 @@ nsLocalFile::SetLeafName(const char * aLeafName) NS_IMETHODIMP -nsLocalFile::GetPath(char **_retval) +nsLocalFile::GetNativePath(nsACString &_retval) { - NS_ENSURE_ARG_POINTER(_retval); - *_retval = (char*) nsMemory::Clone(mWorkingPath.get(), mWorkingPath.Length()+1); + _retval = mWorkingPath; return NS_OK; } nsresult -nsLocalFile::CopySingleFile(nsIFile *sourceFile, nsIFile *destParent, const char * newName, PRBool followSymlinks, PRBool move) +nsLocalFile::CopySingleFile(nsIFile *sourceFile, nsIFile *destParent, const nsACString &newName, PRBool followSymlinks, PRBool move) { nsresult rv; - char* filePath; + nsCAutoString filePath; // get the path that we are going to copy to. // Since windows does not know how to auto // resolve shortcust, we must work with the // target. - char* inFilePath; - destParent->GetTarget(&inFilePath); - nsCString destPath(inFilePath); - nsMemory::Free(inFilePath); + nsCAutoString destPath; + destParent->GetNativeTarget(destPath); destPath.Append("\\"); - if (newName == nsnull) + if (newName.IsEmpty()) { - char *aFileName; - sourceFile->GetLeafName(&aFileName); + nsCAutoString aFileName; + sourceFile->GetNativeLeafName(aFileName); destPath.Append(aFileName); - nsMemory::Free(aFileName); } else { @@ -906,13 +896,13 @@ nsLocalFile::CopySingleFile(nsIFile *sourceFile, nsIFile *destParent, const char if (followSymlinks) { - rv = sourceFile->GetTarget(&filePath); - if (!filePath) - rv = sourceFile->GetPath(&filePath); + rv = sourceFile->GetNativeTarget(filePath); + if (filePath.IsEmpty()) + rv = sourceFile->GetNativePath(filePath); } else { - rv = sourceFile->GetPath(&filePath); + rv = sourceFile->GetNativePath(filePath); } if (NS_FAILED(rv)) @@ -922,7 +912,7 @@ nsLocalFile::CopySingleFile(nsIFile *sourceFile, nsIFile *destParent, const char if( move ) { - rc = DosMove(filePath, (PSZ)NS_CONST_CAST(char*, destPath.get())); + rc = DosMove(filePath.get(), (PSZ)NS_CONST_CAST(char*, destPath.get())); } if (!move || rc == ERROR_NOT_SAME_DEVICE) { @@ -930,7 +920,7 @@ nsLocalFile::CopySingleFile(nsIFile *sourceFile, nsIFile *destParent, const char * same drive. "MoveFile()" on Windows will go ahead and move the * file without error, so we need to do the same IBM-AKR */ - rc = DosCopy(filePath, (PSZ)NS_CONST_CAST(char*, destPath.get()), DCPY_EXISTING); + rc = DosCopy(filePath.get(), (PSZ)NS_CONST_CAST(char*, destPath.get()), DCPY_EXISTING); /* WSOD2 HACK */ if (rc == 65) { // NETWORK_ACCESS_DENIED CHAR achProgram[CCHMAXPATH]; // buffer for program name, parameters @@ -938,7 +928,7 @@ nsLocalFile::CopySingleFile(nsIFile *sourceFile, nsIFile *destParent, const char strcpy(achProgram, "CMD.EXE /C "); strcat(achProgram, """COPY "); - strcat(achProgram, filePath); + strcat(achProgram, filePath.get()); strcat(achProgram, " "); strcat(achProgram, (PSZ)NS_CONST_CAST(char*, destPath.get())); strcat(achProgram, """"); @@ -955,21 +945,19 @@ nsLocalFile::CopySingleFile(nsIFile *sourceFile, nsIFile *destParent, const char */ if( move && (rc == NO_ERROR) ) { - DosDelete( filePath ); + DosDelete( filePath.get() ); } } /* !move or ERROR */ if (rc) rv = ConvertOS2Error(rc); - - nsMemory::Free(filePath); return rv; } nsresult -nsLocalFile::CopyMove(nsIFile *aParentDir, const char *newName, PRBool followSymlinks, PRBool move) +nsLocalFile::CopyMove(nsIFile *aParentDir, const nsACString &newName, PRBool followSymlinks, PRBool move) { nsCOMPtr newParentDir = aParentDir; // check to see if this exists, otherwise return an error. @@ -984,7 +972,7 @@ nsLocalFile::CopyMove(nsIFile *aParentDir, const char *newName, PRBool followSym { // no parent was specified. We must rename. - if (!newName) + if (newName.IsEmpty()) return NS_ERROR_INVALID_ARG; move = PR_TRUE; @@ -1018,16 +1006,14 @@ nsLocalFile::CopyMove(nsIFile *aParentDir, const char *newName, PRBool followSym newParentDir->IsSymlink(&isLink); if (isLink) { - char* target; - newParentDir->GetTarget(&target); + nsCAutoString target; + newParentDir->GetNativeTarget(target); nsCOMPtr realDest = new nsLocalFile(); if (realDest == nsnull) return NS_ERROR_OUT_OF_MEMORY; - rv = realDest->InitWithPath(target); - - nsMemory::Free(target); + rv = realDest->InitWithNativePath(target); if (NS_FAILED(rv)) return rv; @@ -1064,35 +1050,35 @@ nsLocalFile::CopyMove(nsIFile *aParentDir, const char *newName, PRBool followSym if (NS_FAILED(rv)) return rv; - char *allocatedNewName; - if (!newName) + nsCAutoString allocatedNewName; + if (newName.IsEmpty()) { PRBool isLink; IsSymlink(&isLink); if (isLink) { - char* temp; - GetTarget(&temp); - const char* leaf = (const char*) _mbsrchr((const unsigned char*) temp, '\\'); + nsCAutoString temp; + GetNativeTarget(temp); + const char* leaf = (const char*) _mbsrchr((const unsigned char*) temp.get(), '\\'); if (leaf[0] == '\\') leaf++; - allocatedNewName = (char*) nsMemory::Clone( leaf, strlen(leaf)+1 ); + allocatedNewName = leaf; } else { - GetLeafName(&allocatedNewName);// this should be the leaf name of the + GetNativeLeafName(allocatedNewName);// this should be the leaf name of the } } else { - allocatedNewName = (char*) nsMemory::Clone( newName, strlen(newName)+1 ); + allocatedNewName = newName; } - rv = target->Append(allocatedNewName); + rv = target->AppendNative(allocatedNewName); if (NS_FAILED(rv)) return rv; - nsMemory::Free(allocatedNewName); + allocatedNewName.Truncate(); target->Create(DIRECTORY_TYPE, 0644); // TODO, what permissions should we use if (NS_FAILED(rv)) @@ -1124,14 +1110,14 @@ nsLocalFile::CopyMove(nsIFile *aParentDir, const char *newName, PRBool followSym if (followSymlinks) rv = NS_ERROR_FAILURE; else - rv = file->MoveTo(target, nsnull); + rv = file->MoveToNative(target, nsCString()); } else { if (followSymlinks) - rv = file->CopyToFollowingLinks(target, nsnull); + rv = file->CopyToFollowingLinksNative(target, nsCString()); else - rv = file->CopyTo(target, nsnull); + rv = file->CopyToNative(target, nsCString()); } iterator->HasMoreElements(&more); @@ -1144,48 +1130,44 @@ nsLocalFile::CopyMove(nsIFile *aParentDir, const char *newName, PRBool followSym { MakeDirty(); - char* newParentPath; - newParentDir->GetPath(&newParentPath); + nsCAutoString newParentPath; + newParentDir->GetNativePath(newParentPath); - if (newParentPath == nsnull) + if (newParentPath.IsEmpty()) return NS_ERROR_FAILURE; - if (newName == nsnull) + if (newName.IsEmpty()) { - char *aFileName; - GetLeafName(&aFileName); + nsCAutoString aFileName; + GetNativeLeafName(aFileName); - InitWithPath(newParentPath); - Append(aFileName); - - nsMemory::Free(aFileName); + InitWithNativePath(newParentPath); + AppendNative(aFileName); } else { - InitWithPath(newParentPath); - Append(newName); + InitWithNativePath(newParentPath); + AppendNative(newName); } - - nsMemory::Free(newParentPath); } return NS_OK; } NS_IMETHODIMP -nsLocalFile::CopyTo(nsIFile *newParentDir, const char *newName) +nsLocalFile::CopyToNative(nsIFile *newParentDir, const nsACString &newName) { return CopyMove(newParentDir, newName, PR_FALSE, PR_FALSE); } NS_IMETHODIMP -nsLocalFile::CopyToFollowingLinks(nsIFile *newParentDir, const char *newName) +nsLocalFile::CopyToFollowingLinksNative(nsIFile *newParentDir, const nsACString &newName) { return CopyMove(newParentDir, newName, PR_TRUE, PR_FALSE); } NS_IMETHODIMP -nsLocalFile::MoveTo(nsIFile *newParentDir, const char *newName) +nsLocalFile::MoveToNative(nsIFile *newParentDir, const nsACString &newName) { return CopyMove(newParentDir, newName, PR_FALSE, PR_TRUE); } @@ -1665,7 +1647,7 @@ nsLocalFile::GetParent(nsIFile * *aParent) { NS_ENSURE_ARG_POINTER(aParent); - nsCString parentPath = mWorkingPath; + nsCAutoString parentPath(mWorkingPath); // cannot use nsCString::RFindChar() due to 0x5c problem PRInt32 offset = (PRInt32) (_mbsrchr((const unsigned char *) parentPath.get(), '\\') @@ -1676,11 +1658,11 @@ nsLocalFile::GetParent(nsIFile * *aParent) parentPath.Truncate(offset); nsCOMPtr localFile; - nsresult rv = NS_NewLocalFile(parentPath.get(), mFollowSymlinks, getter_AddRefs(localFile)); + nsresult rv = NS_NewNativeLocalFile(parentPath, mFollowSymlinks, getter_AddRefs(localFile)); if(NS_SUCCEEDED(rv) && localFile) { - return localFile->QueryInterface(NS_GET_IID(nsIFile), (void**)aParent); + return CallQueryInterface(localFile, aParent); } return rv; } @@ -1765,7 +1747,7 @@ nsLocalFile::IsExecutable(PRBool *_retval) if (NS_FAILED(rv)) return rv; - char* path = nsnull; + nsCAutoString path; PRBool symLink; rv = IsSymlink(&symLink); @@ -1773,11 +1755,11 @@ nsLocalFile::IsExecutable(PRBool *_retval) return rv; if (symLink) - GetTarget(&path); + GetNativeTarget(path); else - GetPath(&path); + GetNativePath(path); - const char* leaf = (const char*) _mbsrchr((const unsigned char*) path, '\\'); + const char* leaf = (const char*) _mbsrchr((const unsigned char*) path.get(), '\\'); // XXX On Windows NT / 2000, it should use "PATHEXT" environment value #ifdef XP_OS2 @@ -1794,8 +1776,6 @@ nsLocalFile::IsExecutable(PRBool *_retval) *_retval = PR_FALSE; } - nsMemory::Free(path); - return NS_OK; } @@ -1878,20 +1858,19 @@ nsLocalFile::IsSymlink(PRBool *_retval) *_retval = PR_FALSE; #ifndef XP_OS2 // No Symlinks on OS/2 - char* path; + nsCAutoString path; int pathLen; - GetPath(&path); - pathLen = strlen(path); + GetNativePath(path); + pathLen = path.Length(); - const char* leaf = path + pathLen - 4; + const char* leaf = path.get() + pathLen - 4; if ( (strcmp(leaf, ".lnk") == 0)) { *_retval = PR_TRUE; } - nsMemory::Free(path); #endif return NS_OK; @@ -1942,18 +1921,10 @@ nsLocalFile::Equals(nsIFile *inFile, PRBool *_retval) NS_ENSURE_ARG(_retval); *_retval = PR_FALSE; - char* inFilePath; - inFile->GetPath(&inFilePath); + nsCAutoString inFilePath; + inFile->GetNativePath(inFilePath); - char* filePath; - GetPath(&filePath); - - if (strcmp(inFilePath, filePath) == 0) - *_retval = PR_TRUE; - - nsMemory::Free(inFilePath); - nsMemory::Free(filePath); - + *_retval = inFilePath.Equals(mWorkingPath); return NS_OK; } @@ -1962,17 +1933,17 @@ nsLocalFile::Contains(nsIFile *inFile, PRBool recur, PRBool *_retval) { *_retval = PR_FALSE; - char* myFilePath; - if ( NS_FAILED(GetTarget(&myFilePath))) - GetPath(&myFilePath); + nsCAutoString myFilePath; + if ( NS_FAILED(GetNativeTarget(myFilePath))) + GetNativePath(myFilePath); - PRInt32 myFilePathLen = strlen(myFilePath); + PRInt32 myFilePathLen = myFilePath.Length(); - char* inFilePath; - if ( NS_FAILED(inFile->GetTarget(&inFilePath))) - inFile->GetPath(&inFilePath); + nsCAutoString inFilePath; + if ( NS_FAILED(inFile->GetNativeTarget(inFilePath))) + inFile->GetNativePath(inFilePath); - if ( strncmp( myFilePath, inFilePath, myFilePathLen) == 0) + if ( strncmp( myFilePath.get(), inFilePath.get(), myFilePathLen) == 0) { // now make sure that the |inFile|'s path has a trailing // separator. @@ -1984,19 +1955,15 @@ nsLocalFile::Contains(nsIFile *inFile, PRBool recur, PRBool *_retval) } - nsMemory::Free(inFilePath); - nsMemory::Free(myFilePath); - return NS_OK; } NS_IMETHODIMP -nsLocalFile::GetTarget(char **_retval) +nsLocalFile::GetNativeTarget(nsACString &_retval) { - NS_ENSURE_ARG(_retval); - *_retval = nsnull; + _retval.Truncate(); #if STRICT_FAKE_SYMLINKS PRBool symLink; @@ -2011,7 +1978,7 @@ nsLocalFile::GetTarget(char **_retval) #endif ResolveAndStat(PR_TRUE); - *_retval = (char*) nsMemory::Clone( mResolvedPath.get(), mResolvedPath.Length()+1 ); + _retval = mResolvedPath; return NS_OK; } @@ -2062,17 +2029,15 @@ nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator * *entries) } NS_IMETHODIMP -nsLocalFile::GetPersistentDescriptor(char * *aPersistentDescriptor) +nsLocalFile::GetPersistentDescriptor(nsACString &aPersistentDescriptor) { - NS_ENSURE_ARG_POINTER(aPersistentDescriptor); - return GetPath(aPersistentDescriptor); + return GetNativePath(aPersistentDescriptor); } NS_IMETHODIMP -nsLocalFile::SetPersistentDescriptor(const char * aPersistentDescriptor) +nsLocalFile::SetPersistentDescriptor(const nsACString &aPersistentDescriptor) { - NS_ENSURE_ARG(aPersistentDescriptor); - return InitWithPath(aPersistentDescriptor); + return InitWithNativePath(aPersistentDescriptor); } #ifndef OPEN_DEFAULT @@ -2084,22 +2049,22 @@ NS_IMETHODIMP nsLocalFile::Reveal() { PRBool isDirectory = PR_FALSE; - nsXPIDLCString path; + nsCAutoString path; IsDirectory(&isDirectory); if (isDirectory) { - GetPath(getter_Copies(path)); + GetNativePath(path); } else { nsCOMPtr parent; GetParent(getter_AddRefs(parent)); if (parent) - parent->GetPath(getter_Copies(path)); + parent->GetNativePath(path); } - HOBJECT hobject = WinQueryObject(path); + HOBJECT hobject = WinQueryObject(path.get()); WinOpenObject( hobject, OPEN_DEFAULT, TRUE); // we don't care if it succeeded or failed. @@ -2110,11 +2075,7 @@ nsLocalFile::Reveal() NS_IMETHODIMP nsLocalFile::Launch() { - nsXPIDLCString platformPath; - - GetPath(getter_Copies(platformPath)); - - HOBJECT hobject = WinQueryObject(platformPath); + HOBJECT hobject = WinQueryObject(mWorkingPath.get()); WinOpenObject( hobject, OPEN_DEFAULT, TRUE); // we don't care if it succeeded or failed. @@ -2122,7 +2083,7 @@ nsLocalFile::Launch() } nsresult -NS_NewLocalFile(const char* path, PRBool followLinks, nsILocalFile* *result) +NS_NewNativeLocalFile(const nsACString &path, PRBool followLinks, nsILocalFile* *result) { nsLocalFile* file = new nsLocalFile(); if (file == nsnull) @@ -2131,8 +2092,8 @@ NS_NewLocalFile(const char* path, PRBool followLinks, nsILocalFile* *result) file->SetFollowLinks(followLinks); - if (path) { - nsresult rv = file->InitWithPath(path); + if (!path.IsEmpty()) { + nsresult rv = file->InitWithNativePath(path); if (NS_FAILED(rv)) { NS_RELEASE(file); return rv; @@ -2237,7 +2198,7 @@ static int isleadbyte(int c) static UconvObject UnicodeConverter = NULL; -nsresult NS_CreateUnicodeConverters() +static nsresult NS_CreateUnicodeConverters() { ULONG ulLength; ULONG ulCodePage; @@ -2259,7 +2220,7 @@ nsresult NS_CreateUnicodeConverters() } } -void NS_DestroyUnicodeConverters() +static void NS_DestroyUnicodeConverters() { ::UniFreeUconvObject(UnicodeConverter); } @@ -2326,7 +2287,7 @@ nsLocalFile::InitWithUnicodePath(const PRUnichar *filePath) nsresult rv = UCS2toFS(filePath, getter_Copies(tmp)); if (NS_SUCCEEDED(rv)) - return InitWithPath(tmp); + return InitWithNativePath(tmp); return rv; } @@ -2343,7 +2304,7 @@ nsLocalFile::AppendUnicode(const PRUnichar *node) nsresult rv = UCS2toFS(node, getter_Copies(tmp)); if (NS_SUCCEEDED(rv)) - return Append(tmp); + return AppendNative(tmp); return rv; } @@ -2364,7 +2325,7 @@ nsLocalFile::AppendRelativeUnicodePath(const PRUnichar *node) nsresult rv = UCS2toFS(node, getter_Copies(tmp)); if (NS_SUCCEEDED(rv)) - return AppendRelativePath(tmp); + return AppendRelativeNativePath(tmp); return rv; } @@ -2373,11 +2334,11 @@ NS_IMETHODIMP nsLocalFile::GetUnicodeLeafName(PRUnichar **aLeafName) { NS_ENSURE_ARG_POINTER(aLeafName); - nsXPIDLCString tmp; - nsresult rv = GetLeafName(getter_Copies(tmp)); + nsCAutoString tmp; + nsresult rv = GetNativeLeafName(tmp); if (NS_SUCCEEDED(rv)) - return FStoUCS2(tmp, aLeafName); + return FStoUCS2(tmp.get(), aLeafName); return rv; } @@ -2394,7 +2355,7 @@ nsLocalFile::SetUnicodeLeafName(const PRUnichar *aLeafName) nsresult rv = UCS2toFS(aLeafName, getter_Copies(tmp)); if (NS_SUCCEEDED(rv)) - return SetLeafName(tmp); + return SetNativeLeafName(tmp); return rv; } @@ -2403,26 +2364,21 @@ NS_IMETHODIMP nsLocalFile::GetUnicodePath(PRUnichar **_retval) { NS_ENSURE_ARG_POINTER(_retval); - nsXPIDLCString tmp; - nsresult rv = GetPath(getter_Copies(tmp)); - if (NS_SUCCEEDED(rv)) - return FStoUCS2(tmp, _retval); - - return rv; + return FStoUCS2(mWorkingPath.get(), _retval); } NS_IMETHODIMP nsLocalFile::CopyToUnicode(nsIFile *newParentDir, const PRUnichar *newName) { if (!newName || nsCRT::strlen(newName) == 0) - return CopyTo(newParentDir, nsnull); + return CopyToNative(newParentDir, nsCString()); nsXPIDLCString tmp; nsresult rv = UCS2toFS(newName, getter_Copies(tmp)); if (NS_SUCCEEDED(rv)) - return CopyTo(newParentDir, tmp); + return CopyToNative(newParentDir, tmp); return rv; } @@ -2431,13 +2387,13 @@ NS_IMETHODIMP nsLocalFile::CopyToFollowingLinksUnicode(nsIFile *newParentDir, const PRUnichar *newName) { if (!newName || nsCRT::strlen(newName) == 0) - return CopyToFollowingLinks(newParentDir, nsnull); + return CopyToFollowingLinksNative(newParentDir, nsCString()); nsXPIDLCString tmp; nsresult rv = UCS2toFS(newName, getter_Copies(tmp)); if (NS_SUCCEEDED(rv)) - return CopyToFollowingLinks(newParentDir, tmp); + return CopyToFollowingLinksNative(newParentDir, tmp); return rv; } @@ -2446,13 +2402,13 @@ NS_IMETHODIMP nsLocalFile::MoveToUnicode(nsIFile *newParentDir, const PRUnichar *newName) { if (!newName || nsCRT::strlen(newName) == 0) - return MoveTo(newParentDir, nsnull); + return MoveToNative(newParentDir, nsCString()); nsXPIDLCString tmp; nsresult rv = UCS2toFS(newName, getter_Copies(tmp)); if (NS_SUCCEEDED(rv)) - return MoveTo(newParentDir, tmp); + return MoveToNative(newParentDir, tmp); return rv; } @@ -2461,11 +2417,11 @@ NS_IMETHODIMP nsLocalFile::GetUnicodeTarget(PRUnichar **_retval) { NS_ENSURE_ARG_POINTER(_retval); - nsXPIDLCString tmp; - nsresult rv = GetTarget(getter_Copies(tmp)); + nsCAutoString tmp; + nsresult rv = GetNativeTarget(tmp); if (NS_SUCCEEDED(rv)) - return FStoUCS2(tmp, _retval); + return FStoUCS2(tmp.get(), _retval); return rv; } @@ -2480,7 +2436,27 @@ NS_NewUnicodeLocalFile(const PRUnichar* path, PRBool followLinks, nsILocalFile* nsresult rv = UCS2toFS(path, getter_Copies(tmp)); if (NS_SUCCEEDED(rv)) - return NS_NewLocalFile(tmp, followLinks, result); + return NS_NewNativeLocalFile(tmp, followLinks, result); return NS_OK; } + +//---------------------------------------------------------------------------- +// global init/shutdown +//---------------------------------------------------------------------------- + +PRBool nsLocalFile::mFSCharsetIsUTF8 = PR_FALSE; + +void +nsLocalFile::GlobalInit() +{ + NS_CreateUnicodeConverters(); + + // XXX set mFSCharsetIsUTF8 +} + +void +nsLocalFile::GlobalShutdown() +{ + NS_DestroyUnicodeConverters(); +} diff --git a/mozilla/xpcom/io/nsLocalFileOS2.h b/mozilla/xpcom/io/nsLocalFileOS2.h index cc997e097b7..c02d8e419e3 100644 --- a/mozilla/xpcom/io/nsLocalFileOS2.h +++ b/mozilla/xpcom/io/nsLocalFileOS2.h @@ -112,8 +112,14 @@ public: // nsILocalFile interface NS_DECL_NSILOCALFILE +public: + static void GlobalInit(); + static void GlobalShutdown(); + private: + static PRBool mFSCharsetIsUTF8; + // this is the flag which indicates if I can used cached information about the file PRPackedBool mDirty; PRPackedBool mLastResolution; @@ -136,15 +142,18 @@ private: nsresult ResolveAndStat(PRBool resolveTerminal); nsresult ResolvePath(const char* workingPath, PRBool resolveTerminal, char** resolvedPath); - nsresult CopyMove(nsIFile *newParentDir, const char *newName, PRBool followSymlinks, PRBool move); - nsresult CopySingleFile(nsIFile *source, nsIFile* dest, const char * newName, PRBool followSymlinks, PRBool move); + nsresult CopyMove(nsIFile *newParentDir, const nsACString &newName, PRBool followSymlinks, PRBool move); + nsresult CopySingleFile(nsIFile *source, nsIFile* dest, const nsACString &newName, PRBool followSymlinks, PRBool move); nsresult SetModDate(PRInt64 aLastModifiedTime, PRBool resolveTerminal); + static PRBool FSCharsetIsUTF8() { return mFSCharsetIsUTF8; } + + // XXX impl + PRBool PathIsASCII() { return PR_FALSE; } + PRBool LeafIsASCII() { return PR_FALSE; } + + NS_DECL_NSLOCALFILE_UNICODE_METHODS }; - -extern nsresult NS_CreateUnicodeConverters(); -extern void NS_DestroyUnicodeConverters(); - #endif diff --git a/mozilla/xpcom/io/nsLocalFileUnicode.cpp b/mozilla/xpcom/io/nsLocalFileUnicode.cpp index e87a1b996ad..715de2a7a6c 100644 --- a/mozilla/xpcom/io/nsLocalFileUnicode.cpp +++ b/mozilla/xpcom/io/nsLocalFileUnicode.cpp @@ -62,6 +62,7 @@ public: static void CleanUp(); static nsresult UCSToNewFS( const PRUnichar* aIn, char** aOut); static nsresult FSToNewUCS( const char* aIn, PRUnichar** aOut); + static const nsAString *FSCharset(); private: static nsresult PrepareFSCharset(); @@ -89,13 +90,10 @@ void NS_ShutdownLocalFileUnicode() #define GET_UCS( func , arg) \ { \ - char* tmp; \ + nsCAutoString tmp; \ nsresult res; \ - if(NS_SUCCEEDED(res = (func)(&tmp))) { \ - if(NS_SUCCEEDED(res = nsFSStringConversion::FSToNewUCS(tmp, (arg)))){ \ - nsMemory::Free(tmp); \ - } \ - } \ + if(NS_SUCCEEDED(res = (func)(tmp))) \ + res = nsFSStringConversion::FSToNewUCS(tmp.get(), (arg)); \ return res; \ } #define VOID_SET_UCS( func , arg, assertion_msg) \ @@ -113,7 +111,7 @@ void NS_ShutdownLocalFileUnicode() char* tmp; \ nsresult res; \ if(NS_SUCCEEDED(res = nsFSStringConversion::UCSToNewFS((arg), &tmp))) { \ - res = (func)(tmp); \ + res = (func)(nsDependentCString(tmp)); \ nsMemory::Free(tmp); \ } \ return res; \ @@ -123,7 +121,7 @@ void NS_ShutdownLocalFileUnicode() char* tmp; \ nsresult res; \ if(NS_SUCCEEDED(res = nsFSStringConversion::UCSToNewFS((arg2), &tmp))){ \ - res = (func)(arg1, tmp); \ + res = (func)(arg1, nsDependentCString(tmp)); \ nsMemory::Free(tmp); \ } \ return res; \ @@ -133,7 +131,7 @@ void NS_ShutdownLocalFileUnicode() char* tmp; \ nsresult res; \ if(NS_SUCCEEDED(res = nsFSStringConversion::UCSToNewFS((path), &tmp))){ \ - res = (func)(tmp, followLinks, result); \ + res = (func)(nsDependentCString(tmp), followLinks, result); \ nsMemory::Free(tmp); \ } \ return res; \ @@ -294,60 +292,79 @@ nsFSStringConversion::FSToNewUCS( const char* aIn, PRUnichar** aOut) return res; } +const nsAString * +nsFSStringConversion::FSCharset() +{ +#ifndef XPCOM_STANDALONE + nsresult res = PrepareFSCharset(); + if(NS_SUCCEEDED(res)) + return mFSCharset; +#endif + return nsnull; +} + +PRBool +nsLocalFile::FSCharsetIsUTF8() +{ + // assuming charset is normalized uppercase + return nsFSStringConversion::FSCharset() && + nsFSStringConversion::FSCharset()->Equals(NS_LITERAL_STRING("UTF-8")); +} + // Unicode interface Wrapper NS_IMETHODIMP nsLocalFile::InitWithUnicodePath(const PRUnichar *filePath) { - SET_UCS(InitWithPath, filePath); + SET_UCS(InitWithNativePath, filePath); } NS_IMETHODIMP nsLocalFile::AppendUnicode(const PRUnichar *node) { - SET_UCS( Append , node); + SET_UCS( AppendNative , node); } NS_IMETHODIMP nsLocalFile::AppendRelativeUnicodePath(const PRUnichar *node) { - SET_UCS( AppendRelativePath , node); + SET_UCS( AppendRelativeNativePath , node); } NS_IMETHODIMP nsLocalFile::GetUnicodeLeafName(PRUnichar **aLeafName) { - GET_UCS(GetLeafName, aLeafName); + GET_UCS(GetNativeLeafName, aLeafName); } NS_IMETHODIMP nsLocalFile::SetUnicodeLeafName(const PRUnichar * aLeafName) { - SET_UCS( SetLeafName , aLeafName); + SET_UCS( SetNativeLeafName , aLeafName); } NS_IMETHODIMP nsLocalFile::GetUnicodePath(PRUnichar **_retval) { - GET_UCS(GetPath, _retval); + GET_UCS(GetNativePath, _retval); } NS_IMETHODIMP nsLocalFile::CopyToUnicode(nsIFile *newParentDir, const PRUnichar *newName) { - SET_UCS_2ARGS_2( CopyTo , newParentDir, newName); + SET_UCS_2ARGS_2( CopyToNative , newParentDir, newName); } NS_IMETHODIMP nsLocalFile::CopyToFollowingLinksUnicode(nsIFile *newParentDir, const PRUnichar *newName) { - SET_UCS_2ARGS_2( CopyToFollowingLinks , newParentDir, newName); + SET_UCS_2ARGS_2( CopyToFollowingLinksNative , newParentDir, newName); } NS_IMETHODIMP nsLocalFile::MoveToUnicode(nsIFile *newParentDir, const PRUnichar *newName) { - SET_UCS_2ARGS_2( MoveTo , newParentDir, newName); + SET_UCS_2ARGS_2( MoveToNative , newParentDir, newName); } NS_IMETHODIMP nsLocalFile::GetUnicodeTarget(PRUnichar **_retval) { - GET_UCS(GetTarget, _retval); + GET_UCS(GetNativeTarget, _retval); } nsresult NS_NewUnicodeLocalFile(const PRUnichar* path, PRBool followLinks, nsILocalFile* *result) { - SET_UCS_2ARGS_1( NS_NewLocalFile, path, followLinks, result) + SET_UCS_2ARGS_1( NS_NewNativeLocalFile, path, followLinks, result) } diff --git a/mozilla/xpcom/io/nsLocalFileUnicode.h b/mozilla/xpcom/io/nsLocalFileUnicode.h index a334cd1da10..53121835fb7 100644 --- a/mozilla/xpcom/io/nsLocalFileUnicode.h +++ b/mozilla/xpcom/io/nsLocalFileUnicode.h @@ -39,5 +39,8 @@ extern void NS_ShutdownLocalFileUnicode(); +extern "C" NS_EXPORT nsresult +NS_NewUnicodeLocalFile(const PRUnichar *, PRBool, nsILocalFile **); + #endif // _NS_LOCALFILEUNICODE_H_ diff --git a/mozilla/xpcom/io/nsLocalFileUnix.cpp b/mozilla/xpcom/io/nsLocalFileUnix.cpp index 6dcd8770c59..d0db4945cdb 100644 --- a/mozilla/xpcom/io/nsLocalFileUnix.cpp +++ b/mozilla/xpcom/io/nsLocalFileUnix.cpp @@ -61,12 +61,27 @@ #include "nsString.h" #include "nsReadableUtils.h" #include "nsLocalFileUnix.h" +#include "nsLocalFileUnicode.h" #include "nsIComponentManager.h" #include "nsXPIDLString.h" #include "prproces.h" #include "nsISimpleEnumerator.h" #include "nsITimelineService.h" +// nl_langinfo support +#ifdef HAVE_NL_TYPES_H +#include +#endif +#ifdef HAVE_NL_LANGINFO +#include +#endif + +// wchar_t support +#include // wctomb/mbtowc on some platforms +#if defined(HAVE_WCRTOMB) || defined(HAVE_MBRTOWC) +#include // wcrtomb/mbrtowc on some platforms +#endif + // On some platforms file/directory name comparisons need to // be case-blind. #if defined(VMS) @@ -88,7 +103,7 @@ #define CHECK_mPath() \ PR_BEGIN_MACRO \ - if (!mPath.get()) \ + if (mPath.IsEmpty()) \ return NS_ERROR_NOT_INITIALIZED; \ PR_END_MACRO @@ -106,14 +121,14 @@ nsDirEnumeratorUnix : public nsISimpleEnumerator // nsISimpleEnumerator interface NS_DECL_NSISIMPLEENUMERATOR - NS_IMETHOD Init(nsIFile *parent, PRBool ignored); + NS_IMETHOD Init(nsLocalFile *parent, PRBool ignored); protected: NS_IMETHOD GetNextEntry(); - DIR *mDir; + DIR *mDir; struct dirent *mEntry; - nsXPIDLCString mParentPath; + nsCString mParentPath; }; nsDirEnumeratorUnix::nsDirEnumeratorUnix() : @@ -132,15 +147,15 @@ nsDirEnumeratorUnix::~nsDirEnumeratorUnix() NS_IMPL_ISUPPORTS1(nsDirEnumeratorUnix, nsISimpleEnumerator) NS_IMETHODIMP -nsDirEnumeratorUnix::Init(nsIFile *parent, PRBool resolveSymlinks /*ignored*/) +nsDirEnumeratorUnix::Init(nsLocalFile *parent, PRBool resolveSymlinks /*ignored*/) { - nsXPIDLCString dirPath; - if (NS_FAILED(parent->GetPath(getter_Copies(dirPath))) || - (dirPath.get() == nsnull)) { + nsCAutoString dirPath; + if (NS_FAILED(parent->GetNativePath(dirPath)) || + dirPath.IsEmpty()) { return NS_ERROR_FILE_INVALID_PATH; } - if (NS_FAILED(parent->GetPath(getter_Copies(mParentPath)))) + if (NS_FAILED(parent->GetNativePath(mParentPath))) return NS_ERROR_FAILURE; mDir = opendir(dirPath.get()); @@ -165,15 +180,15 @@ nsDirEnumeratorUnix::GetNext(nsISupports **_retval) return NS_OK; } - nsCOMPtr file = new nsLocalFile(); + nsLocalFile* file = new nsLocalFile(); if (!file) return NS_ERROR_OUT_OF_MEMORY; - if (NS_FAILED(rv = file->InitWithPath(mParentPath)) || - NS_FAILED(rv = file->Append(mEntry->d_name))) { + if (NS_FAILED(rv = file->InitWithNativePath(mParentPath)) || + NS_FAILED(rv = file->AppendNative(nsDependentCString(mEntry->d_name)))) { return rv; } - *_retval = file; + *_retval = NS_STATIC_CAST(nsISupports *, file); NS_ADDREF(*_retval); return GetNextEntry(); } @@ -198,7 +213,9 @@ nsDirEnumeratorUnix::GetNextEntry() } nsLocalFile::nsLocalFile() : - mHaveCachedStat(PR_FALSE) + mHaveCachedStat(PR_FALSE), + mPathIsASCII(-1), + mLeafIsASCII(-1) { NS_INIT_REFCNT(); } @@ -207,12 +224,14 @@ nsLocalFile::~nsLocalFile() { } -NS_IMPL_THREADSAFE_ISUPPORTS2(nsLocalFile, nsILocalFile, nsIFile) +NS_IMPL_THREADSAFE_ISUPPORTS2(nsLocalFile, + nsIFile, + nsILocalFile) nsresult nsLocalFile::nsLocalFileConstructor(nsISupports *outer, - const nsIID &aIID, - void **aInstancePtr) + const nsIID &aIID, + void **aInstancePtr) { NS_ENSURE_ARG_POINTER(aInstancePtr); NS_ENSURE_NO_AGGREGATION(outer); @@ -240,34 +259,32 @@ nsLocalFile::FillStatCache() { NS_IMETHODIMP nsLocalFile::Clone(nsIFile **file) { - CHECK_mPath(); NS_ENSURE_ARG(file); - nsCOMPtr localFile = new nsLocalFile(); + nsLocalFile* localFile = new nsLocalFile(); if (!localFile) return NS_ERROR_OUT_OF_MEMORY; - nsresult rv = localFile->InitWithPath(mPath); + nsresult rv = localFile->InitWithNativePath(mPath); if (NS_FAILED(rv)) return rv; - *file = localFile; + *file = NS_STATIC_CAST(nsIFile *, localFile); NS_ADDREF(*file); return NS_OK; } NS_IMETHODIMP -nsLocalFile::InitWithPath(const char *filePath) +nsLocalFile::InitWithNativePath(const nsACString &filePath) { - NS_ENSURE_ARG(filePath); + mPath = filePath; - ssize_t len = strlen(filePath); - while (filePath[len-1] == '/' && len > 1) + // trim off trailing slashes + ssize_t len = mPath.Length(); + while ((len > 1) && (mPath[len - 1] == '/')) --len; - mPath.Assign(Substring(filePath, filePath+len)); + mPath.SetLength(len); - if (!mPath.get()) - return NS_ERROR_OUT_OF_MEMORY; InvalidateCache(); return NS_OK; } @@ -275,8 +292,6 @@ nsLocalFile::InitWithPath(const char *filePath) NS_IMETHODIMP nsLocalFile::CreateAllAncestors(PRUint32 permissions) { - CHECK_mPath(); - // I promise to play nice char *buffer = NS_CONST_CAST(char *, mPath.get()), *slashp = buffer; @@ -331,8 +346,6 @@ nsLocalFile::CreateAllAncestors(PRUint32 permissions) NS_IMETHODIMP nsLocalFile::OpenNSPRFileDesc(PRInt32 flags, PRInt32 mode, PRFileDesc **_retval) { - CHECK_mPath(); - *_retval = PR_Open(mPath.get(), flags, mode); if (! *_retval) return NS_ErrorAccordingToNSPR(); @@ -343,8 +356,6 @@ nsLocalFile::OpenNSPRFileDesc(PRInt32 flags, PRInt32 mode, PRFileDesc **_retval) NS_IMETHODIMP nsLocalFile::OpenANSIFileDesc(const char *mode, FILE **_retval) { - CHECK_mPath(); - *_retval = fopen(mPath.get(), mode); if (! *_retval) return NS_ERROR_FAILURE; @@ -368,7 +379,6 @@ static int exclusive_mkdir(const char *path, mode_t mode) NS_IMETHODIMP nsLocalFile::Create(PRUint32 type, PRUint32 permissions) { - CHECK_mPath(); if (type != NORMAL_FILE_TYPE && type != DIRECTORY_TYPE) return NS_ERROR_FILE_UNKNOWN_TYPE; @@ -413,39 +423,34 @@ nsLocalFile::Create(PRUint32 type, PRUint32 permissions) } NS_IMETHODIMP -nsLocalFile::Append(const char *fragment) +nsLocalFile::AppendNative(const nsACString &fragment) { - CHECK_mPath(); - NS_ENSURE_ARG(fragment); + if (fragment.IsEmpty()) + return NS_OK; // only one component of path can be appended - if (strchr(fragment, '/')) + nsACString::const_iterator begin, end; + if (FindCharInReadable('/', fragment.BeginReading(begin), + fragment.EndReading(end))) return NS_ERROR_FILE_UNRECOGNIZED_PATH; - return AppendRelativePath(fragment); + return AppendRelativeNativePath(fragment); } NS_IMETHODIMP -nsLocalFile::AppendRelativePath(const char *fragment) +nsLocalFile::AppendRelativeNativePath(const nsACString &fragment) { - CHECK_mPath(); - NS_ENSURE_ARG(fragment); - - if (*fragment == '\0') + if (fragment.IsEmpty()) return NS_OK; // No leading '/' - if (*fragment == '/') + if (fragment.First() == '/') return NS_ERROR_FILE_UNRECOGNIZED_PATH; - if (mPath.Equals("/")) { - mPath.Append(nsDependentCString(fragment)); - } else { - mPath.Append(NS_LITERAL_CSTRING("/") + nsDependentCString(fragment)); - } - - if (!mPath.get()) - return NS_ERROR_OUT_OF_MEMORY; + if (mPath.Equals(NS_LITERAL_CSTRING("/"))) + mPath.Append(fragment); + else + mPath.Append(NS_LITERAL_CSTRING("/") + fragment); InvalidateCache(); return NS_OK; @@ -454,7 +459,6 @@ nsLocalFile::AppendRelativePath(const char *fragment) NS_IMETHODIMP nsLocalFile::Normalize() { - CHECK_mPath(); char resolved_path[PATH_MAX] = ""; char *resolved_path_ptr = nsnull; @@ -473,81 +477,62 @@ nsLocalFile::Normalize() if (!resolved_path_ptr) return NSRESULT_FOR_ERRNO(); - mPath.Adopt(nsCRT::strdup(resolved_path)); - if (!mPath.get()) - return NS_ERROR_OUT_OF_MEMORY; + mPath = resolved_path; return NS_OK; } -nsresult -nsLocalFile::GetLeafNameRaw(const char **_retval) +void +nsLocalFile::LocateNativeLeafName(nsACString::const_iterator &begin, + nsACString::const_iterator &end) { - CHECK_mPath(); - const char *leafName = strrchr(mPath.get(), '/'); - *_retval = leafName ? leafName + 1 : mPath.get(); + // XXX perhaps we should cache this?? + + mPath.BeginReading(begin); + mPath.EndReading(end); + + nsACString::const_iterator it = end; + nsACString::const_iterator stop = begin; + --stop; + while (--it != stop) { + if (*it == '/') { + begin = ++it; + return; + } + } + // else, the entire path is the leaf name (which means this + // isn't an absolute path... unexpected??) +} + +NS_IMETHODIMP +nsLocalFile::GetNativeLeafName(nsACString &aLeafName) +{ + nsACString::const_iterator begin, end; + LocateNativeLeafName(begin, end); + aLeafName = Substring(begin, end); return NS_OK; } NS_IMETHODIMP -nsLocalFile::GetLeafName(char **aLeafName) +nsLocalFile::SetNativeLeafName(const nsACString &aLeafName) { - NS_ENSURE_ARG_POINTER(aLeafName); - nsresult rv; - const char *leafName; - if (NS_FAILED(rv = GetLeafNameRaw(&leafName))) - return rv; - - *aLeafName = nsCRT::strdup(leafName); - if (!*aLeafName) - return NS_ERROR_OUT_OF_MEMORY; - return NS_OK; -} - -NS_IMETHODIMP -nsLocalFile::SetLeafName(const char *aLeafName) -{ - CHECK_mPath(); - NS_ENSURE_ARG(aLeafName); - - nsresult rv; - char *leafName; - if (NS_FAILED(rv = GetLeafNameRaw((const char **)&leafName))) - return rv; - - char *newPath = (char *)nsMemory::Alloc((leafName - mPath.get()) - + strlen(aLeafName) - + 1); - if (!newPath) - return NS_ERROR_OUT_OF_MEMORY; - *leafName = '\0'; - strcpy(newPath, mPath.get()); - strcat(newPath, aLeafName); - - mPath.Adopt(newPath); + nsACString::const_iterator begin, end; + LocateNativeLeafName(begin, end); + mPath.Replace(begin.get() - mPath.get(), Distance(begin, end), aLeafName); InvalidateCache(); return NS_OK; } NS_IMETHODIMP -nsLocalFile::GetPath(char **_retval) +nsLocalFile::GetNativePath(nsACString &_retval) { - NS_ENSURE_ARG_POINTER(_retval); - - if (!mPath.get()) { - *_retval = nsnull; - return NS_OK; - } - - *_retval = (char *)nsMemory::Clone(mPath.get(), strlen(mPath.get())+1); - if (!*_retval) - return NS_ERROR_OUT_OF_MEMORY; + _retval = mPath; return NS_OK; } nsresult -nsLocalFile::GetTargetPathName(nsIFile *newParent, - const char *newName, - char **_retval) +nsLocalFile::GetNativeTargetPathName(nsIFile *newParent, + const nsACString &newName, + nsACString &_retval) { nsresult rv; nsCOMPtr oldParent; @@ -577,24 +562,21 @@ nsLocalFile::GetTargetPathName(nsIFile *newParent, } } - if (!newName && NS_FAILED(rv = GetLeafNameRaw(&newName))) + nsACString::const_iterator nameBegin, nameEnd; + if (!newName.IsEmpty()) { + newName.BeginReading(nameBegin); + newName.EndReading(nameEnd); + } + else + LocateNativeLeafName(nameBegin, nameEnd); + + nsCAutoString dirName; + if (NS_FAILED(rv = newParent->GetNativePath(dirName))) return rv; - nsXPIDLCString dirName; - if (NS_FAILED(rv = newParent->GetPath(getter_Copies(dirName)))) - return rv; - - char *newPathName = (char *)nsMemory::Alloc(strlen(dirName.get()) + - strlen(newName) + - 2); - if (!newPathName) - return NS_ERROR_OUT_OF_MEMORY; - - strcpy(newPathName, dirName.get()); - strcat(newPathName, "/"); - strcat(newPathName, newName); - - *_retval = newPathName; + _retval = dirName + + NS_LITERAL_CSTRING("/") + + Substring(nameBegin, nameEnd); return NS_OK; } @@ -612,7 +594,7 @@ nsLocalFile::CopyDirectoryTo(nsIFile *newParent) if NS_FAILED((rv = IsDirectory(&dirCheck))) return rv; if (!dirCheck) - return CopyTo(newParent, nsnull); + return CopyToNative(newParent, nsCString()); if (NS_FAILED(rv = Equals(newParent, &dirCheck))) return rv; @@ -630,10 +612,10 @@ nsLocalFile::CopyDirectoryTo(nsIFile *newParent) if (NS_FAILED(rv = newParent->Create(DIRECTORY_TYPE, oldPerms))) return rv; } else { // dir exists lets try to use leaf - nsXPIDLCString leafName; - if (NS_FAILED(rv = GetLeafName(getter_Copies(leafName)))) + nsCAutoString leafName; + if (NS_FAILED(rv = GetNativeLeafName(leafName))) return rv; - if (NS_FAILED(rv = newParent->Append(leafName))) + if (NS_FAILED(rv = newParent->AppendNative(leafName))) return rv; if (NS_FAILED(rv = newParent->Exists(&dirCheck))) return rv; @@ -662,11 +644,11 @@ nsLocalFile::CopyDirectoryTo(nsIFile *newParent) rv = newParent->Clone(getter_AddRefs(destClone)); if (NS_SUCCEEDED(rv)) { nsCOMPtr newDir(do_QueryInterface(destClone)); - if (NS_FAILED(rv = entry->CopyTo(newDir, nsnull))) { + if (NS_FAILED(rv = entry->CopyTo(newDir, nsCString()))) { #ifdef DEBUG nsresult rv2; - nsXPIDLCString pathName; - if (NS_FAILED(rv2 = entry->GetPath(getter_Copies(pathName)))) + nsCAutoString pathName; + if (NS_FAILED(rv2 = entry->GetPath(pathName))) return rv2; printf("Operation not supported: %s\n", pathName.get()); #endif @@ -676,11 +658,11 @@ nsLocalFile::CopyDirectoryTo(nsIFile *newParent) } } } else { - if (NS_FAILED(rv = entry->CopyTo(newParent, nsnull))) { + if (NS_FAILED(rv = entry->CopyTo(newParent, nsCString()))) { #ifdef DEBUG nsresult rv2; - nsXPIDLCString pathName; - if (NS_FAILED(rv2 = entry->GetPath(getter_Copies(pathName)))) + nsCAutoString pathName; + if (NS_FAILED(rv2 = entry->GetPath(pathName))) return rv2; printf("Operation not supported: %s\n", pathName.get()); #endif @@ -694,7 +676,7 @@ nsLocalFile::CopyDirectoryTo(nsIFile *newParent) } NS_IMETHODIMP -nsLocalFile::CopyTo(nsIFile *newParent, const char *newName) +nsLocalFile::CopyToNative(nsIFile *newParent, const nsACString &newName) { nsresult rv; // check to make sure that this has been initialized properly @@ -704,26 +686,27 @@ nsLocalFile::CopyTo(nsIFile *newParent, const char *newName) nsCOMPtr workParent; if (NS_FAILED(rv = newParent->Clone(getter_AddRefs(workParent)))) return rv; + // check to see if we are a directory or if we are a file PRBool isDirectory; if (NS_FAILED(rv = IsDirectory(&isDirectory))) return rv; - nsXPIDLCString newPathName; + nsCAutoString newPathName; if (isDirectory) { - if (newName) { - if (NS_FAILED(rv = workParent->Append(newName))) + if (!newName.IsEmpty()) { + if (NS_FAILED(rv = workParent->AppendNative(newName))) return rv; } else { - if (NS_FAILED(rv = GetLeafName(getter_Copies(newPathName)))) + if (NS_FAILED(rv = GetNativeLeafName(newPathName))) return rv; - if (NS_FAILED(rv = workParent->Append(newPathName))) + if (NS_FAILED(rv = workParent->AppendNative(newPathName))) return rv; } if (NS_FAILED(rv = CopyDirectoryTo(workParent))) return rv; } else { - rv = GetTargetPathName(workParent, newName, getter_Copies(newPathName)); + rv = GetNativeTargetPathName(workParent, newName, newPathName); if (NS_FAILED(rv)) return rv; @@ -738,7 +721,7 @@ nsLocalFile::CopyTo(nsIFile *newParent, const char *newName) } NS_ADDREF(newFile); - rv = newFile->InitWithPath(newPathName); + rv = newFile->InitWithNativePath(newPathName); if (NS_FAILED(rv)) { NS_RELEASE(newFile); return rv; @@ -840,13 +823,13 @@ nsLocalFile::CopyTo(nsIFile *newParent, const char *newName) } NS_IMETHODIMP -nsLocalFile::CopyToFollowingLinks(nsIFile *newParent, const char *newName) +nsLocalFile::CopyToFollowingLinksNative(nsIFile *newParent, const nsACString &newName) { - return CopyTo(newParent, newName); + return CopyToNative(newParent, newName); } NS_IMETHODIMP -nsLocalFile::MoveTo(nsIFile *newParent, const char *newName) +nsLocalFile::MoveToNative(nsIFile *newParent, const nsACString &newName) { nsresult rv; @@ -854,8 +837,8 @@ nsLocalFile::MoveTo(nsIFile *newParent, const char *newName) CHECK_mPath(); // check to make sure that we have a new parent - nsXPIDLCString newPathName; - rv = GetTargetPathName(newParent, newName, getter_Copies(newPathName)); + nsCAutoString newPathName; + rv = GetNativeTargetPathName(newParent, newName, newPathName); if (NS_FAILED(rv)) return rv; @@ -866,7 +849,7 @@ nsLocalFile::MoveTo(nsIFile *newParent, const char *newName) #else if (errno == EXDEV) { #endif - rv = CopyTo(newParent, newName); + rv = CopyToNative(newParent, newName); if (NS_SUCCEEDED(rv)) rv = Remove(PR_TRUE); } else { @@ -1163,12 +1146,10 @@ nsLocalFile::GetParent(nsIFile **aParent) CHECK_mPath(); NS_ENSURE_ARG_POINTER(aParent); *aParent = nsnull; - PRBool root = PR_FALSE; // I promise to play nice char *buffer = NS_CONST_CAST(char *, mPath.get()), - *slashp = buffer, - *orig = nsCRT::strdup(buffer); + *slashp = buffer; // find the last significant slash in buffer slashp = strrchr(buffer, '/'); @@ -1177,28 +1158,22 @@ nsLocalFile::GetParent(nsIFile **aParent) return NS_ERROR_FILE_INVALID_PATH; // for the case where we are at '/' - if (slashp == buffer) { + if (slashp == buffer) slashp++; - root=PR_TRUE; - } // temporarily terminate buffer at the last significant slash + char c = *slashp; *slashp = '\0'; - nsCOMPtr localFile; - nsresult rv = NS_NewLocalFile(buffer, PR_TRUE, getter_AddRefs(localFile)); - if (root) { - mPath.Adopt(orig); - if (!mPath.get()) - return NS_ERROR_OUT_OF_MEMORY; - } else { - *slashp = '/'; - nsMemory::Free(orig); - } + nsCOMPtr localFile; + nsresult rv = NS_NewNativeLocalFile(nsDependentCString(buffer), PR_TRUE, + getter_AddRefs(localFile)); + + // make buffer whole again + *slashp = c; if (NS_SUCCEEDED(rv) && localFile) - rv = localFile->QueryInterface(NS_GET_IID(nsIFile), (void**)aParent); - + rv = CallQueryInterface(localFile, aParent); return rv; } @@ -1275,11 +1250,9 @@ NS_IMETHODIMP nsLocalFile::IsHidden(PRBool *_retval) { NS_ENSURE_ARG_POINTER(_retval); - nsresult rv; - const char *leafName; - if (NS_FAILED(rv = GetLeafNameRaw(&leafName))) - return rv; - *_retval = (leafName[0] == '.'); + nsACString::const_iterator begin, end; + LocateNativeLeafName(begin, end); + *_retval = (*begin == '.'); return NS_OK; } @@ -1318,14 +1291,12 @@ nsLocalFile::Equals(nsIFile *inFile, PRBool *_retval) *_retval = PR_FALSE; nsresult rv; - nsXPIDLCString myPath, inPath; + nsCAutoString inPath; - if (NS_FAILED(rv = GetPath(getter_Copies(myPath)))) - return rv; - if (NS_FAILED(rv = inFile->GetPath(getter_Copies(inPath)))) + if (NS_FAILED(rv = inFile->GetNativePath(inPath))) return rv; - *_retval = !FILE_STRCMP(inPath.get(), myPath.get()); + *_retval = !FILE_STRCMP(inPath.get(), mPath.get()); return NS_OK; } @@ -1336,19 +1307,19 @@ nsLocalFile::Contains(nsIFile *inFile, PRBool recur, PRBool *_retval) NS_ENSURE_ARG(inFile); NS_ENSURE_ARG_POINTER(_retval); - nsXPIDLCString inPath; + nsCAutoString inPath; nsresult rv; - if (NS_FAILED(rv = inFile->GetPath(getter_Copies(inPath)))) + if (NS_FAILED(rv = inFile->GetNativePath(inPath))) return rv; *_retval = PR_FALSE; - ssize_t len = strlen(mPath.get()); + ssize_t len = mPath.Length(); if (FILE_STRNCMP(mPath.get(), inPath.get(), len) == 0) { // Now make sure that the |inFile|'s path has a separator at len, // which implies that it has more components after len. - if (inPath.get()[len] == '/') + if (inPath[len] == '/') *_retval = PR_TRUE; } @@ -1356,10 +1327,10 @@ nsLocalFile::Contains(nsIFile *inFile, PRBool recur, PRBool *_retval) } NS_IMETHODIMP -nsLocalFile::GetTarget(char **_retval) +nsLocalFile::GetNativeTarget(nsACString &_retval) { CHECK_mPath(); - NS_ENSURE_ARG_POINTER(_retval); + _retval.Truncate(); struct stat symStat; lstat(mPath.get(), &symStat); @@ -1381,7 +1352,6 @@ nsLocalFile::GetTarget(char **_retval) return NSRESULT_FOR_ERRNO(); } target[size] = '\0'; - *_retval = nsnull; nsresult rv; PRBool isSymlink; @@ -1389,37 +1359,39 @@ nsLocalFile::GetTarget(char **_retval) nsCOMPtr parent; while (NS_SUCCEEDED(rv = self->GetParent(getter_AddRefs(parent)))) { NS_ASSERTION(parent != nsnull, "no parent?!"); - NS_ASSERTION(*_retval == nsnull, "leaking *_retval!"); if (target[0] != '/') { nsCOMPtr localFile(do_QueryInterface(parent, &rv)); if (NS_FAILED(rv)) break; - if (NS_FAILED(rv = localFile->AppendRelativePath(target))) + if (NS_FAILED(rv = localFile->AppendRelativeNativePath(nsDependentCString(target)))) break; - if (NS_FAILED(rv = parent->GetPath(_retval))) + if (NS_FAILED(rv = localFile->GetNativePath(_retval))) break; if (NS_FAILED(rv = parent->IsSymlink(&isSymlink))) break; self = parent; } else { nsCOMPtr localFile; - rv = NS_NewLocalFile(target, PR_TRUE, getter_AddRefs(localFile)); + rv = NS_NewNativeLocalFile(nsDependentCString(target), PR_TRUE, + getter_AddRefs(localFile)); if (NS_FAILED(rv)) break; if (NS_FAILED(rv = localFile->IsSymlink(&isSymlink))) break; - *_retval = target; + _retval = target; // XXX can we avoid this buffer copy? self = do_QueryInterface(localFile); } if (NS_FAILED(rv) || !isSymlink) break; + const nsPromiseFlatCString &flatRetval = PromiseFlatCString(_retval); + // strip off any and all trailing '/' PRInt32 len = strlen(target); while (target[len-1] == '/' && len > 1) target[--len] = '\0'; - if (lstat(*_retval, &symStat) < 0) { + if (lstat(flatRetval.get(), &symStat) < 0) { rv = NSRESULT_FOR_ERRNO(); break; } @@ -1428,25 +1400,19 @@ nsLocalFile::GetTarget(char **_retval) break; } size = symStat.st_size; - if (readlink(*_retval, target, size) < 0) { + if (readlink(flatRetval.get(), target, size) < 0) { rv = NSRESULT_FOR_ERRNO(); break; } target[size] = '\0'; - if (*_retval) { - if (*_retval != target) - nsMemory::Free(*_retval); - *_retval = nsnull; - } + _retval.Truncate(); } - if (target != *_retval) - nsMemory::Free(target); - if (NS_FAILED(rv) && *_retval) { - nsMemory::Free(*_retval); - *_retval = nsnull; - } + nsMemory::Free(target); + + if (NS_FAILED(rv)) + _retval.Truncate(); return rv; } @@ -1499,26 +1465,22 @@ nsLocalFile::Load(PRLibrary **_retval) } NS_IMETHODIMP -nsLocalFile::GetPersistentDescriptor(char **aPersistentDescriptor) +nsLocalFile::GetPersistentDescriptor(nsACString &aPersistentDescriptor) { - NS_ENSURE_ARG_POINTER(aPersistentDescriptor); - return GetPath(aPersistentDescriptor); + return GetNativePath(aPersistentDescriptor); } NS_IMETHODIMP -nsLocalFile::SetPersistentDescriptor(const char *aPersistentDescriptor) +nsLocalFile::SetPersistentDescriptor(const nsACString &aPersistentDescriptor) { - NS_ENSURE_ARG(aPersistentDescriptor); - return InitWithPath(aPersistentDescriptor); + return InitWithNativePath(aPersistentDescriptor); } #ifdef XP_BEOS NS_IMETHODIMP nsLocalFile::Reveal() { - nsXPIDLCString path; - GetPath(getter_Copies(path)); - BPath bPath(path); + BPath bPath(mPath.get()); bPath.GetParent(&bPath); entry_ref ref; get_ref_for_path(bPath.Path(),&ref); @@ -1532,11 +1494,8 @@ nsLocalFile::Reveal() NS_IMETHODIMP nsLocalFile::Launch() { - nsXPIDLCString path; - GetPath(getter_Copies(path)); - entry_ref ref; - get_ref_for_path (path, &ref); + get_ref_for_path (mPath.get(), &ref); be_roster->Launch (&ref); return NS_OK; @@ -1556,15 +1515,15 @@ nsLocalFile::Launch() #endif nsresult -NS_NewLocalFile(const char *path, PRBool followSymlinks, nsILocalFile **result) +NS_NewNativeLocalFile(const nsACString &path, PRBool followSymlinks, nsILocalFile **result) { nsLocalFile *file = new nsLocalFile(); if (!file) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(file); - if (path) { - nsresult rv = file->InitWithPath(path); + if (!path.IsEmpty()) { + nsresult rv = file->InitWithNativePath(path); if (NS_FAILED(rv)) { NS_RELEASE(file); return rv; @@ -1573,3 +1532,223 @@ NS_NewLocalFile(const char *path, PRBool followSymlinks, nsILocalFile **result) *result = file; return NS_OK; } + +//----------------------------------------------------------------------------- +// unicode support +//----------------------------------------------------------------------------- + +#define TOLERATE_UCONV_FAILURE 1 + +static int +convert_ucs2_to_native(const PRUnichar *input, char *result, unsigned resultLen) +{ + // this function assumes that |result| is big enough + NS_ASSERTION(resultLen == PATH_MAX, "unexpected resultLen"); +#ifdef HAVE_WCRTOMB + mbstate_t ps = {0}; +#endif + char buf[16], *cursor = result; + int i = 0; + const PRUnichar *p = input; + + NS_ASSERTION(MB_CUR_MAX <= sizeof(buf), "must increase sizeof(buf)"); + + // perform conversion + p = input; + while (*p) { +#ifdef HAVE_WCRTOMB + i = (int) wcrtomb(cursor, (wchar_t) *p, &ps); +#else + // XXX is this thread-safe? + i = (int) wctomb(cursor, (wchar_t) *p); +#endif + if (i < 0) { + NS_WARNING("wctomb failed: possible charset mismatch"); +#ifdef TOLERATE_UCONV_FAILURE + *cursor = (unsigned char) *p; // truncate + i = 1; +#else + return -1; +#endif + } + // most likely we're dead anyways if this assertion should fire + NS_ASSERTION(cursor + i <= result + resultLen, "wrote beyond end of string"); + cursor += i; + if (cursor >= result + resultLen - 1) { + cursor = result + resultLen - 1; // fixup cursor + break; + } + p++; + } + *cursor = '\0'; + return cursor - result; +} + +static int +convert_native_to_ucs2(const char *input, unsigned inputLen, PRUnichar **result) +{ +#ifdef HAVE_MBRTOWC + mbstate_t ps = {0}; +#endif + PRUnichar *p; + int i; + + // allocate space for largest possible result + p = *result = (PRUnichar *) nsMemory::Alloc((inputLen + 1) * sizeof(PRUnichar)); + if (!p) { + NS_ERROR("memory allocation failed"); + return -1; + } + + // cannot use wchar_t here since it may have been redefined (e.g., + // via -fshort-wchar). hopefully, sizeof(tmp) is sufficient XP. + unsigned int tmp = 0; + while (*input) { +#ifdef HAVE_MBRTOWC + i = (int) mbrtowc((wchar_t *) &tmp, input, inputLen, &ps); +#else + // XXX is this thread-safe? + i = (int) mbtowc((wchar_t *) &tmp, input, inputLen); +#endif + if (i < 0) { + NS_WARNING("mbtowc failed: possible charset mismatch"); +#ifdef TOLERATE_UCONV_FAILURE + tmp = (unsigned char) *input; + i = 1; +#else + nsMemory::Free(*result); + *result = nsnull; + return -1; +#endif + } + *p = (PRUnichar) tmp; + input += i; + inputLen -= i; + p++; + } + *p = '\0'; + return p - *result; +} + +#define SET_UCS(func, ucsArg) \ + { \ + char buf[PATH_MAX]; \ + int i = convert_ucs2_to_native(ucsArg, buf, PATH_MAX); \ + if (i == -1) \ + return NS_ERROR_FAILURE; \ + return (func)(nsDependentCString(buf, PRUint32(i))); \ + } + +#define GET_UCS(func, ucsArg) \ + { \ + nsCAutoString buf; \ + nsresult rv = (func)(buf); \ + if (NS_FAILED(rv)) return rv; \ + int i = convert_native_to_ucs2(buf.get(), buf.Length(), ucsArg); \ + if (i == -1) \ + return NS_ERROR_FAILURE; \ + return NS_OK; \ + } + +#define SET_UCS_2ARGS_2(func, opaqueArg, ucsArg) \ + { \ + char buf[PATH_MAX]; \ + int i = convert_ucs2_to_native(ucsArg, buf, PATH_MAX); \ + if (i == -1) \ + return NS_ERROR_FAILURE; \ + return (func)(opaqueArg, nsDependentCString(buf, PRUint32(i))); \ + } + +// Unicode interface Wrapper +nsresult +nsLocalFile::InitWithUnicodePath(const PRUnichar *filePath) +{ + SET_UCS(InitWithNativePath, filePath); +} +nsresult +nsLocalFile::AppendUnicode(const PRUnichar *node) +{ + SET_UCS( AppendNative , node); +} +nsresult +nsLocalFile::AppendRelativeUnicodePath(const PRUnichar *node) +{ + SET_UCS( AppendRelativeNativePath , node); +} +nsresult +nsLocalFile::GetUnicodeLeafName(PRUnichar **aLeafName) +{ + GET_UCS(GetNativeLeafName, aLeafName); +} +nsresult +nsLocalFile::SetUnicodeLeafName(const PRUnichar * aLeafName) +{ + SET_UCS( SetNativeLeafName , aLeafName); +} +nsresult +nsLocalFile::GetUnicodePath(PRUnichar **_retval) +{ + int i = convert_native_to_ucs2(mPath.get(), mPath.Length(), _retval); + if (i == -1) + return NS_ERROR_FAILURE; + return NS_OK; +} +nsresult +nsLocalFile::CopyToUnicode(nsIFile *newParentDir, const PRUnichar *newName) +{ + SET_UCS_2ARGS_2( CopyToNative , newParentDir, newName); +} +nsresult +nsLocalFile::CopyToFollowingLinksUnicode(nsIFile *newParentDir, const PRUnichar *newName) +{ + SET_UCS_2ARGS_2( CopyToFollowingLinksNative , newParentDir, newName); +} +nsresult +nsLocalFile::MoveToUnicode(nsIFile *newParentDir, const PRUnichar *newName) +{ + SET_UCS_2ARGS_2( MoveToNative , newParentDir, newName); +} +nsresult +nsLocalFile::GetUnicodeTarget(PRUnichar **_retval) +{ + GET_UCS(GetNativeTarget, _retval); +} +nsresult +NS_NewUnicodeLocalFile(const PRUnichar* path, PRBool followLinks, nsILocalFile* *result) +{ + char buf[PATH_MAX]; + int i = convert_ucs2_to_native(path, buf, PATH_MAX); + if (i == -1) + return NS_ERROR_FAILURE; + return NS_NewNativeLocalFile(nsDependentCString(buf, PRUint32(i)), followLinks, result); +} + +//----------------------------------------------------------------------------- +// global init/shutdown +//----------------------------------------------------------------------------- + +PRBool +nsLocalFile::FSCharsetIsUTF8() +{ +#if HAVE_NL_LANGINFO && defined(CODESET) + // this result may vary, so we must query nl_langinfo each time. + // fortunately, this amounts to little more than an array lookup (at + // least that's how it's implemented in glibc). + const char *codeset = nl_langinfo(CODESET); + if (!codeset) { + NS_WARNING("cannot get nl_langinfo(CODESET)"); + return PR_FALSE; + } + return (strcmp(codeset, "UTF-8") == 0); +#endif +} + +void +nsLocalFile::GlobalInit() +{ +} + +void +nsLocalFile::GlobalShutdown() +{ +} diff --git a/mozilla/xpcom/io/nsLocalFileUnix.h b/mozilla/xpcom/io/nsLocalFileUnix.h index c5de6cfdc3a..5e4165ec767 100644 --- a/mozilla/xpcom/io/nsLocalFileUnix.h +++ b/mozilla/xpcom/io/nsLocalFileUnix.h @@ -35,10 +35,10 @@ #include #include "nscore.h" -#include "nsIFile.h" #include "nsILocalFile.h" #include "nsLocalFile.h" -#include "nsXPIDLString.h" +#include "nsString.h" +#include "nsReadableUtils.h" /** * we need these for statfs() @@ -113,20 +113,51 @@ public: // nsILocalFile NS_DECL_NSILOCALFILE +public: + static void GlobalInit(); + static void GlobalShutdown(); + static PRBool FSCharsetIsUTF8(); + protected: - PRBool mHaveCachedStat; - struct stat mCachedStat; - nsXPIDLCString mPath; - + struct stat mCachedStat; + nsCString mPath; + PRPackedBool mHaveCachedStat; + PRInt8 mPathIsASCII; // -1 if unknown + PRInt8 mLeafIsASCII; // -1 if unknown + + NS_DECL_NSLOCALFILE_UNICODE_METHODS + + // XXX these results should probably be cached + PRBool PathIsASCII() { + if (mPathIsASCII == -1) + mPathIsASCII = IsASCII(mPath); + return mPathIsASCII; + } + PRBool LeafIsASCII() { + if (mLeafIsASCII == -1) { + nsACString::const_iterator begin, end; + LocateNativeLeafName(begin, end); + mLeafIsASCII = IsASCII(Substring(begin, end)); + } + return mLeafIsASCII; + } + + void LocateNativeLeafName(nsACString::const_iterator &, + nsACString::const_iterator &); + nsresult CopyDirectoryTo(nsIFile *newParent); nsresult CreateAllAncestors(PRUint32 permissions); - nsresult GetLeafNameRaw(const char **_retval); - nsresult GetTargetPathName(nsIFile *newParent, const char *newName, - char **_retval); + nsresult GetNativeTargetPathName(nsIFile *newParent, + const nsACString &newName, + nsACString &_retval); - void InvalidateCache() { mHaveCachedStat = PR_FALSE; } + void InvalidateCache() { + mHaveCachedStat = PR_FALSE; + // not the most optimal place to clear these, but it works... + mPathIsASCII = -1; + mLeafIsASCII = -1; + } nsresult FillStatCache(); - }; #endif /* _nsLocalFileUNIX_H_ */ diff --git a/mozilla/xpcom/io/nsLocalFileWin.cpp b/mozilla/xpcom/io/nsLocalFileWin.cpp index b0bfc8130ed..0dc52c1dd10 100644 --- a/mozilla/xpcom/io/nsLocalFileWin.cpp +++ b/mozilla/xpcom/io/nsLocalFileWin.cpp @@ -27,6 +27,7 @@ #include "nsMemory.h" #include "nsLocalFileWin.h" +#include "nsLocalFileUnicode.h" #include "nsISimpleEnumerator.h" #include "nsIComponentManager.h" @@ -54,6 +55,10 @@ #include "nsAutoLock.h" +//---------------------------------------------------------------------------- +// short cut resolver +//---------------------------------------------------------------------------- + class ShortcutResolver { public: @@ -69,7 +74,6 @@ private: IShellLink* mShellLink; }; - ShortcutResolver::ShortcutResolver() { mLock = nsnull; @@ -77,7 +81,6 @@ ShortcutResolver::ShortcutResolver() mShellLink = nsnull; } - ShortcutResolver::~ShortcutResolver() { if (mLock) @@ -148,7 +151,7 @@ ShortcutResolver::Resolve(const unsigned short* in, char* out) static ShortcutResolver * gResolver = nsnull; -nsresult NS_CreateShortcutResolver() +static nsresult NS_CreateShortcutResolver() { gResolver = new ShortcutResolver(); if (!gResolver) @@ -157,14 +160,17 @@ nsresult NS_CreateShortcutResolver() return gResolver->Init(); } - -void NS_DestroyShortcutResolver() +static void NS_DestroyShortcutResolver() { delete gResolver; gResolver = nsnull; } +//----------------------------------------------------------------------------- +// static helper functions +//----------------------------------------------------------------------------- + // certainly not all the error that can be // encountered, but many of them common ones static nsresult ConvertWinError(DWORD winErr) @@ -245,6 +251,10 @@ myLL_L2II(PRInt64 result, PRInt32 *hi, PRInt32 *lo ) } +//----------------------------------------------------------------------------- +// nsDirEnumerator +//----------------------------------------------------------------------------- + class nsDirEnumerator : public nsISimpleEnumerator { public: @@ -258,25 +268,23 @@ class nsDirEnumerator : public nsISimpleEnumerator nsresult Init(nsILocalFile* parent) { - char* filepath; - parent->GetTarget(&filepath); + nsCAutoString filepath; + parent->GetNativeTarget(filepath); - if (filepath == nsnull) + if (filepath.IsEmpty()) { - parent->GetPath(&filepath); + parent->GetNativePath(filepath); } - if (filepath == nsnull) + if (filepath.IsEmpty()) { - return NS_ERROR_OUT_OF_MEMORY; + return NS_ERROR_UNEXPECTED; } - mDir = PR_OpenDir(filepath); + mDir = PR_OpenDir(filepath.get()); if (mDir == nsnull) // not a directory? return NS_ERROR_FAILURE; - nsMemory::Free(filepath); - mParent = parent; return NS_OK; } @@ -305,13 +313,13 @@ class nsDirEnumerator : public nsISimpleEnumerator if (NS_FAILED(rv)) return rv; - rv = file->Append(entry->name); + rv = file->AppendNative(nsDependentCString(entry->name)); if (NS_FAILED(rv)) return rv; // make sure the thing exists. If it does, try the next one. PRBool exists; - rv = file->Exists(&exists); + rv = file->Exists(&exists); if (NS_FAILED(rv) || !exists) { return HasMoreElements(result); @@ -355,6 +363,10 @@ class nsDirEnumerator : public nsISimpleEnumerator NS_IMPL_ISUPPORTS1(nsDirEnumerator, nsISimpleEnumerator); +//----------------------------------------------------------------------------- +// nsLocalFile +//----------------------------------------------------------------------------- + nsLocalFile::nsLocalFile() { NS_INIT_REFCNT(); @@ -367,9 +379,6 @@ nsLocalFile::~nsLocalFile() { } -/* nsISupports interface implementation. */ -NS_IMPL_THREADSAFE_ISUPPORTS2(nsLocalFile, nsILocalFile, nsIFile) - NS_METHOD nsLocalFile::nsLocalFileConstructor(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr) { @@ -389,6 +398,18 @@ nsLocalFile::nsLocalFileConstructor(nsISupports* outer, const nsIID& aIID, void* return NS_OK; } + +//----------------------------------------------------------------------------- +// nsLocalFile::nsISupports +//----------------------------------------------------------------------------- + +NS_IMPL_THREADSAFE_ISUPPORTS2(nsLocalFile, nsILocalFile, nsIFile) + + +//----------------------------------------------------------------------------- +// nsLocalFile +//----------------------------------------------------------------------------- + // This function resets any cached information about the file. void nsLocalFile::MakeDirty() @@ -396,13 +417,9 @@ nsLocalFile::MakeDirty() mDirty = PR_TRUE; } - -//---------------------------------------------------------------------------------------- -// // ResolvePath // this function will walk the native path of |this| resolving any symbolic // links found. The new resulting path will be placed into mResolvedPath. -//---------------------------------------------------------------------------------------- nsresult nsLocalFile::ResolvePath(const char* workingPath, PRBool resolveTerminal, char** resolvedPath) { @@ -647,6 +664,11 @@ nsLocalFile::ResolveAndStat(PRBool resolveTerminal) return result; } + +//----------------------------------------------------------------------------- +// nsLocalFile::nsIFile,nsILocalFile +//----------------------------------------------------------------------------- + NS_IMETHODIMP nsLocalFile::Clone(nsIFile **file) { @@ -669,51 +691,47 @@ nsLocalFile::Clone(nsIFile **file) } NS_IMETHODIMP -nsLocalFile::InitWithPath(const char *filePath) +nsLocalFile::InitWithNativePath(const nsACString &filePath) { MakeDirty(); - NS_ENSURE_ARG(filePath); - - char* nativeFilePath = nsnull; + nsACString::const_iterator begin, end; + filePath.BeginReading(begin); + filePath.EndReading(end); + + // input string must not be empty + if (begin == end) + return NS_ERROR_FAILURE; + + char firstChar = *begin; + char secondChar = *(++begin); + // just do a sanity check. if it has any forward slashes, it is not a Native path // on windows. Also, it must have a colon at after the first char. - if (filePath[0] == 0) - return NS_ERROR_FAILURE; - - if ( (filePath[2] == 0) && (filePath[1] == ':') ) - { - // C : // - nativeFilePath = (char*) nsMemory::Alloc( 4 ); - if (!nativeFilePath) - return NS_ERROR_OUT_OF_MEMORY; - nativeFilePath[0] = filePath[0]; - nativeFilePath[1] = ':'; - nativeFilePath[2] = '\\'; - nativeFilePath[3] = 0; - } - // XXX is this an 'else'? Otherwise 'nativeFilePath' could leak. - if ( ( (filePath[1] == ':') && (strchr(filePath, '/') == 0) ) || // normal windows path - ( (filePath[0] == '\\') && (filePath[1] == '\\') ) ) // netwerk path + + char *path = nsnull; + PRInt32 pathLen = 0; + + if ( ( (secondChar == ':') && !FindCharInReadable('/', begin, end) ) || // normal path + ( (firstChar == '\\') && (secondChar == '\\') ) ) // network path { // This is a native path - if (nativeFilePath) nsCRT::free(nativeFilePath); - nativeFilePath = (char*) nsMemory::Clone( filePath, strlen(filePath)+1 ); + path = ToNewCString(filePath); + pathLen = filePath.Length(); } - if (nativeFilePath == nsnull) + if (path == nsnull) return NS_ERROR_FILE_UNRECOGNIZED_PATH; - // kill any trailing separator - char* temp = nativeFilePath; - int len = strlen(temp) - 1; - // Is '\' second charactor of DBCS? - if(temp[len] == '\\' && !::IsDBCSLeadByte(temp[len-1])) - temp[len] = '\0'; - - mWorkingPath.Assign(nativeFilePath); - nsMemory::Free( nativeFilePath ); + // kill any trailing '\' provided it isn't the second char of DBCS + PRInt32 len = pathLen - 1; + if (path[len] == '\\' && !::IsDBCSLeadByte(path[len-1])) + { + path[len] = '\0'; + pathLen = len; + } + mWorkingPath.Adopt(path, pathLen); return NS_OK; } @@ -728,17 +746,17 @@ nsLocalFile::OpenNSPRFileDesc(PRInt32 flags, PRInt32 mode, PRFileDesc **_retval) mResolvedPath.Assign(mWorkingPath); *_retval = PR_Open(mResolvedPath.get(), flags, mode); if (*_retval) - { - PRStatus status = PR_GetOpenFileInfo64(*_retval, &mFileInfo64); - NS_ASSERTION( status == PR_SUCCESS, "FileInfo64 invalid while PR_Open succeeded."); - - if (status == PR_SUCCESS) - { - mDirty = PR_FALSE; - mLastResolution = PR_TRUE; - } - return NS_OK; - } + { + PRStatus status = PR_GetOpenFileInfo64(*_retval, &mFileInfo64); + if (status == PR_SUCCESS) + { + mDirty = PR_FALSE; + mLastResolution = PR_TRUE; + } + else + NS_ERROR("FileInfo64 invalid while PR_Open succeeded."); + return NS_OK; + } } nsresult rv = ResolveAndStat(PR_TRUE); @@ -793,14 +811,14 @@ nsLocalFile::Create(PRUint32 type, PRUint32 attributes) while (slash) { *slash = '\0'; - - if (!CreateDirectoryA(mResolvedPath.get(), NULL)) { - rv = ConvertWinError(GetLastError()); - if (rv != NS_ERROR_FILE_ALREADY_EXISTS) return rv; - } - *slash = '\\'; - ++slash; - slash = _mbschr(slash, '\\'); + + if (!CreateDirectoryA(mResolvedPath.get(), NULL)) { + rv = ConvertWinError(GetLastError()); + if (rv != NS_ERROR_FILE_ALREADY_EXISTS) return rv; + } + *slash = '\\'; + ++slash; + slash = _mbschr(slash, '\\'); } } @@ -825,27 +843,30 @@ nsLocalFile::Create(PRUint32 type, PRUint32 attributes) } NS_IMETHODIMP -nsLocalFile::Append(const char *node) +nsLocalFile::AppendNative(const nsACString &node) { // Append only one component. Check for subdirs. - if (!node || (_mbschr((const unsigned char*) node, '\\') != nsnull)) + // XXX can we avoid the PromiseFlatCString call? + if (node.IsEmpty() || (_mbschr((const unsigned char*) PromiseFlatCString(node).get(), '\\') != nsnull)) { return NS_ERROR_FILE_UNRECOGNIZED_PATH; } - return AppendRelativePath(node); + return AppendRelativeNativePath(node); } NS_IMETHODIMP -nsLocalFile::AppendRelativePath(const char *node) +nsLocalFile::AppendRelativeNativePath(const nsACString &node) { // Cannot start with a / or have .. or have / anywhere - if (!node || strchr(node, '/')) + nsACString::const_iterator begin, end; + node.BeginReading(begin); + node.EndReading(end); + if (node.IsEmpty() || FindCharInReadable('/', begin, end)) { return NS_ERROR_FILE_UNRECOGNIZED_PATH; } MakeDirty(); - mWorkingPath.Append("\\"); - mWorkingPath.Append(node); + mWorkingPath.Append(NS_LITERAL_CSTRING("\\") + node); return NS_OK; } @@ -856,9 +877,9 @@ nsLocalFile::Normalize() } NS_IMETHODIMP -nsLocalFile::GetLeafName(char * *aLeafName) +nsLocalFile::GetNativeLeafName(nsACString &aLeafName) { - NS_ENSURE_ARG_POINTER(aLeafName); + aLeafName.Truncate(); const char* temp = mWorkingPath.get(); if(temp == nsnull) @@ -872,12 +893,12 @@ nsLocalFile::GetLeafName(char * *aLeafName) else leaf++; - *aLeafName = (char*) nsMemory::Clone(leaf, strlen(leaf)+1); + aLeafName.Assign(leaf); return NS_OK; } NS_IMETHODIMP -nsLocalFile::SetLeafName(const char * aLeafName) +nsLocalFile::SetNativeLeafName(const nsACString &aLeafName) { MakeDirty(); @@ -898,36 +919,32 @@ nsLocalFile::SetLeafName(const char * aLeafName) NS_IMETHODIMP -nsLocalFile::GetPath(char **_retval) +nsLocalFile::GetNativePath(nsACString &_retval) { - NS_ENSURE_ARG_POINTER(_retval); - *_retval = (char*) nsMemory::Clone(mWorkingPath.get(), mWorkingPath.Length()+1); + _retval = mWorkingPath; return NS_OK; } nsresult -nsLocalFile::CopySingleFile(nsIFile *sourceFile, nsIFile *destParent, const char * newName, PRBool followSymlinks, PRBool move) +nsLocalFile::CopySingleFile(nsIFile *sourceFile, nsIFile *destParent, const nsACString &newName, PRBool followSymlinks, PRBool move) { nsresult rv; - char* filePath; + nsCAutoString filePath; // get the path that we are going to copy to. // Since windows does not know how to auto // resolve shortcust, we must work with the // target. - char* inFilePath; - destParent->GetTarget(&inFilePath); - nsCString destPath(inFilePath); - nsMemory::Free(inFilePath); + nsCAutoString destPath; + destParent->GetNativeTarget(destPath); destPath.Append("\\"); - if (newName == nsnull) + if (newName.IsEmpty()) { - char *aFileName; - sourceFile->GetLeafName(&aFileName); + nsCAutoString aFileName; + sourceFile->GetNativeLeafName(aFileName); destPath.Append(aFileName); - nsMemory::Free(aFileName); } else { @@ -937,13 +954,13 @@ nsLocalFile::CopySingleFile(nsIFile *sourceFile, nsIFile *destParent, const char if (followSymlinks) { - rv = sourceFile->GetTarget(&filePath); - if (!filePath) - rv = sourceFile->GetPath(&filePath); + rv = sourceFile->GetNativeTarget(filePath); + if (filePath.IsEmpty()) + rv = sourceFile->GetNativePath(filePath); } else { - rv = sourceFile->GetPath(&filePath); + rv = sourceFile->GetNativePath(filePath); } if (NS_FAILED(rv)) @@ -952,21 +969,19 @@ nsLocalFile::CopySingleFile(nsIFile *sourceFile, nsIFile *destParent, const char int copyOK; if (!move) - copyOK = CopyFile(filePath, destPath.get(), PR_TRUE); + copyOK = CopyFile(filePath.get(), destPath.get(), PR_TRUE); else - copyOK = MoveFile(filePath, destPath.get()); + copyOK = MoveFile(filePath.get(), destPath.get()); if (!copyOK) // CopyFile and MoveFile returns non-zero if succeeds (backward if you ask me). rv = ConvertWinError(GetLastError()); - - nsMemory::Free(filePath); return rv; } nsresult -nsLocalFile::CopyMove(nsIFile *aParentDir, const char *newName, PRBool followSymlinks, PRBool move) +nsLocalFile::CopyMove(nsIFile *aParentDir, const nsACString &newName, PRBool followSymlinks, PRBool move) { nsCOMPtr newParentDir = aParentDir; // check to see if this exists, otherwise return an error. @@ -981,7 +996,7 @@ nsLocalFile::CopyMove(nsIFile *aParentDir, const char *newName, PRBool followSym { // no parent was specified. We must rename. - if (!newName) + if (newName.IsEmpty()) return NS_ERROR_INVALID_ARG; move = PR_TRUE; @@ -1015,17 +1030,15 @@ nsLocalFile::CopyMove(nsIFile *aParentDir, const char *newName, PRBool followSym newParentDir->IsSymlink(&isLink); if (isLink) { - char* target; - newParentDir->GetTarget(&target); + nsCAutoString target; + newParentDir->GetNativeTarget(target); nsCOMPtr realDest = new nsLocalFile(); if (realDest == nsnull) return NS_ERROR_OUT_OF_MEMORY; - rv = realDest->InitWithPath(target); + rv = realDest->InitWithNativePath(target); - nsMemory::Free(target); - if (NS_FAILED(rv)) return rv; @@ -1061,35 +1074,35 @@ nsLocalFile::CopyMove(nsIFile *aParentDir, const char *newName, PRBool followSym if (NS_FAILED(rv)) return rv; - char *allocatedNewName; - if (!newName) + nsCAutoString allocatedNewName; + if (newName.IsEmpty()) { PRBool isLink; IsSymlink(&isLink); if (isLink) { - char* temp; - GetTarget(&temp); - const char* leaf = (const char*) _mbsrchr((const unsigned char*) temp, '\\'); + nsCAutoString temp; + GetNativeTarget(temp); + const char* leaf = (const char*) _mbsrchr((const unsigned char*) temp.get(), '\\'); if (leaf[0] == '\\') leaf++; - allocatedNewName = (char*) nsMemory::Clone( leaf, strlen(leaf)+1 ); + allocatedNewName = leaf; } else { - GetLeafName(&allocatedNewName);// this should be the leaf name of the + GetNativeLeafName(allocatedNewName);// this should be the leaf name of the } } else { - allocatedNewName = (char*) nsMemory::Clone( newName, strlen(newName)+1 ); + allocatedNewName = newName; } - rv = target->Append(allocatedNewName); + rv = target->AppendNative(allocatedNewName); if (NS_FAILED(rv)) return rv; - nsMemory::Free(allocatedNewName); + allocatedNewName.Truncate(); target->Create(DIRECTORY_TYPE, 0644); // TODO, what permissions should we use if (NS_FAILED(rv)) @@ -1121,14 +1134,14 @@ nsLocalFile::CopyMove(nsIFile *aParentDir, const char *newName, PRBool followSym if (followSymlinks) rv = NS_ERROR_FAILURE; else - rv = file->MoveTo(target, nsnull); + rv = file->MoveToNative(target, nsCString()); } else { if (followSymlinks) - rv = file->CopyToFollowingLinks(target, nsnull); + rv = file->CopyToFollowingLinksNative(target, nsCString()); else - rv = file->CopyTo(target, nsnull); + rv = file->CopyToNative(target, nsCString()); } iterator->HasMoreElements(&more); @@ -1149,48 +1162,44 @@ nsLocalFile::CopyMove(nsIFile *aParentDir, const char *newName, PRBool followSym { MakeDirty(); - char* newParentPath; - newParentDir->GetPath(&newParentPath); + nsCAutoString newParentPath; + newParentDir->GetNativePath(newParentPath); - if (newParentPath == nsnull) + if (newParentPath.IsEmpty()) return NS_ERROR_FAILURE; - if (newName == nsnull) + if (newName.IsEmpty()) { - char *aFileName; - GetLeafName(&aFileName); + nsCAutoString aFileName; + GetNativeLeafName(aFileName); - InitWithPath(newParentPath); - Append(aFileName); - - nsMemory::Free(aFileName); + InitWithNativePath(newParentPath); + AppendNative(aFileName); } else { - InitWithPath(newParentPath); - Append(newName); + InitWithNativePath(newParentPath); + AppendNative(newName); } - - nsMemory::Free(newParentPath); } return NS_OK; } NS_IMETHODIMP -nsLocalFile::CopyTo(nsIFile *newParentDir, const char *newName) +nsLocalFile::CopyToNative(nsIFile *newParentDir, const nsACString &newName) { return CopyMove(newParentDir, newName, PR_FALSE, PR_FALSE); } NS_IMETHODIMP -nsLocalFile::CopyToFollowingLinks(nsIFile *newParentDir, const char *newName) +nsLocalFile::CopyToFollowingLinksNative(nsIFile *newParentDir, const nsACString &newName) { return CopyMove(newParentDir, newName, PR_TRUE, PR_FALSE); } NS_IMETHODIMP -nsLocalFile::MoveTo(nsIFile *newParentDir, const char *newName) +nsLocalFile::MoveToNative(nsIFile *newParentDir, const nsACString &newName) { return CopyMove(newParentDir, newName, PR_FALSE, PR_TRUE); } @@ -1576,7 +1585,7 @@ nsLocalFile::GetParent(nsIFile * *aParent) { NS_ENSURE_ARG_POINTER(aParent); - nsCString parentPath = mWorkingPath; + nsCAutoString parentPath(mWorkingPath); // cannot use nsCString::RFindChar() due to 0x5c problem PRInt32 offset = (PRInt32) (_mbsrchr((const unsigned char *) parentPath.get(), '\\') @@ -1587,11 +1596,11 @@ nsLocalFile::GetParent(nsIFile * *aParent) parentPath.Truncate(offset); nsCOMPtr localFile; - nsresult rv = NS_NewLocalFile(parentPath.get(), mFollowSymlinks, getter_AddRefs(localFile)); + nsresult rv = NS_NewNativeLocalFile(parentPath, mFollowSymlinks, getter_AddRefs(localFile)); if(NS_SUCCEEDED(rv) && localFile) { - return localFile->QueryInterface(NS_GET_IID(nsIFile), (void**)aParent); + return CallQueryInterface(localFile, aParent); } return rv; } @@ -1657,7 +1666,7 @@ nsLocalFile::IsExecutable(PRBool *_retval) if (NS_FAILED(rv)) return rv; - char* path = nsnull; + nsCAutoString path; PRBool symLink; rv = IsSymlink(&symLink); @@ -1665,12 +1674,12 @@ nsLocalFile::IsExecutable(PRBool *_retval) return rv; if (symLink) - GetTarget(&path); + GetNativeTarget(path); else - GetPath(&path); + GetNativePath(path); // Get extension. - char* ext = ::strrchr( path, '.' ); + char* ext = ::strrchr( path.get(), '.' ); if ( ext ) { // Convert extension to lower case. for( char *p = ext; *p; p++ ) { @@ -1699,8 +1708,6 @@ nsLocalFile::IsExecutable(PRBool *_retval) } } - nsMemory::Free(path); - return NS_OK; } @@ -1761,21 +1768,19 @@ nsLocalFile::IsSymlink(PRBool *_retval) NS_ENSURE_ARG(_retval); *_retval = PR_FALSE; - char* path; + nsCAutoString path; int pathLen; - GetPath(&path); - pathLen = strlen(path); + GetNativePath(path); + pathLen = path.Length(); - const char* leaf = path + pathLen - 4; + const char* leaf = path.get() + pathLen - 4; if ( (strcmp(leaf, ".lnk") == 0)) { *_retval = PR_TRUE; } - nsMemory::Free(path); - return NS_OK; } @@ -1803,20 +1808,11 @@ nsLocalFile::Equals(nsIFile *inFile, PRBool *_retval) { NS_ENSURE_ARG(inFile); NS_ENSURE_ARG(_retval); - *_retval = PR_FALSE; - char* inFilePath; - inFile->GetPath(&inFilePath); + nsCAutoString inFilePath; + inFile->GetNativePath(inFilePath); - char* filePath; - GetPath(&filePath); - - if (strcmp(inFilePath, filePath) == 0) - *_retval = PR_TRUE; - - nsMemory::Free(inFilePath); - nsMemory::Free(filePath); - + *_retval = inFilePath.Equals(mWorkingPath); return NS_OK; } @@ -1825,17 +1821,17 @@ nsLocalFile::Contains(nsIFile *inFile, PRBool recur, PRBool *_retval) { *_retval = PR_FALSE; - char* myFilePath; - if ( NS_FAILED(GetTarget(&myFilePath))) - GetPath(&myFilePath); + nsCAutoString myFilePath; + if ( NS_FAILED(GetNativeTarget(myFilePath))) + GetNativePath(myFilePath); - PRInt32 myFilePathLen = strlen(myFilePath); + PRInt32 myFilePathLen = myFilePath.Length(); - char* inFilePath; - if ( NS_FAILED(inFile->GetTarget(&inFilePath))) - inFile->GetPath(&inFilePath); + nsCAutoString inFilePath; + if ( NS_FAILED(inFile->GetNativeTarget(inFilePath))) + inFile->GetNativePath(inFilePath); - if ( strncmp( myFilePath, inFilePath, myFilePathLen) == 0) + if ( strncmp( myFilePath.get(), inFilePath.get(), myFilePathLen) == 0) { // now make sure that the |inFile|'s path has a trailing // separator. @@ -1846,9 +1842,6 @@ nsLocalFile::Contains(nsIFile *inFile, PRBool recur, PRBool *_retval) } } - - nsMemory::Free(inFilePath); - nsMemory::Free(myFilePath); return NS_OK; } @@ -1856,10 +1849,9 @@ nsLocalFile::Contains(nsIFile *inFile, PRBool recur, PRBool *_retval) NS_IMETHODIMP -nsLocalFile::GetTarget(char **_retval) +nsLocalFile::GetNativeTarget(nsACString &_retval) { - NS_ENSURE_ARG(_retval); - *_retval = nsnull; + _retval.Truncate(); #if STRICT_FAKE_SYMLINKS PRBool symLink; @@ -1874,7 +1866,7 @@ nsLocalFile::GetTarget(char **_retval) #endif ResolveAndStat(PR_TRUE); - *_retval = (char*) nsMemory::Clone( mResolvedPath.get(), mResolvedPath.Length()+1 ); + _retval = mResolvedPath; return NS_OK; } @@ -1925,17 +1917,15 @@ nsLocalFile::GetDirectoryEntries(nsISimpleEnumerator * *entries) } NS_IMETHODIMP -nsLocalFile::GetPersistentDescriptor(char * *aPersistentDescriptor) +nsLocalFile::GetPersistentDescriptor(nsACString &aPersistentDescriptor) { - NS_ENSURE_ARG_POINTER(aPersistentDescriptor); - return GetPath(aPersistentDescriptor); + return GetNativePath(aPersistentDescriptor); } NS_IMETHODIMP -nsLocalFile::SetPersistentDescriptor(const char * aPersistentDescriptor) +nsLocalFile::SetPersistentDescriptor(const nsACString &aPersistentDescriptor) { - NS_ENSURE_ARG(aPersistentDescriptor); - return InitWithPath(aPersistentDescriptor); + return InitWithNativePath(aPersistentDescriptor); } NS_IMETHODIMP @@ -1943,13 +1933,13 @@ nsLocalFile::Reveal() { nsresult rv = NS_OK; PRBool isDirectory = PR_FALSE; - nsXPIDLCString path; - nsXPIDLString unicodePath; + nsCAutoString path; + nsCAutoString utf8Path; IsDirectory(&isDirectory); if (isDirectory) { - GetPath(getter_Copies(path)); + GetNativePath(path); } else { @@ -1957,17 +1947,19 @@ nsLocalFile::Reveal() GetParent(getter_AddRefs(parent)); if (parent) { - parent->GetPath(getter_Copies(path)); - parent->GetUnicodePath(getter_Copies(unicodePath)); + parent->GetNativePath(path); + parent->GetPath(utf8Path); } } + NS_ConvertUTF8toUCS2 unicodePath(utf8Path); + // Remember the current fg window. HWND origWin, fgWin; origWin = fgWin = ::GetForegroundWindow(); // use the app registry name to launch a shell execute.... - LONG r = (LONG) ::ShellExecute( NULL, "open", (const char *) path, NULL, NULL, SW_SHOWNORMAL); + LONG r = (LONG) ::ShellExecute( NULL, "open", path.get(), NULL, NULL, SW_SHOWNORMAL); if (r < 32) return NS_ERROR_FAILURE; @@ -2120,17 +2112,15 @@ NS_IMETHODIMP nsLocalFile::Launch() { nsresult rv = NS_OK; - nsXPIDLCString path; - GetPath(getter_Copies(path)); + const nsCString &path = mWorkingPath; // use the app registry name to launch a shell execute.... - LONG r = (LONG) ::ShellExecute( NULL, NULL, (const char *) path, NULL, NULL, SW_SHOWNORMAL); + LONG r = (LONG) ::ShellExecute( NULL, NULL, path.get(), NULL, NULL, SW_SHOWNORMAL); // if the file has no association, we launch windows' "what do you want to do" dialog if (r == SE_ERR_NOASSOC) { nsCAutoString shellArg; - shellArg.Assign(NS_LITERAL_CSTRING("shell32.dll,OpenAs_RunDLL ")); - shellArg.Append(path); + shellArg.Assign(NS_LITERAL_CSTRING("shell32.dll,OpenAs_RunDLL ") + path); r = (LONG) ::ShellExecute(NULL, NULL, "RUNDLL32.EXE", shellArg.get(), NULL, SW_SHOWNORMAL); } @@ -2143,7 +2133,7 @@ nsLocalFile::Launch() } nsresult -NS_NewLocalFile(const char* path, PRBool followLinks, nsILocalFile* *result) +NS_NewNativeLocalFile(const nsACString &path, PRBool followLinks, nsILocalFile* *result) { nsLocalFile* file = new nsLocalFile(); if (file == nsnull) @@ -2152,8 +2142,8 @@ NS_NewLocalFile(const char* path, PRBool followLinks, nsILocalFile* *result) file->SetFollowLinks(followLinks); - if (path) { - nsresult rv = file->InitWithPath(path); + if (!path.IsEmpty()) { + nsresult rv = file->InitWithNativePath(path); if (NS_FAILED(rv)) { NS_RELEASE(file); return rv; @@ -2164,6 +2154,10 @@ NS_NewLocalFile(const char* path, PRBool followLinks, nsILocalFile* *result) return NS_OK; } +//----------------------------------------------------------------------------- +// UCS2 interface +//----------------------------------------------------------------------------- + static nsresult UCS2toFS(const PRUnichar *aBuffer, char **aResult) { NS_ENSURE_ARG_POINTER(aBuffer); @@ -2214,121 +2208,115 @@ static nsresult FStoUCS2(const char* aBuffer, PRUnichar **aResult) return NS_OK; } -// Unicode interface Wrapper -NS_IMETHODIMP +nsresult nsLocalFile::InitWithUnicodePath(const PRUnichar *filePath) { nsXPIDLCString tmp; nsresult rv = UCS2toFS(filePath, getter_Copies(tmp)); if (NS_SUCCEEDED(rv)) - return InitWithPath(tmp); + return InitWithNativePath(tmp); return rv; } -NS_IMETHODIMP +nsresult nsLocalFile::AppendUnicode(const PRUnichar *node) { nsXPIDLCString tmp; nsresult rv = UCS2toFS(node, getter_Copies(tmp)); if (NS_SUCCEEDED(rv)) - return Append(tmp); + return AppendNative(tmp); return rv; } - -NS_IMETHODIMP +nsresult nsLocalFile::AppendRelativeUnicodePath(const PRUnichar *node) { nsXPIDLCString tmp; nsresult rv = UCS2toFS(node, getter_Copies(tmp)); if (NS_SUCCEEDED(rv)) - return AppendRelativePath(tmp); + return AppendRelativeNativePath(tmp); return rv; } -NS_IMETHODIMP +nsresult nsLocalFile::GetUnicodeLeafName(PRUnichar **aLeafName) { - nsXPIDLCString tmp; - nsresult rv = GetLeafName(getter_Copies(tmp)); + nsCAutoString tmp; + nsresult rv = GetNativeLeafName(tmp); if (NS_SUCCEEDED(rv)) - return FStoUCS2(tmp, aLeafName); + return FStoUCS2(tmp.get(), aLeafName); return rv; } -NS_IMETHODIMP +nsresult nsLocalFile::SetUnicodeLeafName(const PRUnichar * aLeafName) { nsXPIDLCString tmp; nsresult rv = UCS2toFS(aLeafName, getter_Copies(tmp)); if (NS_SUCCEEDED(rv)) - return SetLeafName(tmp); + return SetNativeLeafName(tmp); return rv; } -NS_IMETHODIMP +nsresult nsLocalFile::GetUnicodePath(PRUnichar **_retval) { - nsXPIDLCString tmp; - nsresult rv = GetPath(getter_Copies(tmp)); - if (NS_SUCCEEDED(rv)) - return FStoUCS2(tmp, _retval); - - return rv; + return FStoUCS2(mWorkingPath.get(), _retval); } -NS_IMETHODIMP +nsresult nsLocalFile::CopyToUnicode(nsIFile *newParentDir, const PRUnichar *newName) { if (!newName) - return CopyTo(newParentDir, nsnull); + return CopyToNative(newParentDir, nsCString()); nsXPIDLCString tmp; nsresult rv = UCS2toFS(newName, getter_Copies(tmp)); if (NS_SUCCEEDED(rv)) - return CopyTo(newParentDir, tmp); + return CopyToNative(newParentDir, tmp); return rv; } -NS_IMETHODIMP +nsresult nsLocalFile::CopyToFollowingLinksUnicode(nsIFile *newParentDir, const PRUnichar *newName) { - if (!newName) return CopyToFollowingLinks(newParentDir, nsnull); + if (!newName) + return CopyToFollowingLinksNative(newParentDir, nsCString()); nsXPIDLCString tmp; nsresult rv = UCS2toFS(newName, getter_Copies(tmp)); if (NS_SUCCEEDED(rv)) - return CopyToFollowingLinks(newParentDir, tmp); + return CopyToFollowingLinksNative(newParentDir, tmp); return rv; } -NS_IMETHODIMP +nsresult nsLocalFile::MoveToUnicode(nsIFile *newParentDir, const PRUnichar *newName) { if (!newName) - return MoveTo(newParentDir, nsnull); + return MoveToNative(newParentDir, nsCString()); nsXPIDLCString tmp; nsresult rv = UCS2toFS(newName, getter_Copies(tmp)); if (NS_SUCCEEDED(rv)) - return MoveTo(newParentDir, tmp); + return MoveToNative(newParentDir, tmp); return rv; } -NS_IMETHODIMP +nsresult nsLocalFile::GetUnicodeTarget(PRUnichar **_retval) { - nsXPIDLCString tmp; - nsresult rv = GetTarget(getter_Copies(tmp)); + nsCAutoString tmp; + nsresult rv = GetNativeTarget(tmp); if (NS_SUCCEEDED(rv)) - return FStoUCS2(tmp, _retval); + return FStoUCS2(tmp.get(), _retval); return rv; } @@ -2339,13 +2327,28 @@ NS_NewUnicodeLocalFile(const PRUnichar* path, PRBool followLinks, nsILocalFile* nsXPIDLCString tmp; nsresult rv = UCS2toFS(path, getter_Copies(tmp)); if (NS_SUCCEEDED(rv)) - return NS_NewLocalFile(tmp, followLinks, result); + return NS_NewNativeLocalFile(tmp, followLinks, result); return NS_OK; } -// stub this out - windows maintains no state here -void NS_ShutdownLocalFileUnicode() {} +//----------------------------------------------------------------------------- +// nsLocalFile +//----------------------------------------------------------------------------- +PRBool nsLocalFile::mFSCharsetIsUTF8 = PR_FALSE; +void +nsLocalFile::GlobalInit() +{ + nsresult rv = NS_CreateShortcutResolver(); + NS_ASSERTION(NS_SUCCEEDED(rv), "Shortcut resolver could not be created"); + // XXX determine value of mFSCharsetIsUTF8 +} + +void +nsLocalFile::GlobalShutdown() +{ + NS_DestroyShortcutResolver(); +} diff --git a/mozilla/xpcom/io/nsLocalFileWin.h b/mozilla/xpcom/io/nsLocalFileWin.h index d2fb610e605..8650f3c5161 100644 --- a/mozilla/xpcom/io/nsLocalFileWin.h +++ b/mozilla/xpcom/io/nsLocalFileWin.h @@ -65,6 +65,11 @@ public: // nsILocalFile interface NS_DECL_NSILOCALFILE +public: + static void GlobalInit(); + static void GlobalShutdown(); + static PRBool FSCharsetIsUTF8() { return mFSCharsetIsUTF8; } + private: // this is the flag which indicates if I can used cached information about the file @@ -79,21 +84,24 @@ private: // this will be the resolve path which will *NEVER* be return to the user nsCString mResolvedPath; - PRFileInfo64 mFileInfo64; + PRFileInfo64 mFileInfo64; + + static PRBool mFSCharsetIsUTF8; + + NS_DECL_NSLOCALFILE_UNICODE_METHODS + + // XXX impl + PRBool PathIsASCII() { return PR_FALSE; } + PRBool LeafIsASCII() { return PR_FALSE; } void MakeDirty(); nsresult ResolveAndStat(PRBool resolveTerminal); nsresult ResolvePath(const char* workingPath, PRBool resolveTerminal, char** resolvedPath); - nsresult CopyMove(nsIFile *newParentDir, const char *newName, PRBool followSymlinks, PRBool move); - nsresult CopySingleFile(nsIFile *source, nsIFile* dest, const char * newName, PRBool followSymlinks, PRBool move); + nsresult CopyMove(nsIFile *newParentDir, const nsACString &newName, PRBool followSymlinks, PRBool move); + nsresult CopySingleFile(nsIFile *source, nsIFile* dest, const nsACString &newName, PRBool followSymlinks, PRBool move); nsresult SetModDate(PRInt64 aLastModifiedTime, PRBool resolveTerminal); - }; - -extern nsresult NS_CreateShortcutResolver(); -extern void NS_DestroyShortcutResolver(); - #endif diff --git a/mozilla/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp b/mozilla/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp index 55660699098..e01dc35dc82 100644 --- a/mozilla/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp +++ b/mozilla/xpcom/reflect/xptinfo/src/xptiInterfaceInfoManager.cpp @@ -40,6 +40,8 @@ /* Implementation of xptiInterfaceInfoManager. */ #include "xptiprivate.h" +#include "nsDependentString.h" +#include "nsString.h" #define NS_ZIPLOADER_CONTRACTID NS_XPTLOADER_CONTRACTID_PREFIX "zip" @@ -127,7 +129,7 @@ xptiInterfaceInfoManager::xptiInterfaceInfoManager(nsISupportsArray* aSearchPath { mStatsLogFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID); if(mStatsLogFile && - NS_SUCCEEDED(mStatsLogFile->InitWithPath(statsFilename))) + NS_SUCCEEDED(mStatsLogFile->InitWithNativePath(nsDependentCString(statsFilename)))) { printf("* Logging xptinfo stats to: %s\n", statsFilename); } @@ -143,7 +145,7 @@ xptiInterfaceInfoManager::xptiInterfaceInfoManager(nsISupportsArray* aSearchPath { mAutoRegLogFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID); if(mAutoRegLogFile && - NS_SUCCEEDED(mAutoRegLogFile->InitWithPath(autoRegFilename))) + NS_SUCCEEDED(mAutoRegLogFile->InitWithNativePath(nsDependentCString(autoRegFilename)))) { printf("* Logging xptinfo autoreg to: %s\n", autoRegFilename); } @@ -214,6 +216,7 @@ AppendFromDirServiceList(const char* codename, nsISupportsArray* aPath) if(!dir || !aPath->AppendElement(dir)) return PR_FALSE; } + return PR_TRUE; } @@ -328,11 +331,11 @@ xptiInterfaceInfoManager::BuildFileList(nsISupportsArray* aSearchPath, continue; } - nsXPIDLCString name; - if(NS_FAILED(file->GetLeafName(getter_Copies(name)))) + nsCAutoString name; + if(NS_FAILED(file->GetLeafName(name))) return PR_FALSE; - if(xptiFileType::IsUnknown(name)) + if(xptiFileType::IsUnknown(name.get())) continue; LOG_AUTOREG(("found file: %s\n", name.get())); @@ -428,7 +431,7 @@ xptiInterfaceInfoManager::LoadFile(const xptiTypelib& aTypelibRecord, getter_AddRefs(file))) || !file) return PR_FALSE; - if(NS_FAILED(file->Append(fileRecord->GetName()))) + if(NS_FAILED(file->Append(nsDependentCString(fileRecord->GetName())))) return PR_FALSE; XPTHeader* header; @@ -622,27 +625,27 @@ xptiSortFileList(const void * p1, const void *p2, void * closure) nsILocalFile* pFile2 = *((nsILocalFile**) p2); SortData* data = (SortData*) closure; - nsXPIDLCString name1; - nsXPIDLCString name2; + nsCAutoString name1; + nsCAutoString name2; - if(NS_FAILED(pFile1->GetLeafName(getter_Copies(name1)))) + if(NS_FAILED(pFile1->GetLeafName(name1))) { NS_ERROR("way bad, with no happy out!"); return 0; } - if(NS_FAILED(pFile2->GetLeafName(getter_Copies(name2)))) + if(NS_FAILED(pFile2->GetLeafName(name2))) { NS_ERROR("way bad, with no happy out!"); return 0; } - int index1 = IndexOfFileWithName(name1, data->mWorkingSet); - int index2 = IndexOfFileWithName(name2, data->mWorkingSet); + int index1 = IndexOfFileWithName(name1.get(), data->mWorkingSet); + int index2 = IndexOfFileWithName(name2.get(), data->mWorkingSet); // Get these now in case we need them later. - PRBool isXPT1 = xptiFileType::IsXPT(name1); - PRBool isXPT2 = xptiFileType::IsXPT(name2); - int nameOrder = PL_strcmp(name1, name2); + PRBool isXPT1 = xptiFileType::IsXPT(name1.get()); + PRBool isXPT2 = xptiFileType::IsXPT(name2.get()); + int nameOrder = Compare(name1, name2); // both in workingSet, preserve old order if(index1 != -1 && index2 != -1) @@ -784,12 +787,12 @@ xptiInterfaceInfoManager::DetermineAutoRegStrategy(nsISupportsArray* aSearchPath PRInt64 size; PRInt64 date; - nsXPIDLCString name; + nsCAutoString name; PRUint32 directory; if(NS_FAILED(file->GetFileSize(&size)) || NS_FAILED(file->GetLastModifiedTime(&date)) || - NS_FAILED(file->GetLeafName(getter_Copies(name))) || + NS_FAILED(file->GetLeafName(name)) || !aWorkingSet->FindDirectoryOfFile(file, &directory)) { NS_ERROR("unexpected!"); @@ -801,7 +804,7 @@ xptiInterfaceInfoManager::DetermineAutoRegStrategy(nsISupportsArray* aSearchPath xptiFile& target = aWorkingSet->GetFileAt(k); if(directory == target.GetDirectory() && - 0 == PL_strcmp(name, target.GetName())) + name.Equals(target.GetName())) { if(nsInt64(size) != target.GetSize() || nsInt64(date) != target.GetDate()) @@ -833,18 +836,18 @@ xptiInterfaceInfoManager::DetermineAutoRegStrategy(nsISupportsArray* aSearchPath aFileList->QueryElementAt(k, NS_GET_IID(nsILocalFile), getter_AddRefs(file)); NS_ASSERTION(file, "loser!"); - nsXPIDLCString name; + nsCAutoString name; PRInt64 size; PRInt64 date; if(NS_FAILED(file->GetFileSize(&size)) || NS_FAILED(file->GetLastModifiedTime(&date)) || - NS_FAILED(file->GetLeafName(getter_Copies(name)))) + NS_FAILED(file->GetLeafName(name))) { NS_ERROR("unexpected!"); return FULL_VALIDATION_REQUIRED; } - PRBool sameName = (0 == PL_strcmp(name, target.GetName())); + PRBool sameName = name.Equals(target.GetName()); if(sameName) { if(nsInt64(size) != target.GetSize() || @@ -900,20 +903,20 @@ xptiInterfaceInfoManager::AddOnlyNewFilesFromFileList(nsISupportsArray* aSearchP { nsILocalFile* file = orderedFileArray[i]; - nsXPIDLCString name; + nsCAutoString name; PRInt64 size; PRInt64 date; PRUint32 dir; if(NS_FAILED(file->GetFileSize(&size)) || NS_FAILED(file->GetLastModifiedTime(&date)) || - NS_FAILED(file->GetLeafName(getter_Copies(name))) || + NS_FAILED(file->GetLeafName(name)) || !aWorkingSet->FindDirectoryOfFile(file, &dir)) { return PR_FALSE; } - if(xptiWorkingSet::NOT_FOUND != aWorkingSet->FindFile(dir, name)) + if(xptiWorkingSet::NOT_FOUND != aWorkingSet->FindFile(dir, name.get())) { // This file was found in the working set, so skip it. continue; @@ -923,7 +926,7 @@ xptiInterfaceInfoManager::AddOnlyNewFilesFromFileList(nsISupportsArray* aSearchP xptiFile fileRecord; fileRecord = xptiFile(nsInt64(size), nsInt64(date), dir, - name, aWorkingSet); + name.get(), aWorkingSet); if(xptiFileType::IsXPT(fileRecord.GetName())) { @@ -1050,13 +1053,13 @@ xptiInterfaceInfoManager::DoFullValidationMergeFromFileList(nsISupportsArray* aS { nsILocalFile* file = orderedFileArray[i]; - nsXPIDLCString name; + nsCAutoString name; PRInt64 size; PRInt64 date; PRUint32 dir; if(NS_FAILED(file->GetFileSize(&size)) || NS_FAILED(file->GetLastModifiedTime(&date)) || - NS_FAILED(file->GetLeafName(getter_Copies(name))) || + NS_FAILED(file->GetLeafName(name)) || !aWorkingSet->FindDirectoryOfFile(file, &dir)) { return PR_FALSE; @@ -1066,7 +1069,7 @@ xptiInterfaceInfoManager::DoFullValidationMergeFromFileList(nsISupportsArray* aS xptiFile fileRecord; fileRecord = xptiFile(nsInt64(size), nsInt64(date), dir, - name, aWorkingSet); + name.get(), aWorkingSet); // printf("* found %s\n", fileRecord.GetName()); @@ -1541,8 +1544,8 @@ xptiInterfaceInfoManager::DEBUG_DumpFileList(nsISupportsArray* aFileList) if(!file) return PR_FALSE; - nsXPIDLCString name; - if(NS_FAILED(file->GetLeafName(getter_Copies(name)))) + nsCAutoString name; + if(NS_FAILED(file->GetLeafName(name))) return PR_FALSE; printf("* found %s\n", name.get()); @@ -1571,8 +1574,8 @@ xptiInterfaceInfoManager::DEBUG_DumpFileArray(nsILocalFile** aFileArray, { nsILocalFile* file = aFileArray[i]; - nsXPIDLCString name; - if(NS_FAILED(file->GetLeafName(getter_Copies(name)))) + nsCAutoString name; + if(NS_FAILED(file->GetLeafName(name))) return PR_FALSE; printf("found file: %s\n", name.get()); diff --git a/mozilla/xpcom/reflect/xptinfo/src/xptiManifest.cpp b/mozilla/xpcom/reflect/xptinfo/src/xptiManifest.cpp index f69c9b9877c..92c40c13818 100644 --- a/mozilla/xpcom/reflect/xptinfo/src/xptiManifest.cpp +++ b/mozilla/xpcom/reflect/xptinfo/src/xptiManifest.cpp @@ -40,10 +40,11 @@ /* Implementation of xptiManifest. */ #include "xptiprivate.h" +#include "nsString.h" -static const char g_MainManifestFilename[] = "xpti.dat"; -static const char g_TempManifestFilename[] = "xptitemp.dat"; +#define g_MainManifestFilename NS_LITERAL_CSTRING("xpti.dat") +#define g_TempManifestFilename NS_LITERAL_CSTRING("xptitemp.dat") static const char g_Disclaimer[] = "# Generated file. ** DO NOT EDIT! **"; @@ -61,7 +62,7 @@ static const int g_VERSION_MINOR = 0; /***************************************************************************/ static PRBool -GetCurrentAppDirString(xptiInterfaceInfoManager* aMgr, char** aStr) +GetCurrentAppDirString(xptiInterfaceInfoManager* aMgr, nsACString &aStr) { nsCOMPtr appDir; aMgr->GetApplicationDir(getter_AddRefs(appDir)); @@ -72,17 +73,17 @@ GetCurrentAppDirString(xptiInterfaceInfoManager* aMgr, char** aStr) static PRBool CurrentAppDirMatchesPersistentDescriptor(xptiInterfaceInfoManager* aMgr, - const char* inStr) + const char *inStr) { nsCOMPtr appDir; aMgr->GetApplicationDir(getter_AddRefs(appDir)); nsCOMPtr descDir; - nsresult rv = NS_NewLocalFile(nsnull, PR_FALSE, getter_AddRefs(descDir)); + nsresult rv = NS_NewLocalFile(nsCString(), PR_FALSE, getter_AddRefs(descDir)); if(NS_FAILED(rv)) return PR_FALSE; - rv = descDir->SetPersistentDescriptor(inStr); + rv = descDir->SetPersistentDescriptor(nsDependentCString(inStr)); if(NS_FAILED(rv)) return PR_FALSE; @@ -129,7 +130,7 @@ PRBool xptiManifest::Write(xptiInterfaceInfoManager* aMgr, PRUint32 i; PRUint32 size32; PRIntn interfaceCount = 0; - nsXPIDLCString appDirString; + nsCAutoString appDirString; nsCOMPtr tempFile; if(!aMgr->GetCloneOfManifestDir(getter_AddRefs(tempFile)) || !tempFile) @@ -161,8 +162,8 @@ PRBool xptiManifest::Write(xptiInterfaceInfoManager* aMgr, 0, g_TOKEN_Version, g_VERSION_MAJOR, g_VERSION_MINOR)) goto out; - GetCurrentAppDirString(aMgr, getter_Copies(appDirString)); - if(!appDirString) + GetCurrentAppDirString(aMgr, appDirString); + if(appDirString.IsEmpty()) goto out; if(!PR_fprintf(fd, "%d,%s,%s\n", @@ -179,14 +180,14 @@ PRBool xptiManifest::Write(xptiInterfaceInfoManager* aMgr, for(i = 0; i < aWorkingSet->GetDirectoryCount(); i++) { nsCOMPtr dir; - nsXPIDLCString str; + nsCAutoString str; aWorkingSet->GetDirectoryAt(i, getter_AddRefs(dir)); if(!dir) goto out; - dir->GetPersistentDescriptor(getter_Copies(str)); - if(!str) + dir->GetPersistentDescriptor(str); + if(str.IsEmpty()) goto out; if(!PR_fprintf(fd, "%d,%s\n", (int) i, str.get())) @@ -303,8 +304,8 @@ ReadManifestIntoMemory(xptiInterfaceInfoManager* aMgr, { static PRBool shown = PR_FALSE; - nsXPIDLCString path; - if(!shown && NS_SUCCEEDED(aFile->GetPath(getter_Copies(path))) && path) + nsCAutoString path; + if(!shown && NS_SUCCEEDED(aFile->GetPath(path)) && !path.IsEmpty()) { printf("Type Manifest File: %s\n", path.get()); shown = PR_TRUE; diff --git a/mozilla/xpcom/reflect/xptinfo/src/xptiWorkingSet.cpp b/mozilla/xpcom/reflect/xptinfo/src/xptiWorkingSet.cpp index 9d8ff78676d..25bb36bc56a 100644 --- a/mozilla/xpcom/reflect/xptinfo/src/xptiWorkingSet.cpp +++ b/mozilla/xpcom/reflect/xptinfo/src/xptiWorkingSet.cpp @@ -40,6 +40,7 @@ /* Implementation of xptiWorkingSet. */ #include "xptiprivate.h" +#include "nsString.h" #define XPTI_STRING_ARENA_BLOCK_SIZE (1024 * 1) #define XPTI_STRUCT_ARENA_BLOCK_SIZE (1024 * 1) @@ -416,11 +417,11 @@ PRBool xptiWorkingSet::DirectoryAtMatchesPersistentDescriptor(PRUint32 i, return PR_FALSE; nsCOMPtr descDir; - nsresult rv = NS_NewLocalFile(nsnull, PR_FALSE, getter_AddRefs(descDir)); + nsresult rv = NS_NewLocalFile(nsCString(), PR_FALSE, getter_AddRefs(descDir)); if(NS_FAILED(rv)) return PR_FALSE; - rv = descDir->SetPersistentDescriptor(inDesc); + rv = descDir->SetPersistentDescriptor(nsDependentCString(inDesc)); if(NS_FAILED(rv)) return PR_FALSE; diff --git a/mozilla/xpcom/reflect/xptinfo/src/xptiprivate.h b/mozilla/xpcom/reflect/xptinfo/src/xptiprivate.h index b8cb7a7a104..d8e89603b23 100644 --- a/mozilla/xpcom/reflect/xptinfo/src/xptiprivate.h +++ b/mozilla/xpcom/reflect/xptinfo/src/xptiprivate.h @@ -56,7 +56,6 @@ #include "nsIXPTLoader.h" #include "nsIServiceManager.h" -#include "nsIFile.h" #include "nsILocalFile.h" #include "nsIDirectoryService.h" #include "nsDirectoryServiceDefs.h" @@ -956,17 +955,17 @@ private: static PRBool BuildFileSearchPath(nsISupportsArray** aPath); private: - xptiWorkingSet mWorkingSet; - nsCOMPtr mStatsLogFile; - nsCOMPtr mAutoRegLogFile; - PRFileDesc* mOpenLogFile; - PRLock* mResolveLock; - PRLock* mAutoRegLock; - PRMonitor* mInfoMonitor; - PRLock* mAdditionalManagersLock; - nsSupportsArray mAdditionalManagers; - nsCOMPtr mManifestDir; - nsCOMPtr mSearchPath; + xptiWorkingSet mWorkingSet; + nsCOMPtr mStatsLogFile; + nsCOMPtr mAutoRegLogFile; + PRFileDesc* mOpenLogFile; + PRLock* mResolveLock; + PRLock* mAutoRegLock; + PRMonitor* mInfoMonitor; + PRLock* mAdditionalManagersLock; + nsSupportsArray mAdditionalManagers; + nsCOMPtr mManifestDir; + nsCOMPtr mSearchPath; }; /***************************************************************************/ diff --git a/mozilla/xpcom/tests/nsIFileEnumerator.cpp b/mozilla/xpcom/tests/nsIFileEnumerator.cpp index 5f66d739990..afc2d32f094 100644 --- a/mozilla/xpcom/tests/nsIFileEnumerator.cpp +++ b/mozilla/xpcom/tests/nsIFileEnumerator.cpp @@ -1,4 +1,6 @@ #include "nsILocalFile.h" +#include "nsDependentString.h" +#include "nsString.h" #include #include "nsIComponentRegistrar.h" @@ -26,16 +28,16 @@ PRBool LoopInDir(nsILocalFile* file) if(!sup) return PR_FALSE; - nsCOMPtr file = do_QueryInterface(sup); + nsCOMPtr file = do_QueryInterface(sup); if(!file) return PR_FALSE; - char* name; - if(NS_FAILED(file->GetLeafName(&name))) + nsCAutoString name; + if(NS_FAILED(file->GetNativeLeafName(name))) return PR_FALSE; PRBool isDir; - printf("%s\n", name); + printf("%s\n", name.get()); rv = file->IsDirectory(&isDir); if (NS_FAILED(rv)) { @@ -48,8 +50,6 @@ PRBool LoopInDir(nsILocalFile* file) nsCOMPtr lfile = do_QueryInterface(file); LoopInDir(lfile); } - - nsMemory::Free(name); } return PR_TRUE; } @@ -71,7 +71,7 @@ main(int argc, char* argv[]) if (argc > 1 && argv[1] != nsnull) { char* pathStr = argv[1]; - NS_NewLocalFile(pathStr, PR_FALSE, getter_AddRefs(topDir)); + NS_NewNativeLocalFile(nsDependentCString(pathStr), PR_FALSE, getter_AddRefs(topDir)); } if (!topDir) diff --git a/mozilla/xpcom/tests/nsIFileTest.cpp b/mozilla/xpcom/tests/nsIFileTest.cpp index e7e92353e17..6706ba2a761 100644 --- a/mozilla/xpcom/tests/nsIFileTest.cpp +++ b/mozilla/xpcom/tests/nsIFileTest.cpp @@ -1,4 +1,5 @@ #include "nsILocalFile.h" +#include "nsString.h" #include #include "nsXPCOM.h" @@ -55,14 +56,14 @@ void Inspect() void GetPaths(nsILocalFile* file) { nsresult rv; - nsXPIDLCString pathName; + nsCAutoString pathName; printf("Getting Path\n"); - rv = file->GetPath(getter_Copies(pathName)); + rv = file->GetNativePath(pathName); VerifyResult(rv); - printf("filepath: %s\n", (const char *)pathName); + printf("filepath: %s\n", pathName.get()); } void InitTest(const char* creationPath, const char* appendPath) @@ -79,26 +80,26 @@ void InitTest(const char* creationPath, const char* appendPath) return; } - nsXPIDLCString leafName; + nsCAutoString leafName; Banner("InitWithPath"); printf("creationPath == %s\nappendPath == %s\n", creationPath, appendPath); - rv = file->InitWithPath(creationPath); + rv = file->InitWithNativePath(nsDependentCString(creationPath)); VerifyResult(rv); printf("Getting Filename\n"); - rv = file->GetLeafName(getter_Copies(leafName)); - printf(" %s\n", (const char *)leafName); + rv = file->GetNativeLeafName(leafName); + printf(" %s\n", leafName.get()); VerifyResult(rv); printf("Appending %s \n", appendPath); - rv = file->Append(appendPath); + rv = file->AppendNative(nsDependentCString(appendPath)); VerifyResult(rv); printf("Getting Filename\n"); - rv = file->GetLeafName(getter_Copies(leafName)); - printf(" %s\n", (const char *)leafName); + rv = file->GetNativeLeafName(leafName); + printf(" %s\n", leafName.get()); VerifyResult(rv); GetPaths(file); @@ -135,11 +136,11 @@ void CreationTest(const char* creationPath, const char* appendPath, Banner("Creation Test"); printf("creationPath == %s\nappendPath == %s\n", creationPath, appendPath); - rv = file->InitWithPath(creationPath); + rv = file->InitWithNativePath(nsDependentCString(creationPath)); VerifyResult(rv); printf("Appending %s\n", appendPath); - rv = file->AppendRelativePath(appendPath); + rv = file->AppendRelativeNativePath(nsDependentCString(appendPath)); VerifyResult(rv); printf("Check For Existence\n"); @@ -187,11 +188,11 @@ void CreateUniqueTest(const char* creationPath, const char* appendPath, Banner("Creation Test"); printf("creationPath == %s\nappendPath == %s\n", creationPath, appendPath); - rv = file->InitWithPath(creationPath); + rv = file->InitWithNativePath(nsDependentCString(creationPath)); VerifyResult(rv); printf("Appending %s\n", appendPath); - rv = file->Append(appendPath); + rv = file->AppendNative(nsDependentCString(appendPath)); VerifyResult(rv); printf("Check For Existence\n"); @@ -240,7 +241,7 @@ CopyTest(const char *testFile, const char *targetDir) return; } - rv = file->InitWithPath(testFile); + rv = file->InitWithNativePath(nsDependentCString(testFile)); VerifyResult(rv); rv = nsComponentManager::CreateInstance(NS_LOCAL_FILE_CONTRACTID, NULL, @@ -253,10 +254,10 @@ CopyTest(const char *testFile, const char *targetDir) return; } - rv = dir->InitWithPath(targetDir); + rv = dir->InitWithNativePath(nsDependentCString(targetDir)); VerifyResult(rv); - rv = file->CopyTo(dir, NULL); + rv = file->CopyTo(dir, nsCString()); VerifyResult(rv); printf("end copy test\n"); @@ -280,11 +281,11 @@ DeletionTest(const char* creationPath, const char* appendPath, PRBool recursive) Banner("Deletion Test"); printf("creationPath == %s\nappendPath == %s\n", creationPath, appendPath); - rv = file->InitWithPath(creationPath); + rv = file->InitWithNativePath(nsDependentCString(creationPath)); VerifyResult(rv); printf("Appending %s\n", appendPath); - rv = file->Append(appendPath); + rv = file->AppendNative(nsDependentCString(appendPath)); VerifyResult(rv); printf("Check For Existance\n"); diff --git a/mozilla/xpcom/threads/nsIProcess.idl b/mozilla/xpcom/threads/nsIProcess.idl index 18c23a0531c..a2c916ba785 100644 --- a/mozilla/xpcom/threads/nsIProcess.idl +++ b/mozilla/xpcom/threads/nsIProcess.idl @@ -9,6 +9,8 @@ interface nsIProcess : nsISupports void initWithPid(in unsigned long pid); void kill(); + + /** XXX what charset? **/ void run(in boolean blocking, [array, size_is(count)] in string args, in unsigned long count, out unsigned long pid); readonly attribute nsIFile location; @@ -19,6 +21,7 @@ interface nsIProcess : nsISupports /** * Called to get the value of environment variable + * XXX what charset? * * @param aName The string enviroment variable name * @exception NS_ERROR_OUT_OF_MEMORY diff --git a/mozilla/xpcom/threads/nsProcess.h b/mozilla/xpcom/threads/nsProcess.h index 141995cfe43..c2e048a0702 100644 --- a/mozilla/xpcom/threads/nsProcess.h +++ b/mozilla/xpcom/threads/nsProcess.h @@ -26,7 +26,8 @@ #define _nsPROCESSWIN_H_ #include "nsIProcess.h" -#include "nsXPIDLString.h" +#include "nsIFile.h" +#include "nsString.h" #include "prproces.h" #define NS_PROCESS_CID \ @@ -46,7 +47,7 @@ public: private: nsCOMPtr mExecutable; PRInt32 mExitValue; - nsXPIDLCString mTargetPath; + nsCString mTargetPath; PRProcess *mProcess; }; diff --git a/mozilla/xpcom/threads/nsProcessCommon.cpp b/mozilla/xpcom/threads/nsProcessCommon.cpp index 861f4287abe..74d2f7f5d36 100644 --- a/mozilla/xpcom/threads/nsProcessCommon.cpp +++ b/mozilla/xpcom/threads/nsProcessCommon.cpp @@ -79,10 +79,10 @@ nsProcess::Init(nsIFile* executable) mExecutable = executable; //Get the path because it is needed by the NSPR process creation #ifdef XP_WIN - rv = mExecutable->GetTarget(getter_Copies(mTargetPath)); - if (NS_FAILED(rv) || !mTargetPath ) + rv = mExecutable->GetNativeTarget(mTargetPath); + if (NS_FAILED(rv) || mTargetPath.IsEmpty() ) #endif - rv = mExecutable->GetPath(getter_Copies(mTargetPath)); + rv = mExecutable->GetNativePath(mTargetPath); return rv; } @@ -283,12 +283,12 @@ nsProcess::Run(PRBool blocking, const char **args, PRUint32 count, PRUint32 *pid #else if ( blocking ) { - mProcess = PR_CreateProcess(mTargetPath, my_argv, NULL, NULL); + mProcess = PR_CreateProcess(mTargetPath.get(), my_argv, NULL, NULL); if (mProcess) rv = PR_WaitProcess(mProcess, &mExitValue); } else { - rv = PR_CreateProcessDetached(mTargetPath, my_argv, NULL, NULL); + rv = PR_CreateProcessDetached(mTargetPath.get(), my_argv, NULL, NULL); } #endif diff --git a/mozilla/xpcom/tools/registry/regExport.cpp b/mozilla/xpcom/tools/registry/regExport.cpp index d3ba929a4c1..27465cdf831 100644 --- a/mozilla/xpcom/tools/registry/regExport.cpp +++ b/mozilla/xpcom/tools/registry/regExport.cpp @@ -42,6 +42,8 @@ #include "nsCOMPtr.h" #include "nsIRegistry.h" #include "nsIEnumerator.h" +#include "nsILocalFile.h" +#include "nsDependentString.h" #include "prmem.h" #include "plstr.h" #include "nsMemory.h" @@ -101,7 +103,14 @@ int main( int argc, char *argv[] ) { } // Open it against the input file name. - rv = reg->Open( argv[1] ); + nsCOMPtr regFile; + rv = NS_NewNativeLocalFile( nsDependentCString(argv[1]), PR_FALSE, getter_AddRefs(regFile) ); + if ( NS_FAILED(rv) ) { + printf( "Error instantiating local file for %s, rv=%x%08X\n", argv[1] ? argv[1] : "", (int)rv ); + return rv; + } + + rv = reg->Open( regFile ); if ( rv == NS_OK ) { diff --git a/mozilla/xpcom/tools/registry/regxpcom.cpp b/mozilla/xpcom/tools/registry/regxpcom.cpp index a839e85e8e1..636ca84795e 100644 --- a/mozilla/xpcom/tools/registry/regxpcom.cpp +++ b/mozilla/xpcom/tools/registry/regxpcom.cpp @@ -49,17 +49,15 @@ #include "nsIServiceManager.h" #include "nsCOMPtr.h" #include "nsILocalFile.h" +#include "nsDependentString.h" static PRBool gUnreg = PR_FALSE, gSilent = PR_FALSE, gQuiet = PR_FALSE; nsresult Register(nsIComponentRegistrar* registrar, const char *path) { - nsCOMPtr spec; - nsresult rv = nsComponentManager::CreateInstance(NS_LOCAL_FILE_CONTRACTID, - nsnull, - NS_GET_IID(nsILocalFile), - getter_AddRefs(spec)); + nsresult rv; + nsCOMPtr spec( do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv) ); if (NS_FAILED(rv) || (!spec)) { @@ -67,18 +65,15 @@ nsresult Register(nsIComponentRegistrar* registrar, const char *path) return NS_ERROR_FAILURE; } - rv = spec->InitWithPath(path); + rv = spec->InitWithNativePath(nsDependentCString(path)); if (NS_FAILED(rv)) return rv; return registrar->AutoRegister(spec); } nsresult Unregister(nsIComponentRegistrar *registrar, const char *path) { - nsCOMPtr spec; - nsresult rv = nsComponentManager::CreateInstance(NS_LOCAL_FILE_CONTRACTID, - nsnull, - NS_GET_IID(nsILocalFile), - getter_AddRefs(spec)); + nsresult rv; + nsCOMPtr spec( do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv) ); if (NS_FAILED(rv) || (!spec)) { @@ -86,7 +81,7 @@ nsresult Unregister(nsIComponentRegistrar *registrar, const char *path) return NS_ERROR_FAILURE; } - rv = spec->InitWithPath(path); + rv = spec->InitWithNativePath(nsDependentCString(path)); if (NS_FAILED(rv)) return rv; return registrar->AutoUnregister(spec); } diff --git a/mozilla/xpfe/appshell/src/nsCommandLineService.cpp b/mozilla/xpfe/appshell/src/nsCommandLineService.cpp index 17acffe0113..fd3fcedaf8f 100644 --- a/mozilla/xpfe/appshell/src/nsCommandLineService.cpp +++ b/mozilla/xpfe/appshell/src/nsCommandLineService.cpp @@ -39,6 +39,7 @@ #include "nsICmdLineService.h" #include "nsCommandLineService.h" #include "nsIComponentManager.h" +#include "nsILocalFile.h" #include "nsString.h" #include "plstr.h" #include "nsNetUtil.h" @@ -71,7 +72,7 @@ static void* ProcessURLArg(char* str) nsCOMPtr file(do_CreateInstance("@mozilla.org/file/local;1")); if (file) { - rv = file->InitWithPath(str); + rv = file->InitWithNativePath(nsDependentCString(str)); if (NS_SUCCEEDED(rv)) { nsCAutoString fileurl; diff --git a/mozilla/xpfe/bootstrap/nsAppRunner.cpp b/mozilla/xpfe/bootstrap/nsAppRunner.cpp index ebbf2a6e646..038d164cb2b 100644 --- a/mozilla/xpfe/bootstrap/nsAppRunner.cpp +++ b/mozilla/xpfe/bootstrap/nsAppRunner.cpp @@ -1124,7 +1124,7 @@ static void ShowOSAlertFromFile(int argc, char **argv, const char *alert_filenam NS_GET_IID(nsIFile), getter_AddRefs(fileName)); if (NS_SUCCEEDED(rv) && fileName) { - fileName->Append(alert_filename); + fileName->AppendNative(nsDependentCString(alert_filename)); PRFileDesc* fd = 0; fileName->OpenNSPRFileDesc(PR_RDONLY, 0664, &fd); if (fd) { @@ -1168,7 +1168,7 @@ static nsresult VerifyInstallation(int argc, char **argv) nsCOMPtr binPath; const char lastResortMessage[] = "A previous install did not complete correctly. Finishing install."; - ShowOSAlertFromFile(argc, argv, CLEANUP_MESSAGE_FILENAME, lastResortMessage); + ShowOSAlertFromFile(argc, argv, CLEANUP_MESSAGE_FILENAME.get(), lastResortMessage); nsCOMPtr cleanupUtility; registryFile->Clone(getter_AddRefs(cleanupUtility)); diff --git a/mozilla/xpfe/communicator/resources/content/contentAreaUtils.js b/mozilla/xpfe/communicator/resources/content/contentAreaUtils.js index a0a2280fb47..857073c438d 100644 --- a/mozilla/xpfe/communicator/resources/content/contentAreaUtils.js +++ b/mozilla/xpfe/communicator/resources/content/contentAreaUtils.js @@ -301,7 +301,7 @@ function foundHeaderInfo(aSniffer, aData) const lfContractID = "@mozilla.org/file/local;1"; const lfIID = Components.interfaces.nsILocalFile; filesFolder = Components .classes[lfContractID].createInstance(lfIID); - filesFolder.initWithUnicodePath(persistArgs.target.unicodePath); + filesFolder.initWithPath(persistArgs.target.path); var nameWithoutExtension = filesFolder.leafName; nameWithoutExtension = nameWithoutExtension.substring(0, nameWithoutExtension.lastIndexOf(".")); diff --git a/mozilla/xpfe/components/bookmarks/resources/addBookmark.js b/mozilla/xpfe/components/bookmarks/resources/addBookmark.js index 908ec7c45f7..e2b0a173f3d 100644 --- a/mozilla/xpfe/components/bookmarks/resources/addBookmark.js +++ b/mozilla/xpfe/components/bookmarks/resources/addBookmark.js @@ -268,7 +268,7 @@ function getNormalizedURL(url) try { const kLF = Components.classes["@mozilla.org/file/local;1"] .createInstance(Components.interfaces.nsILocalFile); - kLF.initWithUnicodePath(url); + kLF.initWithPath(url); if (kLF.exists()) { var ioService = Components.classes["@mozilla.org/network/io-service;1"] .getService(Components.classes.nsIIOService); diff --git a/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.cpp b/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.cpp index 02aa0e9992e..9c56e1aaf7f 100644 --- a/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.cpp +++ b/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.cpp @@ -3176,7 +3176,7 @@ nsBookmarksService::ResolveKeyword(const PRUnichar *aUserInput, char **aShortcut #ifdef XP_WIN // *** code copied from widget/src/windows/nsClipboard.cpp // Determines the URL for a shortcut file -static void ResolveShortcut(const char* aFileName, char** aOutURL) +static void ResolveShortcut(const nsACString &aFileName, char** aOutURL) { // IUniformResourceLocator isn't supported by VC5 (bless its little heart) #if _MSC_VER >= 1200 @@ -3189,10 +3189,9 @@ static void ResolveShortcut(const char* aFileName, char** aOutURL) IPersistFile* urlFile = nsnull; result = urlLink->QueryInterface(IID_IPersistFile, (void**)&urlFile); if (SUCCEEDED(result) && urlFile) { - WORD wideFileName[MAX_PATH]; - ::MultiByteToWideChar(CP_ACP, 0, aFileName, -1, wideFileName, MAX_PATH); + NS_ConvertUTF8toUCS2 wideFileName(aFileName); - result = urlFile->Load(wideFileName, STGM_READ); + result = urlFile->Load(wideFileName.get(), STGM_READ); if (SUCCEEDED(result) ) { LPSTR lpTemp = nsnull; @@ -3247,8 +3246,9 @@ nsBookmarksService::ParseFavoritesFolder(nsIFile* aDirectory, nsIRDFResource* aP nsCOMPtr fileURL(do_QueryInterface(uri)); fileURL->SetFile(currFile); - nsXPIDLString bookmarkName; - currFile->GetUnicodeLeafName(getter_Copies(bookmarkName)); + nsCAutoString leafName; + currFile->GetLeafName(leafName); + NS_ConvertUTF8toUCS2 bookmarkName(leafName); PRBool isDir = PR_FALSE; currFile->IsDirectory(&isDir); @@ -3272,11 +3272,11 @@ nsBookmarksService::ParseFavoritesFolder(nsIFile* aDirectory, nsIRDFResource* aP nsAutoString name(Substring(bookmarkName, 0, bookmarkName.Length() - extension.Length() - 1)); - nsXPIDLCString path; - currFile->GetPath(getter_Copies(path)); + nsCAutoString path; + currFile->GetPath(path); nsXPIDLCString url; - ResolveShortcut(path.get(), getter_Copies(url)); + ResolveShortcut(path, getter_Copies(url)); nsCOMPtr bookmark; rv = CreateBookmark(name.get(), url.get(), aParentResource, getter_AddRefs(bookmark)); @@ -4652,12 +4652,12 @@ nsBookmarksService::GetBookmarksFile(nsFileSpec* aResult) getter_AddRefs(bookmarksFile)); if (NS_SUCCEEDED(rv)) { - // XXX: When the code which calls this can us nsIFile + // XXX: When the code which calls this can use nsIFile // or nsILocalFile, this conversion from nsIFile to // nsFileSpec can go away. Bug 36974. - nsXPIDLCString pathBuf; - rv = bookmarksFile->GetPath(getter_Copies(pathBuf)); + nsCAutoString pathBuf; + rv = bookmarksFile->GetNativePath(pathBuf); if (NS_SUCCEEDED(rv)) *aResult = pathBuf.get(); } diff --git a/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.h b/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.h index ce6599aaaef..9a4eea5910d 100644 --- a/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.h +++ b/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.h @@ -54,6 +54,7 @@ #include "nsIIOService.h" #include "nsICacheService.h" #include "nsICacheSession.h" +#include "nsILocalFile.h" #ifdef DEBUG #ifdef XP_MAC diff --git a/mozilla/xpfe/components/directory/nsDirectoryViewer.cpp b/mozilla/xpfe/components/directory/nsDirectoryViewer.cpp index 488f465aa5c..4aca993bae5 100644 --- a/mozilla/xpfe/components/directory/nsDirectoryViewer.cpp +++ b/mozilla/xpfe/components/directory/nsDirectoryViewer.cpp @@ -413,7 +413,7 @@ nsHTTPIndex::OnIndexAvailable(nsIRequest* aRequest, nsISupports *aContext, // we found the filename; construct a resource for its entry nsCAutoString entryuriC(baseStr); - + // gopher resources don't point to an entry in the same directory // like ftp uris. So the entryuriC is just a unique string, while // the URL attribute is the destination of this element @@ -421,8 +421,8 @@ nsHTTPIndex::OnIndexAvailable(nsIRequest* aRequest, nsISupports *aContext, nsXPIDLCString filename; nsresult rv = aIndex->GetLocation(getter_Copies(filename)); if (NS_FAILED(rv)) return rv; - entryuriC.Append(filename.get()); - + entryuriC.Append(filename); + // if its a directory, make sure it ends with a trailing slash. // This doesn't matter for gopher, (where directories don't have // to end in a trailing /), because the filename is used for the URL @@ -437,7 +437,7 @@ nsHTTPIndex::OnIndexAvailable(nsIRequest* aRequest, nsISupports *aContext, if (isDirType) { entryuriC.Append('/'); } - + nsCOMPtr entry; rv = mDirRDF->GetResource(entryuriC.get(), getter_AddRefs(entry)); diff --git a/mozilla/xpfe/components/download-manager/src/nsDownloadManager.cpp b/mozilla/xpfe/components/download-manager/src/nsDownloadManager.cpp index c0f9a097852..ed0b4081473 100644 --- a/mozilla/xpfe/components/download-manager/src/nsDownloadManager.cpp +++ b/mozilla/xpfe/components/download-manager/src/nsDownloadManager.cpp @@ -416,12 +416,12 @@ nsDownloadManager::AddDownload(nsIURI* aSource, internalDownload->SetSource(aSource); // the persistent descriptor of the target is the unique identifier we use - char* path; - rv = aTarget->GetPath(&path); + nsCAutoString path; + rv = aTarget->GetNativePath(path); if (NS_FAILED(rv)) return rv; nsCOMPtr downloadRes; - gRDFService->GetResource(path, getter_AddRefs(downloadRes)); + gRDFService->GetResource(path.get(), getter_AddRefs(downloadRes)); // if the resource is in the container already (the user has already // downloaded this file), remove it @@ -453,11 +453,11 @@ nsDownloadManager::AddDownload(nsIURI* aSource, } // Set and assert the "pretty" (display) name of the download - nsXPIDLString prettyName; + nsCAutoString prettyName; nsAutoString displayName; displayName.Assign(aDisplayName); if (displayName.IsEmpty()) { - aTarget->GetUnicodeLeafName(getter_Copies(prettyName)); - displayName.Assign(prettyName); + aTarget->GetLeafName(prettyName); + displayName.Assign(NS_ConvertUTF8toUCS2(prettyName)); } (*aDownload)->SetDisplayName(displayName.get()); @@ -479,7 +479,7 @@ nsDownloadManager::AddDownload(nsIURI* aSource, // Assert file information nsCOMPtr fileResource; - gRDFService->GetResource(path, getter_AddRefs(fileResource)); + gRDFService->GetResource(path.get(), getter_AddRefs(fileResource)); rv = mDataSource->Assert(downloadRes, gNC_File, fileResource, PR_TRUE); if (NS_FAILED(rv)) { downloads->IndexOf(downloadRes, &itemIndex); @@ -787,8 +787,8 @@ nsDownloadManager::Observe(nsISupports* aSubject, const char* aTopic, const PRUn nsCOMPtr target; dialog->GetTarget(getter_AddRefs(target)); - char* path; - nsresult rv = target->GetPath(&path); + nsCAutoString path; + nsresult rv = target->GetNativePath(path); if (NS_FAILED(rv)) return rv; nsCStringKey key(path); @@ -797,7 +797,7 @@ nsDownloadManager::Observe(nsISupports* aSubject, const char* aTopic, const PRUn nsDownload* download = NS_STATIC_CAST(nsDownload*, mCurrDownloads->Get(&key)); download->SetDialog(nsnull); - return CancelDownload(path); + return CancelDownload(path.get()); } } return NS_OK; @@ -821,11 +821,11 @@ nsDownload::nsDownload():mStartTime(0), nsDownload::~nsDownload() { - char* path; - nsresult rv = mTarget->GetPath(&path); + nsCAutoString path; + nsresult rv = mTarget->GetNativePath(path); if (NS_FAILED(rv)) return; - mDownloadManager->AssertProgressInfoFor(path); + mDownloadManager->AssertProgressInfoFor(path.get()); } nsresult @@ -947,12 +947,12 @@ nsDownload::OnProgressChange(nsIWebProgress *aWebProgress, mLastUpdate = now; if (mDownloadState == NOTSTARTED) { - char* path; - nsresult rv = mTarget->GetPath(&path); + nsCAutoString path; + nsresult rv = mTarget->GetNativePath(path); if (NS_FAILED(rv)) return rv; mDownloadState = DOWNLOADING; - mDownloadManager->DownloadStarted(path); + mDownloadManager->DownloadStarted(path.get()); } if (aMaxTotalProgress > 0) @@ -1012,11 +1012,11 @@ nsDownload::OnStatusChange(nsIWebProgress *aWebProgress, { if (NS_FAILED(aStatus)) { mDownloadState = FAILED; - char* path; - nsresult rv = mTarget->GetPath(&path); + nsCAutoString path; + nsresult rv = mTarget->GetNativePath(path); if (NS_FAILED(rv)) return rv; - mDownloadManager->DownloadEnded(path, aMessage); + mDownloadManager->DownloadEnded(path.get(), aMessage); } if (mListener) @@ -1062,11 +1062,11 @@ nsDownload::OnStateChange(nsIWebProgress* aWebProgress, mCurrBytes = mMaxBytes; mPercentComplete = 100; - char* path; - nsresult rv = mTarget->GetPath(&path); + nsCAutoString path; + nsresult rv = mTarget->GetNativePath(path); if (NS_FAILED(rv)) return rv; - mDownloadManager->DownloadEnded(path, nsnull); + mDownloadManager->DownloadEnded(path.get(), nsnull); } // break the cycle we created in AddDownload @@ -1122,11 +1122,11 @@ nsDownload::SetDisplayName(const PRUnichar* aDisplayName) nsCOMPtr nameLiteral; nsCOMPtr res; - char* path; - nsresult rv = mTarget->GetPath(&path); + nsCAutoString path; + nsresult rv = mTarget->GetNativePath(path); if (NS_FAILED(rv)) return rv; - gRDFService->GetResource(path, getter_AddRefs(res)); + gRDFService->GetResource(path.get(), getter_AddRefs(res)); gRDFService->GetLiteral(aDisplayName, getter_AddRefs(nameLiteral)); ds->Assert(res, gNC_Name, nameLiteral, PR_TRUE); diff --git a/mozilla/xpfe/components/download-manager/src/nsDownloadProxy.h b/mozilla/xpfe/components/download-manager/src/nsDownloadProxy.h index 4a254a5f34f..c6faee096fe 100644 --- a/mozilla/xpfe/components/download-manager/src/nsDownloadProxy.h +++ b/mozilla/xpfe/components/download-manager/src/nsDownloadProxy.h @@ -65,11 +65,11 @@ public: rv = dm->AddDownload(aSource, aTarget, aDisplayName, aOpeningWith, aStartTime, aPersist, getter_AddRefs(mInner)); if (NS_FAILED(rv)) return rv; - char* path; - rv = aTarget->GetPath(&path); + nsCAutoString path; + rv = aTarget->GetNativePath(path); if (NS_FAILED(rv)) return rv; - return dm->OpenProgressDialogFor(path, nsnull); + return dm->OpenProgressDialogFor(path.get(), nsnull); } diff --git a/mozilla/xpfe/components/filepicker/res/content/filepicker.js b/mozilla/xpfe/components/filepicker/res/content/filepicker.js index 3800e05d873..2e1b6d7ae64 100644 --- a/mozilla/xpfe/components/filepicker/res/content/filepicker.js +++ b/mozilla/xpfe/components/filepicker/res/content/filepicker.js @@ -58,7 +58,7 @@ function filepickerLoad() { const title = o.title; filePickerMode = o.mode; if (o.displayDirectory) { - const directory = o.displayDirectory.unicodePath; + const directory = o.displayDirectory.path; } const initialText = o.defaultString; const filterTitles = o.filters.titles; @@ -136,11 +136,11 @@ function setInitialDirectory(directory) homeDir = dirServiceProvider.getFile("Home", persistent); if (directory) { - sfile.initWithUnicodePath(directory); + sfile.initWithPath(directory); } if (!directory || !(sfile.exists() && sfile.isDirectory())) { // Start in the user's home directory - sfile.initWithUnicodePath(homeDir.unicodePath); + sfile.initWithPath(homeDir.path); } gotoDirectory(sfile); @@ -164,9 +164,9 @@ function changeFilter(filterTypes) function showFilePermissionsErrorDialog(titleStrName, messageStrName, file) { var errorTitle = - gFilePickerBundle.getFormattedString(titleStrName, [file.unicodePath]); + gFilePickerBundle.getFormattedString(titleStrName, [file.path]); var errorMessage = - gFilePickerBundle.getFormattedString(messageStrName, [file.unicodePath]); + gFilePickerBundle.getFormattedString(messageStrName, [file.path]); var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService); @@ -204,7 +204,7 @@ function selectOnOK() var input = textInput.value; if (input[0] == '~') // XXX XP? - input = homeDir.unicodePath + input.substring(1); + input = homeDir.path + input.substring(1); var file = sfile.clone().QueryInterface(nsILocalFile); if (!file) @@ -212,18 +212,18 @@ function selectOnOK() /* XXX we need an XP way to test for an absolute path! */ if (input[0] == '/') /* an absolute path was entered */ - file.initWithUnicodePath(input); + file.initWithPath(input); else if ((input.indexOf("/../") > 0) || (input.substr(-3) == "/..") || (input.substr(0,3) == "../") || (input == "..")) { /* appendRelativePath doesn't allow .. */ - file.initWithUnicodePath(file.unicodePath + "/" + input); + file.initWithPath(file.path + "/" + input); file.normalize(); } else { try { - file.appendRelativeUnicodePath(input); + file.appendRelativePath(input); } catch (e) { dump("Can't append relative path '"+input+"':\n"); return false; @@ -246,7 +246,7 @@ function selectOnOK() case nsIFilePicker.modeOpen: if (isFile) { if (file.isReadable()) { - retvals.directory = file.parent.unicodePath; + retvals.directory = file.parent.path; ret = nsIFilePicker.returnOK; } else { showFilePermissionsErrorDialog("errorOpeningFileTitle", @@ -274,12 +274,12 @@ function selectOnOK() // we need to pop up a dialog asking if you want to save var message = gFilePickerBundle.getFormattedString("confirmFileReplacing", - [file.unicodePath]); + [file.path]); var rv = window.confirm(message); if (rv) { ret = nsIFilePicker.returnReplace; - retvals.directory = file.parent.unicodePath; + retvals.directory = file.parent.path; } else { ret = nsIFilePicker.returnCancel; } @@ -295,7 +295,7 @@ function selectOnOK() var parent = file.parent; if (parent.exists() && parent.isDirectory() && parent.isWritable()) { ret = nsIFilePicker.returnOK; - retvals.directory = parent.unicodePath; + retvals.directory = parent.path; } else { var oldParent = parent; while (!parent.exists()) { @@ -304,20 +304,20 @@ function selectOnOK() } var errorTitle = gFilePickerBundle.getFormattedString("errorSavingFileTitle", - [file.unicodePath]); + [file.path]); var errorMessage; if (parent.isFile()) { errorMessage = gFilePickerBundle.getFormattedString("saveParentIsFileMessage", - [parent.unicodePath, file.unicodePath]); + [parent.path, file.path]); } else { errorMessage = gFilePickerBundle.getFormattedString("saveParentDoesntExistMessage", - [oldParent.unicodePath, file.unicodePath]); + [oldParent.path, file.path]); } if (!parent.isWritable()) { errorMessage = - gFilePickerBundle.getFormattedString("saveWithoutPermissionMessage_dir", [parent.unicodePath]); + gFilePickerBundle.getFormattedString("saveWithoutPermissionMessage_dir", [parent.path]); } promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] .getService(Components.interfaces.nsIPromptService); @@ -328,9 +328,9 @@ function selectOnOK() break; case nsIFilePicker.modeGetFolder: if (isDir) { - retvals.directory = file.parent.unicodePath; + retvals.directory = file.parent.path; } else { // if nothing selected, the current directory will be fine - retvals.directory = sfile.unicodePath; + retvals.directory = sfile.path; } ret = nsIFilePicker.returnOK; break; @@ -480,7 +480,7 @@ function onSelect(event) { function onFileSelected(file) { if (file) { - var path = file.unicodeLeafName; + var path = file.leafName; if (path) { if ((filePickerMode == nsIFilePicker.modeGetFolder) || !file.isDirectory()) @@ -507,7 +507,7 @@ function onDirectoryChanged(target) var path = target.getAttribute("label"); var file = Components.classes[nsLocalFile_CONTRACTID].createInstance(nsILocalFile); - file.initWithUnicodePath(path); + file.initWithPath(path); if (!sfile.equals(file)) { // Do this on a timeout callback so the directory list can roll up @@ -525,7 +525,7 @@ function populateAncestorList(directory) { } var menuItem = document.createElement("menuitem"); - menuItem.setAttribute("label", directory.unicodePath); + menuItem.setAttribute("label", directory.path); menuItem.setAttribute("crop", "start"); menu.appendChild(menuItem); @@ -533,7 +533,7 @@ function populateAncestorList(directory) { var parent = directory.parent; while (parent && !parent.equals(directory)) { menuItem = document.createElement("menuitem"); - menuItem.setAttribute("label", parent.unicodePath); + menuItem.setAttribute("label", parent.path); menuItem.setAttribute("crop", "start"); menu.appendChild(menuItem); directory = parent; diff --git a/mozilla/xpfe/components/filepicker/src/nsFilePicker.js b/mozilla/xpfe/components/filepicker/src/nsFilePicker.js index 871f9fdf968..d9e2cab388f 100644 --- a/mozilla/xpfe/components/filepicker/src/nsFilePicker.js +++ b/mozilla/xpfe/components/filepicker/src/nsFilePicker.js @@ -66,7 +66,7 @@ function nsFilePicker() this.mFilterIndex = 0; if (lastDirectory) { this.mDisplayDirectory = Components.classes[LOCAL_FILE_CONTRACTID].createInstance(nsILocalFile); - this.mDisplayDirectory.initWithUnicodePath(lastDirectory); + this.mDisplayDirectory.initWithPath(lastDirectory); } else { this.mDisplayDirectory = null; } diff --git a/mozilla/xpfe/components/filepicker/src/nsFilePicker.js.in b/mozilla/xpfe/components/filepicker/src/nsFilePicker.js.in index 871f9fdf968..d9e2cab388f 100644 --- a/mozilla/xpfe/components/filepicker/src/nsFilePicker.js.in +++ b/mozilla/xpfe/components/filepicker/src/nsFilePicker.js.in @@ -66,7 +66,7 @@ function nsFilePicker() this.mFilterIndex = 0; if (lastDirectory) { this.mDisplayDirectory = Components.classes[LOCAL_FILE_CONTRACTID].createInstance(nsILocalFile); - this.mDisplayDirectory.initWithUnicodePath(lastDirectory); + this.mDisplayDirectory.initWithPath(lastDirectory); } else { this.mDisplayDirectory = null; } diff --git a/mozilla/xpfe/components/filepicker/src/nsFileView.cpp b/mozilla/xpfe/components/filepicker/src/nsFileView.cpp index da939acfb0f..41b300a7925 100644 --- a/mozilla/xpfe/components/filepicker/src/nsFileView.cpp +++ b/mozilla/xpfe/components/filepicker/src/nsFileView.cpp @@ -540,10 +540,9 @@ nsFileView::GetCellText(PRInt32 aRow, const PRUnichar* aColID, } if (NS_LITERAL_STRING("FilenameColumn").Equals(aColID)) { - // XXX fix this by making GetUnicodeLeafName take an nsAString& - nsXPIDLString temp; - curFile->GetUnicodeLeafName(getter_Copies(temp)); - aCellText = temp; + nsCAutoString temp; + curFile->GetLeafName(temp); + aCellText = NS_ConvertUTF8toUCS2(temp); } else if (NS_LITERAL_STRING("LastModifiedColumn").Equals(aColID)) { PRInt64 lastModTime; curFile->GetLastModifiedTime(&lastModTime); @@ -648,15 +647,17 @@ nsFileView::FilterFiles() if (!mShowHiddenFiles) file->IsHidden(&isHidden); - nsXPIDLString unicodeLeafName; - if(NS_FAILED(file->GetUnicodeLeafName(getter_Copies(unicodeLeafName)))) { - // need to check return value for GetUnicodeLeafName() + nsCAutoString leafName; + if(NS_FAILED(file->GetLeafName(leafName))) { + // need to check return value for GetLeafName() continue; } + + NS_ConvertUTF8toUCS2 ucsLeafName(leafName); if (!isHidden) { for (PRInt32 j = 0; j < filterCount; ++j) { - if (NS_WildCardMatch(unicodeLeafName.get(), + if (NS_WildCardMatch(ucsLeafName.get(), (const PRUnichar*) mCurrentFilters.ElementAt(j), PR_TRUE) == MATCH) { mFilteredFiles->AppendElement(file); @@ -691,11 +692,11 @@ SortNameCallback(const void* aElement1, const void* aElement2, void* aContext) nsIFile* file1 = *NS_STATIC_CAST(nsIFile* const *, aElement1); nsIFile* file2 = *NS_STATIC_CAST(nsIFile* const *, aElement2); - nsXPIDLString leafName1, leafName2; - file1->GetUnicodeLeafName(getter_Copies(leafName1)); - file2->GetUnicodeLeafName(getter_Copies(leafName2)); + nsCAutoString leafName1, leafName2; + file1->GetLeafName(leafName1); + file2->GetLeafName(leafName2); - return nsCRT::strcmp(leafName1.get(), leafName2.get()); + return Compare(leafName1, leafName2); } PR_STATIC_CALLBACK(int) diff --git a/mozilla/xpfe/components/history/src/nsGlobalHistory.cpp b/mozilla/xpfe/components/history/src/nsGlobalHistory.cpp index 5aab00acb28..073488f7530 100644 --- a/mozilla/xpfe/components/history/src/nsGlobalHistory.cpp +++ b/mozilla/xpfe/components/history/src/nsGlobalHistory.cpp @@ -73,6 +73,7 @@ #include "rdf.h" #include "nsQuickSort.h" #include "nsIIOService.h" +#include "nsILocalFile.h" #include "nsIURL.h" #include "nsNetCID.h" @@ -2380,21 +2381,22 @@ nsGlobalHistory::OpenDB() NS_ASSERTION((err == 0), "unable to create mdb env"); if (err != 0) return NS_ERROR_FAILURE; - nsXPIDLCString filePath; - rv = historyFile->GetPath(getter_Copies(filePath)); - NS_ENSURE_SUCCESS(rv, rv); + // MDB requires native file paths + nsCAutoString filePath; + rv = historyFile->GetNativePath(filePath); + NS_ENSURE_SUCCESS(rv, rv); PRBool exists = PR_TRUE; historyFile->Exists(&exists); - if (!exists || NS_FAILED(rv = OpenExistingFile(gMdbFactory, filePath))) { + if (!exists || NS_FAILED(rv = OpenExistingFile(gMdbFactory, filePath.get()))) { // we couldn't open the file, so it's either corrupt or doesn't exist. // attempt to delete the file, but ignore the error historyFile->Remove(PR_FALSE); - rv = OpenNewFile(gMdbFactory, filePath); + rv = OpenNewFile(gMdbFactory, filePath.get()); } NS_ENSURE_SUCCESS(rv, rv); diff --git a/mozilla/xpfe/components/prefwindow/resources/content/pref-applications-new.js b/mozilla/xpfe/components/prefwindow/resources/content/pref-applications-new.js index 63356b3396a..910905ca853 100644 --- a/mozilla/xpfe/components/prefwindow/resources/content/pref-applications-new.js +++ b/mozilla/xpfe/components/prefwindow/resources/content/pref-applications-new.js @@ -48,7 +48,7 @@ function Startup() // an app may have been selected in the opening dialog but not in the mimeinfo var app = info.preferredApplicationHandler || window.arguments[0].chosenApp; if ( app ) { - gAppPath.value = app.unicodePath; + gAppPath.value = app.path; } // Don't let user change mime type. @@ -145,7 +145,7 @@ function onOK() if (file) { try { file.initWithPath(gAppPath.value); - handlerInfo.appDisplayName = file.unicodeLeafName; + handlerInfo.appDisplayName = file.leafName; } catch(e) { handlerInfo.appDisplayName = gAppPath.value; diff --git a/mozilla/xpfe/components/prefwindow/resources/content/pref-cache.js b/mozilla/xpfe/components/prefwindow/resources/content/pref-cache.js index 751e8e3d243..4c922c65b5c 100644 --- a/mozilla/xpfe/components/prefwindow/resources/content/pref-cache.js +++ b/mozilla/xpfe/components/prefwindow/resources/content/pref-cache.js @@ -46,7 +46,7 @@ function Startup() // if both pref and dir svc fail leave this field blank else show path if (path) document.getElementById("browserCacheDiskCacheFolder").value = - path.unicodePath; + path.path; } @@ -75,7 +75,7 @@ function prefCacheSelectFolder() if (ret == nsIFilePicker.returnOK) { var localFile = fp.file.QueryInterface(nsILocalFile); - var viewable = fp.file.unicodePath; + var viewable = fp.file.path; var folderField = document.getElementById("browserCacheDiskCacheFolder"); folderField.value = viewable; pref.setComplexValue(kCacheParentDirPref, nsILocalFile, localFile) diff --git a/mozilla/xpfe/components/regviewer/nsIRegistryDataSource.idl b/mozilla/xpfe/components/regviewer/nsIRegistryDataSource.idl index 426c0daab4a..78bfa7095fc 100644 --- a/mozilla/xpfe/components/regviewer/nsIRegistryDataSource.idl +++ b/mozilla/xpfe/components/regviewer/nsIRegistryDataSource.idl @@ -43,6 +43,8 @@ #include "nsISupports.idl" +interface nsIFile; + [scriptable, uuid(8FA81100-6F88-11d3-BE43-00104BDE6048)] interface nsIRegistryDataSource : nsISupports { @@ -51,7 +53,7 @@ interface nsIRegistryDataSource : nsISupports /** * Open and initialize the registry viewer */ - void open(in string aPlatformFileName); + void open(in nsIFile aFile); /** * Open a stock registry diff --git a/mozilla/xpfe/components/regviewer/nsRegistryDataSource.cpp b/mozilla/xpfe/components/regviewer/nsRegistryDataSource.cpp index 74ea8fbedf9..e4c533a6257 100644 --- a/mozilla/xpfe/components/regviewer/nsRegistryDataSource.cpp +++ b/mozilla/xpfe/components/regviewer/nsRegistryDataSource.cpp @@ -47,6 +47,7 @@ #include "nsIModule.h" #include "nsIComponentManager.h" #include "nsIGenericFactory.h" +#include "nsIFile.h" #include "nsRDFCID.h" #include "nsXPIDLString.h" #include "plstr.h" @@ -179,11 +180,9 @@ nsRegistryDataSource::GetKey(nsIRDFResource* aResource) // NS_IMETHODIMP -nsRegistryDataSource::Open(const char* aPlatformFileName) +nsRegistryDataSource::Open(nsIFile *aFile) { - NS_PRECONDITION(aPlatformFileName != nsnull, "null ptr"); - if (! aPlatformFileName) - return NS_ERROR_NULL_POINTER; + NS_ENSURE_ARG_POINTER(aFile); nsresult rv; rv = nsComponentManager::CreateInstance(kRegistryCID, @@ -192,7 +191,7 @@ nsRegistryDataSource::Open(const char* aPlatformFileName) getter_AddRefs(mRegistry)); if (NS_FAILED(rv)) return rv; - rv = mRegistry->Open(aPlatformFileName); + rv = mRegistry->Open(aFile); if (NS_FAILED(rv)) return rv; return NS_OK; diff --git a/mozilla/xpfe/components/search/src/nsInternetSearchService.cpp b/mozilla/xpfe/components/search/src/nsInternetSearchService.cpp index 0bd1f98f906..cc73c16a80f 100755 --- a/mozilla/xpfe/components/search/src/nsInternetSearchService.cpp +++ b/mozilla/xpfe/components/search/src/nsInternetSearchService.cpp @@ -77,6 +77,7 @@ #include "nsIStringBundle.h" #include "nsIObserverService.h" #include "nsIURL.h" +#include "nsILocalFile.h" #include "nsUnicharUtils.h" #include "nsReadableUtils.h" @@ -2399,13 +2400,10 @@ InternetSearchDataSource::saveContents(nsIChannel* channel, nsIInternetSearchCon if (!channelURI) return(NS_ERROR_NULL_POINTER); - nsCAutoString spec; - if (NS_FAILED(rv = channelURI->GetSpec(spec))) + nsCAutoString baseName; + if (NS_FAILED(rv = channelURI->GetSpec(baseName))) return(rv); - // get base name - NS_ConvertUTF8toUCS2 baseName(spec); - PRInt32 slashOffset = baseName.RFindChar(PRUnichar('/')); if (slashOffset < 0) return(NS_ERROR_UNEXPECTED); baseName.Cut(0, slashOffset+1); @@ -2435,55 +2433,57 @@ InternetSearchDataSource::saveContents(nsIChannel* channel, nsIInternetSearchCon if (NS_FAILED(context->GetBufferLength(&bufferLength))) return(rv); if (bufferLength < 1) return(NS_OK); - rv = outFile->AppendUnicode(baseName.get()); + rv = outFile->Append(baseName); if (NS_FAILED(rv)) return rv; // save data to file // Note: write out one character at a time, as we might be dealing // with binary data (such as 0x00) [especially for images] + // + // XXX - It appears that this is done in order to discard the upper + // byte of each PRUnichar. I hope that's OK!! + // outFile->Remove(PR_FALSE); - // Make an nsFileSpec from file so we can use nsOutputFileStream - nsXPIDLCString pathBuf; - rv = outFile->GetPath(getter_Copies(pathBuf)); - if (NS_FAILED(rv)) return rv; - nsFileSpec outFileSpec((const char *)pathBuf); + nsCOMPtr outputStream, fileOutputStream; + rv = NS_NewLocalFileOutputStream(getter_AddRefs(fileOutputStream), outFile); + if (NS_FAILED(rv)) return rv; + rv = NS_NewBufferedOutputStream(getter_AddRefs(outputStream), fileOutputStream, 4096); + if (NS_FAILED(rv)) return rv; - nsOutputFileStream outputStream(outFileSpec); - if (!outputStream.failed()) - { - for (PRInt32 loop=0; loop < bufferLength; loop++) - { - outputStream.put((char)(dataBuf[loop])); - } - outputStream.flush(); - outputStream.close(); + PRUint32 bytesWritten; + for (PRInt32 loop=0; loop < bufferLength; loop++) + { + const char b = (const char) dataBuf[loop]; + outputStream->Write(&b, 1, &bytesWritten); + } + outputStream->Flush(); + outputStream->Close(); - if (contextType == nsIInternetSearchContext::ENGINE_DOWNLOAD_CONTEXT || - contextType == nsIInternetSearchContext::ENGINE_UPDATE_CONTEXT) - { + if (contextType == nsIInternetSearchContext::ENGINE_DOWNLOAD_CONTEXT || + contextType == nsIInternetSearchContext::ENGINE_UPDATE_CONTEXT) + { #ifdef XP_MAC - // set appropriate Mac file type/creator for search engine files - nsCOMPtr macFile(do_QueryInterface(outFile)); - if (macFile) { - macFile->SetFileType('issp'); - macFile->SetFileCreator('fndf'); - } + // set appropriate Mac file type/creator for search engine files + nsCOMPtr macFile(do_QueryInterface(outFile)); + if (macFile) { + macFile->SetFileType('issp'); + macFile->SetFileCreator('fndf'); + } #endif - // check suggested category hint - const PRUnichar *hintUni = nsnull; - rv = context->GetHintConst(&hintUni); + // check suggested category hint + const PRUnichar *hintUni = nsnull; + rv = context->GetHintConst(&hintUni); - // update graph with various required info - SaveEngineInfoIntoGraph(outFile, nsnull, hintUni, dataBuf, PR_FALSE, PR_FALSE); - } - else if (contextType == nsIInternetSearchContext::ICON_DOWNLOAD_CONTEXT) - { - // update graph with icon info - SaveEngineInfoIntoGraph(nsnull, outFile, nsnull, nsnull, PR_FALSE, PR_FALSE); - } - } + // update graph with various required info + SaveEngineInfoIntoGraph(outFile, nsnull, hintUni, dataBuf, PR_FALSE, PR_FALSE); + } + else if (contextType == nsIInternetSearchContext::ICON_DOWNLOAD_CONTEXT) + { + // update graph with icon info + SaveEngineInfoIntoGraph(nsnull, outFile, nsnull, nsnull, PR_FALSE, PR_FALSE); + } // after we're all done with the data buffer, get rid of it context->Truncate(); @@ -3740,7 +3740,7 @@ InternetSearchDataSource::DoSearch(nsIRDFResource *source, nsIRDFResource *engin nsCAutoString poststrC; poststrC.AssignWithConversion(postStr); if (NS_SUCCEEDED(rv = NS_NewPostDataStream(getter_AddRefs(postDataStream), - PR_FALSE, poststrC.get(), 0))) + PR_FALSE, poststrC, 0))) { nsCOMPtr uploadChannel(do_QueryInterface(httpChannel)); NS_ASSERTION(uploadChannel, "http must support nsIUploadChannel"); @@ -3831,11 +3831,11 @@ InternetSearchDataSource::SaveEngineInfoIntoGraph(nsIFile *file, nsIFile *icon, if (NS_FAILED(rv)) return(rv); if (!exists) return(NS_ERROR_UNEXPECTED); - nsAutoString basename; - nsXPIDLCString leafCName; - rv = native->GetLeafName(getter_Copies(leafCName)); + nsCAutoString leafName; + rv = native->GetLeafName(leafName); if (NS_FAILED(rv)) return rv; - basename.AssignWithConversion((const char *)leafCName); + + NS_ConvertUTF8toUCS2 basename(leafName); // ensure that the basename points to the search engine file PRInt32 extensionOffset; @@ -3845,14 +3845,13 @@ InternetSearchDataSource::SaveEngineInfoIntoGraph(nsIFile *file, nsIFile *icon, basename.Append(NS_LITERAL_STRING(".src")); } - nsXPIDLCString filePath; - rv = native->GetPath(getter_Copies(filePath)); + nsCAutoString filePath; + rv = native->GetNativePath(filePath); if (NS_FAILED(rv)) return rv; - nsFileSpec nativeSpec((const char *)filePath); nsAutoString searchURL; searchURL.AssignWithConversion(kEngineProtocol); - char *uriCescaped = nsEscape((const char *)filePath, url_Path); + char *uriCescaped = nsEscape(filePath.get(), url_Path); if (!uriCescaped) return(NS_ERROR_NULL_POINTER); searchURL.AppendWithConversion(uriCescaped); nsCRT::free(uriCescaped); @@ -4055,13 +4054,12 @@ InternetSearchDataSource::GetSearchEngineList(nsIFile *searchDir, if (NS_FAILED(rv) || (fileSize == 0)) continue; - nsXPIDLCString pathBuf; - rv = dirEntry->GetPath(getter_Copies(pathBuf)); + nsCAutoString pathBuf; + rv = dirEntry->GetPath(pathBuf); if (NS_FAILED(rv)) continue; - nsAutoString uri; - uri.AssignWithConversion((const char *)pathBuf); + NS_ConvertUTF8toUCS2 uri(pathBuf); PRInt32 len = uri.Length(); if (len < 5) { @@ -4142,7 +4140,7 @@ InternetSearchDataSource::GetSearchEngineList(nsIFile *searchDir, if (foundIconFlag) { - NS_NewLocalFile((const char *)iconSpec, PR_TRUE, getter_AddRefs(iconFile)); + NS_NewNativeLocalFile(nsDependentCString((const char *)iconSpec), PR_TRUE, getter_AddRefs(iconFile)); } SaveEngineInfoIntoGraph(dirEntry, iconFile, nsnull, nsnull, isSystemSearchFile, checkMacFileType); diff --git a/mozilla/xpfe/components/startup/src/nsCommandLineService.cpp b/mozilla/xpfe/components/startup/src/nsCommandLineService.cpp index 17acffe0113..fd3fcedaf8f 100644 --- a/mozilla/xpfe/components/startup/src/nsCommandLineService.cpp +++ b/mozilla/xpfe/components/startup/src/nsCommandLineService.cpp @@ -39,6 +39,7 @@ #include "nsICmdLineService.h" #include "nsCommandLineService.h" #include "nsIComponentManager.h" +#include "nsILocalFile.h" #include "nsString.h" #include "plstr.h" #include "nsNetUtil.h" @@ -71,7 +72,7 @@ static void* ProcessURLArg(char* str) nsCOMPtr file(do_CreateInstance("@mozilla.org/file/local;1")); if (file) { - rv = file->InitWithPath(str); + rv = file->InitWithNativePath(nsDependentCString(str)); if (NS_SUCCEEDED(rv)) { nsCAutoString fileurl; diff --git a/mozilla/xpfe/components/ucth/resources/helperAppDldProgress.js b/mozilla/xpfe/components/ucth/resources/helperAppDldProgress.js index 05463f7f46a..4b8f77f8351 100644 --- a/mozilla/xpfe/components/ucth/resources/helperAppDldProgress.js +++ b/mozilla/xpfe/components/ucth/resources/helperAppDldProgress.js @@ -318,7 +318,7 @@ function loadDialog() dialog.timeLeft.setAttribute("value", formatSeconds( 0 )); dialog.location.setAttribute("value", sourceUrl.spec ); - dialog.fileName.setAttribute( "value", targetFile.unicodePath ); + dialog.fileName.setAttribute( "value", targetFile.path ); var prefs = Components.classes[prefContractID].getService(Components.interfaces.nsIPrefBranch); if (prefs) @@ -390,7 +390,7 @@ function onLoad() { const lfContractID = "@mozilla.org/file/local;1"; const lfIID = Components.interfaces.nsILocalFile; var filesFolder = Components .classes[lfContractID].createInstance(lfIID); - filesFolder.initWithUnicodePath(persistArgs.target.unicodePath); + filesFolder.initWithPath(persistArgs.target.path); var nameWithoutExtension = filesFolder.leafName; nameWithoutExtension = nameWithoutExtension.substring(0, nameWithoutExtension.lastIndexOf(".")); diff --git a/mozilla/xpfe/components/ucth/resources/helperAppLauncher.js b/mozilla/xpfe/components/ucth/resources/helperAppLauncher.js index f54ab7206ac..f09858768cc 100644 --- a/mozilla/xpfe/components/ucth/resources/helperAppLauncher.js +++ b/mozilla/xpfe/components/ucth/resources/helperAppLauncher.js @@ -59,7 +59,7 @@ nsHelperAppLauncherDialog.prototype= { else if (this.chosenApp) { // If a user-chosen application, show its path. - document.getElementById( "appName" ).value = this.chosenApp.unicodePath; + document.getElementById( "appName" ).value = this.chosenApp.path; } var saveToDisk = document.getElementById("saveToDisk"); @@ -151,7 +151,7 @@ nsHelperAppLauncherDialog.prototype= { this.userChoseApp = true; this.chosenApp = fp.file; // Update dialog. - document.getElementById( "appName" ).value = this.chosenApp.unicodePath; + document.getElementById( "appName" ).value = this.chosenApp.path; } }, diff --git a/mozilla/xpfe/components/xfer/resources/downloadProgress.js b/mozilla/xpfe/components/xfer/resources/downloadProgress.js index 07d524c16de..c6b54b26909 100644 --- a/mozilla/xpfe/components/xfer/resources/downloadProgress.js +++ b/mozilla/xpfe/components/xfer/resources/downloadProgress.js @@ -26,7 +26,7 @@ var dialog; function loadDialog() { dialog.location.setAttribute( "value", data.source.URI.spec ); - dialog.fileName.setAttribute( "value", data.target.unicodePath ); + dialog.fileName.setAttribute( "value", data.target.path ); dialog.error = false; } diff --git a/mozilla/xpfe/components/xfer/src/nsStreamTransfer.cpp b/mozilla/xpfe/components/xfer/src/nsStreamTransfer.cpp index 3dfcd676c63..10daa33ed25 100644 --- a/mozilla/xpfe/components/xfer/src/nsStreamTransfer.cpp +++ b/mozilla/xpfe/components/xfer/src/nsStreamTransfer.cpp @@ -328,11 +328,12 @@ nsString nsStreamTransfer::SuggestNameFor( nsIChannel *aChannel, char const *sug // try to overwrite c:\config.sys or something. nsCOMPtr localFile; nsCAutoString suggestedFileName(suggestedName); - if ( NS_SUCCEEDED( NS_NewLocalFile( nsUnescape(NS_CONST_CAST(char*, suggestedFileName.get())), PR_FALSE, getter_AddRefs( localFile ) ) ) ) { + NS_UnescapeURL(suggestedFileName); + if ( NS_SUCCEEDED( NS_NewNativeLocalFile( suggestedFileName, PR_FALSE, getter_AddRefs( localFile ) ) ) ) { // We want base part of name only. - nsXPIDLString baseName; - if ( NS_SUCCEEDED( localFile->GetUnicodeLeafName( getter_Copies( baseName ) ) ) ) { - result = baseName.get(); + nsCAutoString baseName; + if ( NS_SUCCEEDED( localFile->GetLeafName( baseName ) ) ) { + result = NS_ConvertUTF8toUCS2(baseName); } } } else if ( aChannel ) { @@ -348,9 +349,9 @@ nsString nsStreamTransfer::SuggestNameFor( nsIChannel *aChannel, char const *sug rv = fileurl->GetFile(getter_AddRefs(localeFile)); if ( NS_SUCCEEDED( rv ) && localeFile) { - nsXPIDLString baseName; - if ( NS_SUCCEEDED( localeFile->GetUnicodeLeafName( getter_Copies( baseName ) ) ) ) { - result = baseName.get(); + nsCAutoString baseName; + if ( NS_SUCCEEDED( localeFile->GetLeafName( baseName ) ) ) { + result = NS_ConvertUTF8toUCS2(baseName); return result; } } @@ -362,7 +363,7 @@ nsString nsStreamTransfer::SuggestNameFor( nsIChannel *aChannel, char const *sug rv = url->GetFileName( nameFromURL ); if ( NS_SUCCEEDED( rv ) && !nameFromURL.IsEmpty() ) { // Unescape the file name (GetFileName escapes it). - nsUnescape( (char *) nameFromURL.get() ); + NS_UnescapeURL(nameFromURL); //make sure nameFromURL only contains ascii, //otherwise we have no idea about urlname's original charset, suggest nothing diff --git a/mozilla/xpinstall/cleanup/InstallCleanupDefines.h b/mozilla/xpinstall/cleanup/InstallCleanupDefines.h index 9b6b4e13383..8b4e45147b6 100644 --- a/mozilla/xpinstall/cleanup/InstallCleanupDefines.h +++ b/mozilla/xpinstall/cleanup/InstallCleanupDefines.h @@ -38,29 +38,34 @@ #ifndef INSTALLCLEANUPDEFINES_H #define INSTALLCLEANUPDEFINES_H -#define CLEANUP_MESSAGE_FILENAME "cmessage.txt" +// simple hack for xpicleanup.exe +#ifndef NS_LITERAL_CSTRING +#define NS_LITERAL_CSTRING(x) (x) +#endif + +#define CLEANUP_MESSAGE_FILENAME NS_LITERAL_CSTRING("cmessage.txt") #ifndef XP_MAC -#define CLEANUP_REGISTRY "xpicleanup.dat" +#define CLEANUP_REGISTRY NS_LITERAL_CSTRING("xpicleanup.dat") #endif #if defined (XP_MAC) -#define CLEANUP_REGISTRY "XPICleanup Data" -#define ESSENTIAL_FILES "Essential Files" +#define CLEANUP_REGISTRY NS_LITERAL_CSTRING("XPICleanup Data") +#define ESSENTIAL_FILES NS_LITERAL_CSTRING("Essential Files") #ifdef DEBUG -#define CLEANUP_UTIL "XPICleanupDebug" +#define CLEANUP_UTIL NS_LITERAL_CSTRING("XPICleanupDebug") #else -#define CLEANUP_UTIL "XPICleanup" +#define CLEANUP_UTIL NS_LITERAL_CSTRING("XPICleanup") #endif //DEBUG #elif defined (XP_WIN) -#define CLEANUP_UTIL "xpicleanup.exe" +#define CLEANUP_UTIL NS_LITERAL_CSTRING("xpicleanup.exe") #elif defined (XP_OS2) -#define CLEANUP_UTIL "xpicleanup.exe" +#define CLEANUP_UTIL NS_LITERAL_CSTRING("xpicleanup.exe") #else -#define CLEANUP_UTIL "xpicleanup" +#define CLEANUP_UTIL NS_LITERAL_CSTRING("xpicleanup") #endif diff --git a/mozilla/xpinstall/src/ScheduledTasks.cpp b/mozilla/xpinstall/src/ScheduledTasks.cpp index f0f588adac3..d49c947a618 100644 --- a/mozilla/xpinstall/src/ScheduledTasks.cpp +++ b/mozilla/xpinstall/src/ScheduledTasks.cpp @@ -38,19 +38,17 @@ #include "nsAppDirectoryServiceDefs.h" static nsresult -GetPersistentStringFromSpec(nsIFile* inSpec, char **string) +GetPersistentStringFromSpec(nsIFile* inSpec, nsACString &string) { nsresult rv; - if (!string) return NS_ERROR_NULL_POINTER; - nsCOMPtr LocalFile = do_QueryInterface(inSpec, &rv); if (NS_SUCCEEDED(rv)) { - rv = LocalFile->GetPath(string); + rv = LocalFile->GetNativePath(string); } else { - *string = nsnull; + string.Truncate(); } return rv; } @@ -70,11 +68,11 @@ PRInt32 ReplaceWindowsSystemFile(nsIFile* currentSpec, nsIFile* finalSpec) // Get OS version info DWORD dwVersion = GetVersion(); - char *final; - char *current; + nsCAutoString final; + nsCAutoString current; - finalSpec->GetPath(&final); - currentSpec->GetPath(¤t); + finalSpec->GetNativePath(final); + currentSpec->GetNativePath(current); // Get build numbers for Windows NT or Win32s @@ -89,44 +87,39 @@ PRInt32 ReplaceWindowsSystemFile(nsIFile* currentSpec, nsIFile* finalSpec) char Src[_MAX_PATH]; // 8.3 name char Dest[_MAX_PATH]; // 8.3 name - strlen = GetShortPathName( (LPCTSTR)current, (LPTSTR)Src, (DWORD)sizeof(Src) ); + strlen = GetShortPathName( (LPCTSTR)current.get(), (LPTSTR)Src, (DWORD)sizeof(Src) ); if ( strlen > 0 ) { - free(current); - current = strdup(Src); + current = Src; } - strlen = GetShortPathName( (LPCTSTR) final, (LPTSTR) Dest, (DWORD) sizeof(Dest)); + strlen = GetShortPathName( (LPCTSTR) final.get(), (LPTSTR) Dest, (DWORD) sizeof(Dest)); if ( strlen > 0 ) { - free(final); - final = strdup(Dest); + final = Dest; } // NOTE: use OEM filenames! Even though it looks like a Windows // .INI file, WININIT.INI is processed under DOS - AnsiToOem( final, final ); - AnsiToOem( current, current ); + AnsiToOem( (char*)final.get(), (char*)final.get() ); + AnsiToOem( (char*)current.get(), (char*)current.get() ); - if ( WritePrivateProfileString( "Rename", final, current, "WININIT.INI" ) ) + if ( WritePrivateProfileString( "Rename", final.get(), current.get(), "WININIT.INI" ) ) err = 0; } else { // Windows NT - if ( MoveFileEx(final, current, MOVEFILE_DELAY_UNTIL_REBOOT) ) + if ( MoveFileEx(final.get(), current.get(), MOVEFILE_DELAY_UNTIL_REBOOT) ) err = 0; } - - free(final); - free(current); return err; } #endif -char* GetRegFilePath() +nsresult GetRegFilePath(nsACString ®FilePath) { nsresult rv; nsCOMPtr iFileUtilityPath; @@ -162,10 +155,7 @@ char* GetRegFilePath() //Yes, we know using GetPath is buggy on the Mac. //When libreg is fixed to accept nsIFiles we'll change this to match. - char* regFilePath; - iFileUtilityPath->GetPath(®FilePath); - - return regFilePath; + return iFileUtilityPath->GetNativePath(regFilePath); } @@ -191,10 +181,9 @@ PRInt32 ScheduleFileForDeletion(nsIFile *filename) REGERR err; PRInt32 result = nsInstall::UNEXPECTED_ERROR; - char* regFilePath = GetRegFilePath(); - err = NR_RegOpen(regFilePath, ®); - if (regFilePath) - nsCRT::free(regFilePath); + nsCAutoString path; + GetRegFilePath(path); + err = NR_RegOpen((char*)path.get(), ®); if ( err == REGERR_OK ) { @@ -206,12 +195,11 @@ PRInt32 ScheduleFileForDeletion(nsIFile *filename) err = NR_RegGetUniqueName( reg, valname, sizeof(valname) ); if ( err == REGERR_OK ) { - nsXPIDLCString nameowner; - nsresult rv = GetPersistentStringFromSpec( - filename,getter_Copies(nameowner)); - if ( NS_SUCCEEDED(rv) && nameowner ) + nsCAutoString nameowner; + nsresult rv = GetPersistentStringFromSpec(filename, nameowner); + if ( NS_SUCCEEDED(rv) && !nameowner.IsEmpty() ) { - const char *fnamestr = nameowner; + const char *fnamestr = nameowner.get(); err = NR_RegSetEntry( reg, newkey, valname, REGTYPE_ENTRY_BYTES, (void*)fnamestr, @@ -257,7 +245,7 @@ PRInt32 ReplaceFileNow(nsIFile* replacementFile, nsIFile* doomedFile ) nsCOMPtr renamedDoomedFile; nsCOMPtr tmpLocalFile; nsCOMPtr parent; - nsXPIDLCString leafname; + nsCAutoString leafname; doomedFile->Clone(getter_AddRefs(renamedDoomedFile)); renamedDoomedFile->Exists(&flagExists); @@ -266,36 +254,35 @@ PRInt32 ReplaceFileNow(nsIFile* replacementFile, nsIFile* doomedFile ) tmpLocalFile = do_QueryInterface(renamedDoomedFile, &rv); // Convert to an nsILocalFile //get the leafname so we can convert its extension to .old - nsXPIDLCString uniqueLeafName; - tmpLocalFile->GetLeafName(getter_Copies(leafname)); - nsCString newLeafName (leafname); + nsCAutoString uniqueLeafName; + tmpLocalFile->GetNativeLeafName(leafname); - PRInt32 extpos = newLeafName.RFindChar('.'); + PRInt32 extpos = leafname.RFindChar('.'); if (extpos != -1) { // We found the extension; - newLeafName.Truncate(extpos + 1); //strip off the old extension + leafname.Truncate(extpos + 1); //strip off the old extension } - newLeafName.Append("old"); + leafname.Append("old"); //Now reset the leafname - tmpLocalFile->SetLeafName(newLeafName.get()); + tmpLocalFile->SetNativeLeafName(leafname); MakeUnique(tmpLocalFile); // for the call to MakeUnique tmpLocalFile->GetParent(getter_AddRefs(parent)); //get the parent for later use in MoveTo - tmpLocalFile->GetLeafName(getter_Copies(uniqueLeafName));//this is the new "unique" leafname + tmpLocalFile->GetNativeLeafName(uniqueLeafName);//this is the new "unique" leafname rv = doomedFile->Clone(getter_AddRefs(renamedDoomedFile));// Reset renamedDoomed file so doomedfile isn't // changed during the MoveTo call if (NS_FAILED(rv)) result = nsInstall::UNEXPECTED_ERROR; - rv = renamedDoomedFile->MoveTo(parent, uniqueLeafName); + rv = renamedDoomedFile->MoveToNative(parent, uniqueLeafName); if (NS_SUCCEEDED(rv)) { - renamedDoomedFile = parent; //MoveTo on Mac doesn't reset the tmpFile object to - renamedDoomedFile->Append(uniqueLeafName); //the new name or location. That's why there's this - //explict assignment and Append call. + renamedDoomedFile = parent; //MoveTo on Mac doesn't reset the tmpFile object to + renamedDoomedFile->AppendNative(uniqueLeafName); //the new name or location. That's why there's this + //explict assignment and Append call. } if (result == nsInstall::UNEXPECTED_ERROR) @@ -321,13 +308,13 @@ PRInt32 ReplaceFileNow(nsIFile* replacementFile, nsIFile* doomedFile ) if(!flagIsEqual) { NS_WARNING("File unpacked into a non-dest dir" ); - replacementFile->GetLeafName(getter_Copies(leafname)); - rv = replacementFile->MoveTo(parentofFinalFile, leafname); + replacementFile->GetNativeLeafName(leafname); + rv = replacementFile->MoveToNative(parentofFinalFile, leafname); } - rv = doomedFile->GetLeafName(getter_Copies(leafname)); + rv = doomedFile->GetNativeLeafName(leafname); if ( NS_SUCCEEDED(rv)) - rv = replacementFile->MoveTo(parentofReplacementFile, leafname ); + rv = replacementFile->MoveToNative(parentofReplacementFile, leafname ); if ( NS_SUCCEEDED(rv) ) { @@ -339,7 +326,7 @@ PRInt32 ReplaceFileNow(nsIFile* replacementFile, nsIFile* doomedFile ) { // couldn't rename file, try to put old file back renamedDoomedFile->GetParent(getter_AddRefs(parent)); - renamedDoomedFile->MoveTo(parent, leafname); + renamedDoomedFile->MoveToNative(parent, leafname); } } @@ -368,8 +355,9 @@ PRInt32 ReplaceFileNowOrSchedule(nsIFile* replacementFile, nsIFile* doomedFile, HREG reg; REGERR err; - char* regFilePath = GetRegFilePath(); - if ( REGERR_OK == NR_RegOpen(regFilePath, ®) ) + nsCAutoString regFilePath; + GetRegFilePath(regFilePath); + if ( REGERR_OK == NR_RegOpen((char*)regFilePath.get(), ®) ) { err = NR_RegAddKey( reg, ROOTKEY_PRIVATE, REG_REPLACE_LIST_KEY, &listkey ); if ( err == REGERR_OK ) @@ -383,17 +371,14 @@ PRInt32 ReplaceFileNowOrSchedule(nsIFile* replacementFile, nsIFile* doomedFile, err = NR_RegAddKey( reg, listkey, valname, &filekey ); if ( REGERR_OK == err ) { - nsXPIDLCString srcowner; - nsXPIDLCString destowner; - nsresult rv = GetPersistentStringFromSpec( - replacementFile, getter_Copies(srcowner)); - nsresult rv2 = GetPersistentStringFromSpec( - doomedFile, getter_Copies(destowner)); + nsCAutoString srcowner; + nsCAutoString destowner; + nsresult rv = GetPersistentStringFromSpec(replacementFile, srcowner); + nsresult rv2 = GetPersistentStringFromSpec(doomedFile, destowner); if ( NS_SUCCEEDED(rv) && NS_SUCCEEDED(rv2) ) { - - const char *fsrc = srcowner; - const char *fdest = destowner; + const char *fsrc = srcowner.get(); + const char *fdest = destowner.get(); err = NR_RegSetEntry( reg, filekey, REG_REPLACE_SRCFILE, REGTYPE_ENTRY_BYTES, @@ -419,8 +404,6 @@ PRInt32 ReplaceFileNowOrSchedule(nsIFile* replacementFile, nsIFile* doomedFile, } NR_RegClose(reg); } - if (regFilePath) - nsCRT::free(regFilePath); } return result; @@ -477,7 +460,7 @@ void DeleteScheduledFiles( HREG reg ) // no need to check return value of // SetPersistentDescriptorString, it's always NS_OK //spec->SetPersistentDescriptorString(valbuf); //nsIFileXXX: Do we still need this instead of InitWithPath? - NS_NewLocalFile((char*)valbuf, PR_TRUE, getter_AddRefs(spec)); + NS_NewNativeLocalFile(nsDependentCString(valbuf), PR_TRUE, getter_AddRefs(spec)); spec->Clone(getter_AddRefs(doomedFile)); if (NS_SUCCEEDED(rv)) { @@ -538,10 +521,10 @@ void ReplaceScheduledFiles( HREG reg ) if ( err1 == REGERR_OK && err2 == REGERR_OK ) { - rv1 = NS_NewLocalFile((char*)srcFile, PR_TRUE, getter_AddRefs(src)); + rv1 = NS_NewNativeLocalFile(nsDependentCString(srcFile), PR_TRUE, getter_AddRefs(src)); rv1 = src->Clone(getter_AddRefs(srcSpec)); - rv2 = NS_NewLocalFile((char*)doomedFile, PR_TRUE, getter_AddRefs(dest)); + rv2 = NS_NewNativeLocalFile(nsDependentCString(doomedFile), PR_TRUE, getter_AddRefs(dest)); rv2 = dest->Clone(getter_AddRefs(doomedSpec)); if (NS_SUCCEEDED(rv1) && NS_SUCCEEDED(rv2)) diff --git a/mozilla/xpinstall/src/nsInstall.cpp b/mozilla/xpinstall/src/nsInstall.cpp index 0ca081831c7..eb4b1c1b0cd 100644 --- a/mozilla/xpinstall/src/nsInstall.cpp +++ b/mozilla/xpinstall/src/nsInstall.cpp @@ -708,7 +708,7 @@ nsInstall::DiskSpaceAvailable(const nsString& aFolder, PRInt64* aReturn) return NS_OK; } nsCOMPtr folder; - NS_NewLocalFile(NS_LossyConvertUCS2toASCII(aFolder).get(), PR_TRUE, + NS_NewLocalFile(NS_ConvertUCS2toUTF8(aFolder), PR_TRUE, getter_AddRefs(folder)); result = folder->GetDiskSpaceAvailable(aReturn); @@ -1795,7 +1795,7 @@ nsInstall::FileOpFileGetNativeVersion(nsInstallFolder& aTarget, nsString* aRetur #ifdef XP_WIN PRBool flagExists; - nsCOMPtr localTarget(aTarget.GetFileSpec()); + nsCOMPtr localTarget(do_QueryInterface(aTarget.GetFileSpec())); UINT uLen; UINT dwLen; DWORD dwHandle; @@ -1806,7 +1806,7 @@ nsInstall::FileOpFileGetNativeVersion(nsInstallFolder& aTarget, nsString* aRetur DWORD dwMinor = 0; DWORD dwRelease = 0; DWORD dwBuild = 0; - nsXPIDLCString nativeTargetPath; + nsCAutoString nativeTargetPath; char *nativeVersionString = nsnull; if(localTarget == nsnull) @@ -1816,7 +1816,7 @@ nsInstall::FileOpFileGetNativeVersion(nsInstallFolder& aTarget, nsString* aRetur localTarget->Exists(&flagExists); if(flagExists) { - localTarget->GetPath(getter_Copies(nativeTargetPath)); + localTarget->GetNativePath(nativeTargetPath); uLen = 0; /* GetFileVersionInfoSize() requires a char *, but the api doesn't * indicate that it will modify it */ @@ -2033,7 +2033,7 @@ nsInstall::FileOpFileWindowsGetShortName(nsInstallFolder& aTarget, nsString& aSh PRInt32 err; PRBool flagExists; nsString tmpNsString; - nsXPIDLCString nativeTargetPath; + nsCAutoString nativeTargetPath; char nativeShortPathName[MAX_PATH]; nsCOMPtr localTarget(aTarget.GetFileSpec()); @@ -2044,9 +2044,9 @@ nsInstall::FileOpFileWindowsGetShortName(nsInstallFolder& aTarget, nsString& aSh if(flagExists) { memset(nativeShortPathName, 0, MAX_PATH); - localTarget->GetPath(getter_Copies(nativeTargetPath)); + localTarget->GetNativePath(nativeTargetPath); - err = GetShortPathName(nativeTargetPath, nativeShortPathName, MAX_PATH); + err = GetShortPathName(nativeTargetPath.get(), nativeShortPathName, MAX_PATH); if((err > 0) && (*nativeShortPathName == '\0')) { // NativeShortPathName buffer not big enough. @@ -2056,7 +2056,7 @@ nsInstall::FileOpFileWindowsGetShortName(nsInstallFolder& aTarget, nsString& aSh if(nativeShortPathNameTmp == nsnull) return NS_OK; - err = GetShortPathName(nativeTargetPath, nativeShortPathNameTmp, err + 1); + err = GetShortPathName(nativeTargetPath.get(), nativeShortPathNameTmp, err + 1); // Is it safe to assume that the second time around the buffer is big enough // and not to worry about it unless it's a different problem? @@ -2576,7 +2576,7 @@ nsInstall::ExtractFileFromJar(const nsString& aJarfile, nsIFile* aSuggestedName, directoryService->Get(NS_OS_TEMP_DIR, NS_GET_IID(nsIFile), getter_AddRefs(tempFile)); - nsString tempFileName(NS_LITERAL_STRING("xpinstall")); + nsAutoString tempFileName(NS_LITERAL_STRING("xpinstall")); // Get the extension of the file in the JAR extpos = aJarfile.RFindChar('.'); @@ -2587,7 +2587,7 @@ nsInstall::ExtractFileFromJar(const nsString& aJarfile, nsIFile* aSuggestedName, aJarfile.Right(extension, (aJarfile.Length() - extpos) ); tempFileName += extension; } - tempFile->Append(NS_LossyConvertUCS2toASCII(tempFileName).get()); + tempFile->Append(NS_ConvertUCS2toUTF8(tempFileName)); // Create a temporary file to extract to MakeUnique(tempFile); @@ -2616,9 +2616,8 @@ nsInstall::ExtractFileFromJar(const nsString& aJarfile, nsIFile* aSuggestedName, return nsInstall::OUT_OF_MEMORY; //get the leafname so we can convert its extension to .new - nsXPIDLCString leafName; - tempFile->GetLeafName(getter_Copies(leafName)); - nsCString newLeafName (leafName); + nsCAutoString newLeafName; + tempFile->GetLeafName(newLeafName); PRInt32 extpos = newLeafName.RFindChar('.'); if (extpos != -1) @@ -2629,7 +2628,7 @@ nsInstall::ExtractFileFromJar(const nsString& aJarfile, nsIFile* aSuggestedName, newLeafName.Append("new"); //Now reset the leafname - tempFile->SetLeafName(newLeafName.get()); + tempFile->SetLeafName(newLeafName); MakeUnique(tempFile); extractHereSpec = tempFile; @@ -2797,6 +2796,7 @@ nsInstall::DeleteVector(nsVoidArray* vector) } } +// XXX what's wrong with nsIFile::createUnique? nsresult MakeUnique(nsILocalFile* file) { PRBool flagExists; @@ -2806,11 +2806,14 @@ nsresult MakeUnique(nsILocalFile* file) if (NS_FAILED(rv)) return rv; if (!flagExists) return NS_ERROR_FAILURE; - char* leafName; + nsCAutoString leafNameBuf; - rv = file->GetLeafName(&leafName); + rv = file->GetLeafName(leafNameBuf); if (NS_FAILED(rv)) return rv; + // XXX this code should use iterators + char *leafName = (char *) leafNameBuf.get(); + char* lastDot = strrchr(leafName, '.'); char* suffix = ""; if (lastDot) @@ -2830,7 +2833,7 @@ nsresult MakeUnique(nsILocalFile* file) // start with "Picture-1.jpg" after "Picture.jpg" exists char newName[32]; sprintf(newName, "%s-%d%s", leafName, indx, suffix); - file->SetLeafName(newName); + file->SetLeafName(nsDependentCString(newName)); rv = file->Exists(&flagExists); if (NS_FAILED(rv)) return rv; diff --git a/mozilla/xpinstall/src/nsInstallExecute.cpp b/mozilla/xpinstall/src/nsInstallExecute.cpp index fe98d167060..237ff8f53ac 100644 --- a/mozilla/xpinstall/src/nsInstallExecute.cpp +++ b/mozilla/xpinstall/src/nsInstallExecute.cpp @@ -270,9 +270,9 @@ char* nsInstallExecute::toString() if (rsrcVal) { - char* temp; - mExecutableFile->GetPath(&temp); - sprintf( buffer, rsrcVal, temp); + nsCAutoString temp; + mExecutableFile->GetNativePath(temp); + sprintf( buffer, rsrcVal, temp.get()); nsCRT::free(rsrcVal); } } diff --git a/mozilla/xpinstall/src/nsInstallFile.cpp b/mozilla/xpinstall/src/nsInstallFile.cpp index 736d9b51659..8710e62a206 100644 --- a/mozilla/xpinstall/src/nsInstallFile.cpp +++ b/mozilla/xpinstall/src/nsInstallFile.cpp @@ -140,7 +140,7 @@ nsInstallFile::nsInstallFile(nsInstall* inInstall, else { nsresult rv = inPartialPath.Mid(subString, offset, nodeLength); - mFinalFile->Append(NS_LossyConvertUCS2toASCII(subString).get()); + mFinalFile->Append(NS_ConvertUCS2toUTF8(subString)); offset += nodeLength + 1; if (!finished) location = inPartialPath.FindChar('/', offset); @@ -200,7 +200,7 @@ void nsInstallFile::CreateAllFolders(nsInstall *inInstall, nsIFile *inFolderPath inFolderPath->Exists(&flagExists); if(!flagExists) { - char *szPath = nsnull; + nsCAutoString szPath; inFolderPath->GetParent(getter_AddRefs(nsfsFolderPath)); CreateAllFolders(inInstall, nsfsFolderPath, error); @@ -208,9 +208,8 @@ void nsInstallFile::CreateAllFolders(nsInstall *inInstall, nsIFile *inFolderPath inFolderPath->Create(nsIFile::DIRECTORY_TYPE, 0755); //nsIFileXXX: What kind of permissions are required here? ++mFolderCreateCount; - inFolderPath->GetPath(&szPath); - nsStrFolder.AssignWithConversion(szPath); - nsMemory::Free(szPath); + inFolderPath->GetPath(szPath); + nsStrFolder.Assign(NS_ConvertUTF8toUCS2(szPath)); ilc = new nsInstallLogComment(inInstall, NS_LITERAL_STRING("CreateFolder"), nsStrFolder, error); if(ilc == nsnull) *error = nsInstall::OUT_OF_MEMORY; @@ -293,8 +292,8 @@ PRInt32 nsInstallFile::Complete() if ( mRegister && (0 == err || nsInstall::REBOOT_NEEDED == err) ) { - nsXPIDLCString path; - mFinalFile->GetPath(getter_Copies(path)); + nsCAutoString path; + mFinalFile->GetNativePath(path); VR_Install( NS_CONST_CAST(char*, NS_ConvertUCS2toUTF8(*mVersionRegistryName).get()), NS_CONST_CAST(char*, path.get()), NS_CONST_CAST(char*, NS_ConvertUCS2toUTF8(*mVersionInfo).get()), @@ -358,9 +357,9 @@ char* nsInstallFile::toString() if(interimCStr) { - nsXPIDLCString fname; + nsCAutoString fname; if (mFinalFile) - mFinalFile->GetPath(getter_Copies(fname)); + mFinalFile->GetNativePath(fname); PR_snprintf( buffer, RESBUFSIZE, interimCStr, fname.get() ); Recycle(interimCStr); @@ -396,9 +395,9 @@ PRInt32 nsInstallFile::CompleteFileMove() if(mMode & WIN_SHARED_FILE) { - nsXPIDLCString path; - mFinalFile->GetPath(getter_Copies(path)); - RegisterSharedFile(path, mReplaceFile); + nsCAutoString path; + mFinalFile->GetNativePath(path); + RegisterSharedFile(path.get(), mReplaceFile); } return result; diff --git a/mozilla/xpinstall/src/nsInstallFileOpItem.cpp b/mozilla/xpinstall/src/nsInstallFileOpItem.cpp index 71a487d1a00..0c116d3ed17 100644 --- a/mozilla/xpinstall/src/nsInstallFileOpItem.cpp +++ b/mozilla/xpinstall/src/nsInstallFileOpItem.cpp @@ -302,9 +302,9 @@ char* nsInstallFileOpItem::toString() nsString result; char* resultCString = new char[RESBUFSIZE]; char* rsrcVal = nsnull; - char* temp; - char* srcPath; - char* dstPath; + nsCAutoString temp; + nsCAutoString srcPath; + nsCAutoString dstPath; // STRING USE WARNING: perhaps |result| should be an |nsCAutoString| to avoid all this double converting *resultCString = nsnull; @@ -314,115 +314,106 @@ char* nsInstallFileOpItem::toString() if((mSrc == nsnull) || (mTarget == nsnull)) break; - mSrc->GetPath(&srcPath); - mTarget->GetPath(&dstPath); + mSrc->GetNativePath(srcPath); + mTarget->GetNativePath(dstPath); rsrcVal = mInstall->GetResourcedString(NS_LITERAL_STRING("CopyFile")); if(rsrcVal != nsnull) - PR_snprintf(resultCString, RESBUFSIZE, rsrcVal, srcPath, dstPath ); + PR_snprintf(resultCString, RESBUFSIZE, rsrcVal, srcPath.get(), dstPath.get() ); break; case NS_FOP_FILE_DELETE: if(mTarget == nsnull) break; - mTarget->GetPath(&dstPath); + mTarget->GetNativePath(dstPath); rsrcVal = mInstall->GetResourcedString(NS_LITERAL_STRING("DeleteFile")); if(rsrcVal != nsnull) - PR_snprintf(resultCString, RESBUFSIZE, rsrcVal, dstPath ); + PR_snprintf(resultCString, RESBUFSIZE, rsrcVal, dstPath.get() ); break; case NS_FOP_FILE_EXECUTE: if(mTarget == nsnull) break; - mTarget->GetPath(&dstPath); + mTarget->GetNativePath(dstPath); - temp = ToNewCString(*mParams); - if((temp != nsnull) && (*temp != '\0')) + temp = NS_ConvertUCS2toUTF8(*mParams); + if(!temp.IsEmpty()) { rsrcVal = mInstall->GetResourcedString(NS_LITERAL_STRING("ExecuteWithArgs")); if(rsrcVal != nsnull) - PR_snprintf(resultCString, RESBUFSIZE, rsrcVal, dstPath, temp); + PR_snprintf(resultCString, RESBUFSIZE, rsrcVal, dstPath.get(), temp.get()); } else { rsrcVal = mInstall->GetResourcedString(NS_LITERAL_STRING("Execute")); if(rsrcVal != nsnull) - PR_snprintf(resultCString, RESBUFSIZE, rsrcVal, dstPath); + PR_snprintf(resultCString, RESBUFSIZE, rsrcVal, dstPath.get()); } - - if(temp != nsnull) - Recycle(temp); - + temp.Truncate(); break; case NS_FOP_FILE_MOVE: if((mSrc == nsnull) || (mTarget == nsnull)) break; - mSrc->GetPath(&srcPath); - mTarget->GetPath(&dstPath); + mSrc->GetNativePath(srcPath); + mTarget->GetNativePath(dstPath); rsrcVal = mInstall->GetResourcedString(NS_LITERAL_STRING("MoveFile")); if(rsrcVal != nsnull) - PR_snprintf(resultCString, RESBUFSIZE, rsrcVal, srcPath, dstPath ); + PR_snprintf(resultCString, RESBUFSIZE, rsrcVal, srcPath.get(), dstPath.get()); break; case NS_FOP_FILE_RENAME: if((mSrc == nsnull) || (mTarget == nsnull)) break; - mSrc->GetPath(&srcPath); - mTarget->GetPath(&dstPath); + mSrc->GetNativePath(srcPath); + mTarget->GetNativePath(dstPath); rsrcVal = mInstall->GetResourcedString(NS_LITERAL_STRING("RenameFile")); if(rsrcVal != nsnull) - PR_snprintf(resultCString, RESBUFSIZE, rsrcVal, srcPath, dstPath ); + PR_snprintf(resultCString, RESBUFSIZE, rsrcVal, srcPath.get(), dstPath.get()); break; case NS_FOP_DIR_CREATE: if(mTarget == nsnull) break; - mTarget->GetPath(&dstPath); + mTarget->GetNativePath(dstPath); rsrcVal = mInstall->GetResourcedString(NS_LITERAL_STRING("CreateFolder")); if(rsrcVal != nsnull) - PR_snprintf(resultCString, RESBUFSIZE, rsrcVal, dstPath ); + PR_snprintf(resultCString, RESBUFSIZE, rsrcVal, dstPath.get()); break; case NS_FOP_DIR_REMOVE: if(mTarget == nsnull) break; - mTarget->GetPath(&dstPath); + mTarget->GetNativePath(dstPath); rsrcVal = mInstall->GetResourcedString(NS_LITERAL_STRING("RemoveFolder")); if(rsrcVal != nsnull) - PR_snprintf(resultCString, RESBUFSIZE, rsrcVal, dstPath ); + PR_snprintf(resultCString, RESBUFSIZE, rsrcVal, dstPath.get()); break; case NS_FOP_DIR_RENAME: if((mSrc == nsnull) || (mTarget == nsnull)) break; - mSrc->GetPath(&srcPath); - mTarget->GetPath(&dstPath); + mSrc->GetNativePath(srcPath); + mTarget->GetNativePath(dstPath); rsrcVal = mInstall->GetResourcedString(NS_LITERAL_STRING("RenameFolder")); if(rsrcVal != nsnull) - PR_snprintf(resultCString, RESBUFSIZE, rsrcVal, srcPath, dstPath ); + PR_snprintf(resultCString, RESBUFSIZE, rsrcVal, srcPath.get(), dstPath.get()); break; case NS_FOP_WIN_SHORTCUT: rsrcVal = mInstall->GetResourcedString(NS_LITERAL_STRING("WindowsShortcut")); if(rsrcVal && mShortcutPath) { - mShortcutPath->GetPath(&temp); - result.AssignWithConversion(temp); - result.Append(NS_LITERAL_STRING("\\")); - result.Append(*mDescription); - dstPath = ToNewCString(result); - if(dstPath) - { - PR_snprintf(resultCString, RESBUFSIZE, rsrcVal, dstPath ); - Recycle(dstPath); - } + mShortcutPath->GetNativePath(temp); + temp.Append(NS_LITERAL_CSTRING("\\") + NS_LossyConvertUCS2toASCII(*mDescription)); + PR_snprintf(resultCString, RESBUFSIZE, rsrcVal, temp.get()); + temp.Truncate(); } break; @@ -430,10 +421,10 @@ char* nsInstallFileOpItem::toString() if(mTarget == nsnull) break; - mTarget->GetPath(&dstPath); + mTarget->GetNativePath(dstPath); rsrcVal = mInstall->GetResourcedString(NS_LITERAL_STRING("MacAlias")); if(rsrcVal != nsnull) - PR_snprintf(resultCString, RESBUFSIZE, rsrcVal, dstPath ); + PR_snprintf(resultCString, RESBUFSIZE, rsrcVal, dstPath.get()); break; case NS_FOP_UNIX_LINK: @@ -443,10 +434,10 @@ char* nsInstallFileOpItem::toString() if(mTarget == nsnull) break; - mTarget->GetPath(&dstPath); + mTarget->GetNativePath(dstPath); rsrcVal = mInstall->GetResourcedString(NS_LITERAL_STRING("WindowsRegisterServer")); if(rsrcVal != nsnull) - PR_snprintf(resultCString, RESBUFSIZE, rsrcVal, dstPath ); + PR_snprintf(resultCString, RESBUFSIZE, rsrcVal, dstPath.get()); break; default: @@ -677,7 +668,7 @@ nsInstallFileOpItem::NativeFileOpFileRenamePrepare() mSrc->GetParent(&target); nsresult rv = - target->Append(NS_LossyConvertUCS2toASCII(*mStrTarget).get()); + target->Append(NS_ConvertUCS2toUTF8(*mStrTarget)); //90% of the failures during Append will be because the target wasn't in string form // which it must be. if (NS_FAILED(rv)) return nsInstall::INVALID_ARGUMENTS; @@ -717,7 +708,7 @@ nsInstallFileOpItem::NativeFileOpFileRenameComplete() if (target) { - target->Append(NS_LossyConvertUCS2toASCII(*mStrTarget).get()); + target->Append(NS_ConvertUCS2toUTF8(*mStrTarget)); } else return nsInstall::UNEXPECTED_ERROR; @@ -726,7 +717,7 @@ nsInstallFileOpItem::NativeFileOpFileRenameComplete() if(!flagExists) { mSrc->MoveTo(parent, - NS_LossyConvertUCS2toASCII(*mStrTarget).get()); + NS_ConvertUCS2toUTF8(*mStrTarget)); } else return nsInstall::ALREADY_EXISTS; @@ -748,7 +739,7 @@ nsInstallFileOpItem::NativeFileOpFileRenameAbort() { PRInt32 ret = nsInstall::SUCCESS; PRBool flagExists; - char* leafName; + nsCAutoString leafName; nsCOMPtr newFilename; nsCOMPtr parent; @@ -761,14 +752,11 @@ nsInstallFileOpItem::NativeFileOpFileRenameAbort() mSrc->GetParent(getter_AddRefs(parent)); if(parent) { - newFilename->Append(NS_LossyConvertUCS2toASCII(*mStrTarget).get()); + newFilename->Append(NS_ConvertUCS2toUTF8(*mStrTarget)); - mSrc->GetLeafName(&leafName); + mSrc->GetLeafName(leafName); newFilename->MoveTo(parent, leafName); - - if(leafName) - nsCRT::free(leafName); } else return nsInstall::UNEXPECTED_ERROR; @@ -784,7 +772,7 @@ PRInt32 nsInstallFileOpItem::NativeFileOpFileCopyPrepare() { PRBool flagExists, flagIsFile, flagIsWritable; - char* leafName; + nsCAutoString leafName; nsresult rv; nsCOMPtr tempVar; nsCOMPtr targetParent; @@ -824,7 +812,7 @@ nsInstallFileOpItem::NativeFileOpFileCopyPrepare() else { mTarget->Clone(getter_AddRefs(tempVar)); - mSrc->GetLeafName(&leafName); + mSrc->GetLeafName(leafName); tempVar->Append(leafName); tempVar->Exists(&flagExists); if(flagExists) @@ -851,7 +839,7 @@ nsInstallFileOpItem::NativeFileOpFileCopyComplete() { PRInt32 rv = NS_OK; PRBool flagIsFile, flagExists; - char* leafName; + nsCAutoString leafName; nsCOMPtr parent; nsCOMPtr tempTarget; @@ -867,13 +855,13 @@ nsInstallFileOpItem::NativeFileOpFileCopyComplete() if (NS_FAILED(rv)) return rv; rv = mTarget->GetParent(getter_AddRefs(parent)); if (NS_FAILED(rv)) return rv; - rv = mTarget->GetLeafName(&leafName); + rv = mTarget->GetLeafName(leafName); if (NS_FAILED(rv)) return rv; rv = mSrc->CopyTo(parent, leafName); } else //Target is a directory { - rv = mSrc->GetLeafName(&leafName); + rv = mSrc->GetLeafName(leafName); if (NS_FAILED(rv)) return rv; rv = mTarget->Clone(getter_AddRefs(tempTarget)); if (NS_FAILED(rv)) return rv; @@ -890,7 +878,7 @@ nsInstallFileOpItem::NativeFileOpFileCopyComplete() { mTarget->GetParent(getter_AddRefs(parent)); if (NS_FAILED(rv)) return rv; - mTarget->GetLeafName(&leafName); + mTarget->GetLeafName(leafName); if (NS_FAILED(rv)) return rv; rv = mSrc->CopyTo(parent, leafName); } @@ -910,8 +898,8 @@ nsInstallFileOpItem::NativeFileOpFileCopyAbort() mTarget->Clone(getter_AddRefs(fullTarget)); if(nsInstallFileOpItem::ACTION_SUCCESS == mAction) { - char* leafName; - mSrc->GetLeafName(&leafName); + nsCAutoString leafName; + mSrc->GetLeafName(leafName); fullTarget->Append(leafName); fullTarget->Remove(PR_FALSE); } @@ -1062,10 +1050,10 @@ nsInstallFileOpItem::NativeFileOpFileMovePrepare() else { nsCOMPtr tempVar; - char* leaf; + nsCAutoString leaf; mTarget->Clone(getter_AddRefs(tempVar)); - mSrc->GetLeafName(&leaf); + mSrc->GetLeafName(leaf); tempVar->Append(leaf); tempVar->Exists(&flagExists); @@ -1176,7 +1164,7 @@ nsInstallFileOpItem::NativeFileOpDirRenamePrepare() nsCOMPtr target; mSrc->GetParent(getter_AddRefs(target)); - target->Append(NS_LossyConvertUCS2toASCII(*mStrTarget).get()); + target->Append(NS_ConvertUCS2toUTF8(*mStrTarget)); target->Exists(&flagExists); if(flagExists) @@ -1206,7 +1194,7 @@ nsInstallFileOpItem::NativeFileOpDirRenameComplete() nsCOMPtr target; mSrc->GetParent(getter_AddRefs(target)); - target->Append(NS_LossyConvertUCS2toASCII(*mStrTarget).get()); + target->Append(NS_ConvertUCS2toUTF8(*mStrTarget)); target->Exists(&flagExists); if(!flagExists) @@ -1214,7 +1202,7 @@ nsInstallFileOpItem::NativeFileOpDirRenameComplete() nsCOMPtr parent; mSrc->GetParent(getter_AddRefs(parent)); ret = mSrc->MoveTo(parent, - NS_LossyConvertUCS2toASCII(*mStrTarget).get()); + NS_ConvertUCS2toUTF8(*mStrTarget)); } else return nsInstall::ALREADY_EXISTS; @@ -1233,7 +1221,7 @@ nsInstallFileOpItem::NativeFileOpDirRenameAbort() { PRBool flagExists; PRInt32 ret = nsInstall::SUCCESS; - char* leafName; + nsCAutoString leafName; nsCOMPtr newDirName; nsCOMPtr parent; @@ -1241,13 +1229,10 @@ nsInstallFileOpItem::NativeFileOpDirRenameAbort() if(!flagExists) { mSrc->GetParent(getter_AddRefs(newDirName)); - newDirName->Append(NS_LossyConvertUCS2toASCII(*mStrTarget).get()); - mSrc->GetLeafName(&leafName); + newDirName->Append(NS_ConvertUCS2toUTF8(*mStrTarget)); + mSrc->GetLeafName(leafName); mSrc->GetParent(getter_AddRefs(parent)); ret = newDirName->MoveTo(parent, leafName); - - if(leafName) - nsCRT::free(leafName); } return ret; @@ -1275,7 +1260,7 @@ nsInstallFileOpItem::NativeFileOpWindowsShortcutPrepare() } else { - tempVar->Append("NSTestDir"); + tempVar->Append(NS_LITERAL_CSTRING("NSTestDir")); tempVar->Create(1, 0755); tempVar->Exists(&flagExists); if(!flagExists) @@ -1301,10 +1286,10 @@ nsInstallFileOpItem::NativeFileOpWindowsShortcutComplete() #ifdef _WINDOWS char *cDescription = nsnull; char *cParams = nsnull; - char *targetNativePathStr = nsnull; - char *shortcutNativePathStr = nsnull; - char *workingpathNativePathStr = nsnull; - char *iconNativePathStr = nsnull; + nsCAutoString targetNativePathStr; + nsCAutoString shortcutNativePathStr; + nsCAutoString workingpathNativePathStr; + nsCAutoString iconNativePathStr; if(mDescription) cDescription = ToNewCString(*mDescription); @@ -1316,20 +1301,20 @@ nsInstallFileOpItem::NativeFileOpWindowsShortcutComplete() else { if(mTarget) - mTarget->GetPath(&targetNativePathStr); + mTarget->GetNativePath(targetNativePathStr); if(mShortcutPath) - mShortcutPath->GetPath(&shortcutNativePathStr); + mShortcutPath->GetNativePath(shortcutNativePathStr); if(mWorkingPath) - mWorkingPath->GetPath(&workingpathNativePathStr); + mWorkingPath->GetNativePath(workingpathNativePathStr); if(mIcon) - mIcon->GetPath(&iconNativePathStr); + mIcon->GetNativePath(iconNativePathStr); - CreateALink(targetNativePathStr, - shortcutNativePathStr, + CreateALink(targetNativePathStr.get(), + shortcutNativePathStr.get(), cDescription, - workingpathNativePathStr, + workingpathNativePathStr.get(), cParams, - iconNativePathStr, + iconNativePathStr.get(), mIconId); mAction = nsInstallFileOpItem::ACTION_SUCCESS; @@ -1356,7 +1341,7 @@ nsInstallFileOpItem::NativeFileOpWindowsShortcutAbort() shortcutDescription = *mDescription; shortcutDescription.Append(NS_LITERAL_STRING(".lnk")); mShortcutPath->Clone(getter_AddRefs(shortcutTarget)); - shortcutTarget->Append(NS_LossyConvertUCS2toASCII(shortcutDescription).get()); + shortcutTarget->Append(NS_ConvertUCS2toUTF8(shortcutDescription)); NativeFileOpFileDeleteComplete(shortcutTarget); } @@ -1489,14 +1474,14 @@ nsInstallFileOpItem::NativeFileOpWindowsRegisterServerPrepare() PRInt32 rv = nsInstall::SUCCESS; #ifdef _WINDOWS - char *file = nsnull; + nsCAutoString file; FARPROC DllReg; HINSTANCE hLib; - mTarget->GetPath(&file); - if(file != nsnull) + mTarget->GetNativePath(file); + if(!file.IsEmpty()) { - if((hLib = LoadLibraryEx(file, NULL, LOAD_WITH_ALTERED_SEARCH_PATH)) != NULL) + if((hLib = LoadLibraryEx(file.get(), NULL, LOAD_WITH_ALTERED_SEARCH_PATH)) != NULL) { if((DllReg = GetProcAddress(hLib, "DllRegisterServer")) == NULL) rv = nsInstall::UNABLE_TO_LOCATE_LIB_FUNCTION; @@ -1519,14 +1504,14 @@ nsInstallFileOpItem::NativeFileOpWindowsRegisterServerComplete() PRInt32 rv = nsInstall::SUCCESS; #ifdef _WINDOWS - char *file = nsnull; + nsCAutoString file; FARPROC DllReg; HINSTANCE hLib; - mTarget->GetPath(&file); - if(file != nsnull) + mTarget->GetNativePath(file); + if(!file.IsEmpty()) { - if((hLib = LoadLibraryEx(file, NULL, LOAD_WITH_ALTERED_SEARCH_PATH)) != NULL) + if((hLib = LoadLibraryEx(file.get(), NULL, LOAD_WITH_ALTERED_SEARCH_PATH)) != NULL) { if((DllReg = GetProcAddress(hLib, "DllRegisterServer")) != NULL) DllReg(); @@ -1551,14 +1536,14 @@ nsInstallFileOpItem::NativeFileOpWindowsRegisterServerAbort() PRInt32 rv = nsInstall::SUCCESS; #ifdef _WINDOWS - char *file = nsnull; + nsCAutoString file; FARPROC DllUnReg; HINSTANCE hLib; - mTarget->GetPath(&file); - if(file != nsnull) + mTarget->GetNativePath(file); + if(!file.IsEmpty()) { - if((hLib = LoadLibraryEx(file, NULL, LOAD_WITH_ALTERED_SEARCH_PATH)) != NULL) + if((hLib = LoadLibraryEx(file.get(), NULL, LOAD_WITH_ALTERED_SEARCH_PATH)) != NULL) { if((DllUnReg = GetProcAddress(hLib, "DllUnregisterServer")) != NULL) DllUnReg(); diff --git a/mozilla/xpinstall/src/nsInstallFolder.cpp b/mozilla/xpinstall/src/nsInstallFolder.cpp index bab8ca50187..9190f52ce57 100644 --- a/mozilla/xpinstall/src/nsInstallFolder.cpp +++ b/mozilla/xpinstall/src/nsInstallFolder.cpp @@ -139,14 +139,14 @@ void nsInstallFolder::GetDirectoryPath(nsCString& aDirectoryPath) { PRBool flagIsDir; - nsXPIDLCString thePath; + nsCAutoString thePath; aDirectoryPath.SetLength(0); if (mFileSpec != nsnull) { // We want the NATIVE path. - mFileSpec->GetPath(getter_Copies(thePath)); + mFileSpec->GetNativePath(thePath); aDirectoryPath.Assign(thePath); mFileSpec->IsDirectory(&flagIsDir); @@ -528,14 +528,12 @@ nsInstallFolder::AppendXPPath(const nsString& aRelativePath) start = curr+1; } - nsresult rv = mFileSpec->AppendUnicode(segment.get()); + nsresult rv = mFileSpec->Append(NS_ConvertUCS2toUTF8(segment)); if (NS_FAILED(rv)) { // Unicode converters not present (likely wizard case) // so do our best with the vanilla conversion. - nsCAutoString tmp; - tmp.AssignWithConversion(segment); - mFileSpec->Append(tmp.get()); + mFileSpec->AppendNative(NS_LossyConvertUCS2toASCII(segment)); } } while ( start < aRelativePath.Length() ); } @@ -581,11 +579,11 @@ nsInstallFolder::ToString(nsAutoString* outString) if (!mFileSpec || !outString) return NS_ERROR_NULL_POINTER; - nsXPIDLString tempUC; - nsresult rv = mFileSpec->GetUnicodePath(getter_Copies(tempUC)); + nsCAutoString temp; + nsresult rv = mFileSpec->GetPath(temp); if (NS_SUCCEEDED(rv)) { - outString->Assign(tempUC); + outString->Assign(NS_ConvertUTF8toUCS2(temp)); } else { @@ -594,9 +592,9 @@ nsInstallFolder::ToString(nsAutoString* outString) // XXX NOTE we can make sure our filenames are ASCII, but we have no // control over the directory name which might be localized!!! - nsXPIDLCString temp; - rv = mFileSpec->GetPath(getter_Copies(temp)); - outString->AssignWithConversion(temp); + nsCAutoString temp; + rv = mFileSpec->GetPath(temp); + outString->Assign(NS_ConvertUTF8toUCS2(temp)); } PRBool flagIsFile; diff --git a/mozilla/xpinstall/src/nsInstallFolder.h b/mozilla/xpinstall/src/nsInstallFolder.h index 7074863c9c6..65ee4f54422 100644 --- a/mozilla/xpinstall/src/nsInstallFolder.h +++ b/mozilla/xpinstall/src/nsInstallFolder.h @@ -35,13 +35,13 @@ #include "nsSpecialSystemDirectory.h" #ifdef XP_MAC -#define INSTALL_PLUGINS_DIR "Plug-ins" -#define INSTALL_COMPONENTS_DIR "Components" -#define INSTALL_CHROME_DIR "Chrome" +#define INSTALL_PLUGINS_DIR NS_LITERAL_CSTRING("Plug-ins") +#define INSTALL_COMPONENTS_DIR NS_LITERAL_CSTRING("Components") +#define INSTALL_CHROME_DIR NS_LITERAL_CSTRING("Chrome") #else -#define INSTALL_PLUGINS_DIR "plugins" -#define INSTALL_COMPONENTS_DIR "components" -#define INSTALL_CHROME_DIR "chrome" +#define INSTALL_PLUGINS_DIR NS_LITERAL_CSTRING("plugins") +#define INSTALL_COMPONENTS_DIR NS_LITERAL_CSTRING("components") +#define INSTALL_CHROME_DIR NS_LITERAL_CSTRING("chrome") #endif class nsInstallFolder diff --git a/mozilla/xpinstall/src/nsInstallPatch.cpp b/mozilla/xpinstall/src/nsInstallPatch.cpp index e620e97055d..0473a697388 100644 --- a/mozilla/xpinstall/src/nsInstallPatch.cpp +++ b/mozilla/xpinstall/src/nsInstallPatch.cpp @@ -43,6 +43,7 @@ #include "nsInstallPatch.h" #include "nsInstallResources.h" #include "nsIDOMInstallVersion.h" +#include "nsILocalFile.h" #include "gdiff.h" @@ -107,7 +108,7 @@ nsInstallPatch::nsInstallPatch( nsInstall* inInstall, nsString folderSpec; folderSpec.AssignWithConversion(tempTargetFile); nsCOMPtr tmp; - NS_NewLocalFile((char*)tempTargetFile, PR_TRUE, getter_AddRefs(tmp)); + NS_NewNativeLocalFile(nsDependentCString(tempTargetFile), PR_TRUE, getter_AddRefs(tmp)); mPatchFile = nsnull; mTargetFile = nsnull; @@ -175,7 +176,7 @@ nsInstallPatch::nsInstallPatch( nsInstall* inInstall, mVersionInfo->Init(inVInfo); if(! inPartialPath.IsEmpty()) - mTargetFile->Append(NS_LossyConvertUCS2toASCII(inPartialPath).get()); + mTargetFile->Append(NS_ConvertUCS2toUTF8(inPartialPath)); } nsInstallPatch::~nsInstallPatch() @@ -319,8 +320,8 @@ PRInt32 nsInstallPatch::Complete() nsString tempVersionString; mVersionInfo->ToString(tempVersionString); - nsXPIDLCString tempPath; - mTargetFile->GetPath(getter_Copies(tempPath)); + nsCAutoString tempPath; + mTargetFile->GetNativePath(tempPath); // DO NOT propagate version registry errors, it will abort // FinalizeInstall() leaving things hosed. These piddly errors @@ -374,9 +375,9 @@ char* nsInstallPatch::toString() if (rsrcVal) { - char* temp; - mTargetFile->GetPath(&temp); - sprintf( buffer, rsrcVal, temp); + nsCAutoString temp; + mTargetFile->GetNativePath(temp); + sprintf( buffer, rsrcVal, temp.get()); nsCRT::free(rsrcVal); } } @@ -414,8 +415,8 @@ nsInstallPatch::NativePatch(nsIFile *sourceFile, nsIFile *patchFile, nsIFile **n nsCOMPtr uniqueSrcFile; nsCOMPtr patchFileLocal = do_QueryInterface(patchFile, &rv); - char* realfile; - sourceFile->GetPath(&realfile); + nsCAutoString realfile; + sourceFile->GetPath(realfile); sourceFile->Clone(getter_AddRefs(outFileSpec)); @@ -449,20 +450,20 @@ nsInstallPatch::NativePatch(nsIFile *sourceFile, nsIFile *patchFile, nsIFile **n if (( dd->bWin32BoundImage || dd->bMacAppleSingle) && (status == GDIFF_OK )) { // make an unique tmp file (FILENAME-src.EXT) - char* leafName; - rv = sourceFile->GetLeafName(&leafName); + nsCAutoString leafName; + rv = sourceFile->GetLeafName(leafName); - nsString tmpName(NS_LITERAL_STRING("-src")); - nsString tmpFileName; tmpFileName.AssignWithConversion(leafName); + NS_NAMED_LITERAL_STRING(tmpName, "-src"); + NS_ConvertUTF8toUCS2 tmpFileName(leafName); PRInt32 i; if ((i = tmpFileName.RFindChar('.')) > 0) { - nsString ext; - nsString fName; + nsAutoString ext; + nsAutoString fName; tmpFileName.Right(ext, (tmpFileName.Length() - i) ); tmpFileName.Left(fName, (tmpFileName.Length() - (tmpFileName.Length() - i))); - tmpFileName = fName + tmpName + ext; + tmpFileName.Assign(fName + tmpName + ext); } else { tmpFileName += tmpName; @@ -470,29 +471,31 @@ nsInstallPatch::NativePatch(nsIFile *sourceFile, nsIFile *patchFile, nsIFile **n rv = sourceFile->Clone(getter_AddRefs(tempSrcFile)); //Clone the sourceFile - tempSrcFile->SetLeafName(NS_LossyConvertUCS2toASCII(tmpFileName).get()); //Append the new leafname + tempSrcFile->SetLeafName(NS_ConvertUCS2toUTF8(tmpFileName)); //Append the new leafname uniqueSrcFile = do_QueryInterface(tempSrcFile, &rv); //Create an nsILocalFile version to pass to MakeUnique MakeUnique(uniqueSrcFile); - char* realfile; - sourceFile->GetPath(&realfile); + nsCAutoString realfile; + sourceFile->GetPath(realfile); #ifdef WIN32 + nsCAutoString nativeFile; + sourceFile->GetNativePath(nativeFile); + // unbind Win32 images - char* unboundFile; - uniqueSrcFile->GetPath(&unboundFile); + nsCAutoString unboundFile; + uniqueSrcFile->GetNativePath(unboundFile); - if (su_unbind(realfile, unboundFile)) // + if (su_unbind((char*)nativeFile.get(), (char*)unboundFile.get())) // { - PL_strfree(realfile); - realfile = PL_strdup(unboundFile); + uniqueSrcFile->GetPath(realfile); } else { status = GDIFF_ERR_MEM; } - PL_strfree(unboundFile); + unboundFile.Truncate(); #endif #ifdef XP_MAC // Encode src file, and put into temp file @@ -506,8 +509,7 @@ nsInstallPatch::NativePatch(nsIFile *sourceFile, nsIFile *patchFile, nsIFile **n if (status == noErr) { // set - PL_strfree(realfile); - tempSrcFile->GetPath(&realfile); + tempSrcFile->GetPath(realfile); } #endif } @@ -516,16 +518,15 @@ nsInstallPatch::NativePatch(nsIFile *sourceFile, nsIFile *patchFile, nsIFile **n goto cleanup; // make a unique file at the same location of our source file (FILENAME-ptch.EXT) - nsString patchFileName(NS_LITERAL_STRING("-ptch")); - char* leafName; - sourceFile->GetLeafName(&leafName); - nsString newFileName; newFileName.AssignWithConversion(leafName);; + NS_NAMED_LITERAL_CSTRING(patchFileName, "-ptch"); + nsCAutoString newFileName; + sourceFile->GetLeafName(newFileName); PRInt32 index; if ((index = newFileName.RFindChar('.')) > 0) { - nsString extention; - nsString fileName; + nsCAutoString extention; + nsCAutoString fileName; newFileName.Right(extention, (newFileName.Length() - index) ); newFileName.Left(fileName, (newFileName.Length() - (newFileName.Length() - index))); newFileName = fileName + patchFileName + extention; @@ -537,7 +538,7 @@ nsInstallPatch::NativePatch(nsIFile *sourceFile, nsIFile *patchFile, nsIFile **n } - outFileSpec->SetLeafName(NS_LossyConvertUCS2toASCII(newFileName).get()); //Set new leafname + outFileSpec->SetLeafName(newFileName); //Set new leafname nsCOMPtr outFileLocal = do_QueryInterface(outFileSpec, &rv); //Create an nsILocalFile version //to send to MakeUnique() MakeUnique(outFileLocal); @@ -626,8 +627,8 @@ nsInstallPatch::NativePatch(nsIFile *sourceFile, nsIFile *patchFile, nsIFile **n outFileSpec->Remove(PR_FALSE); - char* leaf; - anotherName->GetLeafName(&leaf); + nsCAutoString leaf; + anotherName->GetLeafName(leaf); anotherName->CopyTo(parent, leaf); anotherName->Clone(newFile); @@ -665,11 +666,6 @@ cleanup: PR_DELETE( tmpurl ); } - if (realfile != NULL) - { - PL_strfree(realfile); - } - if (tempSrcFile) { tempSrcFile->Exists(&flagExists); @@ -715,13 +711,13 @@ nsInstallPatch::HashFilePath(nsIFile* aPath) { PRUint32 rv = 0; - char* cPath; - aPath->GetPath(&cPath); + nsCAutoString cPath; + aPath->GetNativePath(cPath); - if(cPath != nsnull) + if (!cPath.IsEmpty()) { char ch; - char* pathIndex = cPath; + const char* pathIndex = cPath.get(); while ((ch = *pathIndex++) != 0) { @@ -730,8 +726,6 @@ nsInstallPatch::HashFilePath(nsIFile* aPath) } } - PL_strfree(cPath); - return (void*)rv; } diff --git a/mozilla/xpinstall/src/nsInstallUninstall.cpp b/mozilla/xpinstall/src/nsInstallUninstall.cpp index abbd3e7c731..5715435b727 100644 --- a/mozilla/xpinstall/src/nsInstallUninstall.cpp +++ b/mozilla/xpinstall/src/nsInstallUninstall.cpp @@ -31,6 +31,7 @@ #include "nsFileSpec.h" #include "ScheduledTasks.h" #include "nsReadableUtils.h" +#include "nsILocalFile.h" extern "C" NS_EXPORT PRInt32 SU_Uninstall(char *regPackageName); REGERR su_UninstallProcessItem(char *component_path); @@ -196,7 +197,7 @@ REGERR su_UninstallProcessItem(char *component_path) err = VR_GetPath(component_path, sizeof(filepath), filepath); if ( err == REGERR_OK ) { - NS_NewLocalFile((char*)filepath, PR_TRUE, getter_AddRefs(nsLFPath)); + NS_NewNativeLocalFile(nsDependentCString(filepath), PR_TRUE, getter_AddRefs(nsLFPath)); nsFPath = nsLFPath; err = VR_GetRefCount(component_path, &refcount); if ( err == REGERR_OK ) diff --git a/mozilla/xpinstall/src/nsJSFile.cpp b/mozilla/xpinstall/src/nsJSFile.cpp index f2266869077..2455390dfe3 100644 --- a/mozilla/xpinstall/src/nsJSFile.cpp +++ b/mozilla/xpinstall/src/nsJSFile.cpp @@ -1163,15 +1163,15 @@ InstallFileOpFileWindowsShortcut(JSContext *cx, JSObject *obj, uintN argc, jsval ConvertJSValToStr(b0, cx, argv[0]); - NS_NewLocalFile(NS_LossyConvertUCS2toASCII(b0).get(), PR_TRUE, getter_AddRefs(nsfsB0)); + NS_NewLocalFile(NS_ConvertUCS2toUTF8(b0), PR_TRUE, getter_AddRefs(nsfsB0)); ConvertJSValToStr(b1, cx, argv[1]); - NS_NewLocalFile(NS_LossyConvertUCS2toASCII(b1).get(), PR_TRUE, getter_AddRefs(nsfsB1)); + NS_NewLocalFile(NS_ConvertUCS2toUTF8(b1), PR_TRUE, getter_AddRefs(nsfsB1)); ConvertJSValToStr(b2, cx, argv[2]); ConvertJSValToStr(b3, cx, argv[3]); - NS_NewLocalFile(NS_LossyConvertUCS2toASCII(b3).get(), PR_TRUE, getter_AddRefs(nsfsB3)); + NS_NewLocalFile(NS_ConvertUCS2toUTF8(b3), PR_TRUE, getter_AddRefs(nsfsB3)); ConvertJSValToStr(b4, cx, argv[4]); ConvertJSValToStr(b5, cx, argv[5]); - NS_NewLocalFile(NS_LossyConvertUCS2toASCII(b5).get(), PR_TRUE, getter_AddRefs(nsfsB5)); + NS_NewLocalFile(NS_ConvertUCS2toUTF8(b5), PR_TRUE, getter_AddRefs(nsfsB5)); if(JSVAL_IS_NULL(argv[6])) { @@ -1273,7 +1273,7 @@ InstallFileOpFileMacAlias(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, } ConvertJSValToStr(sourceLeaf, cx, argv[1]); - rv1 = iFileSource->Append(NS_LossyConvertUCS2toASCII(sourceLeaf).get()); + rv1 = iFileSource->Append(NS_ConvertUCS2toUTF8(sourceLeaf)); // public int FileMacAlias( InstallFolder aSourceFolder, // String aSourceFileName, @@ -1298,7 +1298,7 @@ InstallFileOpFileMacAlias(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, aliasLeaf.Append(NS_LITERAL_STRING(" alias")); // XXX use GetResourcedString(id) } - rv2 = iFileAlias->Append(NS_LossyConvertUCS2toASCII(aliasLeaf).get()); + rv2 = iFileAlias->Append(NS_ConvertUCS2toUTF8(aliasLeaf)); if (NS_FAILED(rv1) || NS_FAILED(rv2)) { *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR); diff --git a/mozilla/xpinstall/src/nsLoggingProgressNotifier.cpp b/mozilla/xpinstall/src/nsLoggingProgressNotifier.cpp index 681e85bf6da..c26e0a2ea5f 100644 --- a/mozilla/xpinstall/src/nsLoggingProgressNotifier.cpp +++ b/mozilla/xpinstall/src/nsLoggingProgressNotifier.cpp @@ -33,13 +33,14 @@ #include "nsDirectoryService.h" #include "nsDirectoryServiceDefs.h" #include "nsAppDirectoryServiceDefs.h" +#include "nsILocalFile.h" #include "nspr.h" #ifdef XP_MAC -#define INSTALL_LOG "Install Log" +#define INSTALL_LOG NS_LITERAL_CSTRING("Install Log") #else -#define INSTALL_LOG "install.log" +#define INSTALL_LOG NS_LITERAL_CSTRING("install.log") #endif @@ -88,9 +89,9 @@ nsLoggingProgressListener::OnInstallStart(const PRUnichar *URL) if (NS_FAILED(rv)) return rv; if (!nsSoftwareUpdate::GetLogName()) - rv = iFile->Append(INSTALL_LOG); + rv = iFile->AppendNative(INSTALL_LOG); else - rv = iFile->Append(nsSoftwareUpdate::GetLogName()); + rv = iFile->AppendNative(nsDependentCString(nsSoftwareUpdate::GetLogName())); if (NS_FAILED(rv)) return rv; @@ -133,9 +134,9 @@ nsLoggingProgressListener::OnInstallStart(const PRUnichar *URL) if (NS_FAILED(rv)) return NS_ERROR_FAILURE; if (!nsSoftwareUpdate::GetLogName()) - rv = iFile->Append(INSTALL_LOG); + rv = iFile->AppendNative(INSTALL_LOG); else - rv = iFile->Append(nsSoftwareUpdate::GetLogName()); + rv = iFile->AppendNative(nsDependentCString(nsSoftwareUpdate::GetLogName())); if (NS_FAILED(rv)) return rv; @@ -315,12 +316,11 @@ Convert_nsIFile_To_nsFileSpec(nsIFile *aInIFile, nsFileSpec **aOutFileSpec) *aOutFileSpec = new nsFileSpec(fsSpec, PR_FALSE); } #else - char *path = nsnull; - - rv = aInIFile->GetPath(&path); + nsCAutoString path; + rv = aInIFile->GetNativePath(path); if (NS_SUCCEEDED(rv)) { - *aOutFileSpec = new nsFileSpec(path, PR_FALSE); + *aOutFileSpec = new nsFileSpec(path.get(), PR_FALSE); } // NOTE: don't release path since nsFileSpec's mPath points to it #endif diff --git a/mozilla/xpinstall/src/nsRegisterItem.cpp b/mozilla/xpinstall/src/nsRegisterItem.cpp index d792bdc4c88..03a6da9a02d 100644 --- a/mozilla/xpinstall/src/nsRegisterItem.cpp +++ b/mozilla/xpinstall/src/nsRegisterItem.cpp @@ -75,12 +75,12 @@ static nsresult hack_nsIFile2URL(nsIFile* file, char * *aURL) { nsresult rv; - char* ePath; - rv = file->GetPath(&ePath); + nsCAutoString ePath; + rv = file->GetNativePath(ePath); if (NS_FAILED(rv)) return rv; #if defined (XP_PC) // Replace \ with / to convert to an url - char* s = ePath; + char* s = (char *) ePath.get(); while (*s) { #ifndef XP_OS2 // We need to call IsDBCSLeadByte because @@ -98,7 +98,7 @@ hack_nsIFile2URL(nsIFile* file, char * *aURL) #endif #if defined( XP_MAC ) // Swap the / and colons to convert to an url - SwapSlashColon(ePath); + SwapSlashColon((char*)ePath.get()); #endif // Escape the path with the directory mask nsCAutoString tmp(ePath); @@ -119,11 +119,9 @@ hack_nsIFile2URL(nsIFile* file, char * *aURL) } *aURL = ToNewCString(escPath); if (*aURL == nsnull) { - nsMemory::Free(ePath); return NS_ERROR_OUT_OF_MEMORY; } // } - nsMemory::Free(ePath); return rv; } @@ -299,7 +297,7 @@ PRInt32 nsRegisterItem::Complete() rv = startupFile->Create(nsIFile::DIRECTORY_TYPE, 0755); if (NS_SUCCEEDED(rv)) { - rv = startupFile->Append("installed-chrome.txt"); + rv = startupFile->Append(NS_LITERAL_CSTRING("installed-chrome.txt")); if (NS_SUCCEEDED(rv)) { rv = startupFile->OpenNSPRFileDesc( diff --git a/mozilla/xpinstall/src/nsSoftwareUpdate.cpp b/mozilla/xpinstall/src/nsSoftwareUpdate.cpp index 2aed57e7a71..a878e1aca1e 100644 --- a/mozilla/xpinstall/src/nsSoftwareUpdate.cpp +++ b/mozilla/xpinstall/src/nsSoftwareUpdate.cpp @@ -132,15 +132,13 @@ nsSoftwareUpdate::nsSoftwareUpdate() if(!directoryService) return; nsCOMPtr dir; - directoryService->Get(NS_XPCOM_CURRENT_PROCESS_DIR, NS_GET_IID(nsIFile), getter_AddRefs(dir)); + directoryService->Get(NS_XPCOM_CURRENT_PROCESS_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(dir)); if (dir) { - char* nativePath; - dir->GetPath(&nativePath); + nsCAutoString nativePath; + dir->GetNativePath(nativePath); // EVIL version registry does not take a nsIFile.; - VR_SetRegDirectory( nativePath ); - if (nativePath) - nsMemory::Free(nativePath); + VR_SetRegDirectory( nativePath.get() ); } /***************************************/ @@ -537,10 +535,10 @@ nsSoftwareUpdate::StubInitialize(nsIFile *aDir, const char* logName) nsresult rv = aDir->Clone(getter_AddRefs(mProgramDir)); // make sure registry updates go to the right place - nsXPIDLCString tempPath; - rv = aDir->GetPath(getter_Copies(tempPath)); + nsCAutoString tempPath; + rv = aDir->GetNativePath(tempPath); if (NS_SUCCEEDED(rv)) - VR_SetRegDirectory( tempPath ); + VR_SetRegDirectory( tempPath.get() ); // Optionally set logfile leafname if (logName) diff --git a/mozilla/xpinstall/src/nsSoftwareUpdateRun.cpp b/mozilla/xpinstall/src/nsSoftwareUpdateRun.cpp index e638573ca88..3d85efce8f3 100644 --- a/mozilla/xpinstall/src/nsSoftwareUpdateRun.cpp +++ b/mozilla/xpinstall/src/nsSoftwareUpdateRun.cpp @@ -199,7 +199,7 @@ GetInstallScriptFromJarfile(nsIZipReader* hZip, nsIFile* jarFile, char** scriptB // Extract the install.js file. nsCOMPtr iFile; - rv = NS_NewLocalFile(installJSFileSpec, PR_TRUE, getter_AddRefs(iFile)); + rv = NS_NewNativeLocalFile(nsDependentCString(installJSFileSpec), PR_TRUE, getter_AddRefs(iFile)); if (NS_SUCCEEDED(rv)) rv = hZip->Extract("install.js", iFile); if ( NS_SUCCEEDED(rv) ) diff --git a/mozilla/xpinstall/src/nsXPInstallManager.cpp b/mozilla/xpinstall/src/nsXPInstallManager.cpp index bebe6a7bbca..67904d32433 100644 --- a/mozilla/xpinstall/src/nsXPInstallManager.cpp +++ b/mozilla/xpinstall/src/nsXPInstallManager.cpp @@ -694,7 +694,7 @@ nsXPInstallManager::GetDestinationFile(nsString& url, nsILocalFile* *file) NS_ENSURE_ARG_POINTER(file); nsresult rv; - nsString leaf; + nsAutoString leaf; PRInt32 pos = url.RFindChar('/'); url.Mid( leaf, pos+1, url.Length() ); @@ -713,7 +713,7 @@ nsXPInstallManager::GetDestinationFile(nsString& url, nsILocalFile* *file) getter_AddRefs(temp)); if (NS_SUCCEEDED(rv)) { - temp->Append("tmp.xpi"); + temp->AppendNative(NS_LITERAL_CSTRING("tmp.xpi")); MakeUnique(temp); *file = temp; NS_IF_ADDREF(*file); @@ -746,7 +746,7 @@ nsXPInstallManager::GetDestinationFile(nsString& url, nsILocalFile* *file) if (NS_SUCCEEDED(rv)) { - userChrome->AppendUnicode(leaf.get()); + userChrome->Append(NS_ConvertUCS2toUTF8(leaf)); MakeUnique(userChrome); *file = userChrome; NS_IF_ADDREF(*file); diff --git a/mozilla/xpinstall/stub/xpistub.cpp b/mozilla/xpinstall/stub/xpistub.cpp index 7417ee90e7a..5d4377f0bf9 100644 --- a/mozilla/xpinstall/stub/xpistub.cpp +++ b/mozilla/xpinstall/stub/xpistub.cpp @@ -121,7 +121,7 @@ PR_PUBLIC_API(nsresult) XPI_Init( getcwd(componentPath, MAX_PATH); nsCOMPtr file; - NS_NewLocalFile(componentPath, PR_TRUE, getter_AddRefs(file)); + NS_NewNativeLocalFile(nsDependentCString(componentPath), PR_TRUE, getter_AddRefs(file)); rv = NS_InitXPCOM2(&gServiceMgr, file, nsnull); @@ -138,7 +138,7 @@ PR_PUBLIC_API(nsresult) XPI_Init( sprintf(compDirPath, "%s/components", cwd); nsCOMPtr compDir; - NS_NewLocalFile(compDirPath, PR_TRUE, getter_AddRefs(compDir)); + NS_NewNativeLocalFile(nsDependentCString(compDirPath), PR_TRUE, getter_AddRefs(compDir)); #else @@ -189,7 +189,7 @@ PR_PUBLIC_API(nsresult) XPI_Init( NS_NewLocalFileWithFSSpec((FSSpec *)&aProgramDir, PR_TRUE, getter_AddRefs(iMacDirSpec)); iDirSpec = do_QueryInterface(iMacDirSpec); #else - NS_NewLocalFile(aProgramDir, PR_TRUE, getter_AddRefs(iDirSpec)); + NS_NewNativeLocalFile(nsDependentCString(aProgramDir), PR_TRUE, getter_AddRefs(iDirSpec)); #endif if (hook && iDirSpec) @@ -263,7 +263,7 @@ PR_PUBLIC_API(PRInt32) XPI_Install( NS_NewLocalFileWithFSSpec((FSSpec *)&aFile, PR_TRUE, getter_AddRefs(iMacFile)); iFile = do_QueryInterface(iMacFile); #else - NS_NewLocalFile(aFile, PR_TRUE, getter_AddRefs(iFile)); + NS_NewNativeLocalFile(nsDependentCString(aFile), PR_TRUE, getter_AddRefs(iFile)); #endif if (iFile && gXPI)