Enable security checks and features
[TortoiseGit.git] / src / TortoiseProc / Commands / CleanupCommand.cpp
blob824ce1d794e9356c4f5481f325db5ed72f8efdb5
1 // TortoiseSVN - a Windows shell extension for easy version control
3 // Copyright (C) 2007-2008 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "StdAfx.h"
20 #include "CleanupCommand.h"
22 #include "MessageBox.h"
23 #include "ProgressDlg.h"
24 #include "Git.h"
25 //#include "GitGlobal.h"
26 #include "GitAdminDir.h"
27 #include "DirFileEnum.h"
28 #include "ShellUpdater.h"
29 #include "CleanTypeDlg.h"
31 bool CleanupCommand::Execute()
33 bool bRet = false;
35 CCleanTypeDlg dlg;
36 if( dlg.DoModal() == IDOK)
38 CProgressDlg progress;
39 CString cmd;
40 cmd.Format(_T("git clean "));
41 if(dlg.m_bDir)
42 cmd += _T(" -d ");
43 switch(dlg.m_CleanType)
45 case 0:
46 cmd += _T(" -fx");
47 break;
48 case 1:
49 cmd += _T(" -f");
50 break;
51 case 2:
52 cmd += _T(" -fX");
53 break;
56 for(int i=0;i<this->pathList.GetCount();i++)
58 CString path;
59 if(this->pathList[i].IsDirectory())
60 path = pathList[i].GetGitPathString();
61 else
62 path = pathList[i].GetContainingDirectory().GetGitPathString();
64 progress.m_GitCmdList.push_back(cmd + _T(" \"") + path + _T("\""));
67 if(progress.DoModal()==IDOK)
68 return TRUE;
70 #if 0
71 CProgressDlg progress;
72 progress.SetTitle(IDS_PROC_CLEANUP);
73 progress.SetAnimation(IDR_CLEANUPANI);
74 progress.SetShowProgressBar(false);
75 progress.SetLine(1, CString(MAKEINTRESOURCE(IDS_PROC_CLEANUP_INFO1)));
76 progress.SetLine(2, CString(MAKEINTRESOURCE(IDS_PROC_CLEANUP_INFO2)));
77 progress.ShowModeless(hwndExplorer);
79 CString strSuccessfullPaths, strFailedPaths;
80 for (int i=0; i<pathList.GetCount(); ++i)
82 SVN svn;
83 if (!svn.CleanUp(pathList[i]))
85 strFailedPaths += _T("- ") + pathList[i].GetWinPathString() + _T("\n");
86 strFailedPaths += svn.GetLastErrorMessage() + _T("\n\n");
88 else
90 strSuccessfullPaths += _T("- ") + pathList[i].GetWinPathString() + _T("\n");
92 // after the cleanup has finished, crawl the path downwards and send a change
93 // notification for every directory to the shell. This will update the
94 // overlays in the left tree view of the explorer.
95 CDirFileEnum crawler(pathList[i].GetWinPathString());
96 CString sPath;
97 bool bDir = false;
98 CTSVNPathList updateList;
99 while (crawler.NextFile(sPath, &bDir))
101 if ((bDir) && (!g_SVNAdminDir.IsAdminDirPath(sPath)))
103 updateList.AddPath(CTSVNPath(sPath));
106 updateList.AddPath(pathList[i]);
107 CShellUpdater::Instance().AddPathsForUpdate(updateList);
108 CShellUpdater::Instance().Flush();
109 updateList.SortByPathname(true);
110 for (INT_PTR i=0; i<updateList.GetCount(); ++i)
112 SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, updateList[i].GetWinPath(), NULL);
113 ATLTRACE(_T("notify change for path %s\n"), updateList[i].GetWinPath());
117 progress.Stop();
119 CString strMessage;
120 if ( !strSuccessfullPaths.IsEmpty() )
122 CString tmp;
123 tmp.Format(IDS_PROC_CLEANUPFINISHED, (LPCTSTR)strSuccessfullPaths);
124 strMessage += tmp;
125 bRet = true;
127 if ( !strFailedPaths.IsEmpty() )
129 if (!strMessage.IsEmpty())
130 strMessage += _T("\n");
131 CString tmp;
132 tmp.Format(IDS_PROC_CLEANUPFINISHED_FAILED, (LPCTSTR)strFailedPaths);
133 strMessage += tmp;
134 bRet = false;
136 CMessageBox::Show(hwndExplorer, strMessage, _T("TortoiseGit"), MB_OK | (strFailedPaths.IsEmpty()?MB_ICONINFORMATION:MB_ICONERROR));
137 #endif
138 CShellUpdater::Instance().Flush();
139 return bRet;