Saved games: increase the XML format version, to indicate incompatibilities

This commit is contained in:
Olivier Teulière 2012-04-04 21:53:54 +02:00
parent 76d761ad8d
commit c423da2425
2 changed files with 25 additions and 2 deletions

View file

@ -53,6 +53,10 @@
#include "navigation.h"
#include "header.h"
// Current version of our save game format. Bump it when it becomes
// incompatible (and keep it in sync with xml_writer.cpp)
#define CURRENT_XML_VERSION "2"
using namespace std;
INIT_LOGGER(game, XmlReader);
@ -165,7 +169,22 @@ void XmlReader::startElement(const string& namespaceURI,
m_data.clear();
const string &tag = localName;
if (tag == "Dictionary")
if (tag == "EliotGame")
{
// Make sure that we are loading the correct XML format
for (int i = 0; i < atts.getLength(); ++i)
{
if (atts.getLocalName(i) == "format" &&
atts.getValue(i) != CURRENT_XML_VERSION)
{
LOG_ERROR("Incompatible save game format: current="
<< CURRENT_XML_VERSION
<< " savegame=" << atts.getValue(i));
throw LoadGameException("This saved game is not compatible with the current version of Eliot.");
}
}
}
else if (tag == "Dictionary")
{
m_context = "Dictionary";
}

View file

@ -42,6 +42,10 @@
#include "dic.h"
#include "header.h"
// Current version of our save game format. Bump it when it becomes
// incompatible (and keep it in sync with xml_reader.cpp)
#define CURRENT_XML_VERSION "2"
using namespace std;
INIT_LOGGER(game, XmlWriter);
@ -101,7 +105,7 @@ void XmlWriter::write(const Game &iGame, const string &iFileName)
out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl;
string indent = "";
out << indent << "<EliotGame format=\"1\">" << endl;
out << indent << "<EliotGame format=\"" << CURRENT_XML_VERSION << "\">" << endl;
addIndent(indent);
// ------------------------