mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-14 14:32:15 -07:00
Allow more naming schemes for custom pictures.
Order is cardName_providerId, cardName_setName_collectorNumber, setName-collectorNumber-cardName and then just generically cardName, if the user has decided to override every printing. Most-to-least specific. Took 2 minutes Took 8 seconds
This commit is contained in:
parent
2267d38352
commit
6b435eb2b4
2 changed files with 55 additions and 56 deletions
|
|
@ -59,84 +59,81 @@ QImage PictureLoaderLocal::tryLoad(const CardInfoPtr &toLoad) const
|
||||||
{
|
{
|
||||||
CardSetPtr set = PictureToLoad::extractSetsSorted(toLoad).first();
|
CardSetPtr set = PictureToLoad::extractSetsSorted(toLoad).first();
|
||||||
|
|
||||||
QString setName = set ? set->getCorrectedShortName() : QString();
|
CardInfoPerSet setInstance = CardDatabaseManager::getInstance()->getSetInfoForCard(toLoad);
|
||||||
|
|
||||||
QString cardName = toLoad->getName();
|
QString cardName = toLoad->getName();
|
||||||
QString correctedCardName = toLoad->getCorrectedName();
|
QString correctedCardName = toLoad->getCorrectedName();
|
||||||
|
|
||||||
// FIXME: This is a hack so that to keep old Cockatrice behavior
|
QString setName, collectorNumber, providerId;
|
||||||
// (ignoring provider ID) when the "override all card art with personal
|
|
||||||
// preference" is set.
|
if (setInstance.getPtr()) {
|
||||||
//
|
setName = setInstance.getPtr()->getCorrectedShortName();
|
||||||
// Figure out a proper way to integrate the two systems at some point.
|
collectorNumber = setInstance.getProperty("num");
|
||||||
//
|
providerId = setInstance.getProperty("uuid");
|
||||||
// Note: need to go through a member for
|
|
||||||
// overrideAllCardArtWithPersonalPreference as reading from the
|
|
||||||
// SettingsCache instance from the PictureLoaderWorker thread could
|
|
||||||
// cause race conditions.
|
|
||||||
//
|
|
||||||
// XXX: Reading from the CardDatabaseManager instance from the
|
|
||||||
// PictureLoaderWorker thread might not be safe either
|
|
||||||
bool searchCustomPics =
|
|
||||||
overrideAllCardArtWithPersonalPreference ||
|
|
||||||
CardDatabaseManager::getInstance()->isProviderIdForPreferredPrinting(cardName, toLoad->getPixmapCacheKey());
|
|
||||||
if (searchCustomPics) {
|
|
||||||
qCDebug(PictureLoaderLocalLog).nospace()
|
|
||||||
<< "[card: " << cardName << " set: " << setName << "]: Attempting to load picture from local";
|
|
||||||
return tryLoadCardImageFromDisk(setName, correctedCardName, searchCustomPics);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qCDebug(PictureLoaderLocalLog).nospace()
|
qCDebug(PictureLoaderLocalLog).nospace()
|
||||||
<< "[card: " << cardName << " set: " << setName << "]: Skipping load picture from local";
|
<< "[card: " << cardName << " set: " << setName << "]: Attempting to load picture from local";
|
||||||
|
return tryLoadCardImageFromDisk(setName, correctedCardName, collectorNumber, providerId);
|
||||||
return QImage();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QImage PictureLoaderLocal::tryLoadCardImageFromDisk(const QString &setName,
|
QImage PictureLoaderLocal::tryLoadCardImageFromDisk(const QString &setName,
|
||||||
const QString &correctedCardName,
|
const QString &correctedCardName,
|
||||||
const bool searchCustomPics) const
|
const QString &collectorNumber,
|
||||||
|
const QString &providerId) const
|
||||||
{
|
{
|
||||||
QImage image;
|
QImage image;
|
||||||
QImageReader imgReader;
|
QImageReader imgReader;
|
||||||
imgReader.setDecideFormatFromContent(true);
|
imgReader.setDecideFormatFromContent(true);
|
||||||
QList<QString> picsPaths = QList<QString>();
|
|
||||||
|
|
||||||
if (searchCustomPics) {
|
// Order is cardName_providerId, cardName_setName_collectorNumber, setName-collectorNumber-cardName and then just
|
||||||
picsPaths << customFolderIndex.values(correctedCardName);
|
// generically cardName, if the user has decided to override every printing. Most-to-least specific.
|
||||||
}
|
|
||||||
|
|
||||||
if (!setName.isEmpty()) {
|
const QStringList nameVariants = {!providerId.isEmpty() ? QString("%1_%2").arg(correctedCardName, providerId)
|
||||||
picsPaths << picsPath + "/" + setName + "/" + correctedCardName
|
: QString(),
|
||||||
// We no longer store downloaded images there, but don't just ignore
|
(!setName.isEmpty() && !collectorNumber.isEmpty())
|
||||||
// stuff that old versions have put there.
|
? QString("%1_%2_%3").arg(correctedCardName, setName, collectorNumber)
|
||||||
<< picsPath + "/downloadedPics/" + setName + "/" + correctedCardName;
|
: QString(),
|
||||||
}
|
(!setName.isEmpty() && !collectorNumber.isEmpty())
|
||||||
|
? QString("%1-%2-%3").arg(setName, collectorNumber, correctedCardName)
|
||||||
|
: QString(),
|
||||||
|
correctedCardName};
|
||||||
|
|
||||||
// Iterates through the list of paths, searching for images with the desired
|
for (const QString &nameVariant : nameVariants) {
|
||||||
// name with any QImageReader-supported extension
|
if (nameVariant.isEmpty()) {
|
||||||
for (const auto &_picsPath : picsPaths) {
|
|
||||||
if (!QFileInfo(_picsPath).isFile()) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
imgReader.setFileName(_picsPath);
|
QStringList candidatePaths;
|
||||||
if (imgReader.read(&image)) {
|
const auto matches = customFolderIndex.values(nameVariant);
|
||||||
qCDebug(PictureLoaderLocalLog).nospace()
|
|
||||||
<< "[card: " << correctedCardName << " set: " << setName << "]: Picture found on disk.";
|
for (const QString &path : matches) {
|
||||||
return image;
|
candidatePaths << path;
|
||||||
}
|
}
|
||||||
imgReader.setFileName(_picsPath + ".full");
|
|
||||||
if (imgReader.read(&image)) {
|
if (!setName.isEmpty()) {
|
||||||
qCDebug(PictureLoaderLocalLog).nospace()
|
candidatePaths << picsPath + "/" + setName + "/" + nameVariant;
|
||||||
<< "[card: " << correctedCardName << " set: " << setName << "]: Picture.full found on disk.";
|
candidatePaths << picsPath + "/downloadedPics/" + setName + "/" + nameVariant;
|
||||||
return image;
|
|
||||||
}
|
}
|
||||||
imgReader.setFileName(_picsPath + ".xlhq");
|
|
||||||
if (imgReader.read(&image)) {
|
for (const QString &path : candidatePaths) {
|
||||||
qCDebug(PictureLoaderLocalLog).nospace()
|
for (const QString suffix : {"", ".full", ".xlhq"}) {
|
||||||
<< "[card: " << correctedCardName << " set: " << setName << "]: Picture.xlhq found on disk.";
|
QString fullPath = path + suffix;
|
||||||
return image;
|
QFileInfo fi(fullPath);
|
||||||
|
if (!fi.exists() || !fi.isFile()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
imgReader.setFileName(fullPath);
|
||||||
|
if (imgReader.read(&image)) {
|
||||||
|
qCDebug(PictureLoaderLocalLog).nospace()
|
||||||
|
<< "[card: " << correctedCardName << " set: " << setName << "] Found picture at: " << fullPath;
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qCDebug(PictureLoaderLocalLog).nospace()
|
qCDebug(PictureLoaderLocalLog).nospace()
|
||||||
<< "[card: " << correctedCardName << " set: " << setName << "]: Picture NOT found on disk.";
|
<< "[card: " << correctedCardName << " set: " << setName << "]: Picture NOT found on disk.";
|
||||||
return QImage();
|
return QImage();
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,10 @@ private:
|
||||||
|
|
||||||
void refreshIndex();
|
void refreshIndex();
|
||||||
|
|
||||||
QImage
|
QImage tryLoadCardImageFromDisk(const QString &setName,
|
||||||
tryLoadCardImageFromDisk(const QString &setName, const QString &correctedCardName, bool searchCustomPics) const;
|
const QString &correctedCardName,
|
||||||
|
const QString &collectorNumber,
|
||||||
|
const QString &providerId) const;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void picsPathChanged();
|
void picsPathChanged();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue