HistoryQueue.cpp
资源名称:FTP总集.rar [点击查看]
上传用户:tjfeida
上传日期:2013-03-10
资源大小:1917k
文件大小:4k
源码类别:
Ftp客户端
开发平台:
Visual C++
- // HistoryQueue.cpp: implementation of the CHistoryQueue class.
- //
- //////////////////////////////////////////////////////////////////////
- /*********************************************
- **该文件是属于WolfFTP工程中的。如果有什么问题
- **请联系
- ** tablejiang@21cn.com
- **或者访问
- ** http://wolfftp.51.net
- **以得到最新的支持。
- *********************************************/
- #include "stdafx.h"
- #include "QuickFTP.h"
- #include "HistoryQueue.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CHistoryQueue::CHistoryQueue()
- {
- m_pHistoryHead = NULL ;
- }
- CHistoryQueue::~CHistoryQueue()
- {
- DeleteAllItem( ) ;
- }
- /****************************************************
- ** @Description
- ** add a ftp file list to histroy queue.
- **
- ** @Parameter
- **
- **
- ** @Return:
- ** @Author: JHM
- ** e-mail: tablejiang@21cn.com
- ** @Date: 2001 3 26
- ****************************************************/
- int CHistoryQueue::AddItem(FTPITEM *pItem, LPSTR szPath)
- {
- HISTORYINFO* pCreate ;
- HISTORYINFO* pCurrent ;
- FTPITEM* pFtpItem ;
- //find it in history queue , if find it ,
- //replace it item queue, else add item .
- pCurrent = FindInHistory( szPath ) ;
- if( pCurrent != NULL )
- {
- pFtpItem = pCurrent->pFtpItem ;
- pCurrent->pFtpItem = pItem ;
- DeleteFtpItem( pFtpItem ) ;
- return 0 ;
- }
- //create new item .
- pCreate = new HISTORYINFO;
- pCreate->pFtpItem = pItem ;
- strcpy( pCreate->historypath , szPath ) ;
- pCreate->pNext = NULL ;
- if( m_pHistoryHead == NULL )
- {
- m_pHistoryHead = pCreate ;
- return true ;
- }
- //find the queue end pos .
- pCurrent = m_pHistoryHead ;
- while( pCurrent->pNext != NULL )
- {
- pCurrent = pCurrent->pNext ;
- }
- pCurrent->pNext = pCreate ;
- return true ;
- }
- /****************************************************
- ** @Description
- ** find a path in history queue .
- **
- ** @Parameter
- **
- **
- ** @Return:
- ** @Author: JHM
- ** e-mail: tablejiang@21cn.com
- ** @Date: 2001 3 26
- ****************************************************/
- HISTORYINFO* CHistoryQueue::FindInHistory(LPSTR szPath)
- {
- HISTORYINFO* pHead ;
- HISTORYINFO* pCur ;
- //make path.
- char strPath[MAX_PATH] ;
- strcpy( strPath , szPath ) ;
- int iLength = strlen( szPath ) ;
- if( iLength != 1 &&( strPath[ iLength - 1 ] == '\' || strPath[iLength -1] == '/' ))
- {
- strPath[iLength -1 ] = ' ' ;
- }
- if( m_pHistoryHead == NULL )
- return NULL ;
- pHead = m_pHistoryHead ;
- pCur = m_pHistoryHead ;
- //find in history list .
- while( pCur != NULL )
- {
- if( strcmp( pCur->historypath , strPath ) == 0 )
- return pCur ;
- else
- pCur = pCur->pNext ;
- }
- return NULL ;
- }
- /****************************************************
- ** @Description
- ** delete a ftp file list .
- **
- ** @Parameter
- **
- **
- ** @Return:
- ** @Author: JHM
- ** e-mail: tablejiang@21cn.com
- ** @Date: 2001 3 26
- ****************************************************/
- BOOL CHistoryQueue::DeleteFtpItem(FTPITEM *pFtpItem)
- {
- FTPITEM * pNextItem = pFtpItem ;
- FTPITEM * pCurItem = pFtpItem ;
- while( pNextItem != NULL )
- {
- pCurItem = pNextItem ;
- pNextItem = pNextItem->pNext ;
- try
- {
- delete pCurItem ;
- }
- catch(...)
- {
- TRACE( "memory delete error!" ) ;
- }
- pCurItem = NULL ;
- }
- return true ;
- }
- /****************************************************
- ** @Description
- ** delete all ftp file list .
- **
- ** @Parameter
- **
- **
- ** @Return:
- ** @Author: JHM
- ** e-mail: tablejiang@21cn.com
- ** @Date: 2001 3 26
- ****************************************************/
- void CHistoryQueue::DeleteAllItem()
- {
- HISTORYINFO * pNextItem = m_pHistoryHead ;
- HISTORYINFO * pCurItem = m_pHistoryHead ;
- if( m_pHistoryHead == NULL)
- return ;
- while( pNextItem != NULL )
- {
- pCurItem = pNextItem ;
- pNextItem = pNextItem->pNext ;
- DeleteFtpItem( pCurItem->pFtpItem ) ;
- try
- {
- delete pCurItem ;
- }
- catch(...)
- {
- TRACE( "memory delete error!" ) ;
- }
- pCurItem = NULL ;
- }
- m_pHistoryHead = NULL ;
- return ;
- }