Skip to content

Commit

Permalink
Volume: Add prefer_long parameter to GetNames
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JosJuice committed May 15, 2015
1 parent bdeb067 commit 3d5a316
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 95 deletions.
2 changes: 1 addition & 1 deletion Source/Core/DiscIO/Volume.h
Expand Up @@ -77,7 +77,7 @@ class IVolume
virtual std::string GetMakerID() const = 0;
virtual int 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;
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DiscIO/VolumeDirectory.cpp
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DiscIO/VolumeDirectory.h
Expand Up @@ -41,7 +41,7 @@ class CVolumeDirectory : public IVolume

int 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;
Expand Down
150 changes: 66 additions & 84 deletions Source/Core/DiscIO/VolumeGC.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -272,14 +195,17 @@ bool CVolumeGC::IsDiscTwo() const
return (disc_two_check == 1);
}

// 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;

Expand Down Expand Up @@ -314,4 +240,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
3 changes: 2 additions & 1 deletion Source/Core/DiscIO/VolumeGC.h
Expand Up @@ -29,7 +29,7 @@ class CVolumeGC : public IVolume
std::string GetMakerID() const override;
int 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;
Expand All @@ -44,6 +44,7 @@ class CVolumeGC : public IVolume

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;
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DiscIO/VolumeWad.cpp
Expand Up @@ -117,7 +117,7 @@ bool CVolumeWAD::IsWadFile() const
return true;
}

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()))
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DiscIO/VolumeWad.h
Expand Up @@ -32,7 +32,7 @@ class CVolumeWAD : public IVolume
std::string GetMakerID() const override;
int 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 ""; }

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DiscIO/VolumeWiiCrypted.cpp
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DiscIO/VolumeWiiCrypted.h
Expand Up @@ -32,7 +32,7 @@ class CVolumeWiiCrypted : public IVolume
std::string GetMakerID() const override;
int 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;

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinQt/GameList/GameFile.cpp
Expand Up @@ -90,7 +90,7 @@ GameFile::GameFile(const QString& fileName)
else
m_platform = WII_WAD;

m_names = ConvertLocalizedStrings(volume->GetNames());
m_names = ConvertLocalizedStrings(volume->GetNames(true));
m_descriptions = ConvertLocalizedStrings(volume->GetDescriptions());
m_company = QString::fromStdString(volume->GetCompany());

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinWX/ISOFile.cpp
Expand Up @@ -87,7 +87,7 @@ GameListItem::GameListItem(const std::string& _rFileName)
else
m_Platform = WII_WAD;

m_names = pVolume->GetNames();
m_names = pVolume->GetNames(true);
m_descriptions = pVolume->GetDescriptions();
m_company = pVolume->GetCompany();

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinWX/MainAndroid.cpp
Expand Up @@ -185,7 +185,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 = IsWiiTitle(filename);
Expand Down

0 comments on commit 3d5a316

Please sign in to comment.