From 42f1c6938fcdb24579e881ff4efea9d4da2414c8 Mon Sep 17 00:00:00 2001 From: Daenyth Date: Sun, 29 Jun 2014 23:00:58 -0400 Subject: [PATCH 1/2] Merged: First draft of better pic url error handling Cherry-picked b9cb61abd05f83c67740aafa5e1e6939143547e4 --- cockatrice/src/carddatabase.cpp | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/cockatrice/src/carddatabase.cpp b/cockatrice/src/carddatabase.cpp index 9e7b38dc..5edd41fb 100644 --- a/cockatrice/src/carddatabase.cpp +++ b/cockatrice/src/carddatabase.cpp @@ -176,7 +176,7 @@ void PictureLoader::processLoadQueue() QString PictureLoader::getPicUrl(CardInfo *card) { - if (!picDownload) return 0; + if (!picDownload) return QString(""); CardSet *set = card->getPreferredSet(); QString picUrl = QString(""); @@ -201,9 +201,22 @@ QString PictureLoader::getPicUrl(CardInfo *card) // otherwise, fallback to the default url picUrl = picDownloadHq ? settingsCache->getPicUrlHq() : settingsCache->getPicUrl(); picUrl.replace("!name!", QUrl::toPercentEncoding(card->getCorrectedName())); - picUrl.replace("!setcode!", QUrl::toPercentEncoding(set->getShortName())); - picUrl.replace("!setname!", QUrl::toPercentEncoding(set->getLongName())); - picUrl.replace("!cardid!", QUrl::toPercentEncoding(QString::number(card->getPreferredMuId()))); + + if (set) { + picUrl.replace("!setcode!", QUrl::toPercentEncoding(set->getShortName())); + picUrl.replace("!setname!", QUrl::toPercentEncoding(set->getLongName())); + } + int muid = card->getPreferredMuId(); + if (muid) + picUrl.replace("!cardid!", QUrl::toPercentEncoding(QString::number(muid))); + + if (picUrl.contains("!name!") || + picUrl.contains("!setcode!") || + picUrl.contains("!setname!") || + picUrl.contains("!cardid!")) { + qDebug() << "Insufficient card data to download" << card->getName() << "Url:" << picUrl; + return QString(""); + } return picUrl; } @@ -220,8 +233,11 @@ void PictureLoader::startNextPicDownload() cardBeingDownloaded = cardsToDownload.takeFirst(); - // TODO: Do something useful when picUrl is 0 or empty, etc QString picUrl = getPicUrl(cardBeingDownloaded.getCard()); + if (picUrl.isEmpty()) { + qDebug() << "No url for" << cardBeingDownloaded.getCard()->getName(); + return; + } QUrl url(picUrl); From 765e865aa2cbc7a573ce496240d9bcb93d6a876e Mon Sep 17 00:00:00 2001 From: Daenyth Date: Wed, 2 Jul 2014 19:18:05 -0400 Subject: [PATCH 2/2] Continue downloading card images after failing url on one. I should probably bust this out to a method. --- cockatrice/src/carddatabase.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cockatrice/src/carddatabase.cpp b/cockatrice/src/carddatabase.cpp index 5edd41fb..79a225ec 100644 --- a/cockatrice/src/carddatabase.cpp +++ b/cockatrice/src/carddatabase.cpp @@ -236,6 +236,8 @@ void PictureLoader::startNextPicDownload() QString picUrl = getPicUrl(cardBeingDownloaded.getCard()); if (picUrl.isEmpty()) { qDebug() << "No url for" << cardBeingDownloaded.getCard()->getName(); + cardBeingDownloaded = 0; + downloadRunning = false; return; }