diff options
| author | Leo Lam <leolino.lam@gmail.com> | 2017-09-15 19:30:05 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-09-15 19:30:05 +0200 |
| commit | 7cb8d6612c6df51073037b56ebc866f180aecd71 (patch) | |
| tree | 634e4c4d34472c6f2e49fbd48bebb6bb5f82de63 /Source/Core/DiscIO/VolumeGC.cpp | |
| parent | 7caf44c8b5a8a435ad1d9db3b2444db614d329eb (diff) | |
| parent | f294599e734f2391db9e74b6454752e75fdf368c (diff) | |
Merge pull request #5870 from JosJuice/lazy-filesystem
DiscIO: Use Common::Lazy more
Diffstat (limited to 'Source/Core/DiscIO/VolumeGC.cpp')
| -rw-r--r-- | Source/Core/DiscIO/VolumeGC.cpp | 101 |
1 files changed, 47 insertions, 54 deletions
diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index 46ac57278c..b61d273388 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include <cinttypes> #include <cstddef> #include <map> #include <memory> @@ -20,6 +21,7 @@ #include "DiscIO/Blob.h" #include "DiscIO/DiscExtractor.h" #include "DiscIO/Enums.h" +#include "DiscIO/FileSystemGCWii.h" #include "DiscIO/Filesystem.h" #include "DiscIO/Volume.h" #include "DiscIO/VolumeGC.h" @@ -29,6 +31,13 @@ namespace DiscIO VolumeGC::VolumeGC(std::unique_ptr<BlobReader> reader) : m_pReader(std::move(reader)) { _assert_(m_pReader); + + m_file_system = [this]() -> std::unique_ptr<FileSystem> { + 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() @@ -43,6 +52,11 @@ bool VolumeGC::Read(u64 _Offset, u64 _Length, u8* _pBuffer, const Partition& par return m_pReader->Read(_Offset, _Length, _pBuffer); } +const FileSystem* VolumeGC::GetFileSystem(const Partition& partition) const +{ + return m_file_system->get(); +} + std::string VolumeGC::GetGameID(const Partition& partition) const { static const std::string NO_UID("NO_UID"); @@ -113,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 @@ -183,39 +191,19 @@ 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; - std::unique_ptr<FileSystem> file_system(CreateFileSystem(this, PARTITION_NONE)); - if (!file_system) - return; - - std::unique_ptr<FileInfo> file_info = file_system->FindFileInfo("opening.bnr"); - if (!file_info) - return; - - size_t file_size = static_cast<size_t>(file_info->GetSize()); - constexpr int BNR1_MAGIC = 0x31524e42; - constexpr int BNR2_MAGIC = 0x32524e42; - if (file_size != BNR1_SIZE && file_size != BNR2_SIZE) - { - WARN_LOG(DISCIO, "Invalid opening.bnr. Size: %0zx", file_size); - return; - } - - if (file_size != ReadFile(*this, PARTITION_NONE, file_info.get(), - reinterpret_cast<u8*>(&banner_file), file_size)) + 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 {}; // Return early so that we don't access the uninitialized banner_file.id } + constexpr u32 BNR1_MAGIC = 0x31524e42; + constexpr u32 BNR2_MAGIC = 0x32524e42; bool is_bnr1; if (banner_file.id == BNR1_MAGIC && file_size == BNR1_SIZE) { @@ -228,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; @@ -251,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) { @@ -264,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 |
