Index: src/ch/task.h =================================================================== diff -u -N -rb684bec49aaaea4b89ab2e599497f4085d8698a3 -r8c87d4185fbe5b952c49f72afcfd5f9fca338fb4 --- src/ch/task.h (.../task.h) (revision b684bec49aaaea4b89ab2e599497f4085d8698a3) +++ src/ch/task.h (.../task.h) (revision 8c87d4185fbe5b952c49f72afcfd5f9fca338fb4) @@ -28,6 +28,10 @@ #include "TTaskDefinition.h" #include "TTaskConfigTracker.h" #include "TBasePathData.h" +#include "TSubTaskBase.h" +#include "TTaskLocalStats.h" +#include "TTaskGlobalStats.h" +#include "TBasicProgressInfo.h" // enum representing current processing state of the task enum ETaskCurrentState @@ -88,180 +92,11 @@ int m_nPercent; }; -struct CUSTOM_COPY_PARAMS -{ - CFileInfoPtr spSrcFile; // CFileInfo - src file - chcore::TSmartPath pathDstFile; // dest path with filename - - CDataBuffer dbBuffer; // buffer handling - bool bOnlyCreate; // flag from configuration - skips real copying - only create - bool bProcessed; // has the element been processed ? (false if skipped) -}; - /////////////////////////////////////////////////////////////////////////// -// TTasksGlobalStats -class TTasksGlobalStats -{ -public: - TTasksGlobalStats(); - ~TTasksGlobalStats(); - - void IncreaseGlobalTotalSize(unsigned long long ullModify); - void DecreaseGlobalTotalSize(unsigned long long ullModify); - unsigned long long GetGlobalTotalSize() const; - - void IncreaseGlobalProcessedSize(unsigned long long ullModify); - void DecreaseGlobalProcessedSize(unsigned long long ullModify); - unsigned long long GetGlobalProcessedSize() const; - - void IncreaseGlobalProgressData(unsigned long long ullTasksPosition, unsigned long long ullTasksSize); - void DecreaseGlobalProgressData(unsigned long long ullTasksPosition, unsigned long long ullTasksSize); - - int GetProgressPercents() const; - - void IncreaseRunningTasks(); - void DecreaseRunningTasks(); - size_t GetRunningTasksCount() const; - -private: - volatile unsigned long long m_ullGlobalTotalSize; - volatile unsigned long long m_ullGlobalProcessedSize; - - volatile size_t m_stRunningTasks; // count of current operations - mutable boost::shared_mutex m_lock; -}; - -/////////////////////////////////////////////////////////////////////////// -// TTaskLocalStats -class TTaskLocalStats -{ -public: - TTaskLocalStats(); - ~TTaskLocalStats(); - - void ConnectGlobalStats(TTasksGlobalStats& rtGlobalStats); - void DisconnectGlobalStats(); - - void IncreaseProcessedSize(unsigned long long ullAdd); - void DecreaseProcessedSize(unsigned long long ullSub); - void SetProcessedSize(unsigned long long ullSet); - unsigned long long GetProcessedSize() const; - unsigned long long GetUnProcessedSize() const; - - void IncreaseTotalSize(unsigned long long ullAdd); - void DecreaseTotalSize(unsigned long long ullSub); - void SetTotalSize(unsigned long long ullSet); - unsigned long long GetTotalSize() const; - - int GetProgressInPercent() const; - - void MarkTaskAsRunning(); - void MarkTaskAsNotRunning(); - bool IsRunning() const; - - void SetTimeElapsed(time_t timeElapsed); - time_t GetTimeElapsed(); - - void EnableTimeTracking(); - void DisableTimeTracking(); - void UpdateTime(); - -private: - volatile unsigned long long m_ullProcessedSize; - volatile unsigned long long m_ullTotalSize; - - volatile bool m_bTaskIsRunning; - - // time - volatile time_t m_timeElapsed; - volatile time_t m_timeLast; - - mutable boost::shared_mutex m_lock; - TTasksGlobalStats* m_prtGlobalStats; -}; - -/////////////////////////////////////////////////////////////////////////// -// TTaskBasicProgressInfo - -class TTaskBasicProgressInfo -{ -public: - TTaskBasicProgressInfo(); - ~TTaskBasicProgressInfo(); - - void SetCurrentIndex(size_t stIndex); // might be unneeded when serialization is implemented - void IncreaseCurrentIndex(); - size_t GetCurrentIndex() const; - - void SetCurrentFileProcessedSize(unsigned long long ullSize); - unsigned long long GetCurrentFileProcessedSize() const; - void IncreaseCurrentFileProcessedSize(unsigned long long ullSizeToAdd); - - void SetSubOperationIndex(size_t stSubOperationIndex); - size_t GetSubOperationIndex() const; - void IncreaseSubOperationIndex(); - - template - void load(Archive& ar, unsigned int /*uiVersion*/) - { - size_t stCurrentIndex = 0; - ar >> stCurrentIndex; - - unsigned long long ullCurrentFileProcessedSize = 0; - ar >> ullCurrentFileProcessedSize; - - size_t stSubOperationIndex = 0; - ar >> stSubOperationIndex; - - boost::unique_lock lock(m_lock); - - m_stCurrentIndex = stCurrentIndex; - m_ullCurrentFileProcessedSize = ullCurrentFileProcessedSize; - m_stSubOperationIndex = stSubOperationIndex; - } - - template - void save(Archive& ar, unsigned int /*uiVersion*/) const - { - m_lock.lock_shared(); - - size_t stCurrentIndex = m_stCurrentIndex; - unsigned long long ullCurrentFileProcessedSize = m_ullCurrentFileProcessedSize; - size_t stSubOperationIndex = m_stSubOperationIndex; - - m_lock.unlock_shared(); - - ar << stCurrentIndex; - ar << ullCurrentFileProcessedSize; - ar << stSubOperationIndex; - } - - BOOST_SERIALIZATION_SPLIT_MEMBER(); - -private: - volatile size_t m_stSubOperationIndex; // index of sub-operation from TOperationDescription - volatile size_t m_stCurrentIndex; // index to the m_files array stating currently processed item - volatile unsigned long long m_ullCurrentFileProcessedSize; // count of bytes processed for current file - - mutable boost::shared_mutex m_lock; -}; - -/////////////////////////////////////////////////////////////////////////// // CTask class CTask { -protected: - // enum using internally by the CTask class to pass the operation results between methods - enum ESubOperationResult - { - eSubResult_Continue, - eSubResult_KillRequest, - eSubResult_Error, - eSubResult_CancelRequest, - eSubResult_PauseRequest - }; - public: enum EPathType { @@ -336,41 +171,22 @@ /// Main function for the task processing thread DWORD WINAPI ThrdProc(); - ESubOperationResult RecurseDirectories(); - int ScanDirectory(chcore::TSmartPath pathDirName, size_t stSrcIndex, bool bRecurse, bool bIncludeDirs); + TSubTaskBase::ESubOperationResult DeleteFiles(); - ESubOperationResult ProcessFiles(); - ESubOperationResult CustomCopyFileFB(CUSTOM_COPY_PARAMS* pData); + TSubTaskBase::ESubOperationResult CheckForWaitState(); - ESubOperationResult DeleteFiles(); - - ESubOperationResult CheckForWaitState(); - // Helper filesystem methods - static bool SetFileDirectoryTime(LPCTSTR lpszName, const CFileInfoPtr& spFileInfo); - bool GetRequiredFreeSpace(ull_t *pi64Needed, ull_t *pi64Available); - ESubOperationResult OpenSourceFileFB(TAutoFileHandle& hFile, const CFileInfoPtr& spSrcFileInfo, bool bNoBuffering); - ESubOperationResult OpenDestinationFileFB(TAutoFileHandle& hFile, const chcore::TSmartPath& pathDstFile, bool bNoBuffering, const CFileInfoPtr& spSrcFileInfo, unsigned long long& ullSeekTo, bool& bFreshlyCreated); - ESubOperationResult OpenExistingDestinationFileFB(TAutoFileHandle& hFile, const chcore::TSmartPath& pathDstFilePath, bool bNoBuffering); + TSubTaskBase::ESubOperationResult CheckForFreeSpaceFB(); - ESubOperationResult SetFilePointerFB(HANDLE hFile, long long llDistance, const chcore::TSmartPath& pathFile, bool& bSkip); - ESubOperationResult SetEndOfFileFB(HANDLE hFile, const chcore::TSmartPath& pathFile, bool& bSkip); - - ESubOperationResult ReadFileFB(HANDLE hFile, CDataBuffer& rBuffer, DWORD dwToRead, DWORD& rdwBytesRead, const chcore::TSmartPath& pathFile, bool& bSkip); - ESubOperationResult WriteFileFB(HANDLE hFile, CDataBuffer& rBuffer, DWORD dwToWrite, DWORD& rdwBytesWritten, const chcore::TSmartPath& pathFile, bool& bSkip); - - ESubOperationResult CheckForFreeSpaceFB(); - // m_nStatus void SetStatusNL(UINT nStatus, UINT nMask); UINT GetStatusNL(UINT nMask = 0xffffffff); void CalculateProcessedSize(); void CalculateProcessedSizeNL(); - void CalculateTotalSize(); void CalculateTotalSizeNL(); void DeleteProgress(); @@ -392,16 +208,6 @@ static void OnCfgOptionChanged(const std::set& rsetChanges, void* pParam); - chcore::TSmartPath FindFreeSubstituteName(chcore::TSmartPath pathSrcPath, chcore::TSmartPath pathDstPath) const; - chcore::TSmartPath GetDestinationPath(const CFileInfoPtr& spFileInfo, chcore::TSmartPath strPath, int iFlags) const; - - int GetBufferIndex(const CFileInfoPtr& spFileInfo); - int GetDriveNumber(const CFileInfoPtr& spFileInfo); - bool GetMove(const CFileInfoPtr& spFileInfo); - - static void GetDriveData(const chcore::TSmartPath& spPath, int *piDrvNum, UINT *puiDrvType); - static bool PathExist(chcore::TSmartPath strPath); // check for file or folder existence - private: // task initial information (needed to start a task); might be a bit processed. TTaskDefinition m_tTaskDefinition;