From 1a7d150dda64c56f924ba8f32e5a230979734160 Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Sat, 9 Jun 2012 21:19:06 +0200 Subject: [PATCH] CTGitPath: refactored, remove duplicate code Signed-off-by: Sven Strickroth --- src/Git/TGitPath.cpp | 59 +++++++++++++++++++++------------------------------- src/Git/TGitPath.h | 1 + 2 files changed, 25 insertions(+), 35 deletions(-) diff --git a/src/Git/TGitPath.cpp b/src/Git/TGitPath.cpp index cc868bf42..daed128e2 100644 --- a/src/Git/TGitPath.cpp +++ b/src/Git/TGitPath.cpp @@ -371,13 +371,7 @@ bool CTGitPath::Delete(bool bTrash) const _tcscpy_s(buf, m_sBackslashPath.GetLength()+2, m_sBackslashPath); buf[m_sBackslashPath.GetLength()] = 0; buf[m_sBackslashPath.GetLength()+1] = 0; - SHFILEOPSTRUCT shop = {0}; - shop.wFunc = FO_DELETE; - shop.pFrom = buf; - shop.fFlags = FOF_NOCONFIRMATION|FOF_NOERRORUI|FOF_SILENT; - if (bTrash) - shop.fFlags |= FOF_ALLOWUNDO; - bRet = (SHFileOperation(&shop) == 0); + bRet = CTGitPathList::DeleteViaShell(buf, bTrash); delete [] buf; } else @@ -1543,41 +1537,36 @@ void CTGitPathList::SortByPathname(bool bReverse /*= false*/) void CTGitPathList::DeleteAllFiles(bool bTrash) { PathVector::const_iterator it; - if (bTrash) - { - SortByPathname(true); // nested ones first - CString sPaths; - for (it = m_paths.begin(); it != m_paths.end(); ++it) - { - if ((it->Exists())&&(!it->IsDirectory())) - { - ::SetFileAttributes(it->GetWinPath(), FILE_ATTRIBUTE_NORMAL); - sPaths += it->GetWinPath(); - sPaths += '\0'; - } - } - sPaths += '\0'; - sPaths += '\0'; - SHFILEOPSTRUCT shop = {0}; - shop.wFunc = FO_DELETE; - shop.pFrom = (LPCTSTR)sPaths; - shop.fFlags = FOF_ALLOWUNDO|FOF_NOCONFIRMATION|FOF_NOERRORUI|FOF_SILENT; - SHFileOperation(&shop); - } - else + SortByPathname(true); // nested ones first + + CString sPaths; + for (it = m_paths.begin(); it != m_paths.end(); ++it) { - for (it = m_paths.begin(); it != m_paths.end(); ++it) + if ((it->Exists())&&(!it->IsDirectory())) { - if (!it->IsDirectory()) - { - ::SetFileAttributes(it->GetWinPath(), FILE_ATTRIBUTE_NORMAL); - ::DeleteFile(it->GetWinPath()); - } + ::SetFileAttributes(it->GetWinPath(), FILE_ATTRIBUTE_NORMAL); + sPaths += it->GetWinPath(); + sPaths += '\0'; } } + sPaths += '\0'; + sPaths += '\0'; + DeleteViaShell((LPCTSTR)sPaths, bTrash); Clear(); } +bool CTGitPathList::DeleteViaShell(LPCTSTR path, bool bTrash) +{ + SHFILEOPSTRUCT shop = {0}; + shop.wFunc = FO_DELETE; + shop.pFrom = path; + shop.fFlags = FOF_NOCONFIRMATION|FOF_NOERRORUI|FOF_SILENT|FOF_NO_CONNECTED_ELEMENTS; + if (bTrash) + shop.fFlags |= FOF_ALLOWUNDO; + const bool bRet = (SHFileOperation(&shop) == 0); + return bRet; +} + void CTGitPathList::RemoveDuplicates() { SortByPathname(); diff --git a/src/Git/TGitPath.h b/src/Git/TGitPath.h index 6227314d8..882a36a4b 100644 --- a/src/Git/TGitPath.h +++ b/src/Git/TGitPath.h @@ -392,6 +392,7 @@ public: * \param bTrash if true, the items are deleted using the Windows trash bin */ void DeleteAllFiles(bool bTrash); + static bool DeleteViaShell(LPCTSTR path, bool useTrashbin); /** Remove duplicate entries from the list (sorts the list as a side-effect */ void RemoveDuplicates(); /** Removes all paths which are on or in a Subversion admin directory */ -- 2.11.4.GIT