MailTmpFile.h
上传用户:weimei12
上传日期:2022-08-11
资源大小:185k
文件大小:4k
- /********************************************************************
- created: 2009:2:19 16:05
- author: 李欣
- filename: e:MyProjectSimpleMailFileStoreFileStoreMailDatabase.h
- classname: CMailDatabase
- purpose: the database to store the mails
- *********************************************************************/
- #pragma once
- class FILE_STORE_CLASSEXT CMailTmpFile
- {
- public:
- CMailTmpFile(void);
- ~CMailTmpFile(void);
-
- ///<summary>
- /// Open a file to save mails
- ///</summary>
- ///<param name = szFileName>
- /// the file name
- ///</param>
- ///<param name = bCanWrite>
- /// whether the file can be written
- ///</param>
- BOOL Open(IN LPCTSTR szFileName, IN BOOL bCanWrite);
- ///<summary>
- /// Create an empty temporary file at first
- ///</summary>
- ///<param name = szFileName>
- /// the file name
- ///</param>
- BOOL CreateEmptyFile(IN LPCTSTR szFileName);
- ///<summary>
- /// close the file to save the mails
- ///</summary>
- ///<param name = bRealClose>
- /// whether to close the file actually, or just leave it open for further use
- ///</param>
- void CloseFile(BOOL bRealClose);
- ///<summary>
- /// read the specified block
- ///</summary>
- ///<param name = nBlockIndex>
- /// the index of the block to be read
- ///</param>
- ///<param name = nLen>
- /// the length of the pBuf
- ///</param>
- ///<param name = pBuf>
- /// the buffer for storing the mail
- ///</param>
- BOOL ReadMailBlock(IN const UINT nBlockIndex, IN const UINT nLen, OUT void* pBuf);
- ///<summary>
- /// write the specified block
- ///</summary>
- ///<param name = nBlockIndex>
- /// the index of the block to be written
- ///</param>
- ///<param name = pBuf>
- /// the buffer for storing the mail
- ///</param>
- ///<param name = nLen>
- /// the length of the pBuf
- ///</param>
- BOOL WriteMailBlock(IN const UINT nBlockIndex, IN void* pBuf, IN const UINT nLen);
- ///<summary>
- /// apply specified number of blocks to save the mails
- ///</summary>
- ///<param name = nCount>
- /// the count of blocks to be applied
- ///</param>
- ///<param name = nStartBlockIndex>
- /// the start index of the blocks to be applied
- ///</param>
- /// <returns>
- /// the start index of the blocks to be applied
- /// </returns>
- UINT ApplyMailBlocks(IN const UINT nCount,IN const UINT nStartBlockIndex = 0);
- ///<summary>
- /// release the specified blocks that will not be used
- ///</summary>
- ///<param name = nStartBlockIndex>
- /// the start index of the blocks to be applied
- ///</param>
- ///<param name = nCount>
- /// the count of blocks to be applied
- ///</param>
- BOOL ReleaseMailBlocks(IN const UINT nStartIndex, IN const UINT nCount);
- private:
- ///<summary>
- /// Test if the file to save mails has been opened
- ///</summary>
- BOOL IsOpened();
- ///<summary>
- /// load the mails from the file
- ///</summary>
- BOOL LoadFromTmpFile();
- ///<summary>
- /// load the mails from the specified cluster
- ///</summary>
- ///<param name = filePos>
- /// the start position of the cluster
- ///</param>
- BOOL LoadMailCluster(IN MAILFILEPOS filePos/*, CDataCluster* pParentMailCluster*/);
- ///<summary>
- /// reopen the file if it is closed
- ///</summary>
- BOOL ReOpenFile();
- ///<summary>
- /// the header of the file
- ///</summary>
- SMailFileHeader m_fileHeader;
- ///<summary>
- /// a pointer of the cluster, it's only one cluster now
- ///</summary>
- CDataCluster* m_pMailCluster;
- ///<summary>
- /// the pointer to the temporary file
- ///</summary>
- CFile* m_pTmpFile;
- ///<summary>
- /// the temporary file name
- ///</summary>
- CString m_strFileName;
- ///<summary>
- /// whether the file can be written
- ///</summary>
- BOOL m_bOpenToWrite;
- };