1 #include "filezilla.h"
2 #include "export.h"
3 #include "filezillaapp.h"
4 #include "xmlfunctions.h"
5 #include "queue.h"
6 #include "xrc_helper.h"
7
8 #include "../commonui/ipcmutex.h"
9
10 #include <wx/filedlg.h>
11
CExportDialog(wxWindow * parent,CQueueView * pQueueView)12 CExportDialog::CExportDialog(wxWindow* parent, CQueueView* pQueueView)
13 : m_parent(parent), m_pQueueView(pQueueView)
14 {
15 }
16
Run()17 void CExportDialog::Run()
18 {
19 if (!Load(m_parent, _T("ID_EXPORT"))) {
20 return;
21 }
22
23 if (ShowModal() != wxID_OK) {
24 return;
25 }
26
27 bool sitemanager = xrc_call(*this, "ID_SITEMANAGER", &wxCheckBox::GetValue);
28 bool settings = xrc_call(*this, "ID_SETTINGS", &wxCheckBox::GetValue);
29 bool queue = xrc_call(*this, "ID_QUEUE", &wxCheckBox::GetValue);
30 bool filters = xrc_call(*this, "ID_FILTERS", &wxCheckBox::GetValue);
31
32 if (!sitemanager && !settings && !queue && !filters) {
33 wxMessageBoxEx(_("No category to export selected"), _("Error exporting settings"), wxICON_ERROR, m_parent);
34 return;
35 }
36
37 wxString str;
38 if (sitemanager && !queue && !settings && !filters) {
39 str = _("Select file for exported sites");
40 }
41 else if (!sitemanager && queue && !settings && !filters) {
42 str = _("Select file for exported queue");
43 }
44 else if (!sitemanager && !queue && settings && !filters) {
45 str = _("Select file for exported settings");
46 }
47 else if (!sitemanager && !queue && !settings && filters) {
48 str = _("Select file for exported filters");
49 }
50 else {
51 str = _("Select file for exported data");
52 }
53
54 wxFileDialog dlg(m_parent, str, wxString(),
55 _T("FileZilla.xml"), _T("XML files (*.xml)|*.xml"),
56 wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
57
58 if (dlg.ShowModal() != wxID_OK) {
59 return;
60 }
61
62 CXmlFile xml(dlg.GetPath().ToStdWstring());
63
64 auto exportRoot = xml.CreateEmpty();
65
66 if (sitemanager) {
67 CInterProcessMutex mutex(MUTEX_SITEMANAGER);
68
69 CXmlFile file(wxGetApp().GetSettingsFile(_T("sitemanager")));
70 auto document = file.Load();
71 if (document) {
72 auto element = document.child("Servers");
73 if (element) {
74 exportRoot.append_copy(element);
75 }
76 }
77 }
78 if (settings) {
79 COptions::Get()->Save();
80 CInterProcessMutex mutex(MUTEX_OPTIONS);
81 CXmlFile file(wxGetApp().GetSettingsFile(_T("filezilla")));
82 auto document = file.Load();
83 if (document) {
84 auto element = document.child("Settings");
85 if (element) {
86 exportRoot.append_copy(element);
87 }
88 }
89 }
90
91 if (queue) {
92 m_pQueueView->WriteToFile(exportRoot);
93 }
94
95 if (filters) {
96 CInterProcessMutex mutex(MUTEX_FILTERS);
97 CXmlFile file(wxGetApp().GetSettingsFile(_T("filters")));
98 auto document = file.Load();
99 if (document) {
100 auto element = document.child("Filters");
101 if (element) {
102 exportRoot.append_copy(element);
103 }
104 element = document.child("Sets");
105 if (element) {
106 exportRoot.append_copy(element);
107 }
108 }
109 }
110
111 SaveWithErrorDialog(xml);
112 }
113