Index: src/ch/ClipboardMonitor.cpp =================================================================== diff -u -N -r3f72015a9db19bd1b0a5e20e0f1aa0ec00bda529 -rb42450e5a25470c399e04cfbb7a368519aa455f2 --- src/ch/ClipboardMonitor.cpp (.../ClipboardMonitor.cpp) (revision 3f72015a9db19bd1b0a5e20e0f1aa0ec00bda529) +++ src/ch/ClipboardMonitor.cpp (.../ClipboardMonitor.cpp) (revision b42450e5a25470c399e04cfbb7a368519aa455f2) @@ -176,6 +176,10 @@ dlg.GetPath(strData); tTaskDefinition.SetDestinationPath((PCTSTR)strData); + // load resource strings + SetTaskPropValue(tTaskDefinition.GetConfiguration(), GetResManager().LoadString(IDS_FIRSTCOPY_STRING)); + SetTaskPropValue(tTaskDefinition.GetConfiguration(), GetResManager().LoadString(IDS_NEXTCOPY_STRING)); + CTaskPtr spTask = pData->m_pTasks->CreateTask(); spTask->SetTaskDefinition(tTaskDefinition); Index: src/ch/FileInfo.cpp =================================================================== diff -u -N -r3f72015a9db19bd1b0a5e20e0f1aa0ec00bda529 -rb42450e5a25470c399e04cfbb7a368519aa455f2 --- src/ch/FileInfo.cpp (.../FileInfo.cpp) (revision 3f72015a9db19bd1b0a5e20e0f1aa0ec00bda529) +++ src/ch/FileInfo.cpp (.../FileInfo.cpp) (revision b42450e5a25470c399e04cfbb7a368519aa455f2) @@ -269,36 +269,7 @@ ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// -// finds another name for a copy of src file(folder) in dest location -void FindFreeSubstituteName(chcore::TSmartPath pathSrcPath, chcore::TSmartPath pathDstPath, CString* pstrResult) -{ - // get the name from srcpath - pathSrcPath.CutIfExists(_T("\\"), false); - pathDstPath.AppendIfNotExists(_T("\\"), false); - chcore::TSmartPath spLastComponent = pathSrcPath.GetLastComponent(_T("\\"), false); - - // set the dest path - CString strCheckPath; - ictranslate::CFormat fmt(GetResManager().LoadString(IDS_FIRSTCOPY_STRING)); - fmt.SetParam(_t("%name"), (PCTSTR)spLastComponent); - chcore::TSmartPath pathCheckPath((PCTSTR)fmt); - - // when adding to strDstPath check if the path already exists - if so - try again - int iCounter=1; - CString strFmt = GetResManager().LoadString(IDS_NEXTCOPY_STRING); - while(CFileInfo::Exist(pathDstPath + pathCheckPath)) - { - fmt.SetFormat(strFmt); - fmt.SetParam(_t("%name"), (PCTSTR)spLastComponent); - fmt.SetParam(_t("%count"), ++iCounter); - pathCheckPath = (PCTSTR)fmt; - } - - *pstrResult = pathCheckPath; -} - -//////////////////////////////////////////////////////////////////////////// CFileInfo::CFileInfo() : m_pClipboard(NULL), m_strFilePath(), @@ -517,46 +488,6 @@ && rInfo.m_ftLastWrite.dwHighDateTime == m_ftLastWrite.dwHighDateTime && rInfo.m_ftLastWrite.dwLowDateTime == m_ftLastWrite.dwLowDateTime && rInfo.m_uhFileSize == m_uhFileSize); } -chcore::TSmartPath CFileInfo::GetDestinationPath(chcore::TSmartPath pathDst, int iFlags) const -{ - // add '\\' - pathDst.AppendIfNotExists(_T("\\"), false); - - // iFlags: bit 0-ignore folders; bit 1-force creating directories - if (iFlags & 0x02) - { - // force create directories - TCHAR dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT]; - _tsplitpath(GetFullFilePath(), NULL, dir, fname, ext); - - CString str=dir; - str.TrimLeft(_T("\\")); - - // force create directory - SHCreateDirectoryEx(NULL, pathDst + str, NULL); - - return pathDst + chcore::TSmartPath((PCTSTR)str) + chcore::TSmartPath(fname) + chcore::TSmartPath(ext); - } - else - { - if (!(iFlags & 0x01) && m_stSrcIndex != std::numeric_limits::max()) - { - // generate new dest name - if(!m_pClipboard->GetAt(m_stSrcIndex)->IsDestinationPathSet()) - { - CString strNewPath; - FindFreeSubstituteName(chcore::TSmartPath((PCTSTR)GetFullFilePath()), pathDst, &strNewPath); - m_pClipboard->GetAt(m_stSrcIndex)->SetDestinationPath(strNewPath); - } - - CString strResultPath = pathDst + m_pClipboard->GetAt(m_stSrcIndex)->GetDestinationPath() + m_strFilePath; - return chcore::TSmartPath((PCTSTR)strResultPath); - } - else - return pathDst + chcore::TSmartPath(GetFileName()); - } -} - CString CFileInfo::GetFullFilePath() const { CString strPath; Index: src/ch/FileInfo.h =================================================================== diff -u -N -r3f72015a9db19bd1b0a5e20e0f1aa0ec00bda529 -rb42450e5a25470c399e04cfbb7a368519aa455f2 --- src/ch/FileInfo.h (.../FileInfo.h) (revision 3f72015a9db19bd1b0a5e20e0f1aa0ec00bda529) +++ src/ch/FileInfo.h (.../FileInfo.h) (revision b42450e5a25470c399e04cfbb7a368519aa455f2) @@ -24,7 +24,6 @@ #include "../libchcore/TPath.h" -void FindFreeSubstituteName(chcore::TSmartPath pathSrcPath, chcore::TSmartPath pathDstPath, CString* pstrResult); void GetDriveData(LPCTSTR lpszPath, int *piDrvNum, UINT *puiDrvType); // CFileInfo flags @@ -203,7 +202,6 @@ // operations void SetClipboard(const CClipboardArray *pClipboard) { m_pClipboard = pClipboard; }; - chcore::TSmartPath GetDestinationPath(chcore::TSmartPath strPath, int iFlags) const; void SetSrcIndex(size_t stIndex) { m_stSrcIndex = stIndex; }; size_t GetSrcIndex() const { return m_stSrcIndex; }; Index: src/ch/MainWnd.cpp =================================================================== diff -u -N -r3f72015a9db19bd1b0a5e20e0f1aa0ec00bda529 -rb42450e5a25470c399e04cfbb7a368519aa455f2 --- src/ch/MainWnd.cpp (.../MainWnd.cpp) (revision 3f72015a9db19bd1b0a5e20e0f1aa0ec00bda529) +++ src/ch/MainWnd.cpp (.../MainWnd.cpp) (revision b42450e5a25470c399e04cfbb7a368519aa455f2) @@ -526,6 +526,10 @@ // Task priority SetTaskPropValue(tTaskDefinition.GetConfiguration(), iPriority); + // load resource strings + SetTaskPropValue(tTaskDefinition.GetConfiguration(), GetResManager().LoadString(IDS_FIRSTCOPY_STRING)); + SetTaskPropValue(tTaskDefinition.GetConfiguration(), GetResManager().LoadString(IDS_NEXTCOPY_STRING)); + // create task with the above definition CTaskPtr spTask = m_tasks.CreateTask(); @@ -611,7 +615,11 @@ // Task priority SetTaskPropValue(tTaskDefinition.GetConfiguration(), dlg.m_ccData.m_iPriority); - + + // load resource strings + SetTaskPropValue(tTaskDefinition.GetConfiguration(), GetResManager().LoadString(IDS_FIRSTCOPY_STRING)); + SetTaskPropValue(tTaskDefinition.GetConfiguration(), GetResManager().LoadString(IDS_NEXTCOPY_STRING)); + // new task CTaskPtr spTask = m_tasks.CreateTask(); spTask->SetTaskDefinition(tTaskDefinition); Index: src/ch/TTaskConfigTracker.cpp =================================================================== diff -u -N -r8213d63ae7b0a09fc4c5e15aa6ca7ddf655ae31f -rb42450e5a25470c399e04cfbb7a368519aa455f2 --- src/ch/TTaskConfigTracker.cpp (.../TTaskConfigTracker.cpp) (revision 8213d63ae7b0a09fc4c5e15aa6ca7ddf655ae31f) +++ src/ch/TTaskConfigTracker.cpp (.../TTaskConfigTracker.cpp) (revision b42450e5a25470c399e04cfbb7a368519aa455f2) @@ -228,12 +228,16 @@ return eTO_CreateDirectoriesRelativeToRoot; else if(strOption == TaskPropData::GetPropertyName()) return eTO_IgnoreDirectories; + else if(strOption == TaskPropData::GetPropertyName()) + return eTO_AlternateFilenameFormatString_AfterFirst; + else if(strOption == TaskPropData::GetPropertyName()) + return eTO_AlternateFilenameFormatString_First; else { BOOST_ASSERT(false); // unhandled case THROW(_T("Unhandled case"), 0, 0, 0); } // add new elements before this one - BOOST_STATIC_ASSERT(eTO_Last == eTO_IgnoreDirectories + 1); + BOOST_STATIC_ASSERT(eTO_Last == eTO_AlternateFilenameFormatString_AfterFirst + 1); } Index: src/ch/TTaskConfiguration.h =================================================================== diff -u -N -rca046f75806db6693a4b2dc6ddb255f76d0bbc3f -rb42450e5a25470c399e04cfbb7a368519aa455f2 --- src/ch/TTaskConfiguration.h (.../TTaskConfiguration.h) (revision ca046f75806db6693a4b2dc6ddb255f76d0bbc3f) +++ src/ch/TTaskConfiguration.h (.../TTaskConfiguration.h) (revision b42450e5a25470c399e04cfbb7a368519aa455f2) @@ -48,6 +48,9 @@ eTO_CreateDirectoriesRelativeToRoot, eTO_IgnoreDirectories, + eTO_AlternateFilenameFormatString_First, + eTO_AlternateFilenameFormatString_AfterFirst, + // add new elements before this one eTO_Last }; @@ -102,6 +105,9 @@ TASK_PROPERTY(eTO_CreateDirectoriesRelativeToRoot, bool, _T("Operation.CreateDirectoriesRelativeToRoot"), false); TASK_PROPERTY(eTO_IgnoreDirectories, bool, _T("Operation.IgnoreDirectories"), false); +TASK_PROPERTY(eTO_AlternateFilenameFormatString_First, CString, _T("Naming.AlternateFilenameFormatFirst"), _T("Copy of %name")); +TASK_PROPERTY(eTO_AlternateFilenameFormatString_AfterFirst, CString, _T("Naming.AlternateFilenameFormatAfterFirst"), _T("Copy (%count) of %name")); + ///////////////////////////////////////////////////////////////////////////////////////////// // Properties retrieval template Index: src/ch/task.cpp =================================================================== diff -u -N -r3f72015a9db19bd1b0a5e20e0f1aa0ec00bda529 -rb42450e5a25470c399e04cfbb7a368519aa455f2 --- src/ch/task.cpp (.../task.cpp) (revision 3f72015a9db19bd1b0a5e20e0f1aa0ec00bda529) +++ src/ch/task.cpp (.../task.cpp) (revision b42450e5a25470c399e04cfbb7a368519aa455f2) @@ -1151,8 +1151,8 @@ } // don't add folder contents when moving inside one disk boundary - if(bIgnoreDirs || !bMove || iDestDrvNumber == -1 - || iDestDrvNumber != spFileInfo->GetDriveNumber() || CFileInfo::Exist(spFileInfo->GetDestinationPath(m_tTaskDefinition.GetDestinationPath(), ((int)bForceDirectories) << 1)) ) + if(bIgnoreDirs || !bMove || iDestDrvNumber == -1 || iDestDrvNumber != spFileInfo->GetDriveNumber() || + CFileInfo::Exist(GetDestinationPath(spFileInfo, m_tTaskDefinition.GetDestinationPath(), ((int)bForceDirectories) << 1)) ) { // log fmt.SetFormat(_T("Recursing folder %path")); @@ -1177,7 +1177,7 @@ else { if(bMove && iDestDrvNumber != -1 && iDestDrvNumber == spFileInfo->GetDriveNumber() && - !CFileInfo::Exist(spFileInfo->GetDestinationPath(m_tTaskDefinition.GetDestinationPath(), ((int)bForceDirectories) << 1)) ) + !CFileInfo::Exist(GetDestinationPath(spFileInfo, m_tTaskDefinition.GetDestinationPath(), ((int)bForceDirectories) << 1)) ) { // if moving within one partition boundary set the file size to 0 so the overall size will // be ok @@ -2113,7 +2113,7 @@ CFileInfoPtr spFileInfo = m_files.GetAt(m_tTaskBasicProgressInfo.GetCurrentIndex()); // set dest path with filename - ccp.strDstFile = spFileInfo->GetDestinationPath((PCTSTR)m_tTaskDefinition.GetDestinationPath(), ((int)bForceDirectories) << 1 | (int)bIgnoreFolders); + ccp.strDstFile = GetDestinationPath(spFileInfo, m_tTaskDefinition.GetDestinationPath(), ((int)bForceDirectories) << 1 | (int)bIgnoreFolders); // are the files/folders lie on the same partition ? int iDstDriveNumber = 0; @@ -2595,6 +2595,81 @@ } } +// finds another name for a copy of src file(folder) in dest location +void CTask::FindFreeSubstituteName(chcore::TSmartPath pathSrcPath, chcore::TSmartPath pathDstPath, CString* pstrResult) const +{ + // get the name from srcpath + pathSrcPath.CutIfExists(_T("\\"), false); + pathDstPath.AppendIfNotExists(_T("\\"), false); + + chcore::TSmartPath spLastComponent = pathSrcPath.GetLastComponent(_T("\\"), false); + + // set the dest path + CString strCheckPath; + ictranslate::CFormat fmt(GetTaskPropValue(m_tTaskDefinition.GetConfiguration())); + fmt.SetParam(_t("%name"), (PCTSTR)spLastComponent); + chcore::TSmartPath pathCheckPath((PCTSTR)fmt); + + // when adding to strDstPath check if the path already exists - if so - try again + int iCounter=1; + CString strFmt = GetTaskPropValue(m_tTaskDefinition.GetConfiguration()); + while(CFileInfo::Exist(pathDstPath + pathCheckPath)) + { + fmt.SetFormat(strFmt); + fmt.SetParam(_t("%name"), (PCTSTR)spLastComponent); + fmt.SetParam(_t("%count"), ++iCounter); + pathCheckPath = (PCTSTR)fmt; + } + + *pstrResult = pathCheckPath; +} + + +chcore::TSmartPath CTask::GetDestinationPath(const CFileInfoPtr& spFileInfo, chcore::TSmartPath pathDst, int iFlags) const +{ + if(!spFileInfo) + THROW(_T("Invalid pointer"), 0, 0, 0); + + // add '\\' + pathDst.AppendIfNotExists(_T("\\"), false); + + // iFlags: bit 0-ignore folders; bit 1-force creating directories + if (iFlags & 0x02) + { + // force create directories + TCHAR dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT]; + _tsplitpath(spFileInfo->GetFullFilePath(), NULL, dir, fname, ext); + + CString str(dir); + str.TrimLeft(_T("\\")); + + // force create directory + SHCreateDirectoryEx(NULL, pathDst + str, NULL); + + return pathDst + chcore::TSmartPath((PCTSTR)str) + chcore::TSmartPath(fname) + chcore::TSmartPath(ext); + } + else + { + size_t stSrcIndex = spFileInfo->GetSrcIndex(); + + if (!(iFlags & 0x01) && stSrcIndex != std::numeric_limits::max()) + { + // generate new dest name + if(!m_arrSourcePaths.GetAt(stSrcIndex)->IsDestinationPathSet()) + { + CString strNewPath; + FindFreeSubstituteName(chcore::TSmartPath((PCTSTR)spFileInfo->GetFullFilePath()), pathDst, &strNewPath); + m_arrSourcePaths.GetAt(stSrcIndex)->SetDestinationPath(strNewPath); + } + + CString strResultPath = pathDst + m_arrSourcePaths.GetAt(stSrcIndex)->GetDestinationPath() + spFileInfo->GetFilePath(); + return chcore::TSmartPath((PCTSTR)strResultPath); + } + else + return pathDst + chcore::TSmartPath(spFileInfo->GetFileName()); + } +} + //////////////////////////////////////////////////////////////////////////////// // CTaskArray members CTaskArray::CTaskArray() : Index: src/ch/task.h =================================================================== diff -u -N -r3f72015a9db19bd1b0a5e20e0f1aa0ec00bda529 -rb42450e5a25470c399e04cfbb7a368519aa455f2 --- src/ch/task.h (.../task.h) (revision 3f72015a9db19bd1b0a5e20e0f1aa0ec00bda529) +++ src/ch/task.h (.../task.h) (revision b42450e5a25470c399e04cfbb7a368519aa455f2) @@ -393,6 +393,9 @@ static void OnCfgOptionChanged(const std::set& rsetChanges, void* pParam); + void FindFreeSubstituteName(chcore::TSmartPath pathSrcPath, chcore::TSmartPath pathDstPath, CString* pstrResult) const; + chcore::TSmartPath GetDestinationPath(const CFileInfoPtr& spFileInfo, chcore::TSmartPath strPath, int iFlags) const; + private: // task initial information (needed to start a task); might be a bit processed. TTaskDefinition m_tTaskDefinition; Index: src/libchcore/TPath.cpp =================================================================== diff -u -N -r3f72015a9db19bd1b0a5e20e0f1aa0ec00bda529 -rb42450e5a25470c399e04cfbb7a368519aa455f2 --- src/libchcore/TPath.cpp (.../TPath.cpp) (revision 3f72015a9db19bd1b0a5e20e0f1aa0ec00bda529) +++ src/libchcore/TPath.cpp (.../TPath.cpp) (revision b42450e5a25470c399e04cfbb7a368519aa455f2) @@ -142,7 +142,7 @@ /// @brief Constructs a path object from string. /// @param[in] pszPath - string with path. // ============================================================================ -TSmartPath::TSmartPath(const tchar_t* pszPath) : +TSmartPath::TSmartPath(const wchar_t* pszPath) : m_pPath(NULL) { m_pPath = TPath::New(); @@ -215,7 +215,7 @@ /// @param[in] strPath - string containing a path. /// @return Reference to this object. // ============================================================================ -TSmartPath& TSmartPath::operator=(const tchar_t* pszPath) +TSmartPath& TSmartPath::operator=(const wchar_t* pszPath) { PrepareToWrite(); m_pPath->m_strPath = pszPath; @@ -523,7 +523,6 @@ // ============================================================================ TPathContainer::~TPathContainer() { - } // ============================================================================ Index: src/libchcore/TPath.h =================================================================== diff -u -N -r3f72015a9db19bd1b0a5e20e0f1aa0ec00bda529 -rb42450e5a25470c399e04cfbb7a368519aa455f2 --- src/libchcore/TPath.h (.../TPath.h) (revision 3f72015a9db19bd1b0a5e20e0f1aa0ec00bda529) +++ src/libchcore/TPath.h (.../TPath.h) (revision b42450e5a25470c399e04cfbb7a368519aa455f2) @@ -51,7 +51,7 @@ public: TSmartPath(); TSmartPath(const tstring_t& strPath); - TSmartPath(const tchar_t* pszPath); + TSmartPath(const wchar_t* pszPath); TSmartPath(const TSmartPath& spPath); ~TSmartPath(); @@ -60,7 +60,7 @@ TSmartPath& operator=(const tstring_t& strPath); TSmartPath& operator=(const TSmartPath& spPath); - TSmartPath& operator=(const tchar_t* pszPath); + TSmartPath& operator=(const wchar_t* pszPath); bool operator==(const TSmartPath& rPath) const; bool operator<(const TSmartPath& rPath) const;