Cleanup
[TortoiseGit.git] / src / TortoiseProc / Commands / DropCopyCommand.cpp
blobff24256edc690de186fe919d3b900cf7a51fd788
1 // TortoiseGit - 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 "DropCopyCommand.h"
22 #include "SysProgressDlg.h"
23 #include "SysProgressDlg.h"
24 #include "MessageBox.h"
25 #include "RenameDlg.h"
26 #include "Git.h"
27 #include "ShellUpdater.h"
29 bool DropCopyCommand::Execute()
32 CString sDroppath = parser.GetVal(_T("droptarget"));
33 if (CTGitPath(sDroppath).IsAdminDir())
35 CMessageBox::Show(NULL,_T("Can't drop to .git repository directory\n"),
36 _T("TortoiseGit"),MB_OK|MB_ICONERROR);
37 return FALSE;
39 unsigned long count = 0;
41 CString sNewName;
42 pathList.RemoveAdminPaths();
43 if ((parser.HasKey(_T("rename")))&&(pathList.GetCount()==1))
45 // ask for a new name of the source item
48 CRenameDlg renDlg;
49 renDlg.m_windowtitle.LoadString(IDS_PROC_COPYRENAME);
50 renDlg.m_name = pathList[0].GetFileOrDirectoryName();
51 if (renDlg.DoModal() != IDOK)
53 return FALSE;
55 sNewName = renDlg.m_name;
56 } while(sNewName.IsEmpty() || PathFileExists(sDroppath+_T("\\")+sNewName));
58 CSysProgressDlg progress;
59 progress.SetTitle(IDS_PROC_COPYING);
60 progress.SetAnimation(IDR_MOVEANI);
61 progress.SetTime(true);
62 progress.ShowModeless(CWnd::FromHandle(hwndExplorer));
63 for(int nPath = 0; nPath < pathList.GetCount(); nPath++)
65 const CTGitPath& sourcePath = orgPathList[nPath];
67 CTGitPath fullDropPath(sDroppath);
69 if (sNewName.IsEmpty())
70 fullDropPath.AppendPathString(sourcePath.GetFileOrDirectoryName());
71 else
72 fullDropPath.AppendPathString(sNewName);
74 // Check for a drop-on-to-ourselves
75 if (sourcePath.IsEquivalentTo(fullDropPath))
77 // Offer a rename
78 progress.Stop();
79 CRenameDlg dlg;
80 dlg.m_windowtitle.Format(IDS_PROC_NEWNAMECOPY, (LPCTSTR)sourcePath.GetUIFileOrDirectoryName());
81 if (dlg.DoModal() != IDOK)
83 return FALSE;
85 // rebuild the progress dialog
86 progress.EnsureValid();
87 progress.SetTitle(IDS_PROC_COPYING);
88 progress.SetAnimation(IDR_MOVEANI);
89 progress.SetTime(true);
90 progress.SetProgress(count, pathList.GetCount());
91 progress.ShowModeless(CWnd::FromHandle(hwndExplorer));
92 // Rebuild the destination path, with the new name
93 fullDropPath.SetFromUnknown(sDroppath);
94 fullDropPath.AppendPathString(dlg.m_name);
97 if( CopyFile( sourcePath.GetWinPath(), fullDropPath.GetWinPath(), true))
99 CString ProjectTopDir;
100 if(fullDropPath.HasAdminDir(&ProjectTopDir))
102 g_Git.SetCurrentDir(ProjectTopDir);
103 SetCurrentDirectory(ProjectTopDir);
104 CString cmd;
105 cmd = _T("git.exe add \"");
107 CString path;
108 path=fullDropPath.GetGitPathString().Mid(ProjectTopDir.GetLength());
109 if(path.GetLength()>0)
110 if(path[0]==_T('\\') || path[0]==_T('/'))
111 path=path.Mid(1);
112 cmd += path;
113 cmd +=_T('\"');
115 CString output;
116 if (g_Git.Run(cmd, &output, CP_UTF8))
118 CMessageBox::Show(NULL, output, _T("TortoiseGit"), MB_OK|MB_ICONERROR);
119 }else
120 CShellUpdater::Instance().AddPathForUpdate(fullDropPath);
123 }else
125 CString str;
126 str+=_T("Copy file fail:");
127 str+=sourcePath.GetWinPath();
129 CMessageBox::Show(NULL, str, _T("TortoiseGit"), MB_OK|MB_ICONERROR);
132 count++;
133 if (progress.IsValid())
135 progress.FormatPathLine(1, IDS_PROC_COPYINGPROG, sourcePath.GetWinPath());
136 progress.FormatPathLine(2, IDS_PROC_CPYMVPROG2, fullDropPath.GetWinPath());
137 progress.SetProgress(count, pathList.GetCount());
139 if ((progress.IsValid())&&(progress.HasUserCancelled()))
141 CMessageBox::Show(hwndExplorer, IDS_SVN_USERCANCELLED, IDS_APPNAME, MB_ICONINFORMATION);
142 return false;
146 return true;