Index: src/libchcore/TSubTaskBase.cpp =================================================================== diff -u -N -r9ebcc7abf1e0e70f0db2d08b2691351a26ef259b -re96806b7f8ff7ca7e9f4afbea603e6351a3dc3e3 --- src/libchcore/TSubTaskBase.cpp (.../TSubTaskBase.cpp) (revision 9ebcc7abf1e0e70f0db2d08b2691351a26ef259b) +++ src/libchcore/TSubTaskBase.cpp (.../TSubTaskBase.cpp) (revision e96806b7f8ff7ca7e9f4afbea603e6351a3dc3e3) @@ -31,92 +31,91 @@ #include "TCoreException.h" #include "ErrorCodes.h" -BEGIN_CHCORE_NAMESPACE - -/////////////////////////////////////////////////////////////////////////// -// TSubTaskBase - -TSubTaskBase::TSubTaskBase(TSubTaskContext& rContext) : - m_rContext(rContext) +namespace chcore { -} + /////////////////////////////////////////////////////////////////////////// + // TSubTaskBase -TSubTaskBase::~TSubTaskBase() -{ -} + TSubTaskBase::TSubTaskBase(TSubTaskContext& rContext) : + m_rContext(rContext) + { + } -TSmartPath TSubTaskBase::CalculateDestinationPath(const TFileInfoPtr& spFileInfo, TSmartPath pathDst, int iFlags) -{ - IFilesystemPtr spFilesystem = GetContext().GetLocalFilesystem(); + TSubTaskBase::~TSubTaskBase() + { + } - if(!spFileInfo) - THROW_CORE_EXCEPTION(eErr_InvalidArgument); - - // iFlags: bit 0-ignore folders; bit 1-force creating directories - if(iFlags & 0x02) + TSmartPath TSubTaskBase::CalculateDestinationPath(const TFileInfoPtr& spFileInfo, TSmartPath pathDst, int iFlags) { - // force create directories - TSmartPath pathCombined = pathDst + spFileInfo->GetFullFilePath().GetFileDir(); + IFilesystemPtr spFilesystem = GetContext().GetLocalFilesystem(); - // force create directory - spFilesystem->CreateDirectory(pathCombined, true); + if (!spFileInfo) + THROW_CORE_EXCEPTION(eErr_InvalidArgument); - return pathCombined + spFileInfo->GetFullFilePath().GetFileName(); - } - else - { - TBasePathDataPtr spPathData = spFileInfo->GetBasePathData(); + // iFlags: bit 0-ignore folders; bit 1-force creating directories + if (iFlags & 0x02) + { + // force create directories + TSmartPath pathCombined = pathDst + spFileInfo->GetFullFilePath().GetFileDir(); - if(!(iFlags & 0x01) && spPathData) + // force create directory + spFilesystem->CreateDirectory(pathCombined, true); + + return pathCombined + spFileInfo->GetFullFilePath().GetFileName(); + } + else { - // generate new dest name - if(!spPathData->IsDestinationPathSet()) + TBasePathDataPtr spPathData = spFileInfo->GetBasePathData(); + + if (!(iFlags & 0x01) && spPathData) { - // generate something - if dest folder == src folder - search for copy - if(pathDst == spFileInfo->GetFullFilePath().GetFileRoot()) + // generate new dest name + if (!spPathData->IsDestinationPathSet()) { - TSmartPath pathSubst = FindFreeSubstituteName(spFileInfo->GetFullFilePath(), pathDst); - spPathData->SetDestinationPath(pathSubst); + // generate something - if dest folder == src folder - search for copy + if (pathDst == spFileInfo->GetFullFilePath().GetFileRoot()) + { + TSmartPath pathSubst = FindFreeSubstituteName(spFileInfo->GetFullFilePath(), pathDst); + spPathData->SetDestinationPath(pathSubst); + } + else + spPathData->SetDestinationPath(spFileInfo->GetFullFilePath().GetFileName()); } - else - spPathData->SetDestinationPath(spFileInfo->GetFullFilePath().GetFileName()); - } - return pathDst + spPathData->GetDestinationPath() + spFileInfo->GetFilePath(); + return pathDst + spPathData->GetDestinationPath() + spFileInfo->GetFilePath(); + } + else + return pathDst + spFileInfo->GetFullFilePath().GetFileName(); } - else - return pathDst + spFileInfo->GetFullFilePath().GetFileName(); } -} -// finds another name for a copy of src file(folder) in dest location -TSmartPath TSubTaskBase::FindFreeSubstituteName(TSmartPath pathSrcPath, TSmartPath pathDstPath) const -{ - const TConfig& rConfig = GetContext().GetConfig(); - IFilesystemPtr spFilesystem = GetContext().GetLocalFilesystem(); + // finds another name for a copy of src file(folder) in dest location + TSmartPath TSubTaskBase::FindFreeSubstituteName(TSmartPath pathSrcPath, TSmartPath pathDstPath) const + { + const TConfig& rConfig = GetContext().GetConfig(); + IFilesystemPtr spFilesystem = GetContext().GetLocalFilesystem(); - // get the name from src path - pathSrcPath.StripSeparatorAtEnd(); + // get the name from src path + pathSrcPath.StripSeparatorAtEnd(); - TSmartPath pathFilename = pathSrcPath.GetFileName(); + TSmartPath pathFilename = pathSrcPath.GetFileName(); - // set the dest path - TString strCheckPath = GetTaskPropValue(rConfig); - strCheckPath.Replace(_T("%name"), pathFilename.ToString()); - TSmartPath pathCheckPath(PathFromWString(strCheckPath)); + // set the dest path + TString strCheckPath = GetTaskPropValue(rConfig); + strCheckPath.Replace(_T("%name"), pathFilename.ToString()); + TSmartPath pathCheckPath(PathFromWString(strCheckPath)); - // when adding to strDstPath check if the path already exists - if so - try again - int iCounter = 1; - TString strFmt = GetTaskPropValue(rConfig); - while(spFilesystem->PathExist(pathDstPath + pathCheckPath)) - { - strCheckPath = strFmt; - strCheckPath.Replace(_t("%name"), pathFilename.ToString()); - strCheckPath.Replace(_t("%count"), boost::lexical_cast(++iCounter).c_str()); - pathCheckPath.FromString(strCheckPath); - } + // when adding to strDstPath check if the path already exists - if so - try again + int iCounter = 1; + TString strFmt = GetTaskPropValue(rConfig); + while (spFilesystem->PathExist(pathDstPath + pathCheckPath)) + { + strCheckPath = strFmt; + strCheckPath.Replace(_t("%name"), pathFilename.ToString()); + strCheckPath.Replace(_t("%count"), boost::lexical_cast(++iCounter).c_str()); + pathCheckPath.FromString(strCheckPath); + } - return pathCheckPath; + return pathCheckPath; + } } - -END_CHCORE_NAMESPACE