Fall back to plain text load when xml load fails
This commit is contained in:
parent
0420f4f7af
commit
e5d9692d78
2 changed files with 31 additions and 11 deletions
|
@ -1,5 +1,6 @@
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
#include <QDebug>
|
||||||
#include "deck_loader.h"
|
#include "deck_loader.h"
|
||||||
#include "decklist.h"
|
#include "decklist.h"
|
||||||
|
|
||||||
|
@ -48,7 +49,16 @@ bool DeckLoader::loadFromFile(const QString &fileName, FileFormat fmt)
|
||||||
bool result = false;
|
bool result = false;
|
||||||
switch (fmt) {
|
switch (fmt) {
|
||||||
case PlainTextFormat: result = loadFromFile_Plain(&file); break;
|
case PlainTextFormat: result = loadFromFile_Plain(&file); break;
|
||||||
case CockatriceFormat: result = loadFromFile_Native(&file); break;
|
case CockatriceFormat:
|
||||||
|
result = loadFromFile_Native(&file);
|
||||||
|
qDebug() << "Loaded from" << fileName << "-" << result;
|
||||||
|
if (!result) {
|
||||||
|
qDebug() << "Retying as plain format";
|
||||||
|
file.seek(0);
|
||||||
|
result = loadFromFile_Plain(&file);
|
||||||
|
fmt = PlainTextFormat;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (result) {
|
if (result) {
|
||||||
lastFileName = fileName;
|
lastFileName = fileName;
|
||||||
|
@ -56,6 +66,7 @@ bool DeckLoader::loadFromFile(const QString &fileName, FileFormat fmt)
|
||||||
|
|
||||||
emit deckLoaded();
|
emit deckLoaded();
|
||||||
}
|
}
|
||||||
|
qDebug() << "Deck was loaded -" << result;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include <QCryptographicHash>
|
#include <QCryptographicHash>
|
||||||
|
#include <QDebug>
|
||||||
#include "decklist.h"
|
#include "decklist.h"
|
||||||
|
|
||||||
SideboardPlan::SideboardPlan(const QString &_name, const QList<MoveCard_ToZone> &_moveList)
|
SideboardPlan::SideboardPlan(const QString &_name, const QList<MoveCard_ToZone> &_moveList)
|
||||||
|
@ -441,6 +442,11 @@ void DeckList::write(QXmlStreamWriter *xml)
|
||||||
|
|
||||||
bool DeckList::loadFromXml(QXmlStreamReader *xml)
|
bool DeckList::loadFromXml(QXmlStreamReader *xml)
|
||||||
{
|
{
|
||||||
|
if (xml->error()) {
|
||||||
|
qDebug() << "Error loading deck from xml: " << xml->errorString();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
cleanList();
|
cleanList();
|
||||||
while (!xml->atEnd()) {
|
while (!xml->atEnd()) {
|
||||||
xml->readNext();
|
xml->readNext();
|
||||||
|
@ -455,6 +461,10 @@ bool DeckList::loadFromXml(QXmlStreamReader *xml)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateDeckHash();
|
updateDeckHash();
|
||||||
|
if (xml->error()) {
|
||||||
|
qDebug() << "Error loading deck from xml: " << xml->errorString();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -477,8 +487,7 @@ QString DeckList::writeToString_Native()
|
||||||
bool DeckList::loadFromFile_Native(QIODevice *device)
|
bool DeckList::loadFromFile_Native(QIODevice *device)
|
||||||
{
|
{
|
||||||
QXmlStreamReader xml(device);
|
QXmlStreamReader xml(device);
|
||||||
loadFromXml(&xml);
|
return loadFromXml(&xml);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeckList::saveToFile_Native(QIODevice *device)
|
bool DeckList::saveToFile_Native(QIODevice *device)
|
||||||
|
|
Loading…
Reference in a new issue