mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-04-26 22:38:34 +00:00
DiscIO: Use Common::Lazy for loading GC banners
This commit is contained in:
parent
ca36c977d9
commit
f294599e73
3 changed files with 51 additions and 60 deletions
|
@ -36,6 +36,8 @@ VolumeGC::VolumeGC(std::unique_ptr<BlobReader> reader) : m_pReader(std::move(rea
|
|||
auto file_system = std::make_unique<FileSystemGCWii>(this, PARTITION_NONE);
|
||||
return file_system->IsValid() ? std::move(file_system) : nullptr;
|
||||
};
|
||||
|
||||
m_converted_banner = [this] { return LoadBannerFile(); };
|
||||
}
|
||||
|
||||
VolumeGC::~VolumeGC()
|
||||
|
@ -125,40 +127,34 @@ std::string VolumeGC::GetInternalName(const Partition& partition) const
|
|||
|
||||
std::map<Language, std::string> VolumeGC::GetShortNames() const
|
||||
{
|
||||
LoadBannerFile();
|
||||
return m_short_names;
|
||||
return m_converted_banner->short_names;
|
||||
}
|
||||
|
||||
std::map<Language, std::string> VolumeGC::GetLongNames() const
|
||||
{
|
||||
LoadBannerFile();
|
||||
return m_long_names;
|
||||
return m_converted_banner->long_names;
|
||||
}
|
||||
|
||||
std::map<Language, std::string> VolumeGC::GetShortMakers() const
|
||||
{
|
||||
LoadBannerFile();
|
||||
return m_short_makers;
|
||||
return m_converted_banner->short_makers;
|
||||
}
|
||||
|
||||
std::map<Language, std::string> VolumeGC::GetLongMakers() const
|
||||
{
|
||||
LoadBannerFile();
|
||||
return m_long_makers;
|
||||
return m_converted_banner->long_makers;
|
||||
}
|
||||
|
||||
std::map<Language, std::string> VolumeGC::GetDescriptions() const
|
||||
{
|
||||
LoadBannerFile();
|
||||
return m_descriptions;
|
||||
return m_converted_banner->descriptions;
|
||||
}
|
||||
|
||||
std::vector<u32> VolumeGC::GetBanner(int* width, int* height) const
|
||||
{
|
||||
LoadBannerFile();
|
||||
*width = m_image_width;
|
||||
*height = m_image_height;
|
||||
return m_image_buffer;
|
||||
*width = m_converted_banner->image_width;
|
||||
*height = m_converted_banner->image_height;
|
||||
return m_converted_banner->image_buffer;
|
||||
}
|
||||
|
||||
std::string VolumeGC::GetApploaderDate(const Partition& partition) const
|
||||
|
@ -195,21 +191,15 @@ Platform VolumeGC::GetVolumeType() const
|
|||
return Platform::GAMECUBE_DISC;
|
||||
}
|
||||
|
||||
void VolumeGC::LoadBannerFile() const
|
||||
VolumeGC::ConvertedGCBanner VolumeGC::LoadBannerFile() const
|
||||
{
|
||||
// If opening.bnr has been loaded already, return immediately
|
||||
if (m_banner_loaded)
|
||||
return;
|
||||
|
||||
m_banner_loaded = true;
|
||||
|
||||
GCBanner banner_file;
|
||||
const u64 file_size = ReadFile(*this, PARTITION_NONE, "opening.bnr",
|
||||
reinterpret_cast<u8*>(&banner_file), sizeof(GCBanner));
|
||||
if (file_size < 4)
|
||||
{
|
||||
WARN_LOG(DISCIO, "Could not read opening.bnr.");
|
||||
return; // Return early so that we don't access the uninitialized banner_file.id
|
||||
return {}; // Return early so that we don't access the uninitialized banner_file.id
|
||||
}
|
||||
|
||||
constexpr u32 BNR1_MAGIC = 0x31524e42;
|
||||
|
@ -226,14 +216,17 @@ void VolumeGC::LoadBannerFile() const
|
|||
else
|
||||
{
|
||||
WARN_LOG(DISCIO, "Invalid opening.bnr. Type: %0x Size: %0zx", banner_file.id, file_size);
|
||||
return;
|
||||
return {};
|
||||
}
|
||||
|
||||
ExtractBannerInformation(banner_file, is_bnr1);
|
||||
return ExtractBannerInformation(banner_file, is_bnr1);
|
||||
}
|
||||
|
||||
void VolumeGC::ExtractBannerInformation(const GCBanner& banner_file, bool is_bnr1) const
|
||||
VolumeGC::ConvertedGCBanner VolumeGC::ExtractBannerInformation(const GCBanner& banner_file,
|
||||
bool is_bnr1) const
|
||||
{
|
||||
ConvertedGCBanner banner;
|
||||
|
||||
u32 number_of_languages = 0;
|
||||
Language start_language = Language::LANGUAGE_UNKNOWN;
|
||||
|
||||
|
@ -249,11 +242,11 @@ void VolumeGC::ExtractBannerInformation(const GCBanner& banner_file, bool is_bnr
|
|||
start_language = Language::LANGUAGE_ENGLISH;
|
||||
}
|
||||
|
||||
m_image_width = GC_BANNER_WIDTH;
|
||||
m_image_height = GC_BANNER_HEIGHT;
|
||||
m_image_buffer = std::vector<u32>(m_image_width * m_image_height);
|
||||
ColorUtil::decode5A3image(m_image_buffer.data(), banner_file.image, m_image_width,
|
||||
m_image_height);
|
||||
banner.image_width = GC_BANNER_WIDTH;
|
||||
banner.image_height = GC_BANNER_HEIGHT;
|
||||
banner.image_buffer = std::vector<u32>(GC_BANNER_WIDTH * GC_BANNER_HEIGHT);
|
||||
ColorUtil::decode5A3image(banner.image_buffer.data(), banner_file.image, GC_BANNER_WIDTH,
|
||||
GC_BANNER_HEIGHT);
|
||||
|
||||
for (u32 i = 0; i < number_of_languages; ++i)
|
||||
{
|
||||
|
@ -262,24 +255,26 @@ void VolumeGC::ExtractBannerInformation(const GCBanner& banner_file, bool is_bnr
|
|||
|
||||
std::string description = DecodeString(info.description);
|
||||
if (!description.empty())
|
||||
m_descriptions[language] = description;
|
||||
banner.descriptions.emplace(language, description);
|
||||
|
||||
std::string short_name = DecodeString(info.short_name);
|
||||
if (!short_name.empty())
|
||||
m_short_names[language] = short_name;
|
||||
banner.short_names.emplace(language, short_name);
|
||||
|
||||
std::string long_name = DecodeString(info.long_name);
|
||||
if (!long_name.empty())
|
||||
m_long_names[language] = long_name;
|
||||
banner.long_names.emplace(language, long_name);
|
||||
|
||||
std::string short_maker = DecodeString(info.short_maker);
|
||||
if (!short_maker.empty())
|
||||
m_short_makers[language] = short_maker;
|
||||
banner.short_makers.emplace(language, short_maker);
|
||||
|
||||
std::string long_maker = DecodeString(info.long_maker);
|
||||
if (!long_maker.empty())
|
||||
m_long_makers[language] = long_maker;
|
||||
banner.long_makers.emplace(language, long_maker);
|
||||
}
|
||||
|
||||
return banner;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue