Index: src/ch/ClipboardMonitor.cpp =================================================================== diff -u -N -rb42450e5a25470c399e04cfbb7a368519aa455f2 -r69b48f0b4d7fad78f95854e95fca166014311474 --- src/ch/ClipboardMonitor.cpp (.../ClipboardMonitor.cpp) (revision b42450e5a25470c399e04cfbb7a368519aa455f2) +++ src/ch/ClipboardMonitor.cpp (.../ClipboardMonitor.cpp) (revision 69b48f0b4d7fad78f95854e95fca166014311474) @@ -91,7 +91,7 @@ { DragQueryFile(static_cast(handle), stIndex, path, _MAX_PATH); - tTaskDefinition.AddSourcePath(path); + tTaskDefinition.AddSourcePath(chcore::PathFromString(path)); } // operation type @@ -148,7 +148,8 @@ size_t stEntries = (stClipboardSize > 3) ? 2 : stClipboardSize; for(size_t stIndex = 0; stIndex < stEntries; stIndex++) { - dlg.m_bdData.strText += tTaskDefinition.GetSourcePathAt(stIndex) + _T("\n"); + dlg.m_bdData.strText += tTaskDefinition.GetSourcePathAt(stIndex).ToString(); + dlg.m_bdData.strText += _T("\n"); } // add ... @@ -174,7 +175,7 @@ // get dest path CString strData; dlg.GetPath(strData); - tTaskDefinition.SetDestinationPath((PCTSTR)strData); + tTaskDefinition.SetDestinationPath(chcore::PathFromString(strData)); // load resource strings SetTaskPropValue(tTaskDefinition.GetConfiguration(), GetResManager().LoadString(IDS_FIRSTCOPY_STRING)); Index: src/ch/FeedbackReplaceDlg.cpp =================================================================== diff -u -N -rc435ab507c8b8280264188b49e9ada56d46c0261 -r69b48f0b4d7fad78f95854e95fca166014311474 --- src/ch/FeedbackReplaceDlg.cpp (.../FeedbackReplaceDlg.cpp) (revision c435ab507c8b8280264188b49e9ada56d46c0261) +++ src/ch/FeedbackReplaceDlg.cpp (.../FeedbackReplaceDlg.cpp) (revision 69b48f0b4d7fad78f95854e95fca166014311474) @@ -96,7 +96,7 @@ strTemplate += rManager.LoadString(IDS_INFO_MODIFIED_STRING); ictranslate::CFormat fmt(strTemplate); - fmt.SetParam(_T("%filename"), m_spSrcFile->GetFullFilePath()); + fmt.SetParam(_T("%filename"), m_spSrcFile->GetFullFilePath().ToString()); fmt.SetParam(_T("%size"), m_spSrcFile->GetLength64()); COleDateTime dtTemp = m_spSrcFile->GetLastWriteTime(); @@ -105,7 +105,7 @@ m_ctlSrcInfo.SetWindowText(fmt); fmt.SetFormat(strTemplate); - fmt.SetParam(_T("%filename"), m_spDstFile->GetFullFilePath()); + fmt.SetParam(_T("%filename"), m_spDstFile->GetFullFilePath().ToString()); fmt.SetParam(_T("%size"), m_spDstFile->GetLength64()); dtTemp = m_spDstFile->GetLastWriteTime(); fmt.SetParam(_T("%datemod"), dtTemp.Format(LOCALE_NOUSEROVERRIDE, LANG_USER_DEFAULT)); @@ -120,11 +120,11 @@ return; SHFILEINFO shfi; - DWORD_PTR dwRes = SHGetFileInfo(m_spSrcFile->GetFullFilePath(), 0, &shfi, sizeof(shfi), SHGFI_ICON); + DWORD_PTR dwRes = SHGetFileInfo(m_spSrcFile->GetFullFilePath().ToString(), 0, &shfi, sizeof(shfi), SHGFI_ICON); if(dwRes) m_ctlSrcIcon.SetIcon(shfi.hIcon); - dwRes = SHGetFileInfo(m_spDstFile->GetFullFilePath(), 0, &shfi, sizeof(shfi), SHGFI_ICON); + dwRes = SHGetFileInfo(m_spDstFile->GetFullFilePath().ToString(), 0, &shfi, sizeof(shfi), SHGFI_ICON); if(dwRes) m_ctlDstIcon.SetIcon(shfi.hIcon); } Index: src/ch/FileFilter.cpp =================================================================== diff -u -N -r22bbc4a87fa0b249e1e02ba385f28da9d77a4aa1 -r69b48f0b4d7fad78f95854e95fca166014311474 --- src/ch/FileFilter.cpp (.../FileFilter.cpp) (revision 22bbc4a87fa0b249e1e02ba385f28da9d77a4aa1) +++ src/ch/FileFilter.cpp (.../FileFilter.cpp) (revision 69b48f0b4d7fad78f95854e95fca166014311474) @@ -192,7 +192,7 @@ bool bRes=false; for(std::vector::const_iterator iterMask = m_astrMask.begin(); iterMask != m_astrMask.end(); ++iterMask) { - if(MatchMask(*iterMask, spInfo->GetFileName())) + if(MatchMask(*iterMask, spInfo->GetFileName().ToString())) bRes = true; } if(!bRes) @@ -204,7 +204,7 @@ { for(std::vector::const_iterator iterExcludeMask = m_astrExcludeMask.begin(); iterExcludeMask != m_astrExcludeMask.end(); ++iterExcludeMask) { - if(MatchMask(*iterExcludeMask, spInfo->GetFileName())) + if(MatchMask(*iterExcludeMask, spInfo->GetFileName().ToString())) return false; } } Index: src/ch/FileInfo.cpp =================================================================== diff -u -N -r5ca05c7da8767b983492c0baf69e504239b22a97 -r69b48f0b4d7fad78f95854e95fca166014311474 --- src/ch/FileInfo.cpp (.../FileInfo.cpp) (revision 5ca05c7da8767b983492c0baf69e504239b22a97) +++ src/ch/FileInfo.cpp (.../FileInfo.cpp) (revision 69b48f0b4d7fad78f95854e95fca166014311474) @@ -39,11 +39,11 @@ #define new DEBUG_NEW #endif -void GetDriveData(LPCTSTR lpszPath, int* piDrvNum, UINT* puiDrvType) +void GetDriveData(const chcore::TSmartPath& spPath, int* piDrvNum, UINT* puiDrvType) { TCHAR drv[_MAX_DRIVE+1]; - _tsplitpath(lpszPath, drv, NULL, NULL, NULL); + _tsplitpath(spPath.ToString(), drv, NULL, NULL, NULL); if(lstrlen(drv) != 0) { // add '\\' @@ -71,7 +71,7 @@ if(puiDrvType) { // check for unc path - if(_tcsncmp(lpszPath, _T("\\\\"), 2) == 0) + if(_tcsncmp(spPath.ToString(), _T("\\\\"), 2) == 0) *puiDrvType=DRIVE_REMOTE; else *puiDrvType=DRIVE_UNKNOWN; @@ -90,32 +90,31 @@ } CClipboardEntry::CClipboardEntry(const CClipboardEntry& rEntry) : - m_strPath(rEntry.m_strPath), + m_path(rEntry.m_path), m_bMove(rEntry.m_bMove), m_iDriveNumber(rEntry.m_iDriveNumber), - m_strDstPath(rEntry.m_strDstPath) + m_pathDst(rEntry.m_pathDst) { } -void CClipboardEntry::SetPath(const CString& strPath) +void CClipboardEntry::SetPath(const chcore::TSmartPath& tPath) { - m_strPath = strPath; // guaranteed without ending '\\' - if(m_strPath.Right(1) == _T('\\')) - m_strPath = m_strPath.Left(m_strPath.GetLength() - 1); + m_path = tPath; // guaranteed without ending '\\' + m_path.CutIfExists(_T("\\"), false); } -CString CClipboardEntry::GetFileName() const +chcore::TSmartPath CClipboardEntry::GetFileName() const { TCHAR szName[_MAX_FNAME]; TCHAR szExt[_MAX_EXT]; - _tsplitpath(m_strPath, NULL, NULL, szName, szExt); - return CString(szName) + szExt; + _tsplitpath(m_path.ToString(), NULL, NULL, szName, szExt); + return chcore::PathFromString(CString(szName) + szExt); } int CClipboardEntry::GetDriveNumber() { if(m_iDriveNumber == -2) - GetDriveData(m_strPath, &m_iDriveNumber, NULL); + GetDriveData(m_path, &m_iDriveNumber, NULL); return m_iDriveNumber; } @@ -128,7 +127,7 @@ UINT uiDriveType = 0; int iDstDriveNumber = 0; UINT uiDstDriveType = 0; - GetDriveData(m_strPath, &iDriveNumber, &uiDriveType); + GetDriveData(m_path, &iDriveNumber, &uiDriveType); GetDriveData(dpDestPath, &iDstDriveNumber, &uiDstDriveType); // what kind of buffer @@ -151,14 +150,14 @@ return m_iBufferIndex; } -void CClipboardEntry::SetDestinationPath(const CString& strPath) +void CClipboardEntry::SetDestinationPath(const chcore::TSmartPath& tPath) { - m_strDstPath = strPath; + m_pathDst = tPath; } -CString CClipboardEntry::GetDestinationPath() const +chcore::TSmartPath CClipboardEntry::GetDestinationPath() const { - return m_strDstPath; + return m_pathDst; } ////////////////////////////////////////////////////////////////////////////// @@ -248,15 +247,15 @@ BOOST_FOREACH(CClipboardEntryPtr& spEntry, m_vEntries) { - strText = spEntry->GetPath(); + strText = spEntry->GetPath().ToString(); strText.MakeLower(); iOffset = strText.Find(strOld, 0); if(iOffset != -1) { // found - strText = spEntry->GetPath(); + strText = spEntry->GetPath().ToString(); strText = strText.Left(iOffset) + strNew + strText.Mid(iOffset + strOld.GetLength()); - spEntry->SetPath(strText); + spEntry->SetPath(chcore::PathFromString(strText)); ++iCount; } @@ -271,7 +270,7 @@ CFileInfo::CFileInfo() : m_pClipboard(NULL), - m_strFilePath(), + m_pathFile(), m_stSrcIndex(std::numeric_limits::max()), m_dwAttributes(0), m_uhFileSize(0), @@ -283,7 +282,7 @@ } CFileInfo::CFileInfo(const CFileInfo& finf) : - m_strFilePath(finf.m_strFilePath), + m_pathFile(finf.m_pathFile), m_stSrcIndex(finf.m_stSrcIndex), m_dwAttributes(finf.m_dwAttributes), m_uhFileSize(finf.m_uhFileSize), @@ -304,7 +303,7 @@ WIN32_FIND_DATA fd; // search by exact name - HANDLE hFind = FindFirstFile(pathToCheck, &fd); + HANDLE hFind = FindFirstFile(pathToCheck.ToString(), &fd); if(hFind != INVALID_HANDLE_VALUE) return true; @@ -313,7 +312,7 @@ pathToCheck.AppendIfNotExists(_T("\\"), false); pathToCheck.AppendIfNotExists(_T("*"), false); - hFind = FindFirstFile(pathToCheck, &fd); + hFind = FindFirstFile(pathToCheck.ToString(), &fd); if(hFind != INVALID_HANDLE_VALUE) { ::FindClose(hFind); @@ -323,18 +322,18 @@ return false; } -void CFileInfo::Create(const WIN32_FIND_DATA* pwfd, LPCTSTR pszFilePath, size_t stSrcIndex) +void CFileInfo::Create(const WIN32_FIND_DATA* pwfd, const chcore::TSmartPath& pathFile, size_t stSrcIndex) { BOOST_ASSERT(stSrcIndex == std::numeric_limits::max() || m_pClipboard); if(stSrcIndex != std::numeric_limits::max() && !m_pClipboard) THROW(_t("Internal error: pointer not initialized."), 0, 0, 0); // copy data from W32_F_D - m_strFilePath = CString(pszFilePath) + pwfd->cFileName; + m_pathFile = pathFile + chcore::PathFromString(pwfd->cFileName); // if proper index has been passed - reduce the path if(m_pClipboard && stSrcIndex >= 0) - m_strFilePath=m_strFilePath.Mid(m_pClipboard->GetAt(stSrcIndex)->GetPath().GetLength()); // cut path from clipboard + m_pathFile.MakeRelativePath(m_pClipboard->GetAt(stSrcIndex)->GetPath()); // cut path from clipboard m_stSrcIndex = stSrcIndex; m_dwAttributes = pwfd->dwFileAttributes; @@ -345,26 +344,24 @@ m_uiFlags = 0; } -bool CFileInfo::Create(CString strFilePath, size_t stSrcIndex) +bool CFileInfo::Create(const chcore::TSmartPath& pathFile, size_t stSrcIndex) { WIN32_FIND_DATA wfd; - HANDLE hFind; - int nBarPos; - - hFind = FindFirstFile(strFilePath, &wfd); + HANDLE hFind = FindFirstFile(pathFile.ToString(), &wfd); if (hFind != INVALID_HANDLE_VALUE) { FindClose(hFind); // add data to members - nBarPos = strFilePath.ReverseFind(TCHAR('\\')); - Create(&wfd, strFilePath.Left(nBarPos+1), stSrcIndex); + chcore::TSmartPath pathNew(pathFile); + pathNew.DeleteLastComponent(); + Create(&wfd, pathNew, stSrcIndex); return true; } else { - m_strFilePath.Empty(); + m_pathFile.Clear(); m_stSrcIndex = std::numeric_limits::max(); m_dwAttributes = (DWORD)-1; m_uhFileSize = (unsigned __int64)-1; @@ -376,16 +373,17 @@ } } -CString CFileInfo::GetFileDrive() const +chcore::TSmartPath CFileInfo::GetFileDrive() const { BOOST_ASSERT(m_pClipboard); if(!m_pClipboard) THROW(_T("Invalid pointer"), 0, 0, 0); - CString strPath=(m_stSrcIndex != std::numeric_limits::max()) ? m_pClipboard->GetAt(m_stSrcIndex)->GetPath() + m_strFilePath : m_strFilePath; + chcore::TSmartPath pathCombined = (m_stSrcIndex != std::numeric_limits::max()) ? m_pClipboard->GetAt(m_stSrcIndex)->GetPath() + m_pathFile : m_pathFile; + TCHAR szDrive[_MAX_DRIVE]; - _tsplitpath(strPath, szDrive, NULL, NULL, NULL); - return CString(szDrive); + _tsplitpath(pathCombined.ToString(), szDrive, NULL, NULL, NULL); + return chcore::PathFromString(szDrive); } int CFileInfo::GetDriveNumber() @@ -403,82 +401,83 @@ { // manually int iNum = 0; - GetDriveData(m_strFilePath, &iNum, NULL); + GetDriveData(m_pathFile, &iNum, NULL); return iNum; } } -CString CFileInfo::GetFileDir() const +chcore::TSmartPath CFileInfo::GetFileDir() const { BOOST_ASSERT(m_pClipboard); if(!m_pClipboard) THROW(_T("Invalid pointer"), 0, 0, 0); - CString strPath=(m_stSrcIndex != std::numeric_limits::max()) ? m_pClipboard->GetAt(m_stSrcIndex)->GetPath()+m_strFilePath : m_strFilePath; + chcore::TSmartPath pathCombined = (m_stSrcIndex != std::numeric_limits::max()) ? m_pClipboard->GetAt(m_stSrcIndex)->GetPath() + m_pathFile : m_pathFile; + TCHAR szDir[_MAX_DIR]; - _tsplitpath(strPath, NULL, szDir, NULL, NULL); - return CString(szDir); + _tsplitpath(pathCombined.ToString(), NULL, szDir, NULL, NULL); + return chcore::PathFromString(szDir); } -CString CFileInfo::GetFileTitle() const +chcore::TSmartPath CFileInfo::GetFileTitle() const { BOOST_ASSERT(m_pClipboard); if(!m_pClipboard) THROW(_T("Invalid pointer"), 0, 0, 0); - CString strPath=(m_stSrcIndex != std::numeric_limits::max()) ? m_pClipboard->GetAt(m_stSrcIndex)->GetPath()+m_strFilePath : m_strFilePath; + chcore::TSmartPath pathCombined = (m_stSrcIndex != std::numeric_limits::max()) ? m_pClipboard->GetAt(m_stSrcIndex)->GetPath()+m_pathFile : m_pathFile; TCHAR szName[_MAX_FNAME]; - _tsplitpath(strPath, NULL, NULL, szName, NULL); - return CString(szName); + _tsplitpath(pathCombined.ToString(), NULL, NULL, szName, NULL); + return chcore::PathFromString(szName); } -CString CFileInfo::GetFileExt() const +chcore::TSmartPath CFileInfo::GetFileExt() const { ASSERT(m_pClipboard); BOOST_ASSERT(m_pClipboard); if(!m_pClipboard) THROW(_T("Invalid pointer"), 0, 0, 0); - CString strPath=(m_stSrcIndex != std::numeric_limits::max()) ? m_pClipboard->GetAt(m_stSrcIndex)->GetPath()+m_strFilePath : m_strFilePath; + chcore::TSmartPath pathCombined = (m_stSrcIndex != std::numeric_limits::max()) ? m_pClipboard->GetAt(m_stSrcIndex)->GetPath()+m_pathFile : m_pathFile; TCHAR szExt[_MAX_EXT]; - _tsplitpath(strPath, NULL, NULL, NULL, szExt); - return CString(szExt); + _tsplitpath(pathCombined.ToString(), NULL, NULL, NULL, szExt); + return chcore::PathFromString(szExt); } -CString CFileInfo::GetFileRoot() const +chcore::TSmartPath CFileInfo::GetFileRoot() const { ASSERT(m_pClipboard); BOOST_ASSERT(m_pClipboard); if(!m_pClipboard) THROW(_T("Invalid pointer"), 0, 0, 0); - CString strPath=(m_stSrcIndex != std::numeric_limits::max()) ? m_pClipboard->GetAt(m_stSrcIndex)->GetPath()+m_strFilePath : m_strFilePath; + chcore::TSmartPath pathCombined = (m_stSrcIndex != std::numeric_limits::max()) ? m_pClipboard->GetAt(m_stSrcIndex)->GetPath() + m_pathFile : m_pathFile; TCHAR szDrive[_MAX_DRIVE]; TCHAR szDir[_MAX_DIR]; - _tsplitpath(strPath, szDrive, szDir, NULL, NULL); - return CString(szDrive)+szDir; + _tsplitpath(pathCombined.ToString(), szDrive, szDir, NULL, NULL); + return chcore::PathFromString(szDrive) + chcore::PathFromString(szDir); } -CString CFileInfo::GetFileName() const +chcore::TSmartPath CFileInfo::GetFileName() const { BOOST_ASSERT(m_pClipboard); if(!m_pClipboard) THROW(_T("Invalid pointer"), 0, 0, 0); - CString strPath; + chcore::TSmartPath pathCombined; if(m_pClipboard && m_stSrcIndex != std::numeric_limits::max()) - strPath = m_pClipboard->GetAt(m_stSrcIndex)->GetPath() + m_strFilePath; + pathCombined = m_pClipboard->GetAt(m_stSrcIndex)->GetPath() + m_pathFile; else { ASSERT(m_stSrcIndex == std::numeric_limits::max()); - strPath = m_strFilePath; + pathCombined = m_pathFile; } TCHAR szName[_MAX_FNAME]; TCHAR szExt[_MAX_EXT]; - _tsplitpath(strPath, NULL, NULL, szName, szExt); - return CString(szName)+szExt; + _tsplitpath(pathCombined.ToString(), NULL, NULL, szName, szExt); + return chcore::PathFromString(szName) + chcore::PathFromString(szExt); } bool CFileInfo::operator==(const CFileInfo& rInfo) @@ -487,20 +486,20 @@ && rInfo.m_ftLastWrite.dwHighDateTime == m_ftLastWrite.dwHighDateTime && rInfo.m_ftLastWrite.dwLowDateTime == m_ftLastWrite.dwLowDateTime && rInfo.m_uhFileSize == m_uhFileSize); } -CString CFileInfo::GetFullFilePath() const +chcore::TSmartPath CFileInfo::GetFullFilePath() const { - CString strPath; if(m_stSrcIndex != std::numeric_limits::max()) { BOOST_ASSERT(m_pClipboard); if(!m_pClipboard) THROW(_T("Invalid pointer"), 0, 0, 0); - strPath += m_pClipboard->GetAt(m_stSrcIndex)->GetPath(); + chcore::TSmartPath pathCombined = m_pClipboard->GetAt(m_stSrcIndex)->GetPath(); + pathCombined += m_pathFile; + return pathCombined; } - strPath += m_strFilePath; - - return strPath; + else + return m_pathFile; } int CFileInfo::GetBufferIndex(const chcore::TSmartPath& dpDestPath) const Index: src/ch/FileInfo.h =================================================================== diff -u -N -rb42450e5a25470c399e04cfbb7a368519aa455f2 -r69b48f0b4d7fad78f95854e95fca166014311474 --- src/ch/FileInfo.h (.../FileInfo.h) (revision b42450e5a25470c399e04cfbb7a368519aa455f2) +++ src/ch/FileInfo.h (.../FileInfo.h) (revision 69b48f0b4d7fad78f95854e95fca166014311474) @@ -24,7 +24,7 @@ #include "../libchcore/TPath.h" -void GetDriveData(LPCTSTR lpszPath, int *piDrvNum, UINT *puiDrvType); +void GetDriveData(const chcore::TSmartPath& spPath, int *piDrvNum, UINT *puiDrvType); // CFileInfo flags // flag stating that file has been processed (used to determine if file can be deleted at the end of copying) @@ -39,9 +39,9 @@ CClipboardEntry(); CClipboardEntry(const CClipboardEntry& rEntry); - void SetPath(const CString& strPath); - const CString& GetPath() const { return m_strPath; } - CString GetFileName() const; + void SetPath(const chcore::TSmartPath& strPath); + chcore::TSmartPath GetPath() const { return m_path; } + chcore::TSmartPath GetFileName() const; void SetMove(bool bValue) { m_bMove=bValue; } bool GetMove() const { return m_bMove; } @@ -55,26 +55,26 @@ { if(bData) { - ar & m_strPath; + ar & m_path; ar & m_bMove; } else - ar & m_strDstPath; + ar & m_pathDst; } - void SetDestinationPath(const CString& strPath); - CString GetDestinationPath() const; - bool IsDestinationPathSet() const { return !m_strDstPath.IsEmpty(); } + void SetDestinationPath(const chcore::TSmartPath& strPath); + chcore::TSmartPath GetDestinationPath() const; + bool IsDestinationPathSet() const { return !m_pathDst.IsEmpty(); } private: - CString m_strPath; // path (ie. c:\\windows\\) - always with ending '\\' + chcore::TSmartPath m_path; // path (ie. c:\\windows\\) - always with ending '\\' bool m_bMove; // specifies if we can use MoveFile (if will be moved) int m_iDriveNumber; // disk number (-1 - none) int m_iBufferIndex; // buffer number, with which we'll copy this data - CString m_strDstPath; // dest path + chcore::TSmartPath m_pathDst; // dest path }; typedef boost::shared_ptr CClipboardEntryPtr; @@ -161,25 +161,25 @@ // static member static bool Exist(chcore::TSmartPath strPath); // check for file or folder existence - void Create(const WIN32_FIND_DATA* pwfd, LPCTSTR pszFilePath, size_t stSrcIndex); - bool Create(CString strFilePath, size_t stSrcIndex); + void Create(const WIN32_FIND_DATA* pwfd, const chcore::TSmartPath& tFilePath, size_t stSrcIndex); + bool Create(const chcore::TSmartPath& strFilePath, size_t stSrcIndex); ULONGLONG GetLength64() const { return m_uhFileSize; } void SetLength64(ULONGLONG uhSize) { m_uhFileSize=uhSize; } // disk - path and disk number (-1 if none - ie. net disk) - CString GetFileDrive() const; // returns string with src disk + chcore::TSmartPath GetFileDrive() const; // returns string with src disk int GetDriveNumber(); // disk number A - 0, b-1, c-2, ... - CString GetFileDir() const; // @rdesc Returns \WINDOWS\ for C:\WINDOWS\WIN.INI - CString GetFileTitle() const; // @cmember returns WIN for C:\WINDOWS\WIN.INI - CString GetFileExt() const; /** @cmember returns INI for C:\WINDOWS\WIN.INI */ - CString GetFileRoot() const; /** @cmember returns C:\WINDOWS\ for C:\WINDOWS\WIN.INI */ - CString GetFileName() const; /** @cmember returns WIN.INI for C:\WINDOWS\WIN.INI */ + chcore::TSmartPath GetFileDir() const; // @rdesc Returns \WINDOWS\ for C:\WINDOWS\WIN.INI + chcore::TSmartPath GetFileTitle() const; // @cmember returns WIN for C:\WINDOWS\WIN.INI + chcore::TSmartPath GetFileExt() const; /** @cmember returns INI for C:\WINDOWS\WIN.INI */ + chcore::TSmartPath GetFileRoot() const; /** @cmember returns C:\WINDOWS\ for C:\WINDOWS\WIN.INI */ + chcore::TSmartPath GetFileName() const; /** @cmember returns WIN.INI for C:\WINDOWS\WIN.INI */ - const CString& GetFilePath() const { return m_strFilePath; } // returns path with m_strFilePath (probably not full) - CString GetFullFilePath() const; /** @cmember returns C:\WINDOWS\WIN.INI for C:\WINDOWS\WIN.INI */ - void SetFilePath(LPCTSTR lpszPath) { m_strFilePath=lpszPath; }; + const chcore::TSmartPath& GetFilePath() const { return m_pathFile; } // returns path with m_pathFile (probably not full) + chcore::TSmartPath GetFullFilePath() const; /** @cmember returns C:\WINDOWS\WIN.INI for C:\WINDOWS\WIN.INI */ + void SetFilePath(const chcore::TSmartPath& tPath) { m_pathFile = tPath; }; /* Get File times info (equivalent to CFindFile members) */ const FILETIME& GetCreationTime() const { return m_ftCreation; }; @@ -216,7 +216,7 @@ template void serialize(Archive& ar, unsigned int /*uiVersion*/) { - ar & m_strFilePath; + ar & m_pathFile; ar & m_stSrcIndex; ar & m_dwAttributes; ar & m_uhFileSize; @@ -230,7 +230,7 @@ } private: - CString m_strFilePath; // contains relative path (first path is in CClipboardArray) + chcore::TSmartPath m_pathFile; // contains relative path (first path is in CClipboardArray) size_t m_stSrcIndex; // index in CClipboardArray table (which contains the first part of the path) DWORD m_dwAttributes; // attributes Index: src/ch/MainWnd.cpp =================================================================== diff -u -N -rb42450e5a25470c399e04cfbb7a368519aa455f2 -r69b48f0b4d7fad78f95854e95fca166014311474 --- src/ch/MainWnd.cpp (.../MainWnd.cpp) (revision b42450e5a25470c399e04cfbb7a368519aa455f2) +++ src/ch/MainWnd.cpp (.../MainWnd.cpp) (revision 69b48f0b4d7fad78f95854e95fca166014311474) @@ -497,12 +497,12 @@ // create new task TTaskDefinition tTaskDefinition; - tTaskDefinition.SetDestinationPath((PCTSTR)strDstPath); + tTaskDefinition.SetDestinationPath(chcore::PathFromString(strDstPath)); // files for(int i = 0; i < astrFiles.GetSize(); i++) { - tTaskDefinition.AddSourcePath(astrFiles.GetAt(i)); + tTaskDefinition.AddSourcePath(chcore::PathFromString(astrFiles.GetAt(i))); } tTaskDefinition.SetOperationType(bMove ? eOperation_Move : eOperation_Copy); @@ -590,10 +590,10 @@ for (int iIndex = 0; iIndex < dlg.m_ccData.m_astrPaths.GetSize(); iIndex++) { - tTaskDefinition.AddSourcePath(dlg.m_ccData.m_astrPaths.GetAt(iIndex)); + tTaskDefinition.AddSourcePath(chcore::PathFromString(dlg.m_ccData.m_astrPaths.GetAt(iIndex))); } - tTaskDefinition.SetDestinationPath((PCTSTR)dlg.m_ccData.m_strDestPath); + tTaskDefinition.SetDestinationPath(chcore::PathFromString(dlg.m_ccData.m_strDestPath)); tTaskDefinition.SetOperationType((dlg.m_ccData.m_iOperation == 1) ? eOperation_Move : eOperation_Copy); Index: src/ch/StatusDlg.cpp =================================================================== diff -u -N -r3f72015a9db19bd1b0a5e20e0f1aa0ec00bda529 -r69b48f0b4d7fad78f95854e95fca166014311474 --- src/ch/StatusDlg.cpp (.../StatusDlg.cpp) (revision 3f72015a9db19bd1b0a5e20e0f1aa0ec00bda529) +++ src/ch/StatusDlg.cpp (.../StatusDlg.cpp) (revision 69b48f0b4d7fad78f95854e95fca166014311474) @@ -258,7 +258,7 @@ // insert 'file' subitem lvi.iSubItem=2; - strTemp = (CString)td.m_pathDstPath; + strTemp = td.m_pathDstPath.ToString(); lvi.pszText=strTemp.GetBuffer(0); strTemp.ReleaseBuffer(); lvi.cchTextMax=lstrlen(lvi.pszText); @@ -325,7 +325,7 @@ // refresh only when there are new selected item // if (spTask != m_spLastSelected) { - GetDlgItem(IDC_DESTINATION_STATIC)->SetWindowText(td.m_pathDstPath); + GetDlgItem(IDC_DESTINATION_STATIC)->SetWindowText(td.m_pathDstPath.ToString()); GetDlgItem(IDC_PRIORITY_STATIC)->SetWindowText(GetResManager().LoadString(IDS_PRIORITY0_STRING+PriorityToIndex(td.m_nPriority))); GetDlgItem(IDC_ASSOCIATEDFILES__STATIC)->SetWindowText(td.m_strUniqueName); } Index: src/ch/TConfig.cpp =================================================================== diff -u -N -r3f72015a9db19bd1b0a5e20e0f1aa0ec00bda529 -r69b48f0b4d7fad78f95854e95fca166014311474 --- src/ch/TConfig.cpp (.../TConfig.cpp) (revision 3f72015a9db19bd1b0a5e20e0f1aa0ec00bda529) +++ src/ch/TConfig.cpp (.../TConfig.cpp) (revision 69b48f0b4d7fad78f95854e95fca166014311474) @@ -363,22 +363,22 @@ chcore::TSmartPath TConfig::GetPath(PCTSTR pszPropName, const chcore::TSmartPath& pathDefault) const { boost::shared_lock lock(m_lock); - std::wstring wstrData = m_propTree.get(pszPropName, std::wstring(pathDefault)); - return chcore::TSmartPath(wstrData); + std::wstring wstrData = m_propTree.get(pszPropName, pathDefault.ToWString()); + return chcore::PathFromString(wstrData); } bool TConfig::GetValue(PCTSTR pszPropName, chcore::TSmartPath& rpathValue) const { std::wstring wstrData; bool bResult = ::GetValue(m_propTree, pszPropName, wstrData, m_lock); - rpathValue = wstrData.c_str(); + rpathValue.FromString(wstrData); return bResult; } TConfig& TConfig::SetValue(PCTSTR pszPropName, const chcore::TSmartPath& pathValue) { - std::wstring wstrData = pathValue; + std::wstring wstrData(pathValue.ToWString()); if(::SetValue(m_propTree, m_bModified, m_lock, pszPropName, wstrData)) SendNotification(pszPropName); @@ -421,6 +421,42 @@ SendNotification(pszPropName); } +bool TConfig::GetValue(PCTSTR pszPropName, chcore::TPathContainer& rvValues) const +{ + rvValues.Clear(); + boost::shared_lock lock(m_lock); + + boost::optional children = m_propTree.get_child_optional(pszPropName); + if(children.is_initialized()) + { + BOOST_FOREACH(const boost::property_tree::wiptree::value_type& rEntry, children.get()) + { + rvValues.Add(chcore::PathFromString(rEntry.second.data())); + } + + return true; + } + else + return false; +} + +void TConfig::SetValue(PCTSTR pszPropName, const chcore::TPathContainer& rvValues) +{ + // separate scope for mutex (to avoid calling notifier inside critical section) + { + boost::unique_lock lock(m_lock); + m_propTree.erase(pszPropName); + for(size_t stIndex = 0; stIndex < rvValues.GetCount(); ++stIndex) + { + m_propTree.add(pszPropName, rvValues.GetAt(stIndex).ToWString()); + } + + m_bModified = true; + } + + SendNotification(pszPropName); +} + // extraction of subtrees void TConfig::ExtractSubConfig(PCTSTR pszSubTreeName, TConfig& rSubConfig) const { Index: src/ch/TConfig.h =================================================================== diff -u -N -r3f72015a9db19bd1b0a5e20e0f1aa0ec00bda529 -r69b48f0b4d7fad78f95854e95fca166014311474 --- src/ch/TConfig.h (.../TConfig.h) (revision 3f72015a9db19bd1b0a5e20e0f1aa0ec00bda529) +++ src/ch/TConfig.h (.../TConfig.h) (revision 69b48f0b4d7fad78f95854e95fca166014311474) @@ -108,6 +108,9 @@ bool GetValue(PCTSTR pszPropName, std::vector& rvValues) const; void SetValue(PCTSTR pszPropName, const std::vector& rvValues); + bool GetValue(PCTSTR pszPropName, chcore::TPathContainer& rvValues) const; + void SetValue(PCTSTR pszPropName, const chcore::TPathContainer& rvValues); + // extraction of subtrees void ExtractSubConfig(PCTSTR pszSubTreeName, TConfig& rSubConfig) const; void PutSubConfig(PCTSTR pszSubTreeName, const TConfig& rSubConfig); Index: src/ch/TTaskDefinition.cpp =================================================================== diff -u -N -r3f72015a9db19bd1b0a5e20e0f1aa0ec00bda529 -r69b48f0b4d7fad78f95854e95fca166014311474 --- src/ch/TTaskDefinition.cpp (.../TTaskDefinition.cpp) (revision 3f72015a9db19bd1b0a5e20e0f1aa0ec00bda529) +++ src/ch/TTaskDefinition.cpp (.../TTaskDefinition.cpp) (revision 69b48f0b4d7fad78f95854e95fca166014311474) @@ -73,29 +73,29 @@ // Source paths // initialize object with data (get/set, from cfg file?, from string(cmd line options)) -void TTaskDefinition::AddSourcePath(const CString& strPath) +void TTaskDefinition::AddSourcePath(const chcore::TSmartPath& tPath) { - m_vSourcePaths.push_back(strPath); + m_vSourcePaths.Add(tPath); m_bModified = true; } -CString TTaskDefinition::GetSourcePathAt(size_t stIndex) const +chcore::TSmartPath TTaskDefinition::GetSourcePathAt(size_t stIndex) const { - return m_vSourcePaths.at(stIndex); + return m_vSourcePaths.GetAt(stIndex); } size_t TTaskDefinition::GetSourcePathCount() const { - return m_vSourcePaths.size(); + return m_vSourcePaths.GetCount(); } void TTaskDefinition::ClearSourcePaths() { - m_vSourcePaths.clear(); + m_vSourcePaths.Clear(); m_bModified = true; } -const std::vector& TTaskDefinition::GetSourcePaths() const +const chcore::TPathContainer& TTaskDefinition::GetSourcePaths() const { return m_vSourcePaths; } @@ -156,7 +156,7 @@ // clear everything m_strTaskUniqueID.Empty(); - m_vSourcePaths.clear(); + m_vSourcePaths.Clear(); m_pathDestinationPath.Clear(); m_tConfiguration.Clear(); @@ -175,7 +175,7 @@ } // basic information - if(!tTaskInfo.GetValue(_T("TaskDefinition.SourcePaths"), m_vSourcePaths) || m_vSourcePaths.empty()) + if(!tTaskInfo.GetValue(_T("TaskDefinition.SourcePaths"), m_vSourcePaths) || m_vSourcePaths.IsEmpty()) THROW(_T("Missing source paths"), 0, 0, 0); if(!tTaskInfo.GetValue(_T("TaskDefinition.DestinationPath"), m_pathDestinationPath) || m_pathDestinationPath.IsEmpty()) Index: src/ch/TTaskDefinition.h =================================================================== diff -u -N -r3f72015a9db19bd1b0a5e20e0f1aa0ec00bda529 -r69b48f0b4d7fad78f95854e95fca166014311474 --- src/ch/TTaskDefinition.h (.../TTaskDefinition.h) (revision 3f72015a9db19bd1b0a5e20e0f1aa0ec00bda529) +++ src/ch/TTaskDefinition.h (.../TTaskDefinition.h) (revision 69b48f0b4d7fad78f95854e95fca166014311474) @@ -43,10 +43,10 @@ CString GetTaskUniqueID() const; // Source paths - void AddSourcePath(const CString& strPath); - CString GetSourcePathAt(size_t stIndex) const; + void AddSourcePath(const chcore::TSmartPath& tPath); + chcore::TSmartPath GetSourcePathAt(size_t stIndex) const; size_t GetSourcePathCount() const; - const std::vector& GetSourcePaths() const; + const chcore::TPathContainer& GetSourcePaths() const; void ClearSourcePaths(); @@ -72,7 +72,7 @@ CString m_strTaskUniqueID; ///< Unique ID of the task that will process this request (generated automatically) // basic information - std::vector m_vSourcePaths; + chcore::TPathContainer m_vSourcePaths; chcore::TSmartPath m_pathDestinationPath; TOperationPlan m_tOperationPlan; ///< Describes the operation along with sub-operations to be performed on the task input data Index: src/ch/task.cpp =================================================================== diff -u -N -rb42450e5a25470c399e04cfbb7a368519aa455f2 -r69b48f0b4d7fad78f95854e95fca166014311474 --- src/ch/task.cpp (.../task.cpp) (revision b42450e5a25470c399e04cfbb7a368519aa455f2) +++ src/ch/task.cpp (.../task.cpp) (revision 69b48f0b4d7fad78f95854e95fca166014311474) @@ -443,10 +443,10 @@ m_arrSourcePaths.RemoveAll(); m_files.Clear(); - BOOST_FOREACH(const CString& strPath, m_tTaskDefinition.GetSourcePaths()) + for(size_t stIndex = 0; stIndex < m_tTaskDefinition.GetSourcePaths().GetCount(); ++stIndex) { CClipboardEntryPtr spEntry(new CClipboardEntry); - spEntry->SetPath(strPath); + spEntry->SetPath(m_tTaskDefinition.GetSourcePaths().GetAt(stIndex)); m_arrSourcePaths.Add(spEntry); } @@ -463,19 +463,18 @@ } // m_files -int CTask::ScanDirectory(CString strDirName, size_t stSrcIndex, bool bRecurse, bool bIncludeDirs) +int CTask::ScanDirectory(chcore::TSmartPath pathDirName, size_t stSrcIndex, bool bRecurse, bool bIncludeDirs) { WIN32_FIND_DATA wfd; - CString strText; + chcore::TSmartPath pathCurrent; // append '\\' at the end of path if needed - if(strDirName.Right(1) != _T("\\")) - strDirName += _T("\\"); + pathDirName.AppendIfNotExists(_T("\\"), false); - strText = strDirName + _T("*"); + pathCurrent = pathDirName + chcore::PathFromString(_T("*")); // Iterate through dirs & files - HANDLE hFind = FindFirstFile(strText, &wfd); + HANDLE hFind = FindFirstFile(pathCurrent.ToString(), &wfd); if(hFind != INVALID_HANDLE_VALUE) { do @@ -485,7 +484,7 @@ CFileInfoPtr spFileInfo(boost::make_shared()); spFileInfo->SetClipboard(&m_arrSourcePaths); // this is the link table (CClipboardArray) - spFileInfo->Create(&wfd, strDirName, stSrcIndex); + spFileInfo->Create(&wfd, pathDirName, stSrcIndex); if(m_afFilters.Match(spFileInfo)) m_files.AddFileInfo(spFileInfo); } @@ -497,14 +496,14 @@ spFileInfo->SetClipboard(&m_arrSourcePaths); // this is the link table (CClipboardArray) // Add directory itself - spFileInfo->Create(&wfd, strDirName, stSrcIndex); + spFileInfo->Create(&wfd, pathDirName, stSrcIndex); m_files.AddFileInfo(spFileInfo); } if(bRecurse) { - strText = strDirName + wfd.cFileName + _T("\\"); + pathCurrent = pathDirName + chcore::PathFromString(wfd.cFileName) + chcore::PathFromString(_T("\\")); // Recurse Dirs - ScanDirectory(strText, stSrcIndex, bRecurse, bIncludeDirs); + ScanDirectory(pathCurrent, stSrcIndex, bRecurse, bIncludeDirs); } } @@ -781,15 +780,15 @@ size_t stCurrentIndex = m_tTaskBasicProgressInfo.GetCurrentIndex(); if(stCurrentIndex < m_files.GetSize()) - pData->m_strPath = m_files.GetAt(stCurrentIndex)->GetFileName(); + pData->m_strPath = m_files.GetAt(stCurrentIndex)->GetFileName().ToString(); else { if(m_files.GetSize() > 0) - pData->m_strPath = m_files.GetAt(0)->GetFileName(); + pData->m_strPath = m_files.GetAt(0)->GetFileName().ToString(); else { if(m_tTaskDefinition.GetSourcePathCount() > 0) - pData->m_strPath = m_arrSourcePaths.GetAt(0)->GetFileName(); + pData->m_strPath = m_arrSourcePaths.GetAt(0)->GetFileName().ToString(); else pData->m_strPath.Empty(); } @@ -808,22 +807,22 @@ size_t stCurrentIndex = m_tTaskBasicProgressInfo.GetCurrentIndex(); if(stCurrentIndex < m_files.GetSize()) { - pData->m_strFullFilePath = m_files.GetAt(stCurrentIndex)->GetFullFilePath(); - pData->m_strFileName = m_files.GetAt(stCurrentIndex)->GetFileName(); + pData->m_strFullFilePath = m_files.GetAt(stCurrentIndex)->GetFullFilePath().ToString(); + pData->m_strFileName = m_files.GetAt(stCurrentIndex)->GetFileName().ToString(); } else { if(m_files.GetSize() > 0) { - pData->m_strFullFilePath = m_files.GetAt(0)->GetFullFilePath(); - pData->m_strFileName = m_files.GetAt(0)->GetFileName(); + pData->m_strFullFilePath = m_files.GetAt(0)->GetFullFilePath().ToString(); + pData->m_strFileName = m_files.GetAt(0)->GetFileName().ToString(); } else { if(m_tTaskDefinition.GetSourcePathCount() > 0) { - pData->m_strFullFilePath = m_arrSourcePaths.GetAt(0)->GetPath(); - pData->m_strFileName = m_arrSourcePaths.GetAt(0)->GetFileName(); + pData->m_strFullFilePath = m_arrSourcePaths.GetAt(0)->GetPath().ToString(); + pData->m_strFileName = m_arrSourcePaths.GetAt(0)->GetFileName().ToString(); } else { @@ -940,7 +939,7 @@ // but GetDiskFreeSpace returns false values // get free space - if(!GetDynamicFreeSpace(m_tTaskDefinition.GetDestinationPath(), pullAvailable, NULL)) + if(!GetDynamicFreeSpace(m_tTaskDefinition.GetDestinationPath().ToString(), pullAvailable, NULL)) return true; return (*pullNeeded <= *pullAvailable); @@ -1083,7 +1082,7 @@ bool bExists = spFileInfo->Create(m_arrSourcePaths.GetAt(stIndex)->GetPath(), stIndex); if(!bExists) { - CString strSrcFile = m_arrSourcePaths.GetAt(stIndex)->GetPath(); + CString strSrcFile = m_arrSourcePaths.GetAt(stIndex)->GetPath().ToString(); FEEDBACK_FILEERROR ferr = { (PCTSTR)strSrcFile, NULL, eFastMoveError, ERROR_FILE_NOT_FOUND }; CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)m_piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &ferr); switch(frResult) @@ -1118,18 +1117,17 @@ // log fmt.SetFormat(_T("Adding file/folder (clipboard) : %path ...")); - fmt.SetParam(_t("%path"), m_arrSourcePaths.GetAt(stIndex)->GetPath()); + fmt.SetParam(_t("%path"), m_arrSourcePaths.GetAt(stIndex)->GetPath().ToString()); m_log.logi(fmt); // found file/folder - check if the dest name has been generated if(!m_arrSourcePaths.GetAt(stIndex)->IsDestinationPathSet()) { // generate something - if dest folder == src folder - search for copy - if((CString)m_tTaskDefinition.GetDestinationPath() == spFileInfo->GetFileRoot()) + if(m_tTaskDefinition.GetDestinationPath() == spFileInfo->GetFileRoot()) { - CString strSubst; - FindFreeSubstituteName(chcore::TSmartPath((PCTSTR)spFileInfo->GetFullFilePath()), m_tTaskDefinition.GetDestinationPath(), &strSubst); - m_arrSourcePaths.GetAt(stIndex)->SetDestinationPath(strSubst); + chcore::TSmartPath pathSubst = FindFreeSubstituteName(spFileInfo->GetFullFilePath(), m_tTaskDefinition.GetDestinationPath()); + m_arrSourcePaths.GetAt(stIndex)->SetDestinationPath(pathSubst); } else m_arrSourcePaths.GetAt(stIndex)->SetDestinationPath(spFileInfo->GetFileName()); @@ -1146,7 +1144,7 @@ // log fmt.SetFormat(_T("Added folder %path")); - fmt.SetParam(_t("%path"), spFileInfo->GetFullFilePath()); + fmt.SetParam(_t("%path"), spFileInfo->GetFullFilePath().ToString()); m_log.logi(fmt); } @@ -1156,7 +1154,7 @@ { // log fmt.SetFormat(_T("Recursing folder %path")); - fmt.SetParam(_t("%path"), spFileInfo->GetFullFilePath()); + fmt.SetParam(_t("%path"), spFileInfo->GetFullFilePath().ToString()); m_log.logi(fmt); // no movefile possibility - use CustomCopyFileFB @@ -1192,7 +1190,7 @@ // log fmt.SetFormat(_T("Added file %path")); - fmt.SetParam(_t("%path"), spFileInfo->GetFullFilePath()); + fmt.SetParam(_t("%path"), spFileInfo->GetFullFilePath().ToString()); m_log.logi(fmt); } } @@ -1247,15 +1245,15 @@ if(spFileInfo->IsDirectory()) { if(!GetTaskPropValue(m_tTaskDefinition.GetConfiguration())) - SetFileAttributes(spFileInfo->GetFullFilePath(), FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY); - bSuccess=RemoveDirectory(spFileInfo->GetFullFilePath()); + SetFileAttributes(spFileInfo->GetFullFilePath().ToString(), FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_DIRECTORY); + bSuccess=RemoveDirectory(spFileInfo->GetFullFilePath().ToString()); } else { // set files attributes to normal - it'd slow processing a bit, but it's better. if(!GetTaskPropValue(m_tTaskDefinition.GetConfiguration())) - SetFileAttributes(spFileInfo->GetFullFilePath(), FILE_ATTRIBUTE_NORMAL); - bSuccess=DeleteFile(spFileInfo->GetFullFilePath()); + SetFileAttributes(spFileInfo->GetFullFilePath().ToString(), FILE_ATTRIBUTE_NORMAL); + bSuccess=DeleteFile(spFileInfo->GetFullFilePath().ToString()); } // operation failed @@ -1265,10 +1263,10 @@ // log fmt.SetFormat(_T("Error #%errno while deleting file/folder %path")); fmt.SetParam(_t("%errno"), dwLastError); - fmt.SetParam(_t("%path"), spFileInfo->GetFullFilePath()); + fmt.SetParam(_t("%path"), spFileInfo->GetFullFilePath().ToString()); m_log.loge(fmt); - CString strFile = spFileInfo->GetFullFilePath(); + CString strFile = spFileInfo->GetFullFilePath().ToString(); FEEDBACK_FILEERROR ferr = { (PCTSTR)strFile, NULL, eDeleteError, dwLastError }; CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)m_piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &ferr); switch(frResult) @@ -1314,7 +1312,7 @@ THROW(_T("Invalid argument"), 0, 0, 0); bool bRetry = false; - CString strPath = spSrcFileInfo->GetFullFilePath(); + CString strPath = spSrcFileInfo->GetFullFilePath().ToString(); hOutFile = INVALID_HANDLE_VALUE; @@ -1377,7 +1375,7 @@ return eSubResult_Continue; } -CTask::ESubOperationResult CTask::OpenDestinationFileFB(TAutoFileHandle& hOutFile, const CString& strDstFilePath, bool bNoBuffering, const CFileInfoPtr& spSrcFileInfo, unsigned long long& ullSeekTo, bool& bFreshlyCreated) +CTask::ESubOperationResult CTask::OpenDestinationFileFB(TAutoFileHandle& hOutFile, const chcore::TSmartPath& pathDstFile, bool bNoBuffering, const CFileInfoPtr& spSrcFileInfo, unsigned long long& ullSeekTo, bool& bFreshlyCreated) { bool bRetry = false; TAutoFileHandle hFile; @@ -1390,7 +1388,7 @@ { bRetry = false; - hFile = CreateFile(strDstFilePath, 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); + 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(); @@ -1399,7 +1397,7 @@ bFreshlyCreated = false; // pass it to the specialized method - CTask::ESubOperationResult eResult = OpenExistingDestinationFileFB(hFile, strDstFilePath, bNoBuffering); + CTask::ESubOperationResult eResult = OpenExistingDestinationFileFB(hFile, pathDstFile, bNoBuffering); if(eResult != eSubResult_Continue) return eResult; else if(hFile == INVALID_HANDLE_VALUE) @@ -1410,7 +1408,7 @@ // 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(strDstFilePath, std::numeric_limits::max())) + 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 @@ -1435,7 +1433,7 @@ // log ictranslate::CFormat fmt; fmt.SetFormat(_T("Cancel request while checking result of dialog before opening source file %path (CustomCopyFileFB)")); - fmt.SetParam(_t("%path"), strDstFilePath); + fmt.SetParam(_t("%path"), pathDstFile.ToString()); m_log.logi(fmt); return eSubResult_CancelRequest; @@ -1450,7 +1448,7 @@ } else { - FEEDBACK_FILEERROR feedStruct = { (PCTSTR)strDstFilePath, NULL, eCreateError, dwLastError }; + FEEDBACK_FILEERROR feedStruct = { pathDstFile.ToString(), NULL, eCreateError, dwLastError }; CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)m_piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &feedStruct); switch (frResult) { @@ -1460,7 +1458,7 @@ ictranslate::CFormat fmt; fmt.SetFormat(_T("Retrying [error %errno] to open destination file %path (CustomCopyFileFB)")); fmt.SetParam(_t("%errno"), dwLastError); - fmt.SetParam(_t("%path"), strDstFilePath); + fmt.SetParam(_t("%path"), pathDstFile.ToString()); m_log.loge(fmt); bRetry = true; @@ -1474,7 +1472,7 @@ fmt.SetFormat(_T("Cancel request [error %errno] while opening destination file %path (CustomCopyFileFB)")); fmt.SetParam(_t("%errno"), dwLastError); - fmt.SetParam(_t("%path"), strDstFilePath); + fmt.SetParam(_t("%path"), pathDstFile.ToString()); m_log.loge(fmt); return eSubResult_CancelRequest; @@ -1500,7 +1498,7 @@ return eSubResult_Continue; } -CTask::ESubOperationResult CTask::OpenExistingDestinationFileFB(TAutoFileHandle& hOutFile, const CString& strDstFilePath, bool bNoBuffering) +CTask::ESubOperationResult CTask::OpenExistingDestinationFileFB(TAutoFileHandle& hOutFile, const chcore::TSmartPath& pathDstFile, bool bNoBuffering) { bool bRetry = false; TAutoFileHandle hFile; @@ -1511,11 +1509,11 @@ { bRetry = false; - hFile = CreateFile(strDstFilePath, 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); + 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 = { (PCTSTR)strDstFilePath, NULL, eCreateError, dwLastError }; + FEEDBACK_FILEERROR feedStruct = { pathDstFile.ToString(), NULL, eCreateError, dwLastError }; CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)m_piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &feedStruct); switch (frResult) { @@ -1525,7 +1523,7 @@ ictranslate::CFormat fmt; fmt.SetFormat(_T("Retrying [error %errno] to open destination file %path (CustomCopyFileFB)")); fmt.SetParam(_t("%errno"), dwLastError); - fmt.SetParam(_t("%path"), strDstFilePath); + fmt.SetParam(_t("%path"), pathDstFile.ToString()); m_log.loge(fmt); bRetry = true; @@ -1539,7 +1537,7 @@ fmt.SetFormat(_T("Cancel request [error %errno] while opening destination file %path (CustomCopyFileFB)")); fmt.SetParam(_t("%errno"), dwLastError); - fmt.SetParam(_t("%path"), strDstFilePath); + fmt.SetParam(_t("%path"), pathDstFile.ToString()); m_log.loge(fmt); return eSubResult_CancelRequest; @@ -1564,7 +1562,7 @@ return eSubResult_Continue; } -CTask::ESubOperationResult CTask::SetFilePointerFB(HANDLE hFile, long long llDistance, const CString& strFilePath, bool& bSkip) +CTask::ESubOperationResult CTask::SetFilePointerFB(HANDLE hFile, long long llDistance, const chcore::TSmartPath& pathFile, bool& bSkip) { bSkip = false; bool bRetry = false; @@ -1581,11 +1579,11 @@ fmt.SetFormat(_T("Error %errno while moving file pointer of %path to %pos")); fmt.SetParam(_t("%errno"), dwLastError); - fmt.SetParam(_t("%path"), strFilePath); + fmt.SetParam(_t("%path"), pathFile.ToString()); fmt.SetParam(_t("%pos"), llDistance); m_log.loge(fmt); - FEEDBACK_FILEERROR ferr = { (PCTSTR)strFilePath, NULL, eSeekError, dwLastError }; + FEEDBACK_FILEERROR ferr = { pathFile.ToString(), NULL, eSeekError, dwLastError }; CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)m_piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &ferr); switch(frResult) { @@ -1614,7 +1612,7 @@ return eSubResult_Continue; } -CTask::ESubOperationResult CTask::SetEndOfFileFB(HANDLE hFile, const CString& strFilePath, bool& bSkip) +CTask::ESubOperationResult CTask::SetEndOfFileFB(HANDLE hFile, const chcore::TSmartPath& pathFile, bool& bSkip) { bSkip = false; @@ -1629,10 +1627,10 @@ 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"), strFilePath); + fmt.SetParam(_t("%path"), pathFile.ToString()); m_log.loge(fmt); - FEEDBACK_FILEERROR ferr = { (PCTSTR)strFilePath, NULL, eResizeError, dwLastError }; + FEEDBACK_FILEERROR ferr = { pathFile.ToString(), NULL, eResizeError, dwLastError }; CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)m_piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &ferr); switch(frResult) { @@ -1660,7 +1658,7 @@ return eSubResult_Continue; } -CTask::ESubOperationResult CTask::ReadFileFB(HANDLE hFile, CDataBuffer& rBuffer, DWORD dwToRead, DWORD& rdwBytesRead, const CString& strFilePath, bool& bSkip) +CTask::ESubOperationResult CTask::ReadFileFB(HANDLE hFile, CDataBuffer& rBuffer, DWORD dwToRead, DWORD& rdwBytesRead, const chcore::TSmartPath& pathFile, bool& bSkip) { bSkip = false; bool bRetry = false; @@ -1677,10 +1675,10 @@ 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"), strFilePath); + fmt.SetParam(_t("%path"), pathFile.ToString()); m_log.loge(fmt); - FEEDBACK_FILEERROR ferr = { (PCTSTR)strFilePath, NULL, eReadError, dwLastError }; + FEEDBACK_FILEERROR ferr = { pathFile.ToString(), NULL, eReadError, dwLastError }; CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)m_piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &ferr); switch(frResult) { @@ -1709,7 +1707,7 @@ return eSubResult_Continue; } -CTask::ESubOperationResult CTask::WriteFileFB(HANDLE hFile, CDataBuffer& rBuffer, DWORD dwToWrite, DWORD& rdwBytesWritten, const CString& strFilePath, bool& bSkip) +CTask::ESubOperationResult CTask::WriteFileFB(HANDLE hFile, CDataBuffer& rBuffer, DWORD dwToWrite, DWORD& rdwBytesWritten, const chcore::TSmartPath& pathFile, bool& bSkip) { bSkip = false; @@ -1727,10 +1725,10 @@ 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"), strFilePath); + fmt.SetParam(_t("%path"), pathFile.ToString()); m_log.loge(fmt); - FEEDBACK_FILEERROR ferr = { (PCTSTR)strFilePath, NULL, eWriteError, dwLastError }; + FEEDBACK_FILEERROR ferr = { pathFile.ToString(), NULL, eWriteError, dwLastError }; CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)m_piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &ferr); switch(frResult) { @@ -1790,7 +1788,7 @@ // NOTE: probably should be removed from here and report problems with read-only files // directly to the user (as feedback request) if(!GetTaskPropValue(m_tTaskDefinition.GetConfiguration())) - SetFileAttributes(pData->strDstFile, FILE_ATTRIBUTE_NORMAL); + 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; @@ -1800,7 +1798,7 @@ { // 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->strDstFile, bNoBuffer, pData->spSrcFile, ullSeekTo, bDstFileFreshlyCreated); + eResult = OpenDestinationFileFB(hDst, pData->pathDstFile, bNoBuffer, pData->spSrcFile, ullSeekTo, bDstFileFreshlyCreated); if(eResult != eSubResult_Continue) return eResult; else if(hDst == INVALID_HANDLE_VALUE) @@ -1813,7 +1811,7 @@ else { // we are resuming previous operation - eResult = OpenExistingDestinationFileFB(hDst, pData->strDstFile, bNoBuffer); + eResult = OpenExistingDestinationFileFB(hDst, pData->pathDstFile, bNoBuffer); if(eResult != eSubResult_Continue) return eResult; else if(hDst == INVALID_HANDLE_VALUE) @@ -1844,7 +1842,7 @@ return eSubResult_Continue; } - eResult = SetFilePointerFB(hDst, ullMove, pData->strDstFile, bSkip); + eResult = SetFilePointerFB(hDst, ullMove, pData->pathDstFile, bSkip); if(eResult != eSubResult_Continue) return eResult; else if(bSkip) @@ -1863,7 +1861,7 @@ if(!bDstFileFreshlyCreated) { // if destination file was opened (as opposed to newly created) - eResult = SetEndOfFileFB(hDst, pData->strDstFile, bSkip); + eResult = SetEndOfFileFB(hDst, pData->pathDstFile, bSkip); if(eResult != eSubResult_Continue) return eResult; else if(bSkip) @@ -1887,8 +1885,8 @@ { // log fmt.SetFormat(_T("Kill request while main copying file %srcpath -> %dstpath")); - fmt.SetParam(_t("%srcpath"), pData->spSrcFile->GetFullFilePath()); - fmt.SetParam(_t("%dstpath"), pData->strDstFile); + fmt.SetParam(_t("%srcpath"), pData->spSrcFile->GetFullFilePath().ToString()); + fmt.SetParam(_t("%dstpath"), pData->pathDstFile.ToString()); m_log.logi(fmt); return eSubResult_KillRequest; } @@ -1919,8 +1917,8 @@ 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()); - fmt.SetParam(_t("%dstfile"), pData->strDstFile); + fmt.SetParam(_t("%srcfile"), pData->spSrcFile->GetFullFilePath().ToString()); + fmt.SetParam(_t("%dstfile"), pData->pathDstFile.ToString()); m_log.logi(fmt); pData->dbBuffer.Create(&bs); @@ -1961,7 +1959,7 @@ unsigned long ulDataToWrite = ROUNDDOWN(ulRead, MAXSECTORSIZE); if(ulDataToWrite > 0) { - eResult = WriteFileFB(hDst, pData->dbBuffer, ulDataToWrite, ulWritten, pData->strDstFile, bSkip); + eResult = WriteFileFB(hDst, pData->dbBuffer, ulDataToWrite, ulWritten, pData->pathDstFile, bSkip); if(eResult != eSubResult_Continue) return eResult; else if(bSkip) @@ -1989,7 +1987,7 @@ 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->strDstFile, false); + eResult = OpenExistingDestinationFileFB(hDst, pData->pathDstFile, false); if(eResult != eSubResult_Continue) return eResult; else if(hDst == INVALID_HANDLE_VALUE) @@ -2000,7 +1998,7 @@ } // move file pointer to the end of destination file - eResult = SetFilePointerFB(hDst, m_tTaskBasicProgressInfo.GetCurrentFileProcessedSize(), pData->strDstFile, bSkip); + eResult = SetFilePointerFB(hDst, m_tTaskBasicProgressInfo.GetCurrentFileProcessedSize(), pData->pathDstFile, bSkip); if(eResult != eSubResult_Continue) return eResult; else if(bSkip) @@ -2016,7 +2014,7 @@ // write if(ulRead != 0) { - eResult = WriteFileFB(hDst, pData->dbBuffer, ulRead, ulWritten, pData->strDstFile, bSkip); + eResult = WriteFileFB(hDst, pData->dbBuffer, ulRead, ulWritten, pData->pathDstFile, bSkip); if(eResult != eSubResult_Continue) return eResult; else if(bSkip) @@ -2094,7 +2092,7 @@ fmt.SetParam(_t("%lansize"), pbs->m_uiLANSize); fmt.SetParam(_t("%filecount"), stSize); fmt.SetParam(_t("%ignorefolders"), bIgnoreFolders); - fmt.SetParam(_t("%dstpath"), (PCTSTR)m_tTaskDefinition.GetDestinationPath()); + fmt.SetParam(_t("%dstpath"), m_tTaskDefinition.GetDestinationPath().ToString()); fmt.SetParam(_t("%currindex"), m_tTaskBasicProgressInfo.GetCurrentIndex()); m_log.logi(fmt); @@ -2113,7 +2111,7 @@ CFileInfoPtr spFileInfo = m_files.GetAt(m_tTaskBasicProgressInfo.GetCurrentIndex()); // set dest path with filename - ccp.strDstFile = GetDestinationPath(spFileInfo, m_tTaskDefinition.GetDestinationPath(), ((int)bForceDirectories) << 1 | (int)bIgnoreFolders); + ccp.pathDstFile = GetDestinationPath(spFileInfo, m_tTaskDefinition.GetDestinationPath(), ((int)bForceDirectories) << 1 | (int)bIgnoreFolders); // are the files/folders lie on the same partition ? int iDstDriveNumber = 0; @@ -2123,19 +2121,17 @@ if(bMove && iDstDriveNumber != -1 && iDstDriveNumber == spFileInfo->GetDriveNumber() && spFileInfo->GetMove()) { bool bRetry = true; - if(bRetry && !MoveFile(spFileInfo->GetFullFilePath(), ccp.strDstFile)) + 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()); - fmt.SetParam(_t("%dstpath"), ccp.strDstFile); + fmt.SetParam(_t("%srcpath"), spFileInfo->GetFullFilePath().ToString()); + fmt.SetParam(_t("%dstpath"), ccp.pathDstFile.ToString()); m_log.loge(fmt); - CString strSrcFile = spFileInfo->GetFullFilePath(); - CString strDstFile = ccp.strDstFile; - FEEDBACK_FILEERROR ferr = { (PCTSTR)strSrcFile, (PCTSTR)strDstFile, eFastMoveError, dwLastError }; + FEEDBACK_FILEERROR ferr = { spFileInfo->GetFullFilePath().ToString(), ccp.pathDstFile.ToString(), eFastMoveError, dwLastError }; CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)m_piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &ferr); switch(frResult) { @@ -2165,16 +2161,15 @@ if(spFileInfo->IsDirectory()) { bool bRetry = true; - if(bRetry && !CreateDirectory(ccp.strDstFile, NULL) && (dwLastError=GetLastError()) != ERROR_ALREADY_EXISTS ) + 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.strDstFile); + fmt.SetParam(_t("%path"), ccp.pathDstFile.ToString()); m_log.loge(fmt); - CString strFile = ccp.strDstFile; - FEEDBACK_FILEERROR ferr = { (PCTSTR)strFile, NULL, eCreateError, dwLastError }; + FEEDBACK_FILEERROR ferr = { ccp.pathDstFile.ToString(), NULL, eCreateError, dwLastError }; CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)m_piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &ferr); switch(frResult) { @@ -2216,19 +2211,19 @@ if(bMove && spFileInfo->GetFlags() & FIF_PROCESSED && !GetTaskPropValue(m_tTaskDefinition.GetConfiguration())) { if(!GetTaskPropValue(m_tTaskDefinition.GetConfiguration())) - SetFileAttributes(spFileInfo->GetFullFilePath(), FILE_ATTRIBUTE_NORMAL); - DeleteFile(spFileInfo->GetFullFilePath()); // there will be another try later, so I don't check + 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(m_tTaskDefinition.GetConfiguration())) - SetFileDirectoryTime(ccp.strDstFile, spFileInfo); // no error checking (but most probably it should be checked) + SetFileDirectoryTime(ccp.pathDstFile.ToString(), spFileInfo); // no error checking (but most probably it should be checked) // attributes if(GetTaskPropValue(m_tTaskDefinition.GetConfiguration())) - SetFileAttributes(ccp.strDstFile, spFileInfo->GetAttributes()); // as above + SetFileAttributes(ccp.pathDstFile.ToString(), spFileInfo->GetAttributes()); // as above } m_tTaskBasicProgressInfo.SetCurrentIndex(stIndex + 1); @@ -2297,9 +2292,7 @@ if(m_tTaskDefinition.GetSourcePathCount() > 0) { - CString strSrcPath = m_arrSourcePaths.GetAt(0)->GetPath(); - CString strDstPath = m_tTaskDefinition.GetDestinationPath(); - FEEDBACK_NOTENOUGHSPACE feedStruct = { ullNeededSize, (PCTSTR)strSrcPath, (PCTSTR)strDstPath }; + FEEDBACK_NOTENOUGHSPACE feedStruct = { ullNeededSize, m_arrSourcePaths.GetAt(0)->GetPath().ToString(), m_tTaskDefinition.GetDestinationPath().ToString() }; CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)m_piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_NotEnoughSpace, &feedStruct); // default @@ -2596,35 +2589,34 @@ } // 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 +chcore::TSmartPath CTask::FindFreeSubstituteName(chcore::TSmartPath pathSrcPath, chcore::TSmartPath pathDstPath) const { // get the name from srcpath - pathSrcPath.CutIfExists(_T("\\"), false); - pathDstPath.AppendIfNotExists(_T("\\"), false); + pathSrcPath.CutIfExists(_T("\\")); + pathDstPath.AppendIfNotExists(_T("\\")); - chcore::TSmartPath spLastComponent = pathSrcPath.GetLastComponent(_T("\\"), false); + chcore::TSmartPath pathLastComponent = pathSrcPath.GetLastComponent(); // set the dest path CString strCheckPath; ictranslate::CFormat fmt(GetTaskPropValue(m_tTaskDefinition.GetConfiguration())); - fmt.SetParam(_t("%name"), (PCTSTR)spLastComponent); - chcore::TSmartPath pathCheckPath((PCTSTR)fmt); + fmt.SetParam(_t("%name"), pathLastComponent.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(m_tTaskDefinition.GetConfiguration()); while(CFileInfo::Exist(pathDstPath + pathCheckPath)) { fmt.SetFormat(strFmt); - fmt.SetParam(_t("%name"), (PCTSTR)spLastComponent); + fmt.SetParam(_t("%name"), pathLastComponent.ToString()); fmt.SetParam(_t("%count"), ++iCounter); - pathCheckPath = (PCTSTR)fmt; + pathCheckPath.FromString((PCTSTR)fmt); } - *pstrResult = pathCheckPath; + return pathCheckPath; } - chcore::TSmartPath CTask::GetDestinationPath(const CFileInfoPtr& spFileInfo, chcore::TSmartPath pathDst, int iFlags) const { if(!spFileInfo) @@ -2638,15 +2630,14 @@ { // force create directories TCHAR dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT]; - _tsplitpath(spFileInfo->GetFullFilePath(), NULL, dir, fname, ext); + _tsplitpath(spFileInfo->GetFullFilePath().ToString(), NULL, dir, fname, ext); - CString str(dir); - str.TrimLeft(_T("\\")); + pathDst.CutIfExists(_T("\\"), false); // force create directory - SHCreateDirectoryEx(NULL, pathDst + str, NULL); + SHCreateDirectoryEx(NULL, CString(pathDst.ToString()) + dir, NULL); - return pathDst + chcore::TSmartPath((PCTSTR)str) + chcore::TSmartPath(fname) + chcore::TSmartPath(ext); + return pathDst + chcore::PathFromString(dir) + chcore::PathFromString(fname) + chcore::PathFromString(ext); } else { @@ -2657,16 +2648,14 @@ // 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); + chcore::TSmartPath pathSubst = FindFreeSubstituteName(spFileInfo->GetFullFilePath(), pathDst); + m_arrSourcePaths.GetAt(stSrcIndex)->SetDestinationPath(pathSubst); } - CString strResultPath = pathDst + m_arrSourcePaths.GetAt(stSrcIndex)->GetDestinationPath() + spFileInfo->GetFilePath(); - return chcore::TSmartPath((PCTSTR)strResultPath); + return pathDst + m_arrSourcePaths.GetAt(stSrcIndex)->GetDestinationPath() + spFileInfo->GetFilePath(); } else - return pathDst + chcore::TSmartPath(spFileInfo->GetFileName()); + return pathDst + spFileInfo->GetFileName(); } } Index: src/ch/task.h =================================================================== diff -u -N -rb42450e5a25470c399e04cfbb7a368519aa455f2 -r69b48f0b4d7fad78f95854e95fca166014311474 --- src/ch/task.h (.../task.h) (revision b42450e5a25470c399e04cfbb7a368519aa455f2) +++ src/ch/task.h (.../task.h) (revision 69b48f0b4d7fad78f95854e95fca166014311474) @@ -90,7 +90,7 @@ struct CUSTOM_COPY_PARAMS { CFileInfoPtr spSrcFile; // CFileInfo - src file - CString strDstFile; // dest path with filename + chcore::TSmartPath pathDstFile; // dest path with filename CDataBuffer dbBuffer; // buffer handling bool bOnlyCreate; // flag from configuration - skips real copying - only create @@ -338,7 +338,7 @@ DWORD WINAPI ThrdProc(); ESubOperationResult RecurseDirectories(); - int ScanDirectory(CString strDirName, size_t stSrcIndex, bool bRecurse, bool bIncludeDirs); + int ScanDirectory(chcore::TSmartPath pathDirName, size_t stSrcIndex, bool bRecurse, bool bIncludeDirs); ESubOperationResult ProcessFiles(); ESubOperationResult CustomCopyFileFB(CUSTOM_COPY_PARAMS* pData); @@ -353,14 +353,14 @@ bool GetRequiredFreeSpace(ull_t *pi64Needed, ull_t *pi64Available); ESubOperationResult OpenSourceFileFB(TAutoFileHandle& hFile, const CFileInfoPtr& spSrcFileInfo, bool bNoBuffering); - ESubOperationResult OpenDestinationFileFB(TAutoFileHandle& hFile, const CString& strDstFilePath, bool bNoBuffering, const CFileInfoPtr& spSrcFileInfo, unsigned long long& ullSeekTo, bool& bFreshlyCreated); - ESubOperationResult OpenExistingDestinationFileFB(TAutoFileHandle& hFile, const CString& strDstFilePath, bool bNoBuffering); + ESubOperationResult OpenDestinationFileFB(TAutoFileHandle& hFile, const chcore::TSmartPath& pathDstFile, bool bNoBuffering, const CFileInfoPtr& spSrcFileInfo, unsigned long long& ullSeekTo, bool& bFreshlyCreated); + ESubOperationResult OpenExistingDestinationFileFB(TAutoFileHandle& hFile, const chcore::TSmartPath& pathDstFilePath, bool bNoBuffering); - ESubOperationResult SetFilePointerFB(HANDLE hFile, long long llDistance, const CString& strFilePath, bool& bSkip); - ESubOperationResult SetEndOfFileFB(HANDLE hFile, const CString& strFilePath, bool& bSkip); + ESubOperationResult SetFilePointerFB(HANDLE hFile, long long llDistance, const chcore::TSmartPath& pathFile, bool& bSkip); + ESubOperationResult SetEndOfFileFB(HANDLE hFile, const chcore::TSmartPath& pathFile, bool& bSkip); - ESubOperationResult ReadFileFB(HANDLE hFile, CDataBuffer& rBuffer, DWORD dwToRead, DWORD& rdwBytesRead, const CString& strFilePath, bool& bSkip); - ESubOperationResult WriteFileFB(HANDLE hFile, CDataBuffer& rBuffer, DWORD dwToWrite, DWORD& rdwBytesWritten, const CString& strFilePath, bool& bSkip); + ESubOperationResult ReadFileFB(HANDLE hFile, CDataBuffer& rBuffer, DWORD dwToRead, DWORD& rdwBytesRead, const chcore::TSmartPath& pathFile, bool& bSkip); + ESubOperationResult WriteFileFB(HANDLE hFile, CDataBuffer& rBuffer, DWORD dwToWrite, DWORD& rdwBytesWritten, const chcore::TSmartPath& pathFile, bool& bSkip); ESubOperationResult CheckForFreeSpaceFB(); @@ -393,7 +393,7 @@ static void OnCfgOptionChanged(const std::set& rsetChanges, void* pParam); - void FindFreeSubstituteName(chcore::TSmartPath pathSrcPath, chcore::TSmartPath pathDstPath, CString* pstrResult) const; + chcore::TSmartPath FindFreeSubstituteName(chcore::TSmartPath pathSrcPath, chcore::TSmartPath pathDstPath) const; chcore::TSmartPath GetDestinationPath(const CFileInfoPtr& spFileInfo, chcore::TSmartPath strPath, int iFlags) const; private: Index: src/libchcore/TPath.cpp =================================================================== diff -u -N -rb42450e5a25470c399e04cfbb7a368519aa455f2 -r69b48f0b4d7fad78f95854e95fca166014311474 --- src/libchcore/TPath.cpp (.../TPath.cpp) (revision b42450e5a25470c399e04cfbb7a368519aa455f2) +++ src/libchcore/TPath.cpp (.../TPath.cpp) (revision 69b48f0b4d7fad78f95854e95fca166014311474) @@ -17,11 +17,15 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "stdafx.h" +#include #include "TPath.h" #include +#include "../libicpf/exception.h" BEGIN_CHCORE_NAMESPACE +#define DEFAULT_PATH_SEPARATOR _T("\\") + // ============================================================================ /// TPath::TPath /// @date 2009/11/29 @@ -124,36 +128,6 @@ /// TSmartPath::TSmartPath /// @date 2009/11/29 /// -/// @brief Constructs path from stl string object. -/// @param[in] strPath - string containing a path. -// ============================================================================ -TSmartPath::TSmartPath(const tstring_t& strPath) : - m_pPath(NULL) -{ - m_pPath = TPath::New(); - if(m_pPath) - m_pPath->m_strPath = strPath; -} - -// ============================================================================ -/// TSmartPath::TSmartPath -/// @date 2009/11/29 -/// -/// @brief Constructs a path object from string. -/// @param[in] pszPath - string with path. -// ============================================================================ -TSmartPath::TSmartPath(const wchar_t* pszPath) : - m_pPath(NULL) -{ - m_pPath = TPath::New(); - if(m_pPath) - m_pPath->m_strPath = pszPath; -} - -// ============================================================================ -/// TSmartPath::TSmartPath -/// @date 2009/11/29 -/// /// @brief Constructs path object from another path object. /// @param[in] spPath - reference to another path object. // ============================================================================ @@ -195,38 +169,6 @@ /// TSmartPath::operator= /// @date 2009/11/29 /// -/// @brief Assigns a path from string. -/// @param[in] strPath - string containing a path. -/// @return Reference to this object. -// ============================================================================ -TSmartPath& TSmartPath::operator=(const tstring_t& strPath) -{ - PrepareToWrite(); - m_pPath->m_strPath = strPath; - - return *this; -} - -// ============================================================================ -/// TSmartPath::operator= -/// @date 2009/11/29 -/// -/// @brief Assigns a path from string. -/// @param[in] strPath - string containing a path. -/// @return Reference to this object. -// ============================================================================ -TSmartPath& TSmartPath::operator=(const wchar_t* pszPath) -{ - PrepareToWrite(); - m_pPath->m_strPath = pszPath; - - return *this; -} - -// ============================================================================ -/// TSmartPath::operator= -/// @date 2009/11/29 -/// /// @brief Assigns a path from other path object. /// @param[in] spPath - path object from which we want to get path. /// @return Reference to this object. @@ -309,7 +251,10 @@ { TSmartPath spNewPath(*this); if(rPath.m_pPath) - spNewPath += rPath.m_pPath->m_strPath; + { + spNewPath.PrepareToWrite(); + spNewPath.m_pPath->m_strPath += rPath.m_pPath->m_strPath; + } return spNewPath; } @@ -335,19 +280,61 @@ } // ============================================================================ -/// TSmartPath::operator const tstring_t -/// @date 2009/11/29 +/// chcore::TSmartPath::FromString +/// @date 2010/10/12 /// -/// @brief Casts this path object to string -/// @return String with path. +/// @brief Initializes this path object with path contained in string. +/// @param[in] pszPath - string containing path. // ============================================================================ -TSmartPath::operator const tstring_t() const +void TSmartPath::FromString(const wchar_t* pszPath) { - tstring_t strPath; + if(!pszPath) + THROW(_T("Invalid pointer"), 0, 0, 0); + + PrepareToWrite(); + m_pPath->m_strPath = pszPath; +} + +// ============================================================================ +/// chcore::TSmartPath::FromString +/// @date 2010/10/12 +/// +/// @brief Initializes this path object with path contained in string. +/// @param[in] strPath - string containing path. +// ============================================================================ +void TSmartPath::FromString(const std::wstring& strPath) +{ + PrepareToWrite(); + m_pPath->m_strPath = strPath; +} + +// ============================================================================ +/// chcore::TSmartPath::ToString +/// @date 2010/10/12 +/// +/// @brief Retrieves the pointer to a string containing path. +/// @return Pointer to the string containing path. +// ============================================================================ +const wchar_t* TSmartPath::ToString() const +{ if(m_pPath) - strPath = m_pPath->m_strPath; + return m_pPath->m_strPath.c_str(); + return _T(""); +} - return strPath; +// ============================================================================ +/// chcore::TSmartPath::ToString +/// @date 2010/10/12 +/// +/// @brief Retrieves the string containing path. +/// @return String containing path. +// ============================================================================ +std::wstring TSmartPath::ToWString() const +{ + std::wstring wstrPath; + if(m_pPath) + wstrPath = m_pPath->m_strPath; + return wstrPath; } // ============================================================================ @@ -393,6 +380,35 @@ } // ============================================================================ +/// chcore::TSmartPath::MakeRelativePath +/// @date 2010/10/12 +/// +/// @brief Converts this path to be relative to the reference, base path. +/// @param[in] rReferenceBasePath - Path which will be base path to this relative path. +/// @param[in] bCaseSensitive - Compare path with case sensitivity on/off. +/// @return True if conversion to relative path succeeded, false otherwise. +// ============================================================================ +void TSmartPath::MakeRelativePath(const TSmartPath& rReferenceBasePath, bool bCaseSensitive) +{ + if(!m_pPath || !rReferenceBasePath.m_pPath) + return; // nothing to do; in this case we might as well treat the path as relative one + + bool bStartsWith = false; + if(bCaseSensitive) + bStartsWith = boost::starts_with(m_pPath->m_strPath, rReferenceBasePath.m_pPath->m_strPath); + else + bStartsWith = boost::istarts_with(m_pPath->m_strPath, rReferenceBasePath.m_pPath->m_strPath); + + if(bStartsWith) + { + PrepareToWrite(); + m_pPath->m_strPath.erase(m_pPath->m_strPath.begin(), m_pPath->m_strPath.begin() + rReferenceBasePath.m_pPath->m_strPath.length()); + } + else + THROW(_T("Incompatible paths"), 0, 0, 0); +} + +// ============================================================================ /// TSmartPath::AppendIfNotExists /// @date 2009/11/29 /// @@ -444,24 +460,49 @@ } } -TSmartPath TSmartPath::GetLastComponent(const wchar_t* pszSeparator, bool bCaseSensitive) +// ============================================================================ +/// chcore::TSmartPath::GetLastComponent +/// @date 2010/10/12 +/// +/// @brief Retrieves the last component of path (i.e. test.txt for c:\test\test.txt) +/// @return Sub-path with the last component. +// ============================================================================ +TSmartPath TSmartPath::GetLastComponent() { if(!m_pPath) return TSmartPath(); boost::iterator_range rangeIter; - if(bCaseSensitive) - rangeIter = boost::find_last(m_pPath->m_strPath, pszSeparator); - else - rangeIter = boost::ifind_last(m_pPath->m_strPath, pszSeparator); + rangeIter = boost::find_last(m_pPath->m_strPath, DEFAULT_PATH_SEPARATOR); std::wstring wstrData; wstrData.insert(wstrData.end(), rangeIter.end(), m_pPath->m_strPath.end()); - return TSmartPath(wstrData); + return PathFromString(wstrData); } // ============================================================================ +/// chcore::TSmartPath::DeleteLastComponent +/// @date 2010/10/12 +/// +/// @brief Removes the last component of a path (i.e. test.txt for c:\test\test.txt) +// ============================================================================ +void TSmartPath::DeleteLastComponent() +{ + if(m_pPath) + { + boost::iterator_range rangeIter = boost::find_last(m_pPath->m_strPath, DEFAULT_PATH_SEPARATOR); + + if(rangeIter.end() != m_pPath->m_strPath.end()) + { + size_t stOffset = std::distance(m_pPath->m_strPath.begin(), rangeIter.end()); + PrepareToWrite(); + m_pPath->m_strPath.erase(m_pPath->m_strPath.begin() + stOffset, m_pPath->m_strPath.end()); + } + } +} + +// ============================================================================ /// TSmartPath::IsEmpty /// @date 2010/10/07 /// @@ -493,6 +534,39 @@ } // ============================================================================ +/// chcore::PathFromString +/// @date 2010/10/12 +/// +/// @brief Creates a path object from string. +/// @param[in] pszPath - string containing path. +/// @return New path object. +// ============================================================================ +TSmartPath PathFromString(const wchar_t* pszPath) +{ + if(!pszPath) + THROW(_T("Invalid pointer"), 0, 0, 0); + + TSmartPath spPath; + spPath.FromString(pszPath); + return spPath; +} + +// ============================================================================ +/// chcore::PathFromString +/// @date 2010/10/12 +/// +/// @brief Creates a path object from string. +/// @param[in] pszPath - string containing path. +/// @return New path object. +// ============================================================================ +TSmartPath PathFromString(const std::wstring& strPath) +{ + TSmartPath spPath; + spPath.FromString(strPath); + return spPath; +} + +// ============================================================================ /// TPathContainer::TPathContainer /// @date 2009/11/30 /// @@ -639,4 +713,16 @@ return m_vPaths.size(); } +// ============================================================================ +/// chcore::TPathContainer::GetCount +/// @date 2010/10/12 +/// +/// @brief Retrieves info if this container is empty. +/// @return True if empty, false otherwise. +// ============================================================================ +bool TPathContainer::IsEmpty() const +{ + return m_vPaths.empty(); +} + END_CHCORE_NAMESPACE Index: src/libchcore/TPath.h =================================================================== diff -u -N -rb42450e5a25470c399e04cfbb7a368519aa455f2 -r69b48f0b4d7fad78f95854e95fca166014311474 --- src/libchcore/TPath.h (.../TPath.h) (revision b42450e5a25470c399e04cfbb7a368519aa455f2) +++ src/libchcore/TPath.h (.../TPath.h) (revision 69b48f0b4d7fad78f95854e95fca166014311474) @@ -19,6 +19,7 @@ #ifndef __TPATH_H__ #define __TPATH_H__ +#include #include "libchcore.h" BEGIN_CHCORE_NAMESPACE @@ -48,19 +49,19 @@ class LIBCHCORE_API TSmartPath { +protected: + BOOST_STATIC_CONSTANT(bool, DefaultCaseSensitivity = false); + BOOST_STATIC_CONSTANT(wchar_t, DefaultSeparator = _T('\\')); + public: TSmartPath(); - TSmartPath(const tstring_t& strPath); - TSmartPath(const wchar_t* pszPath); TSmartPath(const TSmartPath& spPath); ~TSmartPath(); void Clear() throw(); - TSmartPath& operator=(const tstring_t& strPath); TSmartPath& operator=(const TSmartPath& spPath); - TSmartPath& operator=(const wchar_t* pszPath); bool operator==(const TSmartPath& rPath) const; bool operator<(const TSmartPath& rPath) const; @@ -69,33 +70,52 @@ TSmartPath operator+(const TSmartPath& rPath) const; TSmartPath& operator+=(const TSmartPath& rPath); - operator const tstring_t() const; + // from/to string conversions + void FromString(const wchar_t* pszPath); + void FromString(const std::wstring& strPath); - operator const wchar_t*() const - { - if(m_pPath) - return m_pPath->m_strPath.c_str(); + const wchar_t* ToString() const; + std::wstring ToWString() const; - return NULL; - } + // + bool Compare(const TSmartPath& rPath, bool bCaseSensitive = DefaultCaseSensitivity) const; + bool IsChildOf(const TSmartPath& rPath, bool bCaseSensitive = DefaultCaseSensitivity) const; - bool Compare(const TSmartPath& rPath, bool bCaseSensitive) const; - bool IsChildOf(const TSmartPath& rPath, bool bCaseSensitive) const; + void MakeRelativePath(const TSmartPath& rReferenceBasePath, bool bCaseSensitive = DefaultCaseSensitivity); - void AppendIfNotExists(const wchar_t* pszPostfix, bool bCaseSensitive); - void CutIfExists(const wchar_t* pszPostfix, bool bCaseSensitive); + void AppendIfNotExists(const wchar_t* pszPostfix, bool bCaseSensitive = DefaultCaseSensitivity); + void CutIfExists(const wchar_t* pszPostfix, bool bCaseSensitive = DefaultCaseSensitivity); - TSmartPath GetLastComponent(const wchar_t* pszSeparator, bool bCaseSensitive); + void DeleteLastComponent(); + TSmartPath GetLastComponent(); bool IsEmpty() const; + template + void load(Archive& ar, unsigned int /*uiVersion*/) + { + PrepareToWrite(); + ar & m_pPath->m_strPath; + } + + template + void save(Archive& ar, unsigned int /*uiVersion*/) const + { + ar & m_pPath->m_strPath; + } + + BOOST_SERIALIZATION_SPLIT_MEMBER(); + protected: void PrepareToWrite(); protected: TPath* m_pPath; }; +LIBCHCORE_API TSmartPath PathFromString(const wchar_t* pszPath); +LIBCHCORE_API TSmartPath PathFromString(const std::wstring& strPath); + class LIBCHCORE_API TPathContainer { public: @@ -116,6 +136,7 @@ void Clear(); size_t GetCount() const; + bool IsEmpty() const; private: #pragma warning(push)