diff options
| author | JosJuice <josjuice@gmail.com> | 2015-04-09 17:44:53 +0200 |
|---|---|---|
| committer | JosJuice <josjuice@gmail.com> | 2015-04-23 08:14:39 +0200 |
| commit | 235ecfbed71986f0be2ecf469a10e1105dcb3c96 (patch) | |
| tree | 36427d6c1bedd2b695fc3bd68a66743d8c26e33f /Source/Core/DiscIO | |
| parent | 87a63713f4f7c583545f23b75ed8395913c8e600 (diff) | |
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.
Diffstat (limited to 'Source/Core/DiscIO')
| -rw-r--r-- | Source/Core/DiscIO/BannerLoader.h | 6 | ||||
| -rw-r--r-- | Source/Core/DiscIO/BannerLoaderGC.cpp | 60 | ||||
| -rw-r--r-- | Source/Core/DiscIO/BannerLoaderGC.h | 5 | ||||
| -rw-r--r-- | Source/Core/DiscIO/BannerLoaderWii.cpp | 23 | ||||
| -rw-r--r-- | Source/Core/DiscIO/BannerLoaderWii.h | 5 | ||||
| -rw-r--r-- | Source/Core/DiscIO/Volume.h | 60 | ||||
| -rw-r--r-- | Source/Core/DiscIO/VolumeCommon.cpp | 3 | ||||
| -rw-r--r-- | Source/Core/DiscIO/VolumeDirectory.cpp | 7 | ||||
| -rw-r--r-- | Source/Core/DiscIO/VolumeDirectory.h | 2 | ||||
| -rw-r--r-- | Source/Core/DiscIO/VolumeGC.cpp | 7 | ||||
| -rw-r--r-- | Source/Core/DiscIO/VolumeGC.h | 3 | ||||
| -rw-r--r-- | Source/Core/DiscIO/VolumeWad.cpp | 20 | ||||
| -rw-r--r-- | Source/Core/DiscIO/VolumeWad.h | 3 | ||||
| -rw-r--r-- | Source/Core/DiscIO/VolumeWiiCrypted.cpp | 7 | ||||
| -rw-r--r-- | Source/Core/DiscIO/VolumeWiiCrypted.h | 3 |
15 files changed, 125 insertions, 89 deletions
diff --git a/Source/Core/DiscIO/BannerLoader.h b/Source/Core/DiscIO/BannerLoader.h index 7d6a25b8cf..31a09f56d0 100644 --- a/Source/Core/DiscIO/BannerLoader.h +++ b/Source/Core/DiscIO/BannerLoader.h @@ -4,10 +4,12 @@ #pragma once +#include <map> #include <string> #include <vector> #include "Common/CommonTypes.h" +#include "DiscIO/Volume.h" namespace DiscIO { @@ -28,9 +30,9 @@ public: virtual std::vector<u32> GetBanner(int* pWidth, int* pHeight) = 0; - virtual std::vector<std::string> GetNames() = 0; + virtual std::map<IVolume::ELanguage, std::string> GetNames() = 0; virtual std::string GetCompany() = 0; - virtual std::vector<std::string> GetDescriptions() = 0; + virtual std::map<IVolume::ELanguage, std::string> GetDescriptions() = 0; bool IsValid() { 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 <cstddef> +#include <map> #include <string> #include <vector> @@ -60,9 +61,9 @@ std::vector<u32> CBannerLoaderGC::GetBanner(int* pWidth, int* pHeight) } -std::vector<std::string> CBannerLoaderGC::GetNames() +std::map<IVolume::ELanguage, std::string> CBannerLoaderGC::GetNames() { - std::vector<std::string> names; + std::map<IVolume::ELanguage, std::string> names; if (!IsValid()) { @@ -70,16 +71,21 @@ std::vector<std::string> 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<std::string> CBannerLoaderGC::GetNames() auto const banner = reinterpret_cast<const DVDBanner*>(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<std::string> CBannerLoaderGC::GetDescriptions() +std::map<IVolume::ELanguage, std::string> CBannerLoaderGC::GetDescriptions() { - std::vector<std::string> descriptions; + std::map<IVolume::ELanguage, std::string> descriptions; if (!IsValid()) { @@ -133,16 +135,20 @@ std::vector<std::string> 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<std::string> CBannerLoaderGC::GetDescriptions() auto banner = reinterpret_cast<const DVDBanner*>(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<std::string> 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 diff --git a/Source/Core/DiscIO/BannerLoaderGC.h b/Source/Core/DiscIO/BannerLoaderGC.h index 94e261699c..b381e10f92 100644 --- a/Source/Core/DiscIO/BannerLoaderGC.h +++ b/Source/Core/DiscIO/BannerLoaderGC.h @@ -5,6 +5,7 @@ #pragma once #include <cstring> +#include <map> #include <string> #include <vector> @@ -28,9 +29,9 @@ public: virtual std::vector<u32> GetBanner(int* pWidth, int* pHeight) override; - virtual std::vector<std::string> GetNames() override; + virtual std::map<IVolume::ELanguage, std::string> GetNames() override; virtual std::string GetCompany() override; - virtual std::vector<std::string> GetDescriptions() override; + virtual std::map<IVolume::ELanguage, std::string> GetDescriptions() override; private: enum diff --git a/Source/Core/DiscIO/BannerLoaderWii.cpp b/Source/Core/DiscIO/BannerLoaderWii.cpp index eaab54a942..1de9120c10 100644 --- a/Source/Core/DiscIO/BannerLoaderWii.cpp +++ b/Source/Core/DiscIO/BannerLoaderWii.cpp @@ -5,6 +5,7 @@ #include <algorithm> #include <cstddef> #include <cstdio> +#include <map> #include <string> #include <vector> @@ -91,14 +92,15 @@ bool CBannerLoaderWii::GetStringFromComments(const CommentIndex index, std::stri return false; } -std::vector<std::string> CBannerLoaderWii::GetNames() +std::map<IVolume::ELanguage, std::string> CBannerLoaderWii::GetNames() { - std::vector<std::string> ret(1); + std::map<IVolume::ELanguage, std::string> result; - if (!GetStringFromComments(NAME_IDX, ret[0])) - ret.clear(); + std::string name; + if (GetStringFromComments(NAME_IDX, name)) + result[IVolume::ELanguage::LANGUAGE_UNKNOWN] = name; - return ret; + return result; } std::string CBannerLoaderWii::GetCompany() @@ -106,11 +108,14 @@ std::string CBannerLoaderWii::GetCompany() return ""; } -std::vector<std::string> CBannerLoaderWii::GetDescriptions() +std::map<IVolume::ELanguage, std::string> CBannerLoaderWii::GetDescriptions() { - std::vector<std::string> result(1); - if (!GetStringFromComments(DESC_IDX, result[0])) - result.clear(); + std::map<IVolume::ELanguage, std::string> result; + + std::string name; + if (GetStringFromComments(DESC_IDX, name)) + result[IVolume::ELanguage::LANGUAGE_UNKNOWN] = name; + return result; } diff --git a/Source/Core/DiscIO/BannerLoaderWii.h b/Source/Core/DiscIO/BannerLoaderWii.h index 1bbe077509..29d3b0f470 100644 --- a/Source/Core/DiscIO/BannerLoaderWii.h +++ b/Source/Core/DiscIO/BannerLoaderWii.h @@ -4,6 +4,7 @@ #pragma once +#include <map> #include <string> #include <vector> @@ -25,9 +26,9 @@ public: virtual std::vector<u32> GetBanner(int* pWidth, int* pHeight) override; - virtual std::vector<std::string> GetNames() override; + virtual std::map<IVolume::ELanguage, std::string> GetNames() override; virtual std::string GetCompany() override; - virtual std::vector<std::string> GetDescriptions() override; + virtual std::map<IVolume::ELanguage, std::string> GetDescriptions() override; private: enum diff --git a/Source/Core/DiscIO/Volume.h b/Source/Core/DiscIO/Volume.h index 6efe04a37f..50e09c34d1 100644 --- a/Source/Core/DiscIO/Volume.h +++ b/Source/Core/DiscIO/Volume.h @@ -4,6 +4,7 @@ #pragma once +#include <map> #include <memory> #include <string> #include <vector> @@ -16,6 +17,43 @@ namespace DiscIO class IVolume { public: + // Increment CACHE_REVISION if the enums below are modified (ISOFile.cpp & GameFile.cpp) + enum ECountry + { + COUNTRY_EUROPE = 0, + COUNTRY_JAPAN, + COUNTRY_USA, + COUNTRY_AUSTRALIA, + COUNTRY_FRANCE, + COUNTRY_GERMANY, + COUNTRY_ITALY, + COUNTRY_KOREA, + COUNTRY_NETHERLANDS, + COUNTRY_RUSSIA, + COUNTRY_SPAIN, + COUNTRY_TAIWAN, + COUNTRY_WORLD, + COUNTRY_UNKNOWN, + NUMBER_OF_COUNTRIES + }; + + // Languages 0 - 9 match the official Wii language numbering. + // Languages 1 - 6 match the official GC PAL languages 0 - 5. + enum ELanguage + { + LANGUAGE_JAPANESE = 0, + LANGUAGE_ENGLISH = 1, + LANGUAGE_GERMAN = 2, + LANGUAGE_FRENCH = 3, + LANGUAGE_SPANISH = 4, + LANGUAGE_ITALIAN = 5, + LANGUAGE_DUTCH = 6, + LANGUAGE_SIMPLIFIED_CHINESE = 7, + LANGUAGE_TRADITIONAL_CHINESE = 8, + LANGUAGE_KOREAN = 9, + LANGUAGE_UNKNOWN + }; + IVolume() {} virtual ~IVolume() {} @@ -39,7 +77,7 @@ public: virtual int GetRevision() const { return 0; } // TODO: eliminate? virtual std::string GetName() const; - virtual std::vector<std::string> GetNames() const = 0; + virtual std::map<ELanguage, std::string> GetNames() const = 0; virtual u32 GetFSTSize() const = 0; virtual std::string GetApploaderDate() const = 0; @@ -50,26 +88,6 @@ public: virtual bool CheckIntegrity() const { return false; } virtual bool ChangePartition(u64 offset) { return false; } - // Increment CACHE_REVISION if the code below is modified (ISOFile.cpp & GameFile.cpp) - enum ECountry - { - COUNTRY_EUROPE = 0, - COUNTRY_JAPAN, - COUNTRY_USA, - COUNTRY_AUSTRALIA, - COUNTRY_FRANCE, - COUNTRY_GERMANY, - COUNTRY_ITALY, - COUNTRY_KOREA, - COUNTRY_NETHERLANDS, - COUNTRY_RUSSIA, - COUNTRY_SPAIN, - COUNTRY_TAIWAN, - COUNTRY_WORLD, - COUNTRY_UNKNOWN, - NUMBER_OF_COUNTRIES - }; - virtual ECountry GetCountry() const = 0; virtual u64 GetSize() const = 0; diff --git a/Source/Core/DiscIO/VolumeCommon.cpp b/Source/Core/DiscIO/VolumeCommon.cpp index 87f0c722a7..1728e78732 100644 --- a/Source/Core/DiscIO/VolumeCommon.cpp +++ b/Source/Core/DiscIO/VolumeCommon.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 // Refer to the license.txt file included. +#include <map> #include <string> #include <vector> @@ -104,7 +105,7 @@ std::string IVolume::GetName() const if (names.empty()) return ""; else - return names[0]; + return names.cbegin()->second; } } diff --git a/Source/Core/DiscIO/VolumeDirectory.cpp b/Source/Core/DiscIO/VolumeDirectory.cpp index 6f3e4ccb7f..9db6e58e46 100644 --- a/Source/Core/DiscIO/VolumeDirectory.cpp +++ b/Source/Core/DiscIO/VolumeDirectory.cpp @@ -8,7 +8,6 @@ #include <map> #include <memory> #include <string> -#include <utility> #include <vector> #include "Common/CommonPaths.h" @@ -183,9 +182,11 @@ std::string CVolumeDirectory::GetMakerID() const return "VOID"; } -std::vector<std::string> CVolumeDirectory::GetNames() const +std::map<IVolume::ELanguage, std::string> CVolumeDirectory::GetNames() const { - return std::vector<std::string>(1, (char*)(&m_diskHeader[0x20])); + std::map<IVolume::ELanguage, std::string> names; + names[IVolume::ELanguage::LANGUAGE_UNKNOWN] = (char*)(&m_diskHeader[0x20]); + return names; } void CVolumeDirectory::SetName(const std::string& name) diff --git a/Source/Core/DiscIO/VolumeDirectory.h b/Source/Core/DiscIO/VolumeDirectory.h index c3e9c881c2..d283e9051b 100644 --- a/Source/Core/DiscIO/VolumeDirectory.h +++ b/Source/Core/DiscIO/VolumeDirectory.h @@ -39,7 +39,7 @@ public: std::string GetMakerID() const override; - std::vector<std::string> GetNames() const override; + std::map<IVolume::ELanguage, std::string> GetNames() const override; void SetName(const std::string&); u32 GetFSTSize() const override; diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index 132a630cf0..272408011e 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include <cstddef> +#include <map> #include <memory> #include <string> #include <vector> @@ -92,15 +93,15 @@ int CVolumeGC::GetRevision() const return revision; } -std::vector<std::string> CVolumeGC::GetNames() const +std::map<IVolume::ELanguage, std::string> CVolumeGC::GetNames() const { - std::vector<std::string> names; + std::map<IVolume::ELanguage, std::string> names; auto const string_decoder = GetStringDecoder(GetCountry()); char name[0x60 + 1] = {}; if (m_pReader != nullptr && Read(0x20, 0x60, (u8*)name)) - names.push_back(string_decoder(name)); + names[IVolume::ELanguage::LANGUAGE_UNKNOWN] = string_decoder(name); return names; } diff --git a/Source/Core/DiscIO/VolumeGC.h b/Source/Core/DiscIO/VolumeGC.h index c2efcd6e9f..e9757df948 100644 --- a/Source/Core/DiscIO/VolumeGC.h +++ b/Source/Core/DiscIO/VolumeGC.h @@ -4,6 +4,7 @@ #pragma once +#include <map> #include <memory> #include <string> #include <vector> @@ -27,7 +28,7 @@ public: std::string GetUniqueID() const override; std::string GetMakerID() const override; int GetRevision() const override; - std::vector<std::string> GetNames() const override; + std::map<IVolume::ELanguage, std::string> GetNames() const override; u32 GetFSTSize() const override; std::string GetApploaderDate() const override; diff --git a/Source/Core/DiscIO/VolumeWad.cpp b/Source/Core/DiscIO/VolumeWad.cpp index 1dc746ea4d..5bc27738da 100644 --- a/Source/Core/DiscIO/VolumeWad.cpp +++ b/Source/Core/DiscIO/VolumeWad.cpp @@ -4,6 +4,7 @@ #include <algorithm> #include <cstddef> +#include <map> #include <string> #include <vector> @@ -117,9 +118,9 @@ bool CVolumeWAD::IsWadFile() const return true; } -std::vector<std::string> CVolumeWAD::GetNames() const +std::map<IVolume::ELanguage, std::string> CVolumeWAD::GetNames() const { - std::vector<std::string> names; + std::map<IVolume::ELanguage, std::string> names; u32 footer_size; if (!Read(0x1C, 4, (u8*)&footer_size)) @@ -129,26 +130,23 @@ std::vector<std::string> CVolumeWAD::GetNames() const footer_size = Common::swap32(footer_size); - //Japanese, English, German, French, Spanish, Italian, Dutch, unknown, unknown, Korean - for (int i = 0; i != 10; ++i) + //Japanese, English, German, French, Spanish, Italian, Dutch, Simplified Chinese, Traditional Chinese, Korean + for (int i = 0; i < 10; ++i) { static const u32 string_length = 42; static const u32 bytes_length = string_length * sizeof(u16); u16 temp[string_length]; - if (footer_size < 0xF1 || !Read(0x9C + (i * bytes_length) + m_opening_bnr_offset, bytes_length, (u8*)&temp)) - { - names.push_back(""); - } - else + if (footer_size >= 0xF1 && Read(0x9C + (i * bytes_length) + m_opening_bnr_offset, bytes_length, (u8*)&temp)) { std::wstring out_temp; out_temp.resize(string_length); std::transform(temp, temp + out_temp.size(), out_temp.begin(), (u16(&)(u16))Common::swap16); out_temp.erase(std::find(out_temp.begin(), out_temp.end(), 0x00), out_temp.end()); - - names.push_back(UTF16ToUTF8(out_temp)); + std::string name = UTF16ToUTF8(out_temp); + if (!name.empty()) + names[(IVolume::ELanguage)i] = name; } } diff --git a/Source/Core/DiscIO/VolumeWad.h b/Source/Core/DiscIO/VolumeWad.h index 3205da3a24..33dc213aee 100644 --- a/Source/Core/DiscIO/VolumeWad.h +++ b/Source/Core/DiscIO/VolumeWad.h @@ -4,6 +4,7 @@ #pragma once +#include <map> #include <memory> #include <string> #include <vector> @@ -30,7 +31,7 @@ public: std::string GetUniqueID() const override; std::string GetMakerID() const override; int GetRevision() const override; - std::vector<std::string> GetNames() const override; + std::map<IVolume::ELanguage, std::string> GetNames() const override; u32 GetFSTSize() const override { return 0; } std::string GetApploaderDate() const override { return "0"; } diff --git a/Source/Core/DiscIO/VolumeWiiCrypted.cpp b/Source/Core/DiscIO/VolumeWiiCrypted.cpp index 4c703fdb3f..935d18b8f8 100644 --- a/Source/Core/DiscIO/VolumeWiiCrypted.cpp +++ b/Source/Core/DiscIO/VolumeWiiCrypted.cpp @@ -4,6 +4,7 @@ #include <cstddef> #include <cstring> +#include <map> #include <string> #include <vector> #include <polarssl/aes.h> @@ -191,15 +192,15 @@ int CVolumeWiiCrypted::GetRevision() const return revision; } -std::vector<std::string> CVolumeWiiCrypted::GetNames() const +std::map<IVolume::ELanguage, std::string> CVolumeWiiCrypted::GetNames() const { - std::vector<std::string> names; + std::map<IVolume::ELanguage, std::string> names; auto const string_decoder = CVolumeGC::GetStringDecoder(GetCountry()); char name[0xFF] = {}; if (m_pReader != nullptr && Read(0x20, 0x60, (u8*)&name, true)) - names.push_back(string_decoder(name)); + names[IVolume::ELanguage::LANGUAGE_UNKNOWN] = string_decoder(name); return names; } diff --git a/Source/Core/DiscIO/VolumeWiiCrypted.h b/Source/Core/DiscIO/VolumeWiiCrypted.h index 4816bc2ebc..f4712fd230 100644 --- a/Source/Core/DiscIO/VolumeWiiCrypted.h +++ b/Source/Core/DiscIO/VolumeWiiCrypted.h @@ -4,6 +4,7 @@ #pragma once +#include <map> #include <memory> #include <string> #include <vector> @@ -30,7 +31,7 @@ public: std::string GetUniqueID() const override; std::string GetMakerID() const override; int GetRevision() const override; - std::vector<std::string> GetNames() const override; + std::map<IVolume::ELanguage, std::string> GetNames() const override; u32 GetFSTSize() const override; std::string GetApploaderDate() const override; |
