summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorJosJuice <josjuice@gmail.com>2015-06-13 20:06:27 +0200
committerJosJuice <josjuice@gmail.com>2015-06-14 12:23:48 +0200
commita7d374bcb99310d3181a796da04eb919d7e65baa (patch)
tree4e2774803947b372f387888238918576c2ac528f /Source/Core
parent8793f7c325f7164f0cfe3095f697ef9bf5473344 (diff)
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.
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/DolphinQt/GameList/GameFile.cpp51
-rw-r--r--Source/Core/DolphinQt/GameList/GameFile.h2
-rw-r--r--Source/Core/DolphinWX/ISOFile.cpp47
-rw-r--r--Source/Core/DolphinWX/ISOFile.h2
4 files changed, 69 insertions, 33 deletions
diff --git a/Source/Core/DolphinQt/GameList/GameFile.cpp b/Source/Core/DolphinQt/GameList/GameFile.cpp
index df363410f3..03c3ddd037 100644
--- a/Source/Core/DolphinQt/GameList/GameFile.cpp
+++ b/Source/Core/DolphinQt/GameList/GameFile.cpp
@@ -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);
diff --git a/Source/Core/DolphinQt/GameList/GameFile.h b/Source/Core/DolphinQt/GameList/GameFile.h
index 4c603e2236..e62fcd1a79 100644
--- a/Source/Core/DolphinQt/GameList/GameFile.h
+++ b/Source/Core/DolphinQt/GameList/GameFile.h
@@ -79,4 +79,6 @@ private:
void SaveToCache();
QString CreateCacheFilename();
+
+ void ReadBanner(const DiscIO::IVolume& volume);
};
diff --git a/Source/Core/DolphinWX/ISOFile.cpp b/Source/Core/DolphinWX/ISOFile.cpp
index a7a4706fad..2ae56e8fb1 100644
--- a/Source/Core/DolphinWX/ISOFile.cpp
+++ b/Source/Core/DolphinWX/ISOFile.cpp
@@ -34,7 +34,7 @@
#include "DolphinWX/ISOFile.h"
#include "DolphinWX/WxUtils.h"
-static const u32 CACHE_REVISION = 0x124;
+static const u32 CACHE_REVISION = 0x125; // Last changed in PR 2598
#define DVD_BANNER_WIDTH 96
#define DVD_BANNER_HEIGHT 32
@@ -74,6 +74,20 @@ GameListItem::GameListItem(const std::string& _rFileName)
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_pImage.empty())
+ {
+ std::unique_ptr<DiscIO::IVolume> volume(DiscIO::CreateVolumeFromFilename(_rFileName));
+ if (volume != nullptr)
+ {
+ ReadBanner(*volume);
+ if (!m_pImage.empty())
+ SaveToCache();
+ }
+ }
}
else
{
@@ -96,25 +110,12 @@ GameListItem::GameListItem(const std::string& _rFileName)
m_disc_number = pVolume->GetDiscNumber();
m_Revision = pVolume->GetRevision();
- std::vector<u32> Buffer = pVolume->GetBanner(&m_ImageWidth, &m_ImageHeight);
- u32* pData = Buffer.data();
- m_pImage.resize(m_ImageWidth * m_ImageHeight * 3);
-
- for (int i = 0; i < m_ImageWidth * m_ImageHeight; i++)
- {
- m_pImage[i * 3 + 0] = (pData[i] & 0xFF0000) >> 16;
- m_pImage[i * 3 + 1] = (pData[i] & 0x00FF00) >> 8;
- m_pImage[i * 3 + 2] = (pData[i] & 0x0000FF) >> 0;
- }
+ ReadBanner(*pVolume);
delete pVolume;
m_Valid = true;
-
- // Create a cache file only if we have an image.
- // Wii ISOs create their images after you have generated the first savegame
- if (!m_pImage.empty())
- SaveToCache();
+ SaveToCache();
}
}
@@ -201,6 +202,20 @@ std::string GameListItem::CreateCacheFilename()
return fullname;
}
+void GameListItem::ReadBanner(const DiscIO::IVolume& volume)
+{
+ std::vector<u32> Buffer = volume.GetBanner(&m_ImageWidth, &m_ImageHeight);
+ u32* pData = Buffer.data();
+ m_pImage.resize(m_ImageWidth * m_ImageHeight * 3);
+
+ for (int i = 0; i < m_ImageWidth * m_ImageHeight; i++)
+ {
+ m_pImage[i * 3 + 0] = (pData[i] & 0xFF0000) >> 16;
+ m_pImage[i * 3 + 1] = (pData[i] & 0x00FF00) >> 8;
+ m_pImage[i * 3 + 2] = (pData[i] & 0x0000FF) >> 0;
+ }
+}
+
std::string GameListItem::GetDescription(DiscIO::IVolume::ELanguage language) const
{
return GetLanguageString(language, m_descriptions);
diff --git a/Source/Core/DolphinWX/ISOFile.h b/Source/Core/DolphinWX/ISOFile.h
index f2a843cf67..ce9e6684f6 100644
--- a/Source/Core/DolphinWX/ISOFile.h
+++ b/Source/Core/DolphinWX/ISOFile.h
@@ -81,4 +81,6 @@ private:
void SaveToCache();
std::string CreateCacheFilename();
+
+ void ReadBanner(const DiscIO::IVolume& volume);
};