Index: src/ch/TLocalFilesystem.cpp =================================================================== diff -u -N -r28b540c17739ad8b63f3b199e0e2151ec048bd05 -r7749d67cd70821fef9cc51303d42625fbcc2aa9d --- src/ch/TLocalFilesystem.cpp (.../TLocalFilesystem.cpp) (revision 28b540c17739ad8b63f3b199e0e2151ec048bd05) +++ src/ch/TLocalFilesystem.cpp (.../TLocalFilesystem.cpp) (revision 7749d67cd70821fef9cc51303d42625fbcc2aa9d) @@ -24,6 +24,8 @@ #include "TLocalFilesystem.h" #include "TAutoHandles.h" #include "FileInfo.h" +#include "..\Common\FileSupport.h" +#include "DataBuffer.h" void TLocalFilesystem::GetDriveData(const chcore::TSmartPath& spPath, int* piDrvNum, UINT* puiDrvType) { @@ -157,11 +159,16 @@ return ::MoveFile(PrependPathExtensionIfNeeded(pathSource).ToString(), PrependPathExtensionIfNeeded(pathDestination).ToString()) != FALSE; } -TLocalFilesystemFind TLocalFilesystem::CreateFinder(const chcore::TSmartPath& pathDir, const chcore::TSmartPath& pathMask) +TLocalFilesystemFind TLocalFilesystem::CreateFinderObject(const chcore::TSmartPath& pathDir, const chcore::TSmartPath& pathMask) { return TLocalFilesystemFind(pathDir, pathMask); } +TLocalFilesystemFile TLocalFilesystem::CreateFileObject() +{ + return TLocalFilesystemFile(); +} + chcore::TSmartPath TLocalFilesystem::PrependPathExtensionIfNeeded(const chcore::TSmartPath& pathInput) { if(pathInput.GetLength() > _MAX_PATH - 1) @@ -226,3 +233,83 @@ FindClose(m_hFind); m_hFind = INVALID_HANDLE_VALUE; } + +TLocalFilesystemFile::TLocalFilesystemFile() : + m_hFile(INVALID_HANDLE_VALUE), + m_pathFile() +{ +} + +TLocalFilesystemFile::~TLocalFilesystemFile() +{ + Close(); +} + +bool TLocalFilesystemFile::OpenExistingForReading(const chcore::TSmartPath& pathFile, bool bNoBuffering) +{ + Close(); + + m_hFile = ::CreateFile(TLocalFilesystem::PrependPathExtensionIfNeeded(pathFile).ToString(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN | (bNoBuffering ? FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH : 0), NULL); + if(m_hFile == INVALID_HANDLE_VALUE) + return false; + return true; +} + +bool TLocalFilesystemFile::CreateNewForWriting(const chcore::TSmartPath& pathFile, bool bNoBuffering) +{ + Close(); + + m_hFile = ::CreateFile(TLocalFilesystem::PrependPathExtensionIfNeeded(pathFile).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(m_hFile == INVALID_HANDLE_VALUE) + return false; + return true; +} + +bool TLocalFilesystemFile::OpenExistingForWriting(const chcore::TSmartPath& pathFile, bool bNoBuffering) +{ + Close(); + + m_hFile = CreateFile(TLocalFilesystem::PrependPathExtensionIfNeeded(pathFile).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(m_hFile == INVALID_HANDLE_VALUE) + return false; + return true; +} + +bool TLocalFilesystemFile::SetFilePointer(long long llNewPos, DWORD dwMoveMethod) +{ + if(!IsOpen()) + return false; + + return (SetFilePointer64(m_hFile, llNewPos, dwMoveMethod) != -1); +} + +bool TLocalFilesystemFile::SetEndOfFile() +{ + if(!IsOpen()) + return false; + + return ::SetEndOfFile(m_hFile) != FALSE; +} + +bool TLocalFilesystemFile::ReadFile(CDataBuffer& rBuffer, DWORD dwToRead, DWORD& rdwBytesRead) +{ + if(!IsOpen()) + return false; + + return ::ReadFile(m_hFile, rBuffer, dwToRead, &rdwBytesRead, NULL) != FALSE; +} + +bool TLocalFilesystemFile::WriteFile(CDataBuffer& rBuffer, DWORD dwToWrite, DWORD& rdwBytesWritten) +{ + if(!IsOpen()) + return false; + + return ::WriteFile(m_hFile, rBuffer, dwToWrite, &rdwBytesWritten, NULL) != NULL && dwToWrite == rdwBytesWritten; +} + +void TLocalFilesystemFile::Close() +{ + if(m_hFile != INVALID_HANDLE_VALUE) + ::CloseHandle(m_hFile); + m_hFile = INVALID_HANDLE_VALUE; +} Index: src/ch/TLocalFilesystem.h =================================================================== diff -u -N -r28b540c17739ad8b63f3b199e0e2151ec048bd05 -r7749d67cd70821fef9cc51303d42625fbcc2aa9d --- src/ch/TLocalFilesystem.h (.../TLocalFilesystem.h) (revision 28b540c17739ad8b63f3b199e0e2151ec048bd05) +++ src/ch/TLocalFilesystem.h (.../TLocalFilesystem.h) (revision 7749d67cd70821fef9cc51303d42625fbcc2aa9d) @@ -28,7 +28,10 @@ class CFileInfo; typedef boost::shared_ptr CFileInfoPtr; +class TAutoFileHandle; class TLocalFilesystemFind; +class TLocalFilesystemFile; +class CDataBuffer; class TLocalFilesystem { @@ -45,12 +48,14 @@ static bool GetFileInfo(const chcore::TSmartPath& pathFile, CFileInfoPtr& rFileInfo, size_t stSrcIndex = std::numeric_limits::max(), const chcore::TPathContainer* pBasePaths = NULL); static bool FastMove(const chcore::TSmartPath& pathSource, const chcore::TSmartPath& pathDestination); - static TLocalFilesystemFind CreateFinder(const chcore::TSmartPath& pathDir, const chcore::TSmartPath& pathMask); + static TLocalFilesystemFind CreateFinderObject(const chcore::TSmartPath& pathDir, const chcore::TSmartPath& pathMask); + static TLocalFilesystemFile CreateFileObject(); private: static chcore::TSmartPath PrependPathExtensionIfNeeded(const chcore::TSmartPath& pathInput); friend class TLocalFilesystemFind; + friend class TLocalFilesystemFile; }; class TLocalFilesystemFind @@ -65,11 +70,40 @@ TLocalFilesystemFind(const chcore::TSmartPath& pathDir, const chcore::TSmartPath& pathMask); private: - const chcore::TSmartPath m_pathDir; - const chcore::TSmartPath m_pathMask; + chcore::TSmartPath m_pathDir; + chcore::TSmartPath m_pathMask; HANDLE m_hFind; friend class TLocalFilesystem; }; + +class TLocalFilesystemFile +{ +public: + ~TLocalFilesystemFile(); + + bool OpenExistingForReading(const chcore::TSmartPath& pathFile, bool bNoBuffering); + bool CreateNewForWriting(const chcore::TSmartPath& pathFile, bool bNoBuffering); + bool OpenExistingForWriting(const chcore::TSmartPath& pathFile, bool bNoBuffering); + + bool SetFilePointer(long long llNewPos, DWORD dwMoveMethod); + bool SetEndOfFile(); + + bool ReadFile(CDataBuffer& rBuffer, DWORD dwToRead, DWORD& rdwBytesRead); + bool WriteFile(CDataBuffer& rBuffer, DWORD dwToWrite, DWORD& rdwBytesWritten); + + bool IsOpen() const { return m_hFile != INVALID_HANDLE_VALUE; } + + void Close(); + +private: + TLocalFilesystemFile(); + +private: + chcore::TSmartPath m_pathFile; + HANDLE m_hFile; + + friend class TLocalFilesystem; +}; #endif Index: src/ch/TSubTaskCopyMove.cpp =================================================================== diff -u -N -r28b540c17739ad8b63f3b199e0e2151ec048bd05 -r7749d67cd70821fef9cc51303d42625fbcc2aa9d --- src/ch/TSubTaskCopyMove.cpp (.../TSubTaskCopyMove.cpp) (revision 28b540c17739ad8b63f3b199e0e2151ec048bd05) +++ src/ch/TSubTaskCopyMove.cpp (.../TSubTaskCopyMove.cpp) (revision 7749d67cd70821fef9cc51303d42625fbcc2aa9d) @@ -332,8 +332,9 @@ icpf::log_file& rLog = GetContext().GetLog(); TTaskConfigTracker& rCfgTracker = GetContext().GetCfgTracker(); - TAutoFileHandle hSrc = INVALID_HANDLE_VALUE, - hDst = INVALID_HANDLE_VALUE; + TLocalFilesystemFile fileSrc = TLocalFilesystem::CreateFileObject(); + TLocalFilesystemFile fileDst = TLocalFilesystem::CreateFileObject(); + ictranslate::CFormat fmt; TSubTaskBase::ESubOperationResult eResult = TSubTaskBase::eSubResult_Continue; bool bSkip = false; @@ -346,10 +347,10 @@ pData->spSrcFile->GetLength64() >= GetTaskPropValue(rTaskDefinition.GetConfiguration())); // first open the source file and handle any failures - eResult = OpenSourceFileFB(hSrc, pData->spSrcFile, bNoBuffer); + eResult = OpenSourceFileFB(fileSrc, pData->spSrcFile->GetFullFilePath(), bNoBuffer); if(eResult != TSubTaskBase::eSubResult_Continue) return eResult; - else if(hSrc == INVALID_HANDLE_VALUE) + else if(!fileSrc.IsOpen()) { // invalid handle = operation skipped by user rLocalStats.IncreaseProcessedSize(pData->spSrcFile->GetLength64() - rBasicProgressInfo.GetCurrentFileProcessedSize()); @@ -371,10 +372,10 @@ { // 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->pathDstFile, bNoBuffer, pData->spSrcFile, ullSeekTo, bDstFileFreshlyCreated); + eResult = OpenDestinationFileFB(fileDst, pData->pathDstFile, bNoBuffer, pData->spSrcFile, ullSeekTo, bDstFileFreshlyCreated); if(eResult != TSubTaskBase::eSubResult_Continue) return eResult; - else if(hDst == INVALID_HANDLE_VALUE) + else if(!fileDst.IsOpen()) { rLocalStats.IncreaseProcessedSize(pData->spSrcFile->GetLength64() - rBasicProgressInfo.GetCurrentFileProcessedSize()); pData->bProcessed = false; @@ -384,10 +385,10 @@ else { // we are resuming previous operation - eResult = OpenExistingDestinationFileFB(hDst, pData->pathDstFile, bNoBuffer); + eResult = OpenExistingDestinationFileFB(fileDst, pData->pathDstFile, bNoBuffer); if(eResult != TSubTaskBase::eSubResult_Continue) return eResult; - else if(hDst == INVALID_HANDLE_VALUE) + else if(!fileDst.IsOpen()) { rLocalStats.IncreaseProcessedSize(pData->spSrcFile->GetLength64() - rBasicProgressInfo.GetCurrentFileProcessedSize()); pData->bProcessed = false; @@ -405,7 +406,7 @@ // try to move file pointers to the end ULONGLONG ullMove = (bNoBuffer ? ROUNDDOWN(ullSeekTo, MAXSECTORSIZE) : ullSeekTo); - eResult = SetFilePointerFB(hSrc, ullMove, pData->spSrcFile->GetFullFilePath(), bSkip); + eResult = SetFilePointerFB(fileSrc, ullMove, pData->spSrcFile->GetFullFilePath(), bSkip); if(eResult != TSubTaskBase::eSubResult_Continue) return eResult; else if(bSkip) @@ -415,7 +416,7 @@ return TSubTaskBase::eSubResult_Continue; } - eResult = SetFilePointerFB(hDst, ullMove, pData->pathDstFile, bSkip); + eResult = SetFilePointerFB(fileDst, ullMove, pData->pathDstFile, bSkip); if(eResult != TSubTaskBase::eSubResult_Continue) return eResult; else if(bSkip) @@ -434,7 +435,7 @@ if(!bDstFileFreshlyCreated) { // if destination file was opened (as opposed to newly created) - eResult = SetEndOfFileFB(hDst, pData->pathDstFile, bSkip); + eResult = SetEndOfFileFB(fileDst, pData->pathDstFile, bSkip); if(eResult != TSubTaskBase::eSubResult_Continue) return eResult; else if(bSkip) @@ -507,7 +508,7 @@ ulToRead = bNoBuffer ? ROUNDUP(pData->dbBuffer.GetSizes()->m_auiSizes[iBufferIndex], MAXSECTORSIZE) : pData->dbBuffer.GetSizes()->m_auiSizes[iBufferIndex]; // read data from file to buffer - eResult = ReadFileFB(hSrc, pData->dbBuffer, ulToRead, ulRead, pData->spSrcFile->GetFullFilePath(), bSkip); + eResult = ReadFileFB(fileSrc, pData->dbBuffer, ulToRead, ulRead, pData->spSrcFile->GetFullFilePath(), bSkip); if(eResult != TSubTaskBase::eSubResult_Continue) return eResult; else if(bSkip) @@ -533,7 +534,7 @@ unsigned long ulDataToWrite = ROUNDDOWN(ulRead, MAXSECTORSIZE); if(ulDataToWrite > 0) { - eResult = WriteFileFB(hDst, pData->dbBuffer, ulDataToWrite, ulWritten, pData->pathDstFile, bSkip); + eResult = WriteFileFB(fileDst, pData->dbBuffer, ulDataToWrite, ulWritten, pData->pathDstFile, bSkip); if(eResult != TSubTaskBase::eSubResult_Continue) return eResult; else if(bSkip) @@ -555,24 +556,24 @@ } // close and re-open the destination file with buffering option for append - hDst.Close(); + fileDst.Close(); // are there any more data to be written? 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->pathDstFile, false); + eResult = OpenExistingDestinationFileFB(fileDst, pData->pathDstFile, false); if(eResult != TSubTaskBase::eSubResult_Continue) return eResult; - else if(hDst == INVALID_HANDLE_VALUE) + else if(!fileDst.IsOpen()) { rLocalStats.IncreaseProcessedSize(pData->spSrcFile->GetLength64() - rBasicProgressInfo.GetCurrentFileProcessedSize()); pData->bProcessed = false; return TSubTaskBase::eSubResult_Continue; } // move file pointer to the end of destination file - eResult = SetFilePointerFB(hDst, rBasicProgressInfo.GetCurrentFileProcessedSize(), pData->pathDstFile, bSkip); + eResult = SetFilePointerFB(fileDst, rBasicProgressInfo.GetCurrentFileProcessedSize(), pData->pathDstFile, bSkip); if(eResult != TSubTaskBase::eSubResult_Continue) return eResult; else if(bSkip) @@ -588,7 +589,7 @@ // write if(ulRead != 0) { - eResult = WriteFileFB(hDst, pData->dbBuffer, ulRead, ulWritten, pData->pathDstFile, bSkip); + eResult = WriteFileFB(fileDst, pData->dbBuffer, ulRead, ulWritten, pData->pathDstFile, bSkip); if(eResult != TSubTaskBase::eSubResult_Continue) return eResult; else if(bSkip) @@ -619,31 +620,28 @@ } -TSubTaskBase::ESubOperationResult TSubTaskCopyMove::OpenSourceFileFB(TAutoFileHandle& hOutFile, const CFileInfoPtr& spSrcFileInfo, bool bNoBuffering) +TSubTaskBase::ESubOperationResult TSubTaskCopyMove::OpenSourceFileFB(TLocalFilesystemFile& fileSrc, const chcore::TSmartPath& spPathToOpen, bool bNoBuffering) { chcore::IFeedbackHandler* piFeedbackHandler = GetContext().GetFeedbackHandler(); icpf::log_file& rLog = GetContext().GetLog(); - BOOST_ASSERT(spSrcFileInfo); - if(!spSrcFileInfo) + BOOST_ASSERT(!spPathToOpen.IsEmpty()); + if(spPathToOpen.IsEmpty()) THROW(_T("Invalid argument"), 0, 0, 0); bool bRetry = false; - CString strPath = spSrcFileInfo->GetFullFilePath().ToString(); - hOutFile = INVALID_HANDLE_VALUE; + fileSrc.Close(); - TAutoFileHandle hFile; do { bRetry = false; - hFile = CreateFile(strPath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 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) + if(!fileSrc.OpenExistingForReading(spPathToOpen, bNoBuffering)) { DWORD dwLastError = GetLastError(); - FEEDBACK_FILEERROR feedStruct = { (PCTSTR)strPath, NULL, eCreateError, dwLastError }; + FEEDBACK_FILEERROR feedStruct = { spPathToOpen.ToString(), NULL, eCreateError, dwLastError }; CFeedbackHandler::EFeedbackResult frResult = (CFeedbackHandler::EFeedbackResult)piFeedbackHandler->RequestFeedback(CFeedbackHandler::eFT_FileError, &feedStruct); switch(frResult) @@ -657,7 +655,7 @@ ictranslate::CFormat fmt; fmt.SetFormat(_T("Cancel request [error %errno] while opening source file %path (OpenSourceFileFB)")); fmt.SetParam(_t("%errno"), dwLastError); - fmt.SetParam(_t("%path"), strPath); + fmt.SetParam(_t("%path"), spPathToOpen.ToString()); rLog.loge(fmt); return TSubTaskBase::eSubResult_CancelRequest; @@ -672,7 +670,7 @@ ictranslate::CFormat fmt; fmt.SetFormat(_T("Retrying [error %errno] to open source file %path (OpenSourceFileFB)")); fmt.SetParam(_t("%errno"), dwLastError); - fmt.SetParam(_t("%path"), strPath); + fmt.SetParam(_t("%path"), spPathToOpen.ToString()); rLog.loge(fmt); bRetry = true; @@ -687,40 +685,36 @@ } while(bRetry); - hOutFile = hFile.Detach(); - return TSubTaskBase::eSubResult_Continue; } -TSubTaskBase::ESubOperationResult TSubTaskCopyMove::OpenDestinationFileFB(TAutoFileHandle& hOutFile, const chcore::TSmartPath& pathDstFile, bool bNoBuffering, const CFileInfoPtr& spSrcFileInfo, unsigned long long& ullSeekTo, bool& bFreshlyCreated) +TSubTaskBase::ESubOperationResult TSubTaskCopyMove::OpenDestinationFileFB(TLocalFilesystemFile& fileDst, const chcore::TSmartPath& pathDstFile, bool bNoBuffering, const CFileInfoPtr& spSrcFileInfo, unsigned long long& ullSeekTo, bool& bFreshlyCreated) { chcore::IFeedbackHandler* piFeedbackHandler = GetContext().GetFeedbackHandler(); icpf::log_file& rLog = GetContext().GetLog(); bool bRetry = false; - TAutoFileHandle hFile; ullSeekTo = 0; bFreshlyCreated = true; - hOutFile = INVALID_HANDLE_VALUE; + fileDst.Close(); do { bRetry = false; - 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) + if(!fileDst.CreateNewForWriting(pathDstFile, bNoBuffering)) { DWORD dwLastError = GetLastError(); if(dwLastError == ERROR_FILE_EXISTS) { bFreshlyCreated = false; // pass it to the specialized method - TSubTaskBase::ESubOperationResult eResult = OpenExistingDestinationFileFB(hFile, pathDstFile, bNoBuffering); + TSubTaskBase::ESubOperationResult eResult = OpenExistingDestinationFileFB(fileDst, pathDstFile, bNoBuffering); if(eResult != TSubTaskBase::eSubResult_Continue) return eResult; - else if(hFile == INVALID_HANDLE_VALUE) + else if(!fileDst.IsOpen()) return TSubTaskBase::eSubResult_Continue; // read info about the existing destination file, @@ -814,27 +808,23 @@ } while(bRetry); - hOutFile = hFile.Detach(); - return TSubTaskBase::eSubResult_Continue; } -TSubTaskBase::ESubOperationResult TSubTaskCopyMove::OpenExistingDestinationFileFB(TAutoFileHandle& hOutFile, const chcore::TSmartPath& pathDstFile, bool bNoBuffering) +TSubTaskBase::ESubOperationResult TSubTaskCopyMove::OpenExistingDestinationFileFB(TLocalFilesystemFile& fileDst, const chcore::TSmartPath& pathDstFile, bool bNoBuffering) { chcore::IFeedbackHandler* piFeedbackHandler = GetContext().GetFeedbackHandler(); icpf::log_file& rLog = GetContext().GetLog(); bool bRetry = false; - TAutoFileHandle hFile; - hOutFile = INVALID_HANDLE_VALUE; + fileDst.Close(); do { bRetry = false; - 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) + if(!fileDst.OpenExistingForWriting(pathDstFile, bNoBuffering)) { DWORD dwLastError = GetLastError(); FEEDBACK_FILEERROR feedStruct = { pathDstFile.ToString(), NULL, eCreateError, dwLastError }; @@ -881,12 +871,10 @@ } while(bRetry); - hOutFile = hFile.Detach(); - return TSubTaskBase::eSubResult_Continue; } -TSubTaskBase::ESubOperationResult TSubTaskCopyMove::SetFilePointerFB(HANDLE hFile, long long llDistance, const chcore::TSmartPath& pathFile, bool& bSkip) +TSubTaskBase::ESubOperationResult TSubTaskCopyMove::SetFilePointerFB(TLocalFilesystemFile& file, long long llDistance, const chcore::TSmartPath& pathFile, bool& bSkip) { chcore::IFeedbackHandler* piFeedbackHandler = GetContext().GetFeedbackHandler(); icpf::log_file& rLog = GetContext().GetLog(); @@ -897,7 +885,7 @@ { bRetry = false; - if(SetFilePointer64(hFile, llDistance, FILE_BEGIN) == -1) + if(!file.SetFilePointer(llDistance, FILE_BEGIN)) { DWORD dwLastError = GetLastError(); @@ -939,7 +927,7 @@ return TSubTaskBase::eSubResult_Continue; } -TSubTaskBase::ESubOperationResult TSubTaskCopyMove::SetEndOfFileFB(HANDLE hFile, const chcore::TSmartPath& pathFile, bool& bSkip) +TSubTaskBase::ESubOperationResult TSubTaskCopyMove::SetEndOfFileFB(TLocalFilesystemFile& file, const chcore::TSmartPath& pathFile, bool& bSkip) { chcore::IFeedbackHandler* piFeedbackHandler = GetContext().GetFeedbackHandler(); icpf::log_file& rLog = GetContext().GetLog(); @@ -949,7 +937,7 @@ bool bRetry = false; do { - if(!SetEndOfFile(hFile)) + if(!file.SetEndOfFile()) { // log DWORD dwLastError = GetLastError(); @@ -988,7 +976,7 @@ return TSubTaskBase::eSubResult_Continue; } -TSubTaskBase::ESubOperationResult TSubTaskCopyMove::ReadFileFB(HANDLE hFile, CDataBuffer& rBuffer, DWORD dwToRead, DWORD& rdwBytesRead, const chcore::TSmartPath& pathFile, bool& bSkip) +TSubTaskBase::ESubOperationResult TSubTaskCopyMove::ReadFileFB(TLocalFilesystemFile& file, CDataBuffer& rBuffer, DWORD dwToRead, DWORD& rdwBytesRead, const chcore::TSmartPath& pathFile, bool& bSkip) { chcore::IFeedbackHandler* piFeedbackHandler = GetContext().GetFeedbackHandler(); icpf::log_file& rLog = GetContext().GetLog(); @@ -999,7 +987,7 @@ { bRetry = false; - if(!ReadFile(hFile, rBuffer, dwToRead, &rdwBytesRead, NULL)) + if(!file.ReadFile(rBuffer, dwToRead, rdwBytesRead)) { // log DWORD dwLastError = GetLastError(); @@ -1040,7 +1028,7 @@ return TSubTaskBase::eSubResult_Continue; } -TSubTaskBase::ESubOperationResult TSubTaskCopyMove::WriteFileFB(HANDLE hFile, CDataBuffer& rBuffer, DWORD dwToWrite, DWORD& rdwBytesWritten, const chcore::TSmartPath& pathFile, bool& bSkip) +TSubTaskBase::ESubOperationResult TSubTaskCopyMove::WriteFileFB(TLocalFilesystemFile& file, CDataBuffer& rBuffer, DWORD dwToWrite, DWORD& rdwBytesWritten, const chcore::TSmartPath& pathFile, bool& bSkip) { chcore::IFeedbackHandler* piFeedbackHandler = GetContext().GetFeedbackHandler(); icpf::log_file& rLog = GetContext().GetLog(); @@ -1052,7 +1040,7 @@ { bRetry = false; - if(!WriteFile(hFile, rBuffer, dwToWrite, &rdwBytesWritten, NULL) || dwToWrite != rdwBytesWritten) + if(!file.WriteFile(rBuffer, dwToWrite, rdwBytesWritten)) { // log DWORD dwLastError = GetLastError(); Index: src/ch/TSubTaskCopyMove.h =================================================================== diff -u -N -r28b540c17739ad8b63f3b199e0e2151ec048bd05 -r7749d67cd70821fef9cc51303d42625fbcc2aa9d --- src/ch/TSubTaskCopyMove.h (.../TSubTaskCopyMove.h) (revision 28b540c17739ad8b63f3b199e0e2151ec048bd05) +++ src/ch/TSubTaskCopyMove.h (.../TSubTaskCopyMove.h) (revision 7749d67cd70821fef9cc51303d42625fbcc2aa9d) @@ -28,6 +28,7 @@ struct CUSTOM_COPY_PARAMS; class TAutoFileHandle; class CDataBuffer; +class TLocalFilesystemFile; class TSubTaskCopyMove : public TSubTaskBase { @@ -42,15 +43,15 @@ ESubOperationResult CustomCopyFileFB(CUSTOM_COPY_PARAMS* pData); - ESubOperationResult OpenSourceFileFB(TAutoFileHandle& hFile, const CFileInfoPtr& spSrcFileInfo, 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 OpenSourceFileFB(TLocalFilesystemFile& fileSrc, const chcore::TSmartPath& spPathToOpen, bool bNoBuffering); + ESubOperationResult OpenDestinationFileFB(TLocalFilesystemFile& fileDst, const chcore::TSmartPath& pathDstFile, bool bNoBuffering, const CFileInfoPtr& spSrcFileInfo, unsigned long long& ullSeekTo, bool& bFreshlyCreated); + ESubOperationResult OpenExistingDestinationFileFB(TLocalFilesystemFile& fileDst, const chcore::TSmartPath& pathDstFilePath, bool bNoBuffering); - ESubOperationResult SetFilePointerFB(HANDLE hFile, long long llDistance, const chcore::TSmartPath& pathFile, bool& bSkip); - ESubOperationResult SetEndOfFileFB(HANDLE hFile, const chcore::TSmartPath& pathFile, bool& bSkip); + ESubOperationResult SetFilePointerFB(TLocalFilesystemFile& file, long long llDistance, const chcore::TSmartPath& pathFile, bool& bSkip); + ESubOperationResult SetEndOfFileFB(TLocalFilesystemFile& file, const chcore::TSmartPath& pathFile, 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 ReadFileFB(TLocalFilesystemFile& file, CDataBuffer& rBuffer, DWORD dwToRead, DWORD& rdwBytesRead, const chcore::TSmartPath& pathFile, bool& bSkip); + ESubOperationResult WriteFileFB(TLocalFilesystemFile& file, CDataBuffer& rBuffer, DWORD dwToWrite, DWORD& rdwBytesWritten, const chcore::TSmartPath& pathFile, bool& bSkip); ESubOperationResult CreateDirectoryFB(const chcore::TSmartPath& pathDirectory); }; Index: src/ch/TSubTaskScanDirectory.cpp =================================================================== diff -u -N -r1456ff2ae4a98c83f18d20dc253a24f26ddf521d -r7749d67cd70821fef9cc51303d42625fbcc2aa9d --- src/ch/TSubTaskScanDirectory.cpp (.../TSubTaskScanDirectory.cpp) (revision 1456ff2ae4a98c83f18d20dc253a24f26ddf521d) +++ src/ch/TSubTaskScanDirectory.cpp (.../TSubTaskScanDirectory.cpp) (revision 7749d67cd70821fef9cc51303d42625fbcc2aa9d) @@ -218,8 +218,7 @@ TTaskDefinition& rTaskDefinition = GetContext().GetTaskDefinition(); TWorkerThreadController& rThreadController = GetContext().GetThreadController(); -// pathCurrent = pathDirName + chcore::PathFromString(_T("*")); - TLocalFilesystemFind finder = TLocalFilesystem::CreateFinder(pathDirName, chcore::PathFromString(_T("*"))); + TLocalFilesystemFind finder = TLocalFilesystem::CreateFinderObject(pathDirName, chcore::PathFromString(_T("*"))); CFileInfoPtr spFileInfo(boost::make_shared()); while(finder.FindNext(spFileInfo))