Merge pull request #2598 from JosJuice/cache-games-without-banners
Cache games without banners
This commit is contained in:
commit
3df28a4ea0
|
@ -22,10 +22,9 @@
|
|||
#include "DiscIO/Filesystem.h"
|
||||
|
||||
#include "DolphinQt/GameList/GameFile.h"
|
||||
#include "DolphinQt/Utils/Resources.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)
|
||||
|
@ -72,12 +71,23 @@ static QString GetLanguageString(DiscIO::IVolume::ELanguage language, QMap<DiscI
|
|||
GameFile::GameFile(const QString& fileName)
|
||||
: m_file_name(fileName)
|
||||
{
|
||||
bool hasBanner = false;
|
||||
|
||||
if (LoadFromCache())
|
||||
{
|
||||
m_valid = true;
|
||||
hasBanner = 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
|
||||
{
|
||||
|
@ -104,26 +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));
|
||||
}
|
||||
|
||||
if (!banner.isNull())
|
||||
{
|
||||
hasBanner = true;
|
||||
m_banner = QPixmap::fromImage(banner);
|
||||
}
|
||||
ReadBanner(*volume);
|
||||
|
||||
m_valid = true;
|
||||
if (hasBanner)
|
||||
SaveToCache();
|
||||
SaveToCache();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -138,9 +132,6 @@ GameFile::GameFile(const QString& fileName)
|
|||
ini.GetIfExists("EmuState", "EmulationIssues", &issues_temp);
|
||||
m_issues = QString::fromStdString(issues_temp);
|
||||
}
|
||||
|
||||
if (!hasBanner)
|
||||
m_banner = Resources::GetPixmap(Resources::BANNER_MISSING);
|
||||
}
|
||||
|
||||
bool GameFile::LoadFromCache()
|
||||
|
@ -247,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);
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
#include "DiscIO/Volume.h"
|
||||
#include "DiscIO/VolumeCreator.h"
|
||||
|
||||
#include "DolphinQt/Utils/Resources.h"
|
||||
|
||||
class GameFile final
|
||||
{
|
||||
public:
|
||||
|
@ -39,7 +41,13 @@ public:
|
|||
u64 GetVolumeSize() const { return m_volume_size; }
|
||||
// 0 is the first disc, 1 is the second disc
|
||||
u8 GetDiscNumber() const { return m_disc_number; }
|
||||
const QPixmap GetBitmap() const { return m_banner; }
|
||||
const QPixmap GetBitmap() const
|
||||
{
|
||||
if (m_banner.isNull())
|
||||
return Resources::GetPixmap(Resources::BANNER_MISSING);
|
||||
|
||||
return m_banner;
|
||||
}
|
||||
|
||||
private:
|
||||
QString m_file_name;
|
||||
|
@ -71,4 +79,6 @@ private:
|
|||
void SaveToCache();
|
||||
|
||||
QString CreateCacheFilename();
|
||||
|
||||
void ReadBanner(const DiscIO::IVolume& volume);
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -81,4 +81,6 @@ private:
|
|||
void SaveToCache();
|
||||
|
||||
std::string CreateCacheFilename();
|
||||
|
||||
void ReadBanner(const DiscIO::IVolume& volume);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue