mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 21:30:19 -06:00
DolphinWX: properly sync EmuState and banner changes.
This commit is contained in:
@ -61,17 +61,15 @@ static std::string GetLanguageString(DiscIO::Language language,
|
||||
return "";
|
||||
}
|
||||
|
||||
GameListItem::GameListItem(const std::string& _rFileName, const Core::TitleDatabase& title_database)
|
||||
: m_FileName(_rFileName), m_title_id(0), m_emu_state(0), m_FileSize(0),
|
||||
m_region(DiscIO::Region::UNKNOWN_REGION), m_Country(DiscIO::Country::COUNTRY_UNKNOWN),
|
||||
m_Revision(0), m_Valid(false), m_ImageWidth(0), m_ImageHeight(0), m_disc_number(0),
|
||||
m_has_custom_name(false)
|
||||
GameListItem::GameListItem(const std::string& filename, const Core::TitleDatabase& title_database)
|
||||
: m_file_name(filename), m_region(DiscIO::Region::UNKNOWN_REGION),
|
||||
m_country(DiscIO::Country::COUNTRY_UNKNOWN)
|
||||
{
|
||||
{
|
||||
std::unique_ptr<DiscIO::Volume> volume(DiscIO::CreateVolumeFromFilename(_rFileName));
|
||||
std::unique_ptr<DiscIO::Volume> volume(DiscIO::CreateVolumeFromFilename(m_file_name));
|
||||
if (volume != nullptr)
|
||||
{
|
||||
m_Platform = volume->GetVolumeType();
|
||||
m_platform = volume->GetVolumeType();
|
||||
|
||||
m_descriptions = volume->GetDescriptions();
|
||||
m_names = volume->GetLongNames();
|
||||
@ -82,20 +80,20 @@ GameListItem::GameListItem(const std::string& _rFileName, const Core::TitleDatab
|
||||
m_company = GetLanguageString(DiscIO::Language::LANGUAGE_ENGLISH, volume->GetShortMakers());
|
||||
|
||||
m_region = volume->GetRegion();
|
||||
m_Country = volume->GetCountry();
|
||||
m_country = volume->GetCountry();
|
||||
m_blob_type = volume->GetBlobType();
|
||||
m_FileSize = volume->GetRawSize();
|
||||
m_VolumeSize = volume->GetSize();
|
||||
m_file_size = volume->GetRawSize();
|
||||
m_volume_size = volume->GetSize();
|
||||
|
||||
m_game_id = volume->GetGameID();
|
||||
m_title_id = volume->GetTitleID().value_or(0);
|
||||
m_disc_number = volume->GetDiscNumber().value_or(0);
|
||||
m_Revision = volume->GetRevision().value_or(0);
|
||||
m_revision = volume->GetRevision().value_or(0);
|
||||
|
||||
std::vector<u32> buffer = volume->GetBanner(&m_ImageWidth, &m_ImageHeight);
|
||||
ReadVolumeBanner(buffer, m_ImageWidth, m_ImageHeight);
|
||||
std::vector<u32> buffer = volume->GetBanner(&m_banner.width, &m_banner.height);
|
||||
ReadVolumeBanner(&m_banner.buffer, buffer, m_banner.width, m_banner.height);
|
||||
|
||||
m_Valid = true;
|
||||
m_valid = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,22 +102,21 @@ GameListItem::GameListItem(const std::string& _rFileName, const Core::TitleDatab
|
||||
|
||||
if (IsValid())
|
||||
{
|
||||
const auto type = m_Platform == DiscIO::Platform::WII_WAD ?
|
||||
const auto type = m_platform == DiscIO::Platform::WII_WAD ?
|
||||
Core::TitleDatabase::TitleType::Channel :
|
||||
Core::TitleDatabase::TitleType::Other;
|
||||
m_custom_name_titles_txt = title_database.GetTitleName(m_game_id, type);
|
||||
ReloadINI();
|
||||
m_custom_name = title_database.GetTitleName(m_game_id, type);
|
||||
}
|
||||
|
||||
if (!IsValid() && IsElfOrDol())
|
||||
{
|
||||
m_Valid = true;
|
||||
m_FileSize = File::GetSize(_rFileName);
|
||||
m_Platform = DiscIO::Platform::ELF_DOL;
|
||||
m_valid = true;
|
||||
m_file_size = File::GetSize(m_file_name);
|
||||
m_platform = DiscIO::Platform::ELF_DOL;
|
||||
m_blob_type = DiscIO::BlobType::DIRECTORY;
|
||||
|
||||
std::string path, name;
|
||||
SplitPath(m_FileName, &path, &name, nullptr);
|
||||
SplitPath(m_file_name, &path, &name, nullptr);
|
||||
|
||||
// A bit like the Homebrew Channel icon, except there can be multiple files
|
||||
// in a folder with their own icons. Useful for those who don't want to have
|
||||
@ -135,88 +132,92 @@ GameListItem::GameListItem(const std::string& _rFileName, const Core::TitleDatab
|
||||
else
|
||||
{
|
||||
// Volume banner. Typical for everything that isn't a DOL or ELF.
|
||||
SetWxBannerFromRaw();
|
||||
SetWxBannerFromRaw(m_banner);
|
||||
}
|
||||
}
|
||||
|
||||
bool GameListItem::IsValid() const
|
||||
{
|
||||
if (!m_Valid)
|
||||
if (!m_valid)
|
||||
return false;
|
||||
|
||||
if (m_Platform == DiscIO::Platform::WII_WAD && !IOS::ES::IsChannel(m_title_id))
|
||||
if (m_platform == DiscIO::Platform::WII_WAD && !IOS::ES::IsChannel(m_title_id))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void GameListItem::ReloadINI()
|
||||
bool GameListItem::EmuStateChanged()
|
||||
{
|
||||
if (!IsValid())
|
||||
return;
|
||||
IniFile ini = SConfig::LoadGameIni(m_game_id, m_revision);
|
||||
ini.GetIfExists("EmuState", "EmulationStateId", &m_pending.emu_state.rating, 0);
|
||||
ini.GetIfExists("EmuState", "EmulationIssues", &m_pending.emu_state.issues, std::string());
|
||||
return m_emu_state != m_pending.emu_state;
|
||||
}
|
||||
|
||||
IniFile ini = SConfig::LoadGameIni(m_game_id, m_Revision);
|
||||
ini.GetIfExists("EmuState", "EmulationStateId", &m_emu_state, 0);
|
||||
ini.GetIfExists("EmuState", "EmulationIssues", &m_issues, std::string());
|
||||
void GameListItem::EmuStateCommit()
|
||||
{
|
||||
m_emu_state = m_pending.emu_state;
|
||||
}
|
||||
|
||||
m_custom_name.clear();
|
||||
m_has_custom_name = ini.GetIfExists("EmuState", "Title", &m_custom_name);
|
||||
if (!m_has_custom_name && !m_custom_name_titles_txt.empty())
|
||||
{
|
||||
m_custom_name = m_custom_name_titles_txt;
|
||||
m_has_custom_name = true;
|
||||
}
|
||||
void GameListItem::EmuState::DoState(PointerWrap& p)
|
||||
{
|
||||
p.Do(rating);
|
||||
p.Do(issues);
|
||||
}
|
||||
|
||||
void GameListItem::Banner::DoState(PointerWrap& p)
|
||||
{
|
||||
p.Do(buffer);
|
||||
p.Do(width);
|
||||
p.Do(height);
|
||||
}
|
||||
|
||||
void GameListItem::DoState(PointerWrap& p)
|
||||
{
|
||||
p.Do(m_FileName);
|
||||
p.Do(m_valid);
|
||||
p.Do(m_file_name);
|
||||
p.Do(m_file_size);
|
||||
p.Do(m_volume_size);
|
||||
p.Do(m_names);
|
||||
p.Do(m_descriptions);
|
||||
p.Do(m_company);
|
||||
p.Do(m_game_id);
|
||||
p.Do(m_title_id);
|
||||
p.Do(m_issues);
|
||||
p.Do(m_emu_state);
|
||||
p.Do(m_FileSize);
|
||||
p.Do(m_VolumeSize);
|
||||
p.Do(m_region);
|
||||
p.Do(m_Country);
|
||||
p.Do(m_Platform);
|
||||
p.Do(m_country);
|
||||
p.Do(m_platform);
|
||||
p.Do(m_blob_type);
|
||||
p.Do(m_Revision);
|
||||
p.Do(m_pImage);
|
||||
p.Do(m_Valid);
|
||||
p.Do(m_ImageWidth);
|
||||
p.Do(m_ImageHeight);
|
||||
p.Do(m_revision);
|
||||
p.Do(m_disc_number);
|
||||
p.Do(m_custom_name_titles_txt);
|
||||
m_banner.DoState(p);
|
||||
m_emu_state.DoState(p);
|
||||
p.Do(m_custom_name);
|
||||
p.Do(m_has_custom_name);
|
||||
if (p.GetMode() == PointerWrap::MODE_READ)
|
||||
{
|
||||
SetWxBannerFromRaw();
|
||||
SetWxBannerFromRaw(m_banner);
|
||||
}
|
||||
}
|
||||
|
||||
bool GameListItem::IsElfOrDol() const
|
||||
{
|
||||
if (m_FileName.size() < 4)
|
||||
if (m_file_name.size() < 4)
|
||||
return false;
|
||||
|
||||
std::string name_end = m_FileName.substr(m_FileName.size() - 4);
|
||||
std::string name_end = m_file_name.substr(m_file_name.size() - 4);
|
||||
std::transform(name_end.begin(), name_end.end(), name_end.begin(), ::tolower);
|
||||
return name_end == ".elf" || name_end == ".dol";
|
||||
}
|
||||
|
||||
void GameListItem::ReadVolumeBanner(const std::vector<u32>& buffer, int width, int height)
|
||||
void GameListItem::ReadVolumeBanner(std::vector<u8>* image, const std::vector<u32>& buffer,
|
||||
int width, int height)
|
||||
{
|
||||
m_pImage.resize(width * height * 3);
|
||||
image->resize(width * height * 3);
|
||||
for (int i = 0; i < width * height; i++)
|
||||
{
|
||||
m_pImage[i * 3 + 0] = (buffer[i] & 0xFF0000) >> 16;
|
||||
m_pImage[i * 3 + 1] = (buffer[i] & 0x00FF00) >> 8;
|
||||
m_pImage[i * 3 + 2] = (buffer[i] & 0x0000FF) >> 0;
|
||||
(*image)[i * 3 + 0] = (buffer[i] & 0xFF0000) >> 16;
|
||||
(*image)[i * 3 + 1] = (buffer[i] & 0x00FF00) >> 8;
|
||||
(*image)[i * 3 + 2] = (buffer[i] & 0x0000FF) >> 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -229,41 +230,49 @@ bool GameListItem::SetWxBannerFromPngFile(const std::string& path)
|
||||
if (!image.IsOk())
|
||||
return false;
|
||||
|
||||
m_image = image;
|
||||
m_banner_wx = image;
|
||||
return true;
|
||||
}
|
||||
|
||||
void GameListItem::SetWxBannerFromRaw()
|
||||
void GameListItem::SetWxBannerFromRaw(const Banner& banner)
|
||||
{
|
||||
// Need to make explicit copy as wxImage uses reference counting for copies combined with only
|
||||
// taking a pointer, not the content, when given a buffer to its constructor.
|
||||
if (!m_pImage.empty())
|
||||
if (!banner.empty())
|
||||
{
|
||||
m_image.Create(m_ImageWidth, m_ImageHeight, false);
|
||||
std::memcpy(m_image.GetData(), m_pImage.data(), m_pImage.size());
|
||||
m_banner_wx.Create(banner.width, banner.height, false);
|
||||
std::memcpy(m_banner_wx.GetData(), banner.buffer.data(), banner.buffer.size());
|
||||
}
|
||||
}
|
||||
|
||||
bool GameListItem::ReloadBannerIfNeeded()
|
||||
bool GameListItem::BannerChanged()
|
||||
{
|
||||
// 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_Platform == DiscIO::Platform::WII_DISC || m_Platform == DiscIO::Platform::WII_WAD) &&
|
||||
m_pImage.empty())
|
||||
if ((m_platform == DiscIO::Platform::WII_DISC || m_platform == DiscIO::Platform::WII_WAD) &&
|
||||
m_banner.empty())
|
||||
{
|
||||
auto& banner = m_pending.banner;
|
||||
std::vector<u32> buffer =
|
||||
DiscIO::Volume::GetWiiBanner(&m_ImageWidth, &m_ImageHeight, m_title_id);
|
||||
DiscIO::Volume::GetWiiBanner(&banner.width, &banner.height, m_title_id);
|
||||
if (buffer.size())
|
||||
{
|
||||
ReadVolumeBanner(buffer, m_ImageWidth, m_ImageHeight);
|
||||
SetWxBannerFromRaw();
|
||||
ReadVolumeBanner(&banner.buffer, buffer, banner.width, banner.height);
|
||||
// Only reach here if m_banner was empty, so don't need to explicitly compare to see if
|
||||
// different
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void GameListItem::BannerCommit()
|
||||
{
|
||||
m_banner = std::move(m_pending.banner);
|
||||
SetWxBannerFromRaw(m_banner);
|
||||
}
|
||||
|
||||
std::string GameListItem::GetDescription(DiscIO::Language language) const
|
||||
{
|
||||
return GetLanguageString(language, m_descriptions);
|
||||
@ -271,7 +280,7 @@ std::string GameListItem::GetDescription(DiscIO::Language language) const
|
||||
|
||||
std::string GameListItem::GetDescription() const
|
||||
{
|
||||
bool wii = m_Platform != DiscIO::Platform::GAMECUBE_DISC;
|
||||
bool wii = m_platform != DiscIO::Platform::GAMECUBE_DISC;
|
||||
return GetDescription(SConfig::GetInstance().GetCurrentLanguage(wii));
|
||||
}
|
||||
|
||||
@ -282,10 +291,10 @@ std::string GameListItem::GetName(DiscIO::Language language) const
|
||||
|
||||
std::string GameListItem::GetName() const
|
||||
{
|
||||
if (m_has_custom_name)
|
||||
if (!m_custom_name.empty())
|
||||
return m_custom_name;
|
||||
|
||||
bool wii = m_Platform != DiscIO::Platform::GAMECUBE_DISC;
|
||||
bool wii = m_platform != DiscIO::Platform::GAMECUBE_DISC;
|
||||
std::string name = GetName(SConfig::GetInstance().GetCurrentLanguage(wii));
|
||||
if (!name.empty())
|
||||
return name;
|
||||
@ -341,7 +350,7 @@ std::vector<DiscIO::Language> GameListItem::GetLanguages() const
|
||||
|
||||
const std::string GameListItem::GetWiiFSPath() const
|
||||
{
|
||||
if (m_Platform != DiscIO::Platform::WII_DISC && m_Platform != DiscIO::Platform::WII_WAD)
|
||||
if (m_platform != DiscIO::Platform::WII_DISC && m_platform != DiscIO::Platform::WII_WAD)
|
||||
return "";
|
||||
|
||||
const std::string path = Common::GetTitleDataPath(m_title_id, Common::FROM_CONFIGURED_ROOT);
|
||||
|
Reference in New Issue
Block a user