зеркало из https://github.com/mozilla/gecko-dev.git
Bug 132180 eliminate nsFileSpec in address book.
r=dmose sr=bienvenu patch by Mark Banner <bugzilla@standard8.demon.co.uk>
This commit is contained in:
Родитель
58e511d15e
Коммит
d5b4611a81
|
@ -51,7 +51,9 @@
|
|||
#include "nsIAbDirectory.idl"
|
||||
#include "nsIAbCard.idl"
|
||||
|
||||
[scriptable, uuid(C5339441-303F-11d3-9E13-00A0C92B5F0D)]
|
||||
interface nsILocalFile;
|
||||
|
||||
[scriptable, uuid(957abaa8-5cef-49d0-84a5-ce43da384990)]
|
||||
interface nsIAddrBookSession : nsISupports {
|
||||
void addAddressBookListener(in nsIAbListener listener, in abListenerNotifyFlagValue notifyFlags);
|
||||
void removeAddressBookListener(in nsIAbListener listener);
|
||||
|
@ -71,7 +73,7 @@ interface nsIAddrBookSession : nsISupports {
|
|||
*/
|
||||
void notifyDirectoryDeleted(in nsIAbDirectory directory, in nsISupports item);
|
||||
|
||||
[noscript] readonly attribute nsFileSpec userProfileDirectory;
|
||||
readonly attribute nsILocalFile userProfileDirectory;
|
||||
|
||||
/**
|
||||
* generate the name from the card, using the firstName and lastName and the displayName
|
||||
|
|
|
@ -137,13 +137,11 @@ interface nsAddrDBCommitType
|
|||
const long kCompressCommit = 3;
|
||||
};
|
||||
|
||||
[scriptable, uuid(A4186D8B-1DD0-11d3-A303-001083003D0C)]
|
||||
[scriptable, uuid(8175a7ce-4414-489e-ba29-b22d8c4a1cae)]
|
||||
interface nsIAddrDatabase : nsIAddrDBAnnouncer {
|
||||
|
||||
[noscript] attribute nsFileSpec dbPath;
|
||||
[noscript] void open(in nsFileSpec folderName, in boolean create,
|
||||
out nsIAddrDatabase pCardDB, in boolean upgrading);
|
||||
nsIAddrDatabase openWithIFile(in nsIFile dbFile, in boolean create, in boolean upgrading);
|
||||
nsIAddrDatabase open(in nsIFile dbFile, in boolean create, in boolean upgrading);
|
||||
|
||||
void close(in boolean forceCommit);
|
||||
[noscript] void openMDB(in nsFileSpec dbName, in boolean create);
|
||||
|
|
|
@ -44,7 +44,6 @@
|
|||
#include "nsAbUtils.h"
|
||||
#include "nsAbMDBCard.h"
|
||||
#include "nsAbLDAPCard.h"
|
||||
#include "nsFileSpec.h"
|
||||
#include "nsAbLDAPProperties.h"
|
||||
#include "nsProxiedService.h"
|
||||
#include "nsAutoLock.h"
|
||||
|
@ -191,14 +190,27 @@ nsresult nsAbLDAPProcessChangeLogData::OnLDAPSearchResult(nsILDAPMessage *aMessa
|
|||
nsCOMPtr<nsIAddrBookSession> abSession = do_GetService(NS_ADDRBOOKSESSION_CONTRACTID, &rv);
|
||||
if(NS_FAILED(rv))
|
||||
break;
|
||||
nsFileSpec* dbPath;
|
||||
rv = abSession->GetUserProfileDirectory(&dbPath);
|
||||
nsCOMPtr<nsILocalFile> dbPath;
|
||||
rv = abSession->GetUserProfileDirectory(getter_AddRefs(dbPath));
|
||||
if(NS_FAILED(rv))
|
||||
break;
|
||||
(*dbPath) += mDirServerInfo->replInfo->fileName;
|
||||
if (!dbPath->Exists() || !dbPath->GetFileSize())
|
||||
|
||||
rv = dbPath->AppendNative(nsDependentCString(mDirServerInfo->replInfo->fileName));
|
||||
if(NS_FAILED(rv))
|
||||
break;
|
||||
|
||||
PRBool fileExists;
|
||||
rv = dbPath->Exists(&fileExists);
|
||||
if(NS_FAILED(rv))
|
||||
break;
|
||||
|
||||
PRInt64 fileSize;
|
||||
rv = dbPath->GetFileSize(&fileSize);
|
||||
if(NS_FAILED(rv))
|
||||
break;
|
||||
|
||||
if (!fileExists || !fileSize)
|
||||
mUseChangeLog = PR_FALSE;
|
||||
delete dbPath;
|
||||
|
||||
// open / create the AB here since it calls Done,
|
||||
// just return from here.
|
||||
|
|
|
@ -45,7 +45,6 @@
|
|||
#include "nsAbUtils.h"
|
||||
#include "nsAbMDBCard.h"
|
||||
#include "nsAbLDAPCard.h"
|
||||
#include "nsFileSpec.h"
|
||||
#include "nsAbLDAPProperties.h"
|
||||
#include "nsAbLDAPReplicationQuery.h"
|
||||
#include "nsProxiedService.h"
|
||||
|
@ -496,25 +495,23 @@ nsresult nsAbLDAPProcessReplicationData::OpenABForReplicatedDir(PRBool aCreate)
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsFileSpec* dbPath;
|
||||
rv = abSession->GetUserProfileDirectory(&dbPath);
|
||||
rv = abSession->GetUserProfileDirectory(getter_AddRefs(mReplicationFile));
|
||||
if(NS_FAILED(rv)) {
|
||||
Done(PR_FALSE);
|
||||
return rv;
|
||||
}
|
||||
|
||||
(*dbPath) += mDirServerInfo->replInfo->fileName;
|
||||
rv = mReplicationFile->AppendNative(nsDependentCString(mDirServerInfo->replInfo->fileName));
|
||||
if(NS_FAILED(rv)) {
|
||||
Done(PR_FALSE);
|
||||
return rv;
|
||||
}
|
||||
|
||||
// if the AB DB already exists backup existing one,
|
||||
// in case if the user cancels or Abort put back the backed up file
|
||||
if(dbPath->Exists()) {
|
||||
// get nsIFile for nsFileSpec from abSession, why use a obsolete class if not required!
|
||||
rv = NS_FileSpecToIFile(dbPath, getter_AddRefs(mReplicationFile));
|
||||
if(NS_FAILED(rv)) {
|
||||
delete dbPath;
|
||||
Done(PR_FALSE);
|
||||
return rv;
|
||||
}
|
||||
PRBool fileExists;
|
||||
rv = mReplicationFile->Exists(&fileExists);
|
||||
if(NS_SUCCEEDED(rv) && fileExists) {
|
||||
// create the backup file object same as the Replication file object.
|
||||
// we create a backup file here since we need to cleanup the existing file
|
||||
// for create and then commit so instead of deleting existing cards we just
|
||||
|
@ -524,33 +521,28 @@ nsresult nsAbLDAPProcessReplicationData::OpenABForReplicatedDir(PRBool aCreate)
|
|||
nsCOMPtr<nsIFile> 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);
|
||||
return rv;
|
||||
}
|
||||
rv = mBackupReplicationFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0777);
|
||||
if(NS_FAILED(rv)) {
|
||||
delete dbPath;
|
||||
Done(PR_FALSE);
|
||||
return rv;
|
||||
}
|
||||
nsAutoString backupFileLeafName;
|
||||
rv = mBackupReplicationFile->GetLeafName(backupFileLeafName);
|
||||
if(NS_FAILED(rv)) {
|
||||
delete dbPath;
|
||||
Done(PR_FALSE);
|
||||
return rv;
|
||||
}
|
||||
// remove the newly created unique backup file so that move and copy succeeds.
|
||||
rv = mBackupReplicationFile->Remove(PR_FALSE);
|
||||
if(NS_FAILED(rv)) {
|
||||
delete dbPath;
|
||||
Done(PR_FALSE);
|
||||
return rv;
|
||||
}
|
||||
|
@ -578,7 +570,6 @@ nsresult nsAbLDAPProcessReplicationData::OpenABForReplicatedDir(PRBool aCreate)
|
|||
mBackupReplicationFile->SetLeafName(backupFileLeafName);
|
||||
}
|
||||
if(NS_FAILED(rv)) {
|
||||
delete dbPath;
|
||||
Done(PR_FALSE);
|
||||
return rv;
|
||||
}
|
||||
|
@ -587,15 +578,13 @@ nsresult nsAbLDAPProcessReplicationData::OpenABForReplicatedDir(PRBool aCreate)
|
|||
nsCOMPtr<nsIAddrDatabase> addrDBFactory =
|
||||
do_GetService(NS_ADDRDATABASE_CONTRACTID, &rv);
|
||||
if(NS_FAILED(rv)) {
|
||||
delete dbPath;
|
||||
if (mBackupReplicationFile)
|
||||
mBackupReplicationFile->Remove(PR_FALSE);
|
||||
Done(PR_FALSE);
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = addrDBFactory->Open(dbPath, aCreate, getter_AddRefs(mReplicationDB), PR_TRUE);
|
||||
delete dbPath;
|
||||
rv = addrDBFactory->Open(mReplicationFile, aCreate, PR_TRUE, getter_AddRefs(mReplicationDB));
|
||||
if(NS_FAILED(rv)) {
|
||||
Done(PR_FALSE);
|
||||
if (mBackupReplicationFile)
|
||||
|
|
|
@ -282,30 +282,32 @@ nsresult nsAbMDBCardProperty::GetCardDatabase(const char *uri)
|
|||
do_GetService(NS_ADDRBOOKSESSION_CONTRACTID, &rv);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsFileSpec* dbPath;
|
||||
abSession->GetUserProfileDirectory(&dbPath);
|
||||
nsCOMPtr<nsILocalFile> dbPath;
|
||||
rv = abSession->GetUserProfileDirectory(getter_AddRefs(dbPath));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
const char* file = nsnull;
|
||||
file = &(uri[kMDBDirectoryRootLen]);
|
||||
(*dbPath) += file;
|
||||
|
||||
rv = dbPath->AppendNative(nsDependentCString(&(uri[kMDBDirectoryRootLen])));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (dbPath->Exists())
|
||||
PRBool fileExists;
|
||||
rv = dbPath->Exists(&fileExists);
|
||||
if (NS_SUCCEEDED(rv) && fileExists)
|
||||
{
|
||||
nsCOMPtr<nsIAddrDatabase> addrDBFactory =
|
||||
do_GetService(NS_ADDRDATABASE_CONTRACTID, &rv);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && addrDBFactory)
|
||||
rv = addrDBFactory->Open(dbPath, PR_TRUE, getter_AddRefs(mCardDatabase), PR_TRUE);
|
||||
rv = addrDBFactory->Open(dbPath, PR_TRUE, PR_TRUE, getter_AddRefs(mCardDatabase));
|
||||
}
|
||||
else
|
||||
rv = NS_ERROR_FAILURE;
|
||||
delete dbPath;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbMDBCardProperty::Equals(nsIAbCard *card, PRBool *result)
|
||||
{
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
if (this == card) {
|
||||
|
|
|
@ -138,11 +138,11 @@ NS_IMETHODIMP nsAbMDBDirFactory::CreateDirectory(nsIAbDirectoryProperties *aProp
|
|||
nsCOMPtr<nsIAddrBookSession> abSession = do_GetService(NS_ADDRBOOKSESSION_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsFileSpec* dbPath;
|
||||
rv = abSession->GetUserProfileDirectory(&dbPath);
|
||||
nsCOMPtr<nsILocalFile> dbPath;
|
||||
rv = abSession->GetUserProfileDirectory(getter_AddRefs(dbPath));
|
||||
|
||||
nsCOMPtr<nsIAddrDatabase> listDatabase;
|
||||
if (dbPath)
|
||||
nsCOMPtr<nsIAddrDatabase> listDatabase;
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsCAutoString fileName;
|
||||
nsDependentCString uriStr(uri);
|
||||
|
@ -150,13 +150,13 @@ NS_IMETHODIMP nsAbMDBDirFactory::CreateDirectory(nsIAbDirectoryProperties *aProp
|
|||
if (StringBeginsWith(uriStr, NS_LITERAL_CSTRING(kMDBDirectoryRoot)))
|
||||
fileName = Substring(uriStr, kMDBDirectoryRootLen, uriStr.Length() - kMDBDirectoryRootLen);
|
||||
|
||||
(*dbPath) += fileName.get();
|
||||
rv = dbPath->AppendNative(fileName);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIAddrDatabase> addrDBFactory = do_GetService(NS_ADDRDATABASE_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = addrDBFactory->Open(dbPath, PR_TRUE, getter_AddRefs(listDatabase), PR_TRUE);
|
||||
delete dbPath;
|
||||
rv = addrDBFactory->Open(dbPath, PR_TRUE, PR_TRUE, getter_AddRefs(listDatabase));
|
||||
}
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
|
|
|
@ -177,7 +177,7 @@ NS_IMETHODIMP nsAddrBookSession::NotifyDirectoryDeleted(nsIAbDirectory *director
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAddrBookSession::GetUserProfileDirectory(nsFileSpec * *userDir)
|
||||
NS_IMETHODIMP nsAddrBookSession::GetUserProfileDirectory(nsILocalFile * *userDir)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(userDir);
|
||||
*userDir = nsnull;
|
||||
|
@ -192,10 +192,7 @@ NS_IMETHODIMP nsAddrBookSession::GetUserProfileDirectory(nsFileSpec * *userDir)
|
|||
rv = profileDir->GetNativePath(pathBuf);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
*userDir = new nsFileSpec(pathBuf.get());
|
||||
NS_ENSURE_TRUE(*userDir, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
return rv;
|
||||
return NS_NewNativeLocalFile(pathBuf, PR_TRUE, userDir);
|
||||
}
|
||||
|
||||
#define kDisplayName 0
|
||||
|
|
|
@ -40,7 +40,6 @@
|
|||
|
||||
#include "nsAddrDatabase.h"
|
||||
#include "nsIEnumerator.h"
|
||||
#include "nsFileStream.h"
|
||||
#include "nsString.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsRDFCID.h"
|
||||
|
@ -548,33 +547,28 @@ NS_IMETHODIMP nsAddrDatabase::SetDbPath(nsFileSpec * aDbPath)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAddrDatabase::OpenWithIFile(nsIFile *aFile, PRBool aCreate, PRBool aUpgrading, nsIAddrDatabase **aDB)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aDB);
|
||||
nsCOMPtr<nsIFileSpec> dbSpec;
|
||||
nsFileSpec addrDBFileSpec;
|
||||
// Convert the nsILocalFile into an nsIFileSpec
|
||||
// TODO: convert users of nsIFileSpec to nsILocalFile
|
||||
// and avoid this step.
|
||||
nsresult rv = NS_NewFileSpecFromIFile(aFile, getter_AddRefs(dbSpec));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = dbSpec->GetFileSpec(&addrDBFileSpec);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return Open(&addrDBFileSpec, aCreate, aDB, aUpgrading);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAddrDatabase::Open
|
||||
(nsFileSpec *aMabFile, PRBool aCreate, nsIAddrDatabase** pAddrDB, PRBool upgrading /* unused */)
|
||||
(nsIFile *aMabFile, PRBool aCreate, PRBool upgrading /* unused */, nsIAddrDatabase** pAddrDB)
|
||||
{
|
||||
*pAddrDB = nsnull;
|
||||
|
||||
nsAddrDatabase *pAddressBookDB = (nsAddrDatabase *) FindInCache(aMabFile);
|
||||
nsCOMPtr<nsIFileSpec> mabIFileSpec;
|
||||
nsFileSpec mabFileSpec;
|
||||
// Convert the nsILocalFile into an nsIFileSpec
|
||||
// TODO: convert users of nsIFileSpec to nsILocalFile
|
||||
// and avoid this step.
|
||||
nsresult rv = NS_NewFileSpecFromIFile(aMabFile, getter_AddRefs(mabIFileSpec));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = mabIFileSpec->GetFileSpec(&mabFileSpec);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsAddrDatabase *pAddressBookDB = (nsAddrDatabase *) FindInCache(&mabFileSpec);
|
||||
if (pAddressBookDB) {
|
||||
*pAddrDB = pAddressBookDB;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult rv = OpenInternal(aMabFile, aCreate, pAddrDB);
|
||||
rv = OpenInternal(&mabFileSpec, aCreate, pAddrDB);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
return NS_OK;
|
||||
|
||||
|
@ -583,13 +577,13 @@ NS_IMETHODIMP nsAddrDatabase::Open
|
|||
// and prompt the user
|
||||
if (aCreate)
|
||||
{
|
||||
nsFileSpec *newMabFile = new nsFileSpec(*aMabFile);
|
||||
nsFileSpec *newMabFile = new nsFileSpec(mabFileSpec);
|
||||
if (!newMabFile)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
// save off the name of the corrupt mab file, example abook.mab
|
||||
nsXPIDLCString originalMabFileName;
|
||||
originalMabFileName.Adopt(aMabFile->GetLeafName());
|
||||
originalMabFileName.Adopt(mabFileSpec.GetLeafName());
|
||||
|
||||
// the suggest new name for the backup will be abook.mab.bak
|
||||
nsCAutoString backupMabFileName(originalMabFileName);
|
||||
|
@ -602,7 +596,7 @@ NS_IMETHODIMP nsAddrDatabase::Open
|
|||
backupMabFileName.Adopt(newMabFile->GetLeafName());
|
||||
|
||||
// rename abook.mab to abook.mab.bak
|
||||
rv = aMabFile->Rename(backupMabFileName.get());
|
||||
rv = mabFileSpec.Rename(backupMabFileName.get());
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to rename corrupt mab file");
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
|
|
@ -76,8 +76,7 @@ public:
|
|||
|
||||
NS_IMETHOD GetDbPath(nsFileSpec * *aDbPath);
|
||||
NS_IMETHOD SetDbPath(nsFileSpec * aDbPath);
|
||||
NS_IMETHOD Open(nsFileSpec *aMabFile, PRBool aCreate, nsIAddrDatabase **pCardDB, PRBool upgrading);
|
||||
NS_IMETHOD OpenWithIFile(nsIFile *dbFile, PRBool create, PRBool upgrading, nsIAddrDatabase **_retval);
|
||||
NS_IMETHOD Open(nsIFile *aMabFile, PRBool aCreate, PRBool upgrading, nsIAddrDatabase **pCardDB);
|
||||
NS_IMETHOD Close(PRBool forceCommit);
|
||||
NS_IMETHOD OpenMDB(nsFileSpec *dbName, PRBool create);
|
||||
NS_IMETHOD CloseMDB(PRBool commit);
|
||||
|
|
|
@ -67,7 +67,6 @@
|
|||
#include "nsReadableUtils.h"
|
||||
#include "nsICategoryManager.h"
|
||||
#include "nsIAbUpgrader.h"
|
||||
#include "nsSpecialSystemDirectory.h"
|
||||
#include "nsIFilePicker.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
|
@ -282,8 +281,8 @@ NS_IMETHODIMP nsAddressBook::GetAbDatabaseFromURI(const char *aURI, nsIAddrDatab
|
|||
do_GetService(NS_ADDRBOOKSESSION_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
nsFileSpec* dbPath;
|
||||
rv = abSession->GetUserProfileDirectory(&dbPath);
|
||||
nsCOMPtr<nsILocalFile> dbPath;
|
||||
rv = abSession->GetUserProfileDirectory(getter_AddRefs(dbPath));
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
/* directory URIs are of the form
|
||||
|
@ -300,7 +299,8 @@ NS_IMETHODIMP nsAddressBook::GetAbDatabaseFromURI(const char *aURI, nsIAddrDatab
|
|||
PRInt32 pos = file.Find("/");
|
||||
if (pos != kNotFound)
|
||||
file.Truncate(pos);
|
||||
(*dbPath) += file.get();
|
||||
rv = dbPath->AppendNative(file);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
nsCOMPtr<nsIAddrDatabase> addrDBFactory =
|
||||
do_GetService(NS_ADDRDATABASE_CONTRACTID, &rv);
|
||||
|
@ -308,8 +308,7 @@ NS_IMETHODIMP nsAddressBook::GetAbDatabaseFromURI(const char *aURI, nsIAddrDatab
|
|||
|
||||
/* Don't create otherwise we end up re-opening a deleted address book */
|
||||
/* bug 66410 */
|
||||
rv = addrDBFactory->Open(dbPath, PR_FALSE /* no create */, aDB, PR_TRUE);
|
||||
delete dbPath;
|
||||
rv = addrDBFactory->Open(dbPath, PR_FALSE /* no create */, PR_TRUE, aDB);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
@ -320,22 +319,24 @@ nsresult nsAddressBook::GetAbDatabaseFromFile(char* pDbFile, nsIAddrDatabase **d
|
|||
nsCOMPtr<nsIAddrDatabase> database;
|
||||
if (pDbFile)
|
||||
{
|
||||
nsFileSpec* dbPath = nsnull;
|
||||
nsCOMPtr<nsILocalFile> dbPath;
|
||||
|
||||
nsCOMPtr<nsIAddrBookSession> abSession =
|
||||
do_GetService(NS_ADDRBOOKSESSION_CONTRACTID, &rv);
|
||||
if(NS_SUCCEEDED(rv))
|
||||
abSession->GetUserProfileDirectory(&dbPath);
|
||||
{
|
||||
rv = abSession->GetUserProfileDirectory(getter_AddRefs(dbPath));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
nsCAutoString file(pDbFile);
|
||||
(*dbPath) += file.get();
|
||||
rv = dbPath->AppendNative(file);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
nsCOMPtr<nsIAddrDatabase> addrDBFactory =
|
||||
do_GetService(NS_ADDRDATABASE_CONTRACTID, &rv);
|
||||
if (NS_SUCCEEDED(rv) && addrDBFactory)
|
||||
rv = addrDBFactory->Open(dbPath, PR_TRUE, getter_AddRefs(database), PR_TRUE);
|
||||
|
||||
delete dbPath;
|
||||
rv = addrDBFactory->Open(dbPath, PR_TRUE, PR_TRUE, getter_AddRefs(database));
|
||||
|
||||
if (NS_SUCCEEDED(rv) && database)
|
||||
{
|
||||
|
@ -476,27 +477,28 @@ nsresult AddressBookParser::ParseFile()
|
|||
// to do: we should use only one "return rv;" at the very end, instead of this
|
||||
// multi return structure
|
||||
nsresult rv = NS_OK;
|
||||
nsFileSpec* dbPath = nsnull;
|
||||
char* fileName = PR_smprintf("%s.mab", leafName);
|
||||
nsCOMPtr<nsILocalFile> dbPath;
|
||||
nsCAutoString fileName(leafName);
|
||||
fileName.Append(NS_LITERAL_CSTRING(".mab"));
|
||||
|
||||
nsCOMPtr<nsIAddrBookSession> abSession =
|
||||
do_GetService(NS_ADDRBOOKSESSION_CONTRACTID, &rv);
|
||||
if(NS_SUCCEEDED(rv))
|
||||
abSession->GetUserProfileDirectory(&dbPath);
|
||||
rv = abSession->GetUserProfileDirectory(getter_AddRefs(dbPath));
|
||||
|
||||
/* create address book database */
|
||||
if (dbPath)
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
(*dbPath) += fileName;
|
||||
dbPath->AppendNative(fileName);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIAddrDatabase> addrDBFactory =
|
||||
do_GetService(NS_ADDRDATABASE_CONTRACTID, &rv);
|
||||
if (NS_SUCCEEDED(rv) && addrDBFactory)
|
||||
rv = addrDBFactory->Open(dbPath, PR_TRUE, getter_AddRefs(mDatabase), PR_TRUE);
|
||||
rv = addrDBFactory->Open(dbPath, PR_TRUE, PR_TRUE, getter_AddRefs(mDatabase));
|
||||
}
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
delete dbPath;
|
||||
|
||||
nsCOMPtr<nsIRDFService> rdfService = do_GetService (NS_RDF_CONTRACTID "/rdf-service;1", &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsIRDFResource> parentResource;
|
||||
|
@ -514,7 +516,7 @@ nsresult AddressBookParser::ParseFile()
|
|||
nsXPIDLString dirName;
|
||||
nsCOMPtr<nsIPrefLocalizedString> locString;
|
||||
nsCAutoString prefName;
|
||||
if (strcmp(fileName, kPersonalAddressbook) == 0)
|
||||
if (strcmp(fileName.get(), kPersonalAddressbook) == 0)
|
||||
prefName.AssignLiteral("ldap_2.servers.pab.description");
|
||||
else
|
||||
prefName = NS_LITERAL_CSTRING("ldap_2.servers.") + nsDependentCString(leafName) + NS_LITERAL_CSTRING(".description");
|
||||
|
@ -533,8 +535,6 @@ nsresult AddressBookParser::ParseFile()
|
|||
|
||||
if (leafName)
|
||||
nsCRT::free(leafName);
|
||||
if (fileName)
|
||||
PR_smprintf_free(fileName);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
|
|
@ -1725,14 +1725,14 @@ nsresult DIR_DeleteServerFromList(DIR_Server *server)
|
|||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
nsFileSpec* dbPath = nsnull;
|
||||
nsCOMPtr<nsILocalFile> dbPath;
|
||||
|
||||
nsCOMPtr<nsIAddrBookSession> abSession =
|
||||
do_GetService(NS_ADDRBOOKSESSION_CONTRACTID, &rv);
|
||||
if(NS_SUCCEEDED(rv))
|
||||
abSession->GetUserProfileDirectory(&dbPath);
|
||||
rv = abSession->GetUserProfileDirectory(getter_AddRefs(dbPath));
|
||||
|
||||
if (dbPath)
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
// close the database, as long as it isn't the special ones
|
||||
// (personal addressbook and collected addressbook)
|
||||
|
@ -1743,21 +1743,21 @@ nsresult DIR_DeleteServerFromList(DIR_Server *server)
|
|||
strcmp(server->fileName, kCollectedAddressbook)) {
|
||||
nsCOMPtr<nsIAddrDatabase> database;
|
||||
|
||||
(*dbPath) += server->fileName;
|
||||
rv = dbPath->AppendNative(nsDependentCString(server->fileName));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// close file before delete it
|
||||
nsCOMPtr<nsIAddrDatabase> addrDBFactory =
|
||||
do_GetService(NS_ADDRDATABASE_CONTRACTID, &rv);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && addrDBFactory)
|
||||
rv = addrDBFactory->Open(dbPath, PR_FALSE, getter_AddRefs(database), PR_TRUE);
|
||||
rv = addrDBFactory->Open(dbPath, PR_FALSE, PR_TRUE, getter_AddRefs(database));
|
||||
if (database) /* database exists */
|
||||
{
|
||||
database->ForceClosed();
|
||||
dbPath->Delete(PR_FALSE);
|
||||
rv = dbPath->Remove(PR_FALSE);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
delete dbPath;
|
||||
}
|
||||
|
||||
nsVoidArray *dirList = DIR_GetDirectories();
|
||||
|
@ -2562,27 +2562,35 @@ static void DIR_ConvertServerFileName(DIR_Server* pServer)
|
|||
if (leafName) PR_Free(leafName);
|
||||
}
|
||||
|
||||
/* This will generate a correct filename and then remove the path */
|
||||
/* This will generate a correct filename and then remove the path.
|
||||
* Note: we are assuming that the default name is in the native
|
||||
* filesystem charset. The filename will be returned as a UTF8
|
||||
* string.
|
||||
*/
|
||||
void DIR_SetFileName(char** fileName, const char* defaultName)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsFileSpec* dbPath = nsnull;
|
||||
nsCOMPtr<nsILocalFile> dbPath;
|
||||
|
||||
*fileName = nsnull;
|
||||
|
||||
nsCOMPtr<nsIAddrBookSession> abSession =
|
||||
do_GetService(NS_ADDRBOOKSESSION_CONTRACTID, &rv);
|
||||
if(NS_SUCCEEDED(rv))
|
||||
abSession->GetUserProfileDirectory(&dbPath);
|
||||
if (dbPath)
|
||||
rv = abSession->GetUserProfileDirectory(getter_AddRefs(dbPath));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
(*dbPath) += defaultName;
|
||||
dbPath->MakeUnique(defaultName);
|
||||
char* file = nsnull;
|
||||
file = dbPath->GetLeafName();
|
||||
*fileName = nsCRT::strdup(file);
|
||||
if (file)
|
||||
nsCRT::free(file);
|
||||
rv = dbPath->AppendNative(nsDependentCString(defaultName));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
rv = dbPath->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0664);
|
||||
|
||||
delete dbPath;
|
||||
nsAutoString realFileName;
|
||||
rv = dbPath->GetLeafName(realFileName);
|
||||
|
||||
if (NS_SUCCEEDED(rv))
|
||||
*fileName = ToNewUTF8String(realFileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -731,31 +731,20 @@ nsresult nsAbPalmHotSync::OpenABDBForHotSync(PRBool aCreate)
|
|||
if(NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsFileSpec* dbPath;
|
||||
rv = abSession->GetUserProfileDirectory(&dbPath);
|
||||
rv = abSession->GetUserProfileDirectory(getter_AddRefs(mABFile));
|
||||
if(NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
(*dbPath) += mFileName.get();
|
||||
|
||||
// get nsIFile for nsFileSpec from abSession, why use a obsolete class if not required!
|
||||
rv = NS_FileSpecToIFile(dbPath, getter_AddRefs(mABFile));
|
||||
if(NS_FAILED(rv))
|
||||
{
|
||||
delete dbPath;
|
||||
return rv;
|
||||
}
|
||||
mABFile->AppendNative(mFileName);
|
||||
|
||||
nsCOMPtr<nsIAddrDatabase> addrDBFactory =
|
||||
do_GetService(NS_ADDRDATABASE_CONTRACTID, &rv);
|
||||
if(NS_FAILED(rv))
|
||||
{
|
||||
delete dbPath;
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = addrDBFactory->Open(dbPath, aCreate, getter_AddRefs(mABDB), PR_TRUE);
|
||||
delete dbPath;
|
||||
rv = addrDBFactory->Open(mABFile, aCreate, PR_TRUE, getter_AddRefs(mABDB));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
mDBOpen = PR_TRUE; // Moz AB DB is now Open
|
||||
|
||||
|
@ -777,14 +766,10 @@ nsresult nsAbPalmHotSync::KeepCurrentStateAsPrevious()
|
|||
nsCOMPtr<nsIAddrBookSession> abSession = do_GetService(NS_ADDRBOOKSESSION_CONTRACTID, &rv);
|
||||
if(NS_FAILED(rv))
|
||||
return rv;
|
||||
nsFileSpec* dbPath;
|
||||
rv = abSession->GetUserProfileDirectory(&dbPath); // this still uses nsFileSpec!!!
|
||||
rv = abSession->GetUserProfileDirectory(getter_AddRefs(mPreviousABFile));
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
(*dbPath) += previousLeafName.get();
|
||||
// get nsIFile for nsFileSpec from abSession, why use a obsolete class if not required!
|
||||
rv = NS_FileSpecToIFile(dbPath, getter_AddRefs(mPreviousABFile));
|
||||
delete dbPath;
|
||||
mPreviousABFile->AppendNative(previousLeafName);
|
||||
if(NS_FAILED(rv))
|
||||
return rv;
|
||||
}
|
||||
|
|
|
@ -777,29 +777,31 @@ nsIAddrDatabase *GetAddressBook( const PRUnichar *name, PRBool makeNew)
|
|||
nsIAddrDatabase * pDatabase = nsnull;
|
||||
|
||||
/* Get the profile directory */
|
||||
// Note to Candice: This should return an nsIFileSpec, not a nsFileSpec
|
||||
nsFileSpec * dbPath = nsnull;
|
||||
nsCOMPtr<nsILocalFile> dbPath;
|
||||
|
||||
NS_WITH_PROXIED_SERVICE(nsIAddrBookSession, abSession, NS_ADDRBOOKSESSION_CONTRACTID, NS_UI_THREAD_EVENTQ, &rv);
|
||||
|
||||
if (NS_SUCCEEDED(rv))
|
||||
abSession->GetUserProfileDirectory(&dbPath);
|
||||
if (dbPath) {
|
||||
rv = abSession->GetUserProfileDirectory(getter_AddRefs(dbPath));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// Create a new address book file - we don't care what the file
|
||||
// name is, as long as it's unique
|
||||
(*dbPath) += "impab.mab";
|
||||
(*dbPath).MakeUnique();
|
||||
rv = dbPath->Append(NS_LITERAL_STRING("impab.mab"));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = dbPath->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0600);
|
||||
|
||||
IMPORT_LOG0( "Getting the address database factory\n");
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
IMPORT_LOG0( "Getting the address database factory\n");
|
||||
|
||||
NS_WITH_PROXIED_SERVICE(nsIAddrDatabase, addrDBFactory, NS_ADDRDATABASE_CONTRACTID, NS_UI_THREAD_EVENTQ, &rv);
|
||||
if (NS_SUCCEEDED(rv) && addrDBFactory) {
|
||||
|
||||
IMPORT_LOG0( "Opening the new address book\n");
|
||||
rv = addrDBFactory->Open( dbPath, PR_TRUE, &pDatabase, PR_TRUE);
|
||||
}
|
||||
NS_WITH_PROXIED_SERVICE(nsIAddrDatabase, addrDBFactory, NS_ADDRDATABASE_CONTRACTID, NS_UI_THREAD_EVENTQ, &rv);
|
||||
if (NS_SUCCEEDED(rv) && addrDBFactory) {
|
||||
IMPORT_LOG0( "Opening the new address book\n");
|
||||
rv = addrDBFactory->Open( dbPath, PR_TRUE, PR_TRUE, &pDatabase);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0( "Failed to get the user profile directory from the address book session\n");
|
||||
}
|
||||
|
||||
|
@ -829,15 +831,25 @@ nsIAddrDatabase *GetAddressBook( const PRUnichar *name, PRBool makeNew)
|
|||
rv = proxyMgr->GetProxyForObject( NS_UI_THREAD_EVENTQ, NS_GET_IID( nsIAbDirectory),
|
||||
parentResource, PROXY_SYNC | PROXY_ALWAYS, getter_AddRefs( parentDir));
|
||||
if (parentDir)
|
||||
{
|
||||
{
|
||||
nsCAutoString URI("moz-abmdbdirectory://");
|
||||
URI.Append((*dbPath).GetLeafName());
|
||||
parentDir->CreateDirectoryByURI(name, URI.get (), PR_FALSE);
|
||||
|
||||
delete dbPath;
|
||||
nsCAutoString leafName;
|
||||
rv = dbPath->GetNativeLeafName(leafName);
|
||||
if (NS_FAILED(rv)) {
|
||||
IMPORT_LOG0( "*** Error: Unable to get name of database file\n");
|
||||
}
|
||||
else {
|
||||
URI.Append(leafName);
|
||||
rv = parentDir->CreateDirectoryByURI(name, URI.get (), PR_FALSE);
|
||||
if (NS_FAILED(rv))
|
||||
IMPORT_LOG0( "*** Error: Unable to create address book directory\n");
|
||||
}
|
||||
}
|
||||
|
||||
IMPORT_LOG0( "Added new address book to the UI\n");
|
||||
if (NS_SUCCEEDED(rv))
|
||||
IMPORT_LOG0( "Added new address book to the UI\n");
|
||||
else
|
||||
IMPORT_LOG0( "*** Error: An error occurred while adding the address book to the UI\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче