Converted nsIFileLocator to nsIDirectoryService.

This commit is contained in:
ccarlen%netscape.com 2000-08-21 23:43:48 +00:00
Родитель 83b5cd5439
Коммит 1dc6fc3dd3
13 изменённых файлов: 442 добавлений и 244 удалений

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

@ -25,17 +25,15 @@
#include "nsAddrBookSession.h"
#include "nsIAddrBookSession.h"
#include "nsIFileSpec.h"
#include "nsIFileLocator.h"
#include "nsFileLocations.h"
static NS_DEFINE_CID(kFileLocatorCID, NS_FILELOCATOR_CID);
#include "nsIDirectoryService.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsXPIDLString.h"
NS_IMPL_THREADSAFE_ISUPPORTS(nsAddrBookSession, NS_GET_IID(nsIAddrBookSession));
nsAddrBookSession::nsAddrBookSession():
mRefCnt(0), mpUserDirectory(nsnull)
mRefCnt(0)
{
NS_INIT_REFCNT();
@ -46,8 +44,6 @@ nsAddrBookSession::~nsAddrBookSession()
{
if (mListeners)
delete mListeners;
if (mpUserDirectory)
delete mpUserDirectory;
}
@ -55,12 +51,14 @@ nsAddrBookSession::~nsAddrBookSession()
NS_IMETHODIMP nsAddrBookSession::AddAddressBookListener(nsIAbListener * listener)
{
NS_ENSURE_TRUE(mListeners, NS_ERROR_NULL_POINTER);
mListeners->AppendElement(listener);
return NS_OK;
}
NS_IMETHODIMP nsAddrBookSession::RemoveAddressBookListener(nsIAbListener * listener)
{
NS_ENSURE_TRUE(mListeners, NS_ERROR_NULL_POINTER);
mListeners->RemoveElement(listener);
return NS_OK;
}
@ -68,6 +66,8 @@ NS_IMETHODIMP nsAddrBookSession::RemoveAddressBookListener(nsIAbListener * liste
NS_IMETHODIMP nsAddrBookSession::NotifyItemPropertyChanged
(nsISupports *item, const char *property, const PRUnichar* oldValue, const PRUnichar* newValue)
{
NS_ENSURE_TRUE(mListeners, NS_ERROR_NULL_POINTER);
PRInt32 i;
PRInt32 count = mListeners->Count();
for(i = 0; i < count; i++)
@ -82,6 +82,8 @@ NS_IMETHODIMP nsAddrBookSession::NotifyItemPropertyChanged
NS_IMETHODIMP nsAddrBookSession::NotifyDirectoryItemAdded(nsIAbDirectory *directory, nsISupports *item)
{
NS_ENSURE_TRUE(mListeners, NS_ERROR_NULL_POINTER);
PRInt32 i;
PRInt32 count = mListeners->Count();
for(i = 0; i < count; i++)
@ -96,6 +98,8 @@ NS_IMETHODIMP nsAddrBookSession::NotifyDirectoryItemAdded(nsIAbDirectory *direct
NS_IMETHODIMP nsAddrBookSession::NotifyDirectoryItemDeleted(nsIAbDirectory *directory, nsISupports *item)
{
NS_ENSURE_TRUE(mListeners, NS_ERROR_NULL_POINTER);
PRInt32 i;
PRInt32 count = mListeners->Count();
for(i = 0; i < count; i++)
@ -109,21 +113,21 @@ NS_IMETHODIMP nsAddrBookSession::NotifyDirectoryItemDeleted(nsIAbDirectory *dire
NS_IMETHODIMP nsAddrBookSession::GetUserProfileDirectory(nsFileSpec * *userDir)
{
nsresult rv = NS_OK;
if (!mpUserDirectory)
mpUserDirectory = new nsFileSpec();
NS_ENSURE_ARG_POINTER(userDir);
*userDir = nsnull;
NS_WITH_SERVICE(nsIFileLocator, locator, kFileLocatorCID, &rv);
if (NS_FAILED(rv))
return rv;
nsresult rv;
nsCOMPtr<nsIFile> profileDir;
nsXPIDLCString pathBuf;
rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(profileDir));
if (NS_FAILED(rv)) return rv;
rv = profileDir->GetPath(getter_Copies(pathBuf));
if (NS_FAILED(rv)) return rv;
*userDir = new nsFileSpec(pathBuf);
NS_ENSURE_TRUE(*userDir, NS_ERROR_OUT_OF_MEMORY);
nsCOMPtr <nsIFileSpec> profiledir;
rv = locator->GetFileLocation(nsSpecialFileSpec::App_UserProfileDirectory50, getter_AddRefs(profiledir));
if (NS_FAILED(rv))
return rv;
profiledir->GetFileSpec(mpUserDirectory);
*userDir = mpUserDirectory;
return rv;
}

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

@ -39,7 +39,6 @@ public:
protected:
nsVoidArray *mListeners;
nsFileSpec *mpUserDirectory;
};

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

@ -40,8 +40,6 @@
#include "nsIRDFService.h"
#include "nsRDFCID.h"
#include "nsIServiceManager.h"
#include "nsIFileLocator.h"
#include "nsFileLocations.h"
#include "nsAppShellCIDs.h"
#include "nsIAppShellService.h"
#include "nsIDOMWindow.h"
@ -56,7 +54,6 @@
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_IID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID);
static NS_DEFINE_CID(kAddressBookDBCID, NS_ADDRDATABASE_CID);
static NS_DEFINE_CID(kFileLocatorCID, NS_FILELOCATOR_CID);
static NS_DEFINE_CID(kAddrBookSessionCID, NS_ADDRBOOKSESSION_CID);
static NS_DEFINE_CID(kAbDirectoryCID, NS_ABDIRECTORY_CID);
static NS_DEFINE_CID(kAbCardPropertyCID, NS_ABCARDPROPERTY_CID);

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

@ -427,10 +427,6 @@ nsresult DIR_ShutDown() /* FEs should call this when the app is shutting down.
return NS_OK;
}
#include "nsIFileSpec.h"
#include "nsIFileLocator.h"
#include "nsFileLocations.h"
static NS_DEFINE_CID(kFileLocatorCID, NS_FILELOCATOR_CID);
static NS_DEFINE_CID(kAddressBookDBCID, NS_ADDRDATABASE_CID);
nsresult DIR_ContainsServer(DIR_Server* pServer, PRBool *hasDir)

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

@ -33,11 +33,11 @@
#include "nsXPIDLString.h"
#include "nscore.h"
#include "nsIFileLocator.h"
#include "nsFileLocations.h"
#include "nsCRT.h" // for nsCRT::strtok
#include "nsFileStream.h"
#include "nsSpecialSystemDirectory.h"
#include "nsIDirectoryService.h"
#include "nsDirectoryServiceDefs.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsIFileSpec.h"
#include "nsIURL.h"
#include "nsIStringBundle.h"
@ -83,7 +83,6 @@ static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
static NS_DEFINE_CID(kProfileCID, NS_PROFILE_CID);
static NS_DEFINE_CID(kStandardUrlCID, NS_STANDARDURL_CID);
static NS_DEFINE_CID(kSmtpServiceCID, NS_SMTPSERVICE_CID);
static NS_DEFINE_CID(kFileLocatorCID, NS_FILELOCATOR_CID);
static NS_DEFINE_CID(kMsgAccountManagerCID, NS_MSGACCOUNTMANAGER_CID);
static NS_DEFINE_CID(kAB4xUpgraderServiceCID, NS_AB4xUPGRADER_CID);
static NS_DEFINE_CID(kAddressBookCID, NS_ADDRESSBOOK_CID);
@ -516,7 +515,7 @@ nsMessengerMigrator::CreateLocalMailAccount(PRBool migrating)
// create the directory structure for old 4.x "Local Mail"
// under <profile dir>/Mail/Local Folders or
// <"mail.directory" pref>/Local Folders
nsCOMPtr <nsIFileSpec> mailDir;
nsCOMPtr <nsIFile> mailDir;
nsFileSpec dir;
PRBool dirExists;
@ -525,29 +524,41 @@ nsMessengerMigrator::CreateLocalMailAccount(PRBool migrating)
// this only makes sense when we are migrating
// for a new profile, that pref won't be set.
if (migrating) {
rv = m_prefs->GetFilePref(PREF_MAIL_DIRECTORY, getter_AddRefs(mailDir));
}
else {
rv = NS_ERROR_FAILURE;
nsCOMPtr<nsILocalFile> localFile;
rv = m_prefs->GetFileXPref(PREF_MAIL_DIRECTORY, getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv))
mailDir = localFile;
}
if (NS_FAILED(rv)) {
if (!mailDir) {
// we want <profile>/Mail
NS_WITH_SERVICE(nsIFileLocator, locator, kFileLocatorCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = locator->GetFileLocation(nsSpecialFileSpec::App_MailDirectory50, getter_AddRefs(mailDir));
rv = NS_GetSpecialDirectory(NS_APP_MAIL_50_DIR, getter_AddRefs(mailDir));
if (NS_FAILED(rv)) return rv;
}
// set the default local path for "none"
rv = server->SetDefaultLocalPath(mailDir);
rv = mailDir->Exists(&dirExists);
if (NS_SUCCEEDED(rv) && !dirExists)
rv = mailDir->Create(nsIFile::DIRECTORY_TYPE, 0775);
if (NS_FAILED(rv)) return rv;
nsXPIDLCString descString;
nsCOMPtr<nsIFileSpec> mailDirSpec;
// 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));
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;
rv = mailDir->Exists(&dirExists);
if (!dirExists) {
mailDir->CreateDir();
}
// set the default local path for "none"
rv = server->SetDefaultLocalPath(mailDirSpec);
if (NS_FAILED(rv)) return rv;
if (migrating) {
// set the local path for this "none" server
@ -556,14 +567,14 @@ nsMessengerMigrator::CreateLocalMailAccount(PRBool migrating)
// the 4.x "Local Mail" (when using imap) got copied.
// it would be great to use the server key, but we don't know it
// when we are copying of the mail.
rv = mailDir->AppendRelativeUnixPath((const char *)mLocalFoldersHostname);
rv = mailDirSpec->AppendRelativeUnixPath((const char *)mLocalFoldersHostname);
if (NS_FAILED(rv)) return rv;
rv = server->SetLocalPath(mailDir);
rv = server->SetLocalPath(mailDirSpec);
if (NS_FAILED(rv)) return rv;
rv = mailDir->Exists(&dirExists);
rv = mailDirSpec->Exists(&dirExists);
if (!dirExists) {
mailDir->CreateDir();
mailDirSpec->CreateDir();
}
}
return NS_OK;
@ -1083,30 +1094,44 @@ nsMessengerMigrator::MigrateLocalMailAccount()
// create the directory structure for old 4.x "Local Mail"
// under <profile dir>/Mail/Local Folders or
// <"mail.directory" pref>/Local Folders
nsCOMPtr <nsIFileSpec> mailDir;
nsCOMPtr<nsIFile> mailDir;
nsFileSpec dir;
PRBool dirExists;
// if the "mail.directory" pref is set, use that.
// if they used -installer, this pref will point to where their files got copied
rv = m_prefs->GetFilePref(PREF_MAIL_DIRECTORY, getter_AddRefs(mailDir));
if (NS_FAILED(rv)) {
nsCOMPtr<nsILocalFile> localFile;
rv = m_prefs->GetFileXPref(PREF_MAIL_DIRECTORY, getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv))
mailDir = localFile;
if (!mailDir) {
// we want <profile>/Mail
NS_WITH_SERVICE(nsIFileLocator, locator, kFileLocatorCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = locator->GetFileLocation(nsSpecialFileSpec::App_MailDirectory50, getter_AddRefs(mailDir));
rv = NS_GetSpecialDirectory(NS_APP_MAIL_50_DIR, getter_AddRefs(mailDir));
if (NS_FAILED(rv)) return rv;
}
// set the default local path for "none"
rv = server->SetDefaultLocalPath(mailDir);
rv = mailDir->Exists(&dirExists);
if (NS_SUCCEEDED(rv) && !dirExists)
rv = mailDir->Create(nsIFile::DIRECTORY_TYPE, 0775);
if (NS_FAILED(rv)) return rv;
nsXPIDLCString mailDirPath;
nsCOMPtr<nsIFileSpec> 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);
if (NS_FAILED(rv)) return rv;
rv = mailDir->Exists(&dirExists);
if (!dirExists) {
mailDir->CreateDir();
}
// set the default local path for "none"
rv = server->SetDefaultLocalPath(mailDirSpec);
if (NS_FAILED(rv)) return rv;
// set the local path for this "none" server
//
@ -1114,14 +1139,14 @@ nsMessengerMigrator::MigrateLocalMailAccount()
// the 4.x "Local Mail" (when using imap) got copied.
// it would be great to use the server key, but we don't know it
// when we are copying of the mail.
rv = mailDir->AppendRelativeUnixPath((const char *)mLocalFoldersHostname);
rv = mailDirSpec->AppendRelativeUnixPath((const char *)mLocalFoldersHostname);
if (NS_FAILED(rv)) return rv;
rv = server->SetLocalPath(mailDir);
rv = server->SetLocalPath(mailDirSpec);
if (NS_FAILED(rv)) return rv;
rv = mailDir->Exists(&dirExists);
rv = mailDirSpec->Exists(&dirExists);
if (!dirExists) {
mailDir->CreateDir();
mailDirSpec->CreateDir();
}
// pass the "Local Folders" server so the send later uri pref
@ -1134,7 +1159,7 @@ nsMessengerMigrator::MigrateLocalMailAccount()
noneServer = do_QueryInterface(server, &rv);
if (NS_FAILED(rv)) return rv;
if (!noneServer) return NS_ERROR_FAILURE;
rv = noneServer->CopyDefaultMessages("Templates",mailDir);
rv = noneServer->CopyDefaultMessages("Templates",mailDirSpec);
if (NS_FAILED(rv)) return rv;
return NS_OK;
@ -1202,10 +1227,16 @@ nsMessengerMigrator::MigrateMovemailAccount(nsIMsgIdentity *identity)
// if the "mail.directory" pref is set, use that.
if (NS_FAILED(rv)) {
// we wan't <profile>/Mail
NS_WITH_SERVICE(nsIFileLocator, locator, kFileLocatorCID, &rv);
nsCOMPtr<nsIFile> aFile;
nsXPIDLCString pathBuf;
rv = NS_GetSpecialDirectory(NS_APP_MAIL_50_DIR, getter_AddRefs(aFile));
if (NS_FAILED(rv)) return rv;
rv = locator->GetFileLocation(nsSpecialFileSpec::App_MailDirectory50, getter_AddRefs(mailDir));
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);
if (NS_FAILED(rv)) return rv;
}
@ -1311,7 +1342,7 @@ nsMessengerMigrator::MigratePopAccount(nsIMsgIdentity *identity)
if (NS_FAILED(rv)) return rv;
// now upgrade all the prefs
nsCOMPtr <nsIFileSpec> mailDir;
nsCOMPtr <nsIFile> mailDir;
nsFileSpec dir;
PRBool dirExists;
@ -1325,42 +1356,61 @@ nsMessengerMigrator::MigratePopAccount(nsIMsgIdentity *identity)
rv = MigrateOldMailPrefs(server);
if (NS_FAILED(rv)) return rv;
// if they used -installer, this pref will point to where their files got copied
rv = m_prefs->GetFilePref(PREF_MAIL_DIRECTORY, getter_AddRefs(mailDir));
// create the directory structure for old 4.x pop mail
// under <profile dir>/Mail/<pop host name> or
// <"mail.directory" pref>/<pop host name>
//
// if the "mail.directory" pref is set, use that.
if (NS_FAILED(rv)) {
// if they used -installer, this pref will point to where their files got copied
nsCOMPtr<nsILocalFile> localFile;
rv = m_prefs->GetFileXPref(PREF_MAIL_DIRECTORY, getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv))
mailDir = localFile;
if (!mailDir) {
// we wan't <profile>/Mail
NS_WITH_SERVICE(nsIFileLocator, locator, kFileLocatorCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = locator->GetFileLocation(nsSpecialFileSpec::App_MailDirectory50, getter_AddRefs(mailDir));
rv = NS_GetSpecialDirectory(NS_APP_MAIL_50_DIR, getter_AddRefs(mailDir));
if (NS_FAILED(rv)) return rv;
}
// set the default local path for "pop3"
rv = server->SetDefaultLocalPath(mailDir);
rv = mailDir->Exists(&dirExists);
if (NS_SUCCEEDED(rv) && !dirExists)
rv = mailDir->Create(nsIFile::DIRECTORY_TYPE, 0775);
if (NS_FAILED(rv)) return rv;
nsXPIDLCString mailDirPath;
nsCOMPtr<nsIFileSpec> 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);
if (NS_FAILED(rv)) return rv;
rv = mailDir->Exists(&dirExists);
// set the default local path for "pop3"
rv = server->SetDefaultLocalPath(mailDirSpec);
if (NS_FAILED(rv)) return rv;
rv = mailDirSpec->Exists(&dirExists);
if (!dirExists) {
mailDir->CreateDir();
mailDirSpec->CreateDir();
}
// we want .../Mail/<hostname>, not .../Mail
rv = mailDir->AppendRelativeUnixPath(hostAndPort);
rv = mailDirSpec->AppendRelativeUnixPath(hostAndPort);
if (NS_FAILED(rv)) return rv;
// set the local path for this "pop3" server
rv = server->SetLocalPath(mailDir);
rv = server->SetLocalPath(mailDirSpec);
if (NS_FAILED(rv)) return rv;
rv = mailDir->Exists(&dirExists);
rv = mailDirSpec->Exists(&dirExists);
if (!dirExists) {
mailDir->CreateDir();
mailDirSpec->CreateDir();
}
// pass the pop server so the send later uri pref
@ -1555,42 +1605,61 @@ nsMessengerMigrator::MigrateImapAccount(nsIMsgIdentity *identity, const char *ho
rv = MigrateOldImapPrefs(server, hostAndPort);
if (NS_FAILED(rv)) return rv;
nsCOMPtr <nsIFileSpec> imapMailDir;
nsCOMPtr <nsIFile> imapMailDir;
nsFileSpec dir;
PRBool dirExists;
// if they used -installer, this pref will point to where their files got copied
rv = m_prefs->GetFilePref(PREF_IMAP_DIRECTORY, getter_AddRefs(imapMailDir));
// if the "mail.imap.root_dir" pref is set, use that.
if (NS_FAILED(rv)) {
nsCOMPtr<nsILocalFile> localFile;
rv = m_prefs->GetFileXPref(PREF_IMAP_DIRECTORY, getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv))
imapMailDir = localFile;
if (!imapMailDir) {
// we want <profile>/ImapMail
NS_WITH_SERVICE(nsIFileLocator, locator, kFileLocatorCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = locator->GetFileLocation(nsSpecialFileSpec::App_ImapMailDirectory50, getter_AddRefs(imapMailDir));
rv = NS_GetSpecialDirectory(NS_APP_IMAP_MAIL_50_DIR, getter_AddRefs(imapMailDir));
if (NS_FAILED(rv)) return rv;
}
rv = imapMailDir->Exists(&dirExists);
if (NS_SUCCEEDED(rv) && !dirExists)
rv = imapMailDir->Create(nsIFile::DIRECTORY_TYPE, 0775);
if (NS_FAILED(rv)) return rv;
nsXPIDLCString pathBuf;
nsCOMPtr<nsIFileSpec> 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);
if (NS_FAILED(rv)) return rv;
// we only need to do this once
if (!m_alreadySetImapDefaultLocalPath) {
// set the default local path for "imap"
rv = server->SetDefaultLocalPath(imapMailDir);
rv = server->SetDefaultLocalPath(imapMailDirSpec);
if (NS_FAILED(rv)) return rv;
m_alreadySetImapDefaultLocalPath = PR_TRUE;
}
// we want .../ImapMail/<hostname>, not .../ImapMail
rv = imapMailDir->AppendRelativeUnixPath((const char *)hostname);
rv = imapMailDirSpec->AppendRelativeUnixPath((const char *)hostname);
if (NS_FAILED(rv)) return rv;
// set the local path for this "imap" server
rv = server->SetLocalPath(imapMailDir);
rv = server->SetLocalPath(imapMailDirSpec);
if (NS_FAILED(rv)) return rv;
rv = imapMailDir->Exists(&dirExists);
rv = imapMailDirSpec->Exists(&dirExists);
if (!dirExists) {
imapMailDir->CreateDir();
imapMailDirSpec->CreateDir();
}
if (isDefaultAccount) {
@ -1712,30 +1781,48 @@ nsMessengerMigrator::migrateAddressBookPrefEnum(const char *aPref, void *aClosur
abName.SetLength(len - suffixLen);
// get 5.0 profile root.
nsCOMPtr <nsIFileSpec> ab4xFile;
nsCOMPtr <nsIFileSpec> tmpLDIFFile;
nsCOMPtr <nsIFile> ab4xFile;
nsCOMPtr <nsIFileSpec> ab4xFileSpec;
nsCOMPtr <nsIFile> tmpLDIFFile;
nsCOMPtr <nsIFileSpec> tmpLDIFFileSpec;
#ifdef DEBUG_AB_MIGRATION
printf("turn %s%s into %s%s\n", (const char *)abName,ADDRESSBOOK_PREF_VALUE_4x_SUFFIX,(const char *)abName,TEMP_LDIF_FILE_SUFFIX);
#endif /* DEBUG_AB_MIGRATION */
nsCOMPtr<nsIFileLocator> locator = do_GetService(kFileLocatorCID,&rv);
NS_ASSERTION(NS_SUCCEEDED(rv) && locator,"ab migration failed: failed to get locator");
if (NS_FAILED(rv) || !locator) return;
rv = locator->GetFileLocation(nsSpecialFileSpec::App_UserProfileDirectory50, getter_AddRefs(ab4xFile));
rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(ab4xFile));
NS_ASSERTION(NS_SUCCEEDED(rv) && ab4xFile,"ab migration failed: failed to get profile dir");
if (NS_FAILED(rv) || !ab4xFile) return;
rv = ab4xFile->AppendRelativeUnixPath((const char *)abFileName);
// 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 = ab4xFileSpec->AppendRelativeUnixPath((const char *)abFileName);
NS_ASSERTION(NS_SUCCEEDED(rv),"ab migration failed: failed to append filename");
if (NS_FAILED(rv)) return;
nsSpecialSystemDirectory file(nsSpecialSystemDirectory::OS_TemporaryDirectory);
rv = NS_NewFileSpecWithSpec(file, getter_AddRefs(tmpLDIFFile));
NS_ASSERTION(NS_SUCCEEDED(rv) && tmpLDIFFile,"ab migration failed: failed to get tmp dir");
rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(tmpLDIFFile));
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;
}
// HACK: I need to rename pab.ldif -> abook.ldif, because a bunch of places are hacked to point to abook.mab, and when I import abook.ldif it will create abook.mab. this is a temporary hack and will go away soon.
if (!PL_strcmp((const char *)abName,"pab")) {
abName = "abook";
@ -1744,7 +1831,7 @@ nsMessengerMigrator::migrateAddressBookPrefEnum(const char *aPref, void *aClosur
nsCAutoString ldifFileName;
ldifFileName = (const char *)abName;
ldifFileName += TEMP_LDIF_FILE_SUFFIX;
rv = tmpLDIFFile->AppendRelativeUnixPath((const char *)ldifFileName);
rv = tmpLDIFFileSpec->AppendRelativeUnixPath((const char *)ldifFileName);
NS_ASSERTION(NS_SUCCEEDED(rv),"ab migration failed: failed to append filename");
if (NS_FAILED(rv)) return;
@ -1752,11 +1839,11 @@ nsMessengerMigrator::migrateAddressBookPrefEnum(const char *aPref, void *aClosur
NS_ASSERTION(NS_SUCCEEDED(rv) && ab, "failed to get address book");
if (NS_FAILED(rv) || !ab) return;
rv = ab->ConvertNA2toLDIF(ab4xFile, tmpLDIFFile);
rv = ab->ConvertNA2toLDIF(ab4xFileSpec, tmpLDIFFileSpec);
NS_ASSERTION(NS_SUCCEEDED(rv),"ab migration failed: failed to convert na2 to ldif");
if (NS_FAILED(rv)) return;
rv = ab->ConvertLDIFtoMAB(tmpLDIFFile, PR_TRUE /* migrating */);
rv = ab->ConvertLDIFtoMAB(tmpLDIFFileSpec, PR_TRUE /* migrating */);
NS_ASSERTION(NS_SUCCEEDED(rv),"ab migration filed: failed to convert ldif to mab\n");
if (NS_FAILED(rv)) return;
@ -1806,7 +1893,7 @@ nsresult
nsMessengerMigrator::MigrateNewsAccounts(nsIMsgIdentity *identity)
{
nsresult rv;
nsCOMPtr <nsIFileSpec> newsDir;
nsCOMPtr <nsIFile> newsDir;
nsFileSpec newsrcDir; // the directory that holds the newsrc files (and the fat file, if we are using one)
nsFileSpec newsHostsDir; // the directory that holds the host directory, and the summary files.
// the host directories will be under <profile dir>/News or
@ -1821,28 +1908,31 @@ nsMessengerMigrator::MigrateNewsAccounts(nsIMsgIdentity *identity)
// the newsrc files lived. we don't want that for the newsHostsDir.
#ifdef USE_NEWSRC_MAP_FILE
// if they used -installer, this pref will point to where their files got copied
rv = m_prefs->GetFilePref(PREF_NEWS_DIRECTORY, getter_AddRefs(newsDir));
if (NS_SUCCEEDED(rv)) {
rv = newsDir->GetFileSpec(&newsHostsDir);
}
nsCOMPtr<nsILocalFile> localFile;
rv = m_prefs->GetFileXPref(PREF_NEWS_DIRECTORY, getter_AddRefs(localFile));
if (NS_SUCCEEDED(rv))
newsDir = localFile;
#else
rv = NS_ERROR_FAILURE;
#endif /* USE_NEWSRC_MAP_FILE */
if (NS_FAILED(rv)) {
NS_WITH_SERVICE(nsIFileLocator, locator, kFileLocatorCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = locator->GetFileLocation(nsSpecialFileSpec::App_NewsDirectory50, getter_AddRefs(newsDir));
if (NS_FAILED(rv)) return rv;
rv = newsDir->GetFileSpec(&newsHostsDir);
if (NS_FAILED(rv)) return rv;
if (!newsDir) {
rv = NS_GetSpecialDirectory(NS_APP_NEWS_50_DIR, getter_AddRefs(newsDir));
if (NS_FAILED(rv)) return rv;
}
PRBool dirExists;
rv = newsDir->Exists(&dirExists);
if (!dirExists) {
newsDir->CreateDir();
}
if (NS_SUCCEEDED(rv) && !dirExists)
newsDir->Create(nsIFile::DIRECTORY_TYPE, 0775);
if (NS_FAILED(rv)) return rv;
// TODO: convert users os nsIFileSpec to nsILocalFile
// and avoid this step.
nsXPIDLCString pathBuf;
rv = newsDir->GetPath(getter_Copies(pathBuf));
if (NS_FAILED(rv)) return rv;
newsHostsDir = pathBuf;
#ifdef USE_NEWSRC_MAP_FILE
// if we are using the fat file, it lives in the newsHostsDir.
@ -1973,11 +2063,17 @@ nsMessengerMigrator::MigrateNewsAccounts(nsIMsgIdentity *identity)
inputStream.close();
#else /* USE_NEWSRC_MAP_FILE */
rv = m_prefs->GetFilePref(PREF_NEWS_DIRECTORY, getter_AddRefs(newsDir));
nsCOMPtr<nsILocalFile> prefLocal;
rv = m_prefs->GetFileXPref(PREF_NEWS_DIRECTORY, getter_AddRefs(prefLocal));
if (NS_FAILED(rv)) return rv;
newsDir = prefLocal;
rv = newsDir->GetFileSpec(&newsrcDir);
if (NS_FAILED(rv)) return rv;
{
nsXPIDLCString pathBuf;
newsDir->GetPath(getter_Copies(pathBuf));
if (NS_FAILED(rv)) return rv;
newsrcDir = (const char *)pathBuf;
}
for (nsDirectoryIterator i(newsrcDir, PR_FALSE); i.Exists(); i++) {
nsFileSpec possibleRcFile = i.Spec();

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

@ -39,18 +39,13 @@
#include "nsXPIDLString.h"
#include "nscore.h"
#include "nsIProfile.h"
#include "nsIFileLocator.h"
#include "nsFileLocations.h"
#include "nsCRT.h" // for nsCRT::strtok
#include "prprf.h"
#include "nsINetSupportDialogService.h"
#include "nsIMsgFolderCache.h"
#include "nsFileStream.h"
#include "nsMsgUtils.h"
#include "nsSpecialSystemDirectory.h"
#include "nsIFileLocator.h"
#include "nsIFileSpec.h"
#include "nsFileLocations.h"
#include "nsIURL.h"
#include "nsISmtpService.h"
#include "nsString.h"
@ -58,6 +53,8 @@
#include "nsIObserverService.h"
#include "nsIMsgMailSession.h"
#include "nsIEventQueueService.h"
#include "nsIDirectoryService.h"
#include "nsAppDirectoryServiceDefs.h"
#if defined(DEBUG_alecf) || defined(DEBUG_sspitzer_) || defined(DEBUG_seth_)
#define DEBUG_ACCOUNTMANAGER 1
@ -79,8 +76,6 @@ static NS_DEFINE_CID(kProfileCID, NS_PROFILE_CID);
static NS_DEFINE_CID(kCNetSupportDialogCID, NS_NETSUPPORTDIALOG_CID);
static NS_DEFINE_CID(kStandardUrlCID, NS_STANDARDURL_CID);
static NS_DEFINE_CID(kSmtpServiceCID, NS_SMTPSERVICE_CID);
static NS_DEFINE_CID(kFileLocatorCID, NS_FILELOCATOR_CID);
static NS_DEFINE_IID(kIFileLocatorIID, NS_IFILELOCATOR_IID);
static NS_DEFINE_CID(kMsgFolderCacheCID, NS_MSGFOLDERCACHE_CID);
static NS_DEFINE_CID(kMsgMailSessionCID, NS_MSGMAILSESSION_CID);
static NS_DEFINE_CID(kMsgAccountManagerCID, NS_MSGACCOUNTMANAGER_CID);
@ -812,15 +807,23 @@ nsresult nsMsgAccountManager::GetFolderCache(nsIMsgFolderCache* *aFolderCache)
if (NS_FAILED(rv))
return rv;
nsCOMPtr <nsIFileSpec> cacheFile;
NS_WITH_SERVICE(nsIFileLocator, locator, kFileLocatorCID, &rv);
nsCOMPtr<nsIFile> cacheFile;
nsCOMPtr <nsIFileSpec> cacheFileSpec;
rv = NS_GetSpecialDirectory(NS_APP_MESSENGER_FOLDER_CACHE_50_DIR, getter_AddRefs(cacheFile));
if (NS_FAILED(rv)) return rv;
rv = locator->GetFileLocation(nsSpecialFileSpec::App_MessengerFolderCache50, getter_AddRefs(cacheFile));
// 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;
m_msgFolderCache->Init(cacheFile);
rv = NS_NewFileSpec(getter_AddRefs(cacheFileSpec));
if (NS_FAILED(rv)) return rv;
rv = cacheFileSpec->SetNativePath(pathBuf);
if (NS_FAILED(rv)) return rv;
m_msgFolderCache->Init(cacheFileSpec);
}
*aFolderCache = m_msgFolderCache;

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

@ -336,9 +336,24 @@ nsMsgIncomingServer::GetFileValue(const char* prefname,
{
nsCAutoString fullPrefName;
getPrefName(m_serverKey, prefname, fullPrefName);
nsresult rv = m_prefs->GetFilePref(fullPrefName, spec);
nsCOMPtr<nsILocalFile> prefLocal;
nsCOMPtr<nsIFileSpec> outSpec;
nsXPIDLCString pathBuf;
nsresult rv = m_prefs->GetFileXPref(fullPrefName, 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);
if (NS_FAILED(rv)) return rv;
*spec = outSpec;
NS_ADDREF(*spec);
return rv;
return NS_OK;
}
nsresult
@ -347,9 +362,19 @@ nsMsgIncomingServer::SetFileValue(const char* prefname,
{
nsCAutoString fullPrefName;
getPrefName(m_serverKey, prefname, fullPrefName);
nsresult rv = m_prefs->SetFilePref(fullPrefName, spec, PR_FALSE);
nsresult rv;
nsFileSpec tempSpec;
nsCOMPtr<nsILocalFile> prefLocal;
rv = spec->GetFileSpec(&tempSpec);
if (NS_FAILED(rv)) return rv;
rv = NS_FileSpecToIFile(&tempSpec, getter_AddRefs(prefLocal));
if (NS_FAILED(rv)) return rv;
rv = m_prefs->SetFileXPref(fullPrefName, prefLocal);
if (NS_FAILED(rv)) return rv;
return rv;
return NS_OK;
}
nsresult

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

@ -47,13 +47,13 @@
#include "nsIMsgStatusFeedback.h"
#include "nsIPref.h"
#include "nsILoadGroup.h"
#include "nsIFileLocator.h"
#include "nsFileLocations.h"
#include "nsIMsgAccountManager.h"
#include "nsMsgBaseCID.h"
#include "nsMsgFolderFlags.h"
#include "nsISubscribableServer.h"
#include "nsIMessage.h"
#include "nsIDirectoryService.h"
#include "nsAppDirectoryServiceDefs.h"
#define PREF_MAIL_ROOT_IMAP "mail.root.imap"
@ -61,8 +61,6 @@ static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
static NS_DEFINE_CID(kImapUrlCID, NS_IMAPURL_CID);
static NS_DEFINE_IID(kIFileLocatorIID, NS_IFILELOCATOR_IID);
static NS_DEFINE_CID(kFileLocatorCID, NS_FILELOCATOR_CID);
static const char *sequenceString = "SEQUENCE";
@ -2864,20 +2862,50 @@ nsImapService::SetDefaultLocalPath(nsIFileSpec *aPath)
NS_IMETHODIMP
nsImapService::GetDefaultLocalPath(nsIFileSpec ** aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = nsnull;
nsresult rv;
NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = prefs->GetFilePref(PREF_MAIL_ROOT_IMAP, aResult);
if (NS_SUCCEEDED(rv)) return rv;
NS_WITH_SERVICE(nsIFileLocator, locator, kFileLocatorCID, &rv);
PRBool havePref;
nsCOMPtr<nsILocalFile> prefLocal;
nsCOMPtr<nsIFile> localFile;
rv = prefs->GetFileXPref(PREF_MAIL_ROOT_IMAP, getter_AddRefs(prefLocal));
if (NS_SUCCEEDED(rv)) {
localFile = prefLocal;
havePref = PR_TRUE;
}
if (!localFile) {
rv = NS_GetSpecialDirectory(NS_APP_IMAP_MAIL_50_DIR, getter_AddRefs(localFile));
if (NS_FAILED(rv)) return rv;
havePref = FALSE;
}
PRBool exists;
rv = localFile->Exists(&exists);
if (NS_FAILED(rv)) return rv;
rv = locator->GetFileLocation(nsSpecialFileSpec::App_ImapMailDirectory50, aResult);
if (!exists) {
rv = localFile->Create(nsIFile::DIRECTORY_TYPE, 0775);
if (NS_FAILED(rv)) return rv;
}
// 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;
rv = SetDefaultLocalPath(*aResult);
nsCOMPtr<nsIFileSpec> outSpec;
rv = NS_NewFileSpec(getter_AddRefs(outSpec));
if (NS_FAILED(rv)) return rv;
outSpec->SetNativePath(pathBuf);
if (!havePref || !exists)
rv = SetDefaultLocalPath(outSpec);
*aResult = outSpec;
NS_IF_ADDREF(*aResult);
return rv;
}

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

@ -37,7 +37,6 @@
#include "nsIURL.h"
#include "nsIFileSpec.h"
#include "nsIFileLocator.h"
#include "nsIProfile.h"
#include "nsIAddrDatabase.h"

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

@ -39,8 +39,6 @@
#include "nsXPIDLString.h"
#include "nsIFileSpec.h"
#include "nsIFileLocator.h"
#include "nsSpecialSystemDirectory.h"
#include "nsIMsgAccountManager.h"
#include "nsIMsgMailSession.h"

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

@ -35,11 +35,10 @@
#include "nsMsgLocalCID.h"
#include "nsMsgFolderFlags.h"
#include "nsIMsgLocalMailFolder.h"
#include "nsFileLocations.h"
#include "nsIFileLocator.h"
#include "nsIChromeRegistry.h"
#include "nsIDirectoryService.h"
#include "nsAppDirectoryServiceDefs.h"
static NS_DEFINE_CID(kFileLocatorCID, NS_FILELOCATOR_CID);
static NS_DEFINE_CID(kChromeRegistryCID, NS_CHROMEREGISTRY_CID);
NS_IMPL_ISUPPORTS_INHERITED2(nsNoIncomingServer,
@ -94,11 +93,8 @@ NS_IMETHODIMP nsNoIncomingServer::CopyDefaultMessages(const char *folderNameOnDi
PRBool exists;
if (!folderNameOnDisk || !parentDir) return NS_ERROR_NULL_POINTER;
nsCOMPtr<nsIFileLocator> locator = do_GetService(kFileLocatorCID, &rv);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIFileSpec> defaultMessagesFile;
rv = locator->GetFileLocation(nsSpecialFileSpec::App_DefaultsFolder50, getter_AddRefs(defaultMessagesFile));
nsCOMPtr<nsIFile> defaultMessagesFile;
rv = NS_GetSpecialDirectory(NS_APP_DEFAULTS_50_DIR, getter_AddRefs(defaultMessagesFile));
if (NS_FAILED(rv)) return rv;
// bin/defaults better exist
@ -108,7 +104,7 @@ NS_IMETHODIMP nsNoIncomingServer::CopyDefaultMessages(const char *folderNameOnDi
// bin/defaults/messenger doesn't have to exist
// if not, return.
rv = defaultMessagesFile->AppendRelativeUnixPath("messenger");
rv = defaultMessagesFile->Append("messenger");
if (NS_FAILED(rv)) return rv;
rv = defaultMessagesFile->Exists(&exists);
if (NS_FAILED(rv)) return rv;
@ -116,57 +112,58 @@ NS_IMETHODIMP nsNoIncomingServer::CopyDefaultMessages(const char *folderNameOnDi
// test if there is a locale provider
// this code stolen from nsMsgServiceProvider.cpp
nsCOMPtr<nsIChromeRegistry> chromeRegistry = do_GetService(kChromeRegistryCID, &rv);
nsCOMPtr<nsIChromeRegistry> chromeRegistry = do_GetService(kChromeRegistryCID, &rv);
if (NS_SUCCEEDED(rv)) {
nsXPIDLString lc_name;
nsAutoString tmpstr; tmpstr.AssignWithConversion("navigator");
rv = chromeRegistry->GetSelectedLocale(tmpstr.GetUnicode(), getter_Copies(lc_name));
if (NS_SUCCEEDED(rv)) {
nsXPIDLString lc_name;
nsAutoString tmpstr; tmpstr.AssignWithConversion("navigator");
rv = chromeRegistry->GetSelectedLocale(tmpstr.GetUnicode(), getter_Copies(lc_name));
if (NS_SUCCEEDED(rv)) {
nsAutoString localeStr(lc_name);
if (!localeStr.IsEmpty())
{
nsCOMPtr<nsIFileSpec> tmpdataFilesDir;
rv = NS_NewFileSpec(getter_AddRefs(tmpdataFilesDir));
NS_ENSURE_SUCCESS(rv,rv);
rv = tmpdataFilesDir->FromFileSpec(defaultMessagesFile);
NS_ENSURE_SUCCESS(rv,rv);
tmpdataFilesDir->AppendRelativeUnixPath(NS_ConvertUCS2toUTF8(lc_name));
NS_ENSURE_SUCCESS(rv,rv);
rv = tmpdataFilesDir->Exists(&exists);
NS_ENSURE_SUCCESS(rv,rv);
if (exists) {
// use locale provider instead
rv = defaultMessagesFile->AppendRelativeUnixPath(NS_ConvertUCS2toUTF8(lc_name));
NS_ENSURE_SUCCESS(rv,rv);
}
nsAutoString localeStr(lc_name);
if (!localeStr.IsEmpty()) {
nsCOMPtr<nsIFile> tmpdataFilesDir;
rv = defaultMessagesFile->Clone(getter_AddRefs(tmpdataFilesDir));
NS_ENSURE_SUCCESS(rv,rv);
rv = tmpdataFilesDir->AppendUnicode(lc_name);
NS_ENSURE_SUCCESS(rv,rv);
rv = tmpdataFilesDir->Exists(&exists);
NS_ENSURE_SUCCESS(rv,rv);
if (exists && (const PRUnichar *)lc_name) {
// use locale provider instead
rv = defaultMessagesFile->AppendUnicode(lc_name);
NS_ENSURE_SUCCESS(rv,rv);
}
}
}
}
// check if bin/defaults/messenger/<folderNameOnDisk>
// (or bin/defaults/messenger/<locale>/<folderNameOnDisk> if we had a locale provide) exists.
// it doesn't have to exist. if it doesn't, return
rv = defaultMessagesFile->AppendRelativeUnixPath(folderNameOnDisk);
rv = defaultMessagesFile->Append(folderNameOnDisk);
if (NS_FAILED(rv)) return rv;
rv = defaultMessagesFile->Exists(&exists);
if (NS_FAILED(rv)) return rv;
if (!exists) return NS_OK;
// Make an nsILocalFile of the parentDir
nsFileSpec parentDirSpec;
nsCOMPtr<nsILocalFile> localParentDir;
rv = parentDir->GetFileSpec(&parentDirSpec);
if (NS_FAILED(rv)) return rv;
rv = NS_FileSpecToIFile(&parentDirSpec, getter_AddRefs(localParentDir));
if (NS_FAILED(rv)) return rv;
// check if parentDir/<folderNameOnDisk> exists
nsCOMPtr <nsIFileSpec> folderFile;
rv = NS_NewFileSpec(getter_AddRefs(folderFile));
if (NS_FAILED(rv)) return rv;
if (!folderFile) return NS_ERROR_FAILURE;
rv = folderFile->FromFileSpec(parentDir);
if (NS_FAILED(rv)) return rv;
rv = folderFile->AppendRelativeUnixPath(folderNameOnDisk);
if (NS_FAILED(rv)) return rv;
rv = folderFile->Exists(&exists);
if (NS_FAILED(rv)) return rv;
{
nsCOMPtr<nsIFile> testDir;
rv = localParentDir->Clone(getter_AddRefs(testDir));
if (NS_FAILED(rv)) return rv;
rv = testDir->Append(folderNameOnDisk);
if (NS_FAILED(rv)) return rv;
rv = testDir->Exists(&exists);
if (NS_FAILED(rv)) return rv;
}
// if it exists add to the end, else copy
if (exists) {
@ -181,7 +178,7 @@ NS_IMETHODIMP nsNoIncomingServer::CopyDefaultMessages(const char *folderNameOnDi
#ifdef DEBUG_sspitzer
printf("copy default %s\n",folderNameOnDisk);
#endif
rv = defaultMessagesFile->CopyToDir(parentDir);
rv = defaultMessagesFile->CopyTo(localParentDir, nsnull);
if (NS_FAILED(rv)) return rv;
}
return NS_OK;

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

@ -36,15 +36,13 @@
#include "nsXPIDLString.h"
#include "nsCOMPtr.h"
#include "nsIFileLocator.h"
#include "nsFileLocations.h"
#include "nsIDirectoryService.h"
#include "nsAppDirectoryServiceDefs.h"
#define PREF_MAIL_ROOT_NONE "mail.root.none"
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
static NS_DEFINE_CID(kMsgMailSessionCID, NS_MSGMAILSESSION_CID);
static NS_DEFINE_IID(kIFileLocatorIID, NS_IFILELOCATOR_IID);
static NS_DEFINE_CID(kFileLocatorCID, NS_FILELOCATOR_CID);
nsNoneService::nsNoneService()
{
@ -70,20 +68,50 @@ nsNoneService::SetDefaultLocalPath(nsIFileSpec *aPath)
NS_IMETHODIMP
nsNoneService::GetDefaultLocalPath(nsIFileSpec ** aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = nsnull;
nsresult rv;
NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = prefs->GetFilePref(PREF_MAIL_ROOT_NONE, aResult);
if (NS_SUCCEEDED(rv)) return rv;
NS_WITH_SERVICE(nsIFileLocator, locator, kFileLocatorCID, &rv);
PRBool havePref;
nsCOMPtr<nsILocalFile> prefLocal;
nsCOMPtr<nsIFile> localFile;
rv = prefs->GetFileXPref(PREF_MAIL_ROOT_NONE, getter_AddRefs(prefLocal));
if (NS_SUCCEEDED(rv)) {
localFile = prefLocal;
havePref = PR_TRUE;
}
if (!localFile) {
rv = NS_GetSpecialDirectory(NS_APP_MAIL_50_DIR, getter_AddRefs(localFile));
if (NS_FAILED(rv)) return rv;
havePref = PR_FALSE;
}
PRBool exists;
rv = localFile->Exists(&exists);
if (NS_FAILED(rv)) return rv;
rv = locator->GetFileLocation(nsSpecialFileSpec::App_MailDirectory50, aResult);
if (NS_FAILED(rv)) return rv;
rv = SetDefaultLocalPath(*aResult);
if (!exists) {
rv = localFile->Create(nsIFile::DIRECTORY_TYPE, 0775);
if (NS_FAILED(rv)) return rv;
}
// 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<nsIFileSpec> outSpec;
rv = NS_NewFileSpec(getter_AddRefs(outSpec));
if (NS_FAILED(rv)) return rv;
outSpec->SetNativePath(pathBuf);
if (!havePref || !exists)
rv = SetDefaultLocalPath(outSpec);
*aResult = outSpec;
NS_IF_ADDREF(*aResult);
return rv;
}

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

@ -39,11 +39,11 @@
#include "nsCOMPtr.h"
#include "nsIMsgWindow.h"
#include "nsIFileLocator.h"
#include "nsFileLocations.h"
#include "nsIRDFService.h"
#include "nsIRDFDataSource.h"
#include "nsRDFCID.h"
#include "nsIDirectoryService.h"
#include "nsAppDirectoryServiceDefs.h"
#define POP3_PORT 110 // The IANA port for Pop3
@ -52,8 +52,6 @@
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
static NS_DEFINE_CID(kPop3UrlCID, NS_POP3URL_CID);
static NS_DEFINE_CID(kMsgMailSessionCID, NS_MSGMAILSESSION_CID);
static NS_DEFINE_IID(kIFileLocatorIID, NS_IFILELOCATOR_IID);
static NS_DEFINE_CID(kFileLocatorCID, NS_FILELOCATOR_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
nsPop3Service::nsPop3Service()
@ -411,20 +409,50 @@ nsPop3Service::SetDefaultLocalPath(nsIFileSpec *aPath)
NS_IMETHODIMP
nsPop3Service::GetDefaultLocalPath(nsIFileSpec ** aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = nsnull;
nsresult rv;
NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = prefs->GetFilePref(PREF_MAIL_ROOT_POP3, aResult);
if (NS_SUCCEEDED(rv)) return rv;
NS_WITH_SERVICE(nsIFileLocator, locator, kFileLocatorCID, &rv);
PRBool havePref;
nsCOMPtr<nsILocalFile> prefLocal;
nsCOMPtr<nsIFile> localFile;
rv = prefs->GetFileXPref(PREF_MAIL_ROOT_POP3, getter_AddRefs(prefLocal));
if (NS_SUCCEEDED(rv)) {
localFile = prefLocal;
havePref = PR_TRUE;
}
if (!localFile) {
rv = NS_GetSpecialDirectory(NS_APP_MAIL_50_DIR, getter_AddRefs(localFile));
if (NS_FAILED(rv)) return rv;
havePref = FALSE;
}
PRBool exists;
rv = localFile->Exists(&exists);
if (NS_FAILED(rv)) return rv;
rv = locator->GetFileLocation(nsSpecialFileSpec::App_MailDirectory50, aResult);
if (NS_FAILED(rv)) return rv;
rv = SetDefaultLocalPath(*aResult);
if (!exists) {
rv = localFile->Create(nsIFile::DIRECTORY_TYPE, 0775);
if (NS_FAILED(rv)) return rv;
}
// 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<nsIFileSpec> outSpec;
rv = NS_NewFileSpec(getter_AddRefs(outSpec));
if (NS_FAILED(rv)) return rv;
outSpec->SetNativePath(pathBuf);
if (!havePref || !exists)
rv = SetDefaultLocalPath(outSpec);
*aResult = outSpec;
NS_IF_ADDREF(*aResult);
return rv;
}