// Opens the specified XML file if it exists or creates a new one otherwise. // Returns 0 on error. bool CXmlFile::GetXmlFile(wxString const& file) { Close(); if (CLocalFileSystem::GetSize(file) <= 0) { return false; } // File exists, open it if (!LoadXmlDocument(file)) { return false; } m_pElement = m_pDocument->FirstChildElement(m_rootName); if (!m_pElement) { if (m_pDocument->FirstChildElement()) { // Not created by FileZilla3 Close(); m_error = _("Unknown root element, the file does not appear to be generated by FileZilla."); return false; } m_pElement = m_pDocument->LinkEndChild(new TiXmlElement(m_rootName))->ToElement(); } return true; }
// Opens the specified XML file if it exists or creates a new one otherwise. // Returns 0 on error. TiXmlElement* GetXmlFile(wxFileName file, bool create /*=true*/, wxString* error /*=0*/) { if (wxFileExists(file.GetFullPath()) && file.GetSize() > 0) { // File does exist, open it TiXmlDocument* pXmlDocument = new TiXmlDocument; pXmlDocument->SetCondenseWhiteSpace(false); if (!LoadXmlDocument(pXmlDocument, file.GetFullPath(), error)) { delete pXmlDocument; return 0; } TiXmlElement* pElement = pXmlDocument->FirstChildElement("FileZilla3"); if (!pElement) { if (pXmlDocument->FirstChildElement()) { // Not created by FileZilla3 delete pXmlDocument; if (error) *error = _("Unknown root element, the file does not appear to be generated by FileZilla."); return 0; } pElement = pXmlDocument->LinkEndChild(new TiXmlElement("FileZilla3"))->ToElement(); } return pElement; } else { // File does not exist if (!create) return 0; // create new XML document TiXmlDocument* pXmlDocument = new TiXmlDocument(); pXmlDocument->SetCondenseWhiteSpace(false); pXmlDocument->LinkEndChild(new TiXmlDeclaration("1.0", "UTF-8", "yes")); pXmlDocument->LinkEndChild(new TiXmlElement("FileZilla3")); if (!SaveXmlFile(file, pXmlDocument, 0)) { delete pXmlDocument; return 0; } return pXmlDocument->FirstChildElement("FileZilla3"); } }
void CImportDialog::Show() { wxFileDialog dlg(m_parent, _("Select file to import settings from"), _T(""), _T("FileZilla.xml"), _T("XML files (*.xml)|*.xml"), wxFD_OPEN | wxFD_FILE_MUST_EXIST); dlg.CenterOnParent(); if (dlg.ShowModal() != wxID_OK) return; wxFileName fn(dlg.GetPath()); const wxString& path = fn.GetPath(); const wxString& settings(COptions::Get()->GetOption(OPTION_DEFAULT_SETTINGSDIR)); if (path == settings) { wxMessageBox(_("You cannot import settings from FileZilla's own settings directory."), _("Error importing"), wxICON_ERROR, m_parent); return; } TiXmlDocument* xmlDocument = new TiXmlDocument(); xmlDocument->SetCondenseWhiteSpace(false); if (!LoadXmlDocument(xmlDocument, dlg.GetPath())) { delete xmlDocument; wxMessageBox(_("Cannot load file, not a valid XML file."), _("Error importing"), wxICON_ERROR, m_parent); return; } TiXmlElement* fz3Root = xmlDocument->FirstChildElement("FileZilla3"); TiXmlElement* fz2Root = xmlDocument->FirstChildElement("FileZilla"); if (fz3Root) { bool settings = fz3Root->FirstChildElement("Settings") != 0; bool queue = fz3Root->FirstChildElement("Queue") != 0; bool sites = fz3Root->FirstChildElement("Servers") != 0; if (settings || queue || sites) { Load(m_parent, _T("ID_IMPORT")); if (!queue) XRCCTRL(*this, "ID_QUEUE", wxCheckBox)->Hide(); if (!sites) XRCCTRL(*this, "ID_SITEMANAGER", wxCheckBox)->Hide(); if (!settings) XRCCTRL(*this, "ID_SETTINGS", wxCheckBox)->Hide(); Fit(); if (ShowModal() != wxID_OK) { delete xmlDocument; return; } if (queue && XRCCTRL(*this, "ID_QUEUE", wxCheckBox)->IsChecked()) { m_pQueueView->ImportQueue(fz3Root->FirstChildElement("Queue"), true); } if (sites && XRCCTRL(*this, "ID_SITEMANAGER", wxCheckBox)->IsChecked()) { ImportSites(fz3Root->FirstChildElement("Servers")); } if (settings && XRCCTRL(*this, "ID_SETTINGS", wxCheckBox)->IsChecked()) { COptions::Get()->Import(fz3Root->FirstChildElement("Settings")); wxMessageBox(_("The settings have been imported. You have to restart FileZilla for all settings to have effect."), _("Import successful"), wxOK, this); } wxMessageBox(_("The selected categories have been imported."), _("Import successful"), wxOK, this); delete xmlDocument; return; } } else if (fz2Root) { bool sites_fz2 = fz2Root->FirstChildElement("Sites") != 0; if (sites_fz2) { int res = wxMessageBox(_("The file you have selected contains site manager data from a previous version of FileZilla.\nDue to differences in the storage format, only host, port, username and password will be imported.\nContinue with the import?"), _("Import data from older version"), wxICON_QUESTION | wxYES_NO); if (res == wxYES) ImportLegacySites(fz2Root->FirstChildElement("Sites")); delete xmlDocument; return; } } delete xmlDocument; wxMessageBox(_("File does not contain any importable data."), _("Error importing"), wxICON_ERROR, m_parent); }