Index: src/ch/FileFilter.cpp =================================================================== diff -u -N -rb684bec49aaaea4b89ab2e599497f4085d8698a3 -r6e8aa26e2428e3bc71099255c5911f57bc722100 --- src/ch/FileFilter.cpp (.../FileFilter.cpp) (revision b684bec49aaaea4b89ab2e599497f4085d8698a3) +++ src/ch/FileFilter.cpp (.../FileFilter.cpp) (revision 6e8aa26e2428e3bc71099255c5911f57bc722100) @@ -1,21 +1,21 @@ /*************************************************************************** - * Copyright (C) 2001-2008 by Jozef Starosczyk * - * ixen@copyhandler.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU Library General Public License * - * (version 2) as published by the Free Software Foundation; * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ +* Copyright (C) 2001-2008 by Jozef Starosczyk * +* ixen@copyhandler.com * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU Library General Public License * +* (version 2) as published by the Free Software Foundation; * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License for more details. * +* * +* You should have received a copy of the GNU Library General Public * +* License along with this program; if not, write to the * +* Free Software Foundation, Inc., * +* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * +***************************************************************************/ #include "stdafx.h" #include "FileInfo.h" #include "FileFilter.h" @@ -187,40 +187,40 @@ void CFileFilter::StoreInConfig(chcore::TConfig& rConfig) const { - SetConfigValue(rConfig, _T("IncludeMask.Use"), m_bUseMask); - SetConfigValue(rConfig, _T("IncludeMask.MaskList.Mask"), m_astrMask); + SetConfigValue(rConfig, _T("IncludeMask.Use"), m_bUseMask); + SetConfigValue(rConfig, _T("IncludeMask.MaskList.Mask"), m_astrMask); - SetConfigValue(rConfig, _T("ExcludeMask.Use"), m_bUseExcludeMask); - SetConfigValue(rConfig, _T("ExcludeMask.MaskList.Mask"), m_astrExcludeMask); + SetConfigValue(rConfig, _T("ExcludeMask.Use"), m_bUseExcludeMask); + SetConfigValue(rConfig, _T("ExcludeMask.MaskList.Mask"), m_astrExcludeMask); - SetConfigValue(rConfig, _T("SizeA.Use"), m_bUseSize); - SetConfigValue(rConfig, _T("SizeA.FilteringType"), m_iSizeType1); - SetConfigValue(rConfig, _T("SizeA.Value"), m_ullSize1); - SetConfigValue(rConfig, _T("SizeB.Use"), m_bUseSize2); - SetConfigValue(rConfig, _T("SizeB.FilteringType"), m_iSizeType2); - SetConfigValue(rConfig, _T("SizeB.Value"), m_ullSize2); + SetConfigValue(rConfig, _T("SizeA.Use"), m_bUseSize); + SetConfigValue(rConfig, _T("SizeA.FilteringType"), m_iSizeType1); + SetConfigValue(rConfig, _T("SizeA.Value"), m_ullSize1); + SetConfigValue(rConfig, _T("SizeB.Use"), m_bUseSize2); + SetConfigValue(rConfig, _T("SizeB.FilteringType"), m_iSizeType2); + SetConfigValue(rConfig, _T("SizeB.Value"), m_ullSize2); - SetConfigValue(rConfig, _T("DateA.Use"), m_bUseDate); - SetConfigValue(rConfig, _T("DateA.Type"), m_iDateType); // created/last modified/last accessed - SetConfigValue(rConfig, _T("DateA.FilteringType"), m_iDateType1); // before/after - SetConfigValue(rConfig, _T("DateA.EnableDatePart"), m_bDate1); - SetConfigValue(rConfig, _T("DateA.DateValue"), m_tDate1.GetTime()); - SetConfigValue(rConfig, _T("DateA.EnableTimePart"), m_bTime1); - SetConfigValue(rConfig, _T("DateA.TimeValue"), m_tTime1.GetTime()); + SetConfigValue(rConfig, _T("DateA.Use"), m_bUseDate); + SetConfigValue(rConfig, _T("DateA.Type"), m_iDateType); // created/last modified/last accessed + SetConfigValue(rConfig, _T("DateA.FilteringType"), m_iDateType1); // before/after + SetConfigValue(rConfig, _T("DateA.EnableDatePart"), m_bDate1); + SetConfigValue(rConfig, _T("DateA.DateValue"), m_tDate1.GetTime()); + SetConfigValue(rConfig, _T("DateA.EnableTimePart"), m_bTime1); + SetConfigValue(rConfig, _T("DateA.TimeValue"), m_tTime1.GetTime()); - SetConfigValue(rConfig, _T("DateB.Type"), m_bUseDate2); - SetConfigValue(rConfig, _T("DateB.FilteringType"), m_iDateType2); - SetConfigValue(rConfig, _T("DateB.EnableDatePart"), m_bDate2); - SetConfigValue(rConfig, _T("DateB.DateValue"), m_tDate2.GetTime()); - SetConfigValue(rConfig, _T("DateB.EnableTimePart"), m_bTime2); - SetConfigValue(rConfig, _T("DateB.TimeValue"), m_tTime2.GetTime()); + SetConfigValue(rConfig, _T("DateB.Type"), m_bUseDate2); + SetConfigValue(rConfig, _T("DateB.FilteringType"), m_iDateType2); + SetConfigValue(rConfig, _T("DateB.EnableDatePart"), m_bDate2); + SetConfigValue(rConfig, _T("DateB.DateValue"), m_tDate2.GetTime()); + SetConfigValue(rConfig, _T("DateB.EnableTimePart"), m_bTime2); + SetConfigValue(rConfig, _T("DateB.TimeValue"), m_tTime2.GetTime()); - SetConfigValue(rConfig, _T("Attributes.Use"), m_bUseAttributes); - SetConfigValue(rConfig, _T("Attributes.Archive"), m_iArchive); - SetConfigValue(rConfig, _T("Attributes.ReadOnly"), m_iReadOnly); - SetConfigValue(rConfig, _T("Attributes.Hidden"), m_iHidden); - SetConfigValue(rConfig, _T("Attributes.System"), m_iSystem); - SetConfigValue(rConfig, _T("Attributes.Directory"), m_iDirectory); + SetConfigValue(rConfig, _T("Attributes.Use"), m_bUseAttributes); + SetConfigValue(rConfig, _T("Attributes.Archive"), m_iArchive); + SetConfigValue(rConfig, _T("Attributes.ReadOnly"), m_iReadOnly); + SetConfigValue(rConfig, _T("Attributes.Hidden"), m_iHidden); + SetConfigValue(rConfig, _T("Attributes.System"), m_iSystem); + SetConfigValue(rConfig, _T("Attributes.Directory"), m_iDirectory); } void CFileFilter::ReadFromConfig(const chcore::TConfig& rConfig) @@ -261,7 +261,7 @@ m_iDateType1 = EQ; if(!GetConfigValue(rConfig, _T("DateA.EnableDatePart"), m_bDate1)) m_bDate1 = false; - + if(!GetConfigValue(rConfig, _T("DateA.DateValue"), tTime)) tTime = 0; m_tDate1 = tTime; Index: src/ch/TBasicProgressInfo.cpp =================================================================== diff -u -N -r8c87d4185fbe5b952c49f72afcfd5f9fca338fb4 -r6e8aa26e2428e3bc71099255c5911f57bc722100 --- src/ch/TBasicProgressInfo.cpp (.../TBasicProgressInfo.cpp) (revision 8c87d4185fbe5b952c49f72afcfd5f9fca338fb4) +++ src/ch/TBasicProgressInfo.cpp (.../TBasicProgressInfo.cpp) (revision 6e8aa26e2428e3bc71099255c5911f57bc722100) @@ -37,56 +37,56 @@ void TTaskBasicProgressInfo::SetCurrentIndex(size_t stIndex) { - boost::unique_lock lock(m_lock); - m_stCurrentIndex = stIndex; - m_ullCurrentFileProcessedSize = 0; + boost::unique_lock lock(m_lock); + m_stCurrentIndex = stIndex; + m_ullCurrentFileProcessedSize = 0; } void TTaskBasicProgressInfo::IncreaseCurrentIndex() { - boost::unique_lock lock(m_lock); - ++m_stCurrentIndex; - m_ullCurrentFileProcessedSize = 0; + boost::unique_lock lock(m_lock); + ++m_stCurrentIndex; + m_ullCurrentFileProcessedSize = 0; } size_t TTaskBasicProgressInfo::GetCurrentIndex() const { - boost::shared_lock lock(m_lock); - return m_stCurrentIndex; + boost::shared_lock lock(m_lock); + return m_stCurrentIndex; } void TTaskBasicProgressInfo::SetCurrentFileProcessedSize(unsigned long long ullSize) { - boost::unique_lock lock(m_lock); - m_ullCurrentFileProcessedSize = ullSize; + boost::unique_lock lock(m_lock); + m_ullCurrentFileProcessedSize = ullSize; } unsigned long long TTaskBasicProgressInfo::GetCurrentFileProcessedSize() const { - boost::shared_lock lock(m_lock); - return m_ullCurrentFileProcessedSize; + boost::shared_lock lock(m_lock); + return m_ullCurrentFileProcessedSize; } void TTaskBasicProgressInfo::IncreaseCurrentFileProcessedSize(unsigned long long ullSizeToAdd) { - boost::unique_lock lock(m_lock); - m_ullCurrentFileProcessedSize += ullSizeToAdd; + boost::unique_lock lock(m_lock); + m_ullCurrentFileProcessedSize += ullSizeToAdd; } void TTaskBasicProgressInfo::SetSubOperationIndex(size_t stSubOperationIndex) { - boost::unique_lock lock(m_lock); - m_stSubOperationIndex = stSubOperationIndex; + boost::unique_lock lock(m_lock); + m_stSubOperationIndex = stSubOperationIndex; } size_t TTaskBasicProgressInfo::GetSubOperationIndex() const { - boost::shared_lock lock(m_lock); - return m_stSubOperationIndex; + boost::shared_lock lock(m_lock); + return m_stSubOperationIndex; } void TTaskBasicProgressInfo::IncreaseSubOperationIndex() { - boost::unique_lock lock(m_lock); - ++m_stSubOperationIndex; + boost::unique_lock lock(m_lock); + ++m_stSubOperationIndex; } Index: src/ch/TBasicProgressInfo.h =================================================================== diff -u -N -r8c87d4185fbe5b952c49f72afcfd5f9fca338fb4 -r6e8aa26e2428e3bc71099255c5911f57bc722100 --- src/ch/TBasicProgressInfo.h (.../TBasicProgressInfo.h) (revision 8c87d4185fbe5b952c49f72afcfd5f9fca338fb4) +++ src/ch/TBasicProgressInfo.h (.../TBasicProgressInfo.h) (revision 6e8aa26e2428e3bc71099255c5911f57bc722100) @@ -30,64 +30,64 @@ class TTaskBasicProgressInfo { public: - TTaskBasicProgressInfo(); - ~TTaskBasicProgressInfo(); + TTaskBasicProgressInfo(); + ~TTaskBasicProgressInfo(); - void SetCurrentIndex(size_t stIndex); // might be unneeded when serialization is implemented - void IncreaseCurrentIndex(); - size_t GetCurrentIndex() const; + 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 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(); + 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; + template + void load(Archive& ar, unsigned int /*uiVersion*/) + { + size_t stCurrentIndex = 0; + ar >> stCurrentIndex; - unsigned long long ullCurrentFileProcessedSize = 0; - ar >> ullCurrentFileProcessedSize; + unsigned long long ullCurrentFileProcessedSize = 0; + ar >> ullCurrentFileProcessedSize; - size_t stSubOperationIndex = 0; - ar >> stSubOperationIndex; + size_t stSubOperationIndex = 0; + ar >> stSubOperationIndex; - boost::unique_lock lock(m_lock); + boost::unique_lock lock(m_lock); - m_stCurrentIndex = stCurrentIndex; - m_ullCurrentFileProcessedSize = ullCurrentFileProcessedSize; - m_stSubOperationIndex = stSubOperationIndex; - } + m_stCurrentIndex = stCurrentIndex; + m_ullCurrentFileProcessedSize = ullCurrentFileProcessedSize; + m_stSubOperationIndex = stSubOperationIndex; + } - template - void save(Archive& ar, unsigned int /*uiVersion*/) const - { - m_lock.lock_shared(); + 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; + size_t stCurrentIndex = m_stCurrentIndex; + unsigned long long ullCurrentFileProcessedSize = m_ullCurrentFileProcessedSize; + size_t stSubOperationIndex = m_stSubOperationIndex; - m_lock.unlock_shared(); + m_lock.unlock_shared(); - ar << stCurrentIndex; - ar << ullCurrentFileProcessedSize; - ar << stSubOperationIndex; - } + ar << stCurrentIndex; + ar << ullCurrentFileProcessedSize; + ar << stSubOperationIndex; + } - BOOST_SERIALIZATION_SPLIT_MEMBER(); + 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 + 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; + mutable boost::shared_mutex m_lock; }; #endif Index: src/ch/TLocalFilesystem.cpp =================================================================== diff -u -N -r8c87d4185fbe5b952c49f72afcfd5f9fca338fb4 -r6e8aa26e2428e3bc71099255c5911f57bc722100 --- src/ch/TLocalFilesystem.cpp (.../TLocalFilesystem.cpp) (revision 8c87d4185fbe5b952c49f72afcfd5f9fca338fb4) +++ src/ch/TLocalFilesystem.cpp (.../TLocalFilesystem.cpp) (revision 6e8aa26e2428e3bc71099255c5911f57bc722100) @@ -89,14 +89,14 @@ bool TLocalFilesystem::SetFileDirectoryTime(LPCTSTR lpszName, const FILETIME& ftCreationTime, const FILETIME& ftLastAccessTime, const FILETIME& ftLastWriteTime) { - TAutoFileHandle hFile = CreateFile(lpszName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, NULL); - if(hFile == INVALID_HANDLE_VALUE) - return false; + TAutoFileHandle hFile = CreateFile(lpszName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, NULL); + if(hFile == INVALID_HANDLE_VALUE) + return false; - BOOL bResult = (!SetFileTime(hFile, &ftCreationTime, &ftLastAccessTime, &ftLastWriteTime)); + BOOL bResult = (!SetFileTime(hFile, &ftCreationTime, &ftLastAccessTime, &ftLastWriteTime)); - if(!hFile.Close()) - return false; + if(!hFile.Close()) + return false; - return bResult != 0; + return bResult != 0; } Index: src/ch/TSubTaskBase.cpp =================================================================== diff -u -N -r8c87d4185fbe5b952c49f72afcfd5f9fca338fb4 -r6e8aa26e2428e3bc71099255c5911f57bc722100 --- src/ch/TSubTaskBase.cpp (.../TSubTaskBase.cpp) (revision 8c87d4185fbe5b952c49f72afcfd5f9fca338fb4) +++ src/ch/TSubTaskBase.cpp (.../TSubTaskBase.cpp) (revision 6e8aa26e2428e3bc71099255c5911f57bc722100) @@ -32,7 +32,7 @@ // TSubTaskBase TSubTaskBase::TSubTaskBase(TSubTaskContext& rContext) : - m_rContext(rContext) +m_rContext(rContext) { } @@ -43,95 +43,95 @@ int TSubTaskBase::GetDriveNumber(const CFileInfoPtr& spFileInfo) { - if(!spFileInfo) - THROW(_T("Invalid pointer"), 0, 0, 0); - if(spFileInfo->GetSrcIndex() == std::numeric_limits::max()) - THROW(_T("Received non-relative (standalone) path info"), 0, 0, 0); + if(!spFileInfo) + THROW(_T("Invalid pointer"), 0, 0, 0); + if(spFileInfo->GetSrcIndex() == std::numeric_limits::max()) + THROW(_T("Received non-relative (standalone) path info"), 0, 0, 0); - // check if this information has already been stored - size_t stBaseIndex = spFileInfo->GetSrcIndex(); - if(stBaseIndex >= GetContext().GetBasePathDataContainer().GetCount()) - THROW(_T("Index out of bounds"), 0, 0, 0); + // check if this information has already been stored + size_t stBaseIndex = spFileInfo->GetSrcIndex(); + if(stBaseIndex >= GetContext().GetBasePathDataContainer().GetCount()) + THROW(_T("Index out of bounds"), 0, 0, 0); - TBasePathDataPtr spPathData = GetContext().GetBasePathDataContainer().GetAt(stBaseIndex); - if(spPathData->IsDriveNumberSet()) - return spPathData->GetDriveNumber(); + TBasePathDataPtr spPathData = GetContext().GetBasePathDataContainer().GetAt(stBaseIndex); + if(spPathData->IsDriveNumberSet()) + return spPathData->GetDriveNumber(); - // drive number wasn't cached previously - read it now - int iDriveNumber = 0; - TLocalFilesystem::GetDriveData(GetContext().GetTaskDefinition().GetSourcePathAt(stBaseIndex), &iDriveNumber, NULL); + // drive number wasn't cached previously - read it now + int iDriveNumber = 0; + TLocalFilesystem::GetDriveData(GetContext().GetTaskDefinition().GetSourcePathAt(stBaseIndex), &iDriveNumber, NULL); - spPathData->SetDriveNumber(iDriveNumber); + spPathData->SetDriveNumber(iDriveNumber); - return iDriveNumber; + return iDriveNumber; } chcore::TSmartPath TSubTaskBase::CalculateDestinationPath(const CFileInfoPtr& spFileInfo, chcore::TSmartPath pathDst, int iFlags) const { - const TBasePathDataContainer& rSourcePathsInfo = GetContext().GetBasePathDataContainer(); + const TBasePathDataContainer& rSourcePathsInfo = GetContext().GetBasePathDataContainer(); - if(!spFileInfo) - THROW(_T("Invalid pointer"), 0, 0, 0); + if(!spFileInfo) + THROW(_T("Invalid pointer"), 0, 0, 0); - // iFlags: bit 0-ignore folders; bit 1-force creating directories - if (iFlags & 0x02) - { - // force create directories - chcore::TSmartPath pathCombined = pathDst + spFileInfo->GetFullFilePath().GetFileDir(); + // iFlags: bit 0-ignore folders; bit 1-force creating directories + if (iFlags & 0x02) + { + // force create directories + chcore::TSmartPath pathCombined = pathDst + spFileInfo->GetFullFilePath().GetFileDir(); - // force create directory - SHCreateDirectoryEx(NULL, pathCombined.ToString(), NULL); + // force create directory + SHCreateDirectoryEx(NULL, pathCombined.ToString(), NULL); - return pathCombined + spFileInfo->GetFullFilePath().GetFileName(); - } - else - { - size_t stSrcIndex = spFileInfo->GetSrcIndex(); + return pathCombined + spFileInfo->GetFullFilePath().GetFileName(); + } + else + { + size_t stSrcIndex = spFileInfo->GetSrcIndex(); - if (!(iFlags & 0x01) && stSrcIndex != std::numeric_limits::max()) - { - // generate new dest name - if(!rSourcePathsInfo.GetAt(stSrcIndex)->IsDestinationPathSet()) - { - chcore::TSmartPath pathSubst = FindFreeSubstituteName(spFileInfo->GetFullFilePath(), pathDst); - rSourcePathsInfo.GetAt(stSrcIndex)->SetDestinationPath(pathSubst); - } + if (!(iFlags & 0x01) && stSrcIndex != std::numeric_limits::max()) + { + // generate new dest name + if(!rSourcePathsInfo.GetAt(stSrcIndex)->IsDestinationPathSet()) + { + chcore::TSmartPath pathSubst = FindFreeSubstituteName(spFileInfo->GetFullFilePath(), pathDst); + rSourcePathsInfo.GetAt(stSrcIndex)->SetDestinationPath(pathSubst); + } - return pathDst + rSourcePathsInfo.GetAt(stSrcIndex)->GetDestinationPath() + spFileInfo->GetFilePath(); - } - else - return pathDst + spFileInfo->GetFullFilePath().GetFileName(); - } + return pathDst + rSourcePathsInfo.GetAt(stSrcIndex)->GetDestinationPath() + spFileInfo->GetFilePath(); + } + else + return pathDst + spFileInfo->GetFullFilePath().GetFileName(); + } } // finds another name for a copy of src file(folder) in dest location chcore::TSmartPath TSubTaskBase::FindFreeSubstituteName(chcore::TSmartPath pathSrcPath, chcore::TSmartPath pathDstPath) const { - const TTaskDefinition& rTaskDefinition = GetContext().GetTaskDefinition(); + const TTaskDefinition& rTaskDefinition = GetContext().GetTaskDefinition(); - // get the name from srcpath - pathSrcPath.StripSeparatorAtEnd(); + // get the name from srcpath + pathSrcPath.StripSeparatorAtEnd(); - chcore::TSmartPath pathFilename = pathSrcPath.GetFileName(); + chcore::TSmartPath pathFilename = pathSrcPath.GetFileName(); - // set the dest path - CString strCheckPath; - ictranslate::CFormat fmt(GetTaskPropValue(rTaskDefinition.GetConfiguration())); - fmt.SetParam(_t("%name"), pathFilename.ToString()); - chcore::TSmartPath pathCheckPath(chcore::PathFromString((PCTSTR)fmt)); + // set the dest path + CString strCheckPath; + ictranslate::CFormat fmt(GetTaskPropValue(rTaskDefinition.GetConfiguration())); + fmt.SetParam(_t("%name"), pathFilename.ToString()); + chcore::TSmartPath pathCheckPath(chcore::PathFromString((PCTSTR)fmt)); - // when adding to strDstPath check if the path already exists - if so - try again - int iCounter=1; - CString strFmt = GetTaskPropValue(rTaskDefinition.GetConfiguration()); - while(TLocalFilesystem::PathExist(pathDstPath + pathCheckPath)) - { - fmt.SetFormat(strFmt); - fmt.SetParam(_t("%name"), pathFilename.ToString()); - fmt.SetParam(_t("%count"), ++iCounter); - pathCheckPath.FromString((PCTSTR)fmt); - } + // when adding to strDstPath check if the path already exists - if so - try again + int iCounter=1; + CString strFmt = GetTaskPropValue(rTaskDefinition.GetConfiguration()); + while(TLocalFilesystem::PathExist(pathDstPath + pathCheckPath)) + { + fmt.SetFormat(strFmt); + fmt.SetParam(_t("%name"), pathFilename.ToString()); + fmt.SetParam(_t("%count"), ++iCounter); + pathCheckPath.FromString((PCTSTR)fmt); + } - return pathCheckPath; + return pathCheckPath; } Index: src/ch/TSubTaskBase.h =================================================================== diff -u -N -r8c87d4185fbe5b952c49f72afcfd5f9fca338fb4 -r6e8aa26e2428e3bc71099255c5911f57bc722100 --- src/ch/TSubTaskBase.h (.../TSubTaskBase.h) (revision 8c87d4185fbe5b952c49f72afcfd5f9fca338fb4) +++ src/ch/TSubTaskBase.h (.../TSubTaskBase.h) (revision 6e8aa26e2428e3bc71099255c5911f57bc722100) @@ -49,14 +49,14 @@ virtual ESubOperationResult Exec() = 0; - TSubTaskContext& GetContext() { return m_rContext; } - const TSubTaskContext& GetContext() const { return m_rContext; } + TSubTaskContext& GetContext() { return m_rContext; } + const TSubTaskContext& GetContext() const { return m_rContext; } protected: - // some common operations - int GetDriveNumber(const CFileInfoPtr& spFileInfo); - chcore::TSmartPath CalculateDestinationPath(const CFileInfoPtr& spFileInfo, chcore::TSmartPath strPath, int iFlags) const; - chcore::TSmartPath FindFreeSubstituteName(chcore::TSmartPath pathSrcPath, chcore::TSmartPath pathDstPath) const; + // some common operations + int GetDriveNumber(const CFileInfoPtr& spFileInfo); + chcore::TSmartPath CalculateDestinationPath(const CFileInfoPtr& spFileInfo, chcore::TSmartPath strPath, int iFlags) const; + chcore::TSmartPath FindFreeSubstituteName(chcore::TSmartPath pathSrcPath, chcore::TSmartPath pathDstPath) const; private: TSubTaskContext& m_rContext; Index: src/ch/TSubTaskContext.cpp =================================================================== diff -u -N -r8c87d4185fbe5b952c49f72afcfd5f9fca338fb4 -r6e8aa26e2428e3bc71099255c5911f57bc722100 --- src/ch/TSubTaskContext.cpp (.../TSubTaskContext.cpp) (revision 8c87d4185fbe5b952c49f72afcfd5f9fca338fb4) +++ src/ch/TSubTaskContext.cpp (.../TSubTaskContext.cpp) (revision 6e8aa26e2428e3bc71099255c5911f57bc722100) @@ -24,16 +24,16 @@ #include "TSubTaskContext.h" TSubTaskContext::TSubTaskContext(TTaskDefinition& rTaskDefinition, TBasePathDataContainer& rBasePathDataContainer, CFileInfoArray& rFilesCache, TTaskLocalStats& rTaskLocalStats, - TTaskBasicProgressInfo& rTaskBasicProgressInfo, TTaskConfigTracker& rCfgTracker, icpf::log_file& rLog, chcore::IFeedbackHandler* piFeedbackHandler, TWorkerThreadController& rThreadController) : - m_rTaskDefinition(rTaskDefinition), - m_rBasePathDataContainer(rBasePathDataContainer), - m_rFilesCache(rFilesCache), - m_rTaskLocalStats(rTaskLocalStats), - m_rTaskBasicProgressInfo(rTaskBasicProgressInfo), - m_rCfgTracker(rCfgTracker), - m_rLog(rLog), - m_piFeedbackHandler(piFeedbackHandler), - m_rThreadController(rThreadController) + TTaskBasicProgressInfo& rTaskBasicProgressInfo, TTaskConfigTracker& rCfgTracker, icpf::log_file& rLog, chcore::IFeedbackHandler* piFeedbackHandler, TWorkerThreadController& rThreadController) : +m_rTaskDefinition(rTaskDefinition), +m_rBasePathDataContainer(rBasePathDataContainer), +m_rFilesCache(rFilesCache), +m_rTaskLocalStats(rTaskLocalStats), +m_rTaskBasicProgressInfo(rTaskBasicProgressInfo), +m_rCfgTracker(rCfgTracker), +m_rLog(rLog), +m_piFeedbackHandler(piFeedbackHandler), +m_rThreadController(rThreadController) { } Index: src/ch/TSubTaskContext.h =================================================================== diff -u -N -r8c87d4185fbe5b952c49f72afcfd5f9fca338fb4 -r6e8aa26e2428e3bc71099255c5911f57bc722100 --- src/ch/TSubTaskContext.h (.../TSubTaskContext.h) (revision 8c87d4185fbe5b952c49f72afcfd5f9fca338fb4) +++ src/ch/TSubTaskContext.h (.../TSubTaskContext.h) (revision 6e8aa26e2428e3bc71099255c5911f57bc722100) @@ -40,62 +40,61 @@ { public: TSubTaskContext(TTaskDefinition& rTaskDefinition, TBasePathDataContainer& rBasePathDataContainer, CFileInfoArray& rFilesCache, TTaskLocalStats& rTaskLocalStats, - TTaskBasicProgressInfo& rTaskBasicProgressInfo, TTaskConfigTracker& rCfgTracker, icpf::log_file& rLog, - chcore::IFeedbackHandler* piFeedbackHandler, TWorkerThreadController& rThreadController); + TTaskBasicProgressInfo& rTaskBasicProgressInfo, TTaskConfigTracker& rCfgTracker, icpf::log_file& rLog, + chcore::IFeedbackHandler* piFeedbackHandler, TWorkerThreadController& rThreadController); ~TSubTaskContext(); TTaskDefinition& GetTaskDefinition() { return m_rTaskDefinition; } - const TTaskDefinition& GetTaskDefinition() const { return m_rTaskDefinition; } + const TTaskDefinition& GetTaskDefinition() const { return m_rTaskDefinition; } - TBasePathDataContainer& GetBasePathDataContainer() { return m_rBasePathDataContainer; } - const TBasePathDataContainer& GetBasePathDataContainer() const { return m_rBasePathDataContainer; } + TBasePathDataContainer& GetBasePathDataContainer() { return m_rBasePathDataContainer; } + const TBasePathDataContainer& GetBasePathDataContainer() const { return m_rBasePathDataContainer; } - CFileInfoArray& GetFilesCache() { return m_rFilesCache; } - const CFileInfoArray& GetFilesCache() const { return m_rFilesCache; } + CFileInfoArray& GetFilesCache() { return m_rFilesCache; } + const CFileInfoArray& GetFilesCache() const { return m_rFilesCache; } - TTaskLocalStats& GetTaskLocalStats() { return m_rTaskLocalStats; } - const TTaskLocalStats& GetTaskLocalStats() const { return m_rTaskLocalStats; } + TTaskLocalStats& GetTaskLocalStats() { return m_rTaskLocalStats; } + const TTaskLocalStats& GetTaskLocalStats() const { return m_rTaskLocalStats; } - TTaskBasicProgressInfo& GetTaskBasicProgressInfo() { return m_rTaskBasicProgressInfo; } - const TTaskBasicProgressInfo& GetTaskBasicProgressInfo() const { return m_rTaskBasicProgressInfo; } + TTaskBasicProgressInfo& GetTaskBasicProgressInfo() { return m_rTaskBasicProgressInfo; } + const TTaskBasicProgressInfo& GetTaskBasicProgressInfo() const { return m_rTaskBasicProgressInfo; } - TTaskConfigTracker& GetCfgTracker() { return m_rCfgTracker; } - const TTaskConfigTracker& GetCfgTracker() const { return m_rCfgTracker; } + TTaskConfigTracker& GetCfgTracker() { return m_rCfgTracker; } + const TTaskConfigTracker& GetCfgTracker() const { return m_rCfgTracker; } - icpf::log_file& GetLog() { return m_rLog; } - const icpf::log_file& GetLog() const { return m_rLog; } + icpf::log_file& GetLog() { return m_rLog; } + const icpf::log_file& GetLog() const { return m_rLog; } - chcore::IFeedbackHandler* GetFeedbackHandler() { return m_piFeedbackHandler; } - const chcore::IFeedbackHandler* GetFeedbackHandler() const { return m_piFeedbackHandler; } + chcore::IFeedbackHandler* GetFeedbackHandler() { return m_piFeedbackHandler; } + const chcore::IFeedbackHandler* GetFeedbackHandler() const { return m_piFeedbackHandler; } - TWorkerThreadController& GetThreadController() { return m_rThreadController; } - const TWorkerThreadController& GetThreadController() const { return m_rThreadController; } + TWorkerThreadController& GetThreadController() { return m_rThreadController; } + const TWorkerThreadController& GetThreadController() const { return m_rThreadController; } private: TTaskDefinition& m_rTaskDefinition; - // information about input paths - TBasePathDataContainer& m_rBasePathDataContainer; + // information about input paths + TBasePathDataContainer& m_rBasePathDataContainer; // data on which to operate CFileInfoArray& m_rFilesCache; - // local stats for task - TTaskLocalStats& m_rTaskLocalStats; - TTaskBasicProgressInfo& m_rTaskBasicProgressInfo; + // local stats for task + TTaskLocalStats& m_rTaskLocalStats; + TTaskBasicProgressInfo& m_rTaskBasicProgressInfo; - // configuration changes tracking - TTaskConfigTracker& m_rCfgTracker; + // configuration changes tracking + TTaskConfigTracker& m_rCfgTracker; // additional data icpf::log_file& m_rLog; // feedback handling chcore::IFeedbackHandler* m_piFeedbackHandler; - // thread control - TWorkerThreadController& m_rThreadController; + // thread control + TWorkerThreadController& m_rThreadController; }; - #endif // __TSUBTASKCONTEXT_H__ \ No newline at end of file Index: src/ch/TSubTaskCopyMove.cpp =================================================================== diff -u -N -r8c87d4185fbe5b952c49f72afcfd5f9fca338fb4 -r6e8aa26e2428e3bc71099255c5911f57bc722100 --- src/ch/TSubTaskCopyMove.cpp (.../TSubTaskCopyMove.cpp) (revision 8c87d4185fbe5b952c49f72afcfd5f9fca338fb4) +++ src/ch/TSubTaskCopyMove.cpp (.../TSubTaskCopyMove.cpp) (revision 6e8aa26e2428e3bc71099255c5911f57bc722100) @@ -36,1058 +36,1058 @@ struct CUSTOM_COPY_PARAMS { - CFileInfoPtr spSrcFile; // CFileInfo - src file - chcore::TSmartPath pathDstFile; // dest path with filename + 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) + CDataBuffer dbBuffer; // buffer handling + bool bOnlyCreate; // flag from configuration - skips real copying - only create + bool bProcessed; // has the element been processed ? (false if skipped) }; TSubTaskCopyMove::TSubTaskCopyMove(TSubTaskContext& tSubTaskContext) : - TSubTaskBase(tSubTaskContext) +TSubTaskBase(tSubTaskContext) { } TSubTaskBase::ESubOperationResult TSubTaskCopyMove::Exec() { - icpf::log_file& rLog = GetContext().GetLog(); - CFileInfoArray& rFilesCache = GetContext().GetFilesCache(); - TTaskDefinition& rTaskDefinition = GetContext().GetTaskDefinition(); - TTaskConfigTracker& rCfgTracker = GetContext().GetCfgTracker(); - TTaskBasicProgressInfo& rBasicProgressInfo = GetContext().GetTaskBasicProgressInfo(); - TWorkerThreadController& rThreadController = GetContext().GetThreadController(); - chcore::IFeedbackHandler* piFeedbackHandler = GetContext().GetFeedbackHandler(); - TTaskLocalStats& rLocalStats = GetContext().GetTaskLocalStats(); + icpf::log_file& rLog = GetContext().GetLog(); + CFileInfoArray& rFilesCache = GetContext().GetFilesCache(); + TTaskDefinition& rTaskDefinition = GetContext().GetTaskDefinition(); + TTaskConfigTracker& rCfgTracker = GetContext().GetCfgTracker(); + TTaskBasicProgressInfo& rBasicProgressInfo = GetContext().GetTaskBasicProgressInfo(); + TWorkerThreadController& rThreadController = GetContext().GetThreadController(); + chcore::IFeedbackHandler* piFeedbackHandler = GetContext().GetFeedbackHandler(); + TTaskLocalStats& rLocalStats = GetContext().GetTaskLocalStats(); - BOOST_ASSERT(piFeedbackHandler != NULL); - if(piFeedbackHandler == NULL) - return eSubResult_Error; + BOOST_ASSERT(piFeedbackHandler != NULL); + if(piFeedbackHandler == NULL) + return eSubResult_Error; - // log - rLog.logi(_T("Processing files/folders (ProcessFiles)")); + // log + rLog.logi(_T("Processing files/folders (ProcessFiles)")); - // count how much has been done (updates also a member in TSubTaskCopyMoveArray) - rLocalStats.SetProcessedSize(rFilesCache.CalculatePartialSize(rBasicProgressInfo.GetCurrentIndex())); + // count how much has been done (updates also a member in TSubTaskCopyMoveArray) + rLocalStats.SetProcessedSize(rFilesCache.CalculatePartialSize(rBasicProgressInfo.GetCurrentIndex())); - // begin at index which wasn't processed previously - size_t stSize = rFilesCache.GetSize(); - bool bIgnoreFolders = GetTaskPropValue(rTaskDefinition.GetConfiguration()); - bool bForceDirectories = GetTaskPropValue(rTaskDefinition.GetConfiguration()); + // begin at index which wasn't processed previously + size_t stSize = rFilesCache.GetSize(); + bool bIgnoreFolders = GetTaskPropValue(rTaskDefinition.GetConfiguration()); + bool bForceDirectories = GetTaskPropValue(rTaskDefinition.GetConfiguration()); - // create a buffer of size m_nBufferSize - CUSTOM_COPY_PARAMS ccp; - ccp.bProcessed = false; - ccp.bOnlyCreate = GetTaskPropValue(rTaskDefinition.GetConfiguration()); + // create a buffer of size m_nBufferSize + CUSTOM_COPY_PARAMS ccp; + ccp.bProcessed = false; + ccp.bOnlyCreate = GetTaskPropValue(rTaskDefinition.GetConfiguration()); - // remove changes in buffer sizes to avoid re-creation later - rCfgTracker.RemoveModificationSet(TOptionsSet() % eTO_DefaultBufferSize % eTO_OneDiskBufferSize % eTO_TwoDisksBufferSize % eTO_CDBufferSize % eTO_LANBufferSize % eTO_UseOnlyDefaultBuffer); + // remove changes in buffer sizes to avoid re-creation later + rCfgTracker.RemoveModificationSet(TOptionsSet() % eTO_DefaultBufferSize % eTO_OneDiskBufferSize % eTO_TwoDisksBufferSize % eTO_CDBufferSize % eTO_LANBufferSize % eTO_UseOnlyDefaultBuffer); - BUFFERSIZES bs; - bs.m_bOnlyDefault = GetTaskPropValue(rTaskDefinition.GetConfiguration()); - bs.m_uiDefaultSize = GetTaskPropValue(rTaskDefinition.GetConfiguration()); - bs.m_uiOneDiskSize = GetTaskPropValue(rTaskDefinition.GetConfiguration()); - bs.m_uiTwoDisksSize = GetTaskPropValue(rTaskDefinition.GetConfiguration()); - bs.m_uiCDSize = GetTaskPropValue(rTaskDefinition.GetConfiguration()); - bs.m_uiLANSize = GetTaskPropValue(rTaskDefinition.GetConfiguration()); + BUFFERSIZES bs; + bs.m_bOnlyDefault = GetTaskPropValue(rTaskDefinition.GetConfiguration()); + bs.m_uiDefaultSize = GetTaskPropValue(rTaskDefinition.GetConfiguration()); + bs.m_uiOneDiskSize = GetTaskPropValue(rTaskDefinition.GetConfiguration()); + bs.m_uiTwoDisksSize = GetTaskPropValue(rTaskDefinition.GetConfiguration()); + bs.m_uiCDSize = GetTaskPropValue(rTaskDefinition.GetConfiguration()); + bs.m_uiLANSize = GetTaskPropValue(rTaskDefinition.GetConfiguration()); - ccp.dbBuffer.Create(&bs); + ccp.dbBuffer.Create(&bs); - // helpers - DWORD dwLastError = 0; + // helpers + DWORD dwLastError = 0; - // log - const BUFFERSIZES* pbs = ccp.dbBuffer.GetSizes(); + // log + const BUFFERSIZES* pbs = ccp.dbBuffer.GetSizes(); - ictranslate::CFormat fmt; - fmt.SetFormat(_T("Processing files/folders (ProcessFiles):\r\n\tOnlyCreate: %create\r\n\tBufferSize: [Def:%defsize, One:%onesize, Two:%twosize, CD:%cdsize, LAN:%lansize]\r\n\tFiles/folders count: %filecount\r\n\tIgnore Folders: %ignorefolders\r\n\tDest path: %dstpath\r\n\tCurrent index (0-based): %currindex")); - fmt.SetParam(_t("%create"), ccp.bOnlyCreate); - fmt.SetParam(_t("%defsize"), pbs->m_uiDefaultSize); - fmt.SetParam(_t("%onesize"), pbs->m_uiOneDiskSize); - fmt.SetParam(_t("%twosize"), pbs->m_uiTwoDisksSize); - fmt.SetParam(_t("%cdsize"), pbs->m_uiCDSize); - fmt.SetParam(_t("%lansize"), pbs->m_uiLANSize); - fmt.SetParam(_t("%filecount"), stSize); - fmt.SetParam(_t("%ignorefolders"), bIgnoreFolders); - fmt.SetParam(_t("%dstpath"), rTaskDefinition.GetDestinationPath().ToString()); - fmt.SetParam(_t("%currindex"), rBasicProgressInfo.GetCurrentIndex()); + ictranslate::CFormat fmt; + fmt.SetFormat(_T("Processing files/folders (ProcessFiles):\r\n\tOnlyCreate: %create\r\n\tBufferSize: [Def:%defsize, One:%onesize, Two:%twosize, CD:%cdsize, LAN:%lansize]\r\n\tFiles/folders count: %filecount\r\n\tIgnore Folders: %ignorefolders\r\n\tDest path: %dstpath\r\n\tCurrent index (0-based): %currindex")); + fmt.SetParam(_t("%create"), ccp.bOnlyCreate); + fmt.SetParam(_t("%defsize"), pbs->m_uiDefaultSize); + fmt.SetParam(_t("%onesize"), pbs->m_uiOneDiskSize); + fmt.SetParam(_t("%twosize"), pbs->m_uiTwoDisksSize); + fmt.SetParam(_t("%cdsize"), pbs->m_uiCDSize); + fmt.SetParam(_t("%lansize"), pbs->m_uiLANSize); + fmt.SetParam(_t("%filecount"), stSize); + fmt.SetParam(_t("%ignorefolders"), bIgnoreFolders); + fmt.SetParam(_t("%dstpath"), rTaskDefinition.GetDestinationPath().ToString()); + fmt.SetParam(_t("%currindex"), rBasicProgressInfo.GetCurrentIndex()); - rLog.logi(fmt); + rLog.logi(fmt); - for(size_t stIndex = rBasicProgressInfo.GetCurrentIndex(); stIndex < stSize; stIndex++) - { - // should we kill ? - if(rThreadController.KillRequested()) - { - // log - rLog.logi(_T("Kill request while processing file in ProcessFiles")); - return TSubTaskBase::eSubResult_KillRequest; - } + for(size_t stIndex = rBasicProgressInfo.GetCurrentIndex(); stIndex < stSize; stIndex++) + { + // should we kill ? + if(rThreadController.KillRequested()) + { + // log + rLog.logi(_T("Kill request while processing file in ProcessFiles")); + return TSubTaskBase::eSubResult_KillRequest; + } - // update m_stNextIndex, getting current CFileInfo - CFileInfoPtr spFileInfo = rFilesCache.GetAt(rBasicProgressInfo.GetCurrentIndex()); + // update m_stNextIndex, getting current CFileInfo + CFileInfoPtr spFileInfo = rFilesCache.GetAt(rBasicProgressInfo.GetCurrentIndex()); - // set dest path with filename - ccp.pathDstFile = CalculateDestinationPath(spFileInfo, rTaskDefinition.GetDestinationPath(), ((int)bForceDirectories) << 1 | (int)bIgnoreFolders); + // set dest path with filename + ccp.pathDstFile = CalculateDestinationPath(spFileInfo, rTaskDefinition.GetDestinationPath(), ((int)bForceDirectories) << 1 | (int)bIgnoreFolders); - // are the files/folders lie on the same partition ? - int iDstDriveNumber = 0; - bool bMove = rTaskDefinition.GetOperationType() == eOperation_Move; - if(bMove) - TLocalFilesystem::GetDriveData(rTaskDefinition.GetDestinationPath(), &iDstDriveNumber, NULL); - if(bMove && iDstDriveNumber != -1 && iDstDriveNumber == GetDriveNumber(spFileInfo) && GetMove(spFileInfo)) - { - bool bRetry = true; - if(bRetry && !MoveFile(spFileInfo->GetFullFilePath().ToString(), ccp.pathDstFile.ToString())) - { - dwLastError=GetLastError(); - //log - fmt.SetFormat(_T("Error %errno while calling MoveFile %srcpath -> %dstpath (ProcessFiles)")); - fmt.SetParam(_t("%errno"), dwLastError); - fmt.SetParam(_t("%srcpath"), spFileInfo->GetFullFilePath().ToString()); - fmt.SetParam(_t("%dstpath"), ccp.pathDstFile.ToString()); - rLog.loge(fmt); + // are the files/folders lie on the same partition ? + int iDstDriveNumber = 0; + bool bMove = rTaskDefinition.GetOperationType() == eOperation_Move; + if(bMove) + TLocalFilesystem::GetDriveData(rTaskDefinition.GetDestinationPath(), &iDstDriveNumber, NULL); + if(bMove && iDstDriveNumber != -1 && iDstDriveNumber == GetDriveNumber(spFileInfo) && GetMove(spFileInfo)) + { + bool bRetry = true; + if(bRetry && !MoveFile(spFileInfo->GetFullFilePath().ToString(), ccp.pathDstFile.ToString())) + { + dwLastError=GetLastError(); + //log + fmt.SetFormat(_T("Error %errno while calling MoveFile %srcpath -> %dstpath (ProcessFiles)")); + fmt.SetParam(_t("%errno"), dwLastError); + fmt.SetParam(_t("%srcpath"), spFileInfo->GetFullFilePath().ToString()); + fmt.SetParam(_t("%dstpath"), ccp.pathDstFile.ToString()); + rLog.loge(fmt); - FEEDBACK_FILEERROR ferr = { spFileInfo->GetFullFilePath().ToString(), ccp.pathDstFile.ToString(), eFastMoveError, dwLastError }; - CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &ferr); - switch(frResult) - { - case CFeedbackHandler::eResult_Cancel: - return TSubTaskBase::eSubResult_CancelRequest; + FEEDBACK_FILEERROR ferr = { spFileInfo->GetFullFilePath().ToString(), ccp.pathDstFile.ToString(), eFastMoveError, dwLastError }; + CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &ferr); + switch(frResult) + { + case CFeedbackHandler::eResult_Cancel: + return TSubTaskBase::eSubResult_CancelRequest; - case CFeedbackHandler::eResult_Retry: - continue; + case CFeedbackHandler::eResult_Retry: + continue; - case CFeedbackHandler::eResult_Pause: - return TSubTaskBase::eSubResult_PauseRequest; + case CFeedbackHandler::eResult_Pause: + return TSubTaskBase::eSubResult_PauseRequest; - case CFeedbackHandler::eResult_Skip: - bRetry = false; - break; // just do nothing - default: - BOOST_ASSERT(FALSE); // unknown result - THROW(_T("Unhandled case"), 0, 0, 0); - } - } - else - spFileInfo->SetFlags(FIF_PROCESSED, FIF_PROCESSED); - } - else - { - // if folder - create it - if(spFileInfo->IsDirectory()) - { - bool bRetry = true; - if(bRetry && !CreateDirectory(ccp.pathDstFile.ToString(), NULL) && (dwLastError=GetLastError()) != ERROR_ALREADY_EXISTS ) - { - // log - fmt.SetFormat(_T("Error %errno while calling CreateDirectory %path (ProcessFiles)")); - fmt.SetParam(_t("%errno"), dwLastError); - fmt.SetParam(_t("%path"), ccp.pathDstFile.ToString()); - rLog.loge(fmt); + case CFeedbackHandler::eResult_Skip: + bRetry = false; + break; // just do nothing + default: + BOOST_ASSERT(FALSE); // unknown result + THROW(_T("Unhandled case"), 0, 0, 0); + } + } + else + spFileInfo->SetFlags(FIF_PROCESSED, FIF_PROCESSED); + } + else + { + // if folder - create it + if(spFileInfo->IsDirectory()) + { + bool bRetry = true; + if(bRetry && !CreateDirectory(ccp.pathDstFile.ToString(), NULL) && (dwLastError=GetLastError()) != ERROR_ALREADY_EXISTS ) + { + // log + fmt.SetFormat(_T("Error %errno while calling CreateDirectory %path (ProcessFiles)")); + fmt.SetParam(_t("%errno"), dwLastError); + fmt.SetParam(_t("%path"), ccp.pathDstFile.ToString()); + rLog.loge(fmt); - FEEDBACK_FILEERROR ferr = { ccp.pathDstFile.ToString(), NULL, eCreateError, dwLastError }; - CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &ferr); - switch(frResult) - { - case CFeedbackHandler::eResult_Cancel: - return TSubTaskBase::eSubResult_CancelRequest; + FEEDBACK_FILEERROR ferr = { ccp.pathDstFile.ToString(), NULL, eCreateError, dwLastError }; + CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &ferr); + switch(frResult) + { + case CFeedbackHandler::eResult_Cancel: + return TSubTaskBase::eSubResult_CancelRequest; - case CFeedbackHandler::eResult_Retry: - continue; + case CFeedbackHandler::eResult_Retry: + continue; - case CFeedbackHandler::eResult_Pause: - return TSubTaskBase::eSubResult_PauseRequest; + case CFeedbackHandler::eResult_Pause: + return TSubTaskBase::eSubResult_PauseRequest; - case CFeedbackHandler::eResult_Skip: - bRetry = false; - break; // just do nothing - default: - BOOST_ASSERT(FALSE); // unknown result - THROW(_T("Unhandled case"), 0, 0, 0); - } - } + case CFeedbackHandler::eResult_Skip: + bRetry = false; + break; // just do nothing + default: + BOOST_ASSERT(FALSE); // unknown result + THROW(_T("Unhandled case"), 0, 0, 0); + } + } - rLocalStats.IncreaseProcessedSize(spFileInfo->GetLength64()); - spFileInfo->SetFlags(FIF_PROCESSED, FIF_PROCESSED); - } - else - { - // start copying/moving file - ccp.spSrcFile = spFileInfo; - ccp.bProcessed = false; + rLocalStats.IncreaseProcessedSize(spFileInfo->GetLength64()); + spFileInfo->SetFlags(FIF_PROCESSED, FIF_PROCESSED); + } + else + { + // start copying/moving file + ccp.spSrcFile = spFileInfo; + ccp.bProcessed = false; - // kopiuj dane - TSubTaskBase::ESubOperationResult eResult = CustomCopyFileFB(&ccp); - if(eResult != TSubTaskBase::eSubResult_Continue) - return eResult; + // kopiuj dane + TSubTaskBase::ESubOperationResult eResult = CustomCopyFileFB(&ccp); + if(eResult != TSubTaskBase::eSubResult_Continue) + return eResult; - spFileInfo->SetFlags(ccp.bProcessed ? FIF_PROCESSED : 0, FIF_PROCESSED); + spFileInfo->SetFlags(ccp.bProcessed ? FIF_PROCESSED : 0, FIF_PROCESSED); - // if moving - delete file (only if config flag is set) - if(bMove && spFileInfo->GetFlags() & FIF_PROCESSED && !GetTaskPropValue(rTaskDefinition.GetConfiguration())) - { - if(!GetTaskPropValue(rTaskDefinition.GetConfiguration())) - SetFileAttributes(spFileInfo->GetFullFilePath().ToString(), FILE_ATTRIBUTE_NORMAL); - DeleteFile(spFileInfo->GetFullFilePath().ToString()); // there will be another try later, so I don't check - // if succeeded - } - } + // if moving - delete file (only if config flag is set) + if(bMove && spFileInfo->GetFlags() & FIF_PROCESSED && !GetTaskPropValue(rTaskDefinition.GetConfiguration())) + { + if(!GetTaskPropValue(rTaskDefinition.GetConfiguration())) + SetFileAttributes(spFileInfo->GetFullFilePath().ToString(), FILE_ATTRIBUTE_NORMAL); + DeleteFile(spFileInfo->GetFullFilePath().ToString()); // there will be another try later, so I don't check + // if succeeded + } + } - // set a time - if(GetTaskPropValue(rTaskDefinition.GetConfiguration())) - TLocalFilesystem::SetFileDirectoryTime(ccp.pathDstFile.ToString(), spFileInfo->GetCreationTime(), spFileInfo->GetLastAccessTime(), spFileInfo->GetLastWriteTime()); // no error checking (but most probably it should be checked) + // set a time + if(GetTaskPropValue(rTaskDefinition.GetConfiguration())) + TLocalFilesystem::SetFileDirectoryTime(ccp.pathDstFile.ToString(), spFileInfo->GetCreationTime(), spFileInfo->GetLastAccessTime(), spFileInfo->GetLastWriteTime()); // no error checking (but most probably it should be checked) - // attributes - if(GetTaskPropValue(rTaskDefinition.GetConfiguration())) - SetFileAttributes(ccp.pathDstFile.ToString(), spFileInfo->GetAttributes()); // as above - } + // attributes + if(GetTaskPropValue(rTaskDefinition.GetConfiguration())) + SetFileAttributes(ccp.pathDstFile.ToString(), spFileInfo->GetAttributes()); // as above + } - rBasicProgressInfo.SetCurrentIndex(stIndex + 1); - } + rBasicProgressInfo.SetCurrentIndex(stIndex + 1); + } - // delete buffer - it's not needed - ccp.dbBuffer.Delete(); + // delete buffer - it's not needed + ccp.dbBuffer.Delete(); - // to look better (as 100%) - increase current index by 1 - rBasicProgressInfo.SetCurrentIndex(stSize); + // to look better (as 100%) - increase current index by 1 + rBasicProgressInfo.SetCurrentIndex(stSize); - // log - rLog.logi(_T("Finished processing in ProcessFiles")); + // log + rLog.logi(_T("Finished processing in ProcessFiles")); - return TSubTaskBase::eSubResult_Continue; + return TSubTaskBase::eSubResult_Continue; } bool TSubTaskCopyMove::GetMove(const CFileInfoPtr& spFileInfo) { - if(!spFileInfo) - THROW(_T("Invalid pointer"), 0, 0, 0); - if(spFileInfo->GetSrcIndex() == std::numeric_limits::max()) - THROW(_T("Received non-relative (standalone) path info"), 0, 0, 0); + if(!spFileInfo) + THROW(_T("Invalid pointer"), 0, 0, 0); + if(spFileInfo->GetSrcIndex() == std::numeric_limits::max()) + THROW(_T("Received non-relative (standalone) path info"), 0, 0, 0); - // check if this information has already been stored - size_t stBaseIndex = spFileInfo->GetSrcIndex(); - if(stBaseIndex >= GetContext().GetBasePathDataContainer().GetCount()) - THROW(_T("Index out of bounds"), 0, 0, 0); + // check if this information has already been stored + size_t stBaseIndex = spFileInfo->GetSrcIndex(); + if(stBaseIndex >= GetContext().GetBasePathDataContainer().GetCount()) + THROW(_T("Index out of bounds"), 0, 0, 0); - TBasePathDataPtr spPathData = GetContext().GetBasePathDataContainer().GetAt(stBaseIndex); - return spPathData->GetMove(); + TBasePathDataPtr spPathData = GetContext().GetBasePathDataContainer().GetAt(stBaseIndex); + return spPathData->GetMove(); } int TSubTaskCopyMove::GetBufferIndex(const CFileInfoPtr& spFileInfo) { - TBasePathDataContainer& rSrcPathsInfo = GetContext().GetBasePathDataContainer(); - TTaskDefinition& rTaskDefinition = GetContext().GetTaskDefinition(); + TBasePathDataContainer& rSrcPathsInfo = GetContext().GetBasePathDataContainer(); + TTaskDefinition& rTaskDefinition = GetContext().GetTaskDefinition(); - if(!spFileInfo) - THROW(_T("Invalid pointer"), 0, 0, 0); - if(spFileInfo->GetSrcIndex() == std::numeric_limits::max()) - THROW(_T("Received non-relative (standalone) path info"), 0, 0, 0); + if(!spFileInfo) + THROW(_T("Invalid pointer"), 0, 0, 0); + if(spFileInfo->GetSrcIndex() == std::numeric_limits::max()) + THROW(_T("Received non-relative (standalone) path info"), 0, 0, 0); - // check if this information has already been stored - size_t stBaseIndex = spFileInfo->GetSrcIndex(); - if(stBaseIndex >= rSrcPathsInfo.GetCount()) - THROW(_T("Index out of bounds"), 0, 0, 0); + // check if this information has already been stored + size_t stBaseIndex = spFileInfo->GetSrcIndex(); + if(stBaseIndex >= rSrcPathsInfo.GetCount()) + THROW(_T("Index out of bounds"), 0, 0, 0); - TBasePathDataPtr spPathData = rSrcPathsInfo.GetAt(stBaseIndex); - if(spPathData->IsBufferIndexSet()) - return spPathData->GetBufferIndex(); + TBasePathDataPtr spPathData = rSrcPathsInfo.GetAt(stBaseIndex); + if(spPathData->IsBufferIndexSet()) + return spPathData->GetBufferIndex(); - // buffer index wasn't cached previously - read it now - int iDriveNumber = 0; - UINT uiDriveType = 0; - int iDstDriveNumber = 0; - UINT uiDstDriveType = 0; - TLocalFilesystem::GetDriveData(rTaskDefinition.GetSourcePathAt(stBaseIndex), &iDriveNumber, &uiDriveType); - TLocalFilesystem::GetDriveData(rTaskDefinition.GetDestinationPath(), &iDstDriveNumber, &uiDstDriveType); + // buffer index wasn't cached previously - read it now + int iDriveNumber = 0; + UINT uiDriveType = 0; + int iDstDriveNumber = 0; + UINT uiDstDriveType = 0; + TLocalFilesystem::GetDriveData(rTaskDefinition.GetSourcePathAt(stBaseIndex), &iDriveNumber, &uiDriveType); + TLocalFilesystem::GetDriveData(rTaskDefinition.GetDestinationPath(), &iDstDriveNumber, &uiDstDriveType); - // what kind of buffer - int iBufferIndex = BI_DEFAULT; - if(uiDriveType == DRIVE_REMOTE || uiDstDriveType == DRIVE_REMOTE) - iBufferIndex = BI_LAN; - else if(uiDriveType == DRIVE_CDROM || uiDstDriveType == DRIVE_CDROM) - iBufferIndex = BI_CD; - else if(uiDriveType == DRIVE_FIXED && uiDstDriveType == DRIVE_FIXED) - { - // two hdd's - is this the same physical disk ? - if(iDriveNumber == iDstDriveNumber || IsSamePhysicalDisk(iDriveNumber, iDstDriveNumber)) - iBufferIndex = BI_ONEDISK; - else - iBufferIndex = BI_TWODISKS; - } - else - iBufferIndex = BI_DEFAULT; + // what kind of buffer + int iBufferIndex = BI_DEFAULT; + if(uiDriveType == DRIVE_REMOTE || uiDstDriveType == DRIVE_REMOTE) + iBufferIndex = BI_LAN; + else if(uiDriveType == DRIVE_CDROM || uiDstDriveType == DRIVE_CDROM) + iBufferIndex = BI_CD; + else if(uiDriveType == DRIVE_FIXED && uiDstDriveType == DRIVE_FIXED) + { + // two hdd's - is this the same physical disk ? + if(iDriveNumber == iDstDriveNumber || IsSamePhysicalDisk(iDriveNumber, iDstDriveNumber)) + iBufferIndex = BI_ONEDISK; + else + iBufferIndex = BI_TWODISKS; + } + else + iBufferIndex = BI_DEFAULT; - spPathData->SetBufferIndex(iBufferIndex); + spPathData->SetBufferIndex(iBufferIndex); - return iBufferIndex; + return iBufferIndex; } TSubTaskBase::ESubOperationResult TSubTaskCopyMove::CustomCopyFileFB(CUSTOM_COPY_PARAMS* pData) { - TTaskDefinition& rTaskDefinition = GetContext().GetTaskDefinition(); - TTaskBasicProgressInfo& rBasicProgressInfo = GetContext().GetTaskBasicProgressInfo(); - TWorkerThreadController& rThreadController = GetContext().GetThreadController(); - TTaskLocalStats& rLocalStats = GetContext().GetTaskLocalStats(); - icpf::log_file& rLog = GetContext().GetLog(); - TTaskConfigTracker& rCfgTracker = GetContext().GetCfgTracker(); + TTaskDefinition& rTaskDefinition = GetContext().GetTaskDefinition(); + TTaskBasicProgressInfo& rBasicProgressInfo = GetContext().GetTaskBasicProgressInfo(); + TWorkerThreadController& rThreadController = GetContext().GetThreadController(); + TTaskLocalStats& rLocalStats = GetContext().GetTaskLocalStats(); + icpf::log_file& rLog = GetContext().GetLog(); + TTaskConfigTracker& rCfgTracker = GetContext().GetCfgTracker(); - TAutoFileHandle hSrc = INVALID_HANDLE_VALUE, - hDst = INVALID_HANDLE_VALUE; - ictranslate::CFormat fmt; - TSubTaskBase::ESubOperationResult eResult = TSubTaskBase::eSubResult_Continue; - bool bSkip = false; + TAutoFileHandle hSrc = INVALID_HANDLE_VALUE, + hDst = INVALID_HANDLE_VALUE; + ictranslate::CFormat fmt; + TSubTaskBase::ESubOperationResult eResult = TSubTaskBase::eSubResult_Continue; + bool bSkip = false; - // calculate if we want to disable buffering for file transfer - // NOTE: we are using here the file size read when scanning directories for files; it might be - // outdated at this point, but at present we don't want to re-read file size since it - // will cost additional disk access - bool bNoBuffer = (GetTaskPropValue(rTaskDefinition.GetConfiguration()) && - pData->spSrcFile->GetLength64() >= GetTaskPropValue(rTaskDefinition.GetConfiguration())); + // calculate if we want to disable buffering for file transfer + // NOTE: we are using here the file size read when scanning directories for files; it might be + // outdated at this point, but at present we don't want to re-read file size since it + // will cost additional disk access + bool bNoBuffer = (GetTaskPropValue(rTaskDefinition.GetConfiguration()) && + pData->spSrcFile->GetLength64() >= GetTaskPropValue(rTaskDefinition.GetConfiguration())); - // first open the source file and handle any failures - eResult = OpenSourceFileFB(hSrc, pData->spSrcFile, bNoBuffer); - if(eResult != TSubTaskBase::eSubResult_Continue) - return eResult; - else if(hSrc == INVALID_HANDLE_VALUE) - { - // invalid handle = operation skipped by user - rLocalStats.IncreaseProcessedSize(pData->spSrcFile->GetLength64() - rBasicProgressInfo.GetCurrentFileProcessedSize()); - pData->bProcessed = false; - return TSubTaskBase::eSubResult_Continue; - } + // first open the source file and handle any failures + eResult = OpenSourceFileFB(hSrc, pData->spSrcFile, bNoBuffer); + if(eResult != TSubTaskBase::eSubResult_Continue) + return eResult; + else if(hSrc == INVALID_HANDLE_VALUE) + { + // invalid handle = operation skipped by user + rLocalStats.IncreaseProcessedSize(pData->spSrcFile->GetLength64() - rBasicProgressInfo.GetCurrentFileProcessedSize()); + pData->bProcessed = false; + return TSubTaskBase::eSubResult_Continue; + } - // change attributes of a dest file - // NOTE: probably should be removed from here and report problems with read-only files - // directly to the user (as feedback request) - if(!GetTaskPropValue(rTaskDefinition.GetConfiguration())) - SetFileAttributes(pData->pathDstFile.ToString(), FILE_ATTRIBUTE_NORMAL); + // change attributes of a dest file + // NOTE: probably should be removed from here and report problems with read-only files + // directly to the user (as feedback request) + if(!GetTaskPropValue(rTaskDefinition.GetConfiguration())) + SetFileAttributes(pData->pathDstFile.ToString(), FILE_ATTRIBUTE_NORMAL); - // open destination file, handle the failures and possibly existence of the destination file - unsigned long long ullSeekTo = 0; - bool bDstFileFreshlyCreated = false; + // open destination file, handle the failures and possibly existence of the destination file + unsigned long long ullSeekTo = 0; + bool bDstFileFreshlyCreated = false; - if(rBasicProgressInfo.GetCurrentFileProcessedSize() == 0) - { - // open destination file for case, when we start operation on this file (i.e. it is not resume of the - // old operation) - eResult = OpenDestinationFileFB(hDst, pData->pathDstFile, bNoBuffer, pData->spSrcFile, ullSeekTo, bDstFileFreshlyCreated); - if(eResult != TSubTaskBase::eSubResult_Continue) - return eResult; - else if(hDst == INVALID_HANDLE_VALUE) - { - rLocalStats.IncreaseProcessedSize(pData->spSrcFile->GetLength64() - rBasicProgressInfo.GetCurrentFileProcessedSize()); - pData->bProcessed = false; - return TSubTaskBase::eSubResult_Continue; - } - } - else - { - // we are resuming previous operation - eResult = OpenExistingDestinationFileFB(hDst, pData->pathDstFile, bNoBuffer); - if(eResult != TSubTaskBase::eSubResult_Continue) - return eResult; - else if(hDst == INVALID_HANDLE_VALUE) - { - rLocalStats.IncreaseProcessedSize(pData->spSrcFile->GetLength64() - rBasicProgressInfo.GetCurrentFileProcessedSize()); - pData->bProcessed = false; - return TSubTaskBase::eSubResult_Continue; - } + if(rBasicProgressInfo.GetCurrentFileProcessedSize() == 0) + { + // open destination file for case, when we start operation on this file (i.e. it is not resume of the + // old operation) + eResult = OpenDestinationFileFB(hDst, pData->pathDstFile, bNoBuffer, pData->spSrcFile, ullSeekTo, bDstFileFreshlyCreated); + if(eResult != TSubTaskBase::eSubResult_Continue) + return eResult; + else if(hDst == INVALID_HANDLE_VALUE) + { + rLocalStats.IncreaseProcessedSize(pData->spSrcFile->GetLength64() - rBasicProgressInfo.GetCurrentFileProcessedSize()); + pData->bProcessed = false; + return TSubTaskBase::eSubResult_Continue; + } + } + else + { + // we are resuming previous operation + eResult = OpenExistingDestinationFileFB(hDst, pData->pathDstFile, bNoBuffer); + if(eResult != TSubTaskBase::eSubResult_Continue) + return eResult; + else if(hDst == INVALID_HANDLE_VALUE) + { + rLocalStats.IncreaseProcessedSize(pData->spSrcFile->GetLength64() - rBasicProgressInfo.GetCurrentFileProcessedSize()); + pData->bProcessed = false; + return TSubTaskBase::eSubResult_Continue; + } - ullSeekTo = rBasicProgressInfo.GetCurrentFileProcessedSize(); - } + ullSeekTo = rBasicProgressInfo.GetCurrentFileProcessedSize(); + } - if(!pData->bOnlyCreate) - { - // seek to the position where copying will start - if(ullSeekTo != 0) // src and dst files exists, requested resume at the specified index - { - // try to move file pointers to the end - ULONGLONG ullMove = (bNoBuffer ? ROUNDDOWN(ullSeekTo, MAXSECTORSIZE) : ullSeekTo); + if(!pData->bOnlyCreate) + { + // seek to the position where copying will start + if(ullSeekTo != 0) // src and dst files exists, requested resume at the specified index + { + // try to move file pointers to the end + ULONGLONG ullMove = (bNoBuffer ? ROUNDDOWN(ullSeekTo, MAXSECTORSIZE) : ullSeekTo); - eResult = SetFilePointerFB(hSrc, ullMove, pData->spSrcFile->GetFullFilePath(), bSkip); - if(eResult != TSubTaskBase::eSubResult_Continue) - return eResult; - else if(bSkip) - { - rLocalStats.IncreaseProcessedSize(pData->spSrcFile->GetLength64() - rBasicProgressInfo.GetCurrentFileProcessedSize()); - pData->bProcessed = false; - return TSubTaskBase::eSubResult_Continue; - } + eResult = SetFilePointerFB(hSrc, ullMove, pData->spSrcFile->GetFullFilePath(), bSkip); + if(eResult != TSubTaskBase::eSubResult_Continue) + return eResult; + else if(bSkip) + { + rLocalStats.IncreaseProcessedSize(pData->spSrcFile->GetLength64() - rBasicProgressInfo.GetCurrentFileProcessedSize()); + pData->bProcessed = false; + return TSubTaskBase::eSubResult_Continue; + } - eResult = SetFilePointerFB(hDst, ullMove, pData->pathDstFile, bSkip); - if(eResult != TSubTaskBase::eSubResult_Continue) - return eResult; - else if(bSkip) - { - // with either first or second seek we got 'skip' answer... - rLocalStats.IncreaseProcessedSize(pData->spSrcFile->GetLength64() - rBasicProgressInfo.GetCurrentFileProcessedSize()); - pData->bProcessed = false; - return TSubTaskBase::eSubResult_Continue; - } + eResult = SetFilePointerFB(hDst, ullMove, pData->pathDstFile, bSkip); + if(eResult != TSubTaskBase::eSubResult_Continue) + return eResult; + else if(bSkip) + { + // with either first or second seek we got 'skip' answer... + rLocalStats.IncreaseProcessedSize(pData->spSrcFile->GetLength64() - rBasicProgressInfo.GetCurrentFileProcessedSize()); + pData->bProcessed = false; + return TSubTaskBase::eSubResult_Continue; + } - rBasicProgressInfo.IncreaseCurrentFileProcessedSize(ullMove); - rLocalStats.IncreaseProcessedSize(ullMove); - } + rBasicProgressInfo.IncreaseCurrentFileProcessedSize(ullMove); + rLocalStats.IncreaseProcessedSize(ullMove); + } - // if the destination file already exists - truncate it to the current file position - if(!bDstFileFreshlyCreated) - { - // if destination file was opened (as opposed to newly created) - eResult = SetEndOfFileFB(hDst, pData->pathDstFile, bSkip); - if(eResult != TSubTaskBase::eSubResult_Continue) - return eResult; - else if(bSkip) - { - pData->bProcessed = false; - return TSubTaskBase::eSubResult_Continue; - } - } + // if the destination file already exists - truncate it to the current file position + if(!bDstFileFreshlyCreated) + { + // if destination file was opened (as opposed to newly created) + eResult = SetEndOfFileFB(hDst, pData->pathDstFile, bSkip); + if(eResult != TSubTaskBase::eSubResult_Continue) + return eResult; + else if(bSkip) + { + pData->bProcessed = false; + return TSubTaskBase::eSubResult_Continue; + } + } - // copying - unsigned long ulToRead = 0; - unsigned long ulRead = 0; - unsigned long ulWritten = 0; - int iBufferIndex = 0; - bool bLastPart = false; + // copying + unsigned long ulToRead = 0; + unsigned long ulRead = 0; + unsigned long ulWritten = 0; + int iBufferIndex = 0; + bool bLastPart = false; - do - { - // kill flag checks - if(rThreadController.KillRequested()) - { - // log - fmt.SetFormat(_T("Kill request while main copying file %srcpath -> %dstpath")); - fmt.SetParam(_t("%srcpath"), pData->spSrcFile->GetFullFilePath().ToString()); - fmt.SetParam(_t("%dstpath"), pData->pathDstFile.ToString()); - rLog.logi(fmt); - return TSubTaskBase::eSubResult_KillRequest; - } + do + { + // kill flag checks + if(rThreadController.KillRequested()) + { + // log + fmt.SetFormat(_T("Kill request while main copying file %srcpath -> %dstpath")); + fmt.SetParam(_t("%srcpath"), pData->spSrcFile->GetFullFilePath().ToString()); + fmt.SetParam(_t("%dstpath"), pData->pathDstFile.ToString()); + rLog.logi(fmt); + return TSubTaskBase::eSubResult_KillRequest; + } - // recreate buffer if needed - if(rCfgTracker.IsModified() && rCfgTracker.IsModified(TOptionsSet() % eTO_DefaultBufferSize % eTO_OneDiskBufferSize % eTO_TwoDisksBufferSize % eTO_CDBufferSize % eTO_LANBufferSize % eTO_UseOnlyDefaultBuffer, true)) - { - BUFFERSIZES bs; - bs.m_bOnlyDefault = GetTaskPropValue(rTaskDefinition.GetConfiguration()); - bs.m_uiDefaultSize = GetTaskPropValue(rTaskDefinition.GetConfiguration()); - bs.m_uiOneDiskSize = GetTaskPropValue(rTaskDefinition.GetConfiguration()); - bs.m_uiTwoDisksSize = GetTaskPropValue(rTaskDefinition.GetConfiguration()); - bs.m_uiCDSize = GetTaskPropValue(rTaskDefinition.GetConfiguration()); - bs.m_uiLANSize = GetTaskPropValue(rTaskDefinition.GetConfiguration()); + // recreate buffer if needed + if(rCfgTracker.IsModified() && rCfgTracker.IsModified(TOptionsSet() % eTO_DefaultBufferSize % eTO_OneDiskBufferSize % eTO_TwoDisksBufferSize % eTO_CDBufferSize % eTO_LANBufferSize % eTO_UseOnlyDefaultBuffer, true)) + { + BUFFERSIZES bs; + bs.m_bOnlyDefault = GetTaskPropValue(rTaskDefinition.GetConfiguration()); + bs.m_uiDefaultSize = GetTaskPropValue(rTaskDefinition.GetConfiguration()); + bs.m_uiOneDiskSize = GetTaskPropValue(rTaskDefinition.GetConfiguration()); + bs.m_uiTwoDisksSize = GetTaskPropValue(rTaskDefinition.GetConfiguration()); + bs.m_uiCDSize = GetTaskPropValue(rTaskDefinition.GetConfiguration()); + bs.m_uiLANSize = GetTaskPropValue(rTaskDefinition.GetConfiguration()); - // log - const BUFFERSIZES* pbs1 = pData->dbBuffer.GetSizes(); + // log + const BUFFERSIZES* pbs1 = pData->dbBuffer.GetSizes(); - fmt.SetFormat(_T("Changing buffer size from [Def:%defsize, One:%onesize, Two:%twosize, CD:%cdsize, LAN:%lansize] to [Def:%defsize2, One:%onesize2, Two:%twosize2, CD:%cdsize2, LAN:%lansize2] wile copying %srcfile -> %dstfile (CustomCopyFileFB)")); + fmt.SetFormat(_T("Changing buffer size from [Def:%defsize, One:%onesize, Two:%twosize, CD:%cdsize, LAN:%lansize] to [Def:%defsize2, One:%onesize2, Two:%twosize2, CD:%cdsize2, LAN:%lansize2] wile copying %srcfile -> %dstfile (CustomCopyFileFB)")); - fmt.SetParam(_t("%defsize"), pbs1->m_uiDefaultSize); - fmt.SetParam(_t("%onesize"), pbs1->m_uiOneDiskSize); - fmt.SetParam(_t("%twosize"), pbs1->m_uiTwoDisksSize); - fmt.SetParam(_t("%cdsize"), pbs1->m_uiCDSize); - fmt.SetParam(_t("%lansize"), pbs1->m_uiLANSize); - fmt.SetParam(_t("%defsize2"), bs.m_uiDefaultSize); - fmt.SetParam(_t("%onesize2"), bs.m_uiOneDiskSize); - fmt.SetParam(_t("%twosize2"), bs.m_uiTwoDisksSize); - fmt.SetParam(_t("%cdsize2"), bs.m_uiCDSize); - fmt.SetParam(_t("%lansize2"), bs.m_uiLANSize); - fmt.SetParam(_t("%srcfile"), pData->spSrcFile->GetFullFilePath().ToString()); - fmt.SetParam(_t("%dstfile"), pData->pathDstFile.ToString()); + fmt.SetParam(_t("%defsize"), pbs1->m_uiDefaultSize); + fmt.SetParam(_t("%onesize"), pbs1->m_uiOneDiskSize); + fmt.SetParam(_t("%twosize"), pbs1->m_uiTwoDisksSize); + fmt.SetParam(_t("%cdsize"), pbs1->m_uiCDSize); + fmt.SetParam(_t("%lansize"), pbs1->m_uiLANSize); + fmt.SetParam(_t("%defsize2"), bs.m_uiDefaultSize); + fmt.SetParam(_t("%onesize2"), bs.m_uiOneDiskSize); + fmt.SetParam(_t("%twosize2"), bs.m_uiTwoDisksSize); + fmt.SetParam(_t("%cdsize2"), bs.m_uiCDSize); + fmt.SetParam(_t("%lansize2"), bs.m_uiLANSize); + fmt.SetParam(_t("%srcfile"), pData->spSrcFile->GetFullFilePath().ToString()); + fmt.SetParam(_t("%dstfile"), pData->pathDstFile.ToString()); - rLog.logi(fmt); - pData->dbBuffer.Create(&bs); - } + rLog.logi(fmt); + pData->dbBuffer.Create(&bs); + } - // establish count of data to read - if(GetTaskPropValue(rTaskDefinition.GetConfiguration())) - iBufferIndex = BI_DEFAULT; - else - iBufferIndex = GetBufferIndex(pData->spSrcFile); - rLocalStats.SetCurrentBufferIndex(iBufferIndex); + // establish count of data to read + if(GetTaskPropValue(rTaskDefinition.GetConfiguration())) + iBufferIndex = BI_DEFAULT; + else + iBufferIndex = GetBufferIndex(pData->spSrcFile); + rLocalStats.SetCurrentBufferIndex(iBufferIndex); - ulToRead = bNoBuffer ? ROUNDUP(pData->dbBuffer.GetSizes()->m_auiSizes[iBufferIndex], MAXSECTORSIZE) : pData->dbBuffer.GetSizes()->m_auiSizes[iBufferIndex]; + ulToRead = bNoBuffer ? ROUNDUP(pData->dbBuffer.GetSizes()->m_auiSizes[iBufferIndex], MAXSECTORSIZE) : pData->dbBuffer.GetSizes()->m_auiSizes[iBufferIndex]; - // read data from file to buffer - eResult = ReadFileFB(hSrc, pData->dbBuffer, ulToRead, ulRead, pData->spSrcFile->GetFullFilePath(), bSkip); - if(eResult != TSubTaskBase::eSubResult_Continue) - return eResult; - else if(bSkip) - { - rLocalStats.IncreaseProcessedSize(pData->spSrcFile->GetLength64() - rBasicProgressInfo.GetCurrentFileProcessedSize()); - pData->bProcessed = false; - return TSubTaskBase::eSubResult_Continue; - } + // read data from file to buffer + eResult = ReadFileFB(hSrc, pData->dbBuffer, ulToRead, ulRead, pData->spSrcFile->GetFullFilePath(), bSkip); + if(eResult != TSubTaskBase::eSubResult_Continue) + return eResult; + else if(bSkip) + { + rLocalStats.IncreaseProcessedSize(pData->spSrcFile->GetLength64() - rBasicProgressInfo.GetCurrentFileProcessedSize()); + pData->bProcessed = false; + return TSubTaskBase::eSubResult_Continue; + } - if(ulRead > 0) - { - // determine if this is the last chunk of data we could get from the source file (EOF condition) - bLastPart = (ulToRead != ulRead); + if(ulRead > 0) + { + // determine if this is the last chunk of data we could get from the source file (EOF condition) + bLastPart = (ulToRead != ulRead); - // handle not aligned part at the end of file when no buffering is enabled - if(bNoBuffer && bLastPart) - { - // count of data read from the file is less than requested - we're at the end of source file - // and this is the operation with system buffering turned off + // handle not aligned part at the end of file when no buffering is enabled + if(bNoBuffer && bLastPart) + { + // count of data read from the file is less than requested - we're at the end of source file + // and this is the operation with system buffering turned off - // write as much as possible to the destination file with no buffering - // NOTE: as an alternative, we could write more data to the destination file and then truncate the file - unsigned long ulDataToWrite = ROUNDDOWN(ulRead, MAXSECTORSIZE); - if(ulDataToWrite > 0) - { - eResult = WriteFileFB(hDst, pData->dbBuffer, ulDataToWrite, ulWritten, pData->pathDstFile, bSkip); - if(eResult != TSubTaskBase::eSubResult_Continue) - return eResult; - else if(bSkip) - { - rLocalStats.IncreaseProcessedSize(pData->spSrcFile->GetLength64() - rBasicProgressInfo.GetCurrentFileProcessedSize()); - pData->bProcessed = false; - return TSubTaskBase::eSubResult_Continue; - } + // write as much as possible to the destination file with no buffering + // NOTE: as an alternative, we could write more data to the destination file and then truncate the file + unsigned long ulDataToWrite = ROUNDDOWN(ulRead, MAXSECTORSIZE); + if(ulDataToWrite > 0) + { + eResult = WriteFileFB(hDst, pData->dbBuffer, ulDataToWrite, ulWritten, pData->pathDstFile, bSkip); + if(eResult != TSubTaskBase::eSubResult_Continue) + return eResult; + else if(bSkip) + { + rLocalStats.IncreaseProcessedSize(pData->spSrcFile->GetLength64() - rBasicProgressInfo.GetCurrentFileProcessedSize()); + pData->bProcessed = false; + return TSubTaskBase::eSubResult_Continue; + } - // increase count of processed data - rBasicProgressInfo.IncreaseCurrentFileProcessedSize(ulWritten); - rLocalStats.IncreaseProcessedSize(ulWritten); + // increase count of processed data + rBasicProgressInfo.IncreaseCurrentFileProcessedSize(ulWritten); + rLocalStats.IncreaseProcessedSize(ulWritten); - // calculate count of bytes left to be written - ulRead -= ulWritten; + // calculate count of bytes left to be written + ulRead -= ulWritten; - // now remove part of data from buffer (ulWritten bytes) - pData->dbBuffer.CutDataFromBuffer(ulWritten); - } + // now remove part of data from buffer (ulWritten bytes) + pData->dbBuffer.CutDataFromBuffer(ulWritten); + } - // close and re-open the destination file with buffering option for append - hDst.Close(); + // close and re-open the destination file with buffering option for append + hDst.Close(); - // are there any more data to be written? - if(ulRead != 0) - { - // re-open the destination file, this time with standard buffering to allow writing not aligned part of file data - eResult = OpenExistingDestinationFileFB(hDst, pData->pathDstFile, false); - if(eResult != TSubTaskBase::eSubResult_Continue) - return eResult; - else if(hDst == INVALID_HANDLE_VALUE) - { - rLocalStats.IncreaseProcessedSize(pData->spSrcFile->GetLength64() - rBasicProgressInfo.GetCurrentFileProcessedSize()); - pData->bProcessed = false; - return TSubTaskBase::eSubResult_Continue; - } + // are there any more data to be written? + if(ulRead != 0) + { + // re-open the destination file, this time with standard buffering to allow writing not aligned part of file data + eResult = OpenExistingDestinationFileFB(hDst, pData->pathDstFile, false); + if(eResult != TSubTaskBase::eSubResult_Continue) + return eResult; + else if(hDst == INVALID_HANDLE_VALUE) + { + rLocalStats.IncreaseProcessedSize(pData->spSrcFile->GetLength64() - rBasicProgressInfo.GetCurrentFileProcessedSize()); + pData->bProcessed = false; + return TSubTaskBase::eSubResult_Continue; + } - // move file pointer to the end of destination file - eResult = SetFilePointerFB(hDst, rBasicProgressInfo.GetCurrentFileProcessedSize(), pData->pathDstFile, bSkip); - if(eResult != TSubTaskBase::eSubResult_Continue) - return eResult; - else if(bSkip) - { - // with either first or second seek we got 'skip' answer... - rLocalStats.IncreaseProcessedSize(pData->spSrcFile->GetLength64() - rBasicProgressInfo.GetCurrentFileProcessedSize()); - pData->bProcessed = false; - return TSubTaskBase::eSubResult_Continue; - } - } - } + // move file pointer to the end of destination file + eResult = SetFilePointerFB(hDst, rBasicProgressInfo.GetCurrentFileProcessedSize(), pData->pathDstFile, bSkip); + if(eResult != TSubTaskBase::eSubResult_Continue) + return eResult; + else if(bSkip) + { + // with either first or second seek we got 'skip' answer... + rLocalStats.IncreaseProcessedSize(pData->spSrcFile->GetLength64() - rBasicProgressInfo.GetCurrentFileProcessedSize()); + pData->bProcessed = false; + return TSubTaskBase::eSubResult_Continue; + } + } + } - // write - if(ulRead != 0) - { - eResult = WriteFileFB(hDst, pData->dbBuffer, ulRead, ulWritten, pData->pathDstFile, bSkip); - if(eResult != TSubTaskBase::eSubResult_Continue) - return eResult; - else if(bSkip) - { - rLocalStats.IncreaseProcessedSize(pData->spSrcFile->GetLength64() - rBasicProgressInfo.GetCurrentFileProcessedSize()); - pData->bProcessed = false; - return TSubTaskBase::eSubResult_Continue; - } + // write + if(ulRead != 0) + { + eResult = WriteFileFB(hDst, pData->dbBuffer, ulRead, ulWritten, pData->pathDstFile, bSkip); + if(eResult != TSubTaskBase::eSubResult_Continue) + return eResult; + else if(bSkip) + { + rLocalStats.IncreaseProcessedSize(pData->spSrcFile->GetLength64() - rBasicProgressInfo.GetCurrentFileProcessedSize()); + pData->bProcessed = false; + return TSubTaskBase::eSubResult_Continue; + } - // increase count of processed data - rBasicProgressInfo.IncreaseCurrentFileProcessedSize(ulRead); - rLocalStats.IncreaseProcessedSize(ulRead); - } - } - } - while(ulRead != 0 && !bLastPart); - } - else - { - // we don't copy contents, but need to increase processed size - rLocalStats.IncreaseProcessedSize(pData->spSrcFile->GetLength64() - rBasicProgressInfo.GetCurrentFileProcessedSize()); - } + // increase count of processed data + rBasicProgressInfo.IncreaseCurrentFileProcessedSize(ulRead); + rLocalStats.IncreaseProcessedSize(ulRead); + } + } + } + while(ulRead != 0 && !bLastPart); + } + else + { + // we don't copy contents, but need to increase processed size + rLocalStats.IncreaseProcessedSize(pData->spSrcFile->GetLength64() - rBasicProgressInfo.GetCurrentFileProcessedSize()); + } - pData->bProcessed = true; - rBasicProgressInfo.SetCurrentFileProcessedSize(0); + pData->bProcessed = true; + rBasicProgressInfo.SetCurrentFileProcessedSize(0); - return TSubTaskBase::eSubResult_Continue; + return TSubTaskBase::eSubResult_Continue; } TSubTaskBase::ESubOperationResult TSubTaskCopyMove::OpenSourceFileFB(TAutoFileHandle& hOutFile, const CFileInfoPtr& spSrcFileInfo, bool bNoBuffering) { - chcore::IFeedbackHandler* piFeedbackHandler = GetContext().GetFeedbackHandler(); - icpf::log_file& rLog = GetContext().GetLog(); + chcore::IFeedbackHandler* piFeedbackHandler = GetContext().GetFeedbackHandler(); + icpf::log_file& rLog = GetContext().GetLog(); - BOOST_ASSERT(spSrcFileInfo); - if(!spSrcFileInfo) - THROW(_T("Invalid argument"), 0, 0, 0); + BOOST_ASSERT(spSrcFileInfo); + if(!spSrcFileInfo) + THROW(_T("Invalid argument"), 0, 0, 0); - bool bRetry = false; - CString strPath = spSrcFileInfo->GetFullFilePath().ToString(); + bool bRetry = false; + CString strPath = spSrcFileInfo->GetFullFilePath().ToString(); - hOutFile = INVALID_HANDLE_VALUE; + hOutFile = INVALID_HANDLE_VALUE; - TAutoFileHandle hFile; - do - { - bRetry = false; + TAutoFileHandle hFile; + do + { + bRetry = false; - hFile = CreateFile(strPath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN | (bNoBuffering ? FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH : 0), NULL); - if(hFile == INVALID_HANDLE_VALUE) - { - DWORD dwLastError = GetLastError(); + hFile = CreateFile(strPath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN | (bNoBuffering ? FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH : 0), NULL); + if(hFile == INVALID_HANDLE_VALUE) + { + DWORD dwLastError = GetLastError(); - FEEDBACK_FILEERROR feedStruct = { (PCTSTR)strPath, NULL, eCreateError, dwLastError }; - CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &feedStruct); + FEEDBACK_FILEERROR feedStruct = { (PCTSTR)strPath, NULL, eCreateError, dwLastError }; + CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &feedStruct); - switch(frResult) - { - case CFeedbackHandler::eResult_Skip: - break; // will return INVALID_HANDLE_VALUE + switch(frResult) + { + case CFeedbackHandler::eResult_Skip: + break; // will return INVALID_HANDLE_VALUE - case CFeedbackHandler::eResult_Cancel: - { - // log - ictranslate::CFormat fmt; - fmt.SetFormat(_T("Cancel request [error %errno] while opening source file %path (OpenSourceFileFB)")); - fmt.SetParam(_t("%errno"), dwLastError); - fmt.SetParam(_t("%path"), strPath); - rLog.loge(fmt); + case CFeedbackHandler::eResult_Cancel: + { + // log + ictranslate::CFormat fmt; + fmt.SetFormat(_T("Cancel request [error %errno] while opening source file %path (OpenSourceFileFB)")); + fmt.SetParam(_t("%errno"), dwLastError); + fmt.SetParam(_t("%path"), strPath); + rLog.loge(fmt); - return TSubTaskBase::eSubResult_CancelRequest; - } + return TSubTaskBase::eSubResult_CancelRequest; + } - case CFeedbackHandler::eResult_Pause: - return TSubTaskBase::eSubResult_PauseRequest; + case CFeedbackHandler::eResult_Pause: + return TSubTaskBase::eSubResult_PauseRequest; - case CFeedbackHandler::eResult_Retry: - { - // log - ictranslate::CFormat fmt; - fmt.SetFormat(_T("Retrying [error %errno] to open source file %path (OpenSourceFileFB)")); - fmt.SetParam(_t("%errno"), dwLastError); - fmt.SetParam(_t("%path"), strPath); - rLog.loge(fmt); + case CFeedbackHandler::eResult_Retry: + { + // log + ictranslate::CFormat fmt; + fmt.SetFormat(_T("Retrying [error %errno] to open source file %path (OpenSourceFileFB)")); + fmt.SetParam(_t("%errno"), dwLastError); + fmt.SetParam(_t("%path"), strPath); + rLog.loge(fmt); - bRetry = true; - break; - } + bRetry = true; + break; + } - default: - BOOST_ASSERT(FALSE); // unknown result - THROW(_T("Unhandled case"), 0, 0, 0); - } - } - } - while(bRetry); + default: + BOOST_ASSERT(FALSE); // unknown result + THROW(_T("Unhandled case"), 0, 0, 0); + } + } + } + while(bRetry); - hOutFile = hFile.Detach(); + hOutFile = hFile.Detach(); - return TSubTaskBase::eSubResult_Continue; + return TSubTaskBase::eSubResult_Continue; } TSubTaskBase::ESubOperationResult TSubTaskCopyMove::OpenDestinationFileFB(TAutoFileHandle& hOutFile, const chcore::TSmartPath& pathDstFile, bool bNoBuffering, const CFileInfoPtr& spSrcFileInfo, unsigned long long& ullSeekTo, bool& bFreshlyCreated) { - chcore::IFeedbackHandler* piFeedbackHandler = GetContext().GetFeedbackHandler(); - icpf::log_file& rLog = GetContext().GetLog(); + chcore::IFeedbackHandler* piFeedbackHandler = GetContext().GetFeedbackHandler(); + icpf::log_file& rLog = GetContext().GetLog(); - bool bRetry = false; - TAutoFileHandle hFile; + bool bRetry = false; + TAutoFileHandle hFile; - ullSeekTo = 0; - bFreshlyCreated = true; - hOutFile = INVALID_HANDLE_VALUE; + ullSeekTo = 0; + bFreshlyCreated = true; + hOutFile = INVALID_HANDLE_VALUE; - do - { - bRetry = false; + do + { + bRetry = false; - hFile = ::CreateFile(pathDstFile.ToString(), GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN | (bNoBuffering ? FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH : 0), NULL); - if(hFile == INVALID_HANDLE_VALUE) - { - DWORD dwLastError = GetLastError(); - if(dwLastError == ERROR_FILE_EXISTS) - { - bFreshlyCreated = false; + hFile = ::CreateFile(pathDstFile.ToString(), GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN | (bNoBuffering ? FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH : 0), NULL); + if(hFile == INVALID_HANDLE_VALUE) + { + DWORD dwLastError = GetLastError(); + if(dwLastError == ERROR_FILE_EXISTS) + { + bFreshlyCreated = false; - // pass it to the specialized method - TSubTaskBase::ESubOperationResult eResult = OpenExistingDestinationFileFB(hFile, pathDstFile, bNoBuffering); - if(eResult != TSubTaskBase::eSubResult_Continue) - return eResult; - else if(hFile == INVALID_HANDLE_VALUE) - return TSubTaskBase::eSubResult_Continue; + // pass it to the specialized method + TSubTaskBase::ESubOperationResult eResult = OpenExistingDestinationFileFB(hFile, pathDstFile, bNoBuffering); + if(eResult != TSubTaskBase::eSubResult_Continue) + return eResult; + else if(hFile == INVALID_HANDLE_VALUE) + return TSubTaskBase::eSubResult_Continue; - // read info about the existing destination file, - // NOTE: it is not known which one would be faster - reading file parameters - // by using spDstFileInfo->Create() (which uses FindFirstFile()) or by - // reading parameters using opened handle; need to be tested in the future - CFileInfoPtr spDstFileInfo(boost::make_shared()); - if(!spDstFileInfo->Create(pathDstFile, std::numeric_limits::max())) - THROW(_T("Cannot get information about file which has already been opened!"), 0, GetLastError(), 0); + // read info about the existing destination file, + // NOTE: it is not known which one would be faster - reading file parameters + // by using spDstFileInfo->Create() (which uses FindFirstFile()) or by + // reading parameters using opened handle; need to be tested in the future + CFileInfoPtr spDstFileInfo(boost::make_shared()); + if(!spDstFileInfo->Create(pathDstFile, std::numeric_limits::max())) + THROW(_T("Cannot get information about file which has already been opened!"), 0, GetLastError(), 0); - // src and dst files are the same - FEEDBACK_ALREADYEXISTS feedStruct = { spSrcFileInfo, spDstFileInfo }; - CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileAlreadyExists, &feedStruct); - // check for dialog result - switch(frResult) - { - case CFeedbackHandler::eResult_Overwrite: - ullSeekTo = 0; - break; + // src and dst files are the same + FEEDBACK_ALREADYEXISTS feedStruct = { spSrcFileInfo, spDstFileInfo }; + CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileAlreadyExists, &feedStruct); + // check for dialog result + switch(frResult) + { + case CFeedbackHandler::eResult_Overwrite: + ullSeekTo = 0; + break; - case CFeedbackHandler::eResult_CopyRest: - ullSeekTo = spDstFileInfo->GetLength64(); - break; + case CFeedbackHandler::eResult_CopyRest: + ullSeekTo = spDstFileInfo->GetLength64(); + break; - case CFeedbackHandler::eResult_Skip: - return TSubTaskBase::eSubResult_Continue; + case CFeedbackHandler::eResult_Skip: + return TSubTaskBase::eSubResult_Continue; - case CFeedbackHandler::eResult_Cancel: - { - // log - ictranslate::CFormat fmt; - fmt.SetFormat(_T("Cancel request while checking result of dialog before opening source file %path (CustomCopyFileFB)")); - fmt.SetParam(_t("%path"), pathDstFile.ToString()); - rLog.logi(fmt); + case CFeedbackHandler::eResult_Cancel: + { + // log + ictranslate::CFormat fmt; + fmt.SetFormat(_T("Cancel request while checking result of dialog before opening source file %path (CustomCopyFileFB)")); + fmt.SetParam(_t("%path"), pathDstFile.ToString()); + rLog.logi(fmt); - return TSubTaskBase::eSubResult_CancelRequest; - } - case CFeedbackHandler::eResult_Pause: - return TSubTaskBase::eSubResult_PauseRequest; + return TSubTaskBase::eSubResult_CancelRequest; + } + case CFeedbackHandler::eResult_Pause: + return TSubTaskBase::eSubResult_PauseRequest; - default: - BOOST_ASSERT(FALSE); // unknown result - THROW(_T("Unhandled case"), 0, 0, 0); - } - } - else - { - FEEDBACK_FILEERROR feedStruct = { pathDstFile.ToString(), NULL, eCreateError, dwLastError }; - CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &feedStruct); - switch (frResult) - { - case CFeedbackHandler::eResult_Retry: - { - // log - ictranslate::CFormat fmt; - fmt.SetFormat(_T("Retrying [error %errno] to open destination file %path (CustomCopyFileFB)")); - fmt.SetParam(_t("%errno"), dwLastError); - fmt.SetParam(_t("%path"), pathDstFile.ToString()); - rLog.loge(fmt); + default: + BOOST_ASSERT(FALSE); // unknown result + THROW(_T("Unhandled case"), 0, 0, 0); + } + } + else + { + FEEDBACK_FILEERROR feedStruct = { pathDstFile.ToString(), NULL, eCreateError, dwLastError }; + CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &feedStruct); + switch (frResult) + { + case CFeedbackHandler::eResult_Retry: + { + // log + ictranslate::CFormat fmt; + fmt.SetFormat(_T("Retrying [error %errno] to open destination file %path (CustomCopyFileFB)")); + fmt.SetParam(_t("%errno"), dwLastError); + fmt.SetParam(_t("%path"), pathDstFile.ToString()); + rLog.loge(fmt); - bRetry = true; + bRetry = true; - break; - } - case CFeedbackHandler::eResult_Cancel: - { - // log - ictranslate::CFormat fmt; + break; + } + case CFeedbackHandler::eResult_Cancel: + { + // log + ictranslate::CFormat fmt; - fmt.SetFormat(_T("Cancel request [error %errno] while opening destination file %path (CustomCopyFileFB)")); - fmt.SetParam(_t("%errno"), dwLastError); - fmt.SetParam(_t("%path"), pathDstFile.ToString()); - rLog.loge(fmt); + fmt.SetFormat(_T("Cancel request [error %errno] while opening destination file %path (CustomCopyFileFB)")); + fmt.SetParam(_t("%errno"), dwLastError); + fmt.SetParam(_t("%path"), pathDstFile.ToString()); + rLog.loge(fmt); - return TSubTaskBase::eSubResult_CancelRequest; - } + return TSubTaskBase::eSubResult_CancelRequest; + } - case CFeedbackHandler::eResult_Skip: - break; // will return invalid handle value + case CFeedbackHandler::eResult_Skip: + break; // will return invalid handle value - case CFeedbackHandler::eResult_Pause: - return TSubTaskBase::eSubResult_PauseRequest; + case CFeedbackHandler::eResult_Pause: + return TSubTaskBase::eSubResult_PauseRequest; - default: - BOOST_ASSERT(FALSE); // unknown result - THROW(_T("Unhandled case"), 0, 0, 0); - } - } - } - } - while(bRetry); + default: + BOOST_ASSERT(FALSE); // unknown result + THROW(_T("Unhandled case"), 0, 0, 0); + } + } + } + } + while(bRetry); - hOutFile = hFile.Detach(); + hOutFile = hFile.Detach(); - return TSubTaskBase::eSubResult_Continue; + return TSubTaskBase::eSubResult_Continue; } TSubTaskBase::ESubOperationResult TSubTaskCopyMove::OpenExistingDestinationFileFB(TAutoFileHandle& hOutFile, const chcore::TSmartPath& pathDstFile, bool bNoBuffering) { - chcore::IFeedbackHandler* piFeedbackHandler = GetContext().GetFeedbackHandler(); - icpf::log_file& rLog = GetContext().GetLog(); + chcore::IFeedbackHandler* piFeedbackHandler = GetContext().GetFeedbackHandler(); + icpf::log_file& rLog = GetContext().GetLog(); - bool bRetry = false; - TAutoFileHandle hFile; + bool bRetry = false; + TAutoFileHandle hFile; - hOutFile = INVALID_HANDLE_VALUE; + hOutFile = INVALID_HANDLE_VALUE; - do - { - bRetry = false; + do + { + bRetry = false; - hFile = CreateFile(pathDstFile.ToString(), GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN | (bNoBuffering ? FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH : 0), NULL); - if(hFile == INVALID_HANDLE_VALUE) - { - DWORD dwLastError = GetLastError(); - FEEDBACK_FILEERROR feedStruct = { pathDstFile.ToString(), NULL, eCreateError, dwLastError }; - CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &feedStruct); - switch (frResult) - { - case CFeedbackHandler::eResult_Retry: - { - // log - ictranslate::CFormat fmt; - fmt.SetFormat(_T("Retrying [error %errno] to open destination file %path (CustomCopyFileFB)")); - fmt.SetParam(_t("%errno"), dwLastError); - fmt.SetParam(_t("%path"), pathDstFile.ToString()); - rLog.loge(fmt); + hFile = CreateFile(pathDstFile.ToString(), GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN | (bNoBuffering ? FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH : 0), NULL); + if(hFile == INVALID_HANDLE_VALUE) + { + DWORD dwLastError = GetLastError(); + FEEDBACK_FILEERROR feedStruct = { pathDstFile.ToString(), NULL, eCreateError, dwLastError }; + CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &feedStruct); + switch (frResult) + { + case CFeedbackHandler::eResult_Retry: + { + // log + ictranslate::CFormat fmt; + fmt.SetFormat(_T("Retrying [error %errno] to open destination file %path (CustomCopyFileFB)")); + fmt.SetParam(_t("%errno"), dwLastError); + fmt.SetParam(_t("%path"), pathDstFile.ToString()); + rLog.loge(fmt); - bRetry = true; + bRetry = true; - break; - } - case CFeedbackHandler::eResult_Cancel: - { - // log - ictranslate::CFormat fmt; + break; + } + case CFeedbackHandler::eResult_Cancel: + { + // log + ictranslate::CFormat fmt; - fmt.SetFormat(_T("Cancel request [error %errno] while opening destination file %path (CustomCopyFileFB)")); - fmt.SetParam(_t("%errno"), dwLastError); - fmt.SetParam(_t("%path"), pathDstFile.ToString()); - rLog.loge(fmt); + fmt.SetFormat(_T("Cancel request [error %errno] while opening destination file %path (CustomCopyFileFB)")); + fmt.SetParam(_t("%errno"), dwLastError); + fmt.SetParam(_t("%path"), pathDstFile.ToString()); + rLog.loge(fmt); - return TSubTaskBase::eSubResult_CancelRequest; - } + return TSubTaskBase::eSubResult_CancelRequest; + } - case CFeedbackHandler::eResult_Skip: - break; // will return invalid handle value + case CFeedbackHandler::eResult_Skip: + break; // will return invalid handle value - case CFeedbackHandler::eResult_Pause: - return TSubTaskBase::eSubResult_PauseRequest; + case CFeedbackHandler::eResult_Pause: + return TSubTaskBase::eSubResult_PauseRequest; - default: - BOOST_ASSERT(FALSE); // unknown result - THROW(_T("Unhandled case"), 0, 0, 0); - } - } - } - while(bRetry); + default: + BOOST_ASSERT(FALSE); // unknown result + THROW(_T("Unhandled case"), 0, 0, 0); + } + } + } + while(bRetry); - hOutFile = hFile.Detach(); + hOutFile = hFile.Detach(); - return TSubTaskBase::eSubResult_Continue; + return TSubTaskBase::eSubResult_Continue; } TSubTaskBase::ESubOperationResult TSubTaskCopyMove::SetFilePointerFB(HANDLE hFile, long long llDistance, const chcore::TSmartPath& pathFile, bool& bSkip) { - chcore::IFeedbackHandler* piFeedbackHandler = GetContext().GetFeedbackHandler(); - icpf::log_file& rLog = GetContext().GetLog(); + chcore::IFeedbackHandler* piFeedbackHandler = GetContext().GetFeedbackHandler(); + icpf::log_file& rLog = GetContext().GetLog(); - bSkip = false; - bool bRetry = false; - do - { - bRetry = false; + bSkip = false; + bool bRetry = false; + do + { + bRetry = false; - if(SetFilePointer64(hFile, llDistance, FILE_BEGIN) == -1) - { - DWORD dwLastError = GetLastError(); + if(SetFilePointer64(hFile, llDistance, FILE_BEGIN) == -1) + { + DWORD dwLastError = GetLastError(); - // log - ictranslate::CFormat fmt; + // log + ictranslate::CFormat fmt; - fmt.SetFormat(_T("Error %errno while moving file pointer of %path to %pos")); - fmt.SetParam(_t("%errno"), dwLastError); - fmt.SetParam(_t("%path"), pathFile.ToString()); - fmt.SetParam(_t("%pos"), llDistance); - rLog.loge(fmt); + fmt.SetFormat(_T("Error %errno while moving file pointer of %path to %pos")); + fmt.SetParam(_t("%errno"), dwLastError); + fmt.SetParam(_t("%path"), pathFile.ToString()); + fmt.SetParam(_t("%pos"), llDistance); + rLog.loge(fmt); - FEEDBACK_FILEERROR ferr = { pathFile.ToString(), NULL, eSeekError, dwLastError }; - CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &ferr); - switch(frResult) - { - case CFeedbackHandler::eResult_Cancel: - return TSubTaskBase::eSubResult_CancelRequest; + FEEDBACK_FILEERROR ferr = { pathFile.ToString(), NULL, eSeekError, dwLastError }; + CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &ferr); + switch(frResult) + { + case CFeedbackHandler::eResult_Cancel: + return TSubTaskBase::eSubResult_CancelRequest; - case CFeedbackHandler::eResult_Retry: - bRetry = true; - break; + case CFeedbackHandler::eResult_Retry: + bRetry = true; + break; - case CFeedbackHandler::eResult_Pause: - return TSubTaskBase::eSubResult_PauseRequest; + case CFeedbackHandler::eResult_Pause: + return TSubTaskBase::eSubResult_PauseRequest; - case CFeedbackHandler::eResult_Skip: - bSkip = true; - return TSubTaskBase::eSubResult_Continue; + case CFeedbackHandler::eResult_Skip: + bSkip = true; + return TSubTaskBase::eSubResult_Continue; - default: - BOOST_ASSERT(FALSE); // unknown result - THROW(_T("Unhandled case"), 0, 0, 0); - } - } - } - while(bRetry); + default: + BOOST_ASSERT(FALSE); // unknown result + THROW(_T("Unhandled case"), 0, 0, 0); + } + } + } + while(bRetry); - return TSubTaskBase::eSubResult_Continue; + return TSubTaskBase::eSubResult_Continue; } TSubTaskBase::ESubOperationResult TSubTaskCopyMove::SetEndOfFileFB(HANDLE hFile, const chcore::TSmartPath& pathFile, bool& bSkip) { - chcore::IFeedbackHandler* piFeedbackHandler = GetContext().GetFeedbackHandler(); - icpf::log_file& rLog = GetContext().GetLog(); + chcore::IFeedbackHandler* piFeedbackHandler = GetContext().GetFeedbackHandler(); + icpf::log_file& rLog = GetContext().GetLog(); - bSkip = false; + bSkip = false; - bool bRetry = false; - do - { - if(!SetEndOfFile(hFile)) - { - // log - DWORD dwLastError = GetLastError(); + bool bRetry = false; + do + { + if(!SetEndOfFile(hFile)) + { + // log + DWORD dwLastError = GetLastError(); - ictranslate::CFormat fmt; - fmt.SetFormat(_T("Error %errno while setting size of file %path to 0")); - fmt.SetParam(_t("%errno"), dwLastError); - fmt.SetParam(_t("%path"), pathFile.ToString()); - rLog.loge(fmt); + ictranslate::CFormat fmt; + fmt.SetFormat(_T("Error %errno while setting size of file %path to 0")); + fmt.SetParam(_t("%errno"), dwLastError); + fmt.SetParam(_t("%path"), pathFile.ToString()); + rLog.loge(fmt); - FEEDBACK_FILEERROR ferr = { pathFile.ToString(), NULL, eResizeError, dwLastError }; - CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &ferr); - switch(frResult) - { - case CFeedbackHandler::eResult_Cancel: - return TSubTaskBase::eSubResult_CancelRequest; + FEEDBACK_FILEERROR ferr = { pathFile.ToString(), NULL, eResizeError, dwLastError }; + CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &ferr); + switch(frResult) + { + case CFeedbackHandler::eResult_Cancel: + return TSubTaskBase::eSubResult_CancelRequest; - case CFeedbackHandler::eResult_Retry: - bRetry = true; + case CFeedbackHandler::eResult_Retry: + bRetry = true; - case CFeedbackHandler::eResult_Pause: - return TSubTaskBase::eSubResult_PauseRequest; + case CFeedbackHandler::eResult_Pause: + return TSubTaskBase::eSubResult_PauseRequest; - case CFeedbackHandler::eResult_Skip: - bSkip = true; - return TSubTaskBase::eSubResult_Continue; + case CFeedbackHandler::eResult_Skip: + bSkip = true; + return TSubTaskBase::eSubResult_Continue; - default: - BOOST_ASSERT(FALSE); // unknown result - THROW(_T("Unhandled case"), 0, 0, 0); - } - } - } - while(bRetry); + default: + BOOST_ASSERT(FALSE); // unknown result + THROW(_T("Unhandled case"), 0, 0, 0); + } + } + } + while(bRetry); - return TSubTaskBase::eSubResult_Continue; + return TSubTaskBase::eSubResult_Continue; } TSubTaskBase::ESubOperationResult TSubTaskCopyMove::ReadFileFB(HANDLE hFile, CDataBuffer& rBuffer, DWORD dwToRead, DWORD& rdwBytesRead, const chcore::TSmartPath& pathFile, bool& bSkip) { - chcore::IFeedbackHandler* piFeedbackHandler = GetContext().GetFeedbackHandler(); - icpf::log_file& rLog = GetContext().GetLog(); + chcore::IFeedbackHandler* piFeedbackHandler = GetContext().GetFeedbackHandler(); + icpf::log_file& rLog = GetContext().GetLog(); - bSkip = false; - bool bRetry = false; - do - { - bRetry = false; + bSkip = false; + bool bRetry = false; + do + { + bRetry = false; - if(!ReadFile(hFile, rBuffer, dwToRead, &rdwBytesRead, NULL)) - { - // log - DWORD dwLastError = GetLastError(); + if(!ReadFile(hFile, rBuffer, dwToRead, &rdwBytesRead, NULL)) + { + // log + DWORD dwLastError = GetLastError(); - ictranslate::CFormat fmt; - fmt.SetFormat(_T("Error %errno while trying to read %count bytes from source file %path (CustomCopyFileFB)")); - fmt.SetParam(_t("%errno"), dwLastError); - fmt.SetParam(_t("%count"), dwToRead); - fmt.SetParam(_t("%path"), pathFile.ToString()); - rLog.loge(fmt); + ictranslate::CFormat fmt; + fmt.SetFormat(_T("Error %errno while trying to read %count bytes from source file %path (CustomCopyFileFB)")); + fmt.SetParam(_t("%errno"), dwLastError); + fmt.SetParam(_t("%count"), dwToRead); + fmt.SetParam(_t("%path"), pathFile.ToString()); + rLog.loge(fmt); - FEEDBACK_FILEERROR ferr = { pathFile.ToString(), NULL, eReadError, dwLastError }; - CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &ferr); - switch(frResult) - { - case CFeedbackHandler::eResult_Cancel: - return TSubTaskBase::eSubResult_CancelRequest; + FEEDBACK_FILEERROR ferr = { pathFile.ToString(), NULL, eReadError, dwLastError }; + CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &ferr); + switch(frResult) + { + case CFeedbackHandler::eResult_Cancel: + return TSubTaskBase::eSubResult_CancelRequest; - case CFeedbackHandler::eResult_Retry: - bRetry = true; - break; + case CFeedbackHandler::eResult_Retry: + bRetry = true; + break; - case CFeedbackHandler::eResult_Pause: - return TSubTaskBase::eSubResult_PauseRequest; + case CFeedbackHandler::eResult_Pause: + return TSubTaskBase::eSubResult_PauseRequest; - case CFeedbackHandler::eResult_Skip: - bSkip = true; - return TSubTaskBase::eSubResult_Continue; + case CFeedbackHandler::eResult_Skip: + bSkip = true; + return TSubTaskBase::eSubResult_Continue; - default: - BOOST_ASSERT(FALSE); // unknown result - THROW(_T("Unhandled case"), 0, 0, 0); - } - } - } - while(bRetry); + default: + BOOST_ASSERT(FALSE); // unknown result + THROW(_T("Unhandled case"), 0, 0, 0); + } + } + } + while(bRetry); - return TSubTaskBase::eSubResult_Continue; + return TSubTaskBase::eSubResult_Continue; } TSubTaskBase::ESubOperationResult TSubTaskCopyMove::WriteFileFB(HANDLE hFile, CDataBuffer& rBuffer, DWORD dwToWrite, DWORD& rdwBytesWritten, const chcore::TSmartPath& pathFile, bool& bSkip) { - chcore::IFeedbackHandler* piFeedbackHandler = GetContext().GetFeedbackHandler(); - icpf::log_file& rLog = GetContext().GetLog(); + chcore::IFeedbackHandler* piFeedbackHandler = GetContext().GetFeedbackHandler(); + icpf::log_file& rLog = GetContext().GetLog(); - bSkip = false; + bSkip = false; - bool bRetry = false; - do - { - bRetry = false; + bool bRetry = false; + do + { + bRetry = false; - if(!WriteFile(hFile, rBuffer, dwToWrite, &rdwBytesWritten, NULL) || dwToWrite != rdwBytesWritten) - { - // log - DWORD dwLastError = GetLastError(); + if(!WriteFile(hFile, rBuffer, dwToWrite, &rdwBytesWritten, NULL) || dwToWrite != rdwBytesWritten) + { + // log + DWORD dwLastError = GetLastError(); - ictranslate::CFormat fmt; - fmt.SetFormat(_T("Error %errno while trying to write %count bytes to destination file %path (CustomCopyFileFB)")); - fmt.SetParam(_t("%errno"), dwLastError); - fmt.SetParam(_t("%count"), dwToWrite); - fmt.SetParam(_t("%path"), pathFile.ToString()); - rLog.loge(fmt); + ictranslate::CFormat fmt; + fmt.SetFormat(_T("Error %errno while trying to write %count bytes to destination file %path (CustomCopyFileFB)")); + fmt.SetParam(_t("%errno"), dwLastError); + fmt.SetParam(_t("%count"), dwToWrite); + fmt.SetParam(_t("%path"), pathFile.ToString()); + rLog.loge(fmt); - FEEDBACK_FILEERROR ferr = { pathFile.ToString(), NULL, eWriteError, dwLastError }; - CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &ferr); - switch(frResult) - { - case CFeedbackHandler::eResult_Cancel: - return TSubTaskBase::eSubResult_CancelRequest; + FEEDBACK_FILEERROR ferr = { pathFile.ToString(), NULL, eWriteError, dwLastError }; + CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &ferr); + switch(frResult) + { + case CFeedbackHandler::eResult_Cancel: + return TSubTaskBase::eSubResult_CancelRequest; - case CFeedbackHandler::eResult_Retry: - bRetry = true; - break; + case CFeedbackHandler::eResult_Retry: + bRetry = true; + break; - case CFeedbackHandler::eResult_Pause: - return TSubTaskBase::eSubResult_PauseRequest; + case CFeedbackHandler::eResult_Pause: + return TSubTaskBase::eSubResult_PauseRequest; - case CFeedbackHandler::eResult_Skip: - bSkip = true; - return TSubTaskBase::eSubResult_Continue; + case CFeedbackHandler::eResult_Skip: + bSkip = true; + return TSubTaskBase::eSubResult_Continue; - default: - BOOST_ASSERT(FALSE); // unknown result - THROW(_T("Unhandled case"), 0, 0, 0); - } - } - } - while(bRetry); + default: + BOOST_ASSERT(FALSE); // unknown result + THROW(_T("Unhandled case"), 0, 0, 0); + } + } + } + while(bRetry); - return TSubTaskBase::eSubResult_Continue; + return TSubTaskBase::eSubResult_Continue; } Index: src/ch/TSubTaskCopyMove.h =================================================================== diff -u -N -r8c87d4185fbe5b952c49f72afcfd5f9fca338fb4 -r6e8aa26e2428e3bc71099255c5911f57bc722100 --- src/ch/TSubTaskCopyMove.h (.../TSubTaskCopyMove.h) (revision 8c87d4185fbe5b952c49f72afcfd5f9fca338fb4) +++ src/ch/TSubTaskCopyMove.h (.../TSubTaskCopyMove.h) (revision 6e8aa26e2428e3bc71099255c5911f57bc722100) @@ -32,25 +32,25 @@ class TSubTaskCopyMove : public TSubTaskBase { public: - TSubTaskCopyMove(TSubTaskContext& tSubTaskContext); + TSubTaskCopyMove(TSubTaskContext& tSubTaskContext); - ESubOperationResult Exec(); + ESubOperationResult Exec(); private: - bool GetMove(const CFileInfoPtr& spFileInfo); - int GetBufferIndex(const CFileInfoPtr& spFileInfo); + bool GetMove(const CFileInfoPtr& spFileInfo); + int GetBufferIndex(const CFileInfoPtr& spFileInfo); - TSubTaskBase::ESubOperationResult CustomCopyFileFB(CUSTOM_COPY_PARAMS* pData); + TSubTaskBase::ESubOperationResult CustomCopyFileFB(CUSTOM_COPY_PARAMS* pData); - TSubTaskBase::ESubOperationResult OpenSourceFileFB(TAutoFileHandle& hFile, const CFileInfoPtr& spSrcFileInfo, bool bNoBuffering); - TSubTaskBase::ESubOperationResult OpenDestinationFileFB(TAutoFileHandle& hFile, const chcore::TSmartPath& pathDstFile, bool bNoBuffering, const CFileInfoPtr& spSrcFileInfo, unsigned long long& ullSeekTo, bool& bFreshlyCreated); - TSubTaskBase::ESubOperationResult OpenExistingDestinationFileFB(TAutoFileHandle& hFile, const chcore::TSmartPath& pathDstFilePath, bool bNoBuffering); + TSubTaskBase::ESubOperationResult OpenSourceFileFB(TAutoFileHandle& hFile, const CFileInfoPtr& spSrcFileInfo, bool bNoBuffering); + TSubTaskBase::ESubOperationResult OpenDestinationFileFB(TAutoFileHandle& hFile, const chcore::TSmartPath& pathDstFile, bool bNoBuffering, const CFileInfoPtr& spSrcFileInfo, unsigned long long& ullSeekTo, bool& bFreshlyCreated); + TSubTaskBase::ESubOperationResult OpenExistingDestinationFileFB(TAutoFileHandle& hFile, const chcore::TSmartPath& pathDstFilePath, bool bNoBuffering); - TSubTaskBase::ESubOperationResult SetFilePointerFB(HANDLE hFile, long long llDistance, const chcore::TSmartPath& pathFile, bool& bSkip); - TSubTaskBase::ESubOperationResult SetEndOfFileFB(HANDLE hFile, const chcore::TSmartPath& pathFile, bool& bSkip); + TSubTaskBase::ESubOperationResult SetFilePointerFB(HANDLE hFile, long long llDistance, const chcore::TSmartPath& pathFile, bool& bSkip); + TSubTaskBase::ESubOperationResult SetEndOfFileFB(HANDLE hFile, const chcore::TSmartPath& pathFile, bool& bSkip); - TSubTaskBase::ESubOperationResult ReadFileFB(HANDLE hFile, CDataBuffer& rBuffer, DWORD dwToRead, DWORD& rdwBytesRead, const chcore::TSmartPath& pathFile, bool& bSkip); - TSubTaskBase::ESubOperationResult WriteFileFB(HANDLE hFile, CDataBuffer& rBuffer, DWORD dwToWrite, DWORD& rdwBytesWritten, const chcore::TSmartPath& pathFile, bool& bSkip); + TSubTaskBase::ESubOperationResult ReadFileFB(HANDLE hFile, CDataBuffer& rBuffer, DWORD dwToRead, DWORD& rdwBytesRead, const chcore::TSmartPath& pathFile, bool& bSkip); + TSubTaskBase::ESubOperationResult WriteFileFB(HANDLE hFile, CDataBuffer& rBuffer, DWORD dwToWrite, DWORD& rdwBytesWritten, const chcore::TSmartPath& pathFile, bool& bSkip); }; #endif Index: src/ch/TSubTaskScanDirectory.cpp =================================================================== diff -u -N -r8c87d4185fbe5b952c49f72afcfd5f9fca338fb4 -r6e8aa26e2428e3bc71099255c5911f57bc722100 --- src/ch/TSubTaskScanDirectory.cpp (.../TSubTaskScanDirectory.cpp) (revision 8c87d4185fbe5b952c49f72afcfd5f9fca338fb4) +++ src/ch/TSubTaskScanDirectory.cpp (.../TSubTaskScanDirectory.cpp) (revision 6e8aa26e2428e3bc71099255c5911f57bc722100) @@ -33,7 +33,7 @@ #include "TTaskLocalStats.h" TSubTaskScanDirectories::TSubTaskScanDirectories(TSubTaskContext& rContext) : - TSubTaskBase(rContext) +TSubTaskBase(rContext) { } @@ -49,7 +49,7 @@ TTaskDefinition& rTaskDefinition = GetContext().GetTaskDefinition(); chcore::IFeedbackHandler* piFeedbackHandler = GetContext().GetFeedbackHandler(); const TBasePathDataContainer& rarrSourcePathsInfo = GetContext().GetTaskDefinition().GetSourcePaths(); - TWorkerThreadController& rThreadController = GetContext().GetThreadController(); + TWorkerThreadController& rThreadController = GetContext().GetThreadController(); rLog.logi(_T("Searching for files...")); @@ -184,7 +184,7 @@ else { if(bMove && iDestDrvNumber != -1 && iDestDrvNumber == GetDriveNumber(spFileInfo) && - !TLocalFilesystem::PathExist(CalculateDestinationPath(spFileInfo, rTaskDefinition.GetDestinationPath(), ((int)bForceDirectories) << 1)) ) + !TLocalFilesystem::PathExist(CalculateDestinationPath(spFileInfo, rTaskDefinition.GetDestinationPath(), ((int)bForceDirectories) << 1)) ) { // if moving within one partition boundary set the file size to 0 so the overall size will // be ok @@ -205,7 +205,7 @@ } // calc size of all files - GetContext().GetTaskLocalStats().SetTotalSize(rFilesCache.CalculateTotalSize()); + GetContext().GetTaskLocalStats().SetTotalSize(rFilesCache.CalculateTotalSize()); // log rLog.logi(_T("Searching for files finished")); @@ -217,7 +217,7 @@ { CFileInfoArray& rFilesCache = GetContext().GetFilesCache(); TTaskDefinition& rTaskDefinition = GetContext().GetTaskDefinition(); - TWorkerThreadController& rThreadController = GetContext().GetThreadController(); + TWorkerThreadController& rThreadController = GetContext().GetThreadController(); WIN32_FIND_DATA wfd; chcore::TSmartPath pathCurrent; Index: src/ch/TTaskGlobalStats.cpp =================================================================== diff -u -N -r8c87d4185fbe5b952c49f72afcfd5f9fca338fb4 -r6e8aa26e2428e3bc71099255c5911f57bc722100 --- src/ch/TTaskGlobalStats.cpp (.../TTaskGlobalStats.cpp) (revision 8c87d4185fbe5b952c49f72afcfd5f9fca338fb4) +++ src/ch/TTaskGlobalStats.cpp (.../TTaskGlobalStats.cpp) (revision 6e8aa26e2428e3bc71099255c5911f57bc722100) @@ -27,9 +27,9 @@ // TTasksGlobalStats members TTasksGlobalStats::TTasksGlobalStats() : - m_ullGlobalTotalSize(0), - m_ullGlobalProcessedSize(0), - m_stRunningTasks(0) +m_ullGlobalTotalSize(0), +m_ullGlobalProcessedSize(0), +m_stRunningTasks(0) { } @@ -39,80 +39,80 @@ void TTasksGlobalStats::IncreaseGlobalTotalSize(unsigned long long ullModify) { - boost::unique_lock lock(m_lock); - m_ullGlobalTotalSize += ullModify; + boost::unique_lock lock(m_lock); + m_ullGlobalTotalSize += ullModify; } void TTasksGlobalStats::DecreaseGlobalTotalSize(unsigned long long ullModify) { - boost::unique_lock lock(m_lock); - m_ullGlobalTotalSize -= ullModify; + boost::unique_lock lock(m_lock); + m_ullGlobalTotalSize -= ullModify; } unsigned long long TTasksGlobalStats::GetGlobalTotalSize() const { - boost::shared_lock lock(m_lock); - return m_ullGlobalTotalSize; + boost::shared_lock lock(m_lock); + return m_ullGlobalTotalSize; } void TTasksGlobalStats::IncreaseGlobalProcessedSize(unsigned long long ullModify) { - boost::unique_lock lock(m_lock); - m_ullGlobalProcessedSize += ullModify; + boost::unique_lock lock(m_lock); + m_ullGlobalProcessedSize += ullModify; } void TTasksGlobalStats::DecreaseGlobalProcessedSize(unsigned long long ullModify) { - boost::unique_lock lock(m_lock); - m_ullGlobalProcessedSize -= ullModify; + boost::unique_lock lock(m_lock); + m_ullGlobalProcessedSize -= ullModify; } unsigned long long TTasksGlobalStats::GetGlobalProcessedSize() const { - boost::shared_lock lock(m_lock); - return m_ullGlobalProcessedSize; + boost::shared_lock lock(m_lock); + return m_ullGlobalProcessedSize; } void TTasksGlobalStats::IncreaseGlobalProgressData(unsigned long long ullTasksPosition, unsigned long long ullTasksSize) { - boost::unique_lock lock(m_lock); - m_ullGlobalTotalSize += ullTasksSize; - m_ullGlobalProcessedSize += ullTasksPosition; + boost::unique_lock lock(m_lock); + m_ullGlobalTotalSize += ullTasksSize; + m_ullGlobalProcessedSize += ullTasksPosition; } void TTasksGlobalStats::DecreaseGlobalProgressData(unsigned long long ullTasksPosition, unsigned long long ullTasksSize) { - boost::unique_lock lock(m_lock); - m_ullGlobalTotalSize -= ullTasksSize; - m_ullGlobalProcessedSize -= ullTasksPosition; + boost::unique_lock lock(m_lock); + m_ullGlobalTotalSize -= ullTasksSize; + m_ullGlobalProcessedSize -= ullTasksPosition; } int TTasksGlobalStats::GetProgressPercents() const { - unsigned long long llPercent = 0; + unsigned long long llPercent = 0; - boost::shared_lock lock(m_lock); + boost::shared_lock lock(m_lock); - if(m_ullGlobalTotalSize != 0) - llPercent = m_ullGlobalProcessedSize * 100 / m_ullGlobalTotalSize; + if(m_ullGlobalTotalSize != 0) + llPercent = m_ullGlobalProcessedSize * 100 / m_ullGlobalTotalSize; - return boost::numeric_cast(llPercent); + return boost::numeric_cast(llPercent); } void TTasksGlobalStats::IncreaseRunningTasks() { - boost::unique_lock lock(m_lock); - ++m_stRunningTasks; + boost::unique_lock lock(m_lock); + ++m_stRunningTasks; } void TTasksGlobalStats::DecreaseRunningTasks() { - boost::unique_lock lock(m_lock); - --m_stRunningTasks; + boost::unique_lock lock(m_lock); + --m_stRunningTasks; } size_t TTasksGlobalStats::GetRunningTasksCount() const { - boost::shared_lock lock(m_lock); - return m_stRunningTasks; + boost::shared_lock lock(m_lock); + return m_stRunningTasks; } Index: src/ch/TTaskGlobalStats.h =================================================================== diff -u -N -r8c87d4185fbe5b952c49f72afcfd5f9fca338fb4 -r6e8aa26e2428e3bc71099255c5911f57bc722100 --- src/ch/TTaskGlobalStats.h (.../TTaskGlobalStats.h) (revision 8c87d4185fbe5b952c49f72afcfd5f9fca338fb4) +++ src/ch/TTaskGlobalStats.h (.../TTaskGlobalStats.h) (revision 6e8aa26e2428e3bc71099255c5911f57bc722100) @@ -28,32 +28,32 @@ class TTasksGlobalStats { public: - TTasksGlobalStats(); - ~TTasksGlobalStats(); + TTasksGlobalStats(); + ~TTasksGlobalStats(); - void IncreaseGlobalTotalSize(unsigned long long ullModify); - void DecreaseGlobalTotalSize(unsigned long long ullModify); - unsigned long long GetGlobalTotalSize() const; + 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 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); + void IncreaseGlobalProgressData(unsigned long long ullTasksPosition, unsigned long long ullTasksSize); + void DecreaseGlobalProgressData(unsigned long long ullTasksPosition, unsigned long long ullTasksSize); - int GetProgressPercents() const; + int GetProgressPercents() const; - void IncreaseRunningTasks(); - void DecreaseRunningTasks(); - size_t GetRunningTasksCount() const; + void IncreaseRunningTasks(); + void DecreaseRunningTasks(); + size_t GetRunningTasksCount() const; private: - volatile unsigned long long m_ullGlobalTotalSize; - volatile unsigned long long m_ullGlobalProcessedSize; + 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; + volatile size_t m_stRunningTasks; // count of current operations + mutable boost::shared_mutex m_lock; }; #endif Index: src/ch/TTaskLocalStats.cpp =================================================================== diff -u -N -r8c87d4185fbe5b952c49f72afcfd5f9fca338fb4 -r6e8aa26e2428e3bc71099255c5911f57bc722100 --- src/ch/TTaskLocalStats.cpp (.../TTaskLocalStats.cpp) (revision 8c87d4185fbe5b952c49f72afcfd5f9fca338fb4) +++ src/ch/TTaskLocalStats.cpp (.../TTaskLocalStats.cpp) (revision 6e8aa26e2428e3bc71099255c5911f57bc722100) @@ -27,231 +27,231 @@ //////////////////////////////////////////////////////////////////////////////// // TTasksGlobalStats members TTaskLocalStats::TTaskLocalStats() : - m_prtGlobalStats(NULL), - m_ullProcessedSize(0), - m_ullTotalSize(0), - m_bTaskIsRunning(false), - m_timeElapsed(0), - m_timeLast(-1), - m_iCurrentBufferIndex(0) +m_prtGlobalStats(NULL), +m_ullProcessedSize(0), +m_ullTotalSize(0), +m_bTaskIsRunning(false), +m_timeElapsed(0), +m_timeLast(-1), +m_iCurrentBufferIndex(0) { } TTaskLocalStats::~TTaskLocalStats() { - DisconnectGlobalStats(); + DisconnectGlobalStats(); } void TTaskLocalStats::ConnectGlobalStats(TTasksGlobalStats& rtGlobalStats) { - DisconnectGlobalStats(); + DisconnectGlobalStats(); - boost::unique_lock lock(m_lock); + boost::unique_lock lock(m_lock); - m_prtGlobalStats = &rtGlobalStats; - m_prtGlobalStats->IncreaseGlobalProgressData(m_ullProcessedSize, m_ullTotalSize); - if(m_bTaskIsRunning) - m_prtGlobalStats->IncreaseRunningTasks(); + m_prtGlobalStats = &rtGlobalStats; + m_prtGlobalStats->IncreaseGlobalProgressData(m_ullProcessedSize, m_ullTotalSize); + if(m_bTaskIsRunning) + m_prtGlobalStats->IncreaseRunningTasks(); } void TTaskLocalStats::DisconnectGlobalStats() { - boost::unique_lock lock(m_lock); + boost::unique_lock lock(m_lock); - if(m_prtGlobalStats) - { - m_prtGlobalStats->DecreaseGlobalProgressData(m_ullProcessedSize, m_ullTotalSize); - if(m_bTaskIsRunning) - m_prtGlobalStats->DecreaseRunningTasks(); - m_prtGlobalStats = NULL; - } + if(m_prtGlobalStats) + { + m_prtGlobalStats->DecreaseGlobalProgressData(m_ullProcessedSize, m_ullTotalSize); + if(m_bTaskIsRunning) + m_prtGlobalStats->DecreaseRunningTasks(); + m_prtGlobalStats = NULL; + } } void TTaskLocalStats::IncreaseProcessedSize(unsigned long long ullAdd) { - boost::unique_lock lock(m_lock); + boost::unique_lock lock(m_lock); - if(m_prtGlobalStats) - m_prtGlobalStats->IncreaseGlobalProcessedSize(ullAdd); + if(m_prtGlobalStats) + m_prtGlobalStats->IncreaseGlobalProcessedSize(ullAdd); - m_ullProcessedSize += ullAdd; + m_ullProcessedSize += ullAdd; } void TTaskLocalStats::DecreaseProcessedSize(unsigned long long ullSub) { - boost::unique_lock lock(m_lock); - if(m_prtGlobalStats) - m_prtGlobalStats->DecreaseGlobalProcessedSize(ullSub); + boost::unique_lock lock(m_lock); + if(m_prtGlobalStats) + m_prtGlobalStats->DecreaseGlobalProcessedSize(ullSub); - m_ullProcessedSize -= ullSub; + m_ullProcessedSize -= ullSub; } void TTaskLocalStats::SetProcessedSize(unsigned long long ullSet) { - boost::unique_lock lock(m_lock); + boost::unique_lock lock(m_lock); - if(m_prtGlobalStats) - { - if(ullSet < m_ullProcessedSize) - m_prtGlobalStats->DecreaseGlobalProcessedSize(m_ullProcessedSize - ullSet); - else - m_prtGlobalStats->IncreaseGlobalProcessedSize(ullSet - m_ullProcessedSize); - } + if(m_prtGlobalStats) + { + if(ullSet < m_ullProcessedSize) + m_prtGlobalStats->DecreaseGlobalProcessedSize(m_ullProcessedSize - ullSet); + else + m_prtGlobalStats->IncreaseGlobalProcessedSize(ullSet - m_ullProcessedSize); + } - m_ullProcessedSize = ullSet; + m_ullProcessedSize = ullSet; } unsigned long long TTaskLocalStats::GetProcessedSize() const { - boost::shared_lock lock(m_lock); - return m_ullProcessedSize; + boost::shared_lock lock(m_lock); + return m_ullProcessedSize; } unsigned long long TTaskLocalStats::GetUnProcessedSize() const { - boost::shared_lock lock(m_lock); - return m_ullTotalSize - m_ullProcessedSize; + boost::shared_lock lock(m_lock); + return m_ullTotalSize - m_ullProcessedSize; } void TTaskLocalStats::IncreaseTotalSize(unsigned long long ullAdd) { - boost::unique_lock lock(m_lock); + boost::unique_lock lock(m_lock); - if(m_prtGlobalStats) - m_prtGlobalStats->IncreaseGlobalTotalSize(ullAdd); - m_ullTotalSize += ullAdd; + if(m_prtGlobalStats) + m_prtGlobalStats->IncreaseGlobalTotalSize(ullAdd); + m_ullTotalSize += ullAdd; } void TTaskLocalStats::DecreaseTotalSize(unsigned long long ullSub) { - boost::unique_lock lock(m_lock); + boost::unique_lock lock(m_lock); - if(m_prtGlobalStats) - m_prtGlobalStats->DecreaseGlobalTotalSize(ullSub); + if(m_prtGlobalStats) + m_prtGlobalStats->DecreaseGlobalTotalSize(ullSub); - m_ullTotalSize -= ullSub; + m_ullTotalSize -= ullSub; } void TTaskLocalStats::SetTotalSize(unsigned long long ullSet) { - boost::unique_lock lock(m_lock); + boost::unique_lock lock(m_lock); - if(m_prtGlobalStats) - { - if(ullSet < m_ullTotalSize) - m_prtGlobalStats->DecreaseGlobalTotalSize(m_ullTotalSize - ullSet); - else - m_prtGlobalStats->IncreaseGlobalTotalSize(ullSet - m_ullTotalSize); - } + if(m_prtGlobalStats) + { + if(ullSet < m_ullTotalSize) + m_prtGlobalStats->DecreaseGlobalTotalSize(m_ullTotalSize - ullSet); + else + m_prtGlobalStats->IncreaseGlobalTotalSize(ullSet - m_ullTotalSize); + } - m_ullTotalSize = ullSet; + m_ullTotalSize = ullSet; } unsigned long long TTaskLocalStats::GetTotalSize() const { - boost::shared_lock lock(m_lock); - return m_ullTotalSize; + boost::shared_lock lock(m_lock); + return m_ullTotalSize; } int TTaskLocalStats::GetProgressInPercent() const { - boost::shared_lock lock(m_lock); + boost::shared_lock lock(m_lock); - unsigned long long ullPercent = 0; + unsigned long long ullPercent = 0; - if(m_ullTotalSize != 0) - ullPercent = m_ullProcessedSize * 100 / m_ullTotalSize; + if(m_ullTotalSize != 0) + ullPercent = m_ullProcessedSize * 100 / m_ullTotalSize; - return boost::numeric_cast(ullPercent); + return boost::numeric_cast(ullPercent); } void TTaskLocalStats::MarkTaskAsRunning() { - boost::unique_lock lock(m_lock); - if(!m_bTaskIsRunning) - { - if(m_prtGlobalStats) - m_prtGlobalStats->IncreaseRunningTasks(); - m_bTaskIsRunning = true; - } + boost::unique_lock lock(m_lock); + if(!m_bTaskIsRunning) + { + if(m_prtGlobalStats) + m_prtGlobalStats->IncreaseRunningTasks(); + m_bTaskIsRunning = true; + } } void TTaskLocalStats::MarkTaskAsNotRunning() { - boost::unique_lock lock(m_lock); - if(m_bTaskIsRunning) - { - if(m_prtGlobalStats) - m_prtGlobalStats->DecreaseRunningTasks(); - m_bTaskIsRunning = false; - } + boost::unique_lock lock(m_lock); + if(m_bTaskIsRunning) + { + if(m_prtGlobalStats) + m_prtGlobalStats->DecreaseRunningTasks(); + m_bTaskIsRunning = false; + } } bool TTaskLocalStats::IsRunning() const { - boost::shared_lock lock(m_lock); - return m_bTaskIsRunning; + boost::shared_lock lock(m_lock); + return m_bTaskIsRunning; } void TTaskLocalStats::SetTimeElapsed(time_t timeElapsed) { - boost::unique_lock lock(m_lock); - m_timeElapsed = timeElapsed; + boost::unique_lock lock(m_lock); + m_timeElapsed = timeElapsed; } time_t TTaskLocalStats::GetTimeElapsed() { - UpdateTime(); + UpdateTime(); - boost::shared_lock lock(m_lock); - return m_timeElapsed; + boost::shared_lock lock(m_lock); + return m_timeElapsed; } void TTaskLocalStats::EnableTimeTracking() { - boost::upgrade_lock lock(m_lock); - if(m_timeLast == -1) - { - boost::upgrade_to_unique_lock lock_upgraded(lock); - m_timeLast = time(NULL); - } + boost::upgrade_lock lock(m_lock); + if(m_timeLast == -1) + { + boost::upgrade_to_unique_lock lock_upgraded(lock); + m_timeLast = time(NULL); + } } void TTaskLocalStats::DisableTimeTracking() { - UpdateTime(); + UpdateTime(); - boost::upgrade_lock lock(m_lock); - if(m_timeLast != -1) - { - boost::upgrade_to_unique_lock lock_upgraded(lock); - m_timeLast = -1; - } + boost::upgrade_lock lock(m_lock); + if(m_timeLast != -1) + { + boost::upgrade_to_unique_lock lock_upgraded(lock); + m_timeLast = -1; + } } void TTaskLocalStats::UpdateTime() { - boost::upgrade_lock lock(m_lock); - if(m_timeLast != -1) - { - time_t timeCurrent = time(NULL); + boost::upgrade_lock lock(m_lock); + if(m_timeLast != -1) + { + time_t timeCurrent = time(NULL); - boost::upgrade_to_unique_lock lock_upgraded(lock); - m_timeElapsed += timeCurrent - m_timeLast; - m_timeLast = timeCurrent; - } + boost::upgrade_to_unique_lock lock_upgraded(lock); + m_timeElapsed += timeCurrent - m_timeLast; + m_timeLast = timeCurrent; + } } void TTaskLocalStats::SetCurrentBufferIndex(int iCurrentIndex) { - boost::unique_lock lock(m_lock); - m_iCurrentBufferIndex = iCurrentIndex; + boost::unique_lock lock(m_lock); + m_iCurrentBufferIndex = iCurrentIndex; } int TTaskLocalStats::GetCurrentBufferIndex() const { - // locking possibly not needed, not entirely sure now - boost::shared_lock lock(m_lock); - int iResult = m_iCurrentBufferIndex; - return iResult; + // locking possibly not needed, not entirely sure now + boost::shared_lock lock(m_lock); + int iResult = m_iCurrentBufferIndex; + return iResult; } Index: src/ch/TTaskLocalStats.h =================================================================== diff -u -N -r8c87d4185fbe5b952c49f72afcfd5f9fca338fb4 -r6e8aa26e2428e3bc71099255c5911f57bc722100 --- src/ch/TTaskLocalStats.h (.../TTaskLocalStats.h) (revision 8c87d4185fbe5b952c49f72afcfd5f9fca338fb4) +++ src/ch/TTaskLocalStats.h (.../TTaskLocalStats.h) (revision 6e8aa26e2428e3bc71099255c5911f57bc722100) @@ -28,53 +28,53 @@ class TTaskLocalStats { public: - TTaskLocalStats(); - ~TTaskLocalStats(); + TTaskLocalStats(); + ~TTaskLocalStats(); - void ConnectGlobalStats(TTasksGlobalStats& rtGlobalStats); - void DisconnectGlobalStats(); + 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 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; + 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; + int GetProgressInPercent() const; - void MarkTaskAsRunning(); - void MarkTaskAsNotRunning(); - bool IsRunning() const; + void MarkTaskAsRunning(); + void MarkTaskAsNotRunning(); + bool IsRunning() const; - void SetTimeElapsed(time_t timeElapsed); - time_t GetTimeElapsed(); + void SetTimeElapsed(time_t timeElapsed); + time_t GetTimeElapsed(); - void EnableTimeTracking(); - void DisableTimeTracking(); - void UpdateTime(); + void EnableTimeTracking(); + void DisableTimeTracking(); + void UpdateTime(); - void SetCurrentBufferIndex(int iCurrentIndex); - int GetCurrentBufferIndex() const; + void SetCurrentBufferIndex(int iCurrentIndex); + int GetCurrentBufferIndex() const; private: - volatile unsigned long long m_ullProcessedSize; - volatile unsigned long long m_ullTotalSize; + volatile unsigned long long m_ullProcessedSize; + volatile unsigned long long m_ullTotalSize; - volatile bool m_bTaskIsRunning; + volatile bool m_bTaskIsRunning; - // time - volatile time_t m_timeElapsed; - volatile time_t m_timeLast; + // time + volatile time_t m_timeElapsed; + volatile time_t m_timeLast; - volatile int m_iCurrentBufferIndex; + volatile int m_iCurrentBufferIndex; - mutable boost::shared_mutex m_lock; - TTasksGlobalStats* m_prtGlobalStats; + mutable boost::shared_mutex m_lock; + TTasksGlobalStats* m_prtGlobalStats; }; #endif Index: src/ch/task.cpp =================================================================== diff -u -N -rc866a5e96f5eaf160278a8c128bf86e342cc2409 -r6e8aa26e2428e3bc71099255c5911f57bc722100 --- src/ch/task.cpp (.../task.cpp) (revision c866a5e96f5eaf160278a8c128bf86e342cc2409) +++ src/ch/task.cpp (.../task.cpp) (revision 6e8aa26e2428e3bc71099255c5911f57bc722100) @@ -40,17 +40,17 @@ //////////////////////////////////////////////////////////////////////////// // CTask members CTask::CTask(chcore::IFeedbackHandler* piFeedbackHandler, size_t stSessionUniqueID) : - m_log(), - m_piFeedbackHandler(piFeedbackHandler), - m_arrSourcePathsInfo(m_tTaskDefinition.GetSourcePaths()), - m_files(m_tTaskDefinition.GetSourcePaths()), - m_bForce(false), - m_bContinue(false), - m_bRareStateModified(false), - m_bOftenStateModified(false), - m_stSessionUniqueID(stSessionUniqueID), - m_localStats(), - m_eCurrentState(eTaskState_None) +m_log(), +m_piFeedbackHandler(piFeedbackHandler), +m_arrSourcePathsInfo(m_tTaskDefinition.GetSourcePaths()), +m_files(m_tTaskDefinition.GetSourcePaths()), +m_bForce(false), +m_bContinue(false), +m_bRareStateModified(false), +m_bOftenStateModified(false), +m_stSessionUniqueID(stSessionUniqueID), +m_localStats(), +m_eCurrentState(eTaskState_None) { BOOST_ASSERT(piFeedbackHandler); } @@ -117,7 +117,7 @@ int CTask::GetCurrentBufferIndex() { - return m_localStats.GetCurrentBufferIndex(); + return m_localStats.GetCurrentBufferIndex(); } // thread @@ -684,8 +684,8 @@ // start tracking time for this thread m_localStats.EnableTimeTracking(); - // prepare context for subtasks - TSubTaskContext tSubTaskContext(m_tTaskDefinition, m_arrSourcePathsInfo, m_files, m_localStats, m_tTaskBasicProgressInfo, m_cfgTracker, m_log, m_piFeedbackHandler, m_workerThread); + // prepare context for subtasks + TSubTaskContext tSubTaskContext(m_tTaskDefinition, m_arrSourcePathsInfo, m_files, m_localStats, m_tTaskBasicProgressInfo, m_cfgTracker, m_log, m_piFeedbackHandler, m_workerThread); for(; stSubOperationIndex < m_tTaskDefinition.GetOperationPlan().GetSubOperationsCount() && eResult == TSubTaskBase::eSubResult_Continue; ++stSubOperationIndex) { @@ -696,40 +696,40 @@ switch(eSubOperation) { case eSubOperation_Scanning: - { - // get rid of info about processed sizes - m_localStats.SetProcessedSize(0); - m_localStats.SetTotalSize(0); + { + // get rid of info about processed sizes + m_localStats.SetProcessedSize(0); + m_localStats.SetTotalSize(0); - // start searching - TSubTaskScanDirectories tSubTaskScanDir(tSubTaskContext); - //eResult = RecurseDirectories(); - eResult = tSubTaskScanDir.Exec(); + // start searching + TSubTaskScanDirectories tSubTaskScanDir(tSubTaskContext); + //eResult = RecurseDirectories(); + eResult = tSubTaskScanDir.Exec(); - // check for free space - if(eResult == TSubTaskBase::eSubResult_Continue) - eResult = CheckForFreeSpaceFB(); + // check for free space + if(eResult == TSubTaskBase::eSubResult_Continue) + eResult = CheckForFreeSpaceFB(); - // if we didn't wait for permission to start earlier, then ask now (but only in case this is the first search) - if(eResult == TSubTaskBase::eSubResult_Continue && bReadTasksSize && stSubOperationIndex == 0) - { - m_localStats.DisableTimeTracking(); + // if we didn't wait for permission to start earlier, then ask now (but only in case this is the first search) + if(eResult == TSubTaskBase::eSubResult_Continue && bReadTasksSize && stSubOperationIndex == 0) + { + m_localStats.DisableTimeTracking(); - eResult = CheckForWaitState(); + eResult = CheckForWaitState(); - m_localStats.EnableTimeTracking(); - } + m_localStats.EnableTimeTracking(); + } - break; - } + break; + } case eSubOperation_Copying: - { - TSubTaskCopyMove tSubTaskCopyMove(tSubTaskContext); + { + TSubTaskCopyMove tSubTaskCopyMove(tSubTaskContext); - eResult = tSubTaskCopyMove.Exec(); - break; - } + eResult = tSubTaskCopyMove.Exec(); + break; + } case eSubOperation_Deleting: { @@ -926,8 +926,8 @@ //////////////////////////////////////////////////////////////////////////////// // CTaskArray members CTaskArray::CTaskArray() : - m_piFeedbackFactory(NULL), - m_stNextSessionUniqueID(NO_TASK_SESSION_UNIQUE_ID + 1) +m_piFeedbackFactory(NULL), +m_stNextSessionUniqueID(NO_TASK_SESSION_UNIQUE_ID + 1) { } @@ -939,7 +939,7 @@ void CTaskArray::Create(chcore::IFeedbackHandlerFactory* piFeedbackHandlerFactory) { BOOST_ASSERT(piFeedbackHandlerFactory); - + m_piFeedbackFactory = piFeedbackHandlerFactory; } @@ -948,7 +948,7 @@ BOOST_ASSERT(m_piFeedbackFactory); if(!m_piFeedbackFactory) return CTaskPtr(); - + chcore::IFeedbackHandler* piHandler = m_piFeedbackFactory->Create(); if(!piHandler) return CTaskPtr(); @@ -972,11 +972,11 @@ CTaskPtr CTaskArray::GetAt(size_t nIndex) const { boost::shared_lock lock(m_lock); - + _ASSERTE(nIndex >= 0 && nIndex < m_vTasks.size()); if(nIndex >= m_vTasks.size()) THROW(_t("Invalid argument"), 0, 0, 0); - + return m_vTasks.at(nIndex); } @@ -996,19 +996,19 @@ break; } } - + return spFoundTask; } size_t CTaskArray::Add(const CTaskPtr& spNewTask) { if(!spNewTask) THROW(_t("Invalid argument"), 0, 0, 0); - + boost::unique_lock lock(m_lock); // here we know load succeeded spNewTask->SetTaskDirectory(m_strTasksDir.c_str()); - + m_vTasks.push_back(spNewTask); spNewTask->OnRegisterTask(m_globalStats); @@ -1019,15 +1019,15 @@ void CTaskArray::RemoveAt(size_t stIndex, size_t stCount) { boost::unique_lock lock(m_lock); - + _ASSERTE(stIndex >= m_vTasks.size() || stIndex + stCount > m_vTasks.size()); if(stIndex >= m_vTasks.size() || stIndex + stCount > m_vTasks.size()) THROW(_t("Invalid argument"), 0, 0, 0); - + for(std::vector::iterator iterTask = m_vTasks.begin() + stIndex; iterTask != m_vTasks.begin() + stIndex + stCount; ++iterTask) { CTaskPtr& spTask = *iterTask; - + // kill task if needed spTask->KillThread(); @@ -1081,12 +1081,12 @@ void CTaskArray::RemoveFinished(const CTaskPtr& spSelTask) { boost::unique_lock lock(m_lock); - + // this might be optimized by copying tasks to a local table in critical section, and then deleting progress files outside of the critical section for(std::vector::iterator iterTask = m_vTasks.begin(); iterTask != m_vTasks.end(); ++iterTask) { CTaskPtr& spTask = *iterTask; - + if(spTask == spSelTask && (spTask->GetTaskState() == eTaskState_Finished || spTask->GetTaskState() == eTaskState_Cancelled)) { // kill task if needed @@ -1096,9 +1096,9 @@ // delete associated files spTask->DeleteProgress(); - + m_vTasks.erase(iterTask); - + return; } } @@ -1107,7 +1107,7 @@ void CTaskArray::StopAllTasks() { boost::unique_lock lock(m_lock); - + StopAllTasksNL(); } @@ -1149,13 +1149,13 @@ while(bWorking) { bWorking = finder.FindNextFile(); - + // load data spTask = CreateTask(); try { spTask->Load(finder.GetFilePath()); - + // add read task to array Add(spTask); } @@ -1224,7 +1224,7 @@ if(spTask->RetryProcessing()) bChanged = true; } - + return bChanged; } @@ -1255,7 +1255,7 @@ bool CTaskArray::AreAllFinished() { bool bFlag=true; - + if(m_globalStats.GetRunningTasksCount() != 0) bFlag = false; else @@ -1270,7 +1270,7 @@ break; } } - + return bFlag; } @@ -1287,7 +1287,7 @@ { spTask->RequestStopThread(); } - + // wait for finishing BOOST_FOREACH(CTaskPtr& spTask, m_vTasks) { Index: src/libchcore/TConfig.cpp =================================================================== diff -u -N -ra296360740c0d5a9e84f6be32e1654128d2953bc -r6e8aa26e2428e3bc71099255c5911f57bc722100 --- src/libchcore/TConfig.cpp (.../TConfig.cpp) (revision a296360740c0d5a9e84f6be32e1654128d2953bc) +++ src/libchcore/TConfig.cpp (.../TConfig.cpp) (revision 6e8aa26e2428e3bc71099255c5911f57bc722100) @@ -29,7 +29,7 @@ #pragma warning(push) #pragma warning(disable: 4702 4512) - #include +#include #pragma warning(pop) BEGIN_CHCORE_NAMESPACE @@ -38,8 +38,8 @@ // class TConfigNotifier TConfigNotifier::TConfigNotifier(void (*pfnCallback)(const std::set&, void*), void* pParam) : - m_pfnCallback(pfnCallback), - m_pParam(pParam) +m_pfnCallback(pfnCallback), +m_pParam(pParam) { } @@ -109,14 +109,14 @@ // class TConfig TConfig::TConfig() : - m_bDelayedEnabled(false), - m_bModified(false) +m_bDelayedEnabled(false), +m_bModified(false) { } TConfig::TConfig(const TConfig& rSrc) : - m_bDelayedEnabled(false), - m_bModified(rSrc.m_bModified) +m_bDelayedEnabled(false), +m_bModified(rSrc.m_bModified) { boost::shared_lock lock(rSrc.m_lock); @@ -426,23 +426,23 @@ bool TConfig::ExtractMultiSubConfigs(PCTSTR pszSubTreeName, std::vector& rSubConfigs) const { - TConfig cfg; + TConfig cfg; - boost::shared_lock lock(m_lock); + boost::shared_lock lock(m_lock); - boost::optional optChildren = m_propTree.get_child_optional(pszSubTreeName); - if(optChildren.is_initialized()) - { - BOOST_FOREACH(const boost::property_tree::wiptree::value_type& rEntry, optChildren.get()) - { - cfg.m_propTree = rEntry.second; - rSubConfigs.push_back(cfg); - } + boost::optional optChildren = m_propTree.get_child_optional(pszSubTreeName); + if(optChildren.is_initialized()) + { + BOOST_FOREACH(const boost::property_tree::wiptree::value_type& rEntry, optChildren.get()) + { + cfg.m_propTree = rEntry.second; + rSubConfigs.push_back(cfg); + } - return true; - } - else - return false; + return true; + } + else + return false; } void TConfig::PutSubConfig(PCTSTR pszSubTreeName, const TConfig& rSubConfig) @@ -457,12 +457,12 @@ void TConfig::AddSubConfig(PCTSTR pszSubTreeName, const TConfig& rSubConfig) { - boost::unique_lock lock(m_lock); - boost::shared_lock src_lock(rSubConfig.m_lock); + boost::unique_lock lock(m_lock); + boost::shared_lock src_lock(rSubConfig.m_lock); - m_propTree.add_child(pszSubTreeName, rSubConfig.m_propTree); + m_propTree.add_child(pszSubTreeName, rSubConfig.m_propTree); - m_bModified = true; + m_bModified = true; } void TConfig::DeleteNode(PCTSTR pszNodeName)