Bug 132180 eliminate nsFileSpec in address book. Second patch of serveral. r=dmose,sr=bienvenu

This commit is contained in:
bugzilla%standard8.demon.co.uk 2005-08-26 14:47:31 +00:00
Родитель a8c190a4e1
Коммит 089264ae08
26 изменённых файлов: 174 добавлений и 261 удалений

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

@ -21,6 +21,7 @@
*
* Contributor(s):
* Seth Spitzer <sspitzer@netscape.com>
* Mark Banner <mark@standard8.demon.co.uk>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -40,10 +41,7 @@
#include "nsIAbCard.idl"
#include "nsISupportsArray.idl"
[ptr] native nsFileSpec(nsFileSpec);
%{C++
#include "nsFileSpec.h"
#include "nsDirPrefs.h"
%}

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

@ -1,47 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
#include "nsIFileSpec.idl"
[scriptable, uuid(abd6c760-f396-11d3-b9fa-00108335942a)]
interface nsIAbUpgrader : nsISupports {
void StartUpgrade4xAddrBook(in nsIFileSpec sourceAddrBook, in nsIFileSpec destAddrBook);
void ContinueExport(out boolean done);
attribute string currentCharset;
};

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

@ -21,6 +21,7 @@
*
* Contributor(s):
* Seth Spitzer <sspitzer@netscape.com>
* Mark Banner <mark@standard8.demon.co.uk>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -36,7 +37,6 @@
*
* ***** END LICENSE BLOCK ***** */
/* nsFileSpec is declared in nsIAbDirectory.idl */
#include "nsIAddrDBAnnouncer.idl"
#include "nsIAbCard.idl"
#include "nsIAbDirectory.idl"
@ -137,14 +137,34 @@ interface nsAddrDBCommitType
const long kCompressCommit = 3;
};
[scriptable, uuid(8175a7ce-4414-489e-ba29-b22d8c4a1cae)]
[scriptable, uuid(3c6e0a41-7f9d-4e46-a77e-cbeed22ed2be)]
interface nsIAddrDatabase : nsIAddrDBAnnouncer {
[noscript] attribute nsFileSpec dbPath;
/**
* Path to the address book database that this instance represents.
*/
attribute nsIFile dbPath;
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);
/**
* Open the MDB database synchronously creating it if required. If
* successful, this routine will set up the m_mdbStore and m_mdbEnv of the
* database object so other database calls can work.
*
* @param dbName The location of the database file
* to open.
* @param create If set to true, will create the
* database file if it does not
* already exist.
* @exception NS_ERROR_FILE_NOT_FOUND The file was not found at the
* specified location (and create was
* false).
* @exception NS_ERROR_FILE_ACCESS_DENIED The file could not be opened as
* access was denied.
*/
void openMDB(in nsIFile dbName, in boolean create);
void closeMDB(in boolean commit);
void commit(in unsigned long commitType);
@ -183,9 +203,9 @@ interface nsIAddrDatabase : nsIAddrDBAnnouncer {
void deleteCardFromMailList(in nsIAbDirectory mailList, in nsIAbCard card, in boolean aNotify);
readonly attribute wstring directoryName;
/**
* aUTF8Value needs to be in UTF-8
*/
/**
* aUTF8Value needs to be in UTF-8
*/
nsIAbCard getCardFromAttribute(in nsIAbDirectory directory, in string aName, in string aUTF8Value, in boolean caseInsensitive);
PRBool findMailListbyUnicodeName(in wstring listName);
@ -256,37 +276,36 @@ interface nsIAddrDatabase : nsIAddrDBAnnouncer {
[noscript] void addListDescription(in nsIMdbRow row, in string value);
[noscript] void addListDirNode(in nsIMdbRow listRow);
/**
* use for getting and setting generic string attributes
* like _AimScreenName
*/
void setCardValue(in nsIAbCard card, in string name, in wstring value, in boolean notify);
wstring getCardValue(in nsIAbCard card, in string name);
/**
* use for getting and setting generic string attributes
* like _AimScreenName
*/
void setCardValue(in nsIAbCard card, in string name, in wstring value, in boolean notify);
wstring getCardValue(in nsIAbCard card, in string name);
void getDeletedCardList(out unsigned long aCount, out nsISupportsArray aDeletedList);
void getDeletedCardCount(out unsigned long count);
void getDeletedCardList(out unsigned long aCount, out nsISupportsArray aDeletedList);
void getDeletedCardCount(out unsigned long count);
/**
* used for adding a string attributes to a row.
* used during LDIF and addressbook import.
*
* @param aRow
* The row we're adding the column to
* @param aLDIFAttributeName
* The column name (examples: mozillaCategory,
* mozilla_AimScreenName)
* @param aColValue
* The column value (example: jabroni316)
*/
[noscript] void addRowValue(in nsIMdbRow aRow, in ACString aLDIFAttributeName, in AString aColValue);
void AddListCardColumnsToRow(in nsIAbCard aPCard,
in nsIMdbRow aPListRow,
in unsigned long aPos,
out nsIAbCard aPNewCard,
in boolean aInMailingList);
void InitCardFromRow(in nsIAbCard aNewCard,in nsIMdbRow aCardRow);
void SetListAddressTotal(in nsIMdbRow aListRow, in PRUint32 aTotal);
nsIMdbRow FindRowByCard(in nsIAbCard aCard);
/**
* used for adding a string attributes to a row.
* used during LDIF and addressbook import.
*
* @param aRow
* The row we're adding the column to
* @param aLDIFAttributeName
* The column name (examples: mozillaCategory,
* mozilla_AimScreenName)
* @param aColValue
* The column value (example: jabroni316)
*/
[noscript] void addRowValue(in nsIMdbRow aRow, in ACString aLDIFAttributeName, in AString aColValue);
void AddListCardColumnsToRow(in nsIAbCard aPCard,
in nsIMdbRow aPListRow,
in unsigned long aPos,
out nsIAbCard aPNewCard,
in boolean aInMailingList);
void InitCardFromRow(in nsIAbCard aNewCard,in nsIMdbRow aCardRow);
void SetListAddressTotal(in nsIMdbRow aListRow, in PRUint32 aTotal);
nsIMdbRow FindRowByCard(in nsIAbCard aCard);
};

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

@ -23,6 +23,7 @@
* Paul Sandoz <paul.sandoz@sun.com>
* Csaba Borbola <csaba.borbola@sun.com>
* Seth Spitzer <sspitzer@netscape.com>
* Mark Banner <mark@standard8.demon.co.uk>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -56,6 +57,7 @@
#include "nsAbDirFactoryService.h"
#include "nsAbMDBDirFactory.h"
#include "nsArrayEnumerator.h"
#include "nsCRT.h"
nsAbBSDirectory::nsAbBSDirectory()
: nsRDFResource(),

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

@ -22,6 +22,7 @@
* Contributor(s):
* Seth Spitzer <sspitzer@netscape.com>
* Pierre Phaneuf <pp@ludusdesign.com>
* Mark Banner <mark@standard8.demon.co.uk>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -50,7 +51,7 @@
#include "plbase64.h"
#include "nsIAddrBookSession.h"
#include "nsIStringBundle.h"
#include "plstr.h"
#include "nsIRDFResource.h"
#include "nsIRDFService.h"
#include "nsRDFCID.h"

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

@ -20,6 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mark Banner <mark@standard8.demon.co.uk>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -47,6 +48,7 @@
#include "nsIAbCard.h"
#include "nsCOMPtr.h"
#include "nsIAddressBook.h"
#include "nsString.h"
class mozITXTToHTMLConv;
struct AppendItem;

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

@ -21,6 +21,7 @@
*
* Contributor(s):
* Seth Spitzer <sspitzer@netscape.com>
* Mark Banner <mark@standard8.demon.co.uk>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -51,6 +52,7 @@
#include "nsCOMPtr.h"
#include "nsDirPrefs.h"
#include "nsIAddrDatabase.h"
#include "nsString.h"
/*
* Address Book Directory

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

@ -21,6 +21,7 @@
* Contributor(s):
* Rajiv Dayal <rdayal@netscape.com>
* Dan Mosedale <dan.mosedale@oracle.com>
* Mark Banner <mark@standard8.demon.co.uk>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -52,6 +53,7 @@
#include "nsIStringBundle.h"
#include "nsIWindowWatcher.h"
#include "nsUnicharUtils.h"
#include "plstr.h"
// defined here since to be used
// only locally to this file.

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

@ -23,6 +23,7 @@
* Seth Spitzer <sspitzer@netscape.com>
* Dan Mosedale <dmose@netscape.com>
* Paul Sandoz <paul.sandoz@sun.com>
* Mark Banner <mark@standard8.demon.co.uk>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -45,6 +46,7 @@
#include "nsAbBaseCID.h"
#include "nsIAddrBookSession.h"
#include "nsIRDFService.h"
#include "nsIServiceManager.h"
#include "nsString.h"
#include "nsXPIDLString.h"

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

@ -23,6 +23,7 @@
* Seth Spitzer <sspitzer@netscape.com>
* Dan Mosedale <dmose@netscape.com>
* Paul Sandoz <paul.sandoz@sun.com>
* Mark Banner <mark@standard8.demon.co.uk>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -53,9 +54,11 @@
#include "nsAutoLock.h"
#include "nsIProxyObjectManager.h"
#include "prprf.h"
#include "nsCRT.h"
#include "nsIWindowWatcher.h"
#include "nsIDOMWindow.h"
#include "nsICategoryManager.h"
#include "nsIServiceManager.h"
#include "nsCategoryManagerUtils.h"
#include "nsAbLDAPDirectory.h"

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

@ -21,6 +21,7 @@
*
* Contributor(s):
* Dan Mosedale <dan.mosedale@oracle.com>
* Mark Banner <mark@standard8.demon.co.uk>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -47,6 +48,7 @@
#include "nsILocalFile.h"
#include "nsDirPrefs.h"
#include "nsIAbLDAPAttributeMap.h"
#include "nsString.h"
class nsAbLDAPProcessReplicationData : public nsIAbLDAPProcessReplicationData
{

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

@ -22,6 +22,7 @@
*
* Contributor(s):
* Dan Mosedale <dmose@netscape.com>
* Mark Banner <mark@standard8.demon.co.uk>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -48,7 +49,7 @@
#include "nsLDAP.h"
#include "nsAbUtils.h"
#include "nsDirPrefs.h"
#include "nsCRT.h"
NS_IMPL_ISUPPORTS1(nsAbLDAPReplicationQuery, nsIAbLDAPReplicationQuery)

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

@ -20,6 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mark Banner <mark@standard8.demon.co.uk>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -48,6 +49,7 @@
#include "nsAddrDatabase.h"
#include "nsIAddrBookSession.h"
#include "nsIAddressBook.h"
#include "nsILocalFile.h"
nsAbMDBCardProperty::nsAbMDBCardProperty(void)
{

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

@ -23,6 +23,7 @@
* Paul Sandoz <paul.sandoz@sun.com>
* Csaba Borbola <csaba.borbola@sun.com>
* Seth Spitzer <sspitzer@netscape.com>
* Mark Banner <mark@standard8.demon.co.uk>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -44,6 +45,8 @@
#include "nsIRDFService.h"
#include "nsIRDFResource.h"
#include "nsRDFResource.h"
#include "nsIServiceManager.h"
#include "nsILocalFile.h"
#include "nsIAbMDBDirectory.h"
#include "nsAbDirFactoryService.h"

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

@ -21,6 +21,7 @@
*
* Contributor(s):
* Seth Spitzer <sspitzer@netscape.com>
* Mark Banner <mark@standard8.demon.co.uk>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -41,7 +42,8 @@
#include "nsIPrefBranch.h"
#include "nsIAddrBookSession.h"
#include "nsAbBaseCID.h"
#include "nsServiceManagerUtils.h"
#include "nsCRT.h"
#include "prlog.h"
#ifdef PR_LOGGING

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

@ -21,6 +21,7 @@
*
* Contributor(s):
* Created by Cyrille Moureaux <Cyrille.Moureaux@sun.com>
* Mark Banner <mark@standard8.demon.co.uk>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -43,6 +44,7 @@
#include "nsIRDFResource.h"
#include "nsRDFResource.h"
#include "nsEnumeratorUtils.h"
#include "nsServiceManagerUtils.h"
#include "nsAbBaseCID.h"

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

@ -21,6 +21,7 @@
*
* Contributor(s):
* Created by Cyrille Moureaux <Cyrille.Moureaux@sun.com>
* Mark Banner <mark@standard8.demon.co.uk>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -51,6 +52,8 @@
#include "nsAbUtils.h"
#include "nsIProxyObjectManager.h"
#include "nsEnumeratorUtils.h"
#include "nsServiceManagerUtils.h"
#include "nsCRT.h"
#include "prlog.h"
#include "prthread.h"

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

@ -21,6 +21,7 @@
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
* Mark Banner <mark@standard8.demon.co.uk>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -55,6 +56,7 @@
#include "nsCOMPtr.h"
#include "nsXPIDLString.h"
#include "nsAutoLock.h"
#include "nsIServiceManager.h"
// this is used for notification of observers using nsVoidArray
typedef struct _nsAbRDFNotification {

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

@ -21,6 +21,7 @@
*
* Contributor(s):
* Paul Sandoz <paul.sandoz@sun.com>
* Mark Banner <mark@standard8.demon.co.uk>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -51,6 +52,7 @@
#include "nsXPCOM.h"
#include "nsISupportsPrimitives.h"
#include "nsITreeColumns.h"
#include "nsCRT.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch2.h"

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

@ -21,6 +21,7 @@
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
* Mark Banner <mark@standard8.demon.co.uk>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -389,7 +390,7 @@ nsAddrDatabase::CleanupCache()
//----------------------------------------------------------------------
// FindInCache - this addrefs the db it finds.
//----------------------------------------------------------------------
nsAddrDatabase* nsAddrDatabase::FindInCache(nsFileSpec *dbName)
nsAddrDatabase* nsAddrDatabase::FindInCache(nsIFile *dbName)
{
PRInt32 i;
for (i = 0; i < GetDBCache()->Count(); i++)
@ -420,9 +421,15 @@ PRInt32 nsAddrDatabase::FindInCache(nsAddrDatabase* pAddrDB)
return(-1);
}
PRBool nsAddrDatabase::MatchDbName(nsFileSpec* dbName) // returns PR_TRUE if they match
PRBool nsAddrDatabase::MatchDbName(nsIFile* dbName) // returns PR_TRUE if they match
{
return (m_dbName == (*dbName));
PRBool dbMatches = PR_FALSE;
nsresult rv = m_dbName->Equals(dbName, &dbMatches);
if (NS_FAILED(rv))
return PR_FALSE;
return dbMatches;
}
//----------------------------------------------------------------------
@ -451,100 +458,18 @@ nsIMdbFactory *nsAddrDatabase::GetMDBFactory()
return gMDBFactory;
}
#if defined(XP_WIN) || defined(XP_OS2)
// this code is stolen from nsFileSpecWin. Since MDB requires a native path, for
// the time being, we'll just take the Unix/Canonical form and munge it
void nsAddrDatabase::UnixToNative(char*& ioPath)
// This just does string manipulation. It doesn't check reality, or canonify, or
// anything
//----------------------------------------------------------------------------------------
{
// Allow for relative or absolute. We can do this in place, because the
// native path is never longer.
if (!ioPath || !*ioPath)
return;
char* src = ioPath;
if (*ioPath == '/')
{
// Strip initial slash for an absolute path
src++;
}
// Convert the vertical slash to a colon
char* cp = src + 1;
// If it was an absolute path, check for the drive letter
if (*ioPath == '/' && strstr(cp, "|/") == cp)
*cp = ':';
// Convert '/' to '\'.
while (*++cp)
{
if (*cp == '/')
*cp = '\\';
}
if (*ioPath == '/') {
for (cp = ioPath; *cp; ++cp)
*cp = *(cp + 1);
}
}
#endif /* XP_WIN || XP_OS2 */
#ifdef XP_MAC
// this code is stolen from nsFileSpecMac. Since MDB requires a native path, for
// the time being, we'll just take the Unix/Canonical form and munge it
void nsAddrDatabase::UnixToNative(char*& ioPath)
// This just does string manipulation. It doesn't check reality, or canonify, or
// anything
//----------------------------------------------------------------------------------------
{
// Relying on the fact that the unix path is always longer than the mac path:
size_t len = strlen(ioPath);
char* result = new char[len + 2]; // ... but allow for the initial colon in a partial name
if (result)
{
char* dst = result;
const char* src = ioPath;
if (*src == '/') // * full path
src++;
else if (PL_strchr(src, '/')) // * partial path, and not just a leaf name
*dst++ = ':';
strcpy(dst, src);
while ( *dst != 0)
{
if (*dst == '/')
*dst++ = ':';
else
*dst++;
}
nsCRT::free(ioPath);
ioPath = result;
}
}
#endif /* XP_MAC */
/* caller need to delete *aDbPath */
NS_IMETHODIMP nsAddrDatabase::GetDbPath(nsFileSpec * *aDbPath)
NS_IMETHODIMP nsAddrDatabase::GetDbPath(nsIFile* *aDbPath)
{
if (!aDbPath)
return NS_ERROR_NULL_POINTER;
nsFileSpec* pFilePath = new nsFileSpec();
if (!pFilePath)
return NS_ERROR_OUT_OF_MEMORY;
*pFilePath = m_dbName;
*aDbPath = pFilePath;
return NS_OK;
return m_dbName->Clone(aDbPath);
}
NS_IMETHODIMP nsAddrDatabase::SetDbPath(nsFileSpec * aDbPath)
NS_IMETHODIMP nsAddrDatabase::SetDbPath(nsIFile* aDbPath)
{
m_dbName = (*aDbPath);
return NS_OK;
return aDbPath->Clone(getter_AddRefs(m_dbName));
}
NS_IMETHODIMP nsAddrDatabase::Open
@ -552,23 +477,14 @@ NS_IMETHODIMP nsAddrDatabase::Open
{
*pAddrDB = nsnull;
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 = FindInCache(aMabFile);
nsAddrDatabase *pAddressBookDB = (nsAddrDatabase *) FindInCache(&mabFileSpec);
if (pAddressBookDB) {
*pAddrDB = pAddressBookDB;
return NS_OK;
}
rv = OpenInternal(&mabFileSpec, aCreate, pAddrDB);
nsresult rv = OpenInternal(aMabFile, aCreate, pAddrDB);
if (NS_SUCCEEDED(rv))
return NS_OK;
@ -579,9 +495,10 @@ NS_IMETHODIMP nsAddrDatabase::Open
if (!gAlreadyAlerted)
{
gAlreadyAlerted = PR_TRUE;
nsXPIDLCString mabFileName;
mabFileName.Adopt(mabFileSpec.GetLeafName());
AlertAboutLockedMabFile(NS_ConvertASCIItoUCS2(mabFileName).get());
nsAutoString mabFileName;
rv = aMabFile->GetLeafName(mabFileName);
NS_ENSURE_SUCCESS(rv, rv);
AlertAboutLockedMabFile(mabFileName.get());
}
}
// try one more time
@ -636,27 +553,17 @@ NS_IMETHODIMP nsAddrDatabase::Open
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to rename corrupt mab file");
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIFileSpec> newMabIFileSpec;
nsFileSpec newMabFileSpec;
// Convert the nsILocalFile into an nsIFileSpec
// TODO: convert users of nsIFileSpec to nsILocalFile
// and avoid this step.
nsresult rv = NS_NewFileSpecFromIFile(aMabFile, getter_AddRefs(newMabIFileSpec));
NS_ENSURE_SUCCESS(rv, rv);
rv = newMabIFileSpec->GetFileSpec(&newMabFileSpec);
NS_ENSURE_SUCCESS(rv, rv);
rv = OpenInternal(&newMabFileSpec, aCreate, pAddrDB);
// now we can try to recreate the original mab file
rv = OpenInternal(aMabFile, aCreate, pAddrDB);
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to create .mab file, after rename");
if (NS_SUCCEEDED(rv)) {
nsCAutoString originalMabFileName;
rv = aMabFile->GetNativeLeafName(originalMabFileName);
nsAutoString originalMabFileName;
rv = aMabFile->GetLeafName(originalMabFileName);
NS_ENSURE_SUCCESS(rv, rv);
// if this fails, we don't care
(void)AlertAboutCorruptMabFile(NS_ConvertASCIItoUCS2(originalMabFileName).get(),
(void)AlertAboutCorruptMabFile(originalMabFileName.get(),
NS_ConvertASCIItoUCS2(backupMabFileName).get());
}
}
@ -705,7 +612,7 @@ nsresult nsAddrDatabase::AlertAboutLockedMabFile(const PRUnichar *aFileName)
}
nsresult
nsAddrDatabase::OpenInternal(nsFileSpec *aMabFile, PRBool aCreate, nsIAddrDatabase** pAddrDB)
nsAddrDatabase::OpenInternal(nsIFile *aMabFile, PRBool aCreate, nsIAddrDatabase** pAddrDB)
{
nsAddrDatabase *pAddressBookDB = new nsAddrDatabase();
if (!pAddressBookDB) {
@ -734,7 +641,7 @@ nsAddrDatabase::OpenInternal(nsFileSpec *aMabFile, PRBool aCreate, nsIAddrDataba
// Open the MDB database synchronously. If successful, this routine
// will set up the m_mdbStore and m_mdbEnv of the database object
// so other database calls can work.
NS_IMETHODIMP nsAddrDatabase::OpenMDB(nsFileSpec *dbName, PRBool create)
NS_IMETHODIMP nsAddrDatabase::OpenMDB(nsIFile *dbName, PRBool create)
{
nsresult ret = NS_OK;
nsIMdbFactory *myMDBFactory = GetMDBFactory();
@ -744,21 +651,22 @@ NS_IMETHODIMP nsAddrDatabase::OpenMDB(nsFileSpec *dbName, PRBool create)
if (NS_SUCCEEDED(ret))
{
nsIMdbThumb *thumb = nsnull;
const char *pFilename = dbName->GetCString(); /* do not free */
char *nativeFileName = nsCRT::strdup(pFilename);
nsCAutoString filePath;
ret = dbName->GetNativePath(filePath);
NS_ENSURE_SUCCESS(ret, ret);
nsIMdbHeap* dbHeap = 0;
mdb_bool dbFrozen = mdbBool_kFalse; // not readonly, we want modifiable
if (!nativeFileName)
return NS_ERROR_OUT_OF_MEMORY;
if (m_mdbEnv)
m_mdbEnv->SetAutoClear(PR_TRUE);
#if defined(XP_WIN) || defined(XP_OS2) || defined(XP_MAC)
UnixToNative(nativeFileName);
#endif
if (!dbName->Exists())
PRBool dbNameExists = PR_FALSE;
ret = dbName->Exists(&dbNameExists);
NS_ENSURE_SUCCESS(ret, ret);
if (!dbNameExists)
ret = NS_ERROR_FILE_NOT_FOUND;
else
{
@ -766,9 +674,11 @@ NS_IMETHODIMP nsAddrDatabase::OpenMDB(nsFileSpec *dbName, PRBool create)
mdb_bool canOpen;
mdbYarn outFormatVersion;
nsIMdbFile* oldFile = 0;
PRBool isEmptyFile = !dbName->GetFileSize();
PRInt64 fileSize;
ret = dbName->GetFileSize(&fileSize);
NS_ENSURE_SUCCESS(ret, ret);
ret = myMDBFactory->OpenOldFile(m_mdbEnv, dbHeap, nativeFileName,
ret = myMDBFactory->OpenOldFile(m_mdbEnv, dbHeap, filePath.get(),
dbFrozen, &oldFile);
if ( oldFile )
{
@ -785,7 +695,7 @@ NS_IMETHODIMP nsAddrDatabase::OpenMDB(nsFileSpec *dbName, PRBool create)
ret = myMDBFactory->OpenFileStore(m_mdbEnv, dbHeap,
oldFile, &inOpenPolicy, &thumb);
}
else if (!isEmptyFile)
else if (fileSize != 0)
ret = NS_ERROR_FILE_ACCESS_DENIED;
}
NS_RELEASE(oldFile); // always release our file ref, store has own
@ -794,8 +704,6 @@ NS_IMETHODIMP nsAddrDatabase::OpenMDB(nsFileSpec *dbName, PRBool create)
ret = NS_ERROR_FILE_ACCESS_DENIED;
}
nsCRT::free(nativeFileName);
if (NS_SUCCEEDED(ret) && thumb)
{
mdb_count outTotal; // total somethings to do in operation
@ -825,7 +733,7 @@ NS_IMETHODIMP nsAddrDatabase::OpenMDB(nsFileSpec *dbName, PRBool create)
else if (create && ret != NS_ERROR_FILE_ACCESS_DENIED)
{
nsIMdbFile* newFile = 0;
ret = myMDBFactory->CreateNewFile(m_mdbEnv, dbHeap, dbName->GetCString(), &newFile);
ret = myMDBFactory->CreateNewFile(m_mdbEnv, dbHeap, filePath.get(), &newFile);
if ( newFile )
{
if (ret == NS_OK)
@ -3465,9 +3373,11 @@ nsresult nsAddrDatabase::CreateABListCard(nsIMdbRow* listRow, nsIAbCard **result
rowID = outOid.mOid_Id;
char* listURI = nsnull;
char* file = nsnull;
file = m_dbName.GetLeafName();
listURI = PR_smprintf("%s%s/MailList%ld", kMDBDirectoryRoot, file, rowID);
nsAutoString fileName;
rv = m_dbName->GetLeafName(fileName);
NS_ENSURE_SUCCESS(rv, rv);
listURI = PR_smprintf("%s%s/MailList%ld", kMDBDirectoryRoot, NS_ConvertUCS2toUTF8(fileName).get(), rowID);
nsCOMPtr<nsIAbCard> personCard;
nsCOMPtr<nsIAbMDBDirectory> dbm_dbDirectory(do_QueryInterface(m_dbDirectory, &rv));
@ -3495,8 +3405,6 @@ nsresult nsAddrDatabase::CreateABListCard(nsIMdbRow* listRow, nsIAbCard **result
NS_IF_ADDREF(*result = personCard);
}
if (file)
nsCRT::free(file);
if (listURI)
PR_smprintf_free(listURI);
@ -3518,10 +3426,12 @@ nsresult nsAddrDatabase::CreateABList(nsIMdbRow* listRow, nsIAbDirectory **resul
rowID = outOid.mOid_Id;
char* listURI = nsnull;
char* file = nsnull;
file = m_dbName.GetLeafName();
listURI = PR_smprintf("%s%s/MailList%ld", kMDBDirectoryRoot, file, rowID);
nsAutoString fileName;
m_dbName->GetLeafName(fileName);
NS_ENSURE_SUCCESS(rv, rv);
listURI = PR_smprintf("%s%s/MailList%ld", kMDBDirectoryRoot, NS_ConvertUCS2toUTF8(fileName).get(), rowID);
nsCOMPtr<nsIAbDirectory> mailList;
nsCOMPtr<nsIAbMDBDirectory> dbm_dbDirectory(do_QueryInterface(m_dbDirectory, &rv));
@ -3554,8 +3464,6 @@ nsresult nsAddrDatabase::CreateABList(nsIMdbRow* listRow, nsIAbDirectory **resul
}
}
if (file)
nsCRT::free(file);
if (listURI)
PR_smprintf_free(listURI);
@ -3655,9 +3563,13 @@ NS_IMETHODIMP nsAddrDatabase::AddListDirNode(nsIMdbRow * listRow)
{
nsCOMPtr<nsIRDFResource> parentResource;
char* file = m_dbName.GetLeafName();
char *parentUri = PR_smprintf("%s%s", kMDBDirectoryRoot, file);
rv = rdfService->GetResource(nsDependentCString(parentUri), getter_AddRefs(parentResource));
nsAutoString parentURI;
rv = m_dbName->GetLeafName(parentURI);
NS_ENSURE_SUCCESS(rv, rv);
parentURI = NS_LITERAL_STRING(kMDBDirectoryRoot) + parentURI;
rv = rdfService->GetResource(NS_ConvertUCS2toUTF8(parentURI), getter_AddRefs(parentResource));
nsCOMPtr<nsIAbDirectory> parentDir;
rv = proxyMgr->GetProxyForObject( NS_UI_THREAD_EVENTQ, NS_GET_IID( nsIAbDirectory),
parentResource, PROXY_SYNC | PROXY_ALWAYS, getter_AddRefs( parentDir));
@ -3673,10 +3585,6 @@ NS_IMETHODIMP nsAddrDatabase::AddListDirNode(nsIMdbRow * listRow)
dbparentDir->NotifyDirItemAdded(mailList);
}
}
if (parentUri)
PR_smprintf_free(parentUri);
if (file)
nsCRT::free(file);
}
return rv;
}

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

@ -21,6 +21,7 @@
*
* Contributor(s):
* Seth Spitzer <sspitzer@netscape.com>
* Mark Banner <mark@standard8.demon.co.uk>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -43,7 +44,6 @@
#include "mdb.h"
#include "nsVoidArray.h"
#include "nsString.h"
#include "nsFileSpec.h"
#include "nsIAddrDBListener.h"
#include "nsISupportsArray.h"
#include "nsCOMPtr.h"
@ -74,11 +74,11 @@ public:
//////////////////////////////////////////////////////////////////////////////
// nsIAddrDatabase methods:
NS_IMETHOD GetDbPath(nsFileSpec * *aDbPath);
NS_IMETHOD SetDbPath(nsFileSpec * aDbPath);
NS_IMETHOD GetDbPath(nsIFile * *aDbPath);
NS_IMETHOD SetDbPath(nsIFile * aDbPath);
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 OpenMDB(nsIFile *dbName, PRBool create);
NS_IMETHOD CloseMDB(PRBool commit);
NS_IMETHOD Commit(PRUint32 commitType);
NS_IMETHOD ForceClosed();
@ -301,7 +301,7 @@ public:
nsIMdbTableRowCursor *GetTableRowCursor();
nsIMdbTable *GetPabTable() {return m_mdbPabTable;}
static nsAddrDatabase* FindInCache(nsFileSpec *dbName);
static nsAddrDatabase* FindInCache(nsIFile *dbName);
static void CleanupCache();
@ -328,12 +328,7 @@ protected:
static void AddToCache(nsAddrDatabase* pAddrDB) {GetDBCache()->AppendElement(pAddrDB);}
static void RemoveFromCache(nsAddrDatabase* pAddrDB);
static PRInt32 FindInCache(nsAddrDatabase* pAddrDB);
PRBool MatchDbName(nsFileSpec *dbName); // returns TRUE if they match
#if defined(XP_WIN) || defined(XP_OS2) || defined(XP_MAC) // this should go away when we can provide our own file stream to MDB/Mork
static void UnixToNative(char*& ioPath);
#endif
PRBool MatchDbName(nsIFile *dbName); // returns TRUE if they match
void YarnToUInt32(struct mdbYarn *yarn, PRUint32 *pResult);
void GetCharStringYarn(char* str, struct mdbYarn* strYarn);
@ -389,7 +384,7 @@ protected:
nsIMdbStore *m_mdbStore;
nsIMdbTable *m_mdbPabTable;
nsIMdbTable *m_mdbDeletedCardsTable;
nsFileSpec m_dbName;
nsCOMPtr<nsIFile> m_dbName;
PRBool m_mdbTokensInitialized;
nsVoidArray /*<nsIAddrDBListener>*/ *m_ChangeListeners;
@ -475,7 +470,7 @@ protected:
private:
nsresult GetRowForCharColumn(const PRUnichar *unicodeStr, mdb_column findColumn, PRBool bIsCard, nsIMdbRow **findRow);
PRBool HasRowButDeletedForCharColumn(const PRUnichar *unicodeStr, mdb_column findColumn, PRBool aIsCard, nsIMdbRow **aFindRow);
nsresult OpenInternal(nsFileSpec *aMabFile, PRBool aCreate, nsIAddrDatabase **pCardDB);
nsresult OpenInternal(nsIFile *aMabFile, PRBool aCreate, nsIAddrDatabase **pCardDB);
nsresult AlertAboutCorruptMabFile(const PRUnichar *aOldFileName, const PRUnichar *aNewFileName);
nsresult AlertAboutLockedMabFile(const PRUnichar *aFileName);
nsresult DisplayAlert(const PRUnichar *titleName, const PRUnichar *alertStringName,

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

@ -22,6 +22,7 @@
* Contributor(s):
* Seth Spitzer <sspitzer@netscape.com>
* Pierre Phaneuf <pp@ludusdesign.com>
* Mark Banner <mark@standard8.demon.co.uk>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -86,7 +87,7 @@
#include "nsIDocShell.h"
#include "nsAutoPtr.h"
#include "nsIMsgVCardService.h"
#include "nsIFileSpec.h"
#include "nsCRT.h"
#ifdef MOZ_XUL_APP

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

@ -22,6 +22,7 @@
* Contributor(s):
* Seth Spitzer <sspitzer@netscape.com>
* Dan Mosedale <dmose@mozilla.org>
* Mark Banner <mark@standard8.demon.co.uk>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -51,6 +52,8 @@
#include "nsIAbUpgrader.h"
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#include "nsCRT.h"
#include "nsILocalFile.h"
#include "prlog.h"
#include "plstr.h"

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

@ -58,6 +58,8 @@
#include "nsILocaleService.h"
#include "nsCollationCID.h"
#include "prmem.h"
#include "nsServiceManagerUtils.h"
#include "nsCRT.h"
static NS_DEFINE_CID(kCollationFactoryCID, NS_COLLATIONFACTORY_CID);

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

@ -20,6 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mark Banner <mark@standard8.demon.co.uk>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
@ -131,8 +132,8 @@ they will use an appropriately defined local type |vwchar_t|.
#endif
#include "prtypes.h"
#include "nsFileSpec.h"
class nsFileSpec;
class nsOutputFileStream;
PR_BEGIN_EXTERN_C

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

@ -21,6 +21,7 @@
*
* Contributor(s):
* Rajiv Dayal <rdayal@netscape.com>
* Mark Banner <mark@standard8.demon.co.uk>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -280,14 +281,13 @@ nsresult nsAbPalmHotSync::AddAllRecordsToAB(PRBool existingAB, PRInt32 aCount, l
rv = OpenABDBForHotSync(PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv);
// lets try deleting the db out from under ourselves.
nsFileSpec *abFileSpec;
rv = mABDB->GetDbPath(&abFileSpec);
nsCOMPtr<nsIFile> abFile;
rv = mABDB->GetDbPath(getter_AddRefs(abFile));
NS_ENSURE_SUCCESS(rv, rv);
mABDB->ForceClosed();
mDBOpen = PR_FALSE;
mABDB = nsnull;
abFileSpec->Delete(PR_FALSE);
delete abFileSpec;
abFile->Remove(PR_FALSE);
}
else
{