From ab9e14c3c8b51f6e69bd1445de29da668d491406 Mon Sep 17 00:00:00 2001 From: "tonyr%fbdesigns.com" Date: Thu, 3 Feb 2000 00:48:49 +0000 Subject: [PATCH] Fixed progress reporting for mail import --- mailnews/import/oexpress/WabObject.cpp | 25 ++++++++++++++++++-- mailnews/import/oexpress/WabObject.h | 2 +- mailnews/import/oexpress/nsOE5File.cpp | 13 +++++++---- mailnews/import/oexpress/nsOE5File.h | 2 +- mailnews/import/oexpress/nsOEImport.cpp | 21 +++++++++++------ mailnews/import/oexpress/nsOEMailbox.cpp | 29 ++++++++++++++---------- mailnews/import/oexpress/nsOEMailbox.h | 2 +- 7 files changed, 66 insertions(+), 28 deletions(-) diff --git a/mailnews/import/oexpress/WabObject.cpp b/mailnews/import/oexpress/WabObject.cpp index 9e974dc0b6be..62a015432156 100644 --- a/mailnews/import/oexpress/WabObject.cpp +++ b/mailnews/import/oexpress/WabObject.cpp @@ -182,7 +182,7 @@ CWAB::~CWAB() } -HRESULT CWAB::IterateWABContents(CWabIterator *pIter) +HRESULT CWAB::IterateWABContents(CWabIterator *pIter, int *pDone) { if (!m_bInitialized || !m_lpAdrBook) return( E_FAIL); @@ -199,6 +199,8 @@ HRESULT CWAB::IterateWABContents(CWabIterator *pIter) ULONG lpcbEID = 0; LPENTRYID lpEID = NULL; + ULONG rowCount = 0; + ULONG curCount = 0; // Get the entryid of the root PAB container // @@ -234,6 +236,12 @@ HRESULT CWAB::IterateWABContents(CWabIterator *pIter) if(HR_FAILED(hr)) goto exit; + + hr = lpAB->GetRowCount( 0, &rowCount); + if (HR_FAILED(hr)) + rowCount = 100; + if (rowCount == 0) + rowCount = 1; // Order the columns in the ContentsTable to conform to the // ones we want - which are mainly DisplayName, EntryID and @@ -286,10 +294,17 @@ HRESULT CWAB::IterateWABContents(CWabIterator *pIter) // us to uniquely identify the object later if we need to // keepGoing = pIter->EnumUser( lpsz, lpEID, cbEID); + curCount++; + if (pDone) { + *pDone = (curCount * 100) / rowCount; + if (*pDone > 100) + *pDone = 100; + } } } FreeProws(lpRowAB ); } + } while ( SUCCEEDED(hr) && cNumRows && lpRowAB && keepGoing) ; @@ -330,7 +345,13 @@ HRESULT CWAB::IterateWABContents(CWabIterator *pIter) // us to uniquely identify the object later if we need to // keepGoing = pIter->EnumList( lpsz, lpEID, cbEID); - } + curCount++; + if (pDone) { + *pDone = (curCount * 100) / rowCount; + if (*pDone > 100) + *pDone = 100; + } + } } FreeProws(lpRowAB ); } diff --git a/mailnews/import/oexpress/WabObject.h b/mailnews/import/oexpress/WabObject.h index b0c25bc51d2c..35602addbbfc 100644 --- a/mailnews/import/oexpress/WabObject.h +++ b/mailnews/import/oexpress/WabObject.h @@ -47,7 +47,7 @@ public: PRBool Loaded( void) { return( m_bInitialized);} - HRESULT IterateWABContents(CWabIterator *pIter); + HRESULT IterateWABContents(CWabIterator *pIter, int *pDone); // Methods for User entries LPDISTLIST GetDistList( ULONG cbEid, LPENTRYID pEid); diff --git a/mailnews/import/oexpress/nsOE5File.cpp b/mailnews/import/oexpress/nsOE5File.cpp index c5fb801e41c3..266a73d5b1fa 100644 --- a/mailnews/import/oexpress/nsOE5File.cpp +++ b/mailnews/import/oexpress/nsOE5File.cpp @@ -25,7 +25,7 @@ #include "OEDebugLog.h" -#define kIndexGrowBy 50 +#define kIndexGrowBy 100 #define kSignatureSize 12 #define kDontSeek 0xFFFFFFFF @@ -221,7 +221,7 @@ PRBool nsOE5File::IsFromLine( char *pLine, PRUint32 len) #define kMailboxBufferSize 0x4000 const char *nsOE5File::m_pFromLineSep = "From ????@???? 1 Jan 1965 00:00:00\x0D\x0A"; -nsresult nsOE5File::ImportMailbox( PRBool *pAbort, nsString& name, nsIFileSpec *inFile, nsIFileSpec *pDestination, PRInt32 *pCount) +nsresult nsOE5File::ImportMailbox( PRUint32 *pBytesDone, PRBool *pAbort, nsString& name, nsIFileSpec *inFile, nsIFileSpec *pDestination, PRUint32 *pCount) { nsresult rv; PRInt32 msgCount = 0; @@ -271,6 +271,7 @@ nsresult nsOE5File::ImportMailbox( PRBool *pAbort, nsString& name, nsIFileSpec * proceeding to the next message. */ + PRUint32 didBytes = 0; char last2[2] = {0, 0}; PRUint32 next; rv = NS_OK; @@ -294,6 +295,7 @@ nsresult nsOE5File::ImportMailbox( PRBool *pAbort, nsString& name, nsIFileSpec * last2[1] = 0; } rv = WriteMessageBuffer( pDestination, pBuffer, block[2], last2); + didBytes += block[2]; if (NS_FAILED( rv)) break; next = block[3]; @@ -304,6 +306,7 @@ nsresult nsOE5File::ImportMailbox( PRBool *pAbort, nsString& name, nsIFileSpec * (ReadBytes( inFile, pBuffer, kDontSeek, block[2]))) { if (block[2]) rv = WriteMessageBuffer( pDestination, pBuffer, block[2], last2); + didBytes += block[2]; if (NS_FAILED( rv)) break; next = block[3]; @@ -325,6 +328,10 @@ nsresult nsOE5File::ImportMailbox( PRBool *pAbort, nsString& name, nsIFileSpec * } msgCount++; + if (pCount) + *pCount = msgCount; + if (pBytesDone) + *pBytesDone = didBytes; } else { // Error reading message, should this be logged??? @@ -338,8 +345,6 @@ nsresult nsOE5File::ImportMailbox( PRBool *pAbort, nsString& name, nsIFileSpec * inFile->CloseStream(); pDestination->CloseStream(); - if (pCount) - *pCount = msgCount; return( rv); } diff --git a/mailnews/import/oexpress/nsOE5File.h b/mailnews/import/oexpress/nsOE5File.h index 777cf1c478c8..51510d673466 100644 --- a/mailnews/import/oexpress/nsOE5File.h +++ b/mailnews/import/oexpress/nsOE5File.h @@ -36,7 +36,7 @@ public: static PRBool ReadIndex( nsIFileSpec *pFile, PRUint32 **ppIndex, PRUint32 *pSize); - static nsresult ImportMailbox( PRBool *pAbort, nsString& name, nsIFileSpec *inFile, nsIFileSpec *pDestination, PRInt32 *pCount); + static nsresult ImportMailbox( PRUint32 *pBytesDone, PRBool *pAbort, nsString& name, nsIFileSpec *inFile, nsIFileSpec *pDestination, PRUint32 *pCount); private: typedef struct { diff --git a/mailnews/import/oexpress/nsOEImport.cpp b/mailnews/import/oexpress/nsOEImport.cpp index 1edc094238f0..3867a97e0ae9 100644 --- a/mailnews/import/oexpress/nsOEImport.cpp +++ b/mailnews/import/oexpress/nsOEImport.cpp @@ -90,8 +90,12 @@ private: static void ReportError( PRInt32 errorNum, nsString& name, nsString *pStream); static void AddLinebreak( nsString *pStream); static void SetLogs( nsString& success, nsString& error, PRUnichar **pError, PRUnichar **pSuccess); + +private: + PRUint32 m_bytesDone; }; + class ImportAddressImpl : public nsIImportAddressBooks { public: @@ -143,6 +147,7 @@ public: private: CWAB * m_pWab; + int m_doneSoFar; }; //////////////////////////////////////////////////////////////////////// @@ -453,14 +458,15 @@ NS_IMETHODIMP ImportMailImpl::ImportMailbox( nsIImportMailboxDescriptor *pSource nsCRT::free( pPath); #endif - PRInt32 msgCount = 0; + m_bytesDone = 0; + PRUint32 msgCount = 0; nsresult rv; if (nsOE5File::IsLocalMailFile( inFile)) { IMPORT_LOG1( "Importing OE5 mailbox: %S!\n", name.GetUnicode()); - rv = nsOE5File::ImportMailbox( &abort, name, inFile, pDestination, &msgCount); + rv = nsOE5File::ImportMailbox( &m_bytesDone, &abort, name, inFile, pDestination, &msgCount); } else { - if (CImportMailbox::ImportMailbox( &abort, name, inFile, pDestination, &msgCount)) { + if (CImportMailbox::ImportMailbox( &m_bytesDone, &abort, name, inFile, pDestination, &msgCount)) { rv = NS_OK; } else { @@ -491,7 +497,7 @@ NS_IMETHODIMP ImportMailImpl::GetImportProgress( PRUint32 *pDoneSoFar) // TLR: FIXME: Figure our how to update this from the import // of the current mailbox. - *pDoneSoFar = 0; + *pDoneSoFar = m_bytesDone; return( NS_OK); } @@ -617,9 +623,10 @@ NS_IMETHODIMP ImportAddressImpl::ImportAddressBook( nsIImportABDescriptor *sourc } IMPORT_LOG0( "IMPORTING OUTLOOK EXPRESS ADDRESS BOOK\n"); - + + m_doneSoFar = 0; nsOEAddressIterator * pIter = new nsOEAddressIterator( m_pWab, destination); - m_pWab->IterateWABContents( pIter); + m_pWab->IterateWABContents( pIter, &m_doneSoFar); delete pIter; return( NS_OK); @@ -632,7 +639,7 @@ NS_IMETHODIMP ImportAddressImpl::GetImportProgress(PRUint32 *_retval) if (! _retval) return NS_ERROR_NULL_POINTER; - *_retval = 0; + *_retval = (PRUint32) m_doneSoFar; return( NS_OK); } diff --git a/mailnews/import/oexpress/nsOEMailbox.cpp b/mailnews/import/oexpress/nsOEMailbox.cpp index 5f4f65cdc742..9f19ef61de8d 100644 --- a/mailnews/import/oexpress/nsOEMailbox.cpp +++ b/mailnews/import/oexpress/nsOEMailbox.cpp @@ -31,7 +31,7 @@ public: ~CMbxScanner(); virtual PRBool Initialize( void); - virtual PRBool DoWork( PRBool *pAbort); + virtual PRBool DoWork( PRBool *pAbort, PRUint32 *pDone, PRUint32 *pCount); PRBool WasErrorFatal( void) { return( m_fatalError);} PRUint32 BytesProcessed( void) { return( m_didBytes);} @@ -47,9 +47,10 @@ private: PRBool IsFromLineKey( PRUint8 *pBuf, PRUint32 max); public: - PRInt32 m_msgCount; + PRUint32 m_msgCount; protected: + PRUint32 * m_pDone; nsString m_name; nsIFileSpec * m_mbxFile; nsIFileSpec * m_dstFile; @@ -72,7 +73,7 @@ public: ~CIndexScanner(); virtual PRBool Initialize( void); - virtual PRBool DoWork( PRBool *pAbort); + virtual PRBool DoWork( PRBool *pAbort, PRUint32 *pDone, PRUint32 *pCount); protected: virtual void CleanUp( void); @@ -90,7 +91,7 @@ private: }; -PRBool CImportMailbox::ImportMailbox( PRBool *pAbort, nsString& name, nsIFileSpec * inFile, nsIFileSpec * outFile, PRInt32 *pCount) +PRBool CImportMailbox::ImportMailbox( PRUint32 *pDone, PRBool *pAbort, nsString& name, nsIFileSpec * inFile, nsIFileSpec * outFile, PRUint32 *pCount) { PRBool done = PR_FALSE; nsIFileSpec *idxFile; @@ -106,10 +107,8 @@ PRBool CImportMailbox::ImportMailbox( PRBool *pAbort, nsString& name, nsIFileSpe CIndexScanner *pIdxScanner = new CIndexScanner( name, idxFile, inFile, outFile); if (pIdxScanner->Initialize()) { - if (pIdxScanner->DoWork( pAbort)) { + if (pIdxScanner->DoWork( pAbort, pDone, pCount)) { done = PR_TRUE; - if (pCount) - *pCount = pIdxScanner->m_msgCount; } else { IMPORT_LOG0( "CIndexScanner::DoWork() failed\n"); @@ -133,10 +132,8 @@ PRBool CImportMailbox::ImportMailbox( PRBool *pAbort, nsString& name, nsIFileSpe */ CMbxScanner *pMbx = new CMbxScanner( name, inFile, outFile); if (pMbx->Initialize()) { - if (pMbx->DoWork( pAbort)) { + if (pMbx->DoWork( pAbort, pDone, pCount)) { done = PR_TRUE; - if (pCount) - *pCount = pMbx->m_msgCount; } else { IMPORT_LOG0( "CMbxScanner::DoWork() failed\n"); @@ -252,7 +249,7 @@ PRBool CMbxScanner::Initialize( void) #define kMbxHeaderSize 0x0054 #define kMbxMessageHeaderSz 16 -PRBool CMbxScanner::DoWork( PRBool *pAbort) +PRBool CMbxScanner::DoWork( PRBool *pAbort, PRUint32 *pDone, PRUint32 *pCount) { m_mbxOffset = kMbxHeaderSize; m_didBytes = kMbxHeaderSize; @@ -267,6 +264,10 @@ PRBool CMbxScanner::DoWork( PRBool *pAbort) m_mbxOffset += msgSz; m_didBytes += msgSz; m_msgCount++; + if (pDone) + *pDone = m_didBytes; + if (pCount) + *pCount = m_msgCount; } CleanUp(); @@ -613,7 +614,7 @@ PRBool CIndexScanner::GetMailItem( PRUint32 *pFlags, PRUint32 *pOffset, PRUint32 #define kOEDeletedFlag 0x0001 -PRBool CIndexScanner::DoWork( PRBool *pAbort) +PRBool CIndexScanner::DoWork( PRBool *pAbort, PRUint32 *pDone, PRUint32 *pCount) { m_didBytes = 0; if (!ValidateIdxFile()) @@ -635,6 +636,10 @@ PRBool CIndexScanner::DoWork( PRBool *pAbort) } } m_didBytes += size; + if (pDone) + *pDone = m_didBytes; + if (pCount) + *pCount = m_msgCount; } CleanUp(); diff --git a/mailnews/import/oexpress/nsOEMailbox.h b/mailnews/import/oexpress/nsOEMailbox.h index 736c91b42800..62d7765d2d94 100644 --- a/mailnews/import/oexpress/nsOEMailbox.h +++ b/mailnews/import/oexpress/nsOEMailbox.h @@ -30,7 +30,7 @@ class CImportMailbox { public: - static PRBool ImportMailbox( PRBool *pAbort, nsString& name, nsIFileSpec * inFile, nsIFileSpec * outFile, PRInt32 *pCount); + static PRBool ImportMailbox( PRUint32 *pDone, PRBool *pAbort, nsString& name, nsIFileSpec * inFile, nsIFileSpec * outFile, PRUint32 *pCount); private: static PRBool GetIndexFile( nsIFileSpec* mbxFile);