OSDN Git Service

Build TortoisProc is okay
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / Commands / PasteMoveCommand.cpp
1 // TortoiseGit - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2008 - TortoiseGit\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 "PasteMoveCommand.h"\r
21 \r
22 #include "SysProgressDlg.h"\r
23 #include "MessageBox.h"\r
24 #include "Git.h"\r
25 #include "GitStatus.h"\r
26 #include "RenameDlg.h"\r
27 #include "ShellUpdater.h"\r
28 #include "ProjectProperties.h"\r
29 #include "CommonResource.h"\r
30 \r
31 bool PasteMoveCommand::Execute()\r
32 {\r
33         CString sDroppath = parser.GetVal(_T("droptarget"));\r
34         CTGitPath dropPath(sDroppath);\r
35         ProjectProperties props;\r
36         props.ReadProps(dropPath);\r
37         if (dropPath.IsAdminDir())\r
38                 return FALSE;\r
39 \r
40         if(!dropPath.HasAdminDir(&g_Git.m_CurrentDir))\r
41                 return FALSE;\r
42 \r
43         GitStatus status;\r
44         unsigned long count = 0;\r
45         orgPathList.RemoveAdminPaths();\r
46         CString sNewName;\r
47         CSysProgressDlg progress;\r
48         progress.SetTitle(IDS_PROC_MOVING);\r
49         progress.SetAnimation(IDR_MOVEANI);\r
50         progress.SetTime(true);\r
51         progress.ShowModeless(CWnd::FromHandle(hwndExplorer));\r
52         for(int nPath = 0; nPath < orgPathList.GetCount(); nPath++)\r
53         {\r
54                 CTGitPath destPath;\r
55                 if (sNewName.IsEmpty())\r
56                         destPath = CTGitPath(sDroppath+_T("\\")+orgPathList[nPath].GetFileOrDirectoryName());\r
57                 else\r
58                         destPath = CTGitPath(sDroppath+_T("\\")+sNewName);\r
59                 if (destPath.Exists())\r
60                 {\r
61                         CString name = orgPathList[nPath].GetFileOrDirectoryName();\r
62                         if (!sNewName.IsEmpty())\r
63                                 name = sNewName;\r
64                         progress.Stop();\r
65                         CRenameDlg dlg;\r
66                         dlg.m_name = name;\r
67                         dlg.m_windowtitle.Format(IDS_PROC_NEWNAMEMOVE, (LPCTSTR)name);\r
68                         if (dlg.DoModal() != IDOK)\r
69                         {\r
70                                 return FALSE;\r
71                         }\r
72                         destPath.SetFromWin(sDroppath+_T("\\")+dlg.m_name);\r
73                 }\r
74                 CString top;\r
75                 top.Empty();\r
76                 orgPathList[nPath].HasAdminDir(&top);\r
77                 git_wc_status_kind s = status.GetAllStatus(orgPathList[nPath]);\r
78                 if ((s == git_wc_status_none)||(s == git_wc_status_unversioned)||(s == git_wc_status_ignored)||top != g_Git.m_CurrentDir)\r
79                 {\r
80                         // source file is unversioned: move the file to the target, then add it\r
81                         MoveFile(orgPathList[nPath].GetWinPath(), destPath.GetWinPath());\r
82                         CString cmd,output;\r
83                         cmd.Format(_T("git.exe add \"%s\""),destPath.GetWinPath());\r
84                         if(g_Git.Run(cmd,&output,CP_ACP))\r
85                         //if (!Git.Add(CTGitorgPathList(destPath), &props, Git_depth_infinity, true, false, true))\r
86                         {\r
87                                 TRACE(_T("%s\n"), output);\r
88                                 CMessageBox::Show(hwndExplorer, output, _T("TortoiseGit"), MB_ICONERROR);\r
89                                 return FALSE;           //get out of here\r
90                         }\r
91                         CShellUpdater::Instance().AddPathForUpdate(destPath);\r
92                 }\r
93                 else\r
94                 {\r
95                         CString cmd,output;\r
96                         cmd.Format(_T("git.exe mv \"%s\" \"%s\""),orgPathList[nPath].GetGitPathString(),destPath.GetGitPathString());\r
97                         if(g_Git.Run(cmd,&output,CP_ACP))\r
98                         //if (!Git.Move(CTGitorgPathList(orgPathList[nPath]), destPath, FALSE))\r
99                         {\r
100 #if 0\r
101                                 if (Git.Err && (Git.Err->apr_err == Git_ERR_UNVERSIONED_RESOURCE ||\r
102                                         Git.Err->apr_err == Git_ERR_CLIENT_MODIFIED))\r
103                                 {\r
104                                         // file/folder seems to have local modifications. Ask the user if\r
105                                         // a force is requested.\r
106                                         CString temp = Git.GetLastErrorMessage();\r
107                                         CString sQuestion(MAKEINTRESOURCE(IDS_PROC_FORCEMOVE));\r
108                                         temp += _T("\n") + sQuestion;\r
109                                         if (CMessageBox::Show(hwndExplorer, temp, _T("TortoiseGit"), MB_YESNO)==IDYES)\r
110                                         {\r
111                                                 if (!Git.Move(CTGitPathList(pathList[nPath]), destPath, TRUE))\r
112                                                 {\r
113                                                         CMessageBox::Show(hwndExplorer, Git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);\r
114                                                         return FALSE;           //get out of here\r
115                                                 }\r
116                                                 CShellUpdater::Instance().AddPathForUpdate(destPath);\r
117                                         }\r
118                                 }\r
119                                 else\r
120 #endif\r
121                                 {\r
122                                         TRACE(_T("%s\n"), (LPCTSTR)output);\r
123                                         CMessageBox::Show(hwndExplorer, output, _T("TortoiseGit"), MB_ICONERROR);\r
124                                         return FALSE;           //get out of here\r
125                                 }\r
126                         } \r
127                         else\r
128                                 CShellUpdater::Instance().AddPathForUpdate(destPath);\r
129                 }\r
130                 count++;\r
131                 if (progress.IsValid())\r
132                 {\r
133                         progress.FormatPathLine(1, IDS_PROC_MOVINGPROG, orgPathList[nPath].GetWinPath());\r
134                         progress.FormatPathLine(2, IDS_PROC_CPYMVPROG2, destPath.GetWinPath());\r
135                         progress.SetProgress(count, orgPathList.GetCount());\r
136                 }\r
137                 if ((progress.IsValid())&&(progress.HasUserCancelled()))\r
138                 {\r
139                         CMessageBox::Show(hwndExplorer, IDS_SVN_USERCANCELLED, IDS_APPNAME, MB_ICONINFORMATION);\r
140                         return FALSE;\r
141                 }\r
142         }\r
143         return true;\r
144 }