74 changes: 38 additions & 36 deletions Source/Core/Common/Src/FileUtil.cpp
Expand Up @@ -41,10 +41,11 @@
#include <CoreFoundation/CFBundle.h>
#endif

#include <fstream>
#include <algorithm>
#include <sys/stat.h>

#include "StringUtil.h"

#ifndef S_ISDIR
#define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR)
#endif
Expand Down Expand Up @@ -81,7 +82,11 @@ bool Exists(const std::string &filename)
std::string copy(filename);
StripTailDirSlashes(copy);

#ifdef _WIN32
int result = _tstat64(UTF8ToTStr(copy).c_str(), &file_info);
#else
int result = stat64(copy.c_str(), &file_info);
#endif

return (result == 0);
}
Expand All @@ -94,7 +99,11 @@ bool IsDirectory(const std::string &filename)
std::string copy(filename);
StripTailDirSlashes(copy);

#ifdef _WIN32
int result = _tstat64(UTF8ToTStr(copy).c_str(), &file_info);
#else
int result = stat64(copy.c_str(), &file_info);
#endif

if (result < 0) {
WARN_LOG(COMMON, "IsDirectory: stat failed on %s: %s",
Expand Down Expand Up @@ -127,7 +136,7 @@ bool Delete(const std::string &filename)
}

#ifdef _WIN32
if (!DeleteFile(filename.c_str()))
if (!DeleteFile(UTF8ToTStr(filename).c_str()))
{
WARN_LOG(COMMON, "Delete: DeleteFile failed on %s: %s",
filename.c_str(), GetLastErrorMsg());
Expand All @@ -149,7 +158,7 @@ bool CreateDir(const std::string &path)
{
INFO_LOG(COMMON, "CreateDir: directory %s", path.c_str());
#ifdef _WIN32
if (::CreateDirectory(path.c_str(), NULL))
if (::CreateDirectory(UTF8ToTStr(path).c_str(), NULL))
return true;
DWORD error = GetLastError();
if (error == ERROR_ALREADY_EXISTS)
Expand Down Expand Up @@ -228,7 +237,7 @@ bool DeleteDir(const std::string &filename)
}

#ifdef _WIN32
if (::RemoveDirectory(filename.c_str()))
if (::RemoveDirectory(UTF8ToTStr(filename).c_str()))
return true;
#else
if (rmdir(filename.c_str()) == 0)
Expand Down Expand Up @@ -257,7 +266,7 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename)
INFO_LOG(COMMON, "Copy: %s --> %s",
srcFilename.c_str(), destFilename.c_str());
#ifdef _WIN32
if (CopyFile(srcFilename.c_str(), destFilename.c_str(), FALSE))
if (CopyFile(UTF8ToTStr(srcFilename).c_str(), UTF8ToTStr(destFilename).c_str(), FALSE))
return true;

ERROR_LOG(COMMON, "Copy: failed %s --> %s: %s",
Expand Down Expand Up @@ -342,8 +351,13 @@ u64 GetSize(const std::string &filename)
WARN_LOG(COMMON, "GetSize: failed %s: is a directory", filename.c_str());
return 0;
}

struct stat64 buf;
#ifdef _WIN32
if (_tstat64(UTF8ToTStr(filename).c_str(), &buf) == 0)
#else
if (stat64(filename.c_str(), &buf) == 0)
#endif
{
DEBUG_LOG(COMMON, "GetSize: %s: %lld",
filename.c_str(), (long long)buf.st_size);
Expand Down Expand Up @@ -391,13 +405,13 @@ bool CreateEmptyFile(const std::string &filename)
{
INFO_LOG(COMMON, "CreateEmptyFile: %s", filename.c_str());

FILE *pFile = fopen(filename.c_str(), "wb");
if (!pFile) {
if (!File::IOFile(filename, "wb"))
{
ERROR_LOG(COMMON, "CreateEmptyFile: failed %s: %s",
filename.c_str(), GetLastErrorMsg());
return false;
}
fclose(pFile);

return true;
}

Expand All @@ -413,7 +427,7 @@ u32 ScanDirectoryTree(const std::string &directory, FSTEntry& parentEntry)
// Find the first file in the directory.
WIN32_FIND_DATA ffd;

HANDLE hFind = FindFirstFile((directory + "\\*").c_str(), &ffd);
HANDLE hFind = FindFirstFile(UTF8ToTStr(directory + "\\*").c_str(), &ffd);
if (hFind == INVALID_HANDLE_VALUE)
{
FindClose(hFind);
Expand All @@ -423,7 +437,7 @@ u32 ScanDirectoryTree(const std::string &directory, FSTEntry& parentEntry)
do
{
FSTEntry entry;
const std::string virtualName(ffd.cFileName);
const std::string virtualName(TStrToUTF8(ffd.cFileName));
#else
struct dirent dirent, *result = NULL;

Expand Down Expand Up @@ -480,7 +494,7 @@ bool DeleteDirRecursively(const std::string &directory)
#ifdef _WIN32
// Find the first file in the directory.
WIN32_FIND_DATA ffd;
HANDLE hFind = FindFirstFile((directory + "\\*").c_str(), &ffd);
HANDLE hFind = FindFirstFile(UTF8ToTStr(directory + "\\*").c_str(), &ffd);

if (hFind == INVALID_HANDLE_VALUE)
{
Expand All @@ -491,7 +505,7 @@ bool DeleteDirRecursively(const std::string &directory)
// windows loop
do
{
const std::string virtualName = ffd.cFileName;
const std::string virtualName(TStrToUTF8(ffd.cFileName));
#else
struct dirent dirent, *result = NULL;
DIR *dirp = opendir(directory.c_str());
Expand Down Expand Up @@ -622,14 +636,14 @@ std::string GetBundleDirectory()
#endif

#ifdef _WIN32
std::string &GetExeDirectory()
std::string& GetExeDirectory()
{
static std::string DolphinPath;
if (DolphinPath.empty())
{
char Dolphin_exe_Path[2048];
GetModuleFileNameA(NULL, Dolphin_exe_Path, 2048);
DolphinPath = Dolphin_exe_Path;
TCHAR Dolphin_exe_Path[2048];
GetModuleFileName(NULL, Dolphin_exe_Path, 2048);
DolphinPath = TStrToUTF8(Dolphin_exe_Path);
DolphinPath = DolphinPath.substr(0, DolphinPath.find_last_of('\\'));
}
return DolphinPath;
Expand Down Expand Up @@ -730,31 +744,19 @@ std::string &GetUserPath(const unsigned int DirIDX, const std::string &newPath)

bool WriteStringToFile(bool text_file, const std::string &str, const char *filename)
{
FILE *f = fopen(filename, text_file ? "w" : "wb");
if (!f)
return false;
size_t len = str.size();
if (len != fwrite(str.data(), 1, str.size(), f)) // TODO: string::data() may not be contiguous
{
fclose(f);
return false;
}
fclose(f);
return true;
return File::IOFile(filename, text_file ? "w" : "wb").WriteBytes(str.data(), str.size());
}

bool ReadFileToString(bool text_file, const char *filename, std::string &str)
{
FILE *f = fopen(filename, text_file ? "r" : "rb");
File::IOFile file(filename, text_file ? "r" : "rb");
auto const f = file.GetHandle();

if (!f)
return false;
size_t len = (size_t)GetSize(f);
char *buf = new char[len + 1];
buf[fread(buf, 1, len, f)] = 0;
str = std::string(buf, len);
fclose(f);
delete [] buf;
return true;

str.resize(GetSize(f));
return file.ReadArray(&str[0], str.size());
}

IOFile::IOFile()
Expand Down Expand Up @@ -798,7 +800,7 @@ bool IOFile::Open(const std::string& filename, const char openmode[])
{
Close();
#ifdef _WIN32
fopen_s(&m_file, filename.c_str(), openmode);
_tfopen_s(&m_file, UTF8ToTStr(filename).c_str(), UTF8ToTStr(openmode).c_str());
#else
m_file = fopen(filename.c_str(), openmode);
#endif
Expand Down
12 changes: 12 additions & 0 deletions Source/Core/Common/Src/FileUtil.h
Expand Up @@ -25,6 +25,7 @@
#include <string.h>

#include "Common.h"
#include "StringUtil.h"

// User directory indices for GetUserPath
enum {
Expand Down Expand Up @@ -226,4 +227,15 @@ class IOFile

} // namespace

// To deal with Windows being dumb at unicode:
template <typename T>
void OpenFStream(T& fstream, const std::string& filename, std::ios_base::openmode openmode)
{
#ifdef _WIN32
fstream.open(UTF8ToTStr(filename).c_str(), openmode);
#else
fstream.open(filename.c_str(), openmode);
#endif
}

#endif
5 changes: 3 additions & 2 deletions Source/Core/Common/Src/IniFile.cpp
Expand Up @@ -25,6 +25,7 @@
#include <fstream>
#include <algorithm>

#include "FileUtil.h"
#include "StringUtil.h"
#include "IniFile.h"

Expand Down Expand Up @@ -400,7 +401,7 @@ bool IniFile::Load(const char* filename)

// Open file
std::ifstream in;
in.open(filename, std::ios::in);
OpenFStream(in, filename, std::ios::in);

if (in.fail()) return false;

Expand Down Expand Up @@ -452,7 +453,7 @@ bool IniFile::Load(const char* filename)
bool IniFile::Save(const char* filename)
{
std::ofstream out;
out.open(filename, std::ios::out);
OpenFStream(out, filename, std::ios::out);

if (out.fail())
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Common/Src/LinearDiskCache.h
Expand Up @@ -74,7 +74,7 @@ class LinearDiskCache
m_num_entries = 0;

// try opening for reading/writing
m_file.open(filename, ios_base::in | ios_base::out | ios_base::binary);
OpenFStream(m_file, filename, ios_base::in | ios_base::out | ios_base::binary);

m_file.seekg(0, std::ios::end);
std::fstream::pos_type end_pos = m_file.tellg();
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Common/Src/LogManager.cpp
Expand Up @@ -186,7 +186,7 @@ void LogContainer::Trigger(LogTypes::LOG_LEVELS level, const char *msg)

FileLogListener::FileLogListener(const char *filename)
{
m_logfile.open(filename, std::ios::app);
OpenFStream(m_logfile, filename, std::ios::app);
SetEnable(true);
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Common/Src/Misc.cpp
Expand Up @@ -31,7 +31,7 @@ const char* GetLastErrorMsg()
#ifdef _WIN32
static __declspec(thread) char err_str[buff_size] = {};

FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
err_str, buff_size, NULL);
#else
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Common/Src/MsgHandler.cpp
Expand Up @@ -106,7 +106,7 @@ bool DefaultMsgHandler(const char* caption, const char* text, bool yes_no, int S
if (Style == QUESTION) STYLE = MB_ICONQUESTION;
if (Style == WARNING) STYLE = MB_ICONWARNING;

return IDYES == MessageBox(0, text, caption, STYLE | (yes_no ? MB_YESNO : MB_OK));
return IDYES == MessageBox(0, UTF8ToTStr(text).c_str(), UTF8ToTStr(caption).c_str(), STYLE | (yes_no ? MB_YESNO : MB_OK));

#else
printf("%s\n", text);
Expand Down
6 changes: 4 additions & 2 deletions Source/Core/Common/Src/NandPaths.cpp
Expand Up @@ -86,7 +86,8 @@ bool CheckTitleTIK(u64 _titleID)

static void CreateReplacementFile(std::string &filename)
{
std::ofstream replace(filename.c_str());
std::ofstream replace;
OpenFStream(replace, filename, std::ios_base::out);
replace <<"\" __22__\n";
replace << "* __2a__\n";
//replace << "/ __2f__\n";
Expand All @@ -108,7 +109,8 @@ void ReadReplacements(replace_v& replacements)
if (!File::Exists(filename))
CreateReplacementFile(filename);

std::ifstream f(filename.c_str());
std::ifstream f;
OpenFStream(f, filename, std::ios_base::in);
char letter;
std::string replacement;

Expand Down
7 changes: 3 additions & 4 deletions Source/Core/Common/Src/SDCardUtil.cpp
Expand Up @@ -29,6 +29,7 @@
// Modified for Dolphin.

#include "SDCardUtil.h"
#include "FileUtil.h"

#include <time.h>
#include <stdio.h>
Expand Down Expand Up @@ -190,7 +191,6 @@ bool SDCardCreate(u64 disk_size /*in MB*/, const char* filename)
{
u32 sectors_per_fat;
u32 sectors_per_disk;
FILE* f;

// Convert MB to bytes
disk_size *= 1024 * 1024;
Expand All @@ -207,7 +207,8 @@ bool SDCardCreate(u64 disk_size /*in MB*/, const char* filename)
boot_sector_init(s_boot_sector, s_fsinfo_sector, disk_size, nullptr);
fat_init(s_fat_head);

f = fopen(filename, "wb");
File::IOFile file(filename, "wb");
FILE* const f = file.GetHandle();
if (!f)
{
ERROR_LOG(COMMON, "Could not create file '%s', aborting...\n", filename);
Expand Down Expand Up @@ -247,13 +248,11 @@ bool SDCardCreate(u64 disk_size /*in MB*/, const char* filename)

if (write_empty(f, sectors_per_disk - RESERVED_SECTORS - 2*sectors_per_fat)) goto FailWrite;

fclose(f);
return true;

FailWrite:
ERROR_LOG(COMMON, "Could not write to '%s', aborting...\n", filename);
if (unlink(filename) < 0)
ERROR_LOG(COMMON, "unlink(%s) failed\n%s", filename, GetLastErrorMsg());
fclose(f);
return false;
}
144 changes: 144 additions & 0 deletions Source/Core/Common/Src/StringUtil.cpp
Expand Up @@ -17,11 +17,21 @@

#include <stdlib.h>
#include <stdio.h>
#include <algorithm>

#include "Common.h"
#include "CommonPaths.h"
#include "StringUtil.h"

#ifdef _WIN32
#include <Windows.h>
#elif defined(ANDROID)

#else
#include <iconv.h>
#include <errno.h>
#endif

// faster than sscanf
bool AsciiToHex(const char* _szValue, u32& result)
{
Expand Down Expand Up @@ -375,3 +385,137 @@ std::string UriEncode(const std::string & sSrc)
delete [] pStart;
return sResult;
}

#ifdef _WIN32

std::string UTF16ToUTF8(const std::wstring& input)
{
auto const size = WideCharToMultiByte(CP_UTF8, 0, input.data(), input.size(), nullptr, 0, nullptr, nullptr);

std::string output;
output.resize(size);

if (size != WideCharToMultiByte(CP_UTF8, 0, input.data(), input.size(), &output[0], output.size(), nullptr, nullptr))
output.clear();

return output;
}

std::wstring CPToUTF16(u32 code_page, const std::string& input)
{
auto const size = MultiByteToWideChar(code_page, 0, input.data(), input.size(), nullptr, 0);

std::wstring output;
output.resize(size);

if (size != MultiByteToWideChar(code_page, 0, input.data(), input.size(), &output[0], output.size()))
output.clear();

return output;
}

std::wstring UTF8ToUTF16(const std::string& input)
{
return CPToUTF16(CP_UTF8, input);
}

std::string SHIFTJISToUTF8(const std::string& input)
{
return UTF16ToUTF8(CPToUTF16(932, input));
}

std::string CP1252ToUTF8(const std::string& input)
{
return UTF16ToUTF8(CPToUTF16(1252, input));
}

#else

template <typename T>
std::string CodeToUTF8(const char* fromcode, const std::basic_string<T>& input)
{
std::string result;

#if defined(ANDROID)
result = "Not implemented on Android!";

#else
iconv_t const conv_desc = iconv_open("UTF-8", fromcode);
if ((iconv_t)-1 == conv_desc)
{
ERROR_LOG(COMMON, "Iconv initialization failure [%s]: %s", fromcode, strerror(errno));
}
else
{
size_t const in_bytes = sizeof(T) * input.size();
size_t const out_buffer_size = 4 * in_bytes;

std::string out_buffer;
out_buffer.resize(out_buffer_size);

auto src_buffer = &input[0];
size_t src_bytes = in_bytes;
auto dst_buffer = &out_buffer[0];
size_t dst_bytes = out_buffer.size();

while (src_bytes != 0)
{
size_t const iconv_result = iconv(conv_desc, (char**)(&src_buffer), &src_bytes,
&dst_buffer, &dst_bytes);

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);
}

#endif
return result;
}

std::string CP1252ToUTF8(const std::string& input)
{
//return CodeToUTF8("CP1252//TRANSLIT", input);
//return CodeToUTF8("CP1252//IGNORE", input);
return CodeToUTF8("CP1252", input);
}

std::string SHIFTJISToUTF8(const std::string& input)
{
//return CodeToUTF8("CP932", input);
return CodeToUTF8("SJIS", input);
}

std::string UTF16ToUTF8(const std::wstring& 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
24 changes: 24 additions & 0 deletions Source/Core/Common/Src/StringUtil.h
Expand Up @@ -97,4 +97,28 @@ std::string ReplaceAll(std::string result, const std::string& src, const std::st
std::string UriDecode(const std::string & sSrc);
std::string UriEncode(const std::string & sSrc);

std::string CP1252ToUTF8(const std::string& str);
std::string SHIFTJISToUTF8(const std::string& str);
std::string UTF16ToUTF8(const std::wstring& str);

#ifdef _WIN32

std::wstring UTF8ToUTF16(const std::string& str);

#ifdef _UNICODE
inline std::string TStrToUTF8(const std::wstring& str)
{ return UTF16ToUTF8(str); }

inline std::wstring UTF8ToTStr(const std::string& str)
{ return UTF8ToUTF16(str); }
#else
inline std::string TStrToUTF8(const std::string& str)
{ return str; }

inline std::string UTF8ToTStr(const std::string& str)
{ return str; }
#endif

#endif

#endif // _STRINGUTIL_H_
6 changes: 3 additions & 3 deletions Source/Core/Core/Core.vcxproj
Expand Up @@ -44,7 +44,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<UseDebugLibraries>false</UseDebugLibraries>
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugFast|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
Expand All @@ -54,7 +54,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<UseDebugLibraries>false</UseDebugLibraries>
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugFast|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
Expand Down Expand Up @@ -602,4 +602,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
6 changes: 3 additions & 3 deletions Source/Core/Core/Src/ConfigManager.cpp
Expand Up @@ -137,7 +137,7 @@ void SConfig::SaveSettings()
ini.Get("General", "GCMPathes", &oldPaths, 0);
for (int i = numPaths; i < oldPaths; i++)
{
TCHAR tmp[16];
char tmp[16];
sprintf(tmp, "GCMPath%i", i);
ini.DeleteKey("General", tmp);
}
Expand All @@ -146,7 +146,7 @@ void SConfig::SaveSettings()

for (int i = 0; i < numPaths; i++)
{
TCHAR tmp[16];
char tmp[16];
sprintf(tmp, "GCMPath%i", i);
ini.Set("General", tmp, m_ISOFolder[i]);
}
Expand Down Expand Up @@ -284,7 +284,7 @@ void SConfig::LoadSettings()
{
for (int i = 0; i < numGCMPaths; i++)
{
TCHAR tmp[16];
char tmp[16];
sprintf(tmp, "GCMPath%i", i);
std::string tmpPath;
ini.Get("General", tmp, &tmpPath, "");
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Core/Src/Console.cpp
Expand Up @@ -98,8 +98,8 @@ void Console_Submit(const char *cmd)
}
CASE("dump")
{
TCHAR temp[256];
TCHAR filename[256];
char temp[256];
char filename[256];
u32 start;
u32 end;
sscanf(cmd, "%s %08x %08x %s", temp, &start, &end, filename);
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/Core/Src/DSP/assemble.cpp
Expand Up @@ -754,7 +754,8 @@ bool DSPAssembler::AssembleFile(const char *fname, int pass)
{
int disable_text = 0; // modified by Hermes

std::ifstream fsrc(fname);
std::ifstream fsrc;
OpenFStream(fsrc, fname, std::ios_base::in);

if (fsrc.fail())
{
Expand Down
46 changes: 21 additions & 25 deletions Source/Core/Core/Src/HW/BBA-TAP/TAP_Win32.cpp
Expand Up @@ -25,7 +25,7 @@
namespace Win32TAPHelper
{

bool IsTAPDevice(const char *guid)
bool IsTAPDevice(const TCHAR *guid)
{
HKEY netcard_key;
LONG status;
Expand All @@ -39,13 +39,13 @@ bool IsTAPDevice(const char *guid)

for (;;)
{
char enum_name[256];
char unit_string[256];
TCHAR enum_name[256];
TCHAR unit_string[256];
HKEY unit_key;
char component_id_string[] = "ComponentId";
char component_id[256];
char net_cfg_instance_id_string[] = "NetCfgInstanceId";
char net_cfg_instance_id[256];
TCHAR component_id_string[] = _T("ComponentId");
TCHAR component_id[256];
TCHAR net_cfg_instance_id_string[] = _T("NetCfgInstanceId");
TCHAR net_cfg_instance_id[256];
DWORD data_type;

len = sizeof(enum_name);
Expand All @@ -56,7 +56,7 @@ bool IsTAPDevice(const char *guid)
else if (status != ERROR_SUCCESS)
return false;

snprintf(unit_string, sizeof(unit_string), "%s\\%s", ADAPTER_KEY, enum_name);
_sntprintf(unit_string, sizeof(unit_string), _T("%s\\%s"), ADAPTER_KEY, enum_name);

status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, unit_string, 0, KEY_READ, &unit_key);

Expand All @@ -78,8 +78,8 @@ bool IsTAPDevice(const char *guid)

if (status == ERROR_SUCCESS && data_type == REG_SZ)
{
if (!strcmp(component_id, TAP_COMPONENT_ID) &&
!strcmp(net_cfg_instance_id, guid))
if (!_tcscmp(component_id, TAP_COMPONENT_ID) &&
!_tcscmp(net_cfg_instance_id, guid))
{
RegCloseKey(unit_key);
RegCloseKey(netcard_key);
Expand All @@ -96,7 +96,7 @@ bool IsTAPDevice(const char *guid)
return false;
}

bool GetGUIDs(std::vector<std::string>& guids)
bool GetGUIDs(std::vector<std::basic_string<TCHAR>>& guids)
{
LONG status;
HKEY control_net_key;
Expand All @@ -111,12 +111,12 @@ bool GetGUIDs(std::vector<std::string>& guids)

while (!found_all)
{
char enum_name[256];
char connection_string[256];
TCHAR enum_name[256];
TCHAR connection_string[256];
HKEY connection_key;
char name_data[256];
TCHAR name_data[256];
DWORD name_type;
const char name_string[] = "Name";
const TCHAR name_string[] = _T("Name");

len = sizeof(enum_name);
status = RegEnumKeyEx(control_net_key, i, enum_name,
Expand All @@ -127,8 +127,8 @@ bool GetGUIDs(std::vector<std::string>& guids)
else if (status != ERROR_SUCCESS)
return false;

snprintf(connection_string, sizeof(connection_string),
"%s\\%s\\Connection", NETWORK_CONNECTIONS_KEY, enum_name);
_sntprintf(connection_string, sizeof(connection_string),
_T("%s\\%s\\Connection"), NETWORK_CONNECTIONS_KEY, enum_name);

status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, connection_string,
0, KEY_READ, &connection_key);
Expand Down Expand Up @@ -165,15 +165,11 @@ bool GetGUIDs(std::vector<std::string>& guids)
return true;
}

bool OpenTAP(HANDLE& adapter, const std::string device_guid)
bool OpenTAP(HANDLE& adapter, const std::basic_string<TCHAR>& device_guid)
{
char device_path[256];
auto const device_path = USERMODEDEVICEDIR + device_guid + TAPSUFFIX;

/* Open Windows TAP-Win32 adapter */
snprintf(device_path, sizeof(device_path), "%s%s%s",
USERMODEDEVICEDIR, device_guid.c_str(), TAPSUFFIX);

adapter = CreateFile(device_path, GENERIC_READ | GENERIC_WRITE, 0, 0,
adapter = CreateFile(device_path.c_str(), GENERIC_READ | GENERIC_WRITE, 0, 0,
OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, 0);

if (adapter == INVALID_HANDLE_VALUE)
Expand All @@ -192,7 +188,7 @@ bool CEXIETHERNET::Activate()
return true;

DWORD len;
std::vector<std::string> device_guids;
std::vector<std::basic_string<TCHAR>> device_guids;

if (!Win32TAPHelper::GetGUIDs(device_guids))
{
Expand Down
14 changes: 7 additions & 7 deletions Source/Core/Core/Src/HW/BBA-TAP/TAP_Win32.h
Expand Up @@ -65,23 +65,23 @@
// Registry keys
//=================

#define ADAPTER_KEY "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}"
#define ADAPTER_KEY _T("SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}")

#define NETWORK_CONNECTIONS_KEY "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}"
#define NETWORK_CONNECTIONS_KEY _T("SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}")

//======================
// Filesystem prefixes
//======================

#define USERMODEDEVICEDIR "\\\\.\\Global\\"
#define SYSDEVICEDIR "\\Device\\"
#define USERDEVICEDIR "\\DosDevices\\Global\\"
#define TAPSUFFIX ".tap"
#define USERMODEDEVICEDIR _T("\\\\.\\Global\\")
#define SYSDEVICEDIR _T("\\Device\\")
#define USERDEVICEDIR _T("\\DosDevices\\Global\\")
#define TAPSUFFIX _T(".tap")

//=========================================================
// TAP_COMPONENT_ID -- This string defines the TAP driver
// type -- different component IDs can reside in the system
// simultaneously.
//=========================================================

#define TAP_COMPONENT_ID "tap0901"
#define TAP_COMPONENT_ID _T("tap0901")
2 changes: 1 addition & 1 deletion Source/Core/Core/Src/HW/WiimoteEmu/EmuSubroutines.cpp
Expand Up @@ -297,7 +297,7 @@ void Wiimote::WriteData(const wm_write_data* const wd)
{
// writing the whole mii block each write :/
std::ofstream file;
file.open((File::GetUserPath(D_WIIUSER_IDX) + "mii.bin").c_str(), std::ios::binary | std::ios::out);
OpenFStream(file, File::GetUserPath(D_WIIUSER_IDX) + "mii.bin", std::ios::binary | std::ios::out);
file.write((char*)m_eeprom + 0x0FCA, 0x02f0);
file.close();
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/Src/HW/WiimoteEmu/Speaker.cpp
Expand Up @@ -106,7 +106,7 @@ void Wiimote::SpeakerData(wm_speaker_data* sd)
File::Delete("rmtdump.wav");
File::Delete("rmtdump.bin");
atexit(stopdamnwav);
ofile.open("rmtdump.bin", ofile.binary | ofile.out);
OpenFStream(ofile, "rmtdump.bin", ofile.binary | ofile.out);
wav.Start("rmtdump.wav", 6000/*Common::swap16(m_reg_speaker.sample_rate)*/);
}
wav.AddMonoSamples(samples, sd->length*2);
Expand Down
8 changes: 2 additions & 6 deletions Source/Core/Core/Src/HW/WiimoteReal/IOWin.cpp
Expand Up @@ -17,7 +17,6 @@

#include <stdio.h>
#include <stdlib.h>
#include <regex>
#include <algorithm>
#include <unordered_map>
#include <ctime>
Expand Down Expand Up @@ -87,7 +86,7 @@ static int initialized = 0;
std::unordered_map<BTH_ADDR, std::time_t> g_connect_times;

#ifdef SHARE_WRITE_WIIMOTES
std::unordered_set<std::string> g_connected_wiimotes;
std::unordered_set<std::basic_string<TCHAR>> g_connected_wiimotes;
std::mutex g_connected_wiimotes_lock;
#endif

Expand Down Expand Up @@ -495,9 +494,6 @@ int Wiimote::IOWrite(const u8* buf, int len)
template <typename T>
void ProcessWiimotes(bool new_scan, T& callback)
{
// match strings like "Nintendo RVL-WBC-01", "Nintendo RVL-CNT-01", "Nintendo RVL-CNT-01-TR"
const std::wregex wiimote_device_name(L"Nintendo RVL-.*");

BLUETOOTH_DEVICE_SEARCH_PARAMS srch;
srch.dwSize = sizeof(srch);
srch.fReturnAuthenticated = true;
Expand Down Expand Up @@ -540,7 +536,7 @@ void ProcessWiimotes(bool new_scan, T& callback)
DEBUG_LOG(WIIMOTE, "authed %i connected %i remembered %i ",
btdi.fAuthenticated, btdi.fConnected, btdi.fRemembered);

if (std::regex_match(btdi.szName, wiimote_device_name))
if (IsValidBluetoothName(UTF16ToUTF8(btdi.szName)))
{
callback(hRadio, radioInfo, btdi);
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/Src/HW/WiimoteReal/WiimoteReal.h
Expand Up @@ -91,7 +91,7 @@ friend class WiimoteEmu::Wiimote;
int int_sock; // Interrupt socket

#elif defined(_WIN32)
std::string devicepath; // Unique wiimote reference
std::basic_string<TCHAR> devicepath; // Unique wiimote reference
//ULONGLONG btaddr; // Bluetooth address
HANDLE dev_handle; // HID handle
OVERLAPPED hid_overlap_read, hid_overlap_write; // Overlap handle
Expand Down
5 changes: 3 additions & 2 deletions Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_es.cpp
Expand Up @@ -58,6 +58,7 @@
#include "CommonPaths.h"
#include "IPC_HLE/WII_IPC_HLE_Device_usb.h"
#include "../Movie.h"
#include "StringUtil.h"

#ifdef _WIN32
#include <Windows.h>
Expand Down Expand Up @@ -926,7 +927,7 @@ u32 CWII_IPC_HLE_Device_es::ES_DIVerify(u8* _pTMD, u32 _sz)
else
{
#ifdef _WIN32
MoveFile(savePath.c_str(), (savePath + "../backup/").c_str());
MoveFile(UTF8ToTStr(savePath).c_str(), UTF8ToTStr(savePath + "../backup/").c_str());
#else
File::CopyDir(savePath.c_str(),(savePath + "../backup/").c_str());
File::DeleteDirRecursively(savePath.c_str());
Expand All @@ -940,7 +941,7 @@ u32 CWII_IPC_HLE_Device_es::ES_DIVerify(u8* _pTMD, u32 _sz)
if (File::Exists((savePath + "banner.bin").c_str()))
File::DeleteDirRecursively(savePath);
#ifdef _WIN32
MoveFile((savePath + "../backup/").c_str(), savePath.c_str());
MoveFile(UTF8ToTStr(savePath + "../backup/").c_str(), UTF8ToTStr(savePath).c_str());
#else
File::CopyDir((savePath + "../backup/").c_str(), savePath.c_str());
File::DeleteDirRecursively((savePath + "../backup/").c_str());
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/Src/NetPlay.h
Expand Up @@ -34,7 +34,7 @@ struct Rpt : public std::vector<u8>

typedef std::vector<Rpt> NetWiimote;

#define NETPLAY_VERSION "Dolphin NetPlay r6423"
#define NETPLAY_VERSION "Dolphin NetPlay 2013-03-03"

// messages
enum
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/DiscIO/DiscIO.vcxproj
Expand Up @@ -44,7 +44,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<UseDebugLibraries>false</UseDebugLibraries>
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugFast|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
Expand All @@ -54,7 +54,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<UseDebugLibraries>false</UseDebugLibraries>
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugFast|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
Expand Down
182 changes: 2 additions & 180 deletions Source/Core/DiscIO/Src/BannerLoader.cpp
Expand Up @@ -22,196 +22,18 @@
#include "VolumeCreator.h"
#include "FileUtil.h"

// HyperIris: dunno if this suitable, may be need move.
#ifdef _WIN32
#include <Windows.h>
#else
#include <sys/param.h>
#ifndef ANDROID
#include <iconv.h>
#endif
#include <errno.h>
#endif

#ifndef ICONV_CONST
#if defined __FreeBSD__ || __NetBSD__
#define ICONV_CONST const
#else
#define ICONV_CONST
#endif
#endif

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;
}

bool IBannerLoader::CopyBeUnicodeToString( std::string& _rDestination, const u16* _src, int length )
{
bool returnCode = false;
#ifdef WIN32
if (_src)
{
u16* buffer = new u16[length];
if (buffer)
{
memcpy(buffer, _src, sizeof(u16)*length);
for (int i = 0; i < length; i++)
{
buffer[i] = swap16(buffer[i]);
}

u32 ansiNameSize = WideCharToMultiByte(932, 0,
(LPCWSTR)buffer, (int)wcslen((LPCWSTR)buffer),
NULL, NULL, NULL, NULL);
if (ansiNameSize > 0)
{
char* pAnsiStrBuffer = new char[ansiNameSize + 1];
if (pAnsiStrBuffer)
{
memset(pAnsiStrBuffer, 0, (ansiNameSize + 1) * sizeof(char));
if (WideCharToMultiByte(932, 0,
(LPCWSTR)buffer, (int)wcslen((LPCWSTR)buffer),
pAnsiStrBuffer, ansiNameSize, NULL, NULL))
{
_rDestination = pAnsiStrBuffer;
returnCode = true;
}
delete[] pAnsiStrBuffer;
}
}
delete[] buffer;
}
}
#else
#ifdef ANDROID
return false;
#else
if (_src)
{
iconv_t conv_desc = iconv_open("UTF-8", "CP932");
if (conv_desc == (iconv_t) -1)
{
// Initialization failure.
if (errno == EINVAL)
{
ERROR_LOG(DISCIO, "Conversion from CP932 to UTF-8 is not supported.");
}
else
{
ERROR_LOG(DISCIO, "Iconv initialization failure: %s\n", strerror (errno));
}
return false;
}

char* src_buffer = new char[length];
for (int i = 0; i < length; i++)
src_buffer[i] = swap16(_src[i]);

size_t inbytes = sizeof(char) * length;
size_t outbytes = 2 * inbytes;
char* utf8_buffer = new char[outbytes + 1];
memset(utf8_buffer, 0, (outbytes + 1) * sizeof(char));

// Save the buffer locations because iconv increments them
char* utf8_buffer_start = utf8_buffer;
char* src_buffer_start = src_buffer;

size_t iconv_size = iconv(conv_desc,
(ICONV_CONST char**)&src_buffer, &inbytes,
&utf8_buffer, &outbytes);

// Handle failures
if (iconv_size == (size_t) -1)
{
ERROR_LOG(DISCIO, "iconv failed.");
switch (errno) {
case EILSEQ:
ERROR_LOG(DISCIO, "Invalid multibyte sequence.");
break;
case EINVAL:
ERROR_LOG(DISCIO, "Incomplete multibyte sequence.");
break;
case E2BIG:
ERROR_LOG(DISCIO, "Insufficient space allocated for output buffer.");
break;
default:
ERROR_LOG(DISCIO, "Error: %s.", strerror(errno));
}
}
else
{
_rDestination = utf8_buffer_start;
returnCode = true;
}
delete[] utf8_buffer_start;
delete[] src_buffer_start;
iconv_close(conv_desc);
}
#endif
#endif
return returnCode;
}

IBannerLoader* CreateBannerLoader(DiscIO::IFileSystem& _rFileSystem, DiscIO::IVolume *pVolume)
{
if (IsVolumeWiiDisc(pVolume) || IsVolumeWadFile(pVolume))
{
return new CBannerLoaderWii(pVolume);
}
if (_rFileSystem.IsValid())
if (_rFileSystem.IsValid())
{
return new CBannerLoaderGC(_rFileSystem);
return new CBannerLoaderGC(_rFileSystem, pVolume);
}

return NULL;
Expand Down
24 changes: 6 additions & 18 deletions Source/Core/DiscIO/Src/BannerLoader.h
Expand Up @@ -18,6 +18,9 @@
#ifndef _BANNER_LOADER_H_
#define _BANNER_LOADER_H_

#include <vector>
#include <string>

#include "Filesystem.h"

namespace DiscIO
Expand All @@ -38,24 +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;
virtual bool GetDescription(std::wstring& _rDescription) {return false;};


protected:

void CopyToStringAndCheck(std::string& _rDestination, const char* _src);

bool CopyBeUnicodeToString(std::string& _rDestination, const u16* _src, int length);
private:
u16 swap16(u16 data)
{
return ((data & 0xff00) >> 8) | ((data & 0xff) << 8);
}
virtual std::vector<std::string> GetNames() = 0;
virtual std::string GetCompany() = 0;
virtual std::vector<std::string> GetDescriptions() = 0;
};

IBannerLoader* CreateBannerLoader(DiscIO::IFileSystem& _rFileSystem, DiscIO::IVolume *pVolume);
Expand Down
143 changes: 63 additions & 80 deletions Source/Core/DiscIO/Src/BannerLoaderGC.cpp
Expand Up @@ -23,13 +23,14 @@

namespace DiscIO
{
CBannerLoaderGC::CBannerLoaderGC(DiscIO::IFileSystem& _rFileSystem)
: m_pBannerFile(NULL),
m_IsValid(false)
CBannerLoaderGC::CBannerLoaderGC(DiscIO::IFileSystem& _rFileSystem, DiscIO::IVolume* volume)
: m_pBannerFile(NULL)
, m_IsValid(false)
, m_country(volume->GetCountry())
{
// 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)
Expand Down Expand Up @@ -62,140 +63,118 @@ bool CBannerLoaderGC::IsValid()
return m_IsValid;
}


bool CBannerLoaderGC::GetBanner(u32* _pBannerImage)
{
if (!IsValid())
{
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;
name_count = 6;
break;

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);
}
default:
break;
}

returnCode = true;
auto const banner = reinterpret_cast<const DVDBanner*>(m_pBannerFile);

for (u32 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));
}
break;
default:
break;
}

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 (u32 i = 0; i != desc_count; ++i)
{
auto& data = banner->comment[i].comment;
descriptions.push_back(GetDecodedString(data));
}

return descriptions;
}


Expand Down Expand Up @@ -223,13 +202,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
36 changes: 22 additions & 14 deletions Source/Core/DiscIO/Src/BannerLoaderGC.h
Expand Up @@ -19,22 +19,25 @@
#define _BANNER_LOADER_GC_H_

#include "BannerLoader.h"
#include "VolumeGC.h"
#include "StringUtil.h"

namespace DiscIO
{
class CBannerLoaderGC
: public IBannerLoader
{
public:
CBannerLoaderGC(DiscIO::IFileSystem& _rFileSystem);
CBannerLoaderGC(DiscIO::IFileSystem& _rFileSystem, DiscIO::IVolume* volume);
virtual ~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
Expand All @@ -60,30 +63,35 @@ class CBannerLoaderGC
char comment[128]; // Game description shown in IPL game start screen in two lines.
};

// "opening.bnr" file format for JP/US console
// "opening.bnr" file format for EU console
struct DVDBanner
{
u32 id; // 'BNR1'
u32 id; // 'BNR2'
u32 padding[7];
u16 image[DVD_BANNER_WIDTH * DVD_BANNER_HEIGHT]; // RGB5A3 96x32 texture image
DVDBannerComment comment;
DVDBannerComment comment[6]; // Comments in six languages (only 1 for BNR1 type)
};

// "opening.bnr" file format for EU console
struct DVDBanner2
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])
{
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
};
auto const string_decoder = CVolumeGC::GetStringDecoder(m_country);

// strnlen to trim NULLs
return string_decoder(std::string(data, strnlen(data, sizeof(data))));
}

u8* m_pBannerFile;
bool m_IsValid;
BANNER_TYPE m_BNRType;

void decode5A3image(u32* dst, u16* src, int width, int height);
BANNER_TYPE getBannerType();

DiscIO::IVolume::ECountry const m_country;
};

} // namespace
Expand Down
76 changes: 26 additions & 50 deletions Source/Core/DiscIO/Src/BannerLoaderWii.cpp
Expand Up @@ -16,6 +16,7 @@
// http://code.google.com/p/dolphin-emu/

#include <stdio.h>
#include <algorithm>

#include "Common.h"
#include "ColorUtil.h"
Expand Down Expand Up @@ -144,73 +145,48 @@ bool CBannerLoaderWii::GetBanner(u32* _pBannerImage)
return true;
}

bool CBannerLoaderWii::GetStringFromComments(const CommentIndex index, std::string& s)
{
bool ret = false;

if (IsValid())
{
// find Banner type
SWiiBanner *pBanner = (SWiiBanner*)m_pBannerFile;

// Ensure the string is null-terminating, since the banner format
// doesn't require it
u16 *src = new u16[COMMENT_SIZE + 1];
memcpy(src, &pBanner->m_Comment[index], COMMENT_SIZE * sizeof(u16));
src[COMMENT_SIZE] = 0;

ret = CopyBeUnicodeToString(s, src, COMMENT_SIZE + 1);

delete [] src;
}

return ret;
}

bool CBannerLoaderWii::GetStringFromComments(const CommentIndex index, std::wstring& s)
bool CBannerLoaderWii::GetStringFromComments(const CommentIndex index, std::string& result)
{
if (IsValid())
{
// find Banner type
SWiiBanner* pBanner = (SWiiBanner*)m_pBannerFile;

std::wstring description;
for (int i = 0; i < COMMENT_SIZE; ++i)
description.push_back(Common::swap16(pBanner->m_Comment[index][i]));

s = description;
auto const banner = reinterpret_cast<const SWiiBanner*>(m_pBannerFile);
auto const src_ptr = banner->m_Comment[index];

// Trim at first NULL
auto const length = std::find(src_ptr, src_ptr + COMMENT_SIZE, 0x0) - src_ptr;

std::wstring src;
src.resize(length);
std::transform(src_ptr, src_ptr + src.size(), src.begin(), (u16(&)(u16))Common::swap16);
result = UTF16ToUTF8(src);

return true;
}

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)
{
_rCompany = "N/A";
return true;
}

bool CBannerLoaderWii::GetDescription(std::string* _rDescription)
std::string CBannerLoaderWii::GetCompany()
{
return GetStringFromComments(DESC_IDX, *_rDescription);
return "";
}

bool CBannerLoaderWii::GetDescription(std::wstring& _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)
Expand Down
13 changes: 3 additions & 10 deletions Source/Core/DiscIO/Src/BannerLoaderWii.h
Expand Up @@ -35,15 +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);

bool GetDescription(std::wstring& _rDescription);
virtual std::vector<std::string> GetNames();
virtual std::string GetCompany();
virtual std::vector<std::string> GetDescriptions();

private:

Expand Down Expand Up @@ -81,7 +75,6 @@ class CBannerLoaderWii
void decode5A3image(u32* dst, u16* src, int width, int height);

bool GetStringFromComments(const CommentIndex index, std::string& s);
bool GetStringFromComments(const CommentIndex index, std::wstring& s);
};
} // namespace

Expand Down
8 changes: 3 additions & 5 deletions Source/Core/DiscIO/Src/DriveBlob.cpp
Expand Up @@ -16,19 +16,17 @@
// http://code.google.com/p/dolphin-emu/

#include "DriveBlob.h"
#include "StringUtil.h"

namespace DiscIO
{

DriveReader::DriveReader(const char *drive)
{
#ifdef _WIN32
char path[MAX_PATH];
strncpy(path, drive, 3);
path[2] = 0;
sprintf(path, "\\\\.\\%s", drive);
SectorReader::SetSectorSize(2048);
hDisc = CreateFile(path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
auto const path = UTF8ToTStr(std::string("\\\\.\\") + drive);
hDisc = CreateFile(path.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS, NULL);
if (hDisc != INVALID_HANDLE_VALUE)
{
Expand Down
32 changes: 19 additions & 13 deletions Source/Core/DiscIO/Src/FileSystemGCWii.cpp
Expand Up @@ -20,17 +20,18 @@

#include <string>
#include <vector>
#include <algorithm>

#include "FileSystemGCWii.h"
#include "StringUtil.h"

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();
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -311,28 +319,26 @@ 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);
}
else
{
// 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++;
}
Expand Down
6 changes: 3 additions & 3 deletions Source/Core/DiscIO/Src/FileSystemGCWii.h
Expand Up @@ -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);
Expand All @@ -44,11 +44,11 @@ class CFileSystemGCWii : public IFileSystem
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();
Expand Down
6 changes: 4 additions & 2 deletions Source/Core/DiscIO/Src/Volume.h
Expand Up @@ -22,6 +22,7 @@
#include <vector>

#include "Common.h"
#include "StringUtil.h"

namespace DiscIO
{
Expand All @@ -37,8 +38,9 @@ class IVolume
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; }
// TODO: eliminate?
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; }
Expand Down
10 changes: 9 additions & 1 deletion Source/Core/DiscIO/Src/VolumeCommon.cpp
Expand Up @@ -111,5 +111,13 @@ u8 GetSysMenuRegion(u16 _TitleVersion)
}
}

};
std::string IVolume::GetName() const
{
auto names = GetNames();
if (names.empty())
return "";
else
return names[0];
}

}
5 changes: 2 additions & 3 deletions Source/Core/DiscIO/Src/VolumeDirectory.cpp
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DiscIO/Src/VolumeDirectory.h
Expand Up @@ -50,7 +50,7 @@ class CVolumeDirectory : public IVolume

std::string GetMakerID() const;

std::string GetName() const;
std::vector<std::string> GetNames() const;
void SetName(std::string);

u32 GetFSTSize() const;
Expand Down
21 changes: 14 additions & 7 deletions Source/Core/DiscIO/Src/VolumeGC.cpp
Expand Up @@ -91,16 +91,17 @@ 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;

auto const string_decoder = GetStringDecoder(GetCountry());

char name[128];
if (!Read(0x20, 0x60, (u8*)&name))
return "";
char name[0x60 + 1] = {};
if (m_pReader != NULL && Read(0x20, 0x60, (u8*)name))
names.push_back(string_decoder(name));

return name;
return names;
}

u32 CVolumeGC::GetFSTSize() const
Expand Down Expand Up @@ -144,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
6 changes: 5 additions & 1 deletion Source/Core/DiscIO/Src/VolumeGC.h
Expand Up @@ -34,12 +34,16 @@ class CVolumeGC : public IVolume
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;
u64 GetSize() const;
bool IsDiscTwo() const;

typedef std::string(*StringDecoder)(const std::string&);

static StringDecoder GetStringDecoder(ECountry country);

private:
IBlobReader* m_pReader;
Expand Down
81 changes: 23 additions & 58 deletions Source/Core/DiscIO/Src/VolumeWad.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -107,78 +108,42 @@ 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;

u32 footer_size;
if (!Read(0x1C, 4, (u8*)&footer_size))
{
return false;
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))
{
_rwNames.push_back(L"");
continue;
names.push_back("");
}
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);
}

_rwNames.push_back(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(' ');
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));
}
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
Expand Down
3 changes: 1 addition & 2 deletions Source/Core/DiscIO/Src/VolumeWad.h
Expand Up @@ -38,8 +38,7 @@ class CVolumeWAD : public IVolume
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;
Expand Down
21 changes: 9 additions & 12 deletions Source/Core/DiscIO/Src/VolumeWiiCrypted.cpp
Expand Up @@ -16,6 +16,7 @@
// http://code.google.com/p/dolphin-emu/

#include "VolumeWiiCrypted.h"
#include "VolumeGC.h"
#include "StringUtil.h"
#include "Crypto/sha1.h"

Expand Down Expand Up @@ -168,21 +169,17 @@ std::string CVolumeWiiCrypted::GetMakerID() const
return makerID;
}

std::string CVolumeWiiCrypted::GetName() const
std::vector<std::string> CVolumeWiiCrypted::GetNames() const
{
if (m_pReader == NULL)
{
return std::string();
}

char name[0xFF];
std::vector<std::string> names;

auto const string_decoder = CVolumeGC::GetStringDecoder(GetCountry());

if (!Read(0x20, 0x60, (u8*)&name))
{
return std::string();
}
char name[0xFF] = {};
if (m_pReader != NULL && Read(0x20, 0x60, (u8*)&name))
names.push_back(string_decoder(name));

return name;
return names;
}

u32 CVolumeWiiCrypted::GetFSTSize() const
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DiscIO/Src/VolumeWiiCrypted.h
Expand Up @@ -37,7 +37,7 @@ class CVolumeWiiCrypted : public IVolume
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;
Expand Down
11 changes: 6 additions & 5 deletions Source/Core/DolphinWX/Src/ARCodeAddEdit.cpp
Expand Up @@ -17,6 +17,7 @@

#include "ARCodeAddEdit.h"
#include "ARDecrypt.h"
#include "WxUtils.h"

extern std::vector<ActionReplay::ARCode> arCodes;

Expand All @@ -38,7 +39,7 @@ CARCodeAddEdit::CARCodeAddEdit(int _selection, wxWindow* parent, wxWindowID id,
}
else
{
currentName = wxString(arCodes.at(selection).name.c_str(), *wxConvCurrent);
currentName = StrToWxStr(arCodes.at(selection).name);
tempEntries = arCodes.at(selection);
}

Expand Down Expand Up @@ -73,7 +74,7 @@ CARCodeAddEdit::CARCodeAddEdit(int _selection, wxWindow* parent, wxWindowID id,
void CARCodeAddEdit::ChangeEntry(wxSpinEvent& event)
{
ActionReplay::ARCode currentCode = arCodes.at((int)arCodes.size() - event.GetPosition());
EditCheatName->SetValue(wxString(currentCode.name.c_str(), *wxConvCurrent));
EditCheatName->SetValue(StrToWxStr(currentCode.name));
UpdateTextCtrl(currentCode);
}

Expand All @@ -84,7 +85,7 @@ void CARCodeAddEdit::SaveCheatData(wxCommandEvent& WXUNUSED (event))

// Split the entered cheat into lines.
std::vector<std::string> userInputLines;
SplitString(std::string(EditCheatCode->GetValue().mb_str()), '\n', userInputLines);
SplitString(WxStrToStr(EditCheatCode->GetValue()), '\n', userInputLines);

for (size_t i = 0; i < userInputLines.size(); i++)
{
Expand Down Expand Up @@ -148,7 +149,7 @@ void CARCodeAddEdit::SaveCheatData(wxCommandEvent& WXUNUSED (event))
// Add a new AR cheat code.
ActionReplay::ARCode newCheat;

newCheat.name = std::string(EditCheatName->GetValue().mb_str());
newCheat.name = WxStrToStr(EditCheatName->GetValue());
newCheat.ops = decryptedLines;
newCheat.active = true;

Expand All @@ -157,7 +158,7 @@ void CARCodeAddEdit::SaveCheatData(wxCommandEvent& WXUNUSED (event))
else
{
// Update the currently-selected AR cheat code.
arCodes.at(selection).name = std::string(EditCheatName->GetValue().mb_str());
arCodes.at(selection).name = WxStrToStr(EditCheatName->GetValue());
arCodes.at(selection).ops = decryptedLines;
}

Expand Down
3 changes: 2 additions & 1 deletion Source/Core/DolphinWX/Src/AboutDolphin.cpp
Expand Up @@ -17,6 +17,7 @@

#include "Common.h"
#include "AboutDolphin.h"
#include "WxUtils.h"
#include "../resources/dolphin_logo.cpp"
#include "scmrev.h"

Expand Down Expand Up @@ -62,7 +63,7 @@ AboutDolphin::AboutDolphin(wxWindow *parent, wxWindowID id,
"and should not be used to play games you do\n"
"not legally own.";
wxStaticText* const Message = new wxStaticText(this, wxID_ANY,
wxString::FromAscii(Text.c_str()));
StrToWxStr(Text));
Message->Wrap(GetSize().GetWidth());

wxBoxSizer* const sInfo = new wxBoxSizer(wxVERTICAL);
Expand Down
13 changes: 7 additions & 6 deletions Source/Core/DolphinWX/Src/CheatsWindow.cpp
Expand Up @@ -24,6 +24,7 @@
#include "ISOProperties.h"
#include "HW/Memmap.h"
#include "Frame.h"
#include "WxUtils.h"

#define MAX_CHEAT_SEARCH_RESULTS_DISPLAY 256

Expand Down Expand Up @@ -273,7 +274,7 @@ void wxCheatsWindow::Load_ARCodes()
{
ARCode code = GetARCode(i);
ARCodeIndex ind;
u32 index = m_CheckListBox_CheatsList->Append(wxString(code.name.c_str(), *wxConvCurrent));
u32 index = m_CheckListBox_CheatsList->Append(StrToWxStr(code.name));
m_CheckListBox_CheatsList->Check(index, code.active);
ind.index = i;
ind.uiIndex = index;
Expand All @@ -291,18 +292,18 @@ void wxCheatsWindow::OnEvent_CheatsList_ItemSelected(wxCommandEvent& WXUNUSED (e
if ((int)indexList[i].uiIndex == index)
{
ARCode code = GetARCode(i);
m_Label_Codename->SetLabel(_("Name: ") + wxString(code.name.c_str(), *wxConvCurrent));
m_Label_Codename->SetLabel(_("Name: ") + StrToWxStr(code.name));
char text[CHAR_MAX];
char* numcodes = text;
sprintf(numcodes, "Number of Codes: %lu", (unsigned long)code.ops.size());
m_Label_NumCodes->SetLabel(wxString::FromAscii(numcodes));
m_Label_NumCodes->SetLabel(StrToWxStr(numcodes));
m_ListBox_CodesList->Clear();
for (size_t j = 0; j < code.ops.size(); j++)
{
char text2[CHAR_MAX];
char* ops = text2;
sprintf(ops, "%08x %08x", code.ops[j].cmd_addr, code.ops[j].value);
m_ListBox_CodesList->Append(wxString::FromAscii(ops));
m_ListBox_CodesList->Append(StrToWxStr(ops));
}
}
}
Expand Down Expand Up @@ -347,7 +348,7 @@ void wxCheatsWindow::OnEvent_ButtonUpdateLog_Press(wxCommandEvent& WXUNUSED (eve
const std::vector<std::string> &arLog = ActionReplay::GetSelfLog();
for (u32 i = 0; i < arLog.size(); i++)
{
m_TextCtrl_Log->AppendText(wxString::FromAscii(arLog[i].c_str()));
m_TextCtrl_Log->AppendText(StrToWxStr(arLog[i]));
}
}

Expand Down Expand Up @@ -619,7 +620,7 @@ void CreateCodeDialog::PressOK(wxCommandEvent& ev)
// create the new code
ActionReplay::ARCode new_cheat;
new_cheat.active = false;
new_cheat.name = std::string(code_name.ToAscii());
new_cheat.name = WxStrToStr(code_name);
const ActionReplay::AREntry new_entry(code_address, code_value);
new_cheat.ops.push_back(new_entry);

Expand Down
43 changes: 22 additions & 21 deletions Source/Core/DolphinWX/Src/ConfigMain.cpp
Expand Up @@ -33,6 +33,7 @@
#include "IPC_HLE/WII_IPC_HLE.h"
#include "NANDContentLoader.h"

#include "WxUtils.h"
#include "Globals.h" // Local
#include "ConfigMain.h"
#include "ConfigManager.h"
Expand Down Expand Up @@ -100,7 +101,6 @@ static const wxLanguage langIds[] =
#define EXIDEV_AM_BB_STR _trans("AM-Baseboard")
#define EXIDEV_GECKO_STR "USBGecko"

#define CSTR_TRANS(a) wxString(wxGetTranslation(wxT(a))).mb_str()
#define WXSTR_TRANS(a) wxString(wxGetTranslation(wxT(a)))
#ifdef WIN32
//only used with xgettext to be picked up as translatable string.
Expand Down Expand Up @@ -188,7 +188,7 @@ CConfigMain::CConfigMain(wxWindow* parent, wxWindowID id, const wxString& title,
// Update selected ISO paths
for(u32 i = 0; i < SConfig::GetInstance().m_ISOFolder.size(); i++)
{
ISOPaths->Append(wxString(SConfig::GetInstance().m_ISOFolder[i].c_str(), *wxConvCurrent));
ISOPaths->Append(StrToWxStr(SConfig::GetInstance().m_ISOFolder[i]));
}
}

Expand Down Expand Up @@ -477,10 +477,10 @@ void CConfigMain::InitializeGUIValues()

// Paths
RecursiveISOPath->SetValue(SConfig::GetInstance().m_RecursiveISOFolder);
DefaultISO->SetPath(wxString(startup_params.m_strDefaultGCM.c_str(), *wxConvCurrent));
DVDRoot->SetPath(wxString(startup_params.m_strDVDRoot.c_str(), *wxConvCurrent));
ApploaderPath->SetPath(wxString(startup_params.m_strApploader.c_str(), *wxConvCurrent));
NANDRoot->SetPath(wxString(SConfig::GetInstance().m_NANDPath.c_str(), *wxConvCurrent));
DefaultISO->SetPath(StrToWxStr(startup_params.m_strDefaultGCM));
DVDRoot->SetPath(StrToWxStr(startup_params.m_strDVDRoot));
ApploaderPath->SetPath(StrToWxStr(startup_params.m_strApploader));
NANDRoot->SetPath(StrToWxStr(SConfig::GetInstance().m_NANDPath));
}

void CConfigMain::InitializeGUITooltips()
Expand Down Expand Up @@ -958,10 +958,10 @@ void CConfigMain::AudioSettingsChanged(wxCommandEvent& event)
break;

case ID_BACKEND:
VolumeSlider->Enable(SupportsVolumeChanges(std::string(BackendSelection->GetStringSelection().mb_str())));
Latency->Enable(std::string(BackendSelection->GetStringSelection().mb_str()) == BACKEND_OPENAL);
DPL2Decoder->Enable(std::string(BackendSelection->GetStringSelection().mb_str()) == BACKEND_OPENAL);
SConfig::GetInstance().sBackend = BackendSelection->GetStringSelection().mb_str();
VolumeSlider->Enable(SupportsVolumeChanges(WxStrToStr(BackendSelection->GetStringSelection())));
Latency->Enable(WxStrToStr(BackendSelection->GetStringSelection()) == BACKEND_OPENAL);
DPL2Decoder->Enable(WxStrToStr(BackendSelection->GetStringSelection()) == BACKEND_OPENAL);
SConfig::GetInstance().sBackend = WxStrToStr(BackendSelection->GetStringSelection());
AudioCommon::UpdateSoundStream();
break;

Expand All @@ -982,9 +982,9 @@ void CConfigMain::AddAudioBackends()
for (std::vector<std::string>::const_iterator iter = backends.begin();
iter != backends.end(); ++iter)
{
BackendSelection->Append(wxString::FromAscii((*iter).c_str()));
BackendSelection->Append(StrToWxStr(*iter));
int num = BackendSelection->\
FindString(wxString::FromAscii(SConfig::GetInstance().sBackend.c_str()));
FindString(StrToWxStr(SConfig::GetInstance().sBackend));
BackendSelection->SetSelection(num);
}
}
Expand Down Expand Up @@ -1046,12 +1046,12 @@ void CConfigMain::GCSettingsChanged(wxCommandEvent& event)

void CConfigMain::ChooseMemcardPath(std::string& strMemcard, bool isSlotA)
{
std::string filename = std::string(wxFileSelector(
std::string filename = WxStrToStr(wxFileSelector(
_("Choose a file to open"),
wxString::FromUTF8(File::GetUserPath(D_GCUSER_IDX).c_str()),
StrToWxStr(File::GetUserPath(D_GCUSER_IDX)),
isSlotA ? wxT(GC_MEMCARDA) : wxT(GC_MEMCARDB),
wxEmptyString,
_("Gamecube Memory Cards (*.raw,*.gcp)") + wxString(wxT("|*.raw;*.gcp"))).mb_str());
_("Gamecube Memory Cards (*.raw,*.gcp)") + wxString(wxT("|*.raw;*.gcp"))));

if (!filename.empty())
{
Expand Down Expand Up @@ -1242,7 +1242,7 @@ void CConfigMain::AddRemoveISOPaths(wxCommandEvent& event)
SConfig::GetInstance().m_ISOFolder.clear();

for (unsigned int i = 0; i < ISOPaths->GetCount(); i++)
SConfig::GetInstance().m_ISOFolder.push_back(std::string(ISOPaths->GetStrings()[i].mb_str()));
SConfig::GetInstance().m_ISOFolder.push_back(WxStrToStr(ISOPaths->GetStrings()[i]));
}

void CConfigMain::RecursiveDirectoryChanged(wxCommandEvent& WXUNUSED (event))
Expand All @@ -1253,24 +1253,25 @@ void CConfigMain::RecursiveDirectoryChanged(wxCommandEvent& WXUNUSED (event))

void CConfigMain::DefaultISOChanged(wxFileDirPickerEvent& WXUNUSED (event))
{
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strDefaultGCM = DefaultISO->GetPath().mb_str();
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strDefaultGCM = WxStrToStr(DefaultISO->GetPath());
}

void CConfigMain::DVDRootChanged(wxFileDirPickerEvent& WXUNUSED (event))
{
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strDVDRoot = DVDRoot->GetPath().mb_str();
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strDVDRoot = WxStrToStr(DVDRoot->GetPath());
}

void CConfigMain::ApploaderPathChanged(wxFileDirPickerEvent& WXUNUSED (event))
{
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strApploader = ApploaderPath->GetPath().mb_str();
SConfig::GetInstance().m_LocalCoreStartupParameter.m_strApploader = WxStrToStr(ApploaderPath->GetPath());
}

void CConfigMain::NANDRootChanged(wxFileDirPickerEvent& WXUNUSED (event))
{
std::string NANDPath =
SConfig::GetInstance().m_NANDPath = File::GetUserPath(D_WIIROOT_IDX, std::string(NANDRoot->GetPath().mb_str()));
NANDRoot->SetPath(wxString(NANDPath.c_str(), *wxConvCurrent));
SConfig::GetInstance().m_NANDPath =
File::GetUserPath(D_WIIROOT_IDX, WxStrToStr(NANDRoot->GetPath()));
NANDRoot->SetPath(StrToWxStr(NANDPath));
SConfig::GetInstance().m_SYSCONF->UpdateLocation();
DiscIO::cUIDsys::AccessInstance().UpdateLocation();
DiscIO::CSharedContent::AccessInstance().UpdateLocation();
Expand Down
5 changes: 3 additions & 2 deletions Source/Core/DolphinWX/Src/Debugger/BreakpointDlg.cpp
Expand Up @@ -19,6 +19,7 @@
#include "StringUtil.h"
#include "PowerPC/PowerPC.h"
#include "BreakpointWindow.h"
#include "../WxUtils.h"

BEGIN_EVENT_TABLE(BreakPointDlg, wxDialog)
EVT_BUTTON(wxID_OK, BreakPointDlg::OnOK)
Expand All @@ -42,14 +43,14 @@ void BreakPointDlg::OnOK(wxCommandEvent& event)
{
wxString AddressString = m_pEditAddress->GetLineText(0);
u32 Address = 0;
if (AsciiToHex(AddressString.mb_str(), Address))
if (AsciiToHex(WxStrToStr(AddressString).c_str(), Address))
{
PowerPC::breakpoints.Add(Address);
Parent->NotifyUpdate();
Close();
}
else
PanicAlert("The address %s is invalid.", (const char *)AddressString.ToUTF8());
PanicAlert("The address %s is invalid.", WxStrToStr(AddressString).c_str());

event.Skip();
}
19 changes: 10 additions & 9 deletions Source/Core/DolphinWX/Src/Debugger/BreakpointView.cpp
Expand Up @@ -23,6 +23,7 @@
#include "PowerPC/PPCSymbolDB.h"
#include "PowerPC/PowerPC.h"
#include "HW/Memmap.h"
#include "../WxUtils.h"

CBreakPointView::CBreakPointView(wxWindow* parent, const wxWindowID id)
: wxListCtrl(parent, id, wxDefaultPosition, wxDefaultSize,
Expand Down Expand Up @@ -50,20 +51,20 @@ void CBreakPointView::Update()
if (!rBP.bTemporary)
{
wxString temp;
temp = wxString::FromAscii(rBP.bOn ? "on" : " ");
temp = StrToWxStr(rBP.bOn ? "on" : " ");
int Item = InsertItem(0, temp);
temp = wxString::FromAscii("BP");
temp = StrToWxStr("BP");
SetItem(Item, 1, temp);

Symbol *symbol = g_symbolDB.GetSymbolFromAddr(rBP.iAddress);
if (symbol)
{
temp = wxString::FromAscii(g_symbolDB.GetDescription(rBP.iAddress));
temp = StrToWxStr(g_symbolDB.GetDescription(rBP.iAddress));
SetItem(Item, 2, temp);
}

sprintf(szBuffer, "%08x", rBP.iAddress);
temp = wxString::FromAscii(szBuffer);
temp = StrToWxStr(szBuffer);
SetItem(Item, 3, temp);

SetItemData(Item, rBP.iAddress);
Expand All @@ -76,27 +77,27 @@ void CBreakPointView::Update()
const TMemCheck& rMemCheck = rMemChecks[i];

wxString temp;
temp = wxString::FromAscii((rMemCheck.Break || rMemCheck.Log) ? "on" : " ");
temp = StrToWxStr((rMemCheck.Break || rMemCheck.Log) ? "on" : " ");
int Item = InsertItem(0, temp);
temp = wxString::FromAscii("MC");
temp = StrToWxStr("MC");
SetItem(Item, 1, temp);

Symbol *symbol = g_symbolDB.GetSymbolFromAddr(rMemCheck.StartAddress);
if (symbol)
{
temp = wxString::FromAscii(g_symbolDB.GetDescription(rMemCheck.StartAddress));
temp = StrToWxStr(g_symbolDB.GetDescription(rMemCheck.StartAddress));
SetItem(Item, 2, temp);
}

sprintf(szBuffer, "%08x to %08x", rMemCheck.StartAddress, rMemCheck.EndAddress);
temp = wxString::FromAscii(szBuffer);
temp = StrToWxStr(szBuffer);
SetItem(Item, 3, temp);

size_t c = 0;
if (rMemCheck.OnRead) szBuffer[c++] = 'r';
if (rMemCheck.OnWrite) szBuffer[c++] = 'w';
szBuffer[c] = 0x00;
temp = wxString::FromAscii(szBuffer);
temp = StrToWxStr(szBuffer);
SetItem(Item, 4, temp);

SetItemData(Item, rMemCheck.StartAddress);
Expand Down
39 changes: 20 additions & 19 deletions Source/Core/DolphinWX/Src/Debugger/CodeView.cpp
Expand Up @@ -23,6 +23,7 @@
#include "Host.h"
#include "CodeView.h"
#include "SymbolDB.h"
#include "../WxUtils.h"

#include <wx/event.h>
#include <wx/clipbrd.h>
Expand Down Expand Up @@ -223,15 +224,15 @@ void CCodeView::OnPopupMenu(wxCommandEvent& event)
{
char disasm[256];
debugger->disasm(selection, disasm, 256);
wxTheClipboard->SetData(new wxTextDataObject(wxString::FromAscii(disasm)));
wxTheClipboard->SetData(new wxTextDataObject(StrToWxStr(disasm)));
}
break;

case IDM_COPYHEX:
{
char temp[24];
sprintf(temp, "%08x", debugger->readInstruction(selection));
wxTheClipboard->SetData(new wxTextDataObject(wxString::FromAscii(temp)));
wxTheClipboard->SetData(new wxTextDataObject(StrToWxStr(temp)));
}
break;

Expand All @@ -252,7 +253,7 @@ void CCodeView::OnPopupMenu(wxCommandEvent& event)
debugger->disasm(addr, disasm, 256);
text = text + StringFromFormat("%08x: ", addr) + disasm + "\r\n";
}
wxTheClipboard->SetData(new wxTextDataObject(wxString::FromAscii(text.c_str())));
wxTheClipboard->SetData(new wxTextDataObject(StrToWxStr(text)));
}
}
break;
Expand Down Expand Up @@ -297,12 +298,12 @@ void CCodeView::OnPopupMenu(wxCommandEvent& event)
Symbol *symbol = symbol_db->GetSymbolFromAddr(selection);
if (symbol)
{
wxTextEntryDialog input_symbol(this, wxString::FromAscii("Rename symbol:"),
wxTextEntryDialog input_symbol(this, StrToWxStr("Rename symbol:"),
wxGetTextFromUserPromptStr,
wxString::FromAscii(symbol->name.c_str()));
StrToWxStr(symbol->name));
if (input_symbol.ShowModal() == wxID_OK)
{
symbol->name = input_symbol.GetValue().mb_str();
symbol->name = WxStrToStr(input_symbol.GetValue());
Refresh(); // Redraw to show the renamed symbol
}
Host_NotifyMapLoaded();
Expand All @@ -327,23 +328,23 @@ void CCodeView::OnMouseUpR(wxMouseEvent& event)
wxMenu* menu = new wxMenu;
//menu->Append(IDM_GOTOINMEMVIEW, "&Goto in mem view");
menu->Append(IDM_FOLLOWBRANCH,
wxString::FromAscii("&Follow branch"))->Enable(AddrToBranch(selection) ? true : false);
StrToWxStr("&Follow branch"))->Enable(AddrToBranch(selection) ? true : false);
menu->AppendSeparator();
#if wxUSE_CLIPBOARD
menu->Append(IDM_COPYADDRESS, wxString::FromAscii("Copy &address"));
menu->Append(IDM_COPYFUNCTION, wxString::FromAscii("Copy &function"))->Enable(isSymbol);
menu->Append(IDM_COPYCODE, wxString::FromAscii("Copy &code line"));
menu->Append(IDM_COPYHEX, wxString::FromAscii("Copy &hex"));
menu->Append(IDM_COPYADDRESS, StrToWxStr("Copy &address"));
menu->Append(IDM_COPYFUNCTION, StrToWxStr("Copy &function"))->Enable(isSymbol);
menu->Append(IDM_COPYCODE, StrToWxStr("Copy &code line"));
menu->Append(IDM_COPYHEX, StrToWxStr("Copy &hex"));
menu->AppendSeparator();
#endif
menu->Append(IDM_RENAMESYMBOL, wxString::FromAscii("Rename &symbol"))->Enable(isSymbol);
menu->Append(IDM_RENAMESYMBOL, StrToWxStr("Rename &symbol"))->Enable(isSymbol);
menu->AppendSeparator();
menu->Append(IDM_RUNTOHERE, _("&Run To Here"));
menu->Append(IDM_ADDFUNCTION, _("&Add function"));
menu->Append(IDM_JITRESULTS, wxString::FromAscii("PPC vs X86"));
menu->Append(IDM_INSERTBLR, wxString::FromAscii("Insert &blr"));
menu->Append(IDM_INSERTNOP, wxString::FromAscii("Insert &nop"));
menu->Append(IDM_PATCHALERT, wxString::FromAscii("Patch alert"));
menu->Append(IDM_JITRESULTS, StrToWxStr("PPC vs X86"));
menu->Append(IDM_INSERTBLR, StrToWxStr("Insert &blr"));
menu->Append(IDM_INSERTNOP, StrToWxStr("Insert &nop"));
menu->Append(IDM_PATCHALERT, StrToWxStr("Patch alert"));
PopupMenu(menu);
event.Skip(true);
}
Expand Down Expand Up @@ -489,7 +490,7 @@ void CCodeView::OnPaint(wxPaintEvent& event)
dc.SetTextForeground(_T("#000000"));
}

dc.DrawText(wxString::FromAscii(dis2), 17 + 17*charWidth, rowY1);
dc.DrawText(StrToWxStr(dis2), 17 + 17*charWidth, rowY1);
// ------------
}

Expand All @@ -499,7 +500,7 @@ void CCodeView::OnPaint(wxPaintEvent& event)
else
dc.SetTextForeground(_T("#8000FF")); // purple

dc.DrawText(wxString::FromAscii(dis), 17 + (plain ? 1*charWidth : 9*charWidth), rowY1);
dc.DrawText(StrToWxStr(dis), 17 + (plain ? 1*charWidth : 9*charWidth), rowY1);

if (desc[0] == 0)
{
Expand All @@ -513,7 +514,7 @@ void CCodeView::OnPaint(wxPaintEvent& event)
//UnDecorateSymbolName(desc,temp,255,UNDNAME_COMPLETE);
if (strlen(desc))
{
dc.DrawText(wxString::FromAscii(desc), 17 + 35 * charWidth, rowY1);
dc.DrawText(StrToWxStr(desc), 17 + 35 * charWidth, rowY1);
}
}

Expand Down
21 changes: 11 additions & 10 deletions Source/Core/DolphinWX/Src/Debugger/CodeWindow.cpp
Expand Up @@ -30,6 +30,7 @@
#include "CodeWindow.h"
#include "CodeView.h"

#include "../WxUtils.h"
#include "FileUtil.h"
#include "Core.h"
#include "HW/Memmap.h"
Expand Down Expand Up @@ -210,7 +211,7 @@ void CCodeWindow::OnAddrBoxChange(wxCommandEvent& event)
wxTextCtrl* pAddrCtrl = (wxTextCtrl*)GetToolBar()->FindControl(IDM_ADDRBOX);
wxString txt = pAddrCtrl->GetValue();

std::string text(txt.mb_str());
std::string text(WxStrToStr(txt));
text = StripSpaces(text);
if (text.size() == 8)
{
Expand Down Expand Up @@ -312,7 +313,7 @@ void CCodeWindow::UpdateLists()
Symbol *caller_symbol = g_symbolDB.GetSymbolFromAddr(caller_addr);
if (caller_symbol)
{
int idx = callers->Append(wxString::FromAscii(StringFromFormat
int idx = callers->Append(StrToWxStr(StringFromFormat
("< %s (%08x)", caller_symbol->name.c_str(), caller_addr).c_str()));
callers->SetClientData(idx, (void*)(u64)caller_addr);
}
Expand All @@ -325,7 +326,7 @@ void CCodeWindow::UpdateLists()
Symbol *call_symbol = g_symbolDB.GetSymbolFromAddr(call_addr);
if (call_symbol)
{
int idx = calls->Append(wxString::FromAscii(StringFromFormat
int idx = calls->Append(StrToWxStr(StringFromFormat
("> %s (%08x)", call_symbol->name.c_str(), call_addr).c_str()));
calls->SetClientData(idx, (void*)(u64)call_addr);
}
Expand All @@ -344,12 +345,12 @@ void CCodeWindow::UpdateCallstack()

for (size_t i = 0; i < stack.size(); i++)
{
int idx = callstack->Append(wxString::FromAscii(stack[i].Name.c_str()));
int idx = callstack->Append(StrToWxStr(stack[i].Name));
callstack->SetClientData(idx, (void*)(u64)stack[i].vAddress);
}

if (!ret)
callstack->Append(wxString::FromAscii("invalid callstack"));
callstack->Append(StrToWxStr("invalid callstack"));
}

// Create CPU Mode menus
Expand All @@ -360,7 +361,7 @@ void CCodeWindow::CreateMenu(const SCoreStartupParameter& _LocalCoreStartupParam
wxMenu* pCoreMenu = new wxMenu;

wxMenuItem* interpreter = pCoreMenu->Append(IDM_INTERPRETER, _("&Interpreter core"),
wxString::FromAscii("This is necessary to get break points"
StrToWxStr("This is necessary to get break points"
" and stepping to work as explained in the Developer Documentation. But it can be very"
" slow, perhaps slower than 1 fps."),
wxITEM_CHECK);
Expand Down Expand Up @@ -428,7 +429,7 @@ void CCodeWindow::CreateMenuOptions(wxMenu* pMenu)
boottopause->Check(bBootToPause);

wxMenuItem* automaticstart = pMenu->Append(IDM_AUTOMATICSTART, _("&Automatic start"),
wxString::FromAscii(
StrToWxStr(
"Automatically load the Default ISO when Dolphin starts, or the last game you loaded,"
" if you have not given it an elf file with the --elf command line. [This can be"
" convenient if you are bug-testing with a certain game and want to rebuild"
Expand Down Expand Up @@ -515,10 +516,10 @@ void CCodeWindow::OnJitMenu(wxCommandEvent& event)
for (u32 addr = 0x80000000; addr < 0x80100000; addr += 4)
{
const char *name = PPCTables::GetInstructionName(Memory::ReadUnchecked_U32(addr));
if (name && !strcmp((const char *)str.mb_str(), name))
auto const wx_name = WxStrToStr(str);
if (name && (wx_name == name))
{
std::string mb_str(str.mb_str());
NOTICE_LOG(POWERPC, "Found %s at %08x", mb_str.c_str(), addr);
NOTICE_LOG(POWERPC, "Found %s at %08x", wx_name.c_str(), addr);
}
}
break;
Expand Down
23 changes: 12 additions & 11 deletions Source/Core/DolphinWX/Src/Debugger/CodeWindowFunctions.cpp
Expand Up @@ -25,6 +25,7 @@

#include "DebuggerUIUtil.h"

#include "../WxUtils.h"
#include "RegisterWindow.h"
#include "BreakpointWindow.h"
#include "MemoryWindow.h"
Expand Down Expand Up @@ -65,7 +66,7 @@ void CCodeWindow::Load()
std::string fontDesc;
ini.Get("General", "DebuggerFont", &fontDesc);
if (!fontDesc.empty())
DebuggerFont.SetNativeFontInfoUserDesc(wxString::FromAscii(fontDesc.c_str()));
DebuggerFont.SetNativeFontInfoUserDesc(StrToWxStr(fontDesc));

// Boot to pause or not
ini.Get("General", "AutomaticStart", &bAutomaticStart, false);
Expand Down Expand Up @@ -107,7 +108,7 @@ void CCodeWindow::Save()
ini.Load(File::GetUserPath(F_DEBUGGERCONFIG_IDX));

ini.Set("General", "DebuggerFont",
std::string(DebuggerFont.GetNativeFontInfoUserDesc().mb_str()));
WxStrToStr(DebuggerFont.GetNativeFontInfoUserDesc()));

// Boot to pause or not
ini.Set("General", "AutomaticStart", GetMenuBar()->IsChecked(IDM_AUTOMATICSTART));
Expand Down Expand Up @@ -154,7 +155,7 @@ void CCodeWindow::CreateMenuSymbols(wxMenuBar *pMenuBar)
pSymbolsMenu->Append(IDM_SAVEMAPFILE, _("&Save symbol map"));
pSymbolsMenu->AppendSeparator();
pSymbolsMenu->Append(IDM_SAVEMAPFILEWITHCODES, _("Save code"),
wxString::FromAscii("Save the entire disassembled code. This may take a several seconds"
StrToWxStr("Save the entire disassembled code. This may take a several seconds"
" and may require between 50 and 100 MB of hard drive space. It will only save code"
" that are in the first 4 MB of memory, if you are debugging a game that load .rel"
" files with code to memory you may want to increase that to perhaps 8 MB, you can do"
Expand Down Expand Up @@ -208,7 +209,7 @@ void CCodeWindow::OnProfilerMenu(wxCommandEvent& event)
break;
}
wxString OpenCommand;
OpenCommand = filetype->GetOpenCommand(wxString::From8BitData(filename.c_str()));
OpenCommand = filetype->GetOpenCommand(StrToWxStr(filename));
if(!OpenCommand.IsEmpty())
wxExecute(OpenCommand, wxEXEC_SYNC);
}
Expand Down Expand Up @@ -284,7 +285,8 @@ void CCodeWindow::OnSymbolsMenu(wxCommandEvent& event)

if (!path.IsEmpty())
{
std::ifstream f(path.mb_str());
std::ifstream f;
OpenFStream(f, WxStrToStr(path), std::ios_base::in);

std::string line;
while (std::getline(f, line))
Expand Down Expand Up @@ -312,13 +314,13 @@ void CCodeWindow::OnSymbolsMenu(wxCommandEvent& event)
{
wxTextEntryDialog input_prefix(
this,
wxString::FromAscii("Only export symbols with prefix:\n(Blank for all symbols)"),
StrToWxStr("Only export symbols with prefix:\n(Blank for all symbols)"),
wxGetTextFromUserPromptStr,
wxEmptyString);

if (input_prefix.ShowModal() == wxID_OK)
{
std::string prefix(input_prefix.GetValue().mb_str());
std::string prefix(WxStrToStr(input_prefix.GetValue()));

wxString path = wxFileSelector(
_T("Save signature as"), wxEmptyString, wxEmptyString, wxEmptyString,
Expand All @@ -328,8 +330,7 @@ void CCodeWindow::OnSymbolsMenu(wxCommandEvent& event)
{
SignatureDB db;
db.Initialize(&g_symbolDB, prefix.c_str());
std::string filename(path.mb_str());
db.Save(path.mb_str());
db.Save(WxStrToStr(path).c_str());
}
}
}
Expand All @@ -343,7 +344,7 @@ void CCodeWindow::OnSymbolsMenu(wxCommandEvent& event)
if (!path.IsEmpty())
{
SignatureDB db;
db.Load(path.mb_str());
db.Load(WxStrToStr(path).c_str());
db.Apply(&g_symbolDB);
}
}
Expand All @@ -366,7 +367,7 @@ void CCodeWindow::NotifyMapLoaded()
symbols->Clear();
for (PPCSymbolDB::XFuncMap::iterator iter = g_symbolDB.GetIterator(); iter != g_symbolDB.End(); ++iter)
{
int idx = symbols->Append(wxString::FromAscii(iter->second.name.c_str()));
int idx = symbols->Append(StrToWxStr(iter->second.name));
symbols->SetClientData(idx, (void*)&iter->second);
}
symbols->Thaw();
Expand Down
6 changes: 3 additions & 3 deletions Source/Core/DolphinWX/Src/Debugger/DSPDebugWindow.cpp
Expand Up @@ -22,6 +22,7 @@

#include <wx/artprov.h>

#include "../WxUtils.h"
#include "StringUtil.h"
#include "DSPDebugWindow.h"
#include "DSPRegisterView.h"
Expand Down Expand Up @@ -220,7 +221,7 @@ void DSPDebuggerLLE::UpdateSymbolMap()
for (SymbolDB::XFuncMap::iterator iter = DSPSymbols::g_dsp_symbol_db.GetIterator();
iter != DSPSymbols::g_dsp_symbol_db.End(); ++iter)
{
int idx = m_SymbolList->Append(wxString::FromAscii(iter->second.name.c_str()));
int idx = m_SymbolList->Append(StrToWxStr(iter->second.name));
m_SymbolList->SetClientData(idx, (void*)&iter->second);
}
m_SymbolList->Thaw();
Expand Down Expand Up @@ -250,8 +251,7 @@ void DSPDebuggerLLE::OnAddrBoxChange(wxCommandEvent& event)
wxTextCtrl* pAddrCtrl = (wxTextCtrl*)m_Toolbar->FindControl(ID_ADDRBOX);
wxString txt = pAddrCtrl->GetValue();

std::string text(txt.mb_str());
text = StripSpaces(text);
auto text = StripSpaces(WxStrToStr(txt));
if (text.size())
{
u32 addr;
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/DolphinWX/Src/Debugger/DSPRegisterView.cpp
Expand Up @@ -17,15 +17,15 @@

#include "DSPDebugWindow.h"
#include "DSPRegisterView.h"

#include "../WxUtils.h"

wxString CDSPRegTable::GetValue(int row, int col)
{
if (row < 32) // 32 "normal" regs
{
switch (col)
{
case 0: return wxString::FromAscii(pdregname(row));
case 0: return StrToWxStr(pdregname(row));
case 1: return wxString::Format(wxT("0x%04x"), DSPCore_ReadRegister(row));
default: return wxEmptyString;
}
Expand Down
17 changes: 9 additions & 8 deletions Source/Core/DolphinWX/Src/Debugger/JitWindow.cpp
Expand Up @@ -37,6 +37,7 @@
#include "Core.h"
#include "StringUtil.h"
#include "LogManager.h"
#include "../WxUtils.h"

#include "../Globals.h"

Expand Down Expand Up @@ -119,9 +120,9 @@ void CJitWindow::Compare(u32 em_address)
}
// Do not merge this "if" with the above - block_num changes inside it.
if (block_num < 0) {
ppc_box->SetValue(wxString::FromAscii(StringFromFormat("(non-code address: %08x)",
em_address).c_str()));
x86_box->SetValue(wxString::FromAscii(StringFromFormat("(no translation)").c_str()));
ppc_box->SetValue(StrToWxStr(StringFromFormat("(non-code address: %08x)",
em_address)));
x86_box->SetValue(StrToWxStr(StringFromFormat("(no translation)")));
delete[] xDis;
return;
}
Expand Down Expand Up @@ -150,7 +151,7 @@ void CJitWindow::Compare(u32 em_address)
*sptr++ = 10;
num_x86_instructions++;
}
x86_box->SetValue(wxString::FromAscii((char*)xDis));
x86_box->SetValue(StrToWxStr((char*)xDis));

// == Fill in ppc box
u32 ppc_addr = block->originalAddress;
Expand Down Expand Up @@ -189,11 +190,11 @@ void CJitWindow::Compare(u32 em_address)
sptr += sprintf(sptr, "Num bytes: PPC: %i x86: %i (blowup: %i%%)\n",
size * 4, block->codeSize, 100 * (block->codeSize / (4 * size) - 1));

ppc_box->SetValue(wxString::FromAscii((char*)xDis));
ppc_box->SetValue(StrToWxStr((char*)xDis));
} else {
ppc_box->SetValue(wxString::FromAscii(StringFromFormat(
"(non-code address: %08x)", em_address).c_str()));
x86_box->SetValue(wxString::FromAscii("---"));
ppc_box->SetValue(StrToWxStr(StringFromFormat(
"(non-code address: %08x)", em_address)));
x86_box->SetValue("---");
}

delete[] xDis;
Expand Down
5 changes: 3 additions & 2 deletions Source/Core/DolphinWX/Src/Debugger/MemoryCheckDlg.cpp
Expand Up @@ -15,6 +15,7 @@
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/

#include "../WxUtils.h"
#include "MemoryCheckDlg.h"
#include "Common.h"
#include "StringUtil.h"
Expand Down Expand Up @@ -79,9 +80,9 @@ void MemoryCheckDlg::OnOK(wxCommandEvent& event)

u32 StartAddress, EndAddress;
bool EndAddressOK = EndAddressString.Len() &&
AsciiToHex(EndAddressString.mb_str(), EndAddress);
AsciiToHex(WxStrToStr(EndAddressString).c_str(), EndAddress);

if (AsciiToHex(StartAddressString.mb_str(), StartAddress) &&
if (AsciiToHex(WxStrToStr(StartAddressString).c_str(), StartAddress) &&
(OnRead || OnWrite) && (Log || Break))
{
TMemCheck MemCheck;
Expand Down
26 changes: 14 additions & 12 deletions Source/Core/DolphinWX/Src/Debugger/MemoryView.cpp
Expand Up @@ -22,6 +22,8 @@
#include "HW/Memmap.h"

#include "MemoryView.h"
#include "../WxUtils.h"

#include <wx/event.h>
#include <wx/clipbrd.h>

Expand Down Expand Up @@ -149,7 +151,7 @@ void CMemoryView::OnPopupMenu(wxCommandEvent& event)
{
char temp[24];
sprintf(temp, "%08x", debugger->readExtraMemory(memory, selection));
wxTheClipboard->SetData(new wxTextDataObject(wxString::FromAscii(temp)));
wxTheClipboard->SetData(new wxTextDataObject(StrToWxStr(temp)));
}
break;
#endif
Expand Down Expand Up @@ -186,16 +188,16 @@ void CMemoryView::OnMouseDownR(wxMouseEvent& event)
wxMenu* menu = new wxMenu;
//menu.Append(IDM_GOTOINMEMVIEW, "&Goto in mem view");
#if wxUSE_CLIPBOARD
menu->Append(IDM_COPYADDRESS, wxString::FromAscii("Copy &address"));
menu->Append(IDM_COPYHEX, wxString::FromAscii("Copy &hex"));
menu->Append(IDM_COPYADDRESS, StrToWxStr("Copy &address"));
menu->Append(IDM_COPYHEX, StrToWxStr("Copy &hex"));
#endif
menu->Append(IDM_TOGGLEMEMORY, wxString::FromAscii("Toggle &memory"));
menu->Append(IDM_TOGGLEMEMORY, StrToWxStr("Toggle &memory"));

wxMenu* viewAsSubMenu = new wxMenu;
viewAsSubMenu->Append(IDM_VIEWASFP, wxString::FromAscii("FP value"));
viewAsSubMenu->Append(IDM_VIEWASASCII, wxString::FromAscii("ASCII"));
viewAsSubMenu->Append(IDM_VIEWASHEX, wxString::FromAscii("Hex"));
menu->AppendSubMenu(viewAsSubMenu, wxString::FromAscii("View As:"));
viewAsSubMenu->Append(IDM_VIEWASFP, StrToWxStr("FP value"));
viewAsSubMenu->Append(IDM_VIEWASASCII, StrToWxStr("ASCII"));
viewAsSubMenu->Append(IDM_VIEWASHEX, StrToWxStr("Hex"));
menu->AppendSubMenu(viewAsSubMenu, StrToWxStr("View As:"));

PopupMenu(menu);
}
Expand Down Expand Up @@ -285,7 +287,7 @@ void CMemoryView::OnPaint(wxPaintEvent& event)
char mem[256];
debugger->getRawMemoryString(memory, address, mem, 256);
dc.SetTextForeground(_T("#000080"));
dc.DrawText(wxString::FromAscii(mem), 17+fontSize*(8), rowY1);
dc.DrawText(StrToWxStr(mem), 17+fontSize*(8), rowY1);
dc.SetTextForeground(_T("#000000"));
}

Expand Down Expand Up @@ -361,17 +363,17 @@ void CMemoryView::OnPaint(wxPaintEvent& event)

char desc[256] = "";
if (viewAsType != VIEWAS_HEX)
dc.DrawText(wxString::FromAscii(dis), textPlacement + fontSize*(8 + 8), rowY1);
dc.DrawText(StrToWxStr(dis), textPlacement + fontSize*(8 + 8), rowY1);
else
dc.DrawText(wxString::FromAscii(dis), textPlacement, rowY1);
dc.DrawText(StrToWxStr(dis), textPlacement, rowY1);

if (desc[0] == 0)
strcpy(desc, debugger->getDescription(address).c_str());

dc.SetTextForeground(_T("#0000FF"));

if (strlen(desc))
dc.DrawText(wxString::FromAscii(desc), 17+fontSize*((8+8+8+30)*2), rowY1);
dc.DrawText(StrToWxStr(desc), 17+fontSize*((8+8+8+30)*2), rowY1);

// Show blue memory check dot
if (debugger->isMemCheck(address))
Expand Down
17 changes: 8 additions & 9 deletions Source/Core/DolphinWX/Src/Debugger/MemoryWindow.cpp
Expand Up @@ -20,6 +20,8 @@
#include <wx/listctrl.h>
#include <wx/thread.h>
#include <wx/listctrl.h>

#include "../WxUtils.h"
#include "MemoryWindow.h"
#include "HW/CPU.h"
#include "PowerPC/PowerPC.h"
Expand Down Expand Up @@ -152,8 +154,8 @@ void CMemoryWindow::JumpToAddress(u32 _Address)

void CMemoryWindow::SetMemoryValue(wxCommandEvent& event)
{
std::string str_addr = std::string(addrbox->GetValue().mb_str());
std::string str_val = std::string(valbox->GetValue().mb_str());
std::string str_addr = WxStrToStr(addrbox->GetValue());
std::string str_val = WxStrToStr(valbox->GetValue());
u32 addr;
u32 val;

Expand All @@ -179,7 +181,7 @@ void CMemoryWindow::OnAddrBoxChange(wxCommandEvent& event)
if (txt.size())
{
u32 addr;
sscanf(txt.mb_str(), "%08x", &addr);
sscanf(WxStrToStr(txt).c_str(), "%08x", &addr);
memview->Center(addr & ~3);
}

Expand Down Expand Up @@ -349,10 +351,7 @@ void CMemoryWindow::onSearch(wxCommandEvent& event)
tmpstr = new char[newsize + 1];
memset(tmpstr, 0, newsize + 1);
}
//sprintf(tmpstr, "%s%s", tmpstr, rawData.c_str());
//strcpy(&tmpstr[1], rawData.ToAscii());
//memcpy(&tmpstr[1], &rawData.c_str()[0], rawData.size());
sprintf(tmpstr, "%s%s", tmpstr, (const char *)rawData.mb_str());
sprintf(tmpstr, "%s%s", tmpstr, WxStrToStr(rawData).c_str());
tmp2 = &Dest.front();
count = 0;
for(i = 0; i < strlen(tmpstr); i++)
Expand All @@ -376,7 +375,7 @@ void CMemoryWindow::onSearch(wxCommandEvent& event)
tmpstr = new char[size+1];

tmp2 = &Dest.front();
sprintf(tmpstr, "%s", (const char *)rawData.mb_str());
sprintf(tmpstr, "%s", WxStrToStr(rawData).c_str());

for(i = 0; i < size; i++)
tmp2[i] = tmpstr[i];
Expand All @@ -393,7 +392,7 @@ void CMemoryWindow::onSearch(wxCommandEvent& event)
u32 addr = 0;
if (txt.size())
{
sscanf(txt.mb_str(), "%08x", &addr);
sscanf(WxStrToStr(txt).c_str(), "%08x", &addr);
}
i = addr+4;
for( ; i < szRAM; i++)
Expand Down
9 changes: 5 additions & 4 deletions Source/Core/DolphinWX/Src/Debugger/RegisterView.cpp
Expand Up @@ -20,6 +20,7 @@
#include "PowerPC/PowerPC.h"
#include "HW/ProcessorInterface.h"
#include "IniFile.h"
#include "../WxUtils.h"

// F-zero 80005e60 wtf??

Expand Down Expand Up @@ -51,17 +52,17 @@ wxString CRegTable::GetValue(int row, int col)
{
if (row < 32) {
switch (col) {
case 0: return wxString::FromAscii(GetGPRName(row));
case 0: return StrToWxStr(GetGPRName(row));
case 1: return wxString::Format(wxT("%08x"), GPR(row));
case 2: return wxString::FromAscii(GetFPRName(row));
case 2: return StrToWxStr(GetFPRName(row));
case 3: return wxString::Format(wxT("%016llx"), riPS0(row));
case 4: return wxString::Format(wxT("%016llx"), riPS1(row));
default: return wxEmptyString;
}
} else {
if (row - 32 < NUM_SPECIALS) {
switch (col) {
case 0: return wxString::FromAscii(special_reg_names[row - 32]);
case 0: return StrToWxStr(special_reg_names[row - 32]);
case 1: return wxString::Format(wxT("%08x"), GetSpecialRegValue(row - 32));
default: return wxEmptyString;
}
Expand Down Expand Up @@ -91,7 +92,7 @@ static void SetSpecialRegValue(int reg, u32 value) {
void CRegTable::SetValue(int row, int col, const wxString& strNewVal)
{
u32 newVal = 0;
if (TryParse(std::string(strNewVal.mb_str()), &newVal))
if (TryParse(WxStrToStr(strNewVal), &newVal))
{
if (row < 32) {
if (col == 1)
Expand Down
7 changes: 4 additions & 3 deletions Source/Core/DolphinWX/Src/FifoPlayerDlg.cpp
Expand Up @@ -22,6 +22,7 @@
#include "FifoPlayer/FifoPlayer.h"
#include "FifoPlayer/FifoRecorder.h"
#include "OpcodeDecoding.h"
#include "WxUtils.h"

#include <wx/spinctrl.h>
#include <wx/clipbrd.h>
Expand Down Expand Up @@ -395,7 +396,7 @@ void FifoPlayerDlg::OnSaveFile(wxCommandEvent& WXUNUSED(event))
if (!path.empty())
{
wxBeginBusyCursor();
bool result = file->Save(path.mb_str());
bool result = file->Save(WxStrToStr(path).c_str());
wxEndBusyCursor();

if (!result)
Expand Down Expand Up @@ -752,10 +753,10 @@ void FifoPlayerDlg::OnObjectCmdListSelectionChanged(wxCommandEvent& event)
char name[64]="\0", desc[512]="\0";
GetBPRegInfo(cmddata+1, name, sizeof(name), desc, sizeof(desc));
newLabel = _("BP register ");
newLabel += (name[0] != '\0') ? wxString(name, *wxConvCurrent) : wxString::Format(_("UNKNOWN_%02X"), *(cmddata+1));
newLabel += (name[0] != '\0') ? StrToWxStr(name) : wxString::Format(_("UNKNOWN_%02X"), *(cmddata+1));
newLabel += wxT(":\n");
if (desc[0] != '\0')
newLabel += wxString(desc, *wxConvCurrent);
newLabel += StrToWxStr(desc);
else
newLabel += _("No description available");
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/DolphinWX/Src/Frame.cpp
Expand Up @@ -659,7 +659,7 @@ void CFrame::OnGameListCtrl_ItemActivated(wxListEvent& WXUNUSED (event))
// 1. Boot the selected iso
// 2. Boot the default or last loaded iso.
// 3. Call BrowseForDirectory if the gamelist is empty
if (!m_GameListCtrl->GetGameNames().size() &&
if (!m_GameListCtrl->GetISO(0) &&
!((SConfig::GetInstance().m_ListGC &&
SConfig::GetInstance().m_ListWii &&
SConfig::GetInstance().m_ListWad) &&
Expand Down Expand Up @@ -693,7 +693,7 @@ void CFrame::OnGameListCtrl_ItemActivated(wxListEvent& WXUNUSED (event))

m_GameListCtrl->Update();
}
else if (!m_GameListCtrl->GetGameNames().size())
else if (!m_GameListCtrl->GetISO(0))
m_GameListCtrl->BrowseForDirectory();
else
// Game started by double click
Expand Down
11 changes: 6 additions & 5 deletions Source/Core/DolphinWX/Src/FrameAui.cpp
Expand Up @@ -21,6 +21,7 @@
#include "Globals.h" // Local
#include "Frame.h"
#include "LogWindow.h"
#include "WxUtils.h"

#include "ConfigManager.h" // Core

Expand Down Expand Up @@ -548,7 +549,7 @@ void CFrame::OnDropDownToolbarItem(wxAuiToolBarEvent& event)
for (u32 i = 0; i < Perspectives.size(); i++)
{
wxMenuItem* mItem = new wxMenuItem(menuPopup, IDM_PERSPECTIVES_0 + i,
wxString::FromAscii(Perspectives[i].Name.c_str()),
StrToWxStr(Perspectives[i].Name),
wxT(""), wxITEM_CHECK);
menuPopup->Append(mItem);
if (i == ActivePerspective) mItem->Check(true);
Expand Down Expand Up @@ -580,7 +581,7 @@ void CFrame::OnToolBar(wxCommandEvent& event)
return;
}
SaveIniPerspectives();
GetStatusBar()->SetStatusText(wxString::FromAscii(std::string
GetStatusBar()->SetStatusText(StrToWxStr(std::string
("Saved " + Perspectives[ActivePerspective].Name).c_str()), 0);
break;
case IDM_PERSPECTIVES_ADD_PANE:
Expand Down Expand Up @@ -633,7 +634,7 @@ void CFrame::OnDropDownToolbarSelect(wxCommandEvent& event)
}

SPerspectives Tmp;
Tmp.Name = dlg.GetValue().mb_str();
Tmp.Name = WxStrToStr(dlg.GetValue());
Tmp.Perspective = m_Mgr->SavePerspective();

ActivePerspective = (u32)Perspectives.size();
Expand Down Expand Up @@ -870,7 +871,7 @@ void CFrame::LoadIniPerspectives()
ini.Get(_Section.c_str(), "Width", &_Width, "70,25");
ini.Get(_Section.c_str(), "Height", &_Height, "80,80");

Tmp.Perspective = wxString::FromAscii(_Perspective.c_str());
Tmp.Perspective = StrToWxStr(_Perspective);

SplitString(_Width, ',', _SWidth);
SplitString(_Height, ',', _SHeight);
Expand Down Expand Up @@ -940,7 +941,7 @@ void CFrame::SaveIniPerspectives()
for (u32 i = 0; i < Perspectives.size(); i++)
{
std::string _Section = "P - " + Perspectives[i].Name;
ini.Set(_Section.c_str(), "Perspective", Perspectives[i].Perspective.mb_str());
ini.Set(_Section.c_str(), "Perspective", WxStrToStr(Perspectives[i].Perspective));

std::string SWidth = "", SHeight = "";
for (u32 j = 0; j < Perspectives[i].Width.size(); j++)
Expand Down