Cache games without banners

Games without banners were not cached before, because a banner could
become available at any time, making the cache outdated without it
becoming invalidated. Instead of not caching anything, this change makes
Dolphin check for a banner every time a cache that lacks a banner is read.
This is faster than reading all metadata, because reading a Wii banner
only reads from the game's save file, not the volume and its filesystem.

The cache revision is incremented, because otherwise banners will be
missing if a cache without a banner is created in the new version and
the user switches to an old version and creates a savefile.
This commit is contained in:
JosJuice
2015-06-13 20:06:27 +02:00
parent 8793f7c325
commit a7d374bcb9
4 changed files with 69 additions and 33 deletions

View File

@ -24,7 +24,7 @@
#include "DolphinQt/GameList/GameFile.h"
#include "DolphinQt/Utils/Utils.h"
static const u32 CACHE_REVISION = 0x00A;
static const u32 CACHE_REVISION = 0x00B; // Last changed in PR 2598
static const u32 DATASTREAM_REVISION = 15; // Introduced in Qt 5.2
static QMap<DiscIO::IVolume::ELanguage, QString> ConvertLocalizedStrings(std::map<DiscIO::IVolume::ELanguage, std::string> strings)
@ -74,6 +74,20 @@ GameFile::GameFile(const QString& fileName)
if (LoadFromCache())
{
m_valid = true;
// Wii banners can only be read if there is a savefile,
// so sometimes caches don't contain banners. Let's check
// if a banner has become available after the cache was made.
if (m_banner.isNull())
{
std::unique_ptr<DiscIO::IVolume> volume(DiscIO::CreateVolumeFromFilename(fileName.toStdString()));
if (volume != nullptr)
{
ReadBanner(*volume);
if (!m_banner.isNull())
SaveToCache();
}
}
}
else
{
@ -100,24 +114,10 @@ GameFile::GameFile(const QString& fileName)
QFileInfo info(m_file_name);
m_folder_name = info.absoluteDir().dirName();
int width, height;
std::vector<u32> buffer = volume->GetBanner(&width, &height);
QImage banner(width, height, QImage::Format_RGB888);
for (int i = 0; i < width * height; i++)
{
int x = i % width, y = i / width;
banner.setPixel(x, y, qRgb((buffer[i] & 0xFF0000) >> 16,
(buffer[i] & 0x00FF00) >> 8,
(buffer[i] & 0x0000FF) >> 0));
}
ReadBanner(*volume);
m_valid = true;
if (!banner.isNull())
{
m_banner = QPixmap::fromImage(banner);
SaveToCache();
}
SaveToCache();
}
}
@ -238,6 +238,23 @@ QString GameFile::CreateCacheFilename()
return fullname;
}
void GameFile::ReadBanner(const DiscIO::IVolume& volume)
{
int width, height;
std::vector<u32> buffer = volume.GetBanner(&width, &height);
QImage banner(width, height, QImage::Format_RGB888);
for (int i = 0; i < width * height; i++)
{
int x = i % width, y = i / width;
banner.setPixel(x, y, qRgb((buffer[i] & 0xFF0000) >> 16,
(buffer[i] & 0x00FF00) >> 8,
(buffer[i] & 0x0000FF) >> 0));
}
if (!banner.isNull())
m_banner = QPixmap::fromImage(banner);
}
QString GameFile::GetDescription(DiscIO::IVolume::ELanguage language) const
{
return GetLanguageString(language, m_descriptions);

View File

@ -79,4 +79,6 @@ private:
void SaveToCache();
QString CreateCacheFilename();
void ReadBanner(const DiscIO::IVolume& volume);
};