Index: src/ch/FileInfo.cpp =================================================================== diff -u -N -r17059054c69cd5726f4c7d35357f3b9556471783 -r3c7ff3a44a80802d86725064af4bf1d5a16bdfc7 --- src/ch/FileInfo.cpp (.../FileInfo.cpp) (revision 17059054c69cd5726f4c7d35357f3b9556471783) +++ src/ch/FileInfo.cpp (.../FileInfo.cpp) (revision 3c7ff3a44a80802d86725064af4bf1d5a16bdfc7) @@ -39,6 +39,183 @@ #define new DEBUG_NEW #endif +////////////////////////////////////////////////////////////////////////////// +// CClipboardArray + +CClipboardArray::~CClipboardArray() +{ + RemoveAll(); +} + +void CClipboardArray::Serialize(icpf::archive& ar, bool bData) +{ + if (ar.is_storing()) + { + // write data + int iSize = m_vEntries.size(); + ar<Serialize(ar, bData); + } + else + { + int iSize; + ar>>iSize; + + m_vEntries.reserve(iSize); + CClipboardEntry* pEntry; + for (int i=0;iSerialize(ar, bData); + } + } +} + +////////////////////////////////////////////////////////////////////////////// +// CClipboardEntry + +CClipboardEntry::CClipboardEntry() : + m_bMove(true), + m_iDriveNumber(-1), + m_uiDriveType(static_cast(-1)), + m_iBufferIndex(0) +{ +} + +CClipboardEntry::CClipboardEntry(const CClipboardEntry& rEntry) : + m_strPath(rEntry.m_strPath), + m_bMove(rEntry.m_bMove), + m_iDriveNumber(rEntry.m_iDriveNumber), + m_uiDriveType(rEntry.m_uiDriveType), + m_vDstPaths(rEntry.m_vDstPaths) +{ +} + +CClipboardEntry* CClipboardArray::GetAt(int iPos) +{ + return m_vEntries.at(iPos); +} + +void CClipboardArray::SetAt(int nIndex, CClipboardEntry* pEntry) +{ + delete [] m_vEntries.at(nIndex); + m_vEntries[nIndex] = pEntry; +} + +void CClipboardArray::Add(CClipboardEntry* pEntry) +{ + m_vEntries.push_back(pEntry); +} + +void CClipboardArray::RemoveAt(int nIndex, int nCount) +{ + while (nCount--) + { + delete m_vEntries.at(nIndex); + } + m_vEntries.erase(m_vEntries.begin() + nIndex, m_vEntries.begin() + nIndex + nCount); +} + +void CClipboardArray::RemoveAll() +{ + for(std::vector::iterator iterEntry = m_vEntries.begin(); iterEntry != m_vEntries.end(); ++iterEntry) + { + delete *iterEntry; + } + m_vEntries.clear(); +} + +int CClipboardArray::GetSize() const +{ + return m_vEntries.size(); +} + +///////////////////////////////////////////////////////////////////////////// +// CClipboardEntry + +void CClipboardEntry::SetPath(const CString& strPath) +{ + m_strPath=strPath; // guaranteed without ending '\\' + if (m_strPath.Right(1) == _T('\\')) + m_strPath=m_strPath.Left(m_strPath.GetLength()-1); + + GetDriveData(m_strPath, &m_iDriveNumber, &m_uiDriveType); +} + +void CClipboardEntry::CalcBufferIndex(const CDestPath& dpDestPath) +{ + // what kind of buffer + if (m_uiDriveType == DRIVE_REMOTE || dpDestPath.GetDriveType() == DRIVE_REMOTE) + m_iBufferIndex=BI_LAN; + else if (m_uiDriveType == DRIVE_CDROM || dpDestPath.GetDriveType() == DRIVE_CDROM) + m_iBufferIndex=BI_CD; + else if (m_uiDriveType == DRIVE_FIXED && dpDestPath.GetDriveType() == DRIVE_FIXED) + { + // two hdd's - is this the same physical disk ? + if (m_iDriveNumber == dpDestPath.GetDriveNumber() || IsSamePhysicalDisk(m_iDriveNumber, dpDestPath.GetDriveNumber())) + m_iBufferIndex=BI_ONEDISK; + else + m_iBufferIndex=BI_TWODISKS; + } + else + m_iBufferIndex=BI_DEFAULT; +} + +void CClipboardEntry::Serialize(icpf::archive& ar, bool bData) +{ + if (bData) + { + if(ar.is_storing()) + { + ar<(m_bMove); + ar<>m_strPath; + unsigned char ucData; + ar>>ucData; + m_bMove=ucData != 0; + ar>>m_iDriveNumber; + ar>>m_uiDriveType; + ar>>m_iBufferIndex; + } + } + else + { + if(ar.is_storing()) + ar << m_vDstPaths; + else + ar >> m_vDstPaths; + } +} + +void CClipboardEntry::AddDestinationPath(const CString& strPath) +{ + m_vDstPaths.push_back(strPath); +} + +size_t CClipboardEntry::GetDestinationPathsCount() const +{ + return m_vDstPaths.size(); +} + +CString CClipboardEntry::GetDestinationPath(size_t stIndex) +{ + return m_vDstPaths.at(stIndex); +} + ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// @@ -347,14 +524,14 @@ if (!(iFlags & 0x01) && m_iSrcIndex != -1) { // generate new dest name - while (ucCopyNumber >= m_pClipboard->GetAt(m_iSrcIndex)->m_astrDstPaths.GetSize()) + while (ucCopyNumber >= m_pClipboard->GetAt(m_iSrcIndex)->GetDestinationPathsCount()) { CString strNewPath; FindFreeSubstituteName(GetFullFilePath(), strPath, &strNewPath); - m_pClipboard->GetAt(m_iSrcIndex)->m_astrDstPaths.Add(strNewPath); + m_pClipboard->GetAt(m_iSrcIndex)->AddDestinationPath(strNewPath); } - return strPath+m_pClipboard->GetAt(m_iSrcIndex)->m_astrDstPaths.GetAt(ucCopyNumber)+m_strFilePath; + return strPath+m_pClipboard->GetAt(m_iSrcIndex)->GetDestinationPath(ucCopyNumber)+m_strFilePath; } else return strPath+GetFileName(); @@ -411,15 +588,15 @@ { finf.Create(&wfd, strDirName, iSrcIndex); if (pFilters->Match(finf)) - Add(finf); + m_vFiles.push_back(finf); } else if ( _tcscmp(wfd.cFileName, _T(".")) != 0 && _tcscmp(wfd.cFileName, _T("..")) != 0) { if (bIncludeDirs) { // Add directory itself finf.Create(&wfd, strDirName, iSrcIndex); - Add(finf); + m_vFiles.push_back(finf); } if (bRecurse) { @@ -435,7 +612,7 @@ } } -int CFileInfoArray::AddFile(CString strFilePath, int iSrcIndex) +void CFileInfoArray::AddFile(CString strFilePath, int iSrcIndex) { CFileInfo finf; @@ -444,103 +621,80 @@ strFilePath=strFilePath.Left(strFilePath.GetLength()-1); finf.Create(strFilePath, iSrcIndex); - return Add(finf); + return m_vFiles.push_back(finf); } +void CFileInfoArray::AddFileInfo(const CFileInfo& rFileInfo) +{ + m_vFiles.push_back(rFileInfo); +} -////////////////////////////////////////////////////////////////////////////// -// CClipboardArray - -void CClipboardArray::Serialize(icpf::archive& ar, bool bData) +void CFileInfoArray::AppendArray(const CFileInfoArray& arrFiles) { - if (ar.is_storing()) - { - // write data - int iSize=GetSize(); - ar<Serialize(ar, bData); - } - else - { - int iSize; - ar>>iSize; + m_vFiles.insert(m_vFiles.end(), arrFiles.m_vFiles.begin(), arrFiles.m_vFiles.end()); +} - CClipboardEntry* pEntry; - for (int i=0;iSerialize(ar, bData); - } - } +size_t CFileInfoArray::GetSize() const +{ + return m_vFiles.size(); } -///////////////////////////////////////////////////////////////////////////// -// CClipboardEntry - -void CClipboardEntry::SetPath(const CString& strPath) +CFileInfo& CFileInfoArray::GetAt(size_t stIndex) { - m_strPath=strPath; // guaranteed without ending '\\' - if (m_strPath.Right(1) == _T('\\')) - m_strPath=m_strPath.Left(m_strPath.GetLength()-1); + return m_vFiles.at(stIndex); +} - GetDriveData(m_strPath, &m_iDriveNumber, &m_uiDriveType); +void CFileInfoArray::Clear() +{ + m_vFiles.clear(); } -void CClipboardEntry::CalcBufferIndex(const CDestPath& dpDestPath) +void CFileInfoArray::Store(icpf::archive& ar, bool bOnlyFlags) { - // what kind of buffer - if (m_uiDriveType == DRIVE_REMOTE || dpDestPath.GetDriveType() == DRIVE_REMOTE) - m_iBufferIndex=BI_LAN; - else if (m_uiDriveType == DRIVE_CDROM || dpDestPath.GetDriveType() == DRIVE_CDROM) - m_iBufferIndex=BI_CD; - else if (m_uiDriveType == DRIVE_FIXED && dpDestPath.GetDriveType() == DRIVE_FIXED) + INT_PTR iSize = m_vFiles.size(); + ar << iSize; + for (std::vector::iterator iterFile = m_vFiles.begin(); iterFile != m_vFiles.end(); ++iterFile) { - // two hdd's - is this the same physical disk ? - if (m_iDriveNumber == dpDestPath.GetDriveNumber() || IsSamePhysicalDisk(m_iDriveNumber, dpDestPath.GetDriveNumber())) - m_iBufferIndex=BI_ONEDISK; + if(bOnlyFlags) + ar << (*iterFile).GetFlags(); else - m_iBufferIndex=BI_TWODISKS; + (*iterFile).Store(ar); } - else - m_iBufferIndex=BI_DEFAULT; } -void CClipboardEntry::Serialize(icpf::archive& ar, bool bData) +void CFileInfoArray::Load(icpf::archive& ar, bool bOnlyFlags) { - if (bData) + INT_PTR iSize; + ar>>iSize; + + // workaround for a problem, where '0' was stored as int instead of INT_PTR; + // in this case on x86_64 iSize could have some enormous size (because we read + // someone else's data following the int value. + // Try to avoid reading later some invalid data (since we have stolen 4 bytes on x86_64). + if(iSize > INT_MAX) + THROW(_T("[CFileInfoArray::Load()] Corrupted task data (bug [#sf:2905339]"), 0, 0, 0); + + if(!bOnlyFlags) { - if(ar.is_storing()) + m_vFiles.clear(); + m_vFiles.reserve(iSize); + } + + CFileInfo fi; + fi.SetClipboard(&m_rClipboard); + uint_t uiFlags = 0; + for (INT_PTR i = 0; i < iSize; i++) + { + if(bOnlyFlags) { - ar<(m_bMove); - ar<> uiFlags; + rInfo.SetFlags(uiFlags); } else { - ar>>m_strPath; - unsigned char ucData; - ar>>ucData; - m_bMove=ucData != 0; - ar>>m_iDriveNumber; - ar>>m_uiDriveType; - ar>>m_iBufferIndex; + fi.Load(ar); + m_vFiles.push_back(fi); } } - else - { - if(ar.is_storing()) - ar<>m_astrDstPaths; - } } Index: src/ch/FileInfo.h =================================================================== diff -u -N -r7432c718864166ac332355d3c0d3a106a969ab1d -r3c7ff3a44a80802d86725064af4bf1d5a16bdfc7 --- src/ch/FileInfo.h (.../FileInfo.h) (revision 7432c718864166ac332355d3c0d3a106a969ab1d) +++ src/ch/FileInfo.h (.../FileInfo.h) (revision 3c7ff3a44a80802d86725064af4bf1d5a16bdfc7) @@ -16,42 +16,12 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -/** - * @doc FILEINFO - * @module FileInfo.h 1.3 - Interface for the CFileInfo and CFileInfoArray classes | - * The classes contained in this file allow to gather recursively file information - * through directories. - * - * Codeguru & friends - * Coded by Antonio Tejada Lacaci. 1999 - * atejada@espanet.com - * CRC32 code by Floor A.C. Naaijkens - * - * Updates (aaaa-mm-dd): - * MANY CHANGES by Ixen Gerthannes... - * 1999-9-23 ATL: Opensource works! Again, Mr. Szucs (rszucs@cygron.hu) gets another bug: - * Missing "4-(dwRead & 0x3)" in the same lines as before, when calc'ing the padding mask. - * 1999-9-16 ATL: Corrected bug in GetCRC and GetChecksum as suggested by R�bert Szucs (rszucs@cygron.hu): - * There was a buffer overflow and checksum and crc for last dword +1 was calc'ed instead - * of the ones for last dword. Instead accessing buffer[dwRead +3...] it ought to access - * buffer[dwRead...] (shame on me! :'(). - * 1999-9-2 ATL: Corrected bug in AddFile(CString, LPARAM) as suggested by Nhycoh (Nhycoh44@yahoo.com): - * There was some weird stuff at CFileInfo::Create(strFilePath) - * stating strFilePath.GetLength()-nBarPos instead of nBarPos+1 - * (I'm quite sure I left my head on my pillow the day I did that %-#). - * 1999-6-27 ATL: Updated GetCRC & GetChecksum to avoid some bug cases - * 1999-4-7 ATL: Updated source code doc to conform Autoduck 2.0 standard - * 1999-4-7 ATL: Corrected bug in AddDir as suggested by Zhuang Yuyao (zhuangyy@koal.com): - * bIncludeDirs wasn't used if bRecurse was false. - * - * Keep this comment if you redistribute this file. And credit where credit's due! - */ +// File was originally based on FileInfo.h by Antonio Tejada Lacaci. +// Almost everything has changed since then. #ifndef __FILEINFO_H__ #define __FILEINFO_H__ -#include -#include "afxdisp.h" #include "DestPath.h" void FindFreeSubstituteName(CString strSrcPath, CString strDstPath, CString* pstrResult); @@ -67,8 +37,8 @@ class CClipboardEntry { public: - CClipboardEntry() { m_bMove=true; m_iDriveNumber=-1; m_uiDriveType=static_cast(-1); m_iBufferIndex=0; }; - CClipboardEntry(const CClipboardEntry& rEntry) { m_strPath=rEntry.m_strPath; m_bMove=rEntry.m_bMove; m_iDriveNumber=rEntry.m_iDriveNumber; m_uiDriveType=rEntry.m_uiDriveType; m_astrDstPaths.Copy(rEntry.m_astrDstPaths); }; + CClipboardEntry(); + CClipboardEntry(const CClipboardEntry& rEntry); void SetPath(const CString& strPath); void CalcBufferIndex(const CDestPath& dpDestPath); @@ -84,6 +54,10 @@ void Serialize(icpf::archive& ar, bool bData); + void AddDestinationPath(const CString& strPath); + size_t GetDestinationPathsCount() const; + CString GetDestinationPath(size_t stIndex); + private: CString m_strPath; // path (ie. c:\\windows\\) - always with ending '\\' bool m_bMove; // specifies if we can use MoveFile (if will be moved) @@ -93,23 +67,29 @@ int m_iBufferIndex; // buffer number, with which we'll copy this data -public: - CStringArray m_astrDstPaths; // dest paths table for this group of paths + std::vector m_vDstPaths; // dest paths table for this group of paths }; ////////////////////////////////////////////////////////////////////////// // CClipboardArray -class CClipboardArray : public CArray +class CClipboardArray { public: - ~CClipboardArray() { RemoveAll(); }; + ~CClipboardArray(); void Serialize(icpf::archive& ar, bool bData); - void SetAt(int nIndex, CClipboardEntry* pEntry) { delete [] GetAt(nIndex); SetAt(nIndex, pEntry); }; - void RemoveAt(int nIndex, int nCount = 1) { while (nCount--) { delete GetAt(nIndex); static_cast*>(this)->RemoveAt(nIndex, 1); } }; - void RemoveAll() { for (int i=0;i*>(this)->RemoveAll(); }; + CClipboardEntry* GetAt(int iPos); + + int GetSize() const; + void Add(CClipboardEntry* pEntry); + void SetAt(int nIndex, CClipboardEntry* pEntry); + void RemoveAt(int nIndex, int nCount = 1); + void RemoveAll(); + +protected: + std::vector m_vEntries; }; class CFileInfo @@ -198,153 +178,36 @@ /** * @class Allows to retrieve s from files/directories in a directory */ -class CFileInfoArray : public CArray +class CFileInfoArray { public: - /** @access Public members */ - - /** - * @cmember Default constructor - */ CFileInfoArray(CClipboardArray& A_rClipboardArray) : m_rClipboard(A_rClipboardArray) { - - SetSize(0, 5000); } - /** - * @cmember Adds a file or all contained in a directory to the CFileInfoArray - * Only "static" data for CFileInfo is filled (by default CRC and checksum are NOT - * calculated when inserting CFileInfos). Returns the number of s added to the array - * @parm Name of the directory, ended in backslash. - * @parm Mask of files to add in case that strDirName is a directory - * @parm Wether to recurse or not subdirectories - * @parmopt Parameter to pass to protected member function AddFileInfo - * @parmopt Wether to add or not CFileInfos for directories - * @parmopt Pointer to a variable to signal abort of directory retrieval - * (multithreaded apps). - * @parmopt pulCount Pointer to a variable incremented each time a CFileInfo is added to the - * array (multithreaded apps). - * @xref - */ void AddDir(CString strDirName, const CFiltersArray* pFilters, int iSrcIndex, const bool bRecurse, const bool bIncludeDirs, const volatile bool* pbAbort=NULL); - /** - * @cmember Adds a single file or directory to the CFileInfoArray. In case of directory, files - * contained in the directory are NOT added to the array. - * Returns the position in the array where the was added (-1 if - * wasn't added) - * @parm Name of the file or directory to add. NOT ended with backslash. - * @parm Parameter to pass to protected member function AddFileInfo. - * @xref - */ - int AddFile(CString strFilePath, int iSrcIndex); + void AddFile(CString strFilePath, int iSrcIndex); - // store/restore - void Store(icpf::archive& ar, bool bOnlyFlags) - { - INT_PTR iSize = GetSize(); - ar << iSize; - for (INT_PTR i=0;i>iSize; + void AppendArray(const CFileInfoArray& arrFiles); - // workaround for a problem, where '0' was stored as int instead of INT_PTR; - // in this case on x86_64 iSize could have some enormous size (because we read - // someone else's data following the int value. - // Try to avoid reading later some invalid data (since we have stolen 4 bytes on x86_64). - if(iSize > INT_MAX) - THROW(_T("[CFileInfoArray::Load()] Corrupted task data (bug [#sf:2905339]"), 0, 0, 0); + size_t GetSize() const; + CFileInfo& GetAt(size_t stIndex); - SetSize(iSize, 5000); - CFileInfo fi; - fi.SetClipboard(&m_rClipboard); - uint_t uiFlags = 0; - for (INT_PTR i=0;i> uiFlags; - rInfo.SetFlags(uiFlags); - } - else - { - fi.Load(ar); - SetAt(i, fi); - } - } - } - -protected: - CClipboardArray& m_rClipboard; -}; + void Clear(); + // store/restore + void Store(icpf::archive& ar, bool bOnlyFlags); -/** -@ex This code adds all files in root directory and its subdirectories (but not directories themselves) to the array and TRACEs them: | + void Load(icpf::archive& ar, bool bOnlyFlags); - CFileInfoArray fia; - - fia.AddDir( - "C:\\", // Directory - "*.*", // Filemask (all files) - TRUE, // Recurse subdirs - fia::AP_SORTBYNAME | fia::AP_SORTASCENDING, // Sort by name and ascending - FALSE // Do not add array entries for directories (only for files) - ); - TRACE("Dumping directory contents\n"); - for (int i=0;i m_vFiles; +}; #endif Index: src/ch/task.cpp =================================================================== diff -u -N -r055a5c0e008dc0e92960d5fd378863b85b9e697f -r3c7ff3a44a80802d86725064af4bf1d5a16bdfc7 --- src/ch/task.cpp (.../task.cpp) (revision 055a5c0e008dc0e92960d5fd378863b85b9e697f) +++ src/ch/task.cpp (.../task.cpp) (revision 3c7ff3a44a80802d86725064af4bf1d5a16bdfc7) @@ -109,13 +109,11 @@ } // m_clipboard -int CTask::AddClipboardData(CClipboardEntry* pEntry) +void CTask::AddClipboardData(CClipboardEntry* pEntry) { m_cs.Lock(); - int retval=m_clipboard.Add(pEntry); + m_clipboard.Add(pEntry); m_cs.Unlock(); - - return retval; } CClipboardEntry* CTask::GetClipboardData(int nIndex) @@ -176,22 +174,19 @@ m_cs.Lock(); - m_files.Append(fa); + m_files.AppendArray(fa); m_cs.Unlock(); return 0; } -int CTask::FilesAdd(CFileInfo fi) +void CTask::FilesAdd(CFileInfo fi) { - int rv=-1; m_cs.Lock(); if (fi.IsDirectory() || m_afFilters.Match(fi)) - rv=m_files.Add(fi); + m_files.AddFileInfo(fi); m_cs.Unlock(); - - return rv; } CFileInfo CTask::FilesGetAt(int nIndex) @@ -214,14 +209,14 @@ void CTask::FilesRemoveAll() { m_cs.Lock(); - m_files.RemoveAll(); + m_files.Clear(); m_cs.Unlock(); } -int CTask::FilesGetSize() +size_t CTask::FilesGetSize() { m_cs.Lock(); - int nSize=m_files.GetSize(); + size_t nSize=m_files.GetSize(); m_cs.Unlock(); return nSize; @@ -318,7 +313,7 @@ // m_pThread // m_nPriority -int CTask::GetPriority() +int CTask::GetPriority() { m_cs.Lock(); int nPriority=m_nPriority; @@ -388,10 +383,10 @@ m_nAll=0; int nSize=m_files.GetSize(); - CFileInfo* pFiles=m_files.GetData(); - for (int i=0;im_log.logi(fmt); // found file/folder - check if the dest name has been generated - if (pTask->GetClipboardData(i)->m_astrDstPaths.GetSize() == 0) + if (pTask->GetClipboardData(i)->GetDestinationPathsCount() == 0) { // generate something - if dest folder == src folder - search for copy if (pTask->GetDestPath().GetPath() == fi.GetFileRoot()) { CString strSubst; FindFreeSubstituteName(fi.GetFullFilePath(), pTask->GetDestPath().GetPath(), &strSubst); - pTask->GetClipboardData(i)->m_astrDstPaths.Add(strSubst); + pTask->GetClipboardData(i)->AddDestinationPath(strSubst); } else - pTask->GetClipboardData(i)->m_astrDstPaths.Add(fi.GetFileName()); + pTask->GetClipboardData(i)->AddDestinationPath(fi.GetFileName()); } // add if needed Index: src/ch/task.h =================================================================== diff -u -N -r7432c718864166ac332355d3c0d3a106a969ab1d -r3c7ff3a44a80802d86725064af4bf1d5a16bdfc7 --- src/ch/task.h (.../task.h) (revision 7432c718864166ac332355d3c0d3a106a969ab1d) +++ src/ch/task.h (.../task.h) (revision 3c7ff3a44a80802d86725064af4bf1d5a16bdfc7) @@ -141,19 +141,19 @@ ~CTask(); // m_clipboard - int AddClipboardData(CClipboardEntry* pEntry); + void AddClipboardData(CClipboardEntry* pEntry); CClipboardEntry* GetClipboardData(int nIndex); int GetClipboardDataSize(); int ReplaceClipboardStrings(CString strOld, CString strNew); // m_files int FilesAddDir(const CString strDirName, const CFiltersArray* pFilters, int iSrcIndex, const bool bRecurse, const bool bIncludeDirs); - int FilesAdd(CFileInfo fi); + void FilesAdd(CFileInfo fi); CFileInfo FilesGetAt(int nIndex); CFileInfo& FilesGetAtCurrentIndex(); void FilesRemoveAll(); - int FilesGetSize(); + size_t FilesGetSize(); // m_nCurrentIndex void IncreaseCurrentIndex(); @@ -273,7 +273,6 @@ static void RecurseDirectories(CTask* pTask); static bool SetFileDirectoryTime(LPCTSTR lpszName, CFileInfo* pSrcInfo); static bool TimeToFileTime(const COleDateTime& time, LPFILETIME pFileTime); - static void ReplaceNoCase(CString& rString, CString strOld, CString strNew); public: // CLogFile m_log;