mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 14:49:42 -06:00
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.
This commit is contained in:
@ -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()
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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"; }
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
Reference in New Issue
Block a user