Eliminate the wstring game name.

Some cleanup throughout related code. (try to make logic in ISOFile understandable by a human)
Encode strings in UTF-8 rather than somehow trying to determine the encoding in the GUI code.

Non-windows OSes temporarily broken.
This commit is contained in:
Jordan Woyak
2013-03-02 19:46:55 -06:00
parent 2b1af36900
commit 6c8adf6130
22 changed files with 243 additions and 411 deletions

View File

@ -24,58 +24,6 @@
namespace DiscIO
{
void IBannerLoader::CopyToStringAndCheck(std::string& _rDestination, const char* _src)
{
static bool bValidChars[256];
static bool bInitialized = false;
if (!bInitialized)
{
for (int i = 0; i < 0x20; i++)
{
bValidChars[i] = false;
}
// generate valid chars
for (int i = 0x20; i < 256; i++)
{
bValidChars[i] = true;
}
bValidChars[0x0a] = true;
//bValidChars[0xa9] = true;
//bValidChars[0xe9] = true;
bInitialized = true;
}
char destBuffer[2048] = {0};
char* dest = destBuffer;
const char* src = _src;
// copy the string and check for "unknown" characters
while (*src != 0x00)
{
u8 c = *src;
if (c == 0x0a){c = 0x20;}
if (bValidChars[c] == false)
{
src++;
continue;
}
*dest = c;
dest++;
src++;
}
// finalize the string
*dest = 0x00;
_rDestination = destBuffer;
}
IBannerLoader* CreateBannerLoader(DiscIO::IFileSystem& _rFileSystem, DiscIO::IVolume *pVolume)
{

View File

@ -18,6 +18,9 @@
#ifndef _BANNER_LOADER_H_
#define _BANNER_LOADER_H_
#include <vector>
#include <string>
#include "Filesystem.h"
namespace DiscIO
@ -38,15 +41,9 @@ class IBannerLoader
virtual bool GetBanner(u32* _pBannerImage) = 0;
virtual bool GetName(std::string* _rName) = 0;
virtual bool GetName(std::vector<std::wstring>& _rNames) {return false;};
virtual bool GetCompany(std::string& _rCompany) = 0;
virtual bool GetDescription(std::string* _rDescription) = 0;
protected:
void CopyToStringAndCheck(std::string& _rDestination, const char* _src);
virtual std::vector<std::string> GetNames() = 0;
virtual std::string GetCompany() = 0;
virtual std::vector<std::string> GetDescriptions() = 0;
private:
u16 swap16(u16 data)

View File

@ -29,7 +29,7 @@ CBannerLoaderGC::CBannerLoaderGC(DiscIO::IFileSystem& _rFileSystem)
{
// load the opening.bnr
size_t FileSize = (size_t) _rFileSystem.GetFileSize("opening.bnr");
if (FileSize == sizeof(DVDBanner) || FileSize == sizeof(DVDBanner2))
if (FileSize == BNR1_SIZE || FileSize == BNR2_SIZE)
{
m_pBannerFile = new u8[FileSize];
if (m_pBannerFile)
@ -62,7 +62,6 @@ bool CBannerLoaderGC::IsValid()
return m_IsValid;
}
bool CBannerLoaderGC::GetBanner(u32* _pBannerImage)
{
if (!IsValid())
@ -70,132 +69,111 @@ bool CBannerLoaderGC::GetBanner(u32* _pBannerImage)
return false;
}
DVDBanner2* pBanner = (DVDBanner2*)m_pBannerFile;
auto const pBanner = (DVDBanner*)m_pBannerFile;
decode5A3image(_pBannerImage, pBanner->image, DVD_BANNER_WIDTH, DVD_BANNER_HEIGHT);
return true;
}
bool CBannerLoaderGC::GetName(std::string _rName[])
std::vector<std::string> CBannerLoaderGC::GetNames()
{
bool returnCode = false;
std::vector<std::string> names;
if (!IsValid())
{
return false;
return names;
}
u32 name_count = 0;
// find Banner type
switch (m_BNRType)
{
case CBannerLoaderGC::BANNER_BNR1:
{
DVDBanner* pBanner = (DVDBanner*)m_pBannerFile;
char tempBuffer[65] = {0};
if (pBanner->comment.longTitle[0])
{
memcpy(tempBuffer, pBanner->comment.longTitle, 64);
}
else
{
memcpy(tempBuffer, pBanner->comment.shortTitle, 32);
}
for (int i = 0; i < 6; i++)
{
CopyToStringAndCheck(_rName[i], tempBuffer);
}
returnCode = true;
}
name_count = 1;
break;
case CBannerLoaderGC::BANNER_BNR2:
{
DVDBanner2* pBanner = (DVDBanner2*)m_pBannerFile;
for (int i = 0; i < 6; i++)
{
char tempBuffer[65] = {0};
if (pBanner->comment[i].longTitle[0])
{
memcpy(tempBuffer, pBanner->comment[i].longTitle, 64);
}
else
{
memcpy(tempBuffer, pBanner->comment[i].shortTitle, 32);
}
CopyToStringAndCheck(_rName[i], tempBuffer);
}
returnCode = true;
}
name_count = 6;
break;
default:
break;
}
auto const banner = reinterpret_cast<const DVDBanner*>(m_pBannerFile);
for (int i = 0; i != name_count; ++i)
{
auto& comment = banner->comment[i];
if (comment.longTitle[0])
{
auto& data = comment.longTitle;
names.push_back(GetDecodedString(data));
}
else
{
auto& data = comment.shortTitle;
names.push_back(GetDecodedString(data));
}
}
return returnCode;
return names;
}
bool CBannerLoaderGC::GetCompany(std::string& _rCompany)
std::string CBannerLoaderGC::GetCompany()
{
_rCompany = "N/A";
std::string company;
if (!IsValid())
if (IsValid())
{
return(false);
auto const pBanner = (DVDBanner*)m_pBannerFile;
auto& data = pBanner->comment[0].shortMaker;
company = GetDecodedString(data);
}
DVDBanner2* pBanner = (DVDBanner2*)m_pBannerFile;
CopyToStringAndCheck(_rCompany, pBanner->comment[0].shortMaker);
return true;
return company;
}
bool CBannerLoaderGC::GetDescription(std::string* _rDescription)
std::vector<std::string> CBannerLoaderGC::GetDescriptions()
{
bool returnCode = false;
std::vector<std::string> descriptions;
if (!IsValid())
{
return false;
return descriptions;
}
u32 desc_count = 0;
// find Banner type
switch (m_BNRType)
{
case CBannerLoaderGC::BANNER_BNR1:
{
DVDBanner* pBanner = (DVDBanner*)m_pBannerFile;
char tempBuffer[129] = {0};
memcpy(tempBuffer, pBanner->comment.comment, 128);
for (int i = 0; i < 6; i++)
{
CopyToStringAndCheck(_rDescription[i], tempBuffer);
}
returnCode = true;
}
desc_count = 1;
break;
case CBannerLoaderGC::BANNER_BNR2:
{
DVDBanner2* pBanner = (DVDBanner2*)m_pBannerFile;
for (int i = 0; i< 6; i++)
{
char tempBuffer[129] = {0};
memcpy(tempBuffer, pBanner->comment[i].comment, 128);
CopyToStringAndCheck(_rDescription[i], tempBuffer);
}
returnCode = true;
}
case CBannerLoaderGC::BANNER_BNR2:
desc_count = 6;
break;
default:
break;
}
return returnCode;
auto banner = reinterpret_cast<const DVDBanner*>(m_pBannerFile);
for (int i = 0; i != desc_count; ++i)
{
auto& data = banner->comment[i].comment;
descriptions.push_back(GetDecodedString(data));
}
return descriptions;
}
@ -223,13 +201,17 @@ CBannerLoaderGC::BANNER_TYPE CBannerLoaderGC::getBannerType()
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;
}
return type;
}
} // namespace

View File

@ -32,9 +32,10 @@ class CBannerLoaderGC
virtual bool IsValid();
virtual bool GetBanner(u32* _pBannerImage);
virtual bool GetName(std::string* _rName);
virtual bool GetCompany(std::string& _rCompany);
virtual bool GetDescription(std::string* _rDescription);
virtual std::vector<std::string> GetNames();
virtual std::string GetCompany();
virtual std::vector<std::string> GetDescriptions();
private:
enum
@ -60,24 +61,25 @@ class CBannerLoaderGC
char comment[128]; // Game description shown in IPL game start screen in two lines.
};
// "opening.bnr" file format for JP/US console
struct DVDBanner
{
u32 id; // 'BNR1'
u32 padding[7];
u16 image[DVD_BANNER_WIDTH * DVD_BANNER_HEIGHT]; // RGB5A3 96x32 texture image
DVDBannerComment comment;
};
// "opening.bnr" file format for EU console
struct DVDBanner2
struct DVDBanner
{
u32 id; // 'BNR2'
u32 padding[7];
u16 image[DVD_BANNER_WIDTH * DVD_BANNER_HEIGHT]; // RGB5A3 96x32 texture image
DVDBannerComment comment[6]; // Comments in six languages
DVDBannerComment comment[6]; // Comments in six languages (only 1 for BNR1 type)
};
static const u32 BNR1_SIZE = sizeof(DVDBanner) - sizeof(DVDBannerComment) * 5;
static const u32 BNR2_SIZE = sizeof(DVDBanner);
template <u32 N>
std::string GetDecodedString(const char (&data)[N])
{
// Can I always assume SHIFT-JIS?
return SHIFTJISToUTF8(std::string(data, strnlen(data, sizeof(data))));
}
u8* m_pBannerFile;
bool m_IsValid;
BANNER_TYPE m_BNRType;

View File

@ -196,28 +196,27 @@ bool CBannerLoaderWii::GetStringFromComments(const CommentIndex index, std::wstr
return false;
}
bool CBannerLoaderWii::GetName(std::string* _rName)
std::vector<std::string> CBannerLoaderWii::GetNames()
{
return GetStringFromComments(NAME_IDX, *_rName);
}
std::vector<std::string> ret(1);
if (!GetStringFromComments(NAME_IDX, ret[0]))
ret.clear();
bool CBannerLoaderWii::GetName(std::vector<std::wstring>& _rNames)
{
std::wstring temp;
bool ret = GetStringFromComments(NAME_IDX, temp);
_rNames.push_back(temp);
return ret;
}
bool CBannerLoaderWii::GetCompany(std::string& _rCompany)
std::string CBannerLoaderWii::GetCompany()
{
_rCompany = "N/A";
return true;
return "";
}
bool CBannerLoaderWii::GetDescription(std::string* _rDescription)
std::vector<std::string> CBannerLoaderWii::GetDescriptions()
{
return GetStringFromComments(DESC_IDX, *_rDescription);
std::vector<std::string> result(1);
if (!GetStringFromComments(DESC_IDX, result[0]))
result.clear();
return result;
}
void CBannerLoaderWii::decode5A3image(u32* dst, u16* src, int width, int height)

View File

@ -35,13 +35,9 @@ class CBannerLoaderWii
virtual bool GetBanner(u32* _pBannerImage);
virtual bool GetName(std::string* _rName);
bool GetName(std::vector<std::wstring>& _rNames);
virtual bool GetCompany(std::string& _rCompany);
virtual bool GetDescription(std::string* _rDescription);
virtual std::vector<std::string> GetNames();
virtual std::string GetCompany();
virtual std::vector<std::string> GetDescriptions();
private:

View File

@ -37,8 +37,8 @@ public:
virtual void GetTMD(u8*, u32 *_sz) const { *_sz=0; }
virtual std::string GetUniqueID() const = 0;
virtual std::string GetMakerID() const = 0;
virtual std::string GetName() const = 0;
virtual bool GetWName(std::vector<std::wstring>& _rwNames) const { return false; }
virtual std::string GetName() const;
virtual std::vector<std::string> GetNames() const = 0;
virtual u32 GetFSTSize() const = 0;
virtual std::string GetApploaderDate() const = 0;
virtual bool SupportsIntegrityCheck() const { return false; }

View File

@ -111,5 +111,13 @@ u8 GetSysMenuRegion(u16 _TitleVersion)
}
}
};
std::string IVolume::GetName() const
{
auto names = GetNames();
if (names.empty())
return "";
else
return names[0];
}
}

View File

@ -207,11 +207,10 @@ std::string CVolumeDirectory::GetMakerID() const
return "VOID";
}
std::string CVolumeDirectory::GetName() const
std::vector<std::string> CVolumeDirectory::GetNames() const
{
_dbg_assert_(DVDINTERFACE, m_diskHeader);
std::string name = (char*)(m_diskHeader + 0x20);
return name;
return std::vector<std::string>(1, (char*)(m_diskHeader + 0x20));
}
void CVolumeDirectory::SetName(std::string _Name)

View File

@ -50,7 +50,7 @@ public:
std::string GetMakerID() const;
std::string GetName() const;
std::vector<std::string> GetNames() const;
void SetName(std::string);
u32 GetFSTSize() const;

View File

@ -91,16 +91,15 @@ std::string CVolumeGC::GetMakerID() const
return makerID;
}
std::string CVolumeGC::GetName() const
std::vector<std::string> CVolumeGC::GetNames() const
{
if (m_pReader == NULL)
return "";
std::vector<std::string> names;
char name[128];
if (!Read(0x20, 0x60, (u8*)&name))
return "";
char name[128] = {};
if (m_pReader != NULL && Read(0x20, 0x60, (u8*)&name))
names.push_back(name);
return name;
return names;
}
u32 CVolumeGC::GetFSTSize() const

View File

@ -34,7 +34,7 @@ public:
bool RAWRead(u64 _Offset, u64 _Length, u8* _pBuffer) const;
std::string GetUniqueID() const;
std::string GetMakerID() const;
std::string GetName() const;
std::vector<std::string> GetNames() const;
u32 GetFSTSize() const;
std::string GetApploaderDate() const;
ECountry GetCountry() const;

View File

@ -107,13 +107,15 @@ bool CVolumeWAD::GetTitleID(u8* _pBuffer) const
return true;
}
bool CVolumeWAD::GetWName(std::vector<std::wstring>& _rwNames) const
std::vector<std::string> CVolumeWAD::GetNames() const
{
u32 footer_size;
std::vector<std::string> names;
return names;
u32 footer_size;
if (!Read(0x1C, 4, (u8*)&footer_size))
{
return false;
return names;
}
//Japanese, English, German, French, Spanish, Italian, Dutch, unknown, unknown, Korean
@ -126,7 +128,7 @@ bool CVolumeWAD::GetWName(std::vector<std::wstring>& _rwNames) const
if (!Read(0x9C + (i*84) + OpeningBnrOffset, 84, (u8*)&temp) || Common::swap32(footer_size) < 0xF1
|| !temp[0])
{
_rwNames.push_back(L"");
names.push_back("");
continue;
}
for (int j = 0; j < 42; ++j)
@ -141,44 +143,10 @@ bool CVolumeWAD::GetWName(std::vector<std::wstring>& _rwNames) const
out_temp.push_back(t);
}
_rwNames.push_back(out_temp);
names.push_back(UTF16ToUTF8(out_temp));
}
return true;
}
std::string CVolumeWAD::GetName() const
{
u32 footer_size;
if (!Read(0x1C, 4, (u8*)&footer_size))
return "";
//Japanese, English, German, French, Spanish, Italian, Dutch, unknown, unknown, Korean
// Offset to the english title
char temp[84];
if (!Read(0xF1 + OpeningBnrOffset, 84, (u8*)&temp) || Common::swap32(footer_size) < 0xF1 ||
!Common::swap16(temp[0]))
return "";
// Remove the null bytes due to 16bit char length
std::string out_temp;
for (unsigned int i = 0; i < sizeof(temp); i+=2)
{
// Replace null chars with a single space per null section
if (temp[i] == '\0' && i > 0)
{
if (out_temp.at(out_temp.size()-1) != ' ')
out_temp.push_back(' ');
}
else
out_temp.push_back(temp[i]);
}
// Make it a null terminated string
out_temp.replace(out_temp.end()-1, out_temp.end(), 1, '\0');
return out_temp;
return names;
}
u64 CVolumeWAD::GetSize() const

View File

@ -38,8 +38,7 @@ public:
bool GetTitleID(u8* _pBuffer) const;
std::string GetUniqueID() const;
std::string GetMakerID() const;
std::string GetName() const;
bool GetWName(std::vector<std::wstring>& _rwNames) const;
std::vector<std::string> GetNames() const;
u32 GetFSTSize() const { return 0; }
std::string GetApploaderDate() const { return "0"; }
ECountry GetCountry() const;

View File

@ -168,21 +168,17 @@ std::string CVolumeWiiCrypted::GetMakerID() const
return makerID;
}
std::string CVolumeWiiCrypted::GetName() const
std::vector<std::string> CVolumeWiiCrypted::GetNames() const
{
if (m_pReader == NULL)
std::vector<std::string> names;
char name[0xFF] = {};
if (m_pReader != NULL && Read(0x20, 0x60, (u8*)&name))
{
return std::string();
names.push_back(name);
}
char name[0xFF];
if (!Read(0x20, 0x60, (u8*)&name))
{
return std::string();
}
return name;
return names;
}
u32 CVolumeWiiCrypted::GetFSTSize() const

View File

@ -37,7 +37,7 @@ public:
void GetTMD(u8* _pBuffer, u32* _sz) const;
std::string GetUniqueID() const;
std::string GetMakerID() const;
std::string GetName() const;
std::vector<std::string> GetNames() const;
u32 GetFSTSize() const;
std::string GetApploaderDate() const;
ECountry GetCountry() const;