Raise a question popup when zip parsing fails

This commit is contained in:
Fabio Bas 2015-02-04 12:15:28 +01:00
parent 781f8a6603
commit 4ebcfc6b34
2 changed files with 26 additions and 13 deletions

View file

@ -30,6 +30,7 @@
#include "zip/unzip.h" #include "zip/unzip.h"
#define ZIP_SIGNATURE "PK" #define ZIP_SIGNATURE "PK"
#define ALLSETS_URL "http://mtgjson.com/json/AllSets.json.zip" #define ALLSETS_URL "http://mtgjson.com/json/AllSets.json.zip"
#define ALLSETS_URL_FALLBACK "http://mtgjson.com/json/AllSets.json"
#else #else
#define ALLSETS_URL "http://mtgjson.com/json/AllSets.json" #define ALLSETS_URL "http://mtgjson.com/json/AllSets.json"
#endif #endif
@ -282,19 +283,13 @@ void LoadSetsPage::readSetsFromByteArray(QByteArray data)
ec = uz.openArchive(inBuffer); ec = uz.openArchive(inBuffer);
if (ec != UnZip::Ok) { if (ec != UnZip::Ok) {
QMessageBox::critical(this, tr("Error"), tr("Failed to open Zip archive: %1").arg(uz.formatError(ec))); zipDownloadFailed(tr("Failed to open Zip archive: %1.").arg(uz.formatError(ec)));
wizard()->enableButtons();
setEnabled(true);
return; return;
} }
if(uz.fileList().size() != 1) if(uz.fileList().size() != 1)
{ {
QMessageBox::critical(this, tr("Error"), tr("The Zip archive doesn't contain exactly one file")); zipDownloadFailed(tr("The Zip archive doesn't contain exactly one file."));
wizard()->enableButtons();
setEnabled(true);
return; return;
} }
fileName = uz.fileList().at(0); fileName = uz.fileList().at(0);
@ -302,11 +297,8 @@ void LoadSetsPage::readSetsFromByteArray(QByteArray data)
outBuffer->open(QBuffer::ReadWrite); outBuffer->open(QBuffer::ReadWrite);
ec = uz.extractFile(fileName, outBuffer); ec = uz.extractFile(fileName, outBuffer);
if (ec != UnZip::Ok) { if (ec != UnZip::Ok) {
QMessageBox::critical(this, tr("Error"), tr("Zip extraction failed: %1").arg(uz.formatError(ec))); zipDownloadFailed(tr("Zip extraction failed: %1.").arg(uz.formatError(ec)));
uz.closeArchive(); uz.closeArchive();
wizard()->enableButtons();
setEnabled(true);
return; return;
} }
@ -314,10 +306,12 @@ void LoadSetsPage::readSetsFromByteArray(QByteArray data)
watcher.setFuture(future); watcher.setFuture(future);
return; return;
#else #else
QMessageBox::critical(this, tr("Error"), tr("Sorry, this version of Oracle does not support zipped files.")); zipDownloadFailed(tr("Sorry, this version of Oracle does not support zipped files."));
wizard()->enableButtons(); wizard()->enableButtons();
setEnabled(true); setEnabled(true);
progressLabel->hide();
progressBar->hide();
return; return;
#endif #endif
} }
@ -326,6 +320,24 @@ void LoadSetsPage::readSetsFromByteArray(QByteArray data)
watcher.setFuture(future); watcher.setFuture(future);
} }
void LoadSetsPage::zipDownloadFailed(const QString &message)
{
wizard()->enableButtons();
setEnabled(true);
progressLabel->hide();
progressBar->hide();
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this, tr("Error"), message + "<br/>" + tr("Do you want to try to download a fresh copy of the uncompressed file instead?"), QMessageBox::Ok|QMessageBox::Cancel, QMessageBox::Ok);
if (reply == QMessageBox::Ok)
{
urlRadioButton->setChecked(true);
urlLineEdit->setText(ALLSETS_URL_FALLBACK);
wizard()->next();
}
}
void LoadSetsPage::importFinished() void LoadSetsPage::importFinished()
{ {
wizard()->enableButtons(); wizard()->enableButtons();

View file

@ -77,6 +77,7 @@ private slots:
void actDownloadProgressSetsFile(qint64 received, qint64 total); void actDownloadProgressSetsFile(qint64 received, qint64 total);
void actDownloadFinishedSetsFile(); void actDownloadFinishedSetsFile();
void importFinished(); void importFinished();
void zipDownloadFailed(const QString &message);
}; };
class ChooseSetsPage : public OracleWizardPage class ChooseSetsPage : public OracleWizardPage