1 // TortoiseSVN - a Windows shell extension for easy version control
\r
3 // Copyright (C) 2007-2008 - TortoiseSVN
\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
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
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
20 #include "ExportCommand.h"
\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
31 bool ExportCommand::Execute()
\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
44 // ask from where the export has to be done
\r
47 dlg.m_URL = cmdLinePath.GetSVNPathString();
\r
49 dlg.m_strExportDirectory = cmdLinePath.GetWinPathString();
\r
50 if (parser.HasKey(_T("revision")))
\r
52 SVNRev Rev = SVNRev(parser.GetVal(_T("revision")));
\r
55 if (dlg.DoModal() == IDOK)
\r
57 CTSVNPath exportPath(dlg.m_strExportDirectory);
\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
77 bRet = !progDlg.DidErrorsOccur();
\r
82 // ask where the export should go to.
\r
83 CBrowseFolder folderBrowser;
\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
97 CString saveplace = CString(saveto);
\r
99 if (cmdLinePath.IsEquivalentTo(CTSVNPath(saveplace)))
\r
101 // exporting to itself:
\r
102 // remove all svn admin dirs, effectively unversion the 'exported' folder.
\r
104 msg.Format(IDS_PROC_EXPORTUNVERSION, (LPCTSTR)saveplace);
\r
105 if (CMessageBox::Show(hwndExplorer, msg, _T("TortoiseSVN"), MB_ICONQUESTION|MB_YESNO) == IDYES)
\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
115 CDirFileEnum lister(saveplace);
\r
117 bool bFolder = false;
\r
118 while (lister.NextFile(srcFile, &bFolder))
\r
120 CTSVNPath item(srcFile);
\r
121 if ((bFolder)&&(g_SVNAdminDir.IsAdminDirName(item.GetFileOrDirectoryName())))
\r
123 removeVector.push_back(item);
\r
127 for (std::vector<CTSVNPath>::iterator it = removeVector.begin(); (it != removeVector.end()) && (!progress.HasUserCancelled()); ++it)
\r
129 progress.FormatPathLine(1, IDS_SVNPROGRESS_UNVERSION, (LPCTSTR)it->GetWinPath());
\r
130 progress.SetProgress(count, removeVector.size());
\r
142 saveplace += _T("\\") + cmdLinePath.GetFileOrDirectoryName();
\r
143 TRACE(_T("export %s to %s\n"), (LPCTSTR)cmdLinePath.GetUIPathString(), (LPCTSTR)saveto);
\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
149 CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_OK | MB_ICONERROR);
\r
154 regExtended = CBrowseFolder::m_bCheck;
\r