diff --git a/Source/Core/DiscIO/Src/BannerLoader.cpp b/Source/Core/DiscIO/Src/BannerLoader.cpp index 60cee599b0..a45a286c4d 100644 --- a/Source/Core/DiscIO/Src/BannerLoader.cpp +++ b/Source/Core/DiscIO/Src/BannerLoader.cpp @@ -23,6 +23,11 @@ #include "VolumeCreator.h" #include "FileUtil.h" +// HyperIris: dunno if this suitable, may be need move. +#ifdef WIN32 +#include +#endif + namespace DiscIO { bool IBannerLoader::CopyToStringAndCheck(std::string& _rDestination, const char* _src) @@ -89,6 +94,89 @@ bool IBannerLoader::CopyToStringAndCheck(std::string& _rDestination, const char* return(bResult); } +bool IBannerLoader::CopySJISToString( std::string& _rDestination, const char* _src ) +{ + bool returnCode = false; +#ifdef WIN32 + // HyperIris: because dolphin using "Use Multi-Byte Character Set", + // we must convert the SJIS chars to unicode then to our windows local by hand + u32 unicodeNameSize = MultiByteToWideChar(932, MB_PRECOMPOSED, + _src, strlen(_src), NULL, NULL); + if (unicodeNameSize > 0) + { + u16* pUnicodeStrBuffer = new u16[unicodeNameSize + 1]; + if (pUnicodeStrBuffer) + { + memset(pUnicodeStrBuffer, 0, (unicodeNameSize + 1) * sizeof(u16)); + if (MultiByteToWideChar(932, MB_PRECOMPOSED, + _src, strlen(_src), + (LPWSTR)pUnicodeStrBuffer, unicodeNameSize)) + { + u32 ansiNameSize = WideCharToMultiByte(CP_ACP, 0, + (LPCWSTR)pUnicodeStrBuffer, unicodeNameSize, + NULL, NULL, NULL, NULL); + if (ansiNameSize > 0) + { + char* pAnsiStrBuffer = new char[ansiNameSize + 1]; + if (pAnsiStrBuffer) + { + memset(pAnsiStrBuffer, 0, (ansiNameSize + 1) * sizeof(char)); + if (WideCharToMultiByte(CP_ACP, 0, + (LPCWSTR)pUnicodeStrBuffer, unicodeNameSize, + pAnsiStrBuffer, ansiNameSize, NULL, NULL)) + { + _rDestination = pAnsiStrBuffer; + returnCode = true; + } + delete pAnsiStrBuffer; + } + } + } + delete pUnicodeStrBuffer; + } + } +#else + // not implement other than windows + _rDestination = _src; + returnCode = true; +#endif + return returnCode; +} + +bool IBannerLoader::CopyUnicodeToString( std::string& _rDestination, const u16* _src ) +{ + bool returnCode = false; +#ifdef WIN32 + if (_src) + { + u32 ansiNameSize = WideCharToMultiByte(CP_ACP, 0, + (LPCWSTR)_src, wcslen((const wchar_t*)_src), + NULL, NULL, NULL, NULL); + if (ansiNameSize > 0) + { + char* pAnsiStrBuffer = new char[ansiNameSize + 1]; + if (pAnsiStrBuffer) + { + memset(pAnsiStrBuffer, 0, (ansiNameSize + 1) * sizeof(char)); + if (WideCharToMultiByte(CP_ACP, 0, + (LPCWSTR)_src, wcslen((const wchar_t*)_src), + pAnsiStrBuffer, ansiNameSize, NULL, NULL)) + { + _rDestination = pAnsiStrBuffer; + returnCode = true; + } + delete pAnsiStrBuffer; + } + } + } +#else + // not implement other than windows + _rDestination = _src; + returnCode = true; +#endif + return returnCode; +} + IBannerLoader* CreateBannerLoader(DiscIO::IFileSystem& _rFileSystem) { diff --git a/Source/Core/DiscIO/Src/BannerLoader.h b/Source/Core/DiscIO/Src/BannerLoader.h index 33a2e207a8..83fc9f7e95 100644 --- a/Source/Core/DiscIO/Src/BannerLoader.h +++ b/Source/Core/DiscIO/Src/BannerLoader.h @@ -38,16 +38,18 @@ class IBannerLoader virtual bool GetBanner(u32* _pBannerImage) = 0; - virtual bool GetName(std::string& _rName, int language) = 0; + virtual bool GetName(std::string& _rName, DiscIO::IVolume::ECountry language) = 0; virtual bool GetCompany(std::string& _rCompany) = 0; - virtual bool GetDescription(std::string& _rDescription) = 0; + virtual bool GetDescription(std::string& _rDescription, DiscIO::IVolume::ECountry language) = 0; protected: bool CopyToStringAndCheck(std::string& _rDestination, const char* _src); + bool CopySJISToString(std::string& _rDestination, const char* _src); + bool CopyUnicodeToString(std::string& _rDestination, const u16* _src); }; IBannerLoader* CreateBannerLoader(DiscIO::IFileSystem& _rFileSystem); diff --git a/Source/Core/DiscIO/Src/BannerLoaderGC.cpp b/Source/Core/DiscIO/Src/BannerLoaderGC.cpp index 994dbadcf0..62adc6eb97 100644 --- a/Source/Core/DiscIO/Src/BannerLoaderGC.cpp +++ b/Source/Core/DiscIO/Src/BannerLoaderGC.cpp @@ -47,16 +47,22 @@ CBannerLoaderGC::CBannerLoaderGC(DiscIO::IFileSystem& _rFileSystem) if (FileSize > 0) { m_pBannerFile = new u8[FileSize]; - _rFileSystem.ReadFile("opening.bnr", m_pBannerFile, FileSize); - m_IsValid = true; + if (m_pBannerFile) + { + _rFileSystem.ReadFile("opening.bnr", m_pBannerFile, FileSize); + m_IsValid = true; + } } } CBannerLoaderGC::~CBannerLoaderGC() { - delete [] m_pBannerFile; - m_pBannerFile = NULL; + if (m_pBannerFile) + { + delete [] m_pBannerFile; + m_pBannerFile = NULL; + } } @@ -83,23 +89,38 @@ CBannerLoaderGC::GetBanner(u32* _pBannerImage) bool -CBannerLoaderGC::GetName(std::string& _rName, int language) +CBannerLoaderGC::GetName(std::string& _rName, DiscIO::IVolume::ECountry language) { - _rName = "invalid image"; + _rName = "no name"; + + bool returnCode = false; if (!IsValid()) { return(false); } - DVDBanner2* pBanner = (DVDBanner2*)m_pBannerFile; - - if (!CopyToStringAndCheck(_rName, language != 0 ? pBanner->comment[0].shortTitle : pBanner->comment[0].longTitle)) + // find Banner type + if (DiscIO::IVolume::COUNTRY_JAP == language) { - return(false); - } + DVDBanner* pBanner = (DVDBanner*)m_pBannerFile; - return(true); + // dunno, if dolphin using unicode, it will be better = =; + if (CopySJISToString(_rName, pBanner->comment.shortTitle)) + { + returnCode = true; + } + } + else + { + DVDBanner2* pBanner = (DVDBanner2*)m_pBannerFile; + + if (CopyToStringAndCheck(_rName, pBanner->comment[0].shortTitle))//language != 0 ? pBanner->comment[0].shortTitle : pBanner->comment[0].longTitle)) + { + returnCode = true; + } + } + return returnCode; } @@ -125,23 +146,38 @@ CBannerLoaderGC::GetCompany(std::string& _rCompany) bool -CBannerLoaderGC::GetDescription(std::string& _rDescription) +CBannerLoaderGC::GetDescription(std::string& _rDescription, DiscIO::IVolume::ECountry language) { - _rDescription = "invalid images"; + _rDescription = ""; + + bool returnCode = false; if (!IsValid()) { return(false); } - DVDBanner2* pBanner = (DVDBanner2*)m_pBannerFile; - - if (!CopyToStringAndCheck(_rDescription, pBanner->comment[0].comment)) + // find Banner type + if (DiscIO::IVolume::COUNTRY_JAP == language) { - _rDescription = ""; - } + DVDBanner* pBanner = (DVDBanner*)m_pBannerFile; - return(true); + // dunno, if dolphin using unicode, it will be better = =; + if (CopySJISToString(_rDescription, pBanner->comment.comment)) + { + returnCode = true; + } + } + else + { + DVDBanner2* pBanner = (DVDBanner2*)m_pBannerFile; + + if (CopyToStringAndCheck(_rDescription, pBanner->comment[0].comment)) + { + returnCode = true; + } + } + return returnCode; } diff --git a/Source/Core/DiscIO/Src/BannerLoaderGC.h b/Source/Core/DiscIO/Src/BannerLoaderGC.h index 1639338fa4..ab99db118b 100644 --- a/Source/Core/DiscIO/Src/BannerLoaderGC.h +++ b/Source/Core/DiscIO/Src/BannerLoaderGC.h @@ -35,11 +35,11 @@ class CBannerLoaderGC virtual bool GetBanner(u32* _pBannerImage); - virtual bool GetName(std::string& _rName, int language); + virtual bool GetName(std::string& _rName, DiscIO::IVolume::ECountry language); virtual bool GetCompany(std::string& _rCompany); - virtual bool GetDescription(std::string& _rDescription); + virtual bool GetDescription(std::string& _rDescription, DiscIO::IVolume::ECountry language); private: diff --git a/Source/Core/DiscIO/Src/BannerLoaderWii.cpp b/Source/Core/DiscIO/Src/BannerLoaderWii.cpp index f58e98b93c..e0470549df 100644 --- a/Source/Core/DiscIO/Src/BannerLoaderWii.cpp +++ b/Source/Core/DiscIO/Src/BannerLoaderWii.cpp @@ -115,17 +115,27 @@ CBannerLoaderWii::StupidWideCharToString(u16* _pSrc, size_t _max) } bool -CBannerLoaderWii::GetName(std::string& _rName, int language) +CBannerLoaderWii::GetName(std::string& _rName, DiscIO::IVolume::ECountry language) { - if (IsValid()) - { - SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile; + _rName = "no name"; + if (!IsValid()) + { + return false; + } + + // find Banner type + SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile; + if (DiscIO::IVolume::COUNTRY_JAP == language) + { + return CopyUnicodeToString(_rName, pBanner->m_Comment[0]); + } + else + { // very stupid _rName = StupidWideCharToString(pBanner->m_Comment[0], WII_BANNER_COMMENT_SIZE); return true; } - return true; } @@ -139,12 +149,23 @@ CBannerLoaderWii::GetCompany(std::string& _rCompany) bool -CBannerLoaderWii::GetDescription(std::string& _rDescription) +CBannerLoaderWii::GetDescription(std::string& _rDescription, DiscIO::IVolume::ECountry language) { - if (IsValid()) - { - SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile; + _rDescription = ""; + if (!IsValid()) + { + return false; + } + + // find Banner type + SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile; + if (DiscIO::IVolume::COUNTRY_JAP == language) + { + return CopyUnicodeToString(_rDescription, pBanner->m_Comment[1]); + } + else + { // very stupid _rDescription = StupidWideCharToString(pBanner->m_Comment[1], WII_BANNER_COMMENT_SIZE); return true; diff --git a/Source/Core/DiscIO/Src/BannerLoaderWii.h b/Source/Core/DiscIO/Src/BannerLoaderWii.h index 277f0f55ac..5b7890b1fb 100644 --- a/Source/Core/DiscIO/Src/BannerLoaderWii.h +++ b/Source/Core/DiscIO/Src/BannerLoaderWii.h @@ -35,11 +35,11 @@ class CBannerLoaderWii virtual bool GetBanner(u32* _pBannerImage); - virtual bool GetName(std::string& _rName, int language); + virtual bool GetName(std::string& _rName, DiscIO::IVolume::ECountry language); virtual bool GetCompany(std::string& _rCompany); - virtual bool GetDescription(std::string& _rDescription); + virtual bool GetDescription(std::string& _rDescription, DiscIO::IVolume::ECountry language); private: diff --git a/Source/Core/DolphinWX/Src/ISOFile.cpp b/Source/Core/DolphinWX/Src/ISOFile.cpp index 0c8da8010a..b34e3b5573 100644 --- a/Source/Core/DolphinWX/Src/ISOFile.cpp +++ b/Source/Core/DolphinWX/Src/ISOFile.cpp @@ -77,9 +77,9 @@ GameListItem::GameListItem(const std::string& _rFileName) { if (pBannerLoader->IsValid()) { - pBannerLoader->GetName(m_Name, 0); //m_Country == DiscIO::IVolume::COUNTRY_JAP ? 1 : 0); + pBannerLoader->GetName(m_Name, m_Country); //m_Country == DiscIO::IVolume::COUNTRY_JAP ? 1 : 0); pBannerLoader->GetCompany(m_Company); - pBannerLoader->GetDescription(m_Description); + pBannerLoader->GetDescription(m_Description, m_Country); if (pBannerLoader->GetBanner(g_ImageTemp)) { m_ImageSize = DVD_BANNER_WIDTH * DVD_BANNER_HEIGHT * 3;