OSDN Git Service

Show Ignore Sub Menu
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / Commands / ExportCommand.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 "ExportCommand.h"\r
21 \r
22 #include "ExportDlg.h"\r
23 #include "SVNProgressDlg.h"\r
24 #include "SVNAdminDir.h"\r
25 #include "ProgressDlg.h"\r
26 #include "BrowseFolder.h"\r
27 #include "DirFileEnum.h"\r
28 #include "MessageBox.h"\r
29 #include "SVNStatus.h"\r
30 \r
31 bool ExportCommand::Execute()\r
32 {\r
33         bool bRet = false;\r
34         // When the user clicked on a working copy, we know that the export should\r
35         // be done from that. We then have to ask where the export should go to.\r
36         // If however the user clicked on an unversioned folder, we assume that\r
37         // this is where the export should go to and have to ask from where\r
38         // the export should be done from.\r
39         TCHAR saveto[MAX_PATH];\r
40         bool bURL = !!SVN::PathIsURL(cmdLinePath);\r
41         svn_wc_status_kind s = SVNStatus::GetAllStatus(cmdLinePath);\r
42         if ((bURL)||(s == svn_wc_status_unversioned)||(s == svn_wc_status_none))\r
43         {\r
44                 // ask from where the export has to be done\r
45                 CExportDlg dlg;\r
46                 if (bURL)\r
47                         dlg.m_URL = cmdLinePath.GetSVNPathString();\r
48                 else\r
49                         dlg.m_strExportDirectory = cmdLinePath.GetWinPathString();\r
50                 if (parser.HasKey(_T("revision")))\r
51                 {\r
52                         SVNRev Rev = SVNRev(parser.GetVal(_T("revision")));\r
53                         dlg.Revision = Rev;\r
54                 }\r
55                 if (dlg.DoModal() == IDOK)\r
56                 {\r
57                         CTSVNPath exportPath(dlg.m_strExportDirectory);\r
58 \r
59                         CSVNProgressDlg progDlg;\r
60                         theApp.m_pMainWnd = &progDlg;\r
61                         progDlg.SetCommand(CSVNProgressDlg::SVNProgress_Export);\r
62                         if (parser.HasVal(_T("closeonend")))\r
63                                 progDlg.SetAutoClose(parser.GetLongVal(_T("closeonend")));\r
64                         DWORD options = dlg.m_bNoExternals ? ProgOptIgnoreExternals : ProgOptNone;\r
65                         if (dlg.m_eolStyle.CompareNoCase(_T("CRLF"))==0)\r
66                                 options |= ProgOptEolCRLF;\r
67                         if (dlg.m_eolStyle.CompareNoCase(_T("CR"))==0)\r
68                                 options |= ProgOptEolCR;\r
69                         if (dlg.m_eolStyle.CompareNoCase(_T("LF"))==0)\r
70                                 options |= ProgOptEolLF;\r
71                         progDlg.SetOptions(options);\r
72                         progDlg.SetPathList(CTSVNPathList(exportPath));\r
73                         progDlg.SetUrl(dlg.m_URL);\r
74                         progDlg.SetRevision(dlg.Revision);\r
75                         progDlg.SetDepth(dlg.m_depth);\r
76                         progDlg.DoModal();\r
77                         bRet = !progDlg.DidErrorsOccur();\r
78                 }\r
79         }\r
80         else\r
81         {\r
82                 // ask where the export should go to.\r
83                 CBrowseFolder folderBrowser;\r
84                 CString strTemp;\r
85                 strTemp.LoadString(IDS_PROC_EXPORT_1);\r
86                 folderBrowser.SetInfo(strTemp);\r
87                 folderBrowser.m_style = BIF_NEWDIALOGSTYLE | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS | BIF_VALIDATE;\r
88                 strTemp.LoadString(IDS_PROC_EXPORT_2);\r
89                 folderBrowser.SetCheckBoxText(strTemp);\r
90                 strTemp.LoadString(IDS_PROC_OMMITEXTERNALS);\r
91                 folderBrowser.SetCheckBoxText2(strTemp);\r
92                 folderBrowser.DisableCheckBox2WhenCheckbox1IsEnabled(true);\r
93                 CRegDWORD regExtended = CRegDWORD(_T("Software\\TortoiseSVN\\ExportExtended"), FALSE);\r
94                 CBrowseFolder::m_bCheck = regExtended;\r
95                 if (folderBrowser.Show(hwndExplorer, saveto, MAX_PATH)==CBrowseFolder::OK)\r
96                 {\r
97                         CString saveplace = CString(saveto);\r
98 \r
99                         if (cmdLinePath.IsEquivalentTo(CTSVNPath(saveplace)))\r
100                         {\r
101                                 // exporting to itself:\r
102                                 // remove all svn admin dirs, effectively unversion the 'exported' folder.\r
103                                 CString msg;\r
104                                 msg.Format(IDS_PROC_EXPORTUNVERSION, (LPCTSTR)saveplace);\r
105                                 if (CMessageBox::Show(hwndExplorer, msg, _T("TortoiseSVN"), MB_ICONQUESTION|MB_YESNO) == IDYES)\r
106                                 {\r
107                                         CProgressDlg progress;\r
108                                         progress.SetTitle(IDS_PROC_UNVERSION);\r
109                                         progress.SetAnimation(IDR_MOVEANI);\r
110                                         progress.FormatNonPathLine(1, IDS_SVNPROGRESS_EXPORTINGWAIT);\r
111                                         progress.SetTime(true);\r
112                                         progress.ShowModeless(hwndExplorer);\r
113                                         std::vector<CTSVNPath> removeVector;\r
114 \r
115                                         CDirFileEnum lister(saveplace);\r
116                                         CString srcFile;\r
117                                         bool bFolder = false;\r
118                                         while (lister.NextFile(srcFile, &bFolder))\r
119                                         {\r
120                                                 CTSVNPath item(srcFile);\r
121                                                 if ((bFolder)&&(g_SVNAdminDir.IsAdminDirName(item.GetFileOrDirectoryName())))\r
122                                                 {\r
123                                                         removeVector.push_back(item);\r
124                                                 }\r
125                                         }\r
126                                         DWORD count = 0;\r
127                                         for (std::vector<CTSVNPath>::iterator it = removeVector.begin(); (it != removeVector.end()) && (!progress.HasUserCancelled()); ++it)\r
128                                         {\r
129                                                 progress.FormatPathLine(1, IDS_SVNPROGRESS_UNVERSION, (LPCTSTR)it->GetWinPath());\r
130                                                 progress.SetProgress(count, removeVector.size());\r
131                                                 count++;\r
132                                                 it->Delete(false);\r
133                                         }\r
134                                         progress.Stop();\r
135                                         bRet = true;\r
136                                 }\r
137                                 else\r
138                                         return false;\r
139                         }\r
140                         else\r
141                         {\r
142                                 saveplace += _T("\\") + cmdLinePath.GetFileOrDirectoryName();\r
143                                 TRACE(_T("export %s to %s\n"), (LPCTSTR)cmdLinePath.GetUIPathString(), (LPCTSTR)saveto);\r
144                                 SVN svn;\r
145                                 if (!svn.Export(cmdLinePath, CTSVNPath(saveplace), bURL ? SVNRev::REV_HEAD : SVNRev::REV_WC, \r
146                                         bURL ? SVNRev::REV_HEAD : SVNRev::REV_WC, FALSE, folderBrowser.m_bCheck2, svn_depth_infinity,\r
147                                         hwndExplorer, folderBrowser.m_bCheck))\r
148                                 {\r
149                                         CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_OK | MB_ICONERROR);\r
150                                         bRet = false;\r
151                                 }\r
152                                 else\r
153                                         bRet = true;\r
154                                 regExtended = CBrowseFolder::m_bCheck;\r
155                         }\r
156                 }\r
157         }\r
158         return bRet;\r
159 }\r