GitProgressDlg: Move most part of function to GitProgressList
[TortoiseGit.git] / src / TortoiseProc / Commands / DropCopyAddCommand.cpp
blob404448d822cc947e609a18b5809d16e7ee3edd35
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2011,2013 - TortoiseGit
4 // Copyright (C) 2007-2008,2010 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "stdafx.h"
21 #include "DropCopyAddCommand.h"
22 #include "FormatMessageWrapper.h"
23 #include "GITProgressDlg.h"
24 #include "MessageBox.h"
26 bool DropCopyAddCommand::Execute()
28 bool bRet = false;
30 CString droppath = parser.GetVal(_T("droptarget"));
31 if (CTGitPath(droppath).IsAdminDir())
32 return FALSE;
34 if(!CTGitPath(droppath).HasAdminDir(&g_Git.m_CurrentDir))
35 return FALSE;
37 orgPathList.RemoveAdminPaths();
38 CTGitPathList copiedFiles;
39 for (int nPath = 0; nPath < orgPathList.GetCount(); ++nPath)
41 if (!orgPathList[nPath].IsEquivalentTo(CTGitPath(droppath)))
43 //copy the file to the new location
44 CString name = orgPathList[nPath].GetFileOrDirectoryName();
45 if (::PathFileExists(droppath+_T("\\")+name))
47 CString strMessage;
48 strMessage.Format(IDS_PROC_OVERWRITE_CONFIRM, (LPCTSTR)(droppath+_T("\\")+name));
49 int ret = CMessageBox::Show(hwndExplorer, strMessage, _T("TortoiseGit"), MB_YESNOCANCEL | MB_ICONQUESTION);
50 if (ret == IDYES)
52 if (!::CopyFile(orgPathList[nPath].GetWinPath(), droppath+_T("\\")+name, FALSE))
54 //the copy operation failed! Get out of here!
55 ShowErrorMessage();
56 return FALSE;
59 if (ret == IDCANCEL)
61 return FALSE; //cancel the whole operation
64 else if (!CopyFile(orgPathList[nPath].GetWinPath(), droppath+_T("\\")+name, FALSE))
66 //the copy operation failed! Get out of here!
67 ShowErrorMessage();
68 return FALSE;
70 copiedFiles.AddPath(CTGitPath(droppath+_T("\\")+name)); //add the new filepath
73 //now add all the newly copied files to the working copy
74 CGitProgressDlg progDlg;
75 theApp.m_pMainWnd = &progDlg;
76 progDlg.SetCommand(CGitProgressList::GitProgress_Add);
77 if (parser.HasVal(_T("closeonend")))
78 progDlg.SetAutoClose(parser.GetLongVal(_T("closeonend")));
79 progDlg.SetPathList(copiedFiles);
80 ProjectProperties props;
81 props.ReadPropsPathList(copiedFiles);
82 progDlg.SetProjectProperties(props);
83 progDlg.DoModal();
84 bRet = !progDlg.DidErrorsOccur();
86 return bRet;
89 void DropCopyAddCommand::ShowErrorMessage()
91 CString strMessage;
92 strMessage.Format(IDS_ERR_COPYFILES, CFormatMessageWrapper());
93 MessageBox(hwndExplorer, strMessage, _T("TortoiseGit"), MB_OK | MB_ICONINFORMATION);