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

@ -454,10 +454,8 @@ void CGameListCtrl::InsertItemInReportView(long _Index)
// Set the game's banner in the second column
SetItemColumnImage(_Index, COLUMN_BANNER, ImageIndex);
std::wstring wstring_name;
wxString name;
std::string name;
int SelectedLanguage = SConfig::GetInstance().m_LocalCoreStartupParameter.SelectedLanguage;
switch (rISOFile.GetCountry())
@ -465,9 +463,8 @@ void CGameListCtrl::InsertItemInReportView(long _Index)
case DiscIO::IVolume::COUNTRY_TAIWAN:
case DiscIO::IVolume::COUNTRY_JAPAN:
{
rISOFile.GetName(wstring_name, -1);
name = wxString(rISOFile.GetName(0).c_str(), SJISConv);
m_gameList.append(StringFromFormat("%s (J)\n", (const char *)name.c_str()));
name = rISOFile.GetName(-1);
m_gameList.append(StringFromFormat("%s (J)\n", name.c_str()));
}
break;
case DiscIO::IVolume::COUNTRY_USA:
@ -475,22 +472,15 @@ void CGameListCtrl::InsertItemInReportView(long _Index)
SelectedLanguage = 0;
default:
{
wxCSConv WindowsCP1252(wxFontMapper::GetEncodingName(wxFONTENCODING_CP1252));
rISOFile.GetName(wstring_name, SelectedLanguage);
name = wxString(rISOFile.GetName(SelectedLanguage).c_str(), WindowsCP1252);
m_gameList.append(StringFromFormat("%s (%c)\n",
rISOFile.GetName(SelectedLanguage).c_str(),
(rISOFile.GetCountry() == DiscIO::IVolume::COUNTRY_USA) ? 'U' : 'E'));
name = rISOFile.GetName(SelectedLanguage);
m_gameList.append(StringFromFormat("%s (%c)\n", name.c_str(),
(rISOFile.GetCountry() == DiscIO::IVolume::COUNTRY_USA) ? 'U' : 'E'));
}
break;
}
if (wstring_name.length())
name = wstring_name.c_str();
SetItem(_Index, COLUMN_TITLE, name, -1);
SetItem(_Index, COLUMN_TITLE, StrToWxStr(name), -1);
// We show the company string on Gamecube only
// On Wii we show the description instead as the company string is empty

View File

@ -37,7 +37,7 @@
#include "ChunkFile.h"
#include "ConfigManager.h"
#define CACHE_REVISION 0x110
#define CACHE_REVISION 0x112
#define DVD_BANNER_WIDTH 96
#define DVD_BANNER_HEIGHT 32
@ -66,26 +66,10 @@ GameListItem::GameListItem(const std::string& _rFileName)
else
{
m_Platform = WII_WAD;
pVolume->GetWName(m_wNames);
}
m_Company = "N/A";
m_volume_names = pVolume->GetNames();
m_Name[0] = pVolume->GetName();
if(m_Name[0] == "") // Couldn't find the name in the WAD...
{
std::string FileName;
SplitPath(m_FileName, NULL, &FileName, NULL);
m_Name[0] = FileName; // Then just display the filename... Better than something like "No Name"
}
for (int i = 0; i < 6; i++)
{
m_Name[i] = m_Name[0];
m_Description[i] = "No Description";
}
m_Country = pVolume->GetCountry();
m_FileSize = File::GetSize(_rFileName);
m_VolumeSize = pVolume->GetSize();
@ -105,11 +89,9 @@ GameListItem::GameListItem(const std::string& _rFileName)
{
if (pBannerLoader->IsValid())
{
m_wNames.clear();
pBannerLoader->GetName(m_wNames);
pBannerLoader->GetName(m_Name);
pBannerLoader->GetCompany(m_Company);
pBannerLoader->GetDescription(m_Description);
m_names = pBannerLoader->GetNames();
m_company = pBannerLoader->GetCompany();
m_descriptions = pBannerLoader->GetDescriptions();
if (pBannerLoader->GetBanner(g_ImageTemp))
{
@ -129,25 +111,6 @@ GameListItem::GameListItem(const std::string& _rFileName)
delete pFileSystem;
}
std::vector<std::wstring>::iterator i, end = m_wNames.end();
std::wstring wFileName;
for (i = m_wNames.begin(); i != end; ++i)
{
if (*i == L"")
{
if (!wFileName.length())
{
std::string FileName;
SplitPath(m_FileName, NULL, &FileName, NULL);
int length = FileName.length();
wFileName.reserve(length+1);
for (int j = 0; j < length; ++j)
wFileName.push_back(FileName[j]);
wFileName.push_back(0);
}
*i = wFileName;
}
}
delete pVolume;
@ -208,32 +171,10 @@ void GameListItem::SaveToCache()
void GameListItem::DoState(PointerWrap &p)
{
p.Do(m_Name[0]); p.Do(m_Name[1]); p.Do(m_Name[2]);
p.Do(m_Name[3]); p.Do(m_Name[4]); p.Do(m_Name[5]);
int wNamesSize = m_wNames.size();
p.Do(wNamesSize);
if (p.mode == p.MODE_READ)
{
for (int i = 0; i < wNamesSize; ++i)
{
std::wstring temp;
p.Do(temp);
m_wNames.push_back(temp);
}
}
else
{
for (int i = 0; i < wNamesSize; ++i)
{
p.Do(m_wNames[i]);
}
}
p.Do(m_Company);
p.Do(m_Description[0]); p.Do(m_Description[1]); p.Do(m_Description[2]);
p.Do(m_Description[3]); p.Do(m_Description[4]); p.Do(m_Description[5]);
p.Do(m_volume_names);
p.Do(m_company);
p.Do(m_names);
p.Do(m_descriptions);
p.Do(m_UniqueID);
p.Do(m_FileSize);
p.Do(m_VolumeSize);
@ -262,44 +203,51 @@ std::string GameListItem::CreateCacheFilename()
return fullname;
}
const std::string& GameListItem::GetDescription(int index) const
std::string GameListItem::GetCompany() const
{
if ((index >=0) && (index < 6))
{
return m_Description[index];
}
return m_Description[0];
if (m_company.empty())
return "N/A";
else
return m_company;
}
const std::string& GameListItem::GetName(int index) const
// (-1 = Japanese, 0 = English, etc)
std::string GameListItem::GetDescription(int _index) const
{
if ((index >=0) && (index < 6))
{
return m_Name[index];
}
return m_Name[0];
const u32 index = _index + 1;
if (index < m_descriptions.size())
return m_descriptions[index];
if (!m_descriptions.empty())
return m_descriptions[0];
return "";
}
bool GameListItem::GetName(std::wstring& wName, int index) const
// (-1 = Japanese, 0 = English, etc)
std::string GameListItem::GetName(int _index) const
{
// This function will only succeed for wii discs with banners or WADs
// utilize the same array as for gc discs (-1= Japanese, 0 = English etc
index++;
if ((index >= 0) && (index < 10))
{
if (m_wNames.size() > (size_t)index)
{
wName = m_wNames[index];
return true;
}
}
if (m_wNames.size() > 0)
{
wName = m_wNames[0];
return true;
}
return false;
u32 const index = _index + 1;
// banner name
if (index < m_names.size() && !m_names[index].empty())
return m_names[index];
if (!m_names.empty() && !m_names[0].empty())
return m_names[0];
// volume name
if (index < m_volume_names.size() && !m_volume_names[index].empty())
return m_volume_names[index];
if (!m_volume_names.empty() && !m_volume_names[0].empty())
return m_volume_names[0];
// No usable name, return filename (better than nothing)
std::string FileName;
SplitPath(m_FileName, NULL, &FileName, NULL);
return FileName;
}
const std::string GameListItem::GetWiiFSPath() const

View File

@ -18,6 +18,9 @@
#ifndef __ISOFILE_H_
#define __ISOFILE_H_
#include <vector>
#include <string>
#include "Volume.h"
#include "VolumeCreator.h"
@ -34,10 +37,9 @@ public:
bool IsValid() const {return m_Valid;}
const std::string& GetFileName() const {return m_FileName;}
const std::string& GetName(int index) const;
bool GetName(std::wstring& wName, int index=0) const;
const std::string& GetCompany() const {return m_Company;}
const std::string& GetDescription(int index = 0) const;
std::string GetName(int index) const;
std::string GetCompany() const;
std::string GetDescription(int index = 0) const;
const std::string& GetUniqueID() const {return m_UniqueID;}
const std::string GetWiiFSPath() const;
DiscIO::IVolume::ECountry GetCountry() const {return m_Country;}
@ -64,10 +66,15 @@ public:
private:
std::string m_FileName;
std::string m_Name[6];
std::vector<std::wstring> m_wNames;
std::string m_Company;
std::string m_Description[6];
// TODO: eliminate this and overwrite with names from banner when available?
std::vector<std::string> m_volume_names;
// Stuff from banner
std::string m_company;
std::vector<std::string> m_names;
std::vector<std::string> m_descriptions;
std::string m_UniqueID;
std::string m_issues;

View File

@ -158,15 +158,8 @@ CISOProperties::CISOProperties(const std::string fileName, wxWindow* parent, wxW
// Disk header and apploader
std::wstring wname;
wxString name;
if (OpenGameListItem->GetName(wname))
name = wname.c_str();
else
name = wxString(OpenISO->GetName().c_str(), wxConvUTF8);
m_Name->SetValue(name);
m_GameID->SetValue(wxString(OpenISO->GetUniqueID().c_str(), wxConvUTF8));
m_Name->SetValue(StrToWxStr(OpenISO->GetName()));
m_GameID->SetValue(StrToWxStr(OpenISO->GetUniqueID()));
switch (OpenISO->GetCountry())
{
case DiscIO::IVolume::COUNTRY_EUROPE:
@ -1308,54 +1301,29 @@ void CISOProperties::OnChangeBannerLang(wxCommandEvent& event)
void CISOProperties::ChangeBannerDetails(int lang)
{
std::wstring wname;
std::string name;
wxString shortName,
comment,
maker;
#ifdef _WIN32
wxCSConv SJISConv(*(wxCSConv*)wxConvCurrent);
static bool validCP932 = ::IsValidCodePage(932) != 0;
if (validCP932)
{
SJISConv = wxCSConv(wxFontMapper::GetEncodingName(wxFONTENCODING_SHIFT_JIS));
}
else
{
WARN_LOG(COMMON, "Cannot Convert from Charset Windows Japanese cp 932");
}
#else
// on linux the wrong string is returned from wxFontMapper::GetEncodingName(wxFONTENCODING_SHIFT_JIS)
// it returns CP-932, in order to use iconv we need to use CP932
wxCSConv SJISConv(wxT("CP932"));
#endif
switch (OpenGameListItem->GetCountry())
{
case DiscIO::IVolume::COUNTRY_TAIWAN:
case DiscIO::IVolume::COUNTRY_JAPAN:
if (OpenGameListItem->GetName(wname, -1))
shortName = wname.c_str();
else
shortName = wxString(OpenGameListItem->GetName(0).c_str(), SJISConv);
shortName = StrToWxStr(OpenGameListItem->GetName(-1));
comment = StrToWxStr(OpenGameListItem->GetDescription());
maker = wxString(OpenGameListItem->GetCompany().c_str(), SJISConv);
break;
case DiscIO::IVolume::COUNTRY_USA:
// why?
lang = 0;
default:
{
wxCSConv WindowsCP1252(wxFontMapper::GetEncodingName(wxFONTENCODING_CP1252));
if (OpenGameListItem->GetName(wname, lang))
shortName = wname.c_str();
else
shortName = wxString(OpenGameListItem->GetName(lang).c_str(), WindowsCP1252);
shortName = StrToWxStr(OpenGameListItem->GetName(lang));
comment = StrToWxStr(OpenGameListItem->GetDescription(lang));
maker = wxString(OpenGameListItem->GetCompany().c_str(), WindowsCP1252);
}
break;
}
maker = StrToWxStr(OpenGameListItem->GetCompany());
// Updates the informations shown in the window
m_ShortName->SetValue(shortName);
m_Comment->SetValue(comment);