From 8514da82d233b3b28cacb6da692e2a924626477d Mon Sep 17 00:00:00 2001 From: "darin%netscape.com" Date: Mon, 13 May 2002 22:09:29 +0000 Subject: [PATCH] landing nsIFile API changes (b=129279) r=dougt sr=alecf a=asa git-svn-id: svn://10.0.0.236/branches/MOZILLA_1_0_BRANCH@121404 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/caps/src/nsScriptSecurityManager.cpp | 4 +- mozilla/chrome/src/nsChromeRegistry.cpp | 45 +- 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 | 50 +- .../powerplant/source/CProfileManager.cpp | 5 +- .../src/mac/nsPrintingPromptServiceX.cpp | 4 +- .../ui/helperAppDlg/nsHelperAppDlg.js | 10 +- .../ui/progressDlg/nsProgressDialog.js | 4 +- .../ui/progressDlg/nsProgressDlg.js | 4 +- .../src/nsWebBrowserPersist.cpp | 20 +- .../embedding/tests/mfcembed/BrowserView.cpp | 8 +- .../tests/mfcembed/MostRecentUrls.cpp | 2 +- .../mfcembed/components/HelperAppDlg.cpp | 4 +- .../mfcembed/winEmbedFileLocProvider.cpp | 42 +- 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 | 18 +- .../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/nsNameValuePairDB.cpp | 31 +- .../gfx/src/x11shared/nsFT2FontCatalog.cpp | 79 ++- mozilla/gfx/src/x11shared/nsFT2FontCatalog.h | 10 +- .../xpconnect/loader/mozJSComponentLoader.cpp | 32 +- mozilla/js/src/xpconnect/src/nsXPConnect.cpp | 8 +- .../tools/src/nsXPCToolsCompiler.cpp | 8 +- .../html/forms/src/nsFileControlFrame.cpp | 21 +- mozilla/layout/html/tests/ParseCSS.cpp | 2 +- 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 | 48 +- .../mailnews/base/src/nsMessengerMigrator.cpp | 74 +-- .../base/src/nsMessengerWinIntegration.cpp | 10 +- .../mailnews/base/src/nsMsgAccountManager.cpp | 8 +- .../mailnews/base/src/nsMsgMailSession.cpp | 6 +- mozilla/mailnews/base/util/nsMsgDBFolder.cpp | 2 +- .../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 | 45 +- .../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/os2/nsIconChannel.cpp | 15 +- .../libpr0n/decoders/icon/os2/nsIconChannel.h | 2 +- .../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 | 70 +- .../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 | 62 +- .../modules/plugin/base/src/nsIPluginHost.h | 2 +- .../base/src/nsPluginDirServiceProvider.cpp | 11 +- .../plugin/base/src/nsPluginHostImpl.cpp | 189 +++--- mozilla/netwerk/base/public/nsNetUtil.h | 6 +- .../base/src/nsDirectoryIndexStream.cpp | 22 +- mozilla/netwerk/base/src/nsFileStreams.cpp | 23 +- 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 | 18 +- 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 | 23 +- mozilla/netwerk/test/TestFileTransport.cpp | 21 +- mozilla/netwerk/test/TestUpload.cpp | 2 +- mozilla/netwerk/test/TestWriteStream.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 | 188 +++--- mozilla/profile/src/nsProfile.h | 2 +- mozilla/profile/src/nsProfileAccess.cpp | 55 +- mozilla/rdf/chrome/src/nsChromeRegistry.cpp | 45 +- .../datasource/src/nsFileSystemDataSource.cpp | 33 +- .../manager/ssl/src/nsNSSComponent.cpp | 39 +- .../security/manager/ssl/src/nsPKCS12Blob.cpp | 31 +- .../exthandler/mac/nsOSHelperAppService.cpp | 2 +- .../exthandler/nsExternalHelperAppService.cpp | 96 ++- .../exthandler/nsExternalHelperAppService.h | 4 +- .../exthandler/os2/nsOSHelperAppService.cpp | 2 +- .../exthandler/unix/nsOSHelperAppService.cpp | 23 +- .../exthandler/win/nsOSHelperAppService.cpp | 10 +- mozilla/widget/src/beos/nsFilePicker.cpp | 16 +- mozilla/widget/src/os2/nsDragService.cpp | 9 +- mozilla/widget/src/os2/nsFilePicker.cpp | 37 +- mozilla/widget/src/os2/nsSound.cpp | 10 +- mozilla/widget/src/windows/nsClipboard.cpp | 6 +- mozilla/widget/src/windows/nsFilePicker.cpp | 39 +- mozilla/widget/src/windows/nsWindow.cpp | 21 +- 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 | 13 +- 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 | 74 +-- mozilla/xpcom/io/nsDirectoryService.cpp | 31 +- mozilla/xpcom/io/nsFastLoadFile.cpp | 19 +- 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 | 140 ++-- mozilla/xpcom/io/nsIFileSpec.idl | 13 + mozilla/xpcom/io/nsILocalFile.idl | 145 +++-- mozilla/xpcom/io/nsLocalFile.h | 14 +- mozilla/xpcom/io/nsLocalFileCommon.cpp | 101 ++- mozilla/xpcom/io/nsLocalFileMac.cpp | 266 ++++---- mozilla/xpcom/io/nsLocalFileMac.h | 7 +- mozilla/xpcom/io/nsLocalFileOS2.cpp | 479 +++++++------- mozilla/xpcom/io/nsLocalFileOS2.h | 13 +- mozilla/xpcom/io/nsLocalFileUnicode.cpp | 57 +- mozilla/xpcom/io/nsLocalFileUnicode.h | 3 + mozilla/xpcom/io/nsLocalFileUnix.cpp | 615 +++++++++++------- mozilla/xpcom/io/nsLocalFileUnix.h | 29 +- mozilla/xpcom/io/nsLocalFileWin.cpp | 556 ++++++++-------- mozilla/xpcom/io/nsLocalFileWin.h | 19 +- .../xptinfo/src/xptiInterfaceInfoManager.cpp | 67 +- .../reflect/xptinfo/src/xptiManifest.cpp | 39 +- .../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 | 8 +- .../resources/content/contentAreaUtils.js | 2 +- .../bookmarks/resources/addBookmark.js | 2 +- .../bookmarks/src/nsBookmarksService.cpp | 23 +- .../bookmarks/src/nsBookmarksService.h | 1 + .../directory/nsDirectoryViewer.cpp | 8 +- .../src/nsDownloadManager.cpp | 48 +- .../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 | 21 +- .../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 | 105 ++- .../ucth/resources/helperAppDldProgress.js | 4 +- .../ucth/resources/helperAppLauncher.js | 4 +- .../xfer/resources/downloadProgress.js | 2 +- .../components/xfer/src/nsStreamTransfer.cpp | 15 +- .../xpinstall/cleanup/InstallCleanupDefines.h | 23 +- mozilla/xpinstall/src/ScheduledTasks.cpp | 169 +++-- mozilla/xpinstall/src/nsInstall.cpp | 42 +- mozilla/xpinstall/src/nsInstallExecute.cpp | 6 +- mozilla/xpinstall/src/nsInstallFile.cpp | 34 +- mozilla/xpinstall/src/nsInstallFileOpItem.cpp | 165 +++-- mozilla/xpinstall/src/nsInstallFolder.cpp | 45 +- mozilla/xpinstall/src/nsInstallFolder.h | 12 +- mozilla/xpinstall/src/nsInstallPatch.cpp | 106 ++- mozilla/xpinstall/src/nsInstallUninstall.cpp | 3 +- mozilla/xpinstall/src/nsJSFile.cpp | 26 +- .../src/nsLoggingProgressNotifier.cpp | 20 +- mozilla/xpinstall/src/nsRegisterItem.cpp | 14 +- mozilla/xpinstall/src/nsSoftwareUpdate.cpp | 20 +- mozilla/xpinstall/src/nsXPInstallManager.cpp | 6 +- mozilla/xpinstall/stub/xpistub.cpp | 8 +- 218 files changed, 3260 insertions(+), 3356 deletions(-) diff --git a/mozilla/caps/src/nsScriptSecurityManager.cpp b/mozilla/caps/src/nsScriptSecurityManager.cpp index 576cad52303..2a462efc2a7 100644 --- a/mozilla/caps/src/nsScriptSecurityManager.cpp +++ b/mozilla/caps/src/nsScriptSecurityManager.cpp @@ -1912,10 +1912,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->AppendNative(NS_LITERAL_CSTRING("Essential Files")); if (NS_FAILED(rv)) return NS_ERROR_FAILURE; #endif - systemCertFile->Append("systemSignature.jar"); + systemCertFile->AppendNative(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 a510cb2a75c..d1cecd0671a 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 nsCString& 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); @@ -2082,10 +2083,9 @@ nsChromeRegistry::IsProviderSetForPackage(const nsCString& 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; @@ -2171,8 +2171,7 @@ NS_IMETHODIMP nsChromeRegistry::InstallProvider(const nsCString& 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"); @@ -2536,8 +2535,7 @@ nsChromeRegistry::UninstallProvider(const nsCString& 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"); @@ -2608,15 +2606,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->AppendNative(NS_LITERAL_CSTRING("chrome")); + defaultUserContentFile->AppendNative(NS_LITERAL_CSTRING("userContent.css")); + defaultUserChromeFile->AppendNative(NS_LITERAL_CSTRING("chrome")); + defaultUserChromeFile->AppendNative(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->CopyToNative(userChromeDir, nsCString()); + (void) defaultUserChromeFile->CopyToNative(userChromeDir, nsCString()); } } if (NS_FAILED(rv)) @@ -2748,17 +2746,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; @@ -3049,12 +3046,12 @@ nsChromeRegistry::CheckForNewChrome() nsCOMPtr chromeFile; rv = listFile->Clone(getter_AddRefs(chromeFile)); if (NS_FAILED(rv)) return rv; - rv = chromeFile->Append(kChromeFileName); + rv = chromeFile->AppendNative(kChromeFileName); if (NS_FAILED(rv)) return rv; nsInt64 chromeDate; (void)chromeFile->GetLastModifiedTime(&chromeDate.mValue); - rv = listFile->AppendRelativePath(kInstalledChromeFileName); + rv = listFile->AppendRelativeNativePath(kInstalledChromeFileName); if (NS_FAILED(rv)) return rv; nsInt64 listFileDate; (void)listFile->GetLastModifiedTime(&listFileDate.mValue); @@ -3158,7 +3155,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; @@ -3219,9 +3217,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 ee6bb94218c..297c51d3c83 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 ; } ], @@ -1529,7 +1529,7 @@ dnl 2.96-2.97 have a signed wchar_t in c++ only. 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 Since this is gcc-only, CC and CXX should take the same arguments. CC=$_SAVE_CC 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 442e1e6d7e5..4c8771ede3b 100644 --- a/mozilla/content/html/content/src/nsHTMLInputElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLInputElement.cpp @@ -2182,20 +2182,17 @@ nsHTMLInputElement::SubmitNamesValues(nsIFormSubmission* aFormSubmission, &rv)); NS_ENSURE_SUCCESS(rv, rv); - rv = file->InitWithUnicodePath(value.get()); + rv = file->InitWithPath(value); if (NS_SUCCEEDED(rv)) { // // Get the leaf path name (to be submitted as the value) // - PRUnichar* leafNameChars = nsnull; - rv = file->GetUnicodeLeafName(&leafNameChars); + nsAutoString filename; + rv = file->GetLeafName(filename); NS_ENSURE_SUCCESS(rv, rv); - if (leafNameChars) { - nsAutoString filename; - filename.Adopt(leafNameChars); - + if (!filename.IsEmpty()) { 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 072b8393a0a..d5d599a24e9 100644 --- a/mozilla/content/xul/document/src/nsXULDocument.cpp +++ b/mozilla/content/xul/document/src/nsXULDocument.cpp @@ -4904,8 +4904,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->GetNativePath(chromePath); if (NS_FAILED(rv)) return rv; @@ -4980,7 +4980,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; } } @@ -5000,7 +5000,7 @@ nsXULDocument::StartFastLoad() xio->mInputStream = nsnull; #ifdef DEBUG - file->MoveTo(nsnull, "Invalid.mfasl"); + file->MoveToNative(nsnull, NS_LITERAL_CSTRING("Invalid.mfasl")); #else file->Remove(PR_FALSE); #endif @@ -5020,7 +5020,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 @@ -5143,7 +5143,7 @@ nsXULDocument::AbortFastLoads() // Now rename or remove the file. if (file) { #ifdef DEBUG - file->MoveTo(nsnull, "Aborted.mfasl"); + file->MoveToNative(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..f6296d97b66 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(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..46cd878fe28 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 nsACString& GetResCString(PRInt32 stringIndex, nsACString& outStr); //***************************************************************************** @@ -71,7 +71,7 @@ CAppFileLocationProvider::GetFile(const char *prop, PRBool *persistant, nsIFile { nsCOMPtr localFile; nsresult rv = NS_ERROR_FAILURE; - Str255 strBuf; + nsCAutoString strBuf; *_retval = nsnull; *persistant = PR_TRUE; @@ -84,21 +84,21 @@ 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) { rv = CloneMozBinDirectory(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) { - rv = localFile->AppendRelativePath(GetResCString(str_DefaultsDirName, strBuf)); + rv = localFile->AppendRelativeNativePath(GetResCString(str_DefaultsDirName, strBuf)); if (NS_SUCCEEDED(rv)) - rv = localFile->AppendRelativePath(GetResCString(str_PrefDefaultsDirName, strBuf)); + rv = localFile->AppendRelativeNativePath(GetResCString(str_PrefDefaultsDirName, strBuf)); } } else if (nsCRT::strcmp(prop, NS_APP_PROFILE_DEFAULTS_NLOC_50_DIR) == 0 || @@ -106,9 +106,9 @@ CAppFileLocationProvider::GetFile(const char *prop, PRBool *persistant, nsIFile { rv = CloneMozBinDirectory(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) { - rv = localFile->AppendRelativePath(GetResCString(str_DefaultsDirName, strBuf)); + rv = localFile->AppendRelativeNativePath(GetResCString(str_DefaultsDirName, strBuf)); if (NS_SUCCEEDED(rv)) - rv = localFile->AppendRelativePath(GetResCString(str_ProfileDefaultsDirName, strBuf)); + rv = localFile->AppendRelativeNativePath(GetResCString(str_ProfileDefaultsDirName, strBuf)); } } else if (nsCRT::strcmp(prop, NS_APP_USER_PROFILES_ROOT_DIR) == 0) @@ -119,25 +119,25 @@ CAppFileLocationProvider::GetFile(const char *prop, PRBool *persistant, nsIFile { rv = CloneMozBinDirectory(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->AppendRelativePath(GetResCString(str_ResDirName, strBuf)); + rv = localFile->AppendRelativeNativePath(GetResCString(str_ResDirName, strBuf)); } else if (nsCRT::strcmp(prop, NS_APP_CHROME_DIR) == 0) { rv = CloneMozBinDirectory(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->AppendRelativePath(GetResCString(str_ChromeDirName, strBuf)); + rv = localFile->AppendRelativeNativePath(GetResCString(str_ChromeDirName, strBuf)); } else if (nsCRT::strcmp(prop, NS_APP_PLUGINS_DIR) == 0) { rv = CloneMozBinDirectory(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->AppendRelativePath(GetResCString(str_PlugInsDirName, strBuf)); + rv = localFile->AppendRelativeNativePath(GetResCString(str_PlugInsDirName, strBuf)); } else if (nsCRT::strcmp(prop, NS_APP_SEARCH_DIR) == 0) { rv = CloneMozBinDirectory(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->AppendRelativePath(GetResCString(str_SearchPlugInsDirName, strBuf)); + rv = localFile->AppendRelativeNativePath(GetResCString(str_SearchPlugInsDirName, strBuf)); } if (localFile && NS_SUCCEEDED(rv)) @@ -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) @@ -237,12 +237,12 @@ NS_METHOD CAppFileLocationProvider::GetDefaultUserProfileRoot(nsILocalFile **aLo nsresult rv; PRBool exists; nsCOMPtr localDir; - Str255 strBuf; + nsCAutoString strBuf; rv = GetProductDirectory(getter_AddRefs(localDir)); if (NS_FAILED(rv)) return rv; - rv = localDir->AppendRelativePath(GetResCString(str_ProfilesRootDirName, strBuf)); + rv = localDir->AppendRelativeNativePath(GetResCString(str_ProfilesRootDirName, strBuf)); if (NS_FAILED(rv)) return rv; rv = localDir->Exists(&exists); if (NS_SUCCEEDED(rv) && !exists) @@ -259,19 +259,13 @@ NS_METHOD CAppFileLocationProvider::GetDefaultUserProfileRoot(nsILocalFile **aLo // Static Routines //**************************************************************************************** -static char* GetResCString(PRInt32 stringIndex, Str255& buf) +static nsACString& GetResCString(PRInt32 stringIndex, nsACString& outStr) { - GetIndString(buf, STRx_FileLocProviderStrings, stringIndex); - if (!buf[0]) { + Str255 pString; + GetIndString(pString, STRx_FileLocProviderStrings, stringIndex); + if (!pString[0]) NS_ASSERTION(PR_FALSE, "Directory name resource is missing."); - return nsnull; - } - - // Because of different availability of Pascal to C conversion routines - // in Carbon and not, just do it by hand. - PRInt32 len = buf[0]; - memmove(buf, buf + 1, len); - buf[len] = '\0'; - - return (char *)buf; + + outStr.Assign((char*)&pString[1], pString[0]); + return outStr; } 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/printingui/src/mac/nsPrintingPromptServiceX.cpp b/mozilla/embedding/components/printingui/src/mac/nsPrintingPromptServiceX.cpp index 3aa42856e93..e740cd46112 100644 --- a/mozilla/embedding/components/printingui/src/mac/nsPrintingPromptServiceX.cpp +++ b/mozilla/embedding/components/printingui/src/mac/nsPrintingPromptServiceX.cpp @@ -91,8 +91,8 @@ static CFPlugInRef LoadPDEPlugIn() rv = dirService->Get(NS_XPCOM_CURRENT_PROCESS_DIR, NS_GET_IID(nsILocalFileMac), getter_AddRefs(pluginDir)); if (NS_FAILED(rv)) return nsnull; - pluginDir->Append(NS_LITERAL_CSTRING("Essential Files")); - pluginDir->Append(NS_LITERAL_CSTRING("PrintDialogPDE.plugin")); + pluginDir->AppendNative(NS_LITERAL_CSTRING("Essential Files")); + pluginDir->AppendNative(NS_LITERAL_CSTRING("PrintDialogPDE.plugin")); FSSpec pluginSpec; rv = pluginDir->GetFSSpec(&pluginSpec); if (NS_FAILED(rv)) diff --git a/mozilla/embedding/components/ui/helperAppDlg/nsHelperAppDlg.js b/mozilla/embedding/components/ui/helperAppDlg/nsHelperAppDlg.js index 9594a608b65..f074c92e63e 100644 --- a/mozilla/embedding/components/ui/helperAppDlg/nsHelperAppDlg.js +++ b/mozilla/embedding/components/ui/helperAppDlg/nsHelperAppDlg.js @@ -300,7 +300,7 @@ nsHelperAppDialog.prototype = { var parentObject = fileObject.parent; if (parentObject) { - pathString = parentObject.unicodePath; + pathString = parentObject.path; } } } @@ -327,10 +327,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 @@ -399,7 +399,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; } @@ -473,7 +473,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 b43b6e5e67f..3fd432ecbaa 100644 --- a/mozilla/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp +++ b/mozilla/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp @@ -839,15 +839,13 @@ nsresult nsWebBrowserPersist::SendErrorStatusChange( nsAutoString path; if (file) { - nsXPIDLString filePath; - file->GetUnicodePath(getter_Copies(filePath)); - path = filePath; + file->GetPath(path); } else { nsCAutoString fileurl; aURI->GetSpec(fileurl); - path.Assign(NS_ConvertUTF8toUCS2(fileurl)); + path = NS_ConvertUTF8toUCS2(fileurl); } nsAutoString msgId; @@ -1263,13 +1261,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 +1281,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 +1530,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..63845296ff5 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->AppendNative(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..89743e95549 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") //***************************************************************************** @@ -92,21 +92,21 @@ winEmbedFileLocProvider::GetFile(const char *prop, PRBool *persistant, nsIFile * { rv = GetProductDirectory(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->Append(APP_REGISTRY_NAME); + rv = localFile->AppendNative(APP_REGISTRY_NAME); } else if (nsCRT::strcmp(prop, NS_APP_DEFAULTS_50_DIR) == 0) { rv = CloneMozBinDirectory(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->AppendRelativePath(DEFAULTS_DIR_NAME); + rv = localFile->AppendRelativeNativePath(DEFAULTS_DIR_NAME); } else if (nsCRT::strcmp(prop, NS_APP_PREF_DEFAULTS_50_DIR) == 0) { rv = CloneMozBinDirectory(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) { - rv = localFile->AppendRelativePath(DEFAULTS_DIR_NAME); + rv = localFile->AppendRelativeNativePath(DEFAULTS_DIR_NAME); if (NS_SUCCEEDED(rv)) - rv = localFile->AppendRelativePath(DEFAULTS_PREF_DIR_NAME); + rv = localFile->AppendRelativeNativePath(DEFAULTS_PREF_DIR_NAME); } } else if (nsCRT::strcmp(prop, NS_APP_PROFILE_DEFAULTS_NLOC_50_DIR) == 0 || @@ -114,9 +114,9 @@ winEmbedFileLocProvider::GetFile(const char *prop, PRBool *persistant, nsIFile * { rv = CloneMozBinDirectory(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) { - rv = localFile->AppendRelativePath(DEFAULTS_DIR_NAME); + rv = localFile->AppendRelativeNativePath(DEFAULTS_DIR_NAME); if (NS_SUCCEEDED(rv)) - rv = localFile->AppendRelativePath(DEFAULTS_PROFILE_DIR_NAME); + rv = localFile->AppendRelativeNativePath(DEFAULTS_PROFILE_DIR_NAME); } } else if (nsCRT::strcmp(prop, NS_APP_USER_PROFILES_ROOT_DIR) == 0) @@ -127,25 +127,25 @@ winEmbedFileLocProvider::GetFile(const char *prop, PRBool *persistant, nsIFile * { rv = CloneMozBinDirectory(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->AppendRelativePath(RES_DIR_NAME); + rv = localFile->AppendRelativeNativePath(RES_DIR_NAME); } else if (nsCRT::strcmp(prop, NS_APP_CHROME_DIR) == 0) { rv = CloneMozBinDirectory(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->AppendRelativePath(CHROME_DIR_NAME); + rv = localFile->AppendRelativeNativePath(CHROME_DIR_NAME); } else if (nsCRT::strcmp(prop, NS_APP_PLUGINS_DIR) == 0) { rv = CloneMozBinDirectory(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->AppendRelativePath(PLUGINS_DIR_NAME); + rv = localFile->AppendRelativeNativePath(PLUGINS_DIR_NAME); } else if (nsCRT::strcmp(prop, NS_APP_SEARCH_DIR) == 0) { rv = CloneMozBinDirectory(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->AppendRelativePath(SEARCH_DIR_NAME); + rv = localFile->AppendRelativeNativePath(SEARCH_DIR_NAME); } if (localFile && NS_SUCCEEDED(rv)) @@ -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) @@ -252,7 +252,7 @@ NS_METHOD winEmbedFileLocProvider::GetDefaultUserProfileRoot(nsILocalFile **aLoc if (NS_FAILED(rv)) return rv; // These 3 platforms share this part of the path - do them as one - rv = localDir->AppendRelativePath(PROFILE_ROOT_DIR_NAME); + rv = localDir->AppendRelativeNativePath(PROFILE_ROOT_DIR_NAME); 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 ecad75b89bc..7a40677de64 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..c25e2405b30 100644 --- a/mozilla/extensions/inspector/base/src/inFileSearch.cpp +++ b/mozilla/extensions/inspector/base/src/inFileSearch.cpp @@ -171,9 +171,7 @@ inFileSearch::GetStringResultAt(PRInt32 aIndex, nsAString& _retval) } if (file) { - nsXPIDLCString temp; - mLastResult->GetPath(getter_Copies(temp)); - _retval = NS_ConvertASCIItoUCS2(temp); + mLastResult->GetPath(_retval); if (mReturnRelativePaths) MakePathRelative(_retval); } else { @@ -543,13 +541,10 @@ inFileSearch::GetNextDirectory(nsISimpleEnumerator* aEnum) PRBool inFileSearch::MatchFile(nsIFile* aFile) { - char* fileName; - aFile->GetLeafName(&fileName); - - nsAutoString temp; - temp.AssignWithConversion(fileName); + nsAutoString fileName; + aFile->GetLeafName(fileName); - PRUnichar* fileNameUnicode = ToNewUnicode(temp); + PRUnichar* fileNameUnicode = ToNewUnicode(fileName); PRBool match; @@ -558,6 +553,7 @@ inFileSearch::MatchFile(nsIFile* aFile) if (match) return PR_TRUE; } + // XXX are we leaking fileNameUnicode? return PR_FALSE; } @@ -610,10 +606,8 @@ inFileSearch::MakePathRelative(nsAString& aPath) { // get an nsAutoString version of the search path - char* temp; - mSearchPath->GetPath(&temp); nsAutoString searchPath; - searchPath.AssignWithConversion(temp); + mSearchPath->GetPath(searchPath); 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..cc437f12d66 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->AppendNative(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->AppendNative(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 27046edc8f6..567d6ef9c3f 100644 --- a/mozilla/extensions/pref/autoconfig/src/nsReadConfig.cpp +++ b/mozilla/extensions/pref/autoconfig/src/nsReadConfig.cpp @@ -217,18 +217,18 @@ nsresult nsReadConfig::openAndEvaluateJSFile(const char *aFileName, return rv; #ifdef XP_MAC - jsFile->Append("Essential Files"); + jsFile->AppendNative(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->AppendNative(NS_LITERAL_CSTRING("autoconfig")); if (NS_FAILED(rv)) return rv; } - rv = jsFile->Append(aFileName); + rv = jsFile->AppendNative(nsDependentCString(aFileName)); if (NS_FAILED(rv)) return rv; @@ -255,9 +255,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..11fbd838d7c 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->AppendNative(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..5ee41bba783 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(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/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/js/src/xpconnect/loader/mozJSComponentLoader.cpp b/mozilla/js/src/xpconnect/loader/mozJSComponentLoader.cpp index 2b2574387ef..135a4b96551 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,7 @@ mozJSComponentLoader::AttemptRegistration(nsIFile *component, // get the file name if (component) { - nsXPIDLCString leafName; - component->GetLeafName(getter_Copies(leafName)); - fileName.AssignWithConversion(leafName); + component->GetLeafName(fileName); } // this string can't come from a string bundle, because we diff --git a/mozilla/js/src/xpconnect/src/nsXPConnect.cpp b/mozilla/js/src/xpconnect/src/nsXPConnect.cpp index 51649a7baef..96de158b35f 100644 --- a/mozilla/js/src/xpconnect/src/nsXPConnect.cpp +++ b/mozilla/js/src/xpconnect/src/nsXPConnect.cpp @@ -78,13 +78,13 @@ nsXPConnect::nsXPConnect() #ifdef XPC_TOOLS_SUPPORT { - const char* filename = PR_GetEnv("MOZILLA_JS_PROFILER_OUTPUT"); - if(filename) + nsDependentCString filename(PR_GetEnv("MOZILLA_JS_PROFILER_OUTPUT")); + if(!filename.IsEmpty()) { mProfilerOutputFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID); if(mProfilerOutputFile && - NS_SUCCEEDED(mProfilerOutputFile->InitWithPath(filename))) + NS_SUCCEEDED(mProfilerOutputFile->InitWithNativePath(filename))) { mProfiler = do_GetService(XPCTOOLS_PROFILER_CONTRACTID); if(mProfiler) @@ -93,7 +93,7 @@ nsXPConnect::nsXPConnect() { #ifdef DEBUG printf("***** profiling JavaScript. Output to: %s\n", - filename); + filename.get()); #endif } } diff --git a/mozilla/js/src/xpconnect/tools/src/nsXPCToolsCompiler.cpp b/mozilla/js/src/xpconnect/tools/src/nsXPCToolsCompiler.cpp index 63be3cad7cc..b2fdccd9595 100644 --- a/mozilla/js/src/xpconnect/tools/src/nsXPCToolsCompiler.cpp +++ b/mozilla/js/src/xpconnect/tools/src/nsXPCToolsCompiler.cpp @@ -116,8 +116,8 @@ NS_IMETHODIMP nsXPCToolsCompiler::CompileFile(nsILocalFile *aFile, PRBool strict if (!JS_InitStandardClasses(cx, glob)) return NS_ERROR_FAILURE; - char * path = nsnull; - if(NS_FAILED(aFile->GetPath(&path))) + nsCAutoString path; + if(NS_FAILED(aFile->GetNativePath(path))) return NS_ERROR_FAILURE; uint32 oldoptions = JS_GetOptions(cx); @@ -125,7 +125,7 @@ NS_IMETHODIMP nsXPCToolsCompiler::CompileFile(nsILocalFile *aFile, PRBool strict JSErrorReporter older = JS_SetErrorReporter(cx, ErrorReporter); JSExceptionState *es =JS_SaveExceptionState(cx); - if(!JS_CompileFileHandle(cx, glob, path, handle)) + if(!JS_CompileFileHandle(cx, glob, path.get(), handle)) { jsval v; JSErrorReport* report; @@ -152,7 +152,5 @@ NS_IMETHODIMP nsXPCToolsCompiler::CompileFile(nsILocalFile *aFile, PRBool strict JS_SetErrorReporter(cx, older); JS_SetOptions(cx, oldoptions); - if(path) - nsMemory::Free(path); return NS_OK; } diff --git a/mozilla/layout/html/forms/src/nsFileControlFrame.cpp b/mozilla/layout/html/forms/src/nsFileControlFrame.cpp index 87911fd302d..9d238122ae9 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(defaultName); if (NS_SUCCEEDED(result)) { - PRUnichar *leafName = nsnull; - currentFile->GetUnicodeLeafName(&leafName); - if (leafName) { - filePicker->SetDefaultString(leafName); - nsMemory::Free(leafName); + nsAutoString leafName; + currentFile->GetLeafName(leafName); + if (!leafName.IsEmpty()) { + filePicker->SetDefaultString(leafName.get()); } // set directory @@ -336,12 +335,10 @@ 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); - mTextFrame->SetProperty(mPresContext, nsHTMLAtoms::value, pathName); - nsMemory::Free(nativePath); + nsAutoString unicodePath; + result = localFile->GetPath(unicodePath); + if (!unicodePath.IsEmpty()) { + mTextFrame->SetProperty(mPresContext, nsHTMLAtoms::value, unicodePath); return NS_OK; } } diff --git a/mozilla/layout/html/tests/ParseCSS.cpp b/mozilla/layout/html/tests/ParseCSS.cpp index d0dd2c6bebb..a68bd1ce1c3 100644 --- a/mozilla/layout/html/tests/ParseCSS.cpp +++ b/mozilla/layout/html/tests/ParseCSS.cpp @@ -63,7 +63,7 @@ FileToURI(const char *aFilename) { nsCOMPtr lf(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID)); // XXX Handle relative paths somehow. - lf->InitWithPath(aFilename); + lf->InitWithNativePath(nsDependentCString(aFilename)); nsIFileURL *url; CallCreateInstance(kStandardURLCID, &url); diff --git a/mozilla/mailnews/absync/src/nsAbSync.cpp b/mozilla/mailnews/absync/src/nsAbSync.cpp index c8ad837f66a..7072c7b78b4 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->AppendNative(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->AppendNative(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..51746587eff 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)); + nsAutoString 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->SetNativeLeafName(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 62342a0884d..8e968731b2e 100644 --- a/mozilla/mailnews/addrbook/src/nsAddressBook.cpp +++ b/mozilla/mailnews/addrbook/src/nsAddressBook.cpp @@ -1324,8 +1324,8 @@ NS_IMETHODIMP nsAddressBook::ExportAddressBook(nsIAbDirectory *aDirectory) } } - nsXPIDLCString leafName; - rv = localFile->GetLeafName(getter_Copies(leafName)); + nsCAutoString leafName; + rv = localFile->GetNativeLeafName(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 2219c035fdc..7b83fee5007 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..5d77ff68d3a 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->AppendNative(NS_LITERAL_CSTRING("rulesbackup.dat")); PRBool exists; backupFile->Exists(&exists); if (exists) backupFile->Remove(PR_FALSE); - return localFilterFile->CopyTo(localParentDir, "rulesbackup.dat"); + return localFilterFile->CopyToNative(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 311b1eb933d..21308bf16d5 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 @@ -203,28 +204,23 @@ 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); + NS_ConvertUTF8toUCS2 ucs2Str(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(ucs2Str))) { - PRUnichar * tempStr; - aLocalFile->GetUnicodeLeafName(&tempStr); - ucs2Str.Adopt(tempStr); + aLocalFile->GetLeafName(ucs2Str); } #endif @@ -465,7 +461,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; @@ -473,9 +469,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; } } @@ -728,7 +725,7 @@ nsMessenger::SaveAttachment(const char * contentType, const char * url, PRInt16 dialogResult; nsCOMPtr localFile; - nsCOMPtr lastSaveDir; + nsCOMPtr lastSaveDir; nsCOMPtr fileSpec; nsXPIDLCString filePath; nsXPIDLString defaultDisplayString; @@ -766,12 +763,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: @@ -820,8 +815,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; @@ -918,10 +913,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)); + nsAutoString 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 @@ -943,11 +937,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..5eb44cc61c3 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->AppendNative(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 133a8acfef0..6f71ff751bc 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 faef6782c7f..9ff6d52296a 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 aa52eb7f6fc..b707762665f 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(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(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/nsMsgDBFolder.cpp b/mozilla/mailnews/base/util/nsMsgDBFolder.cpp index 428232021a4..fa53020fd06 100644 --- a/mozilla/mailnews/base/util/nsMsgDBFolder.cpp +++ b/mozilla/mailnews/base/util/nsMsgDBFolder.cpp @@ -531,7 +531,7 @@ NS_IMETHODIMP nsMsgDBFolder::GetOfflineFileTransport(nsMsgKey msgKey, PRUint32 * mPath->GetNativePath(getter_Copies(nativePath)); nsCOMPtr localStore; - rv = NS_NewLocalFile(nativePath, PR_TRUE, getter_AddRefs(localStore)); + rv = NS_NewNativeLocalFile(nativePath, PR_TRUE, getter_AddRefs(localStore)); if (NS_SUCCEEDED(rv) && localStore) { NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID); diff --git a/mozilla/mailnews/base/util/nsMsgIncomingServer.cpp b/mozilla/mailnews/base/util/nsMsgIncomingServer.cpp index aa1c4602b34..9190583dcf9 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 8a3b84a325f..5cc0a308482 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); @@ -3042,7 +3043,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; @@ -3054,12 +3055,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 + } } } @@ -3069,7 +3073,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 33e9c68a7b9..ddfdd17ab60 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)); + nsAutoString 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, nsString()); } } @@ -1428,11 +1429,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 c89a03400ed..85e8f983b5f 100644 --- a/mozilla/mailnews/imap/src/nsImapService.cpp +++ b/mozilla/mailnews/imap/src/nsImapService.cpp @@ -3596,13 +3596,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..a39c76e5cb8 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->AppendNative(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->AppendNative(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..5ebff071a12 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, nsString()); 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 b1709317784..8e744aca14f 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" @@ -1561,13 +1562,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->AppendNative(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 ac07dea3a63..684921c3be6 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 (nsDependentString(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,17 +540,17 @@ 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)) ; + nsAutoString 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)) ; + nsAutoString 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)) ; + nsAutoString path ; + pFile->GetPath (path) ; if(NS_FAILED(rv) || path.IsEmpty()) return rv ; // dir path of the file attachment @@ -563,10 +563,9 @@ nsresult nsMapiHook::HandleAttachments (nsIMsgCompFields * aCompFields, PRInt32 { // if not already existing, create another temp dir for mapi within Win temp dir nsAutoString strTempDir ; - strTempDir += tempPath.get() ; // this is windows only so we can do "\\" - strTempDir.AppendWithConversion("\\moz_mapi") ; - pTempDir->InitWithUnicodePath (strTempDir.get()) ; + strTempDir = tempPath + NS_LITERAL_STRING("\\moz_mapi"); + pTempDir->InitWithPath (strTempDir) ; pTempDir->Exists (&bExist) ; if (!bExist) { @@ -582,21 +581,22 @@ nsresult nsMapiHook::HandleAttachments (nsIMsgCompFields * aCompFields, PRInt32 // rename or copy the existing temp file with the real file name if (aIsUnicode) { + nsDependentString fileNameUCS2(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())) + if (!Compare(fileNameUCS2, leafName, nsCaseInsensitiveStringComparator())) { - rv = pFile->CopyToUnicode(pTempDir, aFiles[i].lpszFileName) ; - pFile->InitWithUnicodePath(strTempDir.get()) ; - pFile->AppendUnicode (aFiles[i].lpszFileName) ; + rv = pFile->CopyTo(pTempDir, fileNameUCS2); + pFile->InitWithPath(strTempDir) ; + pFile->Append(fileNameUCS2); } 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, fileNameUCS2); // 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 +613,19 @@ 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 strings if (!Compare(fileName, 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 +781,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 (strFilePaths) ; PRBool bExist ; rv = pFile->Exists(&bExist) ; @@ -816,7 +817,7 @@ nsresult nsMapiHook::PopulateCompFieldsForSendDocs(nsIMsgCompFields * aCompField newFilePaths += offset + strDelimChars.Length() ; } - pFile->InitWithUnicodePath (RemainingPaths.get()) ; + pFile->InitWithPath (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..f69be5a3bfd 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->AppendNative(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->MoveToNative(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->CopyToNative(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->MoveToNative(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/os2/nsIconChannel.cpp b/mozilla/modules/libpr0n/decoders/icon/os2/nsIconChannel.cpp index 830e5e0519a..c2962b11052 100644 --- a/mozilla/modules/libpr0n/decoders/icon/os2/nsIconChannel.cpp +++ b/mozilla/modules/libpr0n/decoders/icon/os2/nsIconChannel.cpp @@ -182,7 +182,7 @@ void InvertRows(PBYTE aInitialBuffer, PRUint32 sizeOfBuffer, PRUint32 numBytesPe 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)); @@ -379,10 +379,10 @@ void ConvertMaskBitMap(PBYTE aBitMaskBuffer, PBITMAPINFO2 pBitMapInfo, nsCString 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... @@ -392,7 +392,7 @@ NS_IMETHODIMP nsIconChannel::AsyncOpen(nsIStreamListener *aListener, nsISupports if (localFile) { - localFile->GetPath(getter_Copies(filePath)); + localFile->GetNativePath(filePath); localFile->Exists(&fileExists); } @@ -404,7 +404,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; @@ -416,10 +416,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/os2/nsIconChannel.h b/mozilla/modules/libpr0n/decoders/icon/os2/nsIconChannel.h index cb51c92b87d..bd150bf7ddc 100644 --- a/mozilla/modules/libpr0n/decoders/icon/os2/nsIconChannel.h +++ b/mozilla/modules/libpr0n/decoders/icon/os2/nsIconChannel.h @@ -56,7 +56,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); }; #define ID_ICO_FILE 5800 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..1260a4e1d28 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_NewNativeLocalFile(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 8ff5ae2b6c6..55f93663102 100644 --- a/mozilla/modules/libpref/src/nsPrefService.cpp +++ b/mozilla/modules/libpref/src/nsPrefService.cpp @@ -42,6 +42,7 @@ #include "nsDirectoryServiceDefs.h" #include "nsICategoryManager.h" #include "nsIFileStreams.h" +#include "nsILocalFile.h" #include "nsIObserverService.h" #include "nsPrefBranch.h" #include "nsXPIDLString.h" @@ -57,7 +58,7 @@ class nsIFileSpec; // needed for prefapi_private_data.h inclusion // supporting PREF_Init() #include "nsIJSRuntimeService.h" -// lose these if possible (supporting nsIFileToFileSpec) +// lose these if possible (need NS_NewFileSpecFromIFile) #include "nsIFileSpec.h" #include "nsFileStream.h" @@ -70,7 +71,6 @@ class nsIFileSpec; // needed for prefapi_private_data.h inclusion // Prototypes -static nsresult nsIFileToFileSpec(nsIFile* inFile, nsIFileSpec **aFileSpec); static nsresult openPrefFile(nsIFile* aFile, PRBool aIsErrorFatal, PRBool aIsGlobalContext, PRBool aSkipFirstLine); static nsresult savePrefFile(nsIFile* aFile); @@ -323,7 +323,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->AppendNative(NS_LITERAL_CSTRING("default_prefs.js")); if (NS_FAILED(rv)) return rv; } @@ -343,11 +343,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->AppendNative(NS_LITERAL_CSTRING("user.js")); if (NS_SUCCEEDED(rv)) { rv = openPrefFile(aFile, PR_FALSE, PR_FALSE, PR_FALSE); } @@ -366,8 +364,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 @@ -420,7 +418,7 @@ static nsresult savePrefFile(nsIFile* aFile) return NS_OK; // TODO: Convert the rest of this code to nsIFile and avoid this conversion to nsIFileSpec - rv = nsIFileToFileSpec(aFile, getter_AddRefs(fileSpec)); + rv = NS_NewFileSpecFromIFile(aFile, getter_AddRefs(fileSpec)); if (NS_FAILED(rv)) return rv; @@ -452,30 +450,6 @@ static nsresult savePrefFile(nsIFile* aFile) } -//---------------------------------------------------------------------------------------- -// 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, this code has -// such a need for it, here it is. Let's stop having to use it though. -static nsresult nsIFileToFileSpec(nsIFile* inFile, nsIFileSpec **aFileSpec) -//---------------------------------------------------------------------------------------- -{ - nsresult rv; - nsCOMPtr newFileSpec; - nsXPIDLCString pathBuf; - - rv = inFile->GetPath(getter_Copies(pathBuf)); - if (NS_FAILED(rv)) return rv; - rv = NS_NewFileSpec(getter_AddRefs(newFileSpec)); - if (NS_FAILED(rv)) return rv; - rv = newFileSpec->SetNativePath((const char *)pathBuf); - if (NS_FAILED(rv)) return rv; - - *aFileSpec = newFileSpec; - NS_ADDREF(*aFileSpec); - - return NS_OK; -} - /* * some stuff that gets called from Pref_Init() */ @@ -484,28 +458,24 @@ static nsresult nsIFileToFileSpec(nsIFile* inFile, nsIFileSpec **aFileSpec) 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; @@ -575,7 +545,7 @@ JSBool pref_InitInitialObjects() if (NS_FAILED(rv)) return JS_FALSE; - rv = aFile->Append((char *)specialFiles[0]); + rv = aFile->AppendNative(nsDependentCString((char *)specialFiles[0])); if (NS_FAILED(rv)) return JS_FALSE; @@ -586,20 +556,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) { @@ -613,8 +583,6 @@ JSBool pref_InitInitialObjects() } } } - if (leafName) - nsCRT::free((char*)leafName); } }; @@ -634,7 +602,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->AppendNative(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..c32bfe64d21 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->GetNativeLeafName(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->SetNativeLeafName(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->SetNativeLeafName(fileName); } else { // no backups desired, delete the previous save - backupFile->SetLeafName(mTargetFileName.get()); + backupFile->SetNativeLeafName(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->SetNativeLeafName(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->SetNativeLeafName(mTargetFileName); + rv = backupFile->MoveToNative(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->SetNativeLeafName(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..24570396fd8 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; // native charset 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..b5610a81a38 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) @@ -193,7 +193,7 @@ nsMPFileLocProvider::GetFile(const char *prop, PRBool *persistant, nsIFile **_re { rv = mProfileDir->Clone(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->Append(PREFS_FILE_50_NAME); + rv = localFile->AppendNative(PREFS_FILE_50_NAME); } else if (inAtom == sApp_UserProfileDirectory50) { @@ -203,19 +203,19 @@ nsMPFileLocProvider::GetFile(const char *prop, PRBool *persistant, nsIFile **_re { rv = mProfileDir->Clone(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->Append(USER_CHROME_DIR_50_NAME); + rv = localFile->AppendNative(USER_CHROME_DIR_50_NAME); } else if (inAtom == sApp_LocalStore50) { rv = mProfileDir->Clone(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->Append(LOCAL_STORE_FILE_50_NAME); + rv = localFile->AppendNative(LOCAL_STORE_FILE_50_NAME); } else if (inAtom == sApp_History50) { rv = mProfileDir->Clone(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->Append(HISTORY_FILE_50_NAME); + rv = localFile->AppendNative(HISTORY_FILE_50_NAME); } else if (inAtom == sApp_UsersPanels50) { @@ -226,7 +226,7 @@ nsMPFileLocProvider::GetFile(const char *prop, PRBool *persistant, nsIFile **_re rv = mProfileDir->Clone(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->Append(PANELS_FILE_50_NAME); + rv = localFile->AppendNative(PANELS_FILE_50_NAME); } else if (inAtom == sApp_UsersMimeTypes50) { @@ -237,19 +237,19 @@ nsMPFileLocProvider::GetFile(const char *prop, PRBool *persistant, nsIFile **_re rv = mProfileDir->Clone(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->Append(MIME_TYPES_FILE_50_NAME); + rv = localFile->AppendNative(MIME_TYPES_FILE_50_NAME); } else if (inAtom == sApp_BookmarksFile50) { rv = mProfileDir->Clone(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->Append(BOOKMARKS_FILE_50_NAME); + rv = localFile->AppendNative(BOOKMARKS_FILE_50_NAME); } else if (inAtom == sApp_DownloadsFile50) { rv = mProfileDir->Clone(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->Append(DOWNLOADS_FILE_50_NAME); + rv = localFile->AppendNative(DOWNLOADS_FILE_50_NAME); } else if (inAtom == sApp_SearchFile50) { @@ -260,31 +260,31 @@ nsMPFileLocProvider::GetFile(const char *prop, PRBool *persistant, nsIFile **_re rv = mProfileDir->Clone(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->Append(SEARCH_FILE_50_NAME); + rv = localFile->AppendNative(SEARCH_FILE_50_NAME); } else if (inAtom == sApp_MailDirectory50) { rv = mProfileDir->Clone(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->Append(MAIL_DIR_50_NAME); + rv = localFile->AppendNative(MAIL_DIR_50_NAME); } else if (inAtom == sApp_ImapMailDirectory50) { rv = mProfileDir->Clone(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->Append(IMAP_MAIL_DIR_50_NAME); + rv = localFile->AppendNative(IMAP_MAIL_DIR_50_NAME); } else if (inAtom == sApp_NewsDirectory50) { rv = mProfileDir->Clone(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->Append(NEWS_DIR_50_NAME); + rv = localFile->AppendNative(NEWS_DIR_50_NAME); } else if (inAtom == sApp_MessengerFolderCache50) { rv = mProfileDir->Clone(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->Append(MSG_FOLDER_CACHE_DIR_50_NAME); + rv = localFile->AppendNative(MSG_FOLDER_CACHE_DIR_50_NAME); } NS_RELEASE(inAtom); @@ -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)); - newChild->AppendRelativePath(leafName); + nsCAutoString leafName; + dirEntry->GetNativeLeafName(leafName); + newChild->AppendRelativeNativePath(leafName); rv = RecursiveCopy(dirEntry, newChild); } } else - rv = dirEntry->CopyTo(destDir, nsnull); + rv = dirEntry->CopyToNative(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 39430761543..572622460f7 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 65c821e3894..4bd5a393357 100644 --- a/mozilla/modules/plugin/base/src/nsPluginDirServiceProvider.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginDirServiceProvider.cpp @@ -42,6 +42,7 @@ #include "nsILocalFile.h" #include "nsIPref.h" #include "nsXPIDLString.h" +#include "nsDependentString.h" #include "prmem.h" #if defined (XP_WIN) @@ -248,7 +249,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); } } @@ -306,7 +307,7 @@ nsPluginDirServiceProvider::GetFile(const char *prop, PRBool *persistant, nsIFil // if nothing is found, then don't add \bin dir 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)); } } else if (nsCRT::strcmp(prop, NS_WIN_QUICKTIME_SCAN_KEY) == 0) { nsXPIDLCString strVer; @@ -340,7 +341,7 @@ nsPluginDirServiceProvider::GetFile(const char *prop, PRBool *persistant, nsIFil result = ::RegQueryValueEx(keyloc, "InstallDir", NULL, &type, (LPBYTE)&path, &pathlen); PL_strcat(path, "\\Plugins"); 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); } } else if (nsCRT::strcmp(prop, NS_WIN_WMP_SCAN_KEY) == 0) { @@ -370,7 +371,7 @@ nsPluginDirServiceProvider::GetFile(const char *prop, PRBool *persistant, nsIFil if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_LOCAL_MACHINE, "software\\Microsoft\\MediaPlayer", 0, KEY_READ, &keyloc)) { if (ERROR_SUCCESS == ::RegQueryValueEx(keyloc, "Installation Directory", NULL, &type, (LPBYTE)&path, &pathlen)) - rv = NS_NewLocalFile(path, PR_TRUE, getter_AddRefs(localFile)); + rv = NS_NewNativeLocalFile(nsDependentCString(path), PR_TRUE, getter_AddRefs(localFile)); ::RegCloseKey(keyloc); } } else if (nsCRT::strcmp(prop, NS_WIN_ACROBAT_SCAN_KEY) == 0) { @@ -428,7 +429,7 @@ nsPluginDirServiceProvider::GetFile(const char *prop, PRBool *persistant, nsIFil ::RegCloseKey(baseloc); if (newestPath[0] != 0) { PL_strcat(newestPath,"\\browser"); - rv = NS_NewLocalFile(newestPath, PR_TRUE, getter_AddRefs(localFile)); + rv = NS_NewNativeLocalFile(nsDependentCString(newestPath), PR_TRUE, getter_AddRefs(localFile)); } } diff --git a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp index ee0f4119598..92f5a743714 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; } @@ -1912,7 +1896,7 @@ nsPluginStreamListenerPeer::SetupPluginCacheFile(nsIChannel* channel) rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(pluginTmp)); if (NS_FAILED(rv)) return rv; - rv = pluginTmp->Append(kPluginTmpDirName); + rv = pluginTmp->AppendNative(kPluginTmpDirName); if (NS_FAILED(rv)) return rv; (void) pluginTmp->Create(nsIFile::DIRECTORY_TYPE,0777); @@ -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)); } ///////////////////////////////////////////////////////////////////////// @@ -3345,7 +3324,7 @@ NS_IMETHODIMP nsPluginHostImpl::Destroy(void) nsresult rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(pluginTmp)); if (NS_FAILED(rv)) return rv; - rv = pluginTmp->Append(kPluginTmpDirName); + rv = pluginTmp->AppendNative(kPluginTmpDirName); if (NS_FAILED(rv)) return rv; pluginTmp->Remove(PR_TRUE); @@ -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); @@ -5180,10 +5159,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. @@ -5207,7 +5184,7 @@ cidToDllname(nsIComponentManager* aComponentManager, nsIRegistry* aRegistry, getter_AddRefs(file)); if (NS_SUCCEEDED(rv)) { - file->GetPath(dllName); + file->GetNativePath(dllName); } nsCRT::free(NS_REINTERPRET_CAST(char*, library)); @@ -5458,13 +5435,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; @@ -5976,14 +5953,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; } @@ -5998,14 +5975,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; } @@ -6395,14 +6372,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 file = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv); if (NS_FAILED(rv) || (NS_FAILED(rv = NS_InitFileFromURLSpec(file, nsDependentCString(postDataURL))) && - NS_FAILED(rv = file->InitWithPath(postDataURL))) || + NS_FAILED(rv = file->InitWithNativePath(nsDependentCString(postDataURL)))) || NS_FAILED(rv = file->GetFileSize(&fileSize)) || - NS_FAILED(rv = file->GetPath(getter_Copies(filename))) + NS_FAILED(rv = file->GetNativePath(filename)) ) return rv; if (!LL_IS_ZERO(fileSize)) { @@ -6416,7 +6393,7 @@ nsPluginHostImpl::CreateTmpFileToPost(const char *postDataURL, char **pTmpFileNa nsresult rv; rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(tempFile)); if (tempFile) { - tempFile->Append("pluginpost"); + tempFile->AppendNative(NS_LITERAL_CSTRING("pluginpost")); // mode is 0600 so that it's not world-readable rv = tempFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0600); } @@ -6451,9 +6428,9 @@ nsPluginHostImpl::CreateTmpFileToPost(const char *postDataURL, char **pTmpFileNa inStream->Close(); outStream->Close(); if (NS_SUCCEEDED(rv)) { - nsXPIDLCString tempFileName; - tempFile->GetPath(getter_Copies(tempFileName)); - *pTmpFileName = PL_strdup(tempFileName); + nsCAutoString tempFileName; + tempFile->GetNativePath(tempFileName); + *pTmpFileName = ToNewCString(tempFileName); } } return rv; @@ -6484,15 +6461,15 @@ nsPluginHostImpl::ScanForRealInComponentsFolder(nsIComponentManager * aCompManag return rv; // make sure the file is actually there - RealPlugin->Append("nppl3260.dll"); + RealPlugin->AppendNative(NS_LITERAL_CSTRING("nppl3260.dll")); PRBool exists; - nsXPIDLCString filePath; + nsCAutoString filePath; RealPlugin->Exists(&exists); - if (!exists || NS_FAILED(RealPlugin->GetPath(getter_Copies(filePath)))) + if (!exists || NS_FAILED(RealPlugin->GetNativePath(filePath))) return rv; // now make sure it's a plugin - nsFileSpec file(filePath); + nsFileSpec file(filePath.get()); if (!nsPluginsDir::IsPluginFile(file)) return rv; diff --git a/mozilla/netwerk/base/public/nsNetUtil.h b/mozilla/netwerk/base/public/nsNetUtil.h index 94d08e8e6c1..5a1c2d88636 100644 --- a/mozilla/netwerk/base/public/nsNetUtil.h +++ b/mozilla/netwerk/base/public/nsNetUtil.h @@ -280,7 +280,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 { @@ -290,7 +290,7 @@ NS_NewPostDataStream(nsIInputStream **result, nsCOMPtr file; nsCOMPtr fileStream; - rv = NS_NewLocalFile(data, PR_FALSE, getter_AddRefs(file)); + rv = NS_NewNativeLocalFile(data, PR_FALSE, getter_AddRefs(file)); if (NS_FAILED(rv)) return rv; rv = NS_NewLocalFileInputStream(getter_AddRefs(fileStream), file); @@ -301,7 +301,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 ec48f2611b2..72caec03d6f 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,11 +386,11 @@ nsFileIO::GetName(nsACString &aName) if (mFile == nsnull) return NS_ERROR_NOT_INITIALIZED; - nsXPIDLCString path; - nsresult rv = mFile->GetPath(getter_Copies(path)); + nsAutoString path; + nsresult rv = mFile->GetPath(path); if (NS_FAILED(rv)) return rv; - aName = path; + aName = NS_ConvertUCS2toUTF8(path); return NS_OK; } diff --git a/mozilla/netwerk/base/src/nsFileStreams.h b/mozilla/netwerk/base/src/nsFileStreams.h index e3425e92c78..a7ea3ced89e 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 23ba563b780..966fbabc760 100644 --- a/mozilla/netwerk/base/src/nsStandardURL.cpp +++ b/mozilla/netwerk/base/src/nsStandardURL.cpp @@ -2177,8 +2177,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..6e7fdd1b6f0 100644 --- a/mozilla/netwerk/cache/src/nsDiskCacheDevice.cpp +++ b/mozilla/netwerk/cache/src/nsDiskCacheDevice.cpp @@ -178,11 +178,11 @@ NS_IMETHODIMP nsDiskCacheDeviceInfo::GetUsageReport(char ** usageReport) buffer.Append("Cache Directory: "); nsCOMPtr cacheDir; - char * path; + nsAutoString path; mDevice->getCacheDirectory(getter_AddRefs(cacheDir)); - nsresult rv = cacheDir->GetPath(&path); + nsresult rv = cacheDir->GetPath(path); if (NS_SUCCEEDED(rv)) { - buffer.Append(path); + buffer.Append(NS_ConvertUCS2toUTF8(path)); } else { buffer.Append("directory unavailable"); } @@ -758,7 +758,7 @@ nsDiskCacheDevice::InitializeCacheDirectory() } // create a directory with unique name to contain existing cache directory - rv = cacheTrashDir->Append("Cache"); + rv = cacheTrashDir->AppendNative(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->MoveToNative(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->SetNativeLeafName(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->AppendNative(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->AppendNative(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->AppendNative(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..0435f87ab12 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->AppendNative(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..44d19210165 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->AppendNative(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->AppendNative(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..beae69682af 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->GetNativePath(inDir); + (void)outDirSpec->GetNativePath(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->GetNativeLeafName(leafName); if (NS_FAILED(rv)) goto done; - rv = outSpec->Append(leafName); - nsCRT::free(leafName); + rv = outSpec->AppendNative(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..0b1dfc6ca36 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->GetNativeLeafName(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->SetNativeLeafName(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/netwerk/test/TestWriteStream.cpp b/mozilla/netwerk/test/TestWriteStream.cpp index cb346571138..92952a89cdd 100644 --- a/mozilla/netwerk/test/TestWriteStream.cpp +++ b/mozilla/netwerk/test/TestWriteStream.cpp @@ -129,7 +129,7 @@ TestSyncWrite(char* filename, PRUint32 startPosition, PRInt32 length) if (NS_FAILED(rv)) return rv ; nsCOMPtr fs; - rv = NS_NewLocalFile(filename, PR_FALSE, getter_AddRefs(fs)); + rv = NS_NewNativeLocalFile(nsDependentCString(filename), PR_FALSE, getter_AddRefs(fs)); if (NS_FAILED(rv)) return rv ; nsCOMPtr transport; diff --git a/mozilla/profile/pref-migrator/src/nsPrefMigration.cpp b/mozilla/profile/pref-migrator/src/nsPrefMigration.cpp index 3e5620c9a6a..137f9dd6ca1 100644 --- a/mozilla/profile/pref-migrator/src/nsPrefMigration.cpp +++ b/mozilla/profile/pref-migrator/src/nsPrefMigration.cpp @@ -48,7 +48,10 @@ #include "nsIWindowMediator.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" @@ -614,34 +617,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->AppendNative(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->CopyToNative(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->AppendNative(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(); @@ -1120,9 +1117,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->AppendNative(NS_LITERAL_CSTRING(PREF_FILE_NAME_IN_5x)); if (NS_FAILED(rv)) return rv; rv=m_prefs->SavePrefFile(newPrefsFile); @@ -1135,9 +1132,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; } @@ -1250,7 +1247,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)); @@ -2014,7 +2011,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(localizedDirName); if (NS_FAILED(rv)) return rv; PRBool exists = PR_FALSE; @@ -2031,10 +2028,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 e483d4e9017..ba60fd50abc 100644 --- a/mozilla/profile/src/nsProfile.cpp +++ b/mozilla/profile/src/nsProfile.cpp @@ -238,14 +238,14 @@ nsresult RecursiveCopy(nsIFile* srcDir, nsIFile* destDir) if (NS_SUCCEEDED(rv)) { nsCOMPtr newChild(do_QueryInterface(destClone)); - nsXPIDLCString leafName; - dirEntry->GetLeafName(getter_Copies(leafName)); - newChild->AppendRelativePath(leafName); + nsCAutoString leafName; + dirEntry->GetNativeLeafName(leafName); + newChild->AppendRelativeNativePath(leafName); rv = RecursiveCopy(dirEntry, newChild); } } else - rv = dirEntry->CopyTo(destDir, nsnull); + rv = dirEntry->CopyToNative(destDir, nsCString()); } } @@ -444,18 +444,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; @@ -466,9 +466,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 chromeRegistry->GetSelectedLocale() doesn't @@ -860,7 +860,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(currProfileDirString, PR_TRUE, getter_AddRefs(currProfileDir)); NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE); } else { @@ -872,9 +872,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); + nsAutoString currProfilePath; + currProfileDir->GetPath(currProfilePath); + rv = CreateNewProfile(currProfileName.get(), currProfilePath.get(), nsnull, PR_TRUE); if (NS_SUCCEEDED(rv)) { *profileDirSet = PR_TRUE; mCurrentProfileAvailable = PR_TRUE; @@ -1048,7 +1048,12 @@ NS_IMETHODIMP nsProfile::GetProfilePath(const PRUnichar *profileName, PRUnichar if (NS_SUCCEEDED(rv)) prettyDir = parentDir; } - return prettyDir->GetUnicodePath(_retval); + nsAutoString path; + rv = prettyDir->GetPath(path); + if (NS_FAILED(rv)) return rv; + + *_retval = ToNewUnicode(path); + return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } NS_IMETHODIMP nsProfile::GetOriginalProfileDir(const PRUnichar *profileName, nsILocalFile **originalDir) @@ -1088,7 +1093,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->AppendNative(NS_LITERAL_CSTRING("prefs.js")); if (NS_FAILED(rv)) return rv; return profileDir->GetLastModifiedTime(_retval); @@ -1333,7 +1338,7 @@ nsProfile::AddLevelOfIndirection(nsIFile *aDir) rv = aDir->Clone(getter_AddRefs(prefFile)); NS_ENSURE_SUCCESS(rv,rv); - rv = prefFile->Append("prefs.js"); + rv = prefFile->AppendNative(NS_LITERAL_CSTRING("prefs.js")); NS_ENSURE_SUCCESS(rv,rv); rv = prefFile->Exists(&exists); @@ -1361,16 +1366,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; } } @@ -1399,7 +1404,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; @@ -1420,16 +1425,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())) ); @@ -1546,16 +1550,16 @@ nsProfile::CreateNewProfileWithLocales(const PRUnichar* profileName, profileDir->Create(nsIFile::DIRECTORY_TYPE, 0775); // append profile name - profileDir->AppendUnicode(profileName); + profileDir->Append(nsDependentString(profileName)); } else { - rv = NS_NewUnicodeLocalFile(nativeProfileDir, PR_TRUE, (nsILocalFile **)((nsIFile **)getter_AddRefs(profileDir))); + rv = NS_NewLocalFile(nsDependentString(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(nsDependentString(profileName)); } @@ -1637,12 +1641,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, @@ -1650,7 +1655,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); } } @@ -1661,17 +1666,15 @@ nsProfile::CreateNewProfileWithLocales(const PRUnichar* profileName, rv = profDefaultsDir->Clone(getter_AddRefs(locProfDefaultsDir)); if (NS_FAILED(rv)) return rv; - locProfDefaultsDir->AppendUnicode(contentLocale); + locProfDefaultsDir->Append(nsDependentString(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 } @@ -1680,7 +1683,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); } } @@ -2035,7 +2038,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; @@ -2044,11 +2047,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; @@ -2075,11 +2078,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; } @@ -2104,7 +2106,7 @@ nsProfile::DefineLocaleDefaultsDir() nsXPIDLString localeName; rv = chromeRegistry->GetSelectedLocale(NS_LITERAL_STRING("global-region").get(), getter_Copies(localeName)); if (NS_SUCCEEDED(rv)) - rv = localeDefaults->AppendUnicode(localeName); + rv = localeDefaults->Append(localeName); } (void) directoryService->Undefine(NS_APP_PROFILE_DEFAULTS_50_DIR); rv = directoryService->Define(NS_APP_PROFILE_DEFAULTS_50_DIR, localeDefaults); @@ -2170,16 +2172,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; @@ -2267,7 +2269,7 @@ nsProfile::MigrateProfile(const PRUnichar* profileName) if (NS_FAILED(rv)) return rv; - rv = newProfDir->AppendUnicode(profileName); + rv = newProfDir->Append(nsDependentString(profileName)); if (NS_FAILED(rv)) return rv; @@ -2303,14 +2305,14 @@ 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); // leave .slt alone, // and remigrate the 4.x profile into .slt-new nsCAutoString newDirLeafName(origDirLeafName + NS_LITERAL_CSTRING("-new")); - rv = newProfileDir->SetLeafName(newDirLeafName.get()); + rv = newProfileDir->SetNativeLeafName(newDirLeafName); NS_ENSURE_SUCCESS(rv,rv); // Create a new directory for the remigrated profile @@ -2416,7 +2418,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(nsDependentString(newProfile)); // Find a unique name in the dest dir rv = destDir->CreateUnique(nsIFile::DIRECTORY_TYPE, 0775); @@ -2454,11 +2456,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)); + nsAutoString 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, profilePath.get(), nsnull, PR_TRUE); return rv; } @@ -2517,19 +2519,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) @@ -2556,7 +2558,7 @@ nsProfile::GetFile(const char *prop, PRBool *persistant, nsIFile **_retval) { rv = CloneProfileDirectorySpec(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->Append(PREFS_FILE_50_NAME); // AppendRelativePath + rv = localFile->AppendNative(PREFS_FILE_50_NAME); // AppendRelativePath } else if (inAtom == sApp_UserProfileDirectory50) { @@ -2566,7 +2568,7 @@ nsProfile::GetFile(const char *prop, PRBool *persistant, nsIFile **_retval) { rv = CloneProfileDirectorySpec(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->Append(USER_CHROME_DIR_50_NAME); + rv = localFile->AppendNative(USER_CHROME_DIR_50_NAME); } else if (inAtom == sApp_LocalStore50) { @@ -2576,7 +2578,7 @@ nsProfile::GetFile(const char *prop, PRBool *persistant, nsIFile **_retval) rv = CloneProfileDirectorySpec(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) { - rv = localFile->Append(LOCAL_STORE_FILE_50_NAME); + rv = localFile->AppendNative(LOCAL_STORE_FILE_50_NAME); if (NS_SUCCEEDED(rv)) rv = EnsureProfileFileExists(localFile); } @@ -2585,7 +2587,7 @@ nsProfile::GetFile(const char *prop, PRBool *persistant, nsIFile **_retval) { rv = CloneProfileDirectorySpec(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->Append(HISTORY_FILE_50_NAME); + rv = localFile->AppendNative(HISTORY_FILE_50_NAME); } else if (inAtom == sApp_UsersPanels50) { @@ -2596,7 +2598,7 @@ nsProfile::GetFile(const char *prop, PRBool *persistant, nsIFile **_retval) rv = CloneProfileDirectorySpec(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) { - rv = localFile->Append(PANELS_FILE_50_NAME); + rv = localFile->AppendNative(PANELS_FILE_50_NAME); if (NS_SUCCEEDED(rv)) rv = EnsureProfileFileExists(localFile); } @@ -2609,7 +2611,7 @@ nsProfile::GetFile(const char *prop, PRBool *persistant, nsIFile **_retval) rv = CloneProfileDirectorySpec(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) { - rv = localFile->Append(MIME_TYPES_FILE_50_NAME); + rv = localFile->AppendNative(MIME_TYPES_FILE_50_NAME); if (NS_SUCCEEDED(rv)) rv = EnsureProfileFileExists(localFile); } @@ -2622,7 +2624,7 @@ nsProfile::GetFile(const char *prop, PRBool *persistant, nsIFile **_retval) rv = CloneProfileDirectorySpec(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) { - rv = localFile->Append(BOOKMARKS_FILE_50_NAME); + rv = localFile->AppendNative(BOOKMARKS_FILE_50_NAME); if (NS_SUCCEEDED(rv)) rv = EnsureProfileFileExists(localFile); } @@ -2631,7 +2633,7 @@ nsProfile::GetFile(const char *prop, PRBool *persistant, nsIFile **_retval) { rv = CloneProfileDirectorySpec(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->Append(DOWNLOADS_FILE_50_NAME); + rv = localFile->AppendNative(DOWNLOADS_FILE_50_NAME); } else if (inAtom == sApp_SearchFile50) { @@ -2642,7 +2644,7 @@ nsProfile::GetFile(const char *prop, PRBool *persistant, nsIFile **_retval) rv = CloneProfileDirectorySpec(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) { - rv = localFile->Append(SEARCH_FILE_50_NAME); + rv = localFile->AppendNative(SEARCH_FILE_50_NAME); if (NS_SUCCEEDED(rv)) rv = EnsureProfileFileExists(localFile); } @@ -2651,25 +2653,25 @@ nsProfile::GetFile(const char *prop, PRBool *persistant, nsIFile **_retval) { rv = CloneProfileDirectorySpec(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->Append(MAIL_DIR_50_NAME); + rv = localFile->AppendNative(MAIL_DIR_50_NAME); } else if (inAtom == sApp_ImapMailDirectory50) { rv = CloneProfileDirectorySpec(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->Append(IMAP_MAIL_DIR_50_NAME); + rv = localFile->AppendNative(IMAP_MAIL_DIR_50_NAME); } else if (inAtom == sApp_NewsDirectory50) { rv = CloneProfileDirectorySpec(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->Append(NEWS_DIR_50_NAME); + rv = localFile->AppendNative(NEWS_DIR_50_NAME); } else if (inAtom == sApp_MessengerFolderCache50) { rv = CloneProfileDirectorySpec(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->Append(MSG_FOLDER_CACHE_DIR_50_NAME); + rv = localFile->AppendNative(MSG_FOLDER_CACHE_DIR_50_NAME); } NS_RELEASE(inAtom); 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 2a306cb492d..ea4aeee8909 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(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(nsString(), 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(regLocationData, PR_TRUE, getter_AddRefs(tempLocal)); } if (NS_SUCCEEDED(rv) && tempLocal) @@ -1425,21 +1417,19 @@ 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)); + rv = resolvedLocation->GetPath(regData); if (NS_FAILED(rv)) return rv; - regData = ucPath; #endif rv = aRegistry->SetString(profKey, @@ -1475,7 +1465,7 @@ nsresult ProfileStruct::InternalizeMigratedFromLocation(nsIRegistry *aRegistry, if (NS_SUCCEEDED(rv)) { #ifdef XP_MAC - rv = NS_NewLocalFile(nsnull, PR_TRUE, getter_AddRefs(tempLocal)); + rv = NS_NewLocalFile(nsString(), PR_TRUE, getter_AddRefs(tempLocal)); if (NS_SUCCEEDED(rv)) { // The persistent desc on Mac is base64 encoded so plain ASCII @@ -1484,7 +1474,7 @@ nsresult ProfileStruct::InternalizeMigratedFromLocation(nsIRegistry *aRegistry, migratedFrom = tempLocal; } #else - rv = NS_NewUnicodeLocalFile(NS_ConvertUTF8toUCS2(regData).get(), PR_TRUE, getter_AddRefs(tempLocal)); + rv = NS_NewLocalFile(NS_ConvertUTF8toUCS2(regData), PR_TRUE, getter_AddRefs(tempLocal)); if (NS_SUCCEEDED(rv)) migratedFrom = tempLocal; #endif @@ -1502,10 +1492,9 @@ nsresult ProfileStruct::ExternalizeMigratedFromLocation(nsIRegistry *aRegistry, #if XP_MAC rv = migratedFrom->GetPersistentDescriptor(getter_Copies(regData)); #else - nsXPIDLString ucPath; - rv = resolvedLocation->GetUnicodePath(getter_Copies(ucPath)); - if (NS_SUCCEEDED(rv)) - regData = NS_ConvertUCS2toUTF8(ucPath); + nsAutoString path; + rv = resolvedLocation->GetPath(path); + regData = NS_ConvertUCS2toUTF8(path); #endif if (NS_SUCCEEDED(rv)) diff --git a/mozilla/rdf/chrome/src/nsChromeRegistry.cpp b/mozilla/rdf/chrome/src/nsChromeRegistry.cpp index a510cb2a75c..d1cecd0671a 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 nsCString& 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); @@ -2082,10 +2083,9 @@ nsChromeRegistry::IsProviderSetForPackage(const nsCString& 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; @@ -2171,8 +2171,7 @@ NS_IMETHODIMP nsChromeRegistry::InstallProvider(const nsCString& 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"); @@ -2536,8 +2535,7 @@ nsChromeRegistry::UninstallProvider(const nsCString& 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"); @@ -2608,15 +2606,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->AppendNative(NS_LITERAL_CSTRING("chrome")); + defaultUserContentFile->AppendNative(NS_LITERAL_CSTRING("userContent.css")); + defaultUserChromeFile->AppendNative(NS_LITERAL_CSTRING("chrome")); + defaultUserChromeFile->AppendNative(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->CopyToNative(userChromeDir, nsCString()); + (void) defaultUserChromeFile->CopyToNative(userChromeDir, nsCString()); } } if (NS_FAILED(rv)) @@ -2748,17 +2746,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; @@ -3049,12 +3046,12 @@ nsChromeRegistry::CheckForNewChrome() nsCOMPtr chromeFile; rv = listFile->Clone(getter_AddRefs(chromeFile)); if (NS_FAILED(rv)) return rv; - rv = chromeFile->Append(kChromeFileName); + rv = chromeFile->AppendNative(kChromeFileName); if (NS_FAILED(rv)) return rv; nsInt64 chromeDate; (void)chromeFile->GetLastModifiedTime(&chromeDate.mValue); - rv = listFile->AppendRelativePath(kInstalledChromeFileName); + rv = listFile->AppendRelativeNativePath(kInstalledChromeFileName); if (NS_FAILED(rv)) return rv; nsInt64 listFileDate; (void)listFile->GetLastModifiedTime(&listFileDate.mValue); @@ -3158,7 +3155,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; @@ -3219,9 +3217,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..44295531c43 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))) + nsAutoString 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; + nsAutoString 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); diff --git a/mozilla/security/manager/ssl/src/nsNSSComponent.cpp b/mozilla/security/manager/ssl/src/nsNSSComponent.cpp index 920d9c5cd91..14963411b52 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 "nss.h" #include "pk11func.h" @@ -267,9 +268,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*/ @@ -356,7 +357,7 @@ nsNSSComponent::InstallLoadableRoots() } if (!hasRoot) { nsresult rv; - nsString modName; + nsAutoString modName; rv = GetPIPNSSBundleString(NS_LITERAL_STRING("RootCertModuleName").get(), modName); if (NS_FAILED(rv)) return; @@ -367,7 +368,7 @@ nsNSSComponent::InstallLoadableRoots() return; directoryService->Get( NS_XPCOM_CURRENT_PROCESS_DIR, - NS_GET_IID(nsIFile), + NS_GET_IID(nsILocalFile), getter_AddRefs(mozFile)); if (!mozFile) { @@ -375,23 +376,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 } } @@ -861,7 +864,7 @@ nsNSSComponent::InitializeNSS() certHashtable_valueCompare, 0, 0 ); nsresult rv; - nsXPIDLCString profileStr; + nsCAutoString profileStr; nsCOMPtr profilePath; rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, @@ -874,12 +877,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; @@ -902,7 +905,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) { @@ -913,11 +916,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 520cd3eda9e..e943b00f2b8 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.8.1 2002-04-10 03:24:05 cltbld%netscape.com Exp $ + * $Id: nsPKCS12Blob.cpp,v 1.24.8.2 2002-05-13 22:08:47 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,7 +258,6 @@ nsPKCS12Blob::ExportToFile(nsILocalFile *file, SEC_PKCS12ExportContext *ecx = NULL; SEC_PKCS12SafeInfo *certSafe = NULL, *keySafe = NULL; SECItem unicodePw; - nsXPIDLCString xpidlFilePath; nsAutoString filePath; int i; nsCOMPtr localFileRef; @@ -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. @@ -364,7 +363,7 @@ nsPKCS12Blob::ExportToFile(nsILocalFile *file, filePath.Append(NS_LITERAL_STRING(".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()); + tmpFile->AppendNative(PIP_PKCS12_TMPFILENAME); + 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..9a5766f3648 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(nsDependentString(platformAppPath)); *aFile = localFile; NS_IF_ADDREF(*aFile); } diff --git a/mozilla/uriloader/exthandler/nsExternalHelperAppService.cpp b/mozilla/uriloader/exthandler/nsExternalHelperAppService.cpp index 90c0361c3d2..bfefde9163e 100644 --- a/mozilla/uriloader/exthandler/nsExternalHelperAppService.cpp +++ b/mozilla/uriloader/exthandler/nsExternalHelperAppService.cpp @@ -949,7 +949,7 @@ nsresult nsExternalAppHandler::RetargetLoadNotifications(nsIRequest *request) #define SALT_SIZE 8 #define TABLE_SIZE 36 -const char table[] = +const PRUnichar table[] = { 'a','b','c','d','e','f','g','h','i','j', 'k','l','m','n','o','p','q','r','s','t', 'u','v','w','x','y','z','0','1','2','3', @@ -972,16 +972,15 @@ void nsExternalAppHandler::EnsureSuggestedFileName() { // Get mSuggestedFileName's current extension. nsAutoString fileExt; - PRInt32 pos = mSuggestedFileName.RFindChar(PRUnichar('.')); + 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, nsCaseInsensitiveStringComparator())) { // Doesn't match, so force mSuggestedFileName to have the extension we want. - mSuggestedFileName.Append(tempFileExt); + mSuggestedFileName.Append(mTempFileExtension); } } } @@ -1032,8 +1031,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 = NS_ConvertUTF8toUCS2(leafName); // XXX leafName may not be UTF-8 #ifndef XP_MAC // Make sure extension is still correct. @@ -1046,7 +1045,7 @@ nsresult nsExternalAppHandler::SetUpTempFile(nsIChannel * aChannel) } // step (2), generate a salted file name for the temp file.... - nsCAutoString saltedTempLeafName; + nsAutoString saltedTempLeafName; // this salting code was ripped directly from the profile manager. // turn PR_Now() into milliseconds since epoch 1058 // and salt rand with that. double fpTime; @@ -1061,7 +1060,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); @@ -1195,7 +1194,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 nsAFlatString &path) { nsAutoString msgId; switch(rv) @@ -1240,7 +1239,7 @@ static void SendStatusChange( if (NS_SUCCEEDED(s->CreateBundle("chrome://global/locale/nsWebBrowserPersist.properties", getter_AddRefs(bundle)))) { nsXPIDLString msgText; - const PRUnichar *strings[] = { path }; + const PRUnichar *strings[] = { path.get() }; if(NS_SUCCEEDED(bundle->FormatStringFromName(msgId.get(), strings, 1, getter_Copies(msgText)))) { aListener->OnStatusChange(nsnull, (type == kReadError) ? aRequest : nsnull, rv, msgText); @@ -1321,10 +1320,10 @@ NS_IMETHODIMP nsExternalAppHandler::OnDataAvailable(nsIRequest *request, nsISupp // An error occurred, notify listener. if (mWebProgressListener) { - nsXPIDLString tempFilePath; + nsAutoString 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); } } } @@ -1405,8 +1404,8 @@ nsresult nsExternalAppHandler::Init(nsIMIMEInfo * aMIMEInfo, const char * aTempF // make sure the extention includes the '.' if (aTempFileExtension && *aTempFileExtension != '.') - mTempFileExtension = "."; - mTempFileExtension.Append(aTempFileExtension); + mTempFileExtension = PRUnichar('.'); + mTempFileExtension.AppendWithConversion(aTempFileExtension); return NS_OK; } @@ -1458,7 +1457,7 @@ nsresult nsExternalAppHandler::ShowProgressDialog() nsCOMPtr file = do_QueryInterface(appl); if (file) { - file->GetUnicodeLeafName(getter_Copies(openWith)); + file->GetLeafName(openWith); } } } @@ -1475,7 +1474,7 @@ nsresult nsExternalAppHandler::ShowProgressDialog() return rv; } -nsresult nsExternalAppHandler::PromptForSaveToFile(nsILocalFile ** aNewFile, const PRUnichar * aDefaultFile, const PRUnichar * aFileExtension) +nsresult nsExternalAppHandler::PromptForSaveToFile(nsILocalFile ** aNewFile, const nsAFlatString &aDefaultFile, const nsAFlatString &aFileExtension) { // invoke the dialog!!!!! use mWindowContext as the window context parameter for the dialog request // XXX Convert to use file picker? @@ -1490,8 +1489,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, + aDefaultFile.get(), + aFileExtension.get(), + aNewFile); return rv; } @@ -1517,20 +1518,20 @@ 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->GetNativeLeafName(fileName); nsCOMPtr directoryLocation; fileToUse->GetParent(getter_AddRefs(directoryLocation)); if (directoryLocation) { - rv = mTempFile->MoveTo(directoryLocation, fileName); + rv = mTempFile->MoveToNative(directoryLocation, fileName); } if (NS_FAILED(rv) && mWebProgressListener) { // Send error notification. - nsXPIDLString path; - fileToUse->GetUnicodePath(getter_Copies(path)); - SendStatusChange(kWriteError, rv, nsnull, mWebProgressListener, path.get()); + nsAutoString path; + fileToUse->GetPath(path); + SendStatusChange(kWriteError, rv, nsnull, mWebProgressListener, path); } } @@ -1555,21 +1556,21 @@ NS_IMETHODIMP nsExternalAppHandler::SaveToDisk(nsIFile * aNewFileLocation, PRBoo if (!aNewFileLocation) { - nsXPIDLString leafName; + nsAutoString 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('.')); + 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) @@ -1611,9 +1612,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()); + nsAutoString path; + mFinalFileDestination->GetPath(path); + SendStatusChange(kLaunchError, rv, nsnull, mWebProgressListener, path); } #ifndef XP_MAC @@ -1667,12 +1668,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); @@ -1945,30 +1944,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->GetNativeLeafName(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..c7f321ed8aa 100644 --- a/mozilla/uriloader/exthandler/nsExternalHelperAppService.h +++ b/mozilla/uriloader/exthandler/nsExternalHelperAppService.h @@ -169,7 +169,7 @@ public: protected: nsCOMPtr mTempFile; nsCOMPtr mSourceUrl; - nsCString mTempFileExtension; + nsString mTempFileExtension; nsCOMPtr mMimeInfo; nsCOMPtr mOutStream; // output stream to the temp file... nsCOMPtr mWindowContext; @@ -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 nsAFlatString &aDefaultFile, const nsAFlatString &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/os2/nsOSHelperAppService.cpp b/mozilla/uriloader/exthandler/os2/nsOSHelperAppService.cpp index 0d2dc2c8db7..018e00209dc 100644 --- a/mozilla/uriloader/exthandler/os2/nsOSHelperAppService.cpp +++ b/mozilla/uriloader/exthandler/os2/nsOSHelperAppService.cpp @@ -227,7 +227,7 @@ nsresult nsOSHelperAppService::GetFileTokenForPath(const PRUnichar * platformApp if (localFile) { if (localFile) - localFile->InitWithUnicodePath(platformAppPath); + localFile->InitWithPath(nsDependentString(platformAppPath)); *aFile = localFile; NS_IF_ADDREF(*aFile); } diff --git a/mozilla/uriloader/exthandler/unix/nsOSHelperAppService.cpp b/mozilla/uriloader/exthandler/unix/nsOSHelperAppService.cpp index 7cf6f53a51f..cd1941ca157 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(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(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(nsDependentString(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,10 @@ 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); + // XXX provided the string code has all it's bugs fixed, we should be able to + // remove this PromiseFlatCString call. + localFile->InitWithNativePath(PromiseFlatCString(Substring(start_iter, colon_iter))); + rv = localFile->AppendRelativePath(nsDependentString(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..26e28903bf0 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(nsDependentString(platformAppPath)); *aFile = localFile; NS_IF_ADDREF(*aFile); } diff --git a/mozilla/widget/src/beos/nsFilePicker.cpp b/mozilla/widget/src/beos/nsFilePicker.cpp index 653b9d14931..d669c0ebb40 100644 --- a/mozilla/widget/src/beos/nsFilePicker.cpp +++ b/mozilla/widget/src/beos/nsFilePicker.cpp @@ -117,10 +117,10 @@ NS_IMETHODIMP nsFilePicker::Show(PRInt16 *retval) } // set initial directory - char * initialDir; - mDisplayDirectory->GetPath(&initialDir); - if (initialDir) - ppanel->SetPanelDirectory(initialDir); + nsCAutoString initialDir; + mDisplayDirectory->GetNativePath(initialDir); + if(initialDir.IsEmpty()) + ppanel->SetPanelDirectory(initialDir.get()); // set modal feel if (ppanel->LockLooper()) { @@ -171,7 +171,7 @@ NS_IMETHODIMP nsFilePicker::Show(PRInt16 *retval) BEntry dir_entry(&dir_ref); BPath dir_path; dir_entry.GetPath(&dir_path); - mDisplayDirectory->InitWithPath(dir_path.Path()); + mDisplayDirectory->InitWithNativePath(nsDependentCString(dir_path.Path())); if (ppanel->Lock()) { ppanel->Quit(); @@ -187,7 +187,7 @@ NS_IMETHODIMP nsFilePicker::Show(PRInt16 *retval) NS_ENSURE_TRUE(file, NS_ERROR_FAILURE); - file->InitWithPath(mFile.get()); + file->InitWithNativePath(mFile); PRBool exists = PR_FALSE; file->Exists(&exists); @@ -217,7 +217,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); @@ -229,7 +229,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/os2/nsDragService.cpp b/mozilla/widget/src/os2/nsDragService.cpp index f7ba06528e8..edeb86ede22 100644 --- a/mozilla/widget/src/os2/nsDragService.cpp +++ b/mozilla/widget/src/os2/nsDragService.cpp @@ -125,13 +125,14 @@ NS_IMETHODIMP nsDragService::InvokeDragSession(nsIDOMNode *aDOMNode, nsISupports if( urlObject ) { nsXPIDLString urlInfo; - nsAutoString linkName, url; + nsAutoString linkName, url, holder; urlObject->GetData ( getter_Copies(urlInfo) ); - PRInt32 lineIndex = urlInfo.FindChar ('\n'); + holder = urlInfo; + PRInt32 lineIndex = holder.FindChar ('\n'); if ( lineIndex != -1 ) { - urlInfo.Left(url, lineIndex); - urlInfo.Mid ( linkName, lineIndex + 1, (len/2) - (lineIndex + 1) ); + holder.Left(url, lineIndex); + holder.Mid ( linkName, lineIndex + 1, (len/2) - (lineIndex + 1) ); dragitem.hstrTargetName = DrgAddStrHandle(ToNewCString(linkName)); dragitem.hstrSourceName = DrgAddStrHandle(ToNewCString(url)); } diff --git a/mozilla/widget/src/os2/nsFilePicker.cpp b/mozilla/widget/src/os2/nsFilePicker.cpp index 1917aaa140a..cee576ba3d7 100644 --- a/mozilla/widget/src/os2/nsFilePicker.cpp +++ b/mozilla/widget/src/os2/nsFilePicker.cpp @@ -109,17 +109,11 @@ 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); - } - // Allocate copy of last used dir. - initialDir = NS_STATIC_CAST( char*, nsMemory::Clone(mLastUsedDirectory, PL_strlen(mLastUsedDirectory)+1) ); - } + if(initialDir.IsEmpty()) + initialDir = mLastUsedDirectory; mFile.SetLength(0); @@ -129,8 +123,8 @@ NS_IMETHODIMP nsFilePicker::Show(PRInt16 *retval) filedlg.pszTitle = title; if (mMode == modeGetFolder) { - if (initialDir && *initialDir) { - PL_strncat(filedlg.szFullFile, initialDir, MAX_PATH); + if (!initialDir.IsEmpty()) { + strcpy(filedlg.szFullFile, initialDir.get()); } PL_strncat(filedlg.szFullFile, "\\", 1); PL_strncat(filedlg.szFullFile, "^", 1); @@ -143,7 +137,7 @@ NS_IMETHODIMP nsFilePicker::Show(PRInt16 *retval) *tempptr = '\0'; if (filedlg.lReturn == DID_OK) { result = PR_TRUE; - mDisplayDirectory->InitWithPath(filedlg.szFullFile); + mDisplayDirectory->InitWithNativePath(nsDependentCString(filedlg.szFullFile)); mFile.Append(filedlg.szFullFile); } } @@ -273,20 +267,19 @@ 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) ); } } @@ -319,7 +312,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); @@ -331,7 +324,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/os2/nsSound.cpp b/mozilla/widget/src/os2/nsSound.cpp index 80f2d874e32..f8208a3aff5 100644 --- a/mozilla/widget/src/os2/nsSound.cpp +++ b/mozilla/widget/src/os2/nsSound.cpp @@ -91,13 +91,13 @@ NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader, nsCOMPtr soundTmp; rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(soundTmp)); if (NS_FAILED(rv)) return rv; - rv = soundTmp->Append(kSoundTmpFileName); - nsXPIDLCString soundFilename; - (void) soundTmp->GetPath(getter_Copies(soundFilename)); - FILE *fp = fopen(soundFilename, "wb+"); + rv = soundTmp->AppendNative(nsDependentCString(kSoundTmpFileName)); + nsCAutoString soundFilename; + (void) soundTmp->GetNativePath(soundFilename); + FILE *fp = fopen(soundFilename.get(), "wb+"); fwrite(string, stringLen, 1, fp); fclose(fp); - HOBJECT hobject = WinQueryObject(soundFilename); + HOBJECT hobject = WinQueryObject(soundFilename.get()); WinSetObjectData(hobject, "OPEN=DEFAULT"); return NS_OK; diff --git a/mozilla/widget/src/windows/nsClipboard.cpp b/mozilla/widget/src/windows/nsClipboard.cpp index 6aa4b6986f7..a50bf04c074 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..b58e1071385 100644 --- a/mozilla/widget/src/windows/nsWindow.cpp +++ b/mozilla/widget/src/windows/nsWindow.cpp @@ -5012,11 +5012,8 @@ 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 ) ); - - // Start there. - nsAutoString iconPath( rootPath ); + nsAutoString iconPath; + chromeDir->GetPath( iconPath ); // Now take input path... nsAutoString iconSpec( anIconSpec ); @@ -5051,20 +5048,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( 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..5a6d437c143 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(nsString(), 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 9c3915b7c8c..a6d5e5ae62f 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->GetNativePath(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..69db46bacdf 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,7 @@ 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); + dllSpec->GetLeafName(fileName); } // 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..2a8d72ed630 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 //***************************************************************************** @@ -138,21 +138,21 @@ nsAppFileLocationProvider::GetFile(const char *prop, PRBool *persistant, nsIFile { rv = GetProductDirectory(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->Append(APP_REGISTRY_NAME); + rv = localFile->AppendNative(APP_REGISTRY_NAME); } else if (nsCRT::strcmp(prop, NS_APP_DEFAULTS_50_DIR) == 0) { rv = CloneMozBinDirectory(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->AppendRelativePath(DEFAULTS_DIR_NAME); + rv = localFile->AppendRelativeNativePath(DEFAULTS_DIR_NAME); } else if (nsCRT::strcmp(prop, NS_APP_PREF_DEFAULTS_50_DIR) == 0) { rv = CloneMozBinDirectory(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) { - rv = localFile->AppendRelativePath(DEFAULTS_DIR_NAME); + rv = localFile->AppendRelativeNativePath(DEFAULTS_DIR_NAME); if (NS_SUCCEEDED(rv)) - rv = localFile->AppendRelativePath(DEFAULTS_PREF_DIR_NAME); + rv = localFile->AppendRelativeNativePath(DEFAULTS_PREF_DIR_NAME); } } else if (nsCRT::strcmp(prop, NS_APP_PROFILE_DEFAULTS_50_DIR) == 0 || @@ -160,9 +160,9 @@ nsAppFileLocationProvider::GetFile(const char *prop, PRBool *persistant, nsIFile { rv = CloneMozBinDirectory(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) { - rv = localFile->AppendRelativePath(DEFAULTS_DIR_NAME); + rv = localFile->AppendRelativeNativePath(DEFAULTS_DIR_NAME); if (NS_SUCCEEDED(rv)) - rv = localFile->AppendRelativePath(DEFAULTS_PROFILE_DIR_NAME); + rv = localFile->AppendRelativeNativePath(DEFAULTS_PROFILE_DIR_NAME); } } else if (nsCRT::strcmp(prop, NS_APP_USER_PROFILES_ROOT_DIR) == 0) @@ -173,37 +173,37 @@ nsAppFileLocationProvider::GetFile(const char *prop, PRBool *persistant, nsIFile { rv = CloneMozBinDirectory(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->AppendRelativePath(RES_DIR_NAME); + rv = localFile->AppendRelativeNativePath(RES_DIR_NAME); } else if (nsCRT::strcmp(prop, NS_APP_CHROME_DIR) == 0) { rv = CloneMozBinDirectory(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->AppendRelativePath(CHROME_DIR_NAME); + rv = localFile->AppendRelativeNativePath(CHROME_DIR_NAME); } else if (nsCRT::strcmp(prop, NS_APP_PLUGINS_DIR) == 0) { rv = CloneMozBinDirectory(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->AppendRelativePath(PLUGINS_DIR_NAME); + rv = localFile->AppendRelativeNativePath(PLUGINS_DIR_NAME); } else if (nsCRT::strcmp(prop, NS_ENV_PLUGINS_DIR) == 0) { 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) { rv = GetProductDirectory(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->AppendRelativePath(PLUGINS_DIR_NAME); + rv = localFile->AppendRelativeNativePath(PLUGINS_DIR_NAME); } else if (nsCRT::strcmp(prop, NS_APP_SEARCH_DIR) == 0) { rv = CloneMozBinDirectory(getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv)) - rv = localFile->AppendRelativePath(SEARCH_DIR_NAME); + rv = localFile->AppendRelativeNativePath(SEARCH_DIR_NAME); } else if (nsCRT::strcmp(prop, NS_APP_INSTALL_CLEANUP_DIR) == 0) { @@ -212,7 +212,7 @@ nsAppFileLocationProvider::GetFile(const char *prop, PRBool *persistant, nsIFile rv = CloneMozBinDirectory(getter_AddRefs(localFile)); #ifdef XP_MAC if (NS_SUCCEEDED(rv)) - rv = localFile->Append(ESSENTIAL_FILES); + rv = localFile->AppendNative(ESSENTIAL_FILES); #endif } @@ -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,13 +319,13 @@ 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 #endif - rv = localDir->AppendRelativePath(DEFAULT_PRODUCT_DIR); + rv = localDir->AppendRelativeNativePath(DEFAULT_PRODUCT_DIR); if (NS_FAILED(rv)) return rv; rv = localDir->Exists(&exists); if (NS_SUCCEEDED(rv) && !exists) @@ -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->AppendRelativeNativePath(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..a959785a9cb 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; } @@ -803,13 +804,13 @@ nsDirectoryService::GetFile(const char *prop, PRBool *persistent, nsIFile **_ret { rv = GetCurrentProcessDirectory(getter_AddRefs(localFile)); if (localFile) - localFile->Append(COMPONENT_REGISTRY_NAME); + localFile->AppendNative(COMPONENT_REGISTRY_NAME); } else if (inAtom == nsDirectoryService::sComponentDirectory) { rv = GetCurrentProcessDirectory(getter_AddRefs(localFile)); if (localFile) - localFile->Append(COMPONENT_DIRECTORY); + localFile->AppendNative(COMPONENT_DIRECTORY); } else if (inAtom == nsDirectoryService::sOS_DriveDirectory) { diff --git a/mozilla/xpcom/io/nsFastLoadFile.cpp b/mozilla/xpcom/io/nsFastLoadFile.cpp index 208b1bf0287..70c0438a979 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" @@ -737,7 +739,7 @@ nsFastLoadFileReader::ReadFooter(nsFastLoadFooter *aFooter) return rv; nsCOMPtr file; - rv = NS_NewLocalFile(filename, PR_TRUE, getter_AddRefs(file)); + rv = NS_NewNativeLocalFile(filename, PR_TRUE, getter_AddRefs(file)); if (NS_FAILED(rv)) return rv; @@ -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->GetNativePath(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->GetNativePath(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..79343e35be9 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->AppendNative(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->GetNativePath(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->GetNativePath(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..de54dd517d3 100644 --- a/mozilla/xpcom/io/nsIFile.idl +++ b/mozilla/xpcom/io/nsIFile.idl @@ -21,47 +21,54 @@ * Contributor(s): * Doug Turner * Christopher Blizzard + * Darin Fisher */ +#include "nsISupports.idl" + +interface nsISimpleEnumerator; /** * This is the only correct cross-platform way to specify a file. * Strings are not such a way. If you grew up on windows or unix, you - * may think they are. Welcome to reality. + * may think they are. Welcome to reality. * - * @status UNDER_REVIEW + * All methods with string parameters have two forms. The preferred + * form operates on UCS-2 encoded characters strings. An alternate + * form operates on characters strings encoded in the "native" charset. + * + * A string containing characters encoded in the native charset cannot + * be safely passed to javascript via xpconnect. Therefore, the "native + * methods" are not scriptable. + * + * @status FROZEN */ - -#include "nsISupports.idl" -interface nsISimpleEnumerator; - [scriptable, uuid(c8c0a080-0868-11d3-915f-d9d889d48e3c)] interface nsIFile : nsISupports { /** - * Create Types + * Create Types * - * NORMAL_FILE_TYPE - A normal file. - * DIRECTORY_TYPE - A directory/folder. + * NORMAL_FILE_TYPE - A normal file. + * DIRECTORY_TYPE - A directory/folder. */ const unsigned long NORMAL_FILE_TYPE = 0; const unsigned long DIRECTORY_TYPE = 1; /** - * appendPath + * append[Native] * - * This function is used for constructing a descendant of the + * This function is used for constructing a descendent of the * current nsIFile. * - * @param relativePath - * A string which is intented to be a child node of the - * nsIFile. + * @param node + * A string which is intended to be a child node of the nsIFile. */ - void append([const] in string node); - void appendUnicode([const] in wstring node); + void append(in AString node); + [noscript] void appendNative(in ACString node); /** - * Normalize the pathName (e.g. removing .. and . components on Unix). + * Normalize the pathName (e.g. removing .. and . components on Unix). */ void normalize(); @@ -85,17 +92,16 @@ interface nsIFile : nsISupports * be ignored on systems that do not need to do * permissions. */ - void create(in unsigned long type, in unsigned long permissions); /** - * Accessor to the leaf name of the file itself. + * Accessor to the leaf name of the file itself. */ - attribute string leafName; - attribute wstring unicodeLeafName; + attribute AString leafName; + [noscript] attribute ACString nativeLeafName; /** - * copyTo + * copyTo[Native] * * This will copy this file to the specified newParentDir. * If a newName is specified, the file will be renamed. @@ -109,33 +115,31 @@ interface nsIFile : nsISupports * * @param newParentDir * This param is the destination directory. If the - * newParentDir is null, copyTo() will use the parent + * newParentDir is empty, copyTo() will use the parent * directory of this file. If the newParentDir is not - * null and is not a directory, an error will be + * empty and is not a directory, an error will be * returned (NS_ERROR_FILE_DESTINATION_NOT_DIR) * * @param newName * This param allows you to specify a new name for - * the file to be copied. This param may be null, in + * the file to be copied. This param may be empty, in * 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 AString newName); + [noscrpit] void CopyToNative(in nsIFile newParentDir, in ACString newName); /** - * copyToFollowingLinks + * copyToFollowingLinks[Native] * - * This function is identical to copyTo except it, as - * the name implies, follows symbolic links. Some OSes - * such as Unix and Linux always follow symbolic links - * when copying. + * This function is identical to copyTo with the exception that, + * as the name implies, it follows symbolic links. The XP_UNIX + * implementation 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 AString newName); + [noscript] void copyToFollowingLinksNative(in nsIFile newParentDir, in ACString newName); /** - * moveTo + * moveTo[Native] * * This will move this file to the specified newParentDir. * If a newName is specified, the file will be renamed. @@ -148,19 +152,18 @@ interface nsIFile : nsISupports * * @param newParentDir * This param is the destination directory. If the - * newParentDir is null, moveTo() will rename the file + * newParentDir is empty, moveTo() will rename the file * within its current directory. If the newParentDir is - * not null and does not name a directory, an error will + * not empty and does not name a directory, an error will * be returned (NS_ERROR_FILE_DESTINATION_NOT_DIR) * * @param newName * This param allows you to specify a new name for - * the file to be moved. This param may be null, in + * the file to be moved. This param may be empty, in * 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 AString newName); + [noscript] void moveToNative(in nsIFile newParentDir, in ACString newName); /** * This will try to delete this file. The 'recursive' flag @@ -186,10 +189,10 @@ interface nsIFile : nsISupports attribute PRInt64 lastModifiedTimeOfLink; /** - * WARNING! On the Mac getting/setting the file size with nsIFile - * only deals with the size of the data fork. If you need to - * know the size of the combined data and resource forks use the - * GetFileSizeWithResFork() method defined in nsILocalFileMac.h + * WARNING! On the Mac, getting/setting the file size with nsIFile + * only deals with the size of the data fork. If you need to + * know the size of the combined data and resource forks use the + * GetFileSizeWithResFork() method defined on nsILocalFileMac. */ attribute PRInt64 fileSize; readonly attribute PRInt64 fileSizeOfLink; @@ -197,29 +200,28 @@ interface nsIFile : nsISupports /** * target & path * - * Accessor to the string path. These strings are - * not guaranteed to be a usable path to pass to NSPR - * or the C stdlib. There are problems that affect - * platforms on which a path does not fully specify a - * file, because two volumes can have the same name. - * This is solved by holding "private", native data in - * the nsIFile implementation. This native data is lost - * when you convert to a string. + * Accessor to the string path. The native version of these + * strings are not guaranteed to be a usable path to pass to + * NSPR or the C stdlib. There are problems that affect + * platforms on which a path does not fully specify a file + * because two volumes can have the same name (e.g., XP_MAC). + * This is solved by holding "private", native data in the + * nsIFile implementation. This native data is lost when + * you convert to a string. * - * DO NOT PASS TO USE WITH NSPR OR STDLIB. + * DO NOT PASS TO USE WITH NSPR OR STDLIB! * - * target: + * target * Find out what the symlink points at. Will give error * (NS_ERROR_FILE_INVALID_PATH) if not a symlink. * - * path: + * 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 AString target; + [noscript] readonly attribute ACString nativeTarget; + readonly attribute AString path; + [noscript] readonly attribute ACString nativePath; boolean exists(); boolean isWritable(); @@ -234,7 +236,7 @@ interface nsIFile : nsISupports */ boolean isSpecial(); - /** + /** * createUnique * * This function will create a new file or directory in the @@ -260,7 +262,6 @@ interface nsIFile : nsISupports * permissions. */ void createUnique(in unsigned long type, in unsigned long permissions); - /** * clone() @@ -281,25 +282,24 @@ interface nsIFile : nsISupports boolean equals(in nsIFile inFile); /** - * Will determine if inFile is a descendant of this file - * If |recur| is true, look in subdirectories too + * Will determine if inFile is a descendant of this file + * If |recur| is true, look in subdirectories too */ boolean contains(in nsIFile inFile, in boolean recur); /** - * Parent will be null when this is at the top of the volume. + * Parent will be null when this is at the top of the volume. */ readonly attribute nsIFile parent; /** - * Returns an enumeration of the elements in a directory. Each - * element in the enumeration is an nsIFile. + * Returns an enumeration of the elements in a directory. Each + * element in the enumeration is an nsIFile. * * @return NS_ERROR_FILE_NOT_DIRECTORY if the current nsIFile does * not specify a directory. */ readonly attribute nsISimpleEnumerator directoryEntries; - }; %{C++ 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..e7c7eb9e8f6 100644 --- a/mozilla/xpcom/io/nsILocalFile.idl +++ b/mozilla/xpcom/io/nsILocalFile.idl @@ -20,15 +20,11 @@ * * Contributor(s): * Doug Turner + * Darin Fisher */ - #include "nsIFile.idl" -/** - * @status UNDER_REVIEW - */ - %{C++ #include "prio.h" #include "prlink.h" @@ -40,55 +36,60 @@ [ptr] native PRLibraryStar(PRLibrary); [ptr] native FILE(FILE); +/** + * This interface adds methods to nsIFile that are particular to a file + * that is accessible via the local file system. + * + * It follows the same string conventions as nsIFile. + * + * @status FROZEN + */ [scriptable, uuid(aa610f20-a889-11d3-8c81-000064657374)] interface nsILocalFile : nsIFile { /** - * initWithPath + * initWith[Native]Path * - * This function will initialize the nsILocalFile object. Any - * internal state information will be reset. + * This function will initialize the nsILocalFile object. Any + * internal state information will be reset. * - * NOTE: This function has a known bug on the macintosh and - * other OSes which do not represent file locations - * as pathes. If you do use this function, be very - * aware of this problem as bugs. + * NOTE: This function has a known bug on the macintosh and + * other OSes which do not represent file locations as paths. + * If you do use this function, be very aware of this problem! * * @param filePath - * A string which specifies a full file path to a - * location. Relative paths will be treated as an - * error (NS_ERROR_FILE_UNRECOGNIZED_PATH). This - * path must in native. + * A string which specifies a full file path to a + * location. Relative paths will be treated as an + * 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 AString filePath); + [noscript] void initWithNativePath(in ACString filePath); /** - * initWithFile + * initWithFile * - * Initialize this object with another file - * - * @param aFile - * the file this becomes equivalent to + * Initialize this object with another file * + * @param aFile + * the file this becomes equivalent to */ void initWithFile(in nsILocalFile aFile); - /** - * followLinks + * followLinks * - * This attribute will determine if the nsLocalFile will auto - * resolve symbolic links. By default, this value will be false - * on all non unix systems. On unix, this attribute is effectively - * a noop. + * This attribute will determine if the nsLocalFile will auto + * resolve symbolic links. By default, this value will be false + * on all non unix systems. On unix, this attribute is effectively + * a noop. * - * Be aware that changing this attribute from true to false after - * the nsILocalFile has been initialized may lead to errors. This - * could happen if there were resolved symlink in the initialized - * path. For example if you had /a/b/c where |b| was a symlink, - * and you change this attribute to false, the next usage would - * mostlikely fail. + * Be aware that changing this attribute from true to false after + * the nsILocalFile has been initialized may lead to errors. This + * could happen if there were resolved symlink in the initialized + * path. For example if you had /a/b/c where |b| was a symlink, + * and you change this attribute to false, the next usage would + * mostlikely fail. */ attribute PRBool followLinks; @@ -100,73 +101,77 @@ interface nsILocalFile : nsIFile readonly attribute PRInt64 diskSpaceAvailable; // maybe we should put this somewhere else. /** - * appendRelativePath + * appendRelative[Native]Path * - * Append a relative path to the current path of the nsILocalFile object. + * Append a relative path to the current path of the nsILocalFile object. * - * @param relativeFilePath - * relativeFilePath is a native relative path. For security reasons, - * this cannot contain .. or cannot start with a directory separator - * XXXbe Why not? Bogus! + * @param relativeFilePath + * relativeFilePath is a native relative path. For security reasons, + * 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 AString 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. + * Accessor to a null terminated string which will specify + * the file in a persistent manner for disk storage. + * + * The character set of this attribute is undefined. DO NOT TRY TO + * INTERPRET IT AS HUMAN READABLE TEXT! */ - attribute string persistentDescriptor; + attribute ACString persistentDescriptor; /** - * reveal --> Ask the operating system to open the folder which contains - * this file or folder. This routine only works on platforms which - * support the ability to open a folder... + * reveal + * + * Ask the operating system to open the folder which contains + * this file or folder. This routine only works on platforms which + * support the ability to open a folder... */ void reveal(); /** - * launch --> Ask the operating system to attempt to open the file. - * this really just simulates "double clicking" the file on your platform. - * This routine only works on platforms which support this functionality. + * launch + * + * Ask the operating system to attempt to open the file. + * this really just simulates "double clicking" the file on your platform. + * This routine only works on platforms which support this functionality. */ void launch(); /** - * getRelativeDescriptor + * getRelativeDescriptor * - * Returns a utf-8 encoded relative file path in an XP format. - * It is therefore not a native path. + * Returns a relative file path in an opaque, XP format. It is therefore + * not a native path. + * + * The character set of the string returned from this function is + * undefined. DO NOT TRY TO INTERPRET IT AS HUMAN READABLE TEXT! * * @param fromFile - * the file from which the descriptor is relative + * the file from which the descriptor is relative */ - AUTF8String getRelativeDescriptor(in nsILocalFile fromFile); - + ACString getRelativeDescriptor(in nsILocalFile fromFile); /** - * setRelativeDescriptor + * setRelativeDescriptor * - * Initializes the file to the location relative to fromFile using - * a string returned by getRelativeDescriptor. + * Initializes the file to the location relative to fromFile using + * a string returned by getRelativeDescriptor. * * @param fromFile - * the file to which the descriptor is relative + * the file to which the descriptor is relative */ - void setRelativeDescriptor(in nsILocalFile fromFile, in AUTF8String relativeDesc); - + void setRelativeDescriptor(in nsILocalFile fromFile, in ACString relativeDesc); }; %{C++ - #define NS_LOCAL_FILE_CONTRACTID "@mozilla.org/file/local;1" #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 nsAString &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..602ecd49e6c 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->GetNativePath(path); + if (path.IsEmpty()) return NS_ERROR_FAILURE; - return InitWithPath(path.get()); + return InitWithNativePath(path); } #endif @@ -95,60 +80,58 @@ 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, '.'); + const 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 PRUnichar kPathSeparatorChar = ':'; #elif defined(XP_WIN) || defined(XP_OS2) -const PRUnichar kPathSeparatorChar = '\\'; +static const PRUnichar kPathSeparatorChar = '\\'; #elif defined(XP_UNIX) || defined(XP_BEOS) -const PRUnichar kPathSeparatorChar = '/'; +static const PRUnichar 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) @@ -179,52 +162,48 @@ NS_IMETHODIMP nsLocalFile::GetRelativeDescriptor(nsILocalFile *fromFile, nsACString& _retval) { const PRInt32 kMaxNodesInPath = 32; + + // + // _retval will be UTF-8 encoded + // nsresult rv; _retval.Truncate(0); - PRUnichar *thisPath = nsnull, *fromPath = nsnull; + nsAutoString thisPath, fromPath; PRUnichar *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((PRUnichar *)thisPath.get(), thisNodes, kMaxNodesInPath); + fromNodeCnt = SplitPath((PRUnichar *)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 (!nsCRT::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 nodeStr.ReplaceSubstring(kSlashStr, kESCSlashStr); #endif - _retval.Append(nodeStr.get()); + _retval.Append(nodeStr); if (nodeIndex + 1 < thisNodeCnt) _retval.Append('/'); } - nsMemory::Free(thisPath); - nsMemory::Free(fromPath); - return NS_OK; } @@ -238,6 +217,10 @@ nsLocalFile::SetRelativeDescriptor(nsILocalFile *fromFile, const nsACString& rel if (NS_FAILED(rv)) return rv; + // + // relativeDesc is UTF-8 encoded + // + nsCString::const_iterator strBegin, strEnd; relativeDesc.BeginReading(strBegin); relativeDesc.EndReading(strEnd); @@ -260,11 +243,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(NS_ConvertUTF8toUCS2(nodeString)); +#else + targetFile->Append(NS_ConvertUTF8toUCS2(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; diff --git a/mozilla/xpcom/io/nsLocalFileMac.cpp b/mozilla/xpcom/io/nsLocalFileMac.cpp index c69aaa39c2c..0decf5fba80 100644 --- a/mozilla/xpcom/io/nsLocalFileMac.cpp +++ b/mozilla/xpcom/io/nsLocalFileMac.cpp @@ -29,7 +29,6 @@ #include "nsXPIDLString.h" #include "nsLocalFileMac.h" -#include "nsLocalFileUnicode.h" #include "nsISimpleEnumerator.h" #include "nsIComponentManager.h" #include "nsIInternetConfigService.h" @@ -97,7 +96,7 @@ const OSType kDefaultCreator = 'MOSS'; class nsPathParser { public: - nsPathParser(const char* path); + nsPathParser(const nsACString &path); ~nsPathParser() { @@ -124,18 +123,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 +1254,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); @@ -1291,13 +1304,13 @@ nsLocalFile::InitWithPath(const char *filePath) } NS_IMETHODIMP -nsLocalFile::InitWithUnicodePath(const PRUnichar *filePath) +nsLocalFile::InitWithPath(const nsAString &filePath) { nsresult rv; nsCAutoString fsStr; - if (NS_SUCCEEDED(rv = nsFSStringConversionMac::UCSToFS(nsDependentString(filePath), fsStr))) - rv = InitWithPath(fsStr.get()); + if (NS_SUCCEEDED(rv = nsFSStringConversionMac::UCSToFS(filePath, fsStr))) + rv = InitWithNativePath(fsStr); return rv; } @@ -1463,16 +1476,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()) { @@ -1514,21 +1532,22 @@ nsLocalFile::Append(const char *aNode) } NS_IMETHODIMP -nsLocalFile::AppendUnicode(const PRUnichar *node) +nsLocalFile::Append(const nsAString &node) { nsresult rv; nsCAutoString fsStr; - if (NS_SUCCEEDED(rv = nsFSStringConversionMac::UCSToFS(nsDependentString(node), fsStr))) - rv = Append(fsStr.get()); + if (NS_SUCCEEDED(rv = nsFSStringConversionMac::UCSToFS(node, fsStr))) + 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 +1555,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(); } @@ -1545,21 +1564,21 @@ nsLocalFile::AppendRelativePath(const char *relPath) } NS_IMETHODIMP -nsLocalFile::AppendRelativeUnicodePath(const PRUnichar *relPath) +nsLocalFile::AppendRelativePath(const nsAString &relPath) { nsresult rv; nsCAutoString fsStr; - if (NS_SUCCEEDED(rv = nsFSStringConversionMac::UCSToFS(nsDependentString(relPath), fsStr))) - rv = AppendRelativePath(fsStr.get()); + if (NS_SUCCEEDED(rv = nsFSStringConversionMac::UCSToFS(relPath, fsStr))) + 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,50 +1595,45 @@ 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; } NS_IMETHODIMP -nsLocalFile::GetUnicodeLeafName(PRUnichar **aLeafName) +nsLocalFile::GetLeafName(nsAString &aLeafName) { nsresult rv; - nsXPIDLCString fsStr; + nsCAutoString fsStr; - if (NS_SUCCEEDED(rv = GetLeafName(getter_Copies(fsStr)))) { - nsAutoString ucStr; - if (NS_SUCCEEDED(rv = nsFSStringConversionMac::FSToUCS(fsStr, ucStr))) { - if ((*aLeafName = ToNewUnicode(ucStr)) == nsnull) - rv = NS_ERROR_OUT_OF_MEMORY; - } - } + if (NS_SUCCEEDED(rv = GetNativeLeafName(fsStr))) + rv = nsFSStringConversionMac::FSToUCS(fsStr, aLeafName); return rv; } 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 @@ -1640,21 +1654,21 @@ nsLocalFile::SetLeafName(const char * aLeafName) } NS_IMETHODIMP -nsLocalFile::SetUnicodeLeafName(const PRUnichar * aLeafName) +nsLocalFile::SetLeafName(const nsAString &aLeafName) { nsresult rv; nsCAutoString fsStr; - if (NS_SUCCEEDED(rv = nsFSStringConversionMac::UCSToFS(nsDependentString(aLeafName), fsStr))) - rv = SetLeafName(fsStr.get()); + if (NS_SUCCEEDED(rv = nsFSStringConversionMac::UCSToFS(aLeafName, fsStr))) + 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,18 +1714,14 @@ nsLocalFile::GetPath(char **_retval) fsCharSetPathStr.Append(mAppendedPath); } - *_retval = ToNewCString(fsCharSetPathStr); - if (!*_retval) - return NS_ERROR_OUT_OF_MEMORY; - + _retval = fsCharSetPathStr; return NS_OK; } NS_IMETHODIMP -nsLocalFile::GetUnicodePath(PRUnichar **_retval) +nsLocalFile::GetPath(nsAString &_retval) { nsresult rv = NS_OK; - NS_ENSURE_ARG_POINTER(_retval); #if TARGET_CARBON if (sHasHFSPlusAPIs) // should always be true under Carbon, but in case... @@ -1740,27 +1750,21 @@ nsLocalFile::GetUnicodePath(PRUnichar **_retval) ucPathString.Append(ucAppendage); } - *_retval = ToNewUnicode(ucPathString); - if (!*_retval) - return NS_ERROR_OUT_OF_MEMORY; + _retval = ucPathString; } else #endif { - nsXPIDLCString fsStr; + nsCAutoString fsStr; - if (NS_SUCCEEDED(rv = GetPath(getter_Copies(fsStr)))) { - nsAutoString ucStr; - if (NS_SUCCEEDED(rv = nsFSStringConversionMac::FSToUCS(fsStr, ucStr))) { - if ((*_retval = ToNewUnicode(ucStr)) == nsnull) - rv = NS_ERROR_OUT_OF_MEMORY; - } + if (NS_SUCCEEDED(rv = GetNativePath(fsStr))) { + rv = nsFSStringConversionMac::FSToUCS(fsStr, _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 +1779,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 +1797,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 +1835,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,59 +1845,59 @@ 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 ); } NS_IMETHODIMP -nsLocalFile::CopyToUnicode(nsIFile *newParentDir, const PRUnichar *newName) +nsLocalFile::CopyTo(nsIFile *newParentDir, const nsAString &newName) { - if (!newName) - return CopyTo(newParentDir, nsnull); + if (newName.IsEmpty()) + return CopyToNative(newParentDir, nsCString()); nsresult rv; nsCAutoString fsStr; - if (NS_SUCCEEDED(rv = nsFSStringConversionMac::UCSToFS(nsDependentString(newName), fsStr))) - rv = CopyTo(newParentDir, PromiseFlatCString(fsStr).get()); + if (NS_SUCCEEDED(rv = nsFSStringConversionMac::UCSToFS(newName, fsStr))) + 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 ); } NS_IMETHODIMP -nsLocalFile::CopyToFollowingLinksUnicode(nsIFile *newParentDir, const PRUnichar *newName) +nsLocalFile::CopyToFollowingLinks(nsIFile *newParentDir, const nsAString &newName) { - if (!newName) - return CopyToFollowingLinks(newParentDir, nsnull); + if (newName.IsEmpty()) + return CopyToFollowingLinksNative(newParentDir, nsCString()); nsresult rv; nsCAutoString fsStr; - if (NS_SUCCEEDED(rv = nsFSStringConversionMac::UCSToFS(nsDependentString(newName), fsStr))) - rv = CopyToFollowingLinks(newParentDir, PromiseFlatCString(fsStr).get()); + if (NS_SUCCEEDED(rv = nsFSStringConversionMac::UCSToFS(newName, fsStr))) + 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 ); } NS_IMETHODIMP -nsLocalFile::MoveToUnicode(nsIFile *newParentDir, const PRUnichar *newName) +nsLocalFile::MoveTo(nsIFile *newParentDir, const nsAString &newName) { - if (!newName) - return MoveTo(newParentDir, nsnull); + if (newName.IsEmpty()) + return MoveToNative(newParentDir, nsCString()); nsresult rv; nsCAutoString fsStr; - if (NS_SUCCEEDED(rv = nsFSStringConversionMac::UCSToFS(nsDependentString(newName), fsStr))) - rv = MoveTo(newParentDir, PromiseFlatCString(fsStr).get()); + if (NS_SUCCEEDED(rv = nsFSStringConversionMac::UCSToFS(newName, fsStr))) + rv = MoveToNative(newParentDir, fsStr); return rv; } @@ -2258,10 +2261,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 +2398,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 +2441,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 +2506,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,21 +2520,17 @@ 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) +nsLocalFile::GetTarget(nsAString &_retval) { nsresult rv; - nsXPIDLCString fsStr; + nsCAutoString fsStr; - if (NS_SUCCEEDED(rv = GetTarget(getter_Copies(fsStr)))) { - nsAutoString ucStr; - if (NS_SUCCEEDED(rv = nsFSStringConversionMac::FSToUCS(fsStr, ucStr))) { - if ((*_retval = ToNewUnicode(ucStr)) == nsnull) - rv = NS_ERROR_OUT_OF_MEMORY; - } + if (NS_SUCCEEDED(rv = GetNativeTarget(fsStr))) { + rv = nsFSStringConversionMac::FSToUCS(fsStr, _retval); } return rv; } @@ -2567,10 +2565,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 +2584,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 +3410,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 +3512,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 +3521,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; @@ -3534,13 +3533,13 @@ NS_NewLocalFile(const char* path, PRBool followLinks, nsILocalFile* *result) } nsresult -NS_NewUnicodeLocalFile(const PRUnichar* path, PRBool followLinks, nsILocalFile* *result) +NS_NewLocalFile(const nsAString &path, PRBool followLinks, nsILocalFile* *result) { nsCAutoString fsCharSetStr; - nsresult rv = nsFSStringConversionMac::UCSToFS(nsDependentString(path), fsCharSetStr); + nsresult rv = nsFSStringConversionMac::UCSToFS(path, fsCharSetStr); if (NS_FAILED(rv)) return rv; - return NS_NewLocalFile(fsCharSetStr.get(), followLinks, result); + return NS_NewNativeLocalFile(fsCharSetStr, followLinks, result); } nsresult @@ -3563,7 +3562,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..31bb17aa9b9 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,7 +79,7 @@ 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); diff --git a/mozilla/xpcom/io/nsLocalFileOS2.cpp b/mozilla/xpcom/io/nsLocalFileOS2.cpp index 448e3ec4e22..45af1767d57 100644 --- a/mozilla/xpcom/io/nsLocalFileOS2.cpp +++ b/mozilla/xpcom/io/nsLocalFileOS2.cpp @@ -157,24 +157,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 +202,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); @@ -625,13 +623,10 @@ NS_IMETHODIMP nsLocalFile::Clone(nsIFile **file) { nsresult rv; - char * aFilePath; - GetPath(&aFilePath); nsCOMPtr localFile; - rv = NS_NewLocalFile(aFilePath, mFollowSymlinks, getter_AddRefs(localFile)); - nsMemory::Free(aFilePath); + rv = NS_NewNativeLocalFile(mWorkingPath, mFollowSymlinks, getter_AddRefs(localFile)); if (NS_SUCCEEDED(rv) && localFile) { @@ -642,55 +637,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 +781,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 +815,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 +831,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 +857,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 +892,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 +908,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 +916,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 +924,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 +941,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 +968,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 +1002,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 +1046,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 +1106,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 +1126,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 +1643,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 +1654,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 +1743,7 @@ nsLocalFile::IsExecutable(PRBool *_retval) if (NS_FAILED(rv)) return rv; - char* path = nsnull; + nsCAutoString path; PRBool symLink; rv = IsSymlink(&symLink); @@ -1773,11 +1751,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 +1772,6 @@ nsLocalFile::IsExecutable(PRBool *_retval) *_retval = PR_FALSE; } - nsMemory::Free(path); - return NS_OK; } @@ -1878,20 +1854,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 +1917,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 +1929,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 +1951,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 +1974,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 +2025,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 +2045,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 +2071,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 +2079,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 +2088,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 +2194,7 @@ static int isleadbyte(int c) static UconvObject UnicodeConverter = NULL; -nsresult NS_CreateUnicodeConverters() +static nsresult NS_CreateUnicodeConverters() { ULONG ulLength; ULONG ulCodePage; @@ -2259,7 +2216,7 @@ nsresult NS_CreateUnicodeConverters() } } -void NS_DestroyUnicodeConverters() +static void NS_DestroyUnicodeConverters() { ::UniFreeUconvObject(UnicodeConverter); } @@ -2314,46 +2271,39 @@ FStoUCS2(const char* aBuffer, PRUnichar **aResult) } NS_IMETHODIMP -nsLocalFile::InitWithUnicodePath(const PRUnichar *filePath) +nsLocalFile::InitWithPath(const nsAString &filePath) { - - NS_ENSURE_ARG(filePath); - - if (nsCRT::strlen(filePath) == 0) - return NS_ERROR_INVALID_ARG; + if (filePath.IsEmpty()) + return InitWithNativePath(nsCString()); nsXPIDLCString tmp; - nsresult rv = UCS2toFS(filePath, getter_Copies(tmp)); + nsresult rv = UCS2toFS(PromiseFlatString(filePath).get(), getter_Copies(tmp)); if (NS_SUCCEEDED(rv)) - return InitWithPath(tmp); + return InitWithNativePath(tmp); return rv; } NS_IMETHODIMP -nsLocalFile::AppendUnicode(const PRUnichar *node) +nsLocalFile::Append(const nsAString &node) { - NS_ENSURE_ARG(node); - - if (nsCRT::strlen(node) == 0) + if (node.IsEmpty()) return NS_OK; nsXPIDLCString tmp; - nsresult rv = UCS2toFS(node, getter_Copies(tmp)); + nsresult rv = UCS2toFS(PromiseFlatString(node).get(), getter_Copies(tmp)); if (NS_SUCCEEDED(rv)) - return Append(tmp); + return AppendNative(tmp); return rv; } NS_IMETHODIMP -nsLocalFile::AppendRelativeUnicodePath(const PRUnichar *node) +nsLocalFile::AppendRelativePath(const nsAString &node) { - NS_ENSURE_ARG(node); - - if (nsCRT::strlen(node) == 0) + if (node.IsEmpty()) return NS_OK; nsXPIDLCString tmp; @@ -2361,126 +2311,143 @@ nsLocalFile::AppendRelativeUnicodePath(const PRUnichar *node) if (tmp.IsEmpty()) return NS_OK; - nsresult rv = UCS2toFS(node, getter_Copies(tmp)); + nsresult rv = UCS2toFS(PromiseFlatString(node).get(), getter_Copies(tmp)); if (NS_SUCCEEDED(rv)) - return AppendRelativePath(tmp); + return AppendRelativeNativePath(tmp); return rv; } NS_IMETHODIMP -nsLocalFile::GetUnicodeLeafName(PRUnichar **aLeafName) +nsLocalFile::GetLeafName(nsAString &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); + if (NS_SUCCEEDED(rv)) { + nsXPIDLString ucsBuf; + rv = FStoUCS2(tmp.get(), getter_Copies(ucsBuf)); + if (NS_SUCCEEDED(rv)) + aLeafName = ucsBuf; + } return rv; } NS_IMETHODIMP -nsLocalFile::SetUnicodeLeafName(const PRUnichar *aLeafName) +nsLocalFile::SetLeafName(const nsAString &aLeafName) { - NS_ENSURE_ARG(aLeafName); - - if (nsCRT::strlen(aLeafName) == 0) - return NS_OK; + if (aLeafName.IsEmpty()) + return SetNativeLeafName(nsCString()); nsXPIDLCString tmp; - nsresult rv = UCS2toFS(aLeafName, getter_Copies(tmp)); + nsresult rv = UCS2toFS(PromiseFlatString(aLeafName).get(), getter_Copies(tmp)); if (NS_SUCCEEDED(rv)) - return SetLeafName(tmp); + return SetNativeLeafName(tmp); return rv; } NS_IMETHODIMP -nsLocalFile::GetUnicodePath(PRUnichar **_retval) +nsLocalFile::GetPath(nsAString &_retval) { - NS_ENSURE_ARG_POINTER(_retval); + nsXPIDLString ucsBuf; + nsresult rv = FStoUCS2(mWorkingPath.get(), getter_Copies(ucsBuf)); + if (NS_SUCCEEDED(rv)) + _retval = ucsBuf; + return rv; +} + +NS_IMETHODIMP +nsLocalFile::CopyTo(nsIFile *newParentDir, const nsAString &newName) +{ + if (newName.IsEmpty()) + return CopyToNative(newParentDir, nsCString()); + nsXPIDLCString tmp; - nsresult rv = GetPath(getter_Copies(tmp)); + nsresult rv = UCS2toFS(PromiseFlatString(newName).get(), getter_Copies(tmp)); if (NS_SUCCEEDED(rv)) - return FStoUCS2(tmp, _retval); + return CopyToNative(newParentDir, tmp); return rv; } NS_IMETHODIMP -nsLocalFile::CopyToUnicode(nsIFile *newParentDir, const PRUnichar *newName) +nsLocalFile::CopyToFollowingLinks(nsIFile *newParentDir, const nsAString &newName) { - if (!newName || nsCRT::strlen(newName) == 0) - return CopyTo(newParentDir, nsnull); + if (newName.IsEmpty()) + return CopyToFollowingLinksNative(newParentDir, nsCString()); nsXPIDLCString tmp; - nsresult rv = UCS2toFS(newName, getter_Copies(tmp)); + nsresult rv = UCS2toFS(PromiseFlatString(newName).get(), getter_Copies(tmp)); if (NS_SUCCEEDED(rv)) - return CopyTo(newParentDir, tmp); + return CopyToFollowingLinksNative(newParentDir, tmp); return rv; } NS_IMETHODIMP -nsLocalFile::CopyToFollowingLinksUnicode(nsIFile *newParentDir, const PRUnichar *newName) +nsLocalFile::MoveTo(nsIFile *newParentDir, const nsAString &newName) { - if (!newName || nsCRT::strlen(newName) == 0) - return CopyToFollowingLinks(newParentDir, nsnull); + if (newName.IsEmpty()) + return MoveToNative(newParentDir, nsCString()); nsXPIDLCString tmp; - nsresult rv = UCS2toFS(newName, getter_Copies(tmp)); + nsresult rv = UCS2toFS(PromiseFlatString(newName).get(), getter_Copies(tmp)); if (NS_SUCCEEDED(rv)) - return CopyToFollowingLinks(newParentDir, tmp); + return MoveToNative(newParentDir, tmp); return rv; } NS_IMETHODIMP -nsLocalFile::MoveToUnicode(nsIFile *newParentDir, const PRUnichar *newName) +nsLocalFile::GetTarget(nsAString &_retval) { - if (!newName || nsCRT::strlen(newName) == 0) - return MoveTo(newParentDir, nsnull); + nsCAutoString tmp; + nsresult rv = GetNativeTarget(tmp); - nsXPIDLCString tmp; - nsresult rv = UCS2toFS(newName, getter_Copies(tmp)); - - if (NS_SUCCEEDED(rv)) - return MoveTo(newParentDir, tmp); - - return rv; -} - -NS_IMETHODIMP -nsLocalFile::GetUnicodeTarget(PRUnichar **_retval) -{ - NS_ENSURE_ARG_POINTER(_retval); - nsXPIDLCString tmp; - nsresult rv = GetTarget(getter_Copies(tmp)); - - if (NS_SUCCEEDED(rv)) - return FStoUCS2(tmp, _retval); + if (NS_SUCCEEDED(rv)) { + nsXPIDLString ucsBuf; + rv = FStoUCS2(tmp.get(), getter_Copies(ucsBuf)); + if (NS_SUCCEEDED(rv)) + _retval = ucsBuf; + } return rv; } nsresult -NS_NewUnicodeLocalFile(const PRUnichar* path, PRBool followLinks, nsILocalFile* *result) +NS_NewLocalFile(const nsAString &path, PRBool followLinks, nsILocalFile* *result) { - if (!path || nsCRT::strlen(path) == 0) - return NS_ERROR_INVALID_ARG; + if (path.IsEmpty()) + return NS_NewNativeLocalFile(nsCString(), followLinks, result); nsXPIDLCString tmp; - nsresult rv = UCS2toFS(path, getter_Copies(tmp)); + nsresult rv = UCS2toFS(PromiseFlatString(path).get(), 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 +//---------------------------------------------------------------------------- + +void +nsLocalFile::GlobalInit() +{ + NS_CreateUnicodeConverters(); +} + +void +nsLocalFile::GlobalShutdown() +{ + NS_DestroyUnicodeConverters(); +} diff --git a/mozilla/xpcom/io/nsLocalFileOS2.h b/mozilla/xpcom/io/nsLocalFileOS2.h index cc997e097b7..f27ae78efe5 100644 --- a/mozilla/xpcom/io/nsLocalFileOS2.h +++ b/mozilla/xpcom/io/nsLocalFileOS2.h @@ -112,6 +112,10 @@ public: // nsILocalFile interface NS_DECL_NSILOCALFILE +public: + static void GlobalInit(); + static void GlobalShutdown(); + private: // this is the flag which indicates if I can used cached information about the file @@ -136,15 +140,10 @@ 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); - }; - -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 5a2d60a470c..bd8d5f0dd5e 100644 --- a/mozilla/xpcom/io/nsLocalFileUnix.cpp +++ b/mozilla/xpcom/io/nsLocalFileUnix.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #ifdef XP_BEOS #include #include @@ -64,6 +65,20 @@ #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) @@ -85,7 +100,7 @@ #define CHECK_mPath() \ PR_BEGIN_MACRO \ - if (!mPath.get()) \ + if (mPath.IsEmpty()) \ return NS_ERROR_NOT_INITIALIZED; \ PR_END_MACRO @@ -103,14 +118,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() : @@ -129,15 +144,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()); @@ -162,15 +177,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(); } @@ -204,12 +219,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); @@ -237,34 +254,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; } @@ -272,8 +287,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; @@ -341,8 +354,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(); @@ -353,8 +364,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; @@ -380,7 +389,6 @@ nsresult nsLocalFile::CreateAndKeepOpen(PRUint32 type, PRIntn flags, PRUint32 permissions, PRFileDesc **_retval) { - CHECK_mPath(); if (type != NORMAL_FILE_TYPE && type != DIRECTORY_TYPE) return NS_ERROR_FILE_UNKNOWN_TYPE; @@ -439,39 +447,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; @@ -480,7 +483,6 @@ nsLocalFile::AppendRelativePath(const char *fragment) NS_IMETHODIMP nsLocalFile::Normalize() { - CHECK_mPath(); char resolved_path[PATH_MAX] = ""; char *resolved_path_ptr = nsnull; @@ -499,81 +501,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; @@ -603,24 +586,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; } @@ -638,7 +618,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; @@ -656,10 +636,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; @@ -688,11 +668,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->CopyToNative(newDir, nsCString()))) { #ifdef DEBUG nsresult rv2; - nsXPIDLCString pathName; - if (NS_FAILED(rv2 = entry->GetPath(getter_Copies(pathName)))) + nsCAutoString pathName; + if (NS_FAILED(rv2 = entry->GetNativePath(pathName))) return rv2; printf("Operation not supported: %s\n", pathName.get()); #endif @@ -702,11 +682,11 @@ nsLocalFile::CopyDirectoryTo(nsIFile *newParent) } } } else { - if (NS_FAILED(rv = entry->CopyTo(newParent, nsnull))) { + if (NS_FAILED(rv = entry->CopyToNative(newParent, nsCString()))) { #ifdef DEBUG nsresult rv2; - nsXPIDLCString pathName; - if (NS_FAILED(rv2 = entry->GetPath(getter_Copies(pathName)))) + nsCAutoString pathName; + if (NS_FAILED(rv2 = entry->GetNativePath(pathName))) return rv2; printf("Operation not supported: %s\n", pathName.get()); #endif @@ -720,7 +700,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 @@ -730,26 +710,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; @@ -762,7 +743,7 @@ nsLocalFile::CopyTo(nsIFile *newParent, const char *newName) if (!newFile) return NS_ERROR_OUT_OF_MEMORY; - rv = newFile->InitWithPath(newPathName); + rv = newFile->InitWithNativePath(newPathName); if (NS_FAILED(rv)) return rv; @@ -849,13 +830,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; @@ -863,8 +844,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; @@ -875,7 +856,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 { @@ -1176,12 +1157,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, '/'); @@ -1190,28 +1169,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; } @@ -1287,11 +1260,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; } @@ -1330,14 +1301,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; } @@ -1348,19 +1317,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; } @@ -1368,10 +1337,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); @@ -1393,7 +1362,6 @@ nsLocalFile::GetTarget(char **_retval) return NSRESULT_FOR_ERRNO(); } target[size] = '\0'; - *_retval = nsnull; nsresult rv; PRBool isSymlink; @@ -1401,37 +1369,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; } @@ -1440,25 +1410,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; } @@ -1511,26 +1475,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); @@ -1544,11 +1504,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; @@ -1568,15 +1525,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; @@ -1585,3 +1542,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 nsAString &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 *cursor = result; + int i = 0; + + nsAString::const_iterator start, end; + input.BeginReading(start); + input.EndReading(end); + PRUint32 size; + + for ( ; start != end; start.advance(size)) { + size = start.size_forward(); + + const PRUnichar *p = start.get(); + + for (PRUint32 j = 0; j < size; ++j, ++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; + } + } + } + *cursor = '\0'; + return cursor - result; +} + +static int +convert_native_to_ucs2(const char *input, unsigned inputLen, nsAString &result) +{ +#ifdef HAVE_MBRTOWC + mbstate_t ps = {0}; +#endif + PRUnichar *p; + int i, resultLen = 0; + + result.Truncate(); + + // allocate space for largest possible result + result.SetLength(inputLen); + + nsAString::iterator start; + result.BeginWriting(start); + + p = start.get(); + 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 + // truncate and hope for the best + tmp = (unsigned char) *input; + i = 1; +#else + nsMemory::Free(*result); + *result = nsnull; + return -1; +#endif + } + *p = (PRUnichar) tmp; + input += i; + inputLen -= i; + p++; + resultLen++; + } + result.SetLength(resultLen); + return 0; +} + +#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::InitWithPath(const nsAString &filePath) +{ + SET_UCS(InitWithNativePath, filePath); +} +nsresult +nsLocalFile::Append(const nsAString &node) +{ + SET_UCS(AppendNative, node); +} +nsresult +nsLocalFile::AppendRelativePath(const nsAString &node) +{ + SET_UCS(AppendRelativeNativePath, node); +} +nsresult +nsLocalFile::GetLeafName(nsAString &aLeafName) +{ + GET_UCS(GetNativeLeafName, aLeafName); +} +nsresult +nsLocalFile::SetLeafName(const nsAString &aLeafName) +{ + SET_UCS(SetNativeLeafName, aLeafName); +} +nsresult +nsLocalFile::GetPath(nsAString &_retval) +{ + int i = convert_native_to_ucs2(mPath.get(), mPath.Length(), _retval); + if (i == -1) + return NS_ERROR_FAILURE; + return NS_OK; +} +nsresult +nsLocalFile::CopyTo(nsIFile *newParentDir, const nsAString &newName) +{ + SET_UCS_2ARGS_2(CopyToNative , newParentDir, newName); +} +nsresult +nsLocalFile::CopyToFollowingLinks(nsIFile *newParentDir, const nsAString &newName) +{ + SET_UCS_2ARGS_2(CopyToFollowingLinksNative , newParentDir, newName); +} +nsresult +nsLocalFile::MoveTo(nsIFile *newParentDir, const nsAString &newName) +{ + SET_UCS_2ARGS_2(MoveToNative, newParentDir, newName); +} +nsresult +nsLocalFile::GetTarget(nsAString &_retval) +{ + GET_UCS(GetNativeTarget, _retval); +} +nsresult +NS_NewLocalFile(const nsAString &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 +//----------------------------------------------------------------------------- + +void +nsLocalFile::GlobalInit() +{ + // need to initialize the locale or else charset conversion will fail. + setlocale(LC_CTYPE, ""); +} + +void +nsLocalFile::GlobalShutdown() +{ +} diff --git a/mozilla/xpcom/io/nsLocalFileUnix.h b/mozilla/xpcom/io/nsLocalFileUnix.h index f1711238aaa..0505b638570 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() @@ -115,18 +115,27 @@ public: // nsILocalFile NS_DECL_NSILOCALFILE +public: + static void GlobalInit(); + static void GlobalShutdown(); + protected: - PRBool mHaveCachedStat; - struct stat mCachedStat; - nsXPIDLCString mPath; - + struct stat mCachedStat; + nsCString mPath; + PRPackedBool mHaveCachedStat; + + 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; + } nsresult FillStatCache(); nsresult CreateAndKeepOpen(PRUint32 type, PRIntn flags, diff --git a/mozilla/xpcom/io/nsLocalFileWin.cpp b/mozilla/xpcom/io/nsLocalFileWin.cpp index b0bfc8130ed..1711ed0aadc 100644 --- a/mozilla/xpcom/io/nsLocalFileWin.cpp +++ b/mozilla/xpcom/io/nsLocalFileWin.cpp @@ -54,6 +54,10 @@ #include "nsAutoLock.h" +//---------------------------------------------------------------------------- +// short cut resolver +//---------------------------------------------------------------------------- + class ShortcutResolver { public: @@ -69,7 +73,6 @@ private: IShellLink* mShellLink; }; - ShortcutResolver::ShortcutResolver() { mLock = nsnull; @@ -77,7 +80,6 @@ ShortcutResolver::ShortcutResolver() mShellLink = nsnull; } - ShortcutResolver::~ShortcutResolver() { if (mLock) @@ -148,7 +150,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 +159,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 +250,10 @@ myLL_L2II(PRInt64 result, PRInt32 *hi, PRInt32 *lo ) } +//----------------------------------------------------------------------------- +// nsDirEnumerator +//----------------------------------------------------------------------------- + class nsDirEnumerator : public nsISimpleEnumerator { public: @@ -258,25 +267,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 +312,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 +362,10 @@ class nsDirEnumerator : public nsISimpleEnumerator NS_IMPL_ISUPPORTS1(nsDirEnumerator, nsISimpleEnumerator); +//----------------------------------------------------------------------------- +// nsLocalFile +//----------------------------------------------------------------------------- + nsLocalFile::nsLocalFile() { NS_INIT_REFCNT(); @@ -367,9 +378,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 +397,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 +416,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 +663,11 @@ nsLocalFile::ResolveAndStat(PRBool resolveTerminal) return result; } + +//----------------------------------------------------------------------------- +// nsLocalFile::nsIFile,nsILocalFile +//----------------------------------------------------------------------------- + NS_IMETHODIMP nsLocalFile::Clone(nsIFile **file) { @@ -669,51 +690,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 +745,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 +810,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 +842,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 +876,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 +892,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 +918,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 +953,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 +968,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 +995,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 +1029,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 +1073,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 +1133,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 +1161,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 +1584,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 +1595,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 +1665,7 @@ nsLocalFile::IsExecutable(PRBool *_retval) if (NS_FAILED(rv)) return rv; - char* path = nsnull; + nsCAutoString path; PRBool symLink; rv = IsSymlink(&symLink); @@ -1665,12 +1673,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 +1707,6 @@ nsLocalFile::IsExecutable(PRBool *_retval) } } - nsMemory::Free(path); - return NS_OK; } @@ -1761,21 +1767,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 +1807,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 +1820,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 +1841,6 @@ nsLocalFile::Contains(nsIFile *inFile, PRBool recur, PRBool *_retval) } } - - nsMemory::Free(inFilePath); - nsMemory::Free(myFilePath); return NS_OK; } @@ -1856,10 +1848,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 +1865,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 +1916,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 +1932,13 @@ nsLocalFile::Reveal() { nsresult rv = NS_OK; PRBool isDirectory = PR_FALSE; - nsXPIDLCString path; - nsXPIDLString unicodePath; + nsCAutoString path; + nsAutoString unicodePath; IsDirectory(&isDirectory); if (isDirectory) { - GetPath(getter_Copies(path)); + GetNativePath(path); } else { @@ -1957,8 +1946,8 @@ nsLocalFile::Reveal() GetParent(getter_AddRefs(parent)); if (parent) { - parent->GetPath(getter_Copies(path)); - parent->GetUnicodePath(getter_Copies(unicodePath)); + parent->GetNativePath(path); + parent->GetPath(unicodePath); } } @@ -1967,7 +1956,7 @@ nsLocalFile::Reveal() 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; @@ -2037,8 +2026,8 @@ nsLocalFile::Reveal() break; // Now get file name pidl from that folder. - nsXPIDLString unicodeLeaf; - if (NS_FAILED(GetUnicodeLeafName(getter_Copies(unicodeLeaf)))) + nsAutoString unicodeLeaf; + if (NS_FAILED(GetLeafName(unicodeLeaf))) break; rc = folder->ParseDisplayName( 0, 0, @@ -2120,17 +2109,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 +2130,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 +2139,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 +2151,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,138 +2205,155 @@ static nsresult FStoUCS2(const char* aBuffer, PRUnichar **aResult) return NS_OK; } -// Unicode interface Wrapper -NS_IMETHODIMP -nsLocalFile::InitWithUnicodePath(const PRUnichar *filePath) +nsresult +nsLocalFile::InitWithPath(const nsAString &filePath) { nsXPIDLCString tmp; - nsresult rv = UCS2toFS(filePath, getter_Copies(tmp)); + nsresult rv = UCS2toFS(PromiseFlatString(filePath).get(), getter_Copies(tmp)); if (NS_SUCCEEDED(rv)) - return InitWithPath(tmp); + return InitWithNativePath(tmp); return rv; } -NS_IMETHODIMP -nsLocalFile::AppendUnicode(const PRUnichar *node) +nsresult +nsLocalFile::Append(const nsAString &node) { nsXPIDLCString tmp; - nsresult rv = UCS2toFS(node, getter_Copies(tmp)); + nsresult rv = UCS2toFS(PromiseFlatString(node).get(), getter_Copies(tmp)); if (NS_SUCCEEDED(rv)) - return Append(tmp); + return AppendNative(tmp); return rv; } - -NS_IMETHODIMP -nsLocalFile::AppendRelativeUnicodePath(const PRUnichar *node) +nsresult +nsLocalFile::AppendRelativePath(const nsAString &node) { nsXPIDLCString tmp; - nsresult rv = UCS2toFS(node, getter_Copies(tmp)); + nsresult rv = UCS2toFS(PromiseFlatString(node).get(), getter_Copies(tmp)); if (NS_SUCCEEDED(rv)) - return AppendRelativePath(tmp); + return AppendRelativeNativePath(tmp); return rv; } -NS_IMETHODIMP -nsLocalFile::GetUnicodeLeafName(PRUnichar **aLeafName) +nsresult +nsLocalFile::GetLeafName(nsAString &aLeafName) { - nsXPIDLCString tmp; - nsresult rv = GetLeafName(getter_Copies(tmp)); - if (NS_SUCCEEDED(rv)) - return FStoUCS2(tmp, aLeafName); + nsCAutoString tmp; + nsresult rv = GetNativeLeafName(tmp); + if (NS_SUCCEEDED(rv)) { + nsXPIDLString ucsBuf; + rv = FStoUCS2(tmp.get(), getter_Copies(ucsBuf)); + if (NS_SUCCEEDED(rv)) + aLeafName = ucsBuf; + } return rv; } -NS_IMETHODIMP -nsLocalFile::SetUnicodeLeafName(const PRUnichar * aLeafName) +nsresult +nsLocalFile::SetLeafName(const nsAString &aLeafName) { nsXPIDLCString tmp; - nsresult rv = UCS2toFS(aLeafName, getter_Copies(tmp)); + nsresult rv = UCS2toFS(PromiseFlatString(aLeafName).get(), getter_Copies(tmp)); if (NS_SUCCEEDED(rv)) - return SetLeafName(tmp); + return SetNativeLeafName(tmp); return rv; } -NS_IMETHODIMP -nsLocalFile::GetUnicodePath(PRUnichar **_retval) +nsresult +nsLocalFile::GetPath(nsAString &_retval) { - nsXPIDLCString tmp; - nsresult rv = GetPath(getter_Copies(tmp)); + nsXPIDLString ucsBuf; + nsresult rv = FStoUCS2(mWorkingPath.get(), getter_Copies(ucsBuf)); if (NS_SUCCEEDED(rv)) - return FStoUCS2(tmp, _retval); + _retval = ucsBuf; + return rv; +} + +nsresult +nsLocalFile::CopyTo(nsIFile *newParentDir, const nsAString &newName) +{ + if (newName.IsEmpty()) + return CopyToNative(newParentDir, nsCString()); + + nsXPIDLCString tmp; + nsresult rv = UCS2toFS(PromiseFlatString(newName).get(), getter_Copies(tmp)); + if (NS_SUCCEEDED(rv)) + return CopyToNative(newParentDir, tmp); return rv; } -NS_IMETHODIMP -nsLocalFile::CopyToUnicode(nsIFile *newParentDir, const PRUnichar *newName) +nsresult +nsLocalFile::CopyToFollowingLinks(nsIFile *newParentDir, const nsAString &newName) { - if (!newName) - return CopyTo(newParentDir, nsnull); + if (newName.IsEmpty()) + return CopyToFollowingLinksNative(newParentDir, nsCString()); nsXPIDLCString tmp; - nsresult rv = UCS2toFS(newName, getter_Copies(tmp)); + nsresult rv = UCS2toFS(PromiseFlatString(newName).get(), getter_Copies(tmp)); if (NS_SUCCEEDED(rv)) - return CopyTo(newParentDir, tmp); + return CopyToFollowingLinksNative(newParentDir, tmp); return rv; } -NS_IMETHODIMP -nsLocalFile::CopyToFollowingLinksUnicode(nsIFile *newParentDir, const PRUnichar *newName) +nsresult +nsLocalFile::MoveTo(nsIFile *newParentDir, const nsAString &newName) { - if (!newName) return CopyToFollowingLinks(newParentDir, nsnull); + if (newName.IsEmpty()) + return MoveToNative(newParentDir, nsCString()); nsXPIDLCString tmp; - nsresult rv = UCS2toFS(newName, getter_Copies(tmp)); + nsresult rv = UCS2toFS(PromiseFlatString(newName).get(), getter_Copies(tmp)); if (NS_SUCCEEDED(rv)) - return CopyToFollowingLinks(newParentDir, tmp); - - return rv; -} - -NS_IMETHODIMP -nsLocalFile::MoveToUnicode(nsIFile *newParentDir, const PRUnichar *newName) -{ - if (!newName) - return MoveTo(newParentDir, nsnull); - - 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 -nsLocalFile::GetUnicodeTarget(PRUnichar **_retval) +nsresult +nsLocalFile::GetTarget(nsAString &_retval) { - nsXPIDLCString tmp; - nsresult rv = GetTarget(getter_Copies(tmp)); - if (NS_SUCCEEDED(rv)) - return FStoUCS2(tmp, _retval); + nsCAutoString tmp; + nsresult rv = GetNativeTarget(tmp); + if (NS_SUCCEEDED(rv)) { + nsXPIDLString ucsBuf; + rv = FStoUCS2(tmp.get(), getter_Copies(ucsBuf)); + if (NS_SUCCEEDED(rv)) + _retval = ucsBuf; + } return rv; } nsresult -NS_NewUnicodeLocalFile(const PRUnichar* path, PRBool followLinks, nsILocalFile* *result) +NS_NewLocalFile(const nsAString &path, PRBool followLinks, nsILocalFile* *result) { nsXPIDLCString tmp; - nsresult rv = UCS2toFS(path, getter_Copies(tmp)); + nsresult rv = UCS2toFS(PromiseFlatString(path).get(), 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 +//----------------------------------------------------------------------------- +void +nsLocalFile::GlobalInit() +{ + nsresult rv = NS_CreateShortcutResolver(); + NS_ASSERTION(NS_SUCCEEDED(rv), "Shortcut resolver could not be created"); +} +void +nsLocalFile::GlobalShutdown() +{ + NS_DestroyShortcutResolver(); +} diff --git a/mozilla/xpcom/io/nsLocalFileWin.h b/mozilla/xpcom/io/nsLocalFileWin.h index d2fb610e605..d4a29b20454 100644 --- a/mozilla/xpcom/io/nsLocalFileWin.h +++ b/mozilla/xpcom/io/nsLocalFileWin.h @@ -65,6 +65,10 @@ public: // nsILocalFile interface NS_DECL_NSILOCALFILE +public: + static void GlobalInit(); + static void GlobalShutdown(); + private: // this is the flag which indicates if I can used cached information about the file @@ -79,21 +83,18 @@ private: // this will be the resolve path which will *NEVER* be return to the user nsCString mResolvedPath; - PRFileInfo64 mFileInfo64; - + PRFileInfo64 mFileInfo64; + + static PRBool mFSCharsetIsUTF8; + 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..48b54546800 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->GetNativeLeafName(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->AppendNative(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->GetNativeLeafName(name1))) { NS_ERROR("way bad, with no happy out!"); return 0; } - if(NS_FAILED(pFile2->GetLeafName(getter_Copies(name2)))) + if(NS_FAILED(pFile2->GetNativeLeafName(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->GetNativeLeafName(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->GetNativeLeafName(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->GetNativeLeafName(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->GetNativeLeafName(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->GetNativeLeafName(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->GetNativeLeafName(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..19079d8f1bc 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_NewNativeLocalFile(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,13 +130,13 @@ 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) return PR_FALSE; - if(NS_FAILED(tempFile->Append(g_TempManifestFilename))) + if(NS_FAILED(tempFile->AppendNative(g_TempManifestFilename))) return PR_FALSE; // All exits via "goto out;" from here on... @@ -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())) @@ -261,7 +262,7 @@ out: if(!aMgr->GetCloneOfManifestDir(getter_AddRefs(mainFile)) || !mainFile) return PR_FALSE; - if(NS_FAILED(mainFile->Append(g_MainManifestFilename))) + if(NS_FAILED(mainFile->AppendNative(g_MainManifestFilename))) return PR_FALSE; PRBool exists; @@ -272,7 +273,7 @@ out: return PR_FALSE; // MoveTo means rename. - if(NS_FAILED(tempFile->MoveTo(nsnull, g_MainManifestFilename))) + if(NS_FAILED(tempFile->MoveToNative(nsnull, g_MainManifestFilename))) return PR_FALSE; } @@ -296,15 +297,15 @@ ReadManifestIntoMemory(xptiInterfaceInfoManager* aMgr, if(!aMgr->GetCloneOfManifestDir(getter_AddRefs(aFile)) || !aFile) return nsnull; - if(NS_FAILED(aFile->Append(g_MainManifestFilename))) + if(NS_FAILED(aFile->AppendNative(g_MainManifestFilename))) return nsnull; #ifdef DEBUG { static PRBool shown = PR_FALSE; - nsXPIDLCString path; - if(!shown && NS_SUCCEEDED(aFile->GetPath(getter_Copies(path))) && path) + nsCAutoString path; + if(!shown && NS_SUCCEEDED(aFile->GetNativePath(path)) && !path.IsEmpty()) { printf("Type Manifest File: %s\n", path.get()); shown = PR_TRUE; @@ -775,7 +776,7 @@ PRBool xptiManifest::Delete(xptiInterfaceInfoManager* aMgr) if(!aMgr->GetCloneOfManifestDir(getter_AddRefs(aFile)) || !aFile) return PR_FALSE; - if(NS_FAILED(aFile->Append(g_MainManifestFilename))) + if(NS_FAILED(aFile->AppendNative(g_MainManifestFilename))) return PR_FALSE; PRBool exists; diff --git a/mozilla/xpcom/reflect/xptinfo/src/xptiWorkingSet.cpp b/mozilla/xpcom/reflect/xptinfo/src/xptiWorkingSet.cpp index 9d8ff78676d..72b682fe254 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_NewNativeLocalFile(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..90bc49f0050 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, nsString()); 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 67522986d98..92ceb0cf549 100644 --- a/mozilla/xpfe/bootstrap/nsAppRunner.cpp +++ b/mozilla/xpfe/bootstrap/nsAppRunner.cpp @@ -1150,7 +1150,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) { @@ -1185,7 +1185,7 @@ static nsresult VerifyInstallation(int argc, char **argv) if (NS_FAILED(rv) || !registryFile) return NS_ERROR_FAILURE; - registryFile->Append(CLEANUP_REGISTRY); + registryFile->AppendNative(CLEANUP_REGISTRY); PRBool exists; registryFile->Exists(&exists); @@ -1194,11 +1194,11 @@ 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)); - cleanupUtility->SetLeafName(CLEANUP_UTIL); + cleanupUtility->SetNativeLeafName(CLEANUP_UTIL); //Create the process framework to run the cleanup utility nsCOMPtr cleanupProcess = do_CreateInstance(kIProcessCID); diff --git a/mozilla/xpfe/communicator/resources/content/contentAreaUtils.js b/mozilla/xpfe/communicator/resources/content/contentAreaUtils.js index ea371793aef..5bb7e3569a1 100644 --- a/mozilla/xpfe/communicator/resources/content/contentAreaUtils.js +++ b/mozilla/xpfe/communicator/resources/content/contentAreaUtils.js @@ -310,7 +310,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 643d28233af..84f5e13b2fd 100644 --- a/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.cpp +++ b/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.cpp @@ -3161,7 +3161,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 nsAFlatString &aFileName, char** aOutURL) { // IUniformResourceLocator isn't supported by VC5 (bless its little heart) #if _MSC_VER >= 1200 @@ -3174,10 +3174,7 @@ 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); - - result = urlFile->Load(wideFileName, STGM_READ); + result = urlFile->Load(aFileName.get(), STGM_READ); if (SUCCEEDED(result) ) { LPSTR lpTemp = nsnull; @@ -3232,8 +3229,8 @@ nsBookmarksService::ParseFavoritesFolder(nsIFile* aDirectory, nsIRDFResource* aP nsCOMPtr fileURL(do_QueryInterface(uri)); fileURL->SetFile(currFile); - nsXPIDLString bookmarkName; - currFile->GetUnicodeLeafName(getter_Copies(bookmarkName)); + nsAutoString bookmarkName; + currFile->GetLeafName(bookmarkName); PRBool isDir = PR_FALSE; currFile->IsDirectory(&isDir); @@ -3254,11 +3251,11 @@ nsBookmarksService::ParseFavoritesFolder(nsIFile* aDirectory, nsIRDFResource* aP if (!extension.Equals(NS_LITERAL_CSTRING("url"))) continue; - nsXPIDLCString path; - currFile->GetPath(getter_Copies(path)); + nsAutoString path; + currFile->GetPath(path); nsXPIDLCString url; - ResolveShortcut(path.get(), getter_Copies(url)); + ResolveShortcut(path, getter_Copies(url)); nsCAutoString baseName; fileURL->GetFileBaseName(baseName); @@ -4637,12 +4634,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 b9c674ba0bc..7705dbdab00 100644 --- a/mozilla/xpfe/components/download-manager/src/nsDownloadManager.cpp +++ b/mozilla/xpfe/components/download-manager/src/nsDownloadManager.cpp @@ -415,12 +415,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 @@ -452,11 +452,9 @@ nsDownloadManager::AddDownload(nsIURI* aSource, } // Set and assert the "pretty" (display) name of the download - nsXPIDLString prettyName; nsAutoString displayName; displayName.Assign(aDisplayName); if (displayName.IsEmpty()) { - aTarget->GetUnicodeLeafName(getter_Copies(prettyName)); - displayName.Assign(prettyName); + aTarget->GetLeafName(displayName); } (*aDownload)->SetDisplayName(displayName.get()); @@ -478,7 +476,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); @@ -777,8 +775,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); @@ -787,7 +785,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; @@ -811,11 +809,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 @@ -937,12 +935,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) @@ -1002,11 +1000,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) @@ -1052,11 +1050,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 @@ -1112,11 +1110,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..3efaf1bfaad 100644 --- a/mozilla/xpfe/components/filepicker/src/nsFileView.cpp +++ b/mozilla/xpfe/components/filepicker/src/nsFileView.cpp @@ -540,10 +540,7 @@ 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; + curFile->GetLeafName(aCellText); } else if (NS_LITERAL_STRING("LastModifiedColumn").Equals(aColID)) { PRInt64 lastModTime; curFile->GetLastModifiedTime(&lastModTime); @@ -648,15 +645,15 @@ nsFileView::FilterFiles() if (!mShowHiddenFiles) file->IsHidden(&isHidden); - nsXPIDLString unicodeLeafName; - if(NS_FAILED(file->GetUnicodeLeafName(getter_Copies(unicodeLeafName)))) { - // need to check return value for GetUnicodeLeafName() + nsAutoString ucsLeafName; + if(NS_FAILED(file->GetLeafName(ucsLeafName))) { + // need to check return value for GetLeafName() continue; } 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 +688,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)); + nsAutoString 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 9351fcd95be..b65f3871966 100644 --- a/mozilla/xpfe/components/history/src/nsGlobalHistory.cpp +++ b/mozilla/xpfe/components/history/src/nsGlobalHistory.cpp @@ -71,6 +71,7 @@ #include "rdf.h" #include "nsQuickSort.h" #include "nsIIOService.h" +#include "nsILocalFile.h" #include "nsIURL.h" #include "nsNetCID.h" @@ -2378,21 +2379,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..4337c0faf01 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(NS_ConvertUTF8toUCS2(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,9 @@ 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)); + nsAutoString basename; + rv = native->GetLeafName(basename); if (NS_FAILED(rv)) return rv; - basename.AssignWithConversion((const char *)leafCName); // ensure that the basename points to the search engine file PRInt32 extensionOffset; @@ -3845,14 +3843,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 +4052,11 @@ InternetSearchDataSource::GetSearchEngineList(nsIFile *searchDir, if (NS_FAILED(rv) || (fileSize == 0)) continue; - nsXPIDLCString pathBuf; - rv = dirEntry->GetPath(getter_Copies(pathBuf)); + nsAutoString uri; + rv = dirEntry->GetPath(uri); if (NS_FAILED(rv)) continue; - nsAutoString uri; - uri.AssignWithConversion((const char *)pathBuf); PRInt32 len = uri.Length(); if (len < 5) { @@ -4142,7 +4137,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/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..d0c895f0f75 100644 --- a/mozilla/xpfe/components/xfer/src/nsStreamTransfer.cpp +++ b/mozilla/xpfe/components/xfer/src/nsStreamTransfer.cpp @@ -328,12 +328,10 @@ 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(); - } + localFile->GetLeafName(result); } } else if ( aChannel ) { // Get URI from channel and spec from URI. @@ -348,11 +346,8 @@ 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(); + if ( NS_SUCCEEDED( localeFile->GetLeafName( result ) ) ) return result; - } } } @@ -362,7 +357,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 d1dab4ec184..4944ad8d09e 100644 --- a/mozilla/xpinstall/src/ScheduledTasks.cpp +++ b/mozilla/xpinstall/src/ScheduledTasks.cpp @@ -34,20 +34,16 @@ #include "nsDirectoryServiceDefs.h" #include "nsAppDirectoryServiceDefs.h" -static nsresult -GetPersistentStringFromSpec(nsIFile* inSpec, char **string) +static nsresult +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 = inSpec->GetNativePath(string); + } else { - *string = nsnull; + string.Truncate(); } return rv; } @@ -67,13 +63,13 @@ 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); - - // Get build numbers for Windows NT or Win32s + finalSpec->GetNativePath(final); + currentSpec->GetNativePath(current); + + // Get build numbers for Windows NT or Win32s if (dwVersion > 0x80000000) { @@ -85,45 +81,39 @@ PRInt32 ReplaceWindowsSystemFile(nsIFile* currentSpec, nsIFile* finalSpec) int strlen; char Src[_MAX_PATH]; // 8.3 name char Dest[_MAX_PATH]; // 8.3 name - - strlen = GetShortPathName( (LPCTSTR)current, (LPTSTR)Src, (DWORD)sizeof(Src) ); - if ( strlen > 0 ) + + 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)); - if ( strlen > 0 ) + 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 + // .INI file, WININIT.INI is processed under DOS + + AnsiToOem( (char*)final.get(), (char*)final.get() ); + AnsiToOem( (char*)current.get(), (char*)current.get() ); - AnsiToOem( final, final ); - AnsiToOem( current, current ); - - 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; @@ -142,7 +132,7 @@ char* GetRegFilePath() return nsnull; #if defined (XP_MAC) - tmp->Append(ESSENTIAL_FILES); + tmp->AppendNative(ESSENTIAL_FILES); #endif iFileUtilityPath = do_QueryInterface(tmp); } @@ -155,14 +145,11 @@ char* GetRegFilePath() if (NS_FAILED(rv) || !iFileUtilityPath) return nsnull; - iFileUtilityPath->Append(CLEANUP_REGISTRY); + iFileUtilityPath->AppendNative(CLEANUP_REGISTRY); - //Yes, we know using GetPath is buggy on the Mac. + //Yes, we know using GetNativePath 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); } @@ -188,10 +175,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 ) { @@ -203,15 +189,14 @@ 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; - err = NR_RegSetEntry( reg, newkey, valname, - REGTYPE_ENTRY_BYTES, - (void*)fnamestr, + const char *fnamestr = nameowner.get(); + err = NR_RegSetEntry( reg, newkey, valname, + REGTYPE_ENTRY_BYTES, + (void*)fnamestr, strlen(fnamestr)+sizeof('\0')); if ( err == REGERR_OK ) @@ -254,7 +239,8 @@ PRInt32 ReplaceFileNow(nsIFile* replacementFile, nsIFile* doomedFile ) nsCOMPtr renamedDoomedFile; nsCOMPtr tmpLocalFile; nsCOMPtr parent; - + nsCAutoString leafname; + doomedFile->Clone(getter_AddRefs(renamedDoomedFile)); renamedDoomedFile->Exists(&flagExists); if ( flagExists ) @@ -262,36 +248,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 - nsXPIDLString uniqueLeafName; - tmpLocalFile->GetUnicodeLeafName(getter_Copies(uniqueLeafName)); - nsString newLeafName (uniqueLeafName); + 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 + // We found the extension; + leafname.Truncate(extpos + 1); //strip off the old extension } - newLeafName.Append(NS_LITERAL_STRING("old")); - + leafname.Append(NS_LITERAL_CSTRING("old")); + //Now reset the leafname - tmpLocalFile->SetUnicodeLeafName(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->GetUnicodeLeafName(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->MoveToUnicode(parent, uniqueLeafName); + rv = renamedDoomedFile->MoveToNative(parent, uniqueLeafName); if (NS_SUCCEEDED(rv)) { - renamedDoomedFile = parent; //MoveTo on Mac doesn't reset the tmpFile object to - renamedDoomedFile->AppendUnicode(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) @@ -305,7 +290,7 @@ PRInt32 ReplaceFileNow(nsIFile* replacementFile, nsIFile* doomedFile ) { nsCOMPtr parentofFinalFile; nsCOMPtr parentofReplacementFile; - nsXPIDLString leafname; + nsCAutoString leafname; doomedFile->GetParent(getter_AddRefs(parentofFinalFile)); replacementFile->GetParent(getter_AddRefs(parentofReplacementFile)); @@ -318,13 +303,13 @@ PRInt32 ReplaceFileNow(nsIFile* replacementFile, nsIFile* doomedFile ) if(!flagIsEqual) { NS_WARNING("File unpacked into a non-dest dir" ); - replacementFile->GetUnicodeLeafName(getter_Copies(leafname)); - rv = replacementFile->MoveToUnicode(parentofFinalFile, leafname); + replacementFile->GetNativeLeafName(leafname); + rv = replacementFile->MoveToNative(parentofFinalFile, leafname); } - - rv = doomedFile->GetUnicodeLeafName(getter_Copies(leafname)); + + rv = doomedFile->GetNativeLeafName(leafname); if ( NS_SUCCEEDED(rv)) - rv = replacementFile->MoveToUnicode(parentofReplacementFile, leafname); + rv = replacementFile->MoveToNative(parentofReplacementFile, leafname); if ( NS_SUCCEEDED(rv) ) { @@ -336,7 +321,7 @@ PRInt32 ReplaceFileNow(nsIFile* replacementFile, nsIFile* doomedFile ) { // couldn't rename file, try to put old file back renamedDoomedFile->GetParent(getter_AddRefs(parent)); - renamedDoomedFile->MoveToUnicode(parent, leafname); + renamedDoomedFile->MoveToNative(parent, leafname); } } @@ -365,8 +350,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 ) @@ -380,18 +366,15 @@ 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; - err = NR_RegSetEntry( reg, filekey, + const char *fsrc = srcowner.get(); + const char *fdest = destowner.get(); + err = NR_RegSetEntry( reg, filekey, REG_REPLACE_SRCFILE, REGTYPE_ENTRY_BYTES, (void*)fsrc, @@ -416,8 +399,6 @@ PRInt32 ReplaceFileNowOrSchedule(nsIFile* replacementFile, nsIFile* doomedFile, } NR_RegClose(reg); } - if (regFilePath) - nsCRT::free(regFilePath); } return result; @@ -474,7 +455,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)) { @@ -535,10 +516,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 663ec8d0cda..b7d6d1c2546 100644 --- a/mozilla/xpinstall/src/nsInstall.cpp +++ b/mozilla/xpinstall/src/nsInstall.cpp @@ -708,8 +708,7 @@ nsInstall::DiskSpaceAvailable(const nsString& aFolder, PRInt64* aReturn) return NS_OK; } nsCOMPtr folder; - NS_NewUnicodeLocalFile(aFolder.get(), PR_TRUE, - getter_AddRefs(folder)); + NS_NewLocalFile(aFolder, PR_TRUE, getter_AddRefs(folder)); result = folder->GetDiskSpaceAvailable(aReturn); return NS_OK; @@ -946,7 +945,7 @@ nsInstall::GetComponentFolder(const nsString& aComponentName, const nsString& aS nsCOMPtr componentDir; nsCOMPtr componentIFile; if(*dir != '\0') - NS_NewLocalFile( dir, PR_FALSE, getter_AddRefs(componentDir) ); // native path from registry + NS_NewNativeLocalFile( nsDependentCString(dir), PR_FALSE, getter_AddRefs(componentDir) ); // native path from registry if ( componentDir ) { @@ -1435,7 +1434,7 @@ nsInstall::StartInstall(const nsString& aUserPackageName, const nsString& aRegis // found one saved in the registry mPackageFolder = new nsInstallFolder(); nsCOMPtr packageDir; - NS_NewLocalFile( szRegPackagePath, PR_FALSE, getter_AddRefs(packageDir) ); // native path + NS_NewNativeLocalFile( nsDependentCString(szRegPackagePath), PR_FALSE, getter_AddRefs(packageDir) ); // native path if (mPackageFolder && packageDir) { @@ -1790,7 +1789,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; @@ -1801,7 +1800,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) @@ -1811,7 +1810,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 */ @@ -2028,7 +2027,7 @@ nsInstall::FileOpFileWindowsGetShortName(nsInstallFolder& aTarget, nsString& aSh PRInt32 err; PRBool flagExists; nsString tmpNsString; - nsXPIDLCString nativeTargetPath; + nsCAutoString nativeTargetPath; nsXPIDLString unicodePath; char nativeShortPathName[MAX_PATH]; nsCOMPtr localTarget(aTarget.GetFileSpec()); @@ -2040,9 +2039,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. @@ -2052,7 +2051,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? @@ -2572,7 +2571,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('.'); @@ -2583,7 +2582,7 @@ nsInstall::ExtractFileFromJar(const nsString& aJarfile, nsIFile* aSuggestedName, aJarfile.Right(extension, (aJarfile.Length() - extpos) ); tempFileName += extension; } - tempFile->AppendUnicode(tempFileName.get()); + tempFile->Append(tempFileName); // Create a temporary file to extract to MakeUnique(tempFile); @@ -2612,9 +2611,8 @@ nsInstall::ExtractFileFromJar(const nsString& aJarfile, nsIFile* aSuggestedName, return nsInstall::OUT_OF_MEMORY; //get the leafname so we can convert its extension to .new - nsXPIDLString leafName; - tempFile->GetUnicodeLeafName(getter_Copies(leafName)); - nsString newLeafName (leafName); + nsAutoString newLeafName; + tempFile->GetLeafName(newLeafName); PRInt32 extpos = newLeafName.RFindChar('.'); if (extpos != -1) @@ -2625,7 +2623,7 @@ nsInstall::ExtractFileFromJar(const nsString& aJarfile, nsIFile* aSuggestedName, newLeafName.Append(NS_LITERAL_STRING("new")); //Now reset the leafname - tempFile->SetUnicodeLeafName(newLeafName.get()); + tempFile->SetLeafName(newLeafName); MakeUnique(tempFile); extractHereSpec = tempFile; @@ -2793,6 +2791,7 @@ nsInstall::DeleteVector(nsVoidArray* vector) } } +// XXX what's wrong with nsIFile::createUnique? nsresult MakeUnique(nsILocalFile* file) { PRBool flagExists; @@ -2802,11 +2801,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->GetNativeLeafName(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) @@ -2826,7 +2828,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->SetNativeLeafName(nsDependentCString(newName)); rv = file->Exists(&flagExists); if (NS_FAILED(rv)) diff --git a/mozilla/xpinstall/src/nsInstallExecute.cpp b/mozilla/xpinstall/src/nsInstallExecute.cpp index b4f47506f9a..f3640541e91 100644 --- a/mozilla/xpinstall/src/nsInstallExecute.cpp +++ b/mozilla/xpinstall/src/nsInstallExecute.cpp @@ -267,9 +267,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 1fc6a6fc786..07fcd9ada2b 100644 --- a/mozilla/xpinstall/src/nsInstallFile.cpp +++ b/mozilla/xpinstall/src/nsInstallFile.cpp @@ -110,7 +110,7 @@ nsInstallFile::nsInstallFile(nsInstall* inInstall, PRBool finished = PR_FALSE; PRUint32 offset = 0; PRInt32 location = 0, nodeLength = 0; - nsString subString; + nsAutoString subString; location = inPartialPath.FindChar('/', offset); if (location == ((PRInt32)inPartialPath.Length() - 1)) //trailing slash @@ -139,12 +139,7 @@ nsInstallFile::nsInstallFile(nsInstall* inInstall, else { nsresult rv = inPartialPath.Mid(subString, offset, nodeLength); -// remove dependency on libuconv on unix. -#ifndef XP_UNIX - mFinalFile->AppendUnicode(subString.get()); -#else - mFinalFile->Append(NS_LossyConvertUCS2toASCII(subString).get()); -#endif + mFinalFile->Append(subString); offset += nodeLength + 1; if (!finished) location = inPartialPath.FindChar('/', offset); @@ -209,16 +204,9 @@ void nsInstallFile::CreateAllFolders(nsInstall *aInstall, nsIFile *aFolder, PRIn aFolder->Create(nsIFile::DIRECTORY_TYPE, 0755); //nsIFileXXX: What kind of permissions are required here? ++mFolderCreateCount; -// remove dependency on libuconv on unix. -#ifndef XP_UNIX - nsXPIDLString folderPath; - aFolder->GetUnicodePath(getter_Copies(folderPath)); + nsAutoString folderPath; + aFolder->GetPath(folderPath); ilc = new nsInstallLogComment(aInstall, NS_LITERAL_STRING("CreateFolder"), folderPath, aError); -#else - nsXPIDLCString folderPath; - aFolder->GetPath(getter_Copies(folderPath)); - ilc = new nsInstallLogComment(aInstall, NS_LITERAL_STRING("CreateFolder"), NS_ConvertASCIItoUCS2(folderPath), aError); -#endif if(ilc == nsnull) *aError = nsInstall::OUT_OF_MEMORY; @@ -300,8 +288,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()), @@ -365,9 +353,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); @@ -403,9 +391,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 2e1230d71c2..1a6dc0bfbca 100644 --- a/mozilla/xpinstall/src/nsInstallFileOpItem.cpp +++ b/mozilla/xpinstall/src/nsInstallFileOpItem.cpp @@ -270,125 +270,119 @@ PRInt32 nsInstallFileOpItem::Complete() #define RESBUFSIZE 4096 char* nsInstallFileOpItem::toString() { - nsString result; + nsCAutoString result; char* resultCString = new char[RESBUFSIZE]; char* rsrcVal = nsnull; - char* temp = nsnull; - char* srcPath = nsnull; - char* dstPath = nsnull; + nsCAutoString temp; + nsCAutoString srcPath; + nsCAutoString dstPath; - // STRING USE WARNING: perhaps |result| should be an |nsCAutoString| to avoid all this double converting - *resultCString = nsnull; + *resultCString = '\0'; switch(mCommand) { case NS_FOP_FILE_COPY: 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()); } + 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 ); - } + mShortcutPath->GetNativePath(temp); + temp.Append(NS_LITERAL_CSTRING("\\") + NS_LossyConvertUCS2toASCII(mDescription)); + PR_snprintf(resultCString, RESBUFSIZE, rsrcVal, temp.get()); } break; @@ -396,10 +390,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: @@ -409,10 +403,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: @@ -422,9 +416,6 @@ char* nsInstallFileOpItem::toString() } if (rsrcVal) Recycle(rsrcVal); - if (temp) Recycle(temp); - if (srcPath) Recycle(srcPath); - if (dstPath) Recycle(dstPath); return resultCString; } @@ -644,7 +635,7 @@ nsInstallFileOpItem::NativeFileOpFileRenamePrepare() nsIFile* target; mSrc->GetParent(&target); - nsresult rv = target->AppendUnicode(mStrTarget->get()); + nsresult rv = target->Append(*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; @@ -684,7 +675,7 @@ nsInstallFileOpItem::NativeFileOpFileRenameComplete() if (target) { - target->AppendUnicode(mStrTarget->get()); + target->Append(*mStrTarget); } else return nsInstall::UNEXPECTED_ERROR; @@ -692,7 +683,7 @@ nsInstallFileOpItem::NativeFileOpFileRenameComplete() target->Exists(&flagExists); if(!flagExists) { - mSrc->MoveToUnicode(parent, mStrTarget->get()); + mSrc->MoveTo(parent, *mStrTarget); } else return nsInstall::ALREADY_EXISTS; @@ -726,11 +717,11 @@ nsInstallFileOpItem::NativeFileOpFileRenameAbort() mSrc->GetParent(getter_AddRefs(parent)); if(parent) { - nsXPIDLString leafName; - mSrc->GetUnicodeLeafName(getter_Copies(leafName)); + nsAutoString leafName; + mSrc->GetLeafName(leafName); - newFilename->AppendUnicode(mStrTarget->get()); - newFilename->MoveToUnicode(parent, leafName); + newFilename->Append(*mStrTarget); + newFilename->MoveTo(parent, leafName); } else return nsInstall::UNEXPECTED_ERROR; @@ -746,7 +737,7 @@ PRInt32 nsInstallFileOpItem::NativeFileOpFileCopyPrepare() { PRBool flagExists, flagIsFile, flagIsWritable; - char* leafName; + nsAutoString leafName; nsresult rv; nsCOMPtr tempVar; nsCOMPtr targetParent; @@ -786,7 +777,7 @@ nsInstallFileOpItem::NativeFileOpFileCopyPrepare() else { mTarget->Clone(getter_AddRefs(tempVar)); - mSrc->GetLeafName(&leafName); + mSrc->GetLeafName(leafName); tempVar->Append(leafName); tempVar->Exists(&flagExists); if(flagExists) @@ -813,7 +804,7 @@ nsInstallFileOpItem::NativeFileOpFileCopyComplete() { PRInt32 rv = NS_OK; PRBool flagIsFile, flagExists; - char* leafName; + nsAutoString leafName; nsCOMPtr parent; nsCOMPtr tempTarget; @@ -829,13 +820,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; @@ -852,7 +843,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); } @@ -872,8 +863,8 @@ nsInstallFileOpItem::NativeFileOpFileCopyAbort() mTarget->Clone(getter_AddRefs(fullTarget)); if(nsInstallFileOpItem::ACTION_SUCCESS == mAction) { - char* leafName; - mSrc->GetLeafName(&leafName); + nsAutoString leafName; + mSrc->GetLeafName(leafName); fullTarget->Append(leafName); fullTarget->Remove(PR_FALSE); } @@ -1022,10 +1013,10 @@ nsInstallFileOpItem::NativeFileOpFileMovePrepare() else { nsCOMPtr tempVar; - char* leaf; + nsAutoString leaf; mTarget->Clone(getter_AddRefs(tempVar)); - mSrc->GetLeafName(&leaf); + mSrc->GetLeafName(leaf); tempVar->Append(leaf); tempVar->Exists(&flagExists); @@ -1136,7 +1127,7 @@ nsInstallFileOpItem::NativeFileOpDirRenamePrepare() nsCOMPtr target; mSrc->GetParent(getter_AddRefs(target)); - target->AppendUnicode(mStrTarget->get()); + target->Append(*mStrTarget); target->Exists(&flagExists); if(flagExists) @@ -1166,14 +1157,14 @@ nsInstallFileOpItem::NativeFileOpDirRenameComplete() nsCOMPtr target; mSrc->GetParent(getter_AddRefs(target)); - target->AppendUnicode(mStrTarget->get()); + target->Append(*mStrTarget); target->Exists(&flagExists); if(!flagExists) { nsCOMPtr parent; mSrc->GetParent(getter_AddRefs(parent)); - ret = mSrc->MoveToUnicode(parent, mStrTarget->get()); + ret = mSrc->MoveTo(parent, *mStrTarget); } else return nsInstall::ALREADY_EXISTS; @@ -1198,12 +1189,12 @@ nsInstallFileOpItem::NativeFileOpDirRenameAbort() mSrc->Exists(&flagExists); if(!flagExists) { - nsXPIDLString leafName; - mSrc->GetUnicodeLeafName(getter_Copies(leafName)); + nsAutoString leafName; + mSrc->GetLeafName(leafName); mSrc->GetParent(getter_AddRefs(newDirName)); mSrc->GetParent(getter_AddRefs(parent)); - newDirName->AppendUnicode(mStrTarget->get()); - ret = newDirName->MoveToUnicode(parent, leafName); + newDirName->Append(*mStrTarget); + ret = newDirName->MoveTo(parent, leafName); } return ret; @@ -1231,7 +1222,7 @@ nsInstallFileOpItem::NativeFileOpWindowsShortcutPrepare() } else { - tempVar->Append("NSTestDir"); + tempVar->AppendNative(NS_LITERAL_CSTRING("NSTestDir")); tempVar->Create(1, 0755); tempVar->Exists(&flagExists); if(!flagExists) @@ -1271,13 +1262,13 @@ nsInstallFileOpItem::NativeFileOpWindowsShortcutComplete() else { if(mTarget) - mTarget->GetPath(getter_Copies(targetPath)); + mTarget->GetNativePath(targetPath); if(mShortcutPath) - mShortcutPath->GetPath(getter_Copies(shortcutPath)); + mShortcutPath->GetNativePath(shortcutPath); if(mWorkingPath) - mWorkingPath->GetPath(getter_Copies(workingPath)); + mWorkingPath->GetNativePath(workingPath); if(mIcon) - mIcon->GetPath(getter_Copies(iconPath)); + mIcon->GetNativePath(iconPath); CreateALink(targetPath, shortcutPath, @@ -1306,7 +1297,7 @@ nsInstallFileOpItem::NativeFileOpWindowsShortcutAbort() shortcutDescription = mDescription; shortcutDescription.Append(NS_LITERAL_STRING(".lnk")); mShortcutPath->Clone(getter_AddRefs(shortcutTarget)); - shortcutTarget->AppendUnicode(shortcutDescription.get()); + shortcutTarget->Append(shortcutDescription); NativeFileOpFileDeleteComplete(shortcutTarget); } @@ -1442,11 +1433,11 @@ nsInstallFileOpItem::NativeFileOpWindowsRegisterServerPrepare() FARPROC DllReg; HINSTANCE hLib; - nsXPIDLCString file; - mTarget->GetPath(getter_Copies(file)); - if(file) + nsCAutoString file; + 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; @@ -1472,11 +1463,11 @@ nsInstallFileOpItem::NativeFileOpWindowsRegisterServerComplete() FARPROC DllReg; HINSTANCE hLib; - nsXPIDLCString file; - mTarget->GetPath(getter_Copies(file)); - if(file) + nsCAutoString file; + 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(); @@ -1504,11 +1495,11 @@ nsInstallFileOpItem::NativeFileOpWindowsRegisterServerAbort() FARPROC DllUnReg; HINSTANCE hLib; - nsXPIDLCString file; - mTarget->GetPath(getter_Copies(file)); - if(file) + nsCAutoString file; + 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 00a313a8ed7..83f43bcc759 100644 --- a/mozilla/xpinstall/src/nsInstallFolder.cpp +++ b/mozilla/xpinstall/src/nsInstallFolder.cpp @@ -32,6 +32,7 @@ #include "nsString.h" #include "nsXPIDLString.h" +#include "nsDependentString.h" #include "nsFileSpec.h" #include "nsIFileSpec.h" #include "nsIFile.h" @@ -159,14 +160,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); @@ -203,7 +204,7 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe rv = nsSoftwareUpdate::GetProgramDirectory()->Clone(getter_AddRefs(mFileSpec)); if (NS_SUCCEEDED(rv)) - mFileSpec->Append(INSTALL_PLUGINS_DIR); + mFileSpec->AppendNative(INSTALL_PLUGINS_DIR); else mFileSpec = nsnull; } @@ -292,7 +293,7 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe rv = nsSoftwareUpdate::GetProgramDirectory()->Clone(getter_AddRefs(mFileSpec)); if (NS_SUCCEEDED(rv)) - mFileSpec->Append(INSTALL_COMPONENTS_DIR); + mFileSpec->AppendNative(INSTALL_COMPONENTS_DIR); else mFileSpec = nsnull; } @@ -310,7 +311,7 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe rv = nsSoftwareUpdate::GetProgramDirectory()->Clone(getter_AddRefs(mFileSpec)); if (NS_SUCCEEDED(rv)) - mFileSpec->Append(INSTALL_CHROME_DIR); + mFileSpec->AppendNative(INSTALL_CHROME_DIR); } break; @@ -402,7 +403,7 @@ nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRe if ( result == ERROR_SUCCESS && type == REG_SZ ) { nsCOMPtr tmp; - NS_NewLocalFile( (char*)path, PR_FALSE, getter_AddRefs(tmp) ); // native path + NS_NewNativeLocalFile( nsDependentCString((const char*) path), PR_FALSE, getter_AddRefs(tmp) ); // native path mFileSpec = do_QueryInterface(tmp); } } @@ -532,19 +533,14 @@ nsInstallFolder::AppendXPPath(const nsString& aRelativePath) aRelativePath.Mid(segment,start,curr-start); start = curr+1; } -// remove dependency on libuconv on unix. -#ifndef XP_UNIX - nsresult rv = mFileSpec->AppendUnicode(segment.get()); + nsresult rv = mFileSpec->Append(segment); if (NS_FAILED(rv)) { // Unicode converters not present (likely wizard case) // so do our best with the vanilla conversion. NS_WARNING("nsInstallFolder: unicode conversion failed"); - mFileSpec->Append(NS_LossyConvertUCS2toASCII(segment).get()); + mFileSpec->AppendNative(NS_LossyConvertUCS2toASCII(segment)); } -#else - mFileSpec->Append(NS_LossyConvertUCS2toASCII(segment).get()); -#endif } while ( start < aRelativePath.Length() ); } @@ -588,16 +584,8 @@ nsInstallFolder::ToString(nsAutoString* outString) if (!mFileSpec || !outString) return NS_ERROR_NULL_POINTER; - nsXPIDLString tempUC; - -// remove dependency on libuconv on unix. -#ifndef XP_UNIX - nsresult rv = mFileSpec->GetUnicodePath(getter_Copies(tempUC)); - if (NS_SUCCEEDED(rv)) - { - outString->Assign(tempUC); - } - else + nsresult rv = mFileSpec->GetPath(*outString); + if (NS_FAILED(rv)) { // converters not present, most likely in wizard case; // do best we can with stock ASCII conversion @@ -607,15 +595,10 @@ 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!!! NS_WARNING("Couldn't get Unicode path, using broken conversion!"); - nsXPIDLCString temp; - rv = mFileSpec->GetPath(getter_Copies(temp)); + nsCAutoString temp; + rv = mFileSpec->GetNativePath(temp); outString->Assign(NS_ConvertASCIItoUCS2(temp)); } -#else - nsXPIDLCString temp; - nsresult rv = mFileSpec->GetPath(getter_Copies(temp)); - outString->Assign(NS_ConvertASCIItoUCS2(temp)); -#endif PRBool flagIsFile = PR_FALSE; mFileSpec->IsFile(&flagIsFile); diff --git a/mozilla/xpinstall/src/nsInstallFolder.h b/mozilla/xpinstall/src/nsInstallFolder.h index 5b9a11a5b20..eefbfbf68af 100644 --- a/mozilla/xpinstall/src/nsInstallFolder.h +++ b/mozilla/xpinstall/src/nsInstallFolder.h @@ -76,13 +76,13 @@ #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 0c7511e9a90..d0dbc887f39 100644 --- a/mozilla/xpinstall/src/nsInstallPatch.cpp +++ b/mozilla/xpinstall/src/nsInstallPatch.cpp @@ -42,6 +42,7 @@ #include "nsInstallPatch.h" #include "nsInstallResources.h" #include "nsIDOMInstallVersion.h" +#include "nsILocalFile.h" #include "gdiff.h" @@ -105,7 +106,7 @@ nsInstallPatch::nsInstallPatch( nsInstall* inInstall, } nsCOMPtr tmp; - NS_NewLocalFile((char*)tempTargetFile, PR_TRUE, getter_AddRefs(tmp)); + NS_NewNativeLocalFile(nsDependentCString(tempTargetFile), PR_TRUE, getter_AddRefs(tmp)); mPatchFile = nsnull; mTargetFile = nsnull; @@ -173,7 +174,7 @@ nsInstallPatch::nsInstallPatch( nsInstall* inInstall, mVersionInfo->Init(inVInfo); if(! inPartialPath.IsEmpty()) - mTargetFile->AppendUnicode(inPartialPath.get()); + mTargetFile->Append(inPartialPath); } nsInstallPatch::~nsInstallPatch() @@ -316,9 +317,9 @@ 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 @@ -372,9 +373,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); } } @@ -409,9 +410,9 @@ nsInstallPatch::NativePatch(nsIFile *sourceFile, nsIFile *patchFile, nsIFile **n nsCOMPtr tempSrcFile; nsCOMPtr uniqueSrcFile; nsCOMPtr patchFileLocal = do_QueryInterface(patchFile, &rv); - - char* realfile; - sourceFile->GetPath(&realfile); + + nsCAutoString realfile; + sourceFile->GetNativePath(realfile); sourceFile->Clone(getter_AddRefs(outFileSpec)); @@ -445,48 +446,48 @@ nsInstallPatch::NativePatch(nsIFile *sourceFile, nsIFile *patchFile, nsIFile **n if (( dd->bWin32BoundImage || dd->bMacAppleSingle) && (status == GDIFF_OK )) { // make an unique tmp file (FILENAME-src.EXT) - nsXPIDLString leafName; - rv = sourceFile->GetUnicodeLeafName(getter_Copies(leafName)); - nsString tmpFileName(leafName); + nsAutoString tmpFileName; + rv = sourceFile->GetLeafName(tmpFileName); + + NS_NAMED_LITERAL_STRING(tmpName, "-src"); PRInt32 i; if ((i = tmpFileName.RFindChar('.')) > 0) { - nsString ext; - nsString fName; - tmpFileName.Right(ext, (tmpFileName.Length() - i) ); + nsAutoString ext; + nsAutoString fName; + tmpFileName.Right(ext, (tmpFileName.Length() - i) ); tmpFileName.Left(fName, (tmpFileName.Length() - (tmpFileName.Length() - i))); - tmpFileName = fName + NS_LITERAL_STRING("-src") + ext; + tmpFileName.Assign(fName + tmpName + ext); } else { - tmpFileName += NS_LITERAL_STRING("-src"); + tmpFileName += NS_LITERAL_STRING("-src"); } rv = sourceFile->Clone(getter_AddRefs(tempSrcFile)); //Clone the sourceFile - tempSrcFile->SetUnicodeLeafName(tmpFileName.get()); //Append the new leafname + tempSrcFile->SetLeafName(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->GetNativePath(realfile); #ifdef WIN32 // unbind Win32 images - char* unboundFile; - uniqueSrcFile->GetPath(&unboundFile); + nsCAutoString unboundFile; + uniqueSrcFile->GetNativePath(unboundFile); - if (su_unbind(realfile, unboundFile)) // + if (su_unbind((char*)realfile.get(), (char*)unboundFile.get())) // { - PL_strfree(realfile); - realfile = PL_strdup(unboundFile); + realfile = unboundFile; } else { status = GDIFF_ERR_MEM; } - PL_strfree(unboundFile); + unboundFile.Truncate(); #endif #ifdef XP_MAC // Encode src file, and put into temp file @@ -500,8 +501,7 @@ nsInstallPatch::NativePatch(nsIFile *sourceFile, nsIFile *patchFile, nsIFile **n if (status == noErr) { // set - PL_strfree(realfile); - tempSrcFile->GetPath(&realfile); + tempSrcFile->GetNativePath(realfile); } #endif } @@ -510,17 +510,16 @@ 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")); - nsXPIDLString leafName; - sourceFile->GetUnicodeLeafName(getter_Copies(leafName)); - nsString newFileName(leafName); + NS_NAMED_LITERAL_STRING(patchFileName, "-ptch"); + nsAutoString newFileName; + sourceFile->GetLeafName(newFileName); PRInt32 index; if ((index = newFileName.RFindChar('.')) > 0) { - nsString extention; - nsString fileName; - newFileName.Right(extention, (newFileName.Length() - index) ); + nsAutoString extention; + nsAutoString fileName; + newFileName.Right(extention, (newFileName.Length() - index) ); newFileName.Left(fileName, (newFileName.Length() - (newFileName.Length() - index))); newFileName = fileName + patchFileName + extention; @@ -531,8 +530,8 @@ nsInstallPatch::NativePatch(nsIFile *sourceFile, nsIFile *patchFile, nsIFile **n } - outFileSpec->SetUnicodeLeafName(newFileName.get()); //Set new leafname - nsCOMPtr outFileLocal = do_QueryInterface(outFileSpec, &rv); //Create an nsILocalFile version + outFileSpec->SetLeafName(newFileName); //Set new leafname + nsCOMPtr outFileLocal = do_QueryInterface(outFileSpec, &rv); //Create an nsILocalFile version //to send to MakeUnique() MakeUnique(outFileLocal); @@ -540,7 +539,7 @@ nsInstallPatch::NativePatch(nsIFile *sourceFile, nsIFile *patchFile, nsIFile **n //dd->fSrc = PR_Open ( realfile, PR_RDONLY, 0666); //dd->fOut = PR_Open ( outFile, PR_RDWR|PR_CREATE_FILE|PR_TRUNCATE, 0666); nsCOMPtr realFileLocal = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID);; - realFileLocal->InitWithPath(realfile); + realFileLocal->InitWithNativePath(realfile); realFileLocal->OpenNSPRFileDesc(PR_RDONLY, 0666, &dd->fSrc); outFileLocal->OpenNSPRFileDesc(PR_RDWR|PR_CREATE_FILE|PR_TRUNCATE, 0666, &dd->fOut); @@ -618,11 +617,11 @@ nsInstallPatch::NativePatch(nsIFile *sourceFile, nsIFile *patchFile, nsIFile **n outFileSpec->GetParent(getter_AddRefs(parent)); outFileSpec->Remove(PR_FALSE); - - nsXPIDLString leaf; - anotherName->GetUnicodeLeafName(getter_Copies(leaf)); - anotherName->CopyToUnicode(parent, leaf.get()); - + + nsAutoString leaf; + anotherName->GetLeafName(leaf); + anotherName->CopyTo(parent, leaf); + anotherName->Clone(newFile); } @@ -658,11 +657,6 @@ cleanup: PR_DELETE( tmpurl ); } - if (realfile != NULL) - { - PL_strfree(realfile); - } - if (tempSrcFile) { tempSrcFile->Exists(&flagExists); @@ -708,13 +702,13 @@ nsInstallPatch::HashFilePath(nsIFile* aPath) { PRUint32 rv = 0; - char* cPath; - aPath->GetPath(&cPath); - - if(cPath != nsnull) + nsCAutoString cPath; + aPath->GetNativePath(cPath); + + if (!cPath.IsEmpty()) { char ch; - char* pathIndex = cPath; + const char* pathIndex = cPath.get(); while ((ch = *pathIndex++) != 0) { @@ -723,8 +717,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 dd312241ee8..07416f8b985 100644 --- a/mozilla/xpinstall/src/nsInstallUninstall.cpp +++ b/mozilla/xpinstall/src/nsInstallUninstall.cpp @@ -30,6 +30,7 @@ #include "prmem.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); @@ -195,7 +196,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 418e5cc68bb..89bb77b3a5f 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_NewUnicodeLocalFile(b0.get(), PR_TRUE, getter_AddRefs(nsfsB0)); + NS_NewLocalFile(b0, PR_TRUE, getter_AddRefs(nsfsB0)); ConvertJSValToStr(b1, cx, argv[1]); - NS_NewUnicodeLocalFile(b1.get(), PR_TRUE, getter_AddRefs(nsfsB1)); + NS_NewLocalFile(b1, PR_TRUE, getter_AddRefs(nsfsB1)); ConvertJSValToStr(b2, cx, argv[2]); ConvertJSValToStr(b3, cx, argv[3]); - NS_NewUnicodeLocalFile(b3.get(), PR_TRUE, getter_AddRefs(nsfsB3)); + NS_NewLocalFile(b3, PR_TRUE, getter_AddRefs(nsfsB3)); ConvertJSValToStr(b4, cx, argv[4]); ConvertJSValToStr(b5, cx, argv[5]); - NS_NewUnicodeLocalFile(b5.get(), PR_TRUE, getter_AddRefs(nsfsB5)); + NS_NewLocalFile(b5, PR_TRUE, getter_AddRefs(nsfsB5)); if(JSVAL_IS_NULL(argv[6])) { @@ -1273,8 +1273,8 @@ InstallFileOpFileMacAlias(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, } ConvertJSValToStr(sourceLeaf, cx, argv[1]); - rv1 = iFileSource->AppendUnicode(sourceLeaf.get()); - + rv1 = iFileSource->Append(sourceLeaf); + // public int FileMacAlias( InstallFolder aSourceFolder, // String aSourceFileName, // InstallFolder aAliasFolder, @@ -1297,13 +1297,13 @@ InstallFileOpFileMacAlias(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, aliasLeaf = sourceLeaf; aliasLeaf.Append(NS_LITERAL_STRING(" alias")); // XXX use GetResourcedString(id) } - - rv2 = iFileAlias->AppendUnicode(aliasLeaf.get()); - if (NS_FAILED(rv1) || NS_FAILED(rv2)) - { - *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR); - return JS_TRUE; - } + + rv2 = iFileAlias->Append(aliasLeaf); + if (NS_FAILED(rv1) || NS_FAILED(rv2)) + { + *rval = INT_TO_JSVAL(nsInstall::UNEXPECTED_ERROR); + return JS_TRUE; + } if(NS_OK != nativeThis->FileOpFileMacAlias(iFileSource, iFileAlias, &nativeRet)) { diff --git a/mozilla/xpinstall/src/nsLoggingProgressNotifier.cpp b/mozilla/xpinstall/src/nsLoggingProgressNotifier.cpp index 6bc12e0d357..6556fed7128 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; @@ -316,12 +317,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 489714ce2a5..8b09030034e 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; } @@ -287,7 +285,7 @@ PRInt32 nsRegisterItem::Complete() if (NS_SUCCEEDED(rv)) { - tmp->Append(INSTALL_CHROME_DIR); + tmp->AppendNative(INSTALL_CHROME_DIR); } } nsCOMPtr startupFile( do_QueryInterface(tmp, &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->AppendNative(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 b8de298206c..a9641653eee 100644 --- a/mozilla/xpinstall/src/nsSoftwareUpdate.cpp +++ b/mozilla/xpinstall/src/nsSoftwareUpdate.cpp @@ -131,15 +131,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() ); } /***************************************/ @@ -205,7 +203,7 @@ nsSoftwareUpdate::Shutdown() nsCOMPtr tmp; rv = nsSoftwareUpdate::GetProgramDirectory()->Clone(getter_AddRefs(tmp)); #if defined (XP_MAC) - tmp->Append(ESSENTIAL_FILES); + tmp->AppendNative(ESSENTIAL_FILES); #endif pathToCleanupUtility = do_QueryInterface(tmp); @@ -220,7 +218,7 @@ nsSoftwareUpdate::Shutdown() NS_ASSERTION(pathToCleanupUtility,"No path to cleanup utility in nsSoftwareUpdate::Shutdown()"); //Create the Process framework - pathToCleanupUtility->Append(CLEANUP_UTIL); + pathToCleanupUtility->AppendNative(CLEANUP_UTIL); nsCOMPtr cleanupProcess = do_CreateInstance(kIProcessCID); rv = cleanupProcess->Init(pathToCleanupUtility); if (NS_SUCCEEDED(rv)) @@ -536,10 +534,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/nsXPInstallManager.cpp b/mozilla/xpinstall/src/nsXPInstallManager.cpp index acfea0bf9eb..d60072444a1 100644 --- a/mozilla/xpinstall/src/nsXPInstallManager.cpp +++ b/mozilla/xpinstall/src/nsXPInstallManager.cpp @@ -692,7 +692,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() ); @@ -711,7 +711,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); @@ -744,7 +744,7 @@ nsXPInstallManager::GetDestinationFile(nsString& url, nsILocalFile* *file) if (NS_SUCCEEDED(rv)) { - userChrome->AppendUnicode(leaf.get()); + userChrome->Append(leaf); MakeUnique(userChrome); *file = userChrome; NS_IF_ADDREF(*file); diff --git a/mozilla/xpinstall/stub/xpistub.cpp b/mozilla/xpinstall/stub/xpistub.cpp index e0c24dd8dd9..b615c5ed92d 100644 --- a/mozilla/xpinstall/stub/xpistub.cpp +++ b/mozilla/xpinstall/stub/xpistub.cpp @@ -118,7 +118,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); @@ -135,7 +135,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 @@ -185,7 +185,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) @@ -259,7 +259,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)