Volume: Add prefer_long parameter to GetNames

GC games with long names store two variations of the name in
opening.bnr. This makes the shorter of those names available.
For volumes other than GC discs, prefer_long is ignored.
This commit is contained in:
JosJuice 2015-05-10 19:09:11 +02:00
parent 881f6db2ab
commit ec0370d2d1
12 changed files with 78 additions and 95 deletions

View File

@ -85,7 +85,7 @@ public:
virtual std::string GetMakerID() const = 0;
virtual u16 GetRevision() const = 0;
virtual std::string GetInternalName() const = 0;
virtual std::map<ELanguage, std::string> GetNames() const = 0;
virtual std::map<ELanguage, std::string> GetNames(bool prefer_long) const = 0;
virtual std::map<ELanguage, std::string> GetDescriptions() const { return std::map<ELanguage, std::string>(); }
virtual std::string GetCompany() const { return std::string(); }
virtual std::vector<u32> GetBanner(int* width, int* height) const;

View File

@ -191,7 +191,7 @@ std::string CVolumeDirectory::GetInternalName() const
return "";
}
std::map<IVolume::ELanguage, std::string> CVolumeDirectory::GetNames() const
std::map<IVolume::ELanguage, std::string> CVolumeDirectory::GetNames(bool prefer_long) const
{
std::map<IVolume::ELanguage, std::string> names;
std::string name = GetInternalName();

View File

@ -41,7 +41,7 @@ public:
u16 GetRevision() const override { return 0; }
std::string GetInternalName() const override;
std::map<IVolume::ELanguage, std::string> GetNames() const override;
std::map<IVolume::ELanguage, std::string> GetNames(bool prefer_long) const override;
void SetName(const std::string&);
u32 GetFSTSize() const override;

View File

@ -105,91 +105,14 @@ std::string CVolumeGC::GetInternalName() const
return "";
}
std::map<IVolume::ELanguage, std::string> CVolumeGC::GetNames() const
std::map<IVolume::ELanguage, std::string> CVolumeGC::GetNames(bool prefer_long) const
{
std::map<IVolume::ELanguage, std::string> names;
if (!LoadBannerFile())
return names;
u32 name_count = 0;
IVolume::ELanguage language;
bool is_japanese = GetCountry() == IVolume::ECountry::COUNTRY_JAPAN;
switch (m_banner_file_type)
{
case BANNER_BNR1:
name_count = 1;
language = is_japanese ? IVolume::ELanguage::LANGUAGE_JAPANESE : IVolume::ELanguage::LANGUAGE_ENGLISH;
break;
case BANNER_BNR2:
name_count = 6;
language = IVolume::ELanguage::LANGUAGE_ENGLISH;
break;
case BANNER_INVALID:
case BANNER_NOT_LOADED:
break;
}
auto const banner = reinterpret_cast<const GCBanner*>(m_banner_file.data());
for (u32 i = 0; i < name_count; ++i)
{
auto& comment = banner->comment[i];
std::string name = DecodeString(comment.longTitle);
if (name.empty())
name = DecodeString(comment.shortTitle);
if (!name.empty())
names[(IVolume::ELanguage)(language + i)] = name;
}
return names;
return ReadMultiLanguageStrings(false, prefer_long);
}
std::map<IVolume::ELanguage, std::string> CVolumeGC::GetDescriptions() const
{
std::map<IVolume::ELanguage, std::string> descriptions;
if (!LoadBannerFile())
return descriptions;
u32 desc_count = 0;
IVolume::ELanguage language;
bool is_japanese = GetCountry() == IVolume::ECountry::COUNTRY_JAPAN;
switch (m_banner_file_type)
{
case BANNER_BNR1:
desc_count = 1;
language = is_japanese ? IVolume::ELanguage::LANGUAGE_JAPANESE : IVolume::ELanguage::LANGUAGE_ENGLISH;
break;
case BANNER_BNR2:
language = IVolume::ELanguage::LANGUAGE_ENGLISH;
desc_count = 6;
break;
case BANNER_INVALID:
case BANNER_NOT_LOADED:
break;
}
auto banner = reinterpret_cast<const GCBanner*>(m_banner_file.data());
for (u32 i = 0; i < desc_count; ++i)
{
auto& data = banner->comment[i].comment;
std::string description = DecodeString(data);
if (!description.empty())
descriptions[(IVolume::ELanguage)(language + i)] = description;
}
return descriptions;
return ReadMultiLanguageStrings(true);
}
std::string CVolumeGC::GetCompany() const
@ -277,14 +200,17 @@ IVolume::EPlatform CVolumeGC::GetVolumeType() const
return GAMECUBE_DISC;
}
// Returns true if the loaded banner file is valid,
// regardless of whether it was loaded by the current call
bool CVolumeGC::LoadBannerFile() const
{
// The methods GetNames, GetDescriptions, GetCompany and GetBanner
// all need to access the opening.bnr file. These four methods are
// typically called after each other, so we store the file in RAM
// to avoid reading it from the disc several times. However,
// The methods ReadMultiLanguageStrings, GetCompany and GetBanner
// need to access the opening.bnr file. These methods are
// usually called one after another. The file is cached in
// RAM to avoid reading it from the disc several times, but
// if none of these methods are called, the file is never loaded.
// If opening.bnr has been loaded already, return immediately
if (m_banner_file_type != BANNER_NOT_LOADED)
return m_banner_file_type != BANNER_INVALID;
@ -319,4 +245,60 @@ bool CVolumeGC::LoadBannerFile() const
return m_banner_file_type != BANNER_INVALID;
}
std::map<IVolume::ELanguage, std::string> CVolumeGC::ReadMultiLanguageStrings(bool description, bool prefer_long) const
{
std::map<ELanguage, std::string> strings;
if (!LoadBannerFile())
return strings;
u32 number_of_languages = 0;
ELanguage start_language;
bool is_japanese = GetCountry() == ECountry::COUNTRY_JAPAN;
switch (m_banner_file_type)
{
case BANNER_BNR1: // NTSC
number_of_languages = 1;
start_language = is_japanese ? ELanguage::LANGUAGE_JAPANESE : ELanguage::LANGUAGE_ENGLISH;
break;
case BANNER_BNR2: // PAL
number_of_languages = 6;
start_language = ELanguage::LANGUAGE_ENGLISH;
break;
// Shouldn't happen
case BANNER_INVALID:
case BANNER_NOT_LOADED:
break;
}
auto const banner = reinterpret_cast<const GCBanner*>(m_banner_file.data());
for (u32 i = 0; i < number_of_languages; ++i)
{
GCBannerComment comment = banner->comment[i];
std::string string;
if (description)
{
string = DecodeString(comment.comment);
}
else // Title
{
if (prefer_long)
string = DecodeString(comment.longTitle);
if (string.empty())
string = DecodeString(comment.shortTitle);
}
if (!string.empty())
strings[(ELanguage)(start_language + i)] = string;
}
return strings;
}
} // namespace

View File

@ -29,7 +29,7 @@ public:
std::string GetMakerID() const override;
u16 GetRevision() const override;
virtual std::string GetInternalName() const override;
std::map<ELanguage, std::string> GetNames() const override;
std::map<ELanguage, std::string> GetNames(bool prefer_long) const override;
std::map<ELanguage, std::string> GetDescriptions() const override;
std::string GetCompany() const override;
std::vector<u32> GetBanner(int* width, int* height) const override;
@ -44,6 +44,7 @@ public:
private:
bool LoadBannerFile() const;
std::map<ELanguage, std::string> ReadMultiLanguageStrings(bool description, bool prefer_long = true) const;
static const int GC_BANNER_WIDTH = 96;
static const int GC_BANNER_HEIGHT = 32;

View File

@ -117,7 +117,7 @@ IVolume::EPlatform CVolumeWAD::GetVolumeType() const
return WII_WAD;
}
std::map<IVolume::ELanguage, std::string> CVolumeWAD::GetNames() const
std::map<IVolume::ELanguage, std::string> CVolumeWAD::GetNames(bool prefer_long) const
{
std::vector<u8> name_data(NAMES_TOTAL_BYTES);
if (!Read(m_opening_bnr_offset + 0x9C, NAMES_TOTAL_BYTES, name_data.data()))

View File

@ -32,7 +32,7 @@ public:
std::string GetMakerID() const override;
u16 GetRevision() const override;
std::string GetInternalName() const override { return ""; }
std::map<IVolume::ELanguage, std::string> GetNames() const override;
std::map<IVolume::ELanguage, std::string> GetNames(bool prefer_long) const override;
u32 GetFSTSize() const override { return 0; }
std::string GetApploaderDate() const override { return ""; }

View File

@ -202,7 +202,7 @@ std::string CVolumeWiiCrypted::GetInternalName() const
return "";
}
std::map<IVolume::ELanguage, std::string> CVolumeWiiCrypted::GetNames() const
std::map<IVolume::ELanguage, std::string> CVolumeWiiCrypted::GetNames(bool prefer_long) const
{
std::unique_ptr<IFileSystem> file_system(CreateFileSystem(this));
std::vector<u8> opening_bnr(NAMES_TOTAL_BYTES);

View File

@ -32,7 +32,7 @@ public:
std::string GetMakerID() const override;
u16 GetRevision() const override;
std::string GetInternalName() const override;
std::map<IVolume::ELanguage, std::string> GetNames() const override;
std::map<IVolume::ELanguage, std::string> GetNames(bool prefer_long) const override;
u32 GetFSTSize() const override;
std::string GetApploaderDate() const override;
u8 GetDiscNumber() const override;

View File

@ -87,7 +87,7 @@ GameFile::GameFile(const QString& fileName)
{
m_platform = volume->GetVolumeType();
m_names = ConvertLocalizedStrings(volume->GetNames());
m_names = ConvertLocalizedStrings(volume->GetNames(true));
m_descriptions = ConvertLocalizedStrings(volume->GetDescriptions());
m_company = QString::fromStdString(volume->GetCompany());

View File

@ -84,7 +84,7 @@ GameListItem::GameListItem(const std::string& _rFileName)
{
m_Platform = pVolume->GetVolumeType();
m_names = pVolume->GetNames();
m_names = pVolume->GetNames(true);
m_descriptions = pVolume->GetDescriptions();
m_company = pVolume->GetCompany();

View File

@ -222,7 +222,7 @@ static std::string GetTitle(std::string filename)
std::unique_ptr<DiscIO::IVolume> pVolume(DiscIO::CreateVolumeFromFilename(filename));
if (pVolume != nullptr) {
std::map <DiscIO::IVolume::ELanguage, std::string> titles = pVolume->GetNames();
std::map <DiscIO::IVolume::ELanguage, std::string> titles = pVolume->GetNames(true);
/*
bool is_wii_title = pVolume->GetVolumeType() != DiscIO::IVolume::GAMECUBE_DISC;