OSDN Git Service

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