Fix more of what I broke.

This commit is contained in:
Jordan Woyak 2013-03-03 16:51:26 -06:00
parent b1a2915304
commit c07b8a6e37
8 changed files with 97 additions and 61 deletions

View File

@ -458,22 +458,33 @@ std::string CodeToUTF8(const char* fromcode, const std::basic_string<T>& input)
auto dst_buffer = &out_buffer[0]; auto dst_buffer = &out_buffer[0];
size_t dst_bytes = out_buffer.size(); size_t dst_bytes = out_buffer.size();
size_t const iconv_size = iconv(conv_desc, (char**)(&src_buffer), &src_bytes, while (src_bytes != 0)
{
size_t const iconv_result = iconv(conv_desc, (char**)(&src_buffer), &src_bytes,
&dst_buffer, &dst_bytes); &dst_buffer, &dst_bytes);
if ((size_t)-1 == iconv_size) if ((size_t)-1 == iconv_result)
{ {
ERROR_LOG(COMMON, "iconv failure [%s]: %s", fromcode, strerror(errno)); if (EILSEQ == errno || EINVAL == errno)
{
// Try to skip the bad character
if (src_bytes != 0)
{
--src_bytes;
++src_buffer;
}
} }
else else
{ {
ERROR_LOG(COMMON, "iconv failure [%s]: %s", fromcode, strerror(errno));
break;
}
}
}
out_buffer.resize(out_buffer_size - dst_bytes); out_buffer.resize(out_buffer_size - dst_bytes);
out_buffer.swap(result); out_buffer.swap(result);
// TODO: why is this needed?
result.erase(std::remove(result.begin(), result.end(), 0x00), result.end());
}
iconv_close(conv_desc); iconv_close(conv_desc);
} }
@ -483,6 +494,8 @@ std::string CodeToUTF8(const char* fromcode, const std::basic_string<T>& input)
std::string CP1252ToUTF8(const std::string& input) std::string CP1252ToUTF8(const std::string& input)
{ {
//return CodeToUTF8("CP1252//TRANSLIT", input);
//return CodeToUTF8("CP1252//IGNORE", input);
return CodeToUTF8("CP1252", input); return CodeToUTF8("CP1252", input);
} }
@ -494,10 +507,15 @@ std::string SHIFTJISToUTF8(const std::string& input)
std::string UTF16ToUTF8(const std::wstring& input) std::string UTF16ToUTF8(const std::wstring& input)
{ {
//return CodeToUTF8("UCS-2", input); std::string result =
//return CodeToUTF8("UCS-2LE", input); // CodeToUTF8("UCS-2", input);
//return CodeToUTF8("UTF-16", input); // CodeToUTF8("UCS-2LE", input);
return CodeToUTF8("UTF-16LE", input); // CodeToUTF8("UTF-16", input);
CodeToUTF8("UTF-16LE", input);
// TODO: why is this needed?
result.erase(std::remove(result.begin(), result.end(), 0x00), result.end());
return result;
} }
#endif #endif

View File

@ -19,6 +19,7 @@
#define _BANNER_LOADER_GC_H_ #define _BANNER_LOADER_GC_H_
#include "BannerLoader.h" #include "BannerLoader.h"
#include "VolumeGC.h"
#include "StringUtil.h" #include "StringUtil.h"
namespace DiscIO namespace DiscIO
@ -77,9 +78,7 @@ class CBannerLoaderGC
template <u32 N> template <u32 N>
std::string GetDecodedString(const char (&data)[N]) std::string GetDecodedString(const char (&data)[N])
{ {
auto const string_decoder = (DiscIO::IVolume::COUNTRY_JAPAN == m_country || auto const string_decoder = CVolumeGC::GetStringDecoder(m_country);
DiscIO::IVolume::COUNTRY_TAIWAN == m_country) ?
SHIFTJISToUTF8 : CP1252ToUTF8;
// strnlen to trim NULLs // strnlen to trim NULLs
return string_decoder(std::string(data, strnlen(data, sizeof(data)))); return string_decoder(std::string(data, strnlen(data, sizeof(data))));

View File

@ -20,6 +20,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <algorithm>
#include "FileSystemGCWii.h" #include "FileSystemGCWii.h"
#include "StringUtil.h" #include "StringUtil.h"
@ -27,10 +28,10 @@
namespace DiscIO namespace DiscIO
{ {
CFileSystemGCWii::CFileSystemGCWii(const IVolume *_rVolume) CFileSystemGCWii::CFileSystemGCWii(const IVolume *_rVolume)
: IFileSystem(_rVolume), : IFileSystem(_rVolume)
m_Initialized(false), , m_Initialized(false)
m_Valid(false), , m_Valid(false)
m_OffsetShift(0) , m_OffsetShift(0)
{ {
m_Valid = DetectFileSystem(); m_Valid = DetectFileSystem();
} }
@ -213,9 +214,16 @@ u32 CFileSystemGCWii::Read32(u64 _Offset) const
return Common::swap32(Temp); return Common::swap32(Temp);
} }
void CFileSystemGCWii::GetStringFromOffset(u64 _Offset, char* Filename) const std::string CFileSystemGCWii::GetStringFromOffset(u64 _Offset) const
{ {
m_rVolume->Read(_Offset, 255, (u8*)Filename); std::string data;
data.resize(255);
m_rVolume->Read(_Offset, data.size(), (u8*)&data[0]);
data.erase(std::find(data.begin(), data.end(), 0x00), data.end());
// TODO: Should we really always use SHIFT-JIS?
// It makes some filenames in Pikmin (NTSC-U) sane, but is it correct?
return SHIFTJISToUTF8(data);
} }
size_t CFileSystemGCWii::GetFileList(std::vector<const SFileInfo *> &_rFilenames) size_t CFileSystemGCWii::GetFileList(std::vector<const SFileInfo *> &_rFilenames)
@ -311,18 +319,16 @@ size_t CFileSystemGCWii::BuildFilenames(const size_t _FirstIndex, const size_t _
{ {
SFileInfo *rFileInfo = &m_FileInfoVector[CurrentIndex]; SFileInfo *rFileInfo = &m_FileInfoVector[CurrentIndex];
u64 uOffset = _NameTableOffset + (rFileInfo->m_NameOffset & 0xFFFFFF); u64 uOffset = _NameTableOffset + (rFileInfo->m_NameOffset & 0xFFFFFF);
char filename[512]; std::string filename = GetStringFromOffset(uOffset);
memset(filename, 0, sizeof(filename));
GetStringFromOffset(uOffset, filename);
// check next index // check next index
if (rFileInfo->IsDirectory()) if (rFileInfo->IsDirectory())
{ {
// this is a directory, build up the new szDirectory // this is a directory, build up the new szDirectory
if (_szDirectory != NULL) if (_szDirectory != NULL)
CharArrayFromFormat(rFileInfo->m_FullPath, "%s%s/", _szDirectory, filename); CharArrayFromFormat(rFileInfo->m_FullPath, "%s%s/", _szDirectory, filename.c_str());
else else
CharArrayFromFormat(rFileInfo->m_FullPath, "%s/", filename); CharArrayFromFormat(rFileInfo->m_FullPath, "%s/", filename.c_str());
CurrentIndex = BuildFilenames(CurrentIndex + 1, (size_t) rFileInfo->m_FileSize, rFileInfo->m_FullPath, _NameTableOffset); CurrentIndex = BuildFilenames(CurrentIndex + 1, (size_t) rFileInfo->m_FileSize, rFileInfo->m_FullPath, _NameTableOffset);
} }
@ -330,9 +336,9 @@ size_t CFileSystemGCWii::BuildFilenames(const size_t _FirstIndex, const size_t _
{ {
// this is a filename // this is a filename
if (_szDirectory != NULL) if (_szDirectory != NULL)
CharArrayFromFormat(rFileInfo->m_FullPath, "%s%s", _szDirectory, filename); CharArrayFromFormat(rFileInfo->m_FullPath, "%s%s", _szDirectory, filename.c_str());
else else
CharArrayFromFormat(rFileInfo->m_FullPath, "%s", filename); CharArrayFromFormat(rFileInfo->m_FullPath, "%s", filename.c_str());
CurrentIndex++; CurrentIndex++;
} }

View File

@ -44,11 +44,11 @@ public:
private: private:
bool m_Initialized; bool m_Initialized;
bool m_Valid; bool m_Valid;
u32 m_OffsetShift; // WII offsets are all shifted u32 m_OffsetShift; // WII offsets are all shifted
std::vector <SFileInfo> m_FileInfoVector; std::vector <SFileInfo> m_FileInfoVector;
u32 Read32(u64 _Offset) const; u32 Read32(u64 _Offset) const;
void GetStringFromOffset(u64 _Offset, char* Filename) const; std::string GetStringFromOffset(u64 _Offset) const;
const SFileInfo* FindFileInfo(const char* _rFullPath); const SFileInfo* FindFileInfo(const char* _rFullPath);
bool DetectFileSystem(); bool DetectFileSystem();
void InitFileSystem(); void InitFileSystem();

View File

@ -95,9 +95,11 @@ std::vector<std::string> CVolumeGC::GetNames() const
{ {
std::vector<std::string> names; std::vector<std::string> names;
char name[128] = {}; auto const string_decoder = GetStringDecoder(GetCountry());
if (m_pReader != NULL && Read(0x20, 0x60, (u8*)&name))
names.push_back(name); char name[0x60 + 1] = {};
if (m_pReader != NULL && Read(0x20, 0x60, (u8*)name))
names.push_back(string_decoder(name));
return names; return names;
} }
@ -143,4 +145,10 @@ bool CVolumeGC::IsDiscTwo() const
return discTwo; return discTwo;
} }
auto CVolumeGC::GetStringDecoder(ECountry country) -> StringDecoder
{
return (COUNTRY_JAPAN == country || COUNTRY_TAIWAN == country) ?
SHIFTJISToUTF8 : CP1252ToUTF8;
}
} // namespace } // namespace

View File

@ -41,6 +41,10 @@ public:
u64 GetSize() const; u64 GetSize() const;
bool IsDiscTwo() const; bool IsDiscTwo() const;
typedef std::string(*StringDecoder)(const std::string&);
static StringDecoder GetStringDecoder(ECountry country);
private: private:
IBlobReader* m_pReader; IBlobReader* m_pReader;
}; };

View File

@ -15,6 +15,7 @@
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include <algorithm>
#include <math.h> #include <math.h>
#include "VolumeWad.h" #include "VolumeWad.h"
@ -117,33 +118,32 @@ std::vector<std::string> CVolumeWAD::GetNames() const
{ {
return names; return names;
} }
footer_size = Common::swap32(footer_size);
//Japanese, English, German, French, Spanish, Italian, Dutch, unknown, unknown, Korean //Japanese, English, German, French, Spanish, Italian, Dutch, unknown, unknown, Korean
for (int i = 0; i != 10; ++i)
// Offset to the english title
for (int i = 0; i < 10; i++)
{ {
u16 temp[42]; static const u32 string_length = 42;
std::wstring out_temp; static const u32 bytes_length = string_length * sizeof(u16);
if (!Read(0x9C + (i*84) + OpeningBnrOffset, 84, (u8*)&temp) || Common::swap32(footer_size) < 0xF1 u16 temp[string_length];
|| !temp[0])
if (footer_size < 0xF1 || !Read(0x9C + (i * bytes_length) + OpeningBnrOffset, bytes_length, (u8*)&temp))
{ {
names.push_back(""); names.push_back("");
continue; ERROR_LOG(COMMON, "added empty WAD name");
}
for (int j = 0; j < 42; ++j)
{
u16 t = Common::swap16(temp[j]);
if (t == 0 && j > 0)
{
if (out_temp.at(out_temp.size()-1) != ' ')
out_temp.push_back(' ');
} }
else else
out_temp.push_back(t); {
} 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)); names.push_back(UTF16ToUTF8(out_temp));
ERROR_LOG(COMMON, "decoded WAD name: %s", names.back().c_str());
}
} }
return names; return names;

View File

@ -16,6 +16,7 @@
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
#include "VolumeWiiCrypted.h" #include "VolumeWiiCrypted.h"
#include "VolumeGC.h"
#include "StringUtil.h" #include "StringUtil.h"
#include "Crypto/sha1.h" #include "Crypto/sha1.h"
@ -172,11 +173,11 @@ std::vector<std::string> CVolumeWiiCrypted::GetNames() const
{ {
std::vector<std::string> names; std::vector<std::string> names;
auto const string_decoder = CVolumeGC::GetStringDecoder(GetCountry());
char name[0xFF] = {}; char name[0xFF] = {};
if (m_pReader != NULL && Read(0x20, 0x60, (u8*)&name)) if (m_pReader != NULL && Read(0x20, 0x60, (u8*)&name))
{ names.push_back(string_decoder(name));
names.push_back(name);
}
return names; return names;
} }