// ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * // * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #include "xml_base.h" #include #include using namespace zen; //loadXmlDocument vs loadStream: //1. better error reporting //2. quick exit if (potentially large) input file is not an XML XmlDoc xmlAccess::loadXmlDocument(const Zstring& filename) //throw FfsXmlError { std::string stream; try { FileInput inputFile(filename); //throw FileError { //quick test whether input is an XML: avoid loading large binary files up front! const std::string xmlBegin = "(e.row + 1)), L"%z", numberTo(e.col + 1))); } } const std::wstring xmlAccess::getErrorMessageFormatted(const std::vector& failedElements) { std::wstring msg; if (!failedElements.empty()) { msg = _("Cannot read the following XML elements:") + L"\n"; std::for_each(failedElements.begin(), failedElements.end(), [&](const std::wstring& elem) { msg += L"\n" + elem; }); } return msg; } void xmlAccess::saveXmlDocument(const zen::XmlDoc& doc, const Zstring& filename) //throw FfsXmlError { std::string stream = serialize(doc); //throw () bool saveNecessary = true; try { if (zen::getFilesize(filename) == stream.size()) //throw FileError try { if (zen::loadStream(filename) == stream) //throw XmlFileError saveNecessary = false; } catch (const zen::XmlFileError&) {} } catch (FileError&) {} if (saveNecessary) try { FileOutput outputFile(filename, FileOutput::ACC_OVERWRITE); //throw FileError outputFile.write(stream.c_str(), stream.length()); // } catch (const FileError& error) //more detailed error messages than with wxWidgets { throw FfsXmlError(error.toString()); } }