Fix for bug 110371 - remove uconv dependency from nsFileSpec by moving unicode-related routines into mailnews. sr=sspitzer, r=nhotta

This commit is contained in:
alecf%netscape.com 2001-11-19 15:28:56 +00:00
Родитель 882cf84ef2
Коммит e3acec7fba
10 изменённых файлов: 33 добавлений и 157 удалений

Просмотреть файл

@ -380,7 +380,7 @@ nsMessenger::PromptIfFileExists(nsFileSpec &fileSpec)
PRBool dialogResult = PR_FALSE;
nsXPIDLString errorMessage;
fileSpec.GetNativePathString(path);
nsMsgGetNativePathString(fileSpec.GetNativePathCString(),path);
const PRUnichar *pathFormatStrings[] = { path.get() };
NS_NAMED_LITERAL_STRING(fileExistsPropertyTag, "fileExists");
const PRUnichar *fpropertyTag = fileExistsPropertyTag.get();

Просмотреть файл

@ -56,6 +56,7 @@
#include "nsIPrompt.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIMsgLocalMailFolder.h"
#include "nsMsgI18N.h"
static NS_DEFINE_CID(kCMailDB, NS_MAILDB_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
@ -362,7 +363,7 @@ nsFolderCompactState::FinishCompact()
nsString dbName;
pathSpec->GetLeafName(getter_Copies(idlName));
summarySpec.GetLeafName(dbName);
nsMsgGetNativePathString(summarySpec.GetLeafName(), dbName);
// close down the temp file stream; preparing for deleting the old folder
// and its database; then rename the temp folder and database

Просмотреть файл

@ -760,3 +760,15 @@ nsMsgI18NGetAcceptLanguage(void)
}
// taken from nsFileSpec::GetNativePAthString()
void
nsMsgGetNativePathString(const char *aPath, nsString& aResult)
{
if (!aPath) {
aResult.Truncate();
return;
}
ConvertToUnicode(nsMsgI18NFileSystemCharset(), aPath, aResult);
}

Просмотреть файл

@ -210,4 +210,11 @@ NS_MSG_BASE nsresult nsMsgI18NSaveAsCharset(const char* contentType, const char*
*/
NS_MSG_BASE nsresult nsMsgI18NFormatNNTPXPATInNonRFC1522Format(const nsCString& aCharset, const nsString& inString, nsCString& outString);
/**
* convert a path in the native filesystem charset
*/
NS_MSG_BASE
void
nsMsgGetNativePathString(const char *aPath, nsString& aResult);
#endif /* _nsMsgI18N_H_ */

Просмотреть файл

@ -509,7 +509,7 @@ nsMsgAttachmentHandler::SnarfMsgAttachment(nsMsgCompFields *compFields)
{
nsAutoString error_msg;
nsAutoString path;
mFileSpec->GetNativePathString(path);
nsMsgGetNativePathString(mFileSpec->GetNativePathCString(),path);
nsMsgBuildErrorMessageByID(NS_MSG_UNABLE_TO_OPEN_TMP_FILE, error_msg, &path, nsnull);
sendReport->SetMessage(nsIMsgSendReport::process_Current, error_msg.get(), PR_FALSE);
}
@ -592,7 +592,7 @@ nsMsgAttachmentHandler::SnarfAttachment(nsMsgCompFields *compFields)
{
nsAutoString error_msg;
nsAutoString path;
mFileSpec->GetNativePathString(path);
nsMsgGetNativePathString(mFileSpec->GetNativePathCString(),path);
nsMsgBuildErrorMessageByID(NS_MSG_UNABLE_TO_OPEN_TMP_FILE, error_msg, &path, nsnull);
sendReport->SetMessage(nsIMsgSendReport::process_Current, error_msg.get(), PR_FALSE);
}

Просмотреть файл

@ -594,7 +594,7 @@ nsMsgComposeAndSend::GatherMimeAttachments()
{
nsAutoString error_msg;
nsAutoString path;
mHTMLFileSpec->GetNativePathString(path);
nsMsgGetNativePathString(mHTMLFileSpec->GetNativePathCString(),path);
nsMsgBuildErrorMessageByID(NS_MSG_UNABLE_TO_OPEN_TMP_FILE, error_msg, &path, nsnull);
mSendReport->SetMessage(nsIMsgSendReport::process_Current, error_msg.get(), PR_FALSE);
}
@ -679,7 +679,7 @@ nsMsgComposeAndSend::GatherMimeAttachments()
{
nsAutoString error_msg;
nsAutoString path;
mTempFileSpec->GetNativePathString(path);
nsMsgGetNativePathString(mTempFileSpec->GetNativePathCString(),path);
nsMsgBuildErrorMessageByID(NS_MSG_UNABLE_TO_OPEN_TMP_FILE, error_msg, &path, nsnull);
mSendReport->SetMessage(nsIMsgSendReport::process_Current, error_msg.get(), PR_FALSE);
}
@ -3956,7 +3956,7 @@ nsMsgComposeAndSend::MimeDoFCC(nsFileSpec *input_file,
{
nsAutoString error_msg;
nsAutoString path;
tFileSpec->GetNativePathString(path);
nsMsgGetNativePathString(tFileSpec->GetNativePathCString(),path);
nsMsgBuildErrorMessageByID(NS_MSG_UNABLE_TO_OPEN_TMP_FILE, error_msg, &path, nsnull);
mSendReport->SetMessage(nsIMsgSendReport::process_Current, error_msg.get(), PR_FALSE);
}
@ -3976,7 +3976,7 @@ nsMsgComposeAndSend::MimeDoFCC(nsFileSpec *input_file,
{
nsAutoString error_msg;
nsAutoString path;
input_file->GetNativePathString(path);
nsMsgGetNativePathString(input_file->GetNativePathCString(),path);
nsMsgBuildErrorMessageByID(NS_MSG_UNABLE_TO_OPEN_FILE, error_msg, &path, nsnull);
mSendReport->SetMessage(nsIMsgSendReport::process_Current, error_msg.get(), PR_FALSE);
}

Просмотреть файл

@ -662,7 +662,7 @@ nsMsgSendPart::Write()
{
nsAutoString error_msg;
nsAutoString path;
m_filespec->GetNativePathString(path);
nsMsgGetNativePathString(m_filespec->GetNativePathCString(),path);
nsMsgBuildErrorMessageByID(NS_MSG_UNABLE_TO_OPEN_TMP_FILE, error_msg, &path, nsnull);
sendReport->SetMessage(nsIMsgSendReport::process_Current, error_msg.get(), PR_FALSE);
}

Просмотреть файл

@ -234,7 +234,7 @@ nsMsgLocalMailFolder::CreateSubFolders(nsFileSpec &path)
for (nsDirectoryIterator dir(path, PR_FALSE); dir.Exists(); dir++) {
nsFileSpec currentFolderPath = dir.Spec();
currentFolderPath.GetLeafName(currentFolderNameStr);
nsMsgGetNativePathString(currentFolderPath.GetLeafName(),currentFolderNameStr);
if (nsShouldIgnoreFile(currentFolderNameStr))
continue;
@ -414,7 +414,7 @@ nsMsgLocalMailFolder::AddDirectorySeparator(nsFileSpec &path)
// here because of the way nsFileSpec concatenates
nsAutoString str;
path.GetNativePathString(str);
nsMsgGetNativePathString(path.GetNativePathCString(), str);
str.Append(sep);
path = str;
@ -771,7 +771,7 @@ nsMsgLocalMailFolder::CheckIfFolderExists(const PRUnichar *folderName, nsFileSpe
for (nsDirectoryIterator dir(path, PR_FALSE); dir.Exists(); dir++)
{
nsFileSpec currentFolderPath = dir.Spec();
currentFolderPath.GetLeafName(leafName);
nsMsgGetNativePathString(currentFolderPath.GetLeafName(),leafName);
if (!leafName.IsEmpty() &&
Compare(nsDependentString(folderName), leafName,
nsCaseInsensitiveStringComparator()) == 0)
@ -1237,7 +1237,7 @@ NS_IMETHODIMP nsMsgLocalMailFolder::Rename(const PRUnichar *aNewName, nsIMsgWind
nsCAutoString newNameStr(convertedNewName.get());
nsXPIDLCString oldLeafName;
oldPathSpec->GetLeafName(getter_Copies(oldLeafName));
oldPathSpec->GetLeafName(getter_Copies(oldLeafName));
if (PL_strcasecmp(oldLeafName, convertedNewName) == 0) {
if(msgWindow)

Просмотреть файл

@ -49,11 +49,6 @@
#include "nsCOMPtr.h"
#include "nsIServiceManager.h"
#define NS_IMPL_IDS
#ifndef XPCOM_STANDALONE
#include "nsIPlatformCharset.h"
#include "nsICharsetConverterManager.h"
#include "nsIUnicodeDecoder.h"
#endif /* XPCOM_STANDALONE */
#include <string.h>
#include <stdio.h>
@ -845,10 +840,6 @@ nsFilePath nsFilePath::operator +(const char* inRelativeUnixPath) const
// nsFileSpec implementation
//========================================================================================
#ifndef XPCOM_STANDALONE
static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
#endif /* XPCOM_STANDALONE */
#if !defined(XP_MAC)
//----------------------------------------------------------------------------------------
nsFileSpec::nsFileSpec()
@ -1164,118 +1155,6 @@ PRBool nsFileSpec::IsChildOf(nsFileSpec &possibleParent)
// not reached, but I bet some compiler will whine
return PR_FALSE;
}
//----------------------------------------------------------------------------------------
void nsFileSpec::GetFileSystemCharset(nsString & fileSystemCharset)
//----------------------------------------------------------------------------------------
{
#ifndef XPCOM_STANDALONE
// From mozilla/widget/src/windows/nsFileWidget.cpp
static nsAutoString aCharset;
nsresult rv;
if (aCharset.Length() < 1) {
nsCOMPtr <nsIPlatformCharset> platformCharset = do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv))
rv = platformCharset->GetCharset(kPlatformCharsetSel_FileName, aCharset);
NS_ASSERTION(NS_SUCCEEDED(rv), "error getting platform charset");
if (NS_FAILED(rv))
aCharset.AssignWithConversion("ISO-8859-1");
}
fileSystemCharset = aCharset;
#endif /* XPCOM_STANDALONE */
}
//----------------------------------------------------------------------------------------
PRUnichar * nsFileSpec::ConvertFromFileSystemCharset(const char *inString)
//----------------------------------------------------------------------------------------
{
nsresult rv = NS_ERROR_NOT_IMPLEMENTED;
PRUnichar *outString = nsnull;
#ifndef XPCOM_STANDALONE
// From mozilla/widget/src/windows/nsFileWidget.cpp
nsIUnicodeDecoder *aUnicodeDecoder = nsnull;
rv = NS_OK;
// get file system charset and create a unicode encoder
nsAutoString fileSystemCharset;
GetFileSystemCharset(fileSystemCharset);
nsCOMPtr<nsICharsetConverterManager> ccm =
do_GetService(kCharsetConverterManagerCID, &rv);
if (NS_SUCCEEDED(rv)) {
rv = ccm->GetUnicodeDecoder(&fileSystemCharset, &aUnicodeDecoder);
}
// converts from the file system charset to unicode
if (NS_SUCCEEDED(rv)) {
PRInt32 inLength = nsCRT::strlen(inString);
PRInt32 outLength;
rv = aUnicodeDecoder->GetMaxLength(inString, inLength, &outLength);
if (NS_SUCCEEDED(rv)) {
outString = new PRUnichar[outLength+1];
if (nsnull == outString) {
return nsnull;
}
rv = aUnicodeDecoder->Convert(inString, &inLength, outString, &outLength);
if (NS_SUCCEEDED(rv)) {
outString[outLength] = 0;
}
}
}
NS_IF_RELEASE(aUnicodeDecoder);
#endif /* XPCOM_STANDALONE */
return NS_SUCCEEDED(rv) ? outString : nsnull;
}
//----------------------------------------------------------------------------------------
void nsFileSpec::GetNativePathString(nsString &nativePathString)
//----------------------------------------------------------------------------------------
{
const char *path = GetCString();
if (nsnull == path) {
nativePathString.SetLength(0);
return;
}
else {
PRUnichar *converted = ConvertFromFileSystemCharset(path);
if (nsnull != converted) {
nativePathString.Assign(converted);
delete [] converted;
}
else
nativePathString.AssignWithConversion(path);
}
}
//----------------------------------------------------------------------------------------
void nsFileSpec::GetLeafName(nsString &nativePathString)
//----------------------------------------------------------------------------------------
{
char * path = GetLeafName();
if (nsnull == path) {
nativePathString.SetLength(0);
return;
} else {
PRUnichar *converted = ConvertFromFileSystemCharset(path);
if (nsnull != converted) {
nativePathString.Assign(converted);
delete [] converted;
}
else
nativePathString.AssignWithConversion(path);
nsCRT::free(path);
}
}
#ifdef XP_MAC
#pragma mark -
#endif

Просмотреть файл

@ -365,10 +365,6 @@ class NS_COM nsFileSpec
// Do not try to free this!
const char* GetNativePathCString() const { return GetCString(); }
// Returns a path in unicode
// converted from a file system charset.
void GetNativePathString(nsString &nativePathString);
PRBool IsChildOf(nsFileSpec &possibleParent);
#if defined(XP_MAC)
@ -420,17 +416,6 @@ class NS_COM nsFileSpec
//--------------------------------------------------
char* GetLeafName() const; // Allocated. Use nsCRT::free().
// Unicode version of GetLeafName()
void GetLeafName(nsString &nativePathString);
#if 0
// needs implementing
// copy the leaf name into the supplied buffer, thus
// getting a copy without allocation. Buffer should be
// 64 chars big.
void GetLeafNameCopy(char* destBuffer, PRInt32 bufferSize) const;
#endif
// inLeafName can be a relative path, so this allows
// one kind of concatenation of "paths".
void SetLeafName(const char* inLeafName);
@ -519,16 +504,8 @@ class NS_COM nsFileSpec
nsresult Execute(const char* args) const;
nsresult Execute(const nsString& args) const;
// Internal routine
//--------------------------------------------------
// Convert's routine from Native charset to Unicode.
protected:
// use delete [] to free the returned buffer
PRUnichar* ConvertFromFileSystemCharset(const char *inString);
static void GetFileSystemCharset(nsString & fileSystemCharset);
//--------------------------------------------------
// Data
//--------------------------------------------------