Index: src/ch/FileInfo.h =================================================================== diff -u -r45cf96558ba334192ef42687d4dac01c46d6ffd8 -r0c8e64ca71144467eed1f1d6c32d59bc2150a004 --- src/ch/FileInfo.h (.../FileInfo.h) (revision 45cf96558ba334192ef42687d4dac01c46d6ffd8) +++ src/ch/FileInfo.h (.../FileInfo.h) (revision 0c8e64ca71144467eed1f1d6c32d59bc2150a004) @@ -167,7 +167,7 @@ void SetLength64(ULONGLONG uhSize) { m_uhFileSize=uhSize; } // disk - path and disk number (-1 if none - ie. net disk) - CString GetFileDrive(void) const; // returns string with src disk + CString 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 Index: src/ch/task.cpp =================================================================== diff -u -r45cf96558ba334192ef42687d4dac01c46d6ffd8 -r0c8e64ca71144467eed1f1d6c32d59bc2150a004 --- src/ch/task.cpp (.../task.cpp) (revision 45cf96558ba334192ef42687d4dac01c46d6ffd8) +++ src/ch/task.cpp (.../task.cpp) (revision 0c8e64ca71144467eed1f1d6c32d59bc2150a004) @@ -493,7 +493,7 @@ } // m_files -int CTask::FilesAddDir(CString strDirName, size_t stSrcIndex, bool bRecurse, bool bIncludeDirs) +int CTask::ScanDirectory(CString strDirName, size_t stSrcIndex, bool bRecurse, bool bIncludeDirs) { WIN32_FIND_DATA wfd; CString strText; @@ -534,7 +534,7 @@ { strText = strDirName + wfd.cFileName + _T("\\"); // Recurse Dirs - FilesAddDir(strText, stSrcIndex, bRecurse, bIncludeDirs); + ScanDirectory(strText, stSrcIndex, bRecurse, bIncludeDirs); } } @@ -549,34 +549,6 @@ return 0; } -void CTask::FilesAdd(const CFileInfoPtr& spFileInfo) -{ - if(spFileInfo->IsDirectory() || m_afFilters.Match(spFileInfo)) - m_files.AddFileInfo(spFileInfo); -} - -CFileInfoPtr CTask::FilesGetAt(size_t stIndex) -{ - return m_files.GetAt(stIndex); -} - -CFileInfoPtr CTask::FilesGetAtCurrentIndex() -{ - boost::shared_lock lock(m_lock); - - return m_files.GetAt(m_tTaskProgressInfo.GetCurrentIndex()); -} - -void CTask::FilesRemoveAll() -{ - m_files.Clear(); -} - -size_t CTask::FilesGetSize() -{ - return m_files.GetSize(); -} - // m_strDestPath - adds '\\' void CTask::SetDestPath(LPCTSTR lpszPath) { @@ -738,7 +710,7 @@ m_bSaved = true; } - CString strPath = m_strTaskBasePath.c_str() + GetUniqueNameNL() + (bData ? _T(".atd") : _T(".atp")); + CString strPath = m_strTaskBasePath.c_str() + m_strUniqueName + (bData ? _T(".atd") : _T(".atp")); std::ofstream ofs(strPath, ios_base::out | ios_base::binary); boost::archive::binary_oarchive ar(ofs); @@ -1041,6 +1013,10 @@ bool CTask::GetRequiredFreeSpace(ull_t *pullNeeded, ull_t *pullAvailable) { + BOOST_ASSERT(pullNeeded && pullAvailable); + if(!pullNeeded || !pullAvailable) + THROW(_T("Invalid argument"), 0, 0, 0); + *pullNeeded = m_localStats.GetUnProcessedSize(); // it'd be nice to round up to take cluster size into consideration, // but GetDiskFreeSpace returns false values @@ -1102,23 +1078,6 @@ return bResult != 0; } -// m_strDestPath - adds '\\' -void CTask::SetDestPathNL(LPCTSTR lpszPath) -{ - m_dpDestPath.SetPath(lpszPath); -} - -// guaranteed '\\' -const CDestPath& CTask::GetDestPathNL() -{ - return m_dpDestPath; -} - -int CTask::GetDestDriveNumberNL() -{ - return m_dpDestPath.GetDriveNumber(); -} - // m_nStatus void CTask::SetStatusNL(UINT nStatus, UINT nMask) { @@ -1171,11 +1130,6 @@ m_localStats.SetTotalSize(ullTotalSize); } -CString CTask::GetUniqueNameNL() -{ - return m_strUniqueName; -} - void CTask::SetForceFlagNL(bool bFlag) { m_bForce=bFlag; @@ -1206,7 +1160,7 @@ SetStatus(ST_SEARCHING, ST_STEP_MASK); // delete the content of m_files - FilesRemoveAll(); + m_files.Clear(); // enter some data to m_files int iDestDrvNumber = GetDestDriveNumber(); @@ -1225,15 +1179,16 @@ CFileInfoPtr spFileInfo; bSkipInputPath = false; - bRetry = false; + spFileInfo.reset(new CFileInfo()); + spFileInfo->SetClipboard(GetClipboard()); + // try to get some info about the input path; let user know if the path does not exist. do { - // read attributes of src file/folder - spFileInfo.reset(new CFileInfo()); - spFileInfo->SetClipboard(GetClipboard()); + bRetry = false; + // read attributes of src file/folder bool bExists = spFileInfo->Create(GetClipboardData(stIndex)->GetPath(), stIndex); if(!bExists) { @@ -1244,18 +1199,18 @@ { case CFeedbackHandler::eResult_Cancel: throw new CProcessingException(E_CANCEL); - break; + case CFeedbackHandler::eResult_Retry: bRetry = true; - continue; break; + case CFeedbackHandler::eResult_Pause: throw new CProcessingException(E_PAUSE); - break; + case CFeedbackHandler::eResult_Skip: bSkipInputPath = true; - bRetry = false; break; // just do nothing + default: BOOST_ASSERT(FALSE); // unknown result throw new CProcessingException(E_ERROR, 0, _t("Unknown feedback result type")); @@ -1293,7 +1248,8 @@ // add if folder's aren't ignored if(!bIgnoreDirs && !bForceDirectories) { - FilesAdd(spFileInfo); + // add directory info; it is not to be filtered with m_afFilters + m_files.AddFileInfo(spFileInfo); // log fmt.SetFormat(_T("Added folder %path")); @@ -1313,7 +1269,7 @@ // no movefile possibility - use CustomCopyFile GetClipboardData(stIndex)->SetMove(false); - FilesAddDir(spFileInfo->GetFullFilePath(), stIndex, true, !bIgnoreDirs || bForceDirectories); + ScanDirectory(spFileInfo->GetFullFilePath(), stIndex, true, !bIgnoreDirs || bForceDirectories); } // check for kill need @@ -1336,7 +1292,9 @@ else GetClipboardData(stIndex)->SetMove(false); // no MoveFile - FilesAdd(spFileInfo); // file - add + // add file info if passes filters + if(m_afFilters.Match(spFileInfo)) + m_files.AddFileInfo(spFileInfo); // log fmt.SetFormat(_T("Added file %path")); @@ -1372,7 +1330,7 @@ // index points to 0 or next item to process size_t stIndex = m_tTaskProgressInfo.GetCurrentIndex(); - while(stIndex < FilesGetSize()) + while(stIndex < m_files.GetSize()) { // set index in pTask to currently deleted element m_tTaskProgressInfo.SetCurrentIndex(stIndex); @@ -1386,7 +1344,7 @@ } // current processed element - spFileInfo = FilesGetAt(FilesGetSize() - stIndex - 1); + spFileInfo = m_files.GetAt(m_files.GetSize() - stIndex - 1); if(!(spFileInfo->GetFlags() & FIF_PROCESSED)) { ++stIndex; @@ -1823,11 +1781,8 @@ throw new CProcessingException(E_PAUSE); case CFeedbackHandler::eResult_Skip: -/* - m_localStats.IncreaseProcessedSize(pData->spSrcFile->GetLength64()); - pData->bProcessed = false; -*/ return false; + default: BOOST_ASSERT(FALSE); // unknown result THROW(_T("Unhandled case"), 0, 0, 0); @@ -2131,7 +2086,7 @@ CalculateProcessedSize(); // begin at index which wasn't processed previously - size_t stSize = FilesGetSize(); + size_t stSize = m_files.GetSize(); bool bIgnoreFolders = (GetStatus(ST_SPECIAL_MASK) & ST_IGNORE_DIRS) != 0; bool bForceDirectories = (GetStatus(ST_SPECIAL_MASK) & ST_FORCE_DIRS) != 0; const CDestPath& dpDestPath = GetDestPath(); @@ -2175,7 +2130,7 @@ } // update m_stCurrentIndex, getting current CFileInfo - CFileInfoPtr spFileInfo = FilesGetAtCurrentIndex(); + CFileInfoPtr spFileInfo = m_files.GetAt(m_tTaskProgressInfo.GetCurrentIndex()); // set dest path with filename ccp.strDstFile = spFileInfo->GetDestinationPath(dpDestPath.GetPath(), ((int)bForceDirectories) << 1 | (int)bIgnoreFolders); @@ -2507,7 +2462,7 @@ case ST_NULL_STATUS: case ST_SEARCHING: // get rid of m_files contents - FilesRemoveAll(); + m_files.Clear(); // save state of a task Store(true); Index: src/ch/task.h =================================================================== diff -u -r45cf96558ba334192ef42687d4dac01c46d6ffd8 -r0c8e64ca71144467eed1f1d6c32d59bc2150a004 --- src/ch/task.h (.../task.h) (revision 45cf96558ba334192ef42687d4dac01c46d6ffd8) +++ src/ch/task.h (.../task.h) (revision 0c8e64ca71144467eed1f1d6c32d59bc2150a004) @@ -444,17 +444,21 @@ /// Main function for the task processing thread DWORD WINAPI ThrdProc(); + void RecurseDirectories(); + int ScanDirectory(CString strDirName, size_t stSrcIndex, bool bRecurse, bool bIncludeDirs); + void ProcessFiles(); void CustomCopyFile(CUSTOM_COPY_PARAMS* pData); void DeleteFiles(); - void RecurseDirectories(); void CheckForWaitState(); // Helper filesystem methods static bool SetFileDirectoryTime(LPCTSTR lpszName, const CFileInfoPtr& spFileInfo); + bool GetRequiredFreeSpace(ull_t *pi64Needed, ull_t *pi64Available); + HANDLE OpenSourceFileFB(const CFileInfoPtr& spSrcFileInfo, bool bNoBuffering); HANDLE OpenDestinationFileFB(const CString& strDstFilePath, bool bNoBuffering, const CFileInfoPtr& spSrcFileInfo, unsigned long long& ullSeekTo, bool& bFreshlyCreated); HANDLE OpenExistingDestinationFileFB(const CString& strDstFilePath, bool bNoBuffering); @@ -465,19 +469,7 @@ bool ReadFileFB(HANDLE hFile, CDataBuffer& rBuffer, DWORD dwToRead, DWORD& rdwBytesRead, const CString& strFilePath); bool WriteFileFB(HANDLE hFile, CDataBuffer& rBuffer, DWORD dwToWrite, DWORD& rdwBytesWritten, const CString& strFilePath); - // m_files - int FilesAddDir(CString strDirName, size_t stSrcIndex, bool bRecurse, bool bIncludeDirs); - void FilesAdd(const CFileInfoPtr& spFileInfo); - CFileInfoPtr FilesGetAt(size_t stIndex); - CFileInfoPtr FilesGetAtCurrentIndex(); - void FilesRemoveAll(); - size_t FilesGetSize(); - - // m_strDestPath - void SetDestPathNL(LPCTSTR lpszPath); - const CDestPath& GetDestPathNL(); int GetDestDriveNumber(); - int GetDestDriveNumberNL(); // m_nStatus void SetStatusNL(UINT nStatus, UINT nMask); @@ -499,10 +491,6 @@ void DeleteProgress(LPCTSTR lpszDirectory); - void KillThread(); - - CString GetUniqueNameNL(); - void SetForceFlagNL(bool bFlag = true); bool GetForceFlagNL(); @@ -511,10 +499,9 @@ void SetContinueFlagNL(bool bFlag = true); bool GetContinueFlagNL(); - bool GetRequiredFreeSpace(ull_t *pi64Needed, ull_t *pi64Available); - bool CanBegin(); + void KillThread(); void RequestStopThread(); private: