Index: src/ch/TSubTaskDelete.cpp =================================================================== diff -u -rb7709acbab26fdb108b77d3e08d3872f54248af2 -rc866a5e96f5eaf160278a8c128bf86e342cc2409 --- src/ch/TSubTaskDelete.cpp (.../TSubTaskDelete.cpp) (revision b7709acbab26fdb108b77d3e08d3872f54248af2) +++ src/ch/TSubTaskDelete.cpp (.../TSubTaskDelete.cpp) (revision c866a5e96f5eaf160278a8c128bf86e342cc2409) @@ -22,4 +22,115 @@ // ============================================================================ #include "stdafx.h" #include "TSubTaskDelete.h" +#include "TSubTaskContext.h" +#include "TBasicProgressInfo.h" +#include "TWorkerThreadController.h" +#include "TTaskConfiguration.h" +#include "TTaskDefinition.h" +#include "FeedbackHandler.h" +TSubTaskDelete::TSubTaskDelete(TSubTaskContext& rContext) : + TSubTaskBase(rContext) +{ +} + +TSubTaskBase::ESubOperationResult TSubTaskDelete::Exec() +{ + // log + icpf::log_file& rLog = GetContext().GetLog(); + CFileInfoArray& rFilesCache = GetContext().GetFilesCache(); + TTaskDefinition& rTaskDefinition = GetContext().GetTaskDefinition(); + TTaskBasicProgressInfo& rBasicProgressInfo = GetContext().GetTaskBasicProgressInfo(); + TWorkerThreadController& rThreadController = GetContext().GetThreadController(); + chcore::IFeedbackHandler* piFeedbackHandler = GetContext().GetFeedbackHandler(); + + // log + rLog.logi(_T("Deleting files (DeleteFiles)...")); + + // current processed path + BOOL bSuccess; + CFileInfoPtr spFileInfo; + ictranslate::CFormat fmt; + + // index points to 0 or next item to process + size_t stIndex = rBasicProgressInfo.GetCurrentIndex(); + while(stIndex < rFilesCache.GetSize()) + { + // set index in pTask to currently deleted element + rBasicProgressInfo.SetCurrentIndex(stIndex); + + // check for kill flag + if(rThreadController.KillRequested()) + { + // log + rLog.logi(_T("Kill request while deleting files (Delete Files)")); + return TSubTaskBase::eSubResult_KillRequest; + } + + // current processed element + spFileInfo = rFilesCache.GetAt(rFilesCache.GetSize() - stIndex - 1); + if(!(spFileInfo->GetFlags() & FIF_PROCESSED)) + { + ++stIndex; + continue; + } + + // delete data + if(spFileInfo->IsDirectory()) + { + if(!GetTaskPropValue(rTaskDefinition.GetConfiguration())) + SetFileAttributes(spFileInfo->GetFullFilePath().ToString(), FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY); + bSuccess=RemoveDirectory(spFileInfo->GetFullFilePath().ToString()); + } + else + { + // set files attributes to normal - it'd slow processing a bit, but it's better. + if(!GetTaskPropValue(rTaskDefinition.GetConfiguration())) + SetFileAttributes(spFileInfo->GetFullFilePath().ToString(), FILE_ATTRIBUTE_NORMAL); + bSuccess=DeleteFile(spFileInfo->GetFullFilePath().ToString()); + } + + // operation failed + DWORD dwLastError=GetLastError(); + if(!bSuccess && dwLastError != ERROR_PATH_NOT_FOUND && dwLastError != ERROR_FILE_NOT_FOUND) + { + // log + fmt.SetFormat(_T("Error #%errno while deleting file/folder %path")); + fmt.SetParam(_t("%errno"), dwLastError); + fmt.SetParam(_t("%path"), spFileInfo->GetFullFilePath().ToString()); + rLog.loge(fmt); + + FEEDBACK_FILEERROR ferr = { spFileInfo->GetFullFilePath().ToString(), NULL, eDeleteError, dwLastError }; + CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &ferr); + switch(frResult) + { + case CFeedbackHandler::eResult_Cancel: + rLog.logi(_T("Cancel request while deleting file.")); + return TSubTaskBase::eSubResult_CancelRequest; + + case CFeedbackHandler::eResult_Retry: + continue; // no stIndex bump, since we are trying again + + case CFeedbackHandler::eResult_Pause: + return TSubTaskBase::eSubResult_PauseRequest; + + case CFeedbackHandler::eResult_Skip: + break; // just do nothing + + default: + BOOST_ASSERT(FALSE); // unknown result + THROW(_T("Unhandled case"), 0, 0, 0); + } + } + + ++stIndex; + }//while + + // add 1 to current index + rBasicProgressInfo.IncreaseCurrentIndex(); + + // log + rLog.logi(_T("Deleting files finished")); + + return TSubTaskBase::eSubResult_Continue; +} Index: src/ch/TSubTaskDelete.h =================================================================== diff -u -rb7709acbab26fdb108b77d3e08d3872f54248af2 -rc866a5e96f5eaf160278a8c128bf86e342cc2409 --- src/ch/TSubTaskDelete.h (.../TSubTaskDelete.h) (revision b7709acbab26fdb108b77d3e08d3872f54248af2) +++ src/ch/TSubTaskDelete.h (.../TSubTaskDelete.h) (revision c866a5e96f5eaf160278a8c128bf86e342cc2409) @@ -23,5 +23,14 @@ #ifndef __TSUBTASKDELETE_H__ #define __TSUBTASKDELETE_H__ +#include "TSubTaskBase.h" +class TSubTaskDelete : public TSubTaskBase +{ +public: + TSubTaskDelete(TSubTaskContext& rContext); + + ESubOperationResult Exec(); +}; + #endif Index: src/ch/task.cpp =================================================================== diff -u -r8c87d4185fbe5b952c49f72afcfd5f9fca338fb4 -rc866a5e96f5eaf160278a8c128bf86e342cc2409 --- src/ch/task.cpp (.../task.cpp) (revision 8c87d4185fbe5b952c49f72afcfd5f9fca338fb4) +++ src/ch/task.cpp (.../task.cpp) (revision c866a5e96f5eaf160278a8c128bf86e342cc2409) @@ -35,6 +35,7 @@ #include "TLocalFilesystem.h" #include "TSubTaskScanDirectory.h" #include "TSubTaskCopyMove.h" +#include "TSubTaskDelete.h" //////////////////////////////////////////////////////////////////////////// // CTask members @@ -558,103 +559,6 @@ return m_bContinue; } -// delete files - after copying -TSubTaskBase::ESubOperationResult CTask::DeleteFiles() -{ - // log - m_log.logi(_T("Deleting files (DeleteFiles)...")); - - // current processed path - BOOL bSuccess; - CFileInfoPtr spFileInfo; - ictranslate::CFormat fmt; - - // index points to 0 or next item to process - size_t stIndex = m_tTaskBasicProgressInfo.GetCurrentIndex(); - while(stIndex < m_files.GetSize()) - { - // set index in pTask to currently deleted element - m_tTaskBasicProgressInfo.SetCurrentIndex(stIndex); - - // check for kill flag - if(m_workerThread.KillRequested()) - { - // log - m_log.logi(_T("Kill request while deleting files (Delete Files)")); - return TSubTaskBase::eSubResult_KillRequest; - } - - // current processed element - spFileInfo = m_files.GetAt(m_files.GetSize() - stIndex - 1); - if(!(spFileInfo->GetFlags() & FIF_PROCESSED)) - { - ++stIndex; - continue; - } - - // delete data - if(spFileInfo->IsDirectory()) - { - if(!GetTaskPropValue(m_tTaskDefinition.GetConfiguration())) - SetFileAttributes(spFileInfo->GetFullFilePath().ToString(), FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY); - bSuccess=RemoveDirectory(spFileInfo->GetFullFilePath().ToString()); - } - else - { - // set files attributes to normal - it'd slow processing a bit, but it's better. - if(!GetTaskPropValue(m_tTaskDefinition.GetConfiguration())) - SetFileAttributes(spFileInfo->GetFullFilePath().ToString(), FILE_ATTRIBUTE_NORMAL); - bSuccess=DeleteFile(spFileInfo->GetFullFilePath().ToString()); - } - - // operation failed - DWORD dwLastError=GetLastError(); - if(!bSuccess && dwLastError != ERROR_PATH_NOT_FOUND && dwLastError != ERROR_FILE_NOT_FOUND) - { - // log - fmt.SetFormat(_T("Error #%errno while deleting file/folder %path")); - fmt.SetParam(_t("%errno"), dwLastError); - fmt.SetParam(_t("%path"), spFileInfo->GetFullFilePath().ToString()); - m_log.loge(fmt); - - FEEDBACK_FILEERROR ferr = { spFileInfo->GetFullFilePath().ToString(), NULL, eDeleteError, dwLastError }; - CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)m_piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &ferr); - switch(frResult) - { - case CFeedbackHandler::eResult_Cancel: - m_log.logi(_T("Cancel request while deleting file.")); - return TSubTaskBase::eSubResult_CancelRequest; - - case CFeedbackHandler::eResult_Retry: - continue; // no stIndex bump, since we are trying again - - case CFeedbackHandler::eResult_Pause: - return TSubTaskBase::eSubResult_PauseRequest; - - case CFeedbackHandler::eResult_Skip: - break; // just do nothing - - default: - BOOST_ASSERT(FALSE); // unknown result - THROW(_T("Unhandled case"), 0, 0, 0); - } - } - - ++stIndex; - }//while - - // change status to finished - SetTaskState(eTaskState_Finished); - - // add 1 to current index - m_tTaskBasicProgressInfo.IncreaseCurrentIndex(); - - // log - m_log.logi(_T("Deleting files finished")); - - return TSubTaskBase::eSubResult_Continue; -} - TSubTaskBase::ESubOperationResult CTask::CheckForWaitState() { // limiting operation count @@ -828,15 +732,21 @@ } case eSubOperation_Deleting: - eResult = DeleteFiles(); - break; + { + TSubTaskDelete tSubTaskDelete(tSubTaskContext); + eResult = tSubTaskDelete.Exec(); + break; + } default: BOOST_ASSERT(false); THROW(_T("Unhandled case"), 0, 0, 0); } } + // change status to finished + SetTaskState(eTaskState_Finished); + // refresh time m_localStats.DisableTimeTracking(); Index: src/ch/task.h =================================================================== diff -u -r8c87d4185fbe5b952c49f72afcfd5f9fca338fb4 -rc866a5e96f5eaf160278a8c128bf86e342cc2409 --- src/ch/task.h (.../task.h) (revision 8c87d4185fbe5b952c49f72afcfd5f9fca338fb4) +++ src/ch/task.h (.../task.h) (revision c866a5e96f5eaf160278a8c128bf86e342cc2409) @@ -171,8 +171,6 @@ /// Main function for the task processing thread DWORD WINAPI ThrdProc(); - TSubTaskBase::ESubOperationResult DeleteFiles(); - TSubTaskBase::ESubOperationResult CheckForWaitState(); // Helper filesystem methods