void dmz::ArchivePluginAutoSave::update_plugin_state ( const PluginStateEnum State, const UInt32 Level) { if (State == PluginStateStart) { if (_firstStart && _saveFile && is_valid_path (_saveFile) && _archiveMod) { _log.info << "Restoring from auto save archive: " << _saveFile << endl; Config global ("global"); XMLParser parser; XMLInterpreterConfig interpreter (global); parser.set_interpreter (&interpreter); FILE *file = open_file (_saveFile, "rb"); if (file) { Boolean error (False); String buffer; while (read_file (file, 1024, buffer) && !error) { const Int32 Length = buffer.get_length (); const char *cbuf = buffer.get_buffer (); if (!parser.parse_buffer (cbuf, Length, Length < 1024)) { error = True; _log.error << "Unable to restore from auto save archive: " << _saveFile << " : " << parser.get_error (); } } close_file (file); Config data; if (!error && global.lookup_all_config_merged ("dmz", data)) { _archiveMod->process_archive (_archiveHandle, data); } } } _firstStart = False; } else if (State == PluginStateShutdown) { if (is_valid_path (_saveFile)) { remove_file (_saveFile); } } }
/*! \ingroup Foundation \brief Converts an XML file to a config context tree. \details Defined in dmzXMLUtil.h. \param[in] File String containing name of XML file to parse. \param[out] data Config object to store parsed XML data. \param[in] log Pointer to Log for streaming log messages. \return Returns dmz::True if the XML file was successfully parsed. \sa dmz::Config \n dmz::ConfigContext */ dmz::Boolean dmz::xml_to_config (const String &File, Config &data, Log *log) { XMLParser parser; XMLInterpreterConfig interpreter (data); parser.set_interpreter (&interpreter); Boolean error (False); FILE *file = open_file (File, "rb"); if (file) { String buffer; while (read_file (file, 1024, buffer) && !error) { const Int32 Length = buffer.get_length (); const char *cbuf = buffer.get_buffer (); if (!parser.parse_buffer (cbuf, Length, Length < 1024)) { error = True; if (log) { log->error << "In file: " << File << " : " << parser.get_error () << endl; } } } close_file (file); } else if (log) { log->error << "Unable to open file: " << file << endl; } return !error; }