From 235ecfbed71986f0be2ecf469a10e1105dcb3c96 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Thu, 9 Apr 2015 17:44:53 +0200 Subject: Return GetNames languages, to avoid hardcoded language lists in callers This makes the code cleaner and also leads to some user-visible changes: The wx game properties will no longer let the user select WAD languages that don't have any names. The Qt game list will now display names using the languages set in the configuration instead of always using English for PAL GC games and Japanese for WADs. If a WAD doesn't have a name in the user's preferred language, English is now selected as a fallback before Japanese. --- Source/Core/DiscIO/BannerLoaderGC.cpp | 60 +++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 28 deletions(-) (limited to 'Source/Core/DiscIO/BannerLoaderGC.cpp') diff --git a/Source/Core/DiscIO/BannerLoaderGC.cpp b/Source/Core/DiscIO/BannerLoaderGC.cpp index ce265a016e..a5da3c4512 100644 --- a/Source/Core/DiscIO/BannerLoaderGC.cpp +++ b/Source/Core/DiscIO/BannerLoaderGC.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include #include @@ -60,9 +61,9 @@ std::vector CBannerLoaderGC::GetBanner(int* pWidth, int* pHeight) } -std::vector CBannerLoaderGC::GetNames() +std::map CBannerLoaderGC::GetNames() { - std::vector names; + std::map names; if (!IsValid()) { @@ -70,16 +71,21 @@ std::vector CBannerLoaderGC::GetNames() } u32 name_count = 0; + IVolume::ELanguage language; + bool is_japanese = m_country == IVolume::ECountry::COUNTRY_JAPAN; // find Banner type switch (m_BNRType) { case CBannerLoaderGC::BANNER_BNR1: name_count = 1; + language = is_japanese ? IVolume::ELanguage::LANGUAGE_JAPANESE : IVolume::ELanguage::LANGUAGE_ENGLISH; break; + // English, German, French, Spanish, Italian, Dutch case CBannerLoaderGC::BANNER_BNR2: name_count = 6; + language = IVolume::ELanguage::LANGUAGE_ENGLISH; break; default: @@ -88,20 +94,16 @@ std::vector CBannerLoaderGC::GetNames() auto const banner = reinterpret_cast(m_pBannerFile); - for (u32 i = 0; i != name_count; ++i) + for (u32 i = 0; i < name_count; ++i) { auto& comment = banner->comment[i]; + std::string name = GetDecodedString(comment.longTitle); - if (comment.longTitle[0]) - { - auto& data = comment.longTitle; - names.push_back(GetDecodedString(data)); - } - else - { - auto& data = comment.shortTitle; - names.push_back(GetDecodedString(data)); - } + if (name.empty()) + name = GetDecodedString(comment.shortTitle); + + if (!name.empty()) + names[(IVolume::ELanguage)(language + i)] = name; } return names; @@ -123,9 +125,9 @@ std::string CBannerLoaderGC::GetCompany() } -std::vector CBannerLoaderGC::GetDescriptions() +std::map CBannerLoaderGC::GetDescriptions() { - std::vector descriptions; + std::map descriptions; if (!IsValid()) { @@ -133,16 +135,20 @@ std::vector CBannerLoaderGC::GetDescriptions() } u32 desc_count = 0; + IVolume::ELanguage language; + bool is_japanese = m_country == IVolume::ECountry::COUNTRY_JAPAN; // find Banner type switch (m_BNRType) { case CBannerLoaderGC::BANNER_BNR1: desc_count = 1; + language = is_japanese ? IVolume::ELanguage::LANGUAGE_JAPANESE : IVolume::ELanguage::LANGUAGE_ENGLISH; break; // English, German, French, Spanish, Italian, Dutch case CBannerLoaderGC::BANNER_BNR2: + language = IVolume::ELanguage::LANGUAGE_ENGLISH; desc_count = 6; break; @@ -152,10 +158,13 @@ std::vector CBannerLoaderGC::GetDescriptions() auto banner = reinterpret_cast(m_pBannerFile); - for (u32 i = 0; i != desc_count; ++i) + for (u32 i = 0; i < desc_count; ++i) { auto& data = banner->comment[i].comment; - descriptions.push_back(GetDecodedString(data)); + std::string description = GetDecodedString(data); + + if (!description.empty()) + descriptions[(IVolume::ELanguage)(language + i)] = description; } return descriptions; @@ -164,20 +173,15 @@ std::vector CBannerLoaderGC::GetDescriptions() CBannerLoaderGC::BANNER_TYPE CBannerLoaderGC::getBannerType() { u32 bannerSignature = *(u32*)m_pBannerFile; - CBannerLoaderGC::BANNER_TYPE type = CBannerLoaderGC::BANNER_UNKNOWN; switch (bannerSignature) { - // "BNR1" - case 0x31524e42: - type = CBannerLoaderGC::BANNER_BNR1; - break; - - // "BNR2" - case 0x32524e42: - type = CBannerLoaderGC::BANNER_BNR2; - break; + case 0x31524e42: // "BNR1" + return CBannerLoaderGC::BANNER_BNR1; + case 0x32524e42: // "BNR2" + return CBannerLoaderGC::BANNER_BNR2; + default: + return CBannerLoaderGC::BANNER_UNKNOWN; } - return type; } } // namespace -- cgit v1.2.3 From ee694e327ada8c42949a3907d6fa222f73f276b0 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Fri, 10 Apr 2015 22:10:49 +0200 Subject: Get rid of banner loaders and move their functionality to volumes Having some data available in banner loaders and some other data data available in volumes gets messy, especially with GetNames(), which is available in both but returns different results depending on which one is used. This change drops support for reading names and descriptions from Wii save data. --- Source/Core/DiscIO/BannerLoaderGC.cpp | 187 ---------------------------------- 1 file changed, 187 deletions(-) delete mode 100644 Source/Core/DiscIO/BannerLoaderGC.cpp (limited to 'Source/Core/DiscIO/BannerLoaderGC.cpp') diff --git a/Source/Core/DiscIO/BannerLoaderGC.cpp b/Source/Core/DiscIO/BannerLoaderGC.cpp deleted file mode 100644 index a5da3c4512..0000000000 --- a/Source/Core/DiscIO/BannerLoaderGC.cpp +++ /dev/null @@ -1,187 +0,0 @@ -// Copyright 2013 Dolphin Emulator Project -// Licensed under GPLv2 -// Refer to the license.txt file included. - -#include -#include -#include -#include - -#include "Common/ColorUtil.h" -#include "Common/CommonTypes.h" -#include "Common/MsgHandler.h" -#include "Common/Logging/Log.h" -#include "DiscIO/BannerLoaderGC.h" -#include "DiscIO/Filesystem.h" -#include "DiscIO/Volume.h" - -namespace DiscIO -{ -CBannerLoaderGC::CBannerLoaderGC(DiscIO::IFileSystem& _rFileSystem, DiscIO::IVolume* volume) - : m_country(volume->GetCountry()) -{ - // load the opening.bnr - size_t FileSize = (size_t) _rFileSystem.GetFileSize("opening.bnr"); - if (FileSize == BNR1_SIZE || FileSize == BNR2_SIZE) - { - m_pBannerFile = new u8[FileSize]; - if (m_pBannerFile) - { - _rFileSystem.ReadFile("opening.bnr", m_pBannerFile, FileSize); - m_BNRType = getBannerType(); - if (m_BNRType == BANNER_UNKNOWN) - PanicAlertT("Invalid opening.bnr found in gcm:\n%s\n You may need to redump this game.", - _rFileSystem.GetVolume()->GetName().c_str()); - else m_IsValid = true; - } - } - else WARN_LOG(DISCIO, "Invalid opening.bnr size: %0lx", - (unsigned long)FileSize); -} - - -CBannerLoaderGC::~CBannerLoaderGC() -{ - if (m_pBannerFile) - { - delete [] m_pBannerFile; - m_pBannerFile = nullptr; - } -} - -std::vector CBannerLoaderGC::GetBanner(int* pWidth, int* pHeight) -{ - std::vector Buffer; - Buffer.resize(DVD_BANNER_WIDTH * DVD_BANNER_HEIGHT); - auto const pBanner = (DVDBanner*)m_pBannerFile; - ColorUtil::decode5A3image(&Buffer[0], pBanner->image, DVD_BANNER_WIDTH, DVD_BANNER_HEIGHT); - *pWidth = DVD_BANNER_WIDTH; - *pHeight = DVD_BANNER_HEIGHT; - return Buffer; -} - - -std::map CBannerLoaderGC::GetNames() -{ - std::map names; - - if (!IsValid()) - { - return names; - } - - u32 name_count = 0; - IVolume::ELanguage language; - bool is_japanese = m_country == IVolume::ECountry::COUNTRY_JAPAN; - - // find Banner type - switch (m_BNRType) - { - case CBannerLoaderGC::BANNER_BNR1: - name_count = 1; - language = is_japanese ? IVolume::ELanguage::LANGUAGE_JAPANESE : IVolume::ELanguage::LANGUAGE_ENGLISH; - break; - - // English, German, French, Spanish, Italian, Dutch - case CBannerLoaderGC::BANNER_BNR2: - name_count = 6; - language = IVolume::ELanguage::LANGUAGE_ENGLISH; - break; - - default: - break; - } - - auto const banner = reinterpret_cast(m_pBannerFile); - - for (u32 i = 0; i < name_count; ++i) - { - auto& comment = banner->comment[i]; - std::string name = GetDecodedString(comment.longTitle); - - if (name.empty()) - name = GetDecodedString(comment.shortTitle); - - if (!name.empty()) - names[(IVolume::ELanguage)(language + i)] = name; - } - - return names; -} - - -std::string CBannerLoaderGC::GetCompany() -{ - std::string company; - - if (IsValid()) - { - auto const pBanner = (DVDBanner*)m_pBannerFile; - auto& data = pBanner->comment[0].shortMaker; - company = GetDecodedString(data); - } - - return company; -} - - -std::map CBannerLoaderGC::GetDescriptions() -{ - std::map descriptions; - - if (!IsValid()) - { - return descriptions; - } - - u32 desc_count = 0; - IVolume::ELanguage language; - bool is_japanese = m_country == IVolume::ECountry::COUNTRY_JAPAN; - - // find Banner type - switch (m_BNRType) - { - case CBannerLoaderGC::BANNER_BNR1: - desc_count = 1; - language = is_japanese ? IVolume::ELanguage::LANGUAGE_JAPANESE : IVolume::ELanguage::LANGUAGE_ENGLISH; - break; - - // English, German, French, Spanish, Italian, Dutch - case CBannerLoaderGC::BANNER_BNR2: - language = IVolume::ELanguage::LANGUAGE_ENGLISH; - desc_count = 6; - break; - - default: - break; - } - - auto banner = reinterpret_cast(m_pBannerFile); - - for (u32 i = 0; i < desc_count; ++i) - { - auto& data = banner->comment[i].comment; - std::string description = GetDecodedString(data); - - if (!description.empty()) - descriptions[(IVolume::ELanguage)(language + i)] = description; - } - - return descriptions; -} - -CBannerLoaderGC::BANNER_TYPE CBannerLoaderGC::getBannerType() -{ - u32 bannerSignature = *(u32*)m_pBannerFile; - switch (bannerSignature) - { - case 0x31524e42: // "BNR1" - return CBannerLoaderGC::BANNER_BNR1; - case 0x32524e42: // "BNR2" - return CBannerLoaderGC::BANNER_BNR2; - default: - return CBannerLoaderGC::BANNER_UNKNOWN; - } -} - -} // namespace -- cgit v1.2.3