123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- #include "stdafx.h"
- #include "DelFiles.h"
- #include "ffscoex.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- using namespace helper_coffs;
- unsigned int __stdcall DelThreadPro(IN LPVOID lpParam);
- CSC_DelFiles::CSC_DelFiles()
- {
- m_dwRefCount = 0;
- m_hThread = NULL;
- m_hEvent = NULL;
- m_bRunning = FALSE;
- m_PFCallBack = NULL;
- }
- CSC_DelFiles::~CSC_DelFiles()
- {
- m_ListMgr.Release();
- TerminateDel();
- }
- STDMETHODIMP CSC_DelFiles::QueryInterface(REFIID refiid, void** ppv)
- {
- if (IID_IUnknown == refiid)
- *ppv = this;
- else if (IID_ISC_DELFILESINTERFACE == refiid)
- *ppv = (ISC_DelFilesInterface*)this;
- else
- {
- *ppv = NULL;
- return E_NOINTERFACE;
- }
- ((IUnknown*)(*ppv))->AddRef();
- return NOERROR;
- }
- STDMETHODIMP_(ULONG) CSC_DelFiles::AddRef(void)
- {
- InterlockedIncrement((LPLONG)&m_dwRefCount);
- return m_dwRefCount;
- }
- STDMETHODIMP_(ULONG) CSC_DelFiles::Release(void)
- {
- InterlockedDecrement((LPLONG)&m_dwRefCount);
- if (!m_dwRefCount)
- delete this;
- return 0;
- }
- int CSC_DelFiles::AddDelData(IN LPCTSTR lpDomain, IN LPCTSTR lpOrderNum, IN LPCTSTR lpDir, IN const BYTE byPhotoType, IN const BOOL bPickuped)
- {
- LPSDELINFO lp = new SDELINFO;
- lp->Clone(lpDomain, lpOrderNum, lpDir, byPhotoType, bPickuped);
- m_ListMgr.Push_Back(lp);
- return 1;
- }
- int CSC_DelFiles::StartDelFiles(IN PFCALLBACK callbackfun)
- {
- if(m_bRunning)
- return 0;
- m_PFCallBack = callbackfun;
- m_hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
- unsigned int nThreadID = 0;
- m_hThread = (HANDLE)_beginthreadex(NULL, 0, DelThreadPro, (void*)this, 0, &nThreadID);
- m_bRunning = TRUE;
- return 1;
- }
- void CSC_DelFiles::TerminateDel()
- {
- if(!m_bRunning)
- return;
- if(m_hEvent)
- SetEvent(m_hEvent);
- ::WaitForSingleObject(m_hThread, INFINITE);
- m_bRunning = FALSE;
- if(m_hThread)
- {
- CloseHandle(m_hThread);
- m_hThread = NULL;
- }
- if(m_hEvent)
- {
- CloseHandle(m_hEvent);
- m_hEvent = NULL;
- }
- }
- BOOL CSC_DelFiles::IsDeleting()
- {
- return m_bRunning;
- }
- void CSC_DelFiles::DelWork()
- {
- while(m_ListMgr.Size() != 0)
- {
- LPSDELINFO lp = m_ListMgr.Pop_Front();
- if(lp != NULL)
- {
- BOOL bSuccess = DeleteDirectory(lp->szDir);
- m_PFCallBack(&lp->byPhotoType, lp->szDomain, lp->szOrderNum, lp->szDir, &bSuccess, NULL);
- delete lp;
- }
- Sleep(10);
- }
-
- if(m_hThread)
- {
- CloseHandle(m_hThread);
- m_hThread = NULL;
- }
- if(m_hEvent)
- {
- CloseHandle(m_hEvent);
- m_hEvent = NULL;
- }
- m_bRunning = FALSE;
- }
- unsigned int __stdcall DelThreadPro(IN LPVOID lpParam)
- {
- CSC_DelFiles* p = (CSC_DelFiles*)lpParam;
- if(p)
- p->DelWork();
- return 0;
- }
- BOOL CSC_DelFiles::DeleteDirectory(IN LPCTSTR lpDiretory)
- {
- ffscoex coex;
- return coex.deldir(lpDiretory);
- }
|