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

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

View File

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

View File

@ -20,6 +20,7 @@
#include <string>
#include <vector>
#include <algorithm>
#include "FileSystemGCWii.h"
#include "StringUtil.h"
@ -27,10 +28,10 @@
namespace DiscIO
{
CFileSystemGCWii::CFileSystemGCWii(const IVolume *_rVolume)
: IFileSystem(_rVolume),
m_Initialized(false),
m_Valid(false),
m_OffsetShift(0)
: IFileSystem(_rVolume)
, m_Initialized(false)
, m_Valid(false)
, m_OffsetShift(0)
{
m_Valid = DetectFileSystem();
}
@ -213,9 +214,16 @@ u32 CFileSystemGCWii::Read32(u64 _Offset) const
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)
@ -311,18 +319,16 @@ size_t CFileSystemGCWii::BuildFilenames(const size_t _FirstIndex, const size_t _
{
SFileInfo *rFileInfo = &m_FileInfoVector[CurrentIndex];
u64 uOffset = _NameTableOffset + (rFileInfo->m_NameOffset & 0xFFFFFF);
char filename[512];
memset(filename, 0, sizeof(filename));
GetStringFromOffset(uOffset, filename);
std::string filename = GetStringFromOffset(uOffset);
// check next index
if (rFileInfo->IsDirectory())
{
// this is a directory, build up the new szDirectory
if (_szDirectory != NULL)
CharArrayFromFormat(rFileInfo->m_FullPath, "%s%s/", _szDirectory, filename);
CharArrayFromFormat(rFileInfo->m_FullPath, "%s%s/", _szDirectory, filename.c_str());
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);
}
@ -330,9 +336,9 @@ size_t CFileSystemGCWii::BuildFilenames(const size_t _FirstIndex, const size_t _
{
// this is a filename
if (_szDirectory != NULL)
CharArrayFromFormat(rFileInfo->m_FullPath, "%s%s", _szDirectory, filename);
CharArrayFromFormat(rFileInfo->m_FullPath, "%s%s", _szDirectory, filename.c_str());
else
CharArrayFromFormat(rFileInfo->m_FullPath, "%s", filename);
CharArrayFromFormat(rFileInfo->m_FullPath, "%s", filename.c_str());
CurrentIndex++;
}

View File

@ -28,7 +28,7 @@ namespace DiscIO
class CFileSystemGCWii : public IFileSystem
{
public:
CFileSystemGCWii(const IVolume *_rVolume);
CFileSystemGCWii(const IVolume* _rVolume);
virtual ~CFileSystemGCWii();
virtual bool IsValid() const { return m_Valid; }
virtual u64 GetFileSize(const char* _rFullPath);
@ -44,11 +44,11 @@ public:
private:
bool m_Initialized;
bool m_Valid;
u32 m_OffsetShift; // WII offsets are all shifted
std::vector <SFileInfo> m_FileInfoVector;
u32 Read32(u64 _Offset) const;
void GetStringFromOffset(u64 _Offset, char* Filename) const;
std::string GetStringFromOffset(u64 _Offset) const;
const SFileInfo* FindFileInfo(const char* _rFullPath);
bool DetectFileSystem();
void InitFileSystem();

View File

@ -94,10 +94,12 @@ std::string CVolumeGC::GetMakerID() const
std::vector<std::string> CVolumeGC::GetNames() const
{
std::vector<std::string> names;
auto const string_decoder = GetStringDecoder(GetCountry());
char name[128] = {};
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;
}
@ -143,4 +145,10 @@ bool CVolumeGC::IsDiscTwo() const
return discTwo;
}
auto CVolumeGC::GetStringDecoder(ECountry country) -> StringDecoder
{
return (COUNTRY_JAPAN == country || COUNTRY_TAIWAN == country) ?
SHIFTJISToUTF8 : CP1252ToUTF8;
}
} // namespace

View File

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

View File

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

View File

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