Index: src/ch/FileInfo.cpp =================================================================== diff -u -N -r16a61d123d45e60dea731a6620f6f47acccd8c43 -r3f33c90e9e49ccf7b52b604e849ba8be5be1dba7 --- src/ch/FileInfo.cpp (.../FileInfo.cpp) (revision 16a61d123d45e60dea731a6620f6f47acccd8c43) +++ src/ch/FileInfo.cpp (.../FileInfo.cpp) (revision 3f33c90e9e49ccf7b52b604e849ba8be5be1dba7) @@ -16,13 +16,8 @@ * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -/************************************************************************* - FileInfo.cpp: implementation of the CFileInfo class. - (c) Codeguru & friends - Coded by Antonio Tejada Lacaci. 1999, modified by Ixen Gerthannes - atejada@espanet.com -*************************************************************************/ - +// File was originally based on FileInfo.cpp by Antonio Tejada Lacaci. +// Almost everything has changed since then. #include "stdafx.h" #include "FileInfo.h" #include "FileFilter.h" @@ -39,46 +34,6 @@ #define new DEBUG_NEW #endif -void GetDriveData(const chcore::TSmartPath& spPath, int* piDrvNum, UINT* puiDrvType) -{ - TCHAR drv[_MAX_DRIVE+1]; - - _tsplitpath(spPath.ToString(), drv, NULL, NULL, NULL); - if(lstrlen(drv) != 0) - { - // add '\\' - lstrcat(drv, _T("\\")); - _tcsupr(drv); - - // disk number - if(piDrvNum) - *piDrvNum=drv[0]-_T('A'); - - // disk type - if(puiDrvType) - { - *puiDrvType=GetDriveType(drv); - if(*puiDrvType == DRIVE_NO_ROOT_DIR) - *puiDrvType=DRIVE_UNKNOWN; - } - } - else - { - // there's no disk in a path - if(piDrvNum) - *piDrvNum=-1; - - if(puiDrvType) - { - // check for unc path - if(_tcsncmp(spPath.ToString(), _T("\\\\"), 2) == 0) - *puiDrvType=DRIVE_REMOTE; - else - *puiDrvType=DRIVE_UNKNOWN; - } - } -} - ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// @@ -113,30 +68,6 @@ { } -bool CFileInfo::Exist(chcore::TSmartPath pathToCheck) -{ - WIN32_FIND_DATA fd; - - // search by exact name - HANDLE hFind = FindFirstFile(pathToCheck.ToString(), &fd); - if(hFind != INVALID_HANDLE_VALUE) - return true; - - // another try (add '\\' if needed and '*' for marking that we look for ie. c:\* - // instead of c:\, which would never be found prev. way) - pathToCheck.AppendIfNotExists(_T("\\"), false); - pathToCheck.AppendIfNotExists(_T("*"), false); - - hFind = FindFirstFile(pathToCheck.ToString(), &fd); - if(hFind != INVALID_HANDLE_VALUE) - { - ::FindClose(hFind); - return true; - } - else - return false; -} - void CFileInfo::Create(const WIN32_FIND_DATA* pwfd, const chcore::TSmartPath& pathFile, size_t stSrcIndex) { BOOST_ASSERT(stSrcIndex == std::numeric_limits::max() || m_pBasePaths); Index: src/ch/FileInfo.h =================================================================== diff -u -N -r16a61d123d45e60dea731a6620f6f47acccd8c43 -r3f33c90e9e49ccf7b52b604e849ba8be5be1dba7 --- src/ch/FileInfo.h (.../FileInfo.h) (revision 16a61d123d45e60dea731a6620f6f47acccd8c43) +++ src/ch/FileInfo.h (.../FileInfo.h) (revision 3f33c90e9e49ccf7b52b604e849ba8be5be1dba7) @@ -24,8 +24,6 @@ #include "../libchcore/TPath.h" -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) #define FIF_PROCESSED 0x00000001 @@ -39,9 +37,6 @@ CFileInfo(const CFileInfo& finf); ~CFileInfo(); - // static member - static bool Exist(chcore::TSmartPath strPath); // check for file or folder existence - void Create(const WIN32_FIND_DATA* pwfd, const chcore::TSmartPath& tFilePath, size_t stSrcIndex); bool Create(const chcore::TSmartPath& strFilePath, size_t stSrcIndex); Index: src/ch/task.cpp =================================================================== diff -u -N -r16a61d123d45e60dea731a6620f6f47acccd8c43 -r3f33c90e9e49ccf7b52b604e849ba8be5be1dba7 --- src/ch/task.cpp (.../task.cpp) (revision 16a61d123d45e60dea731a6620f6f47acccd8c43) +++ src/ch/task.cpp (.../task.cpp) (revision 3f33c90e9e49ccf7b52b604e849ba8be5be1dba7) @@ -1148,7 +1148,7 @@ // don't add folder contents when moving inside one disk boundary if(bIgnoreDirs || !bMove || iDestDrvNumber == -1 || iDestDrvNumber != GetDriveNumber(spFileInfo) || - CFileInfo::Exist(GetDestinationPath(spFileInfo, m_tTaskDefinition.GetDestinationPath(), ((int)bForceDirectories) << 1)) ) + PathExist(GetDestinationPath(spFileInfo, m_tTaskDefinition.GetDestinationPath(), ((int)bForceDirectories) << 1)) ) { // log fmt.SetFormat(_T("Recursing folder %path")); @@ -1173,7 +1173,7 @@ else { if(bMove && iDestDrvNumber != -1 && iDestDrvNumber == GetDriveNumber(spFileInfo) && - !CFileInfo::Exist(GetDestinationPath(spFileInfo, m_tTaskDefinition.GetDestinationPath(), ((int)bForceDirectories) << 1)) ) + !PathExist(GetDestinationPath(spFileInfo, m_tTaskDefinition.GetDestinationPath(), ((int)bForceDirectories) << 1)) ) { // if moving within one partition boundary set the file size to 0 so the overall size will // be ok @@ -2604,7 +2604,7 @@ // 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)) + while(PathExist(pathDstPath + pathCheckPath)) { fmt.SetFormat(strFmt); fmt.SetParam(_t("%name"), pathLastComponent.ToString()); @@ -2744,6 +2744,71 @@ return spPathData->GetMove(); } + +void CTask::GetDriveData(const chcore::TSmartPath& spPath, int* piDrvNum, UINT* puiDrvType) +{ + TCHAR drv[_MAX_DRIVE+1]; + + _tsplitpath(spPath.ToString(), drv, NULL, NULL, NULL); + if(lstrlen(drv) != 0) + { + // add '\\' + lstrcat(drv, _T("\\")); + _tcsupr(drv); + + // disk number + if(piDrvNum) + *piDrvNum=drv[0]-_T('A'); + + // disk type + if(puiDrvType) + { + *puiDrvType=GetDriveType(drv); + if(*puiDrvType == DRIVE_NO_ROOT_DIR) + *puiDrvType=DRIVE_UNKNOWN; + } + } + else + { + // there's no disk in a path + if(piDrvNum) + *piDrvNum=-1; + + if(puiDrvType) + { + // check for unc path + if(_tcsncmp(spPath.ToString(), _T("\\\\"), 2) == 0) + *puiDrvType=DRIVE_REMOTE; + else + *puiDrvType=DRIVE_UNKNOWN; + } + } +} + +bool CTask::PathExist(chcore::TSmartPath pathToCheck) +{ + WIN32_FIND_DATA fd; + + // search by exact name + HANDLE hFind = FindFirstFile(pathToCheck.ToString(), &fd); + if(hFind != INVALID_HANDLE_VALUE) + return true; + + // another try (add '\\' if needed and '*' for marking that we look for ie. c:\* + // instead of c:\, which would never be found prev. way) + pathToCheck.AppendIfNotExists(_T("\\"), false); + pathToCheck.AppendIfNotExists(_T("*"), false); + + hFind = FindFirstFile(pathToCheck.ToString(), &fd); + if(hFind != INVALID_HANDLE_VALUE) + { + ::FindClose(hFind); + return true; + } + else + return false; +} + //////////////////////////////////////////////////////////////////////////////// // CTaskArray members CTaskArray::CTaskArray() : Index: src/ch/task.h =================================================================== diff -u -N -r16a61d123d45e60dea731a6620f6f47acccd8c43 -r3f33c90e9e49ccf7b52b604e849ba8be5be1dba7 --- src/ch/task.h (.../task.h) (revision 16a61d123d45e60dea731a6620f6f47acccd8c43) +++ src/ch/task.h (.../task.h) (revision 3f33c90e9e49ccf7b52b604e849ba8be5be1dba7) @@ -401,6 +401,9 @@ int GetDriveNumber(const CFileInfoPtr& spFileInfo); bool GetMove(const CFileInfoPtr& spFileInfo); + static void GetDriveData(const chcore::TSmartPath& spPath, int *piDrvNum, UINT *puiDrvType); + static bool PathExist(chcore::TSmartPath strPath); // check for file or folder existence + private: // task initial information (needed to start a task); might be a bit processed. TTaskDefinition m_tTaskDefinition;