bool XmlSettingsStore::Save() { if (!modified_) { return true; } try { modified_ = false; std::ofstream out; out.open(widen(filename_), std::ios::out | std::ios::trunc); out << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"; out << "<settings>\n"; for (const auto& p : long_settings_) { out << "<long name=\"" << p.first << "\" value=\"" << p.second << "\"/>\n"; } for (const auto& p : boolean_settings_) { std::string value = p.second ? "True" : "False"; out << "<bool name=\"" << p.first << "\" value=\"" << value << "\"/>\n"; } for (const auto& p : string_settings_) { std::string attribute = p.second; XML_Escape(attribute, true /* attribute */); out << "<string name=\"" << p.first << "\" value=\"" << attribute << "\"/>\n"; } out << "</settings>\n"; out.close(); } catch (...) { // TODO(localize). m_pMsgs->Message("Failed to save the settings", true /* interrupt */); return false; } return true; }
bool XmlSettingsStore::Save() { if (!modified_) { return true; } modified_ = false; std::stringstream out; out << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"; out << "<!DOCTYPE settings SYSTEM \"settings.dtd\">\n"; out << "<settings>\n"; for (const auto& p : long_settings_) { out << "<long name=\"" << p.first << "\" value=\"" << p.second << "\"/>\n"; } for (const auto& p : boolean_settings_) { std::string value = p.second ? "True" : "False"; out << "<bool name=\"" << p.first << "\" value=\"" << value << "\"/>\n"; } for (const auto& p : string_settings_) { std::string attribute = p.second; XML_Escape(attribute, true /* attribute */); out << "<string name=\"" << p.first << "\" value=\"" << attribute << "\"/>\n"; } out << "</settings>\n"; return fileutils_->WriteUserDataFile(filename_, out.str(),false); }