COptions::COptions() { m_theOptions = this; m_pXmlFile = 0; m_pLastServer = 0; SetDefaultValues(); m_save_timer.SetOwner(this); auto const nameOptionMap = GetNameOptionMap(); LoadGlobalDefaultOptions(nameOptionMap); CLocalPath const dir = InitSettingsDir(); CInterProcessMutex mutex(MUTEX_OPTIONS); m_pXmlFile = new CXmlFile(dir.GetPath() + _T("filezilla.xml")); if (!m_pXmlFile->Load()) { wxString msg = m_pXmlFile->GetError() + _T("\n\n") + _("For this session the default settings will be used. Any changes to the settings will not be saved."); wxMessageBoxEx(msg, _("Error loading xml file"), wxICON_ERROR); delete m_pXmlFile; m_pXmlFile = 0; } else CreateSettingsXmlElement(); LoadOptions(nameOptionMap); }
void COptions::SetXmlValue(unsigned int nID, wxString const& value) { if (!m_pXmlFile) return; // No checks are made about the validity of the value, that's done in SetOption wxScopedCharBuffer utf8 = value.utf8_str(); if (!utf8) return; TiXmlElement *settings = CreateSettingsXmlElement(); if (settings) { TiXmlElement *setting = 0; for (setting = settings->FirstChildElement("Setting"); setting; setting = setting->NextSiblingElement("Setting")) { const char *attribute = setting->Attribute("name"); if (!attribute) continue; if (!strcmp(attribute, options[nID].name)) break; } if (setting) { setting->Clear(); } else { setting = new TiXmlElement("Setting"); setting->SetAttribute("name", options[nID].name); settings->LinkEndChild(setting); } setting->LinkEndChild(new TiXmlText(utf8)); } }
void COptions::SetXmlValue(unsigned int nID, std::wstring const& value) { if (!m_pXmlFile) { return; } // No checks are made about the validity of the value, that's done in SetOption std::string utf8 = fz::to_utf8(value); auto settings = CreateSettingsXmlElement(); if (settings) { pugi::xml_node setting; for (setting = settings.child("Setting"); setting; setting = setting.next_sibling("Setting")) { const char *attribute = setting.attribute("name").value(); if (!attribute) { continue; } if (!strcmp(attribute, options[nID].name)) { break; } } if (!setting) { setting = settings.append_child("Setting"); SetTextAttribute(setting, "name", options[nID].name); } setting.text() = utf8.c_str(); } }
COptions::COptions() { m_theOptions = this; m_pXmlFile = 0; m_pLastServer = 0; m_acquired = false; SetDefaultValues(); m_save_timer.SetOwner(this); std::map<std::string, int> nameOptionMap; GetNameOptionMap(nameOptionMap); LoadGlobalDefaultOptions(nameOptionMap); InitSettingsDir(); CInterProcessMutex mutex(MUTEX_OPTIONS); m_pXmlFile = new CXmlFile(_T("filezilla")); if (!m_pXmlFile->Load(wxFileName())) { wxString msg = m_pXmlFile->GetError() + _T("\n\n") + _("For this session the default settings will be used. Any changes to the settings will not be saved."); wxMessageBox(msg, _("Error loading xml file"), wxICON_ERROR); delete m_pXmlFile; m_pXmlFile = 0; } else CreateSettingsXmlElement(); LoadOptions(nameOptionMap); }
void COptions::SetXmlValue(unsigned int nID, wxString const& value) { if (!m_pXmlFile) return; // No checks are made about the validity of the value, that's done in SetOption wxScopedCharBuffer utf8 = value.utf8_str(); if (!utf8) return; auto settings = CreateSettingsXmlElement(); if (settings) { pugi::xml_node setting; for (setting = settings.child("Setting"); setting; setting = setting.next_sibling("Setting")) { const char *attribute = setting.attribute("name").value(); if (!attribute) continue; if (!strcmp(attribute, options[nID].name)) break; } if (!setting) { setting = settings.append_child("Setting"); SetTextAttribute(setting, "name", options[nID].name); } setting.text() = utf8; } }
COptions::COptions() { m_pLastServer = 0; m_acquired = false; for (unsigned int i = 0; i < OPTIONS_NUM; i++) m_optionsCache[i].cached = false; m_save_timer.SetOwner(this); CInterProcessMutex mutex(MUTEX_OPTIONS); m_pXmlFile = new CXmlFile(_T("filezilla")); if (!m_pXmlFile->Load()) { wxString msg = m_pXmlFile->GetError() + _T("\n\n") + _("For this session the default settings will be used. Any changes to the settings will not be saved."); wxMessageBox(msg, _("Error loading xml file"), wxICON_ERROR); delete m_pXmlFile; m_pXmlFile = 0; } else CreateSettingsXmlElement(); LoadGlobalDefaultOptions(); }
void COptions::LoadOptions(std::map<std::string, unsigned int> const& nameOptionMap, pugi::xml_node settings) { if (!settings) { settings = CreateSettingsXmlElement(); if (!settings) { return; } } for (auto setting = settings.child("Setting"); setting; setting = setting.next_sibling("Setting")) { LoadOptionFromElement(setting, nameOptionMap, false); } }
void COptions::LoadOptions(std::map<std::string, unsigned int> const& nameOptionMap, TiXmlElement* settings) { if (!settings) { settings = CreateSettingsXmlElement(); if (!settings) { return; } } TiXmlNode *node = 0; while ((node = settings->IterateChildren("Setting", node))) { TiXmlElement *setting = node->ToElement(); if (!setting) continue; LoadOptionFromElement(setting, nameOptionMap, false); } }