Includes cleanup
[TortoiseGit.git] / src / TortoiseProc / Commands / DropCopyCommand.cpp
blobc3537451cf5e8662ab6d240dd8ace776d04dd945
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2013, 2015 - TortoiseGit
4 // Copyright (C) 2007-2008 - 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 "DropCopyCommand.h"
22 #include "SysProgressDlg.h"
23 #include "MessageBox.h"
24 #include "RenameDlg.h"
25 #include "Git.h"
26 #include "ShellUpdater.h"
28 bool DropCopyCommand::Execute()
31 CString sDroppath = parser.GetVal(_T("droptarget"));
32 if (CTGitPath(sDroppath).IsAdminDir())
34 CMessageBox::Show(NULL,_T("Can't drop to .git repository directory\n"),
35 _T("TortoiseGit"),MB_OK|MB_ICONERROR);
36 return FALSE;
38 unsigned long count = 0;
40 CString sNewName;
41 pathList.RemoveAdminPaths();
42 if ((parser.HasKey(_T("rename")))&&(pathList.GetCount()==1))
44 // ask for a new name of the source item
47 CRenameDlg renDlg;
48 renDlg.m_windowtitle.LoadString(IDS_PROC_COPYRENAME);
49 renDlg.m_name = pathList[0].GetFileOrDirectoryName();
50 if (renDlg.DoModal() != IDOK)
52 return FALSE;
54 sNewName = renDlg.m_name;
55 } while(sNewName.IsEmpty() || PathFileExists(sDroppath+_T("\\")+sNewName));
57 CSysProgressDlg progress;
58 progress.SetTitle(IDS_PROC_COPYING);
59 progress.SetAnimation(IDR_MOVEANI);
60 progress.SetTime(true);
61 progress.ShowModeless(CWnd::FromHandle(hwndExplorer));
62 for (int nPath = 0; nPath < pathList.GetCount(); ++nPath)
64 const CTGitPath& sourcePath = orgPathList[nPath];
66 CTGitPath fullDropPath(sDroppath);
68 if (sNewName.IsEmpty())
69 fullDropPath.AppendPathString(sourcePath.GetFileOrDirectoryName());
70 else
71 fullDropPath.AppendPathString(sNewName);
73 // Check for a drop-on-to-ourselves
74 if (sourcePath.IsEquivalentTo(fullDropPath))
76 // Offer a rename
77 progress.Stop();
78 CRenameDlg dlg;
79 dlg.m_windowtitle.Format(IDS_PROC_NEWNAMECOPY, (LPCTSTR)sourcePath.GetUIFileOrDirectoryName());
80 if (dlg.DoModal() != IDOK)
82 return FALSE;
84 // rebuild the progress dialog
85 progress.EnsureValid();
86 progress.SetTitle(IDS_PROC_COPYING);
87 progress.SetAnimation(IDR_MOVEANI);
88 progress.SetTime(true);
89 progress.SetProgress(count, pathList.GetCount());
90 progress.ShowModeless(CWnd::FromHandle(hwndExplorer));
91 // Rebuild the destination path, with the new name
92 fullDropPath.SetFromUnknown(sDroppath);
93 fullDropPath.AppendPathString(dlg.m_name);
96 if( CopyFile( sourcePath.GetWinPath(), fullDropPath.GetWinPath(), true))
98 CString ProjectTopDir;
99 if(fullDropPath.HasAdminDir(&ProjectTopDir))
101 g_Git.SetCurrentDir(ProjectTopDir);
102 SetCurrentDirectory(ProjectTopDir);
103 CString cmd;
104 cmd = _T("git.exe add -- \"");
106 CString path;
107 path=fullDropPath.GetGitPathString().Mid(ProjectTopDir.GetLength());
108 if(path.GetLength()>0)
109 if(path[0]==_T('\\') || path[0]==_T('/'))
110 path=path.Mid(1);
111 cmd += path;
112 cmd +=_T('\"');
114 CString output;
115 if (g_Git.Run(cmd, &output, CP_UTF8))
117 CMessageBox::Show(NULL, output, _T("TortoiseGit"), MB_OK|MB_ICONERROR);
118 }else
119 CShellUpdater::Instance().AddPathForUpdate(fullDropPath);
122 }else
124 CString str;
125 str+=_T("Copy file fail:");
126 str+=sourcePath.GetWinPath();
128 CMessageBox::Show(NULL, str, _T("TortoiseGit"), MB_OK|MB_ICONERROR);
131 ++count;
132 if (progress.IsValid())
134 progress.FormatPathLine(1, IDS_PROC_COPYINGPROG, sourcePath.GetWinPath());
135 progress.FormatPathLine(2, IDS_PROC_CPYMVPROG2, fullDropPath.GetWinPath());
136 progress.SetProgress(count, pathList.GetCount());
138 if ((progress.IsValid())&&(progress.HasUserCancelled()))
140 CMessageBox::Show(hwndExplorer, IDS_SVN_USERCANCELLED, IDS_APPNAME, MB_ICONINFORMATION);
141 return false;
145 return true;