Oracle / card xml improvements (#3934)

* fix #1610

* fix #2679; partially fix #3647

* Fix tests

* Remove debug code
This commit is contained in:
ctrlaltca
2020-03-30 21:56:03 +02:00
committed by GitHub
parent a135ad064a
commit 27b7ebe208
13 changed files with 131 additions and 10 deletions

View File

@@ -39,6 +39,7 @@
// Xz stream header: 0xFD + "7zXZ"
#define XZ_SIGNATURE "\xFD\x37\x7A\x58\x5A"
#define ALLSETS_URL_FALLBACK "https://www.mtgjson.com/files/AllPrintings.json"
#define MTGJSON_VERSION_URL "https://www.mtgjson.com/files/version.json"
#ifdef HAS_LZMA
#define ALLSETS_URL "https://www.mtgjson.com/files/AllPrintings.json.xz"
@@ -331,14 +332,46 @@ bool LoadSetsPage::validatePage()
wizard()->disableButtons();
setEnabled(false);
wizard()->setCardSourceUrl(setsFile.fileName());
wizard()->setCardSourceVersion("unknown");
readSetsFromByteArray(setsFile.readAll());
}
return false;
}
#include <iostream>
void LoadSetsPage::downloadSetsFile(QUrl url)
{
wizard()->setCardSourceVersion("unknown");
QString urlString = url.toString();
if (urlString == ALLSETS_URL || urlString == ALLSETS_URL_FALLBACK) {
QUrl versionUrl = QUrl::fromUserInput(MTGJSON_VERSION_URL);
QNetworkReply *versionReply = wizard()->nam->get(QNetworkRequest(versionUrl));
connect(versionReply, &QNetworkReply::finished, [this, versionReply]() {
if (versionReply->error() == QNetworkReply::NoError) {
QByteArray jsonData = versionReply->readAll();
QJsonParseError jsonError;
QJsonDocument jsonResponse = QJsonDocument::fromJson(jsonData, &jsonError);
if (jsonError.error == QJsonParseError::NoError) {
QVariantMap jsonMap = jsonResponse.toVariant().toMap();
QString versionString = jsonMap["version"].toString();
if (versionString.isEmpty()) {
versionString = "unknown";
}
wizard()->setCardSourceVersion(versionString);
}
}
versionReply->deleteLater();
});
}
wizard()->setCardSourceUrl(url.toString());
QNetworkReply *reply = wizard()->nam->get(QNetworkRequest(url));
connect(reply, SIGNAL(finished()), this, SLOT(actDownloadFinishedSetsFile()));
@@ -597,7 +630,7 @@ bool SaveSetsPage::validatePage()
return false;
}
if (wizard()->importer->saveToFile(fileName)) {
if (wizard()->importer->saveToFile(fileName, wizard()->getCardSourceUrl(), wizard()->getCardSourceVersion())) {
ok = true;
} else {
QMessageBox::critical(this, tr("Error"), tr("The file could not be saved to %1").arg(fileName));