DeleteFileQueue.cpp
资源名称:FTP总集.rar [点击查看]
上传用户:tjfeida
上传日期:2013-03-10
资源大小:1917k
文件大小:7k
源码类别:
Ftp客户端
开发平台:
Visual C++
- // DeleteFileQueue.cpp: implementation of the CDeleteFileQueue class.
- //
- //////////////////////////////////////////////////////////////////////
- /*********************************************
- **该文件是属于WolfFTP工程中的。如果有什么问题
- **请联系
- ** tablejiang@21cn.com
- **或者访问
- ** http://wolfftp.51.net
- **以得到最新的支持。
- *********************************************/
- #include "stdafx.h"
- #include "quickftp.h"
- #include "DeleteFileQueue.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CDeleteFileQueue::CDeleteFileQueue()
- {
- //init the critical section tag .
- InitializeCriticalSection( &m_cs );
- //set file queue null.
- m_pFileTransmitQueue = NULL ;
- }
- CDeleteFileQueue::~CDeleteFileQueue()
- {
- //clear the file queue .
- DeleteAllFileQueue( ) ;
- //delete tag .
- DeleteCriticalSection( &m_cs );
- }
- /****************************************************
- ** @Description
- ** add a delete file to queue.
- **
- ** @Parameter
- ** FTPFILEINFO* pFileInfo : the ftp file info .
- **
- ** @Return: true
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** @Date: 2001 3 26
- ****************************************************/
- BOOL CDeleteFileQueue::AddItem(FTPFILEINFO *pFileInfo)
- {
- //set enter tag .
- EnterCriticalSection( &m_cs ) ;
- FTPFILEINFO* pFileItem ;
- FTPFILEINFO* pCurItem ;
- BOOL bFind = false ;
- //create a new object .
- pFileItem = new FTPFILEINFO ;
- memcpy( pFileItem , pFileInfo , sizeof( FTPFILEINFO ) ) ;
- //new add item always set state to FILE_STATE_READY.
- pFileItem->state = FILE_STATE_READY ;
- pFileItem->pNext = NULL ;
- //is the head item ?
- if( m_pFileTransmitQueue == NULL )
- {
- m_pFileTransmitQueue = pFileItem ;
- LeaveCriticalSection( &m_cs ) ;
- return true ;
- }
- pCurItem = m_pFileTransmitQueue ;
- //find the item is file queue .if the item is already add in
- //this file queue , don't add it .
- while( pCurItem->pNext != NULL )
- {
- if( strcmp( pFileInfo->site.host , pCurItem->site.host ) == 0 )
- {
- if( strcmp( pFileInfo->remotefilename , pCurItem->remotefilename ) == 0 )
- {
- if( strcmp( pFileInfo->remotepath , pCurItem->remotepath ) == 0 )
- {
- if( pFileInfo->bfileput == pCurItem->bfileput )
- {
- if( pFileInfo->bIsDirectory == pCurItem->bIsDirectory )
- {
- if(strcmp( pFileInfo->site.user , pFileInfo->site.user ) == 0 )
- {
- bFind = true ;
- break ;
- }
- }
- }
- }
- }
- }
- pCurItem = pCurItem->pNext ;
- }
- if( !bFind )
- pCurItem->pNext = pFileItem ;
- //set leave tag .
- LeaveCriticalSection( &m_cs ) ;
- return true ;
- }
- /****************************************************
- ** @Description
- ** delete a file from queue .( delete a item from
- single chain .)
- **
- ** @Parameter
- ** FTPFILEINFO* pFileInfo : the delete file info.
- **
- ** @Return: if delete success return true ,else false .
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** @Date: 2001 3 26
- ****************************************************/
- BOOL CDeleteFileQueue::DeleteItem(FTPFILEINFO *pFileInfo)
- {
- FTPFILEINFO* pFront ;
- FTPFILEINFO* pCurrent ;
- BOOL bFind = false ;
- //set enter tag.
- EnterCriticalSection( &m_cs ) ;
- if( m_pFileTransmitQueue == NULL )
- {
- LeaveCriticalSection( &m_cs ) ;
- return true ;
- }
- pCurrent = m_pFileTransmitQueue ;
- pFront = m_pFileTransmitQueue ;
- while( pCurrent != NULL )
- {
- if( strcmp( pFileInfo->site.host , pCurrent->site.host ) == 0 )
- {
- if( strcmp( pFileInfo->remotefilename , pCurrent->remotefilename ) == 0 )
- {
- if( strcmp( pFileInfo->remotepath , pCurrent->remotepath ) == 0 )
- {
- bFind = true ;
- break ;
- }
- }
- }
- pFront = pCurrent ;
- pCurrent = pCurrent->pNext ;
- }
- //no this item , return false .
- if( bFind == false )
- {
- LeaveCriticalSection( &m_cs ) ;
- return false ;
- }
- if( pCurrent == m_pFileTransmitQueue )
- {
- m_pFileTransmitQueue = pCurrent->pNext ;
- }
- else
- {
- pFront->pNext = pCurrent->pNext ;
- }
- delete pCurrent ;
- LeaveCriticalSection( &m_cs ) ;
- return true ;
- }
- /****************************************************
- ** @Description
- ** is specify file in this file queue .
- ( search a item in single chain )
- **
- ** @Parameter
- **
- ** @Return:
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** @Date: 2001 3 26
- ****************************************************/
- BOOL CDeleteFileQueue::IsInFileQueue(FTPFILEINFO *pFileInfo)
- {
- FTPFILEINFO* pFront ;
- FTPFILEINFO* pCurrent ;
- BOOL bFind = false ;
- EnterCriticalSection( &m_cs ) ;
- if( m_pFileTransmitQueue == NULL )
- {
- LeaveCriticalSection( &m_cs ) ;
- return false ;
- }
- pCurrent = m_pFileTransmitQueue ;
- pFront = m_pFileTransmitQueue ;
- while( pCurrent != NULL )
- {
- if( strcmp( pFileInfo->site.host , pCurrent->site.host ) == 0 )
- {
- if( strcmp( pFileInfo->remotefilename , pCurrent->remotefilename ) == 0 )
- {
- if( strcmp( pFileInfo->remotepath , pCurrent->remotepath ) == 0 )
- {
- bFind = true ;
- break ;
- }
- }
- }
- pFront = pCurrent ;
- pCurrent = pCurrent->pNext ;
- }
- LeaveCriticalSection( &m_cs ) ;
- return bFind ;
- }
- /****************************************************
- ** @Description
- ** clear the file queue .
- **
- ** @Parameter
- ** void
- **
- ** @Return:
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** @Date: 2001 3 26
- ****************************************************/
- BOOL CDeleteFileQueue::DeleteAllFileQueue()
- {
- FTPFILEINFO* pCurrent ;
- EnterCriticalSection( &m_cs ) ;
- if( m_pFileTransmitQueue== NULL)
- {
- LeaveCriticalSection( &m_cs ) ;
- return true ;
- }
- pCurrent = m_pFileTransmitQueue ;
- while( m_pFileTransmitQueue != NULL)
- {
- m_pFileTransmitQueue = pCurrent->pNext ;
- delete pCurrent ;
- pCurrent = m_pFileTransmitQueue ;
- }
- m_pFileTransmitQueue = NULL ;
- LeaveCriticalSection( &m_cs ) ;
- return true ;
- }
- /****************************************************
- ** @Description
- ** Is file queue empty.
- **
- ** @Parameter
- ** void
- **
- ** @Return:
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** @Date: 2001 3 26
- ****************************************************/
- BOOL CDeleteFileQueue::IsEmpty()
- {
- EnterCriticalSection( &m_cs ) ;
- if( m_pFileTransmitQueue == NULL )
- {
- LeaveCriticalSection( &m_cs ) ;
- return true ;
- }
- else
- {
- LeaveCriticalSection( &m_cs ) ;
- return false ;
- }
- }
- /****************************************************
- ** @Description
- ** get next ready item .
- **
- ** @Parameter
- **
- **
- ** @Return:
- ** @Author: Table.JHM.太子
- ** e-mail: tablejiang@21cn.com
- ** @Date: 2001 3 26
- ****************************************************/
- FTPFILEINFO* CDeleteFileQueue::GetNextItem()
- {
- if( IsEmpty( ) )
- return NULL ;
- EnterCriticalSection( &m_cs ) ;
- FTPFILEINFO* pCur ;
- pCur = m_pFileTransmitQueue ;
- while( pCur != NULL )
- {
- if( pCur->state == FILE_STATE_READY )
- break ;
- pCur = pCur->pNext ;
- }
- LeaveCriticalSection( &m_cs ) ;
- return pCur ;
- }